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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Create chassis topology node from SMBIOS Type 3 structure
29  */
30 
31 #include <sys/types.h>
32 #include <strings.h>
33 #include <fm/topo_mod.h>
34 #include <fm/topo_hc.h>
35 #include <sys/systeminfo.h>
36 #include <sys/smbios_impl.h>
37 #include <x86pi_impl.h>
38 
39 
40 tnode_t *
41 x86pi_gen_chassis(topo_mod_t *mod, tnode_t *t_parent, smbios_hdl_t *shp,
42     int smb_id, int instance)
43 {
44 	int			rv;
45 	smbios_info_t		ip;
46 	smbios_chassis_t	ch;
47 	x86pi_hcfmri_t		ch_hcfmri;
48 	tnode_t			*ch_node;
49 	char			*f = "x86pi_gen_chassis";
50 
51 
52 	/* init fmri struct */
53 	bzero(&ch_hcfmri, sizeof (x86pi_hcfmri_t));
54 
55 	/* grab SMBIOS strings */
56 	rv = smbios_info_common(shp, smb_id, &ip);
57 	if (rv != 0) {
58 		return (NULL);
59 	}
60 
61 	/* grab SMBIOS type 3 struct */
62 	rv = smbios_info_chassis(shp, smb_id, &ch);
63 	if (rv != 0) {
64 		return (NULL);
65 	}
66 
67 	/* populate string entries */
68 	ch_hcfmri.serial_number = x86pi_cleanup_smbios_str(mod,
69 	    ip.smbi_serial, 0);
70 	ch_hcfmri.version = x86pi_cleanup_smbios_str(mod, ip.smbi_version, 0);
71 	ch_hcfmri.manufacturer = x86pi_cleanup_smbios_str(mod,
72 	    ip.smbi_manufacturer, 0);
73 
74 	/* set hc_name and instance */
75 	ch_hcfmri.hc_name = topo_mod_strdup(mod, "chassis");
76 	ch_hcfmri.instance = instance;
77 
78 	topo_mod_dprintf(mod, "%s: instance (%d)\n", f, ch_hcfmri.instance);
79 	topo_mod_dprintf(mod, "%s: hc name (%s)\n", f, ch_hcfmri.hc_name);
80 	topo_mod_dprintf(mod, "%s: Serial Number (%s)\n",
81 	    f, ch_hcfmri.serial_number);
82 	topo_mod_dprintf(mod, "%s: Version (%s)\n", f, ch_hcfmri.version);
83 	topo_mod_dprintf(mod, "%s: Manufacturer (%s)\n",
84 	    f, ch_hcfmri.manufacturer);
85 
86 	/* create topo node */
87 	if (!instance) {
88 		/* First Chassis SMBIOS Record is Chassis topo instance 0 */
89 		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, NULL,
90 		    &ch_node, 0);
91 	} else {
92 		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, t_parent,
93 		    &ch_node, 0);
94 	}
95 	if (rv != 0) {
96 		topo_mod_dprintf(mod, "%s: failed to create %d tnode\n", f,
97 		    instance);
98 		return (NULL);
99 	}
100 
101 	/* free up strings */
102 	if (ch_hcfmri.serial_number != NULL) {
103 		topo_mod_strfree(mod, (char *)ch_hcfmri.serial_number);
104 	}
105 	if (ch_hcfmri.version != NULL) {
106 		topo_mod_strfree(mod, (char *)ch_hcfmri.version);
107 	}
108 	if (ch_hcfmri.manufacturer != NULL) {
109 		topo_mod_strfree(mod, (char *)ch_hcfmri.manufacturer);
110 	}
111 	if (ch_hcfmri.hc_name != NULL) {
112 		topo_mod_strfree(mod, (char *)ch_hcfmri.hc_name);
113 	}
114 
115 	return (ch_node);
116 }
117