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