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 2019 Joyent, Inc. 25 * Copyright 2024 Oxide Computer Company 26 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 27 * Use is subject to license terms. 28 */ 29 30 /* 31 * SMBIOS Information Routines 32 * 33 * The routines in this file are used to convert from the SMBIOS data format to 34 * a more reasonable and stable set of structures offered as part of our ABI. 35 * These functions take the general form: 36 * 37 * stp = smb_lookup_type(shp, foo); 38 * smb_foo_t foo; 39 * 40 * smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo)); 41 * bzero(caller's struct); 42 * 43 * copy/convert foo members into caller's struct 44 * 45 * We copy the internal structure on to an automatic variable so as to avoid 46 * checks everywhere for structures that the BIOS has improperly truncated, and 47 * also to automatically handle the case of a structure that has been extended. 48 * When necessary, this code can use smb_gteq() to determine whether the SMBIOS 49 * data is of a particular revision that is supposed to contain a new field. 50 * 51 * Note, when trying to bzero the caller's struct you have to be careful about 52 * versions. One can only bzero the initial version that existed in illumos. In 53 * other words, if someone passes an older library handle that doesn't support a 54 * version you cannot assume that their structures have those additional members 55 * in them. Instead, a 'base' version is introduced for such types that have 56 * differences and instead we only bzero out the base version and then handle 57 * the additional members. In general, because all additional members will be 58 * assigned, there's no reason to zero them out unless they are arrays that 59 * won't be entirely filled in. 60 * 61 * Due to history, anything added after the update from version 2.4, in other 62 * words additions from or after '5094 Update libsmbios with recent items' 63 * (4e901881) is currently being used for this. While we don't allow software 64 * compiling against this to get an older form, this was the first major update 65 * and a good starting point for us to enforce this behavior which is useful for 66 * moving forward to making this more public. 67 */ 68 69 #include <sys/smbios_impl.h> 70 #include <sys/byteorder.h> 71 #include <sys/debug.h> 72 73 #ifdef _KERNEL 74 #include <sys/sunddi.h> 75 #else 76 #include <fcntl.h> 77 #include <unistd.h> 78 #include <string.h> 79 #endif 80 81 #define SMB_CONT_WORD 2 /* contained elements are word size */ 82 83 /* 84 * A large number of SMBIOS structures contain a set of common strings used to 85 * describe a h/w component's serial number, manufacturer, etc. These fields 86 * helpfully have different names and offsets and sometimes aren't consistent. 87 * To simplify life for our clients, we factor these common things out into 88 * smbios_info_t, which can be retrieved for any structure. The following 89 * table describes the mapping from a given structure to the smbios_info_t. 90 * Multiple SMBIOS stuctures' contained objects are also handled here. 91 */ 92 static const struct smb_infospec { 93 uint8_t is_type; /* structure type */ 94 uint8_t is_manu; /* manufacturer offset */ 95 uint8_t is_product; /* product name offset */ 96 uint8_t is_version; /* version offset */ 97 uint8_t is_serial; /* serial number offset */ 98 uint8_t is_asset; /* asset tag offset */ 99 uint8_t is_location; /* location string offset */ 100 uint8_t is_part; /* part number offset */ 101 uint8_t is_contc; /* contained count */ 102 uint8_t is_contsz; /* contained size */ 103 uint8_t is_contv; /* contained objects */ 104 } _smb_infospecs[] = { 105 { SMB_TYPE_SYSTEM, 106 offsetof(smb_system_t, smbsi_manufacturer), 107 offsetof(smb_system_t, smbsi_product), 108 offsetof(smb_system_t, smbsi_version), 109 offsetof(smb_system_t, smbsi_serial), 110 0, 111 0, 112 0, 113 0, 114 0, 115 0 }, 116 { SMB_TYPE_BASEBOARD, 117 offsetof(smb_bboard_t, smbbb_manufacturer), 118 offsetof(smb_bboard_t, smbbb_product), 119 offsetof(smb_bboard_t, smbbb_version), 120 offsetof(smb_bboard_t, smbbb_serial), 121 offsetof(smb_bboard_t, smbbb_asset), 122 offsetof(smb_bboard_t, smbbb_location), 123 0, 124 offsetof(smb_bboard_t, smbbb_cn), 125 SMB_CONT_WORD, 126 offsetof(smb_bboard_t, smbbb_cv) }, 127 { SMB_TYPE_CHASSIS, 128 offsetof(smb_chassis_t, smbch_manufacturer), 129 0, 130 offsetof(smb_chassis_t, smbch_version), 131 offsetof(smb_chassis_t, smbch_serial), 132 offsetof(smb_chassis_t, smbch_asset), 133 0, 134 0, 135 0, 136 0, 137 0 }, 138 { SMB_TYPE_PROCESSOR, 139 offsetof(smb_processor_t, smbpr_manufacturer), 140 0, 141 offsetof(smb_processor_t, smbpr_version), 142 offsetof(smb_processor_t, smbpr_serial), 143 offsetof(smb_processor_t, smbpr_asset), 144 offsetof(smb_processor_t, smbpr_socket), 145 offsetof(smb_processor_t, smbpr_part), 146 0, 147 0, 148 0 }, 149 { SMB_TYPE_CACHE, 150 0, 151 0, 152 0, 153 0, 154 0, 155 offsetof(smb_cache_t, smbca_socket), 156 0, 157 0, 158 0, 159 0 }, 160 { SMB_TYPE_PORT, 161 0, 162 0, 163 0, 164 0, 165 0, 166 offsetof(smb_port_t, smbpo_iref), 167 0, 168 0, 169 0, 170 0 }, 171 { SMB_TYPE_SLOT, 172 0, 173 0, 174 0, 175 0, 176 0, 177 offsetof(smb_slot_t, smbsl_name), 178 0, 179 0, 180 0, 181 0 }, 182 { SMB_TYPE_MEMDEVICE, 183 offsetof(smb_memdevice_t, smbmdev_manufacturer), 184 0, 185 0, 186 offsetof(smb_memdevice_t, smbmdev_serial), 187 offsetof(smb_memdevice_t, smbmdev_asset), 188 offsetof(smb_memdevice_t, smbmdev_dloc), 189 offsetof(smb_memdevice_t, smbmdev_part), 190 0, 191 0, 192 0 }, 193 { SMB_TYPE_POWERSUP, 194 offsetof(smb_powersup_t, smbpsup_manufacturer), 195 offsetof(smb_powersup_t, smbpsup_devname), 196 offsetof(smb_powersup_t, smbpsup_rev), 197 offsetof(smb_powersup_t, smbpsup_serial), 198 offsetof(smb_powersup_t, smbpsup_asset), 199 offsetof(smb_powersup_t, smbpsup_loc), 200 offsetof(smb_powersup_t, smbpsup_part), 201 0, 202 0, 203 0 }, 204 { SMB_TYPE_BATTERY, 205 offsetof(smb_battery_t, smbbat_manufacturer), 206 offsetof(smb_battery_t, smbbat_devname), 207 0, 208 /* 209 * While the serial number is a part of the device, because of 210 * the fact that the battery has two different serial numbers, 211 * we don't include it here. 212 */ 213 0, 214 0, 215 offsetof(smb_battery_t, smbbat_loc), 216 0, 217 0, 218 0, 219 0 220 }, 221 { SMB_TYPE_FWINFO, 222 offsetof(smb_fwinfo_t, smbfwii_mfg), 223 0, 224 offsetof(smb_fwinfo_t, smbfwii_vers), 225 0, 226 0, 227 0, 228 0, 229 0, 230 0, 231 0 232 }, 233 { SMB_TYPE_EOT } 234 }; 235 236 static const char * 237 smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n) 238 { 239 const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr; 240 241 if (off != 0 && sp + off < stp->smbst_end) { 242 (*n)++; /* indicate success for caller */ 243 return (smb_strptr(stp, sp[off])); 244 } 245 246 return (smb_strptr(stp, 0)); 247 } 248 249 static void 250 smb_info_bcopy_offset(const smb_header_t *hp, void *dst, size_t dstlen, 251 size_t offset) 252 { 253 if (offset >= hp->smbh_len) { 254 bzero(dst, dstlen); 255 } else if (offset + dstlen > hp->smbh_len) { 256 size_t nvalid = MIN(hp->smbh_len - offset, dstlen); 257 bcopy((char *)hp + offset, dst, nvalid); 258 bzero((char *)dst + nvalid, dstlen - nvalid); 259 } else { 260 bcopy((char *)hp + offset, dst, dstlen); 261 } 262 } 263 264 static void 265 smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen) 266 { 267 return (smb_info_bcopy_offset(hp, dst, dstlen, 0)); 268 } 269 270 smbios_entry_point_t 271 smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep) 272 { 273 bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t)); 274 return (shp->sh_ent_type); 275 } 276 277 void 278 smbios_info_smbios_version(smbios_hdl_t *shp, smbios_version_t *v) 279 { 280 v->smbv_major = SMB_MAJOR(shp->sh_smbvers); 281 v->smbv_minor = SMB_MINOR(shp->sh_smbvers); 282 } 283 284 #ifndef _KERNEL 285 static char smbios_product_override[256]; 286 static boolean_t smbios_product_checked; 287 #endif 288 289 int 290 smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip) 291 { 292 const smb_struct_t *stp = smb_lookup_id(shp, id); 293 const struct smb_infospec *isp; 294 int n = 0; 295 296 if (stp == NULL) 297 return (-1); /* errno is set for us */ 298 299 for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) { 300 if (isp->is_type == stp->smbst_hdr->smbh_type) 301 break; 302 } 303 304 ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n); 305 ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n); 306 ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n); 307 ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n); 308 ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n); 309 ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n); 310 ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n); 311 312 /* 313 * This private file allows developers to experiment with reporting 314 * different platform strings from SMBIOS. It is not a supported 315 * mechanism in the long term, and does not work in the kernel. 316 */ 317 #ifndef _KERNEL 318 if (isp->is_type == SMB_TYPE_SYSTEM) { 319 if (!smbios_product_checked) { 320 int fd = open("/etc/smbios_product", O_RDONLY); 321 if (fd >= 0) { 322 (void) read(fd, smbios_product_override, 323 sizeof (smbios_product_override) - 1); 324 (void) close(fd); 325 } 326 smbios_product_checked = B_TRUE; 327 } 328 329 if (smbios_product_override[0] != '\0') 330 ip->smbi_product = smbios_product_override; 331 } 332 #endif 333 334 /* 335 * If we have a port with an empty internal reference designator string 336 * try using the external reference designator string instead. 337 */ 338 if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') { 339 ip->smbi_location = smb_info_strptr(stp, 340 offsetof(smb_port_t, smbpo_eref), &n); 341 } 342 343 return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO)); 344 } 345 346 /* 347 * Returns the actual number of contained objects. 348 * 349 * idc - number of contained objects 350 * idv - returned array of contained objects 351 */ 352 int 353 smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv) 354 { 355 const smb_struct_t *stp = smb_lookup_id(shp, id); 356 const struct smb_infospec *isp; 357 id_t *cp; 358 uint_t size; 359 uint8_t cnt; 360 int i, n; 361 362 if (stp == NULL) { 363 return (-1); /* errno is set for us */ 364 } 365 366 for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) { 367 if (isp->is_type == stp->smbst_hdr->smbh_type) 368 break; 369 } 370 if (isp->is_type == SMB_TYPE_EOT) 371 return (smb_set_errno(shp, ESMB_TYPE)); 372 373 size = isp->is_contsz; 374 cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc); 375 cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv); 376 377 n = MIN(cnt, idc); 378 for (i = 0; i < n; i++) { 379 if (size == SMB_CONT_WORD) 380 idv[i] = *((uint16_t *)(uintptr_t)cp + (i * 2)); 381 else 382 return (smb_set_errno(shp, ESMB_INVAL)); 383 } 384 385 return (cnt); 386 } 387 388 id_t 389 smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp) 390 { 391 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS); 392 const smb_bios_t *bip; 393 394 if (stp == NULL) 395 return (-1); /* errno is set for us */ 396 397 if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t)) 398 return (smb_set_errno(shp, ESMB_CORRUPT)); 399 400 bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr; 401 bzero(bp, sizeof (smb_base_bios_t)); 402 if (smb_libgteq(shp, SMB_VERSION_31)) { 403 bp->smbb_extromsize = 0; 404 } 405 406 bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor); 407 bp->smbb_version = smb_strptr(stp, bip->smbbi_version); 408 bp->smbb_segment = bip->smbbi_segment; 409 bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate); 410 bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1); 411 bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment); 412 bp->smbb_cflags = bip->smbbi_cflags; 413 414 /* 415 * If one or more extension bytes are present, reset smbb_xcflags to 416 * point to them. Otherwise leave this member set to NULL. 417 */ 418 if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) { 419 bp->smbb_xcflags = bip->smbbi_xcflags; 420 bp->smbb_nxcflags = stp->smbst_hdr->smbh_len - 421 sizeof (smb_bios_t) + 1; 422 423 if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN && 424 smb_gteq(shp, SMB_VERSION_24)) { 425 bp->smbb_biosv.smbv_major = 426 bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ]; 427 bp->smbb_biosv.smbv_minor = 428 bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN]; 429 bp->smbb_ecfwv.smbv_major = 430 bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ]; 431 bp->smbb_ecfwv.smbv_minor = 432 bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN]; 433 } 434 435 if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 && 436 smb_gteq(shp, SMB_VERSION_31)) { 437 uint16_t val; 438 uint64_t rs; 439 440 /* 441 * Because of the fact that the extended size is a 442 * uint16_t and we'd need to define an explicit 443 * endian-aware way to access it, we don't include it in 444 * the number of extended flags below and thus subtract 445 * its size. 446 */ 447 bp->smbb_nxcflags -= sizeof (uint16_t); 448 bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val, 449 sizeof (val)); 450 val = LE_16(val); 451 452 /* 453 * The upper two bits of the extended rom size are used 454 * to indicate whether the other 14 bits are in MB or 455 * GB. 456 */ 457 rs = SMB_BIOS_EXTROM_VALUE_MASK(val); 458 switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) { 459 case 0: 460 rs *= 1024ULL * 1024ULL; 461 break; 462 case 1: 463 rs *= 1024ULL * 1024ULL * 1024ULL; 464 break; 465 default: 466 rs = 0; 467 break; 468 } 469 470 if (smb_libgteq(shp, SMB_VERSION_31)) { 471 bp->smbb_extromsize = rs; 472 } 473 } 474 } 475 476 if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) { 477 bp->smbb_extromsize = bp->smbb_romsize; 478 } 479 480 return (stp->smbst_hdr->smbh_hdl); 481 } 482 483 id_t 484 smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip) 485 { 486 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM); 487 smb_system_t si; 488 489 if (stp == NULL) 490 return (-1); /* errno is set for us */ 491 492 smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si)); 493 bzero(sip, sizeof (smbios_system_t)); 494 495 sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid; 496 sip->smbs_uuidlen = sizeof (si.smbsi_uuid); 497 sip->smbs_wakeup = si.smbsi_wakeup; 498 sip->smbs_sku = smb_strptr(stp, si.smbsi_sku); 499 sip->smbs_family = smb_strptr(stp, si.smbsi_family); 500 501 return (stp->smbst_hdr->smbh_hdl); 502 } 503 504 int 505 smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp) 506 { 507 const smb_struct_t *stp = smb_lookup_id(shp, id); 508 smb_bboard_t bb; 509 510 if (stp == NULL) 511 return (-1); /* errno is set for us */ 512 513 if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD) 514 return (smb_set_errno(shp, ESMB_TYPE)); 515 516 smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb)); 517 bzero(bbp, sizeof (smbios_bboard_t)); 518 519 bbp->smbb_chassis = bb.smbbb_chassis; 520 bbp->smbb_flags = bb.smbbb_flags; 521 bbp->smbb_type = bb.smbbb_type; 522 bbp->smbb_contn = bb.smbbb_cn; 523 524 return (0); 525 } 526 527 int 528 smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp) 529 { 530 const smb_struct_t *stp = smb_lookup_id(shp, id); 531 off_t skuoff; 532 smb_chassis_t ch; 533 534 if (stp == NULL) { 535 return (-1); /* errno is set for us */ 536 } 537 538 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS) { 539 return (smb_set_errno(shp, ESMB_TYPE)); 540 } 541 542 /* 543 * The minimum table length for the chassis is 0xd, which is the 544 * starting point of the OEM data. This was set in SMBIOS 2.1. We don't 545 * consider SMBIOS 2.0 tables right now. 546 */ 547 if (stp->smbst_hdr->smbh_len < offsetof(smb_chassis_t, smbch_oemdata)) { 548 return (smb_set_errno(shp, ESMB_SHORT)); 549 } 550 551 smb_info_bcopy(stp->smbst_hdr, &ch, sizeof (ch)); 552 bzero(chp, sizeof (smb_base_chassis_t)); 553 554 /* 555 * See the comments for the smb_chassis_pre35_t in sys/smbios_impl.h for 556 * an explanation as to why this is here. The use of smb_strptr with 557 * index 0 below ensures that we initialize this to an empty string. 558 */ 559 if (smb_libgteq(shp, SMB_VERSION_35)) { 560 chp->smbc_sku = smb_strptr(stp, 0); 561 } else if (smb_libgteq(shp, SMB_VERSION_27)) { 562 smb_chassis_pre35_t *p35 = (smb_chassis_pre35_t *)chp; 563 bzero(p35->smbc_sku, sizeof (p35->smbc_sku)); 564 } 565 566 chp->smbc_oemdata = ch.smbch_oemdata; 567 chp->smbc_lock = (ch.smbch_type & SMB_CHT_LOCK) != 0; 568 chp->smbc_type = ch.smbch_type & ~SMB_CHT_LOCK; 569 chp->smbc_bustate = ch.smbch_bustate; 570 chp->smbc_psstate = ch.smbch_psstate; 571 chp->smbc_thstate = ch.smbch_thstate; 572 chp->smbc_security = ch.smbch_security; 573 chp->smbc_uheight = ch.smbch_uheight; 574 chp->smbc_cords = ch.smbch_cords; 575 chp->smbc_elems = ch.smbch_cn; 576 chp->smbc_elemlen = ch.smbch_cm; 577 578 /* 579 * If the table is older than version 2.7 which added support for the 580 * chassis SKU, there's no reason to proceed. A 2.7 table is not 581 * required to have support for a chassis SKU so we don't proceed either 582 * if there isn't space for the SKU byte. This is very common of 583 * hypervisors. 584 */ 585 skuoff = sizeof (ch) + ch.smbch_cn * ch.smbch_cm; 586 if (!smb_gteq(shp, SMB_VERSION_27) || 587 stp->smbst_hdr->smbh_len < skuoff + 1) { 588 return (0); 589 } 590 591 if (smb_libgteq(shp, SMB_VERSION_27)) { 592 uint8_t strno; 593 const char *str; 594 595 smb_info_bcopy_offset(stp->smbst_hdr, &strno, sizeof (strno), 596 skuoff); 597 str = smb_strptr(stp, strno); 598 if (smb_libgteq(shp, SMB_VERSION_35)) { 599 chp->smbc_sku = str; 600 } else { 601 smb_chassis_pre35_t *p35 = (smb_chassis_pre35_t *)chp; 602 (void) strlcpy(p35->smbc_sku, str, 603 sizeof (p35->smbc_sku)); 604 } 605 } 606 607 return (0); 608 } 609 610 int 611 smbios_info_chassis_elts(smbios_hdl_t *shp, id_t id, uint_t *nentsp, 612 smbios_chassis_entry_t **entsp) 613 { 614 const smb_struct_t *stp = smb_lookup_id(shp, id); 615 smbios_chassis_entry_t *entry; 616 smb_chassis_t ch; 617 size_t entlen; 618 uint_t i; 619 620 if (stp == NULL) { 621 return (-1); /* errno is set for us */ 622 } 623 624 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS) { 625 return (smb_set_errno(shp, ESMB_TYPE)); 626 } 627 628 /* 629 * We don't explicitly check the length of the table as it is legal for 630 * the chassis table to be shorter than something that contains the 631 * number of elements. 632 */ 633 smb_info_bcopy(stp->smbst_hdr, &ch, sizeof (ch)); 634 if (ch.smbch_cn == 0) { 635 *nentsp = 0; 636 *entsp = NULL; 637 return (0); 638 } 639 640 if (ch.smbch_cm != sizeof (smb_chassis_entry_t)) { 641 return (smb_set_errno(shp, ESMB_CORRUPT)); 642 } 643 644 entlen = ch.smbch_cm * ch.smbch_cn; 645 if (stp->smbst_hdr->smbh_len < sizeof (ch) + entlen) { 646 return (smb_set_errno(shp, ESMB_SHORT)); 647 } 648 649 if ((entry = smb_alloc(entlen)) == NULL) { 650 return (smb_set_errno(shp, ESMB_NOMEM)); 651 } 652 653 for (i = 0; i < ch.smbch_cn; i++) { 654 smb_chassis_entry_t e; 655 size_t off = sizeof (ch) + i * sizeof (e); 656 657 smb_info_bcopy_offset(stp->smbst_hdr, &e, sizeof (e), off); 658 /* 659 * The top bit is used to indicate what type of record this is, 660 * while the lower 7-bits indicate the actual type. 661 */ 662 entry[i].smbce_type = e.smbce_type & 0x80 ? 663 SMB_CELT_SMBIOS : SMB_CELT_BBOARD; 664 entry[i].smbce_elt = e.smbce_type & 0x7f; 665 entry[i].smbce_min = e.smbce_min; 666 entry[i].smbce_max = e.smbce_max; 667 } 668 669 *entsp = entry; 670 *nentsp = ch.smbch_cn; 671 672 return (0); 673 } 674 675 void 676 smbios_info_chassis_elts_free(smbios_hdl_t *shp, uint_t nents, 677 smbios_chassis_entry_t *ent) 678 { 679 size_t sz = nents * sizeof (smbios_chassis_entry_t); 680 681 if (nents == 0) { 682 ASSERT3P(ent, ==, NULL); 683 return; 684 } 685 686 smb_free(ent, sz); 687 } 688 689 int 690 smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp) 691 { 692 const smb_struct_t *stp = smb_lookup_id(shp, id); 693 smb_processor_t p; 694 695 if (stp == NULL) 696 return (-1); /* errno is set for us */ 697 698 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR) 699 return (smb_set_errno(shp, ESMB_TYPE)); 700 701 smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p)); 702 bzero(pp, sizeof (smb_base_processor_t)); 703 704 pp->smbp_cpuid = p.smbpr_cpuid; 705 pp->smbp_type = p.smbpr_type; 706 pp->smbp_family = p.smbpr_family; 707 pp->smbp_voltage = p.smbpr_voltage; 708 pp->smbp_clkspeed = p.smbpr_clkspeed; 709 pp->smbp_maxspeed = p.smbpr_maxspeed; 710 pp->smbp_curspeed = p.smbpr_curspeed; 711 pp->smbp_status = p.smbpr_status; 712 pp->smbp_upgrade = p.smbpr_upgrade; 713 pp->smbp_l1cache = p.smbpr_l1cache; 714 pp->smbp_l2cache = p.smbpr_l2cache; 715 pp->smbp_l3cache = p.smbpr_l3cache; 716 717 if (smb_libgteq(shp, SMB_VERSION_25)) { 718 pp->smbp_corecount = p.smbpr_corecount; 719 pp->smbp_coresenabled = p.smbpr_coresenabled; 720 pp->smbp_threadcount = p.smbpr_threadcount; 721 pp->smbp_cflags = p.smbpr_cflags; 722 } 723 724 if (smb_libgteq(shp, SMB_VERSION_26)) { 725 if (pp->smbp_family == 0xfe) { 726 pp->smbp_family = p.smbpr_family2; 727 } 728 } 729 730 if (smb_libgteq(shp, SMB_VERSION_30)) { 731 if (pp->smbp_corecount == 0xff) { 732 pp->smbp_corecount = p.smbpr_corecount2; 733 } 734 if (pp->smbp_coresenabled == 0xff) { 735 pp->smbp_coresenabled = p.smbpr_coresenabled2; 736 } 737 if (pp->smbp_threadcount == 0xff) { 738 pp->smbp_threadcount = p.smbpr_threadcount2; 739 } 740 } 741 742 if (smb_libgteq(shp, SMB_VERSION_36)) { 743 pp->smbp_threadsenabled = p.smpbr_threaden; 744 } 745 746 return (0); 747 } 748 749 int 750 smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap) 751 { 752 const smb_struct_t *stp = smb_lookup_id(shp, id); 753 smb_cache_t c; 754 755 if (stp == NULL) 756 return (-1); /* errno is set for us */ 757 758 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE) 759 return (smb_set_errno(shp, ESMB_TYPE)); 760 761 smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c)); 762 bzero(cap, sizeof (smb_base_cache_t)); 763 764 cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize); 765 cap->smba_size = SMB_CACHE_SIZE(c.smbca_size); 766 cap->smba_stype = c.smbca_stype; 767 cap->smba_ctype = c.smbca_ctype; 768 cap->smba_speed = c.smbca_speed; 769 cap->smba_etype = c.smbca_etype; 770 cap->smba_ltype = c.smbca_ltype; 771 cap->smba_assoc = c.smbca_assoc; 772 cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config); 773 cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config); 774 cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config); 775 776 if (SMB_CACHE_CFG_ENABLED(c.smbca_config)) 777 cap->smba_flags |= SMB_CAF_ENABLED; 778 779 if (SMB_CACHE_CFG_SOCKETED(c.smbca_config)) 780 cap->smba_flags |= SMB_CAF_SOCKETED; 781 782 if (smb_libgteq(shp, SMB_VERSION_31)) { 783 cap->smba_maxsize2 = SMB_CACHE_EXT_SIZE(c.smbca_maxsize2); 784 cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2); 785 786 if (cap->smba_maxsize2 == 0) { 787 cap->smba_maxsize2 = cap->smba_maxsize; 788 } 789 790 if (cap->smba_size2 == 0) { 791 cap->smba_size2 = cap->smba_size; 792 } 793 } 794 795 return (0); 796 } 797 798 int 799 smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop) 800 { 801 const smb_struct_t *stp = smb_lookup_id(shp, id); 802 smb_port_t p; 803 804 if (stp == NULL) 805 return (-1); /* errno is set for us */ 806 807 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT) 808 return (smb_set_errno(shp, ESMB_TYPE)); 809 810 smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p)); 811 bzero(pop, sizeof (smbios_port_t)); 812 813 pop->smbo_iref = smb_strptr(stp, p.smbpo_iref); 814 pop->smbo_eref = smb_strptr(stp, p.smbpo_eref); 815 816 pop->smbo_itype = p.smbpo_itype; 817 pop->smbo_etype = p.smbpo_etype; 818 pop->smbo_ptype = p.smbpo_ptype; 819 820 return (0); 821 } 822 823 int 824 smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) 825 { 826 const smb_struct_t *stp = smb_lookup_id(shp, id); 827 smb_slot_t s; 828 smb_slot_cont_t cont; 829 size_t off; 830 831 if (stp == NULL) 832 return (-1); /* errno is set for us */ 833 834 if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT) 835 return (smb_set_errno(shp, ESMB_TYPE)); 836 837 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 838 bzero(sp, sizeof (smb_base_slot_t)); 839 840 sp->smbl_name = smb_strptr(stp, s.smbsl_name); 841 sp->smbl_type = s.smbsl_type; 842 sp->smbl_width = s.smbsl_width; 843 sp->smbl_usage = s.smbsl_usage; 844 sp->smbl_length = s.smbsl_length; 845 sp->smbl_id = s.smbsl_id; 846 sp->smbl_ch1 = s.smbsl_ch1; 847 sp->smbl_ch2 = s.smbsl_ch2; 848 sp->smbl_sg = s.smbsl_sg; 849 sp->smbl_bus = s.smbsl_bus; 850 sp->smbl_df = s.smbsl_df; 851 852 if (smb_libgteq(shp, SMB_VERSION_32)) { 853 sp->smbl_dbw = s.smbsl_dbw; 854 sp->smbl_npeers = s.smbsl_npeers; 855 } 856 857 if (!smb_libgteq(shp, SMB_VERSION_34)) { 858 return (0); 859 } 860 861 /* 862 * In SMBIOS 3.4, several members were added to follow the variable 863 * number of peers. These are defined to start at byte 0x14 + 5 * 864 * npeers. If the table is from before 3.4, we simple zero things out. 865 * Otherwise we check if the length covers the peers and this addendum 866 * to include it as the table length is allowed to be less than this and 867 * not include it. 868 */ 869 off = SMB_SLOT_CONT_START + 5 * s.smbsl_npeers; 870 smb_info_bcopy_offset(stp->smbst_hdr, &cont, sizeof (cont), off); 871 sp->smbl_info = cont.smbsl_info; 872 sp->smbl_pwidth = cont.smbsl_pwidth; 873 sp->smbl_pitch = cont.smbsl_pitch; 874 875 if (smb_libgteq(shp, SMB_VERSION_35)) { 876 sp->smbl_height = cont.smbsl_height; 877 } 878 879 return (0); 880 } 881 882 void 883 smbios_info_slot_peers_free(smbios_hdl_t *shp, uint_t npeers, 884 smbios_slot_peer_t *peer) 885 { 886 size_t sz = npeers * sizeof (smbios_slot_peer_t); 887 888 if (npeers == 0) { 889 ASSERT3P(peer, ==, NULL); 890 return; 891 } 892 893 smb_free(peer, sz); 894 } 895 896 int 897 smbios_info_slot_peers(smbios_hdl_t *shp, id_t id, uint_t *npeers, 898 smbios_slot_peer_t **peerp) 899 { 900 const smb_struct_t *stp = smb_lookup_id(shp, id); 901 const smb_slot_t *slotp; 902 smbios_slot_peer_t *peer; 903 size_t minlen; 904 uint_t i; 905 906 if (stp == NULL) 907 return (-1); /* errno is set for us */ 908 909 slotp = (const smb_slot_t *)stp->smbst_hdr; 910 911 if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT) 912 return (smb_set_errno(shp, ESMB_TYPE)); 913 914 if (stp->smbst_hdr->smbh_len <= offsetof(smb_slot_t, smbsl_npeers) || 915 slotp->smbsl_npeers == 0) { 916 *npeers = 0; 917 *peerp = NULL; 918 return (0); 919 } 920 921 /* 922 * Make sure that the size of the structure makes sense for the number 923 * of peers reported. 924 */ 925 minlen = slotp->smbsl_npeers * sizeof (smb_slot_peer_t) + 926 offsetof(smb_slot_t, smbsl_npeers); 927 if (stp->smbst_hdr->smbh_len < minlen) { 928 return (smb_set_errno(shp, ESMB_SHORT)); 929 } 930 931 if ((peer = smb_alloc(slotp->smbsl_npeers * 932 sizeof (smbios_slot_peer_t))) == NULL) { 933 return (smb_set_errno(shp, ESMB_NOMEM)); 934 } 935 936 for (i = 0; i < slotp->smbsl_npeers; i++) { 937 peer[i].smblp_group = slotp->smbsl_peers[i].smbspb_group_no; 938 peer[i].smblp_bus = slotp->smbsl_peers[i].smbspb_bus; 939 peer[i].smblp_device = slotp->smbsl_peers[i].smbspb_df >> 3; 940 peer[i].smblp_function = slotp->smbsl_peers[i].smbspb_df & 0x7; 941 peer[i].smblp_data_width = slotp->smbsl_peers[i].smbspb_width; 942 } 943 944 *npeers = slotp->smbsl_npeers; 945 *peerp = peer; 946 947 return (0); 948 } 949 950 int 951 smbios_info_obdevs_ext(smbios_hdl_t *shp, id_t id, smbios_obdev_ext_t *oep) 952 { 953 const smb_struct_t *stp = smb_lookup_id(shp, id); 954 smb_obdev_ext_t obe; 955 956 if (stp == NULL) 957 return (-1); /* errno is set for us */ 958 959 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVEXT) 960 return (smb_set_errno(shp, ESMB_TYPE)); 961 962 smb_info_bcopy(stp->smbst_hdr, &obe, sizeof (obe)); 963 bzero(oep, sizeof (smbios_obdev_ext_t)); 964 965 oep->smboe_name = smb_strptr(stp, obe.smbobe_name); 966 oep->smboe_dtype = obe.smbobe_dtype; 967 oep->smboe_dti = obe.smbobe_dti; 968 oep->smboe_sg = obe.smbobe_sg; 969 oep->smboe_bus = obe.smbobe_bus; 970 oep->smboe_df = obe.smbobe_df; 971 972 return (0); 973 } 974 975 int 976 smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp) 977 { 978 const smb_struct_t *stp = smb_lookup_id(shp, id); 979 const smb_obdev_t *op; 980 int i, m, n; 981 982 if (stp == NULL) 983 return (-1); /* errno is set for us */ 984 985 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS) 986 return (smb_set_errno(shp, ESMB_TYPE)); 987 988 op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t)); 989 m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op); 990 n = MIN(m, obc); 991 992 for (i = 0; i < n; i++, op++, obp++) { 993 obp->smbd_name = smb_strptr(stp, op->smbob_name); 994 obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED; 995 obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0; 996 } 997 998 return (m); 999 } 1000 1001 /* 1002 * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the 1003 * first byte to indicate the size of a string table at the end of the record. 1004 * Therefore, smbios_info_strtab() can be used to retrieve the table size and 1005 * strings for any of these underlying record types. 1006 */ 1007 int 1008 smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[]) 1009 { 1010 const smb_struct_t *stp = smb_lookup_id(shp, id); 1011 smb_strtab_t s; 1012 int i, n; 1013 1014 if (stp == NULL) 1015 return (-1); /* errno is set for us */ 1016 1017 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR && 1018 stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR && 1019 stp->smbst_hdr->smbh_type != SMB_TYPE_LANG) 1020 return (smb_set_errno(shp, ESMB_TYPE)); 1021 1022 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 1023 n = MIN(s.smbtb_count, argc); 1024 1025 for (i = 0; i < n; i++) 1026 argv[i] = smb_strptr(stp, i + 1); 1027 1028 return (s.smbtb_count); 1029 } 1030 1031 id_t 1032 smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp) 1033 { 1034 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG); 1035 smb_lang_t l; 1036 1037 if (stp == NULL) 1038 return (-1); /* errno is set for us */ 1039 1040 smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l)); 1041 bzero(lp, sizeof (smbios_lang_t)); 1042 1043 lp->smbla_cur = smb_strptr(stp, l.smblang_cur); 1044 lp->smbla_fmt = l.smblang_flags & 1; 1045 lp->smbla_num = l.smblang_num; 1046 1047 return (stp->smbst_hdr->smbh_hdl); 1048 } 1049 1050 id_t 1051 smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp) 1052 { 1053 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG); 1054 const smb_sel_t *sel; 1055 size_t len; 1056 1057 if (stp == NULL) 1058 return (-1); /* errno is set for us */ 1059 1060 if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t)) 1061 return (smb_set_errno(shp, ESMB_CORRUPT)); 1062 1063 sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr; 1064 len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t); 1065 bzero(evp, sizeof (smbios_evlog_t)); 1066 1067 if (len < sel->smbsel_typec * sel->smbsel_typesz) 1068 return (smb_set_errno(shp, ESMB_CORRUPT)); 1069 1070 evp->smbev_size = sel->smbsel_len; 1071 evp->smbev_hdr = sel->smbsel_hdroff; 1072 evp->smbev_data = sel->smbsel_dataoff; 1073 evp->smbev_method = sel->smbsel_method; 1074 evp->smbev_flags = sel->smbsel_status; 1075 evp->smbev_format = sel->smbsel_format; 1076 evp->smbev_token = sel->smbsel_token; 1077 evp->smbev_addr.eva_addr = sel->smbsel_addr; 1078 1079 if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) { 1080 evp->smbev_typec = sel->smbsel_typec; 1081 evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev; 1082 } 1083 1084 return (stp->smbst_hdr->smbh_hdl); 1085 } 1086 1087 int 1088 smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map) 1089 { 1090 const smb_struct_t *stp = smb_lookup_id(shp, id); 1091 smb_memarray_t m; 1092 1093 if (stp == NULL) 1094 return (-1); /* errno is set for us */ 1095 1096 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY) 1097 return (smb_set_errno(shp, ESMB_TYPE)); 1098 1099 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 1100 bzero(map, sizeof (smbios_memarray_t)); 1101 1102 map->smbma_location = m.smbmarr_loc; 1103 map->smbma_use = m.smbmarr_use; 1104 map->smbma_ecc = m.smbmarr_ecc; 1105 map->smbma_ndevs = m.smbmarr_ndevs; 1106 map->smbma_err = m.smbmarr_err; 1107 1108 if (m.smbmarr_cap != 0x80000000) 1109 map->smbma_size = (uint64_t)m.smbmarr_cap * 1024; 1110 else if (m.smbmarr_extcap != 0) 1111 map->smbma_size = m.smbmarr_extcap; 1112 else 1113 map->smbma_size = 0; /* unknown */ 1114 1115 return (0); 1116 } 1117 1118 int 1119 smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map) 1120 { 1121 const smb_struct_t *stp = smb_lookup_id(shp, id); 1122 smb_memarrmap_t m; 1123 1124 if (stp == NULL) 1125 return (-1); /* errno is set for us */ 1126 1127 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP) 1128 return (smb_set_errno(shp, ESMB_TYPE)); 1129 1130 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 1131 bzero(map, sizeof (smbios_memarrmap_t)); 1132 1133 map->smbmam_array = m.smbamap_array; 1134 map->smbmam_width = m.smbamap_width; 1135 1136 if (m.smbamap_start != 0xFFFFFFFF && m.smbamap_end != 0xFFFFFFFF) { 1137 map->smbmam_addr = (uint64_t)m.smbamap_start * 1024; 1138 map->smbmam_size = (uint64_t) 1139 (m.smbamap_end - m.smbamap_start + 1) * 1024; 1140 } else if (m.smbamap_extstart != 0 && m.smbamap_extend != 0) { 1141 map->smbmam_addr = m.smbamap_extstart; 1142 map->smbmam_size = m.smbamap_extend - m.smbamap_extstart + 1; 1143 } 1144 1145 return (0); 1146 } 1147 1148 int 1149 smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp) 1150 { 1151 const smb_struct_t *stp = smb_lookup_id(shp, id); 1152 smb_memdevice_t m; 1153 1154 if (stp == NULL) 1155 return (-1); /* errno is set for us */ 1156 1157 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE) 1158 return (smb_set_errno(shp, ESMB_TYPE)); 1159 1160 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 1161 bzero(mdp, sizeof (smb_base_memdevice_t)); 1162 1163 mdp->smbmd_array = m.smbmdev_array; 1164 mdp->smbmd_error = m.smbmdev_error; 1165 mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth; 1166 mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth; 1167 1168 if (m.smbmdev_size == 0x7FFF) { 1169 mdp->smbmd_size = (uint64_t)m.smbmdev_extsize; 1170 mdp->smbmd_size *= 1024 * 1024; /* convert MB to bytes */ 1171 } else if (m.smbmdev_size != 0xFFFF) { 1172 mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES); 1173 if (m.smbmdev_size & SMB_MDS_KBYTES) 1174 mdp->smbmd_size *= 1024; 1175 else 1176 mdp->smbmd_size *= 1024 * 1024; 1177 } else 1178 mdp->smbmd_size = -1ULL; /* size unknown */ 1179 1180 mdp->smbmd_form = m.smbmdev_form; 1181 mdp->smbmd_set = m.smbmdev_set; 1182 mdp->smbmd_type = m.smbmdev_type; 1183 mdp->smbmd_speed = m.smbmdev_speed; 1184 mdp->smbmd_flags = m.smbmdev_flags; 1185 mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc); 1186 mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc); 1187 1188 if (smb_libgteq(shp, SMB_VERSION_26)) { 1189 mdp->smbmd_rank = m.smbmdev_attrs & 0x0F; 1190 } 1191 1192 if (smb_libgteq(shp, SMB_VERSION_27)) { 1193 mdp->smbmd_clkspeed = m.smbmdev_clkspeed; 1194 } 1195 1196 if (smb_libgteq(shp, SMB_VERSION_28)) { 1197 mdp->smbmd_minvolt = m.smbmdev_minvolt; 1198 mdp->smbmd_maxvolt = m.smbmdev_maxvolt; 1199 mdp->smbmd_confvolt = m.smbmdev_confvolt; 1200 } 1201 1202 if (smb_libgteq(shp, SMB_VERSION_32)) { 1203 mdp->smbmd_memtech = m.smbmdev_memtech; 1204 mdp->smbmd_opcap_flags = m.smbmdev_opmode; 1205 mdp->smbmd_firmware_rev = smb_strptr(stp, 1206 m.smbmdev_fwver); 1207 mdp->smbmd_modmfg_id = m.smbmdev_modulemfgid; 1208 mdp->smbmd_modprod_id = m.smbmdev_moduleprodid; 1209 mdp->smbmd_cntrlmfg_id = m.smbmdev_memsysmfgid; 1210 mdp->smbmd_cntrlprod_id = m.smbmdev_memsysprodid; 1211 mdp->smbmd_nvsize = m.smbmdev_nvsize; 1212 mdp->smbmd_volatile_size = m.smbmdev_volsize; 1213 mdp->smbmd_cache_size = m.smbmdev_cachesize; 1214 mdp->smbmd_logical_size = m.smbmdev_logicalsize; 1215 } 1216 1217 if (smb_libgteq(shp, SMB_VERSION_33)) { 1218 if (m.smbmdev_speed == 0xffff) { 1219 mdp->smbmd_extspeed = m.smbmdev_extspeed; 1220 } else { 1221 mdp->smbmd_extspeed = m.smbmdev_speed; 1222 } 1223 1224 if (m.smbmdev_clkspeed == 0xffff) { 1225 mdp->smbmd_extclkspeed = m.smbmdev_extclkspeed; 1226 } else { 1227 mdp->smbmd_extclkspeed = m.smbmdev_clkspeed; 1228 } 1229 } 1230 1231 /* 1232 * The unknown key for missing revision information for the RCD and 1233 * PMIC0 is not all zeros. As such, we need to look if the device SMBIOS 1234 * table is not 3.7 then we need to fix up the bits that we copied. 1235 * After that we need to go back and check the consumer's version to 1236 * actually place this data there. 1237 */ 1238 if (!smb_gteq(shp, SMB_VERSION_37)) { 1239 m.smbmdev_pmic0mfgid = SMB_MD_MFG_UNKNOWN; 1240 m.smbmdev_pmic0rev = SMB_MD_REV_UNKNOWN; 1241 m.smbmdev_rcdmfgid = SMB_MD_MFG_UNKNOWN; 1242 m.smbmdev_rcdrev = SMB_MD_REV_UNKNOWN; 1243 } 1244 1245 if (smb_libgteq(shp, SMB_VERSION_37)) { 1246 mdp->smbmd_pmic0_mfgid = m.smbmdev_pmic0mfgid; 1247 mdp->smbmd_pmic0_rev = m.smbmdev_pmic0rev; 1248 mdp->smbmd_rcd_mfgid = m.smbmdev_rcdmfgid; 1249 mdp->smbmd_rcd_rev = m.smbmdev_rcdrev; 1250 } 1251 1252 return (0); 1253 } 1254 1255 int 1256 smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp) 1257 { 1258 const smb_struct_t *stp = smb_lookup_id(shp, id); 1259 smb_memdevmap_t m; 1260 1261 if (stp == NULL) 1262 return (-1); /* errno is set for us */ 1263 1264 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP) 1265 return (smb_set_errno(shp, ESMB_TYPE)); 1266 1267 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 1268 bzero(mdp, sizeof (smbios_memdevmap_t)); 1269 1270 mdp->smbmdm_device = m.smbdmap_device; 1271 mdp->smbmdm_arrmap = m.smbdmap_array; 1272 mdp->smbmdm_rpos = m.smbdmap_rpos; 1273 mdp->smbmdm_ipos = m.smbdmap_ipos; 1274 mdp->smbmdm_idepth = m.smbdmap_idepth; 1275 1276 if (m.smbdmap_start != 0xFFFFFFFF && m.smbdmap_end != 0xFFFFFFFF) { 1277 mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024; 1278 mdp->smbmdm_size = (uint64_t) 1279 (m.smbdmap_end - m.smbdmap_start + 1) * 1024; 1280 } else if (m.smbdmap_extstart != 0 && m.smbdmap_extend != 0) { 1281 mdp->smbmdm_addr = m.smbdmap_extstart; 1282 mdp->smbmdm_size = m.smbdmap_extend - m.smbdmap_extstart + 1; 1283 } 1284 1285 return (0); 1286 } 1287 1288 id_t 1289 smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp) 1290 { 1291 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY); 1292 smb_hwsec_t hs; 1293 1294 if (stp == NULL) 1295 return (-1); /* errno is set for us */ 1296 1297 smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs)); 1298 bzero(hsp, sizeof (smbios_hwsec_t)); 1299 1300 hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings); 1301 hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings); 1302 hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings); 1303 hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings); 1304 1305 return (stp->smbst_hdr->smbh_hdl); 1306 } 1307 1308 id_t 1309 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp) 1310 { 1311 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT); 1312 const smb_boot_t *b; 1313 1314 if (stp == NULL) 1315 return (-1); /* errno is set for us */ 1316 1317 bzero(bp, sizeof (smbios_boot_t)); 1318 1319 b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr; 1320 1321 bp->smbt_status = b->smbbo_status[0]; 1322 bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t); 1323 bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL; 1324 1325 return (stp->smbst_hdr->smbh_hdl); 1326 } 1327 1328 id_t 1329 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip) 1330 { 1331 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV); 1332 smb_ipmi_t i; 1333 1334 if (stp == NULL) 1335 return (-1); /* errno is set for us */ 1336 1337 smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i)); 1338 bzero(ip, sizeof (smbios_ipmi_t)); 1339 1340 ip->smbip_type = i.smbipm_type; 1341 ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec); 1342 ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec); 1343 ip->smbip_i2c = i.smbipm_i2c; 1344 ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO; 1345 ip->smbip_intr = i.smbipm_intr; 1346 1347 if (i.smbipm_bus != (uint8_t)-1) 1348 ip->smbip_bus = i.smbipm_bus; 1349 else 1350 ip->smbip_bus = -1u; 1351 1352 if (SMB_IPM_INFO_LSB(i.smbipm_info)) 1353 ip->smbip_addr |= 1; /* turn on least-significant bit of addr */ 1354 1355 if (i.smbipm_addr & SMB_IPM_ADDR_IO) { 1356 switch (SMB_IPM_INFO_REGS(i.smbipm_info)) { 1357 case SMB_IPM_REGS_1B: 1358 ip->smbip_regspacing = 1; 1359 break; 1360 case SMB_IPM_REGS_4B: 1361 ip->smbip_regspacing = 4; 1362 break; 1363 case SMB_IPM_REGS_16B: 1364 ip->smbip_regspacing = 16; 1365 break; 1366 default: 1367 ip->smbip_regspacing = 1; 1368 } 1369 ip->smbip_flags |= SMB_IPMI_F_IOADDR; 1370 } 1371 1372 if (SMB_IPM_INFO_ISPEC(i.smbipm_info)) 1373 ip->smbip_flags |= SMB_IPMI_F_INTRSPEC; 1374 1375 if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI) 1376 ip->smbip_flags |= SMB_IPMI_F_INTRHIGH; 1377 1378 if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE) 1379 ip->smbip_flags |= SMB_IPMI_F_INTREDGE; 1380 1381 return (stp->smbst_hdr->smbh_hdl); 1382 } 1383 1384 static boolean_t 1385 smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr) 1386 { 1387 const smb_struct_t *stp = shp->sh_structs; 1388 smb_strtab_t s; 1389 int i, j; 1390 1391 for (i = 0; i < shp->sh_nstructs; i++, stp++) { 1392 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR) 1393 continue; 1394 1395 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 1396 for (j = 0; j < s.smbtb_count; j++) 1397 if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0) 1398 return (B_TRUE); 1399 } 1400 1401 return (B_FALSE); 1402 } 1403 1404 static const char * 1405 smb_serial_valid(const char *serial) 1406 { 1407 char buf[MAXNAMELEN]; 1408 int i = 0; 1409 1410 if (serial == NULL) 1411 return (NULL); 1412 1413 (void) strlcpy(buf, serial, sizeof (buf)); 1414 1415 while (buf[i] != '\0' && buf[i] == ' ') 1416 i++; 1417 1418 if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL || 1419 strstr(buf, SMB_DEFAULT2) != NULL) 1420 return (NULL); 1421 1422 return (serial); 1423 } 1424 1425 /* 1426 * Get chassis SN or product SN 1427 */ 1428 static int 1429 smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp) 1430 { 1431 const smb_struct_t *stp; 1432 smbios_info_t s1, s3; 1433 1434 if (psnp == NULL || csnp == NULL) 1435 return (smb_set_errno(shp, ESMB_INVAL)); 1436 1437 *psnp = *csnp = NULL; 1438 1439 /* 1440 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN 1441 * from type 1 structure, and chassis SN from type 3 structure. 1442 * Otherwise return SN in type 1 structure as chassis SN. 1443 */ 1444 1445 /* Get type 1 SN */ 1446 if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL || 1447 smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR) 1448 s1.smbi_serial = NULL; 1449 1450 /* Get type 3 SN */ 1451 if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL || 1452 smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR) 1453 s3.smbi_serial = NULL; 1454 1455 if (smbios_has_oemstr(shp, SMB_PRMS1)) { 1456 *psnp = smb_serial_valid(s1.smbi_serial); 1457 *csnp = smb_serial_valid(s3.smbi_serial); 1458 } else { 1459 *csnp = smb_serial_valid(s1.smbi_serial); 1460 } 1461 1462 return (0); 1463 } 1464 1465 const char * 1466 smbios_psn(smbios_hdl_t *shp) 1467 { 1468 const char *psn, *csn; 1469 1470 return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn); 1471 } 1472 1473 const char * 1474 smbios_csn(smbios_hdl_t *shp) 1475 { 1476 const char *psn, *csn; 1477 1478 return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn); 1479 } 1480 1481 int 1482 smbios_info_extprocessor(smbios_hdl_t *shp, id_t id, 1483 smbios_processor_ext_t *epp) 1484 { 1485 const smb_struct_t *stp = smb_lookup_id(shp, id); 1486 smb_processor_ext_t *exp; 1487 1488 if (stp == NULL) 1489 return (-1); /* errno is set for us */ 1490 1491 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR) 1492 return (smb_set_errno(shp, ESMB_TYPE)); 1493 1494 exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr; 1495 bzero(epp, sizeof (smbios_processor_ext_t)); 1496 1497 epp->smbpe_processor = exp->smbpre_processor; 1498 epp->smbpe_fru = exp->smbpre_fru; 1499 epp->smbpe_n = exp->smbpre_n; 1500 epp->smbpe_apicid = exp->smbpre_apicid; 1501 1502 return (0); 1503 } 1504 1505 int 1506 smbios_info_extport(smbios_hdl_t *shp, id_t id, smbios_port_ext_t *eportp) 1507 { 1508 const smb_struct_t *stp = smb_lookup_id(shp, id); 1509 smb_port_ext_t *ep; 1510 1511 if (stp == NULL) 1512 return (-1); /* errno is set for us */ 1513 1514 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PORT) 1515 return (smb_set_errno(shp, ESMB_TYPE)); 1516 1517 ep = (smb_port_ext_t *)(uintptr_t)stp->smbst_hdr; 1518 bzero(eportp, sizeof (smbios_port_ext_t)); 1519 1520 eportp->smbporte_chassis = ep->smbpoe_chassis; 1521 eportp->smbporte_port = ep->smbpoe_port; 1522 eportp->smbporte_dtype = ep->smbpoe_dtype; 1523 eportp->smbporte_devhdl = ep->smbpoe_devhdl; 1524 eportp->smbporte_phy = ep->smbpoe_phy; 1525 1526 return (0); 1527 } 1528 1529 int 1530 smbios_info_pciexrc(smbios_hdl_t *shp, id_t id, 1531 smbios_pciexrc_t *rcp) 1532 { 1533 const smb_struct_t *stp = smb_lookup_id(shp, id); 1534 smb_pciexrc_t rc; 1535 1536 if (stp == NULL) 1537 return (-1); /* errno is set for us */ 1538 1539 if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC) 1540 return (smb_set_errno(shp, ESMB_TYPE)); 1541 1542 smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc)); 1543 bzero(rcp, sizeof (smbios_pciexrc_t)); 1544 1545 rcp->smbpcie_bb = rc.smbpciexrc_bboard; 1546 rcp->smbpcie_bdf = rc.smbpciexrc_bdf; 1547 1548 return (0); 1549 } 1550 1551 int 1552 smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap) 1553 { 1554 const smb_struct_t *stp = smb_lookup_id(shp, id); 1555 smb_memarray_ext_t exma; 1556 1557 if (stp == NULL) 1558 return (-1); /* errno is set for us */ 1559 1560 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY) 1561 return (smb_set_errno(shp, ESMB_TYPE)); 1562 1563 smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma)); 1564 bzero(emap, sizeof (smbios_memarray_ext_t)); 1565 1566 emap->smbmae_ma = exma.smbmarre_ma; 1567 emap->smbmae_comp = exma.smbmarre_component; 1568 emap->smbmae_bdf = exma.smbmarre_bdf; 1569 1570 return (0); 1571 } 1572 1573 int 1574 smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id, 1575 smbios_memdevice_ext_t *emdp) 1576 { 1577 const smb_struct_t *stp = smb_lookup_id(shp, id); 1578 smb_memdevice_ext_t exmd; 1579 1580 if (stp == NULL) 1581 return (-1); /* errno is set for us */ 1582 1583 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE) 1584 return (smb_set_errno(shp, ESMB_TYPE)); 1585 1586 smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd)); 1587 bzero(emdp, sizeof (smbios_memdevice_ext_t)); 1588 1589 emdp->smbmdeve_md = exmd.smbmdeve_mdev; 1590 emdp->smbmdeve_drch = exmd.smbmdeve_dchan; 1591 emdp->smbmdeve_ncs = exmd.smbmdeve_ncs; 1592 1593 return (0); 1594 } 1595 1596 int 1597 smbios_info_extmemdevice_cs(smbios_hdl_t *shp, id_t id, uint_t *ncsp, 1598 uint8_t **csp) 1599 { 1600 const smb_struct_t *stp = smb_lookup_id(shp, id); 1601 smb_memdevice_ext_t exmd; 1602 size_t size; 1603 void *buf; 1604 1605 if (stp == NULL) 1606 return (-1); /* errno is set for us */ 1607 1608 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE) 1609 return (smb_set_errno(shp, ESMB_TYPE)); 1610 1611 smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd)); 1612 if (exmd.smbmdeve_ncs == 0) { 1613 *ncsp = 0; 1614 *csp = NULL; 1615 return (0); 1616 } 1617 1618 size = exmd.smbmdeve_ncs * sizeof (*exmd.smbmdeve_cs); 1619 1620 if (stp->smbst_hdr->smbh_len < sizeof (exmd) + size) 1621 return (smb_set_errno(shp, ESMB_SHORT)); 1622 1623 buf = smb_alloc(size); 1624 if (buf == NULL) 1625 return (smb_set_errno(shp, ESMB_NOMEM)); 1626 smb_info_bcopy_offset(stp->smbst_hdr, buf, size, sizeof (exmd)); 1627 1628 *ncsp = exmd.smbmdeve_ncs; 1629 *csp = buf; 1630 return (0); 1631 } 1632 1633 void 1634 smbios_info_extmemdevice_cs_free(smbios_hdl_t *shp __unused, uint_t ncs, 1635 uint8_t *csp) 1636 { 1637 size_t size = ncs * sizeof (uint8_t); 1638 1639 if (size == 0) { 1640 ASSERT3P(csp, ==, NULL); 1641 return; 1642 } 1643 smb_free(csp, size); 1644 } 1645 1646 int 1647 smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup) 1648 { 1649 const smb_struct_t *stp = smb_lookup_id(shp, id); 1650 smb_powersup_t psu; 1651 1652 if (stp == NULL) 1653 return (-1); /* errno is set for us */ 1654 1655 if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP) 1656 return (smb_set_errno(shp, ESMB_TYPE)); 1657 1658 /* The minimum length required by the spec is 0x10. */ 1659 if (stp->smbst_hdr->smbh_len < 0x10) 1660 return (smb_set_errno(shp, ESMB_SHORT)); 1661 1662 bzero(psup, sizeof (*psup)); 1663 smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu)); 1664 psup->smbps_group = psu.smbpsup_group; 1665 psup->smbps_maxout = psu.smbpsup_max; 1666 1667 if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char)) 1668 psup->smbps_flags |= SMB_POWERSUP_F_HOT; 1669 if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char)) 1670 psup->smbps_flags |= SMB_POWERSUP_F_PRESENT; 1671 if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char)) 1672 psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG; 1673 1674 psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char); 1675 psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char); 1676 psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char); 1677 1678 if (stp->smbst_hdr->smbh_len >= 0x12) { 1679 psup->smbps_vprobe = psu.smbpsup_vprobe; 1680 } else { 1681 psup->smbps_vprobe = 0xffff; 1682 } 1683 1684 if (stp->smbst_hdr->smbh_len >= 0x14) { 1685 psup->smbps_cooldev = psu.smbpsup_cooldev; 1686 } else { 1687 psup->smbps_cooldev = 0xffff; 1688 } 1689 1690 if (stp->smbst_hdr->smbh_len >= 0x16) { 1691 psup->smbps_iprobe = psu.smbpsup_iprobe; 1692 } else { 1693 psup->smbps_iprobe = 0xffff; 1694 } 1695 1696 return (0); 1697 } 1698 1699 int 1700 smbios_info_vprobe(smbios_hdl_t *shp, id_t id, smbios_vprobe_t *vprobe) 1701 { 1702 const smb_struct_t *stp = smb_lookup_id(shp, id); 1703 smb_vprobe_t vp; 1704 1705 if (stp == NULL) 1706 return (-1); /* errno is set for us */ 1707 1708 if (stp->smbst_hdr->smbh_type != SMB_TYPE_VPROBE) 1709 return (smb_set_errno(shp, ESMB_TYPE)); 1710 1711 if (stp->smbst_hdr->smbh_len < SMB_VPROBE_MINLEN) 1712 return (smb_set_errno(shp, ESMB_SHORT)); 1713 1714 bzero(vprobe, sizeof (*vprobe)); 1715 smb_info_bcopy(stp->smbst_hdr, &vp, sizeof (vp)); 1716 vprobe->smbvp_description = smb_strptr(stp, vp.smbvpr_descr); 1717 vprobe->smbvp_location = SMB_VPROBE_LOCATION(vp.smbvpr_locstat); 1718 vprobe->smbvp_status = SMB_VPROBE_STATUS(vp.smbvpr_locstat); 1719 vprobe->smbvp_maxval = vp.smbvpr_maxval; 1720 vprobe->smbvp_minval = vp.smbvpr_minval; 1721 vprobe->smbvp_resolution = vp.smbvpr_resolution; 1722 vprobe->smbvp_tolerance = vp.smbvpr_tolerance; 1723 vprobe->smbvp_accuracy = vp.smbvpr_accuracy; 1724 1725 if (stp->smbst_hdr->smbh_len >= SMB_VPROBE_NOMINAL_MINLEN) { 1726 vprobe->smbvp_nominal = vp.smbvpr_nominal; 1727 } else { 1728 vprobe->smbvp_nominal = SMB_PROBE_UNKNOWN_VALUE; 1729 } 1730 1731 return (0); 1732 } 1733 1734 int 1735 smbios_info_cooldev(smbios_hdl_t *shp, id_t id, smbios_cooldev_t *cooldev) 1736 { 1737 const smb_struct_t *stp = smb_lookup_id(shp, id); 1738 smb_cooldev_t cd; 1739 1740 if (stp == NULL) 1741 return (-1); /* errno is set for us */ 1742 1743 if (stp->smbst_hdr->smbh_type != SMB_TYPE_COOLDEV) 1744 return (smb_set_errno(shp, ESMB_TYPE)); 1745 1746 if (stp->smbst_hdr->smbh_len < SMB_COOLDEV_MINLEN) 1747 return (smb_set_errno(shp, ESMB_SHORT)); 1748 1749 bzero(cooldev, sizeof (*cooldev)); 1750 smb_info_bcopy(stp->smbst_hdr, &cd, sizeof (cd)); 1751 cooldev->smbcd_tprobe = cd.smbcdev_tprobe; 1752 cooldev->smbcd_type = SMB_COOLDEV_TYPE(cd.smbcdev_typstat); 1753 cooldev->smbcd_status = SMB_COOLDEV_STATUS(cd.smbcdev_typstat); 1754 cooldev->smbcd_group = cd.smbcdev_group; 1755 cooldev->smbcd_oem = cd.smbcdev_oem; 1756 1757 if (stp->smbst_hdr->smbh_len >= SMB_COOLDEV_NOMINAL_MINLEN) { 1758 cooldev->smbcd_nominal = cd.smbcdev_nominal; 1759 } else { 1760 cooldev->smbcd_nominal = SMB_PROBE_UNKNOWN_VALUE; 1761 } 1762 1763 /* 1764 * The description field was added in SMBIOS version 2.7. The 1765 * SMB_TYPE_COOLDEV support was only added after all of the 2.7+ fields 1766 * were added in the spec. So while a user may request an older version, 1767 * we don't have to worry about old structures and just simply skip it 1768 * if they're not asking for it. 1769 */ 1770 if (smb_libgteq(shp, SMB_VERSION_27) && 1771 smb_gteq(shp, SMB_VERSION_27) && 1772 stp->smbst_hdr->smbh_len >= SMB_COOLDEV_DESCR_MINLEN) { 1773 cooldev->smbcd_descr = smb_strptr(stp, cd.smbcdev_descr); 1774 } else { 1775 cooldev->smbcd_descr = NULL; 1776 } 1777 1778 return (0); 1779 } 1780 1781 int 1782 smbios_info_tprobe(smbios_hdl_t *shp, id_t id, smbios_tprobe_t *tprobe) 1783 { 1784 const smb_struct_t *stp = smb_lookup_id(shp, id); 1785 smb_tprobe_t tp; 1786 1787 if (stp == NULL) 1788 return (-1); /* errno is set for us */ 1789 1790 if (stp->smbst_hdr->smbh_type != SMB_TYPE_TPROBE) 1791 return (smb_set_errno(shp, ESMB_TYPE)); 1792 1793 if (stp->smbst_hdr->smbh_len < SMB_TPROBE_MINLEN) 1794 return (smb_set_errno(shp, ESMB_SHORT)); 1795 1796 bzero(tprobe, sizeof (*tprobe)); 1797 smb_info_bcopy(stp->smbst_hdr, &tp, sizeof (tp)); 1798 tprobe->smbtp_description = smb_strptr(stp, tp.smbtpr_descr); 1799 tprobe->smbtp_location = SMB_TPROBE_LOCATION(tp.smbtpr_locstat); 1800 tprobe->smbtp_status = SMB_TPROBE_STATUS(tp.smbtpr_locstat); 1801 tprobe->smbtp_maxval = tp.smbtpr_maxval; 1802 tprobe->smbtp_minval = tp.smbtpr_minval; 1803 tprobe->smbtp_resolution = tp.smbtpr_resolution; 1804 tprobe->smbtp_tolerance = tp.smbtpr_tolerance; 1805 tprobe->smbtp_accuracy = tp.smbtpr_accuracy; 1806 1807 if (stp->smbst_hdr->smbh_len >= SMB_TPROBE_NOMINAL_MINLEN) { 1808 tprobe->smbtp_nominal = tp.smbtpr_nominal; 1809 } else { 1810 tprobe->smbtp_nominal = SMB_PROBE_UNKNOWN_VALUE; 1811 } 1812 1813 return (0); 1814 } 1815 1816 int 1817 smbios_info_iprobe(smbios_hdl_t *shp, id_t id, smbios_iprobe_t *iprobe) 1818 { 1819 const smb_struct_t *sip = smb_lookup_id(shp, id); 1820 smb_iprobe_t ip; 1821 1822 if (sip == NULL) 1823 return (-1); /* errno is set for us */ 1824 1825 if (sip->smbst_hdr->smbh_type != SMB_TYPE_IPROBE) 1826 return (smb_set_errno(shp, ESMB_TYPE)); 1827 1828 if (sip->smbst_hdr->smbh_len < SMB_IPROBE_MINLEN) 1829 return (smb_set_errno(shp, ESMB_SHORT)); 1830 1831 bzero(iprobe, sizeof (*iprobe)); 1832 smb_info_bcopy(sip->smbst_hdr, &ip, sizeof (ip)); 1833 iprobe->smbip_description = smb_strptr(sip, ip.smbipr_descr); 1834 iprobe->smbip_location = SMB_IPROBE_LOCATION(ip.smbipr_locstat); 1835 iprobe->smbip_status = SMB_IPROBE_STATUS(ip.smbipr_locstat); 1836 iprobe->smbip_maxval = ip.smbipr_maxval; 1837 iprobe->smbip_minval = ip.smbipr_minval; 1838 iprobe->smbip_resolution = ip.smbipr_resolution; 1839 iprobe->smbip_tolerance = ip.smbipr_tolerance; 1840 iprobe->smbip_accuracy = ip.smbipr_accuracy; 1841 1842 if (sip->smbst_hdr->smbh_len >= SMB_IPROBE_NOMINAL_MINLEN) { 1843 iprobe->smbip_nominal = ip.smbipr_nominal; 1844 } else { 1845 iprobe->smbip_nominal = SMB_PROBE_UNKNOWN_VALUE; 1846 } 1847 1848 return (0); 1849 } 1850 1851 int 1852 smbios_info_processor_info(smbios_hdl_t *shp, id_t id, 1853 smbios_processor_info_t *proc) 1854 { 1855 const smb_struct_t *stp = smb_lookup_id(shp, id); 1856 smb_processor_info_t pi; 1857 1858 if (stp == NULL) 1859 return (-1); /* errno is set for us */ 1860 1861 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR_INFO) 1862 return (smb_set_errno(shp, ESMB_TYPE)); 1863 1864 if (stp->smbst_hdr->smbh_len < sizeof (pi)) 1865 return (smb_set_errno(shp, ESMB_SHORT)); 1866 1867 bzero(proc, sizeof (*proc)); 1868 smb_info_bcopy(stp->smbst_hdr, &pi, sizeof (pi)); 1869 1870 if (sizeof (pi) + pi.smbpai_len > stp->smbst_hdr->smbh_len) 1871 return (smb_set_errno(shp, ESMB_CORRUPT)); 1872 1873 proc->smbpi_processor = pi.smbpai_proc; 1874 proc->smbpi_ptype = pi.smbpai_type; 1875 1876 return (0); 1877 } 1878 1879 int 1880 smbios_info_processor_riscv(smbios_hdl_t *shp, id_t id, 1881 smbios_processor_info_riscv_t *riscv) 1882 { 1883 const smb_struct_t *stp = smb_lookup_id(shp, id); 1884 const smb_processor_info_t *proc; 1885 const smb_processor_info_riscv_t *rv; 1886 1887 if (stp == NULL) { 1888 return (-1); /* errno is set for us */ 1889 } 1890 1891 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR_INFO) { 1892 return (smb_set_errno(shp, ESMB_TYPE)); 1893 } 1894 1895 if (stp->smbst_hdr->smbh_len < sizeof (*proc)) { 1896 return (smb_set_errno(shp, ESMB_SHORT)); 1897 } 1898 1899 proc = (const smb_processor_info_t *)stp->smbst_hdr; 1900 if (sizeof (*proc) + proc->smbpai_len > stp->smbst_hdr->smbh_len) { 1901 return (smb_set_errno(shp, ESMB_CORRUPT)); 1902 } 1903 1904 switch (proc->smbpai_type) { 1905 case SMB_PROCINFO_T_RV32: 1906 case SMB_PROCINFO_T_RV64: 1907 case SMB_PROCINFO_T_RV128: 1908 break; 1909 default: 1910 return (smb_set_errno(shp, ESMB_TYPE)); 1911 } 1912 1913 if (stp->smbst_hdr->smbh_len < sizeof (*proc) + sizeof (*rv)) { 1914 return (smb_set_errno(shp, ESMB_SHORT)); 1915 } 1916 rv = (const smb_processor_info_riscv_t *)&proc->smbpai_data[0]; 1917 if (rv->smbpairv_len != sizeof (*rv)) { 1918 return (smb_set_errno(shp, ESMB_CORRUPT)); 1919 } 1920 1921 bcopy(rv->smbpairv_hartid, riscv->smbpirv_hartid, 1922 sizeof (riscv->smbpirv_hartid)); 1923 bcopy(rv->smbpairv_vendid, riscv->smbpirv_vendid, 1924 sizeof (riscv->smbpirv_vendid)); 1925 bcopy(rv->smbpairv_archid, riscv->smbpirv_archid, 1926 sizeof (riscv->smbpirv_archid)); 1927 bcopy(rv->smbpairv_machid, riscv->smbpirv_machid, 1928 sizeof (riscv->smbpirv_machid)); 1929 bcopy(rv->smbpairv_metdi, riscv->smbpirv_metdi, 1930 sizeof (riscv->smbpirv_metdi)); 1931 bcopy(rv->smbpairv_mitdi, riscv->smbpirv_mitdi, 1932 sizeof (riscv->smbpirv_mitdi)); 1933 riscv->smbpirv_isa = rv->smbpairv_isa; 1934 riscv->smbpirv_privlvl = rv->smbpairv_privlvl; 1935 riscv->smbpirv_boothart = rv->smbpairv_boot; 1936 riscv->smbpirv_xlen = rv->smbpairv_xlen; 1937 riscv->smbpirv_mxlen = rv->smbpairv_mxlen; 1938 riscv->smbpirv_sxlen = rv->smbpairv_sxlen; 1939 riscv->smbpirv_uxlen = rv->smbpairv_uxlen; 1940 1941 return (0); 1942 } 1943 1944 int 1945 smbios_info_pointdev(smbios_hdl_t *shp, id_t id, smbios_pointdev_t *pd) 1946 { 1947 const smb_struct_t *stp = smb_lookup_id(shp, id); 1948 smb_pointdev_t point; 1949 1950 if (stp == NULL) { 1951 return (-1); /* errno is set for us */ 1952 } 1953 1954 if (stp->smbst_hdr->smbh_type != SMB_TYPE_POINTDEV) { 1955 return (smb_set_errno(shp, ESMB_TYPE)); 1956 } 1957 1958 if (stp->smbst_hdr->smbh_len < sizeof (point)) { 1959 return (smb_set_errno(shp, ESMB_SHORT)); 1960 } 1961 1962 bzero(pd, sizeof (*pd)); 1963 smb_info_bcopy(stp->smbst_hdr, &point, sizeof (point)); 1964 1965 pd->smbpd_type = point.smbpdev_type; 1966 pd->smbpd_iface = point.smbpdev_iface; 1967 pd->smbpd_nbuttons = point.smbpdev_nbuttons; 1968 1969 return (0); 1970 } 1971 1972 int 1973 smbios_info_battery(smbios_hdl_t *shp, id_t id, smbios_battery_t *bp) 1974 { 1975 const smb_struct_t *stp = smb_lookup_id(shp, id); 1976 smb_battery_t bat; 1977 1978 if (stp == NULL) { 1979 return (-1); /* errno is set for us */ 1980 } 1981 1982 if (stp->smbst_hdr->smbh_type != SMB_TYPE_BATTERY) { 1983 return (smb_set_errno(shp, ESMB_TYPE)); 1984 } 1985 1986 if (stp->smbst_hdr->smbh_len < sizeof (bat)) { 1987 return (smb_set_errno(shp, ESMB_SHORT)); 1988 } 1989 1990 bzero(bp, sizeof (*bp)); 1991 smb_info_bcopy(stp->smbst_hdr, &bat, sizeof (bat)); 1992 1993 /* 1994 * This may be superseded by the SBDS data. 1995 */ 1996 if (bat.smbbat_date != 0) { 1997 bp->smbb_date = smb_strptr(stp, bat.smbbat_date); 1998 } else { 1999 bp->smbb_date = NULL; 2000 } 2001 2002 /* 2003 * This may be superseded by the SBDS data. 2004 */ 2005 if (bat.smbbat_serial != 0) { 2006 bp->smbb_serial = smb_strptr(stp, bat.smbbat_serial); 2007 } else { 2008 bp->smbb_serial = NULL; 2009 } 2010 2011 bp->smbb_chem = bat.smbbat_chem; 2012 bp->smbb_cap = bat.smbbat_cap; 2013 if (bat.smbbat_mult > 0) { 2014 bp->smbb_cap *= bat.smbbat_mult; 2015 } 2016 bp->smbb_volt = bat.smbbat_volt; 2017 bp->smbb_version = smb_strptr(stp, bat.smbbat_version); 2018 bp->smbb_err = bat.smbbat_err; 2019 bp->smbb_ssn = bat.smbbat_ssn; 2020 bp->smbb_syear = 1980 + (bat.smbbat_sdate >> 9); 2021 bp->smbb_smonth = (bat.smbbat_sdate >> 5) & 0xf; 2022 bp->smbb_sday = bat.smbbat_sdate & 0x1f; 2023 bp->smbb_schem = smb_strptr(stp, bat.smbbat_schem); 2024 bp->smbb_oemdata = bat.smbbat_oemdata; 2025 2026 return (0); 2027 } 2028 2029 int 2030 smbios_info_strprop(smbios_hdl_t *shp, id_t id, smbios_strprop_t *str) 2031 { 2032 const smb_struct_t *stp = smb_lookup_id(shp, id); 2033 smb_strprop_t prop; 2034 2035 if (stp == NULL) { 2036 return (-1); /* errno is set for us */ 2037 } 2038 2039 if (stp->smbst_hdr->smbh_type != SMB_TYPE_STRPROP) { 2040 return (smb_set_errno(shp, ESMB_TYPE)); 2041 } 2042 2043 if (stp->smbst_hdr->smbh_len < sizeof (prop)) { 2044 return (smb_set_errno(shp, ESMB_SHORT)); 2045 } 2046 2047 if (stp->smbst_hdr->smbh_len > sizeof (prop)) { 2048 return (smb_set_errno(shp, ESMB_CORRUPT)); 2049 } 2050 2051 bzero(str, sizeof (*str)); 2052 smb_info_bcopy(stp->smbst_hdr, &prop, sizeof (prop)); 2053 2054 str->smbsp_parent = prop.smbstrp_phdl; 2055 str->smbsp_prop_id = prop.smbstrp_prop_id; 2056 str->smbsp_prop_val = smb_strptr(stp, prop.smbstrp_prop_val); 2057 2058 return (0); 2059 } 2060 2061 int 2062 smbios_info_fwinfo(smbios_hdl_t *shp, id_t id, smbios_fwinfo_t *fwinfo) 2063 { 2064 const smb_struct_t *stp = smb_lookup_id(shp, id); 2065 smb_fwinfo_t fw; 2066 2067 if (stp == NULL) { 2068 return (-1); /* errno is set for us */ 2069 } 2070 2071 if (stp->smbst_hdr->smbh_type != SMB_TYPE_FWINFO) { 2072 return (smb_set_errno(shp, ESMB_TYPE)); 2073 } 2074 2075 if (stp->smbst_hdr->smbh_len < sizeof (fw)) { 2076 return (smb_set_errno(shp, ESMB_SHORT)); 2077 } 2078 2079 /* 2080 * The verion and manufacturer are part of smbios_info_common(). 2081 */ 2082 bzero(fwinfo, sizeof (*fwinfo)); 2083 smb_info_bcopy(stp->smbst_hdr, &fw, sizeof (fw)); 2084 fwinfo->smbfw_name = smb_strptr(stp, fw.smbfwii_name); 2085 fwinfo->smbfw_id = smb_strptr(stp, fw.smbfwii_id); 2086 fwinfo->smbfw_reldate = smb_strptr(stp, fw.smbfwii_reldate); 2087 fwinfo->smbfw_lsv = smb_strptr(stp, fw.smbfwii_lsv); 2088 fwinfo->smbfw_imgsz = fw.smbfwii_imgsz; 2089 fwinfo->smbfw_chars = fw.smbfwii_chars; 2090 fwinfo->smbfw_state = fw.smbfwii_state; 2091 fwinfo->smbfw_ncomps = fw.smbfwii_ncomps; 2092 fwinfo->smbfw_vers_fmt = fw.smbfwii_vers_fmt; 2093 fwinfo->smbfw_id_fmt = fw.smbfwii_id_fmt; 2094 2095 return (0); 2096 } 2097 2098 int 2099 smbios_info_fwinfo_comps(smbios_hdl_t *shp, id_t id, uint_t *ncompsp, 2100 smbios_fwinfo_comp_t **compsp) 2101 { 2102 const smb_struct_t *stp = smb_lookup_id(shp, id); 2103 smbios_fwinfo_comp_t *comps; 2104 smb_fwinfo_t fw; 2105 size_t need; 2106 uint_t i; 2107 2108 if (stp == NULL) { 2109 return (-1); /* errno is set for us */ 2110 } 2111 2112 if (stp->smbst_hdr->smbh_type != SMB_TYPE_FWINFO) { 2113 return (smb_set_errno(shp, ESMB_TYPE)); 2114 } 2115 2116 if (stp->smbst_hdr->smbh_len < sizeof (fw)) { 2117 return (smb_set_errno(shp, ESMB_SHORT)); 2118 } 2119 2120 smb_info_bcopy(stp->smbst_hdr, &fw, sizeof (fw)); 2121 if (fw.smbfwii_ncomps == 0) { 2122 *ncompsp = 0; 2123 *compsp = NULL; 2124 return (0); 2125 } 2126 2127 need = fw.smbfwii_ncomps * sizeof (uint16_t) + sizeof (smb_fwinfo_t); 2128 if (stp->smbst_hdr->smbh_len < need) { 2129 return (smb_set_errno(shp, ESMB_SHORT)); 2130 } 2131 2132 comps = smb_alloc(fw.smbfwii_ncomps * sizeof (smbios_fwinfo_comp_t)); 2133 if (comps == NULL) { 2134 return (smb_set_errno(shp, ESMB_NOMEM)); 2135 } 2136 2137 for (i = 0; i < fw.smbfwii_ncomps; i++) { 2138 uint16_t id; 2139 size_t off = sizeof (smb_fwinfo_t) + sizeof (uint16_t) * i; 2140 smb_info_bcopy_offset(stp->smbst_hdr, &id, sizeof (id), off); 2141 comps[i].smbfwe_id = id; 2142 } 2143 2144 *ncompsp = fw.smbfwii_ncomps; 2145 *compsp = comps; 2146 2147 return (0); 2148 } 2149 2150 void 2151 smbios_info_fwinfo_comps_free(smbios_hdl_t *shp, uint_t ncomps, 2152 smbios_fwinfo_comp_t *comps) 2153 { 2154 size_t sz = ncomps * sizeof (smbios_fwinfo_comp_t); 2155 2156 if (ncomps == 0) { 2157 ASSERT3P(comps, ==, NULL); 2158 return; 2159 } 2160 2161 smb_free(comps, sz); 2162 } 2163 2164 int 2165 smbios_info_addinfo_nents(smbios_hdl_t *shp, id_t id, uint_t *nentsp) 2166 { 2167 const smb_struct_t *stp = smb_lookup_id(shp, id); 2168 smb_addinfo_t add; 2169 2170 if (stp == NULL) { 2171 return (-1); /* errno is set for us */ 2172 } 2173 2174 if (stp->smbst_hdr->smbh_type != SMB_TYPE_ADDINFO) { 2175 return (smb_set_errno(shp, ESMB_TYPE)); 2176 } 2177 2178 if (stp->smbst_hdr->smbh_len < sizeof (add)) { 2179 return (smb_set_errno(shp, ESMB_SHORT)); 2180 } 2181 2182 smb_info_bcopy(stp->smbst_hdr, &add, sizeof (add)); 2183 *nentsp = add.smbai_nents; 2184 2185 return (0); 2186 } 2187 2188 void 2189 smbios_info_addinfo_ent_free(smbios_hdl_t *hdl, smbios_addinfo_ent_t *ent) 2190 { 2191 if (ent->smbai_dlen > 0) { 2192 ASSERT3P(ent->smbai_data, !=, NULL); 2193 smb_free(ent->smbai_data, ent->smbai_dlen); 2194 } 2195 2196 smb_free(ent, sizeof (smbios_addinfo_ent_t)); 2197 } 2198 2199 int 2200 smbios_info_addinfo_ent(smbios_hdl_t *shp, id_t id, uint_t entno, 2201 smbios_addinfo_ent_t **entp) 2202 { 2203 const smb_struct_t *stp = smb_lookup_id(shp, id); 2204 size_t off; 2205 smb_addinfo_t add; 2206 smb_addinfo_ent_t ent; 2207 smbios_addinfo_ent_t *entry; 2208 uint_t i; 2209 2210 if (stp == NULL) { 2211 return (-1); /* errno is set for us */ 2212 } 2213 2214 if (stp->smbst_hdr->smbh_type != SMB_TYPE_ADDINFO) { 2215 return (smb_set_errno(shp, ESMB_TYPE)); 2216 } 2217 2218 if (stp->smbst_hdr->smbh_len < sizeof (add)) { 2219 return (smb_set_errno(shp, ESMB_SHORT)); 2220 } 2221 2222 smb_info_bcopy(stp->smbst_hdr, &add, sizeof (add)); 2223 if (entno >= add.smbai_nents) { 2224 return (smb_set_errno(shp, ESMB_REQVAL)); 2225 } 2226 2227 off = sizeof (add); 2228 for (i = 0; i <= entno; i++) { 2229 if (off + sizeof (ent) > stp->smbst_hdr->smbh_len) { 2230 return (smb_set_errno(shp, ESMB_SHORT)); 2231 } 2232 2233 smb_info_bcopy_offset(stp->smbst_hdr, &ent, sizeof (ent), off); 2234 if (ent.smbaie_len < sizeof (ent)) { 2235 return (smb_set_errno(shp, ESMB_SHORT)); 2236 } 2237 2238 if (ent.smbaie_len + off > stp->smbst_hdr->smbh_len) { 2239 return (smb_set_errno(shp, ESMB_CORRUPT)); 2240 } 2241 2242 if (i != entno) { 2243 off += ent.smbaie_len; 2244 } 2245 } 2246 2247 entry = smb_alloc(sizeof (smbios_addinfo_ent_t)); 2248 if (entry == NULL) { 2249 return (smb_set_errno(shp, ESMB_NOMEM)); 2250 } 2251 2252 entry->smbai_ref = ent.smbaie_rhdl; 2253 entry->smbai_ref_off = ent.smbaie_off; 2254 if (ent.smbaie_str != 0) { 2255 entry->smbai_str = smb_strptr(stp, ent.smbaie_str); 2256 } else { 2257 entry->smbai_str = NULL; 2258 } 2259 entry->smbai_dlen = ent.smbaie_len - sizeof (ent); 2260 if (entry->smbai_dlen > 0) { 2261 entry->smbai_data = smb_alloc(entry->smbai_dlen); 2262 if (entry->smbai_data == NULL) { 2263 smb_free(entry, sizeof (smbios_addinfo_ent_t)); 2264 return (smb_set_errno(shp, ESMB_NOMEM)); 2265 } 2266 smb_info_bcopy_offset(stp->smbst_hdr, entry->smbai_data, 2267 entry->smbai_dlen, off + offsetof(smb_addinfo_ent_t, 2268 smbaie_val)); 2269 } else { 2270 entry->smbai_data = NULL; 2271 } 2272 2273 *entp = entry; 2274 return (0); 2275 } 2276