Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Bin Meng | 721e992 | 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 | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _SMBIOS_H_ |
| 9 | #define _SMBIOS_H_ |
| 10 | |
Heinrich Schuchardt | efe441a | 2024-01-03 09:07:20 +0100 | [diff] [blame] | 11 | #include <linux/types.h> |
Simon Glass | 78227d4 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 12 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 13 | /* SMBIOS spec version implemented */ |
| 14 | #define SMBIOS_MAJOR_VER 3 |
Simon Glass | 7092429 | 2023-12-31 08:25:47 -0700 | [diff] [blame] | 15 | #define SMBIOS_MINOR_VER 7 |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 16 | |
Simon Glass | 272e62c | 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 | 721e992 | 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 | de4b91c | 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 */ |
Heinrich Schuchardt | 406c410e | 2024-01-31 23:49:34 +0100 | [diff] [blame] | 78 | u32 table_maximum_size; |
Heinrich Schuchardt | de4b91c | 2023-12-31 08:25:46 -0700 | [diff] [blame] | 79 | /** @struct_table_address: 64-bit physical starting address */ |
| 80 | u64 struct_table_address; |
| 81 | }; |
| 82 | |
Bin Meng | 721e992 | 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 | ff19230 | 2021-06-09 18:14:47 +0300 | [diff] [blame] | 89 | #define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3) |
Bin Meng | 721e992 | 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; |
Heinrich Schuchardt | 8c919fc | 2024-07-23 16:44:23 +0200 | [diff] [blame] | 108 | u16 extended_bios_rom_size; |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 109 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 110 | }; |
| 111 | |
Heinrich Schuchardt | 6eca28b | 2024-02-10 12:06:48 +0100 | [diff] [blame] | 112 | /** |
| 113 | * enum smbios_wakeup_type - wake-up type |
| 114 | * |
| 115 | * These constants are used for the Wake-Up Type field in the SMBIOS |
| 116 | * System Information (Type 1) structure. |
| 117 | */ |
| 118 | enum smbios_wakeup_type { |
| 119 | /** @SMBIOS_WAKEUP_TYPE_RESERVED: Reserved */ |
| 120 | SMBIOS_WAKEUP_TYPE_RESERVED, |
| 121 | /** @SMBIOS_WAKEUP_TYPE_OTHER: Other */ |
| 122 | SMBIOS_WAKEUP_TYPE_OTHER, |
| 123 | /** @SMBIOS_WAKEUP_TYPE_UNKNOWN: Unknown */ |
| 124 | SMBIOS_WAKEUP_TYPE_UNKNOWN, |
| 125 | /** @SMBIOS_WAKEUP_TYPE_APM_TIMER: APM Timer */ |
| 126 | SMBIOS_WAKEUP_TYPE_APM_TIMER, |
| 127 | /** @SMBIOS_WAKEUP_TYPE_MODEM_RING: Modem Ring */ |
| 128 | SMBIOS_WAKEUP_TYPE_MODEM_RING, |
| 129 | /** @SMBIOS_WAKEUP_TYPE_LAN_REMOTE: LAN Remote */ |
| 130 | SMBIOS_WAKEUP_TYPE_LAN_REMOTE, |
| 131 | /** @SMBIOS_WAKEUP_TYPE_POWER_SWITCH: Power Switch */ |
| 132 | SMBIOS_WAKEUP_TYPE_POWER_SWITCH, |
| 133 | /** @SMBIOS_WAKEUP_TYPE_PCI_PME: PCI PME# */ |
| 134 | SMBIOS_WAKEUP_TYPE_PCI_PME, |
| 135 | /** @SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED: AC Power Restored */ |
| 136 | SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED, |
| 137 | }; |
| 138 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 139 | struct __packed smbios_type1 { |
| 140 | u8 type; |
| 141 | u8 length; |
| 142 | u16 handle; |
| 143 | u8 manufacturer; |
| 144 | u8 product_name; |
| 145 | u8 version; |
| 146 | u8 serial_number; |
| 147 | u8 uuid[16]; |
| 148 | u8 wakeup_type; |
| 149 | u8 sku_number; |
| 150 | u8 family; |
| 151 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 152 | }; |
| 153 | |
| 154 | #define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0) |
| 155 | #define SMBIOS_BOARD_MOTHERBOARD 10 |
| 156 | |
| 157 | struct __packed smbios_type2 { |
| 158 | u8 type; |
| 159 | u8 length; |
| 160 | u16 handle; |
| 161 | u8 manufacturer; |
| 162 | u8 product_name; |
| 163 | u8 version; |
| 164 | u8 serial_number; |
| 165 | u8 asset_tag_number; |
| 166 | u8 feature_flags; |
| 167 | u8 chassis_location; |
| 168 | u16 chassis_handle; |
| 169 | u8 board_type; |
Heinrich Schuchardt | a5866c3 | 2024-01-25 16:54:33 +0100 | [diff] [blame] | 170 | u8 number_contained_objects; |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 171 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 172 | }; |
| 173 | |
| 174 | #define SMBIOS_ENCLOSURE_DESKTOP 3 |
| 175 | #define SMBIOS_STATE_SAFE 3 |
| 176 | #define SMBIOS_SECURITY_NONE 3 |
| 177 | |
| 178 | struct __packed smbios_type3 { |
| 179 | u8 type; |
| 180 | u8 length; |
| 181 | u16 handle; |
| 182 | u8 manufacturer; |
| 183 | u8 chassis_type; |
| 184 | u8 version; |
| 185 | u8 serial_number; |
| 186 | u8 asset_tag_number; |
| 187 | u8 bootup_state; |
| 188 | u8 power_supply_state; |
| 189 | u8 thermal_state; |
| 190 | u8 security_status; |
| 191 | u32 oem_defined; |
| 192 | u8 height; |
| 193 | u8 number_of_power_cords; |
| 194 | u8 element_count; |
| 195 | u8 element_record_length; |
| 196 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 197 | }; |
| 198 | |
| 199 | #define SMBIOS_PROCESSOR_TYPE_CENTRAL 3 |
| 200 | #define SMBIOS_PROCESSOR_STATUS_ENABLED 1 |
| 201 | #define SMBIOS_PROCESSOR_UPGRADE_NONE 6 |
| 202 | |
Alexander Graf | 9647620 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 203 | #define SMBIOS_PROCESSOR_FAMILY_OTHER 1 |
| 204 | #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 |
| 205 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 206 | struct __packed smbios_type4 { |
| 207 | u8 type; |
| 208 | u8 length; |
| 209 | u16 handle; |
| 210 | u8 socket_designation; |
| 211 | u8 processor_type; |
| 212 | u8 processor_family; |
| 213 | u8 processor_manufacturer; |
| 214 | u32 processor_id[2]; |
| 215 | u8 processor_version; |
| 216 | u8 voltage; |
| 217 | u16 external_clock; |
| 218 | u16 max_speed; |
| 219 | u16 current_speed; |
| 220 | u8 status; |
| 221 | u8 processor_upgrade; |
| 222 | u16 l1_cache_handle; |
| 223 | u16 l2_cache_handle; |
| 224 | u16 l3_cache_handle; |
| 225 | u8 serial_number; |
| 226 | u8 asset_tag; |
| 227 | u8 part_number; |
| 228 | u8 core_count; |
| 229 | u8 core_enabled; |
| 230 | u8 thread_count; |
| 231 | u16 processor_characteristics; |
| 232 | u16 processor_family2; |
| 233 | u16 core_count2; |
| 234 | u16 core_enabled2; |
| 235 | u16 thread_count2; |
| 236 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 237 | }; |
| 238 | |
| 239 | struct __packed smbios_type32 { |
| 240 | u8 type; |
| 241 | u8 length; |
| 242 | u16 handle; |
| 243 | u8 reserved[6]; |
| 244 | u8 boot_status; |
Simon Glass | dc09058 | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 245 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | struct __packed smbios_type127 { |
| 249 | u8 type; |
| 250 | u8 length; |
| 251 | u16 handle; |
Simon Glass | dc09058 | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 252 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | struct __packed smbios_header { |
| 256 | u8 type; |
| 257 | u8 length; |
| 258 | u16 handle; |
| 259 | }; |
| 260 | |
| 261 | /** |
| 262 | * fill_smbios_header() - Fill the header of an SMBIOS table |
| 263 | * |
| 264 | * This fills the header of an SMBIOS table structure. |
| 265 | * |
| 266 | * @table: start address of the structure |
| 267 | * @type: the type of structure |
| 268 | * @length: the length of the formatted area of the structure |
| 269 | * @handle: the structure's handle, a unique 16-bit number |
| 270 | */ |
| 271 | static inline void fill_smbios_header(void *table, int type, |
| 272 | int length, int handle) |
| 273 | { |
| 274 | struct smbios_header *header = table; |
| 275 | |
| 276 | header->type = type; |
| 277 | header->length = length - SMBIOS_STRUCT_EOS_BYTES; |
| 278 | header->handle = handle; |
| 279 | } |
| 280 | |
| 281 | /** |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 282 | * write_smbios_table() - Write SMBIOS table |
| 283 | * |
| 284 | * This writes SMBIOS table at a given address. |
| 285 | * |
Simon Glass | 31f950a | 2023-12-31 08:25:50 -0700 | [diff] [blame] | 286 | * @addr: start address to write SMBIOS table, 16-byte-alignment |
| 287 | * recommended. Note that while the SMBIOS tables themself have no alignment |
| 288 | * requirement, some systems may requires alignment. For example x86 systems |
| 289 | * which put tables at f0000 require 16-byte alignment |
| 290 | * |
Heinrich Schuchardt | c193d9b | 2021-05-15 18:07:47 +0200 | [diff] [blame] | 291 | * Return: end address of SMBIOS table (and start address for next entry) |
| 292 | * or NULL in case of an error |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 293 | */ |
Simon Glass | 42fd8c1 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 294 | ulong write_smbios_table(ulong addr); |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 295 | |
Christian Gmeiner | 415eab0 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 296 | /** |
| 297 | * smbios_entry() - Get a valid struct smbios_entry pointer |
| 298 | * |
| 299 | * @address: address where smbios tables is located |
| 300 | * @size: size of smbios table |
| 301 | * @return: NULL or a valid pointer to a struct smbios_entry |
| 302 | */ |
| 303 | const struct smbios_entry *smbios_entry(u64 address, u32 size); |
| 304 | |
| 305 | /** |
| 306 | * smbios_header() - Search for SMBIOS header type |
| 307 | * |
| 308 | * @entry: pointer to a struct smbios_entry |
| 309 | * @type: SMBIOS type |
| 310 | * @return: NULL or a valid pointer to a struct smbios_header |
| 311 | */ |
| 312 | const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type); |
| 313 | |
| 314 | /** |
| 315 | * smbios_string() - Return string from SMBIOS |
| 316 | * |
| 317 | * @header: pointer to struct smbios_header |
| 318 | * @index: string index |
Masahisa Kojima | 3d49ee8 | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 319 | * @return: NULL or a valid char pointer |
Christian Gmeiner | 415eab0 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 320 | */ |
Masahisa Kojima | 3d49ee8 | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 321 | char *smbios_string(const struct smbios_header *header, int index); |
Christian Gmeiner | 415eab0 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 322 | |
Simon Glass | e9adaa7 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 323 | /** |
| 324 | * smbios_update_version() - Update the version string |
| 325 | * |
| 326 | * This can be called after the SMBIOS tables are written (e.g. after the U-Boot |
| 327 | * main loop has started) to update the BIOS version string (SMBIOS table 0). |
| 328 | * |
| 329 | * @version: New version string to use |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 330 | * Return: 0 if OK, -ENOENT if no version string was previously written, |
Simon Glass | e9adaa7 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 331 | * -ENOSPC if the new string is too large to fit |
| 332 | */ |
| 333 | int smbios_update_version(const char *version); |
| 334 | |
Simon Glass | 272e62c | 2021-03-15 18:00:11 +1300 | [diff] [blame] | 335 | /** |
| 336 | * smbios_update_version_full() - Update the version string |
| 337 | * |
| 338 | * This can be called after the SMBIOS tables are written (e.g. after the U-Boot |
| 339 | * main loop has started) to update the BIOS version string (SMBIOS table 0). |
| 340 | * It scans for the correct place to put the version, so does not need U-Boot |
| 341 | * to have actually written the tables itself (e.g. if a previous bootloader |
| 342 | * did it). |
| 343 | * |
| 344 | * @smbios_tab: Start of SMBIOS tables |
| 345 | * @version: New version string to use |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 346 | * Return: 0 if OK, -ENOENT if no version string was previously written, |
Simon Glass | 272e62c | 2021-03-15 18:00:11 +1300 | [diff] [blame] | 347 | * -ENOSPC if the new string is too large to fit |
| 348 | */ |
| 349 | int smbios_update_version_full(void *smbios_tab, const char *version); |
| 350 | |
Masahisa Kojima | 3d49ee8 | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 351 | /** |
| 352 | * smbios_prepare_measurement() - Update smbios table for the measurement |
| 353 | * |
| 354 | * TCG specification requires to measure static configuration information. |
| 355 | * This function clear the device dependent parameters such as |
| 356 | * serial number for the measurement. |
| 357 | * |
Masahisa Kojima | 2497f6a | 2024-01-26 09:53:42 +0900 | [diff] [blame] | 358 | * @entry: pointer to a struct smbios3_entry |
Masahisa Kojima | 3d49ee8 | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 359 | * @header: pointer to a struct smbios_header |
| 360 | */ |
Masahisa Kojima | 2497f6a | 2024-01-26 09:53:42 +0900 | [diff] [blame] | 361 | void smbios_prepare_measurement(const struct smbios3_entry *entry, |
Masahisa Kojima | 3d49ee8 | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 362 | struct smbios_header *header); |
| 363 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 364 | #endif /* _SMBIOS_H_ */ |