blob: fc49fc10b9d7074c8d4c547d2c7cfa79d33689bc [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
Simon Glass78227d42020-11-05 06:32:07 -070011#include <dm/ofnode.h>
12
Bin Meng721e9922015-10-12 05:23:41 -070013/* SMBIOS spec version implemented */
14#define SMBIOS_MAJOR_VER 3
15#define SMBIOS_MINOR_VER 0
16
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
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)
61
62#define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0)
Ilias Apalodimasff192302021-06-09 18:14:47 +030063#define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3)
Bin Meng721e9922015-10-12 05:23:41 -070064#define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)
65
66struct __packed smbios_type0 {
67 u8 type;
68 u8 length;
69 u16 handle;
70 u8 vendor;
71 u8 bios_ver;
72 u16 bios_start_segment;
73 u8 bios_release_date;
74 u8 bios_rom_size;
75 u64 bios_characteristics;
76 u8 bios_characteristics_ext1;
77 u8 bios_characteristics_ext2;
78 u8 bios_major_release;
79 u8 bios_minor_release;
80 u8 ec_major_release;
81 u8 ec_minor_release;
82 char eos[SMBIOS_STRUCT_EOS_BYTES];
83};
84
85struct __packed smbios_type1 {
86 u8 type;
87 u8 length;
88 u16 handle;
89 u8 manufacturer;
90 u8 product_name;
91 u8 version;
92 u8 serial_number;
93 u8 uuid[16];
94 u8 wakeup_type;
95 u8 sku_number;
96 u8 family;
97 char eos[SMBIOS_STRUCT_EOS_BYTES];
98};
99
100#define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0)
101#define SMBIOS_BOARD_MOTHERBOARD 10
102
103struct __packed smbios_type2 {
104 u8 type;
105 u8 length;
106 u16 handle;
107 u8 manufacturer;
108 u8 product_name;
109 u8 version;
110 u8 serial_number;
111 u8 asset_tag_number;
112 u8 feature_flags;
113 u8 chassis_location;
114 u16 chassis_handle;
115 u8 board_type;
116 char eos[SMBIOS_STRUCT_EOS_BYTES];
117};
118
119#define SMBIOS_ENCLOSURE_DESKTOP 3
120#define SMBIOS_STATE_SAFE 3
121#define SMBIOS_SECURITY_NONE 3
122
123struct __packed smbios_type3 {
124 u8 type;
125 u8 length;
126 u16 handle;
127 u8 manufacturer;
128 u8 chassis_type;
129 u8 version;
130 u8 serial_number;
131 u8 asset_tag_number;
132 u8 bootup_state;
133 u8 power_supply_state;
134 u8 thermal_state;
135 u8 security_status;
136 u32 oem_defined;
137 u8 height;
138 u8 number_of_power_cords;
139 u8 element_count;
140 u8 element_record_length;
141 char eos[SMBIOS_STRUCT_EOS_BYTES];
142};
143
144#define SMBIOS_PROCESSOR_TYPE_CENTRAL 3
145#define SMBIOS_PROCESSOR_STATUS_ENABLED 1
146#define SMBIOS_PROCESSOR_UPGRADE_NONE 6
147
Alexander Graf96476202016-08-19 01:23:28 +0200148#define SMBIOS_PROCESSOR_FAMILY_OTHER 1
149#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2
150
Bin Meng721e9922015-10-12 05:23:41 -0700151struct __packed smbios_type4 {
152 u8 type;
153 u8 length;
154 u16 handle;
155 u8 socket_designation;
156 u8 processor_type;
157 u8 processor_family;
158 u8 processor_manufacturer;
159 u32 processor_id[2];
160 u8 processor_version;
161 u8 voltage;
162 u16 external_clock;
163 u16 max_speed;
164 u16 current_speed;
165 u8 status;
166 u8 processor_upgrade;
167 u16 l1_cache_handle;
168 u16 l2_cache_handle;
169 u16 l3_cache_handle;
170 u8 serial_number;
171 u8 asset_tag;
172 u8 part_number;
173 u8 core_count;
174 u8 core_enabled;
175 u8 thread_count;
176 u16 processor_characteristics;
177 u16 processor_family2;
178 u16 core_count2;
179 u16 core_enabled2;
180 u16 thread_count2;
181 char eos[SMBIOS_STRUCT_EOS_BYTES];
182};
183
184struct __packed smbios_type32 {
185 u8 type;
186 u8 length;
187 u16 handle;
188 u8 reserved[6];
189 u8 boot_status;
Simon Glassdc090582021-02-04 21:17:15 -0700190 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Meng721e9922015-10-12 05:23:41 -0700191};
192
193struct __packed smbios_type127 {
194 u8 type;
195 u8 length;
196 u16 handle;
Simon Glassdc090582021-02-04 21:17:15 -0700197 char eos[SMBIOS_STRUCT_EOS_BYTES];
Bin Meng721e9922015-10-12 05:23:41 -0700198};
199
200struct __packed smbios_header {
201 u8 type;
202 u8 length;
203 u16 handle;
204};
205
206/**
207 * fill_smbios_header() - Fill the header of an SMBIOS table
208 *
209 * This fills the header of an SMBIOS table structure.
210 *
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
215 */
216static inline void fill_smbios_header(void *table, int type,
217 int length, int handle)
218{
219 struct smbios_header *header = table;
220
221 header->type = type;
222 header->length = length - SMBIOS_STRUCT_EOS_BYTES;
223 header->handle = handle;
224}
225
226/**
Bin Meng721e9922015-10-12 05:23:41 -0700227 * write_smbios_table() - Write SMBIOS table
228 *
229 * This writes SMBIOS table at a given address.
230 *
Simon Glass0864c562018-05-16 09:42:19 -0600231 * @addr: start address to write SMBIOS table. If this is not
232 * 16-byte-aligned then it will be aligned before the table is written
233 * @return: end address of SMBIOS table (and start address for next entry)
Bin Meng721e9922015-10-12 05:23:41 -0700234 */
Simon Glass42fd8c12017-01-16 07:03:35 -0700235ulong write_smbios_table(ulong addr);
Bin Meng721e9922015-10-12 05:23:41 -0700236
Christian Gmeiner415eab02020-11-03 15:34:51 +0100237/**
238 * smbios_entry() - Get a valid struct smbios_entry pointer
239 *
240 * @address: address where smbios tables is located
241 * @size: size of smbios table
242 * @return: NULL or a valid pointer to a struct smbios_entry
243 */
244const struct smbios_entry *smbios_entry(u64 address, u32 size);
245
246/**
247 * smbios_header() - Search for SMBIOS header type
248 *
249 * @entry: pointer to a struct smbios_entry
250 * @type: SMBIOS type
251 * @return: NULL or a valid pointer to a struct smbios_header
252 */
253const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
254
255/**
256 * smbios_string() - Return string from SMBIOS
257 *
258 * @header: pointer to struct smbios_header
259 * @index: string index
260 * @return: NULL or a valid const char pointer
261 */
262const char *smbios_string(const struct smbios_header *header, int index);
263
Simon Glasse9adaa72021-02-04 21:17:20 -0700264/**
265 * smbios_update_version() - Update the version string
266 *
267 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
268 * main loop has started) to update the BIOS version string (SMBIOS table 0).
269 *
270 * @version: New version string to use
271 * @return 0 if OK, -ENOENT if no version string was previously written,
272 * -ENOSPC if the new string is too large to fit
273 */
274int smbios_update_version(const char *version);
275
Simon Glass272e62c2021-03-15 18:00:11 +1300276/**
277 * smbios_update_version_full() - Update the version string
278 *
279 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
280 * main loop has started) to update the BIOS version string (SMBIOS table 0).
281 * It scans for the correct place to put the version, so does not need U-Boot
282 * to have actually written the tables itself (e.g. if a previous bootloader
283 * did it).
284 *
285 * @smbios_tab: Start of SMBIOS tables
286 * @version: New version string to use
287 * @return 0 if OK, -ENOENT if no version string was previously written,
288 * -ENOSPC if the new string is too large to fit
289 */
290int smbios_update_version_full(void *smbios_tab, const char *version);
291
Bin Meng721e9922015-10-12 05:23:41 -0700292#endif /* _SMBIOS_H_ */