xref: /titanic_51/usr/src/common/smbios/smb_info.c (revision 074bb90d80fdbeb2d04a8450a55ecbc96de28785)
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 /*
239c94f155SCheng Sean Ye  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2484ab085aSmws  * Use is subject to license terms.
2584ab085aSmws  */
2684ab085aSmws 
2784ab085aSmws /*
2884ab085aSmws  * SMBIOS Information Routines
2984ab085aSmws  *
3084ab085aSmws  * The routines in this file are used to convert from the SMBIOS data format to
3184ab085aSmws  * a more reasonable and stable set of structures offered as part of our ABI.
3284ab085aSmws  * These functions take the general form:
3384ab085aSmws  *
3484ab085aSmws  *	stp = smb_lookup_type(shp, foo);
3584ab085aSmws  *	smb_foo_t foo;
3684ab085aSmws  *
3784ab085aSmws  *	smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
3884ab085aSmws  *      bzero(caller's struct);
3984ab085aSmws  *
4084ab085aSmws  *	copy/convert foo members into caller's struct
4184ab085aSmws  *
4284ab085aSmws  * We copy the internal structure on to an automatic variable so as to avoid
4384ab085aSmws  * checks everywhere for structures that the BIOS has improperly truncated, and
4484ab085aSmws  * also to automatically handle the case of a structure that has been extended.
4584ab085aSmws  * When necessary, this code can use smb_gteq() to determine whether the SMBIOS
4684ab085aSmws  * data is of a particular revision that is supposed to contain a new field.
4784ab085aSmws  */
4884ab085aSmws 
4984ab085aSmws #include <sys/smbios_impl.h>
5084ab085aSmws 
519c94f155SCheng Sean Ye #ifdef _KERNEL
529c94f155SCheng Sean Ye #include <sys/sunddi.h>
539c94f155SCheng Sean Ye #else
54c7c09f80SEric Schrock #include <fcntl.h>
55c7c09f80SEric Schrock #include <unistd.h>
569c94f155SCheng Sean Ye #include <string.h>
57c7c09f80SEric Schrock #endif
58c7c09f80SEric Schrock 
5984ab085aSmws /*
6084ab085aSmws  * A large number of SMBIOS structures contain a set of common strings used to
6184ab085aSmws  * describe a h/w component's serial number, manufacturer, etc.  These fields
6284ab085aSmws  * helpfully have different names and offsets and sometimes aren't consistent.
6384ab085aSmws  * To simplify life for our clients, we factor these common things out into
6484ab085aSmws  * smbios_info_t, which can be retrieved for any structure.  The following
6584ab085aSmws  * table describes the mapping from a given structure to the smbios_info_t.
66*074bb90dSTom Pothier  * Multiple SMBIOS stuctures' contained objects are also handled here.
6784ab085aSmws  */
6884ab085aSmws static const struct smb_infospec {
6984ab085aSmws 	uint8_t is_type;		/* structure type */
7084ab085aSmws 	uint8_t is_manu;		/* manufacturer offset */
7184ab085aSmws 	uint8_t is_product;		/* product name offset */
7284ab085aSmws 	uint8_t is_version;		/* version offset */
7384ab085aSmws 	uint8_t is_serial;		/* serial number offset */
7484ab085aSmws 	uint8_t is_asset;		/* asset tag offset */
7584ab085aSmws 	uint8_t is_location;		/* location string offset */
7684ab085aSmws 	uint8_t is_part;		/* part number offset */
77*074bb90dSTom Pothier 	uint8_t is_contc;		/* contained count */
78*074bb90dSTom Pothier 	uint8_t is_contsz;		/* contained size */
79*074bb90dSTom Pothier 	uint8_t is_contv;		/* contained objects */
8084ab085aSmws } _smb_infospecs[] = {
8184ab085aSmws 	{ SMB_TYPE_SYSTEM,
8284ab085aSmws 		offsetof(smb_system_t, smbsi_manufacturer),
8384ab085aSmws 		offsetof(smb_system_t, smbsi_product),
8484ab085aSmws 		offsetof(smb_system_t, smbsi_version),
8584ab085aSmws 		offsetof(smb_system_t, smbsi_serial),
8684ab085aSmws 		0,
8784ab085aSmws 		0,
88*074bb90dSTom Pothier 		0,
89*074bb90dSTom Pothier 		0,
90*074bb90dSTom Pothier 		0,
9184ab085aSmws 		0 },
9284ab085aSmws 	{ SMB_TYPE_BASEBOARD,
9384ab085aSmws 		offsetof(smb_bboard_t, smbbb_manufacturer),
9484ab085aSmws 		offsetof(smb_bboard_t, smbbb_product),
9584ab085aSmws 		offsetof(smb_bboard_t, smbbb_version),
9684ab085aSmws 		offsetof(smb_bboard_t, smbbb_serial),
9784ab085aSmws 		offsetof(smb_bboard_t, smbbb_asset),
9884ab085aSmws 		offsetof(smb_bboard_t, smbbb_location),
99*074bb90dSTom Pothier 		0,
100*074bb90dSTom Pothier 		offsetof(smb_bboard_t, smbbb_cn),
101*074bb90dSTom Pothier 		SMB_CONT_WORD,
102*074bb90dSTom Pothier 		offsetof(smb_bboard_t, smbbb_cv) },
10384ab085aSmws 	{ SMB_TYPE_CHASSIS,
10484ab085aSmws 		offsetof(smb_chassis_t, smbch_manufacturer),
10584ab085aSmws 		0,
10684ab085aSmws 		offsetof(smb_chassis_t, smbch_version),
10784ab085aSmws 		offsetof(smb_chassis_t, smbch_serial),
10884ab085aSmws 		offsetof(smb_chassis_t, smbch_asset),
10984ab085aSmws 		0,
110*074bb90dSTom Pothier 		0,
111*074bb90dSTom Pothier 		offsetof(smb_chassis_t, smbch_cn),
112*074bb90dSTom Pothier 		SMB_CONT_BYTE,
113*074bb90dSTom Pothier 		offsetof(smb_chassis_t, smbch_cv) },
11484ab085aSmws 	{ SMB_TYPE_PROCESSOR,
11584ab085aSmws 		offsetof(smb_processor_t, smbpr_manufacturer),
11684ab085aSmws 		0,
11784ab085aSmws 		offsetof(smb_processor_t, smbpr_version),
11884ab085aSmws 		offsetof(smb_processor_t, smbpr_serial),
11984ab085aSmws 		offsetof(smb_processor_t, smbpr_asset),
12084ab085aSmws 		offsetof(smb_processor_t, smbpr_socket),
121*074bb90dSTom Pothier 		offsetof(smb_processor_t, smbpr_part),
122*074bb90dSTom Pothier 		0,
123*074bb90dSTom Pothier 		0,
124*074bb90dSTom Pothier 		0 },
12584ab085aSmws 	{ SMB_TYPE_CACHE,
12684ab085aSmws 		0,
12784ab085aSmws 		0,
12884ab085aSmws 		0,
12984ab085aSmws 		0,
13084ab085aSmws 		0,
13184ab085aSmws 		offsetof(smb_cache_t, smbca_socket),
132*074bb90dSTom Pothier 		0,
133*074bb90dSTom Pothier 		0,
134*074bb90dSTom Pothier 		0,
13584ab085aSmws 		0 },
13684ab085aSmws 	{ SMB_TYPE_PORT,
13784ab085aSmws 		0,
13884ab085aSmws 		0,
13984ab085aSmws 		0,
14084ab085aSmws 		0,
14184ab085aSmws 		0,
14284ab085aSmws 		offsetof(smb_port_t, smbpo_iref),
143*074bb90dSTom Pothier 		0,
144*074bb90dSTom Pothier 		0,
145*074bb90dSTom Pothier 		0,
14684ab085aSmws 		0 },
14784ab085aSmws 	{ SMB_TYPE_SLOT,
14884ab085aSmws 		0,
14984ab085aSmws 		0,
15084ab085aSmws 		0,
15184ab085aSmws 		0,
15284ab085aSmws 		0,
15384ab085aSmws 		offsetof(smb_slot_t, smbsl_name),
154*074bb90dSTom Pothier 		0,
155*074bb90dSTom Pothier 		0,
156*074bb90dSTom Pothier 		0,
15784ab085aSmws 		0 },
15884ab085aSmws 	{ SMB_TYPE_MEMDEVICE,
15984ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_manufacturer),
16084ab085aSmws 		0,
16184ab085aSmws 		0,
16284ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_serial),
16384ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_asset),
16484ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_dloc),
165*074bb90dSTom Pothier 		offsetof(smb_memdevice_t, smbmdev_part),
166*074bb90dSTom Pothier 		0,
167*074bb90dSTom Pothier 		0,
168*074bb90dSTom Pothier 		0 },
16984ab085aSmws 	{ SMB_TYPE_POWERSUP,
17084ab085aSmws 		offsetof(smb_powersup_t, smbpsup_manufacturer),
17184ab085aSmws 		offsetof(smb_powersup_t, smbpsup_devname),
17284ab085aSmws 		offsetof(smb_powersup_t, smbpsup_rev),
17384ab085aSmws 		offsetof(smb_powersup_t, smbpsup_serial),
17484ab085aSmws 		offsetof(smb_powersup_t, smbpsup_asset),
17584ab085aSmws 		offsetof(smb_powersup_t, smbpsup_loc),
176*074bb90dSTom Pothier 		offsetof(smb_powersup_t, smbpsup_part),
177*074bb90dSTom Pothier 		0,
178*074bb90dSTom Pothier 		0,
179*074bb90dSTom Pothier 		0 },
18084ab085aSmws 	{ SMB_TYPE_EOT }
18184ab085aSmws };
18284ab085aSmws 
18384ab085aSmws static const char *
18484ab085aSmws smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n)
18584ab085aSmws {
18684ab085aSmws 	const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr;
18784ab085aSmws 
18884ab085aSmws 	if (off != 0 && sp + off < stp->smbst_end) {
18984ab085aSmws 		(*n)++; /* indicate success for caller */
19084ab085aSmws 		return (smb_strptr(stp, sp[off]));
19184ab085aSmws 	}
19284ab085aSmws 
19384ab085aSmws 	return (smb_strptr(stp, 0));
19484ab085aSmws }
19584ab085aSmws 
19684ab085aSmws static void
19784ab085aSmws smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen)
19884ab085aSmws {
19984ab085aSmws 	if (dstlen > hp->smbh_len) {
20084ab085aSmws 		bcopy(hp, dst, hp->smbh_len);
20184ab085aSmws 		bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len);
20284ab085aSmws 	} else
20384ab085aSmws 		bcopy(hp, dst, dstlen);
20484ab085aSmws }
20584ab085aSmws 
20684ab085aSmws void
20784ab085aSmws smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
20884ab085aSmws {
20984ab085aSmws 	bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
21084ab085aSmws }
21184ab085aSmws 
212c7c09f80SEric Schrock #ifndef _KERNEL
213c7c09f80SEric Schrock static char smbios_product_override[256];
214c7c09f80SEric Schrock static boolean_t smbios_product_checked;
215c7c09f80SEric Schrock #endif
216c7c09f80SEric Schrock 
21784ab085aSmws int
21884ab085aSmws smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip)
21984ab085aSmws {
22084ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
22184ab085aSmws 	const struct smb_infospec *isp;
22284ab085aSmws 	int n = 0;
22384ab085aSmws 
22484ab085aSmws 	if (stp == NULL)
22584ab085aSmws 		return (-1); /* errno is set for us */
22684ab085aSmws 
22784ab085aSmws 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
22884ab085aSmws 		if (isp->is_type == stp->smbst_hdr->smbh_type)
22984ab085aSmws 			break;
23084ab085aSmws 	}
23184ab085aSmws 
23284ab085aSmws 	ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n);
23384ab085aSmws 	ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n);
23484ab085aSmws 	ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n);
23584ab085aSmws 	ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n);
23684ab085aSmws 	ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n);
23784ab085aSmws 	ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n);
23884ab085aSmws 	ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n);
23984ab085aSmws 
24084ab085aSmws 	/*
241c7c09f80SEric Schrock 	 * This private file allows developers to experiment with reporting
242c7c09f80SEric Schrock 	 * different platform strings from SMBIOS.  It is not a supported
243c7c09f80SEric Schrock 	 * mechanism in the long term, and does not work in the kernel.
244c7c09f80SEric Schrock 	 */
245c7c09f80SEric Schrock #ifndef _KERNEL
246c7c09f80SEric Schrock 	if (isp->is_type == SMB_TYPE_SYSTEM) {
247c7c09f80SEric Schrock 		if (!smbios_product_checked) {
248c7c09f80SEric Schrock 			int fd = open("/etc/smbios_product", O_RDONLY);
249c7c09f80SEric Schrock 			if (fd >= 0) {
250c7c09f80SEric Schrock 				(void) read(fd, smbios_product_override,
251c7c09f80SEric Schrock 				    sizeof (smbios_product_override) - 1);
252c7c09f80SEric Schrock 				(void) close(fd);
253c7c09f80SEric Schrock 			}
254c7c09f80SEric Schrock 			smbios_product_checked = B_TRUE;
255c7c09f80SEric Schrock 		}
256c7c09f80SEric Schrock 
257c7c09f80SEric Schrock 		if (smbios_product_override[0] != '\0')
258c7c09f80SEric Schrock 			ip->smbi_product = smbios_product_override;
259c7c09f80SEric Schrock 	}
260c7c09f80SEric Schrock #endif
261c7c09f80SEric Schrock 
262c7c09f80SEric Schrock 	/*
26384ab085aSmws 	 * If we have a port with an empty internal reference designator string
26484ab085aSmws 	 * try using the external reference designator string instead.
26584ab085aSmws 	 */
26684ab085aSmws 	if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') {
26784ab085aSmws 		ip->smbi_location = smb_info_strptr(stp,
26884ab085aSmws 		    offsetof(smb_port_t, smbpo_eref), &n);
26984ab085aSmws 	}
27084ab085aSmws 
27184ab085aSmws 	return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO));
27284ab085aSmws }
27384ab085aSmws 
274*074bb90dSTom Pothier /*
275*074bb90dSTom Pothier  * Returns the actual number of contained objects.
276*074bb90dSTom Pothier  *
277*074bb90dSTom Pothier  * idc - number of contained objects
278*074bb90dSTom Pothier  * idv - returned array of contained objects
279*074bb90dSTom Pothier  */
280*074bb90dSTom Pothier int
281*074bb90dSTom Pothier smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv)
282*074bb90dSTom Pothier {
283*074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
284*074bb90dSTom Pothier 	const struct smb_infospec *isp;
285*074bb90dSTom Pothier 	id_t *cp;
286*074bb90dSTom Pothier 	uint_t size;
287*074bb90dSTom Pothier 	uint8_t cnt;
288*074bb90dSTom Pothier 	int i, n;
289*074bb90dSTom Pothier 
290*074bb90dSTom Pothier 	if (stp == NULL) {
291*074bb90dSTom Pothier 		return (-1); /* errno is set for us */
292*074bb90dSTom Pothier 	}
293*074bb90dSTom Pothier 
294*074bb90dSTom Pothier 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
295*074bb90dSTom Pothier 		if (isp->is_type == stp->smbst_hdr->smbh_type)
296*074bb90dSTom Pothier 			break;
297*074bb90dSTom Pothier 	}
298*074bb90dSTom Pothier 	if (isp->is_type == SMB_TYPE_EOT)
299*074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
300*074bb90dSTom Pothier 
301*074bb90dSTom Pothier 	size = isp->is_contsz;
302*074bb90dSTom Pothier 	cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc);
303*074bb90dSTom Pothier 	cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv);
304*074bb90dSTom Pothier 
305*074bb90dSTom Pothier 	n = MIN(cnt, idc);
306*074bb90dSTom Pothier 	for (i = 0; i < n; i++) {
307*074bb90dSTom Pothier 		if (size == SMB_CONT_WORD)
308*074bb90dSTom Pothier 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 2));
309*074bb90dSTom Pothier 		else if (size == SMB_CONT_BYTE)
310*074bb90dSTom Pothier 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 3));
311*074bb90dSTom Pothier 		else
312*074bb90dSTom Pothier 			return (smb_set_errno(shp, ESMB_INVAL));
313*074bb90dSTom Pothier 	}
314*074bb90dSTom Pothier 
315*074bb90dSTom Pothier 	return (cnt);
316*074bb90dSTom Pothier }
317*074bb90dSTom Pothier 
31884ab085aSmws id_t
31984ab085aSmws smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp)
32084ab085aSmws {
32184ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS);
32284ab085aSmws 	const smb_bios_t *bip;
32384ab085aSmws 
32484ab085aSmws 	if (stp == NULL)
32584ab085aSmws 		return (-1); /* errno is set for us */
32684ab085aSmws 
32784ab085aSmws 	if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t))
32884ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
32984ab085aSmws 
33084ab085aSmws 	bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr;
33184ab085aSmws 	bzero(bp, sizeof (smbios_bios_t));
33284ab085aSmws 
33384ab085aSmws 	bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor);
33484ab085aSmws 	bp->smbb_version = smb_strptr(stp, bip->smbbi_version);
33584ab085aSmws 	bp->smbb_segment = bip->smbbi_segment;
33684ab085aSmws 	bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate);
33784ab085aSmws 	bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1);
33884ab085aSmws 	bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment);
33984ab085aSmws 	bp->smbb_cflags = bip->smbbi_cflags;
34084ab085aSmws 
34184ab085aSmws 	/*
34284ab085aSmws 	 * If one or more extension bytes are present, reset smbb_xcflags to
34384ab085aSmws 	 * point to them.  Otherwise leave this member set to NULL.
34484ab085aSmws 	 */
34584ab085aSmws 	if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) {
34684ab085aSmws 		bp->smbb_xcflags = bip->smbbi_xcflags;
34784ab085aSmws 		bp->smbb_nxcflags = stp->smbst_hdr->smbh_len -
34884ab085aSmws 		    sizeof (smb_bios_t) + 1;
34984ab085aSmws 
35084ab085aSmws 		if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
35184ab085aSmws 		    smb_gteq(shp, SMB_VERSION_24)) {
35284ab085aSmws 			bp->smbb_biosv.smbv_major =
35384ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ];
35484ab085aSmws 			bp->smbb_biosv.smbv_minor =
35584ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN];
35684ab085aSmws 			bp->smbb_ecfwv.smbv_major =
35784ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ];
35884ab085aSmws 			bp->smbb_ecfwv.smbv_minor =
35984ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN];
36084ab085aSmws 		}
36184ab085aSmws 	}
36284ab085aSmws 
36384ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
36484ab085aSmws }
36584ab085aSmws 
36684ab085aSmws id_t
36784ab085aSmws smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip)
36884ab085aSmws {
36984ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM);
37084ab085aSmws 	smb_system_t si;
37184ab085aSmws 
37284ab085aSmws 	if (stp == NULL)
37384ab085aSmws 		return (-1); /* errno is set for us */
37484ab085aSmws 
37584ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si));
37684ab085aSmws 	bzero(sip, sizeof (smbios_system_t));
37784ab085aSmws 
37884ab085aSmws 	sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid;
37984ab085aSmws 	sip->smbs_uuidlen = sizeof (si.smbsi_uuid);
38084ab085aSmws 	sip->smbs_wakeup = si.smbsi_wakeup;
38184ab085aSmws 	sip->smbs_sku = smb_strptr(stp, si.smbsi_sku);
38284ab085aSmws 	sip->smbs_family = smb_strptr(stp, si.smbsi_family);
38384ab085aSmws 
38484ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
38584ab085aSmws }
38684ab085aSmws 
38784ab085aSmws int
38884ab085aSmws smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp)
38984ab085aSmws {
39084ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
39184ab085aSmws 	smb_bboard_t bb;
39284ab085aSmws 
39384ab085aSmws 	if (stp == NULL)
39484ab085aSmws 		return (-1); /* errno is set for us */
39584ab085aSmws 
39684ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD)
39784ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
39884ab085aSmws 
39984ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb));
40084ab085aSmws 	bzero(bbp, sizeof (smbios_bboard_t));
40184ab085aSmws 
40284ab085aSmws 	bbp->smbb_chassis = bb.smbbb_chassis;
40384ab085aSmws 	bbp->smbb_flags = bb.smbbb_flags;
40484ab085aSmws 	bbp->smbb_type = bb.smbbb_type;
405*074bb90dSTom Pothier 	bbp->smbb_contn = bb.smbbb_cn;
40684ab085aSmws 
40784ab085aSmws 	return (0);
40884ab085aSmws }
40984ab085aSmws 
41084ab085aSmws int
41184ab085aSmws smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp)
41284ab085aSmws {
41384ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
41484ab085aSmws 	smb_chassis_t ch;
41584ab085aSmws 
41684ab085aSmws 	if (stp == NULL)
41784ab085aSmws 		return (-1); /* errno is set for us */
41884ab085aSmws 
41984ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS)
42084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
42184ab085aSmws 
42284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &ch, sizeof (ch));
42384ab085aSmws 	bzero(chp, sizeof (smbios_chassis_t));
42484ab085aSmws 
42584ab085aSmws 	chp->smbc_oemdata = ch.smbch_oemdata;
42684ab085aSmws 	chp->smbc_lock = (ch.smbch_type & SMB_CHT_LOCK) != 0;
42784ab085aSmws 	chp->smbc_type = ch.smbch_type & ~SMB_CHT_LOCK;
42884ab085aSmws 	chp->smbc_bustate = ch.smbch_bustate;
42984ab085aSmws 	chp->smbc_psstate = ch.smbch_psstate;
43084ab085aSmws 	chp->smbc_thstate = ch.smbch_thstate;
43184ab085aSmws 	chp->smbc_security = ch.smbch_security;
43284ab085aSmws 	chp->smbc_uheight = ch.smbch_uheight;
43384ab085aSmws 	chp->smbc_cords = ch.smbch_cords;
43484ab085aSmws 	chp->smbc_elems = ch.smbch_cn;
435*074bb90dSTom Pothier 	chp->smbc_elemlen = ch.smbch_cm;
43684ab085aSmws 
43784ab085aSmws 	return (0);
43884ab085aSmws }
43984ab085aSmws 
44084ab085aSmws int
44184ab085aSmws smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp)
44284ab085aSmws {
44384ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
44484ab085aSmws 	smb_processor_t p;
44584ab085aSmws 
44684ab085aSmws 	if (stp == NULL)
44784ab085aSmws 		return (-1); /* errno is set for us */
44884ab085aSmws 
44984ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR)
45084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
45184ab085aSmws 
45284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
45384ab085aSmws 	bzero(pp, sizeof (smbios_processor_t));
45484ab085aSmws 
45584ab085aSmws 	pp->smbp_cpuid = p.smbpr_cpuid;
45684ab085aSmws 	pp->smbp_type = p.smbpr_type;
45784ab085aSmws 	pp->smbp_family = p.smbpr_family;
45884ab085aSmws 	pp->smbp_voltage = p.smbpr_voltage;
45984ab085aSmws 	pp->smbp_maxspeed = p.smbpr_maxspeed;
46084ab085aSmws 	pp->smbp_curspeed = p.smbpr_curspeed;
46184ab085aSmws 	pp->smbp_status = p.smbpr_status;
46284ab085aSmws 	pp->smbp_upgrade = p.smbpr_upgrade;
46384ab085aSmws 	pp->smbp_l1cache = p.smbpr_l1cache;
46484ab085aSmws 	pp->smbp_l2cache = p.smbpr_l2cache;
46584ab085aSmws 	pp->smbp_l3cache = p.smbpr_l3cache;
46684ab085aSmws 
46784ab085aSmws 	return (0);
46884ab085aSmws }
46984ab085aSmws 
47084ab085aSmws int
47184ab085aSmws smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap)
47284ab085aSmws {
47384ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
47484ab085aSmws 	smb_cache_t c;
47584ab085aSmws 
47684ab085aSmws 	if (stp == NULL)
47784ab085aSmws 		return (-1); /* errno is set for us */
47884ab085aSmws 
47984ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE)
48084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
48184ab085aSmws 
48284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c));
48384ab085aSmws 	bzero(cap, sizeof (smbios_cache_t));
48484ab085aSmws 
48584ab085aSmws 	cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize);
48684ab085aSmws 	cap->smba_size = SMB_CACHE_SIZE(c.smbca_size);
48784ab085aSmws 	cap->smba_stype = c.smbca_stype;
48884ab085aSmws 	cap->smba_ctype = c.smbca_ctype;
48984ab085aSmws 	cap->smba_speed = c.smbca_speed;
49084ab085aSmws 	cap->smba_etype = c.smbca_etype;
49184ab085aSmws 	cap->smba_ltype = c.smbca_ltype;
49284ab085aSmws 	cap->smba_assoc = c.smbca_assoc;
49384ab085aSmws 	cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config);
49484ab085aSmws 	cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config);
49584ab085aSmws 	cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config);
49684ab085aSmws 
49784ab085aSmws 	if (SMB_CACHE_CFG_ENABLED(c.smbca_config))
49884ab085aSmws 		cap->smba_flags |= SMB_CAF_ENABLED;
49984ab085aSmws 
50084ab085aSmws 	if (SMB_CACHE_CFG_SOCKETED(c.smbca_config))
50184ab085aSmws 		cap->smba_flags |= SMB_CAF_SOCKETED;
50284ab085aSmws 
50384ab085aSmws 	return (0);
50484ab085aSmws }
50584ab085aSmws 
50684ab085aSmws int
50784ab085aSmws smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop)
50884ab085aSmws {
50984ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
51084ab085aSmws 	smb_port_t p;
51184ab085aSmws 
51284ab085aSmws 	if (stp == NULL)
51384ab085aSmws 		return (-1); /* errno is set for us */
51484ab085aSmws 
51584ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT)
51684ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
51784ab085aSmws 
51884ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
51984ab085aSmws 	bzero(pop, sizeof (smbios_port_t));
52084ab085aSmws 
52184ab085aSmws 	pop->smbo_iref = smb_strptr(stp, p.smbpo_iref);
52284ab085aSmws 	pop->smbo_eref = smb_strptr(stp, p.smbpo_eref);
52384ab085aSmws 
52484ab085aSmws 	pop->smbo_itype = p.smbpo_itype;
52584ab085aSmws 	pop->smbo_etype = p.smbpo_etype;
52684ab085aSmws 	pop->smbo_ptype = p.smbpo_ptype;
52784ab085aSmws 
52884ab085aSmws 	return (0);
52984ab085aSmws }
53084ab085aSmws 
53184ab085aSmws int
53284ab085aSmws smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp)
53384ab085aSmws {
53484ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
53584ab085aSmws 	smb_slot_t s;
53684ab085aSmws 
53784ab085aSmws 	if (stp == NULL)
53884ab085aSmws 		return (-1); /* errno is set for us */
53984ab085aSmws 
54084ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
54184ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
54284ab085aSmws 
54384ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
54484ab085aSmws 	bzero(sp, sizeof (smbios_slot_t));
54584ab085aSmws 
54684ab085aSmws 	sp->smbl_name = smb_strptr(stp, s.smbsl_name);
54784ab085aSmws 	sp->smbl_type = s.smbsl_type;
54884ab085aSmws 	sp->smbl_width = s.smbsl_width;
54984ab085aSmws 	sp->smbl_usage = s.smbsl_usage;
55084ab085aSmws 	sp->smbl_length = s.smbsl_length;
55184ab085aSmws 	sp->smbl_id = s.smbsl_id;
55284ab085aSmws 	sp->smbl_ch1 = s.smbsl_ch1;
55384ab085aSmws 	sp->smbl_ch2 = s.smbsl_ch2;
55484ab085aSmws 
55584ab085aSmws 	return (0);
55684ab085aSmws }
55784ab085aSmws 
55884ab085aSmws int
55984ab085aSmws smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp)
56084ab085aSmws {
56184ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
56284ab085aSmws 	const smb_obdev_t *op;
56384ab085aSmws 	int i, m, n;
56484ab085aSmws 
56584ab085aSmws 	if (stp == NULL)
56684ab085aSmws 		return (-1); /* errno is set for us */
56784ab085aSmws 
56884ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS)
56984ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
57084ab085aSmws 
57184ab085aSmws 	op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t));
57284ab085aSmws 	m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op);
57384ab085aSmws 	n = MIN(m, obc);
57484ab085aSmws 
57584ab085aSmws 	for (i = 0; i < n; i++, op++, obp++) {
57684ab085aSmws 		obp->smbd_name = smb_strptr(stp, op->smbob_name);
57784ab085aSmws 		obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED;
57884ab085aSmws 		obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0;
57984ab085aSmws 	}
58084ab085aSmws 
58184ab085aSmws 	return (m);
58284ab085aSmws }
58384ab085aSmws 
58484ab085aSmws /*
58584ab085aSmws  * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the
58684ab085aSmws  * first byte to indicate the size of a string table at the end of the record.
58784ab085aSmws  * Therefore, smbios_info_strtab() can be used to retrieve the table size and
58884ab085aSmws  * strings for any of these underlying record types.
58984ab085aSmws  */
59084ab085aSmws int
59184ab085aSmws smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[])
59284ab085aSmws {
59384ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
59484ab085aSmws 	smb_strtab_t s;
59584ab085aSmws 	int i, n;
59684ab085aSmws 
59784ab085aSmws 	if (stp == NULL)
59884ab085aSmws 		return (-1); /* errno is set for us */
59984ab085aSmws 
60084ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR &&
60184ab085aSmws 	    stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR &&
60284ab085aSmws 	    stp->smbst_hdr->smbh_type != SMB_TYPE_LANG)
60384ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
60484ab085aSmws 
60584ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
60684ab085aSmws 	n = MIN(s.smbtb_count, argc);
60784ab085aSmws 
60884ab085aSmws 	for (i = 0; i < n; i++)
60984ab085aSmws 		argv[i] = smb_strptr(stp, i + 1);
61084ab085aSmws 
61184ab085aSmws 	return (s.smbtb_count);
61284ab085aSmws }
61384ab085aSmws 
61484ab085aSmws id_t
61584ab085aSmws smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp)
61684ab085aSmws {
61784ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG);
61884ab085aSmws 	smb_lang_t l;
61984ab085aSmws 
62084ab085aSmws 	if (stp == NULL)
62184ab085aSmws 		return (-1); /* errno is set for us */
62284ab085aSmws 
62384ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l));
62484ab085aSmws 	bzero(lp, sizeof (smbios_lang_t));
62584ab085aSmws 
62684ab085aSmws 	lp->smbla_cur = smb_strptr(stp, l.smblang_cur);
62784ab085aSmws 	lp->smbla_fmt = l.smblang_flags & 1;
62884ab085aSmws 	lp->smbla_num = l.smblang_num;
62984ab085aSmws 
63084ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
63184ab085aSmws }
63284ab085aSmws 
63384ab085aSmws id_t
63484ab085aSmws smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp)
63584ab085aSmws {
63684ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG);
63784ab085aSmws 	const smb_sel_t *sel;
63884ab085aSmws 	size_t len;
63984ab085aSmws 
64084ab085aSmws 	if (stp == NULL)
64184ab085aSmws 		return (-1); /* errno is set for us */
64284ab085aSmws 
64384ab085aSmws 	if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t))
64484ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
64584ab085aSmws 
64684ab085aSmws 	sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr;
64784ab085aSmws 	len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t);
64884ab085aSmws 	bzero(evp, sizeof (smbios_evlog_t));
64984ab085aSmws 
65084ab085aSmws 	if (len < sel->smbsel_typec * sel->smbsel_typesz)
65184ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
65284ab085aSmws 
65384ab085aSmws 	evp->smbev_size = sel->smbsel_len;
65484ab085aSmws 	evp->smbev_hdr = sel->smbsel_hdroff;
65584ab085aSmws 	evp->smbev_data = sel->smbsel_dataoff;
65684ab085aSmws 	evp->smbev_method = sel->smbsel_method;
65784ab085aSmws 	evp->smbev_flags = sel->smbsel_status;
65884ab085aSmws 	evp->smbev_format = sel->smbsel_format;
65984ab085aSmws 	evp->smbev_token = sel->smbsel_token;
66084ab085aSmws 	evp->smbev_addr.eva_addr = sel->smbsel_addr;
66184ab085aSmws 
66284ab085aSmws 	if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) {
66384ab085aSmws 		evp->smbev_typec = sel->smbsel_typec;
66484ab085aSmws 		evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev;
66584ab085aSmws 	}
66684ab085aSmws 
66784ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
66884ab085aSmws }
66984ab085aSmws 
67084ab085aSmws int
67184ab085aSmws smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map)
67284ab085aSmws {
67384ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
67484ab085aSmws 	smb_memarray_t m;
67584ab085aSmws 
67684ab085aSmws 	if (stp == NULL)
67784ab085aSmws 		return (-1); /* errno is set for us */
67884ab085aSmws 
67984ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY)
68084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
68184ab085aSmws 
68284ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
68384ab085aSmws 	bzero(map, sizeof (smbios_memarray_t));
68484ab085aSmws 
68584ab085aSmws 	map->smbma_location = m.smbmarr_loc;
68684ab085aSmws 	map->smbma_use = m.smbmarr_use;
68784ab085aSmws 	map->smbma_ecc = m.smbmarr_ecc;
68884ab085aSmws 	map->smbma_ndevs = m.smbmarr_ndevs;
68984ab085aSmws 	map->smbma_err = m.smbmarr_err;
69084ab085aSmws 
69184ab085aSmws 	if (m.smbmarr_cap != 0x80000000)
69284ab085aSmws 		map->smbma_size = (uint64_t)m.smbmarr_cap * 1024;
69384ab085aSmws 	else
69484ab085aSmws 		map->smbma_size = 0; /* unknown */
69584ab085aSmws 
69684ab085aSmws 	return (0);
69784ab085aSmws }
69884ab085aSmws 
69984ab085aSmws int
70084ab085aSmws smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map)
70184ab085aSmws {
70284ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
70384ab085aSmws 	smb_memarrmap_t m;
70484ab085aSmws 
70584ab085aSmws 	if (stp == NULL)
70684ab085aSmws 		return (-1); /* errno is set for us */
70784ab085aSmws 
70884ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP)
70984ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
71084ab085aSmws 
71184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
71284ab085aSmws 	bzero(map, sizeof (smbios_memarrmap_t));
71384ab085aSmws 
71484ab085aSmws 	map->smbmam_array = m.smbamap_array;
71584ab085aSmws 	map->smbmam_width = m.smbamap_width;
71684ab085aSmws 	map->smbmam_addr = (uint64_t)m.smbamap_start * 1024;
71784ab085aSmws 	map->smbmam_size = (uint64_t)
71884ab085aSmws 	    (m.smbamap_end - m.smbamap_start + 1) * 1024;
71984ab085aSmws 
72084ab085aSmws 	return (0);
72184ab085aSmws }
72284ab085aSmws 
72384ab085aSmws int
72484ab085aSmws smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp)
72584ab085aSmws {
72684ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
72784ab085aSmws 	smb_memdevice_t m;
72884ab085aSmws 
72984ab085aSmws 	if (stp == NULL)
73084ab085aSmws 		return (-1); /* errno is set for us */
73184ab085aSmws 
73284ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE)
73384ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
73484ab085aSmws 
73584ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
73684ab085aSmws 	bzero(mdp, sizeof (smbios_memdevice_t));
73784ab085aSmws 
73884ab085aSmws 	mdp->smbmd_array = m.smbmdev_array;
73984ab085aSmws 	mdp->smbmd_error = m.smbmdev_error;
74084ab085aSmws 	mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth;
74184ab085aSmws 	mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth;
74284ab085aSmws 
74384ab085aSmws 	if (mdp->smbmd_size != 0xFFFF) {
74484ab085aSmws 		mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES);
74584ab085aSmws 		if (m.smbmdev_size & SMB_MDS_KBYTES)
74684ab085aSmws 			mdp->smbmd_size *= 1024;
74784ab085aSmws 		else
74884ab085aSmws 			mdp->smbmd_size *= 1024 * 1024;
74984ab085aSmws 	} else
75084ab085aSmws 		mdp->smbmd_size = -1ULL; /* size unknown */
75184ab085aSmws 
75284ab085aSmws 	mdp->smbmd_form = m.smbmdev_form;
75384ab085aSmws 	mdp->smbmd_set = m.smbmdev_set;
75484ab085aSmws 	mdp->smbmd_type = m.smbmdev_type;
75584ab085aSmws 	mdp->smbmd_flags = m.smbmdev_flags;
75684ab085aSmws 	mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc);
75784ab085aSmws 	mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc);
75884ab085aSmws 
75984ab085aSmws 	if (m.smbmdev_speed != 0)
76084ab085aSmws 		mdp->smbmd_speed = 1000 / m.smbmdev_speed; /* MHz -> nsec */
76184ab085aSmws 
76284ab085aSmws 	return (0);
76384ab085aSmws }
76484ab085aSmws 
76584ab085aSmws int
76684ab085aSmws smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp)
76784ab085aSmws {
76884ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
76984ab085aSmws 	smb_memdevmap_t m;
77084ab085aSmws 
77184ab085aSmws 	if (stp == NULL)
77284ab085aSmws 		return (-1); /* errno is set for us */
77384ab085aSmws 
77484ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP)
77584ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
77684ab085aSmws 
77784ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
77884ab085aSmws 	bzero(mdp, sizeof (smbios_memdevmap_t));
77984ab085aSmws 
78084ab085aSmws 	mdp->smbmdm_device = m.smbdmap_device;
78184ab085aSmws 	mdp->smbmdm_arrmap = m.smbdmap_array;
78284ab085aSmws 	mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024;
78384ab085aSmws 	mdp->smbmdm_size = (uint64_t)
78484ab085aSmws 	    (m.smbdmap_end - m.smbdmap_start + 1) * 1024;
78584ab085aSmws 	mdp->smbmdm_rpos = m.smbdmap_rpos;
78684ab085aSmws 	mdp->smbmdm_ipos = m.smbdmap_ipos;
78784ab085aSmws 	mdp->smbmdm_idepth = m.smbdmap_idepth;
78884ab085aSmws 
78984ab085aSmws 	return (0);
79084ab085aSmws }
79184ab085aSmws 
79284ab085aSmws id_t
79384ab085aSmws smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp)
79484ab085aSmws {
79584ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY);
79684ab085aSmws 	smb_hwsec_t hs;
79784ab085aSmws 
79884ab085aSmws 	if (stp == NULL)
79984ab085aSmws 		return (-1); /* errno is set for us */
80084ab085aSmws 
80184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
80284ab085aSmws 	bzero(hsp, sizeof (smbios_hwsec_t));
80384ab085aSmws 
80484ab085aSmws 	hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
80584ab085aSmws 	hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
80684ab085aSmws 	hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
80784ab085aSmws 	hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
80884ab085aSmws 
80984ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
81084ab085aSmws }
81184ab085aSmws 
81284ab085aSmws id_t
81384ab085aSmws smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
81484ab085aSmws {
81584ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
81684ab085aSmws 	const smb_boot_t *b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
81784ab085aSmws 
81884ab085aSmws 	if (stp == NULL)
81984ab085aSmws 		return (-1); /* errno is set for us */
82084ab085aSmws 
82184ab085aSmws 	bzero(bp, sizeof (smbios_boot_t));
82284ab085aSmws 
82384ab085aSmws 	bp->smbt_status = b->smbbo_status[0];
82484ab085aSmws 	bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
82584ab085aSmws 	bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
82684ab085aSmws 
82784ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
82884ab085aSmws }
82984ab085aSmws 
83084ab085aSmws id_t
83184ab085aSmws smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
83284ab085aSmws {
83384ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
83484ab085aSmws 	smb_ipmi_t i;
83584ab085aSmws 
83684ab085aSmws 	if (stp == NULL)
83784ab085aSmws 		return (-1); /* errno is set for us */
83884ab085aSmws 
83984ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
84084ab085aSmws 	bzero(ip, sizeof (smbios_ipmi_t));
84184ab085aSmws 
84284ab085aSmws 	ip->smbip_type = i.smbipm_type;
84384ab085aSmws 	ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec);
84484ab085aSmws 	ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec);
84584ab085aSmws 	ip->smbip_i2c = i.smbipm_i2c;
84684ab085aSmws 	ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO;
84784ab085aSmws 	ip->smbip_intr = i.smbipm_intr;
84884ab085aSmws 
84984ab085aSmws 	if (i.smbipm_bus != (uint8_t)-1)
85084ab085aSmws 		ip->smbip_bus = i.smbipm_bus;
85184ab085aSmws 	else
85284ab085aSmws 		ip->smbip_bus = -1u;
85384ab085aSmws 
85484ab085aSmws 	if (SMB_IPM_INFO_LSB(i.smbipm_info))
85584ab085aSmws 		ip->smbip_addr |= 1; /* turn on least-significant bit of addr */
85684ab085aSmws 
85784ab085aSmws 	if (i.smbipm_addr & SMB_IPM_ADDR_IO) {
85884ab085aSmws 		switch (SMB_IPM_INFO_REGS(i.smbipm_info)) {
85984ab085aSmws 		case SMB_IPM_REGS_1B:
86084ab085aSmws 			ip->smbip_regspacing = 1;
86184ab085aSmws 			break;
86284ab085aSmws 		case SMB_IPM_REGS_4B:
86384ab085aSmws 			ip->smbip_regspacing = 4;
86484ab085aSmws 			break;
86584ab085aSmws 		case SMB_IPM_REGS_16B:
86684ab085aSmws 			ip->smbip_regspacing = 16;
86784ab085aSmws 			break;
86884ab085aSmws 		default:
86984ab085aSmws 			ip->smbip_regspacing = 1;
87084ab085aSmws 		}
87184ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_IOADDR;
87284ab085aSmws 	}
87384ab085aSmws 
87484ab085aSmws 	if (SMB_IPM_INFO_ISPEC(i.smbipm_info))
87584ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTRSPEC;
87684ab085aSmws 
87784ab085aSmws 	if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI)
87884ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTRHIGH;
87984ab085aSmws 
88084ab085aSmws 	if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE)
88184ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTREDGE;
88284ab085aSmws 
88384ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
88484ab085aSmws }
8859c94f155SCheng Sean Ye 
8869c94f155SCheng Sean Ye static boolean_t
8879c94f155SCheng Sean Ye smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr)
8889c94f155SCheng Sean Ye {
8899c94f155SCheng Sean Ye 	const smb_struct_t *stp = shp->sh_structs;
8909c94f155SCheng Sean Ye 	smb_strtab_t s;
8919c94f155SCheng Sean Ye 	int i, j;
8929c94f155SCheng Sean Ye 
8939c94f155SCheng Sean Ye 	for (i = 0; i < shp->sh_nstructs; i++, stp++) {
8949c94f155SCheng Sean Ye 		if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR)
8959c94f155SCheng Sean Ye 			continue;
8969c94f155SCheng Sean Ye 
8979c94f155SCheng Sean Ye 		smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
8989c94f155SCheng Sean Ye 		for (j = 0; j < s.smbtb_count; j++)
8999c94f155SCheng Sean Ye 			if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0)
9009c94f155SCheng Sean Ye 				return (B_TRUE);
9019c94f155SCheng Sean Ye 	}
9029c94f155SCheng Sean Ye 
9039c94f155SCheng Sean Ye 	return (B_FALSE);
9049c94f155SCheng Sean Ye }
9059c94f155SCheng Sean Ye 
9069c94f155SCheng Sean Ye static const char *
9079c94f155SCheng Sean Ye smb_serial_valid(const char *serial)
9089c94f155SCheng Sean Ye {
9099c94f155SCheng Sean Ye 	char buf[MAXNAMELEN];
9109c94f155SCheng Sean Ye 	int i = 0;
9119c94f155SCheng Sean Ye 
9129c94f155SCheng Sean Ye 	if (serial == NULL)
9139c94f155SCheng Sean Ye 		return (NULL);
9149c94f155SCheng Sean Ye 
9159c94f155SCheng Sean Ye 	(void) strlcpy(buf, serial, sizeof (buf));
9169c94f155SCheng Sean Ye 
9179c94f155SCheng Sean Ye 	while (buf[i] != '\0' && buf[i] == ' ')
9189c94f155SCheng Sean Ye 		i++;
9199c94f155SCheng Sean Ye 
9209c94f155SCheng Sean Ye 	if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL ||
9219c94f155SCheng Sean Ye 	    strstr(buf, SMB_DEFAULT2) != NULL)
9229c94f155SCheng Sean Ye 		return (NULL);
9239c94f155SCheng Sean Ye 
9249c94f155SCheng Sean Ye 	return (serial);
9259c94f155SCheng Sean Ye }
9269c94f155SCheng Sean Ye 
9279c94f155SCheng Sean Ye /*
9289c94f155SCheng Sean Ye  * Get chassis SN or product SN
9299c94f155SCheng Sean Ye  */
9309c94f155SCheng Sean Ye static int
9319c94f155SCheng Sean Ye smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp)
9329c94f155SCheng Sean Ye {
9339c94f155SCheng Sean Ye 	const smb_struct_t *stp;
9349c94f155SCheng Sean Ye 	smbios_info_t s1, s3;
9359c94f155SCheng Sean Ye 
9369c94f155SCheng Sean Ye 	if (psnp == NULL || csnp == NULL)
9379c94f155SCheng Sean Ye 		return (smb_set_errno(shp, ESMB_INVAL));
9389c94f155SCheng Sean Ye 
9399c94f155SCheng Sean Ye 	*psnp = *csnp = NULL;
9409c94f155SCheng Sean Ye 
9419c94f155SCheng Sean Ye 	/*
9429c94f155SCheng Sean Ye 	 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN
9439c94f155SCheng Sean Ye 	 * from type 1 structure, and chassis SN from type 3 structure.
9449c94f155SCheng Sean Ye 	 * Otherwise return SN in type 1 structure as chassis SN.
9459c94f155SCheng Sean Ye 	 */
9469c94f155SCheng Sean Ye 
9479c94f155SCheng Sean Ye 	/* Get type 1 SN */
9489c94f155SCheng Sean Ye 	if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL ||
9499c94f155SCheng Sean Ye 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR)
9509c94f155SCheng Sean Ye 		s1.smbi_serial = NULL;
9519c94f155SCheng Sean Ye 
9529c94f155SCheng Sean Ye 	/* Get type 3 SN */
9539c94f155SCheng Sean Ye 	if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL ||
9549c94f155SCheng Sean Ye 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR)
9559c94f155SCheng Sean Ye 		s3.smbi_serial = NULL;
9569c94f155SCheng Sean Ye 
9579c94f155SCheng Sean Ye 	if (smbios_has_oemstr(shp, SMB_PRMS1)) {
9589c94f155SCheng Sean Ye 		*psnp = smb_serial_valid(s1.smbi_serial);
9599c94f155SCheng Sean Ye 		*csnp = smb_serial_valid(s3.smbi_serial);
9609c94f155SCheng Sean Ye 	} else {
9619c94f155SCheng Sean Ye 		*csnp = smb_serial_valid(s1.smbi_serial);
9629c94f155SCheng Sean Ye 	}
9639c94f155SCheng Sean Ye 
9649c94f155SCheng Sean Ye 	return (0);
9659c94f155SCheng Sean Ye }
9669c94f155SCheng Sean Ye 
9679c94f155SCheng Sean Ye const char *
9689c94f155SCheng Sean Ye smbios_psn(smbios_hdl_t *shp)
9699c94f155SCheng Sean Ye {
9709c94f155SCheng Sean Ye 	const char *psn, *csn;
9719c94f155SCheng Sean Ye 
9729c94f155SCheng Sean Ye 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn);
9739c94f155SCheng Sean Ye }
9749c94f155SCheng Sean Ye 
9759c94f155SCheng Sean Ye const char *
9769c94f155SCheng Sean Ye smbios_csn(smbios_hdl_t *shp)
9779c94f155SCheng Sean Ye {
9789c94f155SCheng Sean Ye 	const char *psn, *csn;
9799c94f155SCheng Sean Ye 
9809c94f155SCheng Sean Ye 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn);
9819c94f155SCheng Sean Ye }
982*074bb90dSTom Pothier 
983*074bb90dSTom Pothier int
984*074bb90dSTom Pothier smbios_info_extprocessor(smbios_hdl_t *shp, id_t id,
985*074bb90dSTom Pothier     smbios_processor_ext_t *epp)
986*074bb90dSTom Pothier {
987*074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
988*074bb90dSTom Pothier 	smb_processor_ext_t *exp;
989*074bb90dSTom Pothier 
990*074bb90dSTom Pothier 	if (stp == NULL)
991*074bb90dSTom Pothier 		return (-1); /* errno is set for us */
992*074bb90dSTom Pothier 
993*074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR)
994*074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
995*074bb90dSTom Pothier 
996*074bb90dSTom Pothier 	exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr;
997*074bb90dSTom Pothier 	bzero(epp, sizeof (smbios_processor_ext_t));
998*074bb90dSTom Pothier 
999*074bb90dSTom Pothier 	epp->smbpe_processor = exp->smbpre_processor;
1000*074bb90dSTom Pothier 	epp->smbpe_fru = exp->smbpre_fru;
1001*074bb90dSTom Pothier 	epp->smbpe_n = exp->smbpre_n;
1002*074bb90dSTom Pothier 	epp->smbpe_apicid = exp->smbpre_apicid;
1003*074bb90dSTom Pothier 
1004*074bb90dSTom Pothier 	return (0);
1005*074bb90dSTom Pothier }
1006*074bb90dSTom Pothier 
1007*074bb90dSTom Pothier int
1008*074bb90dSTom Pothier smbios_info_pciexrc(smbios_hdl_t *shp, id_t id,
1009*074bb90dSTom Pothier     smbios_pciexrc_t *rcp)
1010*074bb90dSTom Pothier {
1011*074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1012*074bb90dSTom Pothier 	smb_pciexrc_t rc;
1013*074bb90dSTom Pothier 
1014*074bb90dSTom Pothier 	if (stp == NULL)
1015*074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1016*074bb90dSTom Pothier 
1017*074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC)
1018*074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1019*074bb90dSTom Pothier 
1020*074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc));
1021*074bb90dSTom Pothier 	bzero(rcp, sizeof (smbios_pciexrc_t));
1022*074bb90dSTom Pothier 
1023*074bb90dSTom Pothier 	rcp->smbpcie_bb = rc.smbpciexrc_bboard;
1024*074bb90dSTom Pothier 	rcp->smbpcie_bdf = rc.smbpciexrc_bdf;
1025*074bb90dSTom Pothier 
1026*074bb90dSTom Pothier 	return (0);
1027*074bb90dSTom Pothier }
1028*074bb90dSTom Pothier 
1029*074bb90dSTom Pothier int
1030*074bb90dSTom Pothier smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap)
1031*074bb90dSTom Pothier {
1032*074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1033*074bb90dSTom Pothier 	smb_memarray_ext_t exma;
1034*074bb90dSTom Pothier 
1035*074bb90dSTom Pothier 	if (stp == NULL)
1036*074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1037*074bb90dSTom Pothier 
1038*074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY)
1039*074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1040*074bb90dSTom Pothier 
1041*074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma));
1042*074bb90dSTom Pothier 	bzero(emap, sizeof (smbios_memarray_ext_t));
1043*074bb90dSTom Pothier 
1044*074bb90dSTom Pothier 	emap->smbmae_ma = exma.smbmarre_ma;
1045*074bb90dSTom Pothier 	emap->smbmae_comp = exma.smbmarre_component;
1046*074bb90dSTom Pothier 	emap->smbmae_bdf = exma.smbmarre_bdf;
1047*074bb90dSTom Pothier 
1048*074bb90dSTom Pothier 	return (0);
1049*074bb90dSTom Pothier }
1050*074bb90dSTom Pothier 
1051*074bb90dSTom Pothier int
1052*074bb90dSTom Pothier smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id,
1053*074bb90dSTom Pothier     smbios_memdevice_ext_t *emdp)
1054*074bb90dSTom Pothier {
1055*074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1056*074bb90dSTom Pothier 	smb_memdevice_ext_t exmd;
1057*074bb90dSTom Pothier 
1058*074bb90dSTom Pothier 	if (stp == NULL)
1059*074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1060*074bb90dSTom Pothier 
1061*074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE)
1062*074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1063*074bb90dSTom Pothier 
1064*074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd));
1065*074bb90dSTom Pothier 	bzero(emdp, sizeof (smbios_memdevice_ext_t));
1066*074bb90dSTom Pothier 
1067*074bb90dSTom Pothier 	emdp->smbmdeve_md = exmd.smbmdeve_mdev;
1068*074bb90dSTom Pothier 	emdp->smbmdeve_drch = exmd.smbmdeve_dchan;
1069*074bb90dSTom Pothier 	emdp->smbmdeve_ncs  = exmd.smbmdeve_ncs;
1070*074bb90dSTom Pothier 	emdp->smbmdeve_cs = exmd.smbmdeve_cs;
1071*074bb90dSTom Pothier 
1072*074bb90dSTom Pothier 	return (0);
1073*074bb90dSTom Pothier }
1074