xref: /onnv-gate/usr/src/lib/fm/topo/modules/i86pc/x86pi/x86pi_chassis.c (revision 12832:f4172e28e09f)
110942STom.Pothier@Sun.COM /*
210942STom.Pothier@Sun.COM  * CDDL HEADER START
310942STom.Pothier@Sun.COM  *
410942STom.Pothier@Sun.COM  * The contents of this file are subject to the terms of the
510942STom.Pothier@Sun.COM  * Common Development and Distribution License (the "License").
610942STom.Pothier@Sun.COM  * You may not use this file except in compliance with the License.
710942STom.Pothier@Sun.COM  *
810942STom.Pothier@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
910942STom.Pothier@Sun.COM  * or http://www.opensolaris.org/os/licensing.
1010942STom.Pothier@Sun.COM  * See the License for the specific language governing permissions
1110942STom.Pothier@Sun.COM  * and limitations under the License.
1210942STom.Pothier@Sun.COM  *
1310942STom.Pothier@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
1410942STom.Pothier@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1510942STom.Pothier@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
1610942STom.Pothier@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
1710942STom.Pothier@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
1810942STom.Pothier@Sun.COM  *
1910942STom.Pothier@Sun.COM  * CDDL HEADER END
2010942STom.Pothier@Sun.COM  */
2110942STom.Pothier@Sun.COM 
2210942STom.Pothier@Sun.COM /*
23*12832STrang.Do@Sun.COM  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2410942STom.Pothier@Sun.COM  */
2510942STom.Pothier@Sun.COM 
2610942STom.Pothier@Sun.COM /*
2710942STom.Pothier@Sun.COM  * Create chassis topology node from SMBIOS Type 3 structure
2810942STom.Pothier@Sun.COM  */
2910942STom.Pothier@Sun.COM 
3010942STom.Pothier@Sun.COM #include <sys/types.h>
3110942STom.Pothier@Sun.COM #include <strings.h>
3210942STom.Pothier@Sun.COM #include <fm/topo_mod.h>
3310942STom.Pothier@Sun.COM #include <fm/topo_hc.h>
3410942STom.Pothier@Sun.COM #include <sys/systeminfo.h>
3510942STom.Pothier@Sun.COM #include <sys/smbios_impl.h>
3610942STom.Pothier@Sun.COM #include <x86pi_impl.h>
3710942STom.Pothier@Sun.COM 
3810942STom.Pothier@Sun.COM 
3910942STom.Pothier@Sun.COM tnode_t *
x86pi_gen_chassis(topo_mod_t * mod,tnode_t * t_parent,int smb_id,int instance)40*12832STrang.Do@Sun.COM x86pi_gen_chassis(topo_mod_t *mod, tnode_t *t_parent, int smb_id, int instance)
4110942STom.Pothier@Sun.COM {
4210942STom.Pothier@Sun.COM 	int			rv;
4310942STom.Pothier@Sun.COM 	smbios_info_t		ip;
4410942STom.Pothier@Sun.COM 	smbios_chassis_t	ch;
4510942STom.Pothier@Sun.COM 	x86pi_hcfmri_t		ch_hcfmri;
4610942STom.Pothier@Sun.COM 	tnode_t			*ch_node;
4710942STom.Pothier@Sun.COM 	char			*f = "x86pi_gen_chassis";
48*12832STrang.Do@Sun.COM 	smbios_hdl_t		*shp;
4910942STom.Pothier@Sun.COM 
50*12832STrang.Do@Sun.COM 	shp = topo_mod_smbios(mod);
51*12832STrang.Do@Sun.COM 	if (shp == NULL) {
52*12832STrang.Do@Sun.COM 		topo_mod_dprintf(mod, "%s: failed to load SMBIOS\n", f);
53*12832STrang.Do@Sun.COM 		return (NULL);
54*12832STrang.Do@Sun.COM 	}
5510942STom.Pothier@Sun.COM 
5610942STom.Pothier@Sun.COM 	/* init fmri struct */
5710942STom.Pothier@Sun.COM 	bzero(&ch_hcfmri, sizeof (x86pi_hcfmri_t));
5810942STom.Pothier@Sun.COM 
5910942STom.Pothier@Sun.COM 	/* grab SMBIOS strings */
6010942STom.Pothier@Sun.COM 	rv = smbios_info_common(shp, smb_id, &ip);
6110942STom.Pothier@Sun.COM 	if (rv != 0) {
6210942STom.Pothier@Sun.COM 		return (NULL);
6310942STom.Pothier@Sun.COM 	}
6410942STom.Pothier@Sun.COM 
6510942STom.Pothier@Sun.COM 	/* grab SMBIOS type 3 struct */
6610942STom.Pothier@Sun.COM 	rv = smbios_info_chassis(shp, smb_id, &ch);
6710942STom.Pothier@Sun.COM 	if (rv != 0) {
6810942STom.Pothier@Sun.COM 		return (NULL);
6910942STom.Pothier@Sun.COM 	}
7010942STom.Pothier@Sun.COM 
7110942STom.Pothier@Sun.COM 	/* populate string entries */
7210942STom.Pothier@Sun.COM 	ch_hcfmri.serial_number = x86pi_cleanup_smbios_str(mod,
7310942STom.Pothier@Sun.COM 	    ip.smbi_serial, 0);
7410942STom.Pothier@Sun.COM 	ch_hcfmri.version = x86pi_cleanup_smbios_str(mod, ip.smbi_version, 0);
7510942STom.Pothier@Sun.COM 	ch_hcfmri.manufacturer = x86pi_cleanup_smbios_str(mod,
7610942STom.Pothier@Sun.COM 	    ip.smbi_manufacturer, 0);
7710942STom.Pothier@Sun.COM 
7810942STom.Pothier@Sun.COM 	/* set hc_name and instance */
7910942STom.Pothier@Sun.COM 	ch_hcfmri.hc_name = topo_mod_strdup(mod, "chassis");
8010942STom.Pothier@Sun.COM 	ch_hcfmri.instance = instance;
8110942STom.Pothier@Sun.COM 
8210942STom.Pothier@Sun.COM 	topo_mod_dprintf(mod, "%s: instance (%d)\n", f, ch_hcfmri.instance);
8310942STom.Pothier@Sun.COM 	topo_mod_dprintf(mod, "%s: hc name (%s)\n", f, ch_hcfmri.hc_name);
8410942STom.Pothier@Sun.COM 	topo_mod_dprintf(mod, "%s: Serial Number (%s)\n",
8510942STom.Pothier@Sun.COM 	    f, ch_hcfmri.serial_number);
8610942STom.Pothier@Sun.COM 	topo_mod_dprintf(mod, "%s: Version (%s)\n", f, ch_hcfmri.version);
8710942STom.Pothier@Sun.COM 	topo_mod_dprintf(mod, "%s: Manufacturer (%s)\n",
8810942STom.Pothier@Sun.COM 	    f, ch_hcfmri.manufacturer);
8910942STom.Pothier@Sun.COM 
9010942STom.Pothier@Sun.COM 	/* create topo node */
9110942STom.Pothier@Sun.COM 	if (!instance) {
9210942STom.Pothier@Sun.COM 		/* First Chassis SMBIOS Record is Chassis topo instance 0 */
9310942STom.Pothier@Sun.COM 		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, NULL,
9410942STom.Pothier@Sun.COM 		    &ch_node, 0);
9510942STom.Pothier@Sun.COM 	} else {
9610942STom.Pothier@Sun.COM 		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, t_parent,
9710942STom.Pothier@Sun.COM 		    &ch_node, 0);
9810942STom.Pothier@Sun.COM 	}
9910942STom.Pothier@Sun.COM 	if (rv != 0) {
10010942STom.Pothier@Sun.COM 		topo_mod_dprintf(mod, "%s: failed to create %d tnode\n", f,
10110942STom.Pothier@Sun.COM 		    instance);
10210942STom.Pothier@Sun.COM 		return (NULL);
10310942STom.Pothier@Sun.COM 	}
10410942STom.Pothier@Sun.COM 
10510942STom.Pothier@Sun.COM 	/* free up strings */
10610942STom.Pothier@Sun.COM 	if (ch_hcfmri.serial_number != NULL) {
10710942STom.Pothier@Sun.COM 		topo_mod_strfree(mod, (char *)ch_hcfmri.serial_number);
10810942STom.Pothier@Sun.COM 	}
10910942STom.Pothier@Sun.COM 	if (ch_hcfmri.version != NULL) {
11010942STom.Pothier@Sun.COM 		topo_mod_strfree(mod, (char *)ch_hcfmri.version);
11110942STom.Pothier@Sun.COM 	}
11210942STom.Pothier@Sun.COM 	if (ch_hcfmri.manufacturer != NULL) {
11310942STom.Pothier@Sun.COM 		topo_mod_strfree(mod, (char *)ch_hcfmri.manufacturer);
11410942STom.Pothier@Sun.COM 	}
11510942STom.Pothier@Sun.COM 	if (ch_hcfmri.hc_name != NULL) {
11610942STom.Pothier@Sun.COM 		topo_mod_strfree(mod, (char *)ch_hcfmri.hc_name);
11710942STom.Pothier@Sun.COM 	}
11810942STom.Pothier@Sun.COM 
11910942STom.Pothier@Sun.COM 	return (ch_node);
12010942STom.Pothier@Sun.COM }
121