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