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 2016 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 71 #ifdef _KERNEL 72 #include <sys/sunddi.h> 73 #else 74 #include <fcntl.h> 75 #include <unistd.h> 76 #include <string.h> 77 #endif 78 79 /* 80 * A large number of SMBIOS structures contain a set of common strings used to 81 * describe a h/w component's serial number, manufacturer, etc. These fields 82 * helpfully have different names and offsets and sometimes aren't consistent. 83 * To simplify life for our clients, we factor these common things out into 84 * smbios_info_t, which can be retrieved for any structure. The following 85 * table describes the mapping from a given structure to the smbios_info_t. 86 * Multiple SMBIOS stuctures' contained objects are also handled here. 87 */ 88 static const struct smb_infospec { 89 uint8_t is_type; /* structure type */ 90 uint8_t is_manu; /* manufacturer offset */ 91 uint8_t is_product; /* product name offset */ 92 uint8_t is_version; /* version offset */ 93 uint8_t is_serial; /* serial number offset */ 94 uint8_t is_asset; /* asset tag offset */ 95 uint8_t is_location; /* location string offset */ 96 uint8_t is_part; /* part number offset */ 97 uint8_t is_contc; /* contained count */ 98 uint8_t is_contsz; /* contained size */ 99 uint8_t is_contv; /* contained objects */ 100 } _smb_infospecs[] = { 101 { SMB_TYPE_SYSTEM, 102 offsetof(smb_system_t, smbsi_manufacturer), 103 offsetof(smb_system_t, smbsi_product), 104 offsetof(smb_system_t, smbsi_version), 105 offsetof(smb_system_t, smbsi_serial), 106 0, 107 0, 108 0, 109 0, 110 0, 111 0 }, 112 { SMB_TYPE_BASEBOARD, 113 offsetof(smb_bboard_t, smbbb_manufacturer), 114 offsetof(smb_bboard_t, smbbb_product), 115 offsetof(smb_bboard_t, smbbb_version), 116 offsetof(smb_bboard_t, smbbb_serial), 117 offsetof(smb_bboard_t, smbbb_asset), 118 offsetof(smb_bboard_t, smbbb_location), 119 0, 120 offsetof(smb_bboard_t, smbbb_cn), 121 SMB_CONT_WORD, 122 offsetof(smb_bboard_t, smbbb_cv) }, 123 { SMB_TYPE_CHASSIS, 124 offsetof(smb_chassis_t, smbch_manufacturer), 125 0, 126 offsetof(smb_chassis_t, smbch_version), 127 offsetof(smb_chassis_t, smbch_serial), 128 offsetof(smb_chassis_t, smbch_asset), 129 0, 130 0, 131 offsetof(smb_chassis_t, smbch_cn), 132 SMB_CONT_BYTE, 133 offsetof(smb_chassis_t, smbch_cv) }, 134 { SMB_TYPE_PROCESSOR, 135 offsetof(smb_processor_t, smbpr_manufacturer), 136 0, 137 offsetof(smb_processor_t, smbpr_version), 138 offsetof(smb_processor_t, smbpr_serial), 139 offsetof(smb_processor_t, smbpr_asset), 140 offsetof(smb_processor_t, smbpr_socket), 141 offsetof(smb_processor_t, smbpr_part), 142 0, 143 0, 144 0 }, 145 { SMB_TYPE_CACHE, 146 0, 147 0, 148 0, 149 0, 150 0, 151 offsetof(smb_cache_t, smbca_socket), 152 0, 153 0, 154 0, 155 0 }, 156 { SMB_TYPE_PORT, 157 0, 158 0, 159 0, 160 0, 161 0, 162 offsetof(smb_port_t, smbpo_iref), 163 0, 164 0, 165 0, 166 0 }, 167 { SMB_TYPE_SLOT, 168 0, 169 0, 170 0, 171 0, 172 0, 173 offsetof(smb_slot_t, smbsl_name), 174 0, 175 0, 176 0, 177 0 }, 178 { SMB_TYPE_MEMDEVICE, 179 offsetof(smb_memdevice_t, smbmdev_manufacturer), 180 0, 181 0, 182 offsetof(smb_memdevice_t, smbmdev_serial), 183 offsetof(smb_memdevice_t, smbmdev_asset), 184 offsetof(smb_memdevice_t, smbmdev_dloc), 185 offsetof(smb_memdevice_t, smbmdev_part), 186 0, 187 0, 188 0 }, 189 { SMB_TYPE_POWERSUP, 190 offsetof(smb_powersup_t, smbpsup_manufacturer), 191 offsetof(smb_powersup_t, smbpsup_devname), 192 offsetof(smb_powersup_t, smbpsup_rev), 193 offsetof(smb_powersup_t, smbpsup_serial), 194 offsetof(smb_powersup_t, smbpsup_asset), 195 offsetof(smb_powersup_t, smbpsup_loc), 196 offsetof(smb_powersup_t, smbpsup_part), 197 0, 198 0, 199 0 }, 200 { SMB_TYPE_EOT } 201 }; 202 203 static const char * 204 smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n) 205 { 206 const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr; 207 208 if (off != 0 && sp + off < stp->smbst_end) { 209 (*n)++; /* indicate success for caller */ 210 return (smb_strptr(stp, sp[off])); 211 } 212 213 return (smb_strptr(stp, 0)); 214 } 215 216 static void 217 smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen) 218 { 219 if (dstlen > hp->smbh_len) { 220 bcopy(hp, dst, hp->smbh_len); 221 bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len); 222 } else 223 bcopy(hp, dst, dstlen); 224 } 225 226 void 227 smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep) 228 { 229 bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t)); 230 } 231 232 #ifndef _KERNEL 233 static char smbios_product_override[256]; 234 static boolean_t smbios_product_checked; 235 #endif 236 237 int 238 smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip) 239 { 240 const smb_struct_t *stp = smb_lookup_id(shp, id); 241 const struct smb_infospec *isp; 242 int n = 0; 243 244 if (stp == NULL) 245 return (-1); /* errno is set for us */ 246 247 for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) { 248 if (isp->is_type == stp->smbst_hdr->smbh_type) 249 break; 250 } 251 252 ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n); 253 ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n); 254 ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n); 255 ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n); 256 ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n); 257 ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n); 258 ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n); 259 260 /* 261 * This private file allows developers to experiment with reporting 262 * different platform strings from SMBIOS. It is not a supported 263 * mechanism in the long term, and does not work in the kernel. 264 */ 265 #ifndef _KERNEL 266 if (isp->is_type == SMB_TYPE_SYSTEM) { 267 if (!smbios_product_checked) { 268 int fd = open("/etc/smbios_product", O_RDONLY); 269 if (fd >= 0) { 270 (void) read(fd, smbios_product_override, 271 sizeof (smbios_product_override) - 1); 272 (void) close(fd); 273 } 274 smbios_product_checked = B_TRUE; 275 } 276 277 if (smbios_product_override[0] != '\0') 278 ip->smbi_product = smbios_product_override; 279 } 280 #endif 281 282 /* 283 * If we have a port with an empty internal reference designator string 284 * try using the external reference designator string instead. 285 */ 286 if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') { 287 ip->smbi_location = smb_info_strptr(stp, 288 offsetof(smb_port_t, smbpo_eref), &n); 289 } 290 291 return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO)); 292 } 293 294 /* 295 * Returns the actual number of contained objects. 296 * 297 * idc - number of contained objects 298 * idv - returned array of contained objects 299 */ 300 int 301 smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv) 302 { 303 const smb_struct_t *stp = smb_lookup_id(shp, id); 304 const struct smb_infospec *isp; 305 id_t *cp; 306 uint_t size; 307 uint8_t cnt; 308 int i, n; 309 310 if (stp == NULL) { 311 return (-1); /* errno is set for us */ 312 } 313 314 for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) { 315 if (isp->is_type == stp->smbst_hdr->smbh_type) 316 break; 317 } 318 if (isp->is_type == SMB_TYPE_EOT) 319 return (smb_set_errno(shp, ESMB_TYPE)); 320 321 size = isp->is_contsz; 322 cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc); 323 cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv); 324 325 n = MIN(cnt, idc); 326 for (i = 0; i < n; i++) { 327 if (size == SMB_CONT_WORD) 328 idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 2)); 329 else if (size == SMB_CONT_BYTE) 330 idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 3)); 331 else 332 return (smb_set_errno(shp, ESMB_INVAL)); 333 } 334 335 return (cnt); 336 } 337 338 id_t 339 smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp) 340 { 341 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS); 342 const smb_bios_t *bip; 343 344 if (stp == NULL) 345 return (-1); /* errno is set for us */ 346 347 if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t)) 348 return (smb_set_errno(shp, ESMB_CORRUPT)); 349 350 bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr; 351 bzero(bp, sizeof (smb_base_bios_t)); 352 if (smb_libgteq(shp, SMB_VERSION_31)) { 353 bp->smbb_extromsize = 0; 354 } 355 356 bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor); 357 bp->smbb_version = smb_strptr(stp, bip->smbbi_version); 358 bp->smbb_segment = bip->smbbi_segment; 359 bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate); 360 bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1); 361 bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment); 362 bp->smbb_cflags = bip->smbbi_cflags; 363 364 /* 365 * If one or more extension bytes are present, reset smbb_xcflags to 366 * point to them. Otherwise leave this member set to NULL. 367 */ 368 if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) { 369 bp->smbb_xcflags = bip->smbbi_xcflags; 370 bp->smbb_nxcflags = stp->smbst_hdr->smbh_len - 371 sizeof (smb_bios_t) + 1; 372 373 if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN && 374 smb_gteq(shp, SMB_VERSION_24)) { 375 bp->smbb_biosv.smbv_major = 376 bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ]; 377 bp->smbb_biosv.smbv_minor = 378 bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN]; 379 bp->smbb_ecfwv.smbv_major = 380 bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ]; 381 bp->smbb_ecfwv.smbv_minor = 382 bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN]; 383 } 384 385 if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 && 386 smb_gteq(shp, SMB_VERSION_31)) { 387 uint16_t val; 388 uint64_t rs; 389 390 /* 391 * Because of the fact that the extended size is a 392 * uint16_t and we'd need to define an explicit 393 * endian-aware way to access it, we don't include it in 394 * the number of extended flags below and thus subtract 395 * its size. 396 */ 397 bp->smbb_nxcflags -= sizeof (uint16_t); 398 bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val, 399 sizeof (val)); 400 val = LE_16(val); 401 402 /* 403 * The upper two bits of the extended rom size are used 404 * to indicate whether the other 14 bits are in MB or 405 * GB. 406 */ 407 rs = SMB_BIOS_EXTROM_VALUE_MASK(val); 408 switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) { 409 case 0: 410 rs *= 1024ULL * 1024ULL; 411 break; 412 case 1: 413 rs *= 1024ULL * 1024ULL * 1024ULL; 414 break; 415 default: 416 rs = 0; 417 break; 418 } 419 420 if (smb_libgteq(shp, SMB_VERSION_31)) { 421 bp->smbb_extromsize = rs; 422 } 423 } 424 } 425 426 if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) { 427 bp->smbb_extromsize = bp->smbb_romsize; 428 } 429 430 return (stp->smbst_hdr->smbh_hdl); 431 } 432 433 id_t 434 smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip) 435 { 436 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM); 437 smb_system_t si; 438 439 if (stp == NULL) 440 return (-1); /* errno is set for us */ 441 442 smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si)); 443 bzero(sip, sizeof (smbios_system_t)); 444 445 sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid; 446 sip->smbs_uuidlen = sizeof (si.smbsi_uuid); 447 sip->smbs_wakeup = si.smbsi_wakeup; 448 sip->smbs_sku = smb_strptr(stp, si.smbsi_sku); 449 sip->smbs_family = smb_strptr(stp, si.smbsi_family); 450 451 return (stp->smbst_hdr->smbh_hdl); 452 } 453 454 int 455 smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp) 456 { 457 const smb_struct_t *stp = smb_lookup_id(shp, id); 458 smb_bboard_t bb; 459 460 if (stp == NULL) 461 return (-1); /* errno is set for us */ 462 463 if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD) 464 return (smb_set_errno(shp, ESMB_TYPE)); 465 466 smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb)); 467 bzero(bbp, sizeof (smbios_bboard_t)); 468 469 bbp->smbb_chassis = bb.smbbb_chassis; 470 bbp->smbb_flags = bb.smbbb_flags; 471 bbp->smbb_type = bb.smbbb_type; 472 bbp->smbb_contn = bb.smbbb_cn; 473 474 return (0); 475 } 476 477 int 478 smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp) 479 { 480 const smb_struct_t *stp = smb_lookup_id(shp, id); 481 /* Length is measurable by one byte, so it'll be no more than 255. */ 482 uint8_t buf[256]; 483 smb_chassis_t *ch = (smb_chassis_t *)&buf[0]; 484 485 if (stp == NULL) 486 return (-1); /* errno is set for us */ 487 488 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS) 489 return (smb_set_errno(shp, ESMB_TYPE)); 490 491 smb_info_bcopy(stp->smbst_hdr, ch, sizeof (buf)); 492 bzero(chp, sizeof (smb_base_chassis_t)); 493 if (smb_libgteq(shp, SMB_VERSION_27)) { 494 bzero(chp->smbc_sku, sizeof (chp->smbc_sku)); 495 } 496 497 chp->smbc_oemdata = ch->smbch_oemdata; 498 chp->smbc_lock = (ch->smbch_type & SMB_CHT_LOCK) != 0; 499 chp->smbc_type = ch->smbch_type & ~SMB_CHT_LOCK; 500 chp->smbc_bustate = ch->smbch_bustate; 501 chp->smbc_psstate = ch->smbch_psstate; 502 chp->smbc_thstate = ch->smbch_thstate; 503 chp->smbc_security = ch->smbch_security; 504 chp->smbc_uheight = ch->smbch_uheight; 505 chp->smbc_cords = ch->smbch_cords; 506 chp->smbc_elems = ch->smbch_cn; 507 chp->smbc_elemlen = ch->smbch_cm; 508 509 if (smb_libgteq(shp, SMB_VERSION_27)) { 510 (void) strlcpy(chp->smbc_sku, SMB_CH_SKU(ch), 511 sizeof (chp->smbc_sku)); 512 } 513 514 return (0); 515 } 516 517 int 518 smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp) 519 { 520 const smb_struct_t *stp = smb_lookup_id(shp, id); 521 smb_processor_t p; 522 523 if (stp == NULL) 524 return (-1); /* errno is set for us */ 525 526 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR) 527 return (smb_set_errno(shp, ESMB_TYPE)); 528 529 smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p)); 530 bzero(pp, sizeof (smb_base_processor_t)); 531 532 pp->smbp_cpuid = p.smbpr_cpuid; 533 pp->smbp_type = p.smbpr_type; 534 pp->smbp_family = p.smbpr_family; 535 pp->smbp_voltage = p.smbpr_voltage; 536 pp->smbp_maxspeed = p.smbpr_maxspeed; 537 pp->smbp_curspeed = p.smbpr_curspeed; 538 pp->smbp_status = p.smbpr_status; 539 pp->smbp_upgrade = p.smbpr_upgrade; 540 pp->smbp_l1cache = p.smbpr_l1cache; 541 pp->smbp_l2cache = p.smbpr_l2cache; 542 pp->smbp_l3cache = p.smbpr_l3cache; 543 544 if (smb_libgteq(shp, SMB_VERSION_25)) { 545 pp->smbp_corecount = p.smbpr_corecount; 546 pp->smbp_coresenabled = p.smbpr_coresenabled; 547 pp->smbp_threadcount = p.smbpr_threadcount; 548 pp->smbp_cflags = p.smbpr_cflags; 549 } 550 551 if (smb_libgteq(shp, SMB_VERSION_26)) { 552 pp->smbp_family2 = p.smbpr_family2; 553 } 554 555 if (smb_libgteq(shp, SMB_VERSION_30)) { 556 pp->smbp_corecount2 = p.smbpr_corecount2; 557 pp->smbp_coresenabled2 = p.smbpr_coresenabled2; 558 pp->smbp_threadcount2 = p.smbpr_threadcount2; 559 } 560 561 return (0); 562 } 563 564 int 565 smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap) 566 { 567 const smb_struct_t *stp = smb_lookup_id(shp, id); 568 smb_cache_t c; 569 570 if (stp == NULL) 571 return (-1); /* errno is set for us */ 572 573 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE) 574 return (smb_set_errno(shp, ESMB_TYPE)); 575 576 smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c)); 577 bzero(cap, sizeof (smb_base_cache_t)); 578 579 cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize); 580 cap->smba_size = SMB_CACHE_SIZE(c.smbca_size); 581 cap->smba_stype = c.smbca_stype; 582 cap->smba_ctype = c.smbca_ctype; 583 cap->smba_speed = c.smbca_speed; 584 cap->smba_etype = c.smbca_etype; 585 cap->smba_ltype = c.smbca_ltype; 586 cap->smba_assoc = c.smbca_assoc; 587 cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config); 588 cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config); 589 cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config); 590 591 if (SMB_CACHE_CFG_ENABLED(c.smbca_config)) 592 cap->smba_flags |= SMB_CAF_ENABLED; 593 594 if (SMB_CACHE_CFG_SOCKETED(c.smbca_config)) 595 cap->smba_flags |= SMB_CAF_SOCKETED; 596 597 if (smb_libgteq(shp, SMB_VERSION_31)) { 598 if (smb_gteq(shp, SMB_VERSION_31)) { 599 cap->smba_maxsize2 = 600 SMB_CACHE_EXT_SIZE(c.smbca_maxsize2); 601 cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2); 602 } else { 603 cap->smba_maxsize2 = cap->smba_maxsize; 604 cap->smba_size2 = cap->smba_size; 605 } 606 } 607 608 return (0); 609 } 610 611 int 612 smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop) 613 { 614 const smb_struct_t *stp = smb_lookup_id(shp, id); 615 smb_port_t p; 616 617 if (stp == NULL) 618 return (-1); /* errno is set for us */ 619 620 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT) 621 return (smb_set_errno(shp, ESMB_TYPE)); 622 623 smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p)); 624 bzero(pop, sizeof (smbios_port_t)); 625 626 pop->smbo_iref = smb_strptr(stp, p.smbpo_iref); 627 pop->smbo_eref = smb_strptr(stp, p.smbpo_eref); 628 629 pop->smbo_itype = p.smbpo_itype; 630 pop->smbo_etype = p.smbpo_etype; 631 pop->smbo_ptype = p.smbpo_ptype; 632 633 return (0); 634 } 635 636 int 637 smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) 638 { 639 const smb_struct_t *stp = smb_lookup_id(shp, id); 640 smb_slot_t s; 641 642 if (stp == NULL) 643 return (-1); /* errno is set for us */ 644 645 if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT) 646 return (smb_set_errno(shp, ESMB_TYPE)); 647 648 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 649 bzero(sp, sizeof (smbios_slot_t)); 650 651 sp->smbl_name = smb_strptr(stp, s.smbsl_name); 652 sp->smbl_type = s.smbsl_type; 653 sp->smbl_width = s.smbsl_width; 654 sp->smbl_usage = s.smbsl_usage; 655 sp->smbl_length = s.smbsl_length; 656 sp->smbl_id = s.smbsl_id; 657 sp->smbl_ch1 = s.smbsl_ch1; 658 sp->smbl_ch2 = s.smbsl_ch2; 659 sp->smbl_sg = s.smbsl_sg; 660 sp->smbl_bus = s.smbsl_bus; 661 sp->smbl_df = s.smbsl_df; 662 663 return (0); 664 } 665 666 int 667 smbios_info_obdevs_ext(smbios_hdl_t *shp, id_t id, smbios_obdev_ext_t *oep) 668 { 669 const smb_struct_t *stp = smb_lookup_id(shp, id); 670 smb_obdev_ext_t obe; 671 672 if (stp == NULL) 673 return (-1); /* errno is set for us */ 674 675 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVEXT) 676 return (smb_set_errno(shp, ESMB_TYPE)); 677 678 smb_info_bcopy(stp->smbst_hdr, &obe, sizeof (obe)); 679 bzero(oep, sizeof (smbios_obdev_ext_t)); 680 681 oep->smboe_name = smb_strptr(stp, obe.smbobe_name); 682 oep->smboe_dtype = obe.smbobe_dtype; 683 oep->smboe_dti = obe.smbobe_dti; 684 oep->smboe_sg = obe.smbobe_sg; 685 oep->smboe_bus = obe.smbobe_bus; 686 oep->smboe_df = obe.smbobe_df; 687 688 return (0); 689 } 690 691 int 692 smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp) 693 { 694 const smb_struct_t *stp = smb_lookup_id(shp, id); 695 const smb_obdev_t *op; 696 int i, m, n; 697 698 if (stp == NULL) 699 return (-1); /* errno is set for us */ 700 701 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS) 702 return (smb_set_errno(shp, ESMB_TYPE)); 703 704 op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t)); 705 m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op); 706 n = MIN(m, obc); 707 708 for (i = 0; i < n; i++, op++, obp++) { 709 obp->smbd_name = smb_strptr(stp, op->smbob_name); 710 obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED; 711 obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0; 712 } 713 714 return (m); 715 } 716 717 /* 718 * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the 719 * first byte to indicate the size of a string table at the end of the record. 720 * Therefore, smbios_info_strtab() can be used to retrieve the table size and 721 * strings for any of these underlying record types. 722 */ 723 int 724 smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[]) 725 { 726 const smb_struct_t *stp = smb_lookup_id(shp, id); 727 smb_strtab_t s; 728 int i, n; 729 730 if (stp == NULL) 731 return (-1); /* errno is set for us */ 732 733 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR && 734 stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR && 735 stp->smbst_hdr->smbh_type != SMB_TYPE_LANG) 736 return (smb_set_errno(shp, ESMB_TYPE)); 737 738 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 739 n = MIN(s.smbtb_count, argc); 740 741 for (i = 0; i < n; i++) 742 argv[i] = smb_strptr(stp, i + 1); 743 744 return (s.smbtb_count); 745 } 746 747 id_t 748 smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp) 749 { 750 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG); 751 smb_lang_t l; 752 753 if (stp == NULL) 754 return (-1); /* errno is set for us */ 755 756 smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l)); 757 bzero(lp, sizeof (smbios_lang_t)); 758 759 lp->smbla_cur = smb_strptr(stp, l.smblang_cur); 760 lp->smbla_fmt = l.smblang_flags & 1; 761 lp->smbla_num = l.smblang_num; 762 763 return (stp->smbst_hdr->smbh_hdl); 764 } 765 766 id_t 767 smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp) 768 { 769 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG); 770 const smb_sel_t *sel; 771 size_t len; 772 773 if (stp == NULL) 774 return (-1); /* errno is set for us */ 775 776 if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t)) 777 return (smb_set_errno(shp, ESMB_CORRUPT)); 778 779 sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr; 780 len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t); 781 bzero(evp, sizeof (smbios_evlog_t)); 782 783 if (len < sel->smbsel_typec * sel->smbsel_typesz) 784 return (smb_set_errno(shp, ESMB_CORRUPT)); 785 786 evp->smbev_size = sel->smbsel_len; 787 evp->smbev_hdr = sel->smbsel_hdroff; 788 evp->smbev_data = sel->smbsel_dataoff; 789 evp->smbev_method = sel->smbsel_method; 790 evp->smbev_flags = sel->smbsel_status; 791 evp->smbev_format = sel->smbsel_format; 792 evp->smbev_token = sel->smbsel_token; 793 evp->smbev_addr.eva_addr = sel->smbsel_addr; 794 795 if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) { 796 evp->smbev_typec = sel->smbsel_typec; 797 evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev; 798 } 799 800 return (stp->smbst_hdr->smbh_hdl); 801 } 802 803 int 804 smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map) 805 { 806 const smb_struct_t *stp = smb_lookup_id(shp, id); 807 smb_memarray_t m; 808 809 if (stp == NULL) 810 return (-1); /* errno is set for us */ 811 812 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY) 813 return (smb_set_errno(shp, ESMB_TYPE)); 814 815 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 816 bzero(map, sizeof (smbios_memarray_t)); 817 818 map->smbma_location = m.smbmarr_loc; 819 map->smbma_use = m.smbmarr_use; 820 map->smbma_ecc = m.smbmarr_ecc; 821 map->smbma_ndevs = m.smbmarr_ndevs; 822 map->smbma_err = m.smbmarr_err; 823 824 if (m.smbmarr_cap != 0x80000000) 825 map->smbma_size = (uint64_t)m.smbmarr_cap * 1024; 826 else if (m.smbmarr_extcap != 0) 827 map->smbma_size = m.smbmarr_extcap; 828 else 829 map->smbma_size = 0; /* unknown */ 830 831 return (0); 832 } 833 834 int 835 smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map) 836 { 837 const smb_struct_t *stp = smb_lookup_id(shp, id); 838 smb_memarrmap_t m; 839 840 if (stp == NULL) 841 return (-1); /* errno is set for us */ 842 843 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP) 844 return (smb_set_errno(shp, ESMB_TYPE)); 845 846 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 847 bzero(map, sizeof (smbios_memarrmap_t)); 848 849 map->smbmam_array = m.smbamap_array; 850 map->smbmam_width = m.smbamap_width; 851 852 if (m.smbamap_start != 0xFFFFFFFF && m.smbamap_end != 0xFFFFFFFF) { 853 map->smbmam_addr = (uint64_t)m.smbamap_start * 1024; 854 map->smbmam_size = (uint64_t) 855 (m.smbamap_end - m.smbamap_start + 1) * 1024; 856 } else if (m.smbamap_extstart != 0 && m.smbamap_extend != 0) { 857 map->smbmam_addr = m.smbamap_extstart; 858 map->smbmam_size = m.smbamap_extend - m.smbamap_extstart + 1; 859 } 860 861 return (0); 862 } 863 864 int 865 smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp) 866 { 867 const smb_struct_t *stp = smb_lookup_id(shp, id); 868 smb_memdevice_t m; 869 870 if (stp == NULL) 871 return (-1); /* errno is set for us */ 872 873 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE) 874 return (smb_set_errno(shp, ESMB_TYPE)); 875 876 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 877 bzero(mdp, sizeof (smb_base_memdevice_t)); 878 879 mdp->smbmd_array = m.smbmdev_array; 880 mdp->smbmd_error = m.smbmdev_error; 881 mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth; 882 mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth; 883 884 if (m.smbmdev_size == 0x7FFF) { 885 mdp->smbmd_size = (uint64_t)m.smbmdev_extsize; 886 mdp->smbmd_size *= 1024 * 1024; /* convert MB to bytes */ 887 } else if (m.smbmdev_size != 0xFFFF) { 888 mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES); 889 if (m.smbmdev_size & SMB_MDS_KBYTES) 890 mdp->smbmd_size *= 1024; 891 else 892 mdp->smbmd_size *= 1024 * 1024; 893 } else 894 mdp->smbmd_size = -1ULL; /* size unknown */ 895 896 mdp->smbmd_form = m.smbmdev_form; 897 mdp->smbmd_set = m.smbmdev_set; 898 mdp->smbmd_type = m.smbmdev_type; 899 mdp->smbmd_speed = m.smbmdev_speed; 900 mdp->smbmd_flags = m.smbmdev_flags; 901 mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc); 902 mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc); 903 904 if (smb_libgteq(shp, SMB_VERSION_26)) { 905 mdp->smbmd_rank = m.smbmdev_attrs & 0x0F; 906 } 907 908 if (smb_libgteq(shp, SMB_VERSION_27)) { 909 mdp->smbmd_clkspeed = m.smbmdev_clkspeed; 910 } 911 912 if (smb_libgteq(shp, SMB_VERSION_28)) { 913 mdp->smbmd_minvolt = m.smbmdev_minvolt; 914 mdp->smbmd_maxvolt = m.smbmdev_maxvolt; 915 mdp->smbmd_confvolt = m.smbmdev_confvolt; 916 } 917 918 return (0); 919 } 920 921 int 922 smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp) 923 { 924 const smb_struct_t *stp = smb_lookup_id(shp, id); 925 smb_memdevmap_t m; 926 927 if (stp == NULL) 928 return (-1); /* errno is set for us */ 929 930 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP) 931 return (smb_set_errno(shp, ESMB_TYPE)); 932 933 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 934 bzero(mdp, sizeof (smbios_memdevmap_t)); 935 936 mdp->smbmdm_device = m.smbdmap_device; 937 mdp->smbmdm_arrmap = m.smbdmap_array; 938 mdp->smbmdm_rpos = m.smbdmap_rpos; 939 mdp->smbmdm_ipos = m.smbdmap_ipos; 940 mdp->smbmdm_idepth = m.smbdmap_idepth; 941 942 if (m.smbdmap_start != 0xFFFFFFFF && m.smbdmap_end != 0xFFFFFFFF) { 943 mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024; 944 mdp->smbmdm_size = (uint64_t) 945 (m.smbdmap_end - m.smbdmap_start + 1) * 1024; 946 } else if (m.smbdmap_extstart != 0 && m.smbdmap_extend != 0) { 947 mdp->smbmdm_addr = m.smbdmap_extstart; 948 mdp->smbmdm_size = m.smbdmap_extend - m.smbdmap_extstart + 1; 949 } 950 951 return (0); 952 } 953 954 id_t 955 smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp) 956 { 957 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY); 958 smb_hwsec_t hs; 959 960 if (stp == NULL) 961 return (-1); /* errno is set for us */ 962 963 smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs)); 964 bzero(hsp, sizeof (smbios_hwsec_t)); 965 966 hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings); 967 hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings); 968 hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings); 969 hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings); 970 971 return (stp->smbst_hdr->smbh_hdl); 972 } 973 974 id_t 975 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp) 976 { 977 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT); 978 const smb_boot_t *b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr; 979 980 if (stp == NULL) 981 return (-1); /* errno is set for us */ 982 983 bzero(bp, sizeof (smbios_boot_t)); 984 985 bp->smbt_status = b->smbbo_status[0]; 986 bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t); 987 bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL; 988 989 return (stp->smbst_hdr->smbh_hdl); 990 } 991 992 id_t 993 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip) 994 { 995 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV); 996 smb_ipmi_t i; 997 998 if (stp == NULL) 999 return (-1); /* errno is set for us */ 1000 1001 smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i)); 1002 bzero(ip, sizeof (smbios_ipmi_t)); 1003 1004 ip->smbip_type = i.smbipm_type; 1005 ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec); 1006 ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec); 1007 ip->smbip_i2c = i.smbipm_i2c; 1008 ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO; 1009 ip->smbip_intr = i.smbipm_intr; 1010 1011 if (i.smbipm_bus != (uint8_t)-1) 1012 ip->smbip_bus = i.smbipm_bus; 1013 else 1014 ip->smbip_bus = -1u; 1015 1016 if (SMB_IPM_INFO_LSB(i.smbipm_info)) 1017 ip->smbip_addr |= 1; /* turn on least-significant bit of addr */ 1018 1019 if (i.smbipm_addr & SMB_IPM_ADDR_IO) { 1020 switch (SMB_IPM_INFO_REGS(i.smbipm_info)) { 1021 case SMB_IPM_REGS_1B: 1022 ip->smbip_regspacing = 1; 1023 break; 1024 case SMB_IPM_REGS_4B: 1025 ip->smbip_regspacing = 4; 1026 break; 1027 case SMB_IPM_REGS_16B: 1028 ip->smbip_regspacing = 16; 1029 break; 1030 default: 1031 ip->smbip_regspacing = 1; 1032 } 1033 ip->smbip_flags |= SMB_IPMI_F_IOADDR; 1034 } 1035 1036 if (SMB_IPM_INFO_ISPEC(i.smbipm_info)) 1037 ip->smbip_flags |= SMB_IPMI_F_INTRSPEC; 1038 1039 if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI) 1040 ip->smbip_flags |= SMB_IPMI_F_INTRHIGH; 1041 1042 if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE) 1043 ip->smbip_flags |= SMB_IPMI_F_INTREDGE; 1044 1045 return (stp->smbst_hdr->smbh_hdl); 1046 } 1047 1048 static boolean_t 1049 smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr) 1050 { 1051 const smb_struct_t *stp = shp->sh_structs; 1052 smb_strtab_t s; 1053 int i, j; 1054 1055 for (i = 0; i < shp->sh_nstructs; i++, stp++) { 1056 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR) 1057 continue; 1058 1059 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 1060 for (j = 0; j < s.smbtb_count; j++) 1061 if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0) 1062 return (B_TRUE); 1063 } 1064 1065 return (B_FALSE); 1066 } 1067 1068 static const char * 1069 smb_serial_valid(const char *serial) 1070 { 1071 char buf[MAXNAMELEN]; 1072 int i = 0; 1073 1074 if (serial == NULL) 1075 return (NULL); 1076 1077 (void) strlcpy(buf, serial, sizeof (buf)); 1078 1079 while (buf[i] != '\0' && buf[i] == ' ') 1080 i++; 1081 1082 if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL || 1083 strstr(buf, SMB_DEFAULT2) != NULL) 1084 return (NULL); 1085 1086 return (serial); 1087 } 1088 1089 /* 1090 * Get chassis SN or product SN 1091 */ 1092 static int 1093 smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp) 1094 { 1095 const smb_struct_t *stp; 1096 smbios_info_t s1, s3; 1097 1098 if (psnp == NULL || csnp == NULL) 1099 return (smb_set_errno(shp, ESMB_INVAL)); 1100 1101 *psnp = *csnp = NULL; 1102 1103 /* 1104 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN 1105 * from type 1 structure, and chassis SN from type 3 structure. 1106 * Otherwise return SN in type 1 structure as chassis SN. 1107 */ 1108 1109 /* Get type 1 SN */ 1110 if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL || 1111 smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR) 1112 s1.smbi_serial = NULL; 1113 1114 /* Get type 3 SN */ 1115 if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL || 1116 smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR) 1117 s3.smbi_serial = NULL; 1118 1119 if (smbios_has_oemstr(shp, SMB_PRMS1)) { 1120 *psnp = smb_serial_valid(s1.smbi_serial); 1121 *csnp = smb_serial_valid(s3.smbi_serial); 1122 } else { 1123 *csnp = smb_serial_valid(s1.smbi_serial); 1124 } 1125 1126 return (0); 1127 } 1128 1129 const char * 1130 smbios_psn(smbios_hdl_t *shp) 1131 { 1132 const char *psn, *csn; 1133 1134 return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn); 1135 } 1136 1137 const char * 1138 smbios_csn(smbios_hdl_t *shp) 1139 { 1140 const char *psn, *csn; 1141 1142 return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn); 1143 } 1144 1145 int 1146 smbios_info_extprocessor(smbios_hdl_t *shp, id_t id, 1147 smbios_processor_ext_t *epp) 1148 { 1149 const smb_struct_t *stp = smb_lookup_id(shp, id); 1150 smb_processor_ext_t *exp; 1151 1152 if (stp == NULL) 1153 return (-1); /* errno is set for us */ 1154 1155 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR) 1156 return (smb_set_errno(shp, ESMB_TYPE)); 1157 1158 exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr; 1159 bzero(epp, sizeof (smbios_processor_ext_t)); 1160 1161 epp->smbpe_processor = exp->smbpre_processor; 1162 epp->smbpe_fru = exp->smbpre_fru; 1163 epp->smbpe_n = exp->smbpre_n; 1164 epp->smbpe_apicid = exp->smbpre_apicid; 1165 1166 return (0); 1167 } 1168 1169 int 1170 smbios_info_extport(smbios_hdl_t *shp, id_t id, smbios_port_ext_t *eportp) 1171 { 1172 const smb_struct_t *stp = smb_lookup_id(shp, id); 1173 smb_port_ext_t *ep; 1174 1175 if (stp == NULL) 1176 return (-1); /* errno is set for us */ 1177 1178 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PORT) 1179 return (smb_set_errno(shp, ESMB_TYPE)); 1180 1181 ep = (smb_port_ext_t *)(uintptr_t)stp->smbst_hdr; 1182 bzero(eportp, sizeof (smbios_port_ext_t)); 1183 1184 eportp->smbporte_chassis = ep->smbpoe_chassis; 1185 eportp->smbporte_port = ep->smbpoe_port; 1186 eportp->smbporte_dtype = ep->smbpoe_dtype; 1187 eportp->smbporte_devhdl = ep->smbpoe_devhdl; 1188 eportp->smbporte_phy = ep->smbpoe_phy; 1189 1190 return (0); 1191 } 1192 1193 int 1194 smbios_info_pciexrc(smbios_hdl_t *shp, id_t id, 1195 smbios_pciexrc_t *rcp) 1196 { 1197 const smb_struct_t *stp = smb_lookup_id(shp, id); 1198 smb_pciexrc_t rc; 1199 1200 if (stp == NULL) 1201 return (-1); /* errno is set for us */ 1202 1203 if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC) 1204 return (smb_set_errno(shp, ESMB_TYPE)); 1205 1206 smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc)); 1207 bzero(rcp, sizeof (smbios_pciexrc_t)); 1208 1209 rcp->smbpcie_bb = rc.smbpciexrc_bboard; 1210 rcp->smbpcie_bdf = rc.smbpciexrc_bdf; 1211 1212 return (0); 1213 } 1214 1215 int 1216 smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap) 1217 { 1218 const smb_struct_t *stp = smb_lookup_id(shp, id); 1219 smb_memarray_ext_t exma; 1220 1221 if (stp == NULL) 1222 return (-1); /* errno is set for us */ 1223 1224 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY) 1225 return (smb_set_errno(shp, ESMB_TYPE)); 1226 1227 smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma)); 1228 bzero(emap, sizeof (smbios_memarray_ext_t)); 1229 1230 emap->smbmae_ma = exma.smbmarre_ma; 1231 emap->smbmae_comp = exma.smbmarre_component; 1232 emap->smbmae_bdf = exma.smbmarre_bdf; 1233 1234 return (0); 1235 } 1236 1237 int 1238 smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id, 1239 smbios_memdevice_ext_t *emdp) 1240 { 1241 const smb_struct_t *stp = smb_lookup_id(shp, id); 1242 smb_memdevice_ext_t exmd; 1243 1244 if (stp == NULL) 1245 return (-1); /* errno is set for us */ 1246 1247 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE) 1248 return (smb_set_errno(shp, ESMB_TYPE)); 1249 1250 smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd)); 1251 bzero(emdp, sizeof (smbios_memdevice_ext_t)); 1252 1253 emdp->smbmdeve_md = exmd.smbmdeve_mdev; 1254 emdp->smbmdeve_drch = exmd.smbmdeve_dchan; 1255 emdp->smbmdeve_ncs = exmd.smbmdeve_ncs; 1256 emdp->smbmdeve_cs = exmd.smbmdeve_cs; 1257 1258 return (0); 1259 } 1260