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