1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
24  * Copyright (c) 2018, Joyent, Inc.
25  * Copyright 2020 Oxide Computer Company
26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 /*
31  * This header file defines the implementation structures for the SMBIOS access
32  * library, libsmbios, and an equivalent kernel module.  Clients should use
33  * the <smbios.h> or <sys/smbios.h> header files to access DMTF SMBIOS
34  * information, NOT these underlying implementation structures from the spec.
35  * In short, do not user this header file or these routines for any purpose.
36  */
37 
38 #ifndef	_SYS_SMBIOS_IMPL_H
39 #define	_SYS_SMBIOS_IMPL_H
40 
41 #include <sys/smbios.h>
42 #include <sys/sysmacros.h>
43 
44 #ifdef _KERNEL
45 #include <sys/systm.h>
46 #else
47 #include <strings.h>
48 #include <stddef.h>
49 #endif
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * Definitions required to interpret the BIOS type information.
57  */
58 #define	SMB_BIOSXB_EXTROM	6
59 
60 #define	SMB_BIOS_EXTROM_VALUE_MASK(x)	((x) & 0x3fff)
61 #define	SMB_BIOS_EXTROM_SHIFT_MASK(x)	(((x) & 0xc000) >> 14)
62 
63 #pragma pack(1)
64 
65 typedef struct smb_header {
66 	uint8_t smbh_type;		/* structure type (SMB_TYPE_* value) */
67 	uint8_t smbh_len;		/* length in bytes of formatted area */
68 	uint16_t smbh_hdl;		/* structure handle */
69 } smb_header_t;
70 
71 /*
72  * SMBIOS implementation structure for SMB_TYPE_BIOS.
73  */
74 typedef struct smb_bios {
75 	smb_header_t smbbi_hdr;		/* structure header */
76 	uint8_t smbbi_vendor;		/* bios vendor string */
77 	uint8_t smbbi_version;		/* bios version string */
78 	uint16_t smbbi_segment;		/* segment location of bios address */
79 	uint8_t smbbi_reldate;		/* bios release date */
80 	uint8_t smbbi_romsize;		/* bios rom size (64k * (n + 1)) */
81 	uint64_t smbbi_cflags;		/* bios characteristics */
82 	uint8_t smbbi_xcflags[1];	/* bios characteristics extensions */
83 } smb_bios_t;
84 
85 /*
86  * SMBIOS implementation structure for SMB_TYPE_SYSTEM.
87  */
88 typedef struct smb_system {
89 	smb_header_t smbsi_hdr;		/* structure header */
90 	uint8_t smbsi_manufacturer;	/* manufacturer */
91 	uint8_t smbsi_product;		/* product name */
92 	uint8_t smbsi_version;		/* version */
93 	uint8_t smbsi_serial;		/* serial number */
94 	uint8_t smbsi_uuid[16];		/* UUID */
95 	uint8_t smbsi_wakeup;		/* wake-up type */
96 	uint8_t smbsi_sku;		/* SKU number */
97 	uint8_t smbsi_family;		/* family */
98 } smb_system_t;
99 
100 /*
101  * SMBIOS implementation structure for SMB_TYPE_BASEBOARD.
102  */
103 typedef struct smb_bboard {
104 	smb_header_t smbbb_hdr;		/* structure header */
105 	uint8_t smbbb_manufacturer;	/* manufacturer */
106 	uint8_t smbbb_product;		/* product name */
107 	uint8_t smbbb_version;		/* version */
108 	uint8_t smbbb_serial;		/* serial number */
109 	uint8_t smbbb_asset;		/* asset tag */
110 	uint8_t smbbb_flags;		/* feature flags */
111 	uint8_t smbbb_location;		/* location in chassis */
112 	uint16_t smbbb_chassis;		/* chassis handle */
113 	uint8_t smbbb_type;		/* board type */
114 	uint8_t smbbb_cn;		/* number of contained handles */
115 	uint16_t smbbb_cv[1];		/* array of contained handles */
116 } smb_bboard_t;
117 
118 /*
119  * SMBIOS implementation structure for SMB_TYPE_CHASSIS.
120  */
121 typedef struct smb_chassis {
122 	smb_header_t smbch_hdr;		/* structure header */
123 	uint8_t smbch_manufacturer;	/* manufacturer */
124 	uint8_t smbch_type;		/* type */
125 	uint8_t smbch_version;		/* version */
126 	uint8_t smbch_serial;		/* serial number */
127 	uint8_t smbch_asset;		/* asset tag */
128 	uint8_t smbch_bustate;		/* boot-up state */
129 	uint8_t smbch_psstate;		/* power supply state */
130 	uint8_t smbch_thstate;		/* thermal state */
131 	uint8_t smbch_security;		/* security state */
132 	uint32_t smbch_oemdata;		/* OEM-specific data */
133 	uint8_t smbch_uheight;		/* enclosure height */
134 	uint8_t smbch_cords;		/* number of power cords */
135 	uint8_t smbch_cn;		/* number of contained records */
136 	uint8_t smbch_cm;		/* size of contained records */
137 	uint8_t smbch_cv[1];		/* array of contained records */
138 } smb_chassis_t;
139 
140 /* WARNING: the argument is evaluated three times! */
141 #define	SMB_CH_SKU(smbcp) ((char *) \
142 	(smbcp)->smbch_cv + ((smbcp)->smbch_cn * (smbcp)->smbch_cm))
143 #define	SMB_CHT_LOCK	0x80		/* lock bit within smbch_type */
144 
145 /*
146  * SMBIOS implementation structure for SMB_TYPE_PROCESSOR.
147  */
148 typedef struct smb_processor {
149 	smb_header_t smbpr_hdr;		/* structure header */
150 	uint8_t smbpr_socket;		/* socket designation */
151 	uint8_t smbpr_type;		/* processor type (see <smbios.h>) */
152 	uint8_t smbpr_family;		/* processor family (see <smbios.h>) */
153 	uint8_t smbpr_manufacturer;	/* manufacturer */
154 	uint64_t smbpr_cpuid;		/* processor cpuid information */
155 	uint8_t smbpr_version;		/* version */
156 	uint8_t smbpr_voltage;		/* voltage */
157 	uint16_t smbpr_clkspeed;	/* external clock speed in MHz */
158 	uint16_t smbpr_maxspeed;	/* maximum speed in MHz */
159 	uint16_t smbpr_curspeed;	/* current speed in MHz */
160 	uint8_t smbpr_status;		/* status (see <smbios.h>) */
161 	uint8_t smbpr_upgrade;		/* upgrade */
162 	uint16_t smbpr_l1cache;		/* L1 cache handle (if any) */
163 	uint16_t smbpr_l2cache;		/* L2 cache handle (if any) */
164 	uint16_t smbpr_l3cache;		/* L3 cache handle (if any) */
165 	uint8_t smbpr_serial;		/* serial number */
166 	uint8_t smbpr_asset;		/* asset tag */
167 	uint8_t smbpr_part;		/* part number */
168 	uint8_t smbpr_corecount;	/* number of cores per socket */
169 	uint8_t smbpr_coresenabled;	/* number of enabled cores per socket */
170 	uint8_t smbpr_threadcount;	/* number of threads per socket */
171 	uint16_t smbpr_cflags;	/* cpu characteristics (see <smbios.h>) */
172 	uint16_t smbpr_family2;		/* processor family2 (see <smbios.h>) */
173 	uint16_t smbpr_corecount2;	/* second number of cores per socket */
174 	uint16_t smbpr_coresenabled2;	/* second number of enabled cores */
175 	uint16_t smbpr_threadcount2;	/* second number of enabled threads */
176 } smb_processor_t;
177 
178 /*
179  * SMBIOS implementation structure for SMB_TYPE_CACHE.
180  */
181 typedef struct smb_cache {
182 	smb_header_t smbca_hdr;		/* structure header */
183 	uint8_t smbca_socket;		/* socket designation */
184 	uint16_t smbca_config;		/* cache configuration */
185 	uint16_t smbca_maxsize;		/* maximum installed size */
186 	uint16_t smbca_size;		/* installed size */
187 	uint16_t smbca_stype;		/* supported SRAM type */
188 	uint16_t smbca_ctype;		/* current SRAM type */
189 	uint8_t smbca_speed;		/* speed in nanoseconds */
190 	uint8_t smbca_etype;		/* error correction type */
191 	uint8_t smbca_ltype;		/* logical cache type */
192 	uint8_t smbca_assoc;		/* associativity */
193 	uint32_t smbca_maxsize2;	/* maximum installed size 2 */
194 	uint32_t smbca_size2;		/* installed size 2 */
195 } smb_cache_t;
196 
197 /*
198  * Convert encoded cache size to bytes: DSP0134 Section 7.8 explains the
199  * encoding.  The highest bit is 0 for 1k units, 1 for 64k units, and this
200  * macro decodes the value into bytes for exporting to our clients.
201  */
202 #define	SMB_CACHE_SIZE(s)	(((s) & 0x8000) ? \
203 	((uint32_t)((s) & 0x7FFF) * 64 * 1024) : ((uint32_t)(s) * 1024))
204 
205 #define	SMB_CACHE_EXT_SIZE(s)	(((s) & 0x80000000U) ?	\
206 	((uint64_t)((s) & 0x7FFFFFFFULL) * 64ULL * 1024ULL) :	\
207 	((uint64_t)(s) * 1024ULL))
208 
209 #define	SMB_CACHE_CFG_MODE(c)		(((c) >> 8) & 3)
210 #define	SMB_CACHE_CFG_ENABLED(c)	(((c) >> 7) & 1)
211 #define	SMB_CACHE_CFG_LOCATION(c)	(((c) >> 5) & 3)
212 #define	SMB_CACHE_CFG_SOCKETED(c)	(((c) >> 3) & 1)
213 #define	SMB_CACHE_CFG_LEVEL(c)		(((c) & 7) + 1)
214 
215 /*
216  * SMBIOS implementation structure for SMB_TYPE_PORT.
217  */
218 typedef struct smb_port {
219 	smb_header_t smbpo_hdr;		/* structure header */
220 	uint8_t smbpo_iref;		/* internal reference designator */
221 	uint8_t smbpo_itype;		/* internal connector type */
222 	uint8_t smbpo_eref;		/* external reference designator */
223 	uint8_t smbpo_etype;		/* external connector type */
224 	uint8_t smbpo_ptype;		/* port type */
225 } smb_port_t;
226 
227 /*
228  * SMBIOS implementation structure for SMB_TYPE_SLOT.
229  */
230 typedef struct smb_slot_peer {
231 	uint16_t smbspb_group_no;	/* segment group number */
232 	uint8_t smbspb_bus;		/* bus number */
233 	uint8_t smbspb_df;		/* device/function number */
234 	uint8_t smbspb_width;		/* electrical width */
235 } smb_slot_peer_t;
236 
237 typedef struct smb_slot {
238 	smb_header_t smbsl_hdr;		/* structure header */
239 	uint8_t smbsl_name;		/* reference designation */
240 	uint8_t smbsl_type;		/* slot type */
241 	uint8_t smbsl_width;		/* slot data bus width */
242 	uint8_t smbsl_usage;		/* current usage */
243 	uint8_t smbsl_length;		/* slot length */
244 	uint16_t smbsl_id;		/* slot ID */
245 	uint8_t smbsl_ch1;		/* slot characteristics 1 */
246 	uint8_t smbsl_ch2;		/* slot characteristics 2 */
247 	uint16_t smbsl_sg;		/* segment group number */
248 	uint8_t smbsl_bus;		/* bus number */
249 	uint8_t smbsl_df;		/* device/function number */
250 	/* Added in SMBIOS 3.2+ */
251 	uint8_t	smbsl_dbw;		/* Data bus width */
252 	uint8_t	smbsl_npeers;		/* Peer bdf groups */
253 	smb_slot_peer_t smbsl_peers[];	/* bifurcation peers */
254 	/* There are later additions in 3.4+, see smbios_slot_cont_t */
255 } smb_slot_t;
256 
257 /*
258  * After the variable number of smbsl_peers, the smbios_slot has continued in
259  * size and has the following members defined as of version 3.4. These occur
260  * starting at byte 14 + 5 * smbsl_npeers.
261  */
262 typedef struct smb_slot_cont {
263 	uint8_t smbsl_info;		/* slot info */
264 	uint8_t smbsl_pwidth;		/* slot physical width */
265 	uint16_t smbsl_pitch;		/* slot pitch */
266 } smb_slot_cont_t;
267 
268 /*
269  * The first byte that the smb_slot_cont_t is defined to start at.
270  */
271 #define	SMB_SLOT_CONT_START	0x14
272 
273 /*
274  * SMBIOS implementation structure for SMB_TYPE_OBDEVS.
275  */
276 typedef struct smb_obdev {
277 	uint8_t smbob_type;		/* encoded type and enable bit */
278 	uint8_t smbob_name;		/* description string */
279 } smb_obdev_t;
280 
281 #define	SMB_OBT_ENABLED		0x80	/* enable bit within smbob_type */
282 
283 /*
284  * SMBIOS implementation structure for SMB_TYPE_OEMSTR, SMB_TYPE_SYSCONFSTR,
285  * and SMB_TYPE_LANG.
286  */
287 typedef struct smb_strtab {
288 	smb_header_t smbtb_hdr;		/* structure header */
289 	uint8_t smbtb_count;		/* number of strings */
290 } smb_strtab_t;
291 
292 /*
293  * SMBIOS implementation structure for SMB_TYPE_LANG.
294  */
295 typedef struct smb_lang {
296 	smb_header_t smblang_hdr;	/* structure header */
297 	uint8_t smblang_num;		/* number of installed languages */
298 	uint8_t smblang_flags;		/* flags */
299 	uint8_t smblang_resv[15];	/* reserved for future use */
300 	uint8_t smblang_cur;		/* current language string */
301 } smb_lang_t;
302 
303 /*
304  * SMBIOS implementation structure for SMB_TYPE_EVENTLOG.
305  */
306 typedef struct smb_sel {
307 	smb_header_t smbsel_hdr;	/* structure header */
308 	uint16_t smbsel_len;		/* log area length */
309 	uint16_t smbsel_hdroff;		/* header offset */
310 	uint16_t smbsel_dataoff;	/* data offset */
311 	uint8_t smbsel_method;		/* access method */
312 	uint8_t smbsel_status;		/* status flags */
313 	uint32_t smbsel_token;		/* change token */
314 	uint32_t smbsel_addr;		/* access method address */
315 	uint8_t smbsel_format;		/* header format */
316 	uint8_t smbsel_typec;		/* number of type descriptors */
317 	uint8_t smbsel_typesz;		/* size of each type descriptor */
318 	uint8_t smbsel_typev[1];	/* array of type descriptors */
319 } smb_sel_t;
320 
321 /*
322  * SMBIOS implementation structure for SMB_TYPE_MEMARRAY.
323  */
324 typedef struct smb_memarray {
325 	smb_header_t smbmarr_hdr;	/* structure header */
326 	uint8_t smbmarr_loc;		/* location */
327 	uint8_t smbmarr_use;		/* use */
328 	uint8_t smbmarr_ecc;		/* error detect/correct mechanism */
329 	uint32_t smbmarr_cap;		/* maximum capacity */
330 	uint16_t smbmarr_err;		/* error handle */
331 	uint16_t smbmarr_ndevs;		/* number of slots or sockets */
332 	uint64_t smbmarr_extcap;	/* extended maximum capacity */
333 } smb_memarray_t;
334 
335 /*
336  * SMBIOS implementation structure for SMB_TYPE_MEMARRAYMAP.
337  */
338 typedef struct smb_memarrmap {
339 	smb_header_t smbamap_hdr;	/* structure header */
340 	uint32_t smbamap_start;		/* starting address in kilobytes */
341 	uint32_t smbamap_end;		/* ending address in kilobytes */
342 	uint16_t smbamap_array;		/* physical memory array handle */
343 	uint8_t smbamap_width;		/* partition width */
344 	uint64_t smbamap_extstart;	/* extended starting address in bytes */
345 	uint64_t smbamap_extend;	/* extended ending address in bytes */
346 } smb_memarrmap_t;
347 
348 /*
349  * SMBIOS implementation structure for SMB_TYPE_MEMDEVICE.
350  */
351 typedef struct smb_memdevice {
352 	smb_header_t smbmdev_hdr;	/* structure header */
353 	uint16_t smbmdev_array;		/* array handle */
354 	uint16_t smbmdev_error;		/* error handle */
355 	uint16_t smbmdev_twidth;	/* total width */
356 	uint16_t smbmdev_dwidth;	/* data width */
357 	uint16_t smbmdev_size;		/* size in either K or MB */
358 	uint8_t smbmdev_form;		/* form factor */
359 	uint8_t smbmdev_set;		/* device set */
360 	uint8_t smbmdev_dloc;		/* device locator */
361 	uint8_t smbmdev_bloc;		/* bank locator */
362 	uint8_t smbmdev_type;		/* memory type */
363 	uint16_t smbmdev_flags;		/* detail flags */
364 	uint16_t smbmdev_speed;		/* speed in MT/s */
365 	uint8_t smbmdev_manufacturer;	/* manufacturer */
366 	uint8_t smbmdev_serial;		/* serial number */
367 	uint8_t smbmdev_asset;		/* asset tag */
368 	uint8_t smbmdev_part;		/* part number */
369 	uint8_t smbmdev_attrs;		/* attributes */
370 	uint32_t smbmdev_extsize;	/* extended size */
371 	uint16_t smbmdev_clkspeed;	/* configured clock speed */
372 	uint16_t smbmdev_minvolt;	/* minimum voltage */
373 	uint16_t smbmdev_maxvolt;	/* maximum voltage */
374 	uint16_t smbmdev_confvolt;	/* configured voltage */
375 	/* Added in SMBIOS 3.2 */
376 	uint8_t smbmdev_memtech;	/* memory technology */
377 	uint16_t smbmdev_opmode;	/* memory operating mode capability */
378 	uint8_t smbmdev_fwver;		/* firmware version */
379 	uint16_t smbmdev_modulemfgid;	/* module manufacturer ID */
380 	uint16_t smbmdev_moduleprodid;	/* module product ID */
381 	uint16_t smbmdev_memsysmfgid;	/* memory controller manufacturer id */
382 	uint16_t smbmdev_memsysprodid;	/* memory controller product id */
383 	uint64_t smbmdev_nvsize;	/* non-volatile memory size */
384 	uint64_t smbmdev_volsize;	/* volatile memory size */
385 	uint64_t smbmdev_cachesize;	/* cache size */
386 	uint64_t smbmdev_logicalsize;	/* logical size */
387 	/* Added in SMBIOS 3.3 */
388 	uint32_t smbmdev_extspeed;	/* Extended device speed */
389 	uint32_t smbmdev_extclkspeed;	/* Extended clock speed */
390 } smb_memdevice_t;
391 
392 #define	SMB_MDS_KBYTES		0x8000	/* size in specified in kilobytes */
393 
394 /*
395  * SMBIOS implementation structure for SMB_TYPE_MEMDEVICEMAP.
396  */
397 typedef struct smb_memdevmap {
398 	smb_header_t smbdmap_hdr;	/* structure header */
399 	uint32_t smbdmap_start;		/* starting address in kilobytes */
400 	uint32_t smbdmap_end;		/* ending address in kilobytes */
401 	uint16_t smbdmap_device;	/* memory device handle */
402 	uint16_t smbdmap_array;		/* memory array mapped address handle */
403 	uint8_t smbdmap_rpos;		/* row position */
404 	uint8_t smbdmap_ipos;		/* interleave position */
405 	uint8_t smbdmap_idepth;		/* interleave depth */
406 	uint64_t smbdmap_extstart;	/* extended starting address */
407 	uint64_t smbdmap_extend;	/* extended ending address */
408 } smb_memdevmap_t;
409 
410 typedef struct smb_pointdev {
411 	smb_header_t smbpdev_hdr;	/* structure header */
412 	uint8_t smbpdev_type;		/* device type */
413 	uint8_t smbpdev_iface;		/* device interface */
414 	uint8_t smbpdev_nbuttons;	/* number of buttons */
415 } smb_pointdev_t;
416 
417 /*
418  * SMBIOS implementation structure for SMB_TYPE_BATTERY.
419  */
420 typedef struct smb_battery {
421 	smb_header_t smbbat_hdr;	/* structure header */
422 	uint8_t smbbat_loc;		/* location */
423 	uint8_t smbbat_manufacturer;	/* manufacturer */
424 	uint8_t smbbat_date;		/* manufacture date */
425 	uint8_t smbbat_serial;		/* serial number */
426 	uint8_t smbbat_devname;		/* device name */
427 	uint8_t smbbat_chem;		/* device chemistry */
428 	uint16_t smbbat_cap;		/* design capacity in mW hours */
429 	uint16_t smbbat_volt;		/* design voltage in mV */
430 	uint8_t smbbat_version;		/* SBDS version string */
431 	uint8_t smbbat_err;		/* error percentage */
432 	uint16_t smbbat_ssn;		/* SBDS serial number */
433 	uint16_t smbbat_sdate;		/* SBDS manufacture date */
434 	uint8_t smbbat_schem;		/* SBDS chemistry string */
435 	uint8_t smbbat_mult;		/* design capacity multiplier */
436 	uint32_t smbbat_oemdata;	/* OEM-specific data */
437 } smb_battery_t;
438 
439 /*
440  * SMBIOS implementation structure for SMB_TYPE_SECURITY.
441  */
442 typedef struct smb_hwsec {
443 	smb_header_t smbhs_hdr;		/* structure header */
444 	uint8_t smbhs_settings;		/* settings byte */
445 } smb_hwsec_t;
446 
447 #define	SMB_HWS_PWR_PS(x)	(((x) & 0xC0) >> 6)
448 #define	SMB_HWS_KBD_PS(x)	(((x) & 0x30) >> 4)
449 #define	SMB_HWS_ADM_PS(x)	(((x) & 0x0C) >> 2)
450 #define	SMB_HWS_PAN_PS(x)	(((x) & 0x03) >> 0)
451 
452 /*
453  * SMBIOS implementation structure for SMB_TYPE_VPROBE.
454  */
455 typedef struct smb_vprobe {
456 	smb_header_t smbvpr_hdr;	/* structure header */
457 	uint8_t smbvpr_descr;		/* description string */
458 	uint8_t smbvpr_locstat;		/* location and status */
459 	uint16_t smbvpr_maxval;		/* maximum voltage */
460 	uint16_t smbvpr_minval;		/* minimum voltage */
461 	uint16_t smbvpr_resolution;	/* probe resolution */
462 	uint16_t smbvpr_tolerance;	/* probe tolerance */
463 	uint16_t smbvpr_accuracy;	/* probe accuracy */
464 	uint32_t smbvpr_oem;		/* vendor-specific data */
465 	uint16_t smbvpr_nominal;	/* nominal value */
466 } smb_vprobe_t;
467 
468 #define	SMB_VPROBE_MINLEN		0x14
469 #define	SMB_VPROBE_NOMINAL_MINLEN	0x16
470 
471 #define	SMB_VPROBE_LOCATION(x)	((x) & 0x1f)
472 #define	SMB_VPROBE_STATUS(x)	(((x) >> 5) & 0x7)
473 
474 /*
475  * SMBIOS implementation structure for SMB_TYPE_COOLDEV.
476  */
477 typedef struct smb_cooldev {
478 	smb_header_t smbcdev_hdr;	/* structure header */
479 	uint16_t smbcdev_tprobe;	/* temperature probe */
480 	uint8_t smbcdev_typstat;	/* type and status */
481 	uint8_t smbcdev_group;		/* group identifier */
482 	uint32_t smbcdev_oem;		/* vendor-specific data */
483 	uint16_t smbcdev_nominal;	/* nominal value */
484 	uint8_t smbcdev_descr;		/* description string */
485 } smb_cooldev_t;
486 
487 #define	SMB_COOLDEV_MINLEN		0x0c
488 #define	SMB_COOLDEV_NOMINAL_MINLEN	0x0e
489 #define	SMB_COOLDEV_DESCR_MINLEN	0x0f
490 
491 #define	SMB_COOLDEV_TYPE(x)	((x) & 0x1f)
492 #define	SMB_COOLDEV_STATUS(x)	(((x) >> 5) & 0x7)
493 
494 /*
495  * SMBIOS implementation structure for SMB_TYPE_TPROBE.
496  */
497 typedef struct smb_tprobe {
498 	smb_header_t smbtpr_hdr;	/* structure header */
499 	uint8_t smbtpr_descr;		/* description string */
500 	uint8_t smbtpr_locstat;		/* location and status */
501 	uint16_t smbtpr_maxval;		/* maximum temperature */
502 	uint16_t smbtpr_minval;		/* minimum temperature */
503 	uint16_t smbtpr_resolution;	/* probe resolution */
504 	uint16_t smbtpr_tolerance;	/* probe tolerance */
505 	uint16_t smbtpr_accuracy;	/* probe accuracy */
506 	uint32_t smbtpr_oem;		/* vendor-specific data */
507 	uint16_t smbtpr_nominal;	/* nominal value */
508 } smb_tprobe_t;
509 
510 #define	SMB_TPROBE_MINLEN		0x14
511 #define	SMB_TPROBE_NOMINAL_MINLEN	0x16
512 
513 #define	SMB_TPROBE_LOCATION(x)	((x) & 0x1f)
514 #define	SMB_TPROBE_STATUS(x)	(((x) >> 5) & 0x7)
515 
516 /*
517  * SMBIOS implementation structure for SMB_TYPE_IPROBE.
518  */
519 typedef struct smb_iprobe {
520 	smb_header_t smbipr_hdr;	/* structure header */
521 	uint8_t smbipr_descr;		/* description string */
522 	uint8_t smbipr_locstat;		/* location and status */
523 	uint16_t smbipr_maxval;		/* maximum current */
524 	uint16_t smbipr_minval;		/* minimum current */
525 	uint16_t smbipr_resolution;	/* probe resolution */
526 	uint16_t smbipr_tolerance;	/* probe tolerance */
527 	uint16_t smbipr_accuracy;	/* probe accuracy */
528 	uint32_t smbipr_oem;		/* vendor-specific data */
529 	uint16_t smbipr_nominal;	/* nominal value */
530 } smb_iprobe_t;
531 
532 #define	SMB_IPROBE_MINLEN		0x14
533 #define	SMB_IPROBE_NOMINAL_MINLEN	0x16
534 
535 #define	SMB_IPROBE_LOCATION(x)	((x) & 0x1f)
536 #define	SMB_IPROBE_STATUS(x)	(((x) >> 5) & 0x7)
537 
538 /*
539  * SMBIOS implementation structure for SMB_TYPE_BOOT.
540  */
541 typedef struct smb_boot {
542 	smb_header_t smbbo_hdr;		/* structure header */
543 	uint8_t smbbo_pad[6];		/* reserved for future use */
544 	uint8_t smbbo_status[1];	/* variable-length status buffer */
545 } smb_boot_t;
546 
547 /*
548  * SMBIOS implementation structure for SMB_TYPE_IPMIDEV.
549  */
550 typedef struct smb_ipmi {
551 	smb_header_t smbipm_hdr;	/* structure header */
552 	uint8_t smbipm_type;		/* interface type */
553 	uint8_t smbipm_spec;		/* specification revision */
554 	uint8_t smbipm_i2c;		/* i2C slave address */
555 	uint8_t smbipm_bus;		/* NV storage device bus ID */
556 	uint64_t smbipm_addr;		/* base address */
557 	uint8_t smbipm_info;		/* base address modifier/intr info */
558 	uint8_t smbipm_intr;		/* interrupt number */
559 } smb_ipmi_t;
560 
561 #define	SMB_IPM_SPEC_MAJOR(x)	(((x) & 0xF0) >> 4)
562 #define	SMB_IPM_SPEC_MINOR(x)	((x) & 0x0F)
563 
564 #define	SMB_IPM_ADDR_IO		1ULL
565 
566 #define	SMB_IPM_INFO_REGS(x)	(((x) & 0xC0) >> 6)
567 #define	SMB_IPM_INFO_LSB(x)	(((x) & 0x10) >> 4)
568 #define	SMB_IPM_INFO_ISPEC(x)	(((x) & 0x08) >> 3)
569 #define	SMB_IPM_INFO_IPOL(x)	(((x) & 0x02) >> 1)
570 #define	SMB_IPM_INFO_IMODE(x)	(((x) & 0x01) >> 0)
571 
572 #define	SMB_IPM_REGS_1B		0
573 #define	SMB_IPM_REGS_4B		1
574 #define	SMB_IPM_REGS_16B	2
575 
576 #define	SMB_IPM_IPOL_LO		0
577 #define	SMB_IPM_IPOL_HI		1
578 
579 #define	SMB_IPM_IMODE_EDGE	0
580 #define	SMB_IPM_IMODE_LEVEL	1
581 
582 /*
583  * SMBIOS implementation structure for SMB_TYPE_POWERSUP.
584  */
585 typedef struct smb_powersup {
586 	smb_header_t smbpsup_hdr;	/* structure header */
587 	uint8_t smbpsup_group;		/* group id */
588 	uint8_t smbpsup_loc;		/* location tag */
589 	uint8_t smbpsup_devname;	/* device name */
590 	uint8_t smbpsup_manufacturer;	/* manufacturer */
591 	uint8_t smbpsup_serial;		/* serial number */
592 	uint8_t smbpsup_asset;		/* asset tag */
593 	uint8_t smbpsup_part;		/* part number */
594 	uint8_t smbpsup_rev;		/* revision string */
595 	uint16_t smbpsup_max;		/* max output in milliwatts */
596 	uint16_t smbpsup_char;		/* characteristics */
597 	uint16_t smbpsup_vprobe;	/* voltage probe handle */
598 	uint16_t smbpsup_cooldev;	/* cooling device handle */
599 	uint16_t smbpsup_iprobe;	/* current probe handle */
600 } smb_powersup_t;
601 
602 #define	SMB_PSU_CHARS_ISHOT(x)		((x) & 0x01)
603 #define	SMB_PSU_CHARS_ISPRES(x)		((x) & 0x02)
604 #define	SMB_PSU_CHARS_ISUNPLUG(x)	((x) & 0x04)
605 #define	SMB_PSU_CHARS_IVRS(x)		(((x) >> 3) & 0xf)
606 #define	SMB_PSU_CHARS_STATUS(x)		(((x) >> 7) & 0x7)
607 #define	SMB_PSU_CHARS_TYPE(x)		(((x) >> 10) & 0xf)
608 
609 /*
610  * SMBIOS implementation structure for SMB_TYPE_OBDEVEXT.
611  */
612 typedef struct smb_obdev_ext {
613 	smb_header_t smbobe_hdr;	/* structure header */
614 	uint8_t smbobe_name;		/* reference designation */
615 	uint8_t smbobe_dtype;		/* device type */
616 	uint8_t smbobe_dti;		/* device type instance */
617 	uint16_t smbobe_sg;		/* segment group number */
618 	uint8_t smbobe_bus;		/* bus number */
619 	uint8_t smbobe_df;		/* device/function number */
620 } smb_obdev_ext_t;
621 
622 /*
623  * SMBIOS implementation structure for SMB_TYPE_PROCESSOR_INFO
624  */
625 typedef struct smb_processor_info {
626 	smb_header_t smbpai_hdr;	/* structure handle */
627 	uint16_t smbpai_proc;		/* processor handle */
628 	uint8_t smbpai_len;		/* length of processor specific data */
629 	uint8_t smbpai_type;		/* processor type */
630 	uint8_t smbpai_data[];		/* processor-specific block */
631 } smb_processor_info_t;
632 
633 typedef struct smb_processor_info_riscv {
634 	uint16_t smbpairv_vers;		/* structure revision */
635 	uint8_t smbpairv_len;		/* length of structure */
636 	uint8_t smbpairv_hartid[16];	/* id of the hart */
637 	uint8_t smbpairv_boot;		/* boot hart */
638 	uint8_t smbpairv_vendid[16];	/* machine vendor id */
639 	uint8_t smbpairv_archid[16];	/* arch vendor id */
640 	uint8_t smbpairv_machid[16];	/* machine impl id */
641 	uint32_t smbpairv_isa;		/* supported ISA */
642 	uint8_t smbpairv_privlvl;		/* supported privilege levels */
643 	uint8_t smbpairv_metdi[16];	/* Machine exception trap delegation */
644 	uint8_t smbpairv_mitdi[16];	/* Machine interrupt trap delegation */
645 	uint8_t smbpairv_xlen;		/* Register width */
646 	uint8_t smbpairv_mxlen;		/* Machine register width */
647 	uint8_t smbpairv_rsvd;		/* Reserved */
648 	uint8_t smbpairv_sxlen;		/* Supervisor register width */
649 	uint8_t smbpairv_uxlen;		/* User register width */
650 } smb_processor_info_riscv_t;
651 
652 /*
653  * SMBIOS implementation structure for SUN_OEM_EXT_PROCESSOR.
654  */
655 typedef struct smb_processor_ext {
656 	smb_header_t smbpre_hdr;	/* structure header */
657 	uint16_t smbpre_processor;	/* processor handle */
658 	uint8_t smbpre_fru;		/* FRU indicator */
659 	uint8_t smbpre_n;		/* number of APIC IDs */
660 	uint16_t smbpre_apicid[1];	/* strand initial apic id */
661 } smb_processor_ext_t;
662 
663 /*
664  * SMBIOS implementation structure for SUN_OEM_EXT_PORT.
665  */
666 typedef struct smb_port_ext {
667 	smb_header_t smbpoe_hdr;	/* structure header */
668 	uint16_t smbpoe_chassis;	/* chassis handle */
669 	uint16_t smbpoe_port;		/* port connector handle */
670 	uint8_t smbpoe_dtype;		/* device type */
671 	uint16_t smbpoe_devhdl;		/* device handle */
672 	uint8_t smbpoe_phy;		/* PHY number */
673 } smb_port_ext_t;
674 
675 /*
676  * SMBIOS implementation structure for SUN_OEM_PCIEXRC.
677  */
678 typedef struct smb_pciexrc {
679 	smb_header_t smbpciexrc_hdr;	/* structure header */
680 	uint16_t smbpciexrc_bboard;	/* base board handle */
681 	uint16_t smbpciexrc_bdf;	/* PCI Bus/Dev/Func */
682 } smb_pciexrc_t;
683 
684 /*
685  * SMBIOS implementation structure for SUN_OEM_EXT_MEMARRAY.
686  */
687 typedef struct smb_memarray_ext {
688 	smb_header_t smbmarre_hdr;	/* structure header */
689 	uint16_t smbmarre_ma;		/* memory array handle */
690 	uint16_t smbmarre_component;	/* component parent handle */
691 	uint16_t smbmarre_bdf;		/* PCI bus/dev/funct */
692 } smb_memarray_ext_t;
693 
694 /*
695  * SMBIOS implementation structure for SUN_OEM_EXT_MEMDEVICE.
696  */
697 typedef struct smb_memdevice_ext {
698 	smb_header_t smbmdeve_hdr;	/* structure header */
699 	uint16_t smbmdeve_mdev;		/* memory device handle */
700 	uint8_t smbmdeve_dchan;		/* DRAM channel */
701 	uint8_t smbmdeve_ncs;		/* number of chip select */
702 	uint8_t smbmdeve_cs[1];		/* chip selects */
703 } smb_memdevice_ext_t;
704 
705 #pragma pack()
706 
707 typedef struct smb_struct {
708 	const smb_header_t *smbst_hdr;	/* address of raw structure data */
709 	const uchar_t *smbst_str;	/* address of string data (if any) */
710 	const uchar_t *smbst_end;	/* address of 0x0000 ending tag */
711 	struct smb_struct *smbst_next;	/* next structure in hash chain */
712 	uint16_t *smbst_strtab;		/* string index -> offset table */
713 	uint_t smbst_strtablen;		/* length of smbst_strtab */
714 } smb_struct_t;
715 
716 struct smbios_hdl {
717 	smbios_entry_point_t sh_ent_type; /* structure table entry point type */
718 	smbios_entry_t sh_ent;		/* structure table entry point */
719 	uint_t sh_ent_stnum;		/* number of structure table entries */
720 	const void *sh_buf;		/* structure table buffer */
721 	size_t sh_buflen;		/* size of structure table buffer */
722 	smb_struct_t *sh_structs;	/* array of structure descriptors */
723 	uint_t sh_nstructs;		/* number of active structures */
724 	smb_struct_t **sh_hash;		/* hash bucket array for descriptors */
725 	uint_t sh_hashlen;		/* hash bucket array length */
726 	int sh_err;			/* error code for smbios_errno() */
727 	int sh_libvers;			/* library client abi version */
728 	int sh_smbvers;			/* derived underlying format version */
729 	uint_t sh_flags;		/* miscellaneous flags (see below) */
730 };
731 
732 #define	SMB_FL_DEBUG	0x1		/* print debug messages for this hdl */
733 #define	SMB_FL_BUFALLOC	0x2		/* sh_buf was allocated by library */
734 #define	SMB_FL_TRUNC	0x4		/* smbios table is truncated */
735 
736 #define	SMB_BIOS_DEVICE		"/dev/xsvc"	/* device w/ BIOS physmem */
737 #define	SMB_SMBIOS_DEVICE	"/dev/smbios"	/* device w/ SMBIOS image */
738 
739 #define	SMB_RANGE_START	0xF0000		/* start of physical address range */
740 #define	SMB_RANGE_LIMIT	0xFFFFF		/* limit of physical address range */
741 #define	SMB_SCAN_STEP	16		/* stepping by paragraph */
742 
743 #define	SMB_MAJMIN(M, m)	((((M) & 0xFF) << 8) | ((m) & 0xFF))
744 #define	SMB_MAJOR(v)		(((v) & 0xFF00) >> 8)
745 #define	SMB_MINOR(v)		(((v) & 0x00FF))
746 
747 #define	ESMB_BASE	1000		/* base value for libsmbios errnos */
748 
749 enum {
750 	ESMB_NOTFOUND = ESMB_BASE,	/* SMBIOS table not found on system */
751 	ESMB_MAPDEV,			/* failed to map SMBIOS table */
752 	ESMB_NOENT,			/* failed to locate structure */
753 	ESMB_NOMEM,			/* failed to allocate memory */
754 	ESMB_NOHDR,			/* failed to read SMBIOS header */
755 	ESMB_NOSTAB,			/* failed to read SMBIOS struct table */
756 	ESMB_NOINFO,			/* no common info for structure */
757 	ESMB_SHORT,			/* buffer length doesn't match header */
758 	ESMB_CORRUPT,			/* buffer struct or len is corrupt */
759 	ESMB_VERSION,			/* version not supported by library */
760 	ESMB_NOTSUP,			/* feature not supported by provider */
761 	ESMB_HEADER,			/* SMBIOS header corrupt or invalid */
762 	ESMB_OLD,			/* SMBIOS version is too old for us */
763 	ESMB_NEW,			/* SMBIOS version is too new for us */
764 	ESMB_CKSUM,			/* SMBIOS header checksum mismatch */
765 	ESMB_INVAL,			/* invalid function call argument */
766 	ESMB_TYPE,			/* structure type mismatch */
767 	ESMB_UNKNOWN			/* unknown error (maximum value tag) */
768 };
769 
770 extern const smb_struct_t *smb_lookup_type(smbios_hdl_t *, uint_t);
771 extern const smb_struct_t *smb_lookup_id(smbios_hdl_t *, uint_t);
772 extern const char *smb_strptr(const smb_struct_t *, uint_t);
773 extern int smb_gteq(smbios_hdl_t *, int);
774 extern int smb_libgteq(smbios_hdl_t *, int);
775 
776 extern int smb_set_errno(smbios_hdl_t *, int);
777 extern smbios_hdl_t *smb_open_error(smbios_hdl_t *, int *, int);
778 extern const char *smb_strerror(int);
779 
780 extern void *smb_alloc(size_t);
781 extern void *smb_zalloc(size_t);
782 extern void smb_free(void *, size_t);
783 
784 extern void smb_dprintf(smbios_hdl_t *, const char *, ...);
785 
786 extern int _smb_debug;
787 
788 /*
789  * The following series of structures represent the base versions of public
790  * structures that are used inside by the smbios routines. This allows the
791  * common code to properly know how much it should or should not bzero and how
792  * to handle additions to the spec. Types should only be added here if we need
793  * to extend the public structures in sys/smbios.h due to a change in the spec.
794  *
795  * Types here have the name smb_base_%s which corresponds to smbios_%s.
796  */
797 typedef struct smb_base_chassis {
798 	uint32_t smbbc_oemdata;		/* OEM-specific data */
799 	uint8_t smbbc_lock;		/* lock present? */
800 	uint8_t smbbc_type;		/* type */
801 	uint8_t smbbc_bustate;		/* boot-up state */
802 	uint8_t smbbc_psstate;		/* power supply state */
803 	uint8_t smbbc_thstate;		/* thermal state */
804 	uint8_t smbbc_security;		/* security status */
805 	uint8_t smbbc_uheight;		/* enclosure height in U's */
806 	uint8_t smbbc_cords;		/* number of power cords */
807 	uint8_t smbbc_elems;		/* number of element records (n) */
808 	uint8_t smbbc_elemlen;		/* length of contained element (m) */
809 } smb_base_chassis_t;
810 
811 typedef struct smb_base_processor {
812 	uint64_t smbbp_cpuid;		/* processor cpuid information */
813 	uint32_t smbbp_family;		/* processor family */
814 	uint8_t smbbp_type;		/* processor type (SMB_PRT_*) */
815 	uint8_t smbbp_voltage;		/* voltage (SMB_PRV_*) */
816 	uint8_t smbbp_status;		/* status (SMB_PRS_*) */
817 	uint8_t smbbp_upgrade;		/* upgrade (SMB_PRU_*) */
818 	uint32_t smbbp_clkspeed;	/* external clock speed in MHz */
819 	uint32_t smbbp_maxspeed;	/* maximum speed in MHz */
820 	uint32_t smbbp_curspeed;	/* current speed in MHz */
821 	id_t smbbp_l1cache;		/* L1 cache handle */
822 	id_t smbbp_l2cache;		/* L2 cache handle */
823 	id_t smbbp_l3cache;		/* L3 cache handle */
824 } smb_base_processor_t;
825 
826 typedef struct smb_base_memdevice {
827 	id_t smbbmd_array;		/* handle of physical memory array */
828 	id_t smbbmd_error;		/* handle of memory error data */
829 	uint32_t smbbmd_twidth;		/* total width in bits including ecc */
830 	uint32_t smbbmd_dwidth;		/* data width in bits */
831 	uint64_t smbbmd_size;		/* size in bytes (see note above) */
832 	uint8_t smbbmd_form;		/* form factor */
833 	uint8_t smbbmd_set;		/* set (0x00=none, 0xFF=unknown) */
834 	uint8_t smbbmd_type;		/* memory type */
835 	uint8_t smbbmd_pad;		/* padding */
836 	uint32_t smbbmd_flags;		/* flags (see below) */
837 	uint32_t smbbmd_speed;		/* speed in MHz */
838 	const char *smbbmd_dloc;	/* physical device locator string */
839 	const char *smbbmd_bloc;	/* physical bank locator string */
840 	uint8_t smbbmd_rank;		/* rank */
841 } smb_base_memdevice_t;
842 
843 typedef struct smb_base_bios {
844 	const char *smbbb_vendor;	/* bios vendor string */
845 	const char *smbbb_version;	/* bios version string */
846 	const char *smbbb_reldate;	/* bios release date */
847 	uint32_t smbbb_segment;		/* bios address segment location */
848 	uint32_t smbbb_romsize;		/* bios rom size in bytes */
849 	uint32_t smbbb_runsize;		/* bios image size in bytes */
850 	uint64_t smbbb_cflags;		/* bios characteristics */
851 	const uint8_t *smbbb_xcflags;	/* bios characteristics extensions */
852 	size_t smbbb_nxcflags;		/* number of smbb_xcflags[] bytes */
853 	smbios_version_t smbbb_biosv;	/* bios version */
854 	smbios_version_t smbbb_ecfwv;	/* bios embedded ctrl f/w version */
855 } smb_base_bios_t;
856 
857 typedef struct smb_base_cache {
858 	uint32_t smbba_maxsize;		/* maximum installed size in bytes */
859 	uint32_t smbba_size;		/* installed size in bytes */
860 	uint16_t smbba_stype;		/* supported SRAM types (SMB_CAT_*) */
861 	uint16_t smbba_ctype;		/* current SRAM type (SMB_CAT_*) */
862 	uint8_t smbba_speed;		/* speed in nanoseconds */
863 	uint8_t smbba_etype;		/* error correction type (SMB_CAE_*) */
864 	uint8_t smbba_ltype;		/* logical cache type (SMB_CAG_*) */
865 	uint8_t smbba_assoc;		/* associativity (SMB_CAA_*) */
866 	uint8_t smbba_level;		/* cache level */
867 	uint8_t smbba_mode;		/* cache mode (SMB_CAM_*) */
868 	uint8_t smbba_location;		/* cache location (SMB_CAL_*) */
869 	uint8_t smbba_flags;		/* cache flags (SMB_CAF_*) */
870 } smb_base_cache_t;
871 
872 typedef struct smb_base_slot {
873 	const char *smbbl_name;		/* reference designation */
874 	uint8_t smbbl_type;		/* slot type */
875 	uint8_t smbbl_width;		/* slot data bus width */
876 	uint8_t smbbl_usage;		/* current usage */
877 	uint8_t smbbl_length;		/* slot length */
878 	uint16_t smbbl_id;		/* slot ID */
879 	uint8_t smbbl_ch1;		/* slot characteristics 1 */
880 	uint8_t smbbl_ch2;		/* slot characteristics 2 */
881 	uint16_t smbbl_sg;		/* segment group number */
882 	uint8_t smbbl_bus;		/* bus number */
883 	uint8_t smbbl_df;		/* device/function number */
884 } smb_base_slot_t;
885 
886 #ifdef	__cplusplus
887 }
888 #endif
889 
890 #endif	/* _SYS_SMBIOS_IMPL_H */
891