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)
80 u32 *_tmp = (u32 *)tmp;
81 struct cpuid_result res = cpuid(0);
87 return smbios_add_string(start, tmp);
91 static int smbios_processor_name(char *start)
94 u32 *_tmp = (u32 *)tmp;
95 struct cpuid_result res;
98 for (i = 0; i < 3; i++) {
99 res = cpuid(0x80000002 + i);
100 _tmp[i * 4 + 0] = res.eax;
101 _tmp[i * 4 + 1] = res.ebx;
102 _tmp[i * 4 + 2] = res.ecx;
103 _tmp[i * 4 + 3] = res.edx;
107 return smbios_add_string(start, tmp);
110 static int smbios_write_type0(unsigned long *current, int handle)
112 struct cbfs_header *hdr;
113 struct smbios_type0 *t = (struct smbios_type0 *)*current;
114 int len = sizeof(struct smbios_type0);
116 memset(t, 0, sizeof(struct smbios_type0));
117 t->type = SMBIOS_BIOS_INFORMATION;
121 t->vendor = smbios_add_string(t->eos, "coreboot");
122 t->bios_release_date = smbios_add_string(t->eos, COREBOOT_DMI_DATE);
123 t->bios_version = smbios_add_string(t->eos, COREBOOT_VERSION);
125 if ((hdr = get_cbfs_header()) != (struct cbfs_header *)0xffffffff)
126 t->bios_rom_size = (ntohl(hdr->romsize) / 65535) - 1;
127 t->system_bios_major_release = 4;
128 t->bios_characteristics =
129 BIOS_CHARACTERISTICS_PCI_SUPPORTED |
130 #if CONFIG_CARDBUS_PLUGIN_SUPPORT
131 BIOS_CHARACTERISTICS_PC_CARD |
133 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
134 BIOS_CHARACTERISTICS_UPGRADEABLE;
136 #if CONFIG_GENERATE_ACPI_TABLES
137 t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI;
139 t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET;
140 len = t->length + smbios_string_table_len(t->eos);
145 static int smbios_write_type1(unsigned long *current, int handle)
147 struct smbios_type1 *t = (struct smbios_type1 *)*current;
148 int len = sizeof(struct smbios_type1);
150 memset(t, 0, sizeof(struct smbios_type1));
151 t->type = SMBIOS_SYSTEM_INFORMATION;
154 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
155 t->product_name = smbios_add_string(t->eos, CONFIG_MAINBOARD_PART_NUMBER);
156 len = t->length + smbios_string_table_len(t->eos);
161 static int smbios_write_type3(unsigned long *current, int handle)
163 struct smbios_type3 *t = (struct smbios_type3 *)*current;
164 int len = sizeof(struct smbios_type3);
166 memset(t, 0, sizeof(struct smbios_type3));
167 t->type = SMBIOS_SYSTEM_ENCLOSURE;
170 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
171 t->bootup_state = SMBIOS_STATE_SAFE;
172 t->power_supply_state = SMBIOS_STATE_SAFE;
173 t->thermal_state = SMBIOS_STATE_SAFE;
175 t->security_status = SMBIOS_STATE_SAFE;
176 len = t->length + smbios_string_table_len(t->eos);
181 static int smbios_write_type4(unsigned long *current, int handle)
183 struct cpuid_result res;
184 struct smbios_type4 *t = (struct smbios_type4 *)*current;
185 int len = sizeof(struct smbios_type4);
189 memset(t, 0, sizeof(struct smbios_type4));
190 t->type = SMBIOS_PROCESSOR_INFORMATION;
193 t->processor_id[0] = res.eax;
194 t->processor_id[1] = res.edx;
195 t->processor_manufacturer = smbios_cpu_vendor(t->eos);
196 t->processor_version = smbios_processor_name(t->eos);
197 t->processor_family = 0x0c;
198 t->processor_type = 3; /* System Processor */
199 t->processor_upgrade = 0x06;
200 t->core_count = (res.ebx >> 16) & 0xff;
201 t->l1_cache_handle = 0xffff;
202 t->l2_cache_handle = 0xffff;
203 t->l3_cache_handle = 0xffff;
204 t->processor_upgrade = 1;
205 len = t->length + smbios_string_table_len(t->eos);
210 static int smbios_write_type32(unsigned long *current, int handle)
212 struct smbios_type32 *t = (struct smbios_type32 *)*current;
213 int len = sizeof(struct smbios_type32);
215 memset(t, 0, sizeof(struct smbios_type32));
216 t->type = SMBIOS_SYSTEM_BOOT_INFORMATION;
223 static int smbios_write_type127(unsigned long *current, int handle)
225 struct smbios_type127 *t = (struct smbios_type127 *)*current;
226 int len = sizeof(struct smbios_type127);
228 memset(t, 0, sizeof(struct smbios_type127));
229 t->type = SMBIOS_END_OF_TABLE;
236 static int smbios_walk_device_tree(device_t tree, int *handle, unsigned long *current)
241 for(dev = tree; dev; dev = dev->next) {
242 printk(BIOS_INFO, "%s (%s)\n", dev_path(dev), dev->chip_ops ? dev->chip_ops->name : "");
244 if (dev->ops && dev->ops->get_smbios_data)
245 len += dev->ops->get_smbios_data(dev, handle, current);
247 if (dev->chip_ops && dev->chip_ops->get_smbios_data)
248 len += dev->chip_ops->get_smbios_data(dev, handle, current);
253 unsigned long smbios_write_tables(unsigned long current)
255 struct smbios_entry *se;
256 unsigned long tables;
259 current = ALIGN(current, 16);
260 printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current);
262 se = (struct smbios_entry *)current;
263 current += sizeof(struct smbios_entry);
264 current = ALIGN(current, 16);
267 len = smbios_write_type0(¤t, handle++);
268 len += smbios_write_type1(¤t, handle++);
269 len += smbios_write_type3(¤t, handle++);
270 len += smbios_write_type4(¤t, handle++);
271 len += smbios_write_type32(¤t, handle++);
273 len += smbios_walk_device_tree(all_devices, &handle, ¤t);
275 len += smbios_write_type127(¤t, handle++);
277 memset(se, 0, sizeof(struct smbios_entry));
278 memcpy(se->anchor, "_SM_", 4);
279 se->length = sizeof(struct smbios_entry);
280 se->major_version = 2;
281 se->minor_version = 7;
282 se->max_struct_size = 24;
283 se->struct_count = handle;
284 memcpy(se->intermediate_anchor_string, "_DMI_", 5);
286 se->struct_table_address = (u32)tables;
287 se->struct_table_length = len;
289 se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10,
290 sizeof(struct smbios_entry) - 0x10);
291 se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry));