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