blob: c3ac54ab891afd598cdd32398b4d224f686d8226 [file] [log] [blame]
Sven Schnelle164bcfd2011-08-14 20:56:34 +02001/*
2 * This file is part of the coreboot project.
3 *
Timothy Pearson821217b2015-03-27 22:47:25 -05004 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Sven Schnelle164bcfd2011-08-14 20:56:34 +02005 * 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älkkic36af7b2014-11-18 12:41:16 +020027#include <version.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +020028#include <device/device.h>
29#include <arch/cpu.h>
30#include <cpu/x86/name.h>
Duncan Laurie472ec9c2012-06-23 16:13:42 -070031#include <elog.h>
Julius Werner9ff8f6f2015-02-23 14:31:09 -080032#include <endian.h>
Kane Chen33faac62014-07-27 12:54:44 -070033#include <memory_info.h>
34#include <spd.h>
35#include <cbmem.h>
Stefan Reinauerc6b21662012-04-03 16:02:54 -070036#if CONFIG_CHROMEOS
37#include <vendorcode/google/chromeos/gnvs.h>
38#endif
Sven Schnelle164bcfd2011-08-14 20:56:34 +020039
40static u8 smbios_checksum(u8 *p, u32 length)
41{
42 u8 ret = 0;
43 while (length--)
44 ret += *p++;
45 return -ret;
46}
47
48
49int 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
71int 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
84static int smbios_cpu_vendor(char *start)
85{
Rudolf Marek06253cd2012-02-25 23:51:12 +010086 char tmp[13] = "Unknown";
Sven Schnelle164bcfd2011-08-14 20:56:34 +020087 u32 *_tmp = (u32 *)tmp;
Rudolf Marek06253cd2012-02-25 23:51:12 +010088 struct cpuid_result res;
Sven Schnelle164bcfd2011-08-14 20:56:34 +020089
Rudolf Marek06253cd2012-02-25 23:51:12 +010090 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 Schnelle164bcfd2011-08-14 20:56:34 +020098 return smbios_add_string(start, tmp);
Sven Schnelle164bcfd2011-08-14 20:56:34 +020099}
100
101static int smbios_processor_name(char *start)
102{
Rudolf Marek06253cd2012-02-25 23:51:12 +0100103 char tmp[49] = "Unknown Processor Name";
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200104 u32 *_tmp = (u32 *)tmp;
105 struct cpuid_result res;
106 int i;
107
Rudolf Marek06253cd2012-02-25 23:51:12 +0100108 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 Schnelle164bcfd2011-08-14 20:56:34 +0200120 }
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200121 return smbios_add_string(start, tmp);
122}
123
Kane Chen33faac62014-07-27 12:54:44 -0700124/* this function will fill the corresponding manufacturer */
Timothy Pearson4785f2a2015-03-27 23:05:36 -0500125void smbios_fill_dimm_manufacturer_from_id(uint16_t mod_id, struct smbios_type17 *t)
Kane Chen33faac62014-07-27 12:54:44 -0700126{
127 switch (mod_id) {
Timothy Pearson821217b2015-03-27 22:47:25 -0500128 case 0x987f:
129 t->manufacturer = smbios_add_string(t->eos,
130 "Hynix");
131 break;
Kane Chen33faac62014-07-27 12:54:44 -0700132 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 Pearson821217b2015-03-27 22:47:25 -0500144 case 0xff2c:
Kane Chen33faac62014-07-27 12:54:44 -0700145 t->manufacturer = smbios_add_string(t->eos,
Timothy Pearson821217b2015-03-27 22:47:25 -0500146 "Micron");
Kane Chen33faac62014-07-27 12:54:44 -0700147 break;
Timothy Pearson821217b2015-03-27 22:47:25 -0500148 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 Chen33faac62014-07-27 12:54:44 -0700156 }
157}
158
159static 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 Pearson4785f2a2015-03-27 23:05:36 -0500193 smbios_fill_dimm_manufacturer_from_id(dimm->mod_id, t);
Kane Chen33faac62014-07-27 12:54:44 -0700194 /* 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 Serbinenko63acd222014-06-01 00:26:48 +0200227const char *__attribute__((weak)) smbios_mainboard_bios_version(void)
228{
229 if (strlen(CONFIG_LOCALVERSION))
230 return CONFIG_LOCALVERSION;
231 else
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +0200232 return coreboot_version;
Vladimir Serbinenko63acd222014-06-01 00:26:48 +0200233}
234
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200235static int smbios_write_type0(unsigned long *current, int handle)
236{
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200237 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 Reinauerc6b21662012-04-03 16:02:54 -0700246#if !CONFIG_CHROMEOS
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +0200247 t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date);
Christian Gmeiner5e272a42013-02-04 16:22:46 +0100248
Vladimir Serbinenko63acd222014-06-01 00:26:48 +0200249 t->bios_version = smbios_add_string(t->eos, smbios_mainboard_bios_version());
Stefan Reinauerc6b21662012-04-03 16:02:54 -0700250#else
251#define SPACES \
252 " "
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +0200253 t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date);
Lee Leahydbdd0662015-02-26 14:33:18 -0800254#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Stefan Reinauerc6b21662012-04-03 16:02:54 -0700255 u32 version_offset = (u32)smbios_string_table_len(t->eos);
Lee Leahydbdd0662015-02-26 14:33:18 -0800256#endif
Stefan Reinauerc6b21662012-04-03 16:02:54 -0700257 t->bios_version = smbios_add_string(t->eos, SPACES);
Lee Leahydbdd0662015-02-26 14:33:18 -0800258
259#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Stefan Reinauerc6b21662012-04-03 16:02:54 -0700260 /* SMBIOS offsets start at 1 rather than 0 */
261 vboot_data->vbt10 = (u32)t->eos + (version_offset - 1);
262#endif
Lee Leahydbdd0662015-02-26 14:33:18 -0800263#endif /* CONFIG_CHROMEOS */
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200264
Aaron Durbin9eebbd42015-03-26 14:55:34 -0500265 t->bios_rom_size = (CONFIG_ROM_SIZE / 65535) - 1;
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800266
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200267 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 Serbinenko822bc652014-01-03 15:55:40 +0100276#if CONFIG_HAVE_ACPI_TABLES
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200277 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 Gmeinerac3aa092012-07-25 13:42:40 +0200285const char *__attribute__((weak)) smbios_mainboard_serial_number(void)
286{
287 return CONFIG_MAINBOARD_SERIAL_NUMBER;
288}
289
290const char *__attribute__((weak)) smbios_mainboard_version(void)
291{
292 return CONFIG_MAINBOARD_VERSION;
293}
294
Gerd Hoffmann06262742013-11-13 13:37:23 +0100295const char *__attribute__((weak)) smbios_mainboard_manufacturer(void)
296{
297 return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
298}
299
300const char *__attribute__((weak)) smbios_mainboard_product_name(void)
301{
302 return CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME;
303}
304
305void __attribute__((weak)) smbios_mainboard_set_uuid(u8 *uuid)
306{
307 /* leave all zero */
308}
309
Kane Chen51bdc472014-09-08 18:40:30 -0700310#ifdef CONFIG_MAINBOARD_FAMILY
311const char *smbios_mainboard_family(void)
312{
313 return CONFIG_MAINBOARD_FAMILY;
314}
315#endif /* CONFIG_MAINBOARD_FAMILY */
316
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200317static 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 Hoffmann06262742013-11-13 13:37:23 +0100326 t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer());
327 t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name());
Christian Gmeinerac3aa092012-07-25 13:42:40 +0200328 t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number());
329 t->version = smbios_add_string(t->eos, smbios_mainboard_version());
Gerd Hoffmann06262742013-11-13 13:37:23 +0100330 smbios_mainboard_set_uuid(t->uuid);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200331 len = t->length + smbios_string_table_len(t->eos);
332 *current += len;
333 return len;
334}
335
Vladimir Serbinenko47089f22014-03-02 19:14:44 +0100336static 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 Chen51bdc472014-09-08 18:40:30 -0700349#ifdef CONFIG_MAINBOARD_FAMILY
350 t->family = smbios_add_string(t->eos, smbios_mainboard_family());
351#endif
Vladimir Serbinenko47089f22014-03-02 19:14:44 +0100352 len = t->length + smbios_string_table_len(t->eos);
353 *current += len;
354 return len;
355}
356
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200357static 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 Stuge4e7385b2012-10-04 21:18:13 +0200366 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_SMBIOS_MANUFACTURER);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200367 t->bootup_state = SMBIOS_STATE_SAFE;
368 t->power_supply_state = SMBIOS_STATE_SAFE;
369 t->thermal_state = SMBIOS_STATE_SAFE;
Vladimir Serbinenkoa9db82f2014-10-16 13:21:47 +0200370 if(IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) {
371 t->_type = SMBIOS_ENCLOSURE_NOTEBOOK;
372 } else {
373 t->_type = SMBIOS_ENCLOSURE_DESKTOP;
374 }
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200375 t->security_status = SMBIOS_STATE_SAFE;
376 len = t->length + smbios_string_table_len(t->eos);
377 *current += len;
378 return len;
379}
380
381static 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 Marek06253cd2012-02-25 23:51:12 +0100387 /* 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 Schnelle164bcfd2011-08-14 20:56:34 +0200394
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 Marek06253cd2012-02-25 23:51:12 +0100403 t->processor_family = (res.eax > 0) ? 0x0c : 0x6;
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200404 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 Serbinenko6abb33c2014-08-27 23:42:45 +0200416static int smbios_write_type11(unsigned long *current, int *handle)
Peter Stugec392b642013-07-06 19:51:12 +0200417{
418 struct smbios_type11 *t = (struct smbios_type11 *)*current;
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200419 int len;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100420 struct device *dev;
Peter Stugec392b642013-07-06 19:51:12 +0200421
422 memset(t, 0, sizeof *t);
423 t->type = SMBIOS_OEM_STRINGS;
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200424 t->handle = *handle;
Peter Stugec392b642013-07-06 19:51:12 +0200425 t->length = len = sizeof *t - 2;
426
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200427 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 Stugec392b642013-07-06 19:51:12 +0200436
437 len += smbios_string_table_len(t->eos);
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200438
Peter Stugec392b642013-07-06 19:51:12 +0200439 *current += len;
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200440 (*handle)++;
Peter Stugec392b642013-07-06 19:51:12 +0200441 return len;
442}
443
Kane Chen33faac62014-07-27 12:54:44 -0700444static 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 Schnelle164bcfd2011-08-14 20:56:34 +0200464static 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 Laurie21a78702013-05-23 14:17:05 -0700477int 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 Schnelle164bcfd2011-08-14 20:56:34 +0200503static 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'Callaghan2c9d2cf2014-10-27 23:29:29 +1100516static int smbios_walk_device_tree(struct device *tree, int *handle, unsigned long *current)
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200517{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100518 struct device *dev;
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200519 int len = 0;
520
521 for(dev = tree; dev; dev = dev->next) {
Kyösti Mälkki7baadac2012-10-07 14:57:15 +0200522 printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev_name(dev));
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200523
524 if (dev->ops && dev->ops->get_smbios_data)
525 len += dev->ops->get_smbios_data(dev, handle, current);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200526 }
527 return len;
528}
529
530unsigned 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(&current, handle++);
545 len += smbios_write_type1(&current, handle++);
Vladimir Serbinenko47089f22014-03-02 19:14:44 +0100546 len += smbios_write_type2(&current, handle++);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200547 len += smbios_write_type3(&current, handle++);
548 len += smbios_write_type4(&current, handle++);
Vladimir Serbinenko6abb33c2014-08-27 23:42:45 +0200549 len += smbios_write_type11(&current, &handle);
Duncan Laurie472ec9c2012-06-23 16:13:42 -0700550#if CONFIG_ELOG
551 len += elog_smbios_write_type15(&current, handle++);
552#endif
Kane Chen33faac62014-07-27 12:54:44 -0700553 len += smbios_write_type17(&current, &handle);
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200554 len += smbios_write_type32(&current, handle++);
555
556 len += smbios_walk_device_tree(all_devices, &handle, &current);
557
558 len += smbios_write_type127(&current, 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}