xref: /titanic_44/usr/src/common/smbios/smb_info.c (revision 4489a8ab33d57b8357b3fcacead1c05e408759c5)
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*4489a8abSJohn 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.
4904cdb0e3SRobert Mustacchi  *
5004cdb0e3SRobert Mustacchi  * Note, when trying to bzero the caller's struct you have to be careful about
5104cdb0e3SRobert Mustacchi  * versions. One can only bzero the initial version that existed in illumos. In
5204cdb0e3SRobert Mustacchi  * other words, if someone passes an older library handle that doesn't support a
5304cdb0e3SRobert Mustacchi  * version you cannot assume that their structures have those additional members
5404cdb0e3SRobert Mustacchi  * in them. Instead, a 'base' version is introduced for such types that have
5504cdb0e3SRobert Mustacchi  * differences and instead we only bzero out the base version and then handle
5604cdb0e3SRobert Mustacchi  * the additional members. In general, because all additional members will be
5704cdb0e3SRobert Mustacchi  * assigned, there's no reason to zero them out unless they are arrays that
5804cdb0e3SRobert Mustacchi  * won't be entirely filled in.
5904cdb0e3SRobert Mustacchi  *
6004cdb0e3SRobert Mustacchi  * Due to history, anything added after the update from version 2.4, in other
6104cdb0e3SRobert Mustacchi  * words additions from or after '5094 Update libsmbios with recent items'
6204cdb0e3SRobert Mustacchi  * (4e901881) is currently being used for this. While we don't allow software
6304cdb0e3SRobert Mustacchi  * compiling against this to get an older form, this was the first major update
6404cdb0e3SRobert Mustacchi  * and a good starting point for us to enforce this behavior which is useful for
6504cdb0e3SRobert Mustacchi  * moving forward to making this more public.
6684ab085aSmws  */
6784ab085aSmws 
6884ab085aSmws #include <sys/smbios_impl.h>
691eb9e3eaSRobert Mustacchi #include <sys/byteorder.h>
70a60349c8SRobert 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 *
smb_info_strptr(const smb_struct_t * stp,uint8_t off,int * n)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
smb_info_bcopy(const smb_header_t * hp,void * dst,size_t dstlen)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 
227af349cd6SToomas Soome smbios_entry_point_t
smbios_info_smbios(smbios_hdl_t * shp,smbios_entry_t * ep)22884ab085aSmws smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
22984ab085aSmws {
23084ab085aSmws 	bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
231af349cd6SToomas Soome 	return (shp->sh_ent_type);
232af349cd6SToomas Soome }
233af349cd6SToomas Soome 
234af349cd6SToomas Soome void
smbios_info_smbios_version(smbios_hdl_t * shp,smbios_version_t * v)235af349cd6SToomas Soome smbios_info_smbios_version(smbios_hdl_t *shp, smbios_version_t *v)
236af349cd6SToomas Soome {
237af349cd6SToomas Soome 	v->smbv_major = SMB_MAJOR(shp->sh_smbvers);
238af349cd6SToomas 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
smbios_info_common(smbios_hdl_t * shp,id_t id,smbios_info_t * ip)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
smbios_info_contains(smbios_hdl_t * shp,id_t id,uint_t idc,id_t * idv)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
smbios_info_bios(smbios_hdl_t * shp,smbios_bios_t * bp)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;
3601eb9e3eaSRobert Mustacchi 	bzero(bp, sizeof (smb_base_bios_t));
3611eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31)) {
3621eb9e3eaSRobert Mustacchi 		bp->smbb_extromsize = 0;
3631eb9e3eaSRobert 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 		}
3931eb9e3eaSRobert Mustacchi 
3941eb9e3eaSRobert Mustacchi 		if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 &&
3951eb9e3eaSRobert Mustacchi 		    smb_gteq(shp, SMB_VERSION_31)) {
3961eb9e3eaSRobert Mustacchi 			uint16_t val;
3971eb9e3eaSRobert Mustacchi 			uint64_t rs;
3981eb9e3eaSRobert Mustacchi 
3991eb9e3eaSRobert Mustacchi 			/*
4001eb9e3eaSRobert Mustacchi 			 * Because of the fact that the extended size is a
4011eb9e3eaSRobert Mustacchi 			 * uint16_t and we'd need to define an explicit
4021eb9e3eaSRobert Mustacchi 			 * endian-aware way to access it, we don't include it in
4031eb9e3eaSRobert Mustacchi 			 * the number of extended flags below and thus subtract
4041eb9e3eaSRobert Mustacchi 			 * its size.
4051eb9e3eaSRobert Mustacchi 			 */
4061eb9e3eaSRobert Mustacchi 			bp->smbb_nxcflags -= sizeof (uint16_t);
4071eb9e3eaSRobert Mustacchi 			bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val,
4081eb9e3eaSRobert Mustacchi 			    sizeof (val));
4091eb9e3eaSRobert Mustacchi 			val = LE_16(val);
4101eb9e3eaSRobert Mustacchi 
4111eb9e3eaSRobert Mustacchi 			/*
4121eb9e3eaSRobert Mustacchi 			 * The upper two bits of the extended rom size are used
4131eb9e3eaSRobert Mustacchi 			 * to indicate whether the other 14 bits are in MB or
4141eb9e3eaSRobert Mustacchi 			 * GB.
4151eb9e3eaSRobert Mustacchi 			 */
4161eb9e3eaSRobert Mustacchi 			rs = SMB_BIOS_EXTROM_VALUE_MASK(val);
4171eb9e3eaSRobert Mustacchi 			switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) {
4181eb9e3eaSRobert Mustacchi 			case 0:
4191eb9e3eaSRobert Mustacchi 				rs *= 1024ULL * 1024ULL;
4201eb9e3eaSRobert Mustacchi 				break;
4211eb9e3eaSRobert Mustacchi 			case 1:
4221eb9e3eaSRobert Mustacchi 				rs *= 1024ULL * 1024ULL * 1024ULL;
4231eb9e3eaSRobert Mustacchi 				break;
4241eb9e3eaSRobert Mustacchi 			default:
4251eb9e3eaSRobert Mustacchi 				rs = 0;
4261eb9e3eaSRobert Mustacchi 				break;
4271eb9e3eaSRobert Mustacchi 			}
4281eb9e3eaSRobert Mustacchi 
4291eb9e3eaSRobert Mustacchi 			if (smb_libgteq(shp, SMB_VERSION_31)) {
4301eb9e3eaSRobert Mustacchi 				bp->smbb_extromsize = rs;
4311eb9e3eaSRobert Mustacchi 			}
4321eb9e3eaSRobert Mustacchi 		}
4331eb9e3eaSRobert Mustacchi 	}
4341eb9e3eaSRobert Mustacchi 
4351eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) {
4361eb9e3eaSRobert Mustacchi 		bp->smbb_extromsize = bp->smbb_romsize;
43784ab085aSmws 	}
43884ab085aSmws 
43984ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
44084ab085aSmws }
44184ab085aSmws 
44284ab085aSmws id_t
smbios_info_system(smbios_hdl_t * shp,smbios_system_t * sip)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
smbios_info_bboard(smbios_hdl_t * shp,id_t id,smbios_bboard_t * bbp)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
smbios_info_chassis(smbios_hdl_t * shp,id_t id,smbios_chassis_t * chp)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));
50104cdb0e3SRobert Mustacchi 	bzero(chp, sizeof (smb_base_chassis_t));
5021eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
50304cdb0e3SRobert Mustacchi 		bzero(chp->smbc_sku, sizeof (chp->smbc_sku));
50404cdb0e3SRobert 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 
5181eb9e3eaSRobert 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
smbios_info_processor(smbios_hdl_t * shp,id_t id,smbios_processor_t * pp)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));
53904cdb0e3SRobert 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 
5531eb9e3eaSRobert 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 
5601eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_26)) {
5614e901881SDale Ghent 		pp->smbp_family2 = p.smbpr_family2;
5621eb9e3eaSRobert Mustacchi 	}
5634e901881SDale Ghent 
5641eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_30)) {
56504cdb0e3SRobert Mustacchi 		pp->smbp_corecount2 = p.smbpr_corecount2;
56604cdb0e3SRobert Mustacchi 		pp->smbp_coresenabled2 = p.smbpr_coresenabled2;
56704cdb0e3SRobert Mustacchi 		pp->smbp_threadcount2 = p.smbpr_threadcount2;
56804cdb0e3SRobert Mustacchi 	}
56904cdb0e3SRobert Mustacchi 
57084ab085aSmws 	return (0);
57184ab085aSmws }
57284ab085aSmws 
57384ab085aSmws int
smbios_info_cache(smbios_hdl_t * shp,id_t id,smbios_cache_t * cap)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));
5861eb9e3eaSRobert 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 
6061eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31)) {
607a60349c8SRobert Mustacchi 		cap->smba_maxsize2 = SMB_CACHE_EXT_SIZE(c.smbca_maxsize2);
6081eb9e3eaSRobert Mustacchi 		cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2);
609a60349c8SRobert Mustacchi 
610a60349c8SRobert Mustacchi 		if (cap->smba_maxsize2 == 0) {
6111eb9e3eaSRobert Mustacchi 			cap->smba_maxsize2 = cap->smba_maxsize;
612a60349c8SRobert Mustacchi 		}
613a60349c8SRobert Mustacchi 
614a60349c8SRobert Mustacchi 		if (cap->smba_size2 == 0) {
6151eb9e3eaSRobert Mustacchi 			cap->smba_size2 = cap->smba_size;
6161eb9e3eaSRobert Mustacchi 		}
6171eb9e3eaSRobert Mustacchi 	}
6181eb9e3eaSRobert Mustacchi 
61984ab085aSmws 	return (0);
62084ab085aSmws }
62184ab085aSmws 
62284ab085aSmws int
smbios_info_port(smbios_hdl_t * shp,id_t id,smbios_port_t * pop)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
smbios_info_slot(smbios_hdl_t * shp,id_t id,smbios_slot_t * sp)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));
660a60349c8SRobert 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 
674a60349c8SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_32)) {
675a60349c8SRobert Mustacchi 		sp->smbl_dbw = s.smbsl_dbw;
676a60349c8SRobert Mustacchi 		sp->smbl_npeers = s.smbsl_npeers;
677a60349c8SRobert Mustacchi 	}
678a60349c8SRobert Mustacchi 
679a60349c8SRobert Mustacchi 	return (0);
680a60349c8SRobert Mustacchi }
681a60349c8SRobert Mustacchi 
682a60349c8SRobert Mustacchi void
smbios_info_slot_peers_free(smbios_hdl_t * shp,uint_t npeers,smbios_slot_peer_t * peer)683a60349c8SRobert Mustacchi smbios_info_slot_peers_free(smbios_hdl_t *shp, uint_t npeers,
684a60349c8SRobert Mustacchi     smbios_slot_peer_t *peer)
685a60349c8SRobert Mustacchi {
686a60349c8SRobert Mustacchi 	size_t sz = npeers * sizeof (smbios_slot_peer_t);
687a60349c8SRobert Mustacchi 
688a60349c8SRobert Mustacchi 	if (npeers == 0) {
689a60349c8SRobert Mustacchi 		ASSERT3P(peer, ==, NULL);
690a60349c8SRobert Mustacchi 		return;
691a60349c8SRobert Mustacchi 	}
692a60349c8SRobert Mustacchi 
693a60349c8SRobert Mustacchi 	smb_free(peer, sz);
694a60349c8SRobert Mustacchi }
695a60349c8SRobert Mustacchi 
696a60349c8SRobert Mustacchi int
smbios_info_slot_peers(smbios_hdl_t * shp,id_t id,uint_t * npeers,smbios_slot_peer_t ** peerp)697a60349c8SRobert Mustacchi smbios_info_slot_peers(smbios_hdl_t *shp, id_t id, uint_t *npeers,
698a60349c8SRobert Mustacchi     smbios_slot_peer_t **peerp)
699a60349c8SRobert Mustacchi {
700a60349c8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
701*4489a8abSJohn Levon 	const smb_slot_t *slotp;
702a60349c8SRobert Mustacchi 	smbios_slot_peer_t *peer;
703a60349c8SRobert Mustacchi 	size_t minlen;
704a60349c8SRobert Mustacchi 	uint_t i;
705a60349c8SRobert Mustacchi 
706a60349c8SRobert Mustacchi 	if (stp == NULL)
707a60349c8SRobert Mustacchi 		return (-1); /* errno is set for us */
708a60349c8SRobert Mustacchi 
709*4489a8abSJohn Levon 	slotp = (const smb_slot_t *)stp->smbst_hdr;
710*4489a8abSJohn Levon 
711a60349c8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
712a60349c8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
713a60349c8SRobert Mustacchi 
714a60349c8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len <= offsetof(smb_slot_t, smbsl_npeers) ||
715a60349c8SRobert Mustacchi 	    slotp->smbsl_npeers == 0) {
716a60349c8SRobert Mustacchi 		*npeers = 0;
717a60349c8SRobert Mustacchi 		*peerp = NULL;
718a60349c8SRobert Mustacchi 		return (0);
719a60349c8SRobert Mustacchi 	}
720a60349c8SRobert Mustacchi 
721a60349c8SRobert Mustacchi 	/*
722a60349c8SRobert Mustacchi 	 * Make sure that the size of the structure makes sense for the number
723a60349c8SRobert Mustacchi 	 * of peers reported.
724a60349c8SRobert Mustacchi 	 */
725a60349c8SRobert Mustacchi 	minlen = slotp->smbsl_npeers * sizeof (smb_slot_peer_t) +
726a60349c8SRobert Mustacchi 	    offsetof(smb_slot_t, smbsl_npeers);
727a60349c8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < minlen) {
728a60349c8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
729a60349c8SRobert Mustacchi 	}
730a60349c8SRobert Mustacchi 
731a60349c8SRobert Mustacchi 	if ((peer = smb_alloc(slotp->smbsl_npeers *
732a60349c8SRobert Mustacchi 	    sizeof (smbios_slot_peer_t))) == NULL) {
733a60349c8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_NOMEM));
734a60349c8SRobert Mustacchi 	}
735a60349c8SRobert Mustacchi 
736a60349c8SRobert Mustacchi 	for (i = 0; i < slotp->smbsl_npeers; i++) {
737a60349c8SRobert Mustacchi 		peer[i].smblp_group = slotp->smbsl_peers[i].smbspb_group_no;
738a60349c8SRobert Mustacchi 		peer[i].smblp_bus = slotp->smbsl_peers[i].smbspb_bus;
739a60349c8SRobert Mustacchi 		peer[i].smblp_device = slotp->smbsl_peers[i].smbspb_df >> 3;
740a60349c8SRobert Mustacchi 		peer[i].smblp_function = slotp->smbsl_peers[i].smbspb_df & 0x7;
741a60349c8SRobert Mustacchi 		peer[i].smblp_data_width = slotp->smbsl_peers[i].smbspb_width;
742a60349c8SRobert Mustacchi 	}
743a60349c8SRobert Mustacchi 
744a60349c8SRobert Mustacchi 	*npeers = slotp->smbsl_npeers;
745a60349c8SRobert Mustacchi 	*peerp = peer;
746a60349c8SRobert Mustacchi 
74703f9f63dSTom Pothier 	return (0);
74803f9f63dSTom Pothier }
74903f9f63dSTom Pothier 
75003f9f63dSTom Pothier int
smbios_info_obdevs_ext(smbios_hdl_t * shp,id_t id,smbios_obdev_ext_t * oep)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
smbios_info_obdevs(smbios_hdl_t * shp,id_t id,int obc,smbios_obdev_t * obp)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
smbios_info_strtab(smbios_hdl_t * shp,id_t id,int argc,const char * argv[])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
smbios_info_lang(smbios_hdl_t * shp,smbios_lang_t * lp)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
smbios_info_eventlog(smbios_hdl_t * shp,smbios_evlog_t * evp)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
smbios_info_memarray(smbios_hdl_t * shp,id_t id,smbios_memarray_t * map)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
smbios_info_memarrmap(smbios_hdl_t * shp,id_t id,smbios_memarrmap_t * map)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
smbios_info_memdevice(smbios_hdl_t * shp,id_t id,smbios_memdevice_t * mdp)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));
96104cdb0e3SRobert 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 
9881eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_26)) {
9894e901881SDale Ghent 		mdp->smbmd_rank = m.smbmdev_attrs & 0x0F;
9901eb9e3eaSRobert Mustacchi 	}
9914e901881SDale Ghent 
9921eb9e3eaSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
9934e901881SDale Ghent 		mdp->smbmd_clkspeed = m.smbmdev_clkspeed;
9941eb9e3eaSRobert Mustacchi 	}
9954e901881SDale Ghent 
9961eb9e3eaSRobert 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 
1002a60349c8SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_32)) {
1003a60349c8SRobert Mustacchi 		mdp->smbmd_memtech = m.smbmdev_memtech;
1004a60349c8SRobert Mustacchi 		mdp->smbmd_opcap_flags = m.smbmdev_opmode;
1005a60349c8SRobert Mustacchi 		mdp->smbmd_firmware_rev = smb_strptr(stp,
1006a60349c8SRobert Mustacchi 		    m.smbmdev_fwver);
1007a60349c8SRobert Mustacchi 		mdp->smbmd_modmfg_id = m.smbmdev_modulemfgid;
1008a60349c8SRobert Mustacchi 		mdp->smbmd_modprod_id = m.smbmdev_moduleprodid;
1009a60349c8SRobert Mustacchi 		mdp->smbmd_cntrlmfg_id = m.smbmdev_memsysmfgid;
1010a60349c8SRobert Mustacchi 		mdp->smbmd_cntrlprod_id = m.smbmdev_memsysprodid;
1011a60349c8SRobert Mustacchi 		mdp->smbmd_nvsize = m.smbmdev_nvsize;
1012a60349c8SRobert Mustacchi 		mdp->smbmd_volatile_size = m.smbmdev_volsize;
1013a60349c8SRobert Mustacchi 		mdp->smbmd_cache_size = m.smbmdev_cachesize;
1014a60349c8SRobert Mustacchi 		mdp->smbmd_logical_size = m.smbmdev_logicalsize;
1015a60349c8SRobert Mustacchi 	}
1016a60349c8SRobert Mustacchi 
101784ab085aSmws 	return (0);
101884ab085aSmws }
101984ab085aSmws 
102084ab085aSmws int
smbios_info_memdevmap(smbios_hdl_t * shp,id_t id,smbios_memdevmap_t * mdp)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
smbios_info_hwsec(smbios_hdl_t * shp,smbios_hwsec_t * hsp)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
smbios_info_boot(smbios_hdl_t * shp,smbios_boot_t * bp)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);
107792212f2eSJohn 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 
108492212f2eSJohn Levon 	b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
108592212f2eSJohn 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
smbios_info_ipmi(smbios_hdl_t * shp,smbios_ipmi_t * ip)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
smbios_has_oemstr(smbios_hdl_t * shp,const char * oemstr)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 *
smb_serial_valid(const char * serial)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
smb_get_sn(smbios_hdl_t * shp,const char ** psnp,const char ** csnp)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 *
smbios_psn(smbios_hdl_t * shp)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 *
smbios_csn(smbios_hdl_t * shp)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
smbios_info_extprocessor(smbios_hdl_t * shp,id_t id,smbios_processor_ext_t * epp)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
smbios_info_extport(smbios_hdl_t * shp,id_t id,smbios_port_ext_t * eportp)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
smbios_info_pciexrc(smbios_hdl_t * shp,id_t id,smbios_pciexrc_t * rcp)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
smbios_info_extmemarray(smbios_hdl_t * shp,id_t id,smbios_memarray_ext_t * emap)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
smbios_info_extmemdevice(smbios_hdl_t * shp,id_t id,smbios_memdevice_ext_t * emdp)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 }
136165fa020fSRobert Mustacchi 
136265fa020fSRobert Mustacchi int
smbios_info_powersup(smbios_hdl_t * shp,id_t id,smbios_powersup_t * psup)136365fa020fSRobert Mustacchi smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup)
136465fa020fSRobert Mustacchi {
136565fa020fSRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
136665fa020fSRobert Mustacchi 	smb_powersup_t psu;
136765fa020fSRobert Mustacchi 
136865fa020fSRobert Mustacchi 	if (stp == NULL)
136965fa020fSRobert Mustacchi 		return (-1); /* errno is set for us */
137065fa020fSRobert Mustacchi 
137165fa020fSRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP)
137265fa020fSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
137365fa020fSRobert Mustacchi 
137465fa020fSRobert Mustacchi 	/* The minimum length required by the spec is 0x10. */
137565fa020fSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < 0x10)
137665fa020fSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
137765fa020fSRobert Mustacchi 
137865fa020fSRobert Mustacchi 	bzero(psup, sizeof (*psup));
137965fa020fSRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu));
138065fa020fSRobert Mustacchi 	psup->smbps_group = psu.smbpsup_group;
138165fa020fSRobert Mustacchi 	psup->smbps_maxout = psu.smbpsup_max;
138265fa020fSRobert Mustacchi 
138365fa020fSRobert Mustacchi 	if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char))
138465fa020fSRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_HOT;
138565fa020fSRobert Mustacchi 	if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char))
138665fa020fSRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_PRESENT;
138765fa020fSRobert Mustacchi 	if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char))
138865fa020fSRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG;
138965fa020fSRobert Mustacchi 
139065fa020fSRobert Mustacchi 	psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char);
139165fa020fSRobert Mustacchi 	psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char);
139265fa020fSRobert Mustacchi 	psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char);
139365fa020fSRobert Mustacchi 
139465fa020fSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x12) {
139565fa020fSRobert Mustacchi 		psup->smbps_vprobe = psu.smbpsup_vprobe;
139665fa020fSRobert Mustacchi 	} else {
139765fa020fSRobert Mustacchi 		psup->smbps_vprobe = 0xffff;
139865fa020fSRobert Mustacchi 	}
139965fa020fSRobert Mustacchi 
140065fa020fSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x14) {
140165fa020fSRobert Mustacchi 		psup->smbps_cooldev = psu.smbpsup_cooldev;
140265fa020fSRobert Mustacchi 	} else {
140365fa020fSRobert Mustacchi 		psup->smbps_cooldev = 0xffff;
140465fa020fSRobert Mustacchi 	}
140565fa020fSRobert Mustacchi 
140665fa020fSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x16) {
140765fa020fSRobert Mustacchi 		psup->smbps_iprobe = psu.smbpsup_iprobe;
140865fa020fSRobert Mustacchi 	} else {
140965fa020fSRobert Mustacchi 		psup->smbps_iprobe = 0xffff;
141065fa020fSRobert Mustacchi 	}
141165fa020fSRobert Mustacchi 
141265fa020fSRobert Mustacchi 	return (0);
141365fa020fSRobert Mustacchi }
1414a448814aSRobert Mustacchi 
1415a448814aSRobert Mustacchi int
smbios_info_vprobe(smbios_hdl_t * shp,id_t id,smbios_vprobe_t * vprobe)1416a448814aSRobert Mustacchi smbios_info_vprobe(smbios_hdl_t *shp, id_t id, smbios_vprobe_t *vprobe)
1417a448814aSRobert Mustacchi {
1418a448814aSRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1419a448814aSRobert Mustacchi 	smb_vprobe_t vp;
1420a448814aSRobert Mustacchi 
1421a448814aSRobert Mustacchi 	if (stp == NULL)
1422a448814aSRobert Mustacchi 		return (-1); /* errno is set for us */
1423a448814aSRobert Mustacchi 
1424a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_VPROBE)
1425a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
1426a448814aSRobert Mustacchi 
1427a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_VPROBE_MINLEN)
1428a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
1429a448814aSRobert Mustacchi 
1430a448814aSRobert Mustacchi 	bzero(vprobe, sizeof (*vprobe));
1431a448814aSRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &vp, sizeof (vp));
1432a448814aSRobert Mustacchi 	vprobe->smbvp_description = smb_strptr(stp, vp.smbvpr_descr);
1433a448814aSRobert Mustacchi 	vprobe->smbvp_location = SMB_VPROBE_LOCATION(vp.smbvpr_locstat);
1434a448814aSRobert Mustacchi 	vprobe->smbvp_status = SMB_VPROBE_STATUS(vp.smbvpr_locstat);
1435a448814aSRobert Mustacchi 	vprobe->smbvp_maxval = vp.smbvpr_maxval;
1436a448814aSRobert Mustacchi 	vprobe->smbvp_minval = vp.smbvpr_minval;
1437a448814aSRobert Mustacchi 	vprobe->smbvp_resolution = vp.smbvpr_resolution;
1438a448814aSRobert Mustacchi 	vprobe->smbvp_tolerance	= vp.smbvpr_tolerance;
1439a448814aSRobert Mustacchi 	vprobe->smbvp_accuracy = vp.smbvpr_accuracy;
1440a448814aSRobert Mustacchi 
1441a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_VPROBE_NOMINAL_MINLEN) {
1442a448814aSRobert Mustacchi 		vprobe->smbvp_nominal = vp.smbvpr_nominal;
1443a448814aSRobert Mustacchi 	} else {
1444a448814aSRobert Mustacchi 		vprobe->smbvp_nominal = SMB_PROBE_UNKNOWN_VALUE;
1445a448814aSRobert Mustacchi 	}
1446a448814aSRobert Mustacchi 
1447a448814aSRobert Mustacchi 	return (0);
1448a448814aSRobert Mustacchi }
1449a448814aSRobert Mustacchi 
1450a448814aSRobert Mustacchi int
smbios_info_cooldev(smbios_hdl_t * shp,id_t id,smbios_cooldev_t * cooldev)1451a448814aSRobert Mustacchi smbios_info_cooldev(smbios_hdl_t *shp, id_t id, smbios_cooldev_t *cooldev)
1452a448814aSRobert Mustacchi {
1453a448814aSRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1454a448814aSRobert Mustacchi 	smb_cooldev_t cd;
1455a448814aSRobert Mustacchi 
1456a448814aSRobert Mustacchi 	if (stp == NULL)
1457a448814aSRobert Mustacchi 		return (-1); /* errno is set for us */
1458a448814aSRobert Mustacchi 
1459a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_COOLDEV)
1460a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
1461a448814aSRobert Mustacchi 
1462a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_COOLDEV_MINLEN)
1463a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
1464a448814aSRobert Mustacchi 
1465a448814aSRobert Mustacchi 	bzero(cooldev, sizeof (*cooldev));
1466a448814aSRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &cd, sizeof (cd));
1467a448814aSRobert Mustacchi 	cooldev->smbcd_tprobe = cd.smbcdev_tprobe;
1468a448814aSRobert Mustacchi 	cooldev->smbcd_type = SMB_COOLDEV_TYPE(cd.smbcdev_typstat);
1469a448814aSRobert Mustacchi 	cooldev->smbcd_status = SMB_COOLDEV_STATUS(cd.smbcdev_typstat);
1470a448814aSRobert Mustacchi 	cooldev->smbcd_group = cd.smbcdev_group;
1471a448814aSRobert Mustacchi 	cooldev->smbcd_oem = cd.smbcdev_oem;
1472a448814aSRobert Mustacchi 
1473a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_COOLDEV_NOMINAL_MINLEN) {
1474a448814aSRobert Mustacchi 		cooldev->smbcd_nominal = cd.smbcdev_nominal;
1475a448814aSRobert Mustacchi 	} else {
1476a448814aSRobert Mustacchi 		cooldev->smbcd_nominal = SMB_PROBE_UNKNOWN_VALUE;
1477a448814aSRobert Mustacchi 	}
1478a448814aSRobert Mustacchi 
1479a448814aSRobert Mustacchi 	/*
1480a448814aSRobert Mustacchi 	 * The description field was added in SMBIOS version 2.7. The
1481a448814aSRobert Mustacchi 	 * SMB_TYPE_COOLDEV support was only added after all of the 2.7+ fields
1482a448814aSRobert Mustacchi 	 * were added in the spec. So while a user may request an older version,
1483a448814aSRobert Mustacchi 	 * we don't have to worry about old structures and just simply skip it
1484a448814aSRobert Mustacchi 	 * if they're not asking for it.
1485a448814aSRobert Mustacchi 	 */
1486a448814aSRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27) &&
1487a448814aSRobert Mustacchi 	    smb_gteq(shp, SMB_VERSION_27) &&
1488a448814aSRobert Mustacchi 	    stp->smbst_hdr->smbh_len >= SMB_COOLDEV_DESCR_MINLEN) {
1489a448814aSRobert Mustacchi 		cooldev->smbcd_descr = smb_strptr(stp, cd.smbcdev_descr);
1490a448814aSRobert Mustacchi 	} else {
1491a448814aSRobert Mustacchi 		cooldev->smbcd_descr = NULL;
1492a448814aSRobert Mustacchi 	}
1493a448814aSRobert Mustacchi 
1494a448814aSRobert Mustacchi 	return (0);
1495a448814aSRobert Mustacchi }
1496a448814aSRobert Mustacchi 
1497a448814aSRobert Mustacchi int
smbios_info_tprobe(smbios_hdl_t * shp,id_t id,smbios_tprobe_t * tprobe)1498a448814aSRobert Mustacchi smbios_info_tprobe(smbios_hdl_t *shp, id_t id, smbios_tprobe_t *tprobe)
1499a448814aSRobert Mustacchi {
1500a448814aSRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1501a448814aSRobert Mustacchi 	smb_tprobe_t tp;
1502a448814aSRobert Mustacchi 
1503a448814aSRobert Mustacchi 	if (stp == NULL)
1504a448814aSRobert Mustacchi 		return (-1); /* errno is set for us */
1505a448814aSRobert Mustacchi 
1506a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_TPROBE)
1507a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
1508a448814aSRobert Mustacchi 
1509a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_TPROBE_MINLEN)
1510a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
1511a448814aSRobert Mustacchi 
1512a448814aSRobert Mustacchi 	bzero(tprobe, sizeof (*tprobe));
1513a448814aSRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &tp, sizeof (tp));
1514a448814aSRobert Mustacchi 	tprobe->smbtp_description = smb_strptr(stp, tp.smbtpr_descr);
1515a448814aSRobert Mustacchi 	tprobe->smbtp_location = SMB_TPROBE_LOCATION(tp.smbtpr_locstat);
1516a448814aSRobert Mustacchi 	tprobe->smbtp_status = SMB_TPROBE_STATUS(tp.smbtpr_locstat);
1517a448814aSRobert Mustacchi 	tprobe->smbtp_maxval = tp.smbtpr_maxval;
1518a448814aSRobert Mustacchi 	tprobe->smbtp_minval = tp.smbtpr_minval;
1519a448814aSRobert Mustacchi 	tprobe->smbtp_resolution = tp.smbtpr_resolution;
1520a448814aSRobert Mustacchi 	tprobe->smbtp_tolerance	= tp.smbtpr_tolerance;
1521a448814aSRobert Mustacchi 	tprobe->smbtp_accuracy = tp.smbtpr_accuracy;
1522a448814aSRobert Mustacchi 
1523a448814aSRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_TPROBE_NOMINAL_MINLEN) {
1524a448814aSRobert Mustacchi 		tprobe->smbtp_nominal = tp.smbtpr_nominal;
1525a448814aSRobert Mustacchi 	} else {
1526a448814aSRobert Mustacchi 		tprobe->smbtp_nominal = SMB_PROBE_UNKNOWN_VALUE;
1527a448814aSRobert Mustacchi 	}
1528a448814aSRobert Mustacchi 
1529a448814aSRobert Mustacchi 	return (0);
1530a448814aSRobert Mustacchi }
1531a448814aSRobert Mustacchi 
1532a448814aSRobert Mustacchi int
smbios_info_iprobe(smbios_hdl_t * shp,id_t id,smbios_iprobe_t * iprobe)1533a448814aSRobert Mustacchi smbios_info_iprobe(smbios_hdl_t *shp, id_t id, smbios_iprobe_t *iprobe)
1534a448814aSRobert Mustacchi {
1535a448814aSRobert Mustacchi 	const smb_struct_t *sip = smb_lookup_id(shp, id);
1536a448814aSRobert Mustacchi 	smb_iprobe_t ip;
1537a448814aSRobert Mustacchi 
1538a448814aSRobert Mustacchi 	if (sip == NULL)
1539a448814aSRobert Mustacchi 		return (-1); /* errno is set for us */
1540a448814aSRobert Mustacchi 
1541a448814aSRobert Mustacchi 	if (sip->smbst_hdr->smbh_type != SMB_TYPE_IPROBE)
1542a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
1543a448814aSRobert Mustacchi 
1544a448814aSRobert Mustacchi 	if (sip->smbst_hdr->smbh_len < SMB_IPROBE_MINLEN)
1545a448814aSRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
1546a448814aSRobert Mustacchi 
1547a448814aSRobert Mustacchi 	bzero(iprobe, sizeof (*iprobe));
1548a448814aSRobert Mustacchi 	smb_info_bcopy(sip->smbst_hdr, &ip, sizeof (ip));
1549a448814aSRobert Mustacchi 	iprobe->smbip_description = smb_strptr(sip, ip.smbipr_descr);
1550a448814aSRobert Mustacchi 	iprobe->smbip_location = SMB_IPROBE_LOCATION(ip.smbipr_locstat);
1551a448814aSRobert Mustacchi 	iprobe->smbip_status = SMB_IPROBE_STATUS(ip.smbipr_locstat);
1552a448814aSRobert Mustacchi 	iprobe->smbip_maxval = ip.smbipr_maxval;
1553a448814aSRobert Mustacchi 	iprobe->smbip_minval = ip.smbipr_minval;
1554a448814aSRobert Mustacchi 	iprobe->smbip_resolution = ip.smbipr_resolution;
1555a448814aSRobert Mustacchi 	iprobe->smbip_tolerance	= ip.smbipr_tolerance;
1556a448814aSRobert Mustacchi 	iprobe->smbip_accuracy = ip.smbipr_accuracy;
1557a448814aSRobert Mustacchi 
1558a448814aSRobert Mustacchi 	if (sip->smbst_hdr->smbh_len >= SMB_IPROBE_NOMINAL_MINLEN) {
1559a448814aSRobert Mustacchi 		iprobe->smbip_nominal = ip.smbipr_nominal;
1560a448814aSRobert Mustacchi 	} else {
1561a448814aSRobert Mustacchi 		iprobe->smbip_nominal = SMB_PROBE_UNKNOWN_VALUE;
1562a448814aSRobert Mustacchi 	}
1563a448814aSRobert Mustacchi 
1564a448814aSRobert Mustacchi 	return (0);
1565a448814aSRobert Mustacchi }
1566