Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
| 4 | * |
| 5 | * Adapted from coreboot src/include/smbios.h |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _SMBIOS_H_ |
| 9 | #define _SMBIOS_H_ |
| 10 | |
Heinrich Schuchardt | 34e97aa | 2024-01-03 09:07:20 +0100 | [diff] [blame] | 11 | #include <linux/types.h> |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 12 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 13 | /* SMBIOS spec version implemented */ |
| 14 | #define SMBIOS_MAJOR_VER 3 |
Simon Glass | f86d7a0 | 2023-12-31 08:25:47 -0700 | [diff] [blame] | 15 | #define SMBIOS_MINOR_VER 7 |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 16 | |
Simon Glass | 3971a2a | 2021-03-15 18:00:11 +1300 | [diff] [blame] | 17 | enum { |
| 18 | SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */ |
| 19 | }; |
| 20 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 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 | |
Heinrich Schuchardt | 0db02c0 | 2023-12-31 08:25:46 -0700 | [diff] [blame] | 57 | /** |
| 58 | * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure |
| 59 | */ |
| 60 | struct __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 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 83 | /* BIOS characteristics */ |
| 84 | #define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7) |
| 85 | #define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11) |
| 86 | #define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16) |
| 87 | |
| 88 | #define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0) |
Ilias Apalodimas | 15578bc | 2021-06-09 18:14:47 +0300 | [diff] [blame] | 89 | #define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 90 | #define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2) |
| 91 | |
| 92 | struct __packed smbios_type0 { |
| 93 | u8 type; |
| 94 | u8 length; |
| 95 | u16 handle; |
| 96 | u8 vendor; |
| 97 | u8 bios_ver; |
| 98 | u16 bios_start_segment; |
| 99 | u8 bios_release_date; |
| 100 | u8 bios_rom_size; |
| 101 | u64 bios_characteristics; |
| 102 | u8 bios_characteristics_ext1; |
| 103 | u8 bios_characteristics_ext2; |
| 104 | u8 bios_major_release; |
| 105 | u8 bios_minor_release; |
| 106 | u8 ec_major_release; |
| 107 | u8 ec_minor_release; |
| 108 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 109 | }; |
| 110 | |
| 111 | struct __packed smbios_type1 { |
| 112 | u8 type; |
| 113 | u8 length; |
| 114 | u16 handle; |
| 115 | u8 manufacturer; |
| 116 | u8 product_name; |
| 117 | u8 version; |
| 118 | u8 serial_number; |
| 119 | u8 uuid[16]; |
| 120 | u8 wakeup_type; |
| 121 | u8 sku_number; |
| 122 | u8 family; |
| 123 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 124 | }; |
| 125 | |
| 126 | #define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0) |
| 127 | #define SMBIOS_BOARD_MOTHERBOARD 10 |
| 128 | |
| 129 | struct __packed smbios_type2 { |
| 130 | u8 type; |
| 131 | u8 length; |
| 132 | u16 handle; |
| 133 | u8 manufacturer; |
| 134 | u8 product_name; |
| 135 | u8 version; |
| 136 | u8 serial_number; |
| 137 | u8 asset_tag_number; |
| 138 | u8 feature_flags; |
| 139 | u8 chassis_location; |
| 140 | u16 chassis_handle; |
| 141 | u8 board_type; |
| 142 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 143 | }; |
| 144 | |
| 145 | #define SMBIOS_ENCLOSURE_DESKTOP 3 |
| 146 | #define SMBIOS_STATE_SAFE 3 |
| 147 | #define SMBIOS_SECURITY_NONE 3 |
| 148 | |
| 149 | struct __packed smbios_type3 { |
| 150 | u8 type; |
| 151 | u8 length; |
| 152 | u16 handle; |
| 153 | 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; |
| 167 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 168 | }; |
| 169 | |
| 170 | #define SMBIOS_PROCESSOR_TYPE_CENTRAL 3 |
| 171 | #define SMBIOS_PROCESSOR_STATUS_ENABLED 1 |
| 172 | #define SMBIOS_PROCESSOR_UPGRADE_NONE 6 |
| 173 | |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 174 | #define SMBIOS_PROCESSOR_FAMILY_OTHER 1 |
| 175 | #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 |
| 176 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 177 | struct __packed smbios_type4 { |
| 178 | u8 type; |
| 179 | u8 length; |
| 180 | u16 handle; |
| 181 | u8 socket_designation; |
| 182 | u8 processor_type; |
| 183 | u8 processor_family; |
| 184 | u8 processor_manufacturer; |
| 185 | u32 processor_id[2]; |
| 186 | u8 processor_version; |
| 187 | u8 voltage; |
| 188 | u16 external_clock; |
| 189 | u16 max_speed; |
| 190 | u16 current_speed; |
| 191 | u8 status; |
| 192 | u8 processor_upgrade; |
| 193 | u16 l1_cache_handle; |
| 194 | u16 l2_cache_handle; |
| 195 | u16 l3_cache_handle; |
| 196 | u8 serial_number; |
| 197 | u8 asset_tag; |
| 198 | u8 part_number; |
| 199 | u8 core_count; |
| 200 | u8 core_enabled; |
| 201 | u8 thread_count; |
| 202 | u16 processor_characteristics; |
| 203 | u16 processor_family2; |
| 204 | u16 core_count2; |
| 205 | u16 core_enabled2; |
| 206 | u16 thread_count2; |
| 207 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 208 | }; |
| 209 | |
| 210 | struct __packed smbios_type32 { |
| 211 | u8 type; |
| 212 | u8 length; |
| 213 | u16 handle; |
| 214 | u8 reserved[6]; |
| 215 | u8 boot_status; |
Simon Glass | 99cfc6f | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 216 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | struct __packed smbios_type127 { |
| 220 | u8 type; |
| 221 | u8 length; |
| 222 | u16 handle; |
Simon Glass | 99cfc6f | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 223 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | struct __packed smbios_header { |
| 227 | u8 type; |
| 228 | u8 length; |
| 229 | u16 handle; |
| 230 | }; |
| 231 | |
| 232 | /** |
| 233 | * fill_smbios_header() - Fill the header of an SMBIOS table |
| 234 | * |
| 235 | * This fills the header of an SMBIOS table structure. |
| 236 | * |
| 237 | * @table: start address of the structure |
| 238 | * @type: the type of structure |
| 239 | * @length: the length of the formatted area of the structure |
| 240 | * @handle: the structure's handle, a unique 16-bit number |
| 241 | */ |
| 242 | static inline void fill_smbios_header(void *table, int type, |
| 243 | int length, int handle) |
| 244 | { |
| 245 | struct smbios_header *header = table; |
| 246 | |
| 247 | header->type = type; |
| 248 | header->length = length - SMBIOS_STRUCT_EOS_BYTES; |
| 249 | header->handle = handle; |
| 250 | } |
| 251 | |
| 252 | /** |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 253 | * write_smbios_table() - Write SMBIOS table |
| 254 | * |
| 255 | * This writes SMBIOS table at a given address. |
| 256 | * |
Simon Glass | f0e95eb | 2023-12-31 08:25:50 -0700 | [diff] [blame] | 257 | * @addr: start address to write SMBIOS table, 16-byte-alignment |
| 258 | * recommended. Note that while the SMBIOS tables themself have no alignment |
| 259 | * requirement, some systems may requires alignment. For example x86 systems |
| 260 | * which put tables at f0000 require 16-byte alignment |
| 261 | * |
Heinrich Schuchardt | 21da91f | 2021-05-15 18:07:47 +0200 | [diff] [blame] | 262 | * Return: end address of SMBIOS table (and start address for next entry) |
| 263 | * or NULL in case of an error |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 264 | */ |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 265 | ulong write_smbios_table(ulong addr); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 266 | |
Christian Gmeiner | 1985998 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 267 | /** |
| 268 | * smbios_entry() - Get a valid struct smbios_entry pointer |
| 269 | * |
| 270 | * @address: address where smbios tables is located |
| 271 | * @size: size of smbios table |
| 272 | * @return: NULL or a valid pointer to a struct smbios_entry |
| 273 | */ |
| 274 | const struct smbios_entry *smbios_entry(u64 address, u32 size); |
| 275 | |
| 276 | /** |
| 277 | * smbios_header() - Search for SMBIOS header type |
| 278 | * |
| 279 | * @entry: pointer to a struct smbios_entry |
| 280 | * @type: SMBIOS type |
| 281 | * @return: NULL or a valid pointer to a struct smbios_header |
| 282 | */ |
| 283 | const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type); |
| 284 | |
| 285 | /** |
| 286 | * smbios_string() - Return string from SMBIOS |
| 287 | * |
| 288 | * @header: pointer to struct smbios_header |
| 289 | * @index: string index |
Masahisa Kojima | cd1fe7d | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 290 | * @return: NULL or a valid char pointer |
Christian Gmeiner | 1985998 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 291 | */ |
Masahisa Kojima | cd1fe7d | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 292 | char *smbios_string(const struct smbios_header *header, int index); |
Christian Gmeiner | 1985998 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 293 | |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 294 | /** |
| 295 | * smbios_update_version() - Update the version string |
| 296 | * |
| 297 | * This can be called after the SMBIOS tables are written (e.g. after the U-Boot |
| 298 | * main loop has started) to update the BIOS version string (SMBIOS table 0). |
| 299 | * |
| 300 | * @version: New version string to use |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 301 | * Return: 0 if OK, -ENOENT if no version string was previously written, |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 302 | * -ENOSPC if the new string is too large to fit |
| 303 | */ |
| 304 | int smbios_update_version(const char *version); |
| 305 | |
Simon Glass | 3971a2a | 2021-03-15 18:00:11 +1300 | [diff] [blame] | 306 | /** |
| 307 | * smbios_update_version_full() - Update the version string |
| 308 | * |
| 309 | * This can be called after the SMBIOS tables are written (e.g. after the U-Boot |
| 310 | * main loop has started) to update the BIOS version string (SMBIOS table 0). |
| 311 | * It scans for the correct place to put the version, so does not need U-Boot |
| 312 | * to have actually written the tables itself (e.g. if a previous bootloader |
| 313 | * did it). |
| 314 | * |
| 315 | * @smbios_tab: Start of SMBIOS tables |
| 316 | * @version: New version string to use |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 317 | * Return: 0 if OK, -ENOENT if no version string was previously written, |
Simon Glass | 3971a2a | 2021-03-15 18:00:11 +1300 | [diff] [blame] | 318 | * -ENOSPC if the new string is too large to fit |
| 319 | */ |
| 320 | int smbios_update_version_full(void *smbios_tab, const char *version); |
| 321 | |
Masahisa Kojima | cd1fe7d | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 322 | /** |
| 323 | * smbios_prepare_measurement() - Update smbios table for the measurement |
| 324 | * |
| 325 | * TCG specification requires to measure static configuration information. |
| 326 | * This function clear the device dependent parameters such as |
| 327 | * serial number for the measurement. |
| 328 | * |
| 329 | * @entry: pointer to a struct smbios_entry |
| 330 | * @header: pointer to a struct smbios_header |
| 331 | */ |
| 332 | void smbios_prepare_measurement(const struct smbios_entry *entry, |
| 333 | struct smbios_header *header); |
| 334 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 335 | #endif /* _SMBIOS_H_ */ |