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