1 /////////////////////////////////////////////////////////////////////////
3 // 32 bit Bochs BIOS init code
4 // Copyright (C) 2006 Fabrice Bellard
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
11 // This library 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 GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "util.h" // BX_INFO
21 #include "cmos.h" // inb_cmos
22 #include "pci.h" // PCIDevice
23 #include "types.h" // u32
24 #include "config.h" // CONFIG_*
26 // Memory addresses used by this code. (Note global variables (bss)
28 #define CPU_COUNT_ADDR 0xf000
29 #define AP_BOOT_ADDR 0x10000
30 #define BIOS_TMP_STORAGE 0x30000 /* 64 KB used to copy the BIOS to shadow RAM */
32 #define PM_IO_BASE 0xb000
33 #define SMB_IO_BASE 0xb100
35 #define cpuid(index, eax, ebx, ecx, edx) \
36 asm volatile ("cpuid" \
37 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \
40 #define wbinvd() asm volatile("wbinvd")
42 #define CPUID_APIC (1 << 9)
44 #define APIC_BASE ((u8 *)0xfee00000)
45 #define APIC_ICR_LOW 0x300
46 #define APIC_SVR 0x0F0
48 #define APIC_LVT3 0x370
50 #define APIC_ENABLED 0x0100
52 #define MPTABLE_MAX_SIZE 0x00002000
53 #define SMI_CMD_IO_ADDR 0xb2
55 static inline void writel(void *addr, u32 val)
57 *(volatile u32 *)addr = val;
60 static inline void writew(void *addr, u16 val)
62 *(volatile u16 *)addr = val;
65 static inline void writeb(void *addr, u8 val)
67 *(volatile u8 *)addr = val;
70 static inline u32 readl(const void *addr)
72 return *(volatile const u32 *)addr;
75 static inline u16 readw(const void *addr)
77 return *(volatile const u16 *)addr;
80 static inline u8 readb(const void *addr)
82 return *(volatile const u8 *)addr;
88 u32 cpuid_ext_features;
90 #if (CONFIG_USE_EBDA_TABLES == 1)
91 unsigned long ebda_cur_addr;
94 u32 pm_io_base, smb_io_base;
96 unsigned long bios_table_cur_addr;
97 unsigned long bios_table_end_addr;
101 #if (CONFIG_QEMU == 1)
102 u32 eax, ebx, ecx, edx;
104 // check if backdoor port exists
105 asm volatile ("outl %%eax, %%dx"
106 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
107 : "a" (0x564d5868), "c" (0xa), "d" (0x5658));
108 if (ebx == 0x564d5868) {
109 u32 *uuid_ptr = (u32 *)bios_uuid;
111 asm volatile ("outl %%eax, %%dx"
112 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
113 : "a" (0x564d5868), "c" (0x13), "d" (0x5658));
122 memset(bios_uuid, 0, 16);
128 u32 eax, ebx, ecx, edx;
129 cpuid(1, eax, ebx, ecx, edx);
130 cpuid_signature = eax;
131 cpuid_features = edx;
132 cpuid_ext_features = ecx;
135 /****************************************************/
138 extern u8 smp_ap_boot_code_start;
139 extern u8 smp_ap_boot_code_end;
141 /* find the number of CPUs by launching a SIPI to them */
144 u32 val, sipi_vector;
147 if (cpuid_features & CPUID_APIC) {
149 /* enable local APIC */
150 val = readl(APIC_BASE + APIC_SVR);
152 writel(APIC_BASE + APIC_SVR, val);
154 writew((void *)CPU_COUNT_ADDR, 1);
155 /* copy AP boot code */
156 memcpy((void *)AP_BOOT_ADDR, &smp_ap_boot_code_start,
157 &smp_ap_boot_code_end - &smp_ap_boot_code_start);
160 writel(APIC_BASE + APIC_ICR_LOW, 0x000C4500);
161 sipi_vector = AP_BOOT_ADDR >> 12;
162 writel(APIC_BASE + APIC_ICR_LOW, 0x000C4600 | sipi_vector);
166 smp_cpus = readw((void *)CPU_COUNT_ADDR);
168 BX_INFO("Found %d cpu(s)\n", smp_cpus);
171 /****************************************************/
174 #define PCI_ADDRESS_SPACE_MEM 0x00
175 #define PCI_ADDRESS_SPACE_IO 0x01
176 #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
178 #define PCI_ROM_SLOT 6
179 #define PCI_NUM_REGIONS 7
181 #define PCI_DEVICES_MAX 64
183 #define PCI_VENDOR_ID 0x00 /* 16 bits */
184 #define PCI_DEVICE_ID 0x02 /* 16 bits */
185 #define PCI_COMMAND 0x04 /* 16 bits */
186 #define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */
187 #define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */
188 #define PCI_CLASS_DEVICE 0x0a /* Device class */
189 #define PCI_INTERRUPT_LINE 0x3c /* 8 bits */
190 #define PCI_INTERRUPT_PIN 0x3d /* 8 bits */
191 #define PCI_MIN_GNT 0x3e /* 8 bits */
192 #define PCI_MAX_LAT 0x3f /* 8 bits */
194 static u32 pci_bios_io_addr;
195 static u32 pci_bios_mem_addr;
196 static u32 pci_bios_bigmem_addr;
197 /* host irqs corresponding to PCI irqs A-D */
198 static u8 pci_irqs[4] = { 11, 9, 11, 9 };
199 static PCIDevice i440_pcidev;
201 static void pci_set_io_region_addr(PCIDevice *d, int region_num, u32 addr)
206 if ( region_num == PCI_ROM_SLOT ) {
209 ofs = 0x10 + region_num * 4;
212 old_addr = pci_config_readl(d, ofs);
214 pci_config_writel(d, ofs, addr);
215 BX_INFO("region %d: 0x%08x\n", region_num, addr);
217 /* enable memory mappings */
218 cmd = pci_config_readw(d, PCI_COMMAND);
219 if ( region_num == PCI_ROM_SLOT )
221 else if (old_addr & PCI_ADDRESS_SPACE_IO)
225 pci_config_writew(d, PCI_COMMAND, cmd);
228 /* return the global irq number corresponding to a given device irq
229 pin. We could also use the bus number to have a more precise
231 static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
234 slot_addend = (pci_dev->devfn >> 3) - 1;
235 return (irq_num + slot_addend) & 3;
239 copy_bios(PCIDevice *d, int v)
241 pci_config_writeb(d, 0x59, v);
242 memcpy((void *)0x000f0000, (void *)BIOS_TMP_STORAGE, 0x10000);
245 // Test if 'addr' is in the range from 'start'..'start+size'
246 #define IN_RANGE(addr, start, size) ({ \
247 u32 __addr = (addr); \
248 u32 __start = (start); \
249 u32 __size = (size); \
250 (__addr - __start < __size); \
253 static void bios_shadow_init(PCIDevice *d)
255 bios_table_cur_addr = 0xf0000 | OFFSET_freespace2_start;
256 bios_table_end_addr = 0xf0000 | OFFSET_freespace2_end;
257 BX_INFO("bios_table_addr: 0x%08lx end=0x%08lx\n",
258 bios_table_cur_addr, bios_table_end_addr);
260 /* remap the BIOS to shadow RAM an keep it read/write while we
261 are writing tables */
262 int v = pci_config_readb(d, 0x59);
264 pci_config_writeb(d, 0x59, v);
265 memcpy((void *)BIOS_TMP_STORAGE, (void *)0x000f0000, 0x10000);
268 if (IN_RANGE((u32)copy_bios, 0xf0000, 0x10000)) {
269 // Current code is in shadowed area. Perform the copy from
270 // the code that is in the temporary location.
271 u32 pos = (u32)copy_bios - 0xf0000 + BIOS_TMP_STORAGE;
272 void (*func)(PCIDevice *, int) = (void*)pos;
278 // Clear the area just copied.
279 memset((void *)BIOS_TMP_STORAGE, 0, 0x10000);
284 static void bios_lock_shadow_ram(void)
286 PCIDevice *d = &i440_pcidev;
290 v = pci_config_readb(d, 0x59);
291 v = (v & 0x0f) | (0x10);
292 pci_config_writeb(d, 0x59, v);
295 static void pci_bios_init_bridges(PCIDevice *d)
297 u16 vendor_id, device_id;
299 vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
300 device_id = pci_config_readw(d, PCI_DEVICE_ID);
302 if (vendor_id == 0x8086 && device_id == 0x7000) {
310 for(i = 0; i < 4; i++) {
312 /* set to trigger level */
313 elcr[irq >> 3] |= (1 << (irq & 7));
314 /* activate irq remapping in PIIX */
315 pci_config_writeb(d, 0x60 + i, irq);
317 outb(elcr[0], 0x4d0);
318 outb(elcr[1], 0x4d1);
319 BX_INFO("PIIX3 init: elcr=%02x %02x\n",
321 } else if (vendor_id == 0x8086 && device_id == 0x1237) {
322 /* i440 PCI bridge */
328 ".globl smp_ap_boot_code_start\n"
329 ".globl smp_ap_boot_code_end\n"
330 ".global smm_relocation_start\n"
331 ".global smm_relocation_end\n"
332 ".global smm_code_start\n"
333 ".global smm_code_end\n"
336 "smp_ap_boot_code_start:\n"
339 " incw " __stringify(CPU_COUNT_ADDR) "\n"
343 "smp_ap_boot_code_end:\n"
345 /* code to relocate SMBASE to 0xa0000 */
346 "smm_relocation_start:\n"
347 " mov $0x38000 + 0x7efc, %ebx\n"
348 " addr32 mov (%ebx), %al\n" /* revision ID to see if x86_64 or x86 */
351 " mov $0x38000 + 0x7ef8, %ebx\n"
354 " mov $0x38000 + 0x7f00, %ebx\n"
356 " movl $0xa0000, %eax\n"
357 " addr32 movl %eax, (%ebx)\n"
358 /* indicate to the BIOS that the SMM code was executed */
363 "smm_relocation_end:\n"
365 /* minimal SMM code to enable or disable ACPI */
373 " mov $" __stringify(PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
385 " mov $" __stringify(PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
396 extern u8 smm_relocation_start, smm_relocation_end;
397 extern u8 smm_code_start, smm_code_end;
399 #if (CONFIG_USE_SMM == 1)
400 static void smm_init(PCIDevice *d)
404 /* check if SMM init is already done */
405 value = pci_config_readl(d, 0x58);
406 if ((value & (1 << 25)) == 0) {
408 /* copy the SMM relocation code */
409 memcpy((void *)0x38000, &smm_relocation_start,
410 &smm_relocation_end - &smm_relocation_start);
412 /* enable SMI generation when writing to the APMC register */
413 pci_config_writel(d, 0x58, value | (1 << 25));
415 /* init APM status port */
418 /* raise an SMI interrupt */
421 /* wait until SMM code executed */
422 while (inb(0xb3) != 0x00)
425 /* enable the SMM memory window */
426 pci_config_writeb(&i440_pcidev, 0x72, 0x02 | 0x48);
428 /* copy the SMM code */
429 memcpy((void *)0xa8000, &smm_code_start,
430 &smm_code_end - &smm_code_start);
433 /* close the SMM memory window and enable normal SMM */
434 pci_config_writeb(&i440_pcidev, 0x72, 0x02 | 0x08);
439 static void pci_bios_init_device(PCIDevice *d)
443 int i, pin, pic_irq, vendor_id, device_id;
445 class = pci_config_readw(d, PCI_CLASS_DEVICE);
446 vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
447 device_id = pci_config_readw(d, PCI_DEVICE_ID);
448 BX_INFO("PCI: bus=%d devfn=0x%02x: vendor_id=0x%04x device_id=0x%04x\n",
449 d->bus, d->devfn, vendor_id, device_id);
452 if (vendor_id == 0x8086 && device_id == 0x7010) {
454 pci_config_writew(d, 0x40, 0x8000); // enable IDE0
455 pci_config_writew(d, 0x42, 0x8000); // enable IDE1
458 /* IDE: we map it as in ISA mode */
459 pci_set_io_region_addr(d, 0, 0x1f0);
460 pci_set_io_region_addr(d, 1, 0x3f4);
461 pci_set_io_region_addr(d, 2, 0x170);
462 pci_set_io_region_addr(d, 3, 0x374);
466 if (vendor_id != 0x1234)
468 /* VGA: map frame buffer to default Bochs VBE address */
469 pci_set_io_region_addr(d, 0, 0xE0000000);
473 if (vendor_id == 0x1014) {
475 if (device_id == 0x0046 || device_id == 0xFFFF) {
477 pci_set_io_region_addr(d, 0, 0x80800000 + 0x00040000);
482 if (vendor_id == 0x0106b &&
483 (device_id == 0x0017 || device_id == 0x0022)) {
485 pci_set_io_region_addr(d, 0, 0x80800000);
490 /* default memory mappings */
491 for(i = 0; i < PCI_NUM_REGIONS; i++) {
495 if (i == PCI_ROM_SLOT)
499 pci_config_writel(d, ofs, 0xffffffff);
500 val = pci_config_readl(d, ofs);
502 size = (~(val & ~0xf)) + 1;
503 if (val & PCI_ADDRESS_SPACE_IO)
504 paddr = &pci_bios_io_addr;
505 else if (size >= 0x04000000)
506 paddr = &pci_bios_bigmem_addr;
508 paddr = &pci_bios_mem_addr;
509 *paddr = (*paddr + size - 1) & ~(size - 1);
510 pci_set_io_region_addr(d, i, *paddr);
517 /* map the interrupt */
518 pin = pci_config_readb(d, PCI_INTERRUPT_PIN);
520 pin = pci_slot_get_pirq(d, pin - 1);
521 pic_irq = pci_irqs[pin];
522 pci_config_writeb(d, PCI_INTERRUPT_LINE, pic_irq);
525 if (vendor_id == 0x8086 && device_id == 0x7113) {
526 /* PIIX4 Power Management device (for ACPI) */
527 pm_io_base = PM_IO_BASE;
528 pci_config_writel(d, 0x40, pm_io_base | 1);
529 pci_config_writeb(d, 0x80, 0x01); /* enable PM io space */
530 smb_io_base = SMB_IO_BASE;
531 pci_config_writel(d, 0x90, smb_io_base | 1);
532 pci_config_writeb(d, 0xd2, 0x09); /* enable SMBus io space */
533 pm_sci_int = pci_config_readb(d, PCI_INTERRUPT_LINE);
534 #if (CONFIG_USE_SMM == 1)
541 void pci_for_each_device(void (*init_func)(PCIDevice *d))
543 PCIDevice d1, *d = &d1;
545 u16 vendor_id, device_id;
547 for(bus = 0; bus < 1; bus++) {
548 for(devfn = 0; devfn < 256; devfn++) {
551 vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
552 device_id = pci_config_readw(d, PCI_DEVICE_ID);
553 if (vendor_id != 0xffff || device_id != 0xffff) {
560 void pci_bios_init(void)
562 pci_bios_io_addr = 0xc000;
563 pci_bios_mem_addr = 0xf0000000;
564 pci_bios_bigmem_addr = GET_EBDA(ram_size);
565 if (pci_bios_bigmem_addr < 0x90000000)
566 pci_bios_bigmem_addr = 0x90000000;
568 pci_for_each_device(pci_bios_init_bridges);
570 pci_for_each_device(pci_bios_init_device);
573 /****************************************************/
574 /* Multi Processor table init */
576 static void putb(u8 **pp, int val)
584 static void putstr(u8 **pp, const char *str)
593 static void putle16(u8 **pp, int val)
602 static void putle32(u8 **pp, int val)
613 static unsigned long align(unsigned long addr, unsigned long v)
615 return (addr + v - 1) & ~(v - 1);
618 static void mptable_init(void)
620 u8 *mp_config_table, *q, *float_pointer_struct;
621 int ioapic_id, i, len;
622 int mp_config_table_size;
624 #if (CONFIG_QEMU == 1)
629 #if (CONFIG_USE_EBDA_TABLES == 1)
630 mp_config_table = (u8 *)(GET_EBDA(ram_size) - CONFIG_ACPI_DATA_SIZE
633 bios_table_cur_addr = align(bios_table_cur_addr, 16);
634 mp_config_table = (u8 *)bios_table_cur_addr;
637 putstr(&q, "PCMP"); /* "PCMP signature */
638 putle16(&q, 0); /* table length (patched later) */
639 putb(&q, 4); /* spec rev */
640 putb(&q, 0); /* checksum (patched later) */
641 #if (CONFIG_QEMU == 1)
642 putstr(&q, "QEMUCPU "); /* OEM id */
644 putstr(&q, "BOCHSCPU");
646 putstr(&q, "0.1 "); /* vendor id */
647 putle32(&q, 0); /* OEM table ptr */
648 putle16(&q, 0); /* OEM table size */
649 putle16(&q, smp_cpus + 18); /* entry count */
650 putle32(&q, 0xfee00000); /* local APIC addr */
651 putle16(&q, 0); /* ext table length */
652 putb(&q, 0); /* ext table checksum */
653 putb(&q, 0); /* reserved */
655 for(i = 0; i < smp_cpus; i++) {
656 putb(&q, 0); /* entry type = processor */
657 putb(&q, i); /* APIC id */
658 putb(&q, 0x11); /* local APIC version number */
660 putb(&q, 3); /* cpu flags: enabled, bootstrap cpu */
662 putb(&q, 1); /* cpu flags: enabled */
663 putb(&q, 0); /* cpu signature */
667 putle16(&q, 0x201); /* feature flags */
670 putle16(&q, 0); /* reserved */
677 putb(&q, 1); /* entry type = bus */
678 putb(&q, 0); /* bus ID */
682 ioapic_id = smp_cpus;
683 putb(&q, 2); /* entry type = I/O APIC */
684 putb(&q, ioapic_id); /* apic ID */
685 putb(&q, 0x11); /* I/O APIC version number */
686 putb(&q, 1); /* enable */
687 putle32(&q, 0xfec00000); /* I/O APIC addr */
690 for(i = 0; i < 16; i++) {
691 putb(&q, 3); /* entry type = I/O interrupt */
692 putb(&q, 0); /* interrupt type = vectored interrupt */
693 putb(&q, 0); /* flags: po=0, el=0 */
695 putb(&q, 0); /* source bus ID = ISA */
696 putb(&q, i); /* source bus IRQ */
697 putb(&q, ioapic_id); /* dest I/O APIC ID */
698 putb(&q, i); /* dest I/O APIC interrupt in */
701 len = q - mp_config_table;
702 mp_config_table[4] = len;
703 mp_config_table[5] = len >> 8;
705 mp_config_table[7] = -checksum(mp_config_table, q - mp_config_table);
707 mp_config_table_size = q - mp_config_table;
709 #if (CONFIG_USE_EBDA_TABLES != 1)
710 bios_table_cur_addr += mp_config_table_size;
713 /* floating pointer structure */
714 #if (CONFIG_USE_EBDA_TABLES == 1)
715 ebda_cur_addr = align(ebda_cur_addr, 16);
716 float_pointer_struct = (u8 *)ebda_cur_addr;
718 bios_table_cur_addr = align(bios_table_cur_addr, 16);
719 float_pointer_struct = (u8 *)bios_table_cur_addr;
721 q = float_pointer_struct;
723 /* pointer to MP config table */
724 putle32(&q, (unsigned long)mp_config_table);
726 putb(&q, 1); /* length in 16 byte units */
727 putb(&q, 4); /* MP spec revision */
728 putb(&q, 0); /* checksum (patched later) */
729 putb(&q, 0); /* MP feature byte 1 */
735 float_pointer_struct[10] = -checksum(float_pointer_struct
736 , q - float_pointer_struct);
737 #if (CONFIG_USE_EBDA_TABLES == 1)
738 ebda_cur_addr += (q - float_pointer_struct);
740 bios_table_cur_addr += (q - float_pointer_struct);
742 BX_INFO("MP table addr=0x%08lx MPC table addr=0x%08lx size=0x%x\n",
743 (unsigned long)float_pointer_struct,
744 (unsigned long)mp_config_table,
745 mp_config_table_size);
748 /****************************************************/
749 /* ACPI tables init */
751 /* Table structure from Linux kernel (the ACPI tables are under the
754 #define ACPI_TABLE_HEADER_DEF /* ACPI common table header */ \
755 u8 signature [4]; /* ACPI signature (4 ASCII characters) */\
756 u32 length; /* Length of table, in bytes, including header */\
757 u8 revision; /* ACPI Specification minor version # */\
758 u8 checksum; /* To make sum of entire table == 0 */\
759 u8 oem_id [6]; /* OEM identification */\
760 u8 oem_table_id [8]; /* OEM table identification */\
761 u32 oem_revision; /* OEM revision number */\
762 u8 asl_compiler_id [4]; /* ASL compiler vendor ID */\
763 u32 asl_compiler_revision; /* ASL compiler revision number */
766 struct acpi_table_header /* ACPI common table header */
768 ACPI_TABLE_HEADER_DEF
771 struct rsdp_descriptor /* Root System Descriptor Pointer */
773 u8 signature [8]; /* ACPI signature, contains "RSD PTR " */
774 u8 checksum; /* To make sum of struct == 0 */
775 u8 oem_id [6]; /* OEM identification */
776 u8 revision; /* Must be 0 for 1.0, 2 for 2.0 */
777 u32 rsdt_physical_address; /* 32-bit physical address of RSDT */
778 u32 length; /* XSDT Length in bytes including hdr */
779 u64 xsdt_physical_address; /* 64-bit physical address of XSDT */
780 u8 extended_checksum; /* Checksum of entire table */
781 u8 reserved [3]; /* Reserved field must be 0 */
785 * ACPI 1.0 Root System Description Table (RSDT)
787 struct rsdt_descriptor_rev1
789 ACPI_TABLE_HEADER_DEF /* ACPI common table header */
790 u32 table_offset_entry [3]; /* Array of pointers to other */
795 * ACPI 1.0 Firmware ACPI Control Structure (FACS)
797 struct facs_descriptor_rev1
799 u8 signature[4]; /* ACPI Signature */
800 u32 length; /* Length of structure, in bytes */
801 u32 hardware_signature; /* Hardware configuration signature */
802 u32 firmware_waking_vector; /* ACPI OS waking vector */
803 u32 global_lock; /* Global Lock */
804 u32 S4bios_f : 1; /* Indicates if S4BIOS support is present */
805 u32 reserved1 : 31; /* Must be 0 */
806 u8 resverved3 [40]; /* Reserved - must be zero */
811 * ACPI 1.0 Fixed ACPI Description Table (FADT)
813 struct fadt_descriptor_rev1
815 ACPI_TABLE_HEADER_DEF /* ACPI common table header */
816 u32 firmware_ctrl; /* Physical address of FACS */
817 u32 dsdt; /* Physical address of DSDT */
818 u8 model; /* System Interrupt Model */
819 u8 reserved1; /* Reserved */
820 u16 sci_int; /* System vector of SCI interrupt */
821 u32 smi_cmd; /* Port address of SMI command port */
822 u8 acpi_enable; /* Value to write to smi_cmd to enable ACPI */
823 u8 acpi_disable; /* Value to write to smi_cmd to disable ACPI */
824 u8 S4bios_req; /* Value to write to SMI CMD to enter S4BIOS state */
825 u8 reserved2; /* Reserved - must be zero */
826 u32 pm1a_evt_blk; /* Port address of Power Mgt 1a acpi_event Reg Blk */
827 u32 pm1b_evt_blk; /* Port address of Power Mgt 1b acpi_event Reg Blk */
828 u32 pm1a_cnt_blk; /* Port address of Power Mgt 1a Control Reg Blk */
829 u32 pm1b_cnt_blk; /* Port address of Power Mgt 1b Control Reg Blk */
830 u32 pm2_cnt_blk; /* Port address of Power Mgt 2 Control Reg Blk */
831 u32 pm_tmr_blk; /* Port address of Power Mgt Timer Ctrl Reg Blk */
832 u32 gpe0_blk; /* Port addr of General Purpose acpi_event 0 Reg Blk */
833 u32 gpe1_blk; /* Port addr of General Purpose acpi_event 1 Reg Blk */
834 u8 pm1_evt_len; /* Byte length of ports at pm1_x_evt_blk */
835 u8 pm1_cnt_len; /* Byte length of ports at pm1_x_cnt_blk */
836 u8 pm2_cnt_len; /* Byte Length of ports at pm2_cnt_blk */
837 u8 pm_tmr_len; /* Byte Length of ports at pm_tm_blk */
838 u8 gpe0_blk_len; /* Byte Length of ports at gpe0_blk */
839 u8 gpe1_blk_len; /* Byte Length of ports at gpe1_blk */
840 u8 gpe1_base; /* Offset in gpe model where gpe1 events start */
841 u8 reserved3; /* Reserved */
842 u16 plvl2_lat; /* Worst case HW latency to enter/exit C2 state */
843 u16 plvl3_lat; /* Worst case HW latency to enter/exit C3 state */
844 u16 flush_size; /* Size of area read to flush caches */
845 u16 flush_stride; /* Stride used in flushing caches */
846 u8 duty_offset; /* Bit location of duty cycle field in p_cnt reg */
847 u8 duty_width; /* Bit width of duty cycle field in p_cnt reg */
848 u8 day_alrm; /* Index to day-of-month alarm in RTC CMOS RAM */
849 u8 mon_alrm; /* Index to month-of-year alarm in RTC CMOS RAM */
850 u8 century; /* Index to century in RTC CMOS RAM */
851 u8 reserved4; /* Reserved */
852 u8 reserved4a; /* Reserved */
853 u8 reserved4b; /* Reserved */
855 u32 wb_invd : 1; /* The wbinvd instruction works properly */
856 u32 wb_invd_flush : 1; /* The wbinvd flushes but does not invalidate */
857 u32 proc_c1 : 1; /* All processors support C1 state */
858 u32 plvl2_up : 1; /* C2 state works on MP system */
859 u32 pwr_button : 1; /* Power button is handled as a generic feature */
860 u32 sleep_button : 1; /* Sleep button is handled as a generic feature, or not present */
861 u32 fixed_rTC : 1; /* RTC wakeup stat not in fixed register space */
862 u32 rtcs4 : 1; /* RTC wakeup stat not possible from S4 */
863 u32 tmr_val_ext : 1; /* The tmr_val width is 32 bits (0 = 24 bits) */
864 u32 reserved5 : 23; /* Reserved - must be zero */
871 * MADT values and structures
874 /* Values for MADT PCATCompat */
877 #define MULTIPLE_APIC 1
882 struct multiple_apic_table
884 ACPI_TABLE_HEADER_DEF /* ACPI common table header */
885 u32 local_apic_address; /* Physical address of local APIC */
887 u32 PCATcompat : 1; /* A one indicates system also has dual 8259s */
895 /* Values for Type in APIC_HEADER_DEF */
897 #define APIC_PROCESSOR 0
899 #define APIC_XRUPT_OVERRIDE 2
901 #define APIC_LOCAL_NMI 4
902 #define APIC_ADDRESS_OVERRIDE 5
903 #define APIC_IO_SAPIC 6
904 #define APIC_LOCAL_SAPIC 7
905 #define APIC_XRUPT_SOURCE 8
906 #define APIC_RESERVED 9 /* 9 and greater are reserved */
909 * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE)
911 #define APIC_HEADER_DEF /* Common APIC sub-structure header */\
915 /* Sub-structures for MADT */
917 struct madt_processor_apic
920 u8 processor_id; /* ACPI processor id */
921 u8 local_apic_id; /* Processor's local APIC id */
923 u32 processor_enabled: 1; /* Processor is usable if set */
924 u32 reserved2 : 31; /* Reserved, must be zero */
933 u8 io_apic_id; /* I/O APIC ID */
934 u8 reserved; /* Reserved - must be zero */
935 u32 address; /* APIC physical address */
936 u32 interrupt; /* Global system interrupt where INTI
940 #include "acpi-dsdt.hex"
942 static inline u16 cpu_to_le16(u16 x)
947 static inline u32 cpu_to_le32(u32 x)
952 static void acpi_build_table_header(struct acpi_table_header *h,
953 char *sig, int len, u8 rev)
955 memcpy(h->signature, sig, 4);
956 h->length = cpu_to_le32(len);
958 #if (CONFIG_QEMU == 1)
959 memcpy(h->oem_id, "QEMU ", 6);
960 memcpy(h->oem_table_id, "QEMU", 4);
962 memcpy(h->oem_id, "BOCHS ", 6);
963 memcpy(h->oem_table_id, "BXPC", 4);
965 memcpy(h->oem_table_id + 4, sig, 4);
966 h->oem_revision = cpu_to_le32(1);
967 #if (CONFIG_QEMU == 1)
968 memcpy(h->asl_compiler_id, "QEMU", 4);
970 memcpy(h->asl_compiler_id, "BXPC", 4);
972 h->asl_compiler_revision = cpu_to_le32(1);
973 h->checksum = -checksum((void *)h, len);
976 int acpi_build_processor_ssdt(u8 *ssdt)
980 int acpi_cpus = smp_cpus > 0xff ? 0xff : smp_cpus;
982 ssdt_ptr[9] = 0; // checksum;
983 ssdt_ptr += sizeof(struct acpi_table_header);
985 // caluculate the length of processor block and scope block excluding PkgLength
986 length = 0x0d * acpi_cpus + 4;
988 // build processor scope header
989 *(ssdt_ptr++) = 0x10; // ScopeOp
990 if (length <= 0x3e) {
991 *(ssdt_ptr++) = length + 1;
993 *(ssdt_ptr++) = 0x7F;
994 *(ssdt_ptr++) = (length + 2) >> 6;
996 *(ssdt_ptr++) = '_'; // Name
1001 // build object for each processor
1002 for(i=0;i<acpi_cpus;i++) {
1003 *(ssdt_ptr++) = 0x5B; // ProcessorOp
1004 *(ssdt_ptr++) = 0x83;
1005 *(ssdt_ptr++) = 0x0B; // Length
1006 *(ssdt_ptr++) = 'C'; // Name (CPUxx)
1007 *(ssdt_ptr++) = 'P';
1008 if ((i & 0xf0) != 0)
1009 *(ssdt_ptr++) = (i >> 4) < 0xa ? (i >> 4) + '0' : (i >> 4) + 'A' - 0xa;
1011 *(ssdt_ptr++) = 'U';
1012 *(ssdt_ptr++) = (i & 0xf) < 0xa ? (i & 0xf) + '0' : (i & 0xf) + 'A' - 0xa;
1014 *(ssdt_ptr++) = 0x10; // Processor block address
1015 *(ssdt_ptr++) = 0xb0;
1018 *(ssdt_ptr++) = 6; // Processor block length
1021 acpi_build_table_header((struct acpi_table_header *)ssdt,
1022 "SSDT", ssdt_ptr - ssdt, 1);
1024 return ssdt_ptr - ssdt;
1027 /* base_addr must be a multiple of 4KB */
1028 void acpi_bios_init(void)
1030 struct rsdp_descriptor *rsdp;
1031 struct rsdt_descriptor_rev1 *rsdt;
1032 struct fadt_descriptor_rev1 *fadt;
1033 struct facs_descriptor_rev1 *facs;
1034 struct multiple_apic_table *madt;
1036 u32 base_addr, rsdt_addr, fadt_addr, addr, facs_addr, dsdt_addr, ssdt_addr;
1037 u32 acpi_tables_size, madt_addr, madt_size;
1040 /* reserve memory space for tables */
1041 #if (CONFIG_USE_EBDA_TABLES == 1)
1042 ebda_cur_addr = align(ebda_cur_addr, 16);
1043 rsdp = (void *)(ebda_cur_addr);
1044 ebda_cur_addr += sizeof(*rsdp);
1046 bios_table_cur_addr = align(bios_table_cur_addr, 16);
1047 rsdp = (void *)(bios_table_cur_addr);
1048 bios_table_cur_addr += sizeof(*rsdp);
1051 addr = base_addr = GET_EBDA(ram_size) - CONFIG_ACPI_DATA_SIZE;
1053 rsdt = (void *)(addr);
1054 addr += sizeof(*rsdt);
1057 fadt = (void *)(addr);
1058 addr += sizeof(*fadt);
1060 /* XXX: FACS should be in RAM */
1061 addr = (addr + 63) & ~63; /* 64 byte alignment for FACS */
1063 facs = (void *)(addr);
1064 addr += sizeof(*facs);
1067 dsdt = (void *)(addr);
1068 addr += sizeof(AmlCode);
1071 ssdt = (void *)(addr);
1072 addr += acpi_build_processor_ssdt(ssdt);
1074 addr = (addr + 7) & ~7;
1076 madt_size = sizeof(*madt) +
1077 sizeof(struct madt_processor_apic) * smp_cpus +
1078 sizeof(struct madt_io_apic);
1079 madt = (void *)(addr);
1082 acpi_tables_size = addr - base_addr;
1084 BX_INFO("ACPI tables: RSDP addr=0x%08lx ACPI DATA addr=0x%08lx size=0x%x\n",
1085 (unsigned long)rsdp,
1086 (unsigned long)rsdt, acpi_tables_size);
1089 memset(rsdp, 0, sizeof(*rsdp));
1090 memcpy(rsdp->signature, "RSD PTR ", 8);
1091 #if (CONFIG_QEMU == 1)
1092 memcpy(rsdp->oem_id, "QEMU ", 6);
1094 memcpy(rsdp->oem_id, "BOCHS ", 6);
1096 rsdp->rsdt_physical_address = cpu_to_le32(rsdt_addr);
1097 rsdp->checksum = -checksum((void *)rsdp, 20);
1100 memset(rsdt, 0, sizeof(*rsdt));
1101 rsdt->table_offset_entry[0] = cpu_to_le32(fadt_addr);
1102 rsdt->table_offset_entry[1] = cpu_to_le32(madt_addr);
1103 rsdt->table_offset_entry[2] = cpu_to_le32(ssdt_addr);
1104 acpi_build_table_header((struct acpi_table_header *)rsdt,
1105 "RSDT", sizeof(*rsdt), 1);
1108 memset(fadt, 0, sizeof(*fadt));
1109 fadt->firmware_ctrl = cpu_to_le32(facs_addr);
1110 fadt->dsdt = cpu_to_le32(dsdt_addr);
1112 fadt->reserved1 = 0;
1113 fadt->sci_int = cpu_to_le16(pm_sci_int);
1114 fadt->smi_cmd = cpu_to_le32(SMI_CMD_IO_ADDR);
1115 fadt->acpi_enable = 0xf1;
1116 fadt->acpi_disable = 0xf0;
1117 fadt->pm1a_evt_blk = cpu_to_le32(pm_io_base);
1118 fadt->pm1a_cnt_blk = cpu_to_le32(pm_io_base + 0x04);
1119 fadt->pm_tmr_blk = cpu_to_le32(pm_io_base + 0x08);
1120 fadt->pm1_evt_len = 4;
1121 fadt->pm1_cnt_len = 2;
1122 fadt->pm_tmr_len = 4;
1123 fadt->plvl2_lat = cpu_to_le16(0xfff); // C2 state not supported
1124 fadt->plvl3_lat = cpu_to_le16(0xfff); // C3 state not supported
1125 /* WBINVD + PROC_C1 + PWR_BUTTON + SLP_BUTTON + FIX_RTC */
1126 fadt->flags = cpu_to_le32((1 << 0) | (1 << 2) | (1 << 4) | (1 << 5) | (1 << 6));
1127 acpi_build_table_header((struct acpi_table_header *)fadt, "FACP",
1131 memset(facs, 0, sizeof(*facs));
1132 memcpy(facs->signature, "FACS", 4);
1133 facs->length = cpu_to_le32(sizeof(*facs));
1136 memcpy(dsdt, AmlCode, sizeof(AmlCode));
1140 struct madt_processor_apic *apic;
1141 struct madt_io_apic *io_apic;
1143 memset(madt, 0, madt_size);
1144 madt->local_apic_address = cpu_to_le32(0xfee00000);
1145 madt->flags = cpu_to_le32(1);
1146 apic = (void *)(madt + 1);
1147 for(i=0;i<smp_cpus;i++) {
1148 apic->type = APIC_PROCESSOR;
1149 apic->length = sizeof(*apic);
1150 apic->processor_id = i;
1151 apic->local_apic_id = i;
1152 apic->flags = cpu_to_le32(1);
1155 io_apic = (void *)apic;
1156 io_apic->type = APIC_IO;
1157 io_apic->length = sizeof(*io_apic);
1158 io_apic->io_apic_id = smp_cpus;
1159 io_apic->address = cpu_to_le32(0xfec00000);
1160 io_apic->interrupt = cpu_to_le32(0);
1162 acpi_build_table_header((struct acpi_table_header *)madt,
1163 "APIC", madt_size, 1);
1167 /* SMBIOS entry point -- must be written to a 16-bit aligned address
1168 between 0xf0000 and 0xfffff.
1170 struct smbios_entry_point {
1171 char anchor_string[4];
1174 u8 smbios_major_version;
1175 u8 smbios_minor_version;
1176 u16 max_structure_size;
1177 u8 entry_point_revision;
1178 u8 formatted_area[5];
1179 char intermediate_anchor_string[5];
1180 u8 intermediate_checksum;
1181 u16 structure_table_length;
1182 u32 structure_table_address;
1183 u16 number_of_structures;
1184 u8 smbios_bcd_revision;
1185 } __attribute__((__packed__));
1187 /* This goes at the beginning of every SMBIOS structure. */
1188 struct smbios_structure_header {
1192 } __attribute__((__packed__));
1194 /* SMBIOS type 0 - BIOS Information */
1195 struct smbios_type_0 {
1196 struct smbios_structure_header header;
1198 u8 bios_version_str;
1199 u16 bios_starting_address_segment;
1200 u8 bios_release_date_str;
1202 u8 bios_characteristics[8];
1203 u8 bios_characteristics_extension_bytes[2];
1204 u8 system_bios_major_release;
1205 u8 system_bios_minor_release;
1206 u8 embedded_controller_major_release;
1207 u8 embedded_controller_minor_release;
1208 } __attribute__((__packed__));
1210 /* SMBIOS type 1 - System Information */
1211 struct smbios_type_1 {
1212 struct smbios_structure_header header;
1213 u8 manufacturer_str;
1214 u8 product_name_str;
1216 u8 serial_number_str;
1221 } __attribute__((__packed__));
1223 /* SMBIOS type 3 - System Enclosure (v2.3) */
1224 struct smbios_type_3 {
1225 struct smbios_structure_header header;
1226 u8 manufacturer_str;
1229 u8 serial_number_str;
1230 u8 asset_tag_number_str;
1232 u8 power_supply_state;
1237 u8 number_of_power_cords;
1238 u8 contained_element_count;
1239 // contained elements follow
1240 } __attribute__((__packed__));
1242 /* SMBIOS type 4 - Processor Information (v2.0) */
1243 struct smbios_type_4 {
1244 struct smbios_structure_header header;
1245 u8 socket_designation_str;
1247 u8 processor_family;
1248 u8 processor_manufacturer_str;
1249 u32 processor_id[2];
1250 u8 processor_version_str;
1256 u8 processor_upgrade;
1257 } __attribute__((__packed__));
1259 /* SMBIOS type 16 - Physical Memory Array
1260 * Associated with one type 17 (Memory Device).
1262 struct smbios_type_16 {
1263 struct smbios_structure_header header;
1266 u8 error_correction;
1267 u32 maximum_capacity;
1268 u16 memory_error_information_handle;
1269 u16 number_of_memory_devices;
1270 } __attribute__((__packed__));
1272 /* SMBIOS type 17 - Memory Device
1273 * Associated with one type 19
1275 struct smbios_type_17 {
1276 struct smbios_structure_header header;
1277 u16 physical_memory_array_handle;
1278 u16 memory_error_information_handle;
1284 u8 device_locator_str;
1285 u8 bank_locator_str;
1288 } __attribute__((__packed__));
1290 /* SMBIOS type 19 - Memory Array Mapped Address */
1291 struct smbios_type_19 {
1292 struct smbios_structure_header header;
1293 u32 starting_address;
1295 u16 memory_array_handle;
1297 } __attribute__((__packed__));
1299 /* SMBIOS type 20 - Memory Device Mapped Address */
1300 struct smbios_type_20 {
1301 struct smbios_structure_header header;
1302 u32 starting_address;
1304 u16 memory_device_handle;
1305 u16 memory_array_mapped_address_handle;
1306 u8 partition_row_position;
1307 u8 interleave_position;
1308 u8 interleaved_data_depth;
1309 } __attribute__((__packed__));
1311 /* SMBIOS type 32 - System Boot Information */
1312 struct smbios_type_32 {
1313 struct smbios_structure_header header;
1316 } __attribute__((__packed__));
1318 /* SMBIOS type 127 -- End-of-table */
1319 struct smbios_type_127 {
1320 struct smbios_structure_header header;
1321 } __attribute__((__packed__));
1324 smbios_entry_point_init(void *start,
1325 u16 max_structure_size,
1326 u16 structure_table_length,
1327 u32 structure_table_address,
1328 u16 number_of_structures)
1330 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
1332 memcpy(ep->anchor_string, "_SM_", 4);
1334 ep->smbios_major_version = 2;
1335 ep->smbios_minor_version = 4;
1336 ep->max_structure_size = max_structure_size;
1337 ep->entry_point_revision = 0;
1338 memset(ep->formatted_area, 0, 5);
1339 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
1341 ep->structure_table_length = structure_table_length;
1342 ep->structure_table_address = structure_table_address;
1343 ep->number_of_structures = number_of_structures;
1344 ep->smbios_bcd_revision = 0x24;
1347 ep->intermediate_checksum = 0;
1349 ep->checksum = -checksum(start, 0x10);
1351 ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
1354 /* Type 0 -- BIOS Information */
1355 #define RELEASE_DATE_STR "01/01/2007"
1357 smbios_type_0_init(void *start)
1359 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
1362 p->header.length = sizeof(struct smbios_type_0);
1363 p->header.handle = 0;
1366 p->bios_version_str = 1;
1367 p->bios_starting_address_segment = 0xe800;
1368 p->bios_release_date_str = 2;
1369 p->bios_rom_size = 0; /* FIXME */
1371 memset(p->bios_characteristics, 0, 7);
1372 p->bios_characteristics[7] = 0x08; /* BIOS characteristics not supported */
1373 p->bios_characteristics_extension_bytes[0] = 0;
1374 p->bios_characteristics_extension_bytes[1] = 0;
1376 p->system_bios_major_release = 1;
1377 p->system_bios_minor_release = 0;
1378 p->embedded_controller_major_release = 0xff;
1379 p->embedded_controller_minor_release = 0xff;
1381 start += sizeof(struct smbios_type_0);
1382 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
1383 start += sizeof(CONFIG_APPNAME);
1384 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
1385 start += sizeof(RELEASE_DATE_STR);
1391 /* Type 1 -- System Information */
1393 smbios_type_1_init(void *start)
1395 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
1397 p->header.length = sizeof(struct smbios_type_1);
1398 p->header.handle = 0x100;
1400 p->manufacturer_str = 0;
1401 p->product_name_str = 0;
1403 p->serial_number_str = 0;
1405 memcpy(p->uuid, bios_uuid, 16);
1407 p->wake_up_type = 0x06; /* power switch */
1408 p->sku_number_str = 0;
1411 start += sizeof(struct smbios_type_1);
1412 *((u16 *)start) = 0;
1417 /* Type 3 -- System Enclosure */
1419 smbios_type_3_init(void *start)
1421 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
1424 p->header.length = sizeof(struct smbios_type_3);
1425 p->header.handle = 0x300;
1427 p->manufacturer_str = 0;
1428 p->type = 0x01; /* other */
1430 p->serial_number_str = 0;
1431 p->asset_tag_number_str = 0;
1432 p->boot_up_state = 0x03; /* safe */
1433 p->power_supply_state = 0x03; /* safe */
1434 p->thermal_state = 0x03; /* safe */
1435 p->security_status = 0x02; /* unknown */
1438 p->number_of_power_cords = 0;
1439 p->contained_element_count = 0;
1441 start += sizeof(struct smbios_type_3);
1442 *((u16 *)start) = 0;
1447 /* Type 4 -- Processor Information */
1449 smbios_type_4_init(void *start, unsigned int cpu_number)
1451 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
1454 p->header.length = sizeof(struct smbios_type_4);
1455 p->header.handle = 0x400 + cpu_number;
1457 p->socket_designation_str = 1;
1458 p->processor_type = 0x03; /* CPU */
1459 p->processor_family = 0x01; /* other */
1460 p->processor_manufacturer_str = 0;
1462 p->processor_id[0] = cpuid_signature;
1463 p->processor_id[1] = cpuid_features;
1465 p->processor_version_str = 0;
1467 p->external_clock = 0;
1469 p->max_speed = 0; /* unknown */
1470 p->current_speed = 0; /* unknown */
1472 p->status = 0x41; /* socket populated, CPU enabled */
1473 p->processor_upgrade = 0x01; /* other */
1475 start += sizeof(struct smbios_type_4);
1477 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
1478 ((char *)start)[4] = cpu_number + '0';
1483 /* Type 16 -- Physical Memory Array */
1485 smbios_type_16_init(void *start, u32 memsize)
1487 struct smbios_type_16 *p = (struct smbios_type_16*)start;
1489 p->header.type = 16;
1490 p->header.length = sizeof(struct smbios_type_16);
1491 p->header.handle = 0x1000;
1493 p->location = 0x01; /* other */
1494 p->use = 0x03; /* system memory */
1495 p->error_correction = 0x01; /* other */
1496 p->maximum_capacity = memsize * 1024;
1497 p->memory_error_information_handle = 0xfffe; /* none provided */
1498 p->number_of_memory_devices = 1;
1500 start += sizeof(struct smbios_type_16);
1501 *((u16 *)start) = 0;
1506 /* Type 17 -- Memory Device */
1508 smbios_type_17_init(void *start, u32 memory_size_mb)
1510 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
1512 p->header.type = 17;
1513 p->header.length = sizeof(struct smbios_type_17);
1514 p->header.handle = 0x1100;
1516 p->physical_memory_array_handle = 0x1000;
1517 p->total_width = 64;
1519 /* truncate memory_size_mb to 16 bits and clear most significant
1520 bit [indicates size in MB] */
1521 p->size = (u16) memory_size_mb & 0x7fff;
1522 p->form_factor = 0x09; /* DIMM */
1524 p->device_locator_str = 1;
1525 p->bank_locator_str = 0;
1526 p->memory_type = 0x07; /* RAM */
1529 start += sizeof(struct smbios_type_17);
1530 memcpy((char *)start, "DIMM 1", 7);
1537 /* Type 19 -- Memory Array Mapped Address */
1539 smbios_type_19_init(void *start, u32 memory_size_mb)
1541 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
1543 p->header.type = 19;
1544 p->header.length = sizeof(struct smbios_type_19);
1545 p->header.handle = 0x1300;
1547 p->starting_address = 0;
1548 p->ending_address = (memory_size_mb-1) * 1024;
1549 p->memory_array_handle = 0x1000;
1550 p->partition_width = 1;
1552 start += sizeof(struct smbios_type_19);
1553 *((u16 *)start) = 0;
1558 /* Type 20 -- Memory Device Mapped Address */
1560 smbios_type_20_init(void *start, u32 memory_size_mb)
1562 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
1564 p->header.type = 20;
1565 p->header.length = sizeof(struct smbios_type_20);
1566 p->header.handle = 0x1400;
1568 p->starting_address = 0;
1569 p->ending_address = (memory_size_mb-1)*1024;
1570 p->memory_device_handle = 0x1100;
1571 p->memory_array_mapped_address_handle = 0x1300;
1572 p->partition_row_position = 1;
1573 p->interleave_position = 0;
1574 p->interleaved_data_depth = 0;
1576 start += sizeof(struct smbios_type_20);
1578 *((u16 *)start) = 0;
1582 /* Type 32 -- System Boot Information */
1584 smbios_type_32_init(void *start)
1586 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
1588 p->header.type = 32;
1589 p->header.length = sizeof(struct smbios_type_32);
1590 p->header.handle = 0x2000;
1591 memset(p->reserved, 0, 6);
1592 p->boot_status = 0; /* no errors detected */
1594 start += sizeof(struct smbios_type_32);
1595 *((u16 *)start) = 0;
1600 /* Type 127 -- End of Table */
1602 smbios_type_127_init(void *start)
1604 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
1606 p->header.type = 127;
1607 p->header.length = sizeof(struct smbios_type_127);
1608 p->header.handle = 0x7f00;
1610 start += sizeof(struct smbios_type_127);
1611 *((u16 *)start) = 0;
1616 void smbios_init(void)
1618 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
1619 char *start, *p, *q;
1620 int memsize = GET_EBDA(ram_size) / (1024 * 1024);
1622 #if (CONFIG_USE_EBDA_TABLES == 1)
1623 ebda_cur_addr = align(ebda_cur_addr, 16);
1624 start = (void *)(ebda_cur_addr);
1626 bios_table_cur_addr = align(bios_table_cur_addr, 16);
1627 start = (void *)(bios_table_cur_addr);
1630 p = (char *)start + sizeof(struct smbios_entry_point);
1632 #define add_struct(fn) { \
1635 if ((q - p) > max_struct_size) \
1636 max_struct_size = q - p; \
1640 add_struct(smbios_type_0_init(p));
1641 add_struct(smbios_type_1_init(p));
1642 add_struct(smbios_type_3_init(p));
1643 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
1644 add_struct(smbios_type_4_init(p, cpu_num));
1645 add_struct(smbios_type_16_init(p, memsize));
1646 add_struct(smbios_type_17_init(p, memsize));
1647 add_struct(smbios_type_19_init(p, memsize));
1648 add_struct(smbios_type_20_init(p, memsize));
1649 add_struct(smbios_type_32_init(p));
1650 add_struct(smbios_type_127_init(p));
1654 smbios_entry_point_init(
1655 start, max_struct_size,
1656 (p - (char *)start) - sizeof(struct smbios_entry_point),
1657 (u32)(start + sizeof(struct smbios_entry_point)),
1660 #if (CONFIG_USE_EBDA_TABLES == 1)
1661 ebda_cur_addr += (p - (char *)start);
1663 bios_table_cur_addr += (p - (char *)start);
1666 BX_INFO("SMBIOS table addr=0x%08lx\n", (unsigned long)start);
1669 void rombios32_init(void)
1671 BX_INFO("Starting rombios32\n");
1673 #if (CONFIG_USE_EBDA_TABLES == 1)
1674 ebda_cur_addr = ((*(u16 *)(0x40e)) << 4) + 0x380;
1675 BX_INFO("ebda_cur_addr: 0x%08lx\n", ebda_cur_addr);
1684 if (bios_table_cur_addr != 0) {
1695 bios_lock_shadow_ram();
1697 BX_INFO("bios_table_cur_addr: 0x%08lx\n", bios_table_cur_addr);
1698 if (bios_table_cur_addr > bios_table_end_addr)
1699 BX_PANIC("bios_table_end_addr overflow!\n");