xref: /illumos-gate/usr/src/cmd/smbios/smbios.c (revision db2effc6fa1e364418090bfc0ca0cfd267792bea)
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 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
24  * Copyright (c) 2017, Joyent, Inc.
25  * Copyright 2021 Oxide Computer Company
26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #include <sys/sysmacros.h>
31 #include <sys/param.h>
32 
33 #include <smbios.h>
34 #include <alloca.h>
35 #include <limits.h>
36 #include <unistd.h>
37 #include <strings.h>
38 #include <stdlib.h>
39 #include <stdarg.h>
40 #include <stdio.h>
41 #include <fcntl.h>
42 #include <errno.h>
43 #include <ctype.h>
44 #include <libjedec.h>
45 
46 #define	SMBIOS_SUCCESS	0
47 #define	SMBIOS_ERROR	1
48 #define	SMBIOS_USAGE	2
49 
50 static const char *g_pname;
51 static int g_hdr;
52 
53 static int opt_e;
54 static int opt_i = -1;
55 static int opt_O;
56 static int opt_s;
57 static int opt_t = -1;
58 static int opt_x;
59 
60 static boolean_t
61 smbios_vergteq(smbios_version_t *v, uint_t major, uint_t minor)
62 {
63 	if (v->smbv_major > major)
64 		return (B_TRUE);
65 	if (v->smbv_major == major &&
66 	    v->smbv_minor >= minor)
67 		return (B_TRUE);
68 	return (B_FALSE);
69 }
70 
71 /*PRINTFLIKE2*/
72 static void
73 smbios_warn(smbios_hdl_t *shp, const char *format, ...)
74 {
75 	va_list ap;
76 
77 	va_start(ap, format);
78 	(void) vfprintf(stderr, format, ap);
79 	va_end(ap);
80 
81 	if (shp != NULL) {
82 		(void) fprintf(stderr, ": %s",
83 		    smbios_errmsg(smbios_errno(shp)));
84 	}
85 
86 	(void) fprintf(stderr, "\n");
87 }
88 
89 /*PRINTFLIKE2*/
90 static void
91 oprintf(FILE *fp, const char *format, ...)
92 {
93 	va_list ap;
94 
95 	va_start(ap, format);
96 	(void) vfprintf(fp, format, ap);
97 	va_end(ap);
98 }
99 
100 /*PRINTFLIKE3*/
101 static void
102 desc_printf(const char *d, FILE *fp, const char *format, ...)
103 {
104 	va_list ap;
105 
106 	va_start(ap, format);
107 	(void) vfprintf(fp, format, ap);
108 	va_end(ap);
109 
110 	if (d != NULL)
111 		(void) fprintf(fp, " (%s)\n", d);
112 	else
113 		(void) fprintf(fp, "\n");
114 }
115 
116 static void
117 flag_printf(FILE *fp, const char *s, uint_t flags, size_t bits,
118     const char *(*flag_name)(uint_t), const char *(*flag_desc)(uint_t))
119 {
120 	size_t i;
121 
122 	oprintf(fp, "  %s: 0x%x\n", s, flags);
123 
124 	for (i = 0; i < bits; i++) {
125 		uint_t f = 1 << i;
126 		const char *n;
127 
128 		if (!(flags & f))
129 			continue;
130 
131 		if ((n = flag_name(f)) != NULL)
132 			desc_printf(flag_desc(f), fp, "\t%s", n);
133 		else
134 			desc_printf(flag_desc(f), fp, "\t0x%x", f);
135 	}
136 }
137 
138 static void
139 flag64_printf(FILE *fp, const char *s, uint64_t flags, size_t bits,
140     const char *(*flag_name)(uint64_t), const char *(*flag_desc)(uint64_t))
141 {
142 	size_t i;
143 
144 	oprintf(fp, "  %s: 0x%llx\n", s, (u_longlong_t)flags);
145 
146 	for (i = 0; i < bits; i++) {
147 		u_longlong_t f = 1ULL << i;
148 		const char *n;
149 
150 		if (!(flags & f))
151 			continue;
152 
153 		if ((n = flag_name(f)) != NULL)
154 			desc_printf(flag_desc(f), fp, "\t%s", n);
155 		else
156 			desc_printf(flag_desc(f), fp, "\t0x%llx", f);
157 	}
158 }
159 
160 static void
161 id_printf(FILE *fp, const char *s, id_t id)
162 {
163 	switch (id) {
164 	case SMB_ID_NONE:
165 		oprintf(fp, "%sNone\n", s);
166 		break;
167 	case SMB_ID_NOTSUP:
168 		oprintf(fp, "%sNot Supported\n", s);
169 		break;
170 	default:
171 		oprintf(fp, "%s%u\n", s, (uint_t)id);
172 	}
173 }
174 
175 static void
176 jedec_print(FILE *fp, const char *desc, uint_t id)
177 {
178 	const char *name;
179 	uint_t cont, vendor;
180 
181 	/*
182 	 * SMBIOS encodes data in the way that the underlying memory standard
183 	 * does. In this case, the upper byte indicates the vendor that we care
184 	 * about while the lower byte indicates the number of continuations that
185 	 * are needed. libjedec indexes this based on zero (e.g. table 1 is zero
186 	 * continuations), which is how the spec encodes it. We add one so that
187 	 * we can match how the spec describes it.
188 	 */
189 	vendor = id >> 8;
190 	cont = id & 0x7f;
191 	name = libjedec_vendor_string(cont, vendor);
192 	if (name == NULL) {
193 		oprintf(fp, "  %s: Bank: 0x%x Vendor: 0x%x\n", desc, cont + 1,
194 		    vendor);
195 	} else {
196 		oprintf(fp, "  %s: Bank: 0x%x Vendor: 0x%x (%s)\n", desc,
197 		    cont + 1, vendor, name);
198 	}
199 }
200 
201 /*
202  * Print a 128-bit data as a series of 16 hex digits.
203  */
204 static void
205 u128_print(FILE *fp, const char *desc, const uint8_t *data)
206 {
207 	uint_t i;
208 
209 	oprintf(fp, "%s: ", desc);
210 	for (i = 0; i < 16; i++) {
211 		oprintf(fp, " %02x", data[i]);
212 	}
213 	oprintf(fp, "\n");
214 }
215 
216 /*
217  * Print a string that came from an SMBIOS table. We do this character by
218  * character so we can potentially escape strings.
219  */
220 static void
221 str_print_label(FILE *fp, const char *header, const char *str, boolean_t label)
222 {
223 	const char *c;
224 
225 	oprintf(fp, header);
226 	if (label) {
227 		oprintf(fp, ": ");
228 	}
229 
230 	for (c = str; *c != '\0'; c++) {
231 		if (isprint(*c)) {
232 			oprintf(fp, "%c", *c);
233 		} else {
234 			oprintf(fp, "\\x%02x", *c);
235 		}
236 	}
237 
238 	oprintf(fp, "\n");
239 }
240 
241 static void
242 str_print_nolabel(FILE *fp, const char *ws, const char *str)
243 {
244 	return (str_print_label(fp, ws, str, B_FALSE));
245 }
246 
247 static void
248 str_print(FILE *fp, const char *header, const char *str)
249 {
250 	return (str_print_label(fp, header, str, B_TRUE));
251 }
252 
253 static int
254 check_oem(smbios_hdl_t *shp)
255 {
256 	int i;
257 	int cnt;
258 	int rv;
259 	id_t oem_id;
260 	smbios_struct_t s;
261 	const char **oem_str;
262 
263 	rv = smbios_lookup_type(shp, SMB_TYPE_OEMSTR, &s);
264 	if (rv != 0) {
265 		return (-1);
266 	}
267 
268 	oem_id = s.smbstr_id;
269 
270 	cnt = smbios_info_strtab(shp, oem_id, 0, NULL);
271 	if (cnt > 0) {
272 		oem_str =  alloca(sizeof (char *) * cnt);
273 		(void) smbios_info_strtab(shp, oem_id, cnt, oem_str);
274 
275 		for (i = 0; i < cnt; i++) {
276 			if (strncmp(oem_str[i], SMB_PRMS1,
277 			    strlen(SMB_PRMS1) + 1) == 0) {
278 				return (0);
279 			}
280 		}
281 	}
282 
283 	return (-1);
284 }
285 
286 static void
287 print_smbios_21(smbios_21_entry_t *ep, FILE *fp)
288 {
289 	int i;
290 
291 	oprintf(fp, "Entry Point Anchor Tag: %*.*s\n",
292 	    (int)sizeof (ep->smbe_eanchor), (int)sizeof (ep->smbe_eanchor),
293 	    ep->smbe_eanchor);
294 
295 	oprintf(fp, "Entry Point Checksum: 0x%x\n", ep->smbe_ecksum);
296 	oprintf(fp, "Entry Point Length: %u\n", ep->smbe_elen);
297 	oprintf(fp, "Entry Point Version: %u.%u\n",
298 	    ep->smbe_major, ep->smbe_minor);
299 	oprintf(fp, "Max Structure Size: %u\n", ep->smbe_maxssize);
300 	oprintf(fp, "Entry Point Revision: 0x%x\n", ep->smbe_revision);
301 
302 	oprintf(fp, "Entry Point Revision Data:");
303 	for (i = 0; i < sizeof (ep->smbe_format); i++)
304 		oprintf(fp, " 0x%02x", ep->smbe_format[i]);
305 	oprintf(fp, "\n");
306 
307 	oprintf(fp, "Intermediate Anchor Tag: %*.*s\n",
308 	    (int)sizeof (ep->smbe_ianchor), (int)sizeof (ep->smbe_ianchor),
309 	    ep->smbe_ianchor);
310 
311 	oprintf(fp, "Intermediate Checksum: 0x%x\n", ep->smbe_icksum);
312 	oprintf(fp, "Structure Table Length: %u\n", ep->smbe_stlen);
313 	oprintf(fp, "Structure Table Address: 0x%x\n", ep->smbe_staddr);
314 	oprintf(fp, "Structure Table Entries: %u\n", ep->smbe_stnum);
315 	oprintf(fp, "DMI BCD Revision: 0x%x\n", ep->smbe_bcdrev);
316 }
317 
318 static void
319 print_smbios_30(smbios_30_entry_t *ep, FILE *fp)
320 {
321 	oprintf(fp, "Entry Point Anchor Tag: %*.*s\n",
322 	    (int)sizeof (ep->smbe_eanchor), (int)sizeof (ep->smbe_eanchor),
323 	    ep->smbe_eanchor);
324 
325 	oprintf(fp, "Entry Point Checksum: 0x%x\n", ep->smbe_ecksum);
326 	oprintf(fp, "Entry Point Length: %u\n", ep->smbe_elen);
327 	oprintf(fp, "SMBIOS Version: %u.%u\n",
328 	    ep->smbe_major, ep->smbe_minor);
329 	oprintf(fp, "SMBIOS DocRev: 0x%x\n", ep->smbe_docrev);
330 	oprintf(fp, "Entry Point Revision: 0x%x\n", ep->smbe_revision);
331 
332 	oprintf(fp, "Structure Table Length: %u\n", ep->smbe_stlen);
333 	oprintf(fp, "Structure Table Address: 0x%" PRIx64 "\n",
334 	    ep->smbe_staddr);
335 }
336 
337 static void
338 print_smbios(smbios_hdl_t *shp, FILE *fp)
339 {
340 	smbios_entry_t ep;
341 
342 	switch (smbios_info_smbios(shp, &ep)) {
343 	case SMBIOS_ENTRY_POINT_21:
344 		print_smbios_21(&ep.ep21, fp);
345 		break;
346 	case SMBIOS_ENTRY_POINT_30:
347 		print_smbios_30(&ep.ep30, fp);
348 		break;
349 	}
350 }
351 
352 static void
353 print_common(const smbios_info_t *ip, FILE *fp)
354 {
355 	if (ip->smbi_manufacturer[0] != '\0')
356 		str_print(fp, "  Manufacturer", ip->smbi_manufacturer);
357 	if (ip->smbi_product[0] != '\0')
358 		str_print(fp, "  Product", ip->smbi_product);
359 	if (ip->smbi_version[0] != '\0')
360 		str_print(fp, "  Version", ip->smbi_version);
361 	if (ip->smbi_serial[0] != '\0')
362 		str_print(fp, "  Serial Number", ip->smbi_serial);
363 	if (ip->smbi_asset[0] != '\0')
364 		str_print(fp, "  Asset Tag", ip->smbi_asset);
365 	if (ip->smbi_location[0] != '\0')
366 		str_print(fp, "  Location Tag", ip->smbi_location);
367 	if (ip->smbi_part[0] != '\0')
368 		str_print(fp, "  Part Number", ip->smbi_part);
369 }
370 
371 static void
372 print_bios(smbios_hdl_t *shp, FILE *fp)
373 {
374 	smbios_bios_t b;
375 
376 	(void) smbios_info_bios(shp, &b);
377 
378 	str_print(fp, "  Vendor", b.smbb_vendor);
379 	str_print(fp, "  Version String", b.smbb_version);
380 	str_print(fp, "  Release Date", b.smbb_reldate);
381 	oprintf(fp, "  Address Segment: 0x%x\n", b.smbb_segment);
382 	oprintf(fp, "  ROM Size: %" PRIu64 " bytes\n", b.smbb_extromsize);
383 	oprintf(fp, "  Image Size: %u bytes\n", b.smbb_runsize);
384 
385 	flag64_printf(fp, "Characteristics",
386 	    b.smbb_cflags, sizeof (b.smbb_cflags) * NBBY,
387 	    smbios_bios_flag_name, smbios_bios_flag_desc);
388 
389 	if (b.smbb_nxcflags > SMB_BIOSXB_1) {
390 		flag_printf(fp, "Characteristics Extension Byte 1",
391 		    b.smbb_xcflags[SMB_BIOSXB_1],
392 		    sizeof (b.smbb_xcflags[SMB_BIOSXB_1]) * NBBY,
393 		    smbios_bios_xb1_name, smbios_bios_xb1_desc);
394 	}
395 
396 	if (b.smbb_nxcflags > SMB_BIOSXB_2) {
397 		flag_printf(fp, "Characteristics Extension Byte 2",
398 		    b.smbb_xcflags[SMB_BIOSXB_2],
399 		    sizeof (b.smbb_xcflags[SMB_BIOSXB_2]) * NBBY,
400 		    smbios_bios_xb2_name, smbios_bios_xb2_desc);
401 	}
402 
403 	if (b.smbb_nxcflags > SMB_BIOSXB_BIOS_MIN) {
404 		oprintf(fp, "  Version Number: %u.%u\n",
405 		    b.smbb_biosv.smbv_major, b.smbb_biosv.smbv_minor);
406 	}
407 
408 	/*
409 	 * If the major and minor versions are 0xff then that indicates that the
410 	 * embedded controller does not exist.
411 	 */
412 	if (b.smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
413 	    b.smbb_ecfwv.smbv_major != 0xff &&
414 	    b.smbb_ecfwv.smbv_minor != 0xff) {
415 		oprintf(fp, "  Embedded Ctlr Firmware Version Number: %u.%u\n",
416 		    b.smbb_ecfwv.smbv_major, b.smbb_ecfwv.smbv_minor);
417 	}
418 }
419 
420 static void
421 print_system(smbios_hdl_t *shp, FILE *fp)
422 {
423 	smbios_system_t s;
424 	uint_t i;
425 
426 	(void) smbios_info_system(shp, &s);
427 
428 	oprintf(fp, "  UUID: ");
429 	for (i = 0; i < s.smbs_uuidlen; i++) {
430 		oprintf(fp, "%02x", s.smbs_uuid[i]);
431 		if (i == 3 || i == 5 || i == 7 || i == 9)
432 			oprintf(fp, "-");
433 	}
434 	oprintf(fp, "\n");
435 
436 	desc_printf(smbios_system_wakeup_desc(s.smbs_wakeup),
437 	    fp, "  Wake-Up Event: 0x%x", s.smbs_wakeup);
438 
439 	str_print(fp, "  SKU Number", s.smbs_sku);
440 	str_print(fp, "  Family", s.smbs_family);
441 }
442 
443 static void
444 print_bboard(smbios_hdl_t *shp, id_t id, FILE *fp)
445 {
446 	smbios_bboard_t b;
447 	int chdl_cnt;
448 
449 	(void) smbios_info_bboard(shp, id, &b);
450 
451 	oprintf(fp, "  Chassis: %u\n", (uint_t)b.smbb_chassis);
452 
453 	flag_printf(fp, "Flags", b.smbb_flags, sizeof (b.smbb_flags) * NBBY,
454 	    smbios_bboard_flag_name, smbios_bboard_flag_desc);
455 
456 	desc_printf(smbios_bboard_type_desc(b.smbb_type),
457 	    fp, "  Board Type: 0x%x", b.smbb_type);
458 
459 	chdl_cnt = b.smbb_contn;
460 	if (chdl_cnt != 0) {
461 		id_t *chdl;
462 		uint16_t hdl;
463 		int i, n, cnt;
464 
465 		chdl = alloca(chdl_cnt * sizeof (id_t));
466 		cnt = smbios_info_contains(shp, id, chdl_cnt, chdl);
467 		if (cnt > SMB_CONT_MAX)
468 			return;
469 		n = MIN(chdl_cnt, cnt);
470 
471 		oprintf(fp, "\n");
472 		for (i = 0; i < n; i++) {
473 			hdl = (uint16_t)chdl[i];
474 			oprintf(fp, "  Contained Handle: %u\n", hdl);
475 		}
476 	}
477 }
478 
479 static void
480 print_chassis(smbios_hdl_t *shp, id_t id, FILE *fp)
481 {
482 	smbios_chassis_t c;
483 	int elem_cnt;
484 
485 	(void) smbios_info_chassis(shp, id, &c);
486 
487 	oprintf(fp, "  OEM Data: 0x%x\n", c.smbc_oemdata);
488 	str_print(fp, "  SKU Number",
489 	    c.smbc_sku[0] == '\0' ? "<unknown>" : c.smbc_sku);
490 	oprintf(fp, "  Lock Present: %s\n", c.smbc_lock ? "Y" : "N");
491 
492 	desc_printf(smbios_chassis_type_desc(c.smbc_type),
493 	    fp, "  Chassis Type: 0x%x", c.smbc_type);
494 
495 	desc_printf(smbios_chassis_state_desc(c.smbc_bustate),
496 	    fp, "  Boot-Up State: 0x%x", c.smbc_bustate);
497 
498 	desc_printf(smbios_chassis_state_desc(c.smbc_psstate),
499 	    fp, "  Power Supply State: 0x%x", c.smbc_psstate);
500 
501 	desc_printf(smbios_chassis_state_desc(c.smbc_thstate),
502 	    fp, "  Thermal State: 0x%x", c.smbc_thstate);
503 
504 	oprintf(fp, "  Chassis Height: %uu\n", c.smbc_uheight);
505 	oprintf(fp, "  Power Cords: %u\n", c.smbc_cords);
506 
507 	elem_cnt = c.smbc_elems;
508 	oprintf(fp, "  Element Records: %u\n", elem_cnt);
509 
510 	if (elem_cnt > 0) {
511 		id_t *elems;
512 		uint8_t type;
513 		int i, n, cnt;
514 
515 		elems = alloca(c.smbc_elems * sizeof (id_t));
516 		cnt = smbios_info_contains(shp, id, elem_cnt, elems);
517 		if (cnt > SMB_CONT_MAX)
518 			return;
519 		n = MIN(elem_cnt, cnt);
520 
521 		oprintf(fp, "\n");
522 		for (i = 0; i < n; i++) {
523 			type = (uint8_t)elems[i];
524 			if (type & 0x80) {
525 				/* SMBIOS structrure Type */
526 				desc_printf(smbios_type_name(type & 0x7f), fp,
527 				    "  Contained SMBIOS structure Type: %u",
528 				    type & 0x80);
529 			} else {
530 				/* SMBIOS Base Board Type */
531 				desc_printf(smbios_bboard_type_desc(type), fp,
532 				    "  Contained SMBIOS Base Board Type: 0x%x",
533 				    type);
534 			}
535 		}
536 	}
537 }
538 
539 static void
540 print_processor(smbios_hdl_t *shp, id_t id, FILE *fp)
541 {
542 	smbios_processor_t p;
543 	uint_t status;
544 
545 	(void) smbios_info_processor(shp, id, &p);
546 	status = SMB_PRSTATUS_STATUS(p.smbp_status);
547 
548 	desc_printf(smbios_processor_family_desc(p.smbp_family),
549 	    fp, "  Family: %u", p.smbp_family);
550 
551 	oprintf(fp, "  CPUID: 0x%llx\n", (u_longlong_t)p.smbp_cpuid);
552 
553 	desc_printf(smbios_processor_type_desc(p.smbp_type),
554 	    fp, "  Type: %u", p.smbp_type);
555 
556 	desc_printf(smbios_processor_upgrade_desc(p.smbp_upgrade),
557 	    fp, "  Socket Upgrade: %u", p.smbp_upgrade);
558 
559 	oprintf(fp, "  Socket Status: %s\n",
560 	    SMB_PRSTATUS_PRESENT(p.smbp_status) ?
561 	    "Populated" : "Not Populated");
562 
563 	desc_printf(smbios_processor_status_desc(status),
564 	    fp, "  Processor Status: %u", status);
565 
566 	if (SMB_PRV_LEGACY(p.smbp_voltage)) {
567 		oprintf(fp, "  Supported Voltages:");
568 		switch (p.smbp_voltage) {
569 		case SMB_PRV_5V:
570 			oprintf(fp, " 5.0V");
571 			break;
572 		case SMB_PRV_33V:
573 			oprintf(fp, " 3.3V");
574 			break;
575 		case SMB_PRV_29V:
576 			oprintf(fp, " 2.9V");
577 			break;
578 		}
579 		oprintf(fp, "\n");
580 	} else {
581 		oprintf(fp, "  Supported Voltages: %.1fV\n",
582 		    (float)SMB_PRV_VOLTAGE(p.smbp_voltage) / 10);
583 	}
584 
585 	if (p.smbp_corecount != 0) {
586 		oprintf(fp, "  Core Count: %u\n", p.smbp_corecount);
587 	} else {
588 		oprintf(fp, "  Core Count: Unknown\n");
589 	}
590 
591 	if (p.smbp_coresenabled != 0) {
592 		oprintf(fp, "  Cores Enabled: %u\n", p.smbp_coresenabled);
593 	} else {
594 		oprintf(fp, "  Cores Enabled: Unknown\n");
595 	}
596 
597 	if (p.smbp_threadcount != 0) {
598 		oprintf(fp, "  Thread Count: %u\n", p.smbp_threadcount);
599 	} else {
600 		oprintf(fp, "  Thread Count: Unknown\n");
601 	}
602 
603 	if (p.smbp_cflags) {
604 		flag_printf(fp, "Processor Characteristics",
605 		    p.smbp_cflags, sizeof (p.smbp_cflags) * NBBY,
606 		    smbios_processor_core_flag_name,
607 		    smbios_processor_core_flag_desc);
608 	}
609 
610 	if (p.smbp_clkspeed != 0)
611 		oprintf(fp, "  External Clock Speed: %uMHz\n", p.smbp_clkspeed);
612 	else
613 		oprintf(fp, "  External Clock Speed: Unknown\n");
614 
615 	if (p.smbp_maxspeed != 0)
616 		oprintf(fp, "  Maximum Speed: %uMHz\n", p.smbp_maxspeed);
617 	else
618 		oprintf(fp, "  Maximum Speed: Unknown\n");
619 
620 	if (p.smbp_curspeed != 0)
621 		oprintf(fp, "  Current Speed: %uMHz\n", p.smbp_curspeed);
622 	else
623 		oprintf(fp, "  Current Speed: Unknown\n");
624 
625 	id_printf(fp, "  L1 Cache Handle: ", p.smbp_l1cache);
626 	id_printf(fp, "  L2 Cache Handle: ", p.smbp_l2cache);
627 	id_printf(fp, "  L3 Cache Handle: ", p.smbp_l3cache);
628 }
629 
630 static void
631 print_cache(smbios_hdl_t *shp, id_t id, FILE *fp)
632 {
633 	smbios_cache_t c;
634 
635 	(void) smbios_info_cache(shp, id, &c);
636 
637 	oprintf(fp, "  Level: %u\n", c.smba_level);
638 	oprintf(fp, "  Maximum Installed Size: %" PRIu64 " bytes\n",
639 	    c.smba_maxsize2);
640 
641 	if (c.smba_size2 != 0) {
642 		oprintf(fp, "  Installed Size: %" PRIu64 " bytes\n",
643 		    c.smba_size2);
644 	} else {
645 		oprintf(fp, "  Installed Size: Not Installed\n");
646 	}
647 
648 	if (c.smba_speed != 0)
649 		oprintf(fp, "  Speed: %uns\n", c.smba_speed);
650 	else
651 		oprintf(fp, "  Speed: Unknown\n");
652 
653 	flag_printf(fp, "Supported SRAM Types",
654 	    c.smba_stype, sizeof (c.smba_stype) * NBBY,
655 	    smbios_cache_ctype_name, smbios_cache_ctype_desc);
656 
657 	desc_printf(smbios_cache_ctype_desc(c.smba_ctype),
658 	    fp, "  Current SRAM Type: 0x%x", c.smba_ctype);
659 
660 	desc_printf(smbios_cache_ecc_desc(c.smba_etype),
661 	    fp, "  Error Correction Type: %u", c.smba_etype);
662 
663 	desc_printf(smbios_cache_logical_desc(c.smba_ltype),
664 	    fp, "  Logical Cache Type: %u", c.smba_ltype);
665 
666 	desc_printf(smbios_cache_assoc_desc(c.smba_assoc),
667 	    fp, "  Associativity: %u", c.smba_assoc);
668 
669 	desc_printf(smbios_cache_mode_desc(c.smba_mode),
670 	    fp, "  Mode: %u", c.smba_mode);
671 
672 	desc_printf(smbios_cache_loc_desc(c.smba_location),
673 	    fp, "  Location: %u", c.smba_location);
674 
675 	flag_printf(fp, "Flags", c.smba_flags, sizeof (c.smba_flags) * NBBY,
676 	    smbios_cache_flag_name, smbios_cache_flag_desc);
677 }
678 
679 static void
680 print_port(smbios_hdl_t *shp, id_t id, FILE *fp)
681 {
682 	smbios_port_t p;
683 
684 	(void) smbios_info_port(shp, id, &p);
685 
686 	str_print(fp, "  Internal Reference Designator", p.smbo_iref);
687 	str_print(fp, "  External Reference Designator", p.smbo_eref);
688 
689 	desc_printf(smbios_port_conn_desc(p.smbo_itype),
690 	    fp, "  Internal Connector Type: %u", p.smbo_itype);
691 
692 	desc_printf(smbios_port_conn_desc(p.smbo_etype),
693 	    fp, "  External Connector Type: %u", p.smbo_etype);
694 
695 	desc_printf(smbios_port_type_desc(p.smbo_ptype),
696 	    fp, "  Port Type: %u", p.smbo_ptype);
697 }
698 
699 static void
700 print_slot(smbios_hdl_t *shp, id_t id, FILE *fp)
701 {
702 	smbios_slot_t s;
703 	smbios_version_t v;
704 
705 	(void) smbios_info_slot(shp, id, &s);
706 	smbios_info_smbios_version(shp, &v);
707 
708 	str_print(fp, "  Reference Designator", s.smbl_name);
709 	oprintf(fp, "  Slot ID: 0x%x\n", s.smbl_id);
710 
711 	desc_printf(smbios_slot_type_desc(s.smbl_type),
712 	    fp, "  Type: 0x%x", s.smbl_type);
713 
714 	desc_printf(smbios_slot_width_desc(s.smbl_width),
715 	    fp, "  Width: 0x%x", s.smbl_width);
716 
717 	desc_printf(smbios_slot_usage_desc(s.smbl_usage),
718 	    fp, "  Usage: 0x%x", s.smbl_usage);
719 
720 	desc_printf(smbios_slot_length_desc(s.smbl_length),
721 	    fp, "  Length: 0x%x", s.smbl_length);
722 
723 	flag_printf(fp, "Slot Characteristics 1",
724 	    s.smbl_ch1, sizeof (s.smbl_ch1) * NBBY,
725 	    smbios_slot_ch1_name, smbios_slot_ch1_desc);
726 
727 	flag_printf(fp, "Slot Characteristics 2",
728 	    s.smbl_ch2, sizeof (s.smbl_ch2) * NBBY,
729 	    smbios_slot_ch2_name, smbios_slot_ch2_desc);
730 
731 	if (check_oem(shp) != 0 && !smbios_vergteq(&v, 2, 6))
732 		return;
733 
734 	oprintf(fp, "  Segment Group: %u\n", s.smbl_sg);
735 	oprintf(fp, "  Bus Number: %u\n", s.smbl_bus);
736 	oprintf(fp, "  Device/Function Number: %u/%u\n", s.smbl_df >> 3,
737 	    s.smbl_df & 0x7);
738 
739 	if (s.smbl_dbw != 0) {
740 		oprintf(fp, "  Data Bus Width: %d\n", s.smbl_dbw);
741 	}
742 
743 	if (s.smbl_npeers > 0) {
744 		smbios_slot_peer_t *peer;
745 		uint_t i, npeers;
746 
747 		if (smbios_info_slot_peers(shp, id, &npeers, &peer) != 0) {
748 			smbios_warn(shp, "failed to read slot peer "
749 			    "information");
750 			return;
751 		}
752 
753 		for (i = 0; i < npeers; i++) {
754 			oprintf(fp, "  Slot Peer %u:\n", i);
755 			oprintf(fp, "    Segment group: %u\n",
756 			    peer[i].smblp_group);
757 			oprintf(fp, "    Bus/Device/Function: %u/%u/%u\n",
758 			    peer[i].smblp_bus, peer[i].smblp_device,
759 			    peer[i].smblp_function);
760 			oprintf(fp, "    Electrical width: %u\n",
761 			    peer[i].smblp_data_width);
762 		}
763 
764 		smbios_info_slot_peers_free(shp, npeers, peer);
765 	}
766 
767 	if (s.smbl_info != 0) {
768 		if (s.smbl_type >= SMB_SLT_PCIE &&
769 		    s.smbl_type <= SMB_SLT_PCIEG6P) {
770 			oprintf(fp, "  PCIe Generation: %d\n", s.smbl_info);
771 		} else {
772 			oprintf(fp, "  Slot Type: 0x%x\n", s.smbl_info);
773 		}
774 	}
775 
776 	if (s.smbl_pwidth != 0) {
777 		desc_printf(smbios_slot_width_desc(s.smbl_pwidth),
778 		    fp, "  Physical Width: 0x%x", s.smbl_pwidth);
779 	}
780 
781 	if (s.smbl_pitch != 0) {
782 		oprintf(fp, "  Slot Pitch: %u.%u mm\n", s.smbl_pitch / 100,
783 		    s.smbl_pitch % 100);
784 	}
785 }
786 
787 static void
788 print_obdevs_ext(smbios_hdl_t *shp, id_t id, FILE *fp)
789 {
790 	boolean_t enabled;
791 	smbios_obdev_ext_t oe;
792 	const char *type;
793 
794 	(void) smbios_info_obdevs_ext(shp, id, &oe);
795 
796 	/*
797 	 * Bit 7 is always whether or not the device is enabled while bits 0:6
798 	 * are the actual device type.
799 	 */
800 	enabled = oe.smboe_dtype >> 7;
801 	type = smbios_onboard_type_desc(oe.smboe_dtype & 0x7f);
802 
803 	str_print(fp, "  Reference Designator", oe.smboe_name);
804 	oprintf(fp, "  Device Enabled: %s\n", enabled == B_TRUE ? "true" :
805 	    "false");
806 	oprintf(fp, "  Device Type: %s\n", type);
807 	oprintf(fp, "  Device Type Instance: %u\n", oe.smboe_dti);
808 	oprintf(fp, "  Segment Group Number: %u\n", oe.smboe_sg);
809 	oprintf(fp, "  Bus Number: %u\n", oe.smboe_bus);
810 	oprintf(fp, "  Device/Function Number: %u\n", oe.smboe_df);
811 }
812 
813 static void
814 print_obdevs(smbios_hdl_t *shp, id_t id, FILE *fp)
815 {
816 	smbios_obdev_t *argv;
817 	int i, argc;
818 
819 	if ((argc = smbios_info_obdevs(shp, id, 0, NULL)) > 0) {
820 		argv = alloca(sizeof (smbios_obdev_t) * argc);
821 		(void) smbios_info_obdevs(shp, id, argc, argv);
822 		for (i = 0; i < argc; i++)
823 			str_print_nolabel(fp, "  ", argv[i].smbd_name);
824 	}
825 }
826 
827 static void
828 print_strtab(smbios_hdl_t *shp, id_t id, FILE *fp)
829 {
830 	const char **argv;
831 	int i, argc;
832 
833 	if ((argc = smbios_info_strtab(shp, id, 0, NULL)) > 0) {
834 		argv = alloca(sizeof (char *) * argc);
835 		(void) smbios_info_strtab(shp, id, argc, argv);
836 		for (i = 0; i < argc; i++)
837 			str_print_nolabel(fp, "  ", argv[i]);
838 	}
839 }
840 
841 static void
842 print_lang(smbios_hdl_t *shp, id_t id, FILE *fp)
843 {
844 	smbios_lang_t l;
845 
846 	(void) smbios_info_lang(shp, &l);
847 
848 	str_print(fp, "  Current Language", l.smbla_cur);
849 	oprintf(fp, "  Language String Format: %u\n", l.smbla_fmt);
850 	oprintf(fp, "  Number of Installed Languages: %u\n", l.smbla_num);
851 	oprintf(fp, "  Installed Languages:\n");
852 
853 	print_strtab(shp, id, fp);
854 }
855 
856 /*ARGSUSED*/
857 static void
858 print_evlog(smbios_hdl_t *shp, id_t id, FILE *fp)
859 {
860 	smbios_evlog_t ev;
861 	uint32_t i;
862 
863 	(void) smbios_info_eventlog(shp, &ev);
864 
865 	oprintf(fp, "  Log Area Size: %lu bytes\n", (ulong_t)ev.smbev_size);
866 	oprintf(fp, "  Header Offset: %lu\n", (ulong_t)ev.smbev_hdr);
867 	oprintf(fp, "  Data Offset: %lu\n", (ulong_t)ev.smbev_data);
868 
869 	desc_printf(smbios_evlog_method_desc(ev.smbev_method),
870 	    fp, "  Data Access Method: %u", ev.smbev_method);
871 
872 	flag_printf(fp, "Log Flags",
873 	    ev.smbev_flags, sizeof (ev.smbev_flags) * NBBY,
874 	    smbios_evlog_flag_name, smbios_evlog_flag_desc);
875 
876 	desc_printf(smbios_evlog_format_desc(ev.smbev_format),
877 	    fp, "  Log Header Format: %u", ev.smbev_format);
878 
879 	oprintf(fp, "  Update Token: 0x%x\n", ev.smbev_token);
880 	oprintf(fp, "  Data Access Address: ");
881 
882 	switch (ev.smbev_method) {
883 	case SMB_EVM_1x1i_1x1d:
884 	case SMB_EVM_2x1i_1x1d:
885 	case SMB_EVM_1x2i_1x1d:
886 		oprintf(fp, "Index Address 0x%x, Data Address 0x%x\n",
887 		    ev.smbev_addr.eva_io.evi_iaddr,
888 		    ev.smbev_addr.eva_io.evi_daddr);
889 		break;
890 	case SMB_EVM_GPNV:
891 		oprintf(fp, "0x%x\n", ev.smbev_addr.eva_gpnv);
892 		break;
893 	default:
894 		oprintf(fp, "0x%x\n", ev.smbev_addr.eva_addr);
895 	}
896 
897 	oprintf(fp, "  Type Descriptors:\n");
898 
899 	for (i = 0; i < ev.smbev_typec; i++) {
900 		oprintf(fp, "  %u: Log Type 0x%x, Data Type 0x%x\n", i,
901 		    ev.smbev_typev[i].smbevt_ltype,
902 		    ev.smbev_typev[i].smbevt_dtype);
903 	}
904 }
905 
906 static void
907 print_bytes(const uint8_t *data, size_t size, FILE *fp)
908 {
909 	size_t row, rows = P2ROUNDUP(size, 16) / 16;
910 	size_t col, cols;
911 
912 	char buf[17];
913 	uint8_t x;
914 
915 	oprintf(fp, "\n  offset:   0 1 2 3  4 5 6 7  8 9 a b  c d e f  "
916 	    "0123456789abcdef\n");
917 
918 	for (row = 0; row < rows; row++) {
919 		oprintf(fp, "  %#6lx: ", (ulong_t)row * 16);
920 		cols = MIN(size - row * 16, 16);
921 
922 		for (col = 0; col < cols; col++) {
923 			if (col % 4 == 0)
924 				oprintf(fp, " ");
925 			x = *data++;
926 			oprintf(fp, "%02x", x);
927 			buf[col] = x <= ' ' || x > '~' ? '.' : x;
928 		}
929 
930 		for (; col < 16; col++) {
931 			if (col % 4 == 0)
932 				oprintf(fp, " ");
933 			oprintf(fp, "  ");
934 			buf[col] = ' ';
935 		}
936 
937 		buf[col] = '\0';
938 		oprintf(fp, "  %s\n", buf);
939 	}
940 
941 	oprintf(fp, "\n");
942 }
943 
944 static void
945 print_memarray(smbios_hdl_t *shp, id_t id, FILE *fp)
946 {
947 	smbios_memarray_t ma;
948 
949 	(void) smbios_info_memarray(shp, id, &ma);
950 
951 	desc_printf(smbios_memarray_loc_desc(ma.smbma_location),
952 	    fp, "  Location: %u", ma.smbma_location);
953 
954 	desc_printf(smbios_memarray_use_desc(ma.smbma_use),
955 	    fp, "  Use: %u", ma.smbma_use);
956 
957 	desc_printf(smbios_memarray_ecc_desc(ma.smbma_ecc),
958 	    fp, "  ECC: %u", ma.smbma_ecc);
959 
960 	oprintf(fp, "  Number of Slots/Sockets: %u\n", ma.smbma_ndevs);
961 	id_printf(fp, "  Memory Error Data: ", ma.smbma_err);
962 	oprintf(fp, "  Max Capacity: %llu bytes\n",
963 	    (u_longlong_t)ma.smbma_size);
964 }
965 
966 static void
967 print_memdevice(smbios_hdl_t *shp, id_t id, FILE *fp)
968 {
969 	smbios_memdevice_t md;
970 
971 	(void) smbios_info_memdevice(shp, id, &md);
972 
973 	id_printf(fp, "  Physical Memory Array: ", md.smbmd_array);
974 	id_printf(fp, "  Memory Error Data: ", md.smbmd_error);
975 
976 	if (md.smbmd_twidth != -1u)
977 		oprintf(fp, "  Total Width: %u bits\n", md.smbmd_twidth);
978 	else
979 		oprintf(fp, "  Total Width: Unknown\n");
980 
981 	if (md.smbmd_dwidth != -1u)
982 		oprintf(fp, "  Data Width: %u bits\n", md.smbmd_dwidth);
983 	else
984 		oprintf(fp, "  Data Width: Unknown\n");
985 
986 	switch (md.smbmd_size) {
987 	case -1ull:
988 		oprintf(fp, "  Size: Unknown\n");
989 		break;
990 	case 0:
991 		oprintf(fp, "  Size: Not Populated\n");
992 		break;
993 	default:
994 		oprintf(fp, "  Size: %llu bytes\n",
995 		    (u_longlong_t)md.smbmd_size);
996 	}
997 
998 	desc_printf(smbios_memdevice_form_desc(md.smbmd_form),
999 	    fp, "  Form Factor: %u", md.smbmd_form);
1000 
1001 	if (md.smbmd_set == 0)
1002 		oprintf(fp, "  Set: None\n");
1003 	else if (md.smbmd_set == (uint8_t)-1u)
1004 		oprintf(fp, "  Set: Unknown\n");
1005 	else
1006 		oprintf(fp, "  Set: %u\n", md.smbmd_set);
1007 
1008 	if (md.smbmd_rank != 0) {
1009 		desc_printf(smbios_memdevice_rank_desc(md.smbmd_rank),
1010 		    fp, "  Rank: %u", md.smbmd_rank);
1011 	} else {
1012 		oprintf(fp, "  Rank: Unknown\n");
1013 	}
1014 
1015 	desc_printf(smbios_memdevice_type_desc(md.smbmd_type),
1016 	    fp, "  Memory Type: %u", md.smbmd_type);
1017 
1018 	flag_printf(fp, "Flags", md.smbmd_flags, sizeof (md.smbmd_flags) * NBBY,
1019 	    smbios_memdevice_flag_name, smbios_memdevice_flag_desc);
1020 
1021 	if (md.smbmd_extspeed != 0) {
1022 		oprintf(fp, "  Speed: %" PRIu64 " MT/s\n", md.smbmd_extspeed);
1023 	} else {
1024 		oprintf(fp, "  Speed: Unknown\n");
1025 	}
1026 
1027 	if (md.smbmd_extclkspeed != 0) {
1028 		oprintf(fp, "  Configured Speed: %" PRIu64 " MT/s\n",
1029 		    md.smbmd_extclkspeed);
1030 	} else {
1031 		oprintf(fp, "  Configured Speed: Unknown\n");
1032 	}
1033 
1034 	str_print(fp, "  Device Locator", md.smbmd_dloc);
1035 	str_print(fp, "  Bank Locator", md.smbmd_bloc);
1036 
1037 	if (md.smbmd_minvolt != 0) {
1038 		oprintf(fp, "  Minimum Voltage: %.2fV\n",
1039 		    md.smbmd_minvolt / 1000.0);
1040 	} else {
1041 		oprintf(fp, "  Minimum Voltage: Unknown\n");
1042 	}
1043 
1044 	if (md.smbmd_maxvolt != 0) {
1045 		oprintf(fp, "  Maximum Voltage: %.2fV\n",
1046 		    md.smbmd_maxvolt / 1000.0);
1047 	} else {
1048 		oprintf(fp, "  Maximum Voltage: Unknown\n");
1049 	}
1050 
1051 	if (md.smbmd_confvolt != 0) {
1052 		oprintf(fp, "  Configured Voltage: %.2fV\n",
1053 		    md.smbmd_confvolt / 1000.0);
1054 	} else {
1055 		oprintf(fp, "  Configured Voltage: Unknown\n");
1056 	}
1057 
1058 	if (md.smbmd_memtech != 0) {
1059 		desc_printf(smbios_memdevice_memtech_desc(md.smbmd_memtech),
1060 		    fp, "  Memory Technology: %u", md.smbmd_memtech);
1061 	}
1062 
1063 	if (md.smbmd_opcap_flags != 0) {
1064 		flag_printf(fp, "Operating Mode Capabilities",
1065 		    md.smbmd_opcap_flags, sizeof (md.smbmd_opcap_flags) * NBBY,
1066 		    smbios_memdevice_op_capab_name,
1067 		    smbios_memdevice_op_capab_desc);
1068 	}
1069 
1070 	if (md.smbmd_firmware_rev[0] != '\0') {
1071 		str_print(fp, "  Firmware Revision", md.smbmd_firmware_rev);
1072 	}
1073 
1074 	if (md.smbmd_modmfg_id != 0) {
1075 		jedec_print(fp, "Module Manufacturer ID", md.smbmd_modmfg_id);
1076 	}
1077 
1078 	if (md.smbmd_modprod_id  != 0) {
1079 		jedec_print(fp, "Module Product ID", md.smbmd_modprod_id);
1080 	}
1081 
1082 	if (md.smbmd_cntrlmfg_id != 0) {
1083 		jedec_print(fp, "Memory Subsystem Controller Manufacturer ID",
1084 		    md.smbmd_cntrlmfg_id);
1085 	}
1086 
1087 	if (md.smbmd_cntrlprod_id != 0) {
1088 		jedec_print(fp, "Memory Subsystem Controller Product ID",
1089 		    md.smbmd_cntrlprod_id);
1090 	}
1091 
1092 	if (md.smbmd_nvsize == UINT64_MAX) {
1093 		oprintf(fp, "  Non-volatile Size: Unknown\n");
1094 	} else if (md.smbmd_nvsize != 0) {
1095 		oprintf(fp, "  Non-volatile Size: %llu bytes\n",
1096 		    (u_longlong_t)md.smbmd_nvsize);
1097 	}
1098 
1099 	if (md.smbmd_volatile_size == UINT64_MAX) {
1100 		oprintf(fp, "  Volatile Size: Unknown\n");
1101 	} else if (md.smbmd_volatile_size != 0) {
1102 		oprintf(fp, "  Volatile Size: %llu bytes\n",
1103 		    (u_longlong_t)md.smbmd_volatile_size);
1104 	}
1105 
1106 	if (md.smbmd_cache_size == UINT64_MAX) {
1107 		oprintf(fp, "  Cache Size: Unknown\n");
1108 	} else if (md.smbmd_cache_size != 0) {
1109 		oprintf(fp, "  Cache Size: %llu bytes\n",
1110 		    (u_longlong_t)md.smbmd_cache_size);
1111 	}
1112 
1113 	if (md.smbmd_logical_size == UINT64_MAX) {
1114 		oprintf(fp, "  Logical Size: Unknown\n");
1115 	} else if (md.smbmd_logical_size != 0) {
1116 		oprintf(fp, "  Logical Size: %llu bytes\n",
1117 		    (u_longlong_t)md.smbmd_logical_size);
1118 	}
1119 }
1120 
1121 static void
1122 print_memarrmap(smbios_hdl_t *shp, id_t id, FILE *fp)
1123 {
1124 	smbios_memarrmap_t ma;
1125 
1126 	(void) smbios_info_memarrmap(shp, id, &ma);
1127 
1128 	id_printf(fp, "  Physical Memory Array: ", ma.smbmam_array);
1129 	oprintf(fp, "  Devices per Row: %u\n", ma.smbmam_width);
1130 
1131 	oprintf(fp, "  Physical Address: 0x%llx\n  Size: %llu bytes\n",
1132 	    (u_longlong_t)ma.smbmam_addr, (u_longlong_t)ma.smbmam_size);
1133 }
1134 
1135 static void
1136 print_memdevmap(smbios_hdl_t *shp, id_t id, FILE *fp)
1137 {
1138 	smbios_memdevmap_t md;
1139 
1140 	(void) smbios_info_memdevmap(shp, id, &md);
1141 
1142 	id_printf(fp, "  Memory Device: ", md.smbmdm_device);
1143 	id_printf(fp, "  Memory Array Mapped Address: ", md.smbmdm_arrmap);
1144 
1145 	oprintf(fp, "  Physical Address: 0x%llx\n  Size: %llu bytes\n",
1146 	    (u_longlong_t)md.smbmdm_addr, (u_longlong_t)md.smbmdm_size);
1147 
1148 	oprintf(fp, "  Partition Row Position: %u\n", md.smbmdm_rpos);
1149 	oprintf(fp, "  Interleave Position: %u\n", md.smbmdm_ipos);
1150 	oprintf(fp, "  Interleave Data Depth: %u\n", md.smbmdm_idepth);
1151 }
1152 
1153 static void
1154 print_hwsec(smbios_hdl_t *shp, FILE *fp)
1155 {
1156 	smbios_hwsec_t h;
1157 
1158 	(void) smbios_info_hwsec(shp, &h);
1159 
1160 	desc_printf(smbios_hwsec_desc(h.smbh_pwr_ps),
1161 	    fp, "  Power-On Password Status: %u", h.smbh_pwr_ps);
1162 	desc_printf(smbios_hwsec_desc(h.smbh_kbd_ps),
1163 	    fp, "  Keyboard Password Status: %u", h.smbh_kbd_ps);
1164 	desc_printf(smbios_hwsec_desc(h.smbh_adm_ps),
1165 	    fp, "  Administrator Password Status: %u", h.smbh_adm_ps);
1166 	desc_printf(smbios_hwsec_desc(h.smbh_pan_ps),
1167 	    fp, "  Front Panel Reset Status: %u", h.smbh_pan_ps);
1168 }
1169 
1170 static void
1171 print_vprobe(smbios_hdl_t *shp, id_t id, FILE *fp)
1172 {
1173 	smbios_vprobe_t vp;
1174 
1175 	if (smbios_info_vprobe(shp, id, &vp) != 0) {
1176 		smbios_warn(shp, "failed to read voltage probe information");
1177 		return;
1178 	}
1179 
1180 	str_print(fp, "  Description", vp.smbvp_description != NULL ?
1181 	    vp.smbvp_description : "unknown");
1182 	desc_printf(smbios_vprobe_loc_desc(vp.smbvp_location),
1183 	    fp, "  Location: %u", vp.smbvp_location);
1184 	desc_printf(smbios_vprobe_status_desc(vp.smbvp_status),
1185 	    fp, "  Status: %u", vp.smbvp_status);
1186 
1187 	if (vp.smbvp_maxval != SMB_PROBE_UNKNOWN_VALUE) {
1188 		oprintf(fp, "  Maximum Possible Voltage: %u mV\n",
1189 		    vp.smbvp_maxval);
1190 	} else {
1191 		oprintf(fp, "  Maximum Possible Voltage: unknown\n");
1192 	}
1193 
1194 	if (vp.smbvp_minval != SMB_PROBE_UNKNOWN_VALUE) {
1195 		oprintf(fp, "  Minimum Possible Voltage: %u mV\n",
1196 		    vp.smbvp_minval);
1197 	} else {
1198 		oprintf(fp, "  Minimum Possible Voltage: unknown\n");
1199 	}
1200 
1201 	if (vp.smbvp_resolution != SMB_PROBE_UNKNOWN_VALUE) {
1202 		oprintf(fp, "  Probe Resolution: %u.%u mV\n",
1203 		    vp.smbvp_resolution / 10,
1204 		    vp.smbvp_resolution % 10);
1205 	} else {
1206 		oprintf(fp, "  Probe Resolution: unknown\n");
1207 	}
1208 
1209 	if (vp.smbvp_tolerance != SMB_PROBE_UNKNOWN_VALUE) {
1210 		oprintf(fp, "  Probe Tolerance: +/-%u mV\n",
1211 		    vp.smbvp_tolerance);
1212 	} else {
1213 		oprintf(fp, "  Probe Tolerance: unknown\n");
1214 	}
1215 
1216 	if (vp.smbvp_accuracy != SMB_PROBE_UNKNOWN_VALUE) {
1217 		oprintf(fp, "  Probe Accuracy: +/-%u.%02u%%\n",
1218 		    vp.smbvp_accuracy / 100,
1219 		    vp.smbvp_accuracy % 100);
1220 	} else {
1221 		oprintf(fp, "  Probe Accuracy: unknown\n");
1222 	}
1223 
1224 	oprintf(fp, "  OEM- or BIOS- defined value: 0x%x\n", vp.smbvp_oem);
1225 
1226 	if (vp.smbvp_nominal != SMB_PROBE_UNKNOWN_VALUE) {
1227 		oprintf(fp, "  Probe Nominal Value: %u mV\n", vp.smbvp_nominal);
1228 	} else {
1229 		oprintf(fp, "  Probe Nominal Value: unknown\n");
1230 	}
1231 }
1232 
1233 static void
1234 print_cooldev(smbios_hdl_t *shp, id_t id, FILE *fp)
1235 {
1236 	smbios_cooldev_t cd;
1237 
1238 	if (smbios_info_cooldev(shp, id, &cd) != 0) {
1239 		smbios_warn(shp, "failed to read cooling device "
1240 		    "information");
1241 		return;
1242 	}
1243 
1244 	id_printf(fp, "  Temperature Probe Handle: ", cd.smbcd_tprobe);
1245 	desc_printf(smbios_cooldev_type_desc(cd.smbcd_type),
1246 	    fp, "  Device Type: %u", cd.smbcd_type);
1247 	desc_printf(smbios_cooldev_status_desc(cd.smbcd_status),
1248 	    fp, "  Status: %u", cd.smbcd_status);
1249 	oprintf(fp, "  Cooling Unit Group: %u\n", cd.smbcd_group);
1250 	oprintf(fp, "  OEM- or BIOS- defined data: 0x%x\n", cd.smbcd_oem);
1251 	if (cd.smbcd_nominal != SMB_PROBE_UNKNOWN_VALUE) {
1252 		oprintf(fp, "  Nominal Speed: %u RPM\n", cd.smbcd_nominal);
1253 	} else {
1254 		oprintf(fp, "  Nominal Speed: unknown\n");
1255 	}
1256 
1257 	if (cd.smbcd_descr != NULL && cd.smbcd_descr[0] != '\0') {
1258 		str_print(fp, "  Description", cd.smbcd_descr);
1259 	}
1260 }
1261 
1262 static void
1263 print_tprobe(smbios_hdl_t *shp, id_t id, FILE *fp)
1264 {
1265 	smbios_tprobe_t tp;
1266 
1267 	if (smbios_info_tprobe(shp, id, &tp) != 0) {
1268 		smbios_warn(shp, "failed to read temperature probe "
1269 		    "information");
1270 		return;
1271 	}
1272 
1273 	str_print(fp, "  Description", tp.smbtp_description != NULL ?
1274 	    tp.smbtp_description : "unknown");
1275 	desc_printf(smbios_tprobe_loc_desc(tp.smbtp_location),
1276 	    fp, "  Location: %u", tp.smbtp_location);
1277 	desc_printf(smbios_tprobe_status_desc(tp.smbtp_status),
1278 	    fp, "  Status: %u", tp.smbtp_status);
1279 
1280 	if (tp.smbtp_maxval != SMB_PROBE_UNKNOWN_VALUE) {
1281 		oprintf(fp, "  Maximum Possible Temperature: %u.%u C\n",
1282 		    tp.smbtp_maxval / 10, tp.smbtp_maxval % 10);
1283 	} else {
1284 		oprintf(fp, "  Maximum Possible Temperature: unknown\n");
1285 	}
1286 
1287 	if (tp.smbtp_minval != SMB_PROBE_UNKNOWN_VALUE) {
1288 		oprintf(fp, "  Minimum Possible Temperature: %u.%u C\n",
1289 		    tp.smbtp_minval / 10, tp.smbtp_minval % 10);
1290 	} else {
1291 		oprintf(fp, "  Minimum Possible Temperature: unknown\n");
1292 	}
1293 
1294 	if (tp.smbtp_resolution != SMB_PROBE_UNKNOWN_VALUE) {
1295 		oprintf(fp, "  Probe Resolution: %u.%03u C\n",
1296 		    tp.smbtp_resolution / 1000,
1297 		    tp.smbtp_resolution % 1000);
1298 	} else {
1299 		oprintf(fp, "  Probe Resolution: unknown\n");
1300 	}
1301 
1302 	if (tp.smbtp_tolerance != SMB_PROBE_UNKNOWN_VALUE) {
1303 		oprintf(fp, "  Probe Tolerance: +/-%u.%u C\n",
1304 		    tp.smbtp_tolerance / 10, tp.smbtp_tolerance % 10);
1305 	} else {
1306 		oprintf(fp, "  Probe Tolerance: unknown\n");
1307 	}
1308 
1309 	if (tp.smbtp_accuracy != SMB_PROBE_UNKNOWN_VALUE) {
1310 		oprintf(fp, "  Probe Accuracy: +/-%u.%02u%%\n",
1311 		    tp.smbtp_accuracy / 100,
1312 		    tp.smbtp_accuracy % 100);
1313 	} else {
1314 		oprintf(fp, "  Probe Accuracy: unknown\n");
1315 	}
1316 
1317 	oprintf(fp, "  OEM- or BIOS- defined value: 0x%x\n", tp.smbtp_oem);
1318 
1319 	if (tp.smbtp_nominal != SMB_PROBE_UNKNOWN_VALUE) {
1320 		oprintf(fp, "  Probe Nominal Value: %u.%u C\n",
1321 		    tp.smbtp_nominal / 10, tp.smbtp_nominal % 10);
1322 	} else {
1323 		oprintf(fp, "  Probe Nominal Value: unknown\n");
1324 	}
1325 }
1326 
1327 static void
1328 print_iprobe(smbios_hdl_t *shp, id_t id, FILE *fp)
1329 {
1330 	smbios_iprobe_t ip;
1331 
1332 	if (smbios_info_iprobe(shp, id, &ip) != 0) {
1333 		smbios_warn(shp, "failed to read current probe information");
1334 		return;
1335 	}
1336 
1337 	str_print(fp, "  Description", ip.smbip_description != NULL ?
1338 	    ip.smbip_description : "unknown");
1339 	desc_printf(smbios_iprobe_loc_desc(ip.smbip_location),
1340 	    fp, "  Location: %u", ip.smbip_location);
1341 	desc_printf(smbios_iprobe_status_desc(ip.smbip_status),
1342 	    fp, "  Status: %u", ip.smbip_status);
1343 
1344 	if (ip.smbip_maxval != SMB_PROBE_UNKNOWN_VALUE) {
1345 		oprintf(fp, "  Maximum Possible Current: %u mA\n",
1346 		    ip.smbip_maxval);
1347 	} else {
1348 		oprintf(fp, "  Maximum Possible Current: unknown\n");
1349 	}
1350 
1351 	if (ip.smbip_minval != SMB_PROBE_UNKNOWN_VALUE) {
1352 		oprintf(fp, "  Minimum Possible Current: %u mA\n",
1353 		    ip.smbip_minval);
1354 	} else {
1355 		oprintf(fp, "  Minimum Possible Current: unknown\n");
1356 	}
1357 
1358 	if (ip.smbip_resolution != SMB_PROBE_UNKNOWN_VALUE) {
1359 		oprintf(fp, "  Probe Resolution: %u.%u mA\n",
1360 		    ip.smbip_resolution / 10,
1361 		    ip.smbip_resolution % 10);
1362 	} else {
1363 		oprintf(fp, "  Probe Resolution: unknown\n");
1364 	}
1365 
1366 	if (ip.smbip_tolerance != SMB_PROBE_UNKNOWN_VALUE) {
1367 		oprintf(fp, "  Probe Tolerance: +/-%u mA\n",
1368 		    ip.smbip_tolerance);
1369 	} else {
1370 		oprintf(fp, "  Probe Tolerance: unknown\n");
1371 	}
1372 
1373 	if (ip.smbip_accuracy != SMB_PROBE_UNKNOWN_VALUE) {
1374 		oprintf(fp, "  Probe Accuracy: +/-%u.%02u%%\n",
1375 		    ip.smbip_accuracy / 100,
1376 		    ip.smbip_accuracy % 100);
1377 	} else {
1378 		oprintf(fp, "  Probe Accuracy: unknown\n");
1379 	}
1380 
1381 	oprintf(fp, "  OEM- or BIOS- defined value: 0x%x\n", ip.smbip_oem);
1382 
1383 	if (ip.smbip_nominal != SMB_PROBE_UNKNOWN_VALUE) {
1384 		oprintf(fp, "  Probe Nominal Value: %u mA\n", ip.smbip_nominal);
1385 	} else {
1386 		oprintf(fp, "  Probe Nominal Value: unknown\n");
1387 	}
1388 }
1389 
1390 
1391 static void
1392 print_boot(smbios_hdl_t *shp, FILE *fp)
1393 {
1394 	smbios_boot_t b;
1395 
1396 	(void) smbios_info_boot(shp, &b);
1397 
1398 	desc_printf(smbios_boot_desc(b.smbt_status),
1399 	    fp, "  Boot Status Code: 0x%x", b.smbt_status);
1400 
1401 	if (b.smbt_size != 0) {
1402 		oprintf(fp, "  Boot Data (%lu bytes):\n", (ulong_t)b.smbt_size);
1403 		print_bytes(b.smbt_data, b.smbt_size, fp);
1404 	}
1405 }
1406 
1407 static void
1408 print_ipmi(smbios_hdl_t *shp, FILE *fp)
1409 {
1410 	smbios_ipmi_t i;
1411 
1412 	(void) smbios_info_ipmi(shp, &i);
1413 
1414 	desc_printf(smbios_ipmi_type_desc(i.smbip_type),
1415 	    fp, "  Type: %u", i.smbip_type);
1416 
1417 	oprintf(fp, "  BMC IPMI Version: %u.%u\n",
1418 	    i.smbip_vers.smbv_major, i.smbip_vers.smbv_minor);
1419 
1420 	oprintf(fp, "  i2c Bus Slave Address: 0x%x\n", i.smbip_i2c);
1421 	oprintf(fp, "  NV Storage Device Bus ID: 0x%x\n", i.smbip_bus);
1422 	oprintf(fp, "  BMC Base Address: 0x%llx\n", (u_longlong_t)i.smbip_addr);
1423 	oprintf(fp, "  Interrupt Number: %u\n", i.smbip_intr);
1424 	oprintf(fp, "  Register Spacing: %u\n", i.smbip_regspacing);
1425 
1426 	flag_printf(fp, "Flags", i.smbip_flags, sizeof (i.smbip_flags) * NBBY,
1427 	    smbios_ipmi_flag_name, smbios_ipmi_flag_desc);
1428 }
1429 
1430 static void
1431 print_powersup(smbios_hdl_t *shp, id_t id, FILE *fp)
1432 {
1433 	smbios_powersup_t p;
1434 
1435 	if (smbios_info_powersup(shp, id, &p) != 0) {
1436 		smbios_warn(shp, "failed to read power supply information");
1437 		return;
1438 	}
1439 
1440 	oprintf(fp, "  Power Supply Group: %u\n", p.smbps_group);
1441 	if (p.smbps_maxout != 0x8000) {
1442 		oprintf(fp, "  Maximum Output: %llu mW\n", p.smbps_maxout);
1443 	} else {
1444 		oprintf(fp, "  Maximum Output: unknown\n");
1445 	}
1446 
1447 	flag_printf(fp, "Characteristics", p.smbps_flags,
1448 	    sizeof (p.smbps_flags) * NBBY, smbios_powersup_flag_name,
1449 	    smbios_powersup_flag_desc);
1450 
1451 	desc_printf(smbios_powersup_input_desc(p.smbps_ivrs),
1452 	    fp, "  Input Voltage Range Switching: %u", p.smbps_ivrs);
1453 	desc_printf(smbios_powersup_status_desc(p.smbps_status),
1454 	    fp, "  Status: %u", p.smbps_status);
1455 	desc_printf(smbios_powersup_type_desc(p.smbps_pstype),
1456 	    fp, "  Type: %u", p.smbps_pstype);
1457 
1458 	if (p.smbps_vprobe != 0xffff) {
1459 		oprintf(fp, "  Voltage Probe Handle: %lu\n", p.smbps_vprobe);
1460 	}
1461 
1462 	if (p.smbps_cooldev != 0xffff) {
1463 		oprintf(fp, "  Cooling Device Handle: %lu\n", p.smbps_cooldev);
1464 	}
1465 
1466 	if (p.smbps_iprobe != 0xffff) {
1467 		oprintf(fp, "  Current Probe Handle: %lu\n", p.smbps_iprobe);
1468 	}
1469 }
1470 
1471 static void
1472 print_processor_info_riscv(smbios_hdl_t *shp, id_t id, FILE *fp)
1473 {
1474 	smbios_processor_info_riscv_t rv;
1475 
1476 	if (smbios_info_processor_riscv(shp, id, &rv) != 0) {
1477 		smbios_warn(shp, "failed to read RISC-V specific processor "
1478 		    "information");
1479 		return;
1480 	}
1481 
1482 	if (rv.smbpirv_boothart != 0) {
1483 		oprintf(fp, "    Boot Hart\n");
1484 	}
1485 	u128_print(fp, "    Hart ID", rv.smbpirv_hartid);
1486 	u128_print(fp, "    Vendor ID", rv.smbpirv_vendid);
1487 	u128_print(fp, "    Architecture ID", rv.smbpirv_archid);
1488 	u128_print(fp, "    Implementation ID", rv.smbpirv_machid);
1489 	flag64_printf(fp, "  ISA", rv.smbpirv_isa,
1490 	    sizeof (rv.smbpirv_isa) * NBBY, smbios_riscv_isa_name,
1491 	    smbios_riscv_isa_desc);
1492 	flag_printf(fp, "  Privilege Levels", rv.smbpirv_privlvl,
1493 	    sizeof (rv.smbpirv_privlvl) * NBBY, smbios_riscv_priv_name,
1494 	    smbios_riscv_priv_desc);
1495 	u128_print(fp, "    Machine Exception Trap Delegation",
1496 	    rv.smbpirv_metdi);
1497 	u128_print(fp, "    Machine Interrupt Trap Delegation",
1498 	    rv.smbpirv_mitdi);
1499 	desc_printf(smbios_riscv_width_desc(rv.smbpirv_xlen),
1500 	    fp, "    Register Width: 0x%x", rv.smbpirv_xlen);
1501 	desc_printf(smbios_riscv_width_desc(rv.smbpirv_mxlen),
1502 	    fp, "    M-Mode Register Width: 0x%x", rv.smbpirv_mxlen);
1503 	desc_printf(smbios_riscv_width_desc(rv.smbpirv_sxlen),
1504 	    fp, "    S-Mode Register Width: 0x%x", rv.smbpirv_sxlen);
1505 	desc_printf(smbios_riscv_width_desc(rv.smbpirv_uxlen),
1506 	    fp, "    U-Mode Register Width: 0x%x", rv.smbpirv_uxlen);
1507 }
1508 
1509 static void
1510 print_processor_info(smbios_hdl_t *shp, id_t id, FILE *fp)
1511 {
1512 	smbios_processor_info_t p;
1513 
1514 	if (smbios_info_processor_info(shp, id, &p) != 0) {
1515 		smbios_warn(shp, "failed to read processor additional "
1516 		    "information");
1517 		return;
1518 	}
1519 
1520 	id_printf(fp, "  Processor Handle: ", p.smbpi_processor);
1521 	desc_printf(smbios_processor_info_type_desc(p.smbpi_ptype),
1522 	    fp, "  Processor Type: %u", p.smbpi_ptype);
1523 
1524 	switch (p.smbpi_ptype) {
1525 	case SMB_PROCINFO_T_RV32:
1526 	case SMB_PROCINFO_T_RV64:
1527 	case SMB_PROCINFO_T_RV128:
1528 		oprintf(fp, "  RISC-V Additional Processor Information:\n");
1529 		print_processor_info_riscv(shp, id, fp);
1530 		break;
1531 	default:
1532 		break;
1533 	}
1534 }
1535 
1536 static void
1537 print_battery(smbios_hdl_t *shp, id_t id, FILE *fp)
1538 {
1539 	smbios_battery_t bat;
1540 
1541 	if (smbios_info_battery(shp, id, &bat) != 0) {
1542 		smbios_warn(shp, "failed to read battery information");
1543 		return;
1544 	}
1545 
1546 	if (bat.smbb_date != NULL) {
1547 		str_print(fp, "  Manufacture Date", bat.smbb_date);
1548 	}
1549 
1550 	if (bat.smbb_serial != NULL) {
1551 		str_print(fp, "  Serial Number", bat.smbb_serial);
1552 	}
1553 
1554 	if (bat.smbb_chem != SMB_BDC_UNKNOWN) {
1555 		desc_printf(smbios_battery_chem_desc(bat.smbb_chem),
1556 		    fp, "  Battery Chemistry: 0x%x", bat.smbb_chem);
1557 	}
1558 
1559 	if (bat.smbb_cap != 0) {
1560 		oprintf(fp, "  Design Capacity: %u mWh\n", bat.smbb_cap);
1561 	} else {
1562 		oprintf(fp, "  Design Capacity: unknown\n");
1563 	}
1564 
1565 	if (bat.smbb_volt != 0) {
1566 		oprintf(fp, "  Design Voltage: %u mV\n", bat.smbb_volt);
1567 	} else {
1568 		oprintf(fp, "  Design Voltage: unknown\n");
1569 	}
1570 
1571 	str_print(fp, "  SBDS Version Number", bat.smbb_version);
1572 	if (bat.smbb_err != UINT8_MAX) {
1573 		oprintf(fp, "  Maximum Error: %u\n", bat.smbb_err);
1574 	} else {
1575 		oprintf(fp, "  Maximum Error: unknown\n", bat.smbb_err);
1576 	}
1577 	oprintf(fp, "  SBDS Serial Number: %04x\n", bat.smbb_ssn);
1578 	oprintf(fp, "  SBDS Manufacture Date: %u-%02u-%02u\n", bat.smbb_syear,
1579 	    bat.smbb_smonth, bat.smbb_sday);
1580 	str_print(fp, "  SBDS Device Chemistry", bat.smbb_schem);
1581 	oprintf(fp, "  OEM-specific Information: 0x%08x\n", bat.smbb_oemdata);
1582 }
1583 
1584 static void
1585 print_pointdev(smbios_hdl_t *shp, id_t id, FILE *fp)
1586 {
1587 	smbios_pointdev_t pd;
1588 
1589 	if (smbios_info_pointdev(shp, id, &pd) != 0) {
1590 		smbios_warn(shp, "failed to read pointer device information");
1591 		return;
1592 	}
1593 
1594 	desc_printf(smbios_pointdev_type_desc(pd.smbpd_type),
1595 	    fp, "  Type: %u", pd.smbpd_type);
1596 	desc_printf(smbios_pointdev_iface_desc(pd.smbpd_iface),
1597 	    fp, "  Interface: %u", pd.smbpd_iface);
1598 	oprintf(fp, "  Buttons: %u\n", pd.smbpd_nbuttons);
1599 }
1600 
1601 static void
1602 print_extprocessor(smbios_hdl_t *shp, id_t id, FILE *fp)
1603 {
1604 	int i;
1605 	smbios_processor_ext_t ep;
1606 
1607 	if (check_oem(shp) != 0)
1608 		return;
1609 
1610 	(void) smbios_info_extprocessor(shp, id, &ep);
1611 
1612 	oprintf(fp, "  Processor: %u\n", ep.smbpe_processor);
1613 	oprintf(fp, "  FRU: %u\n", ep.smbpe_fru);
1614 	oprintf(fp, "  Initial APIC ID count: %u\n\n", ep.smbpe_n);
1615 
1616 	for (i = 0; i < ep.smbpe_n; i++) {
1617 		oprintf(fp, "  Logical Strand %u: Initial APIC ID: %u\n", i,
1618 		    ep.smbpe_apicid[i]);
1619 	}
1620 }
1621 
1622 static void
1623 print_extport(smbios_hdl_t *shp, id_t id, FILE *fp)
1624 {
1625 	smbios_port_ext_t epo;
1626 
1627 	if (check_oem(shp) != 0)
1628 		return;
1629 
1630 	(void) smbios_info_extport(shp, id, &epo);
1631 
1632 	oprintf(fp, "  Chassis Handle: %u\n", epo.smbporte_chassis);
1633 	oprintf(fp, "  Port Connector Handle: %u\n", epo.smbporte_port);
1634 	oprintf(fp, "  Device Type: %u\n", epo.smbporte_dtype);
1635 	oprintf(fp, "  Device Handle: %u\n", epo.smbporte_devhdl);
1636 	oprintf(fp, "  PHY: %u\n", epo.smbporte_phy);
1637 }
1638 
1639 static void
1640 print_pciexrc(smbios_hdl_t *shp, id_t id, FILE *fp)
1641 {
1642 	smbios_pciexrc_t pcie;
1643 
1644 	if (check_oem(shp) != 0)
1645 		return;
1646 
1647 	(void) smbios_info_pciexrc(shp, id, &pcie);
1648 
1649 	oprintf(fp, "  Component ID: %u\n", pcie.smbpcie_bb);
1650 	oprintf(fp, "  BDF: 0x%x\n", pcie.smbpcie_bdf);
1651 }
1652 
1653 static void
1654 print_extmemarray(smbios_hdl_t *shp, id_t id, FILE *fp)
1655 {
1656 	smbios_memarray_ext_t em;
1657 
1658 	if (check_oem(shp) != 0)
1659 		return;
1660 
1661 	(void) smbios_info_extmemarray(shp, id, &em);
1662 
1663 	oprintf(fp, "  Physical Memory Array Handle: %u\n", em.smbmae_ma);
1664 	oprintf(fp, "  Component Parent Handle: %u\n", em.smbmae_comp);
1665 	oprintf(fp, "  BDF: 0x%x\n", em.smbmae_bdf);
1666 }
1667 
1668 static void
1669 print_extmemdevice(smbios_hdl_t *shp, id_t id, FILE *fp)
1670 {
1671 	int i;
1672 	smbios_memdevice_ext_t emd;
1673 
1674 	if (check_oem(shp) != 0)
1675 		return;
1676 
1677 	(void) smbios_info_extmemdevice(shp, id, &emd);
1678 
1679 	oprintf(fp, "  Memory Device Handle: %u\n", emd.smbmdeve_md);
1680 	oprintf(fp, "  DRAM Channel: %u\n", emd.smbmdeve_drch);
1681 	oprintf(fp, "  Number of Chip Selects: %u\n", emd.smbmdeve_ncs);
1682 
1683 	for (i = 0; i < emd.smbmdeve_ncs; i++) {
1684 		oprintf(fp, "  Chip Select: %u\n", emd.smbmdeve_cs[i]);
1685 	}
1686 }
1687 
1688 static int
1689 print_struct(smbios_hdl_t *shp, const smbios_struct_t *sp, void *fp)
1690 {
1691 	smbios_info_t info;
1692 	int hex = opt_x;
1693 	const char *s;
1694 
1695 	if (opt_t != -1 && opt_t != sp->smbstr_type)
1696 		return (0); /* skip struct if type doesn't match -t */
1697 
1698 	if (!opt_O && (sp->smbstr_type == SMB_TYPE_MEMCTL ||
1699 	    sp->smbstr_type == SMB_TYPE_MEMMOD))
1700 		return (0); /* skip struct if type is obsolete */
1701 
1702 	if (g_hdr++ == 0 || !opt_s)
1703 		oprintf(fp, "%-5s %-4s %s\n", "ID", "SIZE", "TYPE");
1704 
1705 	oprintf(fp, "%-5u %-4lu",
1706 	    (uint_t)sp->smbstr_id, (ulong_t)sp->smbstr_size);
1707 
1708 	if ((s = smbios_type_name(sp->smbstr_type)) != NULL)
1709 		oprintf(fp, " %s (type %u)", s, sp->smbstr_type);
1710 	else if (sp->smbstr_type > SMB_TYPE_OEM_LO &&
1711 	    sp->smbstr_type < SMB_TYPE_OEM_HI)
1712 		oprintf(fp, " %s+%u (type %u)", "SMB_TYPE_OEM_LO",
1713 		    sp->smbstr_type - SMB_TYPE_OEM_LO, sp->smbstr_type);
1714 	else
1715 		oprintf(fp, " %u", sp->smbstr_type);
1716 
1717 	if ((s = smbios_type_desc(sp->smbstr_type)) != NULL)
1718 		oprintf(fp, " (%s)\n", s);
1719 	else
1720 		oprintf(fp, "\n");
1721 
1722 	if (opt_s)
1723 		return (0); /* only print header line if -s specified */
1724 
1725 	if (smbios_info_common(shp, sp->smbstr_id, &info) == 0) {
1726 		oprintf(fp, "\n");
1727 		print_common(&info, fp);
1728 	}
1729 
1730 	switch (sp->smbstr_type) {
1731 	case SMB_TYPE_BIOS:
1732 		oprintf(fp, "\n");
1733 		print_bios(shp, fp);
1734 		break;
1735 	case SMB_TYPE_SYSTEM:
1736 		oprintf(fp, "\n");
1737 		print_system(shp, fp);
1738 		break;
1739 	case SMB_TYPE_BASEBOARD:
1740 		oprintf(fp, "\n");
1741 		print_bboard(shp, sp->smbstr_id, fp);
1742 		break;
1743 	case SMB_TYPE_CHASSIS:
1744 		oprintf(fp, "\n");
1745 		print_chassis(shp, sp->smbstr_id, fp);
1746 		break;
1747 	case SMB_TYPE_PROCESSOR:
1748 		oprintf(fp, "\n");
1749 		print_processor(shp, sp->smbstr_id, fp);
1750 		break;
1751 	case SMB_TYPE_CACHE:
1752 		oprintf(fp, "\n");
1753 		print_cache(shp, sp->smbstr_id, fp);
1754 		break;
1755 	case SMB_TYPE_PORT:
1756 		oprintf(fp, "\n");
1757 		print_port(shp, sp->smbstr_id, fp);
1758 		break;
1759 	case SMB_TYPE_SLOT:
1760 		oprintf(fp, "\n");
1761 		print_slot(shp, sp->smbstr_id, fp);
1762 		break;
1763 	case SMB_TYPE_OBDEVS:
1764 		oprintf(fp, "\n");
1765 		print_obdevs(shp, sp->smbstr_id, fp);
1766 		break;
1767 	case SMB_TYPE_OEMSTR:
1768 	case SMB_TYPE_SYSCONFSTR:
1769 		oprintf(fp, "\n");
1770 		print_strtab(shp, sp->smbstr_id, fp);
1771 		break;
1772 	case SMB_TYPE_LANG:
1773 		oprintf(fp, "\n");
1774 		print_lang(shp, sp->smbstr_id, fp);
1775 		break;
1776 	case SMB_TYPE_EVENTLOG:
1777 		oprintf(fp, "\n");
1778 		print_evlog(shp, sp->smbstr_id, fp);
1779 		break;
1780 	case SMB_TYPE_MEMARRAY:
1781 		oprintf(fp, "\n");
1782 		print_memarray(shp, sp->smbstr_id, fp);
1783 		break;
1784 	case SMB_TYPE_MEMDEVICE:
1785 		oprintf(fp, "\n");
1786 		print_memdevice(shp, sp->smbstr_id, fp);
1787 		break;
1788 	case SMB_TYPE_MEMARRAYMAP:
1789 		oprintf(fp, "\n");
1790 		print_memarrmap(shp, sp->smbstr_id, fp);
1791 		break;
1792 	case SMB_TYPE_MEMDEVICEMAP:
1793 		oprintf(fp, "\n");
1794 		print_memdevmap(shp, sp->smbstr_id, fp);
1795 		break;
1796 	case SMB_TYPE_BATTERY:
1797 		oprintf(fp, "\n");
1798 		print_battery(shp, sp->smbstr_id, fp);
1799 		break;
1800 	case SMB_TYPE_POINTDEV:
1801 		oprintf(fp, "\n");
1802 		print_pointdev(shp, sp->smbstr_id, fp);
1803 		break;
1804 	case SMB_TYPE_SECURITY:
1805 		oprintf(fp, "\n");
1806 		print_hwsec(shp, fp);
1807 		break;
1808 	case SMB_TYPE_VPROBE:
1809 		oprintf(fp, "\n");
1810 		print_vprobe(shp, sp->smbstr_id, fp);
1811 		break;
1812 	case SMB_TYPE_COOLDEV:
1813 		oprintf(fp, "\n");
1814 		print_cooldev(shp, sp->smbstr_id, fp);
1815 		break;
1816 	case SMB_TYPE_TPROBE:
1817 		oprintf(fp, "\n");
1818 		print_tprobe(shp, sp->smbstr_id, fp);
1819 		break;
1820 	case SMB_TYPE_IPROBE:
1821 		oprintf(fp, "\n");
1822 		print_iprobe(shp, sp->smbstr_id, fp);
1823 		break;
1824 	case SMB_TYPE_BOOT:
1825 		oprintf(fp, "\n");
1826 		print_boot(shp, fp);
1827 		break;
1828 	case SMB_TYPE_IPMIDEV:
1829 		oprintf(fp, "\n");
1830 		print_ipmi(shp, fp);
1831 		break;
1832 	case SMB_TYPE_POWERSUP:
1833 		oprintf(fp, "\n");
1834 		print_powersup(shp, sp->smbstr_id, fp);
1835 		break;
1836 	case SMB_TYPE_OBDEVEXT:
1837 		oprintf(fp, "\n");
1838 		print_obdevs_ext(shp, sp->smbstr_id, fp);
1839 		break;
1840 	case SMB_TYPE_PROCESSOR_INFO:
1841 		oprintf(fp, "\n");
1842 		print_processor_info(shp, sp->smbstr_id, fp);
1843 		break;
1844 	case SUN_OEM_EXT_PROCESSOR:
1845 		oprintf(fp, "\n");
1846 		print_extprocessor(shp, sp->smbstr_id, fp);
1847 		break;
1848 	case SUN_OEM_EXT_PORT:
1849 		oprintf(fp, "\n");
1850 		print_extport(shp, sp->smbstr_id, fp);
1851 		break;
1852 	case SUN_OEM_PCIEXRC:
1853 		oprintf(fp, "\n");
1854 		print_pciexrc(shp, sp->smbstr_id, fp);
1855 		break;
1856 	case SUN_OEM_EXT_MEMARRAY:
1857 		oprintf(fp, "\n");
1858 		print_extmemarray(shp, sp->smbstr_id, fp);
1859 		break;
1860 	case SUN_OEM_EXT_MEMDEVICE:
1861 		oprintf(fp, "\n");
1862 		print_extmemdevice(shp, sp->smbstr_id, fp);
1863 		break;
1864 	default:
1865 		hex++;
1866 	}
1867 
1868 	if (hex)
1869 		print_bytes(sp->smbstr_data, sp->smbstr_size, fp);
1870 	else
1871 		oprintf(fp, "\n");
1872 
1873 	return (0);
1874 }
1875 
1876 static uint16_t
1877 getu16(const char *name, const char *s)
1878 {
1879 	u_longlong_t val;
1880 	char *p;
1881 
1882 	errno = 0;
1883 	val = strtoull(s, &p, 0);
1884 
1885 	if (errno != 0 || p == s || *p != '\0' || val > UINT16_MAX) {
1886 		(void) fprintf(stderr, "%s: invalid %s argument -- %s\n",
1887 		    g_pname, name, s);
1888 		exit(SMBIOS_USAGE);
1889 	}
1890 
1891 	return ((uint16_t)val);
1892 }
1893 
1894 static uint16_t
1895 getstype(const char *name, const char *s)
1896 {
1897 	const char *ts;
1898 	uint16_t t;
1899 
1900 	for (t = 0; t < SMB_TYPE_OEM_LO; t++) {
1901 		if ((ts = smbios_type_name(t)) != NULL && strcmp(s, ts) == 0)
1902 			return (t);
1903 	}
1904 
1905 	(void) fprintf(stderr, "%s: invalid %s argument -- %s\n",
1906 	    g_pname, name, s);
1907 
1908 	exit(SMBIOS_USAGE);
1909 	/*NOTREACHED*/
1910 }
1911 
1912 static int
1913 usage(FILE *fp)
1914 {
1915 	(void) fprintf(fp, "Usage: %s "
1916 	    "[-BeOsx] [-i id] [-t type] [-w file] [file]\n\n", g_pname);
1917 
1918 	(void) fprintf(fp,
1919 	    "\t-B disable header validation for broken BIOSes\n"
1920 	    "\t-e display SMBIOS entry point information\n"
1921 	    "\t-i display only the specified structure\n"
1922 	    "\t-O display obsolete structure types\n"
1923 	    "\t-s display only a summary of structure identifiers and types\n"
1924 	    "\t-t display only the specified structure type\n"
1925 	    "\t-w write the raw data to the specified file\n"
1926 	    "\t-x display raw data for structures\n");
1927 
1928 	return (SMBIOS_USAGE);
1929 }
1930 
1931 int
1932 main(int argc, char *argv[])
1933 {
1934 	const char *ifile = NULL;
1935 	const char *ofile = NULL;
1936 	int oflags = 0;
1937 
1938 	smbios_hdl_t *shp;
1939 	smbios_struct_t s;
1940 	int err, fd, c;
1941 	char *p;
1942 
1943 	if ((p = strrchr(argv[0], '/')) == NULL)
1944 		g_pname = argv[0];
1945 	else
1946 		g_pname = p + 1;
1947 
1948 	while (optind < argc) {
1949 		while ((c = getopt(argc, argv, "Bei:Ost:w:xZ")) != EOF) {
1950 			switch (c) {
1951 			case 'B':
1952 				oflags |= SMB_O_NOCKSUM | SMB_O_NOVERS;
1953 				break;
1954 			case 'e':
1955 				opt_e++;
1956 				break;
1957 			case 'i':
1958 				opt_i = getu16("struct ID", optarg);
1959 				break;
1960 			case 'O':
1961 				opt_O++;
1962 				break;
1963 			case 's':
1964 				opt_s++;
1965 				break;
1966 			case 't':
1967 				if (isdigit(optarg[0]))
1968 					opt_t = getu16("struct type", optarg);
1969 				else
1970 					opt_t = getstype("struct type", optarg);
1971 				break;
1972 			case 'w':
1973 				ofile = optarg;
1974 				break;
1975 			case 'x':
1976 				opt_x++;
1977 				break;
1978 			case 'Z':
1979 				oflags |= SMB_O_ZIDS; /* undocumented */
1980 				break;
1981 			default:
1982 				return (usage(stderr));
1983 			}
1984 		}
1985 
1986 		if (optind < argc) {
1987 			if (ifile != NULL) {
1988 				(void) fprintf(stderr, "%s: illegal "
1989 				    "argument -- %s\n", g_pname, argv[optind]);
1990 				return (SMBIOS_USAGE);
1991 			}
1992 			ifile = argv[optind++];
1993 		}
1994 	}
1995 
1996 	if ((shp = smbios_open(ifile, SMB_VERSION, oflags, &err)) == NULL) {
1997 		(void) fprintf(stderr, "%s: failed to load SMBIOS: %s\n",
1998 		    g_pname, smbios_errmsg(err));
1999 		return (SMBIOS_ERROR);
2000 	}
2001 
2002 	if (opt_i == -1 && opt_t == -1 && opt_e == 0 &&
2003 	    smbios_truncated(shp))
2004 		(void) fprintf(stderr, "%s: SMBIOS table is truncated\n",
2005 		    g_pname);
2006 
2007 	if (ofile != NULL) {
2008 		if ((fd = open(ofile, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
2009 			(void) fprintf(stderr, "%s: failed to open %s: %s\n",
2010 			    g_pname, ofile, strerror(errno));
2011 			err = SMBIOS_ERROR;
2012 		} else if (smbios_write(shp, fd) != 0) {
2013 			(void) fprintf(stderr, "%s: failed to write %s: %s\n",
2014 			    g_pname, ofile, smbios_errmsg(smbios_errno(shp)));
2015 			err = SMBIOS_ERROR;
2016 		}
2017 		smbios_close(shp);
2018 		return (err);
2019 	}
2020 
2021 	if (opt_e) {
2022 		print_smbios(shp, stdout);
2023 		smbios_close(shp);
2024 		return (SMBIOS_SUCCESS);
2025 	}
2026 
2027 	if (opt_O && (opt_i != -1 || opt_t != -1))
2028 		opt_O++; /* -i or -t imply displaying obsolete records */
2029 
2030 	if (opt_i != -1)
2031 		err = smbios_lookup_id(shp, opt_i, &s);
2032 	else
2033 		err = smbios_iter(shp, print_struct, stdout);
2034 
2035 	if (err != 0) {
2036 		(void) fprintf(stderr, "%s: failed to access SMBIOS: %s\n",
2037 		    g_pname, smbios_errmsg(smbios_errno(shp)));
2038 		smbios_close(shp);
2039 		return (SMBIOS_ERROR);
2040 	}
2041 
2042 	if (opt_i != -1)
2043 		(void) print_struct(shp, &s, stdout);
2044 
2045 	smbios_close(shp);
2046 	return (SMBIOS_SUCCESS);
2047 }
2048