xref: /titanic_52/usr/src/common/smbios/smb_info.c (revision 489b7c4ab76ae8df137fbfcc2214f7baa52883a0)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * SMBIOS Information Routines
29  *
30  * The routines in this file are used to convert from the SMBIOS data format to
31  * a more reasonable and stable set of structures offered as part of our ABI.
32  * These functions take the general form:
33  *
34  *	stp = smb_lookup_type(shp, foo);
35  *	smb_foo_t foo;
36  *
37  *	smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
38  *      bzero(caller's struct);
39  *
40  *	copy/convert foo members into caller's struct
41  *
42  * We copy the internal structure on to an automatic variable so as to avoid
43  * checks everywhere for structures that the BIOS has improperly truncated, and
44  * also to automatically handle the case of a structure that has been extended.
45  * When necessary, this code can use smb_gteq() to determine whether the SMBIOS
46  * data is of a particular revision that is supposed to contain a new field.
47  */
48 
49 #include <sys/smbios_impl.h>
50 
51 #ifndef _KERNEL
52 #include <fcntl.h>
53 #include <unistd.h>
54 #endif
55 
56 /*
57  * A large number of SMBIOS structures contain a set of common strings used to
58  * describe a h/w component's serial number, manufacturer, etc.  These fields
59  * helpfully have different names and offsets and sometimes aren't consistent.
60  * To simplify life for our clients, we factor these common things out into
61  * smbios_info_t, which can be retrieved for any structure.  The following
62  * table describes the mapping from a given structure to the smbios_info_t.
63  */
64 static const struct smb_infospec {
65 	uint8_t is_type;		/* structure type */
66 	uint8_t is_manu;		/* manufacturer offset */
67 	uint8_t is_product;		/* product name offset */
68 	uint8_t is_version;		/* version offset */
69 	uint8_t is_serial;		/* serial number offset */
70 	uint8_t is_asset;		/* asset tag offset */
71 	uint8_t is_location;		/* location string offset */
72 	uint8_t is_part;		/* part number offset */
73 } _smb_infospecs[] = {
74 	{ SMB_TYPE_SYSTEM,
75 		offsetof(smb_system_t, smbsi_manufacturer),
76 		offsetof(smb_system_t, smbsi_product),
77 		offsetof(smb_system_t, smbsi_version),
78 		offsetof(smb_system_t, smbsi_serial),
79 		0,
80 		0,
81 		0 },
82 	{ SMB_TYPE_BASEBOARD,
83 		offsetof(smb_bboard_t, smbbb_manufacturer),
84 		offsetof(smb_bboard_t, smbbb_product),
85 		offsetof(smb_bboard_t, smbbb_version),
86 		offsetof(smb_bboard_t, smbbb_serial),
87 		offsetof(smb_bboard_t, smbbb_asset),
88 		offsetof(smb_bboard_t, smbbb_location),
89 		0 },
90 	{ SMB_TYPE_CHASSIS,
91 		offsetof(smb_chassis_t, smbch_manufacturer),
92 		0,
93 		offsetof(smb_chassis_t, smbch_version),
94 		offsetof(smb_chassis_t, smbch_serial),
95 		offsetof(smb_chassis_t, smbch_asset),
96 		0,
97 		0 },
98 	{ SMB_TYPE_PROCESSOR,
99 		offsetof(smb_processor_t, smbpr_manufacturer),
100 		0,
101 		offsetof(smb_processor_t, smbpr_version),
102 		offsetof(smb_processor_t, smbpr_serial),
103 		offsetof(smb_processor_t, smbpr_asset),
104 		offsetof(smb_processor_t, smbpr_socket),
105 		offsetof(smb_processor_t, smbpr_part) },
106 	{ SMB_TYPE_CACHE,
107 		0,
108 		0,
109 		0,
110 		0,
111 		0,
112 		offsetof(smb_cache_t, smbca_socket),
113 		0 },
114 	{ SMB_TYPE_PORT,
115 		0,
116 		0,
117 		0,
118 		0,
119 		0,
120 		offsetof(smb_port_t, smbpo_iref),
121 		0 },
122 	{ SMB_TYPE_SLOT,
123 		0,
124 		0,
125 		0,
126 		0,
127 		0,
128 		offsetof(smb_slot_t, smbsl_name),
129 		0 },
130 	{ SMB_TYPE_MEMDEVICE,
131 		offsetof(smb_memdevice_t, smbmdev_manufacturer),
132 		0,
133 		0,
134 		offsetof(smb_memdevice_t, smbmdev_serial),
135 		offsetof(smb_memdevice_t, smbmdev_asset),
136 		offsetof(smb_memdevice_t, smbmdev_dloc),
137 		offsetof(smb_memdevice_t, smbmdev_part) },
138 	{ SMB_TYPE_POWERSUP,
139 		offsetof(smb_powersup_t, smbpsup_manufacturer),
140 		offsetof(smb_powersup_t, smbpsup_devname),
141 		offsetof(smb_powersup_t, smbpsup_rev),
142 		offsetof(smb_powersup_t, smbpsup_serial),
143 		offsetof(smb_powersup_t, smbpsup_asset),
144 		offsetof(smb_powersup_t, smbpsup_loc),
145 		offsetof(smb_powersup_t, smbpsup_part) },
146 	{ SMB_TYPE_EOT }
147 };
148 
149 static const char *
150 smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n)
151 {
152 	const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr;
153 
154 	if (off != 0 && sp + off < stp->smbst_end) {
155 		(*n)++; /* indicate success for caller */
156 		return (smb_strptr(stp, sp[off]));
157 	}
158 
159 	return (smb_strptr(stp, 0));
160 }
161 
162 static void
163 smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen)
164 {
165 	if (dstlen > hp->smbh_len) {
166 		bcopy(hp, dst, hp->smbh_len);
167 		bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len);
168 	} else
169 		bcopy(hp, dst, dstlen);
170 }
171 
172 void
173 smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
174 {
175 	bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
176 }
177 
178 #ifndef _KERNEL
179 static char smbios_product_override[256];
180 static boolean_t smbios_product_checked;
181 #endif
182 
183 int
184 smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip)
185 {
186 	const smb_struct_t *stp = smb_lookup_id(shp, id);
187 	const struct smb_infospec *isp;
188 	int n = 0;
189 
190 	if (stp == NULL)
191 		return (-1); /* errno is set for us */
192 
193 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
194 		if (isp->is_type == stp->smbst_hdr->smbh_type)
195 			break;
196 	}
197 
198 	ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n);
199 	ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n);
200 	ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n);
201 	ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n);
202 	ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n);
203 	ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n);
204 	ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n);
205 
206 	/*
207 	 * This private file allows developers to experiment with reporting
208 	 * different platform strings from SMBIOS.  It is not a supported
209 	 * mechanism in the long term, and does not work in the kernel.
210 	 */
211 #ifndef _KERNEL
212 	if (isp->is_type == SMB_TYPE_SYSTEM) {
213 		if (!smbios_product_checked) {
214 			int fd = open("/etc/smbios_product", O_RDONLY);
215 			if (fd >= 0) {
216 				(void) read(fd, smbios_product_override,
217 				    sizeof (smbios_product_override) - 1);
218 				(void) close(fd);
219 			}
220 			smbios_product_checked = B_TRUE;
221 		}
222 
223 		if (smbios_product_override[0] != '\0')
224 			ip->smbi_product = smbios_product_override;
225 	}
226 #endif
227 
228 	/*
229 	 * If we have a port with an empty internal reference designator string
230 	 * try using the external reference designator string instead.
231 	 */
232 	if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') {
233 		ip->smbi_location = smb_info_strptr(stp,
234 		    offsetof(smb_port_t, smbpo_eref), &n);
235 	}
236 
237 	return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO));
238 }
239 
240 id_t
241 smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp)
242 {
243 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS);
244 	const smb_bios_t *bip;
245 
246 	if (stp == NULL)
247 		return (-1); /* errno is set for us */
248 
249 	if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t))
250 		return (smb_set_errno(shp, ESMB_CORRUPT));
251 
252 	bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr;
253 	bzero(bp, sizeof (smbios_bios_t));
254 
255 	bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor);
256 	bp->smbb_version = smb_strptr(stp, bip->smbbi_version);
257 	bp->smbb_segment = bip->smbbi_segment;
258 	bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate);
259 	bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1);
260 	bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment);
261 	bp->smbb_cflags = bip->smbbi_cflags;
262 
263 	/*
264 	 * If one or more extension bytes are present, reset smbb_xcflags to
265 	 * point to them.  Otherwise leave this member set to NULL.
266 	 */
267 	if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) {
268 		bp->smbb_xcflags = bip->smbbi_xcflags;
269 		bp->smbb_nxcflags = stp->smbst_hdr->smbh_len -
270 		    sizeof (smb_bios_t) + 1;
271 
272 		if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
273 		    smb_gteq(shp, SMB_VERSION_24)) {
274 			bp->smbb_biosv.smbv_major =
275 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ];
276 			bp->smbb_biosv.smbv_minor =
277 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN];
278 			bp->smbb_ecfwv.smbv_major =
279 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ];
280 			bp->smbb_ecfwv.smbv_minor =
281 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN];
282 		}
283 	}
284 
285 	return (stp->smbst_hdr->smbh_hdl);
286 }
287 
288 id_t
289 smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip)
290 {
291 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM);
292 	smb_system_t si;
293 
294 	if (stp == NULL)
295 		return (-1); /* errno is set for us */
296 
297 	smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si));
298 	bzero(sip, sizeof (smbios_system_t));
299 
300 	sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid;
301 	sip->smbs_uuidlen = sizeof (si.smbsi_uuid);
302 	sip->smbs_wakeup = si.smbsi_wakeup;
303 	sip->smbs_sku = smb_strptr(stp, si.smbsi_sku);
304 	sip->smbs_family = smb_strptr(stp, si.smbsi_family);
305 
306 	return (stp->smbst_hdr->smbh_hdl);
307 }
308 
309 int
310 smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp)
311 {
312 	const smb_struct_t *stp = smb_lookup_id(shp, id);
313 	smb_bboard_t bb;
314 
315 	if (stp == NULL)
316 		return (-1); /* errno is set for us */
317 
318 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD)
319 		return (smb_set_errno(shp, ESMB_TYPE));
320 
321 	smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb));
322 	bzero(bbp, sizeof (smbios_bboard_t));
323 
324 	/*
325 	 * At present, we do not provide support for the contained object
326 	 * handles portion of the Base Board structure, as none of the 2.3+
327 	 * BIOSes commonly in use appear to implement it at present.
328 	 */
329 	bbp->smbb_chassis = bb.smbbb_chassis;
330 	bbp->smbb_flags = bb.smbbb_flags;
331 	bbp->smbb_type = bb.smbbb_type;
332 
333 	return (0);
334 }
335 
336 int
337 smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp)
338 {
339 	const smb_struct_t *stp = smb_lookup_id(shp, id);
340 	smb_chassis_t ch;
341 
342 	if (stp == NULL)
343 		return (-1); /* errno is set for us */
344 
345 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS)
346 		return (smb_set_errno(shp, ESMB_TYPE));
347 
348 	smb_info_bcopy(stp->smbst_hdr, &ch, sizeof (ch));
349 	bzero(chp, sizeof (smbios_chassis_t));
350 
351 	/*
352 	 * At present, we do not provide support for the contained object
353 	 * handles portion of the Chassis structure, as none of the 2.3+
354 	 * BIOSes commonly in use appear to implement it at present.
355 	 */
356 	chp->smbc_oemdata = ch.smbch_oemdata;
357 	chp->smbc_lock = (ch.smbch_type & SMB_CHT_LOCK) != 0;
358 	chp->smbc_type = ch.smbch_type & ~SMB_CHT_LOCK;
359 	chp->smbc_bustate = ch.smbch_bustate;
360 	chp->smbc_psstate = ch.smbch_psstate;
361 	chp->smbc_thstate = ch.smbch_thstate;
362 	chp->smbc_security = ch.smbch_security;
363 	chp->smbc_uheight = ch.smbch_uheight;
364 	chp->smbc_cords = ch.smbch_cords;
365 	chp->smbc_elems = ch.smbch_cn;
366 
367 	return (0);
368 }
369 
370 int
371 smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp)
372 {
373 	const smb_struct_t *stp = smb_lookup_id(shp, id);
374 	smb_processor_t p;
375 
376 	if (stp == NULL)
377 		return (-1); /* errno is set for us */
378 
379 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR)
380 		return (smb_set_errno(shp, ESMB_TYPE));
381 
382 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
383 	bzero(pp, sizeof (smbios_processor_t));
384 
385 	pp->smbp_cpuid = p.smbpr_cpuid;
386 	pp->smbp_type = p.smbpr_type;
387 	pp->smbp_family = p.smbpr_family;
388 	pp->smbp_voltage = p.smbpr_voltage;
389 	pp->smbp_maxspeed = p.smbpr_maxspeed;
390 	pp->smbp_curspeed = p.smbpr_curspeed;
391 	pp->smbp_status = p.smbpr_status;
392 	pp->smbp_upgrade = p.smbpr_upgrade;
393 	pp->smbp_l1cache = p.smbpr_l1cache;
394 	pp->smbp_l2cache = p.smbpr_l2cache;
395 	pp->smbp_l3cache = p.smbpr_l3cache;
396 
397 	return (0);
398 }
399 
400 int
401 smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap)
402 {
403 	const smb_struct_t *stp = smb_lookup_id(shp, id);
404 	smb_cache_t c;
405 
406 	if (stp == NULL)
407 		return (-1); /* errno is set for us */
408 
409 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE)
410 		return (smb_set_errno(shp, ESMB_TYPE));
411 
412 	smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c));
413 	bzero(cap, sizeof (smbios_cache_t));
414 
415 	cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize);
416 	cap->smba_size = SMB_CACHE_SIZE(c.smbca_size);
417 	cap->smba_stype = c.smbca_stype;
418 	cap->smba_ctype = c.smbca_ctype;
419 	cap->smba_speed = c.smbca_speed;
420 	cap->smba_etype = c.smbca_etype;
421 	cap->smba_ltype = c.smbca_ltype;
422 	cap->smba_assoc = c.smbca_assoc;
423 	cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config);
424 	cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config);
425 	cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config);
426 
427 	if (SMB_CACHE_CFG_ENABLED(c.smbca_config))
428 		cap->smba_flags |= SMB_CAF_ENABLED;
429 
430 	if (SMB_CACHE_CFG_SOCKETED(c.smbca_config))
431 		cap->smba_flags |= SMB_CAF_SOCKETED;
432 
433 	return (0);
434 }
435 
436 int
437 smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop)
438 {
439 	const smb_struct_t *stp = smb_lookup_id(shp, id);
440 	smb_port_t p;
441 
442 	if (stp == NULL)
443 		return (-1); /* errno is set for us */
444 
445 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT)
446 		return (smb_set_errno(shp, ESMB_TYPE));
447 
448 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
449 	bzero(pop, sizeof (smbios_port_t));
450 
451 	pop->smbo_iref = smb_strptr(stp, p.smbpo_iref);
452 	pop->smbo_eref = smb_strptr(stp, p.smbpo_eref);
453 
454 	pop->smbo_itype = p.smbpo_itype;
455 	pop->smbo_etype = p.smbpo_etype;
456 	pop->smbo_ptype = p.smbpo_ptype;
457 
458 	return (0);
459 }
460 
461 int
462 smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp)
463 {
464 	const smb_struct_t *stp = smb_lookup_id(shp, id);
465 	smb_slot_t s;
466 
467 	if (stp == NULL)
468 		return (-1); /* errno is set for us */
469 
470 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
471 		return (smb_set_errno(shp, ESMB_TYPE));
472 
473 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
474 	bzero(sp, sizeof (smbios_slot_t));
475 
476 	sp->smbl_name = smb_strptr(stp, s.smbsl_name);
477 	sp->smbl_type = s.smbsl_type;
478 	sp->smbl_width = s.smbsl_width;
479 	sp->smbl_usage = s.smbsl_usage;
480 	sp->smbl_length = s.smbsl_length;
481 	sp->smbl_id = s.smbsl_id;
482 	sp->smbl_ch1 = s.smbsl_ch1;
483 	sp->smbl_ch2 = s.smbsl_ch2;
484 
485 	return (0);
486 }
487 
488 int
489 smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp)
490 {
491 	const smb_struct_t *stp = smb_lookup_id(shp, id);
492 	const smb_obdev_t *op;
493 	int i, m, n;
494 
495 	if (stp == NULL)
496 		return (-1); /* errno is set for us */
497 
498 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS)
499 		return (smb_set_errno(shp, ESMB_TYPE));
500 
501 	op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t));
502 	m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op);
503 	n = MIN(m, obc);
504 
505 	for (i = 0; i < n; i++, op++, obp++) {
506 		obp->smbd_name = smb_strptr(stp, op->smbob_name);
507 		obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED;
508 		obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0;
509 	}
510 
511 	return (m);
512 }
513 
514 /*
515  * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the
516  * first byte to indicate the size of a string table at the end of the record.
517  * Therefore, smbios_info_strtab() can be used to retrieve the table size and
518  * strings for any of these underlying record types.
519  */
520 int
521 smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[])
522 {
523 	const smb_struct_t *stp = smb_lookup_id(shp, id);
524 	smb_strtab_t s;
525 	int i, n;
526 
527 	if (stp == NULL)
528 		return (-1); /* errno is set for us */
529 
530 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR &&
531 	    stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR &&
532 	    stp->smbst_hdr->smbh_type != SMB_TYPE_LANG)
533 		return (smb_set_errno(shp, ESMB_TYPE));
534 
535 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
536 	n = MIN(s.smbtb_count, argc);
537 
538 	for (i = 0; i < n; i++)
539 		argv[i] = smb_strptr(stp, i + 1);
540 
541 	return (s.smbtb_count);
542 }
543 
544 id_t
545 smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp)
546 {
547 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG);
548 	smb_lang_t l;
549 
550 	if (stp == NULL)
551 		return (-1); /* errno is set for us */
552 
553 	smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l));
554 	bzero(lp, sizeof (smbios_lang_t));
555 
556 	lp->smbla_cur = smb_strptr(stp, l.smblang_cur);
557 	lp->smbla_fmt = l.smblang_flags & 1;
558 	lp->smbla_num = l.smblang_num;
559 
560 	return (stp->smbst_hdr->smbh_hdl);
561 }
562 
563 id_t
564 smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp)
565 {
566 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG);
567 	const smb_sel_t *sel;
568 	size_t len;
569 
570 	if (stp == NULL)
571 		return (-1); /* errno is set for us */
572 
573 	if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t))
574 		return (smb_set_errno(shp, ESMB_CORRUPT));
575 
576 	sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr;
577 	len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t);
578 	bzero(evp, sizeof (smbios_evlog_t));
579 
580 	if (len < sel->smbsel_typec * sel->smbsel_typesz)
581 		return (smb_set_errno(shp, ESMB_CORRUPT));
582 
583 	evp->smbev_size = sel->smbsel_len;
584 	evp->smbev_hdr = sel->smbsel_hdroff;
585 	evp->smbev_data = sel->smbsel_dataoff;
586 	evp->smbev_method = sel->smbsel_method;
587 	evp->smbev_flags = sel->smbsel_status;
588 	evp->smbev_format = sel->smbsel_format;
589 	evp->smbev_token = sel->smbsel_token;
590 	evp->smbev_addr.eva_addr = sel->smbsel_addr;
591 
592 	if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) {
593 		evp->smbev_typec = sel->smbsel_typec;
594 		evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev;
595 	}
596 
597 	return (stp->smbst_hdr->smbh_hdl);
598 }
599 
600 int
601 smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map)
602 {
603 	const smb_struct_t *stp = smb_lookup_id(shp, id);
604 	smb_memarray_t m;
605 
606 	if (stp == NULL)
607 		return (-1); /* errno is set for us */
608 
609 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY)
610 		return (smb_set_errno(shp, ESMB_TYPE));
611 
612 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
613 	bzero(map, sizeof (smbios_memarray_t));
614 
615 	map->smbma_location = m.smbmarr_loc;
616 	map->smbma_use = m.smbmarr_use;
617 	map->smbma_ecc = m.smbmarr_ecc;
618 	map->smbma_ndevs = m.smbmarr_ndevs;
619 	map->smbma_err = m.smbmarr_err;
620 
621 	if (m.smbmarr_cap != 0x80000000)
622 		map->smbma_size = (uint64_t)m.smbmarr_cap * 1024;
623 	else
624 		map->smbma_size = 0; /* unknown */
625 
626 	return (0);
627 }
628 
629 int
630 smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map)
631 {
632 	const smb_struct_t *stp = smb_lookup_id(shp, id);
633 	smb_memarrmap_t m;
634 
635 	if (stp == NULL)
636 		return (-1); /* errno is set for us */
637 
638 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP)
639 		return (smb_set_errno(shp, ESMB_TYPE));
640 
641 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
642 	bzero(map, sizeof (smbios_memarrmap_t));
643 
644 	map->smbmam_array = m.smbamap_array;
645 	map->smbmam_width = m.smbamap_width;
646 	map->smbmam_addr = (uint64_t)m.smbamap_start * 1024;
647 	map->smbmam_size = (uint64_t)
648 	    (m.smbamap_end - m.smbamap_start + 1) * 1024;
649 
650 	return (0);
651 }
652 
653 int
654 smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp)
655 {
656 	const smb_struct_t *stp = smb_lookup_id(shp, id);
657 	smb_memdevice_t m;
658 
659 	if (stp == NULL)
660 		return (-1); /* errno is set for us */
661 
662 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE)
663 		return (smb_set_errno(shp, ESMB_TYPE));
664 
665 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
666 	bzero(mdp, sizeof (smbios_memdevice_t));
667 
668 	mdp->smbmd_array = m.smbmdev_array;
669 	mdp->smbmd_error = m.smbmdev_error;
670 	mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth;
671 	mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth;
672 
673 	if (mdp->smbmd_size != 0xFFFF) {
674 		mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES);
675 		if (m.smbmdev_size & SMB_MDS_KBYTES)
676 			mdp->smbmd_size *= 1024;
677 		else
678 			mdp->smbmd_size *= 1024 * 1024;
679 	} else
680 		mdp->smbmd_size = -1ULL; /* size unknown */
681 
682 	mdp->smbmd_form = m.smbmdev_form;
683 	mdp->smbmd_set = m.smbmdev_set;
684 	mdp->smbmd_type = m.smbmdev_type;
685 	mdp->smbmd_flags = m.smbmdev_flags;
686 	mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc);
687 	mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc);
688 
689 	if (m.smbmdev_speed != 0)
690 		mdp->smbmd_speed = 1000 / m.smbmdev_speed; /* MHz -> nsec */
691 
692 	return (0);
693 }
694 
695 int
696 smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp)
697 {
698 	const smb_struct_t *stp = smb_lookup_id(shp, id);
699 	smb_memdevmap_t m;
700 
701 	if (stp == NULL)
702 		return (-1); /* errno is set for us */
703 
704 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP)
705 		return (smb_set_errno(shp, ESMB_TYPE));
706 
707 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
708 	bzero(mdp, sizeof (smbios_memdevmap_t));
709 
710 	mdp->smbmdm_device = m.smbdmap_device;
711 	mdp->smbmdm_arrmap = m.smbdmap_array;
712 	mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024;
713 	mdp->smbmdm_size = (uint64_t)
714 	    (m.smbdmap_end - m.smbdmap_start + 1) * 1024;
715 	mdp->smbmdm_rpos = m.smbdmap_rpos;
716 	mdp->smbmdm_ipos = m.smbdmap_ipos;
717 	mdp->smbmdm_idepth = m.smbdmap_idepth;
718 
719 	return (0);
720 }
721 
722 id_t
723 smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp)
724 {
725 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY);
726 	smb_hwsec_t hs;
727 
728 	if (stp == NULL)
729 		return (-1); /* errno is set for us */
730 
731 	smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
732 	bzero(hsp, sizeof (smbios_hwsec_t));
733 
734 	hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
735 	hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
736 	hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
737 	hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
738 
739 	return (stp->smbst_hdr->smbh_hdl);
740 }
741 
742 id_t
743 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
744 {
745 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
746 	const smb_boot_t *b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
747 
748 	if (stp == NULL)
749 		return (-1); /* errno is set for us */
750 
751 	bzero(bp, sizeof (smbios_boot_t));
752 
753 	bp->smbt_status = b->smbbo_status[0];
754 	bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
755 	bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
756 
757 	return (stp->smbst_hdr->smbh_hdl);
758 }
759 
760 id_t
761 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
762 {
763 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
764 	smb_ipmi_t i;
765 
766 	if (stp == NULL)
767 		return (-1); /* errno is set for us */
768 
769 	smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
770 	bzero(ip, sizeof (smbios_ipmi_t));
771 
772 	ip->smbip_type = i.smbipm_type;
773 	ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec);
774 	ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec);
775 	ip->smbip_i2c = i.smbipm_i2c;
776 	ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO;
777 	ip->smbip_intr = i.smbipm_intr;
778 
779 	if (i.smbipm_bus != (uint8_t)-1)
780 		ip->smbip_bus = i.smbipm_bus;
781 	else
782 		ip->smbip_bus = -1u;
783 
784 	if (SMB_IPM_INFO_LSB(i.smbipm_info))
785 		ip->smbip_addr |= 1; /* turn on least-significant bit of addr */
786 
787 	if (i.smbipm_addr & SMB_IPM_ADDR_IO) {
788 		switch (SMB_IPM_INFO_REGS(i.smbipm_info)) {
789 		case SMB_IPM_REGS_1B:
790 			ip->smbip_regspacing = 1;
791 			break;
792 		case SMB_IPM_REGS_4B:
793 			ip->smbip_regspacing = 4;
794 			break;
795 		case SMB_IPM_REGS_16B:
796 			ip->smbip_regspacing = 16;
797 			break;
798 		default:
799 			ip->smbip_regspacing = 1;
800 		}
801 		ip->smbip_flags |= SMB_IPMI_F_IOADDR;
802 	}
803 
804 	if (SMB_IPM_INFO_ISPEC(i.smbipm_info))
805 		ip->smbip_flags |= SMB_IPMI_F_INTRSPEC;
806 
807 	if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI)
808 		ip->smbip_flags |= SMB_IPMI_F_INTRHIGH;
809 
810 	if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE)
811 		ip->smbip_flags |= SMB_IPMI_F_INTREDGE;
812 
813 	return (stp->smbst_hdr->smbh_hdl);
814 }
815