1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#include <fm/topo_mod.h>
28#include <did_props.h>
29
30/*
31 * Including the following file gives us definitions of the three
32 * global arrays used to adjust labels, Slot_Rewrites, Physlot_Names,
33 * and Missing_Names.  With those defined we can use the common labeling
34 * routines for pci.
35 */
36#include "pci_sun4u.h"
37
38#include "pci_sun4.h"
39#include <strings.h>
40
41int
42platform_pci_label(topo_mod_t *mod, tnode_t *node, nvlist_t *in,
43    nvlist_t **out)
44{
45	return (pci_label_cmn(mod, node, in, out));
46}
47int
48platform_pci_fru(topo_mod_t *mod, tnode_t *node, nvlist_t *in,
49    nvlist_t **out)
50{
51	return (pci_fru_compute(mod, node, in, out));
52}
53
54/*
55 * Sun-Fire platform function to test whether the hostbridge which
56 * this PCI device is associated with is an Xmits or not. This
57 * function applies to E3800, E48xx, E4900, E6800, and E6900.
58 *
59 * Return 1 if the hostbridge is an Xmits otherwise return 0.
60 *
61 * This check is done by walking up the topo tree and checking the
62 * associated device info nodes for a binding name or a compatible
63 * name matching that of Xmits.
64 */
65int
66sunfire_test_func(topo_mod_t *mod, did_t *dp)
67{
68	tnode_t *tp;
69	int done, xmits_found, i, n;
70	char *compatible_names, *binding_name;
71
72	done = xmits_found = 0;
73	tp = did_gettnode(dp);
74
75	while (!done) {
76		topo_mod_dprintf(mod, "%s: dp=0x%p, tp=0x%p\n",
77		    __func__, dp, tp);
78
79		/*
80		 * Check binding name.
81		 */
82		binding_name = di_binding_name(did_dinode(dp));
83		if (binding_name != NULL) {
84			topo_mod_dprintf(mod, "%s: binding_name=%s\n",
85			    __func__, binding_name);
86			if (strncmp(binding_name, XMITS_COMPAT,
87			    sizeof (XMITS_COMPAT)) == 0) {
88				done = xmits_found = 1;
89				break;
90			}
91		}
92
93		/*
94		 * Check compatible names.
95		 */
96		n = di_compatible_names(did_dinode(dp), &compatible_names);
97		for (i = 0; i < n; i++) {
98			topo_mod_dprintf(mod, "%s: compatible_name[%d]=%s\n",
99			    __func__, i, compatible_names);
100			if (strncmp(compatible_names, XMITS_COMPAT,
101			    sizeof (XMITS_COMPAT)) == 0) {
102				done = xmits_found = 1;
103				break;
104			}
105			compatible_names += strlen(compatible_names) + 1;
106		}
107
108		/*
109		 * Walk up the tree until we hit the top or hit
110		 * a non-PCI device.
111		 */
112		if (((tp = topo_node_parent(tp)) == NULL) ||
113		    (dp = did_find(mod, topo_node_getspecific(tp))) == NULL) {
114			done = 1;
115			break;
116		}
117	}
118
119	return (xmits_found);
120}
121