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 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 11 | #include <dm/ofnode.h> |
| 12 | |
Bin Meng | ae5bedb | 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 | |
| 17 | /* SMBIOS structure types */ |
| 18 | enum { |
| 19 | SMBIOS_BIOS_INFORMATION = 0, |
| 20 | SMBIOS_SYSTEM_INFORMATION = 1, |
| 21 | SMBIOS_BOARD_INFORMATION = 2, |
| 22 | SMBIOS_SYSTEM_ENCLOSURE = 3, |
| 23 | SMBIOS_PROCESSOR_INFORMATION = 4, |
| 24 | SMBIOS_CACHE_INFORMATION = 7, |
| 25 | SMBIOS_SYSTEM_SLOTS = 9, |
| 26 | SMBIOS_PHYS_MEMORY_ARRAY = 16, |
| 27 | SMBIOS_MEMORY_DEVICE = 17, |
| 28 | SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS = 19, |
| 29 | SMBIOS_SYSTEM_BOOT_INFORMATION = 32, |
| 30 | SMBIOS_END_OF_TABLE = 127 |
| 31 | }; |
| 32 | |
| 33 | #define SMBIOS_INTERMEDIATE_OFFSET 16 |
| 34 | #define SMBIOS_STRUCT_EOS_BYTES 2 |
| 35 | |
| 36 | struct __packed smbios_entry { |
| 37 | u8 anchor[4]; |
| 38 | u8 checksum; |
| 39 | u8 length; |
| 40 | u8 major_ver; |
| 41 | u8 minor_ver; |
| 42 | u16 max_struct_size; |
| 43 | u8 entry_point_rev; |
| 44 | u8 formatted_area[5]; |
| 45 | u8 intermediate_anchor[5]; |
| 46 | u8 intermediate_checksum; |
| 47 | u16 struct_table_length; |
| 48 | u32 struct_table_address; |
| 49 | u16 struct_count; |
| 50 | u8 bcd_rev; |
| 51 | }; |
| 52 | |
| 53 | /* BIOS characteristics */ |
| 54 | #define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7) |
| 55 | #define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11) |
| 56 | #define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16) |
| 57 | |
| 58 | #define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0) |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 59 | #define BIOS_CHARACTERISTICS_EXT1_UEFI (1 << 3) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 60 | #define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2) |
| 61 | |
| 62 | struct __packed smbios_type0 { |
| 63 | u8 type; |
| 64 | u8 length; |
| 65 | u16 handle; |
| 66 | u8 vendor; |
| 67 | u8 bios_ver; |
| 68 | u16 bios_start_segment; |
| 69 | u8 bios_release_date; |
| 70 | u8 bios_rom_size; |
| 71 | u64 bios_characteristics; |
| 72 | u8 bios_characteristics_ext1; |
| 73 | u8 bios_characteristics_ext2; |
| 74 | u8 bios_major_release; |
| 75 | u8 bios_minor_release; |
| 76 | u8 ec_major_release; |
| 77 | u8 ec_minor_release; |
| 78 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 79 | }; |
| 80 | |
| 81 | struct __packed smbios_type1 { |
| 82 | u8 type; |
| 83 | u8 length; |
| 84 | u16 handle; |
| 85 | u8 manufacturer; |
| 86 | u8 product_name; |
| 87 | u8 version; |
| 88 | u8 serial_number; |
| 89 | u8 uuid[16]; |
| 90 | u8 wakeup_type; |
| 91 | u8 sku_number; |
| 92 | u8 family; |
| 93 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 94 | }; |
| 95 | |
| 96 | #define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0) |
| 97 | #define SMBIOS_BOARD_MOTHERBOARD 10 |
| 98 | |
| 99 | struct __packed smbios_type2 { |
| 100 | u8 type; |
| 101 | u8 length; |
| 102 | u16 handle; |
| 103 | u8 manufacturer; |
| 104 | u8 product_name; |
| 105 | u8 version; |
| 106 | u8 serial_number; |
| 107 | u8 asset_tag_number; |
| 108 | u8 feature_flags; |
| 109 | u8 chassis_location; |
| 110 | u16 chassis_handle; |
| 111 | u8 board_type; |
| 112 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 113 | }; |
| 114 | |
| 115 | #define SMBIOS_ENCLOSURE_DESKTOP 3 |
| 116 | #define SMBIOS_STATE_SAFE 3 |
| 117 | #define SMBIOS_SECURITY_NONE 3 |
| 118 | |
| 119 | struct __packed smbios_type3 { |
| 120 | u8 type; |
| 121 | u8 length; |
| 122 | u16 handle; |
| 123 | u8 manufacturer; |
| 124 | u8 chassis_type; |
| 125 | u8 version; |
| 126 | u8 serial_number; |
| 127 | u8 asset_tag_number; |
| 128 | u8 bootup_state; |
| 129 | u8 power_supply_state; |
| 130 | u8 thermal_state; |
| 131 | u8 security_status; |
| 132 | u32 oem_defined; |
| 133 | u8 height; |
| 134 | u8 number_of_power_cords; |
| 135 | u8 element_count; |
| 136 | u8 element_record_length; |
| 137 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 138 | }; |
| 139 | |
| 140 | #define SMBIOS_PROCESSOR_TYPE_CENTRAL 3 |
| 141 | #define SMBIOS_PROCESSOR_STATUS_ENABLED 1 |
| 142 | #define SMBIOS_PROCESSOR_UPGRADE_NONE 6 |
| 143 | |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 144 | #define SMBIOS_PROCESSOR_FAMILY_OTHER 1 |
| 145 | #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 |
| 146 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 147 | struct __packed smbios_type4 { |
| 148 | u8 type; |
| 149 | u8 length; |
| 150 | u16 handle; |
| 151 | u8 socket_designation; |
| 152 | u8 processor_type; |
| 153 | u8 processor_family; |
| 154 | u8 processor_manufacturer; |
| 155 | u32 processor_id[2]; |
| 156 | u8 processor_version; |
| 157 | u8 voltage; |
| 158 | u16 external_clock; |
| 159 | u16 max_speed; |
| 160 | u16 current_speed; |
| 161 | u8 status; |
| 162 | u8 processor_upgrade; |
| 163 | u16 l1_cache_handle; |
| 164 | u16 l2_cache_handle; |
| 165 | u16 l3_cache_handle; |
| 166 | u8 serial_number; |
| 167 | u8 asset_tag; |
| 168 | u8 part_number; |
| 169 | u8 core_count; |
| 170 | u8 core_enabled; |
| 171 | u8 thread_count; |
| 172 | u16 processor_characteristics; |
| 173 | u16 processor_family2; |
| 174 | u16 core_count2; |
| 175 | u16 core_enabled2; |
| 176 | u16 thread_count2; |
| 177 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
| 178 | }; |
| 179 | |
| 180 | struct __packed smbios_type32 { |
| 181 | u8 type; |
| 182 | u8 length; |
| 183 | u16 handle; |
| 184 | u8 reserved[6]; |
| 185 | u8 boot_status; |
Simon Glass | 99cfc6f | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 186 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | struct __packed smbios_type127 { |
| 190 | u8 type; |
| 191 | u8 length; |
| 192 | u16 handle; |
Simon Glass | 99cfc6f | 2021-02-04 21:17:15 -0700 | [diff] [blame] | 193 | char eos[SMBIOS_STRUCT_EOS_BYTES]; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | struct __packed smbios_header { |
| 197 | u8 type; |
| 198 | u8 length; |
| 199 | u16 handle; |
| 200 | }; |
| 201 | |
| 202 | /** |
| 203 | * fill_smbios_header() - Fill the header of an SMBIOS table |
| 204 | * |
| 205 | * This fills the header of an SMBIOS table structure. |
| 206 | * |
| 207 | * @table: start address of the structure |
| 208 | * @type: the type of structure |
| 209 | * @length: the length of the formatted area of the structure |
| 210 | * @handle: the structure's handle, a unique 16-bit number |
| 211 | */ |
| 212 | static inline void fill_smbios_header(void *table, int type, |
| 213 | int length, int handle) |
| 214 | { |
| 215 | struct smbios_header *header = table; |
| 216 | |
| 217 | header->type = type; |
| 218 | header->length = length - SMBIOS_STRUCT_EOS_BYTES; |
| 219 | header->handle = handle; |
| 220 | } |
| 221 | |
| 222 | /** |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 223 | * write_smbios_table() - Write SMBIOS table |
| 224 | * |
| 225 | * This writes SMBIOS table at a given address. |
| 226 | * |
Simon Glass | 2e2858f | 2018-05-16 09:42:19 -0600 | [diff] [blame] | 227 | * @addr: start address to write SMBIOS table. If this is not |
| 228 | * 16-byte-aligned then it will be aligned before the table is written |
| 229 | * @return: end address of SMBIOS table (and start address for next entry) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 230 | */ |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 231 | ulong write_smbios_table(ulong addr); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 232 | |
Christian Gmeiner | 1985998 | 2020-11-03 15:34:51 +0100 | [diff] [blame] | 233 | /** |
| 234 | * smbios_entry() - Get a valid struct smbios_entry pointer |
| 235 | * |
| 236 | * @address: address where smbios tables is located |
| 237 | * @size: size of smbios table |
| 238 | * @return: NULL or a valid pointer to a struct smbios_entry |
| 239 | */ |
| 240 | const struct smbios_entry *smbios_entry(u64 address, u32 size); |
| 241 | |
| 242 | /** |
| 243 | * smbios_header() - Search for SMBIOS header type |
| 244 | * |
| 245 | * @entry: pointer to a struct smbios_entry |
| 246 | * @type: SMBIOS type |
| 247 | * @return: NULL or a valid pointer to a struct smbios_header |
| 248 | */ |
| 249 | const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type); |
| 250 | |
| 251 | /** |
| 252 | * smbios_string() - Return string from SMBIOS |
| 253 | * |
| 254 | * @header: pointer to struct smbios_header |
| 255 | * @index: string index |
| 256 | * @return: NULL or a valid const char pointer |
| 257 | */ |
| 258 | const char *smbios_string(const struct smbios_header *header, int index); |
| 259 | |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 260 | /** |
| 261 | * smbios_update_version() - Update the version string |
| 262 | * |
| 263 | * This can be called after the SMBIOS tables are written (e.g. after the U-Boot |
| 264 | * main loop has started) to update the BIOS version string (SMBIOS table 0). |
| 265 | * |
| 266 | * @version: New version string to use |
| 267 | * @return 0 if OK, -ENOENT if no version string was previously written, |
| 268 | * -ENOSPC if the new string is too large to fit |
| 269 | */ |
| 270 | int smbios_update_version(const char *version); |
| 271 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 272 | #endif /* _SMBIOS_H_ */ |