xref: /illumos-gate/usr/src/lib/fm/topo/modules/i86pc/x86pi/x86pi_chassis.c (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 /*
27  * Create chassis topology node from SMBIOS Type 3 structure
28  */
29 
30 #include <sys/types.h>
31 #include <strings.h>
32 #include <fm/topo_mod.h>
33 #include <fm/topo_hc.h>
34 #include <sys/systeminfo.h>
35 #include <sys/smbios_impl.h>
36 #include <x86pi_impl.h>
37 
38 
39 tnode_t *
x86pi_gen_chassis(topo_mod_t * mod,tnode_t * t_parent,int smb_id,int instance)40 x86pi_gen_chassis(topo_mod_t *mod, tnode_t *t_parent, int smb_id, int instance)
41 {
42 	int			rv;
43 	smbios_info_t		ip;
44 	smbios_chassis_t	ch;
45 	x86pi_hcfmri_t		ch_hcfmri;
46 	tnode_t			*ch_node;
47 	char			*f = "x86pi_gen_chassis";
48 	smbios_hdl_t		*shp;
49 
50 	shp = topo_mod_smbios(mod);
51 	if (shp == NULL) {
52 		topo_mod_dprintf(mod, "%s: failed to load SMBIOS\n", f);
53 		return (NULL);
54 	}
55 
56 	/* init fmri struct */
57 	bzero(&ch_hcfmri, sizeof (x86pi_hcfmri_t));
58 
59 	/* grab SMBIOS strings */
60 	rv = smbios_info_common(shp, smb_id, &ip);
61 	if (rv != 0) {
62 		return (NULL);
63 	}
64 
65 	/* grab SMBIOS type 3 struct */
66 	rv = smbios_info_chassis(shp, smb_id, &ch);
67 	if (rv != 0) {
68 		return (NULL);
69 	}
70 
71 	/* populate string entries */
72 	ch_hcfmri.serial_number = x86pi_cleanup_smbios_str(mod,
73 	    ip.smbi_serial, 0);
74 	ch_hcfmri.version = x86pi_cleanup_smbios_str(mod, ip.smbi_version, 0);
75 	ch_hcfmri.manufacturer = x86pi_cleanup_smbios_str(mod,
76 	    ip.smbi_manufacturer, 0);
77 
78 	/* set hc_name and instance */
79 	ch_hcfmri.hc_name = topo_mod_strdup(mod, "chassis");
80 	ch_hcfmri.instance = instance;
81 
82 	topo_mod_dprintf(mod, "%s: instance (%d)\n", f, ch_hcfmri.instance);
83 	topo_mod_dprintf(mod, "%s: hc name (%s)\n", f, ch_hcfmri.hc_name);
84 	topo_mod_dprintf(mod, "%s: Serial Number (%s)\n",
85 	    f, ch_hcfmri.serial_number);
86 	topo_mod_dprintf(mod, "%s: Version (%s)\n", f, ch_hcfmri.version);
87 	topo_mod_dprintf(mod, "%s: Manufacturer (%s)\n",
88 	    f, ch_hcfmri.manufacturer);
89 
90 	/* create topo node */
91 	if (!instance) {
92 		/* First Chassis SMBIOS Record is Chassis topo instance 0 */
93 		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, NULL,
94 		    &ch_node, 0);
95 	} else {
96 		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, t_parent,
97 		    &ch_node, 0);
98 	}
99 	if (rv != 0) {
100 		topo_mod_dprintf(mod, "%s: failed to create %d tnode\n", f,
101 		    instance);
102 		return (NULL);
103 	}
104 
105 	/* free up strings */
106 	if (ch_hcfmri.serial_number != NULL) {
107 		topo_mod_strfree(mod, (char *)ch_hcfmri.serial_number);
108 	}
109 	if (ch_hcfmri.version != NULL) {
110 		topo_mod_strfree(mod, (char *)ch_hcfmri.version);
111 	}
112 	if (ch_hcfmri.manufacturer != NULL) {
113 		topo_mod_strfree(mod, (char *)ch_hcfmri.manufacturer);
114 	}
115 	if (ch_hcfmri.hc_name != NULL) {
116 		topo_mod_strfree(mod, (char *)ch_hcfmri.hc_name);
117 	}
118 
119 	return (ch_node);
120 }
121