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 static u8 smbios_checksum(u8 *p, u32 length)
42 int smbios_add_string(char *start, const char *str)
64 int smbios_string_table_len(char *start)
77 static int smbios_cpu_vendor(char *start)
79 char tmp[13] = "Unknown";
80 u32 *_tmp = (u32 *)tmp;
81 struct cpuid_result res;
83 if (cpu_have_cpuid()) {
91 return smbios_add_string(start, tmp);
94 static int smbios_processor_name(char *start)
96 char tmp[49] = "Unknown Processor Name";
97 u32 *_tmp = (u32 *)tmp;
98 struct cpuid_result res;
101 if (cpu_have_cpuid()) {
102 res = cpuid(0x80000000);
103 if (res.eax >= 0x80000004) {
104 for (i = 0; i < 3; i++) {
105 res = cpuid(0x80000002 + i);
106 _tmp[i * 4 + 0] = res.eax;
107 _tmp[i * 4 + 1] = res.ebx;
108 _tmp[i * 4 + 2] = res.ecx;
109 _tmp[i * 4 + 3] = res.edx;
114 return smbios_add_string(start, tmp);
117 static int smbios_write_type0(unsigned long *current, int handle)
119 struct cbfs_header *hdr;
120 struct smbios_type0 *t = (struct smbios_type0 *)*current;
121 int len = sizeof(struct smbios_type0);
123 memset(t, 0, sizeof(struct smbios_type0));
124 t->type = SMBIOS_BIOS_INFORMATION;
128 t->vendor = smbios_add_string(t->eos, "coreboot");
129 t->bios_release_date = smbios_add_string(t->eos, COREBOOT_DMI_DATE);
130 t->bios_version = smbios_add_string(t->eos, COREBOOT_VERSION);
132 if ((hdr = get_cbfs_header()) != (struct cbfs_header *)0xffffffff)
133 t->bios_rom_size = (ntohl(hdr->romsize) / 65535) - 1;
134 t->system_bios_major_release = 4;
135 t->bios_characteristics =
136 BIOS_CHARACTERISTICS_PCI_SUPPORTED |
137 #if CONFIG_CARDBUS_PLUGIN_SUPPORT
138 BIOS_CHARACTERISTICS_PC_CARD |
140 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
141 BIOS_CHARACTERISTICS_UPGRADEABLE;
143 #if CONFIG_GENERATE_ACPI_TABLES
144 t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI;
146 t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET;
147 len = t->length + smbios_string_table_len(t->eos);
152 static int smbios_write_type1(unsigned long *current, int handle)
154 struct smbios_type1 *t = (struct smbios_type1 *)*current;
155 int len = sizeof(struct smbios_type1);
157 memset(t, 0, sizeof(struct smbios_type1));
158 t->type = SMBIOS_SYSTEM_INFORMATION;
161 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
162 t->product_name = smbios_add_string(t->eos, CONFIG_MAINBOARD_PART_NUMBER);
163 len = t->length + smbios_string_table_len(t->eos);
168 static int smbios_write_type3(unsigned long *current, int handle)
170 struct smbios_type3 *t = (struct smbios_type3 *)*current;
171 int len = sizeof(struct smbios_type3);
173 memset(t, 0, sizeof(struct smbios_type3));
174 t->type = SMBIOS_SYSTEM_ENCLOSURE;
177 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
178 t->bootup_state = SMBIOS_STATE_SAFE;
179 t->power_supply_state = SMBIOS_STATE_SAFE;
180 t->thermal_state = SMBIOS_STATE_SAFE;
182 t->security_status = SMBIOS_STATE_SAFE;
183 len = t->length + smbios_string_table_len(t->eos);
188 static int smbios_write_type4(unsigned long *current, int handle)
190 struct cpuid_result res;
191 struct smbios_type4 *t = (struct smbios_type4 *)*current;
192 int len = sizeof(struct smbios_type4);
194 /* Provide sane defaults even for CPU without CPUID */
195 res.eax = res.edx = 0;
198 if (cpu_have_cpuid()) {
202 memset(t, 0, sizeof(struct smbios_type4));
203 t->type = SMBIOS_PROCESSOR_INFORMATION;
206 t->processor_id[0] = res.eax;
207 t->processor_id[1] = res.edx;
208 t->processor_manufacturer = smbios_cpu_vendor(t->eos);
209 t->processor_version = smbios_processor_name(t->eos);
210 t->processor_family = (res.eax > 0) ? 0x0c : 0x6;
211 t->processor_type = 3; /* System Processor */
212 t->processor_upgrade = 0x06;
213 t->core_count = (res.ebx >> 16) & 0xff;
214 t->l1_cache_handle = 0xffff;
215 t->l2_cache_handle = 0xffff;
216 t->l3_cache_handle = 0xffff;
217 t->processor_upgrade = 1;
218 len = t->length + smbios_string_table_len(t->eos);
223 static int smbios_write_type32(unsigned long *current, int handle)
225 struct smbios_type32 *t = (struct smbios_type32 *)*current;
226 int len = sizeof(struct smbios_type32);
228 memset(t, 0, sizeof(struct smbios_type32));
229 t->type = SMBIOS_SYSTEM_BOOT_INFORMATION;
236 static int smbios_write_type127(unsigned long *current, int handle)
238 struct smbios_type127 *t = (struct smbios_type127 *)*current;
239 int len = sizeof(struct smbios_type127);
241 memset(t, 0, sizeof(struct smbios_type127));
242 t->type = SMBIOS_END_OF_TABLE;
249 static int smbios_walk_device_tree(device_t tree, int *handle, unsigned long *current)
254 for(dev = tree; dev; dev = dev->next) {
255 printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev->chip_ops ? dev->chip_ops->name : "");
257 if (dev->ops && dev->ops->get_smbios_data)
258 len += dev->ops->get_smbios_data(dev, handle, current);
260 if (dev->chip_ops && dev->chip_ops->get_smbios_data)
261 len += dev->chip_ops->get_smbios_data(dev, handle, current);
266 unsigned long smbios_write_tables(unsigned long current)
268 struct smbios_entry *se;
269 unsigned long tables;
272 current = ALIGN(current, 16);
273 printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current);
275 se = (struct smbios_entry *)current;
276 current += sizeof(struct smbios_entry);
277 current = ALIGN(current, 16);
280 len = smbios_write_type0(¤t, handle++);
281 len += smbios_write_type1(¤t, handle++);
282 len += smbios_write_type3(¤t, handle++);
283 len += smbios_write_type4(¤t, handle++);
284 len += smbios_write_type32(¤t, handle++);
286 len += smbios_walk_device_tree(all_devices, &handle, ¤t);
288 len += smbios_write_type127(¤t, handle++);
290 memset(se, 0, sizeof(struct smbios_entry));
291 memcpy(se->anchor, "_SM_", 4);
292 se->length = sizeof(struct smbios_entry);
293 se->major_version = 2;
294 se->minor_version = 7;
295 se->max_struct_size = 24;
296 se->struct_count = handle;
297 memcpy(se->intermediate_anchor_string, "_DMI_", 5);
299 se->struct_table_address = (u32)tables;
300 se->struct_table_length = len;
302 se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10,
303 sizeof(struct smbios_entry) - 0x10);
304 se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry));