2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * i86pc Generic hostbridge/pciex/pci enumerator
2N/A *
2N/A * hostbridge/pciexrc/pcibus topo nodes are created per SMBIOS type 138
2N/A * (SUN_OEM_PCIEXRC) records. Each type 138 record can either represent
2N/A * a hostbridge or a pciexrc/pcibus determined by whether it points to
2N/A * a baseboard record or another type 138 record.
2N/A *
2N/A * x86pi_gen_hbr() is called when a new hostbridge node needs to be created..
2N/A * It then searches all the type 138 records that connected to it. For each
2N/A * of the records, bdf is compared to find a matching di_node. If the
2N/A * di_node is a pciex root port, a pciexrc (bad name!) node will be created.
2N/A * When pciexrc creation is done, or the di_node is a pcibus, in either
2N/A * case the pcibus module will loaded to enumerate pciexbus/pcibus etc.
2N/A *
2N/A * The enumeration uses did routines heavily, which requires a did hash
2N/A * pointer stored in x86pi's module-specific area.
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <strings.h>
2N/A#include <fm/topo_mod.h>
2N/A#include <fm/topo_hc.h>
2N/A#include <sys/systeminfo.h>
2N/A#include <sys/smbios_impl.h>
2N/A#include <sys/fm/protocol.h>
2N/A#include <x86pi_impl.h>
2N/A#include <did.h>
2N/A#include <did_impl.h>
2N/A#include <did_props.h>
2N/A#include <hostbridge.h>
2N/A
2N/A#define PCI_ENUM "pcibus"
2N/A#define PCI_ENUMR_VERS 1
2N/A#define MAX_HB_BUSES 255
2N/A
2N/Aextern txprop_t RC_common_props[], HB_common_props[], ExHB_common_props[];
2N/Aextern int RC_propcnt, HB_propcnt, ExHB_propcnt;
2N/A
2N/Aint
2N/Ax86pi_hbr_enum_init(topo_mod_t *mod, topo_mod_t **pcimp)
2N/A{
2N/A const char *f = "x86pi_hbr_enum_init";
2N/A
2N/A if (did_hash_init(mod) < 0) {
2N/A topo_mod_dprintf(mod, "%s: did_hash_init() failed.\n", f);
2N/A return (-1);
2N/A }
2N/A
2N/A if ((*pcimp = topo_mod_load(mod, PCI_ENUM, PCI_ENUMR_VERS)) == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: %s enumerator could not load %s.\n",
2N/A f, HOSTBRIDGE, PCI_ENUM);
2N/A did_hash_fini(mod);
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Avoid
2N/Ax86pi_hbr_enum_fini(topo_mod_t *mod, topo_mod_t **pcimp)
2N/A{
2N/A did_hash_fini(mod);
2N/A topo_mod_unload(*pcimp);
2N/A}
2N/A
2N/Astatic int
2N/Apciex_process(topo_mod_t *mod, tnode_t *tn_hbr, di_node_t rcn,
2N/A topo_instance_t rci)
2N/A{
2N/A did_t *did;
2N/A int rv;
2N/A tnode_t *tn_rc;
2N/A x86pi_hcfmri_t hcfmri = {0};
2N/A tnode_t *tn_bb = topo_node_parent(tn_hbr);
2N/A const char *f = "pciexrc_process";
2N/A
2N/A if ((did = did_create(mod, rcn, topo_node_instance(tn_bb),
2N/A topo_node_instance(tn_hbr), rci, TRUST_BDF)) == NULL)
2N/A return (NULL);
2N/A
2N/A did_markrc(did);
2N/A
2N/A /*
2N/A * Let did set the hostbridge properties excluding FRU and label.
2N/A */
2N/A (void) did_props_set(tn_hbr, did, ExHB_common_props, ExHB_propcnt - 2);
2N/A
2N/A if (topo_node_range_create(mod, tn_hbr, PCIEX_ROOT, 0,
2N/A MAX_HB_BUSES) != 0 && topo_mod_errno(mod) != EMOD_NODE_DUP) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: create child range for %s failed: %s\n",
2N/A f, PCIEX_ROOT, topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A hcfmri.hc_name = PCIEX_ROOT;
2N/A hcfmri.instance = rci;
2N/A rv = x86pi_enum_generic(mod, &hcfmri, tn_hbr, tn_hbr, &tn_rc, 0);
2N/A if (rv != 0) {
2N/A topo_mod_dprintf(mod, "%s: failed to create %s = %d\n",
2N/A f, PCIEX_ROOT, rci);
2N/A return (-1);
2N/A }
2N/A
2N/A /*
2N/A * pcibus enumerator requires di_node_t be set in node specific
2N/A */
2N/A topo_node_setspecific(tn_rc, rcn);
2N/A
2N/A /*
2N/A * Let did set the RC properties excluding FRU, and label.
2N/A */
2N/A if (did_props_set(tn_rc, did, RC_common_props, RC_propcnt - 2) < 0) {
2N/A topo_mod_dprintf(mod, "%s: did_props_set failed for %s = %d\n",
2N/A f, PCIEX_ROOT, rci);
2N/A topo_node_unbind(tn_rc);
2N/A return (-1);
2N/A }
2N/A
2N/A if (topo_node_range_create(mod, tn_rc, PCIEX_BUS, 0,
2N/A MAX_HB_BUSES) != 0 && topo_mod_errno(mod) != EMOD_NODE_DUP) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: create child range for %s failed: %s\n",
2N/A f, PCIEX_BUS, topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A return (topo_mod_enumerate(mod, tn_rc, PCI_BUS, PCIEX_BUS,
2N/A 0, MAX_HB_BUSES, did));
2N/A}
2N/A
2N/Astatic int
2N/Apci_process(topo_mod_t *mod, tnode_t *tn_hbr, di_node_t bn)
2N/A{
2N/A did_t *did;
2N/A tnode_t *tn_bb = topo_node_parent(tn_hbr);
2N/A
2N/A if ((did = did_create(mod, bn, topo_node_instance(tn_bb),
2N/A topo_node_instance(tn_hbr), NO_RC, TRUST_BDF)) == NULL)
2N/A return (-1);
2N/A
2N/A /*
2N/A * Let did set the hostbridge properties excluding FRU and label.
2N/A */
2N/A (void) did_props_set(tn_hbr, did, HB_common_props, HB_propcnt - 2);
2N/A
2N/A if (topo_node_range_create(mod, tn_hbr, PCI_BUS, 0,
2N/A MAX_HB_BUSES) != 0 && topo_mod_errno(mod) != EMOD_NODE_DUP) {
2N/A topo_mod_dprintf(mod, "create child range for %s failed: %s\n",
2N/A PCI_BUS, topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A return (topo_mod_enumerate(mod, tn_hbr, PCI_BUS, PCI_BUS,
2N/A 0, MAX_HB_BUSES, did));
2N/A}
2N/A
2N/Astatic int
2N/Ax86pi_gen_pci_pciexrc(topo_mod_t *mod, tnode_t *tn_hbr, uint16_t bdf,
2N/A topo_instance_t *rcip)
2N/A{
2N/A di_node_t devtree, pnode, cnode;
2N/A
2N/A topo_mod_dprintf(mod, "creating pci/pciexrc node bdf = %#x\n",
2N/A (int)bdf);
2N/A
2N/A devtree = topo_mod_devinfo(mod);
2N/A if (devtree == DI_NODE_NIL) {
2N/A topo_mod_dprintf(mod, "devinfo init failed.\n");
2N/A return (-1);
2N/A }
2N/A
2N/A for (pnode = di_drv_first_node(PCI, devtree);
2N/A pnode != DI_NODE_NIL; pnode = di_drv_next_node(pnode))
2N/A if (x86pi_bdf(mod, pnode) == bdf)
2N/A return (pci_process(mod, tn_hbr, pnode));
2N/A
2N/A pnode = di_drv_first_node(NPE, devtree);
2N/A while (pnode != DI_NODE_NIL) {
2N/A for (cnode = di_child_node(pnode); cnode != DI_NODE_NIL;
2N/A cnode = di_sibling_node(cnode)) {
2N/A if (di_driver_name(cnode) == NULL ||
2N/A x86pi_bdf(mod, cnode) != bdf)
2N/A continue;
2N/A
2N/A if (strcmp(di_driver_name(cnode), PCI_PCI) == 0)
2N/A return (pci_process(mod, tn_hbr, cnode));
2N/A
2N/A if (strcmp(di_driver_name(cnode), PCIEB) == 0)
2N/A return (pciex_process(mod, tn_hbr,
2N/A cnode, (*rcip)++));
2N/A
2N/A topo_mod_dprintf(mod, "no matching driver found: "
2N/A "bdf = %#x\n", (int)bdf);
2N/A }
2N/A pnode = di_drv_next_node(pnode);
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "no matching bdf found: bdf = %#x\n", (int)bdf);
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/Ax86pi_gen_hbr(topo_mod_t *mod, tnode_t *tn_bb,
2N/A int hbr_smbid, topo_instance_t hbri, topo_instance_t *rcip)
2N/A{
2N/A x86pi_hcfmri_t hcfmri = {0};
2N/A tnode_t *tn_hbr;
2N/A smbs_cnt_t *smbc = &stypes[SUN_OEM_PCIEXRC];
2N/A smbios_pciexrc_t smb_rc;
2N/A int i, rv, err = 0;
2N/A int min = 0, max = 1024;
2N/A const char *f = "x86pi_gen_hbr";
2N/A smbios_hdl_t *shp;
2N/A
2N/A shp = topo_mod_smbios(mod);
2N/A if (shp == NULL)
2N/A return (topo_mod_seterrno(mod, EMOD_PARTIAL_ENUM));
2N/A
2N/A hcfmri.hc_name = HOSTBRIDGE;
2N/A hcfmri.instance = hbri;
2N/A
2N/A /* create and bind the "hostbridge" node */
2N/A rv = x86pi_enum_generic(mod, &hcfmri, tn_bb, tn_bb, &tn_hbr, 0);
2N/A if (rv != 0) {
2N/A topo_mod_dprintf(mod, "%s: failed to create %s = %d\n",
2N/A f, HOSTBRIDGE, hbri);
2N/A return (topo_mod_seterrno(mod, EMOD_PARTIAL_ENUM));
2N/A }
2N/A
2N/A /*
2N/A * Walk the smbios records and create the pci/pciexrc nodes
2N/A */
2N/A for (i = 0; i < smbc->count; i++) {
2N/A if (smbios_info_pciexrc(shp, smbc->ids[i].id, &smb_rc) != 0)
2N/A topo_mod_dprintf(mod,
2N/A "%s: failed: id = %d\n", f, (int)smbc->ids[i].id);
2N/A else if (smb_rc.smbpcie_bb == hbr_smbid &&
2N/A x86pi_gen_pci_pciexrc(mod, tn_hbr, smb_rc.smbpcie_bdf,
2N/A rcip) != 0)
2N/A err++;
2N/A }
2N/A
2N/A /* USB enumeration */
2N/A if (topo_mod_load(mod, USBTOPO, TOPO_VERSION) == NULL) {
2N/A topo_mod_dprintf(mod, "%s: could not load usb enum\n", f);
2N/A err++;
2N/A } else {
2N/A rv = topo_node_range_create(mod, tn_hbr, USB_BUS, min, max);
2N/A if (rv != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: could not create usb range: %s\n", f,
2N/A topo_strerror(topo_mod_errno(mod)));
2N/A err++;
2N/A } else {
2N/A rv = topo_mod_enumerate(mod, tn_hbr, USBTOPO, USB_BUS,
2N/A min, max, NULL);
2N/A if (rv == 0) {
2N/A topo_mod_dprintf(mod, "%s: usb succeed", f);
2N/A } else {
2N/A topo_mod_dprintf(mod, "%s: usb fail", f);
2N/A err++;
2N/A }
2N/A }
2N/A }
2N/A
2N/A return (err == 0 ? 0 : topo_mod_seterrno(mod, EMOD_PARTIAL_ENUM));
2N/A}