Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 2 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 3 | #include <assert.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 4 | #include <string.h> |
| 5 | #include <smbios.h> |
| 6 | #include <console/console.h> |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 7 | #include <version.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 8 | #include <device/device.h> |
Patrick Rudolph | ff251d2 | 2021-02-11 15:09:22 +0100 | [diff] [blame] | 9 | #include <device/dram/spd.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 10 | #include <arch/cpu.h> |
| 11 | #include <cpu/x86/name.h> |
Duncan Laurie | 472ec9c | 2012-06-23 16:13:42 -0700 | [diff] [blame] | 12 | #include <elog.h> |
Julius Werner | 9ff8f6f | 2015-02-23 14:31:09 -0800 | [diff] [blame] | 13 | #include <endian.h> |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 14 | #include <memory_info.h> |
| 15 | #include <spd.h> |
| 16 | #include <cbmem.h> |
Elyes HAOUAS | e2d152c | 2019-06-21 07:06:50 +0200 | [diff] [blame] | 17 | #include <commonlib/helpers.h> |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 18 | #include <device/pci_ids.h> |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 19 | #include <device/pci.h> |
Johnny Lin | c746a74 | 2020-06-03 11:44:22 +0800 | [diff] [blame] | 20 | #include <drivers/vpd/vpd.h> |
| 21 | #include <stdlib.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 22 | |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 23 | #define update_max(len, max_len, stmt) \ |
| 24 | do { \ |
| 25 | int tmp = stmt; \ |
| 26 | \ |
| 27 | max_len = MAX(max_len, tmp); \ |
| 28 | len += tmp; \ |
| 29 | } while (0) |
| 30 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 31 | static u8 smbios_checksum(u8 *p, u32 length) |
| 32 | { |
| 33 | u8 ret = 0; |
| 34 | while (length--) |
| 35 | ret += *p++; |
| 36 | return -ret; |
| 37 | } |
| 38 | |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 39 | int smbios_add_string(u8 *start, const char *str) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 40 | { |
| 41 | int i = 1; |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 42 | char *p = (char *)start; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 43 | |
Ben Gardner | 6b07cba | 2015-12-09 11:24:35 -0600 | [diff] [blame] | 44 | /* |
| 45 | * Return 0 as required for empty strings. |
| 46 | * See Section 6.1.3 "Text Strings" of the SMBIOS specification. |
| 47 | */ |
| 48 | if (*str == '\0') |
| 49 | return 0; |
| 50 | |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 51 | for (;;) { |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 52 | if (!*p) { |
| 53 | strcpy(p, str); |
| 54 | p += strlen(str); |
| 55 | *p++ = '\0'; |
| 56 | *p++ = '\0'; |
| 57 | return i; |
| 58 | } |
| 59 | |
| 60 | if (!strcmp(p, str)) |
| 61 | return i; |
| 62 | |
| 63 | p += strlen(p)+1; |
| 64 | i++; |
| 65 | } |
| 66 | } |
| 67 | |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 68 | int smbios_string_table_len(u8 *start) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 69 | { |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 70 | char *p = (char *)start; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 71 | int i, len = 0; |
| 72 | |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 73 | while (*p) { |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 74 | i = strlen(p) + 1; |
| 75 | p += i; |
| 76 | len += i; |
| 77 | } |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 78 | |
| 79 | if (!len) |
| 80 | return 2; |
| 81 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 82 | return len + 1; |
| 83 | } |
| 84 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 85 | int smbios_full_table_len(struct smbios_header *header, u8 *str_table_start) |
| 86 | { |
| 87 | return header->length + smbios_string_table_len(str_table_start); |
| 88 | } |
| 89 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 90 | void *smbios_carve_table(unsigned long start, u8 type, u8 length, u16 handle) |
| 91 | { |
| 92 | struct smbios_header *t = (struct smbios_header *)start; |
| 93 | |
| 94 | assert(length >= sizeof(*t)); |
| 95 | memset(t, 0, length); |
| 96 | t->type = type; |
| 97 | t->length = length - 2; |
| 98 | t->handle = handle; |
| 99 | return t; |
| 100 | } |
| 101 | |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 102 | static int smbios_cpu_vendor(u8 *start) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 103 | { |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 104 | if (cpu_have_cpuid()) { |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 105 | u32 tmp[4]; |
| 106 | const struct cpuid_result res = cpuid(0); |
| 107 | tmp[0] = res.ebx; |
| 108 | tmp[1] = res.edx; |
| 109 | tmp[2] = res.ecx; |
| 110 | tmp[3] = 0; |
| 111 | return smbios_add_string(start, (const char *)tmp); |
| 112 | } else { |
| 113 | return smbios_add_string(start, "Unknown"); |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 114 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 117 | static int smbios_processor_name(u8 *start) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 118 | { |
Nico Huber | aa9643e | 2017-06-20 14:49:04 +0200 | [diff] [blame] | 119 | u32 tmp[13]; |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 120 | const char *str = "Unknown Processor Name"; |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 121 | if (cpu_have_cpuid()) { |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 122 | int i; |
Felix Held | 73e9ac6 | 2023-02-20 17:46:41 +0100 | [diff] [blame] | 123 | struct cpuid_result res; |
| 124 | if (cpu_cpuid_extended_level() >= 0x80000004) { |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 125 | int j = 0; |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 126 | for (i = 0; i < 3; i++) { |
| 127 | res = cpuid(0x80000002 + i); |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 128 | tmp[j++] = res.eax; |
| 129 | tmp[j++] = res.ebx; |
| 130 | tmp[j++] = res.ecx; |
| 131 | tmp[j++] = res.edx; |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 132 | } |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 133 | tmp[12] = 0; |
| 134 | str = (const char *)tmp; |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 135 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 136 | } |
Ryan Salsamendi | 1b5eda0 | 2017-06-11 18:50:32 -0700 | [diff] [blame] | 137 | return smbios_add_string(start, str); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Angel Pons | 9630ced | 2020-07-29 18:29:28 +0200 | [diff] [blame] | 140 | /* this function will fill the corresponding manufacturer */ |
| 141 | void smbios_fill_dimm_manufacturer_from_id(uint16_t mod_id, struct smbios_type17 *t) |
| 142 | { |
Patrick Rudolph | ff251d2 | 2021-02-11 15:09:22 +0100 | [diff] [blame] | 143 | const char *const manufacturer = spd_manufacturer_name(mod_id); |
Angel Pons | 9630ced | 2020-07-29 18:29:28 +0200 | [diff] [blame] | 144 | |
| 145 | if (manufacturer) { |
| 146 | t->manufacturer = smbios_add_string(t->eos, manufacturer); |
| 147 | } else { |
| 148 | char string_buffer[256]; |
| 149 | |
| 150 | snprintf(string_buffer, sizeof(string_buffer), "Unknown (%x)", mod_id); |
| 151 | t->manufacturer = smbios_add_string(t->eos, string_buffer); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 155 | static void trim_trailing_whitespace(char *buffer, size_t buffer_size) |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 156 | { |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 157 | size_t len = strnlen(buffer, buffer_size); |
| 158 | |
| 159 | if (len == 0) |
| 160 | return; |
| 161 | |
| 162 | for (char *p = buffer + len - 1; p >= buffer; --p) { |
| 163 | if (*p == ' ') |
| 164 | *p = 0; |
| 165 | else |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** This function will fill the corresponding part number */ |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 171 | static void smbios_fill_dimm_part_number(const char *part_number, struct smbios_type17 *t) |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 172 | { |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 173 | int invalid; |
| 174 | size_t i, len; |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 175 | char trimmed_part_number[DIMM_INFO_PART_NUMBER_SIZE]; |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 176 | |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 177 | strncpy(trimmed_part_number, part_number, sizeof(trimmed_part_number)); |
| 178 | trimmed_part_number[sizeof(trimmed_part_number) - 1] = '\0'; |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 179 | |
| 180 | /* |
| 181 | * SPD mandates that unused characters be represented with a ' '. |
| 182 | * We don't want to publish the whitespace in the SMBIOS tables. |
| 183 | */ |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 184 | trim_trailing_whitespace(trimmed_part_number, sizeof(trimmed_part_number)); |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 185 | |
| 186 | len = strlen(trimmed_part_number); |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 187 | |
| 188 | invalid = 0; /* assume valid */ |
Lijian Zhao | b1fc13a | 2018-03-26 18:27:02 -0700 | [diff] [blame] | 189 | for (i = 0; i < len; i++) { |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 190 | if (trimmed_part_number[i] < ' ') { |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 191 | invalid = 1; |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 192 | trimmed_part_number[i] = '*'; |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 195 | |
Lijian Zhao | b1fc13a | 2018-03-26 18:27:02 -0700 | [diff] [blame] | 196 | if (len == 0) { |
| 197 | /* Null String in Part Number will have "None" instead. */ |
| 198 | t->part_number = smbios_add_string(t->eos, "None"); |
| 199 | } else if (invalid) { |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 200 | char string_buffer[sizeof(trimmed_part_number) + 10]; |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 201 | |
| 202 | snprintf(string_buffer, sizeof(string_buffer), "Invalid (%s)", |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 203 | trimmed_part_number); |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 204 | t->part_number = smbios_add_string(t->eos, string_buffer); |
Raul E Rangel | 50021cd | 2018-03-20 12:40:55 -0600 | [diff] [blame] | 205 | } else { |
| 206 | t->part_number = smbios_add_string(t->eos, trimmed_part_number); |
| 207 | } |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Raul E Rangel | 99f54a6 | 2018-04-11 10:58:14 -0600 | [diff] [blame] | 210 | /* Encodes the SPD serial number into hex */ |
| 211 | static void smbios_fill_dimm_serial_number(const struct dimm_info *dimm, |
| 212 | struct smbios_type17 *t) |
| 213 | { |
| 214 | char serial[9]; |
| 215 | |
| 216 | snprintf(serial, sizeof(serial), "%02hhx%02hhx%02hhx%02hhx", |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 217 | dimm->serial[0], dimm->serial[1], dimm->serial[2], dimm->serial[3]); |
Raul E Rangel | 99f54a6 | 2018-04-11 10:58:14 -0600 | [diff] [blame] | 218 | |
| 219 | t->serial_number = smbios_add_string(t->eos, serial); |
| 220 | } |
| 221 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 222 | static int create_smbios_type17_for_dimm(struct dimm_info *dimm, |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 223 | unsigned long *current, int *handle, |
| 224 | int type16_handle) |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 225 | { |
Subrata Banik | 6de8b42 | 2021-10-26 20:46:21 +0530 | [diff] [blame] | 226 | struct spd_info info; |
| 227 | get_spd_info(dimm->ddr_type, dimm->mod_type, &info); |
| 228 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 229 | struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE, |
| 230 | sizeof(*t), *handle); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 231 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 232 | t->memory_type = dimm->ddr_type; |
Rob Barnes | 327f105 | 2020-09-01 10:26:57 -0600 | [diff] [blame] | 233 | if (dimm->configured_speed_mts != 0) |
| 234 | t->clock_speed = dimm->configured_speed_mts; |
| 235 | else |
| 236 | t->clock_speed = dimm->ddr_frequency; |
| 237 | if (dimm->max_speed_mts != 0) |
| 238 | t->speed = dimm->max_speed_mts; |
| 239 | else |
| 240 | t->speed = dimm->ddr_frequency; |
Julien Viard de Galbert | 9989171 | 2018-01-24 11:04:46 +0100 | [diff] [blame] | 241 | if (dimm->dimm_size < 0x7fff) { |
| 242 | t->size = dimm->dimm_size; |
| 243 | } else { |
| 244 | t->size = 0x7fff; |
| 245 | t->extended_size = dimm->dimm_size & 0x7fffffff; |
| 246 | } |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 247 | t->data_width = 8 * (1 << (dimm->bus_width & 0x7)); |
| 248 | t->total_width = t->data_width + 8 * ((dimm->bus_width & 0x18) >> 3); |
Subrata Banik | 6de8b42 | 2021-10-26 20:46:21 +0530 | [diff] [blame] | 249 | t->form_factor = info.form_factor; |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 250 | |
Timothy Pearson | 4785f2a | 2015-03-27 23:05:36 -0500 | [diff] [blame] | 251 | smbios_fill_dimm_manufacturer_from_id(dimm->mod_id, t); |
Raul E Rangel | 99f54a6 | 2018-04-11 10:58:14 -0600 | [diff] [blame] | 252 | smbios_fill_dimm_serial_number(dimm, t); |
Tim Chu | 31b4209 | 2020-12-23 19:15:21 -0800 | [diff] [blame] | 253 | smbios_fill_dimm_asset_tag(dimm, t); |
Lijian Zhao | 10ea93c | 2019-04-11 00:45:10 -0700 | [diff] [blame] | 254 | smbios_fill_dimm_locator(dimm, t); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 255 | |
| 256 | /* put '\0' in the end of data */ |
Richard Spiegel | bd65480 | 2018-02-22 10:03:39 -0700 | [diff] [blame] | 257 | dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0'; |
| 258 | smbios_fill_dimm_part_number((char *)dimm->module_part_number, t); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 259 | |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 260 | /* Voltage Levels */ |
| 261 | t->configured_voltage = dimm->vdd_voltage; |
| 262 | t->minimum_voltage = dimm->vdd_voltage; |
| 263 | t->maximum_voltage = dimm->vdd_voltage; |
| 264 | |
Tim Chu | 0c094ae | 2021-01-12 01:44:37 -0800 | [diff] [blame] | 265 | /* Fill in type detail */ |
Subrata Banik | 6de8b42 | 2021-10-26 20:46:21 +0530 | [diff] [blame] | 266 | t->type_detail = info.type_detail; |
| 267 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 268 | /* Synchronous = 1 */ |
Tim Chu | 0c094ae | 2021-01-12 01:44:37 -0800 | [diff] [blame] | 269 | t->type_detail |= MEMORY_TYPE_DETAIL_SYNCHRONOUS; |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 270 | /* no handle for error information */ |
| 271 | t->memory_error_information_handle = 0xFFFE; |
| 272 | t->attributes = dimm->rank_per_dimm; |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 273 | t->phys_memory_array_handle = type16_handle; |
| 274 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 275 | *handle += 1; |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 276 | return smbios_full_table_len(&t->header, t->eos); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Angel Pons | 2b48258 | 2022-05-03 18:12:18 +0200 | [diff] [blame] | 279 | static int create_smbios_type17_for_empty_slot(struct dimm_info *dimm, |
| 280 | unsigned long *current, int *handle, |
| 281 | int type16_handle) |
| 282 | { |
| 283 | struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE, |
| 284 | sizeof(*t), *handle); |
| 285 | t->phys_memory_array_handle = type16_handle; |
| 286 | /* no handle for error information */ |
| 287 | t->memory_error_information_handle = 0xfffe; |
| 288 | t->total_width = 0xffff; /* Unknown */ |
| 289 | t->data_width = 0xffff; /* Unknown */ |
| 290 | t->form_factor = 0x2; /* Unknown */ |
| 291 | smbios_fill_dimm_locator(dimm, t); /* Device and Bank */ |
| 292 | t->memory_type = 0x2; /* Unknown */ |
| 293 | t->type_detail = 0x2; /* Unknown */ |
| 294 | |
| 295 | *handle += 1; |
| 296 | return smbios_full_table_len(&t->header, t->eos); |
| 297 | } |
| 298 | |
Johnny Lin | c746a74 | 2020-06-03 11:44:22 +0800 | [diff] [blame] | 299 | #define VERSION_VPD "firmware_version" |
| 300 | static const char *vpd_get_bios_version(void) |
| 301 | { |
| 302 | int size; |
| 303 | const char *s; |
| 304 | char *version; |
| 305 | |
| 306 | s = vpd_find(VERSION_VPD, &size, VPD_RO); |
| 307 | if (!s) { |
| 308 | printk(BIOS_ERR, "Find version from VPD %s failed\n", VERSION_VPD); |
| 309 | return NULL; |
| 310 | } |
| 311 | |
| 312 | version = malloc(size + 1); |
| 313 | if (!version) { |
| 314 | printk(BIOS_ERR, "Failed to malloc %d bytes for VPD version\n", size + 1); |
| 315 | return NULL; |
| 316 | } |
| 317 | memcpy(version, s, size); |
| 318 | version[size] = '\0'; |
| 319 | printk(BIOS_DEBUG, "Firmware version %s from VPD %s\n", version, VERSION_VPD); |
| 320 | return version; |
| 321 | } |
| 322 | |
| 323 | static const char *get_bios_version(void) |
| 324 | { |
| 325 | const char *s; |
| 326 | |
| 327 | #define SPACES \ |
| 328 | " " |
| 329 | |
| 330 | if (CONFIG(CHROMEOS)) |
| 331 | return SPACES; |
| 332 | |
| 333 | if (CONFIG(VPD_SMBIOS_VERSION)) { |
| 334 | s = vpd_get_bios_version(); |
| 335 | if (s != NULL) |
| 336 | return s; |
| 337 | } |
| 338 | |
| 339 | s = smbios_mainboard_bios_version(); |
| 340 | if (s != NULL) |
| 341 | return s; |
| 342 | |
| 343 | if (strlen(CONFIG_LOCALVERSION) != 0) { |
| 344 | printk(BIOS_DEBUG, "BIOS version set to CONFIG_LOCALVERSION: '%s'\n", |
| 345 | CONFIG_LOCALVERSION); |
| 346 | return CONFIG_LOCALVERSION; |
| 347 | } |
| 348 | |
| 349 | printk(BIOS_DEBUG, "SMBIOS firmware version is set to coreboot_version: '%s'\n", |
| 350 | coreboot_version); |
| 351 | return coreboot_version; |
| 352 | } |
| 353 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 354 | static int smbios_write_type0(unsigned long *current, int handle) |
| 355 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 356 | struct smbios_type0 *t = smbios_carve_table(*current, SMBIOS_BIOS_INFORMATION, |
| 357 | sizeof(*t), handle); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 358 | |
| 359 | t->vendor = smbios_add_string(t->eos, "coreboot"); |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 360 | t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date); |
Christian Gmeiner | 5e272a4 | 2013-02-04 16:22:46 +0100 | [diff] [blame] | 361 | |
Kyösti Mälkki | 84d10cc | 2021-02-10 17:53:34 +0200 | [diff] [blame] | 362 | if (CONFIG(CHROMEOS_NVS)) { |
Kyösti Mälkki | 0fcbd3a | 2020-12-20 08:27:21 +0200 | [diff] [blame] | 363 | uintptr_t version_address = (uintptr_t)t->eos; |
| 364 | /* SMBIOS offsets start at 1 rather than 0 */ |
| 365 | version_address += (u32)smbios_string_table_len(t->eos) - 1; |
| 366 | smbios_type0_bios_version(version_address); |
| 367 | } |
Johnny Lin | c746a74 | 2020-06-03 11:44:22 +0800 | [diff] [blame] | 368 | t->bios_version = smbios_add_string(t->eos, get_bios_version()); |
Lee Leahy | 6735871 | 2016-06-08 12:47:07 -0700 | [diff] [blame] | 369 | uint32_t rom_size = CONFIG_ROM_SIZE; |
| 370 | rom_size = MIN(CONFIG_ROM_SIZE, 16 * MiB); |
| 371 | t->bios_rom_size = (rom_size / 65535) - 1; |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 372 | |
Fabio Aiuto | 0805c70 | 2022-08-19 17:25:25 +0200 | [diff] [blame] | 373 | if (CONFIG_ROM_SIZE >= 1 * GiB) |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 374 | t->extended_bios_rom_size = DIV_ROUND_UP(CONFIG_ROM_SIZE, GiB) | (1 << 14); |
Fabio Aiuto | 0805c70 | 2022-08-19 17:25:25 +0200 | [diff] [blame] | 375 | else |
Elyes HAOUAS | 358cbb3 | 2019-02-14 14:19:22 +0100 | [diff] [blame] | 376 | t->extended_bios_rom_size = DIV_ROUND_UP(CONFIG_ROM_SIZE, MiB); |
Elyes HAOUAS | 358cbb3 | 2019-02-14 14:19:22 +0100 | [diff] [blame] | 377 | |
Elyes HAOUAS | 94ad376 | 2019-02-15 17:39:56 +0100 | [diff] [blame] | 378 | t->system_bios_major_release = coreboot_major_revision; |
| 379 | t->system_bios_minor_release = coreboot_minor_revision; |
| 380 | |
Tim Chu | f2f53c4 | 2020-09-07 02:30:19 -0700 | [diff] [blame] | 381 | smbios_ec_revision(&t->ec_major_release, &t->ec_minor_release); |
| 382 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 383 | t->bios_characteristics = |
| 384 | BIOS_CHARACTERISTICS_PCI_SUPPORTED | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 385 | BIOS_CHARACTERISTICS_SELECTABLE_BOOT | |
| 386 | BIOS_CHARACTERISTICS_UPGRADEABLE; |
| 387 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 388 | if (CONFIG(CARDBUS_PLUGIN_SUPPORT)) |
Martin Roth | 898a775 | 2017-06-01 11:39:59 -0600 | [diff] [blame] | 389 | t->bios_characteristics |= BIOS_CHARACTERISTICS_PC_CARD; |
| 390 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 391 | if (CONFIG(HAVE_ACPI_TABLES)) |
Martin Roth | 898a775 | 2017-06-01 11:39:59 -0600 | [diff] [blame] | 392 | t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI; |
| 393 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 394 | t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET; |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 395 | const int len = smbios_full_table_len(&t->header, t->eos); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 396 | *current += len; |
| 397 | return len; |
| 398 | } |
| 399 | |
Elyes HAOUAS | 28fa33c | 2019-01-25 13:46:43 +0100 | [diff] [blame] | 400 | static int get_socket_type(void) |
| 401 | { |
| 402 | if (CONFIG(CPU_INTEL_SLOT_1)) |
Li, Jincheng | aa99012 | 2023-01-03 15:43:40 +0800 | [diff] [blame] | 403 | return PROCESSOR_UPGRADE_SLOT_1; |
Kyösti Mälkki | 7b73e852 | 2022-11-08 04:43:41 +0000 | [diff] [blame] | 404 | if (CONFIG(CPU_INTEL_SOCKET_MPGA604)) |
Li, Jincheng | aa99012 | 2023-01-03 15:43:40 +0800 | [diff] [blame] | 405 | return PROCESSOR_UPGRADE_SOCKET_MPGA604; |
Elyes HAOUAS | 28fa33c | 2019-01-25 13:46:43 +0100 | [diff] [blame] | 406 | if (CONFIG(CPU_INTEL_SOCKET_LGA775)) |
Li, Jincheng | aa99012 | 2023-01-03 15:43:40 +0800 | [diff] [blame] | 407 | return PROCESSOR_UPGRADE_SOCKET_LGA775; |
Zhixing Ma | 42bb7df | 2022-09-30 14:22:41 -0700 | [diff] [blame] | 408 | if (CONFIG(SOC_INTEL_ALDERLAKE)) |
Li, Jincheng | aa99012 | 2023-01-03 15:43:40 +0800 | [diff] [blame] | 409 | return PROCESSOR_UPGRADE_SOCKET_LGA1700; |
Jay Patel | b7da7d5 | 2023-03-13 11:29:59 -0700 | [diff] [blame^] | 410 | if (CONFIG(SOC_INTEL_METEORLAKE)) |
| 411 | return PROCESSOR_UPGRADE_OTHER; |
David Hendricks | 6041699 | 2023-01-28 15:35:37 -0800 | [diff] [blame] | 412 | if (CONFIG(SOC_INTEL_SKYLAKE_SP)) |
| 413 | return PROCESSOR_UPGRADE_SOCKET_LGA3647_1; |
| 414 | if (CONFIG(SOC_INTEL_COOPERLAKE_SP)) |
| 415 | return PROCESSOR_UPGRADE_SOCKET_LGA4189; |
Christian Walter | 55129b3 | 2022-09-08 13:17:50 +0200 | [diff] [blame] | 416 | if (CONFIG(SOC_INTEL_SAPPHIRERAPIDS_SP)) |
| 417 | return PROCESSOR_UPGRADE_SOCKET_LGA4677; |
Elyes HAOUAS | 28fa33c | 2019-01-25 13:46:43 +0100 | [diff] [blame] | 418 | |
Li, Jincheng | aa99012 | 2023-01-03 15:43:40 +0800 | [diff] [blame] | 419 | return PROCESSOR_UPGRADE_UNKNOWN; |
Elyes HAOUAS | 28fa33c | 2019-01-25 13:46:43 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 422 | unsigned int __weak smbios_processor_external_clock(void) |
| 423 | { |
| 424 | return 0; /* Unknown */ |
| 425 | } |
| 426 | |
| 427 | unsigned int __weak smbios_processor_characteristics(void) |
| 428 | { |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | unsigned int __weak smbios_processor_family(struct cpuid_result res) |
| 433 | { |
| 434 | return (res.eax > 0) ? 0x0c : 0x6; |
| 435 | } |
| 436 | |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 437 | unsigned int __weak smbios_cache_error_correction_type(u8 level) |
| 438 | { |
| 439 | return SMBIOS_CACHE_ERROR_CORRECTION_UNKNOWN; |
| 440 | } |
| 441 | |
| 442 | unsigned int __weak smbios_cache_sram_type(void) |
| 443 | { |
| 444 | return SMBIOS_CACHE_SRAM_TYPE_UNKNOWN; |
| 445 | } |
| 446 | |
| 447 | unsigned int __weak smbios_cache_conf_operation_mode(u8 level) |
| 448 | { |
| 449 | return SMBIOS_CACHE_OP_MODE_UNKNOWN; /* Unknown */ |
| 450 | } |
| 451 | |
Patrick Rudolph | b01ac7e | 2020-07-26 14:23:37 +0200 | [diff] [blame] | 452 | /* Returns the processor voltage in 100mV units */ |
| 453 | unsigned int __weak smbios_cpu_get_voltage(void) |
| 454 | { |
| 455 | return 0; /* Unknown */ |
| 456 | } |
| 457 | |
Subrata Banik | e2b5fee | 2021-07-23 21:02:45 +0530 | [diff] [blame] | 458 | static size_t get_number_of_caches(size_t max_logical_cpus_sharing_cache) |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 459 | { |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 460 | size_t number_of_cpus_per_package = 0; |
| 461 | size_t max_logical_cpus_per_package = 0; |
| 462 | struct cpuid_result res; |
| 463 | |
| 464 | if (!cpu_have_cpuid()) |
| 465 | return 1; |
| 466 | |
| 467 | res = cpuid(1); |
| 468 | |
| 469 | max_logical_cpus_per_package = (res.ebx >> 16) & 0xff; |
| 470 | |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 471 | /* Check if it's last level cache */ |
| 472 | if (max_logical_cpus_sharing_cache == max_logical_cpus_per_package) |
| 473 | return 1; |
| 474 | |
| 475 | if (cpuid_get_max_func() >= 0xb) { |
| 476 | res = cpuid_ext(0xb, 1); |
| 477 | number_of_cpus_per_package = res.ebx & 0xff; |
| 478 | } else { |
| 479 | number_of_cpus_per_package = max_logical_cpus_per_package; |
| 480 | } |
| 481 | |
| 482 | return number_of_cpus_per_package / max_logical_cpus_sharing_cache; |
| 483 | } |
| 484 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 485 | static int smbios_write_type1(unsigned long *current, int handle) |
| 486 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 487 | struct smbios_type1 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_INFORMATION, |
| 488 | sizeof(*t), handle); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 489 | |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 490 | t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer()); |
| 491 | t->product_name = smbios_add_string(t->eos, smbios_system_product_name()); |
| 492 | t->serial_number = smbios_add_string(t->eos, smbios_system_serial_number()); |
Tim Chu | 13ab1d7 | 2021-10-19 01:45:12 +0000 | [diff] [blame] | 493 | t->wakeup_type = smbios_system_wakeup_type(); |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 494 | t->sku = smbios_add_string(t->eos, smbios_system_sku()); |
| 495 | t->version = smbios_add_string(t->eos, smbios_system_version()); |
Marc Jones | f43ba9c | 2015-06-09 21:10:43 -0600 | [diff] [blame] | 496 | #ifdef CONFIG_MAINBOARD_FAMILY |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 497 | t->family = smbios_add_string(t->eos, CONFIG_MAINBOARD_FAMILY); |
Marc Jones | f43ba9c | 2015-06-09 21:10:43 -0600 | [diff] [blame] | 498 | #endif |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 499 | smbios_system_set_uuid(t->uuid); |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 500 | const int len = smbios_full_table_len(&t->header, t->eos); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 501 | *current += len; |
| 502 | return len; |
| 503 | } |
| 504 | |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 505 | static int smbios_write_type2(unsigned long *current, int handle, const int chassis_handle) |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 506 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 507 | struct smbios_type2 *t = smbios_carve_table(*current, SMBIOS_BOARD_INFORMATION, |
| 508 | sizeof(*t), handle); |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 509 | |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 510 | t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); |
| 511 | t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name()); |
| 512 | t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number()); |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 513 | t->version = smbios_add_string(t->eos, smbios_mainboard_version()); |
Julien Viard de Galbert | 9a31dfe | 2018-02-22 16:39:58 +0100 | [diff] [blame] | 514 | t->asset_tag = smbios_add_string(t->eos, smbios_mainboard_asset_tag()); |
| 515 | t->feature_flags = smbios_mainboard_feature_flags(); |
| 516 | t->location_in_chassis = smbios_add_string(t->eos, |
| 517 | smbios_mainboard_location_in_chassis()); |
| 518 | t->board_type = smbios_mainboard_board_type(); |
| 519 | t->chassis_handle = chassis_handle; |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 520 | const int len = smbios_full_table_len(&t->header, t->eos); |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 521 | *current += len; |
| 522 | return len; |
| 523 | } |
| 524 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 525 | static int smbios_write_type3(unsigned long *current, int handle) |
| 526 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 527 | struct smbios_type3 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_ENCLOSURE, |
| 528 | sizeof(*t), handle); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 529 | |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 530 | t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer()); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 531 | t->bootup_state = SMBIOS_STATE_SAFE; |
| 532 | t->power_supply_state = SMBIOS_STATE_SAFE; |
| 533 | t->thermal_state = SMBIOS_STATE_SAFE; |
Mathew King | a7d55cf | 2019-07-31 15:50:15 -0600 | [diff] [blame] | 534 | t->_type = smbios_mainboard_enclosure_type(); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 535 | t->security_status = SMBIOS_STATE_SAFE; |
JingleHsuWiwynn | 4330b96 | 2021-01-28 09:13:42 +0800 | [diff] [blame] | 536 | t->number_of_power_cords = smbios_chassis_power_cords(); |
Johnny Lin | d344054 | 2020-01-30 18:21:22 +0800 | [diff] [blame] | 537 | t->asset_tag_number = smbios_add_string(t->eos, smbios_mainboard_asset_tag()); |
| 538 | t->version = smbios_add_string(t->eos, smbios_chassis_version()); |
| 539 | t->serial_number = smbios_add_string(t->eos, smbios_chassis_serial_number()); |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 540 | const int len = smbios_full_table_len(&t->header, t->eos); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 541 | *current += len; |
| 542 | return len; |
| 543 | } |
| 544 | |
Arthur Heymans | 13c8dc5 | 2022-04-07 22:08:23 +0200 | [diff] [blame] | 545 | #define MAX_CPUS_ENABLED (CONFIG_MAX_CPUS > 0xff ? 0xff : CONFIG_MAX_CPUS) |
| 546 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 547 | static int smbios_write_type4(unsigned long *current, int handle) |
| 548 | { |
Patrick Rudolph | b01ac7e | 2020-07-26 14:23:37 +0200 | [diff] [blame] | 549 | unsigned int cpu_voltage; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 550 | struct cpuid_result res; |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 551 | uint16_t characteristics = 0; |
Tim Chu | 27bf0c8 | 2020-09-16 00:34:08 -0700 | [diff] [blame] | 552 | static unsigned int cnt = 0; |
| 553 | char buf[8]; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 554 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 555 | /* Provide sane defaults even for CPU without CPUID */ |
| 556 | res.eax = res.edx = 0; |
| 557 | res.ebx = 0x10000; |
| 558 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 559 | if (cpu_have_cpuid()) |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 560 | res = cpuid(1); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 561 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 562 | struct smbios_type4 *t = smbios_carve_table(*current, SMBIOS_PROCESSOR_INFORMATION, |
| 563 | sizeof(*t), handle); |
Tim Chu | 27bf0c8 | 2020-09-16 00:34:08 -0700 | [diff] [blame] | 564 | |
| 565 | snprintf(buf, sizeof(buf), "CPU%d", cnt++); |
| 566 | t->socket_designation = smbios_add_string(t->eos, buf); |
| 567 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 568 | t->processor_id[0] = res.eax; |
| 569 | t->processor_id[1] = res.edx; |
| 570 | t->processor_manufacturer = smbios_cpu_vendor(t->eos); |
| 571 | t->processor_version = smbios_processor_name(t->eos); |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 572 | t->processor_family = smbios_processor_family(res); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 573 | t->processor_type = 3; /* System Processor */ |
Andrey Petrov | 515ef38 | 2019-11-15 13:19:08 -0800 | [diff] [blame] | 574 | /* |
| 575 | * If CPUID leaf 11 is available, calculate "core count" by dividing |
| 576 | * SMT_ID (logical processors in a core) by Core_ID (number of cores). |
| 577 | * This seems to be the way to arrive to a number of cores mentioned on |
| 578 | * ark.intel.com. |
| 579 | */ |
| 580 | if (cpu_have_cpuid() && cpuid_get_max_func() >= 0xb) { |
| 581 | uint32_t leaf_b_cores = 0, leaf_b_threads = 0; |
| 582 | res = cpuid_ext(0xb, 1); |
| 583 | leaf_b_cores = res.ebx; |
| 584 | res = cpuid_ext(0xb, 0); |
| 585 | leaf_b_threads = res.ebx; |
| 586 | /* if hyperthreading is not available, pretend this is 1 */ |
Fabio Aiuto | 0805c70 | 2022-08-19 17:25:25 +0200 | [diff] [blame] | 587 | if (leaf_b_threads == 0) |
Andrey Petrov | 515ef38 | 2019-11-15 13:19:08 -0800 | [diff] [blame] | 588 | leaf_b_threads = 1; |
Fabio Aiuto | 0805c70 | 2022-08-19 17:25:25 +0200 | [diff] [blame] | 589 | |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 590 | t->core_count2 = leaf_b_cores / leaf_b_threads; |
| 591 | t->core_count = t->core_count2 > 0xff ? 0xff : t->core_count2; |
Francois Toguo | 597922e | 2019-03-27 18:13:07 -0700 | [diff] [blame] | 592 | t->thread_count2 = leaf_b_cores; |
| 593 | t->thread_count = t->thread_count2 > 0xff ? 0xff : t->thread_count2; |
Andrey Petrov | 515ef38 | 2019-11-15 13:19:08 -0800 | [diff] [blame] | 594 | } else { |
| 595 | t->core_count = (res.ebx >> 16) & 0xff; |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 596 | t->core_count2 = t->core_count; |
| 597 | t->thread_count2 = t->core_count2; |
Francois Toguo | 597922e | 2019-03-27 18:13:07 -0700 | [diff] [blame] | 598 | t->thread_count = t->thread_count2; |
Andrey Petrov | 515ef38 | 2019-11-15 13:19:08 -0800 | [diff] [blame] | 599 | } |
Andrey Petrov | 2e032f0 | 2019-10-23 15:31:51 -0700 | [diff] [blame] | 600 | /* Assume we enable all the cores always, capped only by MAX_CPUS */ |
Arthur Heymans | 13c8dc5 | 2022-04-07 22:08:23 +0200 | [diff] [blame] | 601 | t->core_enabled = MIN(t->core_count, MAX_CPUS_ENABLED); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 602 | t->core_enabled2 = MIN(t->core_count2, CONFIG_MAX_CPUS); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 603 | t->l1_cache_handle = 0xffff; |
| 604 | t->l2_cache_handle = 0xffff; |
| 605 | t->l3_cache_handle = 0xffff; |
Johnny Lin | d344054 | 2020-01-30 18:21:22 +0800 | [diff] [blame] | 606 | t->serial_number = smbios_add_string(t->eos, smbios_processor_serial_number()); |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 607 | t->status = SMBIOS_PROCESSOR_STATUS_CPU_ENABLED | SMBIOS_PROCESSOR_STATUS_POPULATED; |
Elyes HAOUAS | 28fa33c | 2019-01-25 13:46:43 +0100 | [diff] [blame] | 608 | t->processor_upgrade = get_socket_type(); |
Andrey Petrov | 2e032f0 | 2019-10-23 15:31:51 -0700 | [diff] [blame] | 609 | if (cpu_have_cpuid() && cpuid_get_max_func() >= 0x16) { |
Andrey Petrov | 2e032f0 | 2019-10-23 15:31:51 -0700 | [diff] [blame] | 610 | t->current_speed = cpuid_eax(0x16); /* base frequency */ |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 611 | t->external_clock = cpuid_ecx(0x16); |
Andrey Petrov | 2e032f0 | 2019-10-23 15:31:51 -0700 | [diff] [blame] | 612 | } else { |
Andrey Petrov | 2e032f0 | 2019-10-23 15:31:51 -0700 | [diff] [blame] | 613 | t->current_speed = smbios_cpu_get_current_speed_mhz(); |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 614 | t->external_clock = smbios_processor_external_clock(); |
Andrey Petrov | 2e032f0 | 2019-10-23 15:31:51 -0700 | [diff] [blame] | 615 | } |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 616 | |
Tim Chu | 40d4599 | 2020-12-14 21:44:40 -0800 | [diff] [blame] | 617 | /* This field identifies a capability for the system, not the processor itself. */ |
| 618 | t->max_speed = smbios_cpu_get_max_speed_mhz(); |
| 619 | |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 620 | if (cpu_have_cpuid()) { |
| 621 | res = cpuid(1); |
| 622 | |
| 623 | if ((res.ecx) & BIT(5)) |
| 624 | characteristics |= BIT(6); /* BIT6: Enhanced Virtualization */ |
| 625 | |
| 626 | if ((res.edx) & BIT(28)) |
| 627 | characteristics |= BIT(4); /* BIT4: Hardware Thread */ |
| 628 | |
| 629 | if (((cpuid_eax(0x80000000) - 0x80000000) + 1) > 2) { |
| 630 | res = cpuid(0x80000001); |
| 631 | |
| 632 | if ((res.edx) & BIT(20)) |
| 633 | characteristics |= BIT(5); /* BIT5: Execute Protection */ |
| 634 | } |
| 635 | } |
| 636 | t->processor_characteristics = characteristics | smbios_processor_characteristics(); |
Patrick Rudolph | b01ac7e | 2020-07-26 14:23:37 +0200 | [diff] [blame] | 637 | cpu_voltage = smbios_cpu_get_voltage(); |
| 638 | if (cpu_voltage > 0) |
| 639 | t->voltage = 0x80 | cpu_voltage; |
Morgan Jang | 92bcc4f | 2020-07-24 10:36:18 +0800 | [diff] [blame] | 640 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 641 | const int len = smbios_full_table_len(&t->header, t->eos); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 642 | *current += len; |
| 643 | return len; |
| 644 | } |
| 645 | |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 646 | /* |
| 647 | * Write SMBIOS type 7. |
| 648 | * Fill in some fields with constant values, as gathering the information |
| 649 | * from CPUID is impossible. |
| 650 | */ |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 651 | static int smbios_write_type7(unsigned long *current, |
| 652 | const int handle, |
| 653 | const u8 level, |
| 654 | const u8 sram_type, |
| 655 | const enum smbios_cache_associativity associativity, |
| 656 | const enum smbios_cache_type type, |
| 657 | const size_t max_cache_size, |
| 658 | const size_t cache_size) |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 659 | { |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 660 | char buf[8]; |
| 661 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 662 | struct smbios_type7 *t = smbios_carve_table(*current, SMBIOS_CACHE_INFORMATION, |
| 663 | sizeof(*t), handle); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 664 | |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 665 | snprintf(buf, sizeof(buf), "CACHE%x", level); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 666 | t->socket_designation = smbios_add_string(t->eos, buf); |
| 667 | |
| 668 | t->cache_configuration = SMBIOS_CACHE_CONF_LEVEL(level) | |
| 669 | SMBIOS_CACHE_CONF_LOCATION(0) | /* Internal */ |
| 670 | SMBIOS_CACHE_CONF_ENABLED(1) | /* Enabled */ |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 671 | SMBIOS_CACHE_CONF_OPERATION_MODE(smbios_cache_conf_operation_mode(level)); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 672 | |
| 673 | if (max_cache_size < (SMBIOS_CACHE_SIZE_MASK * KiB)) { |
| 674 | t->max_cache_size = max_cache_size / KiB; |
| 675 | t->max_cache_size2 = t->max_cache_size; |
| 676 | |
| 677 | t->max_cache_size |= SMBIOS_CACHE_SIZE_UNIT_1KB; |
| 678 | t->max_cache_size2 |= SMBIOS_CACHE_SIZE2_UNIT_1KB; |
| 679 | } else { |
Patrick Rudolph | 8f70267 | 2019-04-13 09:44:02 +0200 | [diff] [blame] | 680 | if (max_cache_size < (SMBIOS_CACHE_SIZE_MASK * 64 * KiB)) |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 681 | t->max_cache_size = max_cache_size / (64 * KiB); |
| 682 | else |
| 683 | t->max_cache_size = SMBIOS_CACHE_SIZE_OVERFLOW; |
| 684 | t->max_cache_size2 = max_cache_size / (64 * KiB); |
| 685 | |
| 686 | t->max_cache_size |= SMBIOS_CACHE_SIZE_UNIT_64KB; |
| 687 | t->max_cache_size2 |= SMBIOS_CACHE_SIZE2_UNIT_64KB; |
| 688 | } |
| 689 | |
| 690 | if (cache_size < (SMBIOS_CACHE_SIZE_MASK * KiB)) { |
| 691 | t->installed_size = cache_size / KiB; |
| 692 | t->installed_size2 = t->installed_size; |
| 693 | |
| 694 | t->installed_size |= SMBIOS_CACHE_SIZE_UNIT_1KB; |
| 695 | t->installed_size2 |= SMBIOS_CACHE_SIZE2_UNIT_1KB; |
| 696 | } else { |
| 697 | if (cache_size < (SMBIOS_CACHE_SIZE_MASK * 64 * KiB)) |
| 698 | t->installed_size = cache_size / (64 * KiB); |
| 699 | else |
| 700 | t->installed_size = SMBIOS_CACHE_SIZE_OVERFLOW; |
| 701 | t->installed_size2 = cache_size / (64 * KiB); |
| 702 | |
| 703 | t->installed_size |= SMBIOS_CACHE_SIZE_UNIT_64KB; |
| 704 | t->installed_size2 |= SMBIOS_CACHE_SIZE2_UNIT_64KB; |
| 705 | } |
| 706 | |
| 707 | t->associativity = associativity; |
| 708 | t->supported_sram_type = sram_type; |
| 709 | t->current_sram_type = sram_type; |
| 710 | t->cache_speed = 0; /* Unknown */ |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 711 | t->error_correction_type = smbios_cache_error_correction_type(level); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 712 | t->system_cache_type = type; |
| 713 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 714 | const int len = smbios_full_table_len(&t->header, t->eos); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 715 | *current += len; |
| 716 | return len; |
| 717 | } |
| 718 | |
| 719 | /* Convert the associativity as integer to the SMBIOS enum if available */ |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 720 | static enum smbios_cache_associativity smbios_cache_associativity(const u8 num) |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 721 | { |
| 722 | switch (num) { |
| 723 | case 1: |
| 724 | return SMBIOS_CACHE_ASSOCIATIVITY_DIRECT; |
| 725 | case 2: |
| 726 | return SMBIOS_CACHE_ASSOCIATIVITY_2WAY; |
| 727 | case 4: |
| 728 | return SMBIOS_CACHE_ASSOCIATIVITY_4WAY; |
| 729 | case 8: |
| 730 | return SMBIOS_CACHE_ASSOCIATIVITY_8WAY; |
| 731 | case 12: |
| 732 | return SMBIOS_CACHE_ASSOCIATIVITY_12WAY; |
| 733 | case 16: |
| 734 | return SMBIOS_CACHE_ASSOCIATIVITY_16WAY; |
| 735 | case 20: |
| 736 | return SMBIOS_CACHE_ASSOCIATIVITY_20WAY; |
| 737 | case 24: |
| 738 | return SMBIOS_CACHE_ASSOCIATIVITY_24WAY; |
| 739 | case 32: |
| 740 | return SMBIOS_CACHE_ASSOCIATIVITY_32WAY; |
| 741 | case 48: |
| 742 | return SMBIOS_CACHE_ASSOCIATIVITY_48WAY; |
| 743 | case 64: |
| 744 | return SMBIOS_CACHE_ASSOCIATIVITY_64WAY; |
| 745 | case 0xff: |
| 746 | return SMBIOS_CACHE_ASSOCIATIVITY_FULL; |
| 747 | default: |
| 748 | return SMBIOS_CACHE_ASSOCIATIVITY_UNKNOWN; |
| 749 | }; |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | * Parse the "Deterministic Cache Parameters" as provided by Intel in |
| 754 | * leaf 4 or AMD in extended leaf 0x8000001d. |
| 755 | * |
| 756 | * @param current Pointer to memory address to write the tables to |
| 757 | * @param handle Pointer to handle for the tables |
| 758 | * @param max_struct_size Pointer to maximum struct size |
Patrick Rudolph | 15589b4 | 2019-03-30 17:51:06 +0100 | [diff] [blame] | 759 | * @param type4 Pointer to SMBIOS type 4 structure |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 760 | */ |
| 761 | static int smbios_write_type7_cache_parameters(unsigned long *current, |
| 762 | int *handle, |
Patrick Rudolph | 15589b4 | 2019-03-30 17:51:06 +0100 | [diff] [blame] | 763 | int *max_struct_size, |
| 764 | struct smbios_type4 *type4) |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 765 | { |
Subrata Banik | e2b5fee | 2021-07-23 21:02:45 +0530 | [diff] [blame] | 766 | unsigned int cnt = CACHE_L1D; |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 767 | int len = 0; |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 768 | |
| 769 | if (!cpu_have_cpuid()) |
| 770 | return len; |
| 771 | |
Subrata Banik | 6efc4aa | 2021-09-01 12:40:47 +0530 | [diff] [blame] | 772 | enum cpu_type dcache_cpuid = cpu_check_deterministic_cache_cpuid_supported(); |
| 773 | if (dcache_cpuid == CPUID_TYPE_INVALID || dcache_cpuid == CPUID_COMMAND_UNSUPPORTED) { |
Subrata Banik | 5586c79 | 2021-09-02 13:17:18 +0530 | [diff] [blame] | 774 | printk(BIOS_DEBUG, "SMBIOS: Unknown CPU or CPU doesn't support Deterministic " |
| 775 | "Cache CPUID leaf\n"); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 776 | return len; |
| 777 | } |
| 778 | |
| 779 | while (1) { |
| 780 | enum smbios_cache_associativity associativity; |
| 781 | enum smbios_cache_type type; |
Subrata Banik | e2b5fee | 2021-07-23 21:02:45 +0530 | [diff] [blame] | 782 | struct cpu_cache_info info; |
| 783 | if (!fill_cpu_cache_info(cnt++, &info)) |
| 784 | continue; |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 785 | |
Subrata Banik | e2b5fee | 2021-07-23 21:02:45 +0530 | [diff] [blame] | 786 | const u8 cache_type = info.type; |
| 787 | const u8 level = info.level; |
| 788 | const size_t assoc = info.num_ways; |
| 789 | const size_t cache_share = info.num_cores_shared; |
| 790 | const size_t cache_size = info.size * get_number_of_caches(cache_share); |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 791 | |
| 792 | if (!cache_type) |
| 793 | /* No more caches in the system */ |
| 794 | break; |
| 795 | |
| 796 | switch (cache_type) { |
| 797 | case 1: |
| 798 | type = SMBIOS_CACHE_TYPE_DATA; |
| 799 | break; |
| 800 | case 2: |
| 801 | type = SMBIOS_CACHE_TYPE_INSTRUCTION; |
| 802 | break; |
| 803 | case 3: |
| 804 | type = SMBIOS_CACHE_TYPE_UNIFIED; |
| 805 | break; |
| 806 | default: |
| 807 | type = SMBIOS_CACHE_TYPE_UNKNOWN; |
| 808 | break; |
| 809 | } |
| 810 | |
Subrata Banik | e2b5fee | 2021-07-23 21:02:45 +0530 | [diff] [blame] | 811 | if (info.fully_associative) |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 812 | associativity = SMBIOS_CACHE_ASSOCIATIVITY_FULL; |
| 813 | else |
| 814 | associativity = smbios_cache_associativity(assoc); |
| 815 | |
Patrick Rudolph | 15589b4 | 2019-03-30 17:51:06 +0100 | [diff] [blame] | 816 | const int h = (*handle)++; |
| 817 | |
| 818 | update_max(len, *max_struct_size, smbios_write_type7(current, h, |
Morgan Jang | 8ae391d | 2020-10-06 16:26:17 +0800 | [diff] [blame] | 819 | level, smbios_cache_sram_type(), associativity, |
Patrick Rudolph | 15589b4 | 2019-03-30 17:51:06 +0100 | [diff] [blame] | 820 | type, cache_size, cache_size)); |
| 821 | |
| 822 | if (type4) { |
| 823 | switch (level) { |
| 824 | case 1: |
| 825 | type4->l1_cache_handle = h; |
| 826 | break; |
| 827 | case 2: |
| 828 | type4->l2_cache_handle = h; |
| 829 | break; |
| 830 | case 3: |
| 831 | type4->l3_cache_handle = h; |
| 832 | break; |
| 833 | } |
| 834 | } |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 835 | }; |
| 836 | |
| 837 | return len; |
| 838 | } |
BryantOu | 4a8e58f | 2020-04-20 19:45:20 -0700 | [diff] [blame] | 839 | |
| 840 | int smbios_write_type8(unsigned long *current, int *handle, |
| 841 | const struct port_information *port, |
| 842 | size_t num_ports) |
| 843 | { |
BryantOu | 4a8e58f | 2020-04-20 19:45:20 -0700 | [diff] [blame] | 844 | unsigned int totallen = 0, i; |
| 845 | |
| 846 | for (i = 0; i < num_ports; i++, port++) { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 847 | struct smbios_type8 *t = smbios_carve_table(*current, |
| 848 | SMBIOS_PORT_CONNECTOR_INFORMATION, |
| 849 | sizeof(*t), *handle); |
BryantOu | 4a8e58f | 2020-04-20 19:45:20 -0700 | [diff] [blame] | 850 | t->internal_reference_designator = |
| 851 | smbios_add_string(t->eos, port->internal_reference_designator); |
| 852 | t->internal_connector_type = port->internal_connector_type; |
| 853 | t->external_reference_designator = |
| 854 | smbios_add_string(t->eos, port->external_reference_designator); |
| 855 | t->external_connector_type = port->external_connector_type; |
| 856 | t->port_type = port->port_type; |
| 857 | *handle += 1; |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 858 | const int len = smbios_full_table_len(&t->header, t->eos); |
| 859 | *current += len; |
| 860 | totallen += len; |
BryantOu | 4a8e58f | 2020-04-20 19:45:20 -0700 | [diff] [blame] | 861 | } |
| 862 | return totallen; |
| 863 | } |
| 864 | |
Lijian Zhao | e98a751 | 2019-04-11 23:28:09 -0700 | [diff] [blame] | 865 | int smbios_write_type9(unsigned long *current, int *handle, |
| 866 | const char *name, const enum misc_slot_type type, |
| 867 | const enum slot_data_bus_bandwidth bandwidth, |
| 868 | const enum misc_slot_usage usage, |
| 869 | const enum misc_slot_length length, |
JingleHsuWiwynn | 20fa59f | 2021-01-26 09:55:34 +0800 | [diff] [blame] | 870 | const u16 id, u8 slot_char1, u8 slot_char2, u8 bus, u8 dev_func) |
Lijian Zhao | e98a751 | 2019-04-11 23:28:09 -0700 | [diff] [blame] | 871 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 872 | struct smbios_type9 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_SLOTS, |
| 873 | sizeof(*t), *handle); |
Lijian Zhao | e98a751 | 2019-04-11 23:28:09 -0700 | [diff] [blame] | 874 | |
Angel Pons | 3c13da7 | 2020-07-29 18:23:23 +0200 | [diff] [blame] | 875 | t->slot_designation = smbios_add_string(t->eos, name ? name : "SLOT"); |
Lijian Zhao | e98a751 | 2019-04-11 23:28:09 -0700 | [diff] [blame] | 876 | t->slot_type = type; |
| 877 | /* TODO add slot_id supoort, will be "_SUN" for ACPI devices */ |
JingleHsuWiwynn | 20fa59f | 2021-01-26 09:55:34 +0800 | [diff] [blame] | 878 | t->slot_id = id; |
Lijian Zhao | e98a751 | 2019-04-11 23:28:09 -0700 | [diff] [blame] | 879 | t->slot_data_bus_width = bandwidth; |
| 880 | t->current_usage = usage; |
| 881 | t->slot_length = length; |
| 882 | t->slot_characteristics_1 = slot_char1; |
| 883 | t->slot_characteristics_2 = slot_char2; |
| 884 | t->segment_group_number = 0; |
| 885 | t->bus_number = bus; |
| 886 | t->device_function_number = dev_func; |
| 887 | t->data_bus_width = SlotDataBusWidthOther; |
| 888 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 889 | const int len = smbios_full_table_len(&t->header, t->eos); |
Lijian Zhao | e98a751 | 2019-04-11 23:28:09 -0700 | [diff] [blame] | 890 | *current += len; |
| 891 | *handle += 1; |
| 892 | return len; |
| 893 | } |
Patrick Rudolph | fc5b809 | 2019-03-30 17:37:28 +0100 | [diff] [blame] | 894 | |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 895 | static int smbios_write_type11(unsigned long *current, int *handle) |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 896 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 897 | struct device *dev; |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 898 | struct smbios_type11 *t = smbios_carve_table(*current, SMBIOS_OEM_STRINGS, |
| 899 | sizeof(*t), *handle); |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 900 | |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 901 | for (dev = all_devices; dev; dev = dev->next) { |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 902 | if (dev->ops && dev->ops->get_smbios_strings) |
| 903 | dev->ops->get_smbios_strings(dev, t); |
| 904 | } |
| 905 | |
| 906 | if (t->count == 0) { |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 907 | memset(t, 0, sizeof(*t)); |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 908 | return 0; |
| 909 | } |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 910 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 911 | const int len = smbios_full_table_len(&t->header, t->eos); |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 912 | *current += len; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 913 | (*handle)++; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 914 | return len; |
| 915 | } |
| 916 | |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 917 | static int smbios_write_type16(unsigned long *current, int *handle) |
| 918 | { |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 919 | int i; |
Tim Chu | 1ee8ddc | 2021-01-22 01:10:45 -0800 | [diff] [blame] | 920 | uint64_t max_capacity; |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 921 | |
| 922 | struct memory_info *meminfo; |
| 923 | meminfo = cbmem_find(CBMEM_ID_MEMINFO); |
| 924 | if (meminfo == NULL) |
| 925 | return 0; /* can't find mem info in cbmem */ |
| 926 | |
| 927 | printk(BIOS_INFO, "Create SMBIOS type 16\n"); |
| 928 | |
| 929 | if (meminfo->max_capacity_mib == 0 || meminfo->number_of_devices == 0) { |
| 930 | /* Fill in defaults if not provided */ |
| 931 | meminfo->number_of_devices = 0; |
| 932 | meminfo->max_capacity_mib = 0; |
| 933 | for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) { |
| 934 | meminfo->max_capacity_mib += meminfo->dimm[i].dimm_size; |
| 935 | meminfo->number_of_devices += !!meminfo->dimm[i].dimm_size; |
| 936 | } |
| 937 | } |
| 938 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 939 | struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY, |
| 940 | sizeof(*t), *handle); |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 941 | |
| 942 | t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; |
| 943 | t->use = MEMORY_ARRAY_USE_SYSTEM; |
Angel Pons | 6e82ebf | 2021-01-31 15:15:11 +0100 | [diff] [blame] | 944 | t->memory_error_correction = meminfo->ecc_type; |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 945 | |
| 946 | /* no error information handle available */ |
| 947 | t->memory_error_information_handle = 0xFFFE; |
Tim Chu | 1ee8ddc | 2021-01-22 01:10:45 -0800 | [diff] [blame] | 948 | max_capacity = meminfo->max_capacity_mib; |
| 949 | if (max_capacity * (MiB / KiB) < SMBIOS_USE_EXTENDED_MAX_CAPACITY) |
| 950 | t->maximum_capacity = max_capacity * (MiB / KiB); |
| 951 | else { |
| 952 | t->maximum_capacity = SMBIOS_USE_EXTENDED_MAX_CAPACITY; |
| 953 | t->extended_maximum_capacity = max_capacity * MiB; |
| 954 | } |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 955 | t->number_of_memory_devices = meminfo->number_of_devices; |
| 956 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 957 | const int len = smbios_full_table_len(&t->header, t->eos); |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 958 | *current += len; |
| 959 | (*handle)++; |
| 960 | return len; |
| 961 | } |
| 962 | |
| 963 | static int smbios_write_type17(unsigned long *current, int *handle, int type16) |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 964 | { |
Iru Cai | 3677520 | 2016-03-09 23:22:58 +0800 | [diff] [blame] | 965 | int totallen = 0; |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 966 | int i; |
| 967 | |
| 968 | struct memory_info *meminfo; |
| 969 | meminfo = cbmem_find(CBMEM_ID_MEMINFO); |
| 970 | if (meminfo == NULL) |
| 971 | return 0; /* can't find mem info in cbmem */ |
| 972 | |
| 973 | printk(BIOS_INFO, "Create SMBIOS type 17\n"); |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 974 | for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) { |
Angel Pons | 2b48258 | 2022-05-03 18:12:18 +0200 | [diff] [blame] | 975 | struct dimm_info *d = &meminfo->dimm[i]; |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 976 | /* |
| 977 | * Windows 10 GetPhysicallyInstalledSystemMemory functions reads SMBIOS tables |
| 978 | * type 16 and type 17. The type 17 tables need to point to a type 16 table. |
| 979 | * Otherwise, the physical installed memory size is guessed from the system |
| 980 | * memory map, which results in a slightly smaller value than the actual size. |
| 981 | */ |
Angel Pons | 2b48258 | 2022-05-03 18:12:18 +0200 | [diff] [blame] | 982 | int len; |
| 983 | if (d->dimm_size > 0) |
| 984 | len = create_smbios_type17_for_dimm(d, current, handle, type16); |
| 985 | else |
| 986 | len = create_smbios_type17_for_empty_slot(d, current, handle, type16); |
| 987 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 988 | *current += len; |
Iru Cai | 3677520 | 2016-03-09 23:22:58 +0800 | [diff] [blame] | 989 | totallen += len; |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 990 | } |
Iru Cai | 3677520 | 2016-03-09 23:22:58 +0800 | [diff] [blame] | 991 | return totallen; |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Tim Chu | e41f595 | 2020-11-02 21:33:52 -0800 | [diff] [blame] | 994 | static int smbios_write_type19(unsigned long *current, int *handle, int type16) |
Patrick Rudolph | 604295e | 2020-07-21 14:53:37 +0200 | [diff] [blame] | 995 | { |
Patrick Rudolph | 604295e | 2020-07-21 14:53:37 +0200 | [diff] [blame] | 996 | int i; |
| 997 | |
| 998 | struct memory_info *meminfo; |
| 999 | meminfo = cbmem_find(CBMEM_ID_MEMINFO); |
| 1000 | if (meminfo == NULL) |
| 1001 | return 0; /* can't find mem info in cbmem */ |
| 1002 | |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 1003 | struct smbios_type19 *t = smbios_carve_table(*current, |
| 1004 | SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS, |
| 1005 | sizeof(*t), *handle); |
Patrick Rudolph | 604295e | 2020-07-21 14:53:37 +0200 | [diff] [blame] | 1006 | |
Tim Chu | e41f595 | 2020-11-02 21:33:52 -0800 | [diff] [blame] | 1007 | t->memory_array_handle = type16; |
Patrick Rudolph | 604295e | 2020-07-21 14:53:37 +0200 | [diff] [blame] | 1008 | |
| 1009 | for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) { |
| 1010 | if (meminfo->dimm[i].dimm_size > 0) { |
| 1011 | t->extended_ending_address += meminfo->dimm[i].dimm_size; |
| 1012 | t->partition_width++; |
| 1013 | } |
| 1014 | } |
| 1015 | t->extended_ending_address *= MiB; |
| 1016 | |
| 1017 | /* Check if it fits into regular address */ |
| 1018 | if (t->extended_ending_address >= KiB && |
| 1019 | t->extended_ending_address < 0x40000000000ULL) { |
| 1020 | /* |
| 1021 | * FIXME: The starting address is SoC specific, but SMBIOS tables are only |
| 1022 | * exported on x86 where it's always 0. |
| 1023 | */ |
| 1024 | |
| 1025 | t->starting_address = 0; |
| 1026 | t->ending_address = t->extended_ending_address / KiB - 1; |
| 1027 | t->extended_starting_address = ~0; |
| 1028 | t->extended_ending_address = ~0; |
| 1029 | } else { |
| 1030 | t->starting_address = ~0; |
| 1031 | t->ending_address = ~0; |
| 1032 | t->extended_starting_address = 0; |
| 1033 | t->extended_ending_address--; |
| 1034 | } |
| 1035 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 1036 | const int len = smbios_full_table_len(&t->header, t->eos); |
Patrick Rudolph | 604295e | 2020-07-21 14:53:37 +0200 | [diff] [blame] | 1037 | *current += len; |
| 1038 | *handle += 1; |
| 1039 | return len; |
| 1040 | } |
| 1041 | |
Matt DeVillier | d1c1afd | 2016-09-02 21:41:26 -0500 | [diff] [blame] | 1042 | static int smbios_write_type20_table(unsigned long *current, int *handle, u32 addr_start, |
| 1043 | u32 addr_end, int type17_handle, int type19_handle) |
| 1044 | { |
| 1045 | struct smbios_type20 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE_MAPPED_ADDRESS, |
| 1046 | sizeof(*t), *handle); |
| 1047 | |
| 1048 | t->memory_device_handle = type17_handle; |
| 1049 | t->memory_array_mapped_address_handle = type19_handle; |
| 1050 | t->addr_start = addr_start; |
| 1051 | t->addr_end = addr_end; |
| 1052 | t->partition_row_pos = 0xff; |
| 1053 | t->interleave_pos = 0xff; |
| 1054 | t->interleave_depth = 0xff; |
| 1055 | |
| 1056 | const int len = smbios_full_table_len(&t->header, t->eos); |
| 1057 | *current += len; |
| 1058 | *handle += 1; |
| 1059 | return len; |
| 1060 | } |
| 1061 | |
| 1062 | static int smbios_write_type20(unsigned long *current, int *handle, |
| 1063 | int type17_handle, int type19_handle) |
| 1064 | { |
| 1065 | u32 start_addr = 0; |
| 1066 | int totallen = 0; |
| 1067 | int i; |
| 1068 | |
| 1069 | struct memory_info *meminfo; |
| 1070 | meminfo = cbmem_find(CBMEM_ID_MEMINFO); |
| 1071 | if (meminfo == NULL) |
| 1072 | return 0; /* can't find mem info in cbmem */ |
| 1073 | |
| 1074 | printk(BIOS_INFO, "Create SMBIOS type 20\n"); |
| 1075 | for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) { |
| 1076 | struct dimm_info *dimm; |
| 1077 | dimm = &meminfo->dimm[i]; |
Angel Pons | 2b48258 | 2022-05-03 18:12:18 +0200 | [diff] [blame] | 1078 | if (dimm->dimm_size == 0) |
| 1079 | continue; |
| 1080 | |
Matt DeVillier | d1c1afd | 2016-09-02 21:41:26 -0500 | [diff] [blame] | 1081 | u32 end_addr = start_addr + (dimm->dimm_size << 10) - 1; |
| 1082 | totallen += smbios_write_type20_table(current, handle, start_addr, end_addr, |
| 1083 | type17_handle, type19_handle); |
| 1084 | start_addr = end_addr + 1; |
| 1085 | } |
| 1086 | return totallen; |
| 1087 | } |
| 1088 | |
Erik van den Bogaert | 9378152 | 2022-09-28 12:35:51 +0200 | [diff] [blame] | 1089 | int smbios_write_type28(unsigned long *current, int *handle, |
| 1090 | const char *name, |
| 1091 | const enum smbios_temp_location location, |
| 1092 | const enum smbios_temp_status status, |
| 1093 | u16 max_value, u16 min_value, |
| 1094 | u16 resolution, u16 tolerance, |
| 1095 | u16 accuracy, |
| 1096 | u32 oem, |
| 1097 | u16 nominal_value) |
| 1098 | { |
| 1099 | struct smbios_type28 *t = smbios_carve_table(*current, SMBIOS_TEMPERATURE_PROBE, |
| 1100 | sizeof(*t), *handle); |
| 1101 | |
| 1102 | t->description = smbios_add_string(t->eos, name ? name : "Temperature"); |
| 1103 | t->location_and_status = location | (status << 5); |
| 1104 | t->maximum_value = max_value; |
| 1105 | t->minimum_value = min_value; |
| 1106 | t->resolution = resolution; |
| 1107 | t->tolerance = tolerance; |
| 1108 | t->accuracy = accuracy; |
| 1109 | t->oem_defined = oem; |
| 1110 | t->nominal_value = nominal_value; |
| 1111 | |
| 1112 | const int len = smbios_full_table_len(&t->header, t->eos); |
| 1113 | *current += len; |
| 1114 | *handle += 1; |
| 1115 | return len; |
| 1116 | } |
| 1117 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1118 | static int smbios_write_type32(unsigned long *current, int handle) |
| 1119 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 1120 | struct smbios_type32 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_BOOT_INFORMATION, |
| 1121 | sizeof(*t), handle); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1122 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 1123 | const int len = smbios_full_table_len(&t->header, t->eos); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1124 | *current += len; |
| 1125 | return len; |
| 1126 | } |
| 1127 | |
Patrick Rudolph | fe98e90 | 2018-03-27 16:17:12 +0200 | [diff] [blame] | 1128 | int smbios_write_type38(unsigned long *current, int *handle, |
| 1129 | const enum smbios_bmc_interface_type interface_type, |
| 1130 | const u8 ipmi_rev, const u8 i2c_addr, const u8 nv_addr, |
| 1131 | const u64 base_addr, const u8 base_modifier, |
| 1132 | const u8 irq) |
| 1133 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 1134 | struct smbios_type38 *t = smbios_carve_table(*current, SMBIOS_IPMI_DEVICE_INFORMATION, |
| 1135 | sizeof(*t), *handle); |
Patrick Rudolph | fe98e90 | 2018-03-27 16:17:12 +0200 | [diff] [blame] | 1136 | |
Patrick Rudolph | fe98e90 | 2018-03-27 16:17:12 +0200 | [diff] [blame] | 1137 | t->interface_type = interface_type; |
| 1138 | t->ipmi_rev = ipmi_rev; |
| 1139 | t->i2c_slave_addr = i2c_addr; |
| 1140 | t->nv_storage_addr = nv_addr; |
| 1141 | t->base_address = base_addr; |
| 1142 | t->base_address_modifier = base_modifier; |
| 1143 | t->irq = irq; |
| 1144 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 1145 | const int len = smbios_full_table_len(&t->header, t->eos); |
Patrick Rudolph | fe98e90 | 2018-03-27 16:17:12 +0200 | [diff] [blame] | 1146 | *current += len; |
| 1147 | *handle += 1; |
Patrick Rudolph | fe98e90 | 2018-03-27 16:17:12 +0200 | [diff] [blame] | 1148 | return len; |
| 1149 | } |
| 1150 | |
Jonathan Zhang | d57b821 | 2022-10-14 17:06:26 -0700 | [diff] [blame] | 1151 | int smbios_write_type39(unsigned long *current, int *handle, |
| 1152 | u8 unit_group, const char *loc, const char *dev_name, |
| 1153 | const char *man, const char *serial_num, |
| 1154 | const char *tag_num, const char *part_num, |
| 1155 | const char *rev_lvl, u16 max_pow_cap, |
| 1156 | const struct power_supply_ch *ps_ch) |
| 1157 | { |
| 1158 | struct smbios_type39 *t = smbios_carve_table(*current, |
| 1159 | SMBIOS_SYSTEM_POWER_SUPPLY, |
| 1160 | sizeof(*t), *handle); |
| 1161 | |
| 1162 | uint16_t val = 0; |
| 1163 | uint16_t ps_type, ps_status, vol_switch, ps_unplug, ps_present, hot_rep; |
| 1164 | |
| 1165 | t->power_unit_group = unit_group; |
| 1166 | t->location = smbios_add_string(t->eos, loc); |
| 1167 | t->device_name = smbios_add_string(t->eos, dev_name); |
| 1168 | t->manufacturer = smbios_add_string(t->eos, man); |
| 1169 | t->serial_number = smbios_add_string(t->eos, serial_num); |
| 1170 | t->asset_tag_number = smbios_add_string(t->eos, tag_num); |
| 1171 | t->model_part_number = smbios_add_string(t->eos, part_num); |
| 1172 | t->revision_level = smbios_add_string(t->eos, rev_lvl); |
| 1173 | t->max_power_capacity = max_pow_cap; |
| 1174 | |
| 1175 | ps_type = ps_ch->power_supply_type & 0xF; |
| 1176 | ps_status = ps_ch->power_supply_status & 0x7; |
| 1177 | vol_switch = ps_ch->input_voltage_range_switch & 0xF; |
| 1178 | ps_unplug = ps_ch->power_supply_unplugged & 0x1; |
| 1179 | ps_present = ps_ch->power_supply_present & 0x1; |
| 1180 | hot_rep = ps_ch->power_supply_hot_replaceble & 0x1; |
| 1181 | |
| 1182 | val |= (ps_type << 10); |
| 1183 | val |= (ps_status << 7); |
| 1184 | val |= (vol_switch << 3); |
| 1185 | val |= (ps_unplug << 2); |
| 1186 | val |= (ps_present << 1); |
| 1187 | val |= hot_rep; |
| 1188 | t->power_supply_characteristics = val; |
| 1189 | |
| 1190 | t->input_voltage_probe_handle = 0xFFFF; |
| 1191 | t->cooling_device_handle = 0xFFFF; |
| 1192 | t->input_current_probe_handle = 0xFFFF; |
| 1193 | |
| 1194 | const int len = smbios_full_table_len(&t->header, t->eos); |
| 1195 | *current += len; |
| 1196 | *handle += 1; |
| 1197 | return len; |
| 1198 | } |
| 1199 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 1200 | int smbios_write_type41(unsigned long *current, int *handle, |
| 1201 | const char *name, u8 instance, u16 segment, |
Christian Walter | e6afab1 | 2019-05-21 17:22:49 +0200 | [diff] [blame] | 1202 | u8 bus, u8 device, u8 function, u8 device_type) |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 1203 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 1204 | struct smbios_type41 *t = smbios_carve_table(*current, |
| 1205 | SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION, |
| 1206 | sizeof(*t), *handle); |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 1207 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 1208 | t->reference_designation = smbios_add_string(t->eos, name); |
Christian Walter | e6afab1 | 2019-05-21 17:22:49 +0200 | [diff] [blame] | 1209 | t->device_type = device_type; |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 1210 | t->device_status = 1; |
| 1211 | t->device_type_instance = instance; |
| 1212 | t->segment_group_number = segment; |
| 1213 | t->bus_number = bus; |
| 1214 | t->device_number = device; |
| 1215 | t->function_number = function; |
| 1216 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 1217 | const int len = smbios_full_table_len(&t->header, t->eos); |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 1218 | *current += len; |
| 1219 | *handle += 1; |
| 1220 | return len; |
| 1221 | } |
| 1222 | |
Michał Żygowski | e779523 | 2022-05-04 14:10:45 +0200 | [diff] [blame] | 1223 | int smbios_write_type43(unsigned long *current, int *handle, const u32 vendor_id, |
| 1224 | const u8 major_spec_ver, const u8 minor_spec_ver, |
| 1225 | const u32 fw_ver1, const u32 fw_ver2, const char *description, |
| 1226 | const u64 characteristics, const u32 oem_defined) |
| 1227 | { |
| 1228 | struct smbios_type43 *t = smbios_carve_table(*current, SMBIOS_TPM_DEVICE, |
| 1229 | sizeof(*t), *handle); |
| 1230 | |
| 1231 | t->vendor_id = vendor_id; |
| 1232 | t->major_spec_ver = major_spec_ver; |
| 1233 | t->minor_spec_ver = minor_spec_ver; |
| 1234 | t->fw_ver1 = fw_ver1; |
| 1235 | t->fw_ver2 = fw_ver2; |
| 1236 | t->characteristics = characteristics; |
| 1237 | t->oem_defined = oem_defined; |
| 1238 | t->description = smbios_add_string(t->eos, description); |
| 1239 | |
| 1240 | const int len = smbios_full_table_len(&t->header, t->eos); |
| 1241 | *current += len; |
| 1242 | *handle += 1; |
| 1243 | return len; |
| 1244 | } |
| 1245 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1246 | static int smbios_write_type127(unsigned long *current, int handle) |
| 1247 | { |
Angel Pons | d62a501 | 2021-06-28 17:18:06 +0200 | [diff] [blame] | 1248 | struct smbios_type127 *t = smbios_carve_table(*current, SMBIOS_END_OF_TABLE, |
| 1249 | sizeof(*t), handle); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1250 | |
Angel Pons | a37701a | 2021-06-28 17:36:53 +0200 | [diff] [blame] | 1251 | const int len = smbios_full_table_len(&t->header, t->eos); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1252 | *current += len; |
| 1253 | return len; |
| 1254 | } |
| 1255 | |
Angel Pons | be2e2bb | 2021-08-27 10:34:05 +0200 | [diff] [blame] | 1256 | /* Get the device type 41 from the dev struct */ |
| 1257 | static u8 smbios_get_device_type_from_dev(struct device *dev) |
| 1258 | { |
| 1259 | u16 pci_basesubclass = (dev->class >> 8) & 0xFFFF; |
| 1260 | |
| 1261 | switch (pci_basesubclass) { |
| 1262 | case PCI_CLASS_NOT_DEFINED: |
| 1263 | return SMBIOS_DEVICE_TYPE_OTHER; |
| 1264 | case PCI_CLASS_DISPLAY_VGA: |
| 1265 | case PCI_CLASS_DISPLAY_XGA: |
| 1266 | case PCI_CLASS_DISPLAY_3D: |
| 1267 | case PCI_CLASS_DISPLAY_OTHER: |
| 1268 | return SMBIOS_DEVICE_TYPE_VIDEO; |
| 1269 | case PCI_CLASS_STORAGE_SCSI: |
| 1270 | return SMBIOS_DEVICE_TYPE_SCSI; |
| 1271 | case PCI_CLASS_NETWORK_ETHERNET: |
| 1272 | return SMBIOS_DEVICE_TYPE_ETHERNET; |
| 1273 | case PCI_CLASS_NETWORK_TOKEN_RING: |
| 1274 | return SMBIOS_DEVICE_TYPE_TOKEN_RING; |
| 1275 | case PCI_CLASS_MULTIMEDIA_VIDEO: |
| 1276 | case PCI_CLASS_MULTIMEDIA_AUDIO: |
| 1277 | case PCI_CLASS_MULTIMEDIA_PHONE: |
| 1278 | case PCI_CLASS_MULTIMEDIA_OTHER: |
| 1279 | return SMBIOS_DEVICE_TYPE_SOUND; |
| 1280 | case PCI_CLASS_STORAGE_ATA: |
| 1281 | return SMBIOS_DEVICE_TYPE_PATA; |
| 1282 | case PCI_CLASS_STORAGE_SATA: |
| 1283 | return SMBIOS_DEVICE_TYPE_SATA; |
| 1284 | case PCI_CLASS_STORAGE_SAS: |
| 1285 | return SMBIOS_DEVICE_TYPE_SAS; |
| 1286 | default: |
| 1287 | return SMBIOS_DEVICE_TYPE_UNKNOWN; |
| 1288 | } |
| 1289 | } |
| 1290 | |
Angel Pons | 437da71 | 2021-09-03 16:51:40 +0200 | [diff] [blame] | 1291 | static bool smbios_get_type41_instance_id(struct device *dev, u8 device_type, u8 *instance_id) |
| 1292 | { |
| 1293 | #if CONFIG(SMBIOS_TYPE41_PROVIDED_BY_DEVTREE) |
| 1294 | *instance_id = dev->smbios_instance_id; |
| 1295 | return dev->smbios_instance_id_valid; |
| 1296 | #else |
| 1297 | static u8 type41_inst_cnt[SMBIOS_DEVICE_TYPE_COUNT + 1] = {}; |
| 1298 | |
| 1299 | if (device_type == SMBIOS_DEVICE_TYPE_OTHER || |
| 1300 | device_type == SMBIOS_DEVICE_TYPE_UNKNOWN) |
| 1301 | return false; |
| 1302 | |
| 1303 | if (device_type > SMBIOS_DEVICE_TYPE_COUNT) |
| 1304 | return false; |
| 1305 | |
| 1306 | *instance_id = type41_inst_cnt[device_type]++; |
| 1307 | return true; |
| 1308 | #endif |
| 1309 | } |
| 1310 | |
| 1311 | static const char *smbios_get_type41_refdes(struct device *dev) |
| 1312 | { |
| 1313 | #if CONFIG(SMBIOS_TYPE41_PROVIDED_BY_DEVTREE) |
| 1314 | if (dev->smbios_refdes) |
| 1315 | return dev->smbios_refdes; |
| 1316 | #endif |
| 1317 | return get_pci_subclass_name(dev); |
| 1318 | } |
| 1319 | |
Angel Pons | 12b809b | 2021-09-03 11:58:04 +0200 | [diff] [blame] | 1320 | static int smbios_generate_type41_from_devtree(struct device *dev, int *handle, |
| 1321 | unsigned long *current) |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 1322 | { |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 1323 | if (dev->path.type != DEVICE_PATH_PCI) |
| 1324 | return 0; |
| 1325 | if (!dev->on_mainboard) |
| 1326 | return 0; |
| 1327 | |
Angel Pons | 437da71 | 2021-09-03 16:51:40 +0200 | [diff] [blame] | 1328 | const u8 device_type = smbios_get_device_type_from_dev(dev); |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 1329 | |
Angel Pons | 437da71 | 2021-09-03 16:51:40 +0200 | [diff] [blame] | 1330 | u8 instance_id; |
| 1331 | |
| 1332 | if (!smbios_get_type41_instance_id(dev, device_type, &instance_id)) |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 1333 | return 0; |
| 1334 | |
Angel Pons | 437da71 | 2021-09-03 16:51:40 +0200 | [diff] [blame] | 1335 | const char *name = smbios_get_type41_refdes(dev); |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 1336 | |
| 1337 | return smbios_write_type41(current, handle, |
| 1338 | name, // name |
Angel Pons | 437da71 | 2021-09-03 16:51:40 +0200 | [diff] [blame] | 1339 | instance_id, // inst |
Christian Walter | 9e5b062 | 2019-05-21 17:37:58 +0200 | [diff] [blame] | 1340 | 0, // segment |
| 1341 | dev->bus->secondary, //bus |
| 1342 | PCI_SLOT(dev->path.pci.devfn), // device |
| 1343 | PCI_FUNC(dev->path.pci.devfn), // func |
| 1344 | device_type); |
| 1345 | } |
| 1346 | |
Angel Pons | 12b809b | 2021-09-03 11:58:04 +0200 | [diff] [blame] | 1347 | static int smbios_generate_type9_from_devtree(struct device *dev, int *handle, |
| 1348 | unsigned long *current) |
Patrick Rudolph | f5b9369 | 2019-04-12 15:59:40 +0200 | [diff] [blame] | 1349 | { |
| 1350 | enum misc_slot_usage usage; |
| 1351 | enum slot_data_bus_bandwidth bandwidth; |
| 1352 | enum misc_slot_type type; |
| 1353 | enum misc_slot_length length; |
| 1354 | |
| 1355 | if (dev->path.type != DEVICE_PATH_PCI) |
| 1356 | return 0; |
| 1357 | |
| 1358 | if (!dev->smbios_slot_type && !dev->smbios_slot_data_width && |
| 1359 | !dev->smbios_slot_designation && !dev->smbios_slot_length) |
| 1360 | return 0; |
| 1361 | |
| 1362 | if (dev_is_active_bridge(dev)) |
| 1363 | usage = SlotUsageInUse; |
| 1364 | else if (dev->enabled) |
| 1365 | usage = SlotUsageAvailable; |
| 1366 | else |
| 1367 | usage = SlotUsageUnknown; |
| 1368 | |
| 1369 | if (dev->smbios_slot_data_width) |
| 1370 | bandwidth = dev->smbios_slot_data_width; |
| 1371 | else |
| 1372 | bandwidth = SlotDataBusWidthUnknown; |
| 1373 | |
| 1374 | if (dev->smbios_slot_type) |
| 1375 | type = dev->smbios_slot_type; |
| 1376 | else |
| 1377 | type = SlotTypeUnknown; |
| 1378 | |
| 1379 | if (dev->smbios_slot_length) |
| 1380 | length = dev->smbios_slot_length; |
| 1381 | else |
| 1382 | length = SlotLengthUnknown; |
| 1383 | |
| 1384 | return smbios_write_type9(current, handle, |
| 1385 | dev->smbios_slot_designation, |
| 1386 | type, |
| 1387 | bandwidth, |
| 1388 | usage, |
| 1389 | length, |
JingleHsuWiwynn | 20fa59f | 2021-01-26 09:55:34 +0800 | [diff] [blame] | 1390 | 0, |
Patrick Rudolph | f5b9369 | 2019-04-12 15:59:40 +0200 | [diff] [blame] | 1391 | 1, |
| 1392 | 0, |
| 1393 | dev->bus->secondary, |
| 1394 | dev->path.pci.devfn); |
| 1395 | } |
| 1396 | |
Angel Pons | 6a73b24 | 2021-09-03 12:18:10 +0200 | [diff] [blame] | 1397 | int get_smbios_data(struct device *dev, int *handle, unsigned long *current) |
| 1398 | { |
| 1399 | int len = 0; |
| 1400 | |
| 1401 | len += smbios_generate_type9_from_devtree(dev, handle, current); |
| 1402 | len += smbios_generate_type41_from_devtree(dev, handle, current); |
| 1403 | |
| 1404 | return len; |
| 1405 | } |
| 1406 | |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1407 | static int smbios_walk_device_tree(struct device *tree, int *handle, unsigned long *current) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1408 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 1409 | struct device *dev; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1410 | int len = 0; |
| 1411 | |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 1412 | for (dev = tree; dev; dev = dev->next) { |
Angel Pons | 8b98f8b | 2021-09-07 14:00:17 +0200 | [diff] [blame] | 1413 | if (!dev->enabled) |
| 1414 | continue; |
| 1415 | |
| 1416 | if (dev->ops && dev->ops->get_smbios_data) { |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1417 | printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev_name(dev)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1418 | len += dev->ops->get_smbios_data(dev, handle, current); |
Angel Pons | 6a73b24 | 2021-09-03 12:18:10 +0200 | [diff] [blame] | 1419 | } else { |
| 1420 | len += get_smbios_data(dev, handle, current); |
Naresh G Solanki | 20c893e | 2018-06-05 18:58:53 +0530 | [diff] [blame] | 1421 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1422 | } |
| 1423 | return len; |
| 1424 | } |
| 1425 | |
| 1426 | unsigned long smbios_write_tables(unsigned long current) |
| 1427 | { |
| 1428 | struct smbios_entry *se; |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1429 | struct smbios_entry30 *se3; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1430 | unsigned long tables; |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 1431 | int len = 0; |
| 1432 | int max_struct_size = 0; |
| 1433 | int handle = 0; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1434 | |
Felix Held | fcbb3c5 | 2019-06-20 14:01:54 +0200 | [diff] [blame] | 1435 | current = ALIGN_UP(current, 16); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1436 | printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current); |
| 1437 | |
| 1438 | se = (struct smbios_entry *)current; |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1439 | current += sizeof(*se); |
Felix Held | fcbb3c5 | 2019-06-20 14:01:54 +0200 | [diff] [blame] | 1440 | current = ALIGN_UP(current, 16); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1441 | |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1442 | se3 = (struct smbios_entry30 *)current; |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1443 | current += sizeof(*se3); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1444 | current = ALIGN_UP(current, 16); |
| 1445 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1446 | tables = current; |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1447 | update_max(len, max_struct_size, smbios_write_type0(¤t, handle++)); |
| 1448 | update_max(len, max_struct_size, smbios_write_type1(¤t, handle++)); |
| 1449 | |
| 1450 | /* The chassis handle is the next one */ |
| 1451 | update_max(len, max_struct_size, smbios_write_type2(¤t, handle, handle + 1)); |
Julien Viard de Galbert | 9a31dfe | 2018-02-22 16:39:58 +0100 | [diff] [blame] | 1452 | handle++; |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1453 | update_max(len, max_struct_size, smbios_write_type3(¤t, handle++)); |
Patrick Rudolph | 15589b4 | 2019-03-30 17:51:06 +0100 | [diff] [blame] | 1454 | |
| 1455 | struct smbios_type4 *type4 = (struct smbios_type4 *)current; |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1456 | update_max(len, max_struct_size, smbios_write_type4(¤t, handle++)); |
| 1457 | len += smbios_write_type7_cache_parameters(¤t, &handle, &max_struct_size, type4); |
| 1458 | update_max(len, max_struct_size, smbios_write_type11(¤t, &handle)); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1459 | if (CONFIG(ELOG)) |
Martin Roth | 898a775 | 2017-06-01 11:39:59 -0600 | [diff] [blame] | 1460 | update_max(len, max_struct_size, |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1461 | elog_smbios_write_type15(¤t, handle++)); |
Patrick Rudolph | 5e00780 | 2020-07-27 15:37:43 +0200 | [diff] [blame] | 1462 | |
| 1463 | const int type16 = handle; |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1464 | update_max(len, max_struct_size, smbios_write_type16(¤t, &handle)); |
Matt DeVillier | d1c1afd | 2016-09-02 21:41:26 -0500 | [diff] [blame] | 1465 | const int type17 = handle; |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1466 | update_max(len, max_struct_size, smbios_write_type17(¤t, &handle, type16)); |
Matt DeVillier | d1c1afd | 2016-09-02 21:41:26 -0500 | [diff] [blame] | 1467 | const int type19 = handle; |
Tim Chu | e41f595 | 2020-11-02 21:33:52 -0800 | [diff] [blame] | 1468 | update_max(len, max_struct_size, smbios_write_type19(¤t, &handle, type16)); |
Matt DeVillier | d1c1afd | 2016-09-02 21:41:26 -0500 | [diff] [blame] | 1469 | update_max(len, max_struct_size, |
| 1470 | smbios_write_type20(¤t, &handle, type17, type19)); |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1471 | update_max(len, max_struct_size, smbios_write_type32(¤t, handle++)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1472 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1473 | update_max(len, max_struct_size, smbios_walk_device_tree(all_devices, |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1474 | &handle, ¤t)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1475 | |
Angel Pons | bf2f91c | 2020-07-29 18:14:59 +0200 | [diff] [blame] | 1476 | update_max(len, max_struct_size, smbios_write_type127(¤t, handle++)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1477 | |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1478 | /* Install SMBIOS 2.1 entry point */ |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1479 | memset(se, 0, sizeof(*se)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1480 | memcpy(se->anchor, "_SM_", 4); |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1481 | se->length = sizeof(*se); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1482 | se->major_version = 3; |
| 1483 | se->minor_version = 0; |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 1484 | se->max_struct_size = max_struct_size; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1485 | se->struct_count = handle; |
| 1486 | memcpy(se->intermediate_anchor_string, "_DMI_", 5); |
| 1487 | |
| 1488 | se->struct_table_address = (u32)tables; |
| 1489 | se->struct_table_length = len; |
| 1490 | |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1491 | se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10, sizeof(*se) - 0x10); |
| 1492 | se->checksum = smbios_checksum((u8 *)se, sizeof(*se)); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1493 | |
| 1494 | /* Install SMBIOS 3.0 entry point */ |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1495 | memset(se3, 0, sizeof(*se3)); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1496 | memcpy(se3->anchor, "_SM3_", 5); |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1497 | se3->length = sizeof(*se3); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1498 | se3->major_version = 3; |
| 1499 | se3->minor_version = 0; |
| 1500 | |
| 1501 | se3->struct_table_address = (u64)tables; |
| 1502 | se3->struct_table_length = len; |
| 1503 | |
Angel Pons | 35b99c6 | 2021-06-28 15:36:23 +0200 | [diff] [blame] | 1504 | se3->checksum = smbios_checksum((u8 *)se3, sizeof(*se3)); |
Patrick Rudolph | 7a83582 | 2020-07-22 16:00:53 +0200 | [diff] [blame] | 1505 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1506 | return current; |
| 1507 | } |