Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <smbios.h> |
| 25 | #include <console/console.h> |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame^] | 26 | #include <version.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 27 | #include <device/device.h> |
| 28 | #include <arch/cpu.h> |
| 29 | #include <cpu/x86/name.h> |
| 30 | #include <cbfs_core.h> |
| 31 | #include <arch/byteorder.h> |
Duncan Laurie | 472ec9c | 2012-06-23 16:13:42 -0700 | [diff] [blame] | 32 | #include <elog.h> |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 33 | #if CONFIG_CHROMEOS |
| 34 | #include <vendorcode/google/chromeos/gnvs.h> |
| 35 | #endif |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 36 | |
| 37 | static u8 smbios_checksum(u8 *p, u32 length) |
| 38 | { |
| 39 | u8 ret = 0; |
| 40 | while (length--) |
| 41 | ret += *p++; |
| 42 | return -ret; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | int smbios_add_string(char *start, const char *str) |
| 47 | { |
| 48 | int i = 1; |
| 49 | char *p = start; |
| 50 | |
| 51 | for(;;) { |
| 52 | if (!*p) { |
| 53 | strcpy(p, str); |
| 54 | p += strlen(str); |
| 55 | *p++ = '\0'; |
| 56 | *p++ = '\0'; |
| 57 | return i; |
| 58 | } |
| 59 | |
| 60 | if (!strcmp(p, str)) |
| 61 | return i; |
| 62 | |
| 63 | p += strlen(p)+1; |
| 64 | i++; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | int smbios_string_table_len(char *start) |
| 69 | { |
| 70 | char *p = start; |
| 71 | int i, len = 0; |
| 72 | |
| 73 | while(*p) { |
| 74 | i = strlen(p) + 1; |
| 75 | p += i; |
| 76 | len += i; |
| 77 | } |
| 78 | return len + 1; |
| 79 | } |
| 80 | |
| 81 | static int smbios_cpu_vendor(char *start) |
| 82 | { |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 83 | char tmp[13] = "Unknown"; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 84 | u32 *_tmp = (u32 *)tmp; |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 85 | struct cpuid_result res; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 86 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 87 | if (cpu_have_cpuid()) { |
| 88 | res = cpuid(0); |
| 89 | _tmp[0] = res.ebx; |
| 90 | _tmp[1] = res.edx; |
| 91 | _tmp[2] = res.ecx; |
| 92 | tmp[12] = '\0'; |
| 93 | } |
| 94 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 95 | return smbios_add_string(start, tmp); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static int smbios_processor_name(char *start) |
| 99 | { |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 100 | char tmp[49] = "Unknown Processor Name"; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 101 | u32 *_tmp = (u32 *)tmp; |
| 102 | struct cpuid_result res; |
| 103 | int i; |
| 104 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 105 | if (cpu_have_cpuid()) { |
| 106 | res = cpuid(0x80000000); |
| 107 | if (res.eax >= 0x80000004) { |
| 108 | for (i = 0; i < 3; i++) { |
| 109 | res = cpuid(0x80000002 + i); |
| 110 | _tmp[i * 4 + 0] = res.eax; |
| 111 | _tmp[i * 4 + 1] = res.ebx; |
| 112 | _tmp[i * 4 + 2] = res.ecx; |
| 113 | _tmp[i * 4 + 3] = res.edx; |
| 114 | } |
| 115 | tmp[48] = 0; |
| 116 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 117 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 118 | return smbios_add_string(start, tmp); |
| 119 | } |
| 120 | |
Vladimir Serbinenko | 63acd22 | 2014-06-01 00:26:48 +0200 | [diff] [blame] | 121 | const char *__attribute__((weak)) smbios_mainboard_bios_version(void) |
| 122 | { |
| 123 | if (strlen(CONFIG_LOCALVERSION)) |
| 124 | return CONFIG_LOCALVERSION; |
| 125 | else |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame^] | 126 | return coreboot_version; |
Vladimir Serbinenko | 63acd22 | 2014-06-01 00:26:48 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 129 | static int smbios_write_type0(unsigned long *current, int handle) |
| 130 | { |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 131 | struct smbios_type0 *t = (struct smbios_type0 *)*current; |
| 132 | int len = sizeof(struct smbios_type0); |
| 133 | |
| 134 | memset(t, 0, sizeof(struct smbios_type0)); |
| 135 | t->type = SMBIOS_BIOS_INFORMATION; |
| 136 | t->handle = handle; |
| 137 | t->length = len - 2; |
| 138 | |
| 139 | t->vendor = smbios_add_string(t->eos, "coreboot"); |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 140 | #if !CONFIG_CHROMEOS |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame^] | 141 | t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date); |
Christian Gmeiner | 5e272a4 | 2013-02-04 16:22:46 +0100 | [diff] [blame] | 142 | |
Vladimir Serbinenko | 63acd22 | 2014-06-01 00:26:48 +0200 | [diff] [blame] | 143 | t->bios_version = smbios_add_string(t->eos, smbios_mainboard_bios_version()); |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 144 | #else |
| 145 | #define SPACES \ |
| 146 | " " |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame^] | 147 | t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date); |
Stefan Reinauer | c6b2166 | 2012-04-03 16:02:54 -0700 | [diff] [blame] | 148 | u32 version_offset = (u32)smbios_string_table_len(t->eos); |
| 149 | t->bios_version = smbios_add_string(t->eos, SPACES); |
| 150 | /* SMBIOS offsets start at 1 rather than 0 */ |
| 151 | vboot_data->vbt10 = (u32)t->eos + (version_offset - 1); |
| 152 | #endif |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 153 | |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 154 | { |
| 155 | const struct cbfs_header *header; |
| 156 | u32 romsize = CONFIG_ROM_SIZE; |
| 157 | header = cbfs_get_header(CBFS_DEFAULT_MEDIA); |
| 158 | if (header != CBFS_HEADER_INVALID_ADDRESS) |
| 159 | romsize = ntohl(header->romsize); |
| 160 | t->bios_rom_size = (romsize / 65535) - 1; |
| 161 | } |
| 162 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 163 | t->system_bios_major_release = 4; |
| 164 | t->bios_characteristics = |
| 165 | BIOS_CHARACTERISTICS_PCI_SUPPORTED | |
| 166 | #if CONFIG_CARDBUS_PLUGIN_SUPPORT |
| 167 | BIOS_CHARACTERISTICS_PC_CARD | |
| 168 | #endif |
| 169 | BIOS_CHARACTERISTICS_SELECTABLE_BOOT | |
| 170 | BIOS_CHARACTERISTICS_UPGRADEABLE; |
| 171 | |
Vladimir Serbinenko | 822bc65 | 2014-01-03 15:55:40 +0100 | [diff] [blame] | 172 | #if CONFIG_HAVE_ACPI_TABLES |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 173 | t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI; |
| 174 | #endif |
| 175 | t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET; |
| 176 | len = t->length + smbios_string_table_len(t->eos); |
| 177 | *current += len; |
| 178 | return len; |
| 179 | } |
| 180 | |
Christian Gmeiner | ac3aa09 | 2012-07-25 13:42:40 +0200 | [diff] [blame] | 181 | const char *__attribute__((weak)) smbios_mainboard_serial_number(void) |
| 182 | { |
| 183 | return CONFIG_MAINBOARD_SERIAL_NUMBER; |
| 184 | } |
| 185 | |
| 186 | const char *__attribute__((weak)) smbios_mainboard_version(void) |
| 187 | { |
| 188 | return CONFIG_MAINBOARD_VERSION; |
| 189 | } |
| 190 | |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 191 | const char *__attribute__((weak)) smbios_mainboard_manufacturer(void) |
| 192 | { |
| 193 | return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 194 | } |
| 195 | |
| 196 | const char *__attribute__((weak)) smbios_mainboard_product_name(void) |
| 197 | { |
| 198 | return CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME; |
| 199 | } |
| 200 | |
| 201 | void __attribute__((weak)) smbios_mainboard_set_uuid(u8 *uuid) |
| 202 | { |
| 203 | /* leave all zero */ |
| 204 | } |
| 205 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 206 | static int smbios_write_type1(unsigned long *current, int handle) |
| 207 | { |
| 208 | struct smbios_type1 *t = (struct smbios_type1 *)*current; |
| 209 | int len = sizeof(struct smbios_type1); |
| 210 | |
| 211 | memset(t, 0, sizeof(struct smbios_type1)); |
| 212 | t->type = SMBIOS_SYSTEM_INFORMATION; |
| 213 | t->handle = handle; |
| 214 | t->length = len - 2; |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 215 | t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); |
| 216 | t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name()); |
Christian Gmeiner | ac3aa09 | 2012-07-25 13:42:40 +0200 | [diff] [blame] | 217 | t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number()); |
| 218 | t->version = smbios_add_string(t->eos, smbios_mainboard_version()); |
Gerd Hoffmann | 0626274 | 2013-11-13 13:37:23 +0100 | [diff] [blame] | 219 | smbios_mainboard_set_uuid(t->uuid); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 220 | len = t->length + smbios_string_table_len(t->eos); |
| 221 | *current += len; |
| 222 | return len; |
| 223 | } |
| 224 | |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 225 | static int smbios_write_type2(unsigned long *current, int handle) |
| 226 | { |
| 227 | struct smbios_type2 *t = (struct smbios_type2 *)*current; |
| 228 | int len = sizeof(struct smbios_type2); |
| 229 | |
| 230 | memset(t, 0, sizeof(struct smbios_type2)); |
| 231 | t->type = SMBIOS_BOARD_INFORMATION; |
| 232 | t->handle = handle; |
| 233 | t->length = len - 2; |
| 234 | t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); |
| 235 | t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name()); |
| 236 | t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number()); |
| 237 | t->version = smbios_add_string(t->eos, smbios_mainboard_version()); |
| 238 | len = t->length + smbios_string_table_len(t->eos); |
| 239 | *current += len; |
| 240 | return len; |
| 241 | } |
| 242 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 243 | static int smbios_write_type3(unsigned long *current, int handle) |
| 244 | { |
| 245 | struct smbios_type3 *t = (struct smbios_type3 *)*current; |
| 246 | int len = sizeof(struct smbios_type3); |
| 247 | |
| 248 | memset(t, 0, sizeof(struct smbios_type3)); |
| 249 | t->type = SMBIOS_SYSTEM_ENCLOSURE; |
| 250 | t->handle = handle; |
| 251 | t->length = len - 2; |
Peter Stuge | 4e7385b | 2012-10-04 21:18:13 +0200 | [diff] [blame] | 252 | t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_SMBIOS_MANUFACTURER); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 253 | t->bootup_state = SMBIOS_STATE_SAFE; |
| 254 | t->power_supply_state = SMBIOS_STATE_SAFE; |
| 255 | t->thermal_state = SMBIOS_STATE_SAFE; |
Vladimir Serbinenko | a9db82f | 2014-10-16 13:21:47 +0200 | [diff] [blame] | 256 | if(IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) { |
| 257 | t->_type = SMBIOS_ENCLOSURE_NOTEBOOK; |
| 258 | } else { |
| 259 | t->_type = SMBIOS_ENCLOSURE_DESKTOP; |
| 260 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 261 | t->security_status = SMBIOS_STATE_SAFE; |
| 262 | len = t->length + smbios_string_table_len(t->eos); |
| 263 | *current += len; |
| 264 | return len; |
| 265 | } |
| 266 | |
| 267 | static int smbios_write_type4(unsigned long *current, int handle) |
| 268 | { |
| 269 | struct cpuid_result res; |
| 270 | struct smbios_type4 *t = (struct smbios_type4 *)*current; |
| 271 | int len = sizeof(struct smbios_type4); |
| 272 | |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 273 | /* Provide sane defaults even for CPU without CPUID */ |
| 274 | res.eax = res.edx = 0; |
| 275 | res.ebx = 0x10000; |
| 276 | |
| 277 | if (cpu_have_cpuid()) { |
| 278 | res = cpuid(1); |
| 279 | } |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 280 | |
| 281 | memset(t, 0, sizeof(struct smbios_type4)); |
| 282 | t->type = SMBIOS_PROCESSOR_INFORMATION; |
| 283 | t->handle = handle; |
| 284 | t->length = len - 2; |
| 285 | t->processor_id[0] = res.eax; |
| 286 | t->processor_id[1] = res.edx; |
| 287 | t->processor_manufacturer = smbios_cpu_vendor(t->eos); |
| 288 | t->processor_version = smbios_processor_name(t->eos); |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 289 | t->processor_family = (res.eax > 0) ? 0x0c : 0x6; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 290 | t->processor_type = 3; /* System Processor */ |
| 291 | t->processor_upgrade = 0x06; |
| 292 | t->core_count = (res.ebx >> 16) & 0xff; |
| 293 | t->l1_cache_handle = 0xffff; |
| 294 | t->l2_cache_handle = 0xffff; |
| 295 | t->l3_cache_handle = 0xffff; |
| 296 | t->processor_upgrade = 1; |
| 297 | len = t->length + smbios_string_table_len(t->eos); |
| 298 | *current += len; |
| 299 | return len; |
| 300 | } |
| 301 | |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 302 | static int smbios_write_type11(unsigned long *current, int *handle) |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 303 | { |
| 304 | struct smbios_type11 *t = (struct smbios_type11 *)*current; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 305 | int len; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 306 | struct device *dev; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 307 | |
| 308 | memset(t, 0, sizeof *t); |
| 309 | t->type = SMBIOS_OEM_STRINGS; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 310 | t->handle = *handle; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 311 | t->length = len = sizeof *t - 2; |
| 312 | |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 313 | for(dev = all_devices; dev; dev = dev->next) { |
| 314 | if (dev->ops && dev->ops->get_smbios_strings) |
| 315 | dev->ops->get_smbios_strings(dev, t); |
| 316 | } |
| 317 | |
| 318 | if (t->count == 0) { |
| 319 | memset(t, 0, sizeof *t); |
| 320 | return 0; |
| 321 | } |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 322 | |
| 323 | len += smbios_string_table_len(t->eos); |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 324 | |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 325 | *current += len; |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 326 | (*handle)++; |
Peter Stuge | c392b64 | 2013-07-06 19:51:12 +0200 | [diff] [blame] | 327 | return len; |
| 328 | } |
| 329 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 330 | static int smbios_write_type32(unsigned long *current, int handle) |
| 331 | { |
| 332 | struct smbios_type32 *t = (struct smbios_type32 *)*current; |
| 333 | int len = sizeof(struct smbios_type32); |
| 334 | |
| 335 | memset(t, 0, sizeof(struct smbios_type32)); |
| 336 | t->type = SMBIOS_SYSTEM_BOOT_INFORMATION; |
| 337 | t->handle = handle; |
| 338 | t->length = len - 2; |
| 339 | *current += len; |
| 340 | return len; |
| 341 | } |
| 342 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 343 | int smbios_write_type41(unsigned long *current, int *handle, |
| 344 | const char *name, u8 instance, u16 segment, |
| 345 | u8 bus, u8 device, u8 function) |
| 346 | { |
| 347 | struct smbios_type41 *t = (struct smbios_type41 *)*current; |
| 348 | int len = sizeof(struct smbios_type41); |
| 349 | |
| 350 | memset(t, 0, sizeof(struct smbios_type41)); |
| 351 | t->type = SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION; |
| 352 | t->handle = *handle; |
| 353 | t->length = len - 2; |
| 354 | t->reference_designation = smbios_add_string(t->eos, name); |
| 355 | t->device_type = SMBIOS_DEVICE_TYPE_OTHER; |
| 356 | t->device_status = 1; |
| 357 | t->device_type_instance = instance; |
| 358 | t->segment_group_number = segment; |
| 359 | t->bus_number = bus; |
| 360 | t->device_number = device; |
| 361 | t->function_number = function; |
| 362 | |
| 363 | len = t->length + smbios_string_table_len(t->eos); |
| 364 | *current += len; |
| 365 | *handle += 1; |
| 366 | return len; |
| 367 | } |
| 368 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 369 | static int smbios_write_type127(unsigned long *current, int handle) |
| 370 | { |
| 371 | struct smbios_type127 *t = (struct smbios_type127 *)*current; |
| 372 | int len = sizeof(struct smbios_type127); |
| 373 | |
| 374 | memset(t, 0, sizeof(struct smbios_type127)); |
| 375 | t->type = SMBIOS_END_OF_TABLE; |
| 376 | t->handle = handle; |
| 377 | t->length = len - 2; |
| 378 | *current += len; |
| 379 | return len; |
| 380 | } |
| 381 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 382 | 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] | 383 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 384 | struct device *dev; |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 385 | int len = 0; |
| 386 | |
| 387 | for(dev = tree; dev; dev = dev->next) { |
Kyösti Mälkki | 7baadac | 2012-10-07 14:57:15 +0200 | [diff] [blame] | 388 | printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev_name(dev)); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 389 | |
| 390 | if (dev->ops && dev->ops->get_smbios_data) |
| 391 | len += dev->ops->get_smbios_data(dev, handle, current); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 392 | } |
| 393 | return len; |
| 394 | } |
| 395 | |
| 396 | unsigned long smbios_write_tables(unsigned long current) |
| 397 | { |
| 398 | struct smbios_entry *se; |
| 399 | unsigned long tables; |
| 400 | int len, handle = 0; |
| 401 | |
| 402 | current = ALIGN(current, 16); |
| 403 | printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current); |
| 404 | |
| 405 | se = (struct smbios_entry *)current; |
| 406 | current += sizeof(struct smbios_entry); |
| 407 | current = ALIGN(current, 16); |
| 408 | |
| 409 | tables = current; |
| 410 | len = smbios_write_type0(¤t, handle++); |
| 411 | len += smbios_write_type1(¤t, handle++); |
Vladimir Serbinenko | 47089f2 | 2014-03-02 19:14:44 +0100 | [diff] [blame] | 412 | len += smbios_write_type2(¤t, handle++); |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 413 | len += smbios_write_type3(¤t, handle++); |
| 414 | len += smbios_write_type4(¤t, handle++); |
Vladimir Serbinenko | 6abb33c | 2014-08-27 23:42:45 +0200 | [diff] [blame] | 415 | len += smbios_write_type11(¤t, &handle); |
Duncan Laurie | 472ec9c | 2012-06-23 16:13:42 -0700 | [diff] [blame] | 416 | #if CONFIG_ELOG |
| 417 | len += elog_smbios_write_type15(¤t, handle++); |
| 418 | #endif |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 419 | len += smbios_write_type32(¤t, handle++); |
| 420 | |
| 421 | len += smbios_walk_device_tree(all_devices, &handle, ¤t); |
| 422 | |
| 423 | len += smbios_write_type127(¤t, handle++); |
| 424 | |
| 425 | memset(se, 0, sizeof(struct smbios_entry)); |
| 426 | memcpy(se->anchor, "_SM_", 4); |
| 427 | se->length = sizeof(struct smbios_entry); |
| 428 | se->major_version = 2; |
| 429 | se->minor_version = 7; |
| 430 | se->max_struct_size = 24; |
| 431 | se->struct_count = handle; |
| 432 | memcpy(se->intermediate_anchor_string, "_DMI_", 5); |
| 433 | |
| 434 | se->struct_table_address = (u32)tables; |
| 435 | se->struct_table_length = len; |
| 436 | |
| 437 | se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10, |
| 438 | sizeof(struct smbios_entry) - 0x10); |
| 439 | se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry)); |
| 440 | return current; |
| 441 | } |