xref: /onnv-gate/usr/src/cmd/smbios/smbios.c (revision 11859:f06d538b0f01)
1437Smws /*
2437Smws  * CDDL HEADER START
3437Smws  *
4437Smws  * 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.
7437Smws  *
8437Smws  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9437Smws  * or http://www.opensolaris.org/os/licensing.
10437Smws  * See the License for the specific language governing permissions
11437Smws  * and limitations under the License.
12437Smws  *
13437Smws  * When distributing Covered Code, include this CDDL HEADER in each
14437Smws  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15437Smws  * If applicable, add the following below this CDDL HEADER, with the
16437Smws  * fields enclosed by brackets "[]" replaced with your own identifying
17437Smws  * information: Portions Copyright [yyyy] [name of copyright owner]
18437Smws  *
19437Smws  * CDDL HEADER END
20437Smws  */
21437Smws 
22437Smws /*
23*11859STom.Pothier@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24437Smws  * Use is subject to license terms.
25437Smws  */
26437Smws 
27437Smws #include <sys/sysmacros.h>
28437Smws #include <sys/param.h>
29437Smws 
30437Smws #include <smbios.h>
31437Smws #include <alloca.h>
32437Smws #include <limits.h>
33437Smws #include <unistd.h>
34437Smws #include <strings.h>
35437Smws #include <stdlib.h>
36437Smws #include <stdarg.h>
37437Smws #include <stdio.h>
38437Smws #include <fcntl.h>
39437Smws #include <errno.h>
40437Smws #include <ctype.h>
41437Smws 
42437Smws #define	SMBIOS_SUCCESS	0
43437Smws #define	SMBIOS_ERROR	1
44437Smws #define	SMBIOS_USAGE	2
45437Smws 
46437Smws static const char *g_pname;
47437Smws static int g_hdr;
48437Smws 
49437Smws static int opt_e;
50437Smws static int opt_i = -1;
51437Smws static int opt_O;
52437Smws static int opt_s;
53437Smws static int opt_t = -1;
54437Smws static int opt_x;
55437Smws 
56437Smws /*PRINTFLIKE2*/
57437Smws static void
oprintf(FILE * fp,const char * format,...)58437Smws oprintf(FILE *fp, const char *format, ...)
59437Smws {
60437Smws 	va_list ap;
61437Smws 
62437Smws 	va_start(ap, format);
63437Smws 	(void) vfprintf(fp, format, ap);
64437Smws 	va_end(ap);
65437Smws }
66437Smws 
67437Smws /*PRINTFLIKE3*/
68437Smws static void
desc_printf(const char * d,FILE * fp,const char * format,...)69437Smws desc_printf(const char *d, FILE *fp, const char *format, ...)
70437Smws {
71437Smws 	va_list ap;
72437Smws 
73437Smws 	va_start(ap, format);
74437Smws 	(void) vfprintf(fp, format, ap);
75437Smws 	va_end(ap);
76437Smws 
77437Smws 	if (d != NULL)
78437Smws 		(void) fprintf(fp, " (%s)\n", d);
79437Smws 	else
80437Smws 		(void) fprintf(fp, "\n");
81437Smws }
82437Smws 
83437Smws static void
flag_printf(FILE * fp,const char * s,uint_t flags,size_t bits,const char * (* flag_name)(uint_t),const char * (* flag_desc)(uint_t))84437Smws flag_printf(FILE *fp, const char *s, uint_t flags, size_t bits,
85437Smws     const char *(*flag_name)(uint_t), const char *(*flag_desc)(uint_t))
86437Smws {
87437Smws 	size_t i;
88437Smws 
89437Smws 	oprintf(fp, "  %s: 0x%x\n", s, flags);
90437Smws 
91437Smws 	for (i = 0; i < bits; i++) {
92437Smws 		uint_t f = 1 << i;
93437Smws 		const char *n;
94437Smws 
95437Smws 		if (!(flags & f))
96437Smws 			continue;
97437Smws 
98437Smws 		if ((n = flag_name(f)) != NULL)
99437Smws 			desc_printf(flag_desc(f), fp, "\t%s", n);
100437Smws 		else
101437Smws 			desc_printf(flag_desc(f), fp, "\t0x%x", f);
102437Smws 	}
103437Smws }
104437Smws 
105437Smws static void
flag64_printf(FILE * fp,const char * s,uint64_t flags,size_t bits,const char * (* flag_name)(uint64_t),const char * (* flag_desc)(uint64_t))106437Smws flag64_printf(FILE *fp, const char *s, uint64_t flags, size_t bits,
107437Smws     const char *(*flag_name)(uint64_t), const char *(*flag_desc)(uint64_t))
108437Smws {
109437Smws 	size_t i;
110437Smws 
111437Smws 	oprintf(fp, "  %s: 0x%llx\n", s, (u_longlong_t)flags);
112437Smws 
113437Smws 	for (i = 0; i < bits; i++) {
114437Smws 		u_longlong_t f = 1ULL << i;
115437Smws 		const char *n;
116437Smws 
117437Smws 		if (!(flags & f))
118437Smws 			continue;
119437Smws 
120437Smws 		if ((n = flag_name(f)) != NULL)
121437Smws 			desc_printf(flag_desc(f), fp, "\t%s", n);
122437Smws 		else
123437Smws 			desc_printf(flag_desc(f), fp, "\t0x%llx", f);
124437Smws 	}
125437Smws }
126437Smws 
127437Smws static void
id_printf(FILE * fp,const char * s,id_t id)128437Smws id_printf(FILE *fp, const char *s, id_t id)
129437Smws {
130437Smws 	switch (id) {
131437Smws 	case SMB_ID_NONE:
132437Smws 		oprintf(fp, "%sNone\n", s);
133437Smws 		break;
134437Smws 	case SMB_ID_NOTSUP:
135437Smws 		oprintf(fp, "%sNot Supported\n", s);
136437Smws 		break;
137437Smws 	default:
138437Smws 		oprintf(fp, "%s%u\n", s, (uint_t)id);
139437Smws 	}
140437Smws }
141437Smws 
142*11859STom.Pothier@Sun.COM static int
check_oem(smbios_hdl_t * shp)143*11859STom.Pothier@Sun.COM check_oem(smbios_hdl_t *shp)
144*11859STom.Pothier@Sun.COM {
145*11859STom.Pothier@Sun.COM 	int i;
146*11859STom.Pothier@Sun.COM 	int cnt;
147*11859STom.Pothier@Sun.COM 	int rv;
148*11859STom.Pothier@Sun.COM 	id_t oem_id;
149*11859STom.Pothier@Sun.COM 	smbios_struct_t s;
150*11859STom.Pothier@Sun.COM 	const char **oem_str;
151*11859STom.Pothier@Sun.COM 
152*11859STom.Pothier@Sun.COM 	rv = smbios_lookup_type(shp, SMB_TYPE_OEMSTR, &s);
153*11859STom.Pothier@Sun.COM 	if (rv != 0) {
154*11859STom.Pothier@Sun.COM 		return (-1);
155*11859STom.Pothier@Sun.COM 	}
156*11859STom.Pothier@Sun.COM 
157*11859STom.Pothier@Sun.COM 	oem_id = s.smbstr_id;
158*11859STom.Pothier@Sun.COM 
159*11859STom.Pothier@Sun.COM 	cnt = smbios_info_strtab(shp, oem_id, 0, NULL);
160*11859STom.Pothier@Sun.COM 	if (cnt > 0) {
161*11859STom.Pothier@Sun.COM 		oem_str =  alloca(sizeof (char *) * cnt);
162*11859STom.Pothier@Sun.COM 		(void) smbios_info_strtab(shp, oem_id, cnt, oem_str);
163*11859STom.Pothier@Sun.COM 
164*11859STom.Pothier@Sun.COM 		for (i = 0; i < cnt; i++) {
165*11859STom.Pothier@Sun.COM 			if (strncmp(oem_str[i], SMB_PRMS1,
166*11859STom.Pothier@Sun.COM 			    strlen(SMB_PRMS1) + 1) == 0) {
167*11859STom.Pothier@Sun.COM 				return (0);
168*11859STom.Pothier@Sun.COM 			}
169*11859STom.Pothier@Sun.COM 		}
170*11859STom.Pothier@Sun.COM 	}
171*11859STom.Pothier@Sun.COM 
172*11859STom.Pothier@Sun.COM 	return (-1);
173*11859STom.Pothier@Sun.COM }
174*11859STom.Pothier@Sun.COM 
175437Smws static void
print_smbios(smbios_hdl_t * shp,FILE * fp)176437Smws print_smbios(smbios_hdl_t *shp, FILE *fp)
177437Smws {
178437Smws 	smbios_entry_t ep;
179437Smws 	int i;
180437Smws 
181437Smws 	smbios_info_smbios(shp, &ep);
182437Smws 
183437Smws 	oprintf(fp, "Entry Point Anchor Tag: %*.*s\n",
184437Smws 	    (int)sizeof (ep.smbe_eanchor), (int)sizeof (ep.smbe_eanchor),
185437Smws 	    ep.smbe_eanchor);
186437Smws 
187437Smws 	oprintf(fp, "Entry Point Checksum: 0x%x\n", ep.smbe_ecksum);
188437Smws 	oprintf(fp, "Entry Point Length: %u\n", ep.smbe_elen);
189437Smws 	oprintf(fp, "Entry Point Version: %u.%u\n",
190437Smws 	    ep.smbe_major, ep.smbe_minor);
191437Smws 	oprintf(fp, "Max Structure Size: %u\n", ep.smbe_maxssize);
192437Smws 	oprintf(fp, "Entry Point Revision: 0x%x\n", ep.smbe_revision);
193437Smws 
194437Smws 	oprintf(fp, "Entry Point Revision Data:");
195437Smws 	for (i = 0; i < sizeof (ep.smbe_format); i++)
196437Smws 		oprintf(fp, " 0x%02x", ep.smbe_format[i]);
197437Smws 	oprintf(fp, "\n");
198437Smws 
199437Smws 	oprintf(fp, "Intermediate Anchor Tag: %*.*s\n",
200437Smws 	    (int)sizeof (ep.smbe_ianchor), (int)sizeof (ep.smbe_ianchor),
201437Smws 	    ep.smbe_ianchor);
202437Smws 
203437Smws 	oprintf(fp, "Intermediate Checksum: 0x%x\n", ep.smbe_icksum);
204437Smws 	oprintf(fp, "Structure Table Length: %u\n", ep.smbe_stlen);
205437Smws 	oprintf(fp, "Structure Table Address: 0x%x\n", ep.smbe_staddr);
206437Smws 	oprintf(fp, "Structure Table Entries: %u\n", ep.smbe_stnum);
207437Smws 	oprintf(fp, "DMI BCD Revision: 0x%x\n", ep.smbe_bcdrev);
208437Smws }
209437Smws 
210437Smws static void
print_common(const smbios_info_t * ip,FILE * fp)211437Smws print_common(const smbios_info_t *ip, FILE *fp)
212437Smws {
213437Smws 	if (ip->smbi_manufacturer[0] != '\0')
214437Smws 		oprintf(fp, "  Manufacturer: %s\n", ip->smbi_manufacturer);
215437Smws 	if (ip->smbi_product[0] != '\0')
216437Smws 		oprintf(fp, "  Product: %s\n", ip->smbi_product);
217437Smws 	if (ip->smbi_version[0] != '\0')
218437Smws 		oprintf(fp, "  Version: %s\n", ip->smbi_version);
219437Smws 	if (ip->smbi_serial[0] != '\0')
220437Smws 		oprintf(fp, "  Serial Number: %s\n", ip->smbi_serial);
221437Smws 	if (ip->smbi_asset[0] != '\0')
222437Smws 		oprintf(fp, "  Asset Tag: %s\n", ip->smbi_asset);
223437Smws 	if (ip->smbi_location[0] != '\0')
224437Smws 		oprintf(fp, "  Location Tag: %s\n", ip->smbi_location);
225437Smws 	if (ip->smbi_part[0] != '\0')
226437Smws 		oprintf(fp, "  Part Number: %s\n", ip->smbi_part);
227437Smws }
228437Smws 
229437Smws static void
print_bios(smbios_hdl_t * shp,FILE * fp)230437Smws print_bios(smbios_hdl_t *shp, FILE *fp)
231437Smws {
232437Smws 	smbios_bios_t b;
233437Smws 
234437Smws 	(void) smbios_info_bios(shp, &b);
235437Smws 
236437Smws 	oprintf(fp, "  Vendor: %s\n", b.smbb_vendor);
237437Smws 	oprintf(fp, "  Version String: %s\n", b.smbb_version);
238437Smws 	oprintf(fp, "  Release Date: %s\n", b.smbb_reldate);
239437Smws 	oprintf(fp, "  Address Segment: 0x%x\n", b.smbb_segment);
240437Smws 	oprintf(fp, "  ROM Size: %u bytes\n", b.smbb_romsize);
241437Smws 	oprintf(fp, "  Image Size: %u bytes\n", b.smbb_runsize);
242437Smws 
243437Smws 	flag64_printf(fp, "Characteristics",
244437Smws 	    b.smbb_cflags, sizeof (b.smbb_cflags) * NBBY,
245437Smws 	    smbios_bios_flag_name, smbios_bios_flag_desc);
246437Smws 
247437Smws 	if (b.smbb_nxcflags > SMB_BIOSXB_1) {
248437Smws 		flag_printf(fp, "Characteristics Extension Byte 1",
249437Smws 		    b.smbb_xcflags[SMB_BIOSXB_1],
250437Smws 		    sizeof (b.smbb_xcflags[SMB_BIOSXB_1]) * NBBY,
251437Smws 		    smbios_bios_xb1_name, smbios_bios_xb1_desc);
252437Smws 	}
253437Smws 
254437Smws 	if (b.smbb_nxcflags > SMB_BIOSXB_2) {
255437Smws 		flag_printf(fp, "Characteristics Extension Byte 2",
256437Smws 		    b.smbb_xcflags[SMB_BIOSXB_2],
257437Smws 		    sizeof (b.smbb_xcflags[SMB_BIOSXB_2]) * NBBY,
258437Smws 		    smbios_bios_xb2_name, smbios_bios_xb2_desc);
259437Smws 	}
260437Smws 
261437Smws 	if (b.smbb_nxcflags > SMB_BIOSXB_BIOS_MIN) {
262437Smws 		oprintf(fp, "  Version Number: %u.%u\n",
263437Smws 		    b.smbb_biosv.smbv_major, b.smbb_biosv.smbv_minor);
264437Smws 	}
265437Smws 
266437Smws 	if (b.smbb_nxcflags > SMB_BIOSXB_ECFW_MIN) {
267437Smws 		oprintf(fp, "  Embedded Ctlr Firmware Version Number: %u.%u\n",
268437Smws 		    b.smbb_ecfwv.smbv_major, b.smbb_ecfwv.smbv_minor);
269437Smws 	}
270437Smws }
271437Smws 
272437Smws static void
print_system(smbios_hdl_t * shp,FILE * fp)273437Smws print_system(smbios_hdl_t *shp, FILE *fp)
274437Smws {
275437Smws 	smbios_system_t s;
276437Smws 	uint_t i;
277437Smws 
278437Smws 	(void) smbios_info_system(shp, &s);
279437Smws 
280437Smws 	oprintf(fp, "  UUID: ");
281437Smws 	for (i = 0; i < s.smbs_uuidlen; i++) {
282437Smws 		oprintf(fp, "%02x", s.smbs_uuid[i]);
283437Smws 		if (i == 3 || i == 5 || i == 7 || i == 9)
284437Smws 			oprintf(fp, "-");
285437Smws 	}
286437Smws 	oprintf(fp, "\n");
287437Smws 
288437Smws 	desc_printf(smbios_system_wakeup_desc(s.smbs_wakeup),
289437Smws 	    fp, "  Wake-Up Event: 0x%x", s.smbs_wakeup);
290437Smws 
291437Smws 	oprintf(fp, "  SKU Number: %s\n", s.smbs_sku);
292437Smws 	oprintf(fp, "  Family: %s\n", s.smbs_family);
293437Smws }
294437Smws 
295437Smws static void
print_bboard(smbios_hdl_t * shp,id_t id,FILE * fp)296437Smws print_bboard(smbios_hdl_t *shp, id_t id, FILE *fp)
297437Smws {
298437Smws 	smbios_bboard_t b;
29910942STom.Pothier@Sun.COM 	int chdl_cnt;
300437Smws 
301437Smws 	(void) smbios_info_bboard(shp, id, &b);
302437Smws 
303437Smws 	oprintf(fp, "  Chassis: %u\n", (uint_t)b.smbb_chassis);
304437Smws 
305437Smws 	flag_printf(fp, "Flags", b.smbb_flags, sizeof (b.smbb_flags) * NBBY,
306437Smws 	    smbios_bboard_flag_name, smbios_bboard_flag_desc);
307437Smws 
308437Smws 	desc_printf(smbios_bboard_type_desc(b.smbb_type),
309437Smws 	    fp, "  Board Type: 0x%x", b.smbb_type);
31010942STom.Pothier@Sun.COM 
31110942STom.Pothier@Sun.COM 	chdl_cnt = b.smbb_contn;
31210942STom.Pothier@Sun.COM 	if (chdl_cnt != 0) {
31310942STom.Pothier@Sun.COM 		id_t *chdl;
31410942STom.Pothier@Sun.COM 		uint16_t hdl;
31510942STom.Pothier@Sun.COM 		int i, n, cnt;
31610942STom.Pothier@Sun.COM 
31710942STom.Pothier@Sun.COM 		chdl = alloca(chdl_cnt * sizeof (id_t));
31810942STom.Pothier@Sun.COM 		cnt = smbios_info_contains(shp, id, chdl_cnt, chdl);
31910942STom.Pothier@Sun.COM 		if (cnt > SMB_CONT_MAX)
32010942STom.Pothier@Sun.COM 			return;
32110942STom.Pothier@Sun.COM 		n = MIN(chdl_cnt, cnt);
32210942STom.Pothier@Sun.COM 
32310942STom.Pothier@Sun.COM 		oprintf(fp, "\n");
32410942STom.Pothier@Sun.COM 		for (i = 0; i < n; i++) {
32510942STom.Pothier@Sun.COM 			hdl = (uint16_t)chdl[i];
32610942STom.Pothier@Sun.COM 			oprintf(fp, "  Contained Handle: %u\n", hdl);
32710942STom.Pothier@Sun.COM 		}
32810942STom.Pothier@Sun.COM 	}
329437Smws }
330437Smws 
331437Smws static void
print_chassis(smbios_hdl_t * shp,id_t id,FILE * fp)332437Smws print_chassis(smbios_hdl_t *shp, id_t id, FILE *fp)
333437Smws {
334437Smws 	smbios_chassis_t c;
33510942STom.Pothier@Sun.COM 	int elem_cnt;
336437Smws 
337437Smws 	(void) smbios_info_chassis(shp, id, &c);
338437Smws 
339437Smws 	oprintf(fp, "  OEM Data: 0x%x\n", c.smbc_oemdata);
340437Smws 	oprintf(fp, "  Lock Present: %s\n", c.smbc_lock ? "Y" : "N");
341437Smws 
342437Smws 	desc_printf(smbios_chassis_type_desc(c.smbc_type),
343437Smws 	    fp, "  Chassis Type: 0x%x", c.smbc_type);
344437Smws 
345437Smws 	desc_printf(smbios_chassis_state_desc(c.smbc_bustate),
346437Smws 	    fp, "  Boot-Up State: 0x%x", c.smbc_bustate);
347437Smws 
348437Smws 	desc_printf(smbios_chassis_state_desc(c.smbc_psstate),
349437Smws 	    fp, "  Power Supply State: 0x%x", c.smbc_psstate);
350437Smws 
351437Smws 	desc_printf(smbios_chassis_state_desc(c.smbc_thstate),
352437Smws 	    fp, "  Thermal State: 0x%x", c.smbc_thstate);
353437Smws 
354437Smws 	oprintf(fp, "  Chassis Height: %uu\n", c.smbc_uheight);
355437Smws 	oprintf(fp, "  Power Cords: %u\n", c.smbc_cords);
35610942STom.Pothier@Sun.COM 
35710942STom.Pothier@Sun.COM 	elem_cnt = c.smbc_elems;
35810942STom.Pothier@Sun.COM 	oprintf(fp, "  Element Records: %u\n", elem_cnt);
35910942STom.Pothier@Sun.COM 
36010942STom.Pothier@Sun.COM 	if (elem_cnt > 0) {
36110942STom.Pothier@Sun.COM 		id_t *elems;
36210942STom.Pothier@Sun.COM 		uint8_t type;
36310942STom.Pothier@Sun.COM 		int i, n, cnt;
36410942STom.Pothier@Sun.COM 
36510942STom.Pothier@Sun.COM 		elems = alloca(c.smbc_elems * sizeof (id_t));
36610942STom.Pothier@Sun.COM 		cnt = smbios_info_contains(shp, id, elem_cnt, elems);
36710942STom.Pothier@Sun.COM 		if (cnt > SMB_CONT_MAX)
36810942STom.Pothier@Sun.COM 			return;
36910942STom.Pothier@Sun.COM 		n = MIN(elem_cnt, cnt);
37010942STom.Pothier@Sun.COM 
37110942STom.Pothier@Sun.COM 		oprintf(fp, "\n");
37210942STom.Pothier@Sun.COM 		for (i = 0; i < n; i++) {
37310942STom.Pothier@Sun.COM 			type = (uint8_t)elems[i];
37410942STom.Pothier@Sun.COM 			if (type & 0x80) {
37510942STom.Pothier@Sun.COM 				/* SMBIOS structrure Type */
37610942STom.Pothier@Sun.COM 				desc_printf(smbios_type_name(type & 0x7f), fp,
37710942STom.Pothier@Sun.COM 				    "  Contained SMBIOS structure Type: %u",
37810942STom.Pothier@Sun.COM 				    type & 0x80);
37910942STom.Pothier@Sun.COM 			} else {
38010942STom.Pothier@Sun.COM 				/* SMBIOS Base Board Type */
38110942STom.Pothier@Sun.COM 				desc_printf(smbios_bboard_type_desc(type), fp,
38210942STom.Pothier@Sun.COM 				    "  Contained SMBIOS Base Board Type: 0x%x",
38310942STom.Pothier@Sun.COM 				    type);
38410942STom.Pothier@Sun.COM 			}
38510942STom.Pothier@Sun.COM 		}
38610942STom.Pothier@Sun.COM 	}
387437Smws }
388437Smws 
389437Smws static void
print_processor(smbios_hdl_t * shp,id_t id,FILE * fp)390437Smws print_processor(smbios_hdl_t *shp, id_t id, FILE *fp)
391437Smws {
392437Smws 	smbios_processor_t p;
393437Smws 	uint_t status;
394437Smws 
395437Smws 	(void) smbios_info_processor(shp, id, &p);
396437Smws 	status = SMB_PRSTATUS_STATUS(p.smbp_status);
397437Smws 
398437Smws 	desc_printf(smbios_processor_family_desc(p.smbp_family),
399437Smws 	    fp, "  Family: %u", p.smbp_family);
400437Smws 
401437Smws 	oprintf(fp, "  CPUID: 0x%llx\n", (u_longlong_t)p.smbp_cpuid);
402437Smws 
403437Smws 	desc_printf(smbios_processor_type_desc(p.smbp_type),
404437Smws 	    fp, "  Type: %u", p.smbp_type);
405437Smws 
406437Smws 	desc_printf(smbios_processor_upgrade_desc(p.smbp_upgrade),
407437Smws 	    fp, "  Socket Upgrade: %u", p.smbp_upgrade);
408437Smws 
409437Smws 	oprintf(fp, "  Socket Status: %s\n",
410437Smws 	    SMB_PRSTATUS_PRESENT(p.smbp_status) ?
411437Smws 	    "Populated" : "Not Populated");
412437Smws 
413437Smws 	desc_printf(smbios_processor_status_desc(status),
414437Smws 	    fp, "  Processor Status: %u", status);
415437Smws 
416437Smws 	if (SMB_PRV_LEGACY(p.smbp_voltage)) {
417437Smws 		oprintf(fp, "  Supported Voltages:");
418437Smws 		switch (p.smbp_voltage) {
419437Smws 		case SMB_PRV_5V:
420437Smws 			oprintf(fp, " 5.0V");
421437Smws 			break;
422437Smws 		case SMB_PRV_33V:
423437Smws 			oprintf(fp, " 3.3V");
424437Smws 			break;
425437Smws 		case SMB_PRV_29V:
426437Smws 			oprintf(fp, " 2.9V");
427437Smws 			break;
428437Smws 		}
429437Smws 		oprintf(fp, "\n");
430437Smws 	} else {
431437Smws 		oprintf(fp, "  Supported Voltages: %.1fV\n",
432437Smws 		    (float)SMB_PRV_VOLTAGE(p.smbp_voltage) / 10);
433437Smws 	}
434437Smws 
435437Smws 	if (p.smbp_clkspeed != 0)
436437Smws 		oprintf(fp, "  External Clock Speed: %uMHz\n", p.smbp_clkspeed);
437437Smws 	else
438437Smws 		oprintf(fp, "  External Clock Speed: Unknown\n");
439437Smws 
440437Smws 	if (p.smbp_maxspeed != 0)
441437Smws 		oprintf(fp, "  Maximum Speed: %uMHz\n", p.smbp_maxspeed);
442437Smws 	else
443437Smws 		oprintf(fp, "  Maximum Speed: Unknown\n");
444437Smws 
445437Smws 	if (p.smbp_curspeed != 0)
446437Smws 		oprintf(fp, "  Current Speed: %uMHz\n", p.smbp_curspeed);
447437Smws 	else
448437Smws 		oprintf(fp, "  Current Speed: Unknown\n");
449437Smws 
450437Smws 	id_printf(fp, "  L1 Cache: ", p.smbp_l1cache);
451437Smws 	id_printf(fp, "  L2 Cache: ", p.smbp_l2cache);
452437Smws 	id_printf(fp, "  L3 Cache: ", p.smbp_l3cache);
453437Smws }
454437Smws 
455437Smws static void
print_cache(smbios_hdl_t * shp,id_t id,FILE * fp)456437Smws print_cache(smbios_hdl_t *shp, id_t id, FILE *fp)
457437Smws {
458437Smws 	smbios_cache_t c;
459437Smws 
460437Smws 	(void) smbios_info_cache(shp, id, &c);
461437Smws 
462437Smws 	oprintf(fp, "  Level: %u\n", c.smba_level);
463437Smws 	oprintf(fp, "  Maximum Installed Size: %u bytes\n", c.smba_maxsize);
464437Smws 
465437Smws 	if (c.smba_size != 0)
466437Smws 		oprintf(fp, "  Installed Size: %u bytes\n", c.smba_size);
467437Smws 	else
468437Smws 		oprintf(fp, "  Installed Size: Not Installed\n");
469437Smws 
470437Smws 	if (c.smba_speed != 0)
471437Smws 		oprintf(fp, "  Speed: %uns\n", c.smba_speed);
472437Smws 	else
473437Smws 		oprintf(fp, "  Speed: Unknown\n");
474437Smws 
475437Smws 	flag_printf(fp, "Supported SRAM Types",
476437Smws 	    c.smba_stype, sizeof (c.smba_stype) * NBBY,
477437Smws 	    smbios_cache_ctype_name, smbios_cache_ctype_desc);
478437Smws 
479437Smws 	desc_printf(smbios_cache_ctype_desc(c.smba_ctype),
480437Smws 	    fp, "  Current SRAM Type: 0x%x", c.smba_ctype);
481437Smws 
482437Smws 	desc_printf(smbios_cache_ecc_desc(c.smba_etype),
483437Smws 	    fp, "  Error Correction Type: %u", c.smba_etype);
484437Smws 
485437Smws 	desc_printf(smbios_cache_logical_desc(c.smba_ltype),
486437Smws 	    fp, "  Logical Cache Type: %u", c.smba_ltype);
487437Smws 
488437Smws 	desc_printf(smbios_cache_assoc_desc(c.smba_assoc),
489437Smws 	    fp, "  Associativity: %u", c.smba_assoc);
490437Smws 
491437Smws 	desc_printf(smbios_cache_mode_desc(c.smba_mode),
492437Smws 	    fp, "  Mode: %u", c.smba_mode);
493437Smws 
494437Smws 	desc_printf(smbios_cache_loc_desc(c.smba_location),
495437Smws 	    fp, "  Location: %u", c.smba_location);
496437Smws 
497437Smws 	flag_printf(fp, "Flags", c.smba_flags, sizeof (c.smba_flags) * NBBY,
498437Smws 	    smbios_cache_flag_name, smbios_cache_flag_desc);
499437Smws }
500437Smws 
501437Smws static void
print_port(smbios_hdl_t * shp,id_t id,FILE * fp)502437Smws print_port(smbios_hdl_t *shp, id_t id, FILE *fp)
503437Smws {
504437Smws 	smbios_port_t p;
505437Smws 
506437Smws 	(void) smbios_info_port(shp, id, &p);
507437Smws 
508437Smws 	oprintf(fp, "  Internal Reference Designator: %s\n", p.smbo_iref);
509437Smws 	oprintf(fp, "  External Reference Designator: %s\n", p.smbo_eref);
510437Smws 
511437Smws 	desc_printf(smbios_port_conn_desc(p.smbo_itype),
512437Smws 	    fp, "  Internal Connector Type: %u", p.smbo_itype);
513437Smws 
514437Smws 	desc_printf(smbios_port_conn_desc(p.smbo_etype),
515437Smws 	    fp, "  External Connector Type: %u", p.smbo_etype);
516437Smws 
517437Smws 	desc_printf(smbios_port_type_desc(p.smbo_ptype),
518437Smws 	    fp, "  Port Type: %u", p.smbo_ptype);
519437Smws }
520437Smws 
521437Smws static void
print_slot(smbios_hdl_t * shp,id_t id,FILE * fp)522437Smws print_slot(smbios_hdl_t *shp, id_t id, FILE *fp)
523437Smws {
524437Smws 	smbios_slot_t s;
525*11859STom.Pothier@Sun.COM 	smbios_entry_t e;
526437Smws 
527437Smws 	(void) smbios_info_slot(shp, id, &s);
528*11859STom.Pothier@Sun.COM 	(void) smbios_info_smbios(shp, &e);
529437Smws 
530437Smws 	oprintf(fp, "  Reference Designator: %s\n", s.smbl_name);
531437Smws 	oprintf(fp, "  Slot ID: 0x%x\n", s.smbl_id);
532437Smws 
533437Smws 	desc_printf(smbios_slot_type_desc(s.smbl_type),
534437Smws 	    fp, "  Type: 0x%x", s.smbl_type);
535437Smws 
536437Smws 	desc_printf(smbios_slot_width_desc(s.smbl_width),
537437Smws 	    fp, "  Width: 0x%x", s.smbl_width);
538437Smws 
539437Smws 	desc_printf(smbios_slot_usage_desc(s.smbl_usage),
540437Smws 	    fp, "  Usage: 0x%x", s.smbl_usage);
541437Smws 
542437Smws 	desc_printf(smbios_slot_length_desc(s.smbl_length),
543437Smws 	    fp, "  Length: 0x%x", s.smbl_length);
544437Smws 
545437Smws 	flag_printf(fp, "Slot Characteristics 1",
546437Smws 	    s.smbl_ch1, sizeof (s.smbl_ch1) * NBBY,
547437Smws 	    smbios_slot_ch1_name, smbios_slot_ch1_desc);
548437Smws 
549437Smws 	flag_printf(fp, "Slot Characteristics 2",
550437Smws 	    s.smbl_ch2, sizeof (s.smbl_ch2) * NBBY,
551437Smws 	    smbios_slot_ch2_name, smbios_slot_ch2_desc);
552*11859STom.Pothier@Sun.COM 
553*11859STom.Pothier@Sun.COM 	if (check_oem(shp) != 0 && (e.smbe_major < 2 || e.smbe_minor < 6))
554*11859STom.Pothier@Sun.COM 		return;
555*11859STom.Pothier@Sun.COM 
556*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Segment Group: %u\n", s.smbl_sg);
557*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Bus Number: %u\n", s.smbl_bus);
558*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Device/Function Number: %u\n", s.smbl_df);
559*11859STom.Pothier@Sun.COM }
560*11859STom.Pothier@Sun.COM 
561*11859STom.Pothier@Sun.COM static void
print_obdevs_ext(smbios_hdl_t * shp,id_t id,FILE * fp)562*11859STom.Pothier@Sun.COM print_obdevs_ext(smbios_hdl_t *shp, id_t id, FILE *fp)
563*11859STom.Pothier@Sun.COM {
564*11859STom.Pothier@Sun.COM 	smbios_obdev_ext_t oe;
565*11859STom.Pothier@Sun.COM 
566*11859STom.Pothier@Sun.COM 	(void) smbios_info_obdevs_ext(shp, id, &oe);
567*11859STom.Pothier@Sun.COM 
568*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Reference Designator: %s\n", oe.smboe_name);
569*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Device Type: %u\n", oe.smboe_dtype);
570*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Device Type Instance: %u\n", oe.smboe_dti);
571*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Segment Group Number: %u\n", oe.smboe_sg);
572*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Bus Number: %u\n", oe.smboe_bus);
573*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Device/Function Number: %u\n", oe.smboe_df);
574437Smws }
575437Smws 
576437Smws static void
print_obdevs(smbios_hdl_t * shp,id_t id,FILE * fp)577437Smws print_obdevs(smbios_hdl_t *shp, id_t id, FILE *fp)
578437Smws {
579437Smws 	smbios_obdev_t *argv;
580437Smws 	int i, argc;
581437Smws 
582437Smws 	if ((argc = smbios_info_obdevs(shp, id, 0, NULL)) > 0) {
583437Smws 		argv = alloca(sizeof (smbios_obdev_t) * argc);
584437Smws 		(void) smbios_info_obdevs(shp, id, argc, argv);
585437Smws 		for (i = 0; i < argc; i++)
586437Smws 			oprintf(fp, "  %s\n", argv[i].smbd_name);
587437Smws 	}
588437Smws }
589437Smws 
590437Smws static void
print_strtab(smbios_hdl_t * shp,id_t id,FILE * fp)591437Smws print_strtab(smbios_hdl_t *shp, id_t id, FILE *fp)
592437Smws {
593437Smws 	const char **argv;
594437Smws 	int i, argc;
595437Smws 
596437Smws 	if ((argc = smbios_info_strtab(shp, id, 0, NULL)) > 0) {
597437Smws 		argv = alloca(sizeof (char *) * argc);
598437Smws 		(void) smbios_info_strtab(shp, id, argc, argv);
599437Smws 		for (i = 0; i < argc; i++)
600437Smws 			oprintf(fp, "  %s\n", argv[i]);
601437Smws 	}
602437Smws }
603437Smws 
604437Smws static void
print_lang(smbios_hdl_t * shp,id_t id,FILE * fp)605437Smws print_lang(smbios_hdl_t *shp, id_t id, FILE *fp)
606437Smws {
607437Smws 	smbios_lang_t l;
608437Smws 
609437Smws 	(void) smbios_info_lang(shp, &l);
610437Smws 
611437Smws 	oprintf(fp, "  Current Language: %s\n", l.smbla_cur);
612437Smws 	oprintf(fp, "  Language String Format: %u\n", l.smbla_fmt);
613437Smws 	oprintf(fp, "  Number of Installed Languages: %u\n", l.smbla_num);
614437Smws 	oprintf(fp, "  Installed Languages:\n");
615437Smws 
616437Smws 	print_strtab(shp, id, fp);
617437Smws }
618437Smws 
619437Smws /*ARGSUSED*/
620437Smws static void
print_evlog(smbios_hdl_t * shp,id_t id,FILE * fp)621437Smws print_evlog(smbios_hdl_t *shp, id_t id, FILE *fp)
622437Smws {
623437Smws 	smbios_evlog_t ev;
624437Smws 	uint32_t i;
625437Smws 
626437Smws 	(void) smbios_info_eventlog(shp, &ev);
627437Smws 
628437Smws 	oprintf(fp, "  Log Area Size: %lu bytes\n", (ulong_t)ev.smbev_size);
629437Smws 	oprintf(fp, "  Header Offset: %lu\n", (ulong_t)ev.smbev_hdr);
630437Smws 	oprintf(fp, "  Data Offset: %lu\n", (ulong_t)ev.smbev_data);
631437Smws 
632437Smws 	desc_printf(smbios_evlog_method_desc(ev.smbev_method),
633437Smws 	    fp, "  Data Access Method: %u", ev.smbev_method);
634437Smws 
635437Smws 	flag_printf(fp, "Log Flags",
636437Smws 	    ev.smbev_flags, sizeof (ev.smbev_flags) * NBBY,
637437Smws 	    smbios_evlog_flag_name, smbios_evlog_flag_desc);
638437Smws 
639437Smws 	desc_printf(smbios_evlog_format_desc(ev.smbev_format),
640437Smws 	    fp, "  Log Header Format: %u", ev.smbev_format);
641437Smws 
642437Smws 	oprintf(fp, "  Update Token: 0x%x\n", ev.smbev_token);
643437Smws 	oprintf(fp, "  Data Access Address: ");
644437Smws 
645437Smws 	switch (ev.smbev_method) {
646437Smws 	case SMB_EVM_1x1i_1x1d:
647437Smws 	case SMB_EVM_2x1i_1x1d:
648437Smws 	case SMB_EVM_1x2i_1x1d:
649437Smws 		oprintf(fp, "Index Address 0x%x, Data Address 0x%x\n",
650437Smws 		    ev.smbev_addr.eva_io.evi_iaddr,
651437Smws 		    ev.smbev_addr.eva_io.evi_daddr);
652437Smws 		break;
653437Smws 	case SMB_EVM_GPNV:
654437Smws 		oprintf(fp, "0x%x\n", ev.smbev_addr.eva_gpnv);
655437Smws 		break;
656437Smws 	default:
657437Smws 		oprintf(fp, "0x%x\n", ev.smbev_addr.eva_addr);
658437Smws 	}
659437Smws 
660437Smws 	oprintf(fp, "  Type Descriptors:\n");
661437Smws 
662437Smws 	for (i = 0; i < ev.smbev_typec; i++) {
663437Smws 		oprintf(fp, "  %u: Log Type 0x%x, Data Type 0x%x\n", i,
664437Smws 		    ev.smbev_typev[i].smbevt_ltype,
665437Smws 		    ev.smbev_typev[i].smbevt_dtype);
666437Smws 	}
667437Smws }
668437Smws 
669437Smws static void
print_bytes(const uint8_t * data,size_t size,FILE * fp)670437Smws print_bytes(const uint8_t *data, size_t size, FILE *fp)
671437Smws {
672437Smws 	size_t row, rows = P2ROUNDUP(size, 16) / 16;
673437Smws 	size_t col, cols;
674437Smws 
675437Smws 	char buf[17];
676437Smws 	uint8_t x;
677437Smws 
678437Smws 	oprintf(fp, "\n  offset:   0 1 2 3  4 5 6 7  8 9 a b  c d e f  "
679437Smws 	    "0123456789abcdef\n");
680437Smws 
681437Smws 	for (row = 0; row < rows; row++) {
682437Smws 		oprintf(fp, "    %#4lx: ", (ulong_t)row * 16);
683437Smws 		cols = MIN(size - row * 16, 16);
684437Smws 
685437Smws 		for (col = 0; col < cols; col++) {
686437Smws 			if (col % 4 == 0)
687437Smws 				oprintf(fp, " ");
688437Smws 			x = *data++;
689437Smws 			oprintf(fp, "%02x", x);
690437Smws 			buf[col] = x <= ' ' || x > '~' ? '.' : x;
691437Smws 		}
692437Smws 
693437Smws 		for (; col < 16; col++) {
694437Smws 			if (col % 4 == 0)
695437Smws 				oprintf(fp, " ");
696437Smws 			oprintf(fp, "  ");
697437Smws 			buf[col] = ' ';
698437Smws 		}
699437Smws 
700437Smws 		buf[col] = '\0';
701437Smws 		oprintf(fp, "  %s\n", buf);
702437Smws 	}
703437Smws 
704437Smws 	oprintf(fp, "\n");
705437Smws }
706437Smws 
707437Smws static void
print_memarray(smbios_hdl_t * shp,id_t id,FILE * fp)708437Smws print_memarray(smbios_hdl_t *shp, id_t id, FILE *fp)
709437Smws {
710437Smws 	smbios_memarray_t ma;
711437Smws 
712437Smws 	(void) smbios_info_memarray(shp, id, &ma);
713437Smws 
714437Smws 	desc_printf(smbios_memarray_loc_desc(ma.smbma_location),
715437Smws 	    fp, "  Location: %u", ma.smbma_location);
716437Smws 
717437Smws 	desc_printf(smbios_memarray_use_desc(ma.smbma_use),
718437Smws 	    fp, "  Use: %u", ma.smbma_use);
719437Smws 
720437Smws 	desc_printf(smbios_memarray_ecc_desc(ma.smbma_ecc),
721437Smws 	    fp, "  ECC: %u", ma.smbma_ecc);
722437Smws 
723437Smws 	oprintf(fp, "  Number of Slots/Sockets: %u\n", ma.smbma_ndevs);
724437Smws 	id_printf(fp, "  Memory Error Data: ", ma.smbma_err);
725437Smws 	oprintf(fp, "  Max Capacity: %llu bytes\n",
726437Smws 	    (u_longlong_t)ma.smbma_size);
727437Smws }
728437Smws 
729437Smws static void
print_memdevice(smbios_hdl_t * shp,id_t id,FILE * fp)730437Smws print_memdevice(smbios_hdl_t *shp, id_t id, FILE *fp)
731437Smws {
732437Smws 	smbios_memdevice_t md;
733437Smws 
734437Smws 	(void) smbios_info_memdevice(shp, id, &md);
735437Smws 
736437Smws 	id_printf(fp, "  Physical Memory Array: ", md.smbmd_array);
737437Smws 	id_printf(fp, "  Memory Error Data: ", md.smbmd_error);
738437Smws 
739437Smws 	if (md.smbmd_twidth != -1u)
740437Smws 		oprintf(fp, "  Total Width: %u bits\n", md.smbmd_twidth);
741437Smws 	else
742437Smws 		oprintf(fp, "  Total Width: Unknown\n");
743437Smws 
744437Smws 	if (md.smbmd_dwidth != -1u)
745437Smws 		oprintf(fp, "  Data Width: %u bits\n", md.smbmd_dwidth);
746437Smws 	else
747437Smws 		oprintf(fp, "  Data Width: Unknown\n");
748437Smws 
749437Smws 	switch (md.smbmd_size) {
750437Smws 	case -1ull:
751437Smws 		oprintf(fp, "  Size: Unknown\n");
752437Smws 		break;
753437Smws 	case 0:
754437Smws 		oprintf(fp, "  Size: Not Populated\n");
755437Smws 		break;
756437Smws 	default:
757437Smws 		oprintf(fp, "  Size: %llu bytes\n",
758437Smws 		    (u_longlong_t)md.smbmd_size);
759437Smws 	}
760437Smws 
761437Smws 	desc_printf(smbios_memdevice_form_desc(md.smbmd_form),
762437Smws 	    fp, "  Form Factor: %u", md.smbmd_form);
763437Smws 
764437Smws 	if (md.smbmd_set == 0)
765437Smws 		oprintf(fp, "  Set: None\n");
766437Smws 	else if (md.smbmd_set == (uint8_t)-1u)
767437Smws 		oprintf(fp, "  Set: Unknown\n");
768437Smws 	else
769437Smws 		oprintf(fp, "  Set: %u\n", md.smbmd_set);
770437Smws 
771437Smws 	desc_printf(smbios_memdevice_type_desc(md.smbmd_type),
772437Smws 	    fp, "  Memory Type: %u", md.smbmd_type);
773437Smws 
774437Smws 	flag_printf(fp, "Flags", md.smbmd_flags, sizeof (md.smbmd_flags) * NBBY,
775437Smws 	    smbios_memdevice_flag_name, smbios_memdevice_flag_desc);
776437Smws 
777437Smws 	if (md.smbmd_speed != 0)
778437Smws 		oprintf(fp, "  Speed: %uns\n", md.smbmd_speed);
779437Smws 	else
780437Smws 		oprintf(fp, "  Speed: Unknown\n");
781437Smws 
782437Smws 	oprintf(fp, "  Device Locator: %s\n", md.smbmd_dloc);
783437Smws 	oprintf(fp, "  Bank Locator: %s\n", md.smbmd_bloc);
784437Smws }
785437Smws 
786437Smws static void
print_memarrmap(smbios_hdl_t * shp,id_t id,FILE * fp)787437Smws print_memarrmap(smbios_hdl_t *shp, id_t id, FILE *fp)
788437Smws {
789437Smws 	smbios_memarrmap_t ma;
790437Smws 
791437Smws 	(void) smbios_info_memarrmap(shp, id, &ma);
792437Smws 
793437Smws 	id_printf(fp, "  Physical Memory Array: ", ma.smbmam_array);
794437Smws 	oprintf(fp, "  Devices per Row: %u\n", ma.smbmam_width);
795437Smws 
796437Smws 	oprintf(fp, "  Physical Address: 0x%llx\n  Size: %llu bytes\n",
797437Smws 	    (u_longlong_t)ma.smbmam_addr, (u_longlong_t)ma.smbmam_size);
798437Smws }
799437Smws 
800437Smws static void
print_memdevmap(smbios_hdl_t * shp,id_t id,FILE * fp)801437Smws print_memdevmap(smbios_hdl_t *shp, id_t id, FILE *fp)
802437Smws {
803437Smws 	smbios_memdevmap_t md;
804437Smws 
805437Smws 	(void) smbios_info_memdevmap(shp, id, &md);
806437Smws 
807437Smws 	id_printf(fp, "  Memory Device: ", md.smbmdm_device);
808437Smws 	id_printf(fp, "  Memory Array Mapped Address: ", md.smbmdm_arrmap);
809437Smws 
810437Smws 	oprintf(fp, "  Physical Address: 0x%llx\n  Size: %llu bytes\n",
811437Smws 	    (u_longlong_t)md.smbmdm_addr, (u_longlong_t)md.smbmdm_size);
812437Smws 
813437Smws 	oprintf(fp, "  Partition Row Position: %u\n", md.smbmdm_rpos);
814437Smws 	oprintf(fp, "  Interleave Position: %u\n", md.smbmdm_ipos);
815437Smws 	oprintf(fp, "  Interleave Data Depth: %u\n", md.smbmdm_idepth);
816437Smws }
817437Smws 
818437Smws static void
print_hwsec(smbios_hdl_t * shp,FILE * fp)819437Smws print_hwsec(smbios_hdl_t *shp, FILE *fp)
820437Smws {
821437Smws 	smbios_hwsec_t h;
822437Smws 
823437Smws 	(void) smbios_info_hwsec(shp, &h);
824437Smws 
825437Smws 	desc_printf(smbios_hwsec_desc(h.smbh_pwr_ps),
826437Smws 	    fp, "  Power-On Password Status: %u", h.smbh_pwr_ps);
827437Smws 	desc_printf(smbios_hwsec_desc(h.smbh_kbd_ps),
828437Smws 	    fp, "  Keyboard Password Status: %u", h.smbh_kbd_ps);
829437Smws 	desc_printf(smbios_hwsec_desc(h.smbh_adm_ps),
830437Smws 	    fp, "  Administrator Password Status: %u", h.smbh_adm_ps);
831437Smws 	desc_printf(smbios_hwsec_desc(h.smbh_pan_ps),
832437Smws 	    fp, "  Front Panel Reset Status: %u", h.smbh_pan_ps);
833437Smws }
834437Smws 
835437Smws static void
print_boot(smbios_hdl_t * shp,FILE * fp)836437Smws print_boot(smbios_hdl_t *shp, FILE *fp)
837437Smws {
838437Smws 	smbios_boot_t b;
839437Smws 
840437Smws 	(void) smbios_info_boot(shp, &b);
841437Smws 
842437Smws 	desc_printf(smbios_boot_desc(b.smbt_status),
843437Smws 	    fp, "  Boot Status Code: 0x%x", b.smbt_status);
844437Smws 
845437Smws 	if (b.smbt_size != 0) {
846437Smws 		oprintf(fp, "  Boot Data (%lu bytes):\n", (ulong_t)b.smbt_size);
847437Smws 		print_bytes(b.smbt_data, b.smbt_size, fp);
848437Smws 	}
849437Smws }
850437Smws 
851437Smws static void
print_ipmi(smbios_hdl_t * shp,FILE * fp)852437Smws print_ipmi(smbios_hdl_t *shp, FILE *fp)
853437Smws {
854437Smws 	smbios_ipmi_t i;
855437Smws 
856437Smws 	(void) smbios_info_ipmi(shp, &i);
857437Smws 
858437Smws 	desc_printf(smbios_ipmi_type_desc(i.smbip_type),
859437Smws 	    fp, "  Type: %u", i.smbip_type);
860437Smws 
861437Smws 	oprintf(fp, "  BMC IPMI Version: %u.%u\n",
862437Smws 	    i.smbip_vers.smbv_major, i.smbip_vers.smbv_minor);
863437Smws 
864437Smws 	oprintf(fp, "  i2c Bus Slave Address: 0x%x\n", i.smbip_i2c);
865437Smws 	oprintf(fp, "  NV Storage Device Bus ID: 0x%x\n", i.smbip_bus);
866437Smws 	oprintf(fp, "  BMC Base Address: 0x%llx\n", (u_longlong_t)i.smbip_addr);
867437Smws 	oprintf(fp, "  Interrupt Number: %u\n", i.smbip_intr);
868437Smws 	oprintf(fp, "  Register Spacing: %u\n", i.smbip_regspacing);
869437Smws 
870437Smws 	flag_printf(fp, "Flags", i.smbip_flags, sizeof (i.smbip_flags) * NBBY,
871437Smws 	    smbios_ipmi_flag_name, smbios_ipmi_flag_desc);
872437Smws }
873437Smws 
87410942STom.Pothier@Sun.COM static void
print_extprocessor(smbios_hdl_t * shp,id_t id,FILE * fp)87510942STom.Pothier@Sun.COM print_extprocessor(smbios_hdl_t *shp, id_t id, FILE *fp)
87610942STom.Pothier@Sun.COM {
87710942STom.Pothier@Sun.COM 	int i;
87810942STom.Pothier@Sun.COM 	smbios_processor_ext_t ep;
87910942STom.Pothier@Sun.COM 
88010942STom.Pothier@Sun.COM 	if (check_oem(shp) != 0)
88110942STom.Pothier@Sun.COM 		return;
88210942STom.Pothier@Sun.COM 
88310942STom.Pothier@Sun.COM 	(void) smbios_info_extprocessor(shp, id, &ep);
88410942STom.Pothier@Sun.COM 
88510942STom.Pothier@Sun.COM 	oprintf(fp, "  Processor: %u\n", ep.smbpe_processor);
88610942STom.Pothier@Sun.COM 	oprintf(fp, "  FRU: %u\n", ep.smbpe_fru);
88710942STom.Pothier@Sun.COM 	oprintf(fp, "  Initial APIC ID count: %u\n\n", ep.smbpe_n);
88810942STom.Pothier@Sun.COM 
88910942STom.Pothier@Sun.COM 	for (i = 0; i < ep.smbpe_n; i++) {
89010942STom.Pothier@Sun.COM 		oprintf(fp, "  Logical Strand %u: Initial APIC ID: %u\n", i,
89110942STom.Pothier@Sun.COM 		    ep.smbpe_apicid[i]);
89210942STom.Pothier@Sun.COM 	}
89310942STom.Pothier@Sun.COM }
89410942STom.Pothier@Sun.COM 
89510942STom.Pothier@Sun.COM static void
print_extport(smbios_hdl_t * shp,id_t id,FILE * fp)896*11859STom.Pothier@Sun.COM print_extport(smbios_hdl_t *shp, id_t id, FILE *fp)
897*11859STom.Pothier@Sun.COM {
898*11859STom.Pothier@Sun.COM 	smbios_port_ext_t epo;
899*11859STom.Pothier@Sun.COM 
900*11859STom.Pothier@Sun.COM 	if (check_oem(shp) != 0)
901*11859STom.Pothier@Sun.COM 		return;
902*11859STom.Pothier@Sun.COM 
903*11859STom.Pothier@Sun.COM 	(void) smbios_info_extport(shp, id, &epo);
904*11859STom.Pothier@Sun.COM 
905*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Chassis Handle: %u\n", epo.smbporte_chassis);
906*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Port Connector Handle: %u\n", epo.smbporte_port);
907*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Device Type: %u\n", epo.smbporte_dtype);
908*11859STom.Pothier@Sun.COM 	oprintf(fp, "  Device Handle: %u\n", epo.smbporte_devhdl);
909*11859STom.Pothier@Sun.COM 	oprintf(fp, "  PHY: %u\n", epo.smbporte_phy);
910*11859STom.Pothier@Sun.COM }
911*11859STom.Pothier@Sun.COM 
912*11859STom.Pothier@Sun.COM static void
print_pciexrc(smbios_hdl_t * shp,id_t id,FILE * fp)91310942STom.Pothier@Sun.COM print_pciexrc(smbios_hdl_t *shp, id_t id, FILE *fp)
91410942STom.Pothier@Sun.COM {
91510942STom.Pothier@Sun.COM 	smbios_pciexrc_t pcie;
91610942STom.Pothier@Sun.COM 
91710942STom.Pothier@Sun.COM 	if (check_oem(shp) != 0)
91810942STom.Pothier@Sun.COM 		return;
91910942STom.Pothier@Sun.COM 
92010942STom.Pothier@Sun.COM 	(void) smbios_info_pciexrc(shp, id, &pcie);
92110942STom.Pothier@Sun.COM 
92210942STom.Pothier@Sun.COM 	oprintf(fp, "  Component ID: %u\n", pcie.smbpcie_bb);
92310942STom.Pothier@Sun.COM 	oprintf(fp, "  BDF: 0x%x\n", pcie.smbpcie_bdf);
92410942STom.Pothier@Sun.COM }
92510942STom.Pothier@Sun.COM 
92610942STom.Pothier@Sun.COM static void
print_extmemarray(smbios_hdl_t * shp,id_t id,FILE * fp)92710942STom.Pothier@Sun.COM print_extmemarray(smbios_hdl_t *shp, id_t id, FILE *fp)
92810942STom.Pothier@Sun.COM {
92910942STom.Pothier@Sun.COM 	smbios_memarray_ext_t em;
93010942STom.Pothier@Sun.COM 
93110942STom.Pothier@Sun.COM 	if (check_oem(shp) != 0)
93210942STom.Pothier@Sun.COM 		return;
93310942STom.Pothier@Sun.COM 
93410942STom.Pothier@Sun.COM 	(void) smbios_info_extmemarray(shp, id, &em);
93510942STom.Pothier@Sun.COM 
93610942STom.Pothier@Sun.COM 	oprintf(fp, "  Physical Memory Array Handle: %u\n", em.smbmae_ma);
93710942STom.Pothier@Sun.COM 	oprintf(fp, "  Component Parent Handle: %u\n", em.smbmae_comp);
93810942STom.Pothier@Sun.COM 	oprintf(fp, "  BDF: 0x%x\n", em.smbmae_bdf);
93910942STom.Pothier@Sun.COM }
94010942STom.Pothier@Sun.COM 
94110942STom.Pothier@Sun.COM static void
print_extmemdevice(smbios_hdl_t * shp,id_t id,FILE * fp)94210942STom.Pothier@Sun.COM print_extmemdevice(smbios_hdl_t *shp, id_t id, FILE *fp)
94310942STom.Pothier@Sun.COM {
94410942STom.Pothier@Sun.COM 	int i;
94510942STom.Pothier@Sun.COM 	smbios_memdevice_ext_t emd;
94610942STom.Pothier@Sun.COM 
94710942STom.Pothier@Sun.COM 	if (check_oem(shp) != 0)
94810942STom.Pothier@Sun.COM 		return;
94910942STom.Pothier@Sun.COM 
95010942STom.Pothier@Sun.COM 	(void) smbios_info_extmemdevice(shp, id, &emd);
95110942STom.Pothier@Sun.COM 
95210942STom.Pothier@Sun.COM 	oprintf(fp, "  Memory Device Handle: %u\n", emd.smbmdeve_md);
95310942STom.Pothier@Sun.COM 	oprintf(fp, "  DRAM Channel: %u\n", emd.smbmdeve_drch);
95410942STom.Pothier@Sun.COM 	oprintf(fp, "  Number of Chip Selects: %u\n", emd.smbmdeve_ncs);
95510942STom.Pothier@Sun.COM 
95610942STom.Pothier@Sun.COM 	for (i = 0; i < emd.smbmdeve_ncs; i++) {
95710942STom.Pothier@Sun.COM 		oprintf(fp, "  Chip Select: %u\n", emd.smbmdeve_cs[i]);
95810942STom.Pothier@Sun.COM 	}
95910942STom.Pothier@Sun.COM }
96010942STom.Pothier@Sun.COM 
96110942STom.Pothier@Sun.COM static int
print_struct(smbios_hdl_t * shp,const smbios_struct_t * sp,void * fp)962437Smws print_struct(smbios_hdl_t *shp, const smbios_struct_t *sp, void *fp)
963437Smws {
964437Smws 	smbios_info_t info;
965437Smws 	int hex = opt_x;
966437Smws 	const char *s;
967437Smws 
968437Smws 	if (opt_t != -1 && opt_t != sp->smbstr_type)
969437Smws 		return (0); /* skip struct if type doesn't match -t */
970437Smws 
971437Smws 	if (!opt_O && (sp->smbstr_type == SMB_TYPE_MEMCTL ||
972437Smws 	    sp->smbstr_type == SMB_TYPE_MEMMOD))
973437Smws 		return (0); /* skip struct if type is obsolete */
974437Smws 
975437Smws 	if (g_hdr++ == 0 || !opt_s)
976437Smws 		oprintf(fp, "%-5s %-4s %s\n", "ID", "SIZE", "TYPE");
977437Smws 
978437Smws 	oprintf(fp, "%-5u %-4lu",
979437Smws 	    (uint_t)sp->smbstr_id, (ulong_t)sp->smbstr_size);
980437Smws 
981437Smws 	if ((s = smbios_type_name(sp->smbstr_type)) != NULL)
982437Smws 		oprintf(fp, " %s", s);
983437Smws 	else if (sp->smbstr_type > SMB_TYPE_OEM_LO &&
984437Smws 	    sp->smbstr_type < SMB_TYPE_OEM_HI)
985437Smws 		oprintf(fp, " %s+%u", "SMB_TYPE_OEM_LO",
986437Smws 		    sp->smbstr_type - SMB_TYPE_OEM_LO);
987437Smws 	else
988437Smws 		oprintf(fp, " %u", sp->smbstr_type);
989437Smws 
990437Smws 	if ((s = smbios_type_desc(sp->smbstr_type)) != NULL)
991437Smws 		oprintf(fp, " (%s)\n", s);
992437Smws 	else
993437Smws 		oprintf(fp, "\n");
994437Smws 
995437Smws 	if (opt_s)
996437Smws 		return (0); /* only print header line if -s specified */
997437Smws 
998437Smws 	if (smbios_info_common(shp, sp->smbstr_id, &info) == 0) {
999437Smws 		oprintf(fp, "\n");
1000437Smws 		print_common(&info, fp);
1001437Smws 	}
1002437Smws 
1003437Smws 	switch (sp->smbstr_type) {
1004437Smws 	case SMB_TYPE_BIOS:
1005437Smws 		oprintf(fp, "\n");
1006437Smws 		print_bios(shp, fp);
1007437Smws 		break;
1008437Smws 	case SMB_TYPE_SYSTEM:
1009437Smws 		oprintf(fp, "\n");
1010437Smws 		print_system(shp, fp);
1011437Smws 		break;
1012437Smws 	case SMB_TYPE_BASEBOARD:
1013437Smws 		oprintf(fp, "\n");
1014437Smws 		print_bboard(shp, sp->smbstr_id, fp);
1015437Smws 		break;
1016437Smws 	case SMB_TYPE_CHASSIS:
1017437Smws 		oprintf(fp, "\n");
1018437Smws 		print_chassis(shp, sp->smbstr_id, fp);
1019437Smws 		break;
1020437Smws 	case SMB_TYPE_PROCESSOR:
1021437Smws 		oprintf(fp, "\n");
1022437Smws 		print_processor(shp, sp->smbstr_id, fp);
1023437Smws 		break;
1024437Smws 	case SMB_TYPE_CACHE:
1025437Smws 		oprintf(fp, "\n");
1026437Smws 		print_cache(shp, sp->smbstr_id, fp);
1027437Smws 		break;
1028437Smws 	case SMB_TYPE_PORT:
1029437Smws 		oprintf(fp, "\n");
1030437Smws 		print_port(shp, sp->smbstr_id, fp);
1031437Smws 		break;
1032437Smws 	case SMB_TYPE_SLOT:
1033437Smws 		oprintf(fp, "\n");
1034437Smws 		print_slot(shp, sp->smbstr_id, fp);
1035437Smws 		break;
1036437Smws 	case SMB_TYPE_OBDEVS:
1037437Smws 		oprintf(fp, "\n");
1038437Smws 		print_obdevs(shp, sp->smbstr_id, fp);
1039437Smws 		break;
1040437Smws 	case SMB_TYPE_OEMSTR:
1041437Smws 	case SMB_TYPE_SYSCONFSTR:
1042437Smws 		oprintf(fp, "\n");
1043437Smws 		print_strtab(shp, sp->smbstr_id, fp);
1044437Smws 		break;
1045437Smws 	case SMB_TYPE_LANG:
1046437Smws 		oprintf(fp, "\n");
1047437Smws 		print_lang(shp, sp->smbstr_id, fp);
1048437Smws 		break;
1049437Smws 	case SMB_TYPE_EVENTLOG:
1050437Smws 		oprintf(fp, "\n");
1051437Smws 		print_evlog(shp, sp->smbstr_id, fp);
1052437Smws 		break;
1053437Smws 	case SMB_TYPE_MEMARRAY:
1054437Smws 		oprintf(fp, "\n");
1055437Smws 		print_memarray(shp, sp->smbstr_id, fp);
1056437Smws 		break;
1057437Smws 	case SMB_TYPE_MEMDEVICE:
1058437Smws 		oprintf(fp, "\n");
1059437Smws 		print_memdevice(shp, sp->smbstr_id, fp);
1060437Smws 		break;
1061437Smws 	case SMB_TYPE_MEMARRAYMAP:
1062437Smws 		oprintf(fp, "\n");
1063437Smws 		print_memarrmap(shp, sp->smbstr_id, fp);
1064437Smws 		break;
1065437Smws 	case SMB_TYPE_MEMDEVICEMAP:
1066437Smws 		oprintf(fp, "\n");
1067437Smws 		print_memdevmap(shp, sp->smbstr_id, fp);
1068437Smws 		break;
1069437Smws 	case SMB_TYPE_SECURITY:
1070437Smws 		oprintf(fp, "\n");
1071437Smws 		print_hwsec(shp, fp);
1072437Smws 		break;
1073437Smws 	case SMB_TYPE_BOOT:
1074437Smws 		oprintf(fp, "\n");
1075437Smws 		print_boot(shp, fp);
1076437Smws 		break;
1077437Smws 	case SMB_TYPE_IPMIDEV:
1078437Smws 		oprintf(fp, "\n");
1079437Smws 		print_ipmi(shp, fp);
1080437Smws 		break;
1081*11859STom.Pothier@Sun.COM 	case SMB_TYPE_OBDEVEXT:
1082*11859STom.Pothier@Sun.COM 		oprintf(fp, "\n");
1083*11859STom.Pothier@Sun.COM 		print_obdevs_ext(shp, sp->smbstr_id, fp);
1084*11859STom.Pothier@Sun.COM 		break;
108510942STom.Pothier@Sun.COM 	case SUN_OEM_EXT_PROCESSOR:
108610942STom.Pothier@Sun.COM 		oprintf(fp, "\n");
108710942STom.Pothier@Sun.COM 		print_extprocessor(shp, sp->smbstr_id, fp);
108810942STom.Pothier@Sun.COM 		break;
1089*11859STom.Pothier@Sun.COM 	case SUN_OEM_EXT_PORT:
1090*11859STom.Pothier@Sun.COM 		oprintf(fp, "\n");
1091*11859STom.Pothier@Sun.COM 		print_extport(shp, sp->smbstr_id, fp);
1092*11859STom.Pothier@Sun.COM 		break;
109310942STom.Pothier@Sun.COM 	case SUN_OEM_PCIEXRC:
109410942STom.Pothier@Sun.COM 		oprintf(fp, "\n");
109510942STom.Pothier@Sun.COM 		print_pciexrc(shp, sp->smbstr_id, fp);
109610942STom.Pothier@Sun.COM 		break;
109710942STom.Pothier@Sun.COM 	case SUN_OEM_EXT_MEMARRAY:
109810942STom.Pothier@Sun.COM 		oprintf(fp, "\n");
109910942STom.Pothier@Sun.COM 		print_extmemarray(shp, sp->smbstr_id, fp);
110010942STom.Pothier@Sun.COM 		break;
110110942STom.Pothier@Sun.COM 	case SUN_OEM_EXT_MEMDEVICE:
110210942STom.Pothier@Sun.COM 		oprintf(fp, "\n");
110310942STom.Pothier@Sun.COM 		print_extmemdevice(shp, sp->smbstr_id, fp);
110410942STom.Pothier@Sun.COM 		break;
1105437Smws 	default:
1106437Smws 		hex++;
1107437Smws 	}
1108437Smws 
1109437Smws 	if (hex)
1110437Smws 		print_bytes(sp->smbstr_data, sp->smbstr_size, fp);
1111437Smws 	else
1112437Smws 		oprintf(fp, "\n");
1113437Smws 
1114437Smws 	return (0);
1115437Smws }
1116437Smws 
1117437Smws static uint16_t
getu16(const char * name,const char * s)1118437Smws getu16(const char *name, const char *s)
1119437Smws {
1120437Smws 	u_longlong_t val;
1121437Smws 	char *p;
1122437Smws 
1123437Smws 	errno = 0;
1124437Smws 	val = strtoull(s, &p, 0);
1125437Smws 
1126437Smws 	if (errno != 0 || p == s || *p != '\0' || val > UINT16_MAX) {
1127437Smws 		(void) fprintf(stderr, "%s: invalid %s argument -- %s\n",
1128437Smws 		    g_pname, name, s);
1129437Smws 		exit(SMBIOS_USAGE);
1130437Smws 	}
1131437Smws 
1132437Smws 	return ((uint16_t)val);
1133437Smws }
1134437Smws 
1135437Smws static uint16_t
getstype(const char * name,const char * s)1136437Smws getstype(const char *name, const char *s)
1137437Smws {
1138437Smws 	const char *ts;
1139437Smws 	uint16_t t;
1140437Smws 
1141437Smws 	for (t = 0; t < SMB_TYPE_OEM_LO; t++) {
1142437Smws 		if ((ts = smbios_type_name(t)) != NULL && strcmp(s, ts) == 0)
1143437Smws 			return (t);
1144437Smws 	}
1145437Smws 
1146437Smws 	(void) fprintf(stderr, "%s: invalid %s argument -- %s\n",
1147437Smws 	    g_pname, name, s);
1148437Smws 
1149437Smws 	exit(SMBIOS_USAGE);
1150437Smws 	/*NOTREACHED*/
1151437Smws }
1152437Smws 
1153437Smws static int
usage(FILE * fp)1154437Smws usage(FILE *fp)
1155437Smws {
1156437Smws 	(void) fprintf(fp, "Usage: %s "
1157437Smws 	    "[-BeOsx] [-i id] [-t type] [-w file] [file]\n\n", g_pname);
1158437Smws 
1159437Smws 	(void) fprintf(fp,
1160437Smws 	    "\t-B disable header validation for broken BIOSes\n"
1161437Smws 	    "\t-e display SMBIOS entry point information\n"
1162437Smws 	    "\t-i display only the specified structure\n"
1163437Smws 	    "\t-O display obsolete structure types\n"
1164437Smws 	    "\t-s display only a summary of structure identifiers and types\n"
1165437Smws 	    "\t-t display only the specified structure type\n"
1166437Smws 	    "\t-w write the raw data to the specified file\n"
1167437Smws 	    "\t-x display raw data for structures\n");
1168437Smws 
1169437Smws 	return (SMBIOS_USAGE);
1170437Smws }
1171437Smws 
1172437Smws int
main(int argc,char * argv[])1173437Smws main(int argc, char *argv[])
1174437Smws {
1175437Smws 	const char *ifile = NULL;
1176437Smws 	const char *ofile = NULL;
1177437Smws 	int oflags = 0;
1178437Smws 
1179437Smws 	smbios_hdl_t *shp;
1180437Smws 	smbios_struct_t s;
1181437Smws 	int err, fd, c;
1182437Smws 	char *p;
1183437Smws 
1184437Smws 	if ((p = strrchr(argv[0], '/')) == NULL)
1185437Smws 		g_pname = argv[0];
1186437Smws 	else
1187437Smws 		g_pname = p + 1;
1188437Smws 
1189437Smws 	while (optind < argc) {
1190437Smws 		while ((c = getopt(argc, argv, "Bei:Ost:w:xZ")) != EOF) {
1191437Smws 			switch (c) {
1192437Smws 			case 'B':
1193437Smws 				oflags |= SMB_O_NOCKSUM | SMB_O_NOVERS;
1194437Smws 				break;
1195437Smws 			case 'e':
1196437Smws 				opt_e++;
1197437Smws 				break;
1198437Smws 			case 'i':
1199437Smws 				opt_i = getu16("struct ID", optarg);
1200437Smws 				break;
1201437Smws 			case 'O':
1202437Smws 				opt_O++;
1203437Smws 				break;
1204437Smws 			case 's':
1205437Smws 				opt_s++;
1206437Smws 				break;
1207437Smws 			case 't':
1208437Smws 				if (isdigit(optarg[0]))
1209437Smws 					opt_t = getu16("struct type", optarg);
1210437Smws 				else
1211437Smws 					opt_t = getstype("struct type", optarg);
1212437Smws 				break;
1213437Smws 			case 'w':
1214437Smws 				ofile = optarg;
1215437Smws 				break;
1216437Smws 			case 'x':
1217437Smws 				opt_x++;
1218437Smws 				break;
1219437Smws 			case 'Z':
1220437Smws 				oflags |= SMB_O_ZIDS; /* undocumented */
1221437Smws 				break;
1222437Smws 			default:
1223437Smws 				return (usage(stderr));
1224437Smws 			}
1225437Smws 		}
1226437Smws 
1227437Smws 		if (optind < argc) {
1228437Smws 			if (ifile != NULL) {
1229437Smws 				(void) fprintf(stderr, "%s: illegal "
1230437Smws 				    "argument -- %s\n", g_pname, argv[optind]);
1231437Smws 				return (SMBIOS_USAGE);
1232437Smws 			}
1233437Smws 			ifile = argv[optind++];
1234437Smws 		}
1235437Smws 	}
1236437Smws 
1237437Smws 	if ((shp = smbios_open(ifile, SMB_VERSION, oflags, &err)) == NULL) {
1238437Smws 		(void) fprintf(stderr, "%s: failed to load SMBIOS: %s\n",
1239437Smws 		    g_pname, smbios_errmsg(err));
1240437Smws 		return (SMBIOS_ERROR);
1241437Smws 	}
1242437Smws 
1243437Smws 	if (ofile != NULL) {
1244437Smws 		if ((fd = open(ofile, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
1245437Smws 			(void) fprintf(stderr, "%s: failed to open %s: %s\n",
1246437Smws 			    g_pname, ofile, strerror(errno));
1247437Smws 			err = SMBIOS_ERROR;
1248437Smws 		} else if (smbios_write(shp, fd) != 0) {
1249437Smws 			(void) fprintf(stderr, "%s: failed to write %s: %s\n",
1250437Smws 			    g_pname, ofile, smbios_errmsg(smbios_errno(shp)));
1251437Smws 			err = SMBIOS_ERROR;
1252437Smws 		}
1253437Smws 		smbios_close(shp);
1254437Smws 		return (err);
1255437Smws 	}
1256437Smws 
1257437Smws 	if (opt_e) {
1258437Smws 		print_smbios(shp, stdout);
1259437Smws 		smbios_close(shp);
1260437Smws 		return (SMBIOS_SUCCESS);
1261437Smws 	}
1262437Smws 
1263437Smws 	if (opt_O && (opt_i != -1 || opt_t != -1))
1264437Smws 		opt_O++; /* -i or -t imply displaying obsolete records */
1265437Smws 
1266437Smws 	if (opt_i != -1)
1267437Smws 		err = smbios_lookup_id(shp, opt_i, &s);
1268437Smws 	else
1269437Smws 		err = smbios_iter(shp, print_struct, stdout);
1270437Smws 
1271437Smws 	if (err != 0) {
1272437Smws 		(void) fprintf(stderr, "%s: failed to access SMBIOS: %s\n",
1273437Smws 		    g_pname, smbios_errmsg(smbios_errno(shp)));
1274437Smws 		smbios_close(shp);
1275437Smws 		return (SMBIOS_ERROR);
1276437Smws 	}
1277437Smws 
1278437Smws 	if (opt_i != -1)
1279437Smws 		(void) print_struct(shp, &s, stdout);
1280437Smws 
1281437Smws 	smbios_close(shp);
1282437Smws 	return (SMBIOS_SUCCESS);
1283437Smws }
1284