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