1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Adapted from coreboot src/include/smbios.h
11 #include <linux/types.h>
12 #include <smbios_def.h>
14 /* SMBIOS spec version implemented */
15 #define SMBIOS_MAJOR_VER 3
16 #define SMBIOS_MINOR_VER 7
19 SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */
22 /* SMBIOS structure types */
24 SMBIOS_BIOS_INFORMATION = 0,
25 SMBIOS_SYSTEM_INFORMATION = 1,
26 SMBIOS_BOARD_INFORMATION = 2,
27 SMBIOS_SYSTEM_ENCLOSURE = 3,
28 SMBIOS_PROCESSOR_INFORMATION = 4,
29 SMBIOS_CACHE_INFORMATION = 7,
30 SMBIOS_SYSTEM_SLOTS = 9,
31 SMBIOS_PHYS_MEMORY_ARRAY = 16,
32 SMBIOS_MEMORY_DEVICE = 17,
33 SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS = 19,
34 SMBIOS_SYSTEM_BOOT_INFORMATION = 32,
35 SMBIOS_END_OF_TABLE = 127
38 #define SMBIOS_INTERMEDIATE_OFFSET 16
39 #define SMBIOS_STRUCT_EOS_BYTES 2
41 struct str_lookup_table {
46 struct __packed smbios_entry {
55 u8 intermediate_anchor[5];
56 u8 intermediate_checksum;
57 u16 struct_table_length;
58 u32 struct_table_address;
64 * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure
66 struct __packed smbios3_entry {
67 /** @anchor: anchor string */
69 /** @checksum: checksum of the entry point structure */
71 /** @length: length of the entry point structure */
73 /** @major_ver: major version of the SMBIOS specification */
75 /** @minor_ver: minor version of the SMBIOS specification */
77 /** @docrev: revision of the SMBIOS specification */
79 /** @entry_point_rev: revision of the entry point structure */
81 /** @reserved: reserved */
83 /** maximum size of SMBIOS table */
84 u32 table_maximum_size;
85 /** @struct_table_address: 64-bit physical starting address */
86 u64 struct_table_address;
89 struct __packed smbios_header {
95 struct __packed smbios_type0 {
96 struct smbios_header hdr;
99 u16 bios_start_segment;
100 u8 bios_release_date;
102 u64 bios_characteristics;
103 u8 bios_characteristics_ext1;
104 u8 bios_characteristics_ext2;
105 u8 bios_major_release;
106 u8 bios_minor_release;
109 u16 extended_bios_rom_size;
110 char eos[SMBIOS_STRUCT_EOS_BYTES];
113 #define SMBIOS_TYPE1_LENGTH_V20 0x08
114 #define SMBIOS_TYPE1_LENGTH_V21 0x19
115 #define SMBIOS_TYPE1_LENGTH_V24 0x1b
117 struct __packed smbios_type1 {
118 struct smbios_header hdr;
127 char eos[SMBIOS_STRUCT_EOS_BYTES];
130 #define SMBIOS_TYPE2_CON_OBJ_HANDLE_SIZE sizeof(u16)
132 struct __packed smbios_type2 {
133 struct smbios_header hdr;
143 u8 number_contained_objects;
145 * Dynamic bytes will be inserted here to store the objects.
146 * length is equal to 'number_contained_objects'.
148 char eos[SMBIOS_STRUCT_EOS_BYTES];
151 struct __packed smbios_type3 {
152 struct smbios_header hdr;
159 u8 power_supply_state;
164 u8 number_of_power_cords;
166 u8 element_record_length;
168 * Dynamic bytes will be inserted here to store the elements.
169 * length is equal to 'element_record_length' * 'element_record_length'
172 char eos[SMBIOS_STRUCT_EOS_BYTES];
175 struct __packed smbios_type4 {
176 struct smbios_header hdr;
180 u8 processor_manufacturer;
182 u8 processor_version;
188 u8 processor_upgrade;
198 u16 processor_characteristics;
199 u16 processor_family2;
204 char eos[SMBIOS_STRUCT_EOS_BYTES];
220 union cache_size_word {
228 union cache_size_dword {
236 union cache_sram_type {
250 struct __packed smbios_type7 {
251 struct smbios_header hdr;
253 union cache_config config;
254 union cache_size_word max_size;
255 union cache_size_word inst_size;
256 union cache_sram_type supp_sram_type;
257 union cache_sram_type curr_sram_type;
262 union cache_size_dword max_size2;
263 union cache_size_dword inst_size2;
264 char eos[SMBIOS_STRUCT_EOS_BYTES];
267 struct __packed smbios_type32 {
273 char eos[SMBIOS_STRUCT_EOS_BYTES];
276 struct __packed smbios_type127 {
280 char eos[SMBIOS_STRUCT_EOS_BYTES];
284 * fill_smbios_header() - Fill the header of an SMBIOS table
286 * This fills the header of an SMBIOS table structure.
288 * @table: start address of the structure
289 * @type: the type of structure
290 * @length: the length of the formatted area of the structure
291 * @handle: the structure's handle, a unique 16-bit number
293 static inline void fill_smbios_header(void *table, int type,
294 int length, int handle)
296 struct smbios_header *header = table;
299 header->length = length - SMBIOS_STRUCT_EOS_BYTES;
300 header->handle = handle;
304 * write_smbios_table() - Write SMBIOS table
306 * This writes SMBIOS table at a given address.
308 * @addr: start address to write SMBIOS table, 16-byte-alignment
309 * recommended. Note that while the SMBIOS tables themself have no alignment
310 * requirement, some systems may requires alignment. For example x86 systems
311 * which put tables at f0000 require 16-byte alignment
313 * Return: end address of SMBIOS table (and start address for next entry)
314 * or NULL in case of an error
316 ulong write_smbios_table(ulong addr);
319 * smbios_entry() - Get a valid struct smbios_entry pointer
321 * @address: address where smbios tables is located
322 * @size: size of smbios table
323 * @return: NULL or a valid pointer to a struct smbios_entry
325 const struct smbios_entry *smbios_entry(u64 address, u32 size);
328 * smbios_header() - Search for SMBIOS header type
330 * @entry: pointer to a struct smbios_entry
332 * @return: NULL or a valid pointer to a struct smbios_header
334 const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
337 * smbios_string() - Return string from SMBIOS
339 * @header: pointer to struct smbios_header
340 * @index: string index
341 * @return: NULL or a valid char pointer
343 char *smbios_string(const struct smbios_header *header, int index);
346 * smbios_update_version() - Update the version string
348 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
349 * main loop has started) to update the BIOS version string (SMBIOS table 0).
351 * @version: New version string to use
352 * Return: 0 if OK, -ENOENT if no version string was previously written,
353 * -ENOSPC if the new string is too large to fit
355 int smbios_update_version(const char *version);
358 * smbios_update_version_full() - Update the version string
360 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
361 * main loop has started) to update the BIOS version string (SMBIOS table 0).
362 * It scans for the correct place to put the version, so does not need U-Boot
363 * to have actually written the tables itself (e.g. if a previous bootloader
366 * @smbios_tab: Start of SMBIOS tables
367 * @version: New version string to use
368 * Return: 0 if OK, -ENOENT if no version string was previously written,
369 * -ENOSPC if the new string is too large to fit
371 int smbios_update_version_full(void *smbios_tab, const char *version);
374 * smbios_prepare_measurement() - Update smbios table for the measurement
376 * TCG specification requires to measure static configuration information.
377 * This function clear the device dependent parameters such as
378 * serial number for the measurement.
380 * @entry: pointer to a struct smbios3_entry
381 * @header: pointer to a struct smbios_header
383 void smbios_prepare_measurement(const struct smbios3_entry *entry,
384 struct smbios_header *header);
386 #endif /* _SMBIOS_H_ */