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