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