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 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
Pali Rohár | ebe9fd8 | 2021-04-22 18:09:57 +0200 | [diff] [blame] | 10 | #include <linux/stringify.h> |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 11 | #include <linux/string.h> |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 12 | #include <mapmem.h> |
Alexander Graf | fb22808 | 2016-08-19 01:23:23 +0200 | [diff] [blame] | 13 | #include <smbios.h> |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 14 | #include <sysinfo.h> |
Alexander Graf | fb22808 | 2016-08-19 01:23:23 +0200 | [diff] [blame] | 15 | #include <tables_csum.h> |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 16 | #include <version.h> |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 17 | #include <malloc.h> |
| 18 | #include <dm/ofnode.h> |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 19 | #ifdef CONFIG_CPU |
| 20 | #include <cpu.h> |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 21 | #include <dm/uclass-internal.h> |
| 22 | #endif |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 23 | |
Pali Rohár | ebe9fd8 | 2021-04-22 18:09:57 +0200 | [diff] [blame] | 24 | /* Safeguard for checking that U_BOOT_VERSION_NUM macros are compatible with U_BOOT_DMI */ |
| 25 | #if U_BOOT_VERSION_NUM < 2000 || U_BOOT_VERSION_NUM > 2099 || \ |
| 26 | U_BOOT_VERSION_NUM_PATCH < 1 || U_BOOT_VERSION_NUM_PATCH > 12 |
| 27 | #error U_BOOT_VERSION_NUM macros are not compatible with DMI, fix U_BOOT_DMI macros |
| 28 | #endif |
| 29 | |
| 30 | /* |
| 31 | * U_BOOT_DMI_DATE contains BIOS Release Date in format mm/dd/yyyy. |
| 32 | * BIOS Release Date is calculated from U-Boot version and fixed day 01. |
| 33 | * So for U-Boot version 2021.04 it is calculated as "04/01/2021". |
| 34 | * BIOS Release Date should contain date when code was released |
| 35 | * and not when it was built or compiled. |
| 36 | */ |
| 37 | #if U_BOOT_VERSION_NUM_PATCH < 10 |
| 38 | #define U_BOOT_DMI_MONTH "0" __stringify(U_BOOT_VERSION_NUM_PATCH) |
| 39 | #else |
| 40 | #define U_BOOT_DMI_MONTH __stringify(U_BOOT_VERSION_NUM_PATCH) |
| 41 | #endif |
| 42 | #define U_BOOT_DMI_DAY "01" |
| 43 | #define U_BOOT_DMI_YEAR __stringify(U_BOOT_VERSION_NUM) |
| 44 | #define U_BOOT_DMI_DATE U_BOOT_DMI_MONTH "/" U_BOOT_DMI_DAY "/" U_BOOT_DMI_YEAR |
| 45 | |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 46 | DECLARE_GLOBAL_DATA_PTR; |
| 47 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 48 | /** |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 49 | * struct map_sysinfo - Mapping of sysinfo strings to DT |
| 50 | * |
| 51 | * @sysinfo_str: sysinfo string |
| 52 | * @dt_str: DT string |
| 53 | * @max: Max index of the tokenized string to pick. Counting starts from 0 |
| 54 | * |
| 55 | */ |
| 56 | struct map_sysinfo { |
| 57 | const char *sysinfo_str; |
| 58 | const char *dt_str; |
| 59 | int max; |
| 60 | }; |
| 61 | |
| 62 | static const struct map_sysinfo sysinfo_to_dt[] = { |
| 63 | { .sysinfo_str = "product", .dt_str = "model", 2 }, |
| 64 | { .sysinfo_str = "manufacturer", .dt_str = "compatible", 1 }, |
| 65 | }; |
| 66 | |
| 67 | /** |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 68 | * struct smbios_ctx - context for writing SMBIOS tables |
| 69 | * |
| 70 | * @node: node containing the information to write (ofnode_null() if none) |
| 71 | * @dev: sysinfo device to use (NULL if none) |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 72 | * @eos: end-of-string pointer for the table being processed. This is set |
| 73 | * up when we start processing a table |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 74 | * @next_ptr: pointer to the start of the next string to be added. When the |
| 75 | * table is nopt empty, this points to the byte after the \0 of the |
| 76 | * previous string. |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 77 | * @last_str: points to the last string that was written to the table, or NULL |
| 78 | * if none |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 79 | */ |
| 80 | struct smbios_ctx { |
| 81 | ofnode node; |
| 82 | struct udevice *dev; |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 83 | char *eos; |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 84 | char *next_ptr; |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 85 | char *last_str; |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /** |
Simon Glass | 099d3ae | 2021-02-04 21:17:14 -0700 | [diff] [blame] | 89 | * Function prototype to write a specific type of SMBIOS structure |
| 90 | * |
| 91 | * @addr: start address to write the structure |
| 92 | * @handle: the structure's handle, a unique 16-bit number |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 93 | * @ctx: context for writing the tables |
Heinrich Schuchardt | 9809bcc | 2021-06-10 12:13:52 +0200 | [diff] [blame] | 94 | * Return: size of the structure |
Simon Glass | 099d3ae | 2021-02-04 21:17:14 -0700 | [diff] [blame] | 95 | */ |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 96 | typedef int (*smbios_write_type)(ulong *addr, int handle, |
| 97 | struct smbios_ctx *ctx); |
Simon Glass | 099d3ae | 2021-02-04 21:17:14 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 100 | * struct smbios_write_method - Information about a table-writing function |
| 101 | * |
| 102 | * @write: Function to call |
| 103 | * @subnode_name: Name of subnode which has the information for this function, |
| 104 | * NULL if none |
| 105 | */ |
| 106 | struct smbios_write_method { |
| 107 | smbios_write_type write; |
| 108 | const char *subnode_name; |
| 109 | }; |
| 110 | |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 111 | static const struct map_sysinfo *convert_sysinfo_to_dt(const char *sysinfo_str) |
| 112 | { |
| 113 | int i; |
| 114 | |
| 115 | for (i = 0; i < ARRAY_SIZE(sysinfo_to_dt); i++) { |
| 116 | if (!strcmp(sysinfo_str, sysinfo_to_dt[i].sysinfo_str)) |
| 117 | return &sysinfo_to_dt[i]; |
| 118 | } |
| 119 | |
| 120 | return NULL; |
| 121 | } |
| 122 | |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 123 | /** |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 124 | * smbios_add_string() - add a string to the string area |
| 125 | * |
| 126 | * This adds a string to the string area which is appended directly after |
| 127 | * the formatted portion of an SMBIOS structure. |
| 128 | * |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 129 | * @ctx: SMBIOS context |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 130 | * @str: string to add |
Heinrich Schuchardt | 9809bcc | 2021-06-10 12:13:52 +0200 | [diff] [blame] | 131 | * Return: string number in the string area (1 or more) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 132 | */ |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 133 | static int smbios_add_string(struct smbios_ctx *ctx, const char *str) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 134 | { |
| 135 | int i = 1; |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 136 | char *p = ctx->eos; |
| 137 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 138 | for (;;) { |
| 139 | if (!*p) { |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 140 | ctx->last_str = p; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 141 | strcpy(p, str); |
| 142 | p += strlen(str); |
| 143 | *p++ = '\0'; |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 144 | ctx->next_ptr = p; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 145 | *p++ = '\0'; |
| 146 | |
| 147 | return i; |
| 148 | } |
| 149 | |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 150 | if (!strcmp(p, str)) { |
| 151 | ctx->last_str = p; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 152 | return i; |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 153 | } |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 154 | |
| 155 | p += strlen(p) + 1; |
| 156 | i++; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 161 | * get_str_from_dt - Get a substring from a DT property. |
| 162 | * After finding the property in the DT, the function |
| 163 | * will parse comma-separated values and return the value. |
| 164 | * If nprop->max exceeds the number of comma-separated |
| 165 | * elements, the last non NULL value will be returned. |
| 166 | * Counting starts from zero. |
| 167 | * |
| 168 | * @nprop: sysinfo property to use |
| 169 | * @str: pointer to fill with data |
| 170 | * @size: str buffer length |
| 171 | */ |
| 172 | static |
| 173 | void get_str_from_dt(const struct map_sysinfo *nprop, char *str, size_t size) |
| 174 | { |
| 175 | const char *dt_str; |
| 176 | int cnt = 0; |
| 177 | char *token; |
| 178 | |
| 179 | memset(str, 0, size); |
| 180 | if (!nprop || !nprop->max) |
| 181 | return; |
| 182 | |
| 183 | dt_str = ofnode_read_string(ofnode_root(), nprop->dt_str); |
| 184 | if (!dt_str) |
| 185 | return; |
| 186 | |
| 187 | memcpy(str, dt_str, size); |
| 188 | token = strtok(str, ","); |
| 189 | while (token && cnt < nprop->max) { |
| 190 | strlcpy(str, token, strlen(token) + 1); |
| 191 | token = strtok(NULL, ","); |
| 192 | cnt++; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /** |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 197 | * smbios_add_prop_si() - Add a property from the devicetree or sysinfo |
| 198 | * |
| 199 | * Sysinfo is used if available, with a fallback to devicetree |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 200 | * |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 201 | * @ctx: context for writing the tables |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 202 | * @prop: property to write |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 203 | * @dval: Default value to use if the string is not found or is empty |
Heinrich Schuchardt | 9809bcc | 2021-06-10 12:13:52 +0200 | [diff] [blame] | 204 | * Return: 0 if not found, else SMBIOS string number (1 or more) |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 205 | */ |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 206 | static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop, |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 207 | int sysinfo_id, const char *dval) |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 208 | { |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 209 | int ret; |
| 210 | |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 211 | if (!dval || !*dval) |
| 212 | dval = "Unknown"; |
| 213 | |
| 214 | if (!prop) |
| 215 | return smbios_add_string(ctx, dval); |
| 216 | |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 217 | if (sysinfo_id && ctx->dev) { |
| 218 | char val[SMBIOS_STR_MAX]; |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 219 | |
| 220 | ret = sysinfo_get_str(ctx->dev, sysinfo_id, sizeof(val), val); |
| 221 | if (!ret) |
| 222 | return smbios_add_string(ctx, val); |
| 223 | } |
Simon Glass | 95f4708 | 2020-11-05 06:32:18 -0700 | [diff] [blame] | 224 | if (IS_ENABLED(CONFIG_OF_CONTROL)) { |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 225 | const char *str = NULL; |
| 226 | char str_dt[128] = { 0 }; |
| 227 | /* |
| 228 | * If the node is not valid fallback and try the entire DT |
| 229 | * so we can at least fill in manufacturer and board type |
| 230 | */ |
| 231 | if (ofnode_valid(ctx->node)) { |
| 232 | str = ofnode_read_string(ctx->node, prop); |
| 233 | } else { |
| 234 | const struct map_sysinfo *nprop; |
Simon Glass | 95f4708 | 2020-11-05 06:32:18 -0700 | [diff] [blame] | 235 | |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 236 | nprop = convert_sysinfo_to_dt(prop); |
| 237 | get_str_from_dt(nprop, str_dt, sizeof(str_dt)); |
| 238 | str = (const char *)str_dt; |
| 239 | } |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 240 | |
Ilias Apalodimas | ada83d9 | 2023-12-07 11:18:50 +0200 | [diff] [blame] | 241 | ret = smbios_add_string(ctx, str && *str ? str : dval); |
| 242 | return ret; |
Simon Glass | 95f4708 | 2020-11-05 06:32:18 -0700 | [diff] [blame] | 243 | } |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 248 | /** |
| 249 | * smbios_add_prop() - Add a property from the devicetree |
| 250 | * |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 251 | * @prop: property to write. The default string will be written if |
| 252 | * prop is NULL |
| 253 | * @dval: Default value to use if the string is not found or is empty |
Heinrich Schuchardt | 9809bcc | 2021-06-10 12:13:52 +0200 | [diff] [blame] | 254 | * Return: 0 if not found, else SMBIOS string number (1 or more) |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 255 | */ |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 256 | static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop, |
| 257 | const char *dval) |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 258 | { |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 259 | return smbios_add_prop_si(ctx, prop, SYSINFO_ID_NONE, dval); |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 262 | static void smbios_set_eos(struct smbios_ctx *ctx, char *eos) |
| 263 | { |
| 264 | ctx->eos = eos; |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 265 | ctx->next_ptr = eos; |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 266 | ctx->last_str = NULL; |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 269 | int smbios_update_version(const char *version) |
| 270 | { |
| 271 | char *ptr = gd->smbios_version; |
| 272 | uint old_len, len; |
| 273 | |
| 274 | if (!ptr) |
| 275 | return log_ret(-ENOENT); |
| 276 | |
| 277 | /* |
| 278 | * This string is supposed to have at least enough bytes and is |
| 279 | * padded with spaces. Update it, taking care not to move the |
| 280 | * \0 terminator, so that other strings in the string table |
| 281 | * are not disturbed. See smbios_add_string() |
| 282 | */ |
| 283 | old_len = strnlen(ptr, SMBIOS_STR_MAX); |
| 284 | len = strnlen(version, SMBIOS_STR_MAX); |
| 285 | if (len > old_len) |
| 286 | return log_ret(-ENOSPC); |
| 287 | |
| 288 | log_debug("Replacing SMBIOS type 0 version string '%s'\n", ptr); |
| 289 | memcpy(ptr, version, len); |
| 290 | #ifdef LOG_DEBUG |
| 291 | print_buffer((ulong)ptr, ptr, 1, old_len + 1, 0); |
| 292 | #endif |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 297 | /** |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 298 | * smbios_string_table_len() - compute the string area size |
| 299 | * |
| 300 | * This computes the size of the string area including the string terminator. |
| 301 | * |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 302 | * @ctx: SMBIOS context |
Heinrich Schuchardt | 9809bcc | 2021-06-10 12:13:52 +0200 | [diff] [blame] | 303 | * Return: string area size |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 304 | */ |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 305 | static int smbios_string_table_len(const struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 306 | { |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 307 | /* Allow for the final \0 after all strings */ |
| 308 | return (ctx->next_ptr + 1) - ctx->eos; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 311 | static int smbios_write_type0(ulong *current, int handle, |
| 312 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 313 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 314 | struct smbios_type0 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 315 | int len = sizeof(struct smbios_type0); |
| 316 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 317 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 318 | memset(t, 0, sizeof(struct smbios_type0)); |
| 319 | fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle); |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 320 | smbios_set_eos(ctx, t->eos); |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 321 | t->vendor = smbios_add_prop(ctx, NULL, "U-Boot"); |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 322 | |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 323 | t->bios_ver = smbios_add_prop(ctx, "version", PLAIN_VERSION); |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 324 | if (t->bios_ver) |
| 325 | gd->smbios_version = ctx->last_str; |
| 326 | log_debug("smbios_version = %p: '%s'\n", gd->smbios_version, |
| 327 | gd->smbios_version); |
| 328 | #ifdef LOG_DEBUG |
| 329 | print_buffer((ulong)gd->smbios_version, gd->smbios_version, |
| 330 | 1, strlen(gd->smbios_version) + 1, 0); |
| 331 | #endif |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 332 | t->bios_release_date = smbios_add_prop(ctx, NULL, U_BOOT_DMI_DATE); |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 333 | #ifdef CONFIG_ROM_SIZE |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 334 | t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 335 | #endif |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 336 | t->bios_characteristics = BIOS_CHARACTERISTICS_PCI_SUPPORTED | |
| 337 | BIOS_CHARACTERISTICS_SELECTABLE_BOOT | |
| 338 | BIOS_CHARACTERISTICS_UPGRADEABLE; |
| 339 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
| 340 | t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI; |
| 341 | #endif |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 342 | #ifdef CONFIG_EFI_LOADER |
Ilias Apalodimas | 15578bc | 2021-06-09 18:14:47 +0300 | [diff] [blame] | 343 | t->bios_characteristics_ext2 |= BIOS_CHARACTERISTICS_EXT2_UEFI; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 344 | #endif |
Ilias Apalodimas | 15578bc | 2021-06-09 18:14:47 +0300 | [diff] [blame] | 345 | t->bios_characteristics_ext2 |= BIOS_CHARACTERISTICS_EXT2_TARGET; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 346 | |
Simon Glass | d7d1682 | 2021-02-04 21:17:16 -0700 | [diff] [blame] | 347 | /* bios_major_release has only one byte, so drop century */ |
| 348 | t->bios_major_release = U_BOOT_VERSION_NUM % 100; |
| 349 | t->bios_minor_release = U_BOOT_VERSION_NUM_PATCH; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 350 | t->ec_major_release = 0xff; |
| 351 | t->ec_minor_release = 0xff; |
| 352 | |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 353 | len = t->length + smbios_string_table_len(ctx); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 354 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 355 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 356 | |
| 357 | return len; |
| 358 | } |
| 359 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 360 | static int smbios_write_type1(ulong *current, int handle, |
| 361 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 362 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 363 | struct smbios_type1 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 364 | int len = sizeof(struct smbios_type1); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 365 | char *serial_str = env_get("serial#"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 366 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 367 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 368 | memset(t, 0, sizeof(struct smbios_type1)); |
| 369 | fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 370 | smbios_set_eos(ctx, t->eos); |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 371 | t->manufacturer = smbios_add_prop(ctx, "manufacturer", "Unknown"); |
| 372 | t->product_name = smbios_add_prop(ctx, "product", "Unknown"); |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 373 | t->version = smbios_add_prop_si(ctx, "version", |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 374 | SYSINFO_ID_SMBIOS_SYSTEM_VERSION, |
| 375 | "Unknown"); |
Alexander Graf | 9a3e3e2 | 2016-08-19 01:23:31 +0200 | [diff] [blame] | 376 | if (serial_str) { |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 377 | t->serial_number = smbios_add_prop(ctx, NULL, serial_str); |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 378 | strncpy((char *)t->uuid, serial_str, sizeof(t->uuid)); |
| 379 | } else { |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 380 | t->serial_number = smbios_add_prop(ctx, "serial", "Unknown"); |
Alexander Graf | 9a3e3e2 | 2016-08-19 01:23:31 +0200 | [diff] [blame] | 381 | } |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 382 | t->sku_number = smbios_add_prop(ctx, "sku", "Unknown"); |
| 383 | t->family = smbios_add_prop(ctx, "family", "Unknown"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 384 | |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 385 | len = t->length + smbios_string_table_len(ctx); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 386 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 387 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 388 | |
| 389 | return len; |
| 390 | } |
| 391 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 392 | static int smbios_write_type2(ulong *current, int handle, |
| 393 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 394 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 395 | struct smbios_type2 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 396 | int len = sizeof(struct smbios_type2); |
| 397 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 398 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 399 | memset(t, 0, sizeof(struct smbios_type2)); |
| 400 | fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 401 | smbios_set_eos(ctx, t->eos); |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 402 | t->manufacturer = smbios_add_prop(ctx, "manufacturer", "Unknown"); |
| 403 | t->product_name = smbios_add_prop(ctx, "product", "Unknown"); |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 404 | t->version = smbios_add_prop_si(ctx, "version", |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 405 | SYSINFO_ID_SMBIOS_BASEBOARD_VERSION, |
| 406 | "Unknown"); |
| 407 | t->asset_tag_number = smbios_add_prop(ctx, "asset-tag", "Unknown"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 408 | t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING; |
| 409 | t->board_type = SMBIOS_BOARD_MOTHERBOARD; |
| 410 | |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 411 | len = t->length + smbios_string_table_len(ctx); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 412 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 413 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 414 | |
| 415 | return len; |
| 416 | } |
| 417 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 418 | static int smbios_write_type3(ulong *current, int handle, |
| 419 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 420 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 421 | struct smbios_type3 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 422 | int len = sizeof(struct smbios_type3); |
| 423 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 424 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 425 | memset(t, 0, sizeof(struct smbios_type3)); |
| 426 | fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 427 | smbios_set_eos(ctx, t->eos); |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 428 | t->manufacturer = smbios_add_prop(ctx, "manufacturer", "Unknown"); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 429 | t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP; |
| 430 | t->bootup_state = SMBIOS_STATE_SAFE; |
| 431 | t->power_supply_state = SMBIOS_STATE_SAFE; |
| 432 | t->thermal_state = SMBIOS_STATE_SAFE; |
| 433 | t->security_status = SMBIOS_SECURITY_NONE; |
| 434 | |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 435 | len = t->length + smbios_string_table_len(ctx); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 436 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 437 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 438 | |
| 439 | return len; |
| 440 | } |
| 441 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 442 | static void smbios_write_type4_dm(struct smbios_type4 *t, |
| 443 | struct smbios_ctx *ctx) |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 444 | { |
| 445 | u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN; |
| 446 | const char *vendor = "Unknown"; |
| 447 | const char *name = "Unknown"; |
| 448 | |
| 449 | #ifdef CONFIG_CPU |
| 450 | char processor_name[49]; |
| 451 | char vendor_name[49]; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 452 | struct udevice *cpu = NULL; |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 453 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 454 | uclass_find_first_device(UCLASS_CPU, &cpu); |
| 455 | if (cpu) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 456 | struct cpu_plat *plat = dev_get_parent_plat(cpu); |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 457 | |
| 458 | if (plat->family) |
| 459 | processor_family = plat->family; |
| 460 | t->processor_id[0] = plat->id[0]; |
| 461 | t->processor_id[1] = plat->id[1]; |
| 462 | |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 463 | if (!cpu_get_vendor(cpu, vendor_name, sizeof(vendor_name))) |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 464 | vendor = vendor_name; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 465 | if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name))) |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 466 | name = processor_name; |
| 467 | } |
| 468 | #endif |
| 469 | |
Heinrich Schuchardt | b5f9aef | 2023-12-28 08:30:23 +0100 | [diff] [blame] | 470 | t->processor_family = 0xfe; |
| 471 | t->processor_family2 = processor_family; |
Ilias Apalodimas | 07f3eba | 2023-12-07 11:18:49 +0200 | [diff] [blame] | 472 | t->processor_manufacturer = smbios_add_prop(ctx, NULL, vendor); |
| 473 | t->processor_version = smbios_add_prop(ctx, NULL, name); |
Alexander Graf | e44b3c0 | 2016-08-19 01:23:28 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 476 | static int smbios_write_type4(ulong *current, int handle, |
| 477 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 478 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 479 | struct smbios_type4 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 480 | int len = sizeof(struct smbios_type4); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 481 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 482 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 483 | memset(t, 0, sizeof(struct smbios_type4)); |
| 484 | fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 485 | smbios_set_eos(ctx, t->eos); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 486 | t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 487 | smbios_write_type4_dm(t, ctx); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 488 | t->status = SMBIOS_PROCESSOR_STATUS_ENABLED; |
| 489 | t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE; |
| 490 | t->l1_cache_handle = 0xffff; |
| 491 | t->l2_cache_handle = 0xffff; |
| 492 | t->l3_cache_handle = 0xffff; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 493 | |
Simon Glass | 721b466 | 2021-02-04 21:17:19 -0700 | [diff] [blame] | 494 | len = t->length + smbios_string_table_len(ctx); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 495 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 496 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 497 | |
| 498 | return len; |
| 499 | } |
| 500 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 501 | static int smbios_write_type32(ulong *current, int handle, |
| 502 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 503 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 504 | struct smbios_type32 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 505 | int len = sizeof(struct smbios_type32); |
| 506 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 507 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 508 | memset(t, 0, sizeof(struct smbios_type32)); |
| 509 | fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle); |
Simon Glass | dff4e86 | 2021-02-04 21:17:18 -0700 | [diff] [blame] | 510 | smbios_set_eos(ctx, t->eos); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 511 | |
| 512 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 513 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 514 | |
| 515 | return len; |
| 516 | } |
| 517 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 518 | static int smbios_write_type127(ulong *current, int handle, |
| 519 | struct smbios_ctx *ctx) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 520 | { |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 521 | struct smbios_type127 *t; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 522 | int len = sizeof(struct smbios_type127); |
| 523 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 524 | t = map_sysmem(*current, len); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 525 | memset(t, 0, sizeof(struct smbios_type127)); |
| 526 | fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle); |
| 527 | |
| 528 | *current += len; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 529 | unmap_sysmem(t); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 530 | |
| 531 | return len; |
| 532 | } |
| 533 | |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 534 | static struct smbios_write_method smbios_write_funcs[] = { |
Simon Glass | a05eb04 | 2021-02-04 21:17:20 -0700 | [diff] [blame] | 535 | { smbios_write_type0, "bios", }, |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 536 | { smbios_write_type1, "system", }, |
| 537 | { smbios_write_type2, "baseboard", }, |
| 538 | { smbios_write_type3, "chassis", }, |
| 539 | { smbios_write_type4, }, |
| 540 | { smbios_write_type32, }, |
| 541 | { smbios_write_type127 }, |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 542 | }; |
| 543 | |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 544 | ulong write_smbios_table(ulong addr) |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 545 | { |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 546 | ofnode parent_node = ofnode_null(); |
Simon Glass | 3905e92 | 2023-12-31 08:25:45 -0700 | [diff] [blame] | 547 | ulong table_addr, start_addr; |
Simon Glass | fc4b552 | 2023-12-31 08:25:51 -0700 | [diff] [blame] | 548 | struct smbios3_entry *se; |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 549 | struct smbios_ctx ctx; |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 550 | ulong tables; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 551 | int len = 0; |
| 552 | int max_struct_size = 0; |
| 553 | int handle = 0; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 554 | int i; |
| 555 | |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 556 | ctx.node = ofnode_null(); |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 557 | if (IS_ENABLED(CONFIG_OF_CONTROL)) { |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 558 | uclass_first_device(UCLASS_SYSINFO, &ctx.dev); |
| 559 | if (ctx.dev) |
| 560 | parent_node = dev_read_subnode(ctx.dev, "smbios"); |
| 561 | } else { |
| 562 | ctx.dev = NULL; |
Simon Glass | 0dd7ca2 | 2020-11-05 06:32:07 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Simon Glass | 3905e92 | 2023-12-31 08:25:45 -0700 | [diff] [blame] | 565 | start_addr = addr; |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 566 | |
Simon Glass | fc4b552 | 2023-12-31 08:25:51 -0700 | [diff] [blame] | 567 | /* move past the (so-far-unwritten) header to start writing structs */ |
| 568 | addr = ALIGN(addr + sizeof(struct smbios3_entry), 16); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 569 | tables = addr; |
| 570 | |
| 571 | /* populate minimum required tables */ |
| 572 | for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) { |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 573 | const struct smbios_write_method *method; |
Simon Glass | 6f3332a | 2020-11-05 06:32:08 -0700 | [diff] [blame] | 574 | int tmp; |
| 575 | |
| 576 | method = &smbios_write_funcs[i]; |
| 577 | if (IS_ENABLED(CONFIG_OF_CONTROL) && method->subnode_name) |
Simon Glass | 8e5ddb0 | 2021-02-04 21:17:17 -0700 | [diff] [blame] | 578 | ctx.node = ofnode_find_subnode(parent_node, |
| 579 | method->subnode_name); |
| 580 | tmp = method->write((ulong *)&addr, handle++, &ctx); |
Christian Gmeiner | 5566caf | 2018-07-30 13:22:07 +0200 | [diff] [blame] | 581 | |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 582 | max_struct_size = max(max_struct_size, tmp); |
| 583 | len += tmp; |
| 584 | } |
| 585 | |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 586 | /* |
| 587 | * We must use a pointer here so things work correctly on sandbox. The |
| 588 | * user of this table is not aware of the mapping of addresses to |
| 589 | * sandbox's DRAM buffer. |
| 590 | */ |
| 591 | table_addr = (ulong)map_sysmem(tables, 0); |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 592 | |
Simon Glass | fc4b552 | 2023-12-31 08:25:51 -0700 | [diff] [blame] | 593 | /* now go back and write the SMBIOS3 header */ |
| 594 | se = map_sysmem(start_addr, sizeof(struct smbios_entry)); |
| 595 | memset(se, '\0', sizeof(struct smbios_entry)); |
| 596 | memcpy(se->anchor, "_SM3_", 5); |
| 597 | se->length = sizeof(struct smbios3_entry); |
| 598 | se->major_ver = SMBIOS_MAJOR_VER; |
| 599 | se->minor_ver = SMBIOS_MINOR_VER; |
| 600 | se->doc_rev = 0; |
| 601 | se->entry_point_rev = 1; |
| 602 | se->max_struct_size = len; |
| 603 | se->struct_table_address = table_addr; |
| 604 | se->checksum = table_compute_checksum(se, sizeof(struct smbios3_entry)); |
| 605 | unmap_sysmem(se); |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 606 | |
| 607 | return addr; |
| 608 | } |