3 * SMBios/DMI table generation for PC machine.
5 * Copyright (C) 2008 Nguyen Anh Quynh <aquynh@gmail.com>
6 * Copyright (C) 2002 MandrakeSoft S.A.
8 * This file may be distributed under the terms of the GNU GPLv3 license.
15 #include "smp.h" // smp_cpus
17 static u8 bios_uuid[16];
23 u32 eax, ebx, ecx, edx;
25 // check if backdoor port exists
26 asm volatile ("outl %%eax, %%dx"
27 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
28 : "a" (0x564d5868), "c" (0xa), "d" (0x5658));
29 if (ebx == 0x564d5868) {
30 u32 *uuid_ptr = (u32 *)bios_uuid;
32 asm volatile ("outl %%eax, %%dx"
33 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
34 : "a" (0x564d5868), "c" (0x13), "d" (0x5658));
43 memset(bios_uuid, 0, 16);
47 /* SMBIOS entry point -- must be written to a 16-bit aligned address
48 between 0xf0000 and 0xfffff. */
49 struct smbios_entry_point {
50 char anchor_string[4];
53 u8 smbios_major_version;
54 u8 smbios_minor_version;
55 u16 max_structure_size;
56 u8 entry_point_revision;
58 char intermediate_anchor_string[5];
59 u8 intermediate_checksum;
60 u16 structure_table_length;
61 u32 structure_table_address;
62 u16 number_of_structures;
63 u8 smbios_bcd_revision;
66 /* This goes at the beginning of every SMBIOS structure. */
67 struct smbios_structure_header {
73 /* SMBIOS type 0 - BIOS Information */
74 struct smbios_type_0 {
75 struct smbios_structure_header header;
78 u16 bios_starting_address_segment;
79 u8 bios_release_date_str;
81 u8 bios_characteristics[8];
82 u8 bios_characteristics_extension_bytes[2];
83 u8 system_bios_major_release;
84 u8 system_bios_minor_release;
85 u8 embedded_controller_major_release;
86 u8 embedded_controller_minor_release;
89 /* SMBIOS type 1 - System Information */
90 struct smbios_type_1 {
91 struct smbios_structure_header header;
102 /* SMBIOS type 3 - System Enclosure (v2.3) */
103 struct smbios_type_3 {
104 struct smbios_structure_header header;
108 u8 serial_number_str;
109 u8 asset_tag_number_str;
111 u8 power_supply_state;
116 u8 number_of_power_cords;
117 u8 contained_element_count;
118 // contained elements follow
121 /* SMBIOS type 4 - Processor Information (v2.0) */
122 struct smbios_type_4 {
123 struct smbios_structure_header header;
124 u8 socket_designation_str;
127 u8 processor_manufacturer_str;
129 u8 processor_version_str;
135 u8 processor_upgrade;
138 /* SMBIOS type 16 - Physical Memory Array
139 * Associated with one type 17 (Memory Device).
141 struct smbios_type_16 {
142 struct smbios_structure_header header;
146 u32 maximum_capacity;
147 u16 memory_error_information_handle;
148 u16 number_of_memory_devices;
151 /* SMBIOS type 17 - Memory Device
152 * Associated with one type 19
154 struct smbios_type_17 {
155 struct smbios_structure_header header;
156 u16 physical_memory_array_handle;
157 u16 memory_error_information_handle;
163 u8 device_locator_str;
169 /* SMBIOS type 19 - Memory Array Mapped Address */
170 struct smbios_type_19 {
171 struct smbios_structure_header header;
172 u32 starting_address;
174 u16 memory_array_handle;
178 /* SMBIOS type 20 - Memory Device Mapped Address */
179 struct smbios_type_20 {
180 struct smbios_structure_header header;
181 u32 starting_address;
183 u16 memory_device_handle;
184 u16 memory_array_mapped_address_handle;
185 u8 partition_row_position;
186 u8 interleave_position;
187 u8 interleaved_data_depth;
190 /* SMBIOS type 32 - System Boot Information */
191 struct smbios_type_32 {
192 struct smbios_structure_header header;
197 /* SMBIOS type 127 -- End-of-table */
198 struct smbios_type_127 {
199 struct smbios_structure_header header;
203 smbios_entry_point_init(void *start,
204 u16 max_structure_size,
205 u16 structure_table_length,
206 u32 structure_table_address,
207 u16 number_of_structures)
211 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
213 memcpy(ep->anchor_string, "_SM_", 4);
215 ep->smbios_major_version = 2;
216 ep->smbios_minor_version = 4;
217 ep->max_structure_size = max_structure_size;
218 ep->entry_point_revision = 0;
219 memset(ep->formatted_area, 0, 5);
220 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
222 ep->structure_table_length = structure_table_length;
223 ep->structure_table_address = structure_table_address;
224 ep->number_of_structures = number_of_structures;
225 ep->smbios_bcd_revision = 0x24;
228 ep->intermediate_checksum = 0;
231 for (i = 0; i < 0x10; i++)
232 sum += ((s8 *)start)[i];
236 for (i = 0x10; i < ep->length; i++)
237 sum += ((s8 *)start)[i];
238 ep->intermediate_checksum = -sum;
241 /* Type 0 -- BIOS Information */
242 #define RELEASE_DATE_STR "01/01/2007"
244 smbios_type_0_init(void *start)
246 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
249 p->header.length = sizeof(struct smbios_type_0);
250 p->header.handle = 0;
253 p->bios_version_str = 1;
254 p->bios_starting_address_segment = 0xe800;
255 p->bios_release_date_str = 2;
256 p->bios_rom_size = 0; /* FIXME */
258 memset(p->bios_characteristics, 0, 7);
259 p->bios_characteristics[7] = 0x08; /* BIOS characteristics not supported */
260 p->bios_characteristics_extension_bytes[0] = 0;
261 p->bios_characteristics_extension_bytes[1] = 0;
263 p->system_bios_major_release = 1;
264 p->system_bios_minor_release = 0;
265 p->embedded_controller_major_release = 0xff;
266 p->embedded_controller_minor_release = 0xff;
268 start += sizeof(struct smbios_type_0);
269 memcpy((char *)start, CONFIG_BIOS_NAME, sizeof(CONFIG_BIOS_NAME));
270 start += sizeof(CONFIG_BIOS_NAME);
271 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
272 start += sizeof(RELEASE_DATE_STR);
278 /* Type 1 -- System Information */
280 smbios_type_1_init(void *start)
282 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
284 p->header.length = sizeof(struct smbios_type_1);
285 p->header.handle = 0x100;
287 p->manufacturer_str = 0;
288 p->product_name_str = 0;
290 p->serial_number_str = 0;
292 memcpy(p->uuid, bios_uuid, 16);
294 p->wake_up_type = 0x06; /* power switch */
295 p->sku_number_str = 0;
298 start += sizeof(struct smbios_type_1);
304 /* Type 3 -- System Enclosure */
306 smbios_type_3_init(void *start)
308 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
311 p->header.length = sizeof(struct smbios_type_3);
312 p->header.handle = 0x300;
314 p->manufacturer_str = 0;
315 p->type = 0x01; /* other */
317 p->serial_number_str = 0;
318 p->asset_tag_number_str = 0;
319 p->boot_up_state = 0x03; /* safe */
320 p->power_supply_state = 0x03; /* safe */
321 p->thermal_state = 0x03; /* safe */
322 p->security_status = 0x02; /* unknown */
325 p->number_of_power_cords = 0;
326 p->contained_element_count = 0;
328 start += sizeof(struct smbios_type_3);
334 /* Type 4 -- Processor Information */
336 smbios_type_4_init(void *start, unsigned int cpu_number)
338 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
341 p->header.length = sizeof(struct smbios_type_4);
342 p->header.handle = 0x400 + cpu_number;
344 p->socket_designation_str = 1;
345 p->processor_type = 0x03; /* CPU */
346 p->processor_family = 0x01; /* other */
347 p->processor_manufacturer_str = 0;
349 p->processor_id[0] = cpuid_signature;
350 p->processor_id[1] = cpuid_features;
352 p->processor_version_str = 0;
354 p->external_clock = 0;
356 p->max_speed = 0; /* unknown */
357 p->current_speed = 0; /* unknown */
359 p->status = 0x41; /* socket populated, CPU enabled */
360 p->processor_upgrade = 0x01; /* other */
362 start += sizeof(struct smbios_type_4);
364 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
365 ((char *)start)[4] = cpu_number + '0';
370 /* Type 16 -- Physical Memory Array */
372 smbios_type_16_init(void *start, u32 memsize)
374 struct smbios_type_16 *p = (struct smbios_type_16*)start;
377 p->header.length = sizeof(struct smbios_type_16);
378 p->header.handle = 0x1000;
380 p->location = 0x01; /* other */
381 p->use = 0x03; /* system memory */
382 p->error_correction = 0x01; /* other */
383 p->maximum_capacity = memsize * 1024;
384 p->memory_error_information_handle = 0xfffe; /* none provided */
385 p->number_of_memory_devices = 1;
387 start += sizeof(struct smbios_type_16);
393 /* Type 17 -- Memory Device */
395 smbios_type_17_init(void *start, u32 memory_size_mb)
397 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
400 p->header.length = sizeof(struct smbios_type_17);
401 p->header.handle = 0x1100;
403 p->physical_memory_array_handle = 0x1000;
406 /* truncate memory_size_mb to 16 bits and clear most significant
407 bit [indicates size in MB] */
408 p->size = (u16) memory_size_mb & 0x7fff;
409 p->form_factor = 0x09; /* DIMM */
411 p->device_locator_str = 1;
412 p->bank_locator_str = 0;
413 p->memory_type = 0x07; /* RAM */
416 start += sizeof(struct smbios_type_17);
417 memcpy((char *)start, "DIMM 1", 7);
424 /* Type 19 -- Memory Array Mapped Address */
426 smbios_type_19_init(void *start, u32 memory_size_mb)
428 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
431 p->header.length = sizeof(struct smbios_type_19);
432 p->header.handle = 0x1300;
434 p->starting_address = 0;
435 p->ending_address = (memory_size_mb-1) * 1024;
436 p->memory_array_handle = 0x1000;
437 p->partition_width = 1;
439 start += sizeof(struct smbios_type_19);
445 /* Type 20 -- Memory Device Mapped Address */
447 smbios_type_20_init(void *start, u32 memory_size_mb)
449 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
452 p->header.length = sizeof(struct smbios_type_20);
453 p->header.handle = 0x1400;
455 p->starting_address = 0;
456 p->ending_address = (memory_size_mb-1)*1024;
457 p->memory_device_handle = 0x1100;
458 p->memory_array_mapped_address_handle = 0x1300;
459 p->partition_row_position = 1;
460 p->interleave_position = 0;
461 p->interleaved_data_depth = 0;
463 start += sizeof(struct smbios_type_20);
469 /* Type 32 -- System Boot Information */
471 smbios_type_32_init(void *start)
473 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
476 p->header.length = sizeof(struct smbios_type_32);
477 p->header.handle = 0x2000;
478 memset(p->reserved, 0, 6);
479 p->boot_status = 0; /* no errors detected */
481 start += sizeof(struct smbios_type_32);
487 /* Type 127 -- End of Table */
489 smbios_type_127_init(void *start)
491 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
493 p->header.type = 127;
494 p->header.length = sizeof(struct smbios_type_127);
495 p->header.handle = 0x7f00;
497 start += sizeof(struct smbios_type_127);
506 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
508 int memsize = ram_size / (1024 * 1024);
512 #ifdef CONFIG_USE_EBDA_TABLES
513 ebda_cur_addr = align(ebda_cur_addr, 16);
514 start = (void *)(ebda_cur_addr);
516 bios_table_cur_addr = align(bios_table_cur_addr, 16);
517 start = (void *)(bios_table_cur_addr);
520 p = (char *)start + sizeof(struct smbios_entry_point);
522 #define add_struct(fn) { \
525 if ((q - p) > max_struct_size) \
526 max_struct_size = q - p; \
530 add_struct(smbios_type_0_init(p));
531 add_struct(smbios_type_1_init(p));
532 add_struct(smbios_type_3_init(p));
533 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
534 add_struct(smbios_type_4_init(p, cpu_num));
535 add_struct(smbios_type_16_init(p, memsize));
536 add_struct(smbios_type_17_init(p, memsize));
537 add_struct(smbios_type_19_init(p, memsize));
538 add_struct(smbios_type_20_init(p, memsize));
539 add_struct(smbios_type_32_init(p));
540 add_struct(smbios_type_127_init(p));
544 smbios_entry_point_init( start, max_struct_size,
545 (p - (char *)start) - sizeof(struct smbios_entry_point),
546 (u32)(start + sizeof(struct smbios_entry_point)), nr_structs);
548 #ifdef CONFIG_USE_EBDA_TABLES
549 ebda_cur_addr += (p - (char *)start);
551 bios_table_cur_addr += (p - (char *)start);
554 BX_INFO("SMBIOS table addr=0x%08lx\n", (unsigned long)start);