blob: a4fda9df7bd0e96f938c2e249ce025c96a4628cd [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Bin Meng721e9922015-10-12 05:23:41 -07002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 *
5 * Adapted from coreboot src/include/smbios.h
Bin Meng721e9922015-10-12 05:23:41 -07006 */
7
8#ifndef _SMBIOS_H_
9#define _SMBIOS_H_
10
Heinrich Schuchardtefe441a2024-01-03 09:07:20 +010011#include <linux/types.h>
Simon Glass78227d42020-11-05 06:32:07 -070012
Bin Meng721e9922015-10-12 05:23:41 -070013/* SMBIOS spec version implemented */
14#define SMBIOS_MAJOR_VER 3
Simon Glass70924292023-12-31 08:25:47 -070015#define SMBIOS_MINOR_VER 7
Bin Meng721e9922015-10-12 05:23:41 -070016
Simon Glass272e62c2021-03-15 18:00:11 +130017enum {
18 SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */
19};
20
Bin Meng721e9922015-10-12 05:23:41 -070021/* SMBIOS structure types */
22enum {
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
35};
36
37#define SMBIOS_INTERMEDIATE_OFFSET 16
38#define SMBIOS_STRUCT_EOS_BYTES 2
39
40struct __packed smbios_entry {
41 u8 anchor[4];
42 u8 checksum;
43 u8 length;
44 u8 major_ver;
45 u8 minor_ver;
46 u16 max_struct_size;
47 u8 entry_point_rev;
48 u8 formatted_area[5];
49 u8 intermediate_anchor[5];
50 u8 intermediate_checksum;
51 u16 struct_table_length;
52 u32 struct_table_address;
53 u16 struct_count;
54 u8 bcd_rev;
55};
56
Heinrich Schuchardtde4b91c2023-12-31 08:25:46 -070057/**
58 * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure
59 */
60struct __packed smbios3_entry {
61 /** @anchor: anchor string */
62 u8 anchor[5];
63 /** @checksum: checksum of the entry point structure */
64 u8 checksum;
65 /** @length: length of the entry point structure */
66 u8 length;
67 /** @major_ver: major version of the SMBIOS specification */
68 u8 major_ver;
69 /** @minor_ver: minor version of the SMBIOS specification */
70 u8 minor_ver;
71 /** @docrev: revision of the SMBIOS specification */
72 u8 doc_rev;
73 /** @entry_point_rev: revision of the entry point structure */
74 u8 entry_point_rev;
75 /** @reserved: reserved */
76 u8 reserved;
77 /** maximum size of SMBIOS table */
Heinrich Schuchardt406c4102024-01-31 23:49:34 +010078 u32 table_maximum_size;
Heinrich Schuchardtde4b91c2023-12-31 08:25:46 -070079 /** @struct_table_address: 64-bit physical starting address */
80 u64 struct_table_address;
81};
82
Bin Meng721e9922015-10-12 05:23:41 -070083/* BIOS characteristics */
84#define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7)
85#define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11)
86#define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16)
87
88#define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0)
Ilias Apalodimasff192302021-06-09 18:14:47 +030089#define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3)
Bin Meng721e9922015-10-12 05:23:41 -070090#define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)
91
92struct __packed smbios_type0 {
93 u8 type;
94 u8 length;
95 u16 handle;
96 u8 vendor;
97 u8 bios_ver;
98 u16 bios_start_segment;
99 u8 bios_release_date;
100 u8 bios_rom_size;
101 u64 bios_characteristics;
102 u8 bios_characteristics_ext1;
103 u8 bios_characteristics_ext2;
104 u8 bios_major_release;
105 u8 bios_minor_release;
106 u8 ec_major_release;
107 u8 ec_minor_release;
108 char eos[SMBIOS_STRUCT_EOS_BYTES];
109};
110
Heinrich Schuchardt6eca28b2024-02-10 12:06:48 +0100111/**
112 * enum smbios_wakeup_type - wake-up type
113 *
114 * These constants are used for the Wake-Up Type field in the SMBIOS
115 * System Information (Type 1) structure.
116 */
117enum smbios_wakeup_type {
118 /** @SMBIOS_WAKEUP_TYPE_RESERVED: Reserved */
119 SMBIOS_WAKEUP_TYPE_RESERVED,
120 /** @SMBIOS_WAKEUP_TYPE_OTHER: Other */
121 SMBIOS_WAKEUP_TYPE_OTHER,
122 /** @SMBIOS_WAKEUP_TYPE_UNKNOWN: Unknown */
123 SMBIOS_WAKEUP_TYPE_UNKNOWN,
124 /** @SMBIOS_WAKEUP_TYPE_APM_TIMER: APM Timer */
125 SMBIOS_WAKEUP_TYPE_APM_TIMER,
126 /** @SMBIOS_WAKEUP_TYPE_MODEM_RING: Modem Ring */
127 SMBIOS_WAKEUP_TYPE_MODEM_RING,
128 /** @SMBIOS_WAKEUP_TYPE_LAN_REMOTE: LAN Remote */
129 SMBIOS_WAKEUP_TYPE_LAN_REMOTE,
130 /** @SMBIOS_WAKEUP_TYPE_POWER_SWITCH: Power Switch */
131 SMBIOS_WAKEUP_TYPE_POWER_SWITCH,
132 /** @SMBIOS_WAKEUP_TYPE_PCI_PME: PCI PME# */
133 SMBIOS_WAKEUP_TYPE_PCI_PME,
134 /** @SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED: AC Power Restored */
135 SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED,
136};
137
Bin Meng721e9922015-10-12 05:23:41 -0700138struct __packed smbios_type1 {
139 u8 type;
140 u8 length;
141 u16 handle;
142 u8 manufacturer;
143 u8 product_name;
144 u8 version;
145 u8 serial_number;
146 u8 uuid[16];
147 u8 wakeup_type;
148 u8 sku_number;
149 u8 family;
150 char eos[SMBIOS_STRUCT_EOS_BYTES];
151};
152
153#define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0)
154#define SMBIOS_BOARD_MOTHERBOARD 10
155
156struct __packed smbios_type2 {
157 u8 type;
158 u8 length;
159 u16 handle;
160 u8 manufacturer;
161 u8 product_name;
162 u8 version;
163 u8 serial_number;
164 u8 asset_tag_number;
165 u8 feature_flags;
166 u8 chassis_location;
167 u16 chassis_handle;
168 u8 board_type;
Heinrich Schuchardta5866c32024-01-25 16:54:33 +0100169 u8 number_contained_objects;
Bin Meng721e9922015-10-12 05:23:41 -0700170 char eos[SMBIOS_STRUCT_EOS_BYTES];
171};
172
173#define SMBIOS_ENCLOSURE_DESKTOP 3
174#define SMBIOS_STATE_SAFE 3
175#define SMBIOS_SECURITY_NONE 3
176
177struct __packed smbios_type3 {
178 u8 type;
179 u8 length;
180 u16 handle;
181 u8 manufacturer;
182 u8 chassis_type;
183 u8 version;
184 u8 serial_number;
185 u8 asset_tag_number;
186 u8 bootup_state;
187 u8 power_supply_state;
188 u8 thermal_state;
189 u8 security_status;
190 u32 oem_defined;
191 u8 height;
192 u8 number_of_power_cords;
193 u8 element_count;
194 u8 element_record_length;
195 char eos[SMBIOS_STRUCT_EOS_BYTES];
196};
197
198#define SMBIOS_PROCESSOR_TYPE_CENTRAL 3
199#define SMBIOS_PROCESSOR_STATUS_ENABLED 1
200#define SMBIOS_PROCESSOR_UPGRADE_NONE 6
201
Alexander Graf96476202016-08-19 01:23:28 +0200202#define SMBIOS_PROCESSOR_FAMILY_OTHER 1
203#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2
204
Bin Meng721e9922015-10-12 05:23:41 -0700205struct __packed smbios_type4 {
206 u8 type;
207 u8 length;
208 u16 handle;
209 u8 socket_designation;
210 u8 processor_type;
211 u8 processor_family;
212 u8 processor_manufacturer;
213 u32 processor_id[2];
214 u8 processor_version;
215 u8 voltage;
216 u16 external_clock;
217 u16 max_speed;
218 u16 current_speed;
219 u8 status;
220 u8 processor_upgrade;
221 u16 l1_cache_handle;
222 u16 l2_cache_handle;
223 u16 l3_cache_handle;
224 u8 serial_number;
225 u8 asset_tag;
226 u8 part_number;
227 u8 core_count;
228 u8 core_enabled;
229 u8 thread_count;
230 u16 processor_characteristics;
231 u16 processor_family2;
232 u16 core_count2;
233 u16 core_enabled2;
234 u16 thread_count2;
235 char eos[SMBIOS_STRUCT_EOS_BYTES];
236};
237
238struct __packed smbios_type32 {
239 u8 type;
240 u8 length;
241 u16 handle;
242 u8 reserved[6];
243 u8 boot_status;
Simon Glassdc090582021-02-04 21:17:15 -0700244 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Meng721e9922015-10-12 05:23:41 -0700245};
246
247struct __packed smbios_type127 {
248 u8 type;
249 u8 length;
250 u16 handle;
Simon Glassdc090582021-02-04 21:17:15 -0700251 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Meng721e9922015-10-12 05:23:41 -0700252};
253
254struct __packed smbios_header {
255 u8 type;
256 u8 length;
257 u16 handle;
258};
259
260/**
261 * fill_smbios_header() - Fill the header of an SMBIOS table
262 *
263 * This fills the header of an SMBIOS table structure.
264 *
265 * @table: start address of the structure
266 * @type: the type of structure
267 * @length: the length of the formatted area of the structure
268 * @handle: the structure's handle, a unique 16-bit number
269 */
270static inline void fill_smbios_header(void *table, int type,
271 int length, int handle)
272{
273 struct smbios_header *header = table;
274
275 header->type = type;
276 header->length = length - SMBIOS_STRUCT_EOS_BYTES;
277 header->handle = handle;
278}
279
280/**
Bin Meng721e9922015-10-12 05:23:41 -0700281 * write_smbios_table() - Write SMBIOS table
282 *
283 * This writes SMBIOS table at a given address.
284 *
Simon Glass31f950a2023-12-31 08:25:50 -0700285 * @addr: start address to write SMBIOS table, 16-byte-alignment
286 * recommended. Note that while the SMBIOS tables themself have no alignment
287 * requirement, some systems may requires alignment. For example x86 systems
288 * which put tables at f0000 require 16-byte alignment
289 *
Heinrich Schuchardtc193d9b2021-05-15 18:07:47 +0200290 * Return: end address of SMBIOS table (and start address for next entry)
291 * or NULL in case of an error
Bin Meng721e9922015-10-12 05:23:41 -0700292 */
Simon Glass42fd8c12017-01-16 07:03:35 -0700293ulong write_smbios_table(ulong addr);
Bin Meng721e9922015-10-12 05:23:41 -0700294
Christian Gmeiner415eab02020-11-03 15:34:51 +0100295/**
296 * smbios_entry() - Get a valid struct smbios_entry pointer
297 *
298 * @address: address where smbios tables is located
299 * @size: size of smbios table
300 * @return: NULL or a valid pointer to a struct smbios_entry
301 */
302const struct smbios_entry *smbios_entry(u64 address, u32 size);
303
304/**
305 * smbios_header() - Search for SMBIOS header type
306 *
307 * @entry: pointer to a struct smbios_entry
308 * @type: SMBIOS type
309 * @return: NULL or a valid pointer to a struct smbios_header
310 */
311const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
312
313/**
314 * smbios_string() - Return string from SMBIOS
315 *
316 * @header: pointer to struct smbios_header
317 * @index: string index
Masahisa Kojima3d49ee82021-10-26 17:27:24 +0900318 * @return: NULL or a valid char pointer
Christian Gmeiner415eab02020-11-03 15:34:51 +0100319 */
Masahisa Kojima3d49ee82021-10-26 17:27:24 +0900320char *smbios_string(const struct smbios_header *header, int index);
Christian Gmeiner415eab02020-11-03 15:34:51 +0100321
Simon Glasse9adaa72021-02-04 21:17:20 -0700322/**
323 * smbios_update_version() - Update the version string
324 *
325 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
326 * main loop has started) to update the BIOS version string (SMBIOS table 0).
327 *
328 * @version: New version string to use
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100329 * Return: 0 if OK, -ENOENT if no version string was previously written,
Simon Glasse9adaa72021-02-04 21:17:20 -0700330 * -ENOSPC if the new string is too large to fit
331 */
332int smbios_update_version(const char *version);
333
Simon Glass272e62c2021-03-15 18:00:11 +1300334/**
335 * smbios_update_version_full() - Update the version string
336 *
337 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
338 * main loop has started) to update the BIOS version string (SMBIOS table 0).
339 * It scans for the correct place to put the version, so does not need U-Boot
340 * to have actually written the tables itself (e.g. if a previous bootloader
341 * did it).
342 *
343 * @smbios_tab: Start of SMBIOS tables
344 * @version: New version string to use
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100345 * Return: 0 if OK, -ENOENT if no version string was previously written,
Simon Glass272e62c2021-03-15 18:00:11 +1300346 * -ENOSPC if the new string is too large to fit
347 */
348int smbios_update_version_full(void *smbios_tab, const char *version);
349
Masahisa Kojima3d49ee82021-10-26 17:27:24 +0900350/**
351 * smbios_prepare_measurement() - Update smbios table for the measurement
352 *
353 * TCG specification requires to measure static configuration information.
354 * This function clear the device dependent parameters such as
355 * serial number for the measurement.
356 *
Masahisa Kojima2497f6a2024-01-26 09:53:42 +0900357 * @entry: pointer to a struct smbios3_entry
Masahisa Kojima3d49ee82021-10-26 17:27:24 +0900358 * @header: pointer to a struct smbios_header
359 */
Masahisa Kojima2497f6a2024-01-26 09:53:42 +0900360void smbios_prepare_measurement(const struct smbios3_entry *entry,
Masahisa Kojima3d49ee82021-10-26 17:27:24 +0900361 struct smbios_header *header);
362
Bin Meng721e9922015-10-12 05:23:41 -0700363#endif /* _SMBIOS_H_ */