blob: 49de32fec2deb7edf1cfe4d98971a83e71cc8a1d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Bin Mengae5bedb2015-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 Mengae5bedb2015-10-12 05:23:41 -07006 */
7
8#ifndef _SMBIOS_H_
9#define _SMBIOS_H_
10
Simon Glass0dd7ca22020-11-05 06:32:07 -070011#include <dm/ofnode.h>
12
Bin Mengae5bedb2015-10-12 05:23:41 -070013/* SMBIOS spec version implemented */
14#define SMBIOS_MAJOR_VER 3
Simon Glassf86d7a02023-12-31 08:25:47 -070015#define SMBIOS_MINOR_VER 7
Bin Mengae5bedb2015-10-12 05:23:41 -070016
Simon Glass3971a2a2021-03-15 18:00:11 +130017enum {
18 SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */
19};
20
Bin Mengae5bedb2015-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 Schuchardt0db02c02023-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 */
78 u32 max_struct_size;
79 /** @struct_table_address: 64-bit physical starting address */
80 u64 struct_table_address;
81};
82
Simon Glassf86d7a02023-12-31 08:25:47 -070083/* These two structures should use the same amount of 16-byte-aligned space */
84static_assert(ALIGN(16, sizeof(struct smbios_entry)) ==
85 ALIGN(16, sizeof(struct smbios3_entry)));
86
Bin Mengae5bedb2015-10-12 05:23:41 -070087/* BIOS characteristics */
88#define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7)
89#define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11)
90#define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16)
91
92#define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0)
Ilias Apalodimas15578bc2021-06-09 18:14:47 +030093#define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3)
Bin Mengae5bedb2015-10-12 05:23:41 -070094#define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)
95
96struct __packed smbios_type0 {
97 u8 type;
98 u8 length;
99 u16 handle;
100 u8 vendor;
101 u8 bios_ver;
102 u16 bios_start_segment;
103 u8 bios_release_date;
104 u8 bios_rom_size;
105 u64 bios_characteristics;
106 u8 bios_characteristics_ext1;
107 u8 bios_characteristics_ext2;
108 u8 bios_major_release;
109 u8 bios_minor_release;
110 u8 ec_major_release;
111 u8 ec_minor_release;
112 char eos[SMBIOS_STRUCT_EOS_BYTES];
113};
114
115struct __packed smbios_type1 {
116 u8 type;
117 u8 length;
118 u16 handle;
119 u8 manufacturer;
120 u8 product_name;
121 u8 version;
122 u8 serial_number;
123 u8 uuid[16];
124 u8 wakeup_type;
125 u8 sku_number;
126 u8 family;
127 char eos[SMBIOS_STRUCT_EOS_BYTES];
128};
129
130#define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0)
131#define SMBIOS_BOARD_MOTHERBOARD 10
132
133struct __packed smbios_type2 {
134 u8 type;
135 u8 length;
136 u16 handle;
137 u8 manufacturer;
138 u8 product_name;
139 u8 version;
140 u8 serial_number;
141 u8 asset_tag_number;
142 u8 feature_flags;
143 u8 chassis_location;
144 u16 chassis_handle;
145 u8 board_type;
146 char eos[SMBIOS_STRUCT_EOS_BYTES];
147};
148
149#define SMBIOS_ENCLOSURE_DESKTOP 3
150#define SMBIOS_STATE_SAFE 3
151#define SMBIOS_SECURITY_NONE 3
152
153struct __packed smbios_type3 {
154 u8 type;
155 u8 length;
156 u16 handle;
157 u8 manufacturer;
158 u8 chassis_type;
159 u8 version;
160 u8 serial_number;
161 u8 asset_tag_number;
162 u8 bootup_state;
163 u8 power_supply_state;
164 u8 thermal_state;
165 u8 security_status;
166 u32 oem_defined;
167 u8 height;
168 u8 number_of_power_cords;
169 u8 element_count;
170 u8 element_record_length;
171 char eos[SMBIOS_STRUCT_EOS_BYTES];
172};
173
174#define SMBIOS_PROCESSOR_TYPE_CENTRAL 3
175#define SMBIOS_PROCESSOR_STATUS_ENABLED 1
176#define SMBIOS_PROCESSOR_UPGRADE_NONE 6
177
Alexander Grafe44b3c02016-08-19 01:23:28 +0200178#define SMBIOS_PROCESSOR_FAMILY_OTHER 1
179#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2
180
Bin Mengae5bedb2015-10-12 05:23:41 -0700181struct __packed smbios_type4 {
182 u8 type;
183 u8 length;
184 u16 handle;
185 u8 socket_designation;
186 u8 processor_type;
187 u8 processor_family;
188 u8 processor_manufacturer;
189 u32 processor_id[2];
190 u8 processor_version;
191 u8 voltage;
192 u16 external_clock;
193 u16 max_speed;
194 u16 current_speed;
195 u8 status;
196 u8 processor_upgrade;
197 u16 l1_cache_handle;
198 u16 l2_cache_handle;
199 u16 l3_cache_handle;
200 u8 serial_number;
201 u8 asset_tag;
202 u8 part_number;
203 u8 core_count;
204 u8 core_enabled;
205 u8 thread_count;
206 u16 processor_characteristics;
207 u16 processor_family2;
208 u16 core_count2;
209 u16 core_enabled2;
210 u16 thread_count2;
211 char eos[SMBIOS_STRUCT_EOS_BYTES];
212};
213
214struct __packed smbios_type32 {
215 u8 type;
216 u8 length;
217 u16 handle;
218 u8 reserved[6];
219 u8 boot_status;
Simon Glass99cfc6f2021-02-04 21:17:15 -0700220 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Mengae5bedb2015-10-12 05:23:41 -0700221};
222
223struct __packed smbios_type127 {
224 u8 type;
225 u8 length;
226 u16 handle;
Simon Glass99cfc6f2021-02-04 21:17:15 -0700227 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Mengae5bedb2015-10-12 05:23:41 -0700228};
229
230struct __packed smbios_header {
231 u8 type;
232 u8 length;
233 u16 handle;
234};
235
236/**
237 * fill_smbios_header() - Fill the header of an SMBIOS table
238 *
239 * This fills the header of an SMBIOS table structure.
240 *
241 * @table: start address of the structure
242 * @type: the type of structure
243 * @length: the length of the formatted area of the structure
244 * @handle: the structure's handle, a unique 16-bit number
245 */
246static inline void fill_smbios_header(void *table, int type,
247 int length, int handle)
248{
249 struct smbios_header *header = table;
250
251 header->type = type;
252 header->length = length - SMBIOS_STRUCT_EOS_BYTES;
253 header->handle = handle;
254}
255
256/**
Bin Mengae5bedb2015-10-12 05:23:41 -0700257 * write_smbios_table() - Write SMBIOS table
258 *
259 * This writes SMBIOS table at a given address.
260 *
Simon Glassf0e95eb2023-12-31 08:25:50 -0700261 * @addr: start address to write SMBIOS table, 16-byte-alignment
262 * recommended. Note that while the SMBIOS tables themself have no alignment
263 * requirement, some systems may requires alignment. For example x86 systems
264 * which put tables at f0000 require 16-byte alignment
265 *
Heinrich Schuchardt21da91f2021-05-15 18:07:47 +0200266 * Return: end address of SMBIOS table (and start address for next entry)
267 * or NULL in case of an error
Bin Mengae5bedb2015-10-12 05:23:41 -0700268 */
Simon Glassca37a392017-01-16 07:03:35 -0700269ulong write_smbios_table(ulong addr);
Bin Mengae5bedb2015-10-12 05:23:41 -0700270
Christian Gmeiner19859982020-11-03 15:34:51 +0100271/**
272 * smbios_entry() - Get a valid struct smbios_entry pointer
273 *
274 * @address: address where smbios tables is located
275 * @size: size of smbios table
276 * @return: NULL or a valid pointer to a struct smbios_entry
277 */
278const struct smbios_entry *smbios_entry(u64 address, u32 size);
279
280/**
281 * smbios_header() - Search for SMBIOS header type
282 *
283 * @entry: pointer to a struct smbios_entry
284 * @type: SMBIOS type
285 * @return: NULL or a valid pointer to a struct smbios_header
286 */
287const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
288
289/**
290 * smbios_string() - Return string from SMBIOS
291 *
292 * @header: pointer to struct smbios_header
293 * @index: string index
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900294 * @return: NULL or a valid char pointer
Christian Gmeiner19859982020-11-03 15:34:51 +0100295 */
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900296char *smbios_string(const struct smbios_header *header, int index);
Christian Gmeiner19859982020-11-03 15:34:51 +0100297
Simon Glassa05eb042021-02-04 21:17:20 -0700298/**
299 * smbios_update_version() - Update the version string
300 *
301 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
302 * main loop has started) to update the BIOS version string (SMBIOS table 0).
303 *
304 * @version: New version string to use
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100305 * Return: 0 if OK, -ENOENT if no version string was previously written,
Simon Glassa05eb042021-02-04 21:17:20 -0700306 * -ENOSPC if the new string is too large to fit
307 */
308int smbios_update_version(const char *version);
309
Simon Glass3971a2a2021-03-15 18:00:11 +1300310/**
311 * smbios_update_version_full() - Update the version string
312 *
313 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
314 * main loop has started) to update the BIOS version string (SMBIOS table 0).
315 * It scans for the correct place to put the version, so does not need U-Boot
316 * to have actually written the tables itself (e.g. if a previous bootloader
317 * did it).
318 *
319 * @smbios_tab: Start of SMBIOS tables
320 * @version: New version string to use
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100321 * Return: 0 if OK, -ENOENT if no version string was previously written,
Simon Glass3971a2a2021-03-15 18:00:11 +1300322 * -ENOSPC if the new string is too large to fit
323 */
324int smbios_update_version_full(void *smbios_tab, const char *version);
325
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900326/**
327 * smbios_prepare_measurement() - Update smbios table for the measurement
328 *
329 * TCG specification requires to measure static configuration information.
330 * This function clear the device dependent parameters such as
331 * serial number for the measurement.
332 *
333 * @entry: pointer to a struct smbios_entry
334 * @header: pointer to a struct smbios_header
335 */
336void smbios_prepare_measurement(const struct smbios_entry *entry,
337 struct smbios_header *header);
338
Bin Mengae5bedb2015-10-12 05:23:41 -0700339#endif /* _SMBIOS_H_ */