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 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * This header file defines the implementation structures for the SMBIOS access 29 * library, libsmbios, and an equivalent kernel module. Clients should use 30 * the <smbios.h> or <sys/smbios.h> header files to access DMTF SMBIOS 31 * information, NOT these underlying implementation structures from the spec. 32 * In short, do not user this header file or these routines for any purpose. 33 */ 34 35 #ifndef _SYS_SMBIOS_IMPL_H 36 #define _SYS_SMBIOS_IMPL_H 37 38 #include <sys/smbios.h> 39 #include <sys/sysmacros.h> 40 41 #ifdef _KERNEL 42 #include <sys/systm.h> 43 #else 44 #include <strings.h> 45 #include <stddef.h> 46 #endif 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 #pragma pack(1) 53 54 typedef struct smb_header { 55 uint8_t smbh_type; /* structure type (SMB_TYPE_* value) */ 56 uint8_t smbh_len; /* length in bytes of formatted area */ 57 uint16_t smbh_hdl; /* structure handle */ 58 } smb_header_t; 59 60 typedef struct smb_bios { 61 smb_header_t smbbi_hdr; /* structure header */ 62 uint8_t smbbi_vendor; /* bios vendor string */ 63 uint8_t smbbi_version; /* bios version string */ 64 uint16_t smbbi_segment; /* segment location of bios address */ 65 uint8_t smbbi_reldate; /* bios release date */ 66 uint8_t smbbi_romsize; /* bios rom size (64k * (n + 1)) */ 67 uint64_t smbbi_cflags; /* bios characteristics */ 68 uint8_t smbbi_xcflags[1]; /* bios characteristics extensions */ 69 } smb_bios_t; 70 71 typedef struct smb_system { 72 smb_header_t smbsi_hdr; /* structure header */ 73 uint8_t smbsi_manufacturer; /* manufacturer */ 74 uint8_t smbsi_product; /* product name */ 75 uint8_t smbsi_version; /* version */ 76 uint8_t smbsi_serial; /* serial number */ 77 uint8_t smbsi_uuid[16]; /* UUID */ 78 uint8_t smbsi_wakeup; /* wake-up type */ 79 uint8_t smbsi_sku; /* SKU number */ 80 uint8_t smbsi_family; /* family */ 81 } smb_system_t; 82 83 typedef struct smb_bboard { 84 smb_header_t smbbb_hdr; /* structure header */ 85 uint8_t smbbb_manufacturer; /* manufacturer */ 86 uint8_t smbbb_product; /* product name */ 87 uint8_t smbbb_version; /* version */ 88 uint8_t smbbb_serial; /* serial number */ 89 uint8_t smbbb_asset; /* asset tag */ 90 uint8_t smbbb_flags; /* feature flags */ 91 uint8_t smbbb_location; /* location in chassis */ 92 uint16_t smbbb_chassis; /* chassis handle */ 93 uint8_t smbbb_type; /* board type */ 94 uint8_t smbbb_cn; /* number of contained handles */ 95 uint16_t smbbb_cv[1]; /* array of contained handles */ 96 } smb_bboard_t; 97 98 typedef struct smb_chassis { 99 smb_header_t smbch_hdr; /* structure header */ 100 uint8_t smbch_manufacturer; /* manufacturer */ 101 uint8_t smbch_type; /* type */ 102 uint8_t smbch_version; /* version */ 103 uint8_t smbch_serial; /* serial number */ 104 uint8_t smbch_asset; /* asset tag */ 105 uint8_t smbch_bustate; /* boot-up state */ 106 uint8_t smbch_psstate; /* power supply state */ 107 uint8_t smbch_thstate; /* thermal state */ 108 uint8_t smbch_security; /* security state */ 109 uint32_t smbch_oemdata; /* OEM-specific data */ 110 uint8_t smbch_uheight; /* enclosure height */ 111 uint8_t smbch_cords; /* number of power cords */ 112 uint8_t smbch_cn; /* number of contained records */ 113 uint8_t smbch_cm; /* size of contained records */ 114 uint8_t smbch_cv[1]; /* array of contained records */ 115 } smb_chassis_t; 116 117 #define SMB_CHT_LOCK 0x80 /* lock bit within smbch_type */ 118 119 typedef struct smb_processor { 120 smb_header_t smbpr_hdr; /* structure header */ 121 uint8_t smbpr_socket; /* socket designation */ 122 uint8_t smbpr_type; /* processor type (see <smbios.h>) */ 123 uint8_t smbpr_family; /* processor family (see <smbios.h>) */ 124 uint8_t smbpr_manufacturer; /* manufacturer */ 125 uint64_t smbpr_cpuid; /* processor cpuid information */ 126 uint8_t smbpr_version; /* version */ 127 uint8_t smbpr_voltage; /* voltage */ 128 uint16_t smbpr_clkspeed; /* external clock speed in MHz */ 129 uint16_t smbpr_maxspeed; /* maximum speed in MHz */ 130 uint16_t smbpr_curspeed; /* current speed in MHz */ 131 uint8_t smbpr_status; /* status (see <smbios.h>) */ 132 uint8_t smbpr_upgrade; /* upgrade */ 133 uint16_t smbpr_l1cache; /* L1 cache handle (if any) */ 134 uint16_t smbpr_l2cache; /* L2 cache handle (if any) */ 135 uint16_t smbpr_l3cache; /* L3 cache handle (if any) */ 136 uint8_t smbpr_serial; /* serial number */ 137 uint8_t smbpr_asset; /* asset tag */ 138 uint8_t smbpr_part; /* part number */ 139 } smb_processor_t; 140 141 typedef struct smb_cache { 142 smb_header_t smbca_hdr; /* structure header */ 143 uint8_t smbca_socket; /* socket designation */ 144 uint16_t smbca_config; /* cache configuration */ 145 uint16_t smbca_maxsize; /* maximum installed size */ 146 uint16_t smbca_size; /* installed size */ 147 uint16_t smbca_stype; /* supported SRAM type */ 148 uint16_t smbca_ctype; /* current SRAM type */ 149 uint8_t smbca_speed; /* speed in nanoseconds */ 150 uint8_t smbca_etype; /* error correction type */ 151 uint8_t smbca_ltype; /* logical cache type */ 152 uint8_t smbca_assoc; /* associativity */ 153 } smb_cache_t; 154 155 /* 156 * Convert encoded cache size to bytes: DSP0134 Section 3.3.8 explains the 157 * encoding. The highest bit is 0 for 1k units, 1 for 64k units, and this 158 * macro decodes the value into bytes for exporting to our clients. 159 */ 160 #define SMB_CACHE_SIZE(s) (((s) & 0x8000) ? \ 161 ((uint32_t)((s) & 0x7FFF) * 64 * 1024) : ((uint32_t)(s) * 1024)) 162 163 #define SMB_CACHE_CFG_MODE(c) (((c) >> 8) & 3) 164 #define SMB_CACHE_CFG_ENABLED(c) (((c) >> 7) & 1) 165 #define SMB_CACHE_CFG_LOCATION(c) (((c) >> 5) & 3) 166 #define SMB_CACHE_CFG_SOCKETED(c) (((c) >> 3) & 1) 167 #define SMB_CACHE_CFG_LEVEL(c) (((c) & 7) + 1) 168 169 typedef struct smb_port { 170 smb_header_t smbpo_hdr; /* structure header */ 171 uint8_t smbpo_iref; /* internal reference designator */ 172 uint8_t smbpo_itype; /* internal connector type */ 173 uint8_t smbpo_eref; /* external reference designator */ 174 uint8_t smbpo_etype; /* external connector type */ 175 uint8_t smbpo_ptype; /* port type */ 176 } smb_port_t; 177 178 typedef struct smb_slot { 179 smb_header_t smbsl_hdr; /* structure header */ 180 uint8_t smbsl_name; /* reference designation */ 181 uint8_t smbsl_type; /* slot type */ 182 uint8_t smbsl_width; /* slot data bus width */ 183 uint8_t smbsl_usage; /* current usage */ 184 uint8_t smbsl_length; /* slot length */ 185 uint16_t smbsl_id; /* slot ID */ 186 uint8_t smbsl_ch1; /* slot characteristics 1 */ 187 uint8_t smbsl_ch2; /* slot characteristics 2 */ 188 } smb_slot_t; 189 190 typedef struct smb_obdev { 191 uint8_t smbob_type; /* encoded type and enable bit */ 192 uint8_t smbob_name; /* descriptiong string */ 193 } smb_obdev_t; 194 195 #define SMB_OBT_ENABLED 0x80 /* enable bit within smbob_type */ 196 197 typedef struct smb_strtab { 198 smb_header_t smbtb_hdr; /* structure header */ 199 uint8_t smbtb_count; /* number of strings */ 200 } smb_strtab_t; 201 202 typedef struct smb_lang { 203 smb_header_t smblang_hdr; /* structure header */ 204 uint8_t smblang_num; /* number of installed languages */ 205 uint8_t smblang_flags; /* flags */ 206 uint8_t smblang_resv[15]; /* reserved for future use */ 207 uint8_t smblang_cur; /* current language string */ 208 } smb_lang_t; 209 210 typedef struct smb_sel { 211 smb_header_t smbsel_hdr; /* structure header */ 212 uint16_t smbsel_len; /* log area length */ 213 uint16_t smbsel_hdroff; /* header offset */ 214 uint16_t smbsel_dataoff; /* data offset */ 215 uint8_t smbsel_method; /* access method */ 216 uint8_t smbsel_status; /* status flags */ 217 uint32_t smbsel_token; /* change token */ 218 uint32_t smbsel_addr; /* access method address */ 219 uint8_t smbsel_format; /* header format */ 220 uint8_t smbsel_typec; /* number of type descriptors */ 221 uint8_t smbsel_typesz; /* size of each type descriptor */ 222 uint8_t smbsel_typev[1]; /* array of type descriptors */ 223 } smb_sel_t; 224 225 typedef struct smb_memarray { 226 smb_header_t smbmarr_hdr; /* structure header */ 227 uint8_t smbmarr_loc; /* location */ 228 uint8_t smbmarr_use; /* use */ 229 uint8_t smbmarr_ecc; /* error detect/correct mechanism */ 230 uint32_t smbmarr_cap; /* maximum capacity */ 231 uint16_t smbmarr_err; /* error handle */ 232 uint16_t smbmarr_ndevs; /* number of slots or sockets */ 233 } smb_memarray_t; 234 235 typedef struct smb_memarrmap { 236 smb_header_t smbamap_hdr; /* structure header */ 237 uint32_t smbamap_start; /* starting address in kilobytes */ 238 uint32_t smbamap_end; /* ending address in kilobytes */ 239 uint16_t smbamap_array; /* physical memory array handle */ 240 uint8_t smbamap_width; /* partition width */ 241 } smb_memarrmap_t; 242 243 typedef struct smb_memdevice { 244 smb_header_t smbmdev_hdr; /* structure header */ 245 uint16_t smbmdev_array; /* array handle */ 246 uint16_t smbmdev_error; /* error handle */ 247 uint16_t smbmdev_twidth; /* total width */ 248 uint16_t smbmdev_dwidth; /* data width */ 249 uint16_t smbmdev_size; /* size in either K or MB */ 250 uint8_t smbmdev_form; /* form factor */ 251 uint8_t smbmdev_set; /* device set */ 252 uint8_t smbmdev_dloc; /* device locator */ 253 uint8_t smbmdev_bloc; /* bank locator */ 254 uint8_t smbmdev_type; /* memory type */ 255 uint16_t smbmdev_flags; /* detail flags */ 256 uint16_t smbmdev_speed; /* speed in MHz */ 257 uint8_t smbmdev_manufacturer; /* manufacturer */ 258 uint8_t smbmdev_serial; /* serial number */ 259 uint8_t smbmdev_asset; /* asset tag */ 260 uint8_t smbmdev_part; /* part number */ 261 } smb_memdevice_t; 262 263 #define SMB_MDS_KBYTES 0x8000 /* size in specified in kilobytes */ 264 265 typedef struct smb_memdevmap { 266 smb_header_t smbdmap_hdr; /* structure header */ 267 uint32_t smbdmap_start; /* starting address in kilobytes */ 268 uint32_t smbdmap_end; /* ending address in kilobytes */ 269 uint16_t smbdmap_device; /* memory device handle */ 270 uint16_t smbdmap_array; /* memory array mapped address handle */ 271 uint8_t smbdmap_rpos; /* row position */ 272 uint8_t smbdmap_ipos; /* interleave position */ 273 uint8_t smbdmap_idepth; /* interleave depth */ 274 } smb_memdevmap_t; 275 276 typedef struct smb_battery { 277 smb_header_t smbbat_hdr; /* structure header */ 278 uint8_t smbbat_loc; /* location */ 279 uint8_t smbbat_manufacturer; /* manufacturer */ 280 uint8_t smbbat_date; /* manufacture date */ 281 uint8_t smbbat_serial; /* serial number */ 282 uint8_t smbbat_devname; /* device name */ 283 uint8_t smbbat_chem; /* device chemistry */ 284 uint16_t smbbat_cap; /* design capacity in mW hours */ 285 uint16_t smbbat_volt; /* design voltage in mV */ 286 uint8_t smbbat_version; /* SBDS version string */ 287 uint8_t smbbat_err; /* error percentage */ 288 uint16_t smbbat_ssn; /* SBDS serial number */ 289 uint16_t smbbat_sdate; /* SBDS manufacture date */ 290 uint8_t smbbat_schem; /* SBDS chemistry string */ 291 uint8_t smbbat_mult; /* design capacity multiplier */ 292 uint32_t smbbat_oemdata; /* OEM-specific data */ 293 } smb_battery_t; 294 295 typedef struct smb_hwsec { 296 smb_header_t smbhs_hdr; /* structure header */ 297 uint8_t smbhs_settings; /* settings byte */ 298 } smb_hwsec_t; 299 300 #define SMB_HWS_PWR_PS(x) (((x) & 0xC0) >> 6) 301 #define SMB_HWS_KBD_PS(x) (((x) & 0x30) >> 4) 302 #define SMB_HWS_ADM_PS(x) (((x) & 0x0C) >> 2) 303 #define SMB_HWS_PAN_PS(x) (((x) & 0x03) >> 0) 304 305 typedef struct smb_boot { 306 smb_header_t smbbo_hdr; /* structure header */ 307 uint8_t smbbo_pad[6]; /* reserved for future use */ 308 uint8_t smbbo_status[1]; /* variable-length status buffer */ 309 } smb_boot_t; 310 311 typedef struct smb_ipmi { 312 smb_header_t smbipm_hdr; /* structure header */ 313 uint8_t smbipm_type; /* interface type */ 314 uint8_t smbipm_spec; /* specification revision */ 315 uint8_t smbipm_i2c; /* i2C slave address */ 316 uint8_t smbipm_bus; /* NV storage device bus ID */ 317 uint64_t smbipm_addr; /* base address */ 318 uint8_t smbipm_info; /* base address modifier/intr info */ 319 uint8_t smbipm_intr; /* interrupt number */ 320 } smb_ipmi_t; 321 322 #define SMB_IPM_SPEC_MAJOR(x) (((x) & 0xF0) >> 4) 323 #define SMB_IPM_SPEC_MINOR(x) ((x) & 0x0F) 324 325 #define SMB_IPM_ADDR_IO 1ULL 326 327 #define SMB_IPM_INFO_REGS(x) (((x) & 0xC0) >> 6) 328 #define SMB_IPM_INFO_LSB(x) (((x) & 0x10) >> 4) 329 #define SMB_IPM_INFO_ISPEC(x) (((x) & 0x08) >> 3) 330 #define SMB_IPM_INFO_IPOL(x) (((x) & 0x02) >> 1) 331 #define SMB_IPM_INFO_IMODE(x) (((x) & 0x01) >> 0) 332 333 #define SMB_IPM_REGS_1B 0 334 #define SMB_IPM_REGS_4B 1 335 #define SMB_IPM_REGS_16B 2 336 337 #define SMB_IPM_IPOL_LO 0 338 #define SMB_IPM_IPOL_HI 1 339 340 #define SMB_IPM_IMODE_EDGE 0 341 #define SMB_IPM_IMODE_LEVEL 1 342 343 typedef struct smb_powersup { 344 smb_header_t smbpsup_hdr; /* structure header */ 345 uint8_t smbpsup_group; /* group id */ 346 uint8_t smbpsup_loc; /* location tag */ 347 uint8_t smbpsup_devname; /* device name */ 348 uint8_t smbpsup_manufacturer; /* manufacturer */ 349 uint8_t smbpsup_serial; /* serial number */ 350 uint8_t smbpsup_asset; /* asset tag */ 351 uint8_t smbpsup_part; /* part number */ 352 uint8_t smbpsup_rev; /* revision string */ 353 uint16_t smbpsup_max; /* max output in milliwatts */ 354 uint16_t smbpsup_char; /* characteristics */ 355 uint16_t smbpsup_vprobe; /* voltage probe handle */ 356 uint16_t smbpsup_cooldev; /* cooling device handle */ 357 uint16_t smbpsup_iprobe; /* current probe handle */ 358 } smb_powersup_t; 359 360 typedef struct smb_processor_ext { 361 smb_header_t smbpre_hdr; /* structure header */ 362 uint16_t smbpre_processor; /* processor handle */ 363 uint8_t smbpre_fru; /* FRU indicator */ 364 uint8_t smbpre_n; /* number of APIC IDs */ 365 uint16_t smbpre_apicid[1]; /* strand initial apic id */ 366 } smb_processor_ext_t; 367 368 typedef struct smb_pciexrc { 369 smb_header_t smbpciexrc_hdr; /* structure header */ 370 uint16_t smbpciexrc_bboard; /* base board handle */ 371 uint16_t smbpciexrc_bdf; /* PCI Bus/Dev/Func */ 372 } smb_pciexrc_t; 373 374 typedef struct smb_memarray_ext { 375 smb_header_t smbmarre_hdr; /* structure header */ 376 uint16_t smbmarre_ma; /* memory array handle */ 377 uint16_t smbmarre_component; /* component parent handle */ 378 uint16_t smbmarre_bdf; /* PCI bus/dev/funct */ 379 } smb_memarray_ext_t; 380 381 typedef struct smb_memdevice_ext { 382 smb_header_t smbmdeve_hdr; /* structure header */ 383 uint16_t smbmdeve_mdev; /* memory device handle */ 384 uint8_t smbmdeve_dchan; /* DRAM channel */ 385 uint8_t smbmdeve_ncs; /* number of chip select */ 386 uint8_t smbmdeve_cs[1]; /* chip selects */ 387 } smb_memdevice_ext_t; 388 389 #pragma pack() 390 391 typedef struct smb_struct { 392 const smb_header_t *smbst_hdr; /* address of raw structure data */ 393 const uchar_t *smbst_str; /* address of string data (if any) */ 394 const uchar_t *smbst_end; /* address of 0x0000 ending tag */ 395 struct smb_struct *smbst_next; /* next structure in hash chain */ 396 uint16_t *smbst_strtab; /* string index -> offset table */ 397 uint_t smbst_strtablen; /* length of smbst_strtab */ 398 } smb_struct_t; 399 400 struct smbios_hdl { 401 smbios_entry_t sh_ent; /* structure table entry point */ 402 const void *sh_buf; /* structure table buffer */ 403 size_t sh_buflen; /* size of structure table buffer */ 404 smb_struct_t *sh_structs; /* array of structure descriptors */ 405 uint_t sh_nstructs; /* number of active structures */ 406 smb_struct_t **sh_hash; /* hash bucket array for descriptors */ 407 uint_t sh_hashlen; /* hash bucket array length */ 408 int sh_err; /* error code for smbios_errno() */ 409 int sh_libvers; /* library client abi version */ 410 int sh_smbvers; /* derived underlying format version */ 411 uint_t sh_flags; /* miscellaneous flags (see below) */ 412 }; 413 414 #define SMB_FL_DEBUG 0x1 /* print debug messages for this hdl */ 415 #define SMB_FL_BUFALLOC 0x2 /* sh_buf was allocated by library */ 416 417 #define SMB_BIOS_DEVICE "/dev/xsvc" /* device w/ BIOS physmem */ 418 #define SMB_SMBIOS_DEVICE "/dev/smbios" /* device w/ SMBIOS image */ 419 420 #define SMB_RANGE_START 0xF0000 /* start of physical address range */ 421 #define SMB_RANGE_LIMIT 0xFFFFF /* limit of physical address range */ 422 423 #define SMB_MAJMIN(M, m) ((((M) & 0xFF) << 16) | ((m) & 0xFF)) 424 #define SMB_MAJOR(v) (((v) & 0xFF00) >> 8) 425 #define SMB_MINOR(v) (((v) & 0x00FF)) 426 427 #define ESMB_BASE 1000 /* base value for libsmbios errnos */ 428 429 enum { 430 ESMB_NOTFOUND = ESMB_BASE, /* SMBIOS table not found on system */ 431 ESMB_MAPDEV, /* failed to map SMBIOS table */ 432 ESMB_NOENT, /* failed to locate structure */ 433 ESMB_NOMEM, /* failed to allocate memory */ 434 ESMB_NOHDR, /* failed to read SMBIOS header */ 435 ESMB_NOSTAB, /* failed to read SMBIOS struct table */ 436 ESMB_NOINFO, /* no common info for structure */ 437 ESMB_SHORT, /* buffer length doesn't match header */ 438 ESMB_CORRUPT, /* buffer struct or len is corrupt */ 439 ESMB_VERSION, /* version not supported by library */ 440 ESMB_NOTSUP, /* feature not supported by provider */ 441 ESMB_HEADER, /* SMBIOS header corrupt or invalid */ 442 ESMB_OLD, /* SMBIOS version is too old for us */ 443 ESMB_NEW, /* SMBIOS version is too new for us */ 444 ESMB_CKSUM, /* SMBIOS header checksum mismatch */ 445 ESMB_INVAL, /* invalid function call argument */ 446 ESMB_TYPE, /* structure type mismatch */ 447 ESMB_UNKNOWN /* unknown error (maximum value tag) */ 448 }; 449 450 extern const smb_struct_t *smb_lookup_type(smbios_hdl_t *, uint_t); 451 extern const smb_struct_t *smb_lookup_id(smbios_hdl_t *, uint_t); 452 extern const char *smb_strptr(const smb_struct_t *, uint_t); 453 extern int smb_gteq(smbios_hdl_t *, int); 454 455 extern int smb_set_errno(smbios_hdl_t *, int); 456 extern smbios_hdl_t *smb_open_error(smbios_hdl_t *, int *, int); 457 extern const char *smb_strerror(int); 458 459 extern void *smb_alloc(size_t); 460 extern void *smb_zalloc(size_t); 461 extern void smb_free(void *, size_t); 462 463 extern void smb_dprintf(smbios_hdl_t *, const char *, ...); 464 465 extern int _smb_debug; 466 467 #ifdef __cplusplus 468 } 469 #endif 470 471 #endif /* _SYS_SMBIOS_IMPL_H */ 472