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