xref: /freebsd/sys/dev/smbios/smbios.h (revision 06326613afebc645433c6bf8a2249cf978db9e71)
1d0673fe1SAllan Jude /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3d0673fe1SAllan Jude  *
4d0673fe1SAllan Jude  * Copyright (c) 1997 Michael Smith
5d0673fe1SAllan Jude  * Copyright (c) 1998 Jonathan Lemon
6d0673fe1SAllan Jude  * All rights reserved.
7d0673fe1SAllan Jude  *
8d0673fe1SAllan Jude  * Redistribution and use in source and binary forms, with or without
9d0673fe1SAllan Jude  * modification, are permitted provided that the following conditions
10d0673fe1SAllan Jude  * are met:
11d0673fe1SAllan Jude  * 1. Redistributions of source code must retain the above copyright
12d0673fe1SAllan Jude  *    notice, this list of conditions and the following disclaimer.
13d0673fe1SAllan Jude  * 2. Redistributions in binary form must reproduce the above copyright
14d0673fe1SAllan Jude  *    notice, this list of conditions and the following disclaimer in the
15d0673fe1SAllan Jude  *    documentation and/or other materials provided with the distribution.
16d0673fe1SAllan Jude  *
17d0673fe1SAllan Jude  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18d0673fe1SAllan Jude  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19d0673fe1SAllan Jude  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20d0673fe1SAllan Jude  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21d0673fe1SAllan Jude  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22d0673fe1SAllan Jude  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23d0673fe1SAllan Jude  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24d0673fe1SAllan Jude  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25d0673fe1SAllan Jude  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26d0673fe1SAllan Jude  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27d0673fe1SAllan Jude  * SUCH DAMAGE.
28d0673fe1SAllan Jude  */
29d0673fe1SAllan Jude 
30d0673fe1SAllan Jude #ifndef _SMBIOS_H_
31d0673fe1SAllan Jude #define _SMBIOS_H_
32d0673fe1SAllan Jude 
33d0673fe1SAllan Jude /*
34d0673fe1SAllan Jude  * System Management BIOS
35d0673fe1SAllan Jude  */
36d0673fe1SAllan Jude #define	SMBIOS_START	0xf0000
37d0673fe1SAllan Jude #define	SMBIOS_STEP	0x10
38d0673fe1SAllan Jude #define	SMBIOS_OFF	0
39d0673fe1SAllan Jude #define	SMBIOS_LEN	4
40d0673fe1SAllan Jude #define	SMBIOS_SIG	"_SM_"
41ba0e4d79SAndrew Gallatin #define	SMBIOS3_LEN	5
42ba0e4d79SAndrew Gallatin #define	SMBIOS3_SIG	"_SM3_"
43d0673fe1SAllan Jude 
44d0673fe1SAllan Jude struct smbios_eps {
45d0673fe1SAllan Jude 	uint8_t		anchor_string[4];		/* '_SM_' */
46d0673fe1SAllan Jude 	uint8_t		checksum;
47d0673fe1SAllan Jude 	uint8_t		length;
48d0673fe1SAllan Jude 	uint8_t		major_version;
49d0673fe1SAllan Jude 	uint8_t		minor_version;
50d0673fe1SAllan Jude 	uint16_t	maximum_structure_size;
51d0673fe1SAllan Jude 	uint8_t		entry_point_revision;
52d0673fe1SAllan Jude 	uint8_t		formatted_area[5];
53d0673fe1SAllan Jude 	uint8_t		intermediate_anchor_string[5];	/* '_DMI_' */
54d0673fe1SAllan Jude 	uint8_t		intermediate_checksum;
55d0673fe1SAllan Jude 	uint16_t	structure_table_length;
56d0673fe1SAllan Jude 	uint32_t	structure_table_address;
57d0673fe1SAllan Jude 	uint16_t	number_structures;
58d0673fe1SAllan Jude 	uint8_t		BCD_revision;
59f689cb23SGreg V } __packed;
60d0673fe1SAllan Jude 
61ba0e4d79SAndrew Gallatin struct smbios3_eps {
62ba0e4d79SAndrew Gallatin         uint8_t		anchor_string[5];                /* '_SM3_' */
63ba0e4d79SAndrew Gallatin         uint8_t		checksum;
64ba0e4d79SAndrew Gallatin         uint8_t		length;
65ba0e4d79SAndrew Gallatin         uint8_t		major_version;
66ba0e4d79SAndrew Gallatin         uint8_t		minor_version;
67ba0e4d79SAndrew Gallatin         uint8_t		docrev;
68ba0e4d79SAndrew Gallatin         uint8_t		entry_point_revision;
69ba0e4d79SAndrew Gallatin         uint8_t		reserved;
70ba0e4d79SAndrew Gallatin         uint32_t	structure_table_max_size;
71ba0e4d79SAndrew Gallatin         uint64_t	structure_table_address;
72ba0e4d79SAndrew Gallatin };
73ba0e4d79SAndrew Gallatin 
74d0673fe1SAllan Jude struct smbios_structure_header {
75d0673fe1SAllan Jude 	uint8_t		type;
76d0673fe1SAllan Jude 	uint8_t		length;
77d0673fe1SAllan Jude 	uint16_t	handle;
78f689cb23SGreg V } __packed;
79f689cb23SGreg V 
80f689cb23SGreg V typedef void (*smbios_callback_t)(struct smbios_structure_header *, void *);
81f689cb23SGreg V 
82f689cb23SGreg V static inline void
83*06326613SWarner Losh smbios_walk_table(uint8_t *p, int entries, vm_size_t len,
84*06326613SWarner Losh     smbios_callback_t cb, void *arg)
85f689cb23SGreg V {
86f689cb23SGreg V 	struct smbios_structure_header *s;
87*06326613SWarner Losh 	uint8_t *endp = p + len;
88f689cb23SGreg V 
89*06326613SWarner Losh 	while (entries-- && p < endp) {
90f689cb23SGreg V 		s = (struct smbios_structure_header *)p;
91f689cb23SGreg V 		cb(s, arg);
92f689cb23SGreg V 
93f689cb23SGreg V 		/*
94f689cb23SGreg V 		 * Look for a double-nul after the end of the
95f689cb23SGreg V 		 * formatted area of this structure.
96f689cb23SGreg V 		 */
97f689cb23SGreg V 		p += s->length;
98*06326613SWarner Losh 		while (p + 1 < endp && !(p[0] == 0 && p[1] == 0))
99f689cb23SGreg V 			p++;
100f689cb23SGreg V 
101f689cb23SGreg V 		/*
102f689cb23SGreg V 		 * Skip over the double-nul to the start of the next
103f689cb23SGreg V 		 * structure.
104f689cb23SGreg V 		 */
105f689cb23SGreg V 		p += 2;
106f689cb23SGreg V 	}
107f689cb23SGreg V }
108d0673fe1SAllan Jude 
1092fee8756SJohn-Mark Gurney #ifdef _KERNEL
1102fee8756SJohn-Mark Gurney void identify_hypervisor_smbios(void);
1112fee8756SJohn-Mark Gurney #endif
1122fee8756SJohn-Mark Gurney 
113d0673fe1SAllan Jude #endif /* _SMBIOS_H_ */
114