2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
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
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.
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,
25 #include <console/console.h>
27 #include <device/device.h>
29 #include <cpu/x86/name.h>
30 #include <cbfs_core.h>
31 #include <arch/byteorder.h>
33 #include <vendorcode/google/chromeos/gnvs.h>
36 static u8 smbios_checksum(u8 *p, u32 length)
45 int smbios_add_string(char *start, const char *str)
67 int smbios_string_table_len(char *start)
80 static int smbios_cpu_vendor(char *start)
82 char tmp[13] = "Unknown";
83 u32 *_tmp = (u32 *)tmp;
84 struct cpuid_result res;
86 if (cpu_have_cpuid()) {
94 return smbios_add_string(start, tmp);
97 static int smbios_processor_name(char *start)
99 char tmp[49] = "Unknown Processor Name";
100 u32 *_tmp = (u32 *)tmp;
101 struct cpuid_result res;
104 if (cpu_have_cpuid()) {
105 res = cpuid(0x80000000);
106 if (res.eax >= 0x80000004) {
107 for (i = 0; i < 3; i++) {
108 res = cpuid(0x80000002 + i);
109 _tmp[i * 4 + 0] = res.eax;
110 _tmp[i * 4 + 1] = res.ebx;
111 _tmp[i * 4 + 2] = res.ecx;
112 _tmp[i * 4 + 3] = res.edx;
117 return smbios_add_string(start, tmp);
120 static int smbios_write_type0(unsigned long *current, int handle)
122 struct cbfs_header *hdr;
123 struct smbios_type0 *t = (struct smbios_type0 *)*current;
124 int len = sizeof(struct smbios_type0);
126 memset(t, 0, sizeof(struct smbios_type0));
127 t->type = SMBIOS_BIOS_INFORMATION;
131 t->vendor = smbios_add_string(t->eos, "coreboot");
133 t->bios_release_date = smbios_add_string(t->eos, COREBOOT_DMI_DATE);
134 t->bios_version = smbios_add_string(t->eos, COREBOOT_VERSION);
138 t->bios_release_date = smbios_add_string(t->eos, COREBOOT_DMI_DATE);
139 u32 version_offset = (u32)smbios_string_table_len(t->eos);
140 t->bios_version = smbios_add_string(t->eos, SPACES);
141 /* SMBIOS offsets start at 1 rather than 0 */
142 vboot_data->vbt10 = (u32)t->eos + (version_offset - 1);
145 if ((hdr = get_cbfs_header()) != (struct cbfs_header *)0xffffffff)
146 t->bios_rom_size = (ntohl(hdr->romsize) / 65535) - 1;
147 t->system_bios_major_release = 4;
148 t->bios_characteristics =
149 BIOS_CHARACTERISTICS_PCI_SUPPORTED |
150 #if CONFIG_CARDBUS_PLUGIN_SUPPORT
151 BIOS_CHARACTERISTICS_PC_CARD |
153 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
154 BIOS_CHARACTERISTICS_UPGRADEABLE;
156 #if CONFIG_GENERATE_ACPI_TABLES
157 t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI;
159 t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET;
160 len = t->length + smbios_string_table_len(t->eos);
165 static int smbios_write_type1(unsigned long *current, int handle)
167 struct smbios_type1 *t = (struct smbios_type1 *)*current;
168 int len = sizeof(struct smbios_type1);
170 memset(t, 0, sizeof(struct smbios_type1));
171 t->type = SMBIOS_SYSTEM_INFORMATION;
174 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
175 t->product_name = smbios_add_string(t->eos, CONFIG_MAINBOARD_PART_NUMBER);
176 t->serial_number = smbios_add_string(t->eos, "123456789");
177 t->version = smbios_add_string(t->eos, "1.0");
178 len = t->length + smbios_string_table_len(t->eos);
183 static int smbios_write_type3(unsigned long *current, int handle)
185 struct smbios_type3 *t = (struct smbios_type3 *)*current;
186 int len = sizeof(struct smbios_type3);
188 memset(t, 0, sizeof(struct smbios_type3));
189 t->type = SMBIOS_SYSTEM_ENCLOSURE;
192 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
193 t->bootup_state = SMBIOS_STATE_SAFE;
194 t->power_supply_state = SMBIOS_STATE_SAFE;
195 t->thermal_state = SMBIOS_STATE_SAFE;
197 t->security_status = SMBIOS_STATE_SAFE;
198 len = t->length + smbios_string_table_len(t->eos);
203 static int smbios_write_type4(unsigned long *current, int handle)
205 struct cpuid_result res;
206 struct smbios_type4 *t = (struct smbios_type4 *)*current;
207 int len = sizeof(struct smbios_type4);
209 /* Provide sane defaults even for CPU without CPUID */
210 res.eax = res.edx = 0;
213 if (cpu_have_cpuid()) {
217 memset(t, 0, sizeof(struct smbios_type4));
218 t->type = SMBIOS_PROCESSOR_INFORMATION;
221 t->processor_id[0] = res.eax;
222 t->processor_id[1] = res.edx;
223 t->processor_manufacturer = smbios_cpu_vendor(t->eos);
224 t->processor_version = smbios_processor_name(t->eos);
225 t->processor_family = (res.eax > 0) ? 0x0c : 0x6;
226 t->processor_type = 3; /* System Processor */
227 t->processor_upgrade = 0x06;
228 t->core_count = (res.ebx >> 16) & 0xff;
229 t->l1_cache_handle = 0xffff;
230 t->l2_cache_handle = 0xffff;
231 t->l3_cache_handle = 0xffff;
232 t->processor_upgrade = 1;
233 len = t->length + smbios_string_table_len(t->eos);
238 static int smbios_write_type32(unsigned long *current, int handle)
240 struct smbios_type32 *t = (struct smbios_type32 *)*current;
241 int len = sizeof(struct smbios_type32);
243 memset(t, 0, sizeof(struct smbios_type32));
244 t->type = SMBIOS_SYSTEM_BOOT_INFORMATION;
251 static int smbios_write_type127(unsigned long *current, int handle)
253 struct smbios_type127 *t = (struct smbios_type127 *)*current;
254 int len = sizeof(struct smbios_type127);
256 memset(t, 0, sizeof(struct smbios_type127));
257 t->type = SMBIOS_END_OF_TABLE;
264 static int smbios_walk_device_tree(device_t tree, int *handle, unsigned long *current)
269 for(dev = tree; dev; dev = dev->next) {
270 printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev->chip_ops ? dev->chip_ops->name : "");
272 if (dev->ops && dev->ops->get_smbios_data)
273 len += dev->ops->get_smbios_data(dev, handle, current);
275 if (dev->chip_ops && dev->chip_ops->get_smbios_data)
276 len += dev->chip_ops->get_smbios_data(dev, handle, current);
281 unsigned long smbios_write_tables(unsigned long current)
283 struct smbios_entry *se;
284 unsigned long tables;
287 current = ALIGN(current, 16);
288 printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current);
290 se = (struct smbios_entry *)current;
291 current += sizeof(struct smbios_entry);
292 current = ALIGN(current, 16);
295 len = smbios_write_type0(¤t, handle++);
296 len += smbios_write_type1(¤t, handle++);
297 len += smbios_write_type3(¤t, handle++);
298 len += smbios_write_type4(¤t, handle++);
299 len += smbios_write_type32(¤t, handle++);
301 len += smbios_walk_device_tree(all_devices, &handle, ¤t);
303 len += smbios_write_type127(¤t, handle++);
305 memset(se, 0, sizeof(struct smbios_entry));
306 memcpy(se->anchor, "_SM_", 4);
307 se->length = sizeof(struct smbios_entry);
308 se->major_version = 2;
309 se->minor_version = 7;
310 se->max_struct_size = 24;
311 se->struct_count = handle;
312 memcpy(se->intermediate_anchor_string, "_DMI_", 5);
314 se->struct_table_address = (u32)tables;
315 se->struct_table_length = len;
317 se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10,
318 sizeof(struct smbios_entry) - 0x10);
319 se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry));