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