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 | |
Simon Glass | 78227d4 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 11 | #include <dm/ofnode.h> |
| 12 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 13 | /* SMBIOS spec version implemented */ |
| 14 | #define SMBIOS_MAJOR_VER 3 |
| 15 | #define SMBIOS_MINOR_VER 0 |
| 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 | |
| 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 Apalodimas | ff19230 | 2021-06-09 18:14:47 +0300 | [diff] [blame] | 63 | #define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3) |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 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 | |
Alexander Graf | 9647620 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 148 | #define SMBIOS_PROCESSOR_FAMILY_OTHER 1 |
| 149 | #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 |
| 150 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 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; |
Simon Glass | dc09058 | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 190 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | struct __packed smbios_type127 { |
| 194 | u8 type; |
| 195 | u8 length; |
| 196 | u16 handle; |
Simon Glass | dc09058 | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 197 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 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 | /** |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 227 | * write_smbios_table() - Write SMBIOS table |
| 228 | * |
| 229 | * This writes SMBIOS table at a given address. |
| 230 | * |
Simon Glass | 0864c56 | 2018-05-16 09:42:19 -0600 | [diff] [blame] | 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 written |
| 233 | * @return: end address of SMBIOS table (and start address for next entry) |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 234 | */ |
Simon Glass | 42fd8c1 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 235 | ulong write_smbios_table(ulong addr); |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 236 | |
Christian Gmeiner | 415eab0 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 237 | /** |
| 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 | */ |
| 244 | const 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 | */ |
| 253 | const 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 | */ |
| 262 | const char *smbios_string(const struct smbios_header *header, int index); |
| 263 | |
Simon Glass | e9adaa7 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 264 | /** |
| 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 | */ |
| 274 | int smbios_update_version(const char *version); |
| 275 | |
Simon Glass | 272e62c | 2021-03-15 18:00:11 +1300 | [diff] [blame] | 276 | /** |
| 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 | */ |
| 290 | int smbios_update_version_full(void *smbios_tab, const char *version); |
| 291 | |
Bin Meng | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 292 | #endif /* _SMBIOS_H_ */ |