Convert CONFIG_SYS_LOAD_ADDR to Kconfig
[platform/kernel/u-boot.git] / include / smbios.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4  *
5  * Adapted from coreboot src/include/smbios.h
6  */
7
8 #ifndef _SMBIOS_H_
9 #define _SMBIOS_H_
10
11 #include <dm/ofnode.h>
12
13 /* SMBIOS spec version implemented */
14 #define SMBIOS_MAJOR_VER        3
15 #define SMBIOS_MINOR_VER        0
16
17 enum {
18         SMBIOS_STR_MAX  = 64,   /* Maximum length allowed for a string */
19 };
20
21 /* SMBIOS structure types */
22 enum {
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
40 struct __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)
63 #define BIOS_CHARACTERISTICS_EXT2_UEFI          (1 << 3)
64 #define BIOS_CHARACTERISTICS_EXT2_TARGET        (1 << 2)
65
66 struct __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
85 struct __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
103 struct __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
123 struct __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
148 #define SMBIOS_PROCESSOR_FAMILY_OTHER   1
149 #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2
150
151 struct __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
184 struct __packed smbios_type32 {
185         u8 type;
186         u8 length;
187         u16 handle;
188         u8 reserved[6];
189         u8 boot_status;
190         char eos[SMBIOS_STRUCT_EOS_BYTES];
191 };
192
193 struct __packed smbios_type127 {
194         u8 type;
195         u8 length;
196         u16 handle;
197         char eos[SMBIOS_STRUCT_EOS_BYTES];
198 };
199
200 struct __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  */
216 static 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 /**
227  * write_smbios_table() - Write SMBIOS table
228  *
229  * This writes SMBIOS table at a given address.
230  *
231  * @addr:       start address to write SMBIOS table. If this is not
232  *              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  *
237  */
238 ulong write_smbios_table(ulong addr);
239
240 /**
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  */
247 const 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  */
256 const 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  */
265 const char *smbios_string(const struct smbios_header *header, int index);
266
267 /**
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  */
277 int smbios_update_version(const char *version);
278
279 /**
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  */
293 int smbios_update_version_full(void *smbios_tab, const char *version);
294
295 #endif /* _SMBIOS_H_ */