xref: /freebsd/sys/dev/smbios/smbios.h (revision f689cb23b2782d0d0f586bcfabbad68f728ed1df)
1d0673fe1SAllan Jude /*-
2d0673fe1SAllan Jude  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
30d0673fe1SAllan Jude  */
31d0673fe1SAllan Jude 
32d0673fe1SAllan Jude #ifndef _SMBIOS_H_
33d0673fe1SAllan Jude #define _SMBIOS_H_
34d0673fe1SAllan Jude 
35d0673fe1SAllan Jude /*
36d0673fe1SAllan Jude  * System Management BIOS
37d0673fe1SAllan Jude  */
38d0673fe1SAllan Jude #define	SMBIOS_START	0xf0000
39d0673fe1SAllan Jude #define	SMBIOS_STEP	0x10
40d0673fe1SAllan Jude #define	SMBIOS_OFF	0
41d0673fe1SAllan Jude #define	SMBIOS_LEN	4
42d0673fe1SAllan Jude #define	SMBIOS_SIG	"_SM_"
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;
59*f689cb23SGreg V } __packed;
60d0673fe1SAllan Jude 
61d0673fe1SAllan Jude struct smbios_structure_header {
62d0673fe1SAllan Jude 	uint8_t		type;
63d0673fe1SAllan Jude 	uint8_t		length;
64d0673fe1SAllan Jude 	uint16_t	handle;
65*f689cb23SGreg V } __packed;
66*f689cb23SGreg V 
67*f689cb23SGreg V typedef void (*smbios_callback_t)(struct smbios_structure_header *, void *);
68*f689cb23SGreg V 
69*f689cb23SGreg V static inline void
70*f689cb23SGreg V smbios_walk_table(uint8_t *p, int entries, smbios_callback_t cb, void *arg)
71*f689cb23SGreg V {
72*f689cb23SGreg V 	struct smbios_structure_header *s;
73*f689cb23SGreg V 
74*f689cb23SGreg V 	while (entries--) {
75*f689cb23SGreg V 		s = (struct smbios_structure_header *)p;
76*f689cb23SGreg V 		cb(s, arg);
77*f689cb23SGreg V 
78*f689cb23SGreg V 		/*
79*f689cb23SGreg V 		 * Look for a double-nul after the end of the
80*f689cb23SGreg V 		 * formatted area of this structure.
81*f689cb23SGreg V 		 */
82*f689cb23SGreg V 		p += s->length;
83*f689cb23SGreg V 		while (!(p[0] == 0 && p[1] == 0))
84*f689cb23SGreg V 			p++;
85*f689cb23SGreg V 
86*f689cb23SGreg V 		/*
87*f689cb23SGreg V 		 * Skip over the double-nul to the start of the next
88*f689cb23SGreg V 		 * structure.
89*f689cb23SGreg V 		 */
90*f689cb23SGreg V 		p += 2;
91*f689cb23SGreg V 	}
92*f689cb23SGreg V }
93d0673fe1SAllan Jude 
94d0673fe1SAllan Jude #endif /* _SMBIOS_H_ */
95