Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Timothy Pearson | 821217b | 2015-03-27 22:47:25 -0500 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 5 | * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <smbios.h> |
| 21 | #include <console/console.h> |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 22 | #include <version.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 23 | #include <device/device.h> |
| 24 | #include <arch/cpu.h> |
| 25 | #include <cpu/x86/name.h> |
Duncan Laurie | 472ec9c | 2012-06-23 16:13:42 -0700 | [diff] [blame] | 26 | #include <elog.h> |
Julius Werner | 9ff8f6f | 2015-02-23 14:31:09 -0800 | [diff] [blame] | 27 | #include <endian.h> |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 28 | #include <memory_info.h> |
| 29 | #include <spd.h> |
| 30 | #include <cbmem.h> |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 31 | #if CONFIG_CHROMEOS |
| 32 | #include <vendorcode/google/chromeos/gnvs.h> |
| 33 | #endif |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 34 | |
| 35 | static u8 smbios_checksum(u8 *p, u32 length) |
| 36 | { |
| 37 | u8 ret = 0; |
| 38 | while (length--) |
| 39 | ret += *p++; |
| 40 | return -ret; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | int smbios_add_string(char *start, const char *str) |
| 45 | { |
| 46 | int i = 1; |
| 47 | char *p = start; |
| 48 | |
Ben Gardner | 6b07cba | 2015-12-09 11:24:35 -0600 | [diff] [blame] | 49 | /* |
| 50 | * Return 0 as required for empty strings. |
| 51 | * See Section 6.1.3 "Text Strings" of the SMBIOS specification. |
| 52 | */ |
| 53 | if (*str == '\0') |
| 54 | return 0; |
| 55 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 56 | for(;;) { |
| 57 | if (!*p) { |
| 58 | strcpy(p, str); |
| 59 | p += strlen(str); |
| 60 | *p++ = '\0'; |
| 61 | *p++ = '\0'; |
| 62 | return i; |
| 63 | } |
| 64 | |
| 65 | if (!strcmp(p, str)) |
| 66 | return i; |
| 67 | |
| 68 | p += strlen(p)+1; |
| 69 | i++; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | int smbios_string_table_len(char *start) |
| 74 | { |
| 75 | char *p = start; |
| 76 | int i, len = 0; |
| 77 | |
| 78 | while(*p) { |
| 79 | i = strlen(p) + 1; |
| 80 | p += i; |
| 81 | len += i; |
| 82 | } |
| 83 | return len + 1; |
| 84 | } |
| 85 | |
| 86 | static int smbios_cpu_vendor(char *start) |
| 87 | { |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 88 | char tmp[13] = "Unknown"; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 89 | u32 *_tmp = (u32 *)tmp; |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 90 | struct cpuid_result res; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 91 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 92 | if (cpu_have_cpuid()) { |
| 93 | res = cpuid(0); |
| 94 | _tmp[0] = res.ebx; |
| 95 | _tmp[1] = res.edx; |
| 96 | _tmp[2] = res.ecx; |
| 97 | tmp[12] = '\0'; |
| 98 | } |
| 99 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 100 | return smbios_add_string(start, tmp); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static int smbios_processor_name(char *start) |
| 104 | { |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 105 | char tmp[49] = "Unknown Processor Name"; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 106 | u32 *_tmp = (u32 *)tmp; |
| 107 | struct cpuid_result res; |
| 108 | int i; |
| 109 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 110 | if (cpu_have_cpuid()) { |
| 111 | res = cpuid(0x80000000); |
| 112 | if (res.eax >= 0x80000004) { |
| 113 | for (i = 0; i < 3; i++) { |
| 114 | res = cpuid(0x80000002 + i); |
| 115 | _tmp[i * 4 + 0] = res.eax; |
| 116 | _tmp[i * 4 + 1] = res.ebx; |
| 117 | _tmp[i * 4 + 2] = res.ecx; |
| 118 | _tmp[i * 4 + 3] = res.edx; |
| 119 | } |
| 120 | tmp[48] = 0; |
| 121 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 122 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 123 | return smbios_add_string(start, tmp); |
| 124 | } |
| 125 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 126 | /* this function will fill the corresponding manufacturer */ |
Timothy Pearson | 4785f2a | 2015-03-27 23:05:36 -0500 | [diff] [blame] | 127 | void smbios_fill_dimm_manufacturer_from_id(uint16_t mod_id, struct smbios_type17 *t) |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 128 | { |
| 129 | switch (mod_id) { |
Timothy Pearson | cfbcba5 | 2015-07-28 09:22:59 -0500 | [diff] [blame] | 130 | case 0x2c80: |
| 131 | t->manufacturer = smbios_add_string(t->eos, |
| 132 | "Crucial"); |
| 133 | break; |
Timothy Pearson | ace3525 | 2015-06-25 18:37:58 -0500 | [diff] [blame] | 134 | case 0x9801: |
| 135 | t->manufacturer = smbios_add_string(t->eos, |
| 136 | "Kingston"); |
| 137 | break; |
Timothy Pearson | 821217b | 2015-03-27 22:47:25 -0500 | [diff] [blame] | 138 | case 0x987f: |
| 139 | t->manufacturer = smbios_add_string(t->eos, |
| 140 | "Hynix"); |
| 141 | break; |
Timothy Pearson | ace3525 | 2015-06-25 18:37:58 -0500 | [diff] [blame] | 142 | case 0x9e02: |
| 143 | t->manufacturer = smbios_add_string(t->eos, |
| 144 | "Corsair"); |
| 145 | break; |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 146 | case 0xad80: |
| 147 | t->manufacturer = smbios_add_string(t->eos, |
| 148 | "Hynix/Hyundai"); |
| 149 | break; |
| 150 | case 0xce80: |
| 151 | t->manufacturer = smbios_add_string(t->eos, |
| 152 | "Samsung"); |
| 153 | break; |
| 154 | case 0xfe02: |
| 155 | t->manufacturer = smbios_add_string(t->eos, |
| 156 | "Elpida"); |
| 157 | break; |
Timothy Pearson | 821217b | 2015-03-27 22:47:25 -0500 | [diff] [blame] | 158 | case 0xff2c: |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 159 | t->manufacturer = smbios_add_string(t->eos, |
Timothy Pearson | 821217b | 2015-03-27 22:47:25 -0500 | [diff] [blame] | 160 | "Micron"); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 161 | break; |
Timothy Pearson | 821217b | 2015-03-27 22:47:25 -0500 | [diff] [blame] | 162 | default: { |
| 163 | char string_buffer[256]; |
| 164 | snprintf(string_buffer, sizeof(string_buffer), |
| 165 | "Unknown (%x)", mod_id); |
| 166 | t->manufacturer = smbios_add_string(t->eos, |
| 167 | string_buffer); |
| 168 | break; |
| 169 | } |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
| 173 | static int create_smbios_type17_for_dimm(struct dimm_info *dimm, |
| 174 | unsigned long *current, int *handle) |
| 175 | { |
| 176 | struct smbios_type17 *t = (struct smbios_type17 *)*current; |
| 177 | uint8_t length; |
| 178 | char locator[40]; |
| 179 | |
| 180 | memset(t, 0, sizeof(struct smbios_type17)); |
| 181 | t->memory_type = dimm->ddr_type; |
| 182 | t->clock_speed = dimm->ddr_frequency; |
| 183 | t->speed = dimm->ddr_frequency; |
| 184 | t->type = SMBIOS_MEMORY_DEVICE; |
| 185 | t->size = dimm->dimm_size; |
| 186 | t->data_width = 8 * (1 << (dimm->bus_width & 0x7)); |
| 187 | t->total_width = t->data_width + 8 * ((dimm->bus_width & 0x18) >> 3); |
| 188 | |
| 189 | switch (dimm->mod_type) { |
| 190 | case SPD_RDIMM: |
| 191 | case SPD_MINI_RDIMM: |
| 192 | t->form_factor = MEMORY_FORMFACTOR_RIMM; |
| 193 | break; |
| 194 | case SPD_UDIMM: |
| 195 | case SPD_MICRO_DIMM: |
| 196 | case SPD_MINI_UDIMM: |
| 197 | t->form_factor = MEMORY_FORMFACTOR_DIMM; |
| 198 | break; |
| 199 | case SPD_SODIMM: |
| 200 | t->form_factor = MEMORY_FORMFACTOR_SODIMM; |
| 201 | break; |
| 202 | default: |
| 203 | t->form_factor = MEMORY_FORMFACTOR_UNKNOWN; |
| 204 | break; |
| 205 | } |
| 206 | |
Timothy Pearson | 4785f2a | 2015-03-27 23:05:36 -0500 | [diff] [blame] | 207 | smbios_fill_dimm_manufacturer_from_id(dimm->mod_id, t); |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 208 | /* put '\0' in the end of data */ |
| 209 | length = sizeof(dimm->serial); |
| 210 | dimm->serial[length - 1] = '\0'; |
| 211 | if (dimm->serial[0] == 0) |
| 212 | t->serial_number = smbios_add_string(t->eos, "None"); |
| 213 | else |
| 214 | t->serial_number = smbios_add_string(t->eos, |
| 215 | (const char *)dimm->serial); |
| 216 | |
| 217 | snprintf(locator, sizeof(locator), "Channel-%d-DIMM-%d", |
| 218 | dimm->channel_num, dimm->dimm_num); |
| 219 | t->device_locator = smbios_add_string(t->eos, locator); |
| 220 | |
| 221 | snprintf(locator, sizeof(locator), "BANK %d", dimm->bank_locator); |
| 222 | t->bank_locator = smbios_add_string(t->eos, locator); |
| 223 | |
| 224 | /* put '\0' in the end of data */ |
| 225 | length = sizeof(dimm->module_part_number); |
| 226 | dimm->module_part_number[length - 1] = '\0'; |
| 227 | t->part_number = smbios_add_string(t->eos, |
| 228 | (const char *)dimm->module_part_number); |
| 229 | |
| 230 | /* Synchronous = 1 */ |
| 231 | t->type_detail = 0x0080; |
| 232 | /* no handle for error information */ |
| 233 | t->memory_error_information_handle = 0xFFFE; |
| 234 | t->attributes = dimm->rank_per_dimm; |
| 235 | t->handle = *handle; |
| 236 | *handle += 1; |
| 237 | t->length = sizeof(struct smbios_type17) - 2; |
| 238 | return t->length + smbios_string_table_len(t->eos); |
| 239 | } |
| 240 | |
Vladimir Serbinenko | 63acd22 | 2014-06-01 00:26:48 +0200 | [diff] [blame] | 241 | const char *__attribute__((weak)) smbios_mainboard_bios_version(void) |
| 242 | { |
| 243 | if (strlen(CONFIG_LOCALVERSION)) |
| 244 | return CONFIG_LOCALVERSION; |
| 245 | else |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 246 | return coreboot_version; |
Vladimir Serbinenko | 63acd22 | 2014-06-01 00:26:48 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 249 | static int smbios_write_type0(unsigned long *current, int handle) |
| 250 | { |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 251 | struct smbios_type0 *t = (struct smbios_type0 *)*current; |
| 252 | int len = sizeof(struct smbios_type0); |
| 253 | |
| 254 | memset(t, 0, sizeof(struct smbios_type0)); |
| 255 | t->type = SMBIOS_BIOS_INFORMATION; |
| 256 | t->handle = handle; |
| 257 | t->length = len - 2; |
| 258 | |
| 259 | t->vendor = smbios_add_string(t->eos, "coreboot"); |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 260 | #if !CONFIG_CHROMEOS |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 261 | t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date); |
Christian Gmeiner | 5e272a4 | 2013-02-04 16:22:46 +0100 | [diff] [blame] | 262 | |
Vladimir Serbinenko | 63acd22 | 2014-06-01 00:26:48 +0200 | [diff] [blame] | 263 | t->bios_version = smbios_add_string(t->eos, smbios_mainboard_bios_version()); |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 264 | #else |
| 265 | #define SPACES \ |
| 266 | " " |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 267 | t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date); |
Lee Leahy | dbdd066 | 2015-02-26 14:33:18 -0800 | [diff] [blame] | 268 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 269 | u32 version_offset = (u32)smbios_string_table_len(t->eos); |
Lee Leahy | dbdd066 | 2015-02-26 14:33:18 -0800 | [diff] [blame] | 270 | #endif |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 271 | t->bios_version = smbios_add_string(t->eos, SPACES); |
Lee Leahy | dbdd066 | 2015-02-26 14:33:18 -0800 | [diff] [blame] | 272 | |
| 273 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 274 | /* SMBIOS offsets start at 1 rather than 0 */ |
| 275 | vboot_data->vbt10 = (u32)t->eos + (version_offset - 1); |
| 276 | #endif |
Lee Leahy | dbdd066 | 2015-02-26 14:33:18 -0800 | [diff] [blame] | 277 | #endif /* CONFIG_CHROMEOS */ |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 278 | |
Aaron Durbin | 9eebbd4 | 2015-03-26 14:55:34 -0500 | [diff] [blame] | 279 | t->bios_rom_size = (CONFIG_ROM_SIZE / 65535) - 1; |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 280 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 281 | t->system_bios_major_release = 4; |
| 282 | t->bios_characteristics = |
| 283 | BIOS_CHARACTERISTICS_PCI_SUPPORTED | |
| 284 | #if CONFIG_CARDBUS_PLUGIN_SUPPORT |
| 285 | BIOS_CHARACTERISTICS_PC_CARD | |
| 286 | #endif |
| 287 | BIOS_CHARACTERISTICS_SELECTABLE_BOOT | |
| 288 | BIOS_CHARACTERISTICS_UPGRADEABLE; |
| 289 | |
Vladimir Serbinenko | 822bc65 | 2014-01-03 15:55:40 +0100 | [diff] [blame] | 290 | #if CONFIG_HAVE_ACPI_TABLES |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 291 | t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI; |
| 292 | #endif |
| 293 | t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET; |
| 294 | len = t->length + smbios_string_table_len(t->eos); |
| 295 | *current += len; |
| 296 | return len; |
| 297 | } |
| 298 | |
Vladimir Serbinenko | 0afdec4 | 2015-05-30 23:08:26 +0200 | [diff] [blame] | 299 | #if !CONFIG_SMBIOS_PROVIDED_BY_MOBO |
| 300 | |
Christian Gmeiner | ac3aa09 | 2012-07-25 13:42:40 +0200 | [diff] [blame] | 301 | const char *__attribute__((weak)) smbios_mainboard_serial_number(void) |
| 302 | { |
| 303 | return CONFIG_MAINBOARD_SERIAL_NUMBER; |
| 304 | } |
| 305 | |
| 306 | const char *__attribute__((weak)) smbios_mainboard_version(void) |
| 307 | { |
| 308 | return CONFIG_MAINBOARD_VERSION; |
| 309 | } |
| 310 | |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 311 | const char *__attribute__((weak)) smbios_mainboard_manufacturer(void) |
| 312 | { |
| 313 | return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 314 | } |
| 315 | |
| 316 | const char *__attribute__((weak)) smbios_mainboard_product_name(void) |
| 317 | { |
| 318 | return CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME; |
| 319 | } |
| 320 | |
| 321 | void __attribute__((weak)) smbios_mainboard_set_uuid(u8 *uuid) |
| 322 | { |
| 323 | /* leave all zero */ |
| 324 | } |
Vladimir Serbinenko | 0afdec4 | 2015-05-30 23:08:26 +0200 | [diff] [blame] | 325 | #endif |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 326 | |
Kane Chen | 51bdc47 | 2014-09-08 18:40:30 -0700 | [diff] [blame] | 327 | #ifdef CONFIG_MAINBOARD_FAMILY |
| 328 | const char *smbios_mainboard_family(void) |
| 329 | { |
| 330 | return CONFIG_MAINBOARD_FAMILY; |
| 331 | } |
| 332 | #endif /* CONFIG_MAINBOARD_FAMILY */ |
| 333 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 334 | static int smbios_write_type1(unsigned long *current, int handle) |
| 335 | { |
| 336 | struct smbios_type1 *t = (struct smbios_type1 *)*current; |
| 337 | int len = sizeof(struct smbios_type1); |
| 338 | |
| 339 | memset(t, 0, sizeof(struct smbios_type1)); |
| 340 | t->type = SMBIOS_SYSTEM_INFORMATION; |
| 341 | t->handle = handle; |
| 342 | t->length = len - 2; |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 343 | t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); |
| 344 | t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name()); |
Christian Gmeiner | ac3aa09 | 2012-07-25 13:42:40 +0200 | [diff] [blame] | 345 | t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number()); |
| 346 | t->version = smbios_add_string(t->eos, smbios_mainboard_version()); |
Marc Jones | f43ba9c | 2015-06-09 21:10:43 -0600 | [diff] [blame] | 347 | #ifdef CONFIG_MAINBOARD_FAMILY |
| 348 | t->family = smbios_add_string(t->eos, smbios_mainboard_family()); |
| 349 | #endif |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 350 | smbios_mainboard_set_uuid(t->uuid); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 351 | len = t->length + smbios_string_table_len(t->eos); |
| 352 | *current += len; |
| 353 | return len; |
| 354 | } |
| 355 | |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 356 | static int smbios_write_type2(unsigned long *current, int handle) |
| 357 | { |
| 358 | struct smbios_type2 *t = (struct smbios_type2 *)*current; |
| 359 | int len = sizeof(struct smbios_type2); |
| 360 | |
| 361 | memset(t, 0, sizeof(struct smbios_type2)); |
| 362 | t->type = SMBIOS_BOARD_INFORMATION; |
| 363 | t->handle = handle; |
| 364 | t->length = len - 2; |
| 365 | t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); |
| 366 | t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name()); |
| 367 | t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number()); |
| 368 | t->version = smbios_add_string(t->eos, smbios_mainboard_version()); |
| 369 | len = t->length + smbios_string_table_len(t->eos); |
| 370 | *current += len; |
| 371 | return len; |
| 372 | } |
| 373 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 374 | static int smbios_write_type3(unsigned long *current, int handle) |
| 375 | { |
| 376 | struct smbios_type3 *t = (struct smbios_type3 *)*current; |
| 377 | int len = sizeof(struct smbios_type3); |
| 378 | |
| 379 | memset(t, 0, sizeof(struct smbios_type3)); |
| 380 | t->type = SMBIOS_SYSTEM_ENCLOSURE; |
| 381 | t->handle = handle; |
| 382 | t->length = len - 2; |
Vladimir Serbinenko | 4ba3b79 | 2015-05-30 23:09:53 +0200 | [diff] [blame] | 383 | t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 384 | t->bootup_state = SMBIOS_STATE_SAFE; |
| 385 | t->power_supply_state = SMBIOS_STATE_SAFE; |
| 386 | t->thermal_state = SMBIOS_STATE_SAFE; |
Vladimir Serbinenko | a9db82f | 2014-10-16 13:21:47 +0200 | [diff] [blame] | 387 | if(IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) { |
| 388 | t->_type = SMBIOS_ENCLOSURE_NOTEBOOK; |
| 389 | } else { |
| 390 | t->_type = SMBIOS_ENCLOSURE_DESKTOP; |
| 391 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 392 | t->security_status = SMBIOS_STATE_SAFE; |
| 393 | len = t->length + smbios_string_table_len(t->eos); |
| 394 | *current += len; |
| 395 | return len; |
| 396 | } |
| 397 | |
| 398 | static int smbios_write_type4(unsigned long *current, int handle) |
| 399 | { |
| 400 | struct cpuid_result res; |
| 401 | struct smbios_type4 *t = (struct smbios_type4 *)*current; |
| 402 | int len = sizeof(struct smbios_type4); |
| 403 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 404 | /* Provide sane defaults even for CPU without CPUID */ |
| 405 | res.eax = res.edx = 0; |
| 406 | res.ebx = 0x10000; |
| 407 | |
| 408 | if (cpu_have_cpuid()) { |
| 409 | res = cpuid(1); |
| 410 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 411 | |
| 412 | memset(t, 0, sizeof(struct smbios_type4)); |
| 413 | t->type = SMBIOS_PROCESSOR_INFORMATION; |
| 414 | t->handle = handle; |
| 415 | t->length = len - 2; |
| 416 | t->processor_id[0] = res.eax; |
| 417 | t->processor_id[1] = res.edx; |
| 418 | t->processor_manufacturer = smbios_cpu_vendor(t->eos); |
| 419 | t->processor_version = smbios_processor_name(t->eos); |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 420 | t->processor_family = (res.eax > 0) ? 0x0c : 0x6; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 421 | t->processor_type = 3; /* System Processor */ |
| 422 | t->processor_upgrade = 0x06; |
| 423 | t->core_count = (res.ebx >> 16) & 0xff; |
| 424 | t->l1_cache_handle = 0xffff; |
| 425 | t->l2_cache_handle = 0xffff; |
| 426 | t->l3_cache_handle = 0xffff; |
| 427 | t->processor_upgrade = 1; |
| 428 | len = t->length + smbios_string_table_len(t->eos); |
| 429 | *current += len; |
| 430 | return len; |
| 431 | } |
| 432 | |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 433 | static int smbios_write_type11(unsigned long *current, int *handle) |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 434 | { |
| 435 | struct smbios_type11 *t = (struct smbios_type11 *)*current; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 436 | int len; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 437 | struct device *dev; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 438 | |
| 439 | memset(t, 0, sizeof *t); |
| 440 | t->type = SMBIOS_OEM_STRINGS; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 441 | t->handle = *handle; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 442 | t->length = len = sizeof *t - 2; |
| 443 | |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 444 | for(dev = all_devices; dev; dev = dev->next) { |
| 445 | if (dev->ops && dev->ops->get_smbios_strings) |
| 446 | dev->ops->get_smbios_strings(dev, t); |
| 447 | } |
| 448 | |
| 449 | if (t->count == 0) { |
| 450 | memset(t, 0, sizeof *t); |
| 451 | return 0; |
| 452 | } |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 453 | |
| 454 | len += smbios_string_table_len(t->eos); |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 455 | |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 456 | *current += len; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 457 | (*handle)++; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 458 | return len; |
| 459 | } |
| 460 | |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 461 | static int smbios_write_type17(unsigned long *current, int *handle) |
| 462 | { |
| 463 | int len = sizeof(struct smbios_type17); |
| 464 | int i; |
| 465 | |
| 466 | struct memory_info *meminfo; |
| 467 | meminfo = cbmem_find(CBMEM_ID_MEMINFO); |
| 468 | if (meminfo == NULL) |
| 469 | return 0; /* can't find mem info in cbmem */ |
| 470 | |
| 471 | printk(BIOS_INFO, "Create SMBIOS type 17\n"); |
| 472 | for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) { |
| 473 | struct dimm_info *dimm; |
| 474 | dimm = &meminfo->dimm[i]; |
| 475 | len = create_smbios_type17_for_dimm(dimm, current, handle); |
| 476 | *current += len; |
| 477 | } |
| 478 | return meminfo->dimm_cnt * len; |
| 479 | } |
| 480 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 481 | static int smbios_write_type32(unsigned long *current, int handle) |
| 482 | { |
| 483 | struct smbios_type32 *t = (struct smbios_type32 *)*current; |
| 484 | int len = sizeof(struct smbios_type32); |
| 485 | |
| 486 | memset(t, 0, sizeof(struct smbios_type32)); |
| 487 | t->type = SMBIOS_SYSTEM_BOOT_INFORMATION; |
| 488 | t->handle = handle; |
| 489 | t->length = len - 2; |
| 490 | *current += len; |
| 491 | return len; |
| 492 | } |
| 493 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 494 | int smbios_write_type41(unsigned long *current, int *handle, |
| 495 | const char *name, u8 instance, u16 segment, |
| 496 | u8 bus, u8 device, u8 function) |
| 497 | { |
| 498 | struct smbios_type41 *t = (struct smbios_type41 *)*current; |
| 499 | int len = sizeof(struct smbios_type41); |
| 500 | |
| 501 | memset(t, 0, sizeof(struct smbios_type41)); |
| 502 | t->type = SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION; |
| 503 | t->handle = *handle; |
| 504 | t->length = len - 2; |
| 505 | t->reference_designation = smbios_add_string(t->eos, name); |
| 506 | t->device_type = SMBIOS_DEVICE_TYPE_OTHER; |
| 507 | t->device_status = 1; |
| 508 | t->device_type_instance = instance; |
| 509 | t->segment_group_number = segment; |
| 510 | t->bus_number = bus; |
| 511 | t->device_number = device; |
| 512 | t->function_number = function; |
| 513 | |
| 514 | len = t->length + smbios_string_table_len(t->eos); |
| 515 | *current += len; |
| 516 | *handle += 1; |
| 517 | return len; |
| 518 | } |
| 519 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 520 | static int smbios_write_type127(unsigned long *current, int handle) |
| 521 | { |
| 522 | struct smbios_type127 *t = (struct smbios_type127 *)*current; |
| 523 | int len = sizeof(struct smbios_type127); |
| 524 | |
| 525 | memset(t, 0, sizeof(struct smbios_type127)); |
| 526 | t->type = SMBIOS_END_OF_TABLE; |
| 527 | t->handle = handle; |
| 528 | t->length = len - 2; |
| 529 | *current += len; |
| 530 | return len; |
| 531 | } |
| 532 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 533 | 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] | 534 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 535 | struct device *dev; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 536 | int len = 0; |
| 537 | |
| 538 | for(dev = tree; dev; dev = dev->next) { |
Kyösti Mälkki | 7baadac | 2012-10-07 14:57:15 +0200 | [diff] [blame] | 539 | printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev_name(dev)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 540 | |
| 541 | if (dev->ops && dev->ops->get_smbios_data) |
| 542 | len += dev->ops->get_smbios_data(dev, handle, current); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 543 | } |
| 544 | return len; |
| 545 | } |
| 546 | |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 547 | #define update_max(len, max_len, stmt) do { int tmp = stmt; max_len = MAX(max_len, tmp); len += tmp; } while(0) |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 548 | unsigned long smbios_write_tables(unsigned long current) |
| 549 | { |
| 550 | struct smbios_entry *se; |
| 551 | unsigned long tables; |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 552 | int len = 0; |
| 553 | int max_struct_size = 0; |
| 554 | int handle = 0; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 555 | |
| 556 | current = ALIGN(current, 16); |
| 557 | printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current); |
| 558 | |
| 559 | se = (struct smbios_entry *)current; |
| 560 | current += sizeof(struct smbios_entry); |
| 561 | current = ALIGN(current, 16); |
| 562 | |
| 563 | tables = current; |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 564 | update_max(len, max_struct_size, smbios_write_type0(¤t, handle++)); |
| 565 | update_max(len, max_struct_size, smbios_write_type1(¤t, handle++)); |
| 566 | update_max(len, max_struct_size, smbios_write_type2(¤t, handle++)); |
| 567 | update_max(len, max_struct_size, smbios_write_type3(¤t, handle++)); |
| 568 | update_max(len, max_struct_size, smbios_write_type4(¤t, handle++)); |
| 569 | update_max(len, max_struct_size, smbios_write_type11(¤t, &handle)); |
Duncan Laurie | 472ec9c | 2012-06-23 16:13:42 -0700 | [diff] [blame] | 570 | #if CONFIG_ELOG |
Patrick Georgi | 10ef872 | 2015-07-07 17:29:43 +0200 | [diff] [blame] | 571 | update_max(len, max_struct_size, elog_smbios_write_type15(¤t, handle++)); |
Duncan Laurie | 472ec9c | 2012-06-23 16:13:42 -0700 | [diff] [blame] | 572 | #endif |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 573 | update_max(len, max_struct_size, smbios_write_type17(¤t, &handle)); |
| 574 | update_max(len, max_struct_size, smbios_write_type32(¤t, handle++)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 575 | |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 576 | update_max(len, max_struct_size, smbios_walk_device_tree(all_devices, &handle, ¤t)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 577 | |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 578 | update_max(len, max_struct_size, smbios_write_type127(¤t, handle++)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 579 | |
| 580 | memset(se, 0, sizeof(struct smbios_entry)); |
| 581 | memcpy(se->anchor, "_SM_", 4); |
| 582 | se->length = sizeof(struct smbios_entry); |
| 583 | se->major_version = 2; |
| 584 | se->minor_version = 7; |
Ben Frisch | 72af5d7 | 2015-05-09 19:52:18 -0500 | [diff] [blame] | 585 | se->max_struct_size = max_struct_size; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 586 | se->struct_count = handle; |
| 587 | memcpy(se->intermediate_anchor_string, "_DMI_", 5); |
| 588 | |
| 589 | se->struct_table_address = (u32)tables; |
| 590 | se->struct_table_length = len; |
| 591 | |
| 592 | se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10, |
| 593 | sizeof(struct smbios_entry) - 0x10); |
| 594 | se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry)); |
| 595 | return current; |
| 596 | } |