blob: aa6b6f38495b282d67c16f25862274958364876f [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
Heinrich Schuchardtc193d9b2021-05-15 18:07:47 +0200232 * 16-byte-aligned then it will be aligned before the table is
233 * written.
234 * Return: end address of SMBIOS table (and start address for next entry)
235 * or NULL in case of an error
236 *
Bin Meng721e9922015-10-12 05:23:41 -0700237 */
Simon Glass42fd8c12017-01-16 07:03:35 -0700238ulong write_smbios_table(ulong addr);
Bin Meng721e9922015-10-12 05:23:41 -0700239
Christian Gmeiner415eab02020-11-03 15:34:51 +0100240/**
241 * smbios_entry() - Get a valid struct smbios_entry pointer
242 *
243 * @address: address where smbios tables is located
244 * @size: size of smbios table
245 * @return: NULL or a valid pointer to a struct smbios_entry
246 */
247const struct smbios_entry *smbios_entry(u64 address, u32 size);
248
249/**
250 * smbios_header() - Search for SMBIOS header type
251 *
252 * @entry: pointer to a struct smbios_entry
253 * @type: SMBIOS type
254 * @return: NULL or a valid pointer to a struct smbios_header
255 */
256const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
257
258/**
259 * smbios_string() - Return string from SMBIOS
260 *
261 * @header: pointer to struct smbios_header
262 * @index: string index
263 * @return: NULL or a valid const char pointer
264 */
265const char *smbios_string(const struct smbios_header *header, int index);
266
Simon Glasse9adaa72021-02-04 21:17:20 -0700267/**
268 * smbios_update_version() - Update the version string
269 *
270 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
271 * main loop has started) to update the BIOS version string (SMBIOS table 0).
272 *
273 * @version: New version string to use
274 * @return 0 if OK, -ENOENT if no version string was previously written,
275 * -ENOSPC if the new string is too large to fit
276 */
277int smbios_update_version(const char *version);
278
Simon Glass272e62c2021-03-15 18:00:11 +1300279/**
280 * smbios_update_version_full() - Update the version string
281 *
282 * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
283 * main loop has started) to update the BIOS version string (SMBIOS table 0).
284 * It scans for the correct place to put the version, so does not need U-Boot
285 * to have actually written the tables itself (e.g. if a previous bootloader
286 * did it).
287 *
288 * @smbios_tab: Start of SMBIOS tables
289 * @version: New version string to use
290 * @return 0 if OK, -ENOENT if no version string was previously written,
291 * -ENOSPC if the new string is too large to fit
292 */
293int smbios_update_version_full(void *smbios_tab, const char *version);
294
Bin Meng721e9922015-10-12 05:23:41 -0700295#endif /* _SMBIOS_H_ */