x86pi.c revision 03f9f63d24f0494b7d47b927090ad9045e396402
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/*
2N/A * x86 Generic FMA Topology Enumerator
2N/A */
2N/A
2N/A
2N/A#include <fcntl.h>
2N/A#include <unistd.h>
2N/A#include <sys/types.h>
2N/A#include <strings.h>
2N/A#include <sys/fcntl.h>
2N/A#include <fm/topo_mod.h>
2N/A#include <fm/topo_hc.h>
2N/A#include <sys/systeminfo.h>
2N/A#include <sys/smbios.h>
2N/A#include <sys/smbios_impl.h>
2N/A#include <sys/fm/protocol.h>
2N/A#include <x86pi_impl.h>
2N/A
2N/A
2N/Astatic int x86pi_enum_start(topo_mod_t *, x86pi_enum_t *);
2N/Astatic int x86pi_enum_gentopo(topo_mod_t *, tnode_t *, smbios_hdl_t *);
2N/A
2N/A/*
2N/A * Entry point called by libtopo when enumeration is required
2N/A */
2N/Astatic topo_enum_f x86pi_enum; /* libtopo enumeration entry point */
2N/A
2N/A/*
2N/A * Declare the operations vector and information structure used during
2N/A * module registration
2N/A */
2N/Astatic topo_modops_t x86pi_ops =
2N/A { x86pi_enum, NULL };
2N/A
2N/Astatic topo_modinfo_t x86pi_modinfo =
2N/A { X86PI_DESC, X86PI_SCHEME, X86PI_VERSION, &x86pi_ops };
2N/A
2N/A/*
2N/A * Used to pass SMBIOS' FM compatibility to the
2N/A * chip enumerator
2N/A */
2N/Aint x86pi_smbios = 0;
2N/A
2N/A/*
2N/A * Called by libtopo when the topo module is loaded.
2N/A */
2N/Aint
2N/A_topo_init(topo_mod_t *mod, topo_version_t version)
2N/A{
2N/A int result;
2N/A char isa[MAXNAMELEN];
2N/A
2N/A if (getenv("TOPOX86PIDBG") != NULL) {
2N/A /* Debugging is requested for this module */
2N/A topo_mod_setdebug(mod);
2N/A }
2N/A topo_mod_dprintf(mod, "module initializing.\n");
2N/A
2N/A if (version != TOPO_VERSION) {
2N/A (void) topo_mod_seterrno(mod, EMOD_VER_NEW);
2N/A topo_mod_dprintf(mod, "incompatible topo version %d\n",
2N/A version);
2N/A return (-1);
2N/A }
2N/A
2N/A /* Verify that this is a i86pc architecture machine */
2N/A (void) sysinfo(SI_MACHINE, isa, MAXNAMELEN);
2N/A if (strncmp(isa, "i86pc", MAXNAMELEN) != 0) {
2N/A topo_mod_dprintf(mod, "not i86pc architecture: %s\n", isa);
2N/A return (-1);
2N/A }
2N/A
2N/A result = topo_mod_register(mod, &x86pi_modinfo, TOPO_VERSION);
2N/A if (result < 0) {
2N/A topo_mod_dprintf(mod, "registration failed: %s\n",
2N/A topo_mod_errmsg(mod));
2N/A /* module errno already set */
2N/A return (-1);
2N/A }
2N/A topo_mod_dprintf(mod, "module ready.\n");
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Clean up any data used by the module before it is unloaded.
2N/A */
2N/Avoid
2N/A_topo_fini(topo_mod_t *mod)
2N/A{
2N/A topo_mod_dprintf(mod, "module finishing.\n");
2N/A
2N/A x86pi_hbr_enum_fini(mod);
2N/A
2N/A /* Unregister from libtopo */
2N/A topo_mod_unregister(mod);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Enumeration entry point for the x86 Generic topology enumerator
2N/A */
2N/A/* ARGSUSED */
2N/Astatic int
2N/Ax86pi_enum(topo_mod_t *mod, tnode_t *t_parent, const char *name,
2N/A topo_instance_t min, topo_instance_t max, void *pi_private, void *data)
2N/A{
2N/A int result;
2N/A hrtime_t starttime;
2N/A x86pi_enum_t x86pi;
2N/A
2N/A /* Begin enumeration */
2N/A starttime = gethrtime();
2N/A topo_mod_dprintf(mod, "enumeration starting.\n");
2N/A
2N/A /*
2N/A * Let's do some enumeration.
2N/A */
2N/A bzero(&x86pi, sizeof (x86pi_enum_t));
2N/A x86pi.t_parent = t_parent;
2N/A result = x86pi_enum_start(mod, &x86pi);
2N/A if (result != 0) {
2N/A topo_mod_dprintf(mod, "Enumeration failed.\n");
2N/A return (-1);
2N/A }
2N/A
2N/A /* Complete enumeration */
2N/A topo_mod_dprintf(mod, "enumeration complete in %lld ms.\n",
2N/A ((gethrtime() - starttime)/MICROSEC));
2N/A
2N/A /* All done */
2N/A return (result);
2N/A}
2N/A
2N/Astatic int
2N/Ax86pi_enum_start(topo_mod_t *mod, x86pi_enum_t *x86pi)
2N/A{
2N/A int rv;
2N/A int complvl = 0;
2N/A smbios_hdl_t *shp;
2N/A char *f = "x86pi_enum_start";
2N/A
2N/A /*
2N/A * Verify BIOS compliance.
2N/A */
2N/A shp = x86pi_smb_open(mod);
2N/A if (shp == NULL) {
2N/A topo_mod_dprintf(mod, "%s: failed to open SMBIOS\n", f);
2N/A complvl = X86PI_NONE;
2N/A } else {
2N/A complvl = x86pi_check_comp(mod, shp);
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s: SMBIOS x86pi compliance: %s\n", f,
2N/A complvl == X86PI_FULL ? "FULL" : "NONE");
2N/A
2N/A if (complvl == X86PI_NONE) {
/* fall back to legacy enumeration */
topo_mod_dprintf(mod,
"%s: Calling legacy enumeration\n", f);
return (topo_mod_enummap(mod, x86pi->t_parent,
"i86pc-legacy", FM_FMRI_SCHEME_HC));
}
x86pi->priv = (void *)shp;
x86pi_smbios = complvl;
if (x86pi_hbr_enum_init(mod) < 0) {
topo_mod_dprintf(mod, "%s: x86pi_hbr_enum_init() failed.\n", f);
return (-1);
}
/*
* Create the topology.
*/
fac_done = 0;
rv = x86pi_enum_gentopo(mod, x86pi->t_parent, shp);
if (rv != 0) {
return (-1);
}
x86pi->mod = mod;
if (fac_done == 0) {
(void) topo_mod_enummap(mod, x86pi->t_parent, "chassis",
FM_FMRI_SCHEME_HC);
(void) topo_mod_enummap(mod, x86pi->t_parent, "fan",
FM_FMRI_SCHEME_HC);
(void) topo_mod_enummap(mod, x86pi->t_parent, "psu",
FM_FMRI_SCHEME_HC);
}
/* All done */
topo_mod_dprintf(mod, "%s: done.\n", f);
return (rv);
}
/*
* Create the i86pc topology
*
* If either Type 2 or Type 3 structures have contained elements/handles,
* walk them creating the topo.
*
* If there are no contained elements/handles, build this topo:
*
* Main Chassis
* Motherboard
* CMP Chip/Core/Strands
* Memory Controllers/Memory Devices (DIMMs)
* PCIE HostBrige
* PCIE Root Complex
*
*/
static int
x86pi_enum_gentopo(topo_mod_t *mod, tnode_t *t_parent, smbios_hdl_t *shp)
{
int rv;
int nch, nbb, ncmp, i;
int ch_smbid, bb_smbid;
tnode_t *chassis_node = NULL;
tnode_t *basebd_node = NULL;
smbs_cnt_t *smbc;
tnode_t *motherchassis_node = NULL;
tnode_t *pnode = NULL;
id_t psmbid;
int notvisited;
int bb_count, ch_count;
int min, max;
int ch_inst = 0;
int disk_inst = 0;
topo_instance_t hbri = 0, rci = 0;
smbios_pciexrc_t hbr;
smbios_port_ext_t export;
char *f = "x86pi_enum_gentopo";
if (t_parent == NULL) {
topo_mod_dprintf(mod, "%s: NULL parent\n", f);
return (-1);
}
/*
* "Chassis'"
*/
/* Type 3 structs */
stypes[SMB_TYPE_CHASSIS].type = SMB_TYPE_CHASSIS;
x86pi_smb_strcnt(shp, &stypes[SMB_TYPE_CHASSIS]);
ch_count = stypes[SMB_TYPE_CHASSIS].count;
for (nch = 0; nch < ch_count; nch++) {
topo_mod_dprintf(mod, "%s: found %d chassis\n", f,
stypes[SMB_TYPE_CHASSIS].count);
ch_smbid = stypes[SMB_TYPE_CHASSIS].ids[nch].id;
/*
* Expect SMBIOS to set the first Chassis Structure to be the
* parent/mother of all chassis
*/
if (nch == 0)
motherchassis_node = chassis_node =
x86pi_gen_chassis(mod, t_parent, shp,
ch_smbid, ch_inst++);
else {
if (motherchassis_node != NULL)
chassis_node = x86pi_gen_chassis(mod,
motherchassis_node, shp,
ch_smbid, ch_inst++);
else
chassis_node = x86pi_gen_chassis(mod,
t_parent, shp, ch_smbid, ch_inst++);
}
if (chassis_node == NULL) {
topo_mod_dprintf(mod,
"%s: Failed to create chassis %d\n", f, nch);
continue;
}
stypes[SMB_TYPE_CHASSIS].ids[nch].node = chassis_node;
/* count SMBIOS extended port connector structures */
smbc = &stypes[SUN_OEM_EXT_PORT];
smbc->type = SUN_OEM_EXT_PORT;
x86pi_smb_strcnt(shp, smbc);
/* enumerate direct attached SATA disks */
rv = topo_node_range_create(mod, chassis_node, BAY, 0,
smbc->count + 1);
if (rv != 0) {
topo_mod_dprintf(mod,
"%s: Failed to create %s range: %s\n",
f, BAY, topo_mod_errmsg(mod));
continue;
}
for (i = 0; i < smbc->count; i++) {
if (smbios_info_extport(shp, smbc->ids[i].id,
&export) != 0) {
topo_mod_dprintf(mod,
"smbios_info_export failed: id = %d\n",
(int)smbc->ids[i].id);
continue;
}
if (export.smbporte_chassis != ch_smbid)
continue;
/*
* x86pi_gen_bay:
* create "bay" node
* call "disk" enum passing in "bay" node
*/
rv = x86pi_gen_bay(mod, chassis_node, shp,
&export, disk_inst);
if (rv != 0)
topo_mod_dprintf(mod,
"Failed to create disk %d\n", i);
disk_inst++;
}
}
/*
* "Base Board"
*/
/* Type 2 structs */
stypes[SMB_TYPE_BASEBOARD].type = SMB_TYPE_BASEBOARD;
x86pi_smb_strcnt(shp, &stypes[SMB_TYPE_BASEBOARD]);
bb_count = notvisited = stypes[SMB_TYPE_BASEBOARD].count;
for (nbb = 0; nbb < bb_count; nbb++) {
stypes[SMB_TYPE_BASEBOARD].ids[nbb].visited = 0;
stypes[SMB_TYPE_BASEBOARD].ids[nbb].con_by_id = 0;
stypes[SMB_TYPE_BASEBOARD].ids[nbb].node = NULL;
}
(void) x86pi_bb_contains(mod, shp);
min = 0;
nbb = 0;
do {
/*
* We have reached end of the array due to the
* parent-child relationship, without visiting all
* baseboards! so re-iterate..
* (or)
* All baseboards are visited and their contained
* processors are enumerated
* (and/or)
* More baseboards pending a visit
*/
if (nbb > bb_count && notvisited)
nbb = 0;
else if (nbb > bb_count && !notvisited)
break;
if (stypes[SMB_TYPE_BASEBOARD].ids[nbb].visited ==
X86PI_VISITED) {
nbb++;
continue;
}
/*
* Get the Top-most Parent Baseboard, irrespective
* of its index in the array of Type-2s
* If this Baseboard has no Baseboard parents
* place it under the chassis that contains it
*/
bb_smbid = x86pi_bb_topparent(shp, nbb, &pnode, &psmbid);
if (bb_smbid == -1 || pnode == NULL) {
topo_mod_dprintf(mod,
"Failed to get BaseBoard node (%d): parent\n",
nbb);
return (-1);
}
if (stypes[SMB_TYPE_BASEBOARD].ids[nbb].id != bb_smbid) {
for (int i = 0; i < bb_count; i++) {
if (bb_smbid ==
stypes[SMB_TYPE_BASEBOARD].ids[i].id) {
stypes[SMB_TYPE_BASEBOARD].ids[i].\
visited = 1;
notvisited--;
break;
}
}
} else {
stypes[SMB_TYPE_BASEBOARD].ids[nbb].visited = 1;
notvisited--;
}
basebd_node = x86pi_gen_bboard(mod, pnode, shp,
bb_smbid, nbb, psmbid);
if (basebd_node == NULL) {
topo_mod_dprintf(mod,
"Failed to create BaseBoard node (%d)\n", nbb);
nbb++;
continue;
}
stypes[SMB_TYPE_BASEBOARD].ids[nbb].node = basebd_node;
/*
* Look for contained handles here and if there are
* make sure the chip handle below is part of it.
*/
ncmp = x86pi_bb_getchips(mod, shp, nbb, bb_count);
if (ncmp > 0) {
max = min + ncmp - 1;
/* make sure the chip enum is loaded */
topo_mod_dprintf(mod, "%s: loading chip enum\n", f);
if (topo_mod_load(mod, CHIP, TOPO_VERSION) == NULL) {
topo_mod_dprintf(mod,
"%s: Failed to load %s module: %s\n", f,
CHIP, topo_strerror(topo_mod_errno(mod)));
} else {
/* create node range */
topo_mod_dprintf(mod,
"%s: chip range %d to %d\n",
f, min, max);
rv = topo_node_range_create(mod, basebd_node,
CHIP, min, max);
if (rv != 0) {
topo_mod_dprintf(mod,
"%s: Failed to create node range: "
"%s\n", f,
topo_strerror(topo_mod_errno(mod)));
} else {
/* call the chip enumerator */
topo_mod_dprintf(mod, "%s: calling"
" chip enum\n", f);
rv =
topo_mod_enumerate(mod, basebd_node,
CHIP, CHIP, min, max,
&x86pi_smbios);
min = max + 1;
if (rv != 0)
topo_mod_dprintf(mod, "%s:%s"
"enumeration failed: \n",
f, CHIP);
}
}
}
/* enumerate the hostbridge node */
rv = topo_node_range_create(mod, basebd_node, HOSTBRIDGE,
0, 255);
if (rv != 0) {
topo_mod_dprintf(mod,
"%s: Failed to create %s range: %s\n",
f, HOSTBRIDGE, topo_mod_errmsg(mod));
continue;
}
smbc = &stypes[SUN_OEM_PCIEXRC];
smbc->type = SUN_OEM_PCIEXRC;
x86pi_smb_strcnt(shp, smbc);
for (i = 0; i < smbc->count; i++) {
if (smbios_info_pciexrc(shp, smbc->ids[i].id,
&hbr) != 0) {
topo_mod_dprintf(mod,
"smbios_info_pciexrc failed: "
"id = %d\n", (int)smbc->ids[i].id);
continue;
}
if (hbr.smbpcie_bb != bb_smbid)
continue;
rv = x86pi_gen_hbr(mod, basebd_node, shp,
smbc->ids[i].id, hbri, &rci);
if (rv != 0)
topo_mod_dprintf(mod,
"couldn't create hostbridge=%d\n", hbri);
hbri++;
}
nbb++;
} while (notvisited);
return (0);
}