blob: 8bc49b18adcce5f18cf9c19b637462d08fb716b5 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Sven Schnelle164bcfd2011-08-14 20:56:34 +02002
Sven Schnelle164bcfd2011-08-14 20:56:34 +02003#include <string.h>
4#include <smbios.h>
5#include <console/console.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +02006#include <version.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +02007#include <device/device.h>
8#include <arch/cpu.h>
9#include <cpu/x86/name.h>
Duncan Laurie472ec9c2012-06-23 16:13:42 -070010#include <elog.h>
Julius Werner9ff8f6f2015-02-23 14:31:09 -080011#include <endian.h>
Kane Chen33faac62014-07-27 12:54:44 -070012#include <memory_info.h>
13#include <spd.h>
14#include <cbmem.h>
Elyes HAOUASe2d152c2019-06-21 07:06:50 +020015#include <commonlib/helpers.h>
Christian Walter9e5b0622019-05-21 17:37:58 +020016#include <device/pci_ids.h>
17#include <device/pci_def.h>
18#include <device/pci.h>
Johnny Linc746a742020-06-03 11:44:22 +080019#include <drivers/vpd/vpd.h>
20#include <stdlib.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +020021
Patrick Rudolphfc5b8092019-03-30 17:37:28 +010022#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 Schnelle164bcfd2011-08-14 20:56:34 +020030static u8 smbios_checksum(u8 *p, u32 length)
31{
32 u8 ret = 0;
33 while (length--)
34 ret += *p++;
35 return -ret;
36}
37
Christian Walter9e5b0622019-05-21 17:37:58 +020038/* Get the device type 41 from the dev struct */
39static 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 Aladyshevd0df1d72017-08-01 15:52:46 +030073int smbios_add_string(u8 *start, const char *str)
Sven Schnelle164bcfd2011-08-14 20:56:34 +020074{
75 int i = 1;
Konstantin Aladyshevd0df1d72017-08-01 15:52:46 +030076 char *p = (char *)start;
Sven Schnelle164bcfd2011-08-14 20:56:34 +020077
Ben Gardner6b07cba2015-12-09 11:24:35 -060078 /*
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 HAOUASdbf30672016-08-21 17:37:15 +020085 for (;;) {
Sven Schnelle164bcfd2011-08-14 20:56:34 +020086 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 Aladyshevd0df1d72017-08-01 15:52:46 +0300102int smbios_string_table_len(u8 *start)
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200103{
Konstantin Aladyshevd0df1d72017-08-01 15:52:46 +0300104 char *p = (char *)start;
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200105 int i, len = 0;
106
Lee Leahy024b13d2017-03-16 13:41:11 -0700107 while (*p) {
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200108 i = strlen(p) + 1;
109 p += i;
110 len += i;
111 }
Konstantin Aladyshevd0df1d72017-08-01 15:52:46 +0300112
113 if (!len)
114 return 2;
115
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200116 return len + 1;
117}
118
Konstantin Aladyshevd0df1d72017-08-01 15:52:46 +0300119static int smbios_cpu_vendor(u8 *start)
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200120{
Rudolf Marek06253cd2012-02-25 23:51:12 +0100121 if (cpu_have_cpuid()) {
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700122 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 Marek06253cd2012-02-25 23:51:12 +0100131 }
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200132}
133
Konstantin Aladyshevd0df1d72017-08-01 15:52:46 +0300134static int smbios_processor_name(u8 *start)
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200135{
Nico Huberaa9643e2017-06-20 14:49:04 +0200136 u32 tmp[13];
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700137 const char *str = "Unknown Processor Name";
Rudolf Marek06253cd2012-02-25 23:51:12 +0100138 if (cpu_have_cpuid()) {
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700139 int i;
140 struct cpuid_result res = cpuid(0x80000000);
Rudolf Marek06253cd2012-02-25 23:51:12 +0100141 if (res.eax >= 0x80000004) {
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700142 int j = 0;
Rudolf Marek06253cd2012-02-25 23:51:12 +0100143 for (i = 0; i < 3; i++) {
144 res = cpuid(0x80000002 + i);
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700145 tmp[j++] = res.eax;
146 tmp[j++] = res.ebx;
147 tmp[j++] = res.ecx;
148 tmp[j++] = res.edx;
Rudolf Marek06253cd2012-02-25 23:51:12 +0100149 }
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700150 tmp[12] = 0;
151 str = (const char *)tmp;
Rudolf Marek06253cd2012-02-25 23:51:12 +0100152 }
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200153 }
Ryan Salsamendi1b5eda02017-06-11 18:50:32 -0700154 return smbios_add_string(start, str);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200155}
156
Angel Pons9630ced2020-07-29 18:29:28 +0200157static const char *get_dimm_manufacturer_name(const uint16_t mod_id)
Kane Chen33faac62014-07-27 12:54:44 -0700158{
159 switch (mod_id) {
Lijian Zhao6eaa7812019-05-16 07:32:42 -0700160 case 0x9b85:
Angel Pons9630ced2020-07-29 18:29:28 +0200161 return "Crucial";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700162 case 0x4304:
Angel Pons9630ced2020-07-29 18:29:28 +0200163 return "Ramaxel";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700164 case 0x4f01:
Angel Pons9630ced2020-07-29 18:29:28 +0200165 return "Transcend";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700166 case 0x9801:
Angel Pons9630ced2020-07-29 18:29:28 +0200167 return "Kingston";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700168 case 0x987f:
Angel Pons9630ced2020-07-29 18:29:28 +0200169 return "Hynix";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700170 case 0x9e02:
Angel Pons9630ced2020-07-29 18:29:28 +0200171 return "Corsair";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700172 case 0xb004:
Angel Pons9630ced2020-07-29 18:29:28 +0200173 return "OCZ";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700174 case 0xad80:
Angel Pons9630ced2020-07-29 18:29:28 +0200175 return "Hynix/Hyundai";
Lijian Zhao6eaa7812019-05-16 07:32:42 -0700176 case 0x3486:
Angel Pons9630ced2020-07-29 18:29:28 +0200177 return "Super Talent";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700178 case 0xcd04:
Angel Pons9630ced2020-07-29 18:29:28 +0200179 return "GSkill";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700180 case 0xce80:
Angel Pons9630ced2020-07-29 18:29:28 +0200181 return "Samsung";
Lee Leahy0b5678f2017-03-16 16:01:40 -0700182 case 0xfe02:
Angel Pons9630ced2020-07-29 18:29:28 +0200183 return "Elpida";
Lijian Zhao6eaa7812019-05-16 07:32:42 -0700184 case 0x2c80:
Angel Pons9630ced2020-07-29 18:29:28 +0200185 return "Micron";
186 default:
187 return NULL;
188 }
189}
Lee Leahy0b5678f2017-03-16 16:01:40 -0700190
Angel Pons9630ced2020-07-29 18:29:28 +0200191/* this function will fill the corresponding manufacturer */
192void 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 Chen33faac62014-07-27 12:54:44 -0700203 }
204}
205
Raul E Rangel50021cd2018-03-20 12:40:55 -0600206static void trim_trailing_whitespace(char *buffer, size_t buffer_size)
Richard Spiegelbd654802018-02-22 10:03:39 -0700207{
Raul E Rangel50021cd2018-03-20 12:40:55 -0600208 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 Ponsbf2f91c2020-07-29 18:14:59 +0200222static void smbios_fill_dimm_part_number(const char *part_number, struct smbios_type17 *t)
Raul E Rangel50021cd2018-03-20 12:40:55 -0600223{
Raul E Rangel50021cd2018-03-20 12:40:55 -0600224 int invalid;
225 size_t i, len;
Jacob Garber9172b692019-06-26 16:18:16 -0600226 char trimmed_part_number[DIMM_INFO_PART_NUMBER_SIZE];
Raul E Rangel50021cd2018-03-20 12:40:55 -0600227
Jacob Garber9172b692019-06-26 16:18:16 -0600228 strncpy(trimmed_part_number, part_number, sizeof(trimmed_part_number));
229 trimmed_part_number[sizeof(trimmed_part_number) - 1] = '\0';
Raul E Rangel50021cd2018-03-20 12:40:55 -0600230
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 Garber9172b692019-06-26 16:18:16 -0600235 trim_trailing_whitespace(trimmed_part_number, sizeof(trimmed_part_number));
Raul E Rangel50021cd2018-03-20 12:40:55 -0600236
237 len = strlen(trimmed_part_number);
Richard Spiegelbd654802018-02-22 10:03:39 -0700238
239 invalid = 0; /* assume valid */
Lijian Zhaob1fc13a2018-03-26 18:27:02 -0700240 for (i = 0; i < len; i++) {
Raul E Rangel50021cd2018-03-20 12:40:55 -0600241 if (trimmed_part_number[i] < ' ') {
Richard Spiegelbd654802018-02-22 10:03:39 -0700242 invalid = 1;
Raul E Rangel50021cd2018-03-20 12:40:55 -0600243 trimmed_part_number[i] = '*';
Richard Spiegelbd654802018-02-22 10:03:39 -0700244 }
245 }
Raul E Rangel50021cd2018-03-20 12:40:55 -0600246
Lijian Zhaob1fc13a2018-03-26 18:27:02 -0700247 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 Garber9172b692019-06-26 16:18:16 -0600251 char string_buffer[sizeof(trimmed_part_number) + 10];
Richard Spiegelbd654802018-02-22 10:03:39 -0700252
253 snprintf(string_buffer, sizeof(string_buffer), "Invalid (%s)",
Raul E Rangel50021cd2018-03-20 12:40:55 -0600254 trimmed_part_number);
Richard Spiegelbd654802018-02-22 10:03:39 -0700255 t->part_number = smbios_add_string(t->eos, string_buffer);
Raul E Rangel50021cd2018-03-20 12:40:55 -0600256 } else {
257 t->part_number = smbios_add_string(t->eos, trimmed_part_number);
258 }
Richard Spiegelbd654802018-02-22 10:03:39 -0700259}
260
Raul E Rangel99f54a62018-04-11 10:58:14 -0600261/* Encodes the SPD serial number into hex */
262static 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 Ponsbf2f91c2020-07-29 18:14:59 +0200268 dimm->serial[0], dimm->serial[1], dimm->serial[2], dimm->serial[3]);
Raul E Rangel99f54a62018-04-11 10:58:14 -0600269
270 t->serial_number = smbios_add_string(t->eos, serial);
271}
272
Kane Chen33faac62014-07-27 12:54:44 -0700273static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
Patrick Rudolph5e007802020-07-27 15:37:43 +0200274 unsigned long *current, int *handle,
275 int type16_handle)
Kane Chen33faac62014-07-27 12:54:44 -0700276{
277 struct smbios_type17 *t = (struct smbios_type17 *)*current;
Kane Chen33faac62014-07-27 12:54:44 -0700278
279 memset(t, 0, sizeof(struct smbios_type17));
280 t->memory_type = dimm->ddr_type;
Rob Barnes327f1052020-09-01 10:26:57 -0600281 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 Chen33faac62014-07-27 12:54:44 -0700289 t->type = SMBIOS_MEMORY_DEVICE;
Julien Viard de Galbert99891712018-01-24 11:04:46 +0100290 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 Chen33faac62014-07-27 12:54:44 -0700296 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 Leahy0b5678f2017-03-16 16:01:40 -0700300 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 Chen33faac62014-07-27 12:54:44 -0700315 }
316
Timothy Pearson4785f2a2015-03-27 23:05:36 -0500317 smbios_fill_dimm_manufacturer_from_id(dimm->mod_id, t);
Raul E Rangel99f54a62018-04-11 10:58:14 -0600318 smbios_fill_dimm_serial_number(dimm, t);
Lijian Zhao10ea93c2019-04-11 00:45:10 -0700319 smbios_fill_dimm_locator(dimm, t);
Kane Chen33faac62014-07-27 12:54:44 -0700320
321 /* put '\0' in the end of data */
Richard Spiegelbd654802018-02-22 10:03:39 -0700322 dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0';
323 smbios_fill_dimm_part_number((char *)dimm->module_part_number, t);
Kane Chen33faac62014-07-27 12:54:44 -0700324
Christian Walterf9723222019-05-28 10:37:24 +0200325 /* 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 Chu0c094ae2021-01-12 01:44:37 -0800330 /* 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 Chen33faac62014-07-27 12:54:44 -0700344 /* Synchronous = 1 */
Tim Chu0c094ae2021-01-12 01:44:37 -0800345 t->type_detail |= MEMORY_TYPE_DETAIL_SYNCHRONOUS;
Kane Chen33faac62014-07-27 12:54:44 -0700346 /* no handle for error information */
347 t->memory_error_information_handle = 0xFFFE;
348 t->attributes = dimm->rank_per_dimm;
349 t->handle = *handle;
Patrick Rudolph5e007802020-07-27 15:37:43 +0200350 t->phys_memory_array_handle = type16_handle;
351
Kane Chen33faac62014-07-27 12:54:44 -0700352 *handle += 1;
353 t->length = sizeof(struct smbios_type17) - 2;
354 return t->length + smbios_string_table_len(t->eos);
355}
356
Johnny Linc746a742020-06-03 11:44:22 +0800357#define VERSION_VPD "firmware_version"
358static 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
381static 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 Schnelle164bcfd2011-08-14 20:56:34 +0200412static int smbios_write_type0(unsigned long *current, int handle)
413{
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200414 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älkkic36af7b2014-11-18 12:41:16 +0200423 t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date);
Christian Gmeiner5e272a42013-02-04 16:22:46 +0100424
Raul E Rangel6d26d802021-02-05 16:44:18 -0700425 if (CONFIG(CHROMEOS) && CONFIG(HAVE_ACPI_TABLES)) {
Kyösti Mälkki0fcbd3a2020-12-20 08:27:21 +0200426 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 Linc746a742020-06-03 11:44:22 +0800431 t->bios_version = smbios_add_string(t->eos, get_bios_version());
Lee Leahy67358712016-06-08 12:47:07 -0700432 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 Lin6fe0cab2013-01-22 18:57:56 +0800435
Elyes HAOUAS358cbb32019-02-14 14:19:22 +0100436 if (CONFIG_ROM_SIZE >= 1 * GiB) {
Angel Ponsbf2f91c2020-07-29 18:14:59 +0200437 t->extended_bios_rom_size = DIV_ROUND_UP(CONFIG_ROM_SIZE, GiB) | (1 << 14);
Elyes HAOUAS358cbb32019-02-14 14:19:22 +0100438 } else {
439 t->extended_bios_rom_size = DIV_ROUND_UP(CONFIG_ROM_SIZE, MiB);
440 }
441
Elyes HAOUAS94ad3762019-02-15 17:39:56 +0100442 t->system_bios_major_release = coreboot_major_revision;
443 t->system_bios_minor_release = coreboot_minor_revision;
444
Tim Chuf2f53c42020-09-07 02:30:19 -0700445 smbios_ec_revision(&t->ec_major_release, &t->ec_minor_release);
446
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200447 t->bios_characteristics =
448 BIOS_CHARACTERISTICS_PCI_SUPPORTED |
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200449 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
450 BIOS_CHARACTERISTICS_UPGRADEABLE;
451
Julius Wernercd49cce2019-03-05 16:53:33 -0800452 if (CONFIG(CARDBUS_PLUGIN_SUPPORT))
Martin Roth898a7752017-06-01 11:39:59 -0600453 t->bios_characteristics |= BIOS_CHARACTERISTICS_PC_CARD;
454
Julius Wernercd49cce2019-03-05 16:53:33 -0800455 if (CONFIG(HAVE_ACPI_TABLES))
Martin Roth898a7752017-06-01 11:39:59 -0600456 t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI;
457
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200458 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 HAOUAS28fa33c2019-01-25 13:46:43 +0100464static 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 Jang92bcc4f2020-07-24 10:36:18 +0800472 if (CONFIG(XEON_SP_COMMON_BASE))
473 return 0x36;
Elyes HAOUAS28fa33c2019-01-25 13:46:43 +0100474
475 return 0x02; /* Unknown */
476}
477
Tim Chua96eaf82020-11-12 03:15:39 -0800478unsigned 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 Jang92bcc4f2020-07-24 10:36:18 +0800484unsigned int __weak smbios_processor_external_clock(void)
485{
486 return 0; /* Unknown */
487}
488
489unsigned int __weak smbios_processor_characteristics(void)
490{
491 return 0;
492}
493
494unsigned int __weak smbios_processor_family(struct cpuid_result res)
495{
496 return (res.eax > 0) ? 0x0c : 0x6;
497}
498
Morgan Jang8ae391d2020-10-06 16:26:17 +0800499unsigned int __weak smbios_cache_error_correction_type(u8 level)
500{
501 return SMBIOS_CACHE_ERROR_CORRECTION_UNKNOWN;
502}
503
504unsigned int __weak smbios_cache_sram_type(void)
505{
506 return SMBIOS_CACHE_SRAM_TYPE_UNKNOWN;
507}
508
509unsigned int __weak smbios_cache_conf_operation_mode(u8 level)
510{
511 return SMBIOS_CACHE_OP_MODE_UNKNOWN; /* Unknown */
512}
513
Patrick Rudolphb01ac7e2020-07-26 14:23:37 +0200514/* Returns the processor voltage in 100mV units */
515unsigned int __weak smbios_cpu_get_voltage(void)
516{
517 return 0; /* Unknown */
518}
519
Morgan Jang8ae391d2020-10-06 16:26:17 +0800520static 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 Schnelle164bcfd2011-08-14 20:56:34 +0200550static 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 Ponsbf2f91c2020-07-29 18:14:59 +0200559 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 Huberebd8a4f2017-11-01 09:49:16 +0100562 t->sku = smbios_add_string(t->eos, smbios_system_sku());
563 t->version = smbios_add_string(t->eos, smbios_system_version());
Marc Jonesf43ba9c2015-06-09 21:10:43 -0600564#ifdef CONFIG_MAINBOARD_FAMILY
Nico Huberebd8a4f2017-11-01 09:49:16 +0100565 t->family = smbios_add_string(t->eos, CONFIG_MAINBOARD_FAMILY);
Marc Jonesf43ba9c2015-06-09 21:10:43 -0600566#endif
Nico Huberebd8a4f2017-11-01 09:49:16 +0100567 smbios_system_set_uuid(t->uuid);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200568 len = t->length + smbios_string_table_len(t->eos);
569 *current += len;
570 return len;
571}
572
Angel Ponsbf2f91c2020-07-29 18:14:59 +0200573static int smbios_write_type2(unsigned long *current, int handle, const int chassis_handle)
Vladimir Serbinenko47089f22014-03-02 19:14:44 +0100574{
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 Ponsbf2f91c2020-07-29 18:14:59 +0200582 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 Serbinenko47089f22014-03-02 19:14:44 +0100585 t->version = smbios_add_string(t->eos, smbios_mainboard_version());
Julien Viard de Galbert9a31dfe2018-02-22 16:39:58 +0100586 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 Serbinenko47089f22014-03-02 19:14:44 +0100592 len = t->length + smbios_string_table_len(t->eos);
593 *current += len;
594 return len;
595}
596
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200597static 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 Ponsbf2f91c2020-07-29 18:14:59 +0200606 t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer());
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200607 t->bootup_state = SMBIOS_STATE_SAFE;
608 t->power_supply_state = SMBIOS_STATE_SAFE;
609 t->thermal_state = SMBIOS_STATE_SAFE;
Mathew Kinga7d55cf2019-07-31 15:50:15 -0600610 t->_type = smbios_mainboard_enclosure_type();
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200611 t->security_status = SMBIOS_STATE_SAFE;
JingleHsuWiwynn4330b962021-01-28 09:13:42 +0800612 t->number_of_power_cords = smbios_chassis_power_cords();
Johnny Lind3440542020-01-30 18:21:22 +0800613 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 Schnelle164bcfd2011-08-14 20:56:34 +0200616 len = t->length + smbios_string_table_len(t->eos);
617 *current += len;
618 return len;
619}
620
621static int smbios_write_type4(unsigned long *current, int handle)
622{
Patrick Rudolphb01ac7e2020-07-26 14:23:37 +0200623 unsigned int cpu_voltage;
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200624 struct cpuid_result res;
625 struct smbios_type4 *t = (struct smbios_type4 *)*current;
626 int len = sizeof(struct smbios_type4);
Morgan Jang92bcc4f2020-07-24 10:36:18 +0800627 uint16_t characteristics = 0;
Tim Chu27bf0c82020-09-16 00:34:08 -0700628 static unsigned int cnt = 0;
629 char buf[8];
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200630
Rudolf Marek06253cd2012-02-25 23:51:12 +0100631 /* Provide sane defaults even for CPU without CPUID */
632 res.eax = res.edx = 0;
633 res.ebx = 0x10000;
634
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700635 if (cpu_have_cpuid())
Rudolf Marek06253cd2012-02-25 23:51:12 +0100636 res = cpuid(1);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200637
638 memset(t, 0, sizeof(struct smbios_type4));
639 t->type = SMBIOS_PROCESSOR_INFORMATION;
640 t->handle = handle;
641 t->length = len - 2;
Tim Chu27bf0c82020-09-16 00:34:08 -0700642
643 snprintf(buf, sizeof(buf), "CPU%d", cnt++);
644 t->socket_designation = smbios_add_string(t->eos, buf);
645
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200646 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 Jang92bcc4f2020-07-24 10:36:18 +0800650 t->processor_family = smbios_processor_family(res);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200651 t->processor_type = 3; /* System Processor */
Andrey Petrov515ef382019-11-15 13:19:08 -0800652 /*
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 Rudolph7a835822020-07-22 16:00:53 +0200668 t->core_count2 = leaf_b_cores / leaf_b_threads;
669 t->core_count = t->core_count2 > 0xff ? 0xff : t->core_count2;
Francois Toguo597922e2019-03-27 18:13:07 -0700670 t->thread_count2 = leaf_b_cores;
671 t->thread_count = t->thread_count2 > 0xff ? 0xff : t->thread_count2;
Andrey Petrov515ef382019-11-15 13:19:08 -0800672 } else {
673 t->core_count = (res.ebx >> 16) & 0xff;
Patrick Rudolph7a835822020-07-22 16:00:53 +0200674 t->core_count2 = t->core_count;
675 t->thread_count2 = t->core_count2;
Francois Toguo597922e2019-03-27 18:13:07 -0700676 t->thread_count = t->thread_count2;
Andrey Petrov515ef382019-11-15 13:19:08 -0800677 }
Andrey Petrov2e032f02019-10-23 15:31:51 -0700678 /* Assume we enable all the cores always, capped only by MAX_CPUS */
Andrey Petrova7fb2302019-11-07 09:48:41 -0800679 t->core_enabled = MIN(t->core_count, CONFIG_MAX_CPUS);
Patrick Rudolph7a835822020-07-22 16:00:53 +0200680 t->core_enabled2 = MIN(t->core_count2, CONFIG_MAX_CPUS);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200681 t->l1_cache_handle = 0xffff;
682 t->l2_cache_handle = 0xffff;
683 t->l3_cache_handle = 0xffff;
Johnny Lind3440542020-01-30 18:21:22 +0800684 t->serial_number = smbios_add_string(t->eos, smbios_processor_serial_number());
Angel Ponsbf2f91c2020-07-29 18:14:59 +0200685 t->status = SMBIOS_PROCESSOR_STATUS_CPU_ENABLED | SMBIOS_PROCESSOR_STATUS_POPULATED;
Elyes HAOUAS28fa33c2019-01-25 13:46:43 +0100686 t->processor_upgrade = get_socket_type();
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200687 len = t->length + smbios_string_table_len(t->eos);
Andrey Petrov2e032f02019-10-23 15:31:51 -0700688 if (cpu_have_cpuid() && cpuid_get_max_func() >= 0x16) {
Andrey Petrov2e032f02019-10-23 15:31:51 -0700689 t->current_speed = cpuid_eax(0x16); /* base frequency */
Morgan Jang92bcc4f2020-07-24 10:36:18 +0800690 t->external_clock = cpuid_ecx(0x16);
Andrey Petrov2e032f02019-10-23 15:31:51 -0700691 } else {
Andrey Petrov2e032f02019-10-23 15:31:51 -0700692 t->current_speed = smbios_cpu_get_current_speed_mhz();
Morgan Jang92bcc4f2020-07-24 10:36:18 +0800693 t->external_clock = smbios_processor_external_clock();
Andrey Petrov2e032f02019-10-23 15:31:51 -0700694 }
Morgan Jang92bcc4f2020-07-24 10:36:18 +0800695
Tim Chu40d45992020-12-14 21:44:40 -0800696 /* This field identifies a capability for the system, not the processor itself. */
697 t->max_speed = smbios_cpu_get_max_speed_mhz();
698
Morgan Jang92bcc4f2020-07-24 10:36:18 +0800699 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 Rudolphb01ac7e2020-07-26 14:23:37 +0200716 cpu_voltage = smbios_cpu_get_voltage();
717 if (cpu_voltage > 0)
718 t->voltage = 0x80 | cpu_voltage;
Morgan Jang92bcc4f2020-07-24 10:36:18 +0800719
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200720 *current += len;
721 return len;
722}
723
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100724/*
725 * Write SMBIOS type 7.
726 * Fill in some fields with constant values, as gathering the information
727 * from CPUID is impossible.
728 */
Angel Ponsbf2f91c2020-07-29 18:14:59 +0200729static 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 Rudolphfc5b8092019-03-30 17:37:28 +0100737{
738 struct smbios_type7 *t = (struct smbios_type7 *)*current;
739 int len = sizeof(struct smbios_type7);
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100740 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 Jang8ae391d2020-10-06 16:26:17 +0800747 snprintf(buf, sizeof(buf), "CACHE%x", level);
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100748 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 Jang8ae391d2020-10-06 16:26:17 +0800753 SMBIOS_CACHE_CONF_OPERATION_MODE(smbios_cache_conf_operation_mode(level));
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100754
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 Rudolph8f702672019-04-13 09:44:02 +0200762 if (max_cache_size < (SMBIOS_CACHE_SIZE_MASK * 64 * KiB))
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100763 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 Jang8ae391d2020-10-06 16:26:17 +0800793 t->error_correction_type = smbios_cache_error_correction_type(level);
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100794 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 Ponsbf2f91c2020-07-29 18:14:59 +0200802static enum smbios_cache_associativity smbios_cache_associativity(const u8 num)
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100803{
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 Rudolph15589b42019-03-30 17:51:06 +0100841 * @param type4 Pointer to SMBIOS type 4 structure
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100842 */
843static int smbios_write_type7_cache_parameters(unsigned long *current,
844 int *handle,
Patrick Rudolph15589b42019-03-30 17:51:06 +0100845 int *max_struct_size,
846 struct smbios_type4 *type4)
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100847{
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 Jang8ae391d2020-10-06 16:26:17 +0800888 const size_t cache_size = assoc * partitions * cache_line_size * number_of_sets
889 * get_number_of_caches(res);
Patrick Rudolphfc5b8092019-03-30 17:37:28 +0100890
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 Rudolph15589b42019-03-30 17:51:06 +0100915 const int h = (*handle)++;
916
917 update_max(len, *max_struct_size, smbios_write_type7(current, h,
Morgan Jang8ae391d2020-10-06 16:26:17 +0800918 level, smbios_cache_sram_type(), associativity,
Patrick Rudolph15589b42019-03-30 17:51:06 +0100919 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 Rudolphfc5b8092019-03-30 17:37:28 +0100934 };
935
936 return len;
937}
BryantOu4a8e58f2020-04-20 19:45:20 -0700938
939int 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 Zhaoe98a7512019-04-11 23:28:09 -0700966int 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 Pons3c13da72020-07-29 18:23:23 +0200980 t->slot_designation = smbios_add_string(t->eos, name ? name : "SLOT");
Lijian Zhaoe98a7512019-04-11 23:28:09 -0700981 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 Rudolphfc5b8092019-03-30 17:37:28 +0100998
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200999static int smbios_write_type11(unsigned long *current, int *handle)
Peter Stugec392b642013-07-06 19:51:12 +02001000{
1001 struct smbios_type11 *t = (struct smbios_type11 *)*current;
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +02001002 int len;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001003 struct device *dev;
Peter Stugec392b642013-07-06 19:51:12 +02001004
Lee Leahy0b5678f2017-03-16 16:01:40 -07001005 memset(t, 0, sizeof(*t));
Peter Stugec392b642013-07-06 19:51:12 +02001006 t->type = SMBIOS_OEM_STRINGS;
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +02001007 t->handle = *handle;
Lee Leahy0b5678f2017-03-16 16:01:40 -07001008 t->length = len = sizeof(*t) - 2;
Peter Stugec392b642013-07-06 19:51:12 +02001009
Elyes HAOUASdbf30672016-08-21 17:37:15 +02001010 for (dev = all_devices; dev; dev = dev->next) {
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +02001011 if (dev->ops && dev->ops->get_smbios_strings)
1012 dev->ops->get_smbios_strings(dev, t);
1013 }
1014
1015 if (t->count == 0) {
Lee Leahy0b5678f2017-03-16 16:01:40 -07001016 memset(t, 0, sizeof(*t));
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +02001017 return 0;
1018 }
Peter Stugec392b642013-07-06 19:51:12 +02001019
1020 len += smbios_string_table_len(t->eos);
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +02001021
Peter Stugec392b642013-07-06 19:51:12 +02001022 *current += len;
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +02001023 (*handle)++;
Peter Stugec392b642013-07-06 19:51:12 +02001024 return len;
1025}
1026
Patrick Rudolph5e007802020-07-27 15:37:43 +02001027static 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 Chu1ee8ddc2021-01-22 01:10:45 -08001033 uint64_t max_capacity;
Patrick Rudolph5e007802020-07-27 15:37:43 +02001034
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 Chua96eaf82020-11-12 03:15:39 -08001059 t->memory_error_correction = smbios_memory_error_correction_type(meminfo);
Patrick Rudolph5e007802020-07-27 15:37:43 +02001060
1061 /* no error information handle available */
1062 t->memory_error_information_handle = 0xFFFE;
Tim Chu1ee8ddc2021-01-22 01:10:45 -08001063 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 Rudolph5e007802020-07-27 15:37:43 +02001070 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
1079static int smbios_write_type17(unsigned long *current, int *handle, int type16)
Kane Chen33faac62014-07-27 12:54:44 -07001080{
1081 int len = sizeof(struct smbios_type17);
Iru Cai36775202016-03-09 23:22:58 +08001082 int totallen = 0;
Kane Chen33faac62014-07-27 12:54:44 -07001083 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 Ponsbf2f91c2020-07-29 18:14:59 +02001091 for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) {
Kane Chen33faac62014-07-27 12:54:44 -07001092 struct dimm_info *dimm;
1093 dimm = &meminfo->dimm[i];
Patrick Rudolph5e007802020-07-27 15:37:43 +02001094 /*
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 Chen33faac62014-07-27 12:54:44 -07001101 *current += len;
Iru Cai36775202016-03-09 23:22:58 +08001102 totallen += len;
Kane Chen33faac62014-07-27 12:54:44 -07001103 }
Iru Cai36775202016-03-09 23:22:58 +08001104 return totallen;
Kane Chen33faac62014-07-27 12:54:44 -07001105}
1106
Tim Chue41f5952020-11-02 21:33:52 -08001107static int smbios_write_type19(unsigned long *current, int *handle, int type16)
Patrick Rudolph604295e2020-07-21 14:53:37 +02001108{
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 Chue41f5952020-11-02 21:33:52 -08001123 t->memory_array_handle = type16;
Patrick Rudolph604295e2020-07-21 14:53:37 +02001124
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 Schnelle164bcfd2011-08-14 20:56:34 +02001158static 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 Rudolphfe98e902018-03-27 16:17:12 +02001171int 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 Laurie21a78702013-05-23 14:17:05 -07001198int smbios_write_type41(unsigned long *current, int *handle,
1199 const char *name, u8 instance, u16 segment,
Christian Waltere6afab12019-05-21 17:22:49 +02001200 u8 bus, u8 device, u8 function, u8 device_type)
Duncan Laurie21a78702013-05-23 14:17:05 -07001201{
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 Waltere6afab12019-05-21 17:22:49 +02001210 t->device_type = device_type;
Duncan Laurie21a78702013-05-23 14:17:05 -07001211 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 Schnelle164bcfd2011-08-14 20:56:34 +02001224static 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 Walter9e5b0622019-05-21 17:37:58 +02001237/* Generate Type41 entries from devicetree */
1238static int smbios_walk_device_tree_type41(struct device *dev, int *handle,
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001239 unsigned long *current)
Christian Walter9e5b0622019-05-21 17:37:58 +02001240{
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 Rudolphf5b93692019-04-12 15:59:40 +02001269/* Generate Type9 entries from devicetree */
1270static 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 Ponsbf2f91c2020-07-29 18:14:59 +02001319static int smbios_walk_device_tree(struct device *tree, int *handle, unsigned long *current)
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001320{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001321 struct device *dev;
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001322 int len = 0;
1323
Elyes HAOUASdbf30672016-08-21 17:37:15 +02001324 for (dev = tree; dev; dev = dev->next) {
Naresh G Solanki20c893e2018-06-05 18:58:53 +05301325 if (dev->enabled && dev->ops && dev->ops->get_smbios_data) {
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001326 printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev_name(dev));
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001327 len += dev->ops->get_smbios_data(dev, handle, current);
Naresh G Solanki20c893e2018-06-05 18:58:53 +05301328 }
Patrick Rudolphf5b93692019-04-12 15:59:40 +02001329 len += smbios_walk_device_tree_type9(dev, handle, current);
Christian Walter9e5b0622019-05-21 17:37:58 +02001330 len += smbios_walk_device_tree_type41(dev, handle, current);
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001331 }
1332 return len;
1333}
1334
1335unsigned long smbios_write_tables(unsigned long current)
1336{
1337 struct smbios_entry *se;
Patrick Rudolph7a835822020-07-22 16:00:53 +02001338 struct smbios_entry30 *se3;
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001339 unsigned long tables;
Ben Frisch72af5d72015-05-09 19:52:18 -05001340 int len = 0;
1341 int max_struct_size = 0;
1342 int handle = 0;
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001343
Felix Heldfcbb3c52019-06-20 14:01:54 +02001344 current = ALIGN_UP(current, 16);
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001345 printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current);
1346
1347 se = (struct smbios_entry *)current;
1348 current += sizeof(struct smbios_entry);
Felix Heldfcbb3c52019-06-20 14:01:54 +02001349 current = ALIGN_UP(current, 16);
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001350
Patrick Rudolph7a835822020-07-22 16:00:53 +02001351 se3 = (struct smbios_entry30 *)current;
1352 current += sizeof(struct smbios_entry30);
1353 current = ALIGN_UP(current, 16);
1354
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001355 tables = current;
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001356 update_max(len, max_struct_size, smbios_write_type0(&current, handle++));
1357 update_max(len, max_struct_size, smbios_write_type1(&current, handle++));
1358
1359 /* The chassis handle is the next one */
1360 update_max(len, max_struct_size, smbios_write_type2(&current, handle, handle + 1));
Julien Viard de Galbert9a31dfe2018-02-22 16:39:58 +01001361 handle++;
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001362 update_max(len, max_struct_size, smbios_write_type3(&current, handle++));
Patrick Rudolph15589b42019-03-30 17:51:06 +01001363
1364 struct smbios_type4 *type4 = (struct smbios_type4 *)current;
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001365 update_max(len, max_struct_size, smbios_write_type4(&current, handle++));
1366 len += smbios_write_type7_cache_parameters(&current, &handle, &max_struct_size, type4);
1367 update_max(len, max_struct_size, smbios_write_type11(&current, &handle));
Julius Wernercd49cce2019-03-05 16:53:33 -08001368 if (CONFIG(ELOG))
Martin Roth898a7752017-06-01 11:39:59 -06001369 update_max(len, max_struct_size,
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001370 elog_smbios_write_type15(&current, handle++));
Patrick Rudolph5e007802020-07-27 15:37:43 +02001371
1372 const int type16 = handle;
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001373 update_max(len, max_struct_size, smbios_write_type16(&current, &handle));
1374 update_max(len, max_struct_size, smbios_write_type17(&current, &handle, type16));
Tim Chue41f5952020-11-02 21:33:52 -08001375 update_max(len, max_struct_size, smbios_write_type19(&current, &handle, type16));
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001376 update_max(len, max_struct_size, smbios_write_type32(&current, handle++));
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001377
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001378 update_max(len, max_struct_size, smbios_walk_device_tree(all_devices,
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001379 &handle, &current));
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001380
Angel Ponsbf2f91c2020-07-29 18:14:59 +02001381 update_max(len, max_struct_size, smbios_write_type127(&current, handle++));
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001382
Patrick Rudolph7a835822020-07-22 16:00:53 +02001383 /* Install SMBIOS 2.1 entry point */
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001384 memset(se, 0, sizeof(struct smbios_entry));
1385 memcpy(se->anchor, "_SM_", 4);
1386 se->length = sizeof(struct smbios_entry);
Patrick Rudolph7a835822020-07-22 16:00:53 +02001387 se->major_version = 3;
1388 se->minor_version = 0;
Ben Frisch72af5d72015-05-09 19:52:18 -05001389 se->max_struct_size = max_struct_size;
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001390 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 Ponsbf2f91c2020-07-29 18:14:59 +02001397 sizeof(struct smbios_entry) - 0x10);
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001398 se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry));
Patrick Rudolph7a835822020-07-22 16:00:53 +02001399
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 Schnelle164bcfd2011-08-14 20:56:34 +02001412 return current;
1413}