1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
5 * Adapted from coreboot src/include/smbios.h
11 #include <dm/ofnode.h>
13 /* SMBIOS spec version implemented */
14 #define SMBIOS_MAJOR_VER 3
15 #define SMBIOS_MINOR_VER 0
18 SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */
21 /* SMBIOS structure types */
23 SMBIOS_BIOS_INFORMATION = 0,
24 SMBIOS_SYSTEM_INFORMATION = 1,
25 SMBIOS_BOARD_INFORMATION = 2,
26 SMBIOS_SYSTEM_ENCLOSURE = 3,
27 SMBIOS_PROCESSOR_INFORMATION = 4,
28 SMBIOS_CACHE_INFORMATION = 7,
29 SMBIOS_SYSTEM_SLOTS = 9,
30 SMBIOS_PHYS_MEMORY_ARRAY = 16,
31 SMBIOS_MEMORY_DEVICE = 17,
32 SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS = 19,
33 SMBIOS_SYSTEM_BOOT_INFORMATION = 32,
34 SMBIOS_END_OF_TABLE = 127
37 #define SMBIOS_INTERMEDIATE_OFFSET 16
38 #define SMBIOS_STRUCT_EOS_BYTES 2
40 struct __packed smbios_entry {
49 u8 intermediate_anchor[5];
50 u8 intermediate_checksum;
51 u16 struct_table_length;
52 u32 struct_table_address;
57 /* BIOS characteristics */
58 #define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7)
59 #define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11)
60 #define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16)
62 #define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0)
63 #define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3)
64 #define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)
66 struct __packed smbios_type0 {
72 u16 bios_start_segment;
75 u64 bios_characteristics;
76 u8 bios_characteristics_ext1;
77 u8 bios_characteristics_ext2;
78 u8 bios_major_release;
79 u8 bios_minor_release;
82 char eos[SMBIOS_STRUCT_EOS_BYTES];
85 struct __packed smbios_type1 {
97 char eos[SMBIOS_STRUCT_EOS_BYTES];
100 #define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0)
101 #define SMBIOS_BOARD_MOTHERBOARD 10
103 struct __packed smbios_type2 {
116 char eos[SMBIOS_STRUCT_EOS_BYTES];
119 #define SMBIOS_ENCLOSURE_DESKTOP 3
120 #define SMBIOS_STATE_SAFE 3
121 #define SMBIOS_SECURITY_NONE 3
123 struct __packed smbios_type3 {
133 u8 power_supply_state;
138 u8 number_of_power_cords;
140 u8 element_record_length;
141 char eos[SMBIOS_STRUCT_EOS_BYTES];
144 #define SMBIOS_PROCESSOR_TYPE_CENTRAL 3
145 #define SMBIOS_PROCESSOR_STATUS_ENABLED 1
146 #define SMBIOS_PROCESSOR_UPGRADE_NONE 6
148 #define SMBIOS_PROCESSOR_FAMILY_OTHER 1
149 #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2
151 struct __packed smbios_type4 {
155 u8 socket_designation;
158 u8 processor_manufacturer;
160 u8 processor_version;
166 u8 processor_upgrade;
176 u16 processor_characteristics;
177 u16 processor_family2;
181 char eos[SMBIOS_STRUCT_EOS_BYTES];
184 struct __packed smbios_type32 {
190 char eos[SMBIOS_STRUCT_EOS_BYTES];
193 struct __packed smbios_type127 {
197 char eos[SMBIOS_STRUCT_EOS_BYTES];
200 struct __packed smbios_header {
207 * fill_smbios_header() - Fill the header of an SMBIOS table
209 * This fills the header of an SMBIOS table structure.
211 * @table: start address of the structure
212 * @type: the type of structure
213 * @length: the length of the formatted area of the structure
214 * @handle: the structure's handle, a unique 16-bit number
216 static inline void fill_smbios_header(void *table, int type,
217 int length, int handle)
219 struct smbios_header *header = table;
222 header->length = length - SMBIOS_STRUCT_EOS_BYTES;
223 header->handle = handle;
227 * write_smbios_table() - Write SMBIOS table
229 * This writes SMBIOS table at a given address.
231 * @addr: start address to write SMBIOS table. If this is not
232 * 16-byte-aligned then it will be aligned before the table is
234 * Return: end address of SMBIOS table (and start address for next entry)
235 * or NULL in case of an error
238 ulong write_smbios_table(ulong addr);
241 * smbios_entry() - Get a valid struct smbios_entry pointer
243 * @address: address where smbios tables is located
244 * @size: size of smbios table
245 * @return: NULL or a valid pointer to a struct smbios_entry
247 const struct smbios_entry *smbios_entry(u64 address, u32 size);
250 * smbios_header() - Search for SMBIOS header type
252 * @entry: pointer to a struct smbios_entry
254 * @return: NULL or a valid pointer to a struct smbios_header
256 const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
259 * smbios_string() - Return string from SMBIOS
261 * @header: pointer to struct smbios_header
262 * @index: string index
263 * @return: NULL or a valid char pointer
265 char *smbios_string(const struct smbios_header *header, int index);
268 * smbios_update_version() - Update the version string
270 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
271 * main loop has started) to update the BIOS version string (SMBIOS table 0).
273 * @version: New version string to use
274 * @return 0 if OK, -ENOENT if no version string was previously written,
275 * -ENOSPC if the new string is too large to fit
277 int smbios_update_version(const char *version);
280 * smbios_update_version_full() - Update the version string
282 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
283 * main loop has started) to update the BIOS version string (SMBIOS table 0).
284 * It scans for the correct place to put the version, so does not need U-Boot
285 * to have actually written the tables itself (e.g. if a previous bootloader
288 * @smbios_tab: Start of SMBIOS tables
289 * @version: New version string to use
290 * @return 0 if OK, -ENOENT if no version string was previously written,
291 * -ENOSPC if the new string is too large to fit
293 int smbios_update_version_full(void *smbios_tab, const char *version);
296 * smbios_prepare_measurement() - Update smbios table for the measurement
298 * TCG specification requires to measure static configuration information.
299 * This function clear the device dependent parameters such as
300 * serial number for the measurement.
302 * @entry: pointer to a struct smbios_entry
303 * @header: pointer to a struct smbios_header
305 void smbios_prepare_measurement(const struct smbios_entry *entry,
306 struct smbios_header *header);
308 #endif /* _SMBIOS_H_ */