diff options
| author | cindi <none@none> | 2006-11-04 01:18:55 -0800 |
|---|---|---|
| committer | cindi <none@none> | 2006-11-04 01:18:55 -0800 |
| commit | 0eb822a1c0c2bea495647510b75f77f0e57633eb (patch) | |
| tree | d104741eef4bddb27171407d1243e37790c7d499 /usr/src/lib/fm/topo/modules/common | |
| parent | 389056bd4327caca73482e60b80da00f4eaf3de9 (diff) | |
| download | illumos-joyent-0eb822a1c0c2bea495647510b75f77f0e57633eb.tar.gz | |
6396916 verification of dtd file name is wrong
6399876 libtopo does not properly support an alternate root path
6399927 libtopo debug information indicates "no topology file found" when it is unable to parse file.
6421101 fmsim doesn't allow simulated topology to be specified with new libtopo
6422759 fmd memory leaks detected on system experiencing significant pcie fabric errors
6429072 memory leak in iob_tnode_create
6448718 libtopo needs better enum module APIs
6467144 topo_fmri_str2nvl doesn't handle authority or properties
6473916 fmd should return a full populated topo snapshot in fmd_hdl_topology() and fmd_fmri_topology()
6473918 hc scheme plugin is_present routine is broken
6477382 Need public header file for hc scheme component names and properties
6477385 fmtopo -V needs to be more friendly
6477426 fmtopo -d should not be so chatty
6477430 Need ability to load additional libtopo map files
6477442 libtopo should allow alternate platform topo map files
6477446 Remove unused topo methods from enumerator modules
6477453 pcibus and hostbridge interface boundaries are a mess
6477456 hc enumerators must support authority information
6477461 topo_fru_compute and topo_asru_compute should return static props when computation fails
6480930 fmtopo should support a -x option
--HG--
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Blade-T6300/Makefile => deleted_files/usr/src/lib/fm/topo/files/SUNW,Sun-Blade-T6300/Makefile
rename : usr/src/lib/fm/topo/modules/common/pcifn_enum.c => deleted_files/usr/src/lib/fm/topo/modules/common/pcibus/pcifn_enum.c
rename : usr/src/lib/fm/topo/modules/common/pcifn_enum.h => deleted_files/usr/src/lib/fm/topo/modules/common/pcibus/pcifn_enum.h
rename : usr/src/lib/fm/topo/modules/sun4v/ioboard/Makefile => deleted_files/usr/src/lib/fm/topo/modules/sun4v/ioboard/Makefile
rename : usr/src/lib/fm/topo/modules/sun4v/ioboard/iob_platform.c => deleted_files/usr/src/lib/fm/topo/modules/sun4v/ioboard/iob_platform.c
rename : usr/src/lib/fm/topo/libtopo/common/hc_canon.h => usr/src/lib/fm/topo/libtopo/common/topo_hc.h
rename : usr/src/lib/fm/topo/files/Makefile => usr/src/lib/fm/topo/maps/Makefile
rename : usr/src/lib/fm/topo/files/Makefile.file => usr/src/lib/fm/topo/maps/Makefile.map
rename : usr/src/lib/fm/topo/files/SUNW,SPARC-Enterprise/Makefile => usr/src/lib/fm/topo/maps/SUNW,SPARC-Enterprise/Makefile
rename : usr/src/lib/fm/topo/files/SUNW,SPARC-Enterprise/hc-topology.xml => usr/src/lib/fm/topo/maps/SUNW,SPARC-Enterprise/SPARC-Enterprise-hc-topology.xml
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Fire-15000/Makefile => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire-15000/Makefile
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Fire-15000/hc-topology.xml => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire-15000/Sun-Fire-15000-hc-topology.xml
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Fire-T200/Makefile => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire-T200/Makefile
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Blade-T6300/hc-topology.xml => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire-T200/Sun-Blade-T6300-hc-topology.xml
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Fire-T200/hc-topology.xml => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire-T200/Sun-Fire-T200-hc-topology.xml
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Fire/Makefile => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire/Makefile
rename : usr/src/lib/fm/topo/files/SUNW,Sun-Fire/hc-topology.xml => usr/src/lib/fm/topo/maps/SUNW,Sun-Fire/Sun-Fire-hc-topology.xml
rename : usr/src/lib/fm/topo/files/common/topology.dtd.1 => usr/src/lib/fm/topo/maps/common/topology.dtd.1
rename : usr/src/lib/fm/topo/files/i86pc/Makefile => usr/src/lib/fm/topo/maps/i86pc/Makefile
rename : usr/src/lib/fm/topo/files/i86pc/hc-topology.xml => usr/src/lib/fm/topo/maps/i86pc/i86pc-hc-topology.xml
rename : usr/src/lib/fm/topo/files/sun4u/Makefile => usr/src/lib/fm/topo/maps/sun4u/Makefile
rename : usr/src/lib/fm/topo/files/sun4u/hc-topology.xml => usr/src/lib/fm/topo/maps/sun4u/sun4u-hc-topology.xml
rename : usr/src/lib/fm/topo/files/sun4v/Makefile => usr/src/lib/fm/topo/maps/sun4v/Makefile
rename : usr/src/lib/fm/topo/files/sun4v/hc-topology.xml => usr/src/lib/fm/topo/maps/sun4v/sun4v-hc-topology.xml
rename : usr/src/lib/fm/topo/modules/common/hostbridge.c => usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c
rename : usr/src/lib/fm/topo/modules/common/hostbridge.h => usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.h
rename : usr/src/lib/fm/topo/modules/common/did.c => usr/src/lib/fm/topo/modules/common/pcibus/did.c
rename : usr/src/lib/fm/topo/modules/common/did.h => usr/src/lib/fm/topo/modules/common/pcibus/did.h
rename : usr/src/lib/fm/topo/modules/common/did_hash.c => usr/src/lib/fm/topo/modules/common/pcibus/did_hash.c
rename : usr/src/lib/fm/topo/modules/common/did_impl.h => usr/src/lib/fm/topo/modules/common/pcibus/did_impl.h
rename : usr/src/lib/fm/topo/modules/common/did_props.c => usr/src/lib/fm/topo/modules/common/pcibus/did_props.c
rename : usr/src/lib/fm/topo/modules/common/did_props.h => usr/src/lib/fm/topo/modules/common/pcibus/did_props.h
rename : usr/src/lib/fm/topo/modules/common/pcibus.c => usr/src/lib/fm/topo/modules/common/pcibus/pcibus.c
rename : usr/src/lib/fm/topo/modules/common/pcibus.h => usr/src/lib/fm/topo/modules/common/pcibus/pcibus.h
rename : usr/src/lib/fm/topo/modules/common/pcibus_labels.c => usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.c
rename : usr/src/lib/fm/topo/modules/common/pcibus_labels.h => usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.h
rename : usr/src/lib/fm/topo/modules/common/util.c => usr/src/lib/fm/topo/modules/common/pcibus/util.c
rename : usr/src/lib/fm/topo/modules/common/util.h => usr/src/lib/fm/topo/modules/common/pcibus/util.h
Diffstat (limited to 'usr/src/lib/fm/topo/modules/common')
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/hostbridge.c | 421 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c | 357 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.h (renamed from usr/src/lib/fm/topo/modules/common/hostbridge.h) | 38 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did.c (renamed from usr/src/lib/fm/topo/modules/common/did.c) | 88 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did.h (renamed from usr/src/lib/fm/topo/modules/common/did.h) | 22 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did_hash.c (renamed from usr/src/lib/fm/topo/modules/common/did_hash.c) | 34 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did_impl.h (renamed from usr/src/lib/fm/topo/modules/common/did_impl.h) | 26 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did_props.c (renamed from usr/src/lib/fm/topo/modules/common/did_props.c) | 294 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did_props.h (renamed from usr/src/lib/fm/topo/modules/common/did_props.h) | 37 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/pcibus.c (renamed from usr/src/lib/fm/topo/modules/common/pcibus.c) | 329 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/pcibus.h (renamed from usr/src/lib/fm/topo/modules/common/pcibus.h) | 40 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.c (renamed from usr/src/lib/fm/topo/modules/common/pcibus_labels.c) | 33 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.h (renamed from usr/src/lib/fm/topo/modules/common/pcibus_labels.h) | 2 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/util.c (renamed from usr/src/lib/fm/topo/modules/common/util.c) | 43 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/util.h (renamed from usr/src/lib/fm/topo/modules/common/util.h) | 0 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcifn_enum.c | 122 | ||||
| -rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcifn_enum.h | 65 |
17 files changed, 785 insertions, 1166 deletions
diff --git a/usr/src/lib/fm/topo/modules/common/hostbridge.c b/usr/src/lib/fm/topo/modules/common/hostbridge.c deleted file mode 100644 index 7dbca54af6..0000000000 --- a/usr/src/lib/fm/topo/modules/common/hostbridge.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <string.h> -#include <fm/topo_mod.h> -#include <libdevinfo.h> -#include <limits.h> -#include <sys/fm/protocol.h> -#include <sys/param.h> -#include <sys/systeminfo.h> -#include <assert.h> -#include <pthread.h> - -#include "pcibus.h" -#include "hostbridge.h" -#include "did.h" -#include "did_props.h" -#include "util.h" - -/* - * hostbridge.c - * Generic code shared by all the hostbridge enumerators - */ - -static void hb_release(topo_mod_t *, tnode_t *); -static int hb_contains(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, - nvlist_t **); -static int hb_present(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, - nvlist_t **); -static int hb_label(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, - nvlist_t **); -static int hb_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t, - topo_instance_t, void *); - -extern txprop_t ExHB_common_props[]; -extern txprop_t HB_common_props[]; -extern txprop_t RC_common_props[]; -extern int ExHB_propcnt; -extern int HB_propcnt; -extern int RC_propcnt; - -static int specific_hb_enum(tnode_t *, const char *, topo_instance_t, - topo_instance_t, di_prom_handle_t, topo_mod_t *); - -const topo_modinfo_t Hb_info = - { HOSTBRIDGE, HB_ENUMR_VERS, hb_enum, hb_release }; - -const topo_method_t Hb_methods[] = { - { "hb_contains", "hb element contains other element", HB_ENUMR_VERS, - TOPO_STABILITY_INTERNAL, hb_contains }, - { "hb_present", "hb element currently present", HB_ENUMR_VERS, - TOPO_STABILITY_INTERNAL, hb_present }, - { TOPO_METH_LABEL, TOPO_METH_LABEL_DESC, - TOPO_METH_LABEL_VERSION, TOPO_STABILITY_INTERNAL, hb_label }, - { NULL } -}; - -void -_topo_init(topo_mod_t *modhdl) -{ - /* - * Turn on module debugging output - */ - if (getenv("TOPOHBDBG") != NULL) - topo_mod_setdebug(modhdl, TOPO_DBG_ALL); - topo_mod_dprintf(modhdl, "initializing hostbridge enumerator\n"); - - topo_mod_register(modhdl, &Hb_info, NULL); - topo_mod_dprintf(modhdl, "Hostbridge enumr initd\n"); -} - -void -_topo_fini(topo_mod_t *modhdl) -{ - topo_mod_unregister(modhdl); -} - -/*ARGSUSED*/ -static int -hb_contains(topo_mod_t *mp, tnode_t *node, topo_version_t version, - nvlist_t *in, nvlist_t **out) -{ - return (0); -} - -/*ARGSUSED*/ -static int -hb_present(topo_mod_t *mp, tnode_t *node, topo_version_t version, - nvlist_t *in, nvlist_t **out) -{ - return (0); -} - -static int -hb_label(topo_mod_t *mp, tnode_t *node, topo_version_t version, - nvlist_t *in, nvlist_t **out) -{ - if (version > TOPO_METH_LABEL_VERSION) - return (topo_mod_seterrno(mp, EMOD_VER_NEW)); - return (platform_hb_label(node, in, out, mp)); -} - -static topo_mod_t * -pci_enumr_load(topo_mod_t *mp, tnode_t *parent) -{ - topo_mod_t *rp = NULL; - char *plat, *mach; - char *pcipath; - char *rootdir; - int err; - - plat = mach = NULL; - - if (topo_prop_get_string(parent, - TOPO_PGROUP_SYSTEM, TOPO_PROP_PLATFORM, &plat, &err) < 0) { - (void) topo_mod_seterrno(mp, err); - return (NULL); - } - if (topo_prop_get_string(parent, - TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, &mach, &err) < 0) { - (void) topo_mod_seterrno(mp, err); - return (NULL); - } - pcipath = topo_mod_alloc(mp, PATH_MAX); - rootdir = topo_mod_rootdir(mp); - (void) snprintf(pcipath, - PATH_MAX, PATH_TO_PCI_ENUM, rootdir ? rootdir : "", plat); - - if ((rp = topo_mod_load(mp, pcipath)) == NULL) { - topo_mod_dprintf(mp, - "%s enumerator could not load %s.\n", HOSTBRIDGE, pcipath); - (void) snprintf(pcipath, - PATH_MAX, PATH_TO_PCI_ENUM, rootdir ? rootdir : "", mach); - if ((rp = topo_mod_load(mp, pcipath)) == NULL) { - topo_mod_dprintf(mp, - "%s enumerator could not load %s.\n", - HOSTBRIDGE, pcipath); - } - } - topo_mod_strfree(mp, plat); - topo_mod_strfree(mp, mach); - topo_mod_free(mp, pcipath, PATH_MAX); - return (rp); -} - -/*ARGSUSED*/ -static int -hb_enum(topo_mod_t *mp, tnode_t *pn, const char *name, topo_instance_t imin, - topo_instance_t imax, void *notused) -{ - topo_mod_t *pcimod; - did_hash_t *didhash; - di_prom_handle_t promtree; - int rv; - - if (strcmp(name, HOSTBRIDGE) != 0) { - topo_mod_dprintf(mp, - "Currently only know how to enumerate %s components.\n", - HOSTBRIDGE); - return (0); - } - - /* - * Load the pcibus enumerator, we'll soon need it! - */ - if ((pcimod = pci_enumr_load(mp, pn)) == NULL) - return (-1); - - if ((promtree = di_prom_init()) == DI_PROM_HANDLE_NIL) { - topo_mod_unload(pcimod); - topo_mod_dprintf(mp, - "Hostbridge enumerator: di_prom_handle_init failed.\n"); - return (-1); - } - - /* - * If we're asked to enumerate a whole range of hostbridges, then - * we need to find them all. If we're just asked to enumerate a - * single hostbridge, we expect our caller to have passed us linked - * did_t structures we can use to enumerate the singled out hostbridge. - */ - if (imin != imax) { - - if ((didhash = did_hash_init(mp)) == NULL) { - topo_mod_dprintf(mp, - "Hash initialization for hostbridge " - "enumerator failed.\n"); - topo_mod_unload(pcimod); - return (-1); - } - if ((rv = platform_hb_enum(pn, name, imin, imax, didhash, - promtree, mp)) < 0) - topo_mod_seterrno(mp, EMOD_PARTIAL_ENUM); - di_prom_fini(promtree); - did_hash_fini(didhash); - topo_mod_unload(pcimod); - return (rv); - } else { - rv = specific_hb_enum(pn, name, imin, imax, promtree, mp); - di_prom_fini(promtree); - topo_mod_unload(pcimod); - return (rv); - } -} - -/*ARGSUSED*/ -static void -hb_release(topo_mod_t *mp, tnode_t *node) -{ - topo_method_unregister_all(mp, node); -} - -static tnode_t * -hb_tnode_create(tnode_t *parent, - const char *name, topo_instance_t i, void *priv, topo_mod_t *mod) -{ - topo_hdl_t *thp; - nvlist_t *args, *fmri, *pfmri; - tnode_t *ntn; - int err; - - thp = topo_mod_handle(mod); - - if (topo_node_resource(parent, &pfmri, &err) < 0) { - topo_mod_seterrno(mod, err); - topo_mod_dprintf(mod, - "Unable to retrieve parent resource.\n"); - return (NULL); - } - if (topo_mod_nvalloc(mod, &args, NV_UNIQUE_NAME) != 0) { - (void) topo_mod_seterrno(mod, EMOD_FMRI_NVL); - nvlist_free(pfmri); - return (NULL); - } - err = nvlist_add_nvlist(args, TOPO_METH_FMRI_ARG_PARENT, pfmri); - if (err != 0) { - nvlist_free(pfmri); - nvlist_free(args); - (void) topo_mod_seterrno(mod, EMOD_FMRI_NVL); - return (NULL); - } - - fmri = topo_fmri_create(thp, FM_FMRI_SCHEME_HC, name, i, args, &err); - if (fmri == NULL) { - nvlist_free(pfmri); - nvlist_free(args); - (void) topo_mod_seterrno(mod, err); - topo_mod_dprintf(mod, - "Unable to make nvlist for %s bind: %s.\n", - name, topo_strerror(err)); - return (NULL); - } - - nvlist_free(pfmri); - nvlist_free(args); - ntn = topo_node_bind(mod, parent, name, i, fmri, priv); - if (ntn == NULL) { - topo_mod_dprintf(mod, - "topo_node_bind (%s%d/%s%d) failed: %s\n", - topo_node_name(parent), topo_node_instance(parent), - name, i, - topo_strerror(topo_mod_errno(mod))); - nvlist_free(fmri); - return (NULL); - } - nvlist_free(fmri); - if (topo_method_register(mod, ntn, Hb_methods) < 0) { - topo_mod_dprintf(mod, "topo_method_register failed: %s\n", - topo_strerror(topo_mod_errno(mod))); - topo_node_unbind(ntn); - return (NULL); - } - return (ntn); -} - -tnode_t * -pcihostbridge_declare(tnode_t *parent, di_node_t din, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) -{ - did_t *pd; - tnode_t *ntn; - - if ((pd = did_find(didhash, din)) == NULL) - return (NULL); - if ((ntn = hb_tnode_create(parent, HOSTBRIDGE, i, pd, mod)) == NULL) - return (NULL); - if (did_props_set(ntn, pd, HB_common_props, HB_propcnt, - promtree) < 0) { - topo_node_unbind(ntn); - return (NULL); - } - /* - * We expect to find pci buses beneath the hostbridge. - */ - if (child_range_add(mod, ntn, PCI_BUS, 0, MAX_HB_BUSES) < 0) { - topo_node_unbind(ntn); - return (NULL); - } - return (ntn); -} - -tnode_t * -pciexhostbridge_declare(tnode_t *parent, di_node_t din, topo_instance_t hi, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) -{ - did_t *pd; - tnode_t *ntn; - - if ((pd = did_find(didhash, din)) == NULL) - return (NULL); - if ((ntn = hb_tnode_create(parent, HOSTBRIDGE, hi, din, mod)) == NULL) - return (NULL); - if (did_props_set(ntn, pd, ExHB_common_props, ExHB_propcnt, - promtree) < 0) { - topo_node_unbind(ntn); - return (NULL); - } - /* - * We expect to find root complexes beneath the hostbridge. - */ - if (child_range_add(mod, ntn, PCIEX_ROOT, 0, MAX_HB_BUSES) < 0) { - topo_node_unbind(ntn); - return (NULL); - } - return (ntn); -} - -tnode_t * -pciexrc_declare(tnode_t *parent, di_node_t din, topo_instance_t ri, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) -{ - did_t *pd; - tnode_t *ntn; - - if ((pd = did_find(didhash, din)) == NULL) - return (NULL); - did_markrc(pd); - if ((ntn = hb_tnode_create(parent, PCIEX_ROOT, ri, din, mod)) == NULL) - return (NULL); - if (did_props_set(ntn, pd, RC_common_props, RC_propcnt, - promtree) < 0) { - topo_node_unbind(ntn); - return (NULL); - } - /* - * We expect to find pci-express buses beneath a root complex - */ - if (child_range_add(mod, ntn, PCIEX_BUS, 0, MAX_HB_BUSES) < 0) { - topo_node_range_destroy(ntn, PCIEX_BUS); - return (NULL); - } - return (ntn); -} - -/*ARGSUSED*/ -static int -specific_hb_enum(tnode_t *pn, const char *name, topo_instance_t imin, - topo_instance_t imax, di_prom_handle_t promtree, topo_mod_t *mod) -{ - tnode_t *hb; - did_t *iodid, *didp; - did_hash_t *didhash; - char *pname; - int brc = 0; - int bus; - - pname = topo_node_name(pn); - if ((iodid = topo_node_private(pn)) == NULL) { - topo_mod_dprintf(mod, - "Parent %s node missing private data.\n" - "Unable to proceed with %s enumeration.\n", - pname, name); - return (-1); - } - didhash = did_hash(iodid); - - /* - * Find the hostbridge of interest - */ - didp = iodid; - for (brc = 0; brc < imin; brc++) - didp = did_chain_get(didp); - assert(didp != NULL); - - if ((hb = pcihostbridge_declare(pn, did_dinode(didp), imin, didhash, - promtree, mod)) == NULL) - return (-1); - while (didp != NULL) { - did_BDF(didp, &bus, NULL, NULL); - if (topo_mod_enumerate(mod, - hb, PCI_BUS, PCI_BUS, bus, bus) != 0) - return (topo_mod_seterrno(mod, EMOD_PARTIAL_ENUM)); - didp = did_link_get(didp); - } - return (0); -} diff --git a/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c b/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c new file mode 100644 index 0000000000..2ff4c768c1 --- /dev/null +++ b/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c @@ -0,0 +1,357 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <string.h> +#include <fm/topo_mod.h> +#include <fm/topo_hc.h> +#include <libdevinfo.h> +#include <limits.h> +#include <sys/fm/protocol.h> +#include <sys/param.h> +#include <sys/systeminfo.h> +#include <assert.h> + +#include <hostbridge.h> +#include <pcibus.h> +#include <did.h> +#include <did_props.h> +#include <util.h> + +/* + * hostbridge.c + * Generic code shared by all the hostbridge enumerators + */ +static void hb_release(topo_mod_t *, tnode_t *); +static int hb_label(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, + nvlist_t **); +static int hb_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t, + topo_instance_t, void *, void *); + +extern int platform_hb_label(topo_mod_t *, tnode_t *, nvlist_t *, nvlist_t **); +extern int platform_hb_enum(topo_mod_t *, tnode_t *, + const char *, topo_instance_t, topo_instance_t); + +extern txprop_t ExHB_common_props[]; +extern txprop_t HB_common_props[]; +extern txprop_t RC_common_props[]; +extern int ExHB_propcnt; +extern int HB_propcnt; +extern int RC_propcnt; + +static int specific_hb_enum(topo_mod_t *, tnode_t *, const char *, + topo_instance_t, topo_instance_t, void *); + +static const topo_modops_t Hb_ops = + { hb_enum, hb_release }; +static const topo_modinfo_t Hb_info = + { HOSTBRIDGE, FM_FMRI_SCHEME_HC, HB_ENUMR_VERS, &Hb_ops }; + +static const topo_method_t Hb_methods[] = { + { TOPO_METH_LABEL, TOPO_METH_LABEL_DESC, + TOPO_METH_LABEL_VERSION, TOPO_STABILITY_INTERNAL, hb_label }, + { NULL } +}; + +static const topo_pgroup_info_t hb_auth_pgroup = { + FM_FMRI_AUTHORITY, + TOPO_STABILITY_PRIVATE, + TOPO_STABILITY_PRIVATE, + 1 +}; + +int +_topo_init(topo_mod_t *modhdl, topo_version_t version) +{ + /* + * Turn on module debugging output + */ + if (getenv("TOPOHBDBG") != NULL) + topo_mod_setdebug(modhdl); + topo_mod_dprintf(modhdl, "initializing hostbridge enumerator\n"); + + if (version != HB_ENUMR_VERS) + return (topo_mod_seterrno(modhdl, EMOD_VER_NEW)); + + if (topo_mod_register(modhdl, &Hb_info, TOPO_VERSION) < 0) { + topo_mod_dprintf(modhdl, "hostbridge registration failed: %s\n", + topo_mod_errmsg(modhdl)); + return (-1); /* mod errno already set */ + } + + topo_mod_dprintf(modhdl, "Hostbridge enumr initd\n"); + + return (0); +} + +void +_topo_fini(topo_mod_t *modhdl) +{ + topo_mod_unregister(modhdl); +} + +static int +hb_label(topo_mod_t *mp, tnode_t *node, topo_version_t version, + nvlist_t *in, nvlist_t **out) +{ + if (version > TOPO_METH_LABEL_VERSION) + return (topo_mod_seterrno(mp, EMOD_VER_NEW)); + return (platform_hb_label(mp, node, in, out)); +} + +static topo_mod_t * +pci_enumr_load(topo_mod_t *mp) +{ + topo_mod_t *rp = NULL; + + if ((rp = topo_mod_load(mp, PCI_ENUM, PCI_ENUMR_VERS)) == NULL) { + topo_mod_dprintf(mp, + "%s enumerator could not load %s.\n", HOSTBRIDGE, PCI_ENUM); + } + return (rp); +} + +/*ARGSUSED*/ +static int +hb_enum(topo_mod_t *mp, tnode_t *pn, const char *name, topo_instance_t imin, + topo_instance_t imax, void *notused, void *data) +{ + topo_mod_t *pcimod; + + if (strcmp(name, HOSTBRIDGE) != 0) { + topo_mod_dprintf(mp, + "Currently only know how to enumerate %s components.\n", + HOSTBRIDGE); + return (0); + } + /* + * Load the pcibus enumerator + */ + if ((pcimod = pci_enumr_load(mp)) == NULL) + return (-1); + + /* + * If we're asked to enumerate a whole range of hostbridges, then + * we need to find them all. If we're just asked to enumerate a + * single hostbridge, we expect our caller to have passed us linked + * did_t structures we can use to enumerate the singled out hostbridge. + */ + if (imin != imax) { + int rv; + + if (did_hash_init(mp) < 0) { + topo_mod_dprintf(mp, + "Hash initialization for hostbridge " + "enumerator failed.\n"); + topo_mod_unload(pcimod); + return (-1); + } + if ((rv = platform_hb_enum(mp, pn, name, imin, imax)) < 0) + topo_mod_seterrno(mp, EMOD_PARTIAL_ENUM); + did_hash_fini(mp); + return (rv); + } else { + return (specific_hb_enum(mp, pn, name, imin, imax, + data)); + } +} + +/*ARGSUSED*/ +static void +hb_release(topo_mod_t *mp, tnode_t *node) +{ + topo_method_unregister_all(mp, node); + + /* + * node private data (did_t) for this node is destroyed in + * did_hash_destroy() + */ + +} + +static tnode_t * +hb_tnode_create(topo_mod_t *mod, tnode_t *parent, + const char *name, topo_instance_t i, void *priv) +{ + int err; + nvlist_t *fmri; + tnode_t *ntn; + nvlist_t *auth = topo_mod_auth(mod, parent); + + fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, + NULL, auth, NULL, NULL, NULL); + nvlist_free(auth); + if (fmri == NULL) { + topo_mod_dprintf(mod, + "Unable to make nvlist for %s bind: %s.\n", + name, topo_mod_errmsg(mod)); + return (NULL); + } + + ntn = topo_node_bind(mod, parent, name, i, fmri); + if (ntn == NULL) { + topo_mod_dprintf(mod, + "topo_node_bind (%s%d/%s%d) failed: %s\n", + topo_node_name(parent), topo_node_instance(parent), + name, i, + topo_strerror(topo_mod_errno(mod))); + nvlist_free(fmri); + return (NULL); + } + nvlist_free(fmri); + topo_node_setspecific(ntn, priv); + + if (topo_pgroup_create(ntn, &hb_auth_pgroup, &err) == 0) { + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_CHASSIS, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_SERVER, &err); + } + + if (topo_method_register(mod, ntn, Hb_methods) < 0) { + topo_mod_dprintf(mod, "topo_method_register failed: %s\n", + topo_strerror(topo_mod_errno(mod))); + topo_node_unbind(ntn); + return (NULL); + } + return (ntn); +} + +tnode_t * +pcihostbridge_declare(topo_mod_t *mod, tnode_t *parent, di_node_t din, + topo_instance_t i) +{ + did_t *pd; + tnode_t *ntn; + + if ((pd = did_find(mod, din)) == NULL) + return (NULL); + if ((ntn = hb_tnode_create(mod, parent, HOSTBRIDGE, i, din)) == NULL) + return (NULL); + if (did_props_set(ntn, pd, HB_common_props, HB_propcnt) < 0) { + topo_node_unbind(ntn); + return (NULL); + } + /* + * We expect to find pci buses beneath the hostbridge. + */ + if (child_range_add(mod, ntn, PCI_BUS, 0, MAX_HB_BUSES) < 0) { + topo_node_unbind(ntn); + return (NULL); + } + return (ntn); +} + +tnode_t * +pciexhostbridge_declare(topo_mod_t *mod, tnode_t *parent, di_node_t din, + topo_instance_t hi) +{ + did_t *pd; + tnode_t *ntn; + + if ((pd = did_find(mod, din)) == NULL) + return (NULL); + if ((ntn = hb_tnode_create(mod, parent, HOSTBRIDGE, hi, din)) == NULL) + return (NULL); + if (did_props_set(ntn, pd, ExHB_common_props, ExHB_propcnt) < 0) { + topo_node_unbind(ntn); + return (NULL); + } + /* + * We expect to find root complexes beneath the hostbridge. + */ + if (child_range_add(mod, ntn, PCIEX_ROOT, 0, MAX_HB_BUSES) < 0) { + topo_node_unbind(ntn); + return (NULL); + } + return (ntn); +} + +tnode_t * +pciexrc_declare(topo_mod_t *mod, tnode_t *parent, di_node_t din, + topo_instance_t ri) +{ + did_t *pd; + tnode_t *ntn; + + if ((pd = did_find(mod, din)) == NULL) + return (NULL); + did_markrc(pd); + if ((ntn = hb_tnode_create(mod, parent, PCIEX_ROOT, ri, din)) == NULL) + return (NULL); + if (did_props_set(ntn, pd, RC_common_props, RC_propcnt) < 0) { + topo_node_unbind(ntn); + return (NULL); + } + /* + * We expect to find pci-express buses beneath a root complex + */ + if (child_range_add(mod, ntn, PCIEX_BUS, 0, MAX_HB_BUSES) < 0) { + topo_node_range_destroy(ntn, PCIEX_BUS); + return (NULL); + } + return (ntn); +} + +/*ARGSUSED*/ +static int +specific_hb_enum(topo_mod_t *mod, tnode_t *pn, const char *name, + topo_instance_t imin, topo_instance_t imax, void *priv) +{ + tnode_t *hb; + did_t *iodid = (did_t *)priv; + did_t *didp; + int brc = 0; + int bus; + + did_setspecific(mod, priv); + + /* + * Find the hostbridge of interest + */ + didp = iodid; + for (brc = 0; brc < imin; brc++) + didp = did_chain_get(didp); + assert(didp != NULL); + + if ((hb = pcihostbridge_declare(mod, pn, did_dinode(didp), imin)) + == NULL) { + return (-1); + } + while (didp != NULL) { + did_BDF(didp, &bus, NULL, NULL); + if (topo_mod_enumerate(mod, + hb, PCI_BUS, PCI_BUS, bus, bus, didp) != 0) { + return (topo_mod_seterrno(mod, EMOD_PARTIAL_ENUM)); + } + didp = did_link_get(didp); + } + + return (0); +} diff --git a/usr/src/lib/fm/topo/modules/common/hostbridge.h b/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.h index 039ad359ea..ee76315446 100644 --- a/usr/src/lib/fm/topo/modules/common/hostbridge.h +++ b/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.h @@ -30,7 +30,6 @@ #pragma ident "%Z%%M% %I% %E% SMI" #include <libdevinfo.h> -#include "did.h" #ifdef __cplusplus extern "C" { @@ -38,22 +37,18 @@ extern "C" { #define HB_ENUMR_VERS 1 -#define PATH_TO_HB_ENUM "%s/usr/platform/%s/lib/fm/topo/plugins/hostbridge.so" - -#define HOSTBRIDGE "hostbridge" - #define MAX_HBS 255 /* * Solaris Drivers for hostbridge ASICs. */ -#define SCHIZO "pcisch" -#define PSYCHO "pcipsy" -#define NPE "npe" -#define PCIE_PCI "pcie_pci" -#define PCI_PCI "pci_pci" -#define PCI "pci" -#define PX "px" +#define SCHIZO "pcisch" +#define PSYCHO "pcipsy" +#define NPE "npe" +#define PCIE_PCI "pcie_pci" +#define PCI_PCI "pci_pci" +#define PCI "pci" +#define PX "px" /* * These #defines are special values of bus and root complex instance @@ -70,19 +65,12 @@ extern "C" { */ #define TO_PCI (1000) -struct did_hash; - -extern tnode_t *pcihostbridge_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pciexhostbridge_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pciexrc_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); - -extern int platform_hb_label(tnode_t *, nvlist_t *, nvlist_t **, topo_mod_t *); -extern int platform_hb_enum(tnode_t *, - const char *, topo_instance_t, topo_instance_t, did_hash_t *, - di_prom_handle_t, topo_mod_t *); +extern tnode_t *pcihostbridge_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pciexhostbridge_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pciexrc_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/common/did.c b/usr/src/lib/fm/topo/modules/common/pcibus/did.c index 1dc42eab66..e57d84a4a4 100644 --- a/usr/src/lib/fm/topo/modules/common/did.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did.c @@ -40,16 +40,16 @@ #include <string.h> #include <strings.h> #include <sys/types.h> -#include <libtopo.h> +#include <fm/topo_mod.h> #include <libnvpair.h> #include <libdevinfo.h> #include <sys/pcie.h> -#include "topo_mod.h" -#include "hostbridge.h" -#include "pcibus.h" +#include <hostbridge.h> +#include <pcibus.h> +#include <did_props.h> + #include "did_impl.h" -#include "did_props.h" static void slotnm_destroy(slotnm_t *); @@ -115,15 +115,14 @@ slotnm_cp(did_t *from, did_t *to, int *nslots) static int di_physlotinfo_get(topo_mod_t *mp, di_node_t src, uint_t excap, - int *slotnum, char **slotnm, di_prom_handle_t promtree) + int *slotnum, char **slotnm) { char *slotbuf; int sz; uchar_t *buf; *slotnum = -1; - (void) di_uintprop_get(src, DI_PHYSPROP, (uint_t *)slotnum, - promtree); + (void) di_uintprop_get(mp, src, DI_PHYSPROP, (uint_t *)slotnum); /* * If no physical slot number property was found, then the * capabilities register may indicate the pci-express device @@ -132,8 +131,7 @@ di_physlotinfo_get(topo_mod_t *mp, di_node_t src, uint_t excap, if (*slotnum == -1 && (excap & PCIE_PCIECAP_SLOT_IMPL) != 0) { uint_t slotcap; int e; - e = di_uintprop_get(src, "pcie-slotcap-reg", &slotcap, - promtree); + e = di_uintprop_get(mp, src, "pcie-slotcap-reg", &slotcap); if (e == 0) *slotnum = slotcap >> PCIE_SLOTCAP_PHY_SLOT_NUM_SHIFT; } @@ -145,7 +143,7 @@ di_physlotinfo_get(topo_mod_t *mp, di_node_t src, uint_t excap, * a slot-names property, and if it exists, ignore the slotmask value * and use the string as the label. */ - if (di_bytes_get(src, DI_SLOTPROP, &sz, &buf, promtree) == 0 && + if (di_bytes_get(mp, src, DI_SLOTPROP, &sz, &buf) == 0 && sz > 4) { slotbuf = (char *)&buf[4]; } else { @@ -163,8 +161,7 @@ di_physlotinfo_get(topo_mod_t *mp, di_node_t src, uint_t excap, } static int -di_slotinfo_get(topo_mod_t *mp, di_node_t src, int *nslots, slotnm_t **slots, - di_prom_handle_t promtree) +di_slotinfo_get(topo_mod_t *mp, di_node_t src, int *nslots, slotnm_t **slots) { slotnm_t *lastslot = NULL; slotnm_t *newslot; @@ -176,7 +173,7 @@ di_slotinfo_get(topo_mod_t *mp, di_node_t src, int *nslots, slotnm_t **slots, *slots = NULL; *nslots = 0; - if (di_bytes_get(src, DI_SLOTPROP, &sz, &slotbuf, promtree) < 0) + if (di_bytes_get(mp, src, DI_SLOTPROP, &sz, &slotbuf) < 0) return (0); if (sz < sizeof (uint_t)) return (0); @@ -214,26 +211,16 @@ did_physslot(did_t *did) return (did->dp_physlot); } - -did_hash_t * -did_hash(did_t *did) -{ - assert(did != NULL); - return (did->dp_hash); -} - did_t * -did_create(did_hash_t *dhash, di_node_t src, - int ibrd, int ibrdge, int irc, int ibus, di_prom_handle_t promtree) +did_create(topo_mod_t *mp, di_node_t src, + int ibrd, int ibrdge, int irc, int ibus) { - topo_mod_t *mp; did_t *np; did_t *pd; uint_t code; uint_t reg; - mp = dhash->dph_mod; - if ((pd = did_hash_lookup(dhash, src)) != NULL) { + if ((pd = did_hash_lookup(mp, src)) != NULL) { topo_mod_dprintf(mp, "Attempt to create existing did_t.\n"); assert(ibus == TRUST_BDF || (pd->dp_bus == ibus)); return (pd); @@ -243,13 +230,13 @@ did_create(did_hash_t *dhash, di_node_t src, return (NULL); np->dp_mod = mp; np->dp_src = src; - np->dp_hash = dhash; + np->dp_hash = (did_hash_t *)topo_mod_getspecific(mp); /* * We must have a reg prop and from it we extract the bus #, * device #, and function #. */ - if (di_uintprop_get(src, DI_REGPROP, ®, promtree) < 0) { + if (di_uintprop_get(mp, src, DI_REGPROP, ®) < 0) { topo_mod_free(mp, np, sizeof (did_t)); return (NULL); } @@ -268,7 +255,7 @@ did_create(did_hash_t *dhash, di_node_t src, * There *may* be a class code we can capture. If there wasn't * one, capture that fact by setting the class value to -1. */ - if (di_uintprop_get(src, DI_CCPROP, &code, promtree) == 0) { + if (di_uintprop_get(mp, src, DI_CCPROP, &code) == 0) { np->dp_class = GETCLASS(code); np->dp_subclass = GETSUBCLASS(code); } else { @@ -279,28 +266,25 @@ did_create(did_hash_t *dhash, di_node_t src, * If there wasn't one, the capabilities will be the out-of-bounds * value of zero. */ - (void) di_uintprop_get(src, "pcie-capid-reg", &np->dp_excap, - promtree); + (void) di_uintprop_get(mp, src, "pcie-capid-reg", &np->dp_excap); /* * There *may* be a physical slot number property we can capture. */ if (di_physlotinfo_get(mp, - src, np->dp_excap, &np->dp_physlot, &np->dp_physlot_label, - promtree) < 0) { + src, np->dp_excap, &np->dp_physlot, &np->dp_physlot_label) < 0) { topo_mod_free(mp, np, sizeof (did_t)); return (NULL); } /* * There *may* be PCI slot info we can capture */ - if (di_slotinfo_get(mp, src, &np->dp_nslots, &np->dp_slotnames, - promtree) < 0) { + if (di_slotinfo_get(mp, src, &np->dp_nslots, &np->dp_slotnames) < 0) { if (np->dp_physlot_label != NULL) topo_mod_strfree(mp, np->dp_physlot_label); topo_mod_free(mp, np, sizeof (did_t)); return (NULL); } - did_hash_insert(dhash, src, np); + did_hash_insert(mp, src, np); did_hold(np); return (np); } @@ -320,12 +304,12 @@ did_chain_get(did_t *dp) } void -did_link_set(tnode_t *head, did_t *tail) +did_link_set(topo_mod_t *mod, tnode_t *head, did_t *tail) { did_t *hd, *pd; assert(head != NULL); - pd = hd = topo_node_private(head); + pd = hd = did_find(mod, topo_node_getspecific(head)); assert(hd != NULL); while ((hd = did_link_get(hd)) != NULL) pd = hd; @@ -474,17 +458,17 @@ did_label(did_t *dp, int dev) } did_t * -did_find(did_hash_t *dhash, di_node_t dn) +did_find(topo_mod_t *mp, di_node_t dn) { - return (did_hash_lookup(dhash, dn)); + return (did_hash_lookup(mp, dn)); } int -pci_BDF_get(did_hash_t *dhash, di_node_t dn, int *bus, int *dev, int *fn) +pci_BDF_get(topo_mod_t *mp, di_node_t dn, int *bus, int *dev, int *fn) { did_t *dp; - if ((dp = did_find(dhash, dn)) == NULL) + if ((dp = did_find(mp, dn)) == NULL) return (-1); *bus = dp->dp_bus; *dev = dp->dp_dev; @@ -494,12 +478,11 @@ pci_BDF_get(did_hash_t *dhash, di_node_t dn, int *bus, int *dev, int *fn) } int -pci_classcode_get(did_hash_t *dhash, - di_node_t dn, uint_t *class, uint_t *sub) +pci_classcode_get(topo_mod_t *mp, di_node_t dn, uint_t *class, uint_t *sub) { did_t *dp; - if ((dp = did_find(dhash, dn)) == NULL) + if ((dp = did_find(mp, dn)) == NULL) return (-1); if (dp->dp_class < 0) { did_rele(dp); @@ -512,11 +495,11 @@ pci_classcode_get(did_hash_t *dhash, } int -pciex_cap_get(did_hash_t *dhash, di_node_t dn) +pciex_cap_get(topo_mod_t *mp, di_node_t dn) { did_t *dp; - if ((dp = did_find(dhash, dn)) == NULL) + if ((dp = did_find(mp, dn)) == NULL) return (-1); did_rele(dp); return (dp->dp_excap); @@ -552,3 +535,12 @@ did_inherit(did_t *pdp, did_t *dp) return (-1); return (0); } + +void +did_setspecific(topo_mod_t *mp, void *data) +{ + did_t *hbdid; + + hbdid = (did_t *)data; + topo_mod_setspecific(mp, hbdid->dp_hash); +} diff --git a/usr/src/lib/fm/topo/modules/common/did.h b/usr/src/lib/fm/topo/modules/common/pcibus/did.h index 9a0342dcc0..ceddd3a32b 100644 --- a/usr/src/lib/fm/topo/modules/common/did.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did.h @@ -33,12 +33,23 @@ #include <fm/topo_mod.h> #include <libdevinfo.h> #include <libnvpair.h> -#include "did_impl.h" #ifdef __cplusplus extern "C" { #endif +typedef struct did did_t; + +extern did_t *did_create(topo_mod_t *, di_node_t, int, int, int, + int); +extern did_t *did_find(topo_mod_t *, di_node_t); +extern did_t *did_hash_lookup(topo_mod_t *, di_node_t); +extern void did_hash_insert(topo_mod_t *, di_node_t, did_t *); +extern void did_hash_fini(topo_mod_t *); +extern int did_hash_init(topo_mod_t *); +extern void did_link_set(topo_mod_t *, tnode_t *, did_t *); +extern void did_setspecific(topo_mod_t *, void *); + extern topo_mod_t *did_mod(did_t *); extern di_node_t did_dinode(did_t *); extern void did_BDF(did_t *, int *, int *, int *); @@ -51,21 +62,14 @@ extern int did_physslot(did_t *); extern int did_inherit(did_t *, did_t *); extern int did_excap(did_t *); extern int did_bdf(did_t *); - -extern did_t *did_create(did_hash_t *, di_node_t, int, int, int, int, - di_prom_handle_t); -extern did_t *did_find(did_hash_t *, di_node_t); extern did_t *did_link_get(did_t *); extern did_t *did_chain_get(did_t *); extern void did_destroy(did_t *); -extern did_hash_t *did_hash(did_t *); -extern void did_hash_fini(did_hash_t *); extern void did_hold(did_t *); -extern void did_link_set(tnode_t *, did_t *); extern void did_did_link_set(did_t *, did_t *); extern void did_did_chain_set(did_t *, did_t *); extern void did_rele(did_t *); -extern did_hash_t *did_hash_init(topo_mod_t *); + #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/common/did_hash.c b/usr/src/lib/fm/topo/modules/common/pcibus/did_hash.c index ca0596a18f..f8a43ab884 100644 --- a/usr/src/lib/fm/topo/modules/common/did_hash.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did_hash.c @@ -31,21 +31,35 @@ #include <assert.h> #include <sys/types.h> #include <libdevinfo.h> -#include <topo_mod.h> +#include <fm/topo_mod.h> +#include <pcibus.h> +#include <did.h> -#include "pcibus.h" #include "did_impl.h" #include "did_props.h" -did_hash_t * +static did_hash_t *did_hash_create(topo_mod_t *); +static void did_hash_destroy(did_hash_t *); + +int did_hash_init(topo_mod_t *hdl) { - return (did_hash_create(hdl)); + did_hash_t *dh = did_hash_create(hdl); + + if (dh != NULL) { + topo_mod_setspecific(hdl, (void *) dh); + return (0); + } else { + return (-1); + } } void -did_hash_fini(did_hash_t *dh) +did_hash_fini(topo_mod_t *mod) { + did_hash_t *dh = (did_hash_t *)topo_mod_getspecific(mod); + + topo_mod_setspecific(mod, NULL); if (dh == NULL) return; did_hash_destroy(dh); @@ -71,7 +85,7 @@ did_dnhash(di_node_t key) return (keyn / key_divisor); } -did_hash_t * +static did_hash_t * did_hash_create(topo_mod_t *hdl) { did_hash_t *r = topo_mod_zalloc(hdl, sizeof (did_hash_t)); @@ -92,7 +106,7 @@ did_hash_create(topo_mod_t *hdl) return (r); } -void +static void did_hash_destroy(did_hash_t *ht) { did_t *e, *n; @@ -113,8 +127,9 @@ did_hash_destroy(did_hash_t *ht) } void -did_hash_insert(did_hash_t *tab, di_node_t key, did_t *new) +did_hash_insert(topo_mod_t *mp, di_node_t key, did_t *new) { + did_hash_t *tab = (did_hash_t *)topo_mod_getspecific(mp); did_t *assertchk; int idx = did_dnhash(key) % tab->dph_hashlen; @@ -139,9 +154,10 @@ did_hash_insert(did_hash_t *tab, di_node_t key, did_t *new) } did_t * -did_hash_lookup(did_hash_t *tab, di_node_t key) +did_hash_lookup(topo_mod_t *mp, di_node_t key) { did_t *e; + did_hash_t *tab = (did_hash_t *)topo_mod_getspecific(mp); int idx = did_dnhash(key) % tab->dph_hashlen; e = tab->dph_hash[idx]; diff --git a/usr/src/lib/fm/topo/modules/common/did_impl.h b/usr/src/lib/fm/topo/modules/common/pcibus/did_impl.h index 3a27641353..4f97b9a28a 100644 --- a/usr/src/lib/fm/topo/modules/common/did_impl.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did_impl.h @@ -33,6 +33,7 @@ #include <fm/libtopo.h> #include <libdevinfo.h> #include <libnvpair.h> +#include <did.h> #ifdef __cplusplus extern "C" { @@ -40,8 +41,6 @@ extern "C" { #define REC_HASHLEN 253 -struct did_hash; - /* * Slot name info is attached to devinfo nodes, compressed inside of * a "slot-names" property. When we dig this out we store each name @@ -54,6 +53,8 @@ typedef struct slotnm { char *snm_label; /* label describing the slot */ } slotnm_t; +typedef struct did_hash did_hash_t; + /* * Private data stored with a tnode_t. We collect slot-name info from * di_nodes that describe buses, but then don't use it until we get to @@ -61,11 +62,11 @@ typedef struct slotnm { * this struct to pass around bus, dev, function info so that doesn't * have to be re-computed. */ -typedef struct did { +struct did { struct did *dp_next; /* for chaining in a hash bucket */ struct did *dp_link; /* for chaining to related did_t */ struct did *dp_chain; /* for chaining to another chain of did_ts */ - struct did_hash *dp_hash; /* the hash table where we reside */ + did_hash_t *dp_hash; /* the hash table where we reside */ topo_mod_t *dp_mod; /* module that allocated the did private data */ di_node_t dp_src; /* di_node_t from which the info was derived */ int dp_refcnt; /* multiple nodes allowed to point at a did_t */ @@ -88,25 +89,14 @@ typedef struct did { */ int dp_nslots; /* number of slots actually described */ slotnm_t *dp_slotnames; /* the slot names as labels */ -} did_t; +}; -typedef struct did_hash { +struct did_hash { did_t **dph_hash; /* hash bucket array */ uint_t dph_hashlen; /* size of hash bucket array */ uint_t dph_nelems; /* number of elements in the hash */ topo_mod_t *dph_mod; /* module that allocated the hash table */ -} did_hash_t; - -extern did_hash_t *did_hash_create(topo_mod_t *); -extern did_t *did_hash_lookup(did_hash_t *, di_node_t); -extern void did_hash_destroy(did_hash_t *); -extern void did_hash_insert(did_hash_t *, di_node_t, did_t *); - -extern did_t *did_create(did_hash_t *, di_node_t, int, int, int, int, - di_prom_handle_t); -extern void did_destroy(did_t *); -extern void did_hold(did_t *); -extern void did_rele(did_t *); +}; #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/common/did_props.c b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.c index 3830de2e63..4d06535268 100644 --- a/usr/src/lib/fm/topo/modules/common/did_props.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.c @@ -36,32 +36,32 @@ #include <sys/pcie.h> #include <sys/fm/protocol.h> #include <fm/topo_mod.h> +#include <fm/topo_hc.h> #include <libdevinfo.h> -#include <topo_error.h> -#include "hostbridge.h" -#include "pcibus.h" -#include "did.h" -#include "did_props.h" +#include <hostbridge.h> +#include <pcibus.h> +#include <did.h> +#include <did_props.h> static int ASRU_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int FRU_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int DEVprop_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int DRIVERprop_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int EXCAP_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int BDF_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int label_set(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int maybe_di_chars_copy(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); static int maybe_di_uint_to_str(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); /* * Arrays of "property translation routines" to set the properties a @@ -74,99 +74,74 @@ static int maybe_di_uint_to_str(tnode_t *, did_t *, * */ +static const topo_pgroup_info_t io_pgroup = + { TOPO_PGROUP_IO, TOPO_STABILITY_PRIVATE, TOPO_STABILITY_PRIVATE, 1 }; +static const topo_pgroup_info_t pci_pgroup = + { TOPO_PGROUP_PCI, TOPO_STABILITY_PRIVATE, TOPO_STABILITY_PRIVATE, 1 }; + +static const topo_pgroup_info_t protocol_pgroup = { + TOPO_PGROUP_PROTOCOL, + TOPO_STABILITY_PRIVATE, + TOPO_STABILITY_PRIVATE, + 1 +}; /* Request to create protocol will be ignored by libtopo */ + txprop_t Fn_common_props[] = { - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DEV, - TOPO_STABILITY_PRIVATE, DEVprop_set }, - { DI_DEVTYPPROP, TOPO_PGROUP_IO, TOPO_PROP_DEVTYPE, - TOPO_STABILITY_PRIVATE, maybe_di_chars_copy }, - { DI_DEVIDPROP, TOPO_PGROUP_PCI, TOPO_PROP_DEVID, - TOPO_STABILITY_PRIVATE, maybe_di_uint_to_str }, - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DRIVER, - TOPO_STABILITY_PRIVATE, DRIVERprop_set }, - { NULL, TOPO_PGROUP_PCI, TOPO_PROP_EXCAP, - TOPO_STABILITY_PRIVATE, EXCAP_set }, - { DI_CLASSPROP, TOPO_PGROUP_PCI, TOPO_PROP_CLASS, - TOPO_STABILITY_PRIVATE, maybe_di_uint_to_str }, - { DI_VENDIDPROP, TOPO_PGROUP_PCI, TOPO_PROP_VENDID, - TOPO_STABILITY_PRIVATE, maybe_di_uint_to_str }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { NULL, &io_pgroup, TOPO_IO_DEV, DEVprop_set }, + { DI_DEVTYPPROP, &io_pgroup, TOPO_IO_DEVTYPE, maybe_di_chars_copy }, + { DI_DEVIDPROP, &pci_pgroup, TOPO_PCI_DEVID, maybe_di_uint_to_str }, + { NULL, &io_pgroup, TOPO_IO_DRIVER, DRIVERprop_set }, + { NULL, &pci_pgroup, TOPO_PCI_EXCAP, EXCAP_set }, + { DI_CLASSPROP, &pci_pgroup, TOPO_PCI_CLASS, maybe_di_uint_to_str }, + { DI_VENDIDPROP, &pci_pgroup, TOPO_PCI_VENDID, maybe_di_uint_to_str }, + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; txprop_t Dev_common_props[] = { - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; txprop_t Bus_common_props[] = { - { DI_DEVTYPPROP, TOPO_PGROUP_IO, TOPO_PROP_DEVTYPE, - TOPO_STABILITY_PRIVATE, maybe_di_chars_copy }, - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DRIVER, - TOPO_STABILITY_PRIVATE, DRIVERprop_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { DI_DEVTYPPROP, &io_pgroup, TOPO_IO_DEVTYPE, maybe_di_chars_copy }, + { NULL, &io_pgroup, TOPO_IO_DRIVER, DRIVERprop_set }, + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; txprop_t RC_common_props[] = { - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DEV, - TOPO_STABILITY_PRIVATE, DEVprop_set }, - { DI_DEVTYPPROP, TOPO_PGROUP_IO, TOPO_PROP_DEVTYPE, - TOPO_STABILITY_PRIVATE, maybe_di_chars_copy }, - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DRIVER, - TOPO_STABILITY_PRIVATE, DRIVERprop_set }, - { NULL, TOPO_PGROUP_PCI, TOPO_PROP_EXCAP, - TOPO_STABILITY_PRIVATE, EXCAP_set }, - { NULL, TOPO_PGROUP_PCI, TOPO_PROP_BDF, - TOPO_STABILITY_PRIVATE, BDF_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { NULL, &io_pgroup, TOPO_IO_DEV, DEVprop_set }, + { DI_DEVTYPPROP, &io_pgroup, TOPO_IO_DEVTYPE, maybe_di_chars_copy }, + { NULL, &io_pgroup, TOPO_IO_DRIVER, DRIVERprop_set }, + { NULL, &pci_pgroup, TOPO_PCI_EXCAP, EXCAP_set }, + { NULL, &pci_pgroup, TOPO_PCI_BDF, BDF_set }, + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; txprop_t ExHB_common_props[] = { - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; txprop_t IOB_common_props[] = { - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; txprop_t HB_common_props[] = { - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DEV, - TOPO_STABILITY_PRIVATE, DEVprop_set }, - { NULL, TOPO_PGROUP_IO, TOPO_PROP_DRIVER, - TOPO_STABILITY_PRIVATE, DRIVERprop_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, - TOPO_STABILITY_PRIVATE, label_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU, - TOPO_STABILITY_PRIVATE, FRU_set }, - { NULL, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU, - TOPO_STABILITY_PRIVATE, ASRU_set } + { NULL, &io_pgroup, TOPO_IO_DEV, DEVprop_set }, + { NULL, &io_pgroup, TOPO_IO_DRIVER, DRIVERprop_set }, + { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, + { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } }; int Bus_propcnt = sizeof (Bus_common_props) / sizeof (txprop_t); @@ -187,13 +162,16 @@ int Fn_propcnt = sizeof (Fn_common_props) / sizeof (txprop_t); * gets updated with the property value and we return 0. */ static int -promprop2uint(di_node_t n, const char *propnm, uint_t *val, - di_prom_handle_t promtree) +promprop2uint(topo_mod_t *mod, di_node_t n, const char *propnm, uint_t *val) { + di_prom_handle_t ptp = DI_PROM_HANDLE_NIL; di_prom_prop_t pp = DI_PROM_PROP_NIL; uchar_t *buf; - while ((pp = di_prom_prop_next(promtree, n, pp)) != DI_PROM_PROP_NIL) { + if ((ptp = topo_mod_prominfo(mod)) == DI_PROM_HANDLE_NIL) + return (-1); + + while ((pp = di_prom_prop_next(ptp, n, pp)) != DI_PROM_PROP_NIL) { if (strcmp(di_prom_prop_name(pp), propnm) == 0) { if (di_prom_prop_data(pp, &buf) < sizeof (uint_t)) continue; @@ -232,22 +210,25 @@ hwprop2uint(di_node_t n, const char *propnm, uint_t *val) } int -di_uintprop_get(di_node_t n, const char *pnm, uint_t *pv, - di_prom_handle_t promtree) +di_uintprop_get(topo_mod_t *mod, di_node_t n, const char *pnm, uint_t *pv) { if (hwprop2uint(n, pnm, pv) < 0) - if (promprop2uint(n, pnm, pv, promtree) < 0) + if (promprop2uint(mod, n, pnm, pv) < 0) return (-1); return (0); } int -di_bytes_get(di_node_t n, const char *pnm, int *sz, uchar_t **db, - di_prom_handle_t promtree) +di_bytes_get(topo_mod_t *mod, di_node_t n, const char *pnm, int *sz, + uchar_t **db) { + di_prom_handle_t ptp = DI_PROM_HANDLE_NIL; di_prom_prop_t pp = DI_PROM_PROP_NIL; di_prop_t hp = DI_PROP_NIL; + if ((ptp = topo_mod_prominfo(mod)) == DI_PROM_HANDLE_NIL) + return (-1); + *sz = -1; while ((hp = di_prop_next(n, hp)) != DI_PROP_NIL) { if (strcmp(di_prop_name(hp), pnm) == 0) { @@ -257,7 +238,7 @@ di_bytes_get(di_node_t n, const char *pnm, int *sz, uchar_t **db, } } if (*sz < 0) { - while ((pp = di_prom_prop_next(promtree, n, pp)) != + while ((pp = di_prom_prop_next(ptp, n, pp)) != DI_PROM_PROP_NIL) { if (strcmp(di_prom_prop_name(pp), pnm) == 0) { *sz = di_prom_prop_data(pp, db); @@ -267,6 +248,7 @@ di_bytes_get(di_node_t n, const char *pnm, int *sz, uchar_t **db, } } } + if (*sz < 0) return (-1); return (0); @@ -361,12 +343,10 @@ dev_for_hostbridge(topo_mod_t *mp, char *path) /*ARGSUSED*/ static int ASRU_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { topo_mod_t *mp; - topo_hdl_t *hp; - nvlist_t *fmri, *in; + nvlist_t *fmri; char *dnpath, *path, *fpath, *nm; int d, e, f; @@ -378,7 +358,6 @@ ASRU_set(tnode_t *tn, did_t *pd, * isn't a function, inherit any ASRU from the parent. */ mp = did_mod(pd); - hp = topo_mod_handle(mp); nm = topo_node_name(tn); if (strcmp(nm, PCI_FUNCTION) == 0 || strcmp(nm, PCIEX_FUNCTION) == 0 || strcmp(nm, PCIEX_ROOT) == 0) { @@ -397,24 +376,13 @@ ASRU_set(tnode_t *tn, did_t *pd, if ((fpath = dev_path_fix(mp, path, d, f)) == NULL) return (topo_mod_seterrno(mp, EMOD_NOMEM)); - if (topo_mod_nvalloc(mp, &in, NV_UNIQUE_NAME) != 0) { - topo_mod_strfree(mp, fpath); - return (topo_mod_seterrno(mp, EMOD_FMRI_NVL)); - } - if (nvlist_add_string(in, - FM_FMRI_DEV_PATH, fpath) != 0) { - nvlist_free(in); - topo_mod_strfree(mp, fpath); - return (topo_mod_seterrno(mp, EMOD_NOMEM)); - } - fmri = topo_fmri_create(hp, FM_FMRI_SCHEME_DEV, - FM_FMRI_SCHEME_DEV, 0, in, &e); - nvlist_free(in); + fmri = topo_mod_devfmri(mp, FM_DEV_SCHEME_VERSION, + fpath, NULL); if (fmri == NULL) { topo_mod_dprintf(mp, "dev:///%s fmri creation failed.\n", fpath); topo_mod_strfree(mp, fpath); - return (topo_mod_seterrno(mp, e)); + return (-1); } topo_mod_strfree(mp, fpath); } else { @@ -430,9 +398,8 @@ ASRU_set(tnode_t *tn, did_t *pd, nvlist_free(fmri); return (0); } - if (topo_node_asru_set(tn, NULL, 0, &e) < 0) - if (e != ETOPO_PROP_NOENT) - return (topo_mod_seterrno(mp, e)); + (void) topo_node_asru_set(tn, NULL, 0, &e); + return (0); } @@ -442,16 +409,14 @@ ASRU_set(tnode_t *tn, did_t *pd, static int FRU_fmri_hack(topo_mod_t *mp, tnode_t *tn, const char *label) { - topo_hdl_t *hp; char buf[PATH_MAX]; nvlist_t *fmri; int err, e; - hp = topo_mod_handle(mp); (void) snprintf(buf, PATH_MAX, "hc:///component=%s", label); - if (topo_fmri_str2nvl(hp, buf, &fmri, &err) < 0) - return (topo_mod_seterrno(mp, err)); + if (topo_mod_str2nvl(mp, buf, &fmri) < 0) + return (-1); e = topo_node_fru_set(tn, fmri, 0, &err); nvlist_free(fmri); @@ -463,8 +428,7 @@ FRU_fmri_hack(topo_mod_t *mp, tnode_t *tn, const char *label) /*ARGSUSED*/ static int FRU_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { topo_mod_t *mp; char *label, *nm; @@ -482,10 +446,7 @@ FRU_set(tnode_t *tn, did_t *pd, */ if (strcmp(nm, "ioboard") != 0 && strcmp(nm, PCI_DEVICE) != 0 && strcmp(nm, PCIEX_DEVICE) != 0) { - if (topo_node_fru_set(tn, NULL, 0, &e) < 0) { - if (e != ETOPO_PROP_NOENT) - return (topo_mod_seterrno(mp, e)); - } + (void) topo_node_fru_set(tn, NULL, 0, &e); return (0); } @@ -493,10 +454,7 @@ FRU_set(tnode_t *tn, did_t *pd, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL, &label, &e) < 0) { if (e != ETOPO_PROP_NOENT) return (topo_mod_seterrno(mp, e)); - if (topo_node_fru_set(tn, NULL, 0, &e) < 0) { - if (e != ETOPO_PROP_NOENT) - return (topo_mod_seterrno(mp, e)); - } + (void) topo_node_fru_set(tn, NULL, 0, &e); return (0); } e = FRU_fmri_hack(mp, tn, label); @@ -507,8 +465,7 @@ FRU_set(tnode_t *tn, did_t *pd, /*ARGSUSED*/ static int label_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { topo_mod_t *mp; nvlist_t *in, *out; @@ -532,7 +489,7 @@ label_set(tnode_t *tn, did_t *pd, if (out != NULL && nvlist_lookup_string(out, TOPO_METH_LABEL_RET_STR, &label) == 0) { if (topo_prop_set_string(tn, TOPO_PGROUP_PROTOCOL, - TOPO_PROP_LABEL, TOPO_PROP_SET_ONCE, label, &err) != 0) { + TOPO_PROP_LABEL, TOPO_PROP_IMMUTABLE, label, &err) != 0) { nvlist_free(out); return (topo_mod_seterrno(mp, err)); } @@ -544,8 +501,7 @@ label_set(tnode_t *tn, did_t *pd, /*ARGSUSED*/ static int EXCAP_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { int excap; int err; @@ -557,27 +513,27 @@ EXCAP_set(tnode_t *tn, did_t *pd, switch (excap & PCIE_PCIECAP_DEV_TYPE_MASK) { case PCIE_PCIECAP_DEV_TYPE_ROOT: e = topo_prop_set_string(tn, TOPO_PGROUP_PCI, - TOPO_PROP_EXCAP, TOPO_PROP_SET_ONCE, PCIEX_ROOT, &err); + TOPO_PCI_EXCAP, TOPO_PROP_IMMUTABLE, PCIEX_ROOT, &err); break; case PCIE_PCIECAP_DEV_TYPE_UP: e = topo_prop_set_string(tn, TOPO_PGROUP_PCI, - TOPO_PROP_EXCAP, TOPO_PROP_SET_ONCE, PCIEX_SWUP, &err); + TOPO_PCI_EXCAP, TOPO_PROP_IMMUTABLE, PCIEX_SWUP, &err); break; case PCIE_PCIECAP_DEV_TYPE_DOWN: e = topo_prop_set_string(tn, TOPO_PGROUP_PCI, - TOPO_PROP_EXCAP, TOPO_PROP_SET_ONCE, PCIEX_SWDWN, &err); + TOPO_PCI_EXCAP, TOPO_PROP_IMMUTABLE, PCIEX_SWDWN, &err); break; case PCIE_PCIECAP_DEV_TYPE_PCI2PCIE: e = topo_prop_set_string(tn, TOPO_PGROUP_PCI, - TOPO_PROP_EXCAP, TOPO_PROP_SET_ONCE, PCIEX_BUS, &err); + TOPO_PCI_EXCAP, TOPO_PROP_IMMUTABLE, PCIEX_BUS, &err); break; case PCIE_PCIECAP_DEV_TYPE_PCIE2PCI: e = topo_prop_set_string(tn, TOPO_PGROUP_PCI, - TOPO_PROP_EXCAP, TOPO_PROP_SET_ONCE, PCI_BUS, &err); + TOPO_PCI_EXCAP, TOPO_PROP_IMMUTABLE, PCI_BUS, &err); break; case PCIE_PCIECAP_DEV_TYPE_PCIE_DEV: e = topo_prop_set_string(tn, TOPO_PGROUP_PCI, - TOPO_PROP_EXCAP, TOPO_PROP_SET_ONCE, PCIEX_DEVICE, &err); + TOPO_PCI_EXCAP, TOPO_PROP_IMMUTABLE, PCIEX_DEVICE, &err); break; } if (e != 0) @@ -588,8 +544,7 @@ EXCAP_set(tnode_t *tn, did_t *pd, /*ARGSUSED*/ static int DEVprop_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { topo_mod_t *mp; char *dnpath; @@ -618,7 +573,7 @@ DEVprop_set(tnode_t *tn, did_t *pd, if (fpath == NULL) return (-1); e = topo_prop_set_string(tn, - tpgrp, tpnm, TOPO_PROP_SET_ONCE, fpath, &err); + tpgrp, tpnm, TOPO_PROP_IMMUTABLE, fpath, &err); topo_mod_strfree(mp, fpath); if (e != 0) return (topo_mod_seterrno(mp, err)); @@ -628,8 +583,7 @@ DEVprop_set(tnode_t *tn, did_t *pd, /*ARGSUSED*/ static int DRIVERprop_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { char *dnm; int err; @@ -637,7 +591,7 @@ DRIVERprop_set(tnode_t *tn, did_t *pd, if ((dnm = di_driver_name(did_dinode(pd))) == NULL) return (0); if (topo_prop_set_string(tn, - tpgrp, tpnm, TOPO_PROP_SET_ONCE, dnm, &err) < 0) + tpgrp, tpnm, TOPO_PROP_IMMUTABLE, dnm, &err) < 0) return (topo_mod_seterrno(did_mod(pd), err)); return (0); @@ -646,8 +600,7 @@ DRIVERprop_set(tnode_t *tn, did_t *pd, /*ARGSUSED*/ static int maybe_di_chars_copy(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { topo_mod_t *mp; uchar_t *typbuf; @@ -655,15 +608,14 @@ maybe_di_chars_copy(tnode_t *tn, did_t *pd, int sz = -1; int err, e; - if (di_bytes_get(did_dinode(pd), dpnm, &sz, &typbuf, - promtree) < 0) + if (di_bytes_get(did_mod(pd), did_dinode(pd), dpnm, &sz, &typbuf) < 0) return (0); mp = did_mod(pd); tmpbuf = topo_mod_alloc(mp, sz + 1); bcopy(typbuf, tmpbuf, sz); tmpbuf[sz] = 0; e = topo_prop_set_string(tn, - tpgrp, tpnm, TOPO_PROP_SET_ONCE, tmpbuf, &err); + tpgrp, tpnm, TOPO_PROP_IMMUTABLE, tmpbuf, &err); topo_mod_free(mp, tmpbuf, sz + 1); if (e != 0) return (topo_mod_seterrno(mp, err)); @@ -679,20 +631,18 @@ uint_to_strprop(topo_mod_t *mp, uint_t v, tnode_t *tn, (void) snprintf(str, 21, "%x", v); if (topo_prop_set_string(tn, - tpgrp, tpnm, TOPO_PROP_SET_ONCE, str, &e) < 0) + tpgrp, tpnm, TOPO_PROP_IMMUTABLE, str, &e) < 0) return (topo_mod_seterrno(mp, e)); return (0); } static int maybe_di_uint_to_str(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) + const char *dpnm, const char *tpgrp, const char *tpnm) { uint_t v; - if (di_uintprop_get(did_dinode(pd), dpnm, &v, - promtree) < 0) + if (di_uintprop_get(did_mod(pd), did_dinode(pd), dpnm, &v) < 0) return (0); return (uint_to_strprop(did_mod(pd), v, tn, tpgrp, tpnm)); @@ -700,9 +650,8 @@ maybe_di_uint_to_str(tnode_t *tn, did_t *pd, /*ARGSUSED*/ static int -BDF_set(tnode_t *tn, did_t *pd, - const char *dpnm, const char *tpgrp, const char *tpnm, - di_prom_handle_t promtree) +BDF_set(tnode_t *tn, did_t *pd, const char *dpnm, const char *tpgrp, + const char *tpnm) { int bdf; char str[23]; /* '0x' + sizeof (UINT64_MAX) + '\0' */ @@ -713,17 +662,15 @@ BDF_set(tnode_t *tn, did_t *pd, (void) snprintf(str, 23, "0x%x", bdf); if (topo_prop_set_string(tn, - tpgrp, tpnm, TOPO_PROP_SET_ONCE, str, &e) < 0) + tpgrp, tpnm, TOPO_PROP_IMMUTABLE, str, &e) < 0) return (topo_mod_seterrno(did_mod(pd), e)); return (0); } int -did_props_set(tnode_t *tn, did_t *pd, txprop_t txarray[], int txnum, - di_prom_handle_t promtree) +did_props_set(tnode_t *tn, did_t *pd, txprop_t txarray[], int txnum) { topo_mod_t *mp; - const char *ppgroup = NULL; int i, r, e; mp = did_mod(pd); @@ -731,10 +678,9 @@ did_props_set(tnode_t *tn, did_t *pd, txprop_t txarray[], int txnum, /* * Ensure the property group has been created. */ - if (ppgroup == NULL || - strcmp(txarray[i].tx_tpgroup, ppgroup) != 0) { - if (topo_pgroup_create(tn, txarray[i].tx_tpgroup, - txarray[i].tx_pgstab, &e) < 0) { + if (txarray[i].tx_tpgroup != NULL) { + if (topo_pgroup_create(tn, txarray[i].tx_tpgroup, &e) + < 0) { if (e != ETOPO_PROP_DEFD) return (topo_mod_seterrno(mp, e)); } @@ -742,10 +688,10 @@ did_props_set(tnode_t *tn, did_t *pd, txprop_t txarray[], int txnum, topo_mod_dprintf(mp, "Setting property %s in group %s.\n", - txarray[i].tx_tprop, txarray[i].tx_tpgroup); + txarray[i].tx_tprop, txarray[i].tx_tpgroup->tpi_name); r = txarray[i].tx_xlate(tn, pd, - txarray[i].tx_diprop, txarray[i].tx_tpgroup, - txarray[i].tx_tprop, promtree); + txarray[i].tx_diprop, txarray[i].tx_tpgroup->tpi_name, + txarray[i].tx_tprop); if (r != 0) { topo_mod_dprintf(mp, "failed.\n"); topo_mod_dprintf(mp, "Error was %s.\n", diff --git a/usr/src/lib/fm/topo/modules/common/did_props.h b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.h index c43d0ef29d..3711fa439e 100644 --- a/usr/src/lib/fm/topo/modules/common/did_props.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.h @@ -30,10 +30,12 @@ #pragma ident "%Z%%M% %I% %E% SMI" #include <sys/pci.h> -#include <fm/libtopo.h> +#include <fm/topo_mod.h> #include <libdevinfo.h> #include <libnvpair.h> +#include <did.h> + #ifdef __cplusplus extern "C" { #endif @@ -48,30 +50,17 @@ extern "C" { */ typedef struct txprop { const char *tx_diprop; /* property examined off the di_node_t */ - const char *tx_tpgroup; /* property group defined on the tnode_t */ + const topo_pgroup_info_t *tx_tpgroup; /* pgroup defined for tnode_t */ const char *tx_tprop; /* property defined on the tnode_t */ - topo_stability_t tx_pgstab; /* stability of property group */ /* * translation function * If NULL, the devinfo prop's value is copied to the * topo property. */ int (*tx_xlate)(tnode_t *, did_t *, - const char *, const char *, const char *, di_prom_handle_t); + const char *, const char *, const char *); } txprop_t; -#define TOPO_PGROUP_PCI "pci" -#define TOPO_PGROUP_IO "io" - -#define TOPO_PROP_DEVTYPE "DEVTYPE" -#define TOPO_PROP_DRIVER "DRIVER" -#define TOPO_PROP_VENDID "VENDOR-ID" -#define TOPO_PROP_DEVID "DEVICE-ID" -#define TOPO_PROP_CLASS "CLASS-CODE" -#define TOPO_PROP_EXCAP "EXCAP" -#define TOPO_PROP_BDF "BDF" -#define TOPO_PROP_DEV "DEV" - #define DI_DEVTYPPROP "device_type" #define DI_VENDIDPROP "vendor-id" #define DI_DEVIDPROP "device-id" @@ -81,17 +70,15 @@ typedef struct txprop { #define DI_PHYSPROP "physical-slot#" #define DI_SLOTPROP "slot-names" -extern int did_props_set(tnode_t *, did_t *, txprop_t[], int, - di_prom_handle_t); +extern int did_props_set(tnode_t *, did_t *, txprop_t[], int); -extern int pciex_cap_get(did_hash_t *, di_node_t); -extern int pci_BDF_get(did_hash_t *, di_node_t, int *, int *, int *); -extern int pci_classcode_get(did_hash_t *, di_node_t, uint_t *, uint_t *); +extern int pciex_cap_get(topo_mod_t *, di_node_t); +extern int pci_BDF_get(topo_mod_t *, di_node_t, int *, int *, int *); +extern int pci_classcode_get(topo_mod_t *, di_node_t, uint_t *, uint_t *); -extern int di_uintprop_get(di_node_t, const char *, uint_t *, - di_prom_handle_t); -extern int di_bytes_get(di_node_t, const char *, int *, uchar_t **, - di_prom_handle_t); +extern int di_uintprop_get(topo_mod_t *, di_node_t, const char *, uint_t *); +extern int di_bytes_get(topo_mod_t *, di_node_t, const char *, int *, + uchar_t **); #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/common/pcibus.c b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus.c index 069b24da46..5e5a400888 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus.c @@ -39,13 +39,13 @@ #include <libdevinfo.h> #include <libnvpair.h> #include <fm/topo_mod.h> -#include <pthread.h> +#include <fm/topo_hc.h> -#include "hostbridge.h" -#include "pcibus.h" -#include "did.h" -#include "did_props.h" -#include "util.h" +#include <hostbridge.h> +#include <pcibus.h> +#include <did.h> +#include <did_props.h> +#include <util.h> extern txprop_t Bus_common_props[]; extern txprop_t Dev_common_props[]; @@ -54,43 +54,43 @@ extern int Bus_propcnt; extern int Dev_propcnt; extern int Fn_propcnt; -extern int pcifn_enum(topo_mod_t *, tnode_t *); +extern int platform_pci_label(topo_mod_t *mod, tnode_t *, nvlist_t *, + nvlist_t **); static void pci_release(topo_mod_t *, tnode_t *); static int pci_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t, - topo_instance_t, void *); -static int pci_contains(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, - nvlist_t **); -static int pci_present(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, - nvlist_t **); + topo_instance_t, void *, void *); static int pci_label(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, nvlist_t **); -const topo_modinfo_t Pci_info = - { PCI_BUS, PCI_ENUMR_VERS, pci_enum, pci_release }; +static const topo_modops_t Pci_ops = + { pci_enum, pci_release }; +static const topo_modinfo_t Pci_info = + { PCI_BUS, FM_FMRI_SCHEME_HC, PCI_ENUMR_VERS, &Pci_ops }; -const topo_method_t Pci_methods[] = { - { "pci_contains", "pci element contains other element", PCI_ENUMR_VERS, - TOPO_STABILITY_INTERNAL, pci_contains }, - { "pci_present", "pci element currently present", PCI_ENUMR_VERS, - TOPO_STABILITY_INTERNAL, pci_present }, +static const topo_method_t Pci_methods[] = { { TOPO_METH_LABEL, TOPO_METH_LABEL_DESC, TOPO_METH_LABEL_VERSION, TOPO_STABILITY_INTERNAL, pci_label }, { NULL } }; -void -_topo_init(topo_mod_t *modhdl) +int +_topo_init(topo_mod_t *modhdl, topo_version_t version) { /* * Turn on module debugging output */ if (getenv("TOPOPCIDBG") != NULL) - topo_mod_setdebug(modhdl, TOPO_DBG_ALL); + topo_mod_setdebug(modhdl); topo_mod_dprintf(modhdl, "initializing pcibus builtin\n"); - topo_mod_register(modhdl, &Pci_info, NULL); + if (version != PCI_ENUMR_VERS) + return (topo_mod_seterrno(modhdl, EMOD_VER_NEW)); + + topo_mod_register(modhdl, &Pci_info, TOPO_VERSION); topo_mod_dprintf(modhdl, "PCI Enumr initd\n"); + + return (0); } void @@ -99,34 +99,18 @@ _topo_fini(topo_mod_t *modhdl) topo_mod_unregister(modhdl); } -/*ARGSUSED*/ -static int -pci_contains(topo_mod_t *mp, tnode_t *node, topo_version_t version, - nvlist_t *in, nvlist_t **out) -{ - return (0); -} - -/*ARGSUSED*/ -static int -pci_present(topo_mod_t *mp, tnode_t *node, topo_version_t version, - nvlist_t *in, nvlist_t **out) -{ - return (0); -} - static int pci_label(topo_mod_t *mp, tnode_t *node, topo_version_t version, nvlist_t *in, nvlist_t **out) { if (version > TOPO_METH_LABEL_VERSION) return (topo_mod_seterrno(mp, EMOD_VER_NEW)); - return (platform_pci_label(node, in, out, mp)); + return (platform_pci_label(mp, node, in, out)); } static tnode_t * -pci_tnode_create(tnode_t *parent, - const char *name, topo_instance_t i, void *priv, topo_mod_t *mod) +pci_tnode_create(topo_mod_t *mod, tnode_t *parent, + const char *name, topo_instance_t i, void *priv) { tnode_t *ntn; @@ -143,37 +127,34 @@ pci_tnode_create(tnode_t *parent, /*ARGSUSED*/ static int -hostbridge_asdevice(tnode_t *bus, did_hash_t *didhash, - di_prom_handle_t promtree, topo_mod_t *mod) +hostbridge_asdevice(topo_mod_t *mod, tnode_t *bus) { di_node_t di; tnode_t *dev32; - di = topo_node_private(bus); + di = topo_node_getspecific(bus); assert(di != DI_NODE_NIL); - if ((dev32 = pcidev_declare(bus, di, 32, didhash, promtree, mod)) - == NULL) + if ((dev32 = pcidev_declare(mod, bus, di, 32)) == NULL) return (-1); - if (pcifn_declare(dev32, di, 0, didhash, promtree, mod) == NULL) + if (pcifn_declare(mod, dev32, di, 0) == NULL) return (-1); return (0); } tnode_t * -pciexfn_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +pciexfn_declare(topo_mod_t *mod, tnode_t *parent, di_node_t dn, + topo_instance_t i) { did_t *pd; tnode_t *ntn; - if ((pd = did_find(didhash, dn)) == NULL) + if ((pd = did_find(mod, dn)) == NULL) return (NULL); - if ((ntn = pci_tnode_create(parent, PCIEX_FUNCTION, i, dn, mod)) + if ((ntn = pci_tnode_create(mod, parent, PCIEX_FUNCTION, i, dn)) == NULL) return (NULL); - if (did_props_set(ntn, pd, Fn_common_props, Fn_propcnt, - promtree) < 0) { + if (did_props_set(ntn, pd, Fn_common_props, Fn_propcnt) < 0) { topo_node_unbind(ntn); return (NULL); } @@ -192,21 +173,21 @@ pciexfn_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, } tnode_t * -pciexdev_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +pciexdev_declare(topo_mod_t *mod, tnode_t *parent, di_node_t dn, + topo_instance_t i) { did_t *pd; tnode_t *ntn; - if ((pd = did_find(didhash, dn)) == NULL) + if ((pd = did_find(mod, dn)) == NULL) return (NULL); - if ((ntn = pci_tnode_create(parent, PCIEX_DEVICE, i, dn, mod)) == NULL) + if ((ntn = pci_tnode_create(mod, parent, PCIEX_DEVICE, i, dn)) == NULL) return (NULL); - if (did_props_set(ntn, pd, Dev_common_props, Dev_propcnt, - promtree) < 0) { + if (did_props_set(ntn, pd, Dev_common_props, Dev_propcnt) < 0) { topo_node_unbind(ntn); return (NULL); } + /* * We can expect to find pci-express functions beneath the device */ @@ -219,18 +200,17 @@ pciexdev_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, } tnode_t * -pciexbus_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +pciexbus_declare(topo_mod_t *mod, tnode_t *parent, di_node_t dn, + topo_instance_t i) { did_t *pd; tnode_t *ntn; - if ((pd = did_find(didhash, dn)) == NULL) + if ((pd = did_find(mod, dn)) == NULL) return (NULL); - if ((ntn = pci_tnode_create(parent, PCIEX_BUS, i, dn, mod)) == NULL) + if ((ntn = pci_tnode_create(mod, parent, PCIEX_BUS, i, dn)) == NULL) return (NULL); - if (did_props_set(ntn, pd, Bus_common_props, Bus_propcnt, - promtree) < 0) { + if (did_props_set(ntn, pd, Bus_common_props, Bus_propcnt) < 0) { topo_node_range_destroy(ntn, PCI_DEVICE); topo_node_unbind(ntn); return (NULL); @@ -247,18 +227,17 @@ pciexbus_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, } tnode_t * -pcifn_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +pcifn_declare(topo_mod_t *mod, tnode_t *parent, di_node_t dn, + topo_instance_t i) { did_t *pd; tnode_t *ntn; - if ((pd = did_find(didhash, dn)) == NULL) + if ((pd = did_find(mod, dn)) == NULL) return (NULL); - if ((ntn = pci_tnode_create(parent, PCI_FUNCTION, i, dn, mod)) == NULL) + if ((ntn = pci_tnode_create(mod, parent, PCI_FUNCTION, i, dn)) == NULL) return (NULL); - if (did_props_set(ntn, pd, Fn_common_props, Fn_propcnt, - promtree) < 0) { + if (did_props_set(ntn, pd, Fn_common_props, Fn_propcnt) < 0) { topo_node_unbind(ntn); return (NULL); } @@ -273,21 +252,21 @@ pcifn_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, } tnode_t * -pcidev_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +pcidev_declare(topo_mod_t *mod, tnode_t *parent, di_node_t dn, + topo_instance_t i) { - di_node_t pdn; did_t *pd; - tnode_t *ntn; did_t *ppd; + di_node_t pdn; + tnode_t *ntn; - if ((pdn = topo_node_private(parent)) == DI_NODE_NIL) + if ((pdn = topo_node_getspecific(parent)) == DI_NODE_NIL) return (NULL); - if ((ppd = did_find(didhash, pdn)) == NULL) + if ((ppd = did_find(mod, pdn)) == NULL) return (NULL); - if ((pd = did_find(didhash, dn)) == NULL) + if ((pd = did_find(mod, dn)) == NULL) return (NULL); - if ((ntn = pci_tnode_create(parent, PCI_DEVICE, i, dn, mod)) == NULL) + if ((ntn = pci_tnode_create(mod, parent, PCI_DEVICE, i, dn)) == NULL) return (NULL); /* * If our devinfo node is lacking certain information of its @@ -295,11 +274,11 @@ pcidev_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, * from our parent node's private data. */ did_inherit(ppd, pd); - if (did_props_set(ntn, pd, Dev_common_props, Dev_propcnt, - promtree) < 0) { + if (did_props_set(ntn, pd, Dev_common_props, Dev_propcnt) < 0) { topo_node_unbind(ntn); return (NULL); } + /* * We can expect to find pci functions beneath the device */ @@ -312,16 +291,16 @@ pcidev_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, } tnode_t * -pcibus_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +pcibus_declare(topo_mod_t *mod, tnode_t *parent, di_node_t dn, + topo_instance_t i) { did_t *pd; tnode_t *ntn; int hbchild = 0; - if ((pd = did_find(didhash, dn)) == NULL) + if ((pd = did_find(mod, dn)) == NULL) return (NULL); - if ((ntn = pci_tnode_create(parent, PCI_BUS, i, dn, mod)) == NULL) + if ((ntn = pci_tnode_create(mod, parent, PCI_BUS, i, dn)) == NULL) return (NULL); /* * If our devinfo node is lacking certain information of its @@ -331,8 +310,7 @@ pcibus_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, */ if (strcmp(topo_node_name(parent), HOSTBRIDGE) == 0) hbchild = 1; - if (did_props_set(ntn, pd, Bus_common_props, Bus_propcnt, - promtree) < 0) { + if (did_props_set(ntn, pd, Bus_common_props, Bus_propcnt) < 0) { topo_node_unbind(ntn); return (NULL); } @@ -349,7 +327,7 @@ pcibus_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, * numbers. */ if (hbchild == 1) { - if (hostbridge_asdevice(ntn, didhash, promtree, mod) < 0) { + if (hostbridge_asdevice(mod, ntn) < 0) { topo_node_range_destroy(ntn, PCI_DEVICE); topo_node_unbind(ntn); return (NULL); @@ -359,68 +337,65 @@ pcibus_declare(tnode_t *parent, di_node_t dn, topo_instance_t i, } static int -pci_bridge_declare(tnode_t *fn, di_node_t din, int board, - int bridge, int rc, int depth, did_hash_t *didhash, - di_prom_handle_t promtree, topo_mod_t *mod) +pci_bridge_declare(topo_mod_t *mod, tnode_t *fn, di_node_t din, int board, + int bridge, int rc, int depth) { int err, excap, extyp; - excap = pciex_cap_get(didhash, din); + excap = pciex_cap_get(mod, din); extyp = excap & PCIE_PCIECAP_DEV_TYPE_MASK; if (excap <= 0 || extyp != PCIE_PCIECAP_DEV_TYPE_PCIE2PCI) - err = pci_children_instantiate(fn, - din, board, bridge, rc, TRUST_BDF, depth + 1, didhash, - promtree, mod); + err = pci_children_instantiate(mod, fn, din, board, bridge, + rc, TRUST_BDF, depth + 1); else - err = pci_children_instantiate(fn, - din, board, bridge, rc - TO_PCI, TRUST_BDF, depth + 1, - didhash, promtree, mod); + err = pci_children_instantiate(mod, fn, din, board, bridge, + rc - TO_PCI, TRUST_BDF, depth + 1); return (err); } static int -declare_dev_and_fn(tnode_t *bus, tnode_t **dev, di_node_t din, - int board, int bridge, int rc, int devno, int fnno, int depth, - did_hash_t *didhash, di_prom_handle_t promtree, topo_mod_t *mod) +declare_dev_and_fn(topo_mod_t *mod, tnode_t *bus, tnode_t **dev, di_node_t din, + int board, int bridge, int rc, int devno, int fnno, int depth) { + int err = 0; tnode_t *fn; uint_t class, subclass; - int err; if (*dev == NULL) { if (rc >= 0) - *dev = pciexdev_declare(bus, din, devno, didhash, - promtree, mod); + *dev = pciexdev_declare(mod, bus, din, devno); else - *dev = pcidev_declare(bus, din, devno, didhash, - promtree, mod); + *dev = pcidev_declare(mod, bus, din, devno); if (*dev == NULL) return (-1); } if (rc >= 0) - fn = pciexfn_declare(*dev, din, fnno, didhash, promtree, mod); + fn = pciexfn_declare(mod, *dev, din, fnno); else - fn = pcifn_declare(*dev, din, fnno, didhash, promtree, mod); + fn = pcifn_declare(mod, *dev, din, fnno); if (fn == NULL) return (-1); - if (pci_classcode_get(didhash, din, &class, &subclass) < 0) + if (pci_classcode_get(mod, din, &class, &subclass) < 0) return (-1); + + /* + * This function may be a bridge. If not, check for a possible + * topology map file and kick off its enumeration of lower-level + * devices. + */ if (class == PCI_CLASS_BRIDGE && subclass == PCI_BRIDGE_PCI) - err = pci_bridge_declare(fn, din, board, bridge, rc, depth, - didhash, promtree, mod); - else - err = pcifn_enum(mod, fn); - if (err < 0) - return (-1); - else - return (0); + err = pci_bridge_declare(mod, fn, din, board, bridge, rc, + depth); + else if (class == PCI_CLASS_MASS) + (void) topo_mod_enummap(mod, fn, "storage", FM_FMRI_SCHEME_HC); + + return (err); } int -pci_children_instantiate(tnode_t *parent, di_node_t pn, - int board, int bridge, int rc, int bover, int depth, did_hash_t *didhash, - di_prom_handle_t promtree, topo_mod_t *mod) +pci_children_instantiate(topo_mod_t *mod, tnode_t *parent, di_node_t pn, + int board, int bridge, int rc, int bover, int depth) { did_t *pps[MAX_PCIBUS_DEVS][MAX_PCIDEV_FNS]; did_t *bp = NULL; @@ -439,8 +414,7 @@ pci_children_instantiate(tnode_t *parent, di_node_t pn, /* start at the parent's first sibling */ sib = di_child_node(pn); while (sib != DI_NODE_NIL) { - np = did_create(didhash, sib, board, bridge, rc, bover, - promtree); + np = did_create(mod, sib, board, bridge, rc, bover); if (np == NULL) return (-1); did_BDF(np, &b, &d, &f); @@ -454,11 +428,9 @@ pci_children_instantiate(tnode_t *parent, di_node_t pn, if (pb < 0 && bover < 0) return (0); if (rc >= 0) - bn = pciexbus_declare(parent, pn, ((pb < 0) ? bover : pb), - didhash, promtree, mod); + bn = pciexbus_declare(mod, parent, pn, ((pb < 0) ? bover : pb)); else - bn = pcibus_declare(parent, pn, ((pb < 0) ? bover : pb), - didhash, promtree, mod); + bn = pcibus_declare(mod, parent, pn, ((pb < 0) ? bover : pb)); if (bn == NULL) return (-1); if (pb < 0) @@ -469,10 +441,14 @@ pci_children_instantiate(tnode_t *parent, di_node_t pn, if (pps[d][f] == NULL) continue; din = did_dinode(pps[d][f]); - if ((declare_dev_and_fn(bn, - &dn, din, board, bridge, rc, d, f, depth, - didhash, promtree, mod)) != 0) - return (-1); + /* + * Ignore error and try to enumerate as much as + * possible. If we ever need to check for an + * error all declared buses, devices and functions + * need to be cleaned up + */ + (void) declare_dev_and_fn(mod, bn, + &dn, din, board, bridge, rc, d, f, depth); did_rele(pps[d][f]); } dn = NULL; @@ -481,14 +457,12 @@ pci_children_instantiate(tnode_t *parent, di_node_t pn, } static int -pciexbus_enum(tnode_t *ptn, - char *pnm, topo_instance_t min, topo_instance_t max, - di_prom_handle_t promtree, topo_mod_t *mod) +pciexbus_enum(topo_mod_t *mp, tnode_t *ptn, char *pnm, topo_instance_t min, + topo_instance_t max) { di_node_t pdn; int rc; int retval; - did_hash_t *didhash; /* * PCI-Express; root complex shares the hostbridge's instance @@ -497,43 +471,35 @@ pciexbus_enum(tnode_t *ptn, */ rc = topo_node_instance(ptn); - if ((pdn = topo_node_private(ptn)) == DI_NODE_NIL) { - topo_mod_dprintf(mod, + if ((pdn = topo_node_getspecific(ptn)) == DI_NODE_NIL) { + topo_mod_dprintf(mp, "Parent %s node missing private data.\n" - "Unable to proceed with %s enumeration.\n", - pnm, PCIEX_BUS); + "Unable to proceed with %s enumeration.\n", pnm, PCIEX_BUS); return (0); } - if ((didhash = did_hash_init(mod)) == NULL || - (did_create(didhash, pdn, 0, 0, rc, TRUST_BDF, promtree) == NULL)) + did_hash_init(mp); + if (did_create(mp, pdn, 0, 0, rc, TRUST_BDF) == NULL) return (-1); /* errno already set */ - retval = pci_children_instantiate(ptn, - pdn, 0, 0, rc, (min == max) ? min : TRUST_BDF, 0, didhash, - promtree, mod); - did_hash_fini(didhash); + retval = pci_children_instantiate(mp, ptn, pdn, 0, 0, rc, + (min == max) ? min : TRUST_BDF, 0); + did_hash_fini(mp); + return (retval); } static int -pcibus_enum(tnode_t *ptn, char *pnm, topo_instance_t min, topo_instance_t max, - di_prom_handle_t promtree, topo_mod_t *mod) +pcibus_enum(topo_mod_t *mp, tnode_t *ptn, char *pnm, topo_instance_t min, + topo_instance_t max, void *data) { - did_t *hbdid, *didp; + did_t *didp, *hbdid = (did_t *)data; int retval; - did_hash_t *didhash; /* - * PCI Bus; Parent node's private data is a did_t. We'll + * XXTOPO: we should not be sharing private node data with another + * module. PCI Bus; Parent node's private data is a did_t. We'll * use the did hash established by the parent. */ - if ((hbdid = topo_node_private(ptn)) == NULL) { - topo_mod_dprintf(mod, - "Parent %s node missing private data.\n" - "Unable to proceed with %s enumeration.\n", - pnm, PCIEX_BUS); - return (0); - } - didhash = did_hash(hbdid); + did_setspecific(mp, data); /* * If we're looking for a specific bus-instance, find the right @@ -549,62 +515,63 @@ pcibus_enum(tnode_t *ptn, char *pnm, topo_instance_t min, topo_instance_t max, didp = did_link_get(didp); } if (didp == NULL) { - topo_mod_dprintf(mod, + topo_mod_dprintf(mp, "Parent %s node missing private data related\n" "to %s instance %d.\n", pnm, PCI_BUS, min); + topo_mod_setspecific(mp, NULL); return (0); } } else { assert(did_link_get(hbdid) == NULL); didp = hbdid; } - retval = pci_children_instantiate(ptn, did_dinode(didp), + retval = pci_children_instantiate(mp, ptn, did_dinode(didp), did_board(didp), did_bridge(didp), did_rc(didp), - (min == max) ? min : TRUST_BDF, 0, didhash, promtree, mod); + (min == max) ? min : TRUST_BDF, 0); + + topo_mod_setspecific(mp, NULL); + return (retval); } /*ARGSUSED*/ static int -pci_enum(topo_mod_t *mp, tnode_t *ptn, const char *name, - topo_instance_t min, topo_instance_t max, void *notused) +pci_enum(topo_mod_t *mod, tnode_t *ptn, const char *name, + topo_instance_t min, topo_instance_t max, void *notused, void *data) { - char *pnm; int retval; - di_prom_handle_t promtree; + char *pname; - topo_mod_dprintf(mp, "Enumerating pci!\n"); + topo_mod_dprintf(mod, "Enumerating pci!\n"); - if ((promtree = di_prom_init()) == DI_PROM_HANDLE_NIL) { - topo_mod_dprintf(mp, - "Pcibus enumerator: di_prom_handle_init failed.\n"); - return (-1); + if (strcmp(name, PCI_BUS) != 0 && strcmp(name, PCIEX_BUS) != 0) { + topo_mod_dprintf(mod, + "Currently only know how to enumerate %s or %s.\n", + PCI_BUS, PCIEX_BUS); + return (0); } - - pnm = topo_node_name(ptn); - if (strcmp(pnm, HOSTBRIDGE) != 0 && strcmp(pnm, PCIEX_ROOT) != 0) { - topo_mod_dprintf(mp, + pname = topo_node_name(ptn); + if (strcmp(pname, HOSTBRIDGE) != 0 && strcmp(pname, PCIEX_ROOT) != 0) { + topo_mod_dprintf(mod, "Currently can only enumerate a %s or %s directly\n", PCI_BUS, PCIEX_BUS); - topo_mod_dprintf(mp, + topo_mod_dprintf(mod, "descended from a %s or %s node.\n", HOSTBRIDGE, PCIEX_ROOT); - di_prom_fini(promtree); return (0); } if (strcmp(name, PCI_BUS) == 0) { - retval = pcibus_enum(ptn, pnm, min, max, promtree, mp); + retval = pcibus_enum(mod, ptn, pname, min, max, data); } else if (strcmp(name, PCIEX_BUS) == 0) { - retval = pciexbus_enum(ptn, pnm, min, max, promtree, mp); + retval = pciexbus_enum(mod, ptn, pname, min, max); } else { - topo_mod_dprintf(mp, + topo_mod_dprintf(mod, "Currently only know how to enumerate %s or %s not %s.\n", PCI_BUS, PCIEX_BUS, name); - di_prom_fini(promtree); return (0); } - di_prom_fini(promtree); + return (retval); } diff --git a/usr/src/lib/fm/topo/modules/common/pcibus.h b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus.h index 21d61643cd..743eef62f2 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus.h @@ -31,7 +31,6 @@ #include <sys/pci.h> #include <fm/topo_mod.h> -#include <fm/libtopo.h> #include <libdevinfo.h> #ifdef __cplusplus @@ -40,7 +39,7 @@ extern "C" { #define PCI_ENUMR_VERS 1 -#define PATH_TO_PCI_ENUM "%s/usr/platform/%s/lib/fm/topo/plugins/pcibus.so" +#define PCI_ENUM "pcibus" #define PCI_BUS "pcibus" #define PCI_DEVICE "pcidev" @@ -62,27 +61,22 @@ extern "C" { #define GETCLASS(x) (((x) & 0xff0000) >> 16) #define GETSUBCLASS(x) (((x) & 0xff00) >> 8) -struct did_hash; - -extern tnode_t *pcibus_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pcidev_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pcifn_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pciexbus_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pciexdev_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern tnode_t *pciexfn_declare(tnode_t *, di_node_t, topo_instance_t, - struct did_hash *, di_prom_handle_t, topo_mod_t *); -extern int pci_children_instantiate(tnode_t *, di_node_t, - int, int, int, int, int, struct did_hash *, di_prom_handle_t, - topo_mod_t *); - -extern int platform_pci_label(tnode_t *, nvlist_t *, nvlist_t **, topo_mod_t *); - -extern const topo_method_t Pci_methods[]; +extern tnode_t *pcibus_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pcidev_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pcifn_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pciexbus_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pciexdev_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern tnode_t *pciexfn_declare(topo_mod_t *, tnode_t *, di_node_t, + topo_instance_t); +extern int pci_children_instantiate(topo_mod_t *, tnode_t *, di_node_t, + int, int, int, int, int); + +extern int platform_pci_label(topo_mod_t *, tnode_t *, nvlist_t *, nvlist_t **); #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/common/pcibus_labels.c b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.c index 5a48004081..86e839c6a3 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus_labels.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.c @@ -30,11 +30,11 @@ #include <fm/topo_mod.h> #include <assert.h> #include <string.h> +#include <sys/fm/protocol.h> -#include "topo_error.h" -#include "did.h" -#include "pcibus.h" -#include "pcibus_labels.h" +#include <did.h> +#include <pcibus.h> +#include <pcibus_labels.h> extern slotnm_rewrite_t *Slot_Rewrites; extern physlot_names_t *Physlot_Names; @@ -96,7 +96,7 @@ pci_slotname_rewrite(char *platform, const char *label) } static const char * -pci_missing_match(char *platform, did_t *dp, topo_mod_t *mod) +pci_missing_match(topo_mod_t *mod, char *platform, did_t *dp) { const char *rlabel = NULL; int board, bridge, rc, bus, dev; @@ -132,31 +132,38 @@ pci_missing_match(char *platform, did_t *dp, topo_mod_t *mod) } static const char * -pci_slotname_lookup(tnode_t *node, did_t *dp, topo_mod_t *mod) +pci_slotname_lookup(topo_mod_t *mod, tnode_t *node, did_t *dp) { const char *l; - char *plat; + char *plat, *pp; int err; int d; if (topo_prop_get_string(node, - TOPO_PGROUP_SYSTEM, TOPO_PROP_PLATFORM, &plat, &err) < 0) { + FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &plat, &err) < 0) { (void) topo_mod_seterrno(mod, err); return (NULL); } + + /* + * Trim SUNW, from the platform name + */ + pp = strchr(plat, ','); + ++pp; + did_BDF(dp, NULL, &d, NULL); - if ((l = pci_physslot_name_lookup(plat, dp)) == NULL) + if ((l = pci_physslot_name_lookup(pp, dp)) == NULL) if ((l = did_label(dp, d)) != NULL) { - l = pci_slotname_rewrite(plat, l); + l = pci_slotname_rewrite(pp, l); } else { - l = pci_missing_match(plat, dp, mod); + l = pci_missing_match(mod, pp, dp); } topo_mod_strfree(mod, plat); return (l); } int -pci_label_cmn(tnode_t *node, nvlist_t *in, nvlist_t **out, topo_mod_t *mod) +pci_label_cmn(topo_mod_t *mod, tnode_t *node, nvlist_t *in, nvlist_t **out) { uint64_t ptr; const char *l; @@ -189,7 +196,7 @@ pci_label_cmn(tnode_t *node, nvlist_t *in, nvlist_t **out, topo_mod_t *mod) /* * Is there a slotname associated with the device? */ - if ((l = pci_slotname_lookup(node, dp, mod)) != NULL) { + if ((l = pci_slotname_lookup(mod, node, dp)) != NULL) { nvlist_t *rnvl; if (topo_mod_nvalloc(mod, &rnvl, NV_UNIQUE_NAME) != 0 || diff --git a/usr/src/lib/fm/topo/modules/common/pcibus_labels.h b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.h index a5cb823003..2eae7d7ef5 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus_labels.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.h @@ -101,7 +101,7 @@ typedef struct missing_names { struct pdevlabs *mn_names; /* platform entries */ } missing_names_t; -extern int pci_label_cmn(tnode_t *, nvlist_t *, nvlist_t **, topo_mod_t *mod); +extern int pci_label_cmn(topo_mod_t *mod, tnode_t *, nvlist_t *, nvlist_t **); #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/common/util.c b/usr/src/lib/fm/topo/modules/common/pcibus/util.c index 43adf4e66c..f619862eda 100644 --- a/usr/src/lib/fm/topo/modules/common/util.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/util.c @@ -29,8 +29,8 @@ #include <stdlib.h> #include <sys/fm/protocol.h> #include <fm/topo_mod.h> - -#include "topo_error.h" +#include <fm/topo_hc.h> +#include <fm/libtopo.h> int child_range_add(topo_mod_t *mp, tnode_t *tn, const char *cnm, @@ -68,44 +68,21 @@ tnode_t * tnode_create(topo_mod_t *mp, tnode_t *parent, const char *name, topo_instance_t i, void *priv) { - topo_hdl_t *thp; - nvlist_t *fmri, *pfmri, *nvl; + nvlist_t *fmri; tnode_t *ntn; - int err; - - thp = topo_mod_handle(mp); + nvlist_t *auth; - if (topo_node_resource(parent, &pfmri, &err) < 0) { - topo_mod_seterrno(mp, err); - topo_mod_dprintf(mp, "Unable to retrieve parent resource.\n"); - return (NULL); - } - if (topo_mod_nvalloc(mp, &nvl, NV_UNIQUE_NAME) != 0) { - (void) topo_mod_seterrno(mp, EMOD_FMRI_NVL); - nvlist_free(pfmri); - return (NULL); - } - err = nvlist_add_nvlist(nvl, TOPO_METH_FMRI_ARG_PARENT, pfmri); - if (err != 0) { - nvlist_free(pfmri); - nvlist_free(nvl); - (void) topo_mod_seterrno(mp, EMOD_FMRI_NVL); - return (NULL); - } - - fmri = topo_fmri_create(thp, FM_FMRI_SCHEME_HC, name, i, nvl, &err); + auth = topo_mod_auth(mp, parent); + fmri = topo_mod_hcfmri(mp, parent, FM_HC_SCHEME_VERSION, name, i, NULL, + auth, NULL, NULL, NULL); + nvlist_free(auth); if (fmri == NULL) { - nvlist_free(pfmri); - nvlist_free(nvl); - topo_mod_seterrno(mp, err); topo_mod_dprintf(mp, "Unable to make nvlist for %s bind.\n", name); return (NULL); } - nvlist_free(pfmri); - nvlist_free(nvl); - ntn = topo_node_bind(mp, parent, name, i, fmri, priv); + ntn = topo_node_bind(mp, parent, name, i, fmri); if (ntn == NULL) { topo_mod_dprintf(mp, "topo_node_bind (%s%d/%s%d) failed: %s\n", @@ -116,6 +93,8 @@ tnode_create(topo_mod_t *mp, tnode_t *parent, return (NULL); } nvlist_free(fmri); + topo_node_setspecific(ntn, priv); + return (ntn); } diff --git a/usr/src/lib/fm/topo/modules/common/util.h b/usr/src/lib/fm/topo/modules/common/pcibus/util.h index 8dda2b6304..8dda2b6304 100644 --- a/usr/src/lib/fm/topo/modules/common/util.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/util.h diff --git a/usr/src/lib/fm/topo/modules/common/pcifn_enum.c b/usr/src/lib/fm/topo/modules/common/pcifn_enum.c deleted file mode 100644 index 30ae12c372..0000000000 --- a/usr/src/lib/fm/topo/modules/common/pcifn_enum.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <limits.h> -#include <fm/libtopo.h> -#include "did.h" -#include "did_props.h" -#include "pcifn_enum.h" - -static topo_mod_t * -module_load(topo_mod_t *mp, tnode_t *parent, const char *name) -{ - topo_mod_t *rp = NULL; - char *plat, *mach; - char *path; - char *rootdir; - int err; - - plat = mach = NULL; - - if (topo_prop_get_string(parent, - TOPO_PGROUP_SYSTEM, TOPO_PROP_PLATFORM, &plat, &err) < 0) { - (void) topo_mod_seterrno(mp, err); - return (NULL); - } - if (topo_prop_get_string(parent, - TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, &mach, &err) < 0) { - (void) topo_mod_seterrno(mp, err); - return (NULL); - } - path = topo_mod_alloc(mp, PATH_MAX); - rootdir = topo_mod_rootdir(mp); - (void) snprintf(path, PATH_MAX, - PATH_TEMPLATE, rootdir ? rootdir : "", plat, name); - - if ((rp = topo_mod_load(mp, path)) == NULL) { - topo_mod_dprintf(mp, "Unable to load %s.\n", path); - (void) snprintf(path, PATH_MAX, - PATH_TEMPLATE, rootdir ? rootdir : "", mach, name); - if ((rp = topo_mod_load(mp, path)) == NULL) - topo_mod_dprintf(mp, "Unable to load %s.\n", path); - } - topo_mod_strfree(mp, plat); - topo_mod_strfree(mp, mach); - topo_mod_free(mp, path, PATH_MAX); - return (rp); -} - -static int -module_run(topo_mod_t *mp, tnode_t *parent, pfn_enum_t *ep) -{ - return (topo_mod_enumerate(mp, parent, - ep->pfne_modname, ep->pfne_childname, - ep->pfne_imin, ep->pfne_imax)); -} - -int -pcifn_enum(topo_mod_t *mp, tnode_t *parent) -{ - char *ccstr; - int rv = 0; - int i, e; - uint_t cc; - topo_mod_t *child_mod; - - topo_mod_dprintf(mp, "Enumerating beneath pci(ex) function.\n"); - - /* - * Extract the class code of the PCI function and make sure - * it matches the type that the module cares about. - */ - if (topo_prop_get_string(parent, - TOPO_PGROUP_PCI, TOPO_PROP_CLASS, &ccstr, &e) < 0) - return (0); - if (sscanf(ccstr, "%x", &cc) != 1) { - topo_mod_strfree(mp, ccstr); - return (0); - } - topo_mod_strfree(mp, ccstr); - cc = cc >> 16; - - for (i = 0; i < Pcifn_enumerator_count; i++) { - - if (cc != Pcifn_enumerators[i].pfne_class) - continue; - - child_mod = module_load(mp, parent, - Pcifn_enumerators[i].pfne_modname); - - if (child_mod) { - rv = module_run(mp, parent, - &Pcifn_enumerators[i]) != 0 ? -1 : 0; - topo_mod_unload(child_mod); - } - } - return (rv); -} diff --git a/usr/src/lib/fm/topo/modules/common/pcifn_enum.h b/usr/src/lib/fm/topo/modules/common/pcifn_enum.h deleted file mode 100644 index 26f5f60225..0000000000 --- a/usr/src/lib/fm/topo/modules/common/pcifn_enum.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PCIFN_ENUM_H -#define _PCIFN_ENUM_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <sys/types.h> -#include <sys/pci.h> -#include <fm/topo_mod.h> - -#define PATH_TEMPLATE "%s/usr/platform/%s/lib/fm/topo/plugins/%s.so" - -/* - * When a pci or pci-express function is enumerated in the topology - * we'll attempt to load modules that can expand the topology - * beneath that function. This data structure helps us track which modules - * to attempt to load, whether or not the loading was successful - * so we don't waste time trying again, and if loading is successful, - * the module pointer returned by topo_mod_load(). - */ -typedef struct pfn_enum { - uint_t pfne_class; /* expected PCI class of the parent function */ - const char *pfne_modname; /* enumerator module name */ - const char *pfne_childname; /* name of nodes to enumerate */ - topo_instance_t pfne_imin; /* minimum instance number to enumerate */ - topo_instance_t pfne_imax; /* maximum instance number to enumerate */ -} pfn_enum_t; - -/* - * The current list of modules to potentially load and expand topology - * beneath pci(-express) functions. - */ -pfn_enum_t Pcifn_enumerators[] = { - { PCI_CLASS_MASS, "sata", "sata-port", 0, 7 }, - { PCI_CLASS_MASS, "scsi", "disk", 0, 15 } -}; - -int Pcifn_enumerator_count = sizeof (Pcifn_enumerators) / sizeof (pfn_enum_t); - -#endif /* _PCIFN_ENUM_H */ |
