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 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <fm/topo_mod.h> 30 #include <libdevinfo.h> 31 #include "pcibus.h" 32 #include "hostbridge.h" 33 #include "did.h" 34 #include "util.h" 35 36 extern did_hash_t *Didhash; 37 38 static int 39 hb_process(tnode_t *ptn, topo_instance_t hbi, di_node_t bn) 40 { 41 tnode_t *hb; 42 43 if (did_create(Didhash, bn, 0, hbi, NO_RC, TRUST_BDF) == NULL) 44 return (-1); 45 if ((hb = pcihostbridge_declare(ptn, bn, hbi)) == NULL) 46 return (-1); 47 return (topo_mod_enumerate(HbHdl, 48 hb, PCI_BUS, PCI_BUS, 0, MAX_HB_BUSES)); 49 } 50 51 static int 52 rc_process(tnode_t *ptn, topo_instance_t hbi, di_node_t bn) 53 { 54 tnode_t *hb; 55 tnode_t *rc; 56 57 if (did_create(Didhash, bn, 0, hbi, hbi, TRUST_BDF) == NULL) 58 return (-1); 59 if ((hb = pciexhostbridge_declare(ptn, bn, hbi)) == NULL) 60 return (-1); 61 if ((rc = pciexrc_declare(hb, bn, hbi)) == NULL) 62 return (-1); 63 return (topo_mod_enumerate(HbHdl, 64 rc, PCI_BUS, PCIEX_BUS, 0, MAX_HB_BUSES)); 65 } 66 67 68 int 69 pci_hostbridges_find(tnode_t *ptn) 70 { 71 di_node_t devtree; 72 di_node_t pnode; 73 char *eplain; 74 int hbcnt = 0; 75 76 /* Scan for buses, top-level devinfo nodes with the right driver */ 77 devtree = di_init("/", DINFOCPYALL); 78 if (devtree == DI_NODE_NIL) { 79 topo_mod_dprintf(HbHdl, "devinfo init failed."); 80 topo_node_range_destroy(ptn, HOSTBRIDGE); 81 return (0); 82 } 83 84 /* 85 * By default we do not enumerate generic PCI on x86 86 */ 87 eplain = getenv("TOPOENUMPLAINPCI"); 88 if (eplain != NULL) { 89 pnode = di_drv_first_node(PCI, devtree); 90 while (pnode != DI_NODE_NIL) { 91 if (hb_process(ptn, hbcnt++, pnode) < 0) { 92 di_fini(devtree); 93 topo_node_range_destroy(ptn, HOSTBRIDGE); 94 return (topo_mod_seterrno(HbHdl, 95 EMOD_PARTIAL_ENUM)); 96 } 97 pnode = di_drv_next_node(pnode); 98 } 99 } 100 101 pnode = di_drv_first_node(NPE, devtree); 102 while (pnode != DI_NODE_NIL) { 103 if (rc_process(ptn, hbcnt++, pnode) < 0) { 104 di_fini(devtree); 105 topo_node_range_destroy(ptn, HOSTBRIDGE); 106 return (topo_mod_seterrno(HbHdl, EMOD_PARTIAL_ENUM)); 107 } 108 pnode = di_drv_next_node(pnode); 109 } 110 di_fini(devtree); 111 return (0); 112 } 113 114 /*ARGSUSED*/ 115 int 116 platform_hb_enum(tnode_t *parent, const char *name, 117 topo_instance_t imin, topo_instance_t imax) 118 { 119 return (pci_hostbridges_find(parent)); 120 } 121 122 /*ARGSUSED*/ 123 int 124 platform_hb_label(tnode_t *node, nvlist_t *in, nvlist_t **out) 125 { 126 return (labelmethod_inherit(HbHdl, node, in, out)); 127 } 128