xref: /titanic_51/usr/src/common/smbios/smb_info.c (revision 6e16fefe90fa535df0ce167f6836fbfe5fb06738)
184ab085aSmws /*
284ab085aSmws  * CDDL HEADER START
384ab085aSmws  *
484ab085aSmws  * The contents of this file are subject to the terms of the
5c7c09f80SEric Schrock  * Common Development and Distribution License (the "License").
6c7c09f80SEric Schrock  * You may not use this file except in compliance with the License.
784ab085aSmws  *
884ab085aSmws  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
984ab085aSmws  * or http://www.opensolaris.org/os/licensing.
1084ab085aSmws  * See the License for the specific language governing permissions
1184ab085aSmws  * and limitations under the License.
1284ab085aSmws  *
1384ab085aSmws  * When distributing Covered Code, include this CDDL HEADER in each
1484ab085aSmws  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1584ab085aSmws  * If applicable, add the following below this CDDL HEADER, with the
1684ab085aSmws  * fields enclosed by brackets "[]" replaced with your own identifying
1784ab085aSmws  * information: Portions Copyright [yyyy] [name of copyright owner]
1884ab085aSmws  *
1984ab085aSmws  * CDDL HEADER END
2084ab085aSmws  */
2184ab085aSmws 
2284ab085aSmws /*
234e901881SDale Ghent  * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
24*6e16fefeSJohn Levon  * Copyright 2019 Joyent, Inc.
2503f9f63dSTom Pothier  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2684ab085aSmws  * Use is subject to license terms.
2784ab085aSmws  */
2884ab085aSmws 
2984ab085aSmws /*
3084ab085aSmws  * SMBIOS Information Routines
3184ab085aSmws  *
3284ab085aSmws  * The routines in this file are used to convert from the SMBIOS data format to
3384ab085aSmws  * a more reasonable and stable set of structures offered as part of our ABI.
3484ab085aSmws  * These functions take the general form:
3584ab085aSmws  *
3684ab085aSmws  *	stp = smb_lookup_type(shp, foo);
3784ab085aSmws  *	smb_foo_t foo;
3884ab085aSmws  *
3984ab085aSmws  *	smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
4084ab085aSmws  *      bzero(caller's struct);
4184ab085aSmws  *
4284ab085aSmws  *	copy/convert foo members into caller's struct
4384ab085aSmws  *
4484ab085aSmws  * We copy the internal structure on to an automatic variable so as to avoid
4584ab085aSmws  * checks everywhere for structures that the BIOS has improperly truncated, and
4684ab085aSmws  * also to automatically handle the case of a structure that has been extended.
4784ab085aSmws  * When necessary, this code can use smb_gteq() to determine whether the SMBIOS
4884ab085aSmws  * data is of a particular revision that is supposed to contain a new field.
496734c4b0SRobert Mustacchi  *
506734c4b0SRobert Mustacchi  * Note, when trying to bzero the caller's struct you have to be careful about
516734c4b0SRobert Mustacchi  * versions. One can only bzero the initial version that existed in illumos. In
526734c4b0SRobert Mustacchi  * other words, if someone passes an older library handle that doesn't support a
536734c4b0SRobert Mustacchi  * version you cannot assume that their structures have those additional members
546734c4b0SRobert Mustacchi  * in them. Instead, a 'base' version is introduced for such types that have
556734c4b0SRobert Mustacchi  * differences and instead we only bzero out the base version and then handle
566734c4b0SRobert Mustacchi  * the additional members. In general, because all additional members will be
576734c4b0SRobert Mustacchi  * assigned, there's no reason to zero them out unless they are arrays that
586734c4b0SRobert Mustacchi  * won't be entirely filled in.
596734c4b0SRobert Mustacchi  *
606734c4b0SRobert Mustacchi  * Due to history, anything added after the update from version 2.4, in other
616734c4b0SRobert Mustacchi  * words additions from or after '5094 Update libsmbios with recent items'
626734c4b0SRobert Mustacchi  * (4e901881) is currently being used for this. While we don't allow software
636734c4b0SRobert Mustacchi  * compiling against this to get an older form, this was the first major update
646734c4b0SRobert Mustacchi  * and a good starting point for us to enforce this behavior which is useful for
656734c4b0SRobert Mustacchi  * moving forward to making this more public.
6684ab085aSmws  */
6784ab085aSmws 
6884ab085aSmws #include <sys/smbios_impl.h>
6938d76b18SRobert Mustacchi #include <sys/byteorder.h>
70174bc649SRobert Mustacchi #include <sys/debug.h>
7184ab085aSmws 
729c94f155SCheng Sean Ye #ifdef _KERNEL
739c94f155SCheng Sean Ye #include <sys/sunddi.h>
749c94f155SCheng Sean Ye #else
75c7c09f80SEric Schrock #include <fcntl.h>
76c7c09f80SEric Schrock #include <unistd.h>
779c94f155SCheng Sean Ye #include <string.h>
78c7c09f80SEric Schrock #endif
79c7c09f80SEric Schrock 
8084ab085aSmws /*
8184ab085aSmws  * A large number of SMBIOS structures contain a set of common strings used to
8284ab085aSmws  * describe a h/w component's serial number, manufacturer, etc.  These fields
8384ab085aSmws  * helpfully have different names and offsets and sometimes aren't consistent.
8484ab085aSmws  * To simplify life for our clients, we factor these common things out into
8584ab085aSmws  * smbios_info_t, which can be retrieved for any structure.  The following
8684ab085aSmws  * table describes the mapping from a given structure to the smbios_info_t.
87074bb90dSTom Pothier  * Multiple SMBIOS stuctures' contained objects are also handled here.
8884ab085aSmws  */
8984ab085aSmws static const struct smb_infospec {
9084ab085aSmws 	uint8_t is_type;		/* structure type */
9184ab085aSmws 	uint8_t is_manu;		/* manufacturer offset */
9284ab085aSmws 	uint8_t is_product;		/* product name offset */
9384ab085aSmws 	uint8_t is_version;		/* version offset */
9484ab085aSmws 	uint8_t is_serial;		/* serial number offset */
9584ab085aSmws 	uint8_t is_asset;		/* asset tag offset */
9684ab085aSmws 	uint8_t is_location;		/* location string offset */
9784ab085aSmws 	uint8_t is_part;		/* part number offset */
98074bb90dSTom Pothier 	uint8_t is_contc;		/* contained count */
99074bb90dSTom Pothier 	uint8_t is_contsz;		/* contained size */
100074bb90dSTom Pothier 	uint8_t is_contv;		/* contained objects */
10184ab085aSmws } _smb_infospecs[] = {
10284ab085aSmws 	{ SMB_TYPE_SYSTEM,
10384ab085aSmws 		offsetof(smb_system_t, smbsi_manufacturer),
10484ab085aSmws 		offsetof(smb_system_t, smbsi_product),
10584ab085aSmws 		offsetof(smb_system_t, smbsi_version),
10684ab085aSmws 		offsetof(smb_system_t, smbsi_serial),
10784ab085aSmws 		0,
10884ab085aSmws 		0,
109074bb90dSTom Pothier 		0,
110074bb90dSTom Pothier 		0,
111074bb90dSTom Pothier 		0,
11284ab085aSmws 		0 },
11384ab085aSmws 	{ SMB_TYPE_BASEBOARD,
11484ab085aSmws 		offsetof(smb_bboard_t, smbbb_manufacturer),
11584ab085aSmws 		offsetof(smb_bboard_t, smbbb_product),
11684ab085aSmws 		offsetof(smb_bboard_t, smbbb_version),
11784ab085aSmws 		offsetof(smb_bboard_t, smbbb_serial),
11884ab085aSmws 		offsetof(smb_bboard_t, smbbb_asset),
11984ab085aSmws 		offsetof(smb_bboard_t, smbbb_location),
120074bb90dSTom Pothier 		0,
121074bb90dSTom Pothier 		offsetof(smb_bboard_t, smbbb_cn),
122074bb90dSTom Pothier 		SMB_CONT_WORD,
123074bb90dSTom Pothier 		offsetof(smb_bboard_t, smbbb_cv) },
12484ab085aSmws 	{ SMB_TYPE_CHASSIS,
12584ab085aSmws 		offsetof(smb_chassis_t, smbch_manufacturer),
12684ab085aSmws 		0,
12784ab085aSmws 		offsetof(smb_chassis_t, smbch_version),
12884ab085aSmws 		offsetof(smb_chassis_t, smbch_serial),
12984ab085aSmws 		offsetof(smb_chassis_t, smbch_asset),
13084ab085aSmws 		0,
131074bb90dSTom Pothier 		0,
132074bb90dSTom Pothier 		offsetof(smb_chassis_t, smbch_cn),
133074bb90dSTom Pothier 		SMB_CONT_BYTE,
134074bb90dSTom Pothier 		offsetof(smb_chassis_t, smbch_cv) },
13584ab085aSmws 	{ SMB_TYPE_PROCESSOR,
13684ab085aSmws 		offsetof(smb_processor_t, smbpr_manufacturer),
13784ab085aSmws 		0,
13884ab085aSmws 		offsetof(smb_processor_t, smbpr_version),
13984ab085aSmws 		offsetof(smb_processor_t, smbpr_serial),
14084ab085aSmws 		offsetof(smb_processor_t, smbpr_asset),
14184ab085aSmws 		offsetof(smb_processor_t, smbpr_socket),
142074bb90dSTom Pothier 		offsetof(smb_processor_t, smbpr_part),
143074bb90dSTom Pothier 		0,
144074bb90dSTom Pothier 		0,
145074bb90dSTom Pothier 		0 },
14684ab085aSmws 	{ SMB_TYPE_CACHE,
14784ab085aSmws 		0,
14884ab085aSmws 		0,
14984ab085aSmws 		0,
15084ab085aSmws 		0,
15184ab085aSmws 		0,
15284ab085aSmws 		offsetof(smb_cache_t, smbca_socket),
153074bb90dSTom Pothier 		0,
154074bb90dSTom Pothier 		0,
155074bb90dSTom Pothier 		0,
15684ab085aSmws 		0 },
15784ab085aSmws 	{ SMB_TYPE_PORT,
15884ab085aSmws 		0,
15984ab085aSmws 		0,
16084ab085aSmws 		0,
16184ab085aSmws 		0,
16284ab085aSmws 		0,
16384ab085aSmws 		offsetof(smb_port_t, smbpo_iref),
164074bb90dSTom Pothier 		0,
165074bb90dSTom Pothier 		0,
166074bb90dSTom Pothier 		0,
16784ab085aSmws 		0 },
16884ab085aSmws 	{ SMB_TYPE_SLOT,
16984ab085aSmws 		0,
17084ab085aSmws 		0,
17184ab085aSmws 		0,
17284ab085aSmws 		0,
17384ab085aSmws 		0,
17484ab085aSmws 		offsetof(smb_slot_t, smbsl_name),
175074bb90dSTom Pothier 		0,
176074bb90dSTom Pothier 		0,
177074bb90dSTom Pothier 		0,
17884ab085aSmws 		0 },
17984ab085aSmws 	{ SMB_TYPE_MEMDEVICE,
18084ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_manufacturer),
18184ab085aSmws 		0,
18284ab085aSmws 		0,
18384ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_serial),
18484ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_asset),
18584ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_dloc),
186074bb90dSTom Pothier 		offsetof(smb_memdevice_t, smbmdev_part),
187074bb90dSTom Pothier 		0,
188074bb90dSTom Pothier 		0,
189074bb90dSTom Pothier 		0 },
19084ab085aSmws 	{ SMB_TYPE_POWERSUP,
19184ab085aSmws 		offsetof(smb_powersup_t, smbpsup_manufacturer),
19284ab085aSmws 		offsetof(smb_powersup_t, smbpsup_devname),
19384ab085aSmws 		offsetof(smb_powersup_t, smbpsup_rev),
19484ab085aSmws 		offsetof(smb_powersup_t, smbpsup_serial),
19584ab085aSmws 		offsetof(smb_powersup_t, smbpsup_asset),
19684ab085aSmws 		offsetof(smb_powersup_t, smbpsup_loc),
197074bb90dSTom Pothier 		offsetof(smb_powersup_t, smbpsup_part),
198074bb90dSTom Pothier 		0,
199074bb90dSTom Pothier 		0,
200074bb90dSTom Pothier 		0 },
20184ab085aSmws 	{ SMB_TYPE_EOT }
20284ab085aSmws };
20384ab085aSmws 
20484ab085aSmws static const char *
20584ab085aSmws smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n)
20684ab085aSmws {
20784ab085aSmws 	const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr;
20884ab085aSmws 
20984ab085aSmws 	if (off != 0 && sp + off < stp->smbst_end) {
21084ab085aSmws 		(*n)++; /* indicate success for caller */
21184ab085aSmws 		return (smb_strptr(stp, sp[off]));
21284ab085aSmws 	}
21384ab085aSmws 
21484ab085aSmws 	return (smb_strptr(stp, 0));
21584ab085aSmws }
21684ab085aSmws 
21784ab085aSmws static void
21884ab085aSmws smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen)
21984ab085aSmws {
22084ab085aSmws 	if (dstlen > hp->smbh_len) {
22184ab085aSmws 		bcopy(hp, dst, hp->smbh_len);
22284ab085aSmws 		bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len);
22384ab085aSmws 	} else
22484ab085aSmws 		bcopy(hp, dst, dstlen);
22584ab085aSmws }
22684ab085aSmws 
227c325726fSToomas Soome smbios_entry_point_t
22884ab085aSmws smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
22984ab085aSmws {
23084ab085aSmws 	bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
231c325726fSToomas Soome 	return (shp->sh_ent_type);
232c325726fSToomas Soome }
233c325726fSToomas Soome 
234c325726fSToomas Soome void
235c325726fSToomas Soome smbios_info_smbios_version(smbios_hdl_t *shp, smbios_version_t *v)
236c325726fSToomas Soome {
237c325726fSToomas Soome 	v->smbv_major = SMB_MAJOR(shp->sh_smbvers);
238c325726fSToomas Soome 	v->smbv_minor = SMB_MINOR(shp->sh_smbvers);
23984ab085aSmws }
24084ab085aSmws 
241c7c09f80SEric Schrock #ifndef _KERNEL
242c7c09f80SEric Schrock static char smbios_product_override[256];
243c7c09f80SEric Schrock static boolean_t smbios_product_checked;
244c7c09f80SEric Schrock #endif
245c7c09f80SEric Schrock 
24684ab085aSmws int
24784ab085aSmws smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip)
24884ab085aSmws {
24984ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
25084ab085aSmws 	const struct smb_infospec *isp;
25184ab085aSmws 	int n = 0;
25284ab085aSmws 
25384ab085aSmws 	if (stp == NULL)
25484ab085aSmws 		return (-1); /* errno is set for us */
25584ab085aSmws 
25684ab085aSmws 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
25784ab085aSmws 		if (isp->is_type == stp->smbst_hdr->smbh_type)
25884ab085aSmws 			break;
25984ab085aSmws 	}
26084ab085aSmws 
26184ab085aSmws 	ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n);
26284ab085aSmws 	ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n);
26384ab085aSmws 	ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n);
26484ab085aSmws 	ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n);
26584ab085aSmws 	ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n);
26684ab085aSmws 	ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n);
26784ab085aSmws 	ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n);
26884ab085aSmws 
26984ab085aSmws 	/*
270c7c09f80SEric Schrock 	 * This private file allows developers to experiment with reporting
271c7c09f80SEric Schrock 	 * different platform strings from SMBIOS.  It is not a supported
272c7c09f80SEric Schrock 	 * mechanism in the long term, and does not work in the kernel.
273c7c09f80SEric Schrock 	 */
274c7c09f80SEric Schrock #ifndef _KERNEL
275c7c09f80SEric Schrock 	if (isp->is_type == SMB_TYPE_SYSTEM) {
276c7c09f80SEric Schrock 		if (!smbios_product_checked) {
277c7c09f80SEric Schrock 			int fd = open("/etc/smbios_product", O_RDONLY);
278c7c09f80SEric Schrock 			if (fd >= 0) {
279c7c09f80SEric Schrock 				(void) read(fd, smbios_product_override,
280c7c09f80SEric Schrock 				    sizeof (smbios_product_override) - 1);
281c7c09f80SEric Schrock 				(void) close(fd);
282c7c09f80SEric Schrock 			}
283c7c09f80SEric Schrock 			smbios_product_checked = B_TRUE;
284c7c09f80SEric Schrock 		}
285c7c09f80SEric Schrock 
286c7c09f80SEric Schrock 		if (smbios_product_override[0] != '\0')
287c7c09f80SEric Schrock 			ip->smbi_product = smbios_product_override;
288c7c09f80SEric Schrock 	}
289c7c09f80SEric Schrock #endif
290c7c09f80SEric Schrock 
291c7c09f80SEric Schrock 	/*
29284ab085aSmws 	 * If we have a port with an empty internal reference designator string
29384ab085aSmws 	 * try using the external reference designator string instead.
29484ab085aSmws 	 */
29584ab085aSmws 	if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') {
29684ab085aSmws 		ip->smbi_location = smb_info_strptr(stp,
29784ab085aSmws 		    offsetof(smb_port_t, smbpo_eref), &n);
29884ab085aSmws 	}
29984ab085aSmws 
30084ab085aSmws 	return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO));
30184ab085aSmws }
30284ab085aSmws 
303074bb90dSTom Pothier /*
304074bb90dSTom Pothier  * Returns the actual number of contained objects.
305074bb90dSTom Pothier  *
306074bb90dSTom Pothier  * idc - number of contained objects
307074bb90dSTom Pothier  * idv - returned array of contained objects
308074bb90dSTom Pothier  */
309074bb90dSTom Pothier int
310074bb90dSTom Pothier smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv)
311074bb90dSTom Pothier {
312074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
313074bb90dSTom Pothier 	const struct smb_infospec *isp;
314074bb90dSTom Pothier 	id_t *cp;
315074bb90dSTom Pothier 	uint_t size;
316074bb90dSTom Pothier 	uint8_t cnt;
317074bb90dSTom Pothier 	int i, n;
318074bb90dSTom Pothier 
319074bb90dSTom Pothier 	if (stp == NULL) {
320074bb90dSTom Pothier 		return (-1); /* errno is set for us */
321074bb90dSTom Pothier 	}
322074bb90dSTom Pothier 
323074bb90dSTom Pothier 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
324074bb90dSTom Pothier 		if (isp->is_type == stp->smbst_hdr->smbh_type)
325074bb90dSTom Pothier 			break;
326074bb90dSTom Pothier 	}
327074bb90dSTom Pothier 	if (isp->is_type == SMB_TYPE_EOT)
328074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
329074bb90dSTom Pothier 
330074bb90dSTom Pothier 	size = isp->is_contsz;
331074bb90dSTom Pothier 	cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc);
332074bb90dSTom Pothier 	cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv);
333074bb90dSTom Pothier 
334074bb90dSTom Pothier 	n = MIN(cnt, idc);
335074bb90dSTom Pothier 	for (i = 0; i < n; i++) {
336074bb90dSTom Pothier 		if (size == SMB_CONT_WORD)
337074bb90dSTom Pothier 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 2));
338074bb90dSTom Pothier 		else if (size == SMB_CONT_BYTE)
339074bb90dSTom Pothier 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 3));
340074bb90dSTom Pothier 		else
341074bb90dSTom Pothier 			return (smb_set_errno(shp, ESMB_INVAL));
342074bb90dSTom Pothier 	}
343074bb90dSTom Pothier 
344074bb90dSTom Pothier 	return (cnt);
345074bb90dSTom Pothier }
346074bb90dSTom Pothier 
34784ab085aSmws id_t
34884ab085aSmws smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp)
34984ab085aSmws {
35084ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS);
35184ab085aSmws 	const smb_bios_t *bip;
35284ab085aSmws 
35384ab085aSmws 	if (stp == NULL)
35484ab085aSmws 		return (-1); /* errno is set for us */
35584ab085aSmws 
35684ab085aSmws 	if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t))
35784ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
35884ab085aSmws 
35984ab085aSmws 	bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr;
36038d76b18SRobert Mustacchi 	bzero(bp, sizeof (smb_base_bios_t));
36138d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31)) {
36238d76b18SRobert Mustacchi 		bp->smbb_extromsize = 0;
36338d76b18SRobert Mustacchi 	}
36484ab085aSmws 
36584ab085aSmws 	bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor);
36684ab085aSmws 	bp->smbb_version = smb_strptr(stp, bip->smbbi_version);
36784ab085aSmws 	bp->smbb_segment = bip->smbbi_segment;
36884ab085aSmws 	bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate);
36984ab085aSmws 	bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1);
37084ab085aSmws 	bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment);
37184ab085aSmws 	bp->smbb_cflags = bip->smbbi_cflags;
37284ab085aSmws 
37384ab085aSmws 	/*
37484ab085aSmws 	 * If one or more extension bytes are present, reset smbb_xcflags to
37584ab085aSmws 	 * point to them.  Otherwise leave this member set to NULL.
37684ab085aSmws 	 */
37784ab085aSmws 	if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) {
37884ab085aSmws 		bp->smbb_xcflags = bip->smbbi_xcflags;
37984ab085aSmws 		bp->smbb_nxcflags = stp->smbst_hdr->smbh_len -
38084ab085aSmws 		    sizeof (smb_bios_t) + 1;
38184ab085aSmws 
38284ab085aSmws 		if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
38384ab085aSmws 		    smb_gteq(shp, SMB_VERSION_24)) {
38484ab085aSmws 			bp->smbb_biosv.smbv_major =
38584ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ];
38684ab085aSmws 			bp->smbb_biosv.smbv_minor =
38784ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN];
38884ab085aSmws 			bp->smbb_ecfwv.smbv_major =
38984ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ];
39084ab085aSmws 			bp->smbb_ecfwv.smbv_minor =
39184ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN];
39284ab085aSmws 		}
39338d76b18SRobert Mustacchi 
39438d76b18SRobert Mustacchi 		if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 &&
39538d76b18SRobert Mustacchi 		    smb_gteq(shp, SMB_VERSION_31)) {
39638d76b18SRobert Mustacchi 			uint16_t val;
39738d76b18SRobert Mustacchi 			uint64_t rs;
39838d76b18SRobert Mustacchi 
39938d76b18SRobert Mustacchi 			/*
40038d76b18SRobert Mustacchi 			 * Because of the fact that the extended size is a
40138d76b18SRobert Mustacchi 			 * uint16_t and we'd need to define an explicit
40238d76b18SRobert Mustacchi 			 * endian-aware way to access it, we don't include it in
40338d76b18SRobert Mustacchi 			 * the number of extended flags below and thus subtract
40438d76b18SRobert Mustacchi 			 * its size.
40538d76b18SRobert Mustacchi 			 */
40638d76b18SRobert Mustacchi 			bp->smbb_nxcflags -= sizeof (uint16_t);
40738d76b18SRobert Mustacchi 			bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val,
40838d76b18SRobert Mustacchi 			    sizeof (val));
40938d76b18SRobert Mustacchi 			val = LE_16(val);
41038d76b18SRobert Mustacchi 
41138d76b18SRobert Mustacchi 			/*
41238d76b18SRobert Mustacchi 			 * The upper two bits of the extended rom size are used
41338d76b18SRobert Mustacchi 			 * to indicate whether the other 14 bits are in MB or
41438d76b18SRobert Mustacchi 			 * GB.
41538d76b18SRobert Mustacchi 			 */
41638d76b18SRobert Mustacchi 			rs = SMB_BIOS_EXTROM_VALUE_MASK(val);
41738d76b18SRobert Mustacchi 			switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) {
41838d76b18SRobert Mustacchi 			case 0:
41938d76b18SRobert Mustacchi 				rs *= 1024ULL * 1024ULL;
42038d76b18SRobert Mustacchi 				break;
42138d76b18SRobert Mustacchi 			case 1:
42238d76b18SRobert Mustacchi 				rs *= 1024ULL * 1024ULL * 1024ULL;
42338d76b18SRobert Mustacchi 				break;
42438d76b18SRobert Mustacchi 			default:
42538d76b18SRobert Mustacchi 				rs = 0;
42638d76b18SRobert Mustacchi 				break;
42738d76b18SRobert Mustacchi 			}
42838d76b18SRobert Mustacchi 
42938d76b18SRobert Mustacchi 			if (smb_libgteq(shp, SMB_VERSION_31)) {
43038d76b18SRobert Mustacchi 				bp->smbb_extromsize = rs;
43138d76b18SRobert Mustacchi 			}
43238d76b18SRobert Mustacchi 		}
43338d76b18SRobert Mustacchi 	}
43438d76b18SRobert Mustacchi 
43538d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) {
43638d76b18SRobert Mustacchi 		bp->smbb_extromsize = bp->smbb_romsize;
43784ab085aSmws 	}
43884ab085aSmws 
43984ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
44084ab085aSmws }
44184ab085aSmws 
44284ab085aSmws id_t
44384ab085aSmws smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip)
44484ab085aSmws {
44584ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM);
44684ab085aSmws 	smb_system_t si;
44784ab085aSmws 
44884ab085aSmws 	if (stp == NULL)
44984ab085aSmws 		return (-1); /* errno is set for us */
45084ab085aSmws 
45184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si));
45284ab085aSmws 	bzero(sip, sizeof (smbios_system_t));
45384ab085aSmws 
45484ab085aSmws 	sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid;
45584ab085aSmws 	sip->smbs_uuidlen = sizeof (si.smbsi_uuid);
45684ab085aSmws 	sip->smbs_wakeup = si.smbsi_wakeup;
45784ab085aSmws 	sip->smbs_sku = smb_strptr(stp, si.smbsi_sku);
45884ab085aSmws 	sip->smbs_family = smb_strptr(stp, si.smbsi_family);
45984ab085aSmws 
46084ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
46184ab085aSmws }
46284ab085aSmws 
46384ab085aSmws int
46484ab085aSmws smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp)
46584ab085aSmws {
46684ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
46784ab085aSmws 	smb_bboard_t bb;
46884ab085aSmws 
46984ab085aSmws 	if (stp == NULL)
47084ab085aSmws 		return (-1); /* errno is set for us */
47184ab085aSmws 
47284ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD)
47384ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
47484ab085aSmws 
47584ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb));
47684ab085aSmws 	bzero(bbp, sizeof (smbios_bboard_t));
47784ab085aSmws 
47884ab085aSmws 	bbp->smbb_chassis = bb.smbbb_chassis;
47984ab085aSmws 	bbp->smbb_flags = bb.smbbb_flags;
48084ab085aSmws 	bbp->smbb_type = bb.smbbb_type;
481074bb90dSTom Pothier 	bbp->smbb_contn = bb.smbbb_cn;
48284ab085aSmws 
48384ab085aSmws 	return (0);
48484ab085aSmws }
48584ab085aSmws 
48684ab085aSmws int
48784ab085aSmws smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp)
48884ab085aSmws {
48984ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
4904e901881SDale Ghent 	/* Length is measurable by one byte, so it'll be no more than 255. */
4914e901881SDale Ghent 	uint8_t buf[256];
4924e901881SDale Ghent 	smb_chassis_t *ch = (smb_chassis_t *)&buf[0];
49384ab085aSmws 
49484ab085aSmws 	if (stp == NULL)
49584ab085aSmws 		return (-1); /* errno is set for us */
49684ab085aSmws 
49784ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS)
49884ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
49984ab085aSmws 
5004e901881SDale Ghent 	smb_info_bcopy(stp->smbst_hdr, ch, sizeof (buf));
5016734c4b0SRobert Mustacchi 	bzero(chp, sizeof (smb_base_chassis_t));
50238d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
5036734c4b0SRobert Mustacchi 		bzero(chp->smbc_sku, sizeof (chp->smbc_sku));
5046734c4b0SRobert Mustacchi 	}
50584ab085aSmws 
5064e901881SDale Ghent 	chp->smbc_oemdata = ch->smbch_oemdata;
5074e901881SDale Ghent 	chp->smbc_lock = (ch->smbch_type & SMB_CHT_LOCK) != 0;
5084e901881SDale Ghent 	chp->smbc_type = ch->smbch_type & ~SMB_CHT_LOCK;
5094e901881SDale Ghent 	chp->smbc_bustate = ch->smbch_bustate;
5104e901881SDale Ghent 	chp->smbc_psstate = ch->smbch_psstate;
5114e901881SDale Ghent 	chp->smbc_thstate = ch->smbch_thstate;
5124e901881SDale Ghent 	chp->smbc_security = ch->smbch_security;
5134e901881SDale Ghent 	chp->smbc_uheight = ch->smbch_uheight;
5144e901881SDale Ghent 	chp->smbc_cords = ch->smbch_cords;
5154e901881SDale Ghent 	chp->smbc_elems = ch->smbch_cn;
5164e901881SDale Ghent 	chp->smbc_elemlen = ch->smbch_cm;
5174e901881SDale Ghent 
51838d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
5194e901881SDale Ghent 		(void) strlcpy(chp->smbc_sku, SMB_CH_SKU(ch),
5204e901881SDale Ghent 		    sizeof (chp->smbc_sku));
5214e901881SDale Ghent 	}
52284ab085aSmws 
52384ab085aSmws 	return (0);
52484ab085aSmws }
52584ab085aSmws 
52684ab085aSmws int
52784ab085aSmws smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp)
52884ab085aSmws {
52984ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
53084ab085aSmws 	smb_processor_t p;
53184ab085aSmws 
53284ab085aSmws 	if (stp == NULL)
53384ab085aSmws 		return (-1); /* errno is set for us */
53484ab085aSmws 
53584ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR)
53684ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
53784ab085aSmws 
53884ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
5396734c4b0SRobert Mustacchi 	bzero(pp, sizeof (smb_base_processor_t));
54084ab085aSmws 
54184ab085aSmws 	pp->smbp_cpuid = p.smbpr_cpuid;
54284ab085aSmws 	pp->smbp_type = p.smbpr_type;
54384ab085aSmws 	pp->smbp_family = p.smbpr_family;
54484ab085aSmws 	pp->smbp_voltage = p.smbpr_voltage;
54584ab085aSmws 	pp->smbp_maxspeed = p.smbpr_maxspeed;
54684ab085aSmws 	pp->smbp_curspeed = p.smbpr_curspeed;
54784ab085aSmws 	pp->smbp_status = p.smbpr_status;
54884ab085aSmws 	pp->smbp_upgrade = p.smbpr_upgrade;
54984ab085aSmws 	pp->smbp_l1cache = p.smbpr_l1cache;
55084ab085aSmws 	pp->smbp_l2cache = p.smbpr_l2cache;
55184ab085aSmws 	pp->smbp_l3cache = p.smbpr_l3cache;
55284ab085aSmws 
55338d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_25)) {
5544e901881SDale Ghent 		pp->smbp_corecount = p.smbpr_corecount;
5554e901881SDale Ghent 		pp->smbp_coresenabled = p.smbpr_coresenabled;
5564e901881SDale Ghent 		pp->smbp_threadcount = p.smbpr_threadcount;
5574e901881SDale Ghent 		pp->smbp_cflags = p.smbpr_cflags;
5584e901881SDale Ghent 	}
5594e901881SDale Ghent 
56038d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_26)) {
5614e901881SDale Ghent 		pp->smbp_family2 = p.smbpr_family2;
56238d76b18SRobert Mustacchi 	}
5634e901881SDale Ghent 
56438d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_30)) {
5656734c4b0SRobert Mustacchi 		pp->smbp_corecount2 = p.smbpr_corecount2;
5666734c4b0SRobert Mustacchi 		pp->smbp_coresenabled2 = p.smbpr_coresenabled2;
5676734c4b0SRobert Mustacchi 		pp->smbp_threadcount2 = p.smbpr_threadcount2;
5686734c4b0SRobert Mustacchi 	}
5696734c4b0SRobert Mustacchi 
57084ab085aSmws 	return (0);
57184ab085aSmws }
57284ab085aSmws 
57384ab085aSmws int
57484ab085aSmws smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap)
57584ab085aSmws {
57684ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
57784ab085aSmws 	smb_cache_t c;
57884ab085aSmws 
57984ab085aSmws 	if (stp == NULL)
58084ab085aSmws 		return (-1); /* errno is set for us */
58184ab085aSmws 
58284ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE)
58384ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
58484ab085aSmws 
58584ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c));
58638d76b18SRobert Mustacchi 	bzero(cap, sizeof (smb_base_cache_t));
58784ab085aSmws 
58884ab085aSmws 	cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize);
58984ab085aSmws 	cap->smba_size = SMB_CACHE_SIZE(c.smbca_size);
59084ab085aSmws 	cap->smba_stype = c.smbca_stype;
59184ab085aSmws 	cap->smba_ctype = c.smbca_ctype;
59284ab085aSmws 	cap->smba_speed = c.smbca_speed;
59384ab085aSmws 	cap->smba_etype = c.smbca_etype;
59484ab085aSmws 	cap->smba_ltype = c.smbca_ltype;
59584ab085aSmws 	cap->smba_assoc = c.smbca_assoc;
59684ab085aSmws 	cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config);
59784ab085aSmws 	cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config);
59884ab085aSmws 	cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config);
59984ab085aSmws 
60084ab085aSmws 	if (SMB_CACHE_CFG_ENABLED(c.smbca_config))
60184ab085aSmws 		cap->smba_flags |= SMB_CAF_ENABLED;
60284ab085aSmws 
60384ab085aSmws 	if (SMB_CACHE_CFG_SOCKETED(c.smbca_config))
60484ab085aSmws 		cap->smba_flags |= SMB_CAF_SOCKETED;
60584ab085aSmws 
60638d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31)) {
607174bc649SRobert Mustacchi 		cap->smba_maxsize2 = SMB_CACHE_EXT_SIZE(c.smbca_maxsize2);
60838d76b18SRobert Mustacchi 		cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2);
609174bc649SRobert Mustacchi 
610174bc649SRobert Mustacchi 		if (cap->smba_maxsize2 == 0) {
61138d76b18SRobert Mustacchi 			cap->smba_maxsize2 = cap->smba_maxsize;
612174bc649SRobert Mustacchi 		}
613174bc649SRobert Mustacchi 
614174bc649SRobert Mustacchi 		if (cap->smba_size2 == 0) {
61538d76b18SRobert Mustacchi 			cap->smba_size2 = cap->smba_size;
61638d76b18SRobert Mustacchi 		}
61738d76b18SRobert Mustacchi 	}
61838d76b18SRobert Mustacchi 
61984ab085aSmws 	return (0);
62084ab085aSmws }
62184ab085aSmws 
62284ab085aSmws int
62384ab085aSmws smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop)
62484ab085aSmws {
62584ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
62684ab085aSmws 	smb_port_t p;
62784ab085aSmws 
62884ab085aSmws 	if (stp == NULL)
62984ab085aSmws 		return (-1); /* errno is set for us */
63084ab085aSmws 
63184ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT)
63284ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
63384ab085aSmws 
63484ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
63584ab085aSmws 	bzero(pop, sizeof (smbios_port_t));
63684ab085aSmws 
63784ab085aSmws 	pop->smbo_iref = smb_strptr(stp, p.smbpo_iref);
63884ab085aSmws 	pop->smbo_eref = smb_strptr(stp, p.smbpo_eref);
63984ab085aSmws 
64084ab085aSmws 	pop->smbo_itype = p.smbpo_itype;
64184ab085aSmws 	pop->smbo_etype = p.smbpo_etype;
64284ab085aSmws 	pop->smbo_ptype = p.smbpo_ptype;
64384ab085aSmws 
64484ab085aSmws 	return (0);
64584ab085aSmws }
64684ab085aSmws 
64784ab085aSmws int
64884ab085aSmws smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp)
64984ab085aSmws {
65084ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
65184ab085aSmws 	smb_slot_t s;
65284ab085aSmws 
65384ab085aSmws 	if (stp == NULL)
65484ab085aSmws 		return (-1); /* errno is set for us */
65584ab085aSmws 
65684ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
65784ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
65884ab085aSmws 
65984ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
660174bc649SRobert Mustacchi 	bzero(sp, sizeof (smb_base_slot_t));
66184ab085aSmws 
66284ab085aSmws 	sp->smbl_name = smb_strptr(stp, s.smbsl_name);
66384ab085aSmws 	sp->smbl_type = s.smbsl_type;
66484ab085aSmws 	sp->smbl_width = s.smbsl_width;
66584ab085aSmws 	sp->smbl_usage = s.smbsl_usage;
66684ab085aSmws 	sp->smbl_length = s.smbsl_length;
66784ab085aSmws 	sp->smbl_id = s.smbsl_id;
66884ab085aSmws 	sp->smbl_ch1 = s.smbsl_ch1;
66984ab085aSmws 	sp->smbl_ch2 = s.smbsl_ch2;
67003f9f63dSTom Pothier 	sp->smbl_sg = s.smbsl_sg;
67103f9f63dSTom Pothier 	sp->smbl_bus = s.smbsl_bus;
67203f9f63dSTom Pothier 	sp->smbl_df = s.smbsl_df;
67303f9f63dSTom Pothier 
674174bc649SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_32)) {
675174bc649SRobert Mustacchi 		sp->smbl_dbw = s.smbsl_dbw;
676174bc649SRobert Mustacchi 		sp->smbl_npeers = s.smbsl_npeers;
677174bc649SRobert Mustacchi 	}
678174bc649SRobert Mustacchi 
679174bc649SRobert Mustacchi 	return (0);
680174bc649SRobert Mustacchi }
681174bc649SRobert Mustacchi 
682174bc649SRobert Mustacchi void
683174bc649SRobert Mustacchi smbios_info_slot_peers_free(smbios_hdl_t *shp, uint_t npeers,
684174bc649SRobert Mustacchi     smbios_slot_peer_t *peer)
685174bc649SRobert Mustacchi {
686174bc649SRobert Mustacchi 	size_t sz = npeers * sizeof (smbios_slot_peer_t);
687174bc649SRobert Mustacchi 
688174bc649SRobert Mustacchi 	if (npeers == 0) {
689174bc649SRobert Mustacchi 		ASSERT3P(peer, ==, NULL);
690174bc649SRobert Mustacchi 		return;
691174bc649SRobert Mustacchi 	}
692174bc649SRobert Mustacchi 
693174bc649SRobert Mustacchi 	smb_free(peer, sz);
694174bc649SRobert Mustacchi }
695174bc649SRobert Mustacchi 
696174bc649SRobert Mustacchi int
697174bc649SRobert Mustacchi smbios_info_slot_peers(smbios_hdl_t *shp, id_t id, uint_t *npeers,
698174bc649SRobert Mustacchi     smbios_slot_peer_t **peerp)
699174bc649SRobert Mustacchi {
700174bc649SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
701*6e16fefeSJohn Levon 	const smb_slot_t *slotp;
702174bc649SRobert Mustacchi 	smbios_slot_peer_t *peer;
703174bc649SRobert Mustacchi 	size_t minlen;
704174bc649SRobert Mustacchi 	uint_t i;
705174bc649SRobert Mustacchi 
706174bc649SRobert Mustacchi 	if (stp == NULL)
707174bc649SRobert Mustacchi 		return (-1); /* errno is set for us */
708174bc649SRobert Mustacchi 
709*6e16fefeSJohn Levon 	slotp = (const smb_slot_t *)stp->smbst_hdr;
710*6e16fefeSJohn Levon 
711174bc649SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
712174bc649SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
713174bc649SRobert Mustacchi 
714174bc649SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len <= offsetof(smb_slot_t, smbsl_npeers) ||
715174bc649SRobert Mustacchi 	    slotp->smbsl_npeers == 0) {
716174bc649SRobert Mustacchi 		*npeers = 0;
717174bc649SRobert Mustacchi 		*peerp = NULL;
718174bc649SRobert Mustacchi 		return (0);
719174bc649SRobert Mustacchi 	}
720174bc649SRobert Mustacchi 
721174bc649SRobert Mustacchi 	/*
722174bc649SRobert Mustacchi 	 * Make sure that the size of the structure makes sense for the number
723174bc649SRobert Mustacchi 	 * of peers reported.
724174bc649SRobert Mustacchi 	 */
725174bc649SRobert Mustacchi 	minlen = slotp->smbsl_npeers * sizeof (smb_slot_peer_t) +
726174bc649SRobert Mustacchi 	    offsetof(smb_slot_t, smbsl_npeers);
727174bc649SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < minlen) {
728174bc649SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
729174bc649SRobert Mustacchi 	}
730174bc649SRobert Mustacchi 
731174bc649SRobert Mustacchi 	if ((peer = smb_alloc(slotp->smbsl_npeers *
732174bc649SRobert Mustacchi 	    sizeof (smbios_slot_peer_t))) == NULL) {
733174bc649SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_NOMEM));
734174bc649SRobert Mustacchi 	}
735174bc649SRobert Mustacchi 
736174bc649SRobert Mustacchi 	for (i = 0; i < slotp->smbsl_npeers; i++) {
737174bc649SRobert Mustacchi 		peer[i].smblp_group = slotp->smbsl_peers[i].smbspb_group_no;
738174bc649SRobert Mustacchi 		peer[i].smblp_bus = slotp->smbsl_peers[i].smbspb_bus;
739174bc649SRobert Mustacchi 		peer[i].smblp_device = slotp->smbsl_peers[i].smbspb_df >> 3;
740174bc649SRobert Mustacchi 		peer[i].smblp_function = slotp->smbsl_peers[i].smbspb_df & 0x7;
741174bc649SRobert Mustacchi 		peer[i].smblp_data_width = slotp->smbsl_peers[i].smbspb_width;
742174bc649SRobert Mustacchi 	}
743174bc649SRobert Mustacchi 
744174bc649SRobert Mustacchi 	*npeers = slotp->smbsl_npeers;
745174bc649SRobert Mustacchi 	*peerp = peer;
746174bc649SRobert Mustacchi 
74703f9f63dSTom Pothier 	return (0);
74803f9f63dSTom Pothier }
74903f9f63dSTom Pothier 
75003f9f63dSTom Pothier int
75103f9f63dSTom Pothier smbios_info_obdevs_ext(smbios_hdl_t *shp, id_t id, smbios_obdev_ext_t *oep)
75203f9f63dSTom Pothier {
75303f9f63dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
75403f9f63dSTom Pothier 	smb_obdev_ext_t obe;
75503f9f63dSTom Pothier 
75603f9f63dSTom Pothier 	if (stp == NULL)
75703f9f63dSTom Pothier 		return (-1); /* errno is set for us */
75803f9f63dSTom Pothier 
75903f9f63dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVEXT)
76003f9f63dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
76103f9f63dSTom Pothier 
76203f9f63dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &obe, sizeof (obe));
76303f9f63dSTom Pothier 	bzero(oep, sizeof (smbios_obdev_ext_t));
76403f9f63dSTom Pothier 
76503f9f63dSTom Pothier 	oep->smboe_name = smb_strptr(stp, obe.smbobe_name);
76603f9f63dSTom Pothier 	oep->smboe_dtype = obe.smbobe_dtype;
76703f9f63dSTom Pothier 	oep->smboe_dti = obe.smbobe_dti;
76803f9f63dSTom Pothier 	oep->smboe_sg = obe.smbobe_sg;
76903f9f63dSTom Pothier 	oep->smboe_bus = obe.smbobe_bus;
77003f9f63dSTom Pothier 	oep->smboe_df = obe.smbobe_df;
77184ab085aSmws 
77284ab085aSmws 	return (0);
77384ab085aSmws }
77484ab085aSmws 
77584ab085aSmws int
77684ab085aSmws smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp)
77784ab085aSmws {
77884ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
77984ab085aSmws 	const smb_obdev_t *op;
78084ab085aSmws 	int i, m, n;
78184ab085aSmws 
78284ab085aSmws 	if (stp == NULL)
78384ab085aSmws 		return (-1); /* errno is set for us */
78484ab085aSmws 
78584ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS)
78684ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
78784ab085aSmws 
78884ab085aSmws 	op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t));
78984ab085aSmws 	m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op);
79084ab085aSmws 	n = MIN(m, obc);
79184ab085aSmws 
79284ab085aSmws 	for (i = 0; i < n; i++, op++, obp++) {
79384ab085aSmws 		obp->smbd_name = smb_strptr(stp, op->smbob_name);
79484ab085aSmws 		obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED;
79584ab085aSmws 		obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0;
79684ab085aSmws 	}
79784ab085aSmws 
79884ab085aSmws 	return (m);
79984ab085aSmws }
80084ab085aSmws 
80184ab085aSmws /*
80284ab085aSmws  * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the
80384ab085aSmws  * first byte to indicate the size of a string table at the end of the record.
80484ab085aSmws  * Therefore, smbios_info_strtab() can be used to retrieve the table size and
80584ab085aSmws  * strings for any of these underlying record types.
80684ab085aSmws  */
80784ab085aSmws int
80884ab085aSmws smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[])
80984ab085aSmws {
81084ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
81184ab085aSmws 	smb_strtab_t s;
81284ab085aSmws 	int i, n;
81384ab085aSmws 
81484ab085aSmws 	if (stp == NULL)
81584ab085aSmws 		return (-1); /* errno is set for us */
81684ab085aSmws 
81784ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR &&
81884ab085aSmws 	    stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR &&
81984ab085aSmws 	    stp->smbst_hdr->smbh_type != SMB_TYPE_LANG)
82084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
82184ab085aSmws 
82284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
82384ab085aSmws 	n = MIN(s.smbtb_count, argc);
82484ab085aSmws 
82584ab085aSmws 	for (i = 0; i < n; i++)
82684ab085aSmws 		argv[i] = smb_strptr(stp, i + 1);
82784ab085aSmws 
82884ab085aSmws 	return (s.smbtb_count);
82984ab085aSmws }
83084ab085aSmws 
83184ab085aSmws id_t
83284ab085aSmws smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp)
83384ab085aSmws {
83484ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG);
83584ab085aSmws 	smb_lang_t l;
83684ab085aSmws 
83784ab085aSmws 	if (stp == NULL)
83884ab085aSmws 		return (-1); /* errno is set for us */
83984ab085aSmws 
84084ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l));
84184ab085aSmws 	bzero(lp, sizeof (smbios_lang_t));
84284ab085aSmws 
84384ab085aSmws 	lp->smbla_cur = smb_strptr(stp, l.smblang_cur);
84484ab085aSmws 	lp->smbla_fmt = l.smblang_flags & 1;
84584ab085aSmws 	lp->smbla_num = l.smblang_num;
84684ab085aSmws 
84784ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
84884ab085aSmws }
84984ab085aSmws 
85084ab085aSmws id_t
85184ab085aSmws smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp)
85284ab085aSmws {
85384ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG);
85484ab085aSmws 	const smb_sel_t *sel;
85584ab085aSmws 	size_t len;
85684ab085aSmws 
85784ab085aSmws 	if (stp == NULL)
85884ab085aSmws 		return (-1); /* errno is set for us */
85984ab085aSmws 
86084ab085aSmws 	if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t))
86184ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
86284ab085aSmws 
86384ab085aSmws 	sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr;
86484ab085aSmws 	len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t);
86584ab085aSmws 	bzero(evp, sizeof (smbios_evlog_t));
86684ab085aSmws 
86784ab085aSmws 	if (len < sel->smbsel_typec * sel->smbsel_typesz)
86884ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
86984ab085aSmws 
87084ab085aSmws 	evp->smbev_size = sel->smbsel_len;
87184ab085aSmws 	evp->smbev_hdr = sel->smbsel_hdroff;
87284ab085aSmws 	evp->smbev_data = sel->smbsel_dataoff;
87384ab085aSmws 	evp->smbev_method = sel->smbsel_method;
87484ab085aSmws 	evp->smbev_flags = sel->smbsel_status;
87584ab085aSmws 	evp->smbev_format = sel->smbsel_format;
87684ab085aSmws 	evp->smbev_token = sel->smbsel_token;
87784ab085aSmws 	evp->smbev_addr.eva_addr = sel->smbsel_addr;
87884ab085aSmws 
87984ab085aSmws 	if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) {
88084ab085aSmws 		evp->smbev_typec = sel->smbsel_typec;
88184ab085aSmws 		evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev;
88284ab085aSmws 	}
88384ab085aSmws 
88484ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
88584ab085aSmws }
88684ab085aSmws 
88784ab085aSmws int
88884ab085aSmws smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map)
88984ab085aSmws {
89084ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
89184ab085aSmws 	smb_memarray_t m;
89284ab085aSmws 
89384ab085aSmws 	if (stp == NULL)
89484ab085aSmws 		return (-1); /* errno is set for us */
89584ab085aSmws 
89684ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY)
89784ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
89884ab085aSmws 
89984ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
90084ab085aSmws 	bzero(map, sizeof (smbios_memarray_t));
90184ab085aSmws 
90284ab085aSmws 	map->smbma_location = m.smbmarr_loc;
90384ab085aSmws 	map->smbma_use = m.smbmarr_use;
90484ab085aSmws 	map->smbma_ecc = m.smbmarr_ecc;
90584ab085aSmws 	map->smbma_ndevs = m.smbmarr_ndevs;
90684ab085aSmws 	map->smbma_err = m.smbmarr_err;
90784ab085aSmws 
90884ab085aSmws 	if (m.smbmarr_cap != 0x80000000)
90984ab085aSmws 		map->smbma_size = (uint64_t)m.smbmarr_cap * 1024;
9104e901881SDale Ghent 	else if (m.smbmarr_extcap != 0)
9114e901881SDale Ghent 		map->smbma_size = m.smbmarr_extcap;
91284ab085aSmws 	else
91384ab085aSmws 		map->smbma_size = 0; /* unknown */
91484ab085aSmws 
91584ab085aSmws 	return (0);
91684ab085aSmws }
91784ab085aSmws 
91884ab085aSmws int
91984ab085aSmws smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map)
92084ab085aSmws {
92184ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
92284ab085aSmws 	smb_memarrmap_t m;
92384ab085aSmws 
92484ab085aSmws 	if (stp == NULL)
92584ab085aSmws 		return (-1); /* errno is set for us */
92684ab085aSmws 
92784ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP)
92884ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
92984ab085aSmws 
93084ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
93184ab085aSmws 	bzero(map, sizeof (smbios_memarrmap_t));
93284ab085aSmws 
93384ab085aSmws 	map->smbmam_array = m.smbamap_array;
93484ab085aSmws 	map->smbmam_width = m.smbamap_width;
9354e901881SDale Ghent 
9364e901881SDale Ghent 	if (m.smbamap_start != 0xFFFFFFFF && m.smbamap_end != 0xFFFFFFFF) {
93784ab085aSmws 		map->smbmam_addr = (uint64_t)m.smbamap_start * 1024;
93884ab085aSmws 		map->smbmam_size = (uint64_t)
93984ab085aSmws 		    (m.smbamap_end - m.smbamap_start + 1) * 1024;
9404e901881SDale Ghent 	} else if (m.smbamap_extstart != 0 && m.smbamap_extend != 0) {
9414e901881SDale Ghent 		map->smbmam_addr = m.smbamap_extstart;
9424e901881SDale Ghent 		map->smbmam_size = m.smbamap_extend - m.smbamap_extstart + 1;
9434e901881SDale Ghent 	}
94484ab085aSmws 
94584ab085aSmws 	return (0);
94684ab085aSmws }
94784ab085aSmws 
94884ab085aSmws int
94984ab085aSmws smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp)
95084ab085aSmws {
95184ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
95284ab085aSmws 	smb_memdevice_t m;
95384ab085aSmws 
95484ab085aSmws 	if (stp == NULL)
95584ab085aSmws 		return (-1); /* errno is set for us */
95684ab085aSmws 
95784ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE)
95884ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
95984ab085aSmws 
96084ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
9616734c4b0SRobert Mustacchi 	bzero(mdp, sizeof (smb_base_memdevice_t));
96284ab085aSmws 
96384ab085aSmws 	mdp->smbmd_array = m.smbmdev_array;
96484ab085aSmws 	mdp->smbmd_error = m.smbmdev_error;
96584ab085aSmws 	mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth;
96684ab085aSmws 	mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth;
96784ab085aSmws 
9684e901881SDale Ghent 	if (m.smbmdev_size == 0x7FFF) {
9694e901881SDale Ghent 		mdp->smbmd_size = (uint64_t)m.smbmdev_extsize;
9704e901881SDale Ghent 		mdp->smbmd_size *= 1024 * 1024; /* convert MB to bytes */
9714e901881SDale Ghent 	} else if (m.smbmdev_size != 0xFFFF) {
97284ab085aSmws 		mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES);
97384ab085aSmws 		if (m.smbmdev_size & SMB_MDS_KBYTES)
97484ab085aSmws 			mdp->smbmd_size *= 1024;
97584ab085aSmws 		else
97684ab085aSmws 			mdp->smbmd_size *= 1024 * 1024;
97784ab085aSmws 	} else
97884ab085aSmws 		mdp->smbmd_size = -1ULL; /* size unknown */
97984ab085aSmws 
98084ab085aSmws 	mdp->smbmd_form = m.smbmdev_form;
98184ab085aSmws 	mdp->smbmd_set = m.smbmdev_set;
98284ab085aSmws 	mdp->smbmd_type = m.smbmdev_type;
9834e901881SDale Ghent 	mdp->smbmd_speed = m.smbmdev_speed;
98484ab085aSmws 	mdp->smbmd_flags = m.smbmdev_flags;
98584ab085aSmws 	mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc);
98684ab085aSmws 	mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc);
98784ab085aSmws 
98838d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_26)) {
9894e901881SDale Ghent 		mdp->smbmd_rank = m.smbmdev_attrs & 0x0F;
99038d76b18SRobert Mustacchi 	}
9914e901881SDale Ghent 
99238d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
9934e901881SDale Ghent 		mdp->smbmd_clkspeed = m.smbmdev_clkspeed;
99438d76b18SRobert Mustacchi 	}
9954e901881SDale Ghent 
99638d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_28)) {
9974e901881SDale Ghent 		mdp->smbmd_minvolt = m.smbmdev_minvolt;
9984e901881SDale Ghent 		mdp->smbmd_maxvolt = m.smbmdev_maxvolt;
9994e901881SDale Ghent 		mdp->smbmd_confvolt = m.smbmdev_confvolt;
10004e901881SDale Ghent 	}
100184ab085aSmws 
1002174bc649SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_32)) {
1003174bc649SRobert Mustacchi 		mdp->smbmd_memtech = m.smbmdev_memtech;
1004174bc649SRobert Mustacchi 		mdp->smbmd_opcap_flags = m.smbmdev_opmode;
1005174bc649SRobert Mustacchi 		mdp->smbmd_firmware_rev = smb_strptr(stp,
1006174bc649SRobert Mustacchi 		    m.smbmdev_fwver);
1007174bc649SRobert Mustacchi 		mdp->smbmd_modmfg_id = m.smbmdev_modulemfgid;
1008174bc649SRobert Mustacchi 		mdp->smbmd_modprod_id = m.smbmdev_moduleprodid;
1009174bc649SRobert Mustacchi 		mdp->smbmd_cntrlmfg_id = m.smbmdev_memsysmfgid;
1010174bc649SRobert Mustacchi 		mdp->smbmd_cntrlprod_id = m.smbmdev_memsysprodid;
1011174bc649SRobert Mustacchi 		mdp->smbmd_nvsize = m.smbmdev_nvsize;
1012174bc649SRobert Mustacchi 		mdp->smbmd_volatile_size = m.smbmdev_volsize;
1013174bc649SRobert Mustacchi 		mdp->smbmd_cache_size = m.smbmdev_cachesize;
1014174bc649SRobert Mustacchi 		mdp->smbmd_logical_size = m.smbmdev_logicalsize;
1015174bc649SRobert Mustacchi 	}
1016174bc649SRobert Mustacchi 
101784ab085aSmws 	return (0);
101884ab085aSmws }
101984ab085aSmws 
102084ab085aSmws int
102184ab085aSmws smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp)
102284ab085aSmws {
102384ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
102484ab085aSmws 	smb_memdevmap_t m;
102584ab085aSmws 
102684ab085aSmws 	if (stp == NULL)
102784ab085aSmws 		return (-1); /* errno is set for us */
102884ab085aSmws 
102984ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP)
103084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
103184ab085aSmws 
103284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
103384ab085aSmws 	bzero(mdp, sizeof (smbios_memdevmap_t));
103484ab085aSmws 
103584ab085aSmws 	mdp->smbmdm_device = m.smbdmap_device;
103684ab085aSmws 	mdp->smbmdm_arrmap = m.smbdmap_array;
103784ab085aSmws 	mdp->smbmdm_rpos = m.smbdmap_rpos;
103884ab085aSmws 	mdp->smbmdm_ipos = m.smbdmap_ipos;
103984ab085aSmws 	mdp->smbmdm_idepth = m.smbdmap_idepth;
104084ab085aSmws 
10414e901881SDale Ghent 	if (m.smbdmap_start != 0xFFFFFFFF && m.smbdmap_end != 0xFFFFFFFF) {
10424e901881SDale Ghent 		mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024;
10434e901881SDale Ghent 		mdp->smbmdm_size = (uint64_t)
10444e901881SDale Ghent 		    (m.smbdmap_end - m.smbdmap_start + 1) * 1024;
10454e901881SDale Ghent 	} else if (m.smbdmap_extstart != 0 && m.smbdmap_extend != 0) {
10464e901881SDale Ghent 		mdp->smbmdm_addr = m.smbdmap_extstart;
10474e901881SDale Ghent 		mdp->smbmdm_size = m.smbdmap_extend - m.smbdmap_extstart + 1;
10484e901881SDale Ghent 	}
10494e901881SDale Ghent 
105084ab085aSmws 	return (0);
105184ab085aSmws }
105284ab085aSmws 
105384ab085aSmws id_t
105484ab085aSmws smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp)
105584ab085aSmws {
105684ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY);
105784ab085aSmws 	smb_hwsec_t hs;
105884ab085aSmws 
105984ab085aSmws 	if (stp == NULL)
106084ab085aSmws 		return (-1); /* errno is set for us */
106184ab085aSmws 
106284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
106384ab085aSmws 	bzero(hsp, sizeof (smbios_hwsec_t));
106484ab085aSmws 
106584ab085aSmws 	hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
106684ab085aSmws 	hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
106784ab085aSmws 	hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
106884ab085aSmws 	hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
106984ab085aSmws 
107084ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
107184ab085aSmws }
107284ab085aSmws 
107384ab085aSmws id_t
107484ab085aSmws smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
107584ab085aSmws {
107684ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
10770cf7d4e9SJohn Levon 	const smb_boot_t *b;
107884ab085aSmws 
107984ab085aSmws 	if (stp == NULL)
108084ab085aSmws 		return (-1); /* errno is set for us */
108184ab085aSmws 
108284ab085aSmws 	bzero(bp, sizeof (smbios_boot_t));
108384ab085aSmws 
10840cf7d4e9SJohn Levon 	b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
10850cf7d4e9SJohn Levon 
108684ab085aSmws 	bp->smbt_status = b->smbbo_status[0];
108784ab085aSmws 	bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
108884ab085aSmws 	bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
108984ab085aSmws 
109084ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
109184ab085aSmws }
109284ab085aSmws 
109384ab085aSmws id_t
109484ab085aSmws smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
109584ab085aSmws {
109684ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
109784ab085aSmws 	smb_ipmi_t i;
109884ab085aSmws 
109984ab085aSmws 	if (stp == NULL)
110084ab085aSmws 		return (-1); /* errno is set for us */
110184ab085aSmws 
110284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
110384ab085aSmws 	bzero(ip, sizeof (smbios_ipmi_t));
110484ab085aSmws 
110584ab085aSmws 	ip->smbip_type = i.smbipm_type;
110684ab085aSmws 	ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec);
110784ab085aSmws 	ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec);
110884ab085aSmws 	ip->smbip_i2c = i.smbipm_i2c;
110984ab085aSmws 	ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO;
111084ab085aSmws 	ip->smbip_intr = i.smbipm_intr;
111184ab085aSmws 
111284ab085aSmws 	if (i.smbipm_bus != (uint8_t)-1)
111384ab085aSmws 		ip->smbip_bus = i.smbipm_bus;
111484ab085aSmws 	else
111584ab085aSmws 		ip->smbip_bus = -1u;
111684ab085aSmws 
111784ab085aSmws 	if (SMB_IPM_INFO_LSB(i.smbipm_info))
111884ab085aSmws 		ip->smbip_addr |= 1; /* turn on least-significant bit of addr */
111984ab085aSmws 
112084ab085aSmws 	if (i.smbipm_addr & SMB_IPM_ADDR_IO) {
112184ab085aSmws 		switch (SMB_IPM_INFO_REGS(i.smbipm_info)) {
112284ab085aSmws 		case SMB_IPM_REGS_1B:
112384ab085aSmws 			ip->smbip_regspacing = 1;
112484ab085aSmws 			break;
112584ab085aSmws 		case SMB_IPM_REGS_4B:
112684ab085aSmws 			ip->smbip_regspacing = 4;
112784ab085aSmws 			break;
112884ab085aSmws 		case SMB_IPM_REGS_16B:
112984ab085aSmws 			ip->smbip_regspacing = 16;
113084ab085aSmws 			break;
113184ab085aSmws 		default:
113284ab085aSmws 			ip->smbip_regspacing = 1;
113384ab085aSmws 		}
113484ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_IOADDR;
113584ab085aSmws 	}
113684ab085aSmws 
113784ab085aSmws 	if (SMB_IPM_INFO_ISPEC(i.smbipm_info))
113884ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTRSPEC;
113984ab085aSmws 
114084ab085aSmws 	if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI)
114184ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTRHIGH;
114284ab085aSmws 
114384ab085aSmws 	if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE)
114484ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTREDGE;
114584ab085aSmws 
114684ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
114784ab085aSmws }
11489c94f155SCheng Sean Ye 
11499c94f155SCheng Sean Ye static boolean_t
11509c94f155SCheng Sean Ye smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr)
11519c94f155SCheng Sean Ye {
11529c94f155SCheng Sean Ye 	const smb_struct_t *stp = shp->sh_structs;
11539c94f155SCheng Sean Ye 	smb_strtab_t s;
11549c94f155SCheng Sean Ye 	int i, j;
11559c94f155SCheng Sean Ye 
11569c94f155SCheng Sean Ye 	for (i = 0; i < shp->sh_nstructs; i++, stp++) {
11579c94f155SCheng Sean Ye 		if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR)
11589c94f155SCheng Sean Ye 			continue;
11599c94f155SCheng Sean Ye 
11609c94f155SCheng Sean Ye 		smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
11619c94f155SCheng Sean Ye 		for (j = 0; j < s.smbtb_count; j++)
11629c94f155SCheng Sean Ye 			if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0)
11639c94f155SCheng Sean Ye 				return (B_TRUE);
11649c94f155SCheng Sean Ye 	}
11659c94f155SCheng Sean Ye 
11669c94f155SCheng Sean Ye 	return (B_FALSE);
11679c94f155SCheng Sean Ye }
11689c94f155SCheng Sean Ye 
11699c94f155SCheng Sean Ye static const char *
11709c94f155SCheng Sean Ye smb_serial_valid(const char *serial)
11719c94f155SCheng Sean Ye {
11729c94f155SCheng Sean Ye 	char buf[MAXNAMELEN];
11739c94f155SCheng Sean Ye 	int i = 0;
11749c94f155SCheng Sean Ye 
11759c94f155SCheng Sean Ye 	if (serial == NULL)
11769c94f155SCheng Sean Ye 		return (NULL);
11779c94f155SCheng Sean Ye 
11789c94f155SCheng Sean Ye 	(void) strlcpy(buf, serial, sizeof (buf));
11799c94f155SCheng Sean Ye 
11809c94f155SCheng Sean Ye 	while (buf[i] != '\0' && buf[i] == ' ')
11819c94f155SCheng Sean Ye 		i++;
11829c94f155SCheng Sean Ye 
11839c94f155SCheng Sean Ye 	if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL ||
11849c94f155SCheng Sean Ye 	    strstr(buf, SMB_DEFAULT2) != NULL)
11859c94f155SCheng Sean Ye 		return (NULL);
11869c94f155SCheng Sean Ye 
11879c94f155SCheng Sean Ye 	return (serial);
11889c94f155SCheng Sean Ye }
11899c94f155SCheng Sean Ye 
11909c94f155SCheng Sean Ye /*
11919c94f155SCheng Sean Ye  * Get chassis SN or product SN
11929c94f155SCheng Sean Ye  */
11939c94f155SCheng Sean Ye static int
11949c94f155SCheng Sean Ye smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp)
11959c94f155SCheng Sean Ye {
11969c94f155SCheng Sean Ye 	const smb_struct_t *stp;
11979c94f155SCheng Sean Ye 	smbios_info_t s1, s3;
11989c94f155SCheng Sean Ye 
11999c94f155SCheng Sean Ye 	if (psnp == NULL || csnp == NULL)
12009c94f155SCheng Sean Ye 		return (smb_set_errno(shp, ESMB_INVAL));
12019c94f155SCheng Sean Ye 
12029c94f155SCheng Sean Ye 	*psnp = *csnp = NULL;
12039c94f155SCheng Sean Ye 
12049c94f155SCheng Sean Ye 	/*
12059c94f155SCheng Sean Ye 	 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN
12069c94f155SCheng Sean Ye 	 * from type 1 structure, and chassis SN from type 3 structure.
12079c94f155SCheng Sean Ye 	 * Otherwise return SN in type 1 structure as chassis SN.
12089c94f155SCheng Sean Ye 	 */
12099c94f155SCheng Sean Ye 
12109c94f155SCheng Sean Ye 	/* Get type 1 SN */
12119c94f155SCheng Sean Ye 	if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL ||
12129c94f155SCheng Sean Ye 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR)
12139c94f155SCheng Sean Ye 		s1.smbi_serial = NULL;
12149c94f155SCheng Sean Ye 
12159c94f155SCheng Sean Ye 	/* Get type 3 SN */
12169c94f155SCheng Sean Ye 	if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL ||
12179c94f155SCheng Sean Ye 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR)
12189c94f155SCheng Sean Ye 		s3.smbi_serial = NULL;
12199c94f155SCheng Sean Ye 
12209c94f155SCheng Sean Ye 	if (smbios_has_oemstr(shp, SMB_PRMS1)) {
12219c94f155SCheng Sean Ye 		*psnp = smb_serial_valid(s1.smbi_serial);
12229c94f155SCheng Sean Ye 		*csnp = smb_serial_valid(s3.smbi_serial);
12239c94f155SCheng Sean Ye 	} else {
12249c94f155SCheng Sean Ye 		*csnp = smb_serial_valid(s1.smbi_serial);
12259c94f155SCheng Sean Ye 	}
12269c94f155SCheng Sean Ye 
12279c94f155SCheng Sean Ye 	return (0);
12289c94f155SCheng Sean Ye }
12299c94f155SCheng Sean Ye 
12309c94f155SCheng Sean Ye const char *
12319c94f155SCheng Sean Ye smbios_psn(smbios_hdl_t *shp)
12329c94f155SCheng Sean Ye {
12339c94f155SCheng Sean Ye 	const char *psn, *csn;
12349c94f155SCheng Sean Ye 
12359c94f155SCheng Sean Ye 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn);
12369c94f155SCheng Sean Ye }
12379c94f155SCheng Sean Ye 
12389c94f155SCheng Sean Ye const char *
12399c94f155SCheng Sean Ye smbios_csn(smbios_hdl_t *shp)
12409c94f155SCheng Sean Ye {
12419c94f155SCheng Sean Ye 	const char *psn, *csn;
12429c94f155SCheng Sean Ye 
12439c94f155SCheng Sean Ye 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn);
12449c94f155SCheng Sean Ye }
1245074bb90dSTom Pothier 
1246074bb90dSTom Pothier int
1247074bb90dSTom Pothier smbios_info_extprocessor(smbios_hdl_t *shp, id_t id,
1248074bb90dSTom Pothier     smbios_processor_ext_t *epp)
1249074bb90dSTom Pothier {
1250074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1251074bb90dSTom Pothier 	smb_processor_ext_t *exp;
1252074bb90dSTom Pothier 
1253074bb90dSTom Pothier 	if (stp == NULL)
1254074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1255074bb90dSTom Pothier 
1256074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR)
1257074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1258074bb90dSTom Pothier 
1259074bb90dSTom Pothier 	exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr;
1260074bb90dSTom Pothier 	bzero(epp, sizeof (smbios_processor_ext_t));
1261074bb90dSTom Pothier 
1262074bb90dSTom Pothier 	epp->smbpe_processor = exp->smbpre_processor;
1263074bb90dSTom Pothier 	epp->smbpe_fru = exp->smbpre_fru;
1264074bb90dSTom Pothier 	epp->smbpe_n = exp->smbpre_n;
1265074bb90dSTom Pothier 	epp->smbpe_apicid = exp->smbpre_apicid;
1266074bb90dSTom Pothier 
1267074bb90dSTom Pothier 	return (0);
1268074bb90dSTom Pothier }
1269074bb90dSTom Pothier 
1270074bb90dSTom Pothier int
127103f9f63dSTom Pothier smbios_info_extport(smbios_hdl_t *shp, id_t id, smbios_port_ext_t *eportp)
127203f9f63dSTom Pothier {
127303f9f63dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
127403f9f63dSTom Pothier 	smb_port_ext_t *ep;
127503f9f63dSTom Pothier 
127603f9f63dSTom Pothier 	if (stp == NULL)
127703f9f63dSTom Pothier 		return (-1); /* errno is set for us */
127803f9f63dSTom Pothier 
127903f9f63dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PORT)
128003f9f63dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
128103f9f63dSTom Pothier 
128203f9f63dSTom Pothier 	ep = (smb_port_ext_t *)(uintptr_t)stp->smbst_hdr;
128303f9f63dSTom Pothier 	bzero(eportp, sizeof (smbios_port_ext_t));
128403f9f63dSTom Pothier 
128503f9f63dSTom Pothier 	eportp->smbporte_chassis = ep->smbpoe_chassis;
128603f9f63dSTom Pothier 	eportp->smbporte_port = ep->smbpoe_port;
128703f9f63dSTom Pothier 	eportp->smbporte_dtype = ep->smbpoe_dtype;
128803f9f63dSTom Pothier 	eportp->smbporte_devhdl = ep->smbpoe_devhdl;
128903f9f63dSTom Pothier 	eportp->smbporte_phy = ep->smbpoe_phy;
129003f9f63dSTom Pothier 
129103f9f63dSTom Pothier 	return (0);
129203f9f63dSTom Pothier }
129303f9f63dSTom Pothier 
129403f9f63dSTom Pothier int
1295074bb90dSTom Pothier smbios_info_pciexrc(smbios_hdl_t *shp, id_t id,
1296074bb90dSTom Pothier     smbios_pciexrc_t *rcp)
1297074bb90dSTom Pothier {
1298074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1299074bb90dSTom Pothier 	smb_pciexrc_t rc;
1300074bb90dSTom Pothier 
1301074bb90dSTom Pothier 	if (stp == NULL)
1302074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1303074bb90dSTom Pothier 
1304074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC)
1305074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1306074bb90dSTom Pothier 
1307074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc));
1308074bb90dSTom Pothier 	bzero(rcp, sizeof (smbios_pciexrc_t));
1309074bb90dSTom Pothier 
1310074bb90dSTom Pothier 	rcp->smbpcie_bb = rc.smbpciexrc_bboard;
1311074bb90dSTom Pothier 	rcp->smbpcie_bdf = rc.smbpciexrc_bdf;
1312074bb90dSTom Pothier 
1313074bb90dSTom Pothier 	return (0);
1314074bb90dSTom Pothier }
1315074bb90dSTom Pothier 
1316074bb90dSTom Pothier int
1317074bb90dSTom Pothier smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap)
1318074bb90dSTom Pothier {
1319074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1320074bb90dSTom Pothier 	smb_memarray_ext_t exma;
1321074bb90dSTom Pothier 
1322074bb90dSTom Pothier 	if (stp == NULL)
1323074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1324074bb90dSTom Pothier 
1325074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY)
1326074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1327074bb90dSTom Pothier 
1328074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma));
1329074bb90dSTom Pothier 	bzero(emap, sizeof (smbios_memarray_ext_t));
1330074bb90dSTom Pothier 
1331074bb90dSTom Pothier 	emap->smbmae_ma = exma.smbmarre_ma;
1332074bb90dSTom Pothier 	emap->smbmae_comp = exma.smbmarre_component;
1333074bb90dSTom Pothier 	emap->smbmae_bdf = exma.smbmarre_bdf;
1334074bb90dSTom Pothier 
1335074bb90dSTom Pothier 	return (0);
1336074bb90dSTom Pothier }
1337074bb90dSTom Pothier 
1338074bb90dSTom Pothier int
1339074bb90dSTom Pothier smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id,
1340074bb90dSTom Pothier     smbios_memdevice_ext_t *emdp)
1341074bb90dSTom Pothier {
1342074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1343074bb90dSTom Pothier 	smb_memdevice_ext_t exmd;
1344074bb90dSTom Pothier 
1345074bb90dSTom Pothier 	if (stp == NULL)
1346074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1347074bb90dSTom Pothier 
1348074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE)
1349074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1350074bb90dSTom Pothier 
1351074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd));
1352074bb90dSTom Pothier 	bzero(emdp, sizeof (smbios_memdevice_ext_t));
1353074bb90dSTom Pothier 
1354074bb90dSTom Pothier 	emdp->smbmdeve_md = exmd.smbmdeve_mdev;
1355074bb90dSTom Pothier 	emdp->smbmdeve_drch = exmd.smbmdeve_dchan;
1356074bb90dSTom Pothier 	emdp->smbmdeve_ncs  = exmd.smbmdeve_ncs;
1357074bb90dSTom Pothier 	emdp->smbmdeve_cs = exmd.smbmdeve_cs;
1358074bb90dSTom Pothier 
1359074bb90dSTom Pothier 	return (0);
1360074bb90dSTom Pothier }
13612b9d2074SRobert Mustacchi 
13622b9d2074SRobert Mustacchi int
13632b9d2074SRobert Mustacchi smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup)
13642b9d2074SRobert Mustacchi {
13652b9d2074SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
13662b9d2074SRobert Mustacchi 	smb_powersup_t psu;
13672b9d2074SRobert Mustacchi 
13682b9d2074SRobert Mustacchi 	if (stp == NULL)
13692b9d2074SRobert Mustacchi 		return (-1); /* errno is set for us */
13702b9d2074SRobert Mustacchi 
13712b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP)
13722b9d2074SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
13732b9d2074SRobert Mustacchi 
13742b9d2074SRobert Mustacchi 	/* The minimum length required by the spec is 0x10. */
13752b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < 0x10)
13762b9d2074SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
13772b9d2074SRobert Mustacchi 
13782b9d2074SRobert Mustacchi 	bzero(psup, sizeof (*psup));
13792b9d2074SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu));
13802b9d2074SRobert Mustacchi 	psup->smbps_group = psu.smbpsup_group;
13812b9d2074SRobert Mustacchi 	psup->smbps_maxout = psu.smbpsup_max;
13822b9d2074SRobert Mustacchi 
13832b9d2074SRobert Mustacchi 	if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char))
13842b9d2074SRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_HOT;
13852b9d2074SRobert Mustacchi 	if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char))
13862b9d2074SRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_PRESENT;
13872b9d2074SRobert Mustacchi 	if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char))
13882b9d2074SRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG;
13892b9d2074SRobert Mustacchi 
13902b9d2074SRobert Mustacchi 	psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char);
13912b9d2074SRobert Mustacchi 	psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char);
13922b9d2074SRobert Mustacchi 	psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char);
13932b9d2074SRobert Mustacchi 
13942b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x12) {
13952b9d2074SRobert Mustacchi 		psup->smbps_vprobe = psu.smbpsup_vprobe;
13962b9d2074SRobert Mustacchi 	} else {
13972b9d2074SRobert Mustacchi 		psup->smbps_vprobe = 0xffff;
13982b9d2074SRobert Mustacchi 	}
13992b9d2074SRobert Mustacchi 
14002b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x14) {
14012b9d2074SRobert Mustacchi 		psup->smbps_cooldev = psu.smbpsup_cooldev;
14022b9d2074SRobert Mustacchi 	} else {
14032b9d2074SRobert Mustacchi 		psup->smbps_cooldev = 0xffff;
14042b9d2074SRobert Mustacchi 	}
14052b9d2074SRobert Mustacchi 
14062b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x16) {
14072b9d2074SRobert Mustacchi 		psup->smbps_iprobe = psu.smbpsup_iprobe;
14082b9d2074SRobert Mustacchi 	} else {
14092b9d2074SRobert Mustacchi 		psup->smbps_iprobe = 0xffff;
14102b9d2074SRobert Mustacchi 	}
14112b9d2074SRobert Mustacchi 
14122b9d2074SRobert Mustacchi 	return (0);
14132b9d2074SRobert Mustacchi }
141445807aa8SRobert Mustacchi 
141545807aa8SRobert Mustacchi int
141645807aa8SRobert Mustacchi smbios_info_vprobe(smbios_hdl_t *shp, id_t id, smbios_vprobe_t *vprobe)
141745807aa8SRobert Mustacchi {
141845807aa8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
141945807aa8SRobert Mustacchi 	smb_vprobe_t vp;
142045807aa8SRobert Mustacchi 
142145807aa8SRobert Mustacchi 	if (stp == NULL)
142245807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
142345807aa8SRobert Mustacchi 
142445807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_VPROBE)
142545807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
142645807aa8SRobert Mustacchi 
142745807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_VPROBE_MINLEN)
142845807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
142945807aa8SRobert Mustacchi 
143045807aa8SRobert Mustacchi 	bzero(vprobe, sizeof (*vprobe));
143145807aa8SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &vp, sizeof (vp));
143245807aa8SRobert Mustacchi 	vprobe->smbvp_description = smb_strptr(stp, vp.smbvpr_descr);
143345807aa8SRobert Mustacchi 	vprobe->smbvp_location = SMB_VPROBE_LOCATION(vp.smbvpr_locstat);
143445807aa8SRobert Mustacchi 	vprobe->smbvp_status = SMB_VPROBE_STATUS(vp.smbvpr_locstat);
143545807aa8SRobert Mustacchi 	vprobe->smbvp_maxval = vp.smbvpr_maxval;
143645807aa8SRobert Mustacchi 	vprobe->smbvp_minval = vp.smbvpr_minval;
143745807aa8SRobert Mustacchi 	vprobe->smbvp_resolution = vp.smbvpr_resolution;
143845807aa8SRobert Mustacchi 	vprobe->smbvp_tolerance	= vp.smbvpr_tolerance;
143945807aa8SRobert Mustacchi 	vprobe->smbvp_accuracy = vp.smbvpr_accuracy;
144045807aa8SRobert Mustacchi 
144145807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_VPROBE_NOMINAL_MINLEN) {
144245807aa8SRobert Mustacchi 		vprobe->smbvp_nominal = vp.smbvpr_nominal;
144345807aa8SRobert Mustacchi 	} else {
144445807aa8SRobert Mustacchi 		vprobe->smbvp_nominal = SMB_PROBE_UNKNOWN_VALUE;
144545807aa8SRobert Mustacchi 	}
144645807aa8SRobert Mustacchi 
144745807aa8SRobert Mustacchi 	return (0);
144845807aa8SRobert Mustacchi }
144945807aa8SRobert Mustacchi 
145045807aa8SRobert Mustacchi int
145145807aa8SRobert Mustacchi smbios_info_cooldev(smbios_hdl_t *shp, id_t id, smbios_cooldev_t *cooldev)
145245807aa8SRobert Mustacchi {
145345807aa8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
145445807aa8SRobert Mustacchi 	smb_cooldev_t cd;
145545807aa8SRobert Mustacchi 
145645807aa8SRobert Mustacchi 	if (stp == NULL)
145745807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
145845807aa8SRobert Mustacchi 
145945807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_COOLDEV)
146045807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
146145807aa8SRobert Mustacchi 
146245807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_COOLDEV_MINLEN)
146345807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
146445807aa8SRobert Mustacchi 
146545807aa8SRobert Mustacchi 	bzero(cooldev, sizeof (*cooldev));
146645807aa8SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &cd, sizeof (cd));
146745807aa8SRobert Mustacchi 	cooldev->smbcd_tprobe = cd.smbcdev_tprobe;
146845807aa8SRobert Mustacchi 	cooldev->smbcd_type = SMB_COOLDEV_TYPE(cd.smbcdev_typstat);
146945807aa8SRobert Mustacchi 	cooldev->smbcd_status = SMB_COOLDEV_STATUS(cd.smbcdev_typstat);
147045807aa8SRobert Mustacchi 	cooldev->smbcd_group = cd.smbcdev_group;
147145807aa8SRobert Mustacchi 	cooldev->smbcd_oem = cd.smbcdev_oem;
147245807aa8SRobert Mustacchi 
147345807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_COOLDEV_NOMINAL_MINLEN) {
147445807aa8SRobert Mustacchi 		cooldev->smbcd_nominal = cd.smbcdev_nominal;
147545807aa8SRobert Mustacchi 	} else {
147645807aa8SRobert Mustacchi 		cooldev->smbcd_nominal = SMB_PROBE_UNKNOWN_VALUE;
147745807aa8SRobert Mustacchi 	}
147845807aa8SRobert Mustacchi 
147945807aa8SRobert Mustacchi 	/*
148045807aa8SRobert Mustacchi 	 * The description field was added in SMBIOS version 2.7. The
148145807aa8SRobert Mustacchi 	 * SMB_TYPE_COOLDEV support was only added after all of the 2.7+ fields
148245807aa8SRobert Mustacchi 	 * were added in the spec. So while a user may request an older version,
148345807aa8SRobert Mustacchi 	 * we don't have to worry about old structures and just simply skip it
148445807aa8SRobert Mustacchi 	 * if they're not asking for it.
148545807aa8SRobert Mustacchi 	 */
148645807aa8SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27) &&
148745807aa8SRobert Mustacchi 	    smb_gteq(shp, SMB_VERSION_27) &&
148845807aa8SRobert Mustacchi 	    stp->smbst_hdr->smbh_len >= SMB_COOLDEV_DESCR_MINLEN) {
148945807aa8SRobert Mustacchi 		cooldev->smbcd_descr = smb_strptr(stp, cd.smbcdev_descr);
149045807aa8SRobert Mustacchi 	} else {
149145807aa8SRobert Mustacchi 		cooldev->smbcd_descr = NULL;
149245807aa8SRobert Mustacchi 	}
149345807aa8SRobert Mustacchi 
149445807aa8SRobert Mustacchi 	return (0);
149545807aa8SRobert Mustacchi }
149645807aa8SRobert Mustacchi 
149745807aa8SRobert Mustacchi int
149845807aa8SRobert Mustacchi smbios_info_tprobe(smbios_hdl_t *shp, id_t id, smbios_tprobe_t *tprobe)
149945807aa8SRobert Mustacchi {
150045807aa8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
150145807aa8SRobert Mustacchi 	smb_tprobe_t tp;
150245807aa8SRobert Mustacchi 
150345807aa8SRobert Mustacchi 	if (stp == NULL)
150445807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
150545807aa8SRobert Mustacchi 
150645807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_TPROBE)
150745807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
150845807aa8SRobert Mustacchi 
150945807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_TPROBE_MINLEN)
151045807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
151145807aa8SRobert Mustacchi 
151245807aa8SRobert Mustacchi 	bzero(tprobe, sizeof (*tprobe));
151345807aa8SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &tp, sizeof (tp));
151445807aa8SRobert Mustacchi 	tprobe->smbtp_description = smb_strptr(stp, tp.smbtpr_descr);
151545807aa8SRobert Mustacchi 	tprobe->smbtp_location = SMB_TPROBE_LOCATION(tp.smbtpr_locstat);
151645807aa8SRobert Mustacchi 	tprobe->smbtp_status = SMB_TPROBE_STATUS(tp.smbtpr_locstat);
151745807aa8SRobert Mustacchi 	tprobe->smbtp_maxval = tp.smbtpr_maxval;
151845807aa8SRobert Mustacchi 	tprobe->smbtp_minval = tp.smbtpr_minval;
151945807aa8SRobert Mustacchi 	tprobe->smbtp_resolution = tp.smbtpr_resolution;
152045807aa8SRobert Mustacchi 	tprobe->smbtp_tolerance	= tp.smbtpr_tolerance;
152145807aa8SRobert Mustacchi 	tprobe->smbtp_accuracy = tp.smbtpr_accuracy;
152245807aa8SRobert Mustacchi 
152345807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_TPROBE_NOMINAL_MINLEN) {
152445807aa8SRobert Mustacchi 		tprobe->smbtp_nominal = tp.smbtpr_nominal;
152545807aa8SRobert Mustacchi 	} else {
152645807aa8SRobert Mustacchi 		tprobe->smbtp_nominal = SMB_PROBE_UNKNOWN_VALUE;
152745807aa8SRobert Mustacchi 	}
152845807aa8SRobert Mustacchi 
152945807aa8SRobert Mustacchi 	return (0);
153045807aa8SRobert Mustacchi }
153145807aa8SRobert Mustacchi 
153245807aa8SRobert Mustacchi int
153345807aa8SRobert Mustacchi smbios_info_iprobe(smbios_hdl_t *shp, id_t id, smbios_iprobe_t *iprobe)
153445807aa8SRobert Mustacchi {
153545807aa8SRobert Mustacchi 	const smb_struct_t *sip = smb_lookup_id(shp, id);
153645807aa8SRobert Mustacchi 	smb_iprobe_t ip;
153745807aa8SRobert Mustacchi 
153845807aa8SRobert Mustacchi 	if (sip == NULL)
153945807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
154045807aa8SRobert Mustacchi 
154145807aa8SRobert Mustacchi 	if (sip->smbst_hdr->smbh_type != SMB_TYPE_IPROBE)
154245807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
154345807aa8SRobert Mustacchi 
154445807aa8SRobert Mustacchi 	if (sip->smbst_hdr->smbh_len < SMB_IPROBE_MINLEN)
154545807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
154645807aa8SRobert Mustacchi 
154745807aa8SRobert Mustacchi 	bzero(iprobe, sizeof (*iprobe));
154845807aa8SRobert Mustacchi 	smb_info_bcopy(sip->smbst_hdr, &ip, sizeof (ip));
154945807aa8SRobert Mustacchi 	iprobe->smbip_description = smb_strptr(sip, ip.smbipr_descr);
155045807aa8SRobert Mustacchi 	iprobe->smbip_location = SMB_IPROBE_LOCATION(ip.smbipr_locstat);
155145807aa8SRobert Mustacchi 	iprobe->smbip_status = SMB_IPROBE_STATUS(ip.smbipr_locstat);
155245807aa8SRobert Mustacchi 	iprobe->smbip_maxval = ip.smbipr_maxval;
155345807aa8SRobert Mustacchi 	iprobe->smbip_minval = ip.smbipr_minval;
155445807aa8SRobert Mustacchi 	iprobe->smbip_resolution = ip.smbipr_resolution;
155545807aa8SRobert Mustacchi 	iprobe->smbip_tolerance	= ip.smbipr_tolerance;
155645807aa8SRobert Mustacchi 	iprobe->smbip_accuracy = ip.smbipr_accuracy;
155745807aa8SRobert Mustacchi 
155845807aa8SRobert Mustacchi 	if (sip->smbst_hdr->smbh_len >= SMB_IPROBE_NOMINAL_MINLEN) {
155945807aa8SRobert Mustacchi 		iprobe->smbip_nominal = ip.smbipr_nominal;
156045807aa8SRobert Mustacchi 	} else {
156145807aa8SRobert Mustacchi 		iprobe->smbip_nominal = SMB_PROBE_UNKNOWN_VALUE;
156245807aa8SRobert Mustacchi 	}
156345807aa8SRobert Mustacchi 
156445807aa8SRobert Mustacchi 	return (0);
156545807aa8SRobert Mustacchi }
1566