blob: b5fed57aba2122d89478b4c8a66e12ddd3f6cad2 [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
Heinrich Schuchardt34e97aa2024-01-03 09:07:20 +010011#include <linux/types.h>
Raymond Maof4b933d2024-12-06 14:54:18 -080012#include <smbios_def.h>
Simon Glass0dd7ca22020-11-05 06:32:07 -070013
Bin Mengae5bedb2015-10-12 05:23:41 -070014/* SMBIOS spec version implemented */
15#define SMBIOS_MAJOR_VER 3
Simon Glassf86d7a02023-12-31 08:25:47 -070016#define SMBIOS_MINOR_VER 7
Bin Mengae5bedb2015-10-12 05:23:41 -070017
Simon Glass3971a2a2021-03-15 18:00:11 +130018enum {
19 SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */
20};
21
Bin Mengae5bedb2015-10-12 05:23:41 -070022/* SMBIOS structure types */
23enum {
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
36};
37
38#define SMBIOS_INTERMEDIATE_OFFSET 16
39#define SMBIOS_STRUCT_EOS_BYTES 2
40
Raymond Mao6a125b32024-12-06 14:54:26 -080041struct str_lookup_table {
42 u16 idx;
43 const char *str;
44};
45
Bin Mengae5bedb2015-10-12 05:23:41 -070046struct __packed smbios_entry {
47 u8 anchor[4];
48 u8 checksum;
49 u8 length;
50 u8 major_ver;
51 u8 minor_ver;
52 u16 max_struct_size;
53 u8 entry_point_rev;
54 u8 formatted_area[5];
55 u8 intermediate_anchor[5];
56 u8 intermediate_checksum;
57 u16 struct_table_length;
58 u32 struct_table_address;
59 u16 struct_count;
60 u8 bcd_rev;
61};
62
Heinrich Schuchardt0db02c02023-12-31 08:25:46 -070063/**
64 * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure
65 */
66struct __packed smbios3_entry {
67 /** @anchor: anchor string */
68 u8 anchor[5];
69 /** @checksum: checksum of the entry point structure */
70 u8 checksum;
71 /** @length: length of the entry point structure */
72 u8 length;
73 /** @major_ver: major version of the SMBIOS specification */
74 u8 major_ver;
75 /** @minor_ver: minor version of the SMBIOS specification */
76 u8 minor_ver;
77 /** @docrev: revision of the SMBIOS specification */
78 u8 doc_rev;
79 /** @entry_point_rev: revision of the entry point structure */
80 u8 entry_point_rev;
81 /** @reserved: reserved */
82 u8 reserved;
83 /** maximum size of SMBIOS table */
Heinrich Schuchardt68e948a2024-01-31 23:49:34 +010084 u32 table_maximum_size;
Heinrich Schuchardt0db02c02023-12-31 08:25:46 -070085 /** @struct_table_address: 64-bit physical starting address */
86 u64 struct_table_address;
87};
88
Raymond Maof4b933d2024-12-06 14:54:18 -080089struct __packed smbios_header {
Bin Mengae5bedb2015-10-12 05:23:41 -070090 u8 type;
91 u8 length;
92 u16 handle;
Raymond Maof4b933d2024-12-06 14:54:18 -080093};
94
95struct __packed smbios_type0 {
96 struct smbios_header hdr;
Bin Mengae5bedb2015-10-12 05:23:41 -070097 u8 vendor;
98 u8 bios_ver;
99 u16 bios_start_segment;
100 u8 bios_release_date;
101 u8 bios_rom_size;
102 u64 bios_characteristics;
103 u8 bios_characteristics_ext1;
104 u8 bios_characteristics_ext2;
105 u8 bios_major_release;
106 u8 bios_minor_release;
107 u8 ec_major_release;
108 u8 ec_minor_release;
Heinrich Schuchardtbfeb45f2024-07-23 16:44:23 +0200109 u16 extended_bios_rom_size;
Bin Mengae5bedb2015-10-12 05:23:41 -0700110 char eos[SMBIOS_STRUCT_EOS_BYTES];
111};
112
Raymond Maof4b933d2024-12-06 14:54:18 -0800113#define SMBIOS_TYPE1_LENGTH_V20 0x08
114#define SMBIOS_TYPE1_LENGTH_V21 0x19
115#define SMBIOS_TYPE1_LENGTH_V24 0x1b
Heinrich Schuchardta0501b52024-02-10 12:06:48 +0100116
Bin Mengae5bedb2015-10-12 05:23:41 -0700117struct __packed smbios_type1 {
Raymond Maof4b933d2024-12-06 14:54:18 -0800118 struct smbios_header hdr;
Bin Mengae5bedb2015-10-12 05:23:41 -0700119 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
Raymond Maoa28ef802024-12-06 14:54:22 -0800130#define SMBIOS_TYPE2_CON_OBJ_HANDLE_SIZE sizeof(u16)
131
Bin Mengae5bedb2015-10-12 05:23:41 -0700132struct __packed smbios_type2 {
Raymond Maof4b933d2024-12-06 14:54:18 -0800133 struct smbios_header hdr;
Bin Mengae5bedb2015-10-12 05:23:41 -0700134 u8 manufacturer;
135 u8 product_name;
136 u8 version;
137 u8 serial_number;
138 u8 asset_tag_number;
139 u8 feature_flags;
140 u8 chassis_location;
141 u16 chassis_handle;
142 u8 board_type;
Heinrich Schuchardt856ffa52024-01-25 16:54:33 +0100143 u8 number_contained_objects;
Raymond Maoa28ef802024-12-06 14:54:22 -0800144 /*
145 * Dynamic bytes will be inserted here to store the objects.
146 * length is equal to 'number_contained_objects'.
147 */
Bin Mengae5bedb2015-10-12 05:23:41 -0700148 char eos[SMBIOS_STRUCT_EOS_BYTES];
149};
150
Bin Mengae5bedb2015-10-12 05:23:41 -0700151struct __packed smbios_type3 {
Raymond Maof4b933d2024-12-06 14:54:18 -0800152 struct smbios_header hdr;
Bin Mengae5bedb2015-10-12 05:23:41 -0700153 u8 manufacturer;
154 u8 chassis_type;
155 u8 version;
156 u8 serial_number;
157 u8 asset_tag_number;
158 u8 bootup_state;
159 u8 power_supply_state;
160 u8 thermal_state;
161 u8 security_status;
162 u32 oem_defined;
163 u8 height;
164 u8 number_of_power_cords;
165 u8 element_count;
166 u8 element_record_length;
Raymond Maoa28ef802024-12-06 14:54:22 -0800167 /*
168 * Dynamic bytes will be inserted here to store the elements.
169 * length is equal to 'element_record_length' * 'element_record_length'
170 */
171 u8 sku_number;
Bin Mengae5bedb2015-10-12 05:23:41 -0700172 char eos[SMBIOS_STRUCT_EOS_BYTES];
173};
174
Bin Mengae5bedb2015-10-12 05:23:41 -0700175struct __packed smbios_type4 {
Raymond Maof4b933d2024-12-06 14:54:18 -0800176 struct smbios_header hdr;
Raymond Maoa28ef802024-12-06 14:54:22 -0800177 u8 socket_design;
Bin Mengae5bedb2015-10-12 05:23:41 -0700178 u8 processor_type;
179 u8 processor_family;
180 u8 processor_manufacturer;
181 u32 processor_id[2];
182 u8 processor_version;
183 u8 voltage;
184 u16 external_clock;
185 u16 max_speed;
186 u16 current_speed;
187 u8 status;
188 u8 processor_upgrade;
189 u16 l1_cache_handle;
190 u16 l2_cache_handle;
191 u16 l3_cache_handle;
192 u8 serial_number;
193 u8 asset_tag;
194 u8 part_number;
195 u8 core_count;
196 u8 core_enabled;
197 u8 thread_count;
198 u16 processor_characteristics;
199 u16 processor_family2;
200 u16 core_count2;
201 u16 core_enabled2;
202 u16 thread_count2;
Raymond Maoa28ef802024-12-06 14:54:22 -0800203 u16 thread_enabled;
Bin Mengae5bedb2015-10-12 05:23:41 -0700204 char eos[SMBIOS_STRUCT_EOS_BYTES];
205};
206
Raymond Mao8fe07312024-12-06 14:54:21 -0800207union cache_config {
208 struct {
209 u16 level:3;
210 u16 bsocketed:1;
211 u16 rsvd0:1;
212 u16 locate:2;
213 u16 benabled:1;
214 u16 opmode:2;
215 u16 rsvd1:6;
216 } fields;
217 u16 data;
218};
219
220union cache_size_word {
221 struct {
222 u16 size:15;
223 u16 granu:1;
224 } fields;
225 u16 data;
226};
227
228union cache_size_dword {
229 struct {
230 u32 size:31;
231 u32 granu:1;
232 } fields;
233 u32 data;
234};
235
236union cache_sram_type {
237 struct {
238 u16 other:1;
239 u16 unknown:1;
240 u16 nonburst:1;
241 u16 burst:1;
242 u16 plburst:1;
243 u16 sync:1;
244 u16 async:1;
245 u16 rsvd:9;
246 } fields;
247 u16 data;
248};
249
250struct __packed smbios_type7 {
251 struct smbios_header hdr;
252 u8 socket_design;
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;
258 u8 speed;
259 u8 err_corr_type;
260 u8 sys_cache_type;
261 u8 associativity;
262 union cache_size_dword max_size2;
263 union cache_size_dword inst_size2;
264 char eos[SMBIOS_STRUCT_EOS_BYTES];
265};
266
Bin Mengae5bedb2015-10-12 05:23:41 -0700267struct __packed smbios_type32 {
268 u8 type;
269 u8 length;
270 u16 handle;
271 u8 reserved[6];
272 u8 boot_status;
Simon Glass99cfc6f2021-02-04 21:17:15 -0700273 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Mengae5bedb2015-10-12 05:23:41 -0700274};
275
276struct __packed smbios_type127 {
277 u8 type;
278 u8 length;
279 u16 handle;
Simon Glass99cfc6f2021-02-04 21:17:15 -0700280 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Mengae5bedb2015-10-12 05:23:41 -0700281};
282
Bin Mengae5bedb2015-10-12 05:23:41 -0700283/**
284 * fill_smbios_header() - Fill the header of an SMBIOS table
285 *
286 * This fills the header of an SMBIOS table structure.
287 *
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
292 */
293static inline void fill_smbios_header(void *table, int type,
294 int length, int handle)
295{
296 struct smbios_header *header = table;
297
298 header->type = type;
299 header->length = length - SMBIOS_STRUCT_EOS_BYTES;
300 header->handle = handle;
301}
302
303/**
Bin Mengae5bedb2015-10-12 05:23:41 -0700304 * write_smbios_table() - Write SMBIOS table
305 *
306 * This writes SMBIOS table at a given address.
307 *
Simon Glassf0e95eb2023-12-31 08:25:50 -0700308 * @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
312 *
Heinrich Schuchardt21da91f2021-05-15 18:07:47 +0200313 * Return: end address of SMBIOS table (and start address for next entry)
314 * or NULL in case of an error
Bin Mengae5bedb2015-10-12 05:23:41 -0700315 */
Simon Glassca37a392017-01-16 07:03:35 -0700316ulong write_smbios_table(ulong addr);
Bin Mengae5bedb2015-10-12 05:23:41 -0700317
Christian Gmeiner19859982020-11-03 15:34:51 +0100318/**
319 * smbios_entry() - Get a valid struct smbios_entry pointer
320 *
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
324 */
325const struct smbios_entry *smbios_entry(u64 address, u32 size);
326
327/**
328 * smbios_header() - Search for SMBIOS header type
329 *
330 * @entry: pointer to a struct smbios_entry
331 * @type: SMBIOS type
332 * @return: NULL or a valid pointer to a struct smbios_header
333 */
334const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
335
336/**
337 * smbios_string() - Return string from SMBIOS
338 *
339 * @header: pointer to struct smbios_header
340 * @index: string index
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900341 * @return: NULL or a valid char pointer
Christian Gmeiner19859982020-11-03 15:34:51 +0100342 */
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900343char *smbios_string(const struct smbios_header *header, int index);
Christian Gmeiner19859982020-11-03 15:34:51 +0100344
Simon Glassa05eb042021-02-04 21:17:20 -0700345/**
346 * smbios_update_version() - Update the version string
347 *
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).
350 *
351 * @version: New version string to use
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100352 * Return: 0 if OK, -ENOENT if no version string was previously written,
Simon Glassa05eb042021-02-04 21:17:20 -0700353 * -ENOSPC if the new string is too large to fit
354 */
355int smbios_update_version(const char *version);
356
Simon Glass3971a2a2021-03-15 18:00:11 +1300357/**
358 * smbios_update_version_full() - Update the version string
359 *
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
364 * did it).
365 *
366 * @smbios_tab: Start of SMBIOS tables
367 * @version: New version string to use
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100368 * Return: 0 if OK, -ENOENT if no version string was previously written,
Simon Glass3971a2a2021-03-15 18:00:11 +1300369 * -ENOSPC if the new string is too large to fit
370 */
371int smbios_update_version_full(void *smbios_tab, const char *version);
372
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900373/**
374 * smbios_prepare_measurement() - Update smbios table for the measurement
375 *
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.
379 *
Masahisa Kojimad8733f32024-01-26 09:53:42 +0900380 * @entry: pointer to a struct smbios3_entry
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900381 * @header: pointer to a struct smbios_header
382 */
Masahisa Kojimad8733f32024-01-26 09:53:42 +0900383void smbios_prepare_measurement(const struct smbios3_entry *entry,
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900384 struct smbios_header *header);
385
Bin Mengae5bedb2015-10-12 05:23:41 -0700386#endif /* _SMBIOS_H_ */