xref: /illumos-gate/usr/src/common/smbios/smb_info.c (revision e25cb0e77ab84d3147918b8aef1f5161fbccb30e)
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 2019 Joyent, Inc.
25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 /*
30  * SMBIOS Information Routines
31  *
32  * The routines in this file are used to convert from the SMBIOS data format to
33  * a more reasonable and stable set of structures offered as part of our ABI.
34  * These functions take the general form:
35  *
36  *	stp = smb_lookup_type(shp, foo);
37  *	smb_foo_t foo;
38  *
39  *	smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
40  *      bzero(caller's struct);
41  *
42  *	copy/convert foo members into caller's struct
43  *
44  * We copy the internal structure on to an automatic variable so as to avoid
45  * checks everywhere for structures that the BIOS has improperly truncated, and
46  * also to automatically handle the case of a structure that has been extended.
47  * When necessary, this code can use smb_gteq() to determine whether the SMBIOS
48  * data is of a particular revision that is supposed to contain a new field.
49  *
50  * Note, when trying to bzero the caller's struct you have to be careful about
51  * versions. One can only bzero the initial version that existed in illumos. In
52  * other words, if someone passes an older library handle that doesn't support a
53  * version you cannot assume that their structures have those additional members
54  * in them. Instead, a 'base' version is introduced for such types that have
55  * differences and instead we only bzero out the base version and then handle
56  * the additional members. In general, because all additional members will be
57  * assigned, there's no reason to zero them out unless they are arrays that
58  * won't be entirely filled in.
59  *
60  * Due to history, anything added after the update from version 2.4, in other
61  * words additions from or after '5094 Update libsmbios with recent items'
62  * (4e901881) is currently being used for this. While we don't allow software
63  * compiling against this to get an older form, this was the first major update
64  * and a good starting point for us to enforce this behavior which is useful for
65  * moving forward to making this more public.
66  */
67 
68 #include <sys/smbios_impl.h>
69 #include <sys/byteorder.h>
70 #include <sys/debug.h>
71 
72 #ifdef _KERNEL
73 #include <sys/sunddi.h>
74 #else
75 #include <fcntl.h>
76 #include <unistd.h>
77 #include <string.h>
78 #endif
79 
80 /*
81  * A large number of SMBIOS structures contain a set of common strings used to
82  * describe a h/w component's serial number, manufacturer, etc.  These fields
83  * helpfully have different names and offsets and sometimes aren't consistent.
84  * To simplify life for our clients, we factor these common things out into
85  * smbios_info_t, which can be retrieved for any structure.  The following
86  * table describes the mapping from a given structure to the smbios_info_t.
87  * Multiple SMBIOS stuctures' contained objects are also handled here.
88  */
89 static const struct smb_infospec {
90 	uint8_t is_type;		/* structure type */
91 	uint8_t is_manu;		/* manufacturer offset */
92 	uint8_t is_product;		/* product name offset */
93 	uint8_t is_version;		/* version offset */
94 	uint8_t is_serial;		/* serial number offset */
95 	uint8_t is_asset;		/* asset tag offset */
96 	uint8_t is_location;		/* location string offset */
97 	uint8_t is_part;		/* part number offset */
98 	uint8_t is_contc;		/* contained count */
99 	uint8_t is_contsz;		/* contained size */
100 	uint8_t is_contv;		/* contained objects */
101 } _smb_infospecs[] = {
102 	{ SMB_TYPE_SYSTEM,
103 		offsetof(smb_system_t, smbsi_manufacturer),
104 		offsetof(smb_system_t, smbsi_product),
105 		offsetof(smb_system_t, smbsi_version),
106 		offsetof(smb_system_t, smbsi_serial),
107 		0,
108 		0,
109 		0,
110 		0,
111 		0,
112 		0 },
113 	{ SMB_TYPE_BASEBOARD,
114 		offsetof(smb_bboard_t, smbbb_manufacturer),
115 		offsetof(smb_bboard_t, smbbb_product),
116 		offsetof(smb_bboard_t, smbbb_version),
117 		offsetof(smb_bboard_t, smbbb_serial),
118 		offsetof(smb_bboard_t, smbbb_asset),
119 		offsetof(smb_bboard_t, smbbb_location),
120 		0,
121 		offsetof(smb_bboard_t, smbbb_cn),
122 		SMB_CONT_WORD,
123 		offsetof(smb_bboard_t, smbbb_cv) },
124 	{ SMB_TYPE_CHASSIS,
125 		offsetof(smb_chassis_t, smbch_manufacturer),
126 		0,
127 		offsetof(smb_chassis_t, smbch_version),
128 		offsetof(smb_chassis_t, smbch_serial),
129 		offsetof(smb_chassis_t, smbch_asset),
130 		0,
131 		0,
132 		offsetof(smb_chassis_t, smbch_cn),
133 		SMB_CONT_BYTE,
134 		offsetof(smb_chassis_t, smbch_cv) },
135 	{ SMB_TYPE_PROCESSOR,
136 		offsetof(smb_processor_t, smbpr_manufacturer),
137 		0,
138 		offsetof(smb_processor_t, smbpr_version),
139 		offsetof(smb_processor_t, smbpr_serial),
140 		offsetof(smb_processor_t, smbpr_asset),
141 		offsetof(smb_processor_t, smbpr_socket),
142 		offsetof(smb_processor_t, smbpr_part),
143 		0,
144 		0,
145 		0 },
146 	{ SMB_TYPE_CACHE,
147 		0,
148 		0,
149 		0,
150 		0,
151 		0,
152 		offsetof(smb_cache_t, smbca_socket),
153 		0,
154 		0,
155 		0,
156 		0 },
157 	{ SMB_TYPE_PORT,
158 		0,
159 		0,
160 		0,
161 		0,
162 		0,
163 		offsetof(smb_port_t, smbpo_iref),
164 		0,
165 		0,
166 		0,
167 		0 },
168 	{ SMB_TYPE_SLOT,
169 		0,
170 		0,
171 		0,
172 		0,
173 		0,
174 		offsetof(smb_slot_t, smbsl_name),
175 		0,
176 		0,
177 		0,
178 		0 },
179 	{ SMB_TYPE_MEMDEVICE,
180 		offsetof(smb_memdevice_t, smbmdev_manufacturer),
181 		0,
182 		0,
183 		offsetof(smb_memdevice_t, smbmdev_serial),
184 		offsetof(smb_memdevice_t, smbmdev_asset),
185 		offsetof(smb_memdevice_t, smbmdev_dloc),
186 		offsetof(smb_memdevice_t, smbmdev_part),
187 		0,
188 		0,
189 		0 },
190 	{ SMB_TYPE_POWERSUP,
191 		offsetof(smb_powersup_t, smbpsup_manufacturer),
192 		offsetof(smb_powersup_t, smbpsup_devname),
193 		offsetof(smb_powersup_t, smbpsup_rev),
194 		offsetof(smb_powersup_t, smbpsup_serial),
195 		offsetof(smb_powersup_t, smbpsup_asset),
196 		offsetof(smb_powersup_t, smbpsup_loc),
197 		offsetof(smb_powersup_t, smbpsup_part),
198 		0,
199 		0,
200 		0 },
201 	{ SMB_TYPE_EOT }
202 };
203 
204 static const char *
205 smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n)
206 {
207 	const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr;
208 
209 	if (off != 0 && sp + off < stp->smbst_end) {
210 		(*n)++; /* indicate success for caller */
211 		return (smb_strptr(stp, sp[off]));
212 	}
213 
214 	return (smb_strptr(stp, 0));
215 }
216 
217 static void
218 smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen)
219 {
220 	if (dstlen > hp->smbh_len) {
221 		bcopy(hp, dst, hp->smbh_len);
222 		bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len);
223 	} else
224 		bcopy(hp, dst, dstlen);
225 }
226 
227 smbios_entry_point_t
228 smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
229 {
230 	bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
231 	return (shp->sh_ent_type);
232 }
233 
234 void
235 smbios_info_smbios_version(smbios_hdl_t *shp, smbios_version_t *v)
236 {
237 	v->smbv_major = SMB_MAJOR(shp->sh_smbvers);
238 	v->smbv_minor = SMB_MINOR(shp->sh_smbvers);
239 }
240 
241 #ifndef _KERNEL
242 static char smbios_product_override[256];
243 static boolean_t smbios_product_checked;
244 #endif
245 
246 int
247 smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip)
248 {
249 	const smb_struct_t *stp = smb_lookup_id(shp, id);
250 	const struct smb_infospec *isp;
251 	int n = 0;
252 
253 	if (stp == NULL)
254 		return (-1); /* errno is set for us */
255 
256 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
257 		if (isp->is_type == stp->smbst_hdr->smbh_type)
258 			break;
259 	}
260 
261 	ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n);
262 	ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n);
263 	ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n);
264 	ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n);
265 	ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n);
266 	ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n);
267 	ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n);
268 
269 	/*
270 	 * This private file allows developers to experiment with reporting
271 	 * different platform strings from SMBIOS.  It is not a supported
272 	 * mechanism in the long term, and does not work in the kernel.
273 	 */
274 #ifndef _KERNEL
275 	if (isp->is_type == SMB_TYPE_SYSTEM) {
276 		if (!smbios_product_checked) {
277 			int fd = open("/etc/smbios_product", O_RDONLY);
278 			if (fd >= 0) {
279 				(void) read(fd, smbios_product_override,
280 				    sizeof (smbios_product_override) - 1);
281 				(void) close(fd);
282 			}
283 			smbios_product_checked = B_TRUE;
284 		}
285 
286 		if (smbios_product_override[0] != '\0')
287 			ip->smbi_product = smbios_product_override;
288 	}
289 #endif
290 
291 	/*
292 	 * If we have a port with an empty internal reference designator string
293 	 * try using the external reference designator string instead.
294 	 */
295 	if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') {
296 		ip->smbi_location = smb_info_strptr(stp,
297 		    offsetof(smb_port_t, smbpo_eref), &n);
298 	}
299 
300 	return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO));
301 }
302 
303 /*
304  * Returns the actual number of contained objects.
305  *
306  * idc - number of contained objects
307  * idv - returned array of contained objects
308  */
309 int
310 smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv)
311 {
312 	const smb_struct_t *stp = smb_lookup_id(shp, id);
313 	const struct smb_infospec *isp;
314 	id_t *cp;
315 	uint_t size;
316 	uint8_t cnt;
317 	int i, n;
318 
319 	if (stp == NULL) {
320 		return (-1); /* errno is set for us */
321 	}
322 
323 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
324 		if (isp->is_type == stp->smbst_hdr->smbh_type)
325 			break;
326 	}
327 	if (isp->is_type == SMB_TYPE_EOT)
328 		return (smb_set_errno(shp, ESMB_TYPE));
329 
330 	size = isp->is_contsz;
331 	cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc);
332 	cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv);
333 
334 	n = MIN(cnt, idc);
335 	for (i = 0; i < n; i++) {
336 		if (size == SMB_CONT_WORD)
337 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 2));
338 		else if (size == SMB_CONT_BYTE)
339 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 3));
340 		else
341 			return (smb_set_errno(shp, ESMB_INVAL));
342 	}
343 
344 	return (cnt);
345 }
346 
347 id_t
348 smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp)
349 {
350 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS);
351 	const smb_bios_t *bip;
352 
353 	if (stp == NULL)
354 		return (-1); /* errno is set for us */
355 
356 	if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t))
357 		return (smb_set_errno(shp, ESMB_CORRUPT));
358 
359 	bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr;
360 	bzero(bp, sizeof (smb_base_bios_t));
361 	if (smb_libgteq(shp, SMB_VERSION_31)) {
362 		bp->smbb_extromsize = 0;
363 	}
364 
365 	bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor);
366 	bp->smbb_version = smb_strptr(stp, bip->smbbi_version);
367 	bp->smbb_segment = bip->smbbi_segment;
368 	bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate);
369 	bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1);
370 	bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment);
371 	bp->smbb_cflags = bip->smbbi_cflags;
372 
373 	/*
374 	 * If one or more extension bytes are present, reset smbb_xcflags to
375 	 * point to them.  Otherwise leave this member set to NULL.
376 	 */
377 	if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) {
378 		bp->smbb_xcflags = bip->smbbi_xcflags;
379 		bp->smbb_nxcflags = stp->smbst_hdr->smbh_len -
380 		    sizeof (smb_bios_t) + 1;
381 
382 		if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
383 		    smb_gteq(shp, SMB_VERSION_24)) {
384 			bp->smbb_biosv.smbv_major =
385 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ];
386 			bp->smbb_biosv.smbv_minor =
387 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN];
388 			bp->smbb_ecfwv.smbv_major =
389 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ];
390 			bp->smbb_ecfwv.smbv_minor =
391 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN];
392 		}
393 
394 		if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 &&
395 		    smb_gteq(shp, SMB_VERSION_31)) {
396 			uint16_t val;
397 			uint64_t rs;
398 
399 			/*
400 			 * Because of the fact that the extended size is a
401 			 * uint16_t and we'd need to define an explicit
402 			 * endian-aware way to access it, we don't include it in
403 			 * the number of extended flags below and thus subtract
404 			 * its size.
405 			 */
406 			bp->smbb_nxcflags -= sizeof (uint16_t);
407 			bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val,
408 			    sizeof (val));
409 			val = LE_16(val);
410 
411 			/*
412 			 * The upper two bits of the extended rom size are used
413 			 * to indicate whether the other 14 bits are in MB or
414 			 * GB.
415 			 */
416 			rs = SMB_BIOS_EXTROM_VALUE_MASK(val);
417 			switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) {
418 			case 0:
419 				rs *= 1024ULL * 1024ULL;
420 				break;
421 			case 1:
422 				rs *= 1024ULL * 1024ULL * 1024ULL;
423 				break;
424 			default:
425 				rs = 0;
426 				break;
427 			}
428 
429 			if (smb_libgteq(shp, SMB_VERSION_31)) {
430 				bp->smbb_extromsize = rs;
431 			}
432 		}
433 	}
434 
435 	if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) {
436 		bp->smbb_extromsize = bp->smbb_romsize;
437 	}
438 
439 	return (stp->smbst_hdr->smbh_hdl);
440 }
441 
442 id_t
443 smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip)
444 {
445 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM);
446 	smb_system_t si;
447 
448 	if (stp == NULL)
449 		return (-1); /* errno is set for us */
450 
451 	smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si));
452 	bzero(sip, sizeof (smbios_system_t));
453 
454 	sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid;
455 	sip->smbs_uuidlen = sizeof (si.smbsi_uuid);
456 	sip->smbs_wakeup = si.smbsi_wakeup;
457 	sip->smbs_sku = smb_strptr(stp, si.smbsi_sku);
458 	sip->smbs_family = smb_strptr(stp, si.smbsi_family);
459 
460 	return (stp->smbst_hdr->smbh_hdl);
461 }
462 
463 int
464 smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp)
465 {
466 	const smb_struct_t *stp = smb_lookup_id(shp, id);
467 	smb_bboard_t bb;
468 
469 	if (stp == NULL)
470 		return (-1); /* errno is set for us */
471 
472 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD)
473 		return (smb_set_errno(shp, ESMB_TYPE));
474 
475 	smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb));
476 	bzero(bbp, sizeof (smbios_bboard_t));
477 
478 	bbp->smbb_chassis = bb.smbbb_chassis;
479 	bbp->smbb_flags = bb.smbbb_flags;
480 	bbp->smbb_type = bb.smbbb_type;
481 	bbp->smbb_contn = bb.smbbb_cn;
482 
483 	return (0);
484 }
485 
486 int
487 smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp)
488 {
489 	const smb_struct_t *stp = smb_lookup_id(shp, id);
490 	/* Length is measurable by one byte, so it'll be no more than 255. */
491 	uint8_t buf[256];
492 	smb_chassis_t *ch = (smb_chassis_t *)&buf[0];
493 
494 	if (stp == NULL)
495 		return (-1); /* errno is set for us */
496 
497 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS)
498 		return (smb_set_errno(shp, ESMB_TYPE));
499 
500 	smb_info_bcopy(stp->smbst_hdr, ch, sizeof (buf));
501 	bzero(chp, sizeof (smb_base_chassis_t));
502 	if (smb_libgteq(shp, SMB_VERSION_27)) {
503 		bzero(chp->smbc_sku, sizeof (chp->smbc_sku));
504 	}
505 
506 	chp->smbc_oemdata = ch->smbch_oemdata;
507 	chp->smbc_lock = (ch->smbch_type & SMB_CHT_LOCK) != 0;
508 	chp->smbc_type = ch->smbch_type & ~SMB_CHT_LOCK;
509 	chp->smbc_bustate = ch->smbch_bustate;
510 	chp->smbc_psstate = ch->smbch_psstate;
511 	chp->smbc_thstate = ch->smbch_thstate;
512 	chp->smbc_security = ch->smbch_security;
513 	chp->smbc_uheight = ch->smbch_uheight;
514 	chp->smbc_cords = ch->smbch_cords;
515 	chp->smbc_elems = ch->smbch_cn;
516 	chp->smbc_elemlen = ch->smbch_cm;
517 
518 	if (smb_libgteq(shp, SMB_VERSION_27)) {
519 		(void) strlcpy(chp->smbc_sku, SMB_CH_SKU(ch),
520 		    sizeof (chp->smbc_sku));
521 	}
522 
523 	return (0);
524 }
525 
526 int
527 smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp)
528 {
529 	const smb_struct_t *stp = smb_lookup_id(shp, id);
530 	smb_processor_t p;
531 
532 	if (stp == NULL)
533 		return (-1); /* errno is set for us */
534 
535 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR)
536 		return (smb_set_errno(shp, ESMB_TYPE));
537 
538 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
539 	bzero(pp, sizeof (smb_base_processor_t));
540 
541 	pp->smbp_cpuid = p.smbpr_cpuid;
542 	pp->smbp_type = p.smbpr_type;
543 	pp->smbp_family = p.smbpr_family;
544 	pp->smbp_voltage = p.smbpr_voltage;
545 	pp->smbp_maxspeed = p.smbpr_maxspeed;
546 	pp->smbp_curspeed = p.smbpr_curspeed;
547 	pp->smbp_status = p.smbpr_status;
548 	pp->smbp_upgrade = p.smbpr_upgrade;
549 	pp->smbp_l1cache = p.smbpr_l1cache;
550 	pp->smbp_l2cache = p.smbpr_l2cache;
551 	pp->smbp_l3cache = p.smbpr_l3cache;
552 
553 	if (smb_libgteq(shp, SMB_VERSION_25)) {
554 		pp->smbp_corecount = p.smbpr_corecount;
555 		pp->smbp_coresenabled = p.smbpr_coresenabled;
556 		pp->smbp_threadcount = p.smbpr_threadcount;
557 		pp->smbp_cflags = p.smbpr_cflags;
558 	}
559 
560 	if (smb_libgteq(shp, SMB_VERSION_26)) {
561 		if (pp->smbp_family == 0xfe) {
562 			pp->smbp_family = p.smbpr_family2;
563 		}
564 	}
565 
566 	if (smb_libgteq(shp, SMB_VERSION_30)) {
567 		if (pp->smbp_corecount == 0xff) {
568 			pp->smbp_corecount = p.smbpr_corecount2;
569 		}
570 		if (pp->smbp_coresenabled == 0xff) {
571 			pp->smbp_coresenabled = p.smbpr_coresenabled2;
572 		}
573 		if (pp->smbp_threadcount == 0xff) {
574 			pp->smbp_threadcount = p.smbpr_threadcount2;
575 		}
576 	}
577 
578 	return (0);
579 }
580 
581 int
582 smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap)
583 {
584 	const smb_struct_t *stp = smb_lookup_id(shp, id);
585 	smb_cache_t c;
586 
587 	if (stp == NULL)
588 		return (-1); /* errno is set for us */
589 
590 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE)
591 		return (smb_set_errno(shp, ESMB_TYPE));
592 
593 	smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c));
594 	bzero(cap, sizeof (smb_base_cache_t));
595 
596 	cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize);
597 	cap->smba_size = SMB_CACHE_SIZE(c.smbca_size);
598 	cap->smba_stype = c.smbca_stype;
599 	cap->smba_ctype = c.smbca_ctype;
600 	cap->smba_speed = c.smbca_speed;
601 	cap->smba_etype = c.smbca_etype;
602 	cap->smba_ltype = c.smbca_ltype;
603 	cap->smba_assoc = c.smbca_assoc;
604 	cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config);
605 	cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config);
606 	cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config);
607 
608 	if (SMB_CACHE_CFG_ENABLED(c.smbca_config))
609 		cap->smba_flags |= SMB_CAF_ENABLED;
610 
611 	if (SMB_CACHE_CFG_SOCKETED(c.smbca_config))
612 		cap->smba_flags |= SMB_CAF_SOCKETED;
613 
614 	if (smb_libgteq(shp, SMB_VERSION_31)) {
615 		cap->smba_maxsize2 = SMB_CACHE_EXT_SIZE(c.smbca_maxsize2);
616 		cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2);
617 
618 		if (cap->smba_maxsize2 == 0) {
619 			cap->smba_maxsize2 = cap->smba_maxsize;
620 		}
621 
622 		if (cap->smba_size2 == 0) {
623 			cap->smba_size2 = cap->smba_size;
624 		}
625 	}
626 
627 	return (0);
628 }
629 
630 int
631 smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop)
632 {
633 	const smb_struct_t *stp = smb_lookup_id(shp, id);
634 	smb_port_t p;
635 
636 	if (stp == NULL)
637 		return (-1); /* errno is set for us */
638 
639 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT)
640 		return (smb_set_errno(shp, ESMB_TYPE));
641 
642 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
643 	bzero(pop, sizeof (smbios_port_t));
644 
645 	pop->smbo_iref = smb_strptr(stp, p.smbpo_iref);
646 	pop->smbo_eref = smb_strptr(stp, p.smbpo_eref);
647 
648 	pop->smbo_itype = p.smbpo_itype;
649 	pop->smbo_etype = p.smbpo_etype;
650 	pop->smbo_ptype = p.smbpo_ptype;
651 
652 	return (0);
653 }
654 
655 int
656 smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp)
657 {
658 	const smb_struct_t *stp = smb_lookup_id(shp, id);
659 	smb_slot_t s;
660 
661 	if (stp == NULL)
662 		return (-1); /* errno is set for us */
663 
664 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
665 		return (smb_set_errno(shp, ESMB_TYPE));
666 
667 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
668 	bzero(sp, sizeof (smb_base_slot_t));
669 
670 	sp->smbl_name = smb_strptr(stp, s.smbsl_name);
671 	sp->smbl_type = s.smbsl_type;
672 	sp->smbl_width = s.smbsl_width;
673 	sp->smbl_usage = s.smbsl_usage;
674 	sp->smbl_length = s.smbsl_length;
675 	sp->smbl_id = s.smbsl_id;
676 	sp->smbl_ch1 = s.smbsl_ch1;
677 	sp->smbl_ch2 = s.smbsl_ch2;
678 	sp->smbl_sg = s.smbsl_sg;
679 	sp->smbl_bus = s.smbsl_bus;
680 	sp->smbl_df = s.smbsl_df;
681 
682 	if (smb_libgteq(shp, SMB_VERSION_32)) {
683 		sp->smbl_dbw = s.smbsl_dbw;
684 		sp->smbl_npeers = s.smbsl_npeers;
685 	}
686 
687 	return (0);
688 }
689 
690 void
691 smbios_info_slot_peers_free(smbios_hdl_t *shp, uint_t npeers,
692     smbios_slot_peer_t *peer)
693 {
694 	size_t sz = npeers * sizeof (smbios_slot_peer_t);
695 
696 	if (npeers == 0) {
697 		ASSERT3P(peer, ==, NULL);
698 		return;
699 	}
700 
701 	smb_free(peer, sz);
702 }
703 
704 int
705 smbios_info_slot_peers(smbios_hdl_t *shp, id_t id, uint_t *npeers,
706     smbios_slot_peer_t **peerp)
707 {
708 	const smb_struct_t *stp = smb_lookup_id(shp, id);
709 	const smb_slot_t *slotp;
710 	smbios_slot_peer_t *peer;
711 	size_t minlen;
712 	uint_t i;
713 
714 	if (stp == NULL)
715 		return (-1); /* errno is set for us */
716 
717 	slotp = (const smb_slot_t *)stp->smbst_hdr;
718 
719 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
720 		return (smb_set_errno(shp, ESMB_TYPE));
721 
722 	if (stp->smbst_hdr->smbh_len <= offsetof(smb_slot_t, smbsl_npeers) ||
723 	    slotp->smbsl_npeers == 0) {
724 		*npeers = 0;
725 		*peerp = NULL;
726 		return (0);
727 	}
728 
729 	/*
730 	 * Make sure that the size of the structure makes sense for the number
731 	 * of peers reported.
732 	 */
733 	minlen = slotp->smbsl_npeers * sizeof (smb_slot_peer_t) +
734 	    offsetof(smb_slot_t, smbsl_npeers);
735 	if (stp->smbst_hdr->smbh_len < minlen) {
736 		return (smb_set_errno(shp, ESMB_SHORT));
737 	}
738 
739 	if ((peer = smb_alloc(slotp->smbsl_npeers *
740 	    sizeof (smbios_slot_peer_t))) == NULL) {
741 		return (smb_set_errno(shp, ESMB_NOMEM));
742 	}
743 
744 	for (i = 0; i < slotp->smbsl_npeers; i++) {
745 		peer[i].smblp_group = slotp->smbsl_peers[i].smbspb_group_no;
746 		peer[i].smblp_bus = slotp->smbsl_peers[i].smbspb_bus;
747 		peer[i].smblp_device = slotp->smbsl_peers[i].smbspb_df >> 3;
748 		peer[i].smblp_function = slotp->smbsl_peers[i].smbspb_df & 0x7;
749 		peer[i].smblp_data_width = slotp->smbsl_peers[i].smbspb_width;
750 	}
751 
752 	*npeers = slotp->smbsl_npeers;
753 	*peerp = peer;
754 
755 	return (0);
756 }
757 
758 int
759 smbios_info_obdevs_ext(smbios_hdl_t *shp, id_t id, smbios_obdev_ext_t *oep)
760 {
761 	const smb_struct_t *stp = smb_lookup_id(shp, id);
762 	smb_obdev_ext_t obe;
763 
764 	if (stp == NULL)
765 		return (-1); /* errno is set for us */
766 
767 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVEXT)
768 		return (smb_set_errno(shp, ESMB_TYPE));
769 
770 	smb_info_bcopy(stp->smbst_hdr, &obe, sizeof (obe));
771 	bzero(oep, sizeof (smbios_obdev_ext_t));
772 
773 	oep->smboe_name = smb_strptr(stp, obe.smbobe_name);
774 	oep->smboe_dtype = obe.smbobe_dtype;
775 	oep->smboe_dti = obe.smbobe_dti;
776 	oep->smboe_sg = obe.smbobe_sg;
777 	oep->smboe_bus = obe.smbobe_bus;
778 	oep->smboe_df = obe.smbobe_df;
779 
780 	return (0);
781 }
782 
783 int
784 smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp)
785 {
786 	const smb_struct_t *stp = smb_lookup_id(shp, id);
787 	const smb_obdev_t *op;
788 	int i, m, n;
789 
790 	if (stp == NULL)
791 		return (-1); /* errno is set for us */
792 
793 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS)
794 		return (smb_set_errno(shp, ESMB_TYPE));
795 
796 	op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t));
797 	m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op);
798 	n = MIN(m, obc);
799 
800 	for (i = 0; i < n; i++, op++, obp++) {
801 		obp->smbd_name = smb_strptr(stp, op->smbob_name);
802 		obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED;
803 		obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0;
804 	}
805 
806 	return (m);
807 }
808 
809 /*
810  * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the
811  * first byte to indicate the size of a string table at the end of the record.
812  * Therefore, smbios_info_strtab() can be used to retrieve the table size and
813  * strings for any of these underlying record types.
814  */
815 int
816 smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[])
817 {
818 	const smb_struct_t *stp = smb_lookup_id(shp, id);
819 	smb_strtab_t s;
820 	int i, n;
821 
822 	if (stp == NULL)
823 		return (-1); /* errno is set for us */
824 
825 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR &&
826 	    stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR &&
827 	    stp->smbst_hdr->smbh_type != SMB_TYPE_LANG)
828 		return (smb_set_errno(shp, ESMB_TYPE));
829 
830 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
831 	n = MIN(s.smbtb_count, argc);
832 
833 	for (i = 0; i < n; i++)
834 		argv[i] = smb_strptr(stp, i + 1);
835 
836 	return (s.smbtb_count);
837 }
838 
839 id_t
840 smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp)
841 {
842 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG);
843 	smb_lang_t l;
844 
845 	if (stp == NULL)
846 		return (-1); /* errno is set for us */
847 
848 	smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l));
849 	bzero(lp, sizeof (smbios_lang_t));
850 
851 	lp->smbla_cur = smb_strptr(stp, l.smblang_cur);
852 	lp->smbla_fmt = l.smblang_flags & 1;
853 	lp->smbla_num = l.smblang_num;
854 
855 	return (stp->smbst_hdr->smbh_hdl);
856 }
857 
858 id_t
859 smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp)
860 {
861 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG);
862 	const smb_sel_t *sel;
863 	size_t len;
864 
865 	if (stp == NULL)
866 		return (-1); /* errno is set for us */
867 
868 	if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t))
869 		return (smb_set_errno(shp, ESMB_CORRUPT));
870 
871 	sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr;
872 	len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t);
873 	bzero(evp, sizeof (smbios_evlog_t));
874 
875 	if (len < sel->smbsel_typec * sel->smbsel_typesz)
876 		return (smb_set_errno(shp, ESMB_CORRUPT));
877 
878 	evp->smbev_size = sel->smbsel_len;
879 	evp->smbev_hdr = sel->smbsel_hdroff;
880 	evp->smbev_data = sel->smbsel_dataoff;
881 	evp->smbev_method = sel->smbsel_method;
882 	evp->smbev_flags = sel->smbsel_status;
883 	evp->smbev_format = sel->smbsel_format;
884 	evp->smbev_token = sel->smbsel_token;
885 	evp->smbev_addr.eva_addr = sel->smbsel_addr;
886 
887 	if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) {
888 		evp->smbev_typec = sel->smbsel_typec;
889 		evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev;
890 	}
891 
892 	return (stp->smbst_hdr->smbh_hdl);
893 }
894 
895 int
896 smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map)
897 {
898 	const smb_struct_t *stp = smb_lookup_id(shp, id);
899 	smb_memarray_t m;
900 
901 	if (stp == NULL)
902 		return (-1); /* errno is set for us */
903 
904 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY)
905 		return (smb_set_errno(shp, ESMB_TYPE));
906 
907 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
908 	bzero(map, sizeof (smbios_memarray_t));
909 
910 	map->smbma_location = m.smbmarr_loc;
911 	map->smbma_use = m.smbmarr_use;
912 	map->smbma_ecc = m.smbmarr_ecc;
913 	map->smbma_ndevs = m.smbmarr_ndevs;
914 	map->smbma_err = m.smbmarr_err;
915 
916 	if (m.smbmarr_cap != 0x80000000)
917 		map->smbma_size = (uint64_t)m.smbmarr_cap * 1024;
918 	else if (m.smbmarr_extcap != 0)
919 		map->smbma_size = m.smbmarr_extcap;
920 	else
921 		map->smbma_size = 0; /* unknown */
922 
923 	return (0);
924 }
925 
926 int
927 smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map)
928 {
929 	const smb_struct_t *stp = smb_lookup_id(shp, id);
930 	smb_memarrmap_t m;
931 
932 	if (stp == NULL)
933 		return (-1); /* errno is set for us */
934 
935 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP)
936 		return (smb_set_errno(shp, ESMB_TYPE));
937 
938 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
939 	bzero(map, sizeof (smbios_memarrmap_t));
940 
941 	map->smbmam_array = m.smbamap_array;
942 	map->smbmam_width = m.smbamap_width;
943 
944 	if (m.smbamap_start != 0xFFFFFFFF && m.smbamap_end != 0xFFFFFFFF) {
945 		map->smbmam_addr = (uint64_t)m.smbamap_start * 1024;
946 		map->smbmam_size = (uint64_t)
947 		    (m.smbamap_end - m.smbamap_start + 1) * 1024;
948 	} else if (m.smbamap_extstart != 0 && m.smbamap_extend != 0) {
949 		map->smbmam_addr = m.smbamap_extstart;
950 		map->smbmam_size = m.smbamap_extend - m.smbamap_extstart + 1;
951 	}
952 
953 	return (0);
954 }
955 
956 int
957 smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp)
958 {
959 	const smb_struct_t *stp = smb_lookup_id(shp, id);
960 	smb_memdevice_t m;
961 
962 	if (stp == NULL)
963 		return (-1); /* errno is set for us */
964 
965 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE)
966 		return (smb_set_errno(shp, ESMB_TYPE));
967 
968 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
969 	bzero(mdp, sizeof (smb_base_memdevice_t));
970 
971 	mdp->smbmd_array = m.smbmdev_array;
972 	mdp->smbmd_error = m.smbmdev_error;
973 	mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth;
974 	mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth;
975 
976 	if (m.smbmdev_size == 0x7FFF) {
977 		mdp->smbmd_size = (uint64_t)m.smbmdev_extsize;
978 		mdp->smbmd_size *= 1024 * 1024; /* convert MB to bytes */
979 	} else if (m.smbmdev_size != 0xFFFF) {
980 		mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES);
981 		if (m.smbmdev_size & SMB_MDS_KBYTES)
982 			mdp->smbmd_size *= 1024;
983 		else
984 			mdp->smbmd_size *= 1024 * 1024;
985 	} else
986 		mdp->smbmd_size = -1ULL; /* size unknown */
987 
988 	mdp->smbmd_form = m.smbmdev_form;
989 	mdp->smbmd_set = m.smbmdev_set;
990 	mdp->smbmd_type = m.smbmdev_type;
991 	mdp->smbmd_speed = m.smbmdev_speed;
992 	mdp->smbmd_flags = m.smbmdev_flags;
993 	mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc);
994 	mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc);
995 
996 	if (smb_libgteq(shp, SMB_VERSION_26)) {
997 		mdp->smbmd_rank = m.smbmdev_attrs & 0x0F;
998 	}
999 
1000 	if (smb_libgteq(shp, SMB_VERSION_27)) {
1001 		mdp->smbmd_clkspeed = m.smbmdev_clkspeed;
1002 	}
1003 
1004 	if (smb_libgteq(shp, SMB_VERSION_28)) {
1005 		mdp->smbmd_minvolt = m.smbmdev_minvolt;
1006 		mdp->smbmd_maxvolt = m.smbmdev_maxvolt;
1007 		mdp->smbmd_confvolt = m.smbmdev_confvolt;
1008 	}
1009 
1010 	if (smb_libgteq(shp, SMB_VERSION_32)) {
1011 		mdp->smbmd_memtech = m.smbmdev_memtech;
1012 		mdp->smbmd_opcap_flags = m.smbmdev_opmode;
1013 		mdp->smbmd_firmware_rev = smb_strptr(stp,
1014 		    m.smbmdev_fwver);
1015 		mdp->smbmd_modmfg_id = m.smbmdev_modulemfgid;
1016 		mdp->smbmd_modprod_id = m.smbmdev_moduleprodid;
1017 		mdp->smbmd_cntrlmfg_id = m.smbmdev_memsysmfgid;
1018 		mdp->smbmd_cntrlprod_id = m.smbmdev_memsysprodid;
1019 		mdp->smbmd_nvsize = m.smbmdev_nvsize;
1020 		mdp->smbmd_volatile_size = m.smbmdev_volsize;
1021 		mdp->smbmd_cache_size = m.smbmdev_cachesize;
1022 		mdp->smbmd_logical_size = m.smbmdev_logicalsize;
1023 	}
1024 
1025 	if (smb_libgteq(shp, SMB_VERSION_33)) {
1026 		if (m.smbmdev_speed == 0xffff) {
1027 			mdp->smbmd_extspeed = m.smbmdev_extspeed;
1028 		} else {
1029 			mdp->smbmd_extspeed = m.smbmdev_speed;
1030 		}
1031 
1032 		if (m.smbmdev_clkspeed == 0xffff) {
1033 			mdp->smbmd_extclkspeed = m.smbmdev_extclkspeed;
1034 		} else {
1035 			mdp->smbmd_extclkspeed = m.smbmdev_clkspeed;
1036 		}
1037 	}
1038 
1039 	return (0);
1040 }
1041 
1042 int
1043 smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp)
1044 {
1045 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1046 	smb_memdevmap_t m;
1047 
1048 	if (stp == NULL)
1049 		return (-1); /* errno is set for us */
1050 
1051 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP)
1052 		return (smb_set_errno(shp, ESMB_TYPE));
1053 
1054 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
1055 	bzero(mdp, sizeof (smbios_memdevmap_t));
1056 
1057 	mdp->smbmdm_device = m.smbdmap_device;
1058 	mdp->smbmdm_arrmap = m.smbdmap_array;
1059 	mdp->smbmdm_rpos = m.smbdmap_rpos;
1060 	mdp->smbmdm_ipos = m.smbdmap_ipos;
1061 	mdp->smbmdm_idepth = m.smbdmap_idepth;
1062 
1063 	if (m.smbdmap_start != 0xFFFFFFFF && m.smbdmap_end != 0xFFFFFFFF) {
1064 		mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024;
1065 		mdp->smbmdm_size = (uint64_t)
1066 		    (m.smbdmap_end - m.smbdmap_start + 1) * 1024;
1067 	} else if (m.smbdmap_extstart != 0 && m.smbdmap_extend != 0) {
1068 		mdp->smbmdm_addr = m.smbdmap_extstart;
1069 		mdp->smbmdm_size = m.smbdmap_extend - m.smbdmap_extstart + 1;
1070 	}
1071 
1072 	return (0);
1073 }
1074 
1075 id_t
1076 smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp)
1077 {
1078 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY);
1079 	smb_hwsec_t hs;
1080 
1081 	if (stp == NULL)
1082 		return (-1); /* errno is set for us */
1083 
1084 	smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
1085 	bzero(hsp, sizeof (smbios_hwsec_t));
1086 
1087 	hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
1088 	hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
1089 	hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
1090 	hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
1091 
1092 	return (stp->smbst_hdr->smbh_hdl);
1093 }
1094 
1095 id_t
1096 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
1097 {
1098 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
1099 	const smb_boot_t *b;
1100 
1101 	if (stp == NULL)
1102 		return (-1); /* errno is set for us */
1103 
1104 	bzero(bp, sizeof (smbios_boot_t));
1105 
1106 	b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
1107 
1108 	bp->smbt_status = b->smbbo_status[0];
1109 	bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
1110 	bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
1111 
1112 	return (stp->smbst_hdr->smbh_hdl);
1113 }
1114 
1115 id_t
1116 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
1117 {
1118 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
1119 	smb_ipmi_t i;
1120 
1121 	if (stp == NULL)
1122 		return (-1); /* errno is set for us */
1123 
1124 	smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
1125 	bzero(ip, sizeof (smbios_ipmi_t));
1126 
1127 	ip->smbip_type = i.smbipm_type;
1128 	ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec);
1129 	ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec);
1130 	ip->smbip_i2c = i.smbipm_i2c;
1131 	ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO;
1132 	ip->smbip_intr = i.smbipm_intr;
1133 
1134 	if (i.smbipm_bus != (uint8_t)-1)
1135 		ip->smbip_bus = i.smbipm_bus;
1136 	else
1137 		ip->smbip_bus = -1u;
1138 
1139 	if (SMB_IPM_INFO_LSB(i.smbipm_info))
1140 		ip->smbip_addr |= 1; /* turn on least-significant bit of addr */
1141 
1142 	if (i.smbipm_addr & SMB_IPM_ADDR_IO) {
1143 		switch (SMB_IPM_INFO_REGS(i.smbipm_info)) {
1144 		case SMB_IPM_REGS_1B:
1145 			ip->smbip_regspacing = 1;
1146 			break;
1147 		case SMB_IPM_REGS_4B:
1148 			ip->smbip_regspacing = 4;
1149 			break;
1150 		case SMB_IPM_REGS_16B:
1151 			ip->smbip_regspacing = 16;
1152 			break;
1153 		default:
1154 			ip->smbip_regspacing = 1;
1155 		}
1156 		ip->smbip_flags |= SMB_IPMI_F_IOADDR;
1157 	}
1158 
1159 	if (SMB_IPM_INFO_ISPEC(i.smbipm_info))
1160 		ip->smbip_flags |= SMB_IPMI_F_INTRSPEC;
1161 
1162 	if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI)
1163 		ip->smbip_flags |= SMB_IPMI_F_INTRHIGH;
1164 
1165 	if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE)
1166 		ip->smbip_flags |= SMB_IPMI_F_INTREDGE;
1167 
1168 	return (stp->smbst_hdr->smbh_hdl);
1169 }
1170 
1171 static boolean_t
1172 smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr)
1173 {
1174 	const smb_struct_t *stp = shp->sh_structs;
1175 	smb_strtab_t s;
1176 	int i, j;
1177 
1178 	for (i = 0; i < shp->sh_nstructs; i++, stp++) {
1179 		if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR)
1180 			continue;
1181 
1182 		smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
1183 		for (j = 0; j < s.smbtb_count; j++)
1184 			if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0)
1185 				return (B_TRUE);
1186 	}
1187 
1188 	return (B_FALSE);
1189 }
1190 
1191 static const char *
1192 smb_serial_valid(const char *serial)
1193 {
1194 	char buf[MAXNAMELEN];
1195 	int i = 0;
1196 
1197 	if (serial == NULL)
1198 		return (NULL);
1199 
1200 	(void) strlcpy(buf, serial, sizeof (buf));
1201 
1202 	while (buf[i] != '\0' && buf[i] == ' ')
1203 		i++;
1204 
1205 	if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL ||
1206 	    strstr(buf, SMB_DEFAULT2) != NULL)
1207 		return (NULL);
1208 
1209 	return (serial);
1210 }
1211 
1212 /*
1213  * Get chassis SN or product SN
1214  */
1215 static int
1216 smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp)
1217 {
1218 	const smb_struct_t *stp;
1219 	smbios_info_t s1, s3;
1220 
1221 	if (psnp == NULL || csnp == NULL)
1222 		return (smb_set_errno(shp, ESMB_INVAL));
1223 
1224 	*psnp = *csnp = NULL;
1225 
1226 	/*
1227 	 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN
1228 	 * from type 1 structure, and chassis SN from type 3 structure.
1229 	 * Otherwise return SN in type 1 structure as chassis SN.
1230 	 */
1231 
1232 	/* Get type 1 SN */
1233 	if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL ||
1234 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR)
1235 		s1.smbi_serial = NULL;
1236 
1237 	/* Get type 3 SN */
1238 	if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL ||
1239 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR)
1240 		s3.smbi_serial = NULL;
1241 
1242 	if (smbios_has_oemstr(shp, SMB_PRMS1)) {
1243 		*psnp = smb_serial_valid(s1.smbi_serial);
1244 		*csnp = smb_serial_valid(s3.smbi_serial);
1245 	} else {
1246 		*csnp = smb_serial_valid(s1.smbi_serial);
1247 	}
1248 
1249 	return (0);
1250 }
1251 
1252 const char *
1253 smbios_psn(smbios_hdl_t *shp)
1254 {
1255 	const char *psn, *csn;
1256 
1257 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn);
1258 }
1259 
1260 const char *
1261 smbios_csn(smbios_hdl_t *shp)
1262 {
1263 	const char *psn, *csn;
1264 
1265 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn);
1266 }
1267 
1268 int
1269 smbios_info_extprocessor(smbios_hdl_t *shp, id_t id,
1270     smbios_processor_ext_t *epp)
1271 {
1272 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1273 	smb_processor_ext_t *exp;
1274 
1275 	if (stp == NULL)
1276 		return (-1); /* errno is set for us */
1277 
1278 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR)
1279 		return (smb_set_errno(shp, ESMB_TYPE));
1280 
1281 	exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr;
1282 	bzero(epp, sizeof (smbios_processor_ext_t));
1283 
1284 	epp->smbpe_processor = exp->smbpre_processor;
1285 	epp->smbpe_fru = exp->smbpre_fru;
1286 	epp->smbpe_n = exp->smbpre_n;
1287 	epp->smbpe_apicid = exp->smbpre_apicid;
1288 
1289 	return (0);
1290 }
1291 
1292 int
1293 smbios_info_extport(smbios_hdl_t *shp, id_t id, smbios_port_ext_t *eportp)
1294 {
1295 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1296 	smb_port_ext_t *ep;
1297 
1298 	if (stp == NULL)
1299 		return (-1); /* errno is set for us */
1300 
1301 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PORT)
1302 		return (smb_set_errno(shp, ESMB_TYPE));
1303 
1304 	ep = (smb_port_ext_t *)(uintptr_t)stp->smbst_hdr;
1305 	bzero(eportp, sizeof (smbios_port_ext_t));
1306 
1307 	eportp->smbporte_chassis = ep->smbpoe_chassis;
1308 	eportp->smbporte_port = ep->smbpoe_port;
1309 	eportp->smbporte_dtype = ep->smbpoe_dtype;
1310 	eportp->smbporte_devhdl = ep->smbpoe_devhdl;
1311 	eportp->smbporte_phy = ep->smbpoe_phy;
1312 
1313 	return (0);
1314 }
1315 
1316 int
1317 smbios_info_pciexrc(smbios_hdl_t *shp, id_t id,
1318     smbios_pciexrc_t *rcp)
1319 {
1320 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1321 	smb_pciexrc_t rc;
1322 
1323 	if (stp == NULL)
1324 		return (-1); /* errno is set for us */
1325 
1326 	if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC)
1327 		return (smb_set_errno(shp, ESMB_TYPE));
1328 
1329 	smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc));
1330 	bzero(rcp, sizeof (smbios_pciexrc_t));
1331 
1332 	rcp->smbpcie_bb = rc.smbpciexrc_bboard;
1333 	rcp->smbpcie_bdf = rc.smbpciexrc_bdf;
1334 
1335 	return (0);
1336 }
1337 
1338 int
1339 smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap)
1340 {
1341 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1342 	smb_memarray_ext_t exma;
1343 
1344 	if (stp == NULL)
1345 		return (-1); /* errno is set for us */
1346 
1347 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY)
1348 		return (smb_set_errno(shp, ESMB_TYPE));
1349 
1350 	smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma));
1351 	bzero(emap, sizeof (smbios_memarray_ext_t));
1352 
1353 	emap->smbmae_ma = exma.smbmarre_ma;
1354 	emap->smbmae_comp = exma.smbmarre_component;
1355 	emap->smbmae_bdf = exma.smbmarre_bdf;
1356 
1357 	return (0);
1358 }
1359 
1360 int
1361 smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id,
1362     smbios_memdevice_ext_t *emdp)
1363 {
1364 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1365 	smb_memdevice_ext_t exmd;
1366 
1367 	if (stp == NULL)
1368 		return (-1); /* errno is set for us */
1369 
1370 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE)
1371 		return (smb_set_errno(shp, ESMB_TYPE));
1372 
1373 	smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd));
1374 	bzero(emdp, sizeof (smbios_memdevice_ext_t));
1375 
1376 	emdp->smbmdeve_md = exmd.smbmdeve_mdev;
1377 	emdp->smbmdeve_drch = exmd.smbmdeve_dchan;
1378 	emdp->smbmdeve_ncs  = exmd.smbmdeve_ncs;
1379 	emdp->smbmdeve_cs = exmd.smbmdeve_cs;
1380 
1381 	return (0);
1382 }
1383 
1384 int
1385 smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup)
1386 {
1387 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1388 	smb_powersup_t psu;
1389 
1390 	if (stp == NULL)
1391 		return (-1); /* errno is set for us */
1392 
1393 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP)
1394 		return (smb_set_errno(shp, ESMB_TYPE));
1395 
1396 	/* The minimum length required by the spec is 0x10. */
1397 	if (stp->smbst_hdr->smbh_len < 0x10)
1398 		return (smb_set_errno(shp, ESMB_SHORT));
1399 
1400 	bzero(psup, sizeof (*psup));
1401 	smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu));
1402 	psup->smbps_group = psu.smbpsup_group;
1403 	psup->smbps_maxout = psu.smbpsup_max;
1404 
1405 	if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char))
1406 		psup->smbps_flags |= SMB_POWERSUP_F_HOT;
1407 	if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char))
1408 		psup->smbps_flags |= SMB_POWERSUP_F_PRESENT;
1409 	if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char))
1410 		psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG;
1411 
1412 	psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char);
1413 	psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char);
1414 	psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char);
1415 
1416 	if (stp->smbst_hdr->smbh_len >= 0x12) {
1417 		psup->smbps_vprobe = psu.smbpsup_vprobe;
1418 	} else {
1419 		psup->smbps_vprobe = 0xffff;
1420 	}
1421 
1422 	if (stp->smbst_hdr->smbh_len >= 0x14) {
1423 		psup->smbps_cooldev = psu.smbpsup_cooldev;
1424 	} else {
1425 		psup->smbps_cooldev = 0xffff;
1426 	}
1427 
1428 	if (stp->smbst_hdr->smbh_len >= 0x16) {
1429 		psup->smbps_iprobe = psu.smbpsup_iprobe;
1430 	} else {
1431 		psup->smbps_iprobe = 0xffff;
1432 	}
1433 
1434 	return (0);
1435 }
1436 
1437 int
1438 smbios_info_vprobe(smbios_hdl_t *shp, id_t id, smbios_vprobe_t *vprobe)
1439 {
1440 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1441 	smb_vprobe_t vp;
1442 
1443 	if (stp == NULL)
1444 		return (-1); /* errno is set for us */
1445 
1446 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_VPROBE)
1447 		return (smb_set_errno(shp, ESMB_TYPE));
1448 
1449 	if (stp->smbst_hdr->smbh_len < SMB_VPROBE_MINLEN)
1450 		return (smb_set_errno(shp, ESMB_SHORT));
1451 
1452 	bzero(vprobe, sizeof (*vprobe));
1453 	smb_info_bcopy(stp->smbst_hdr, &vp, sizeof (vp));
1454 	vprobe->smbvp_description = smb_strptr(stp, vp.smbvpr_descr);
1455 	vprobe->smbvp_location = SMB_VPROBE_LOCATION(vp.smbvpr_locstat);
1456 	vprobe->smbvp_status = SMB_VPROBE_STATUS(vp.smbvpr_locstat);
1457 	vprobe->smbvp_maxval = vp.smbvpr_maxval;
1458 	vprobe->smbvp_minval = vp.smbvpr_minval;
1459 	vprobe->smbvp_resolution = vp.smbvpr_resolution;
1460 	vprobe->smbvp_tolerance	= vp.smbvpr_tolerance;
1461 	vprobe->smbvp_accuracy = vp.smbvpr_accuracy;
1462 
1463 	if (stp->smbst_hdr->smbh_len >= SMB_VPROBE_NOMINAL_MINLEN) {
1464 		vprobe->smbvp_nominal = vp.smbvpr_nominal;
1465 	} else {
1466 		vprobe->smbvp_nominal = SMB_PROBE_UNKNOWN_VALUE;
1467 	}
1468 
1469 	return (0);
1470 }
1471 
1472 int
1473 smbios_info_cooldev(smbios_hdl_t *shp, id_t id, smbios_cooldev_t *cooldev)
1474 {
1475 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1476 	smb_cooldev_t cd;
1477 
1478 	if (stp == NULL)
1479 		return (-1); /* errno is set for us */
1480 
1481 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_COOLDEV)
1482 		return (smb_set_errno(shp, ESMB_TYPE));
1483 
1484 	if (stp->smbst_hdr->smbh_len < SMB_COOLDEV_MINLEN)
1485 		return (smb_set_errno(shp, ESMB_SHORT));
1486 
1487 	bzero(cooldev, sizeof (*cooldev));
1488 	smb_info_bcopy(stp->smbst_hdr, &cd, sizeof (cd));
1489 	cooldev->smbcd_tprobe = cd.smbcdev_tprobe;
1490 	cooldev->smbcd_type = SMB_COOLDEV_TYPE(cd.smbcdev_typstat);
1491 	cooldev->smbcd_status = SMB_COOLDEV_STATUS(cd.smbcdev_typstat);
1492 	cooldev->smbcd_group = cd.smbcdev_group;
1493 	cooldev->smbcd_oem = cd.smbcdev_oem;
1494 
1495 	if (stp->smbst_hdr->smbh_len >= SMB_COOLDEV_NOMINAL_MINLEN) {
1496 		cooldev->smbcd_nominal = cd.smbcdev_nominal;
1497 	} else {
1498 		cooldev->smbcd_nominal = SMB_PROBE_UNKNOWN_VALUE;
1499 	}
1500 
1501 	/*
1502 	 * The description field was added in SMBIOS version 2.7. The
1503 	 * SMB_TYPE_COOLDEV support was only added after all of the 2.7+ fields
1504 	 * were added in the spec. So while a user may request an older version,
1505 	 * we don't have to worry about old structures and just simply skip it
1506 	 * if they're not asking for it.
1507 	 */
1508 	if (smb_libgteq(shp, SMB_VERSION_27) &&
1509 	    smb_gteq(shp, SMB_VERSION_27) &&
1510 	    stp->smbst_hdr->smbh_len >= SMB_COOLDEV_DESCR_MINLEN) {
1511 		cooldev->smbcd_descr = smb_strptr(stp, cd.smbcdev_descr);
1512 	} else {
1513 		cooldev->smbcd_descr = NULL;
1514 	}
1515 
1516 	return (0);
1517 }
1518 
1519 int
1520 smbios_info_tprobe(smbios_hdl_t *shp, id_t id, smbios_tprobe_t *tprobe)
1521 {
1522 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1523 	smb_tprobe_t tp;
1524 
1525 	if (stp == NULL)
1526 		return (-1); /* errno is set for us */
1527 
1528 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_TPROBE)
1529 		return (smb_set_errno(shp, ESMB_TYPE));
1530 
1531 	if (stp->smbst_hdr->smbh_len < SMB_TPROBE_MINLEN)
1532 		return (smb_set_errno(shp, ESMB_SHORT));
1533 
1534 	bzero(tprobe, sizeof (*tprobe));
1535 	smb_info_bcopy(stp->smbst_hdr, &tp, sizeof (tp));
1536 	tprobe->smbtp_description = smb_strptr(stp, tp.smbtpr_descr);
1537 	tprobe->smbtp_location = SMB_TPROBE_LOCATION(tp.smbtpr_locstat);
1538 	tprobe->smbtp_status = SMB_TPROBE_STATUS(tp.smbtpr_locstat);
1539 	tprobe->smbtp_maxval = tp.smbtpr_maxval;
1540 	tprobe->smbtp_minval = tp.smbtpr_minval;
1541 	tprobe->smbtp_resolution = tp.smbtpr_resolution;
1542 	tprobe->smbtp_tolerance	= tp.smbtpr_tolerance;
1543 	tprobe->smbtp_accuracy = tp.smbtpr_accuracy;
1544 
1545 	if (stp->smbst_hdr->smbh_len >= SMB_TPROBE_NOMINAL_MINLEN) {
1546 		tprobe->smbtp_nominal = tp.smbtpr_nominal;
1547 	} else {
1548 		tprobe->smbtp_nominal = SMB_PROBE_UNKNOWN_VALUE;
1549 	}
1550 
1551 	return (0);
1552 }
1553 
1554 int
1555 smbios_info_iprobe(smbios_hdl_t *shp, id_t id, smbios_iprobe_t *iprobe)
1556 {
1557 	const smb_struct_t *sip = smb_lookup_id(shp, id);
1558 	smb_iprobe_t ip;
1559 
1560 	if (sip == NULL)
1561 		return (-1); /* errno is set for us */
1562 
1563 	if (sip->smbst_hdr->smbh_type != SMB_TYPE_IPROBE)
1564 		return (smb_set_errno(shp, ESMB_TYPE));
1565 
1566 	if (sip->smbst_hdr->smbh_len < SMB_IPROBE_MINLEN)
1567 		return (smb_set_errno(shp, ESMB_SHORT));
1568 
1569 	bzero(iprobe, sizeof (*iprobe));
1570 	smb_info_bcopy(sip->smbst_hdr, &ip, sizeof (ip));
1571 	iprobe->smbip_description = smb_strptr(sip, ip.smbipr_descr);
1572 	iprobe->smbip_location = SMB_IPROBE_LOCATION(ip.smbipr_locstat);
1573 	iprobe->smbip_status = SMB_IPROBE_STATUS(ip.smbipr_locstat);
1574 	iprobe->smbip_maxval = ip.smbipr_maxval;
1575 	iprobe->smbip_minval = ip.smbipr_minval;
1576 	iprobe->smbip_resolution = ip.smbipr_resolution;
1577 	iprobe->smbip_tolerance	= ip.smbipr_tolerance;
1578 	iprobe->smbip_accuracy = ip.smbipr_accuracy;
1579 
1580 	if (sip->smbst_hdr->smbh_len >= SMB_IPROBE_NOMINAL_MINLEN) {
1581 		iprobe->smbip_nominal = ip.smbipr_nominal;
1582 	} else {
1583 		iprobe->smbip_nominal = SMB_PROBE_UNKNOWN_VALUE;
1584 	}
1585 
1586 	return (0);
1587 }
1588 
1589 int
1590 smbios_info_processor_info(smbios_hdl_t *shp, id_t id,
1591     smbios_processor_info_t *proc)
1592 {
1593 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1594 	smb_processor_info_t pi;
1595 
1596 	if (stp == NULL)
1597 		return (-1); /* errno is set for us */
1598 
1599 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR_INFO)
1600 		return (smb_set_errno(shp, ESMB_TYPE));
1601 
1602 	if (stp->smbst_hdr->smbh_len < sizeof (pi))
1603 		return (smb_set_errno(shp, ESMB_SHORT));
1604 
1605 	bzero(proc, sizeof (*proc));
1606 	smb_info_bcopy(stp->smbst_hdr, &pi, sizeof (pi));
1607 
1608 	if (sizeof (pi) + pi.smbpai_len > stp->smbst_hdr->smbh_len)
1609 		return (smb_set_errno(shp, ESMB_CORRUPT));
1610 
1611 	proc->smbpi_processor = pi.smbpai_proc;
1612 	proc->smbpi_ptype = pi.smbpai_type;
1613 
1614 	return (0);
1615 }
1616 
1617 int
1618 smbios_info_processor_riscv(smbios_hdl_t *shp, id_t id,
1619     smbios_processor_info_riscv_t *riscv)
1620 {
1621 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1622 	const smb_processor_info_t *proc;
1623 	const smb_processor_info_riscv_t *rv;
1624 
1625 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR_INFO) {
1626 		return (smb_set_errno(shp, ESMB_TYPE));
1627 	}
1628 
1629 	if (stp->smbst_hdr->smbh_len < sizeof (*proc)) {
1630 		return (smb_set_errno(shp, ESMB_SHORT));
1631 	}
1632 
1633 	proc = (const smb_processor_info_t *)stp->smbst_hdr;
1634 	if (sizeof (*proc) + proc->smbpai_len > stp->smbst_hdr->smbh_len) {
1635 		return (smb_set_errno(shp, ESMB_CORRUPT));
1636 	}
1637 
1638 	switch (proc->smbpai_type) {
1639 	case SMB_PROCINFO_T_RV32:
1640 	case SMB_PROCINFO_T_RV64:
1641 	case SMB_PROCINFO_T_RV128:
1642 		break;
1643 	default:
1644 		return (smb_set_errno(shp, ESMB_TYPE));
1645 	}
1646 
1647 	if (stp->smbst_hdr->smbh_len < sizeof (*proc) + sizeof (*rv)) {
1648 		return (smb_set_errno(shp, ESMB_SHORT));
1649 	}
1650 	rv = (const smb_processor_info_riscv_t *)&proc->smbpai_data[0];
1651 	if (rv->smbpairv_len != sizeof (*rv)) {
1652 		return (smb_set_errno(shp, ESMB_CORRUPT));
1653 	}
1654 
1655 	bcopy(rv->smbpairv_hartid, riscv->smbpirv_hartid,
1656 	    sizeof (riscv->smbpirv_hartid));
1657 	bcopy(rv->smbpairv_vendid, riscv->smbpirv_vendid,
1658 	    sizeof (riscv->smbpirv_vendid));
1659 	bcopy(rv->smbpairv_archid, riscv->smbpirv_archid,
1660 	    sizeof (riscv->smbpirv_archid));
1661 	bcopy(rv->smbpairv_machid, riscv->smbpirv_machid,
1662 	    sizeof (riscv->smbpirv_machid));
1663 	bcopy(rv->smbpairv_metdi, riscv->smbpirv_metdi,
1664 	    sizeof (riscv->smbpirv_metdi));
1665 	bcopy(rv->smbpairv_mitdi, riscv->smbpirv_mitdi,
1666 	    sizeof (riscv->smbpirv_mitdi));
1667 	riscv->smbpirv_isa = rv->smbpairv_isa;
1668 	riscv->smbpirv_privlvl = rv->smbpairv_privlvl;
1669 	riscv->smbpirv_boothart = rv->smbpairv_boot;
1670 	riscv->smbpirv_xlen = rv->smbpairv_xlen;
1671 	riscv->smbpirv_mxlen = rv->smbpairv_mxlen;
1672 	riscv->smbpirv_sxlen = rv->smbpairv_sxlen;
1673 	riscv->smbpirv_uxlen = rv->smbpairv_uxlen;
1674 
1675 	return (0);
1676 }
1677 
1678 int
1679 smbios_info_pointdev(smbios_hdl_t *shp, id_t id, smbios_pointdev_t *pd)
1680 {
1681 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1682 	smb_pointdev_t point;
1683 
1684 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_POINTDEV) {
1685 		return (smb_set_errno(shp, ESMB_TYPE));
1686 	}
1687 
1688 	if (stp->smbst_hdr->smbh_len < sizeof (point)) {
1689 		return (smb_set_errno(shp, ESMB_SHORT));
1690 	}
1691 
1692 	bzero(pd, sizeof (*pd));
1693 	smb_info_bcopy(stp->smbst_hdr, &point, sizeof (point));
1694 
1695 	pd->smbpd_type = point.smbpdev_type;
1696 	pd->smbpd_iface = point.smbpdev_iface;
1697 	pd->smbpd_nbuttons = point.smbpdev_nbuttons;
1698 
1699 	return (0);
1700 }
1701