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/arch/x86/smbios.c |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 11 | #include <mapmem.h> |
Alexander Graf | fb22808 | 2016-08-19 01:23:23 +0200 | [diff] [blame] | 12 | #include <smbios.h> |
| 13 | #include <tables_csum.h> |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 14 | #include <version.h> |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 15 | #ifdef CONFIG_CPU |
| 16 | #include <cpu.h> |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 17 | #include <dm/uclass-internal.h> |
| 18 | #endif |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 19 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 20 | /** |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 21 | * struct smbios_write_method - Information about a table-writing function |
| 22 | * |
| 23 | * @write: Function to call |
| 24 | * @subnode_name: Name of subnode which has the information for this function, |
| 25 | * NULL if none |
| 26 | */ |
| 27 | struct smbios_write_method { |
| 28 | smbios_write_type write; |
| 29 | const char *subnode_name; |
| 30 | }; |
| 31 | |
| 32 | /** |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 33 | * smbios_add_string() - add a string to the string area |
| 34 | * |
| 35 | * This adds a string to the string area which is appended directly after |
| 36 | * the formatted portion of an SMBIOS structure. |
| 37 | * |
| 38 | * @start: string area start address |
| 39 | * @str: string to add |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 40 | * @return: string number in the string area (1 or more) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 41 | */ |
| 42 | static int smbios_add_string(char *start, const char *str) |
| 43 | { |
| 44 | int i = 1; |
| 45 | char *p = start; |
Heinrich Schuchardt | 20dcde4 | 2020-06-01 15:44:00 +0200 | [diff] [blame] | 46 | if (!*str) |
| 47 | str = "Unknown"; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 48 | |
| 49 | for (;;) { |
| 50 | if (!*p) { |
| 51 | strcpy(p, str); |
| 52 | p += strlen(str); |
| 53 | *p++ = '\0'; |
| 54 | *p++ = '\0'; |
| 55 | |
| 56 | return i; |
| 57 | } |
| 58 | |
| 59 | if (!strcmp(p, str)) |
| 60 | return i; |
| 61 | |
| 62 | p += strlen(p) + 1; |
| 63 | i++; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 68 | * smbios_add_prop_default() - Add a property from the device tree or default |
| 69 | * |
| 70 | * @start: string area start address |
| 71 | * @node: node containing the information to write (ofnode_null() if none) |
| 72 | * @prop: property to write |
| 73 | * @def: default string if the node has no such property |
| 74 | * @return 0 if not found, else SMBIOS string number (1 or more) |
| 75 | */ |
| 76 | static int smbios_add_prop_default(char *start, ofnode node, const char *prop, |
| 77 | const char *def) |
| 78 | { |
| 79 | const char *str = NULL; |
| 80 | |
| 81 | if (IS_ENABLED(CONFIG_OF_CONTROL)) |
| 82 | str = ofnode_read_string(node, prop); |
| 83 | if (str) |
| 84 | return smbios_add_string(start, str); |
| 85 | else if (def) |
| 86 | return smbios_add_string(start, def); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * smbios_add_prop() - Add a property from the device tree |
| 93 | * |
| 94 | * @start: string area start address |
| 95 | * @node: node containing the information to write (ofnode_null() if none) |
| 96 | * @prop: property to write |
| 97 | * @return 0 if not found, else SMBIOS string number (1 or more) |
| 98 | */ |
| 99 | static int smbios_add_prop(char *start, ofnode node, const char *prop) |
| 100 | { |
| 101 | return smbios_add_prop_default(start, node, prop, NULL); |
| 102 | } |
| 103 | |
| 104 | /** |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 105 | * smbios_string_table_len() - compute the string area size |
| 106 | * |
| 107 | * This computes the size of the string area including the string terminator. |
| 108 | * |
| 109 | * @start: string area start address |
| 110 | * @return: string area size |
| 111 | */ |
| 112 | static int smbios_string_table_len(char *start) |
| 113 | { |
| 114 | char *p = start; |
| 115 | int i, len = 0; |
| 116 | |
| 117 | while (*p) { |
| 118 | i = strlen(p) + 1; |
| 119 | p += i; |
| 120 | len += i; |
| 121 | } |
| 122 | |
| 123 | return len + 1; |
| 124 | } |
| 125 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 126 | static int smbios_write_type0(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 127 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 128 | struct smbios_type0 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 129 | int len = sizeof(struct smbios_type0); |
| 130 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 131 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 132 | memset(t, 0, sizeof(struct smbios_type0)); |
| 133 | fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle); |
| 134 | t->vendor = smbios_add_string(t->eos, "U-Boot"); |
| 135 | t->bios_ver = smbios_add_string(t->eos, PLAIN_VERSION); |
| 136 | t->bios_release_date = smbios_add_string(t->eos, U_BOOT_DMI_DATE); |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 137 | #ifdef CONFIG_ROM_SIZE |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 138 | t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 139 | #endif |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 140 | t->bios_characteristics = BIOS_CHARACTERISTICS_PCI_SUPPORTED | |
| 141 | BIOS_CHARACTERISTICS_SELECTABLE_BOOT | |
| 142 | BIOS_CHARACTERISTICS_UPGRADEABLE; |
| 143 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
| 144 | t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI; |
| 145 | #endif |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 146 | #ifdef CONFIG_EFI_LOADER |
| 147 | t->bios_characteristics_ext1 |= BIOS_CHARACTERISTICS_EXT1_UEFI; |
| 148 | #endif |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 149 | t->bios_characteristics_ext2 = BIOS_CHARACTERISTICS_EXT2_TARGET; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 150 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 151 | t->bios_major_release = 0xff; |
| 152 | t->bios_minor_release = 0xff; |
| 153 | t->ec_major_release = 0xff; |
| 154 | t->ec_minor_release = 0xff; |
| 155 | |
| 156 | len = t->length + smbios_string_table_len(t->eos); |
| 157 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 158 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 159 | |
| 160 | return len; |
| 161 | } |
| 162 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 163 | static int smbios_write_type1(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 164 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 165 | struct smbios_type1 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 166 | int len = sizeof(struct smbios_type1); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 167 | char *serial_str = env_get("serial#"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 168 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 169 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 170 | memset(t, 0, sizeof(struct smbios_type1)); |
| 171 | fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 172 | t->manufacturer = smbios_add_prop_default(t->eos, node, "manufacturer", |
| 173 | CONFIG_SMBIOS_MANUFACTURER); |
| 174 | t->product_name = smbios_add_prop_default(t->eos, node, "product", |
| 175 | CONFIG_SMBIOS_PRODUCT_NAME); |
Simon Glass | bc14e15 | 2020-11-05 06:32:09 -0700 | [diff] [blame^] | 176 | t->version = smbios_add_prop(t->eos, node, "version"); |
Alexander Graf | 9a3e3e2 | 2016-08-19 01:23:31 +0200 | [diff] [blame] | 177 | if (serial_str) { |
Alexander Graf | 9a3e3e2 | 2016-08-19 01:23:31 +0200 | [diff] [blame] | 178 | t->serial_number = smbios_add_string(t->eos, serial_str); |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 179 | strncpy((char *)t->uuid, serial_str, sizeof(t->uuid)); |
| 180 | } else { |
| 181 | t->serial_number = smbios_add_prop(t->eos, node, "serial"); |
Alexander Graf | 9a3e3e2 | 2016-08-19 01:23:31 +0200 | [diff] [blame] | 182 | } |
Simon Glass | bc14e15 | 2020-11-05 06:32:09 -0700 | [diff] [blame^] | 183 | t->sku_number = smbios_add_prop(t->eos, node, "sku"); |
| 184 | t->family = smbios_add_prop(t->eos, node, "family"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 185 | |
| 186 | len = t->length + smbios_string_table_len(t->eos); |
| 187 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 188 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 189 | |
| 190 | return len; |
| 191 | } |
| 192 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 193 | static int smbios_write_type2(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 194 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 195 | struct smbios_type2 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 196 | int len = sizeof(struct smbios_type2); |
| 197 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 198 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 199 | memset(t, 0, sizeof(struct smbios_type2)); |
| 200 | fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 201 | t->manufacturer = smbios_add_prop_default(t->eos, node, "manufacturer", |
| 202 | CONFIG_SMBIOS_MANUFACTURER); |
| 203 | t->product_name = smbios_add_prop_default(t->eos, node, "product", |
| 204 | CONFIG_SMBIOS_PRODUCT_NAME); |
Simon Glass | bc14e15 | 2020-11-05 06:32:09 -0700 | [diff] [blame^] | 205 | t->asset_tag_number = smbios_add_prop(t->eos, node, "asset-tag"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 206 | t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING; |
| 207 | t->board_type = SMBIOS_BOARD_MOTHERBOARD; |
| 208 | |
| 209 | len = t->length + smbios_string_table_len(t->eos); |
| 210 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 211 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 212 | |
| 213 | return len; |
| 214 | } |
| 215 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 216 | static int smbios_write_type3(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 217 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 218 | struct smbios_type3 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 219 | int len = sizeof(struct smbios_type3); |
| 220 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 221 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 222 | memset(t, 0, sizeof(struct smbios_type3)); |
| 223 | fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 224 | t->manufacturer = smbios_add_prop_default(t->eos, node, "manufacturer", |
| 225 | CONFIG_SMBIOS_MANUFACTURER); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 226 | t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP; |
| 227 | t->bootup_state = SMBIOS_STATE_SAFE; |
| 228 | t->power_supply_state = SMBIOS_STATE_SAFE; |
| 229 | t->thermal_state = SMBIOS_STATE_SAFE; |
| 230 | t->security_status = SMBIOS_SECURITY_NONE; |
| 231 | |
| 232 | len = t->length + smbios_string_table_len(t->eos); |
| 233 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 234 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 235 | |
| 236 | return len; |
| 237 | } |
| 238 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 239 | static void smbios_write_type4_dm(struct smbios_type4 *t, ofnode node) |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 240 | { |
| 241 | u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN; |
| 242 | const char *vendor = "Unknown"; |
| 243 | const char *name = "Unknown"; |
| 244 | |
| 245 | #ifdef CONFIG_CPU |
| 246 | char processor_name[49]; |
| 247 | char vendor_name[49]; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 248 | struct udevice *cpu = NULL; |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 249 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 250 | uclass_find_first_device(UCLASS_CPU, &cpu); |
| 251 | if (cpu) { |
| 252 | struct cpu_platdata *plat = dev_get_parent_platdata(cpu); |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 253 | |
| 254 | if (plat->family) |
| 255 | processor_family = plat->family; |
| 256 | t->processor_id[0] = plat->id[0]; |
| 257 | t->processor_id[1] = plat->id[1]; |
| 258 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 259 | if (!cpu_get_vendor(cpu, vendor_name, sizeof(vendor_name))) |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 260 | vendor = vendor_name; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 261 | if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name))) |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 262 | name = processor_name; |
| 263 | } |
| 264 | #endif |
| 265 | |
| 266 | t->processor_family = processor_family; |
| 267 | t->processor_manufacturer = smbios_add_string(t->eos, vendor); |
| 268 | t->processor_version = smbios_add_string(t->eos, name); |
| 269 | } |
| 270 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 271 | static int smbios_write_type4(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 272 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 273 | struct smbios_type4 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 274 | int len = sizeof(struct smbios_type4); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 275 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 276 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 277 | memset(t, 0, sizeof(struct smbios_type4)); |
| 278 | fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); |
| 279 | t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 280 | smbios_write_type4_dm(t, node); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 281 | t->status = SMBIOS_PROCESSOR_STATUS_ENABLED; |
| 282 | t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE; |
| 283 | t->l1_cache_handle = 0xffff; |
| 284 | t->l2_cache_handle = 0xffff; |
| 285 | t->l3_cache_handle = 0xffff; |
| 286 | t->processor_family2 = t->processor_family; |
| 287 | |
| 288 | len = t->length + smbios_string_table_len(t->eos); |
| 289 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 290 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 291 | |
| 292 | return len; |
| 293 | } |
| 294 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 295 | static int smbios_write_type32(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 296 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 297 | struct smbios_type32 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 298 | int len = sizeof(struct smbios_type32); |
| 299 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 300 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 301 | memset(t, 0, sizeof(struct smbios_type32)); |
| 302 | fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle); |
| 303 | |
| 304 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 305 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 306 | |
| 307 | return len; |
| 308 | } |
| 309 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 310 | static int smbios_write_type127(ulong *current, int handle, ofnode node) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 311 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 312 | struct smbios_type127 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 313 | int len = sizeof(struct smbios_type127); |
| 314 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 315 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 316 | memset(t, 0, sizeof(struct smbios_type127)); |
| 317 | fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle); |
| 318 | |
| 319 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 320 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 321 | |
| 322 | return len; |
| 323 | } |
| 324 | |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 325 | static struct smbios_write_method smbios_write_funcs[] = { |
| 326 | { smbios_write_type0, }, |
| 327 | { smbios_write_type1, "system", }, |
| 328 | { smbios_write_type2, "baseboard", }, |
| 329 | { smbios_write_type3, "chassis", }, |
| 330 | { smbios_write_type4, }, |
| 331 | { smbios_write_type32, }, |
| 332 | { smbios_write_type127 }, |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 333 | }; |
| 334 | |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 335 | ulong write_smbios_table(ulong addr) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 336 | { |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 337 | ofnode parent_node = ofnode_null(); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 338 | struct smbios_entry *se; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 339 | struct udevice *dev; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 340 | ulong table_addr; |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 341 | ulong tables; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 342 | int len = 0; |
| 343 | int max_struct_size = 0; |
| 344 | int handle = 0; |
| 345 | char *istart; |
| 346 | int isize; |
| 347 | int i; |
| 348 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 349 | if (IS_ENABLED(CONFIG_OF_CONTROL)) { |
| 350 | uclass_first_device(UCLASS_SYSINFO, &dev); |
| 351 | if (dev) |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 352 | parent_node = dev_read_subnode(dev, "smbios"); |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 355 | /* 16 byte align the table address */ |
| 356 | addr = ALIGN(addr, 16); |
| 357 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 358 | se = map_sysmem(addr, sizeof(struct smbios_entry)); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 359 | memset(se, 0, sizeof(struct smbios_entry)); |
| 360 | |
| 361 | addr += sizeof(struct smbios_entry); |
| 362 | addr = ALIGN(addr, 16); |
| 363 | tables = addr; |
| 364 | |
| 365 | /* populate minimum required tables */ |
| 366 | for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) { |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 367 | const struct smbios_write_method *method; |
| 368 | ofnode node = ofnode_null(); |
| 369 | int tmp; |
| 370 | |
| 371 | method = &smbios_write_funcs[i]; |
| 372 | if (IS_ENABLED(CONFIG_OF_CONTROL) && method->subnode_name) |
| 373 | node = ofnode_find_subnode(parent_node, |
| 374 | method->subnode_name); |
| 375 | tmp = method->write((ulong *)&addr, handle++, node); |
Christian Gmeiner | 5566caf | 2018-07-30 13:22:07 +0200 | [diff] [blame] | 376 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 377 | max_struct_size = max(max_struct_size, tmp); |
| 378 | len += tmp; |
| 379 | } |
| 380 | |
| 381 | memcpy(se->anchor, "_SM_", 4); |
| 382 | se->length = sizeof(struct smbios_entry); |
| 383 | se->major_ver = SMBIOS_MAJOR_VER; |
| 384 | se->minor_ver = SMBIOS_MINOR_VER; |
| 385 | se->max_struct_size = max_struct_size; |
| 386 | memcpy(se->intermediate_anchor, "_DMI_", 5); |
| 387 | se->struct_table_length = len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * We must use a pointer here so things work correctly on sandbox. The |
| 391 | * user of this table is not aware of the mapping of addresses to |
| 392 | * sandbox's DRAM buffer. |
| 393 | */ |
| 394 | table_addr = (ulong)map_sysmem(tables, 0); |
| 395 | if (sizeof(table_addr) > sizeof(u32) && table_addr > (ulong)UINT_MAX) { |
| 396 | /* |
| 397 | * We need to put this >32-bit pointer into the table but the |
| 398 | * field is only 32 bits wide. |
| 399 | */ |
| 400 | printf("WARNING: SMBIOS table_address overflow %llx\n", |
| 401 | (unsigned long long)table_addr); |
| 402 | table_addr = 0; |
| 403 | } |
| 404 | se->struct_table_address = table_addr; |
| 405 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 406 | se->struct_count = handle; |
| 407 | |
| 408 | /* calculate checksums */ |
| 409 | istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET; |
| 410 | isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET; |
| 411 | se->intermediate_checksum = table_compute_checksum(istart, isize); |
| 412 | se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry)); |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 413 | unmap_sysmem(se); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 414 | |
| 415 | return addr; |
| 416 | } |