1 /////////////////////////////////////////////////////////////////////////
2 // $Id: rombios32.c,v 1.11 2007/08/03 13:56:13 vruppert Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // 32 bit Bochs BIOS init code
6 // Copyright (C) 2006 Fabrice Bellard
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 typedef signed char int8_t;
27 typedef short int16_t;
29 typedef long long int64_t;
30 typedef unsigned char uint8_t;
31 typedef unsigned short uint16_t;
32 typedef unsigned int uint32_t;
33 typedef unsigned long long uint64_t;
35 /* if true, put the MP float table and ACPI RSDT in EBDA and the MP
36 table in RAM. Unfortunately, Linux has bugs with that, so we prefer
37 to modify the BIOS in shadow RAM */
38 //#define BX_USE_EBDA_TABLES
40 /* define it if the (emulated) hardware supports SMM mode */
43 #define cpuid(index, eax, ebx, ecx, edx) \
44 asm volatile ("cpuid" \
45 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \
48 #define wbinvd() asm volatile("wbinvd")
50 #define CPUID_MSR (1 << 5)
51 #define CPUID_APIC (1 << 9)
52 #define CPUID_MTRR (1 << 12)
54 #define APIC_BASE ((uint8_t *)0xfee00000)
55 #define APIC_ICR_LOW 0x300
56 #define APIC_SVR 0x0F0
58 #define APIC_LVT3 0x370
61 #define PCI_ISA_IRQ_MASK 0x0e20U
63 #define APIC_ENABLED 0x0100
65 #define AP_BOOT_ADDR 0x9f000
67 #define MPTABLE_MAX_SIZE 0x00002000
68 #define SMI_CMD_IO_ADDR 0xb2
70 #define BIOS_TMP_STORAGE 0x00030000 /* 64 KB used to copy the BIOS to shadow RAM */
72 #define MSR_MTRRcap 0x000000fe
73 #define MSR_MTRRfix64K_00000 0x00000250
74 #define MSR_MTRRfix16K_80000 0x00000258
75 #define MSR_MTRRfix16K_A0000 0x00000259
76 #define MSR_MTRRfix4K_C0000 0x00000268
77 #define MSR_MTRRfix4K_C8000 0x00000269
78 #define MSR_MTRRfix4K_D0000 0x0000026a
79 #define MSR_MTRRfix4K_D8000 0x0000026b
80 #define MSR_MTRRfix4K_E0000 0x0000026c
81 #define MSR_MTRRfix4K_E8000 0x0000026d
82 #define MSR_MTRRfix4K_F0000 0x0000026e
83 #define MSR_MTRRfix4K_F8000 0x0000026f
84 #define MSR_MTRRdefType 0x000002ff
86 #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
87 #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
89 static inline void outl(int addr
, int val
)
91 asm volatile ("outl %1, %w0" : : "d" (addr
), "a" (val
));
94 static inline void outw(int addr
, int val
)
96 asm volatile ("outw %w1, %w0" : : "d" (addr
), "a" (val
));
99 static inline void outb(int addr
, int val
)
101 asm volatile ("outb %b1, %w0" : : "d" (addr
), "a" (val
));
104 static inline uint32_t inl(int addr
)
107 asm volatile ("inl %w1, %0" : "=a" (val
) : "d" (addr
));
111 static inline uint16_t inw(int addr
)
114 asm volatile ("inw %w1, %w0" : "=a" (val
) : "d" (addr
));
118 static inline uint8_t inb(int addr
)
121 asm volatile ("inb %w1, %b0" : "=a" (val
) : "d" (addr
));
125 static inline void writel(void *addr
, uint32_t val
)
127 *(volatile uint32_t *)addr
= val
;
130 static inline void writew(void *addr
, uint16_t val
)
132 *(volatile uint16_t *)addr
= val
;
135 static inline void writeb(void *addr
, uint8_t val
)
137 *(volatile uint8_t *)addr
= val
;
140 static inline uint32_t readl(const void *addr
)
142 return *(volatile const uint32_t *)addr
;
145 static inline uint16_t readw(const void *addr
)
147 return *(volatile const uint16_t *)addr
;
150 static inline uint8_t readb(const void *addr
)
152 return *(volatile const uint8_t *)addr
;
155 static inline void putc(int c
)
160 static uint64_t rdmsr(unsigned index
)
162 unsigned long long ret
;
164 asm ("rdmsr" : "=A"(ret
) : "c"(index
));
168 static void wrmsr(unsigned index
, uint64_t val
)
170 asm volatile ("wrmsr" : : "c"(index
), "A"(val
));
173 static inline int isdigit(int c
)
175 return c
>= '0' && c
<= '9';
178 void *memset(void *d1
, int val
, size_t len
)
188 void *memcpy(void *d1
, const void *s1
, size_t len
)
191 const uint8_t *s
= s1
;
199 void *memmove(void *d1
, const void *s1
, size_t len
)
202 const uint8_t *s
= s1
;
218 int memcmp(const void *s1
, const void *s2
, size_t len
)
220 const int8_t *p1
= s1
;
221 const int8_t *p2
= s2
;
224 int r
= *p1
++ - *p2
++;
232 size_t strlen(const char *s
)
235 for(s1
= s
; *s1
!= '\0'; s1
++);
239 /* from BSD ppp sources */
240 int vsnprintf(char *buf
, int buflen
, const char *fmt
, va_list args
)
243 int width
, prec
, fillch
;
245 unsigned long val
= 0;
249 static const char hexchars
[] = "0123456789abcdef";
254 for (f
= fmt
; *f
!= '%' && *f
!= 0; ++f
)
260 memcpy(buf
, fmt
, len
);
275 width
= va_arg(args
, int);
279 width
= width
* 10 + c
- '0';
286 prec
= va_arg(args
, int);
290 prec
= prec
* 10 + c
- '0';
309 i
= va_arg(args
, int);
318 val
= va_arg(args
, unsigned int);
323 val
= va_arg(args
, unsigned int);
327 val
= (unsigned long) va_arg(args
, void *);
332 str
= va_arg(args
, char *);
335 num
[0] = va_arg(args
, int);
342 --fmt
; /* so %z outputs %z etc. */
347 str
= num
+ sizeof(num
);
349 while (str
> num
+ neg
) {
350 *--str
= hexchars
[val
% base
];
352 if (--prec
<= 0 && val
== 0)
364 len
= num
+ sizeof(num
) - 1 - str
;
367 if (prec
> 0 && len
> prec
)
373 if ((n
= width
- len
) > 0) {
381 memcpy(buf
, str
, len
);
389 int snprintf(char * buf
, size_t size
, const char *fmt
, ...)
395 i
=vsnprintf(buf
,size
,fmt
,args
);
400 void bios_printf(int flags
, const char *fmt
, ...)
406 if ((flags
& BIOS_PRINTF_DEBHALT
) == BIOS_PRINTF_DEBHALT
)
407 outb(PANIC_PORT2
, 0x00);
410 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
420 for(i
= 0; i
< n
; i
++) {
422 /* approximative ! */
423 for(j
= 0; j
< 1000000; j
++);
428 r1
= inb(0x61) & 0x10;
430 r2
= inb(0x61) & 0x10;
442 uint32_t cpuid_signature
;
443 uint32_t cpuid_features
;
444 uint32_t cpuid_ext_features
;
445 unsigned long ram_size
;
447 uint8_t bios_uuid
[16];
448 #ifdef BX_USE_EBDA_TABLES
449 unsigned long ebda_cur_addr
;
452 uint32_t pm_io_base
, smb_io_base
;
454 unsigned long bios_table_cur_addr
;
455 unsigned long bios_table_end_addr
;
457 void init_smp_msrs(void)
459 *(uint32_t *)SMP_MSR_ADDR
= 0;
462 void wrmsr_smp(uint32_t index
, uint64_t val
)
464 static struct { uint32_t ecx
, eax
, edx
; } *p
= (void *)SMP_MSR_ADDR
;
475 #define QEMU_CFG_CTL_PORT 0x510
476 #define QEMU_CFG_DATA_PORT 0x511
477 #define QEMU_CFG_SIGNATURE 0x00
478 #define QEMU_CFG_ID 0x01
479 #define QEMU_CFG_UUID 0x02
483 void qemu_cfg_select(int f
)
485 outw(QEMU_CFG_CTL_PORT
, f
);
488 int qemu_cfg_port_probe()
493 qemu_cfg_select(QEMU_CFG_SIGNATURE
);
495 for (i
= 0; i
< 4; i
++)
496 if (inb(QEMU_CFG_DATA_PORT
) != sig
[i
])
502 void qemu_cfg_read(uint8_t *buf
, int len
)
505 *(buf
++) = inb(QEMU_CFG_DATA_PORT
);
509 void uuid_probe(void)
513 qemu_cfg_select(QEMU_CFG_UUID
);
514 qemu_cfg_read(bios_uuid
, 16);
518 memset(bios_uuid
, 0, 16);
523 uint32_t eax
, ebx
, ecx
, edx
;
524 cpuid(1, eax
, ebx
, ecx
, edx
);
525 cpuid_signature
= eax
;
526 cpuid_features
= edx
;
527 cpuid_ext_features
= ecx
;
530 static int cmos_readb(int addr
)
536 void setup_mtrr(void)
538 int i
, vcnt
, fix
, wc
;
545 if (!(cpuid_features
& CPUID_MTRR
))
548 if (!(cpuid_features
& CPUID_MSR
))
551 mtrr_cap
= rdmsr(MSR_MTRRcap
);
552 vcnt
= mtrr_cap
& 0xff;
553 fix
= mtrr_cap
& 0x100;
554 wc
= mtrr_cap
& 0x400;
559 for (i
= 0; i
< 8; ++i
)
560 if (ram_size
>= 65536 * (i
+ 1))
562 wrmsr_smp(MSR_MTRRfix64K_00000
, u
.val
);
564 for (i
= 0; i
< 8; ++i
)
565 if (ram_size
>= 65536 * 8 + 16384 * (i
+ 1))
567 wrmsr_smp(MSR_MTRRfix16K_80000
, u
.val
);
568 wrmsr_smp(MSR_MTRRfix16K_A0000
, 0);
569 wrmsr_smp(MSR_MTRRfix4K_C0000
, 0);
570 wrmsr_smp(MSR_MTRRfix4K_C8000
, 0);
571 wrmsr_smp(MSR_MTRRfix4K_D0000
, 0);
572 wrmsr_smp(MSR_MTRRfix4K_D8000
, 0);
573 wrmsr_smp(MSR_MTRRfix4K_E0000
, 0);
574 wrmsr_smp(MSR_MTRRfix4K_E8000
, 0);
575 wrmsr_smp(MSR_MTRRfix4K_F0000
, 0);
576 wrmsr_smp(MSR_MTRRfix4K_F8000
, 0);
577 /* Mark 3.5-4GB as UC, anything not specified defaults to WB */
578 wrmsr_smp(MTRRphysBase_MSR(0), 0xe0000000ull
| 0);
579 wrmsr_smp(MTRRphysMask_MSR(0), ~(0x20000000ull
- 1) | 0x800);
580 wrmsr_smp(MSR_MTRRdefType
, 0xc06);
585 if (cmos_readb(0x34) | cmos_readb(0x35))
586 ram_size
= (cmos_readb(0x34) | (cmos_readb(0x35) << 8)) * 65536 +
589 ram_size
= (cmos_readb(0x17) | (cmos_readb(0x18) << 8)) * 1024;
591 if (cmos_readb(0x5b) | cmos_readb(0x5c) | cmos_readb(0x5d))
592 ram_end
= (((uint64_t)cmos_readb(0x5b) << 16) |
593 ((uint64_t)cmos_readb(0x5c) << 24) |
594 ((uint64_t)cmos_readb(0x5d) << 32)) + (1ull << 32);
598 BX_INFO("end of ram=%ldMB\n", ram_end
>> 20);
600 BX_INFO("ram_size=0x%08lx\n", ram_size
);
601 #ifdef BX_USE_EBDA_TABLES
602 ebda_cur_addr
= ((*(uint16_t *)(0x40e)) << 4) + 0x380;
603 BX_INFO("ebda_cur_addr: 0x%08lx\n", ebda_cur_addr
);
607 /****************************************************/
610 extern uint8_t smp_ap_boot_code_start
;
611 extern uint8_t smp_ap_boot_code_end
;
613 /* find the number of CPUs by launching a SIPI to them */
616 uint32_t val
, sipi_vector
;
618 writew(&smp_cpus
, 1);
619 if (cpuid_features
& CPUID_APIC
) {
621 /* enable local APIC */
622 val
= readl(APIC_BASE
+ APIC_SVR
);
624 writel(APIC_BASE
+ APIC_SVR
, val
);
626 /* copy AP boot code */
627 memcpy((void *)AP_BOOT_ADDR
, &smp_ap_boot_code_start
,
628 &smp_ap_boot_code_end
- &smp_ap_boot_code_start
);
631 writel(APIC_BASE
+ APIC_ICR_LOW
, 0x000C4500);
632 sipi_vector
= AP_BOOT_ADDR
>> 12;
633 writel(APIC_BASE
+ APIC_ICR_LOW
, 0x000C4600 | sipi_vector
);
638 while (cmos_readb(0x5f) + 1 != readw(&smp_cpus
))
642 BX_INFO("Found %d cpu(s)\n", readw(&smp_cpus
));
645 /****************************************************/
648 #define PCI_ADDRESS_SPACE_MEM 0x00
649 #define PCI_ADDRESS_SPACE_IO 0x01
650 #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
652 #define PCI_ROM_SLOT 6
653 #define PCI_NUM_REGIONS 7
655 #define PCI_DEVICES_MAX 64
657 #define PCI_VENDOR_ID 0x00 /* 16 bits */
658 #define PCI_DEVICE_ID 0x02 /* 16 bits */
659 #define PCI_COMMAND 0x04 /* 16 bits */
660 #define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */
661 #define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */
662 #define PCI_CLASS_DEVICE 0x0a /* Device class */
663 #define PCI_INTERRUPT_LINE 0x3c /* 8 bits */
664 #define PCI_INTERRUPT_PIN 0x3d /* 8 bits */
665 #define PCI_MIN_GNT 0x3e /* 8 bits */
666 #define PCI_MAX_LAT 0x3f /* 8 bits */
668 #define PCI_VENDOR_ID_INTEL 0x8086
669 #define PCI_DEVICE_ID_INTEL_82441 0x1237
670 #define PCI_DEVICE_ID_INTEL_82371SB_0 0x7000
671 #define PCI_DEVICE_ID_INTEL_82371SB_1 0x7010
672 #define PCI_DEVICE_ID_INTEL_82371AB_0 0x7110
673 #define PCI_DEVICE_ID_INTEL_82371AB 0x7111
674 #define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113
676 #define PCI_VENDOR_ID_IBM 0x1014
677 #define PCI_VENDOR_ID_APPLE 0x106b
679 typedef struct PCIDevice
{
684 static uint32_t pci_bios_io_addr
;
685 static uint32_t pci_bios_mem_addr
;
686 static uint32_t pci_bios_bigmem_addr
;
687 /* host irqs corresponding to PCI irqs A-D */
688 static uint8_t pci_irqs
[4] = { 10, 10, 11, 11 };
689 static PCIDevice i440_pcidev
;
691 static void pci_config_writel(PCIDevice
*d
, uint32_t addr
, uint32_t val
)
693 outl(0xcf8, 0x80000000 | (d
->bus
<< 16) | (d
->devfn
<< 8) | (addr
& 0xfc));
697 static void pci_config_writew(PCIDevice
*d
, uint32_t addr
, uint32_t val
)
699 outl(0xcf8, 0x80000000 | (d
->bus
<< 16) | (d
->devfn
<< 8) | (addr
& 0xfc));
700 outw(0xcfc + (addr
& 2), val
);
703 static void pci_config_writeb(PCIDevice
*d
, uint32_t addr
, uint32_t val
)
705 outl(0xcf8, 0x80000000 | (d
->bus
<< 16) | (d
->devfn
<< 8) | (addr
& 0xfc));
706 outb(0xcfc + (addr
& 3), val
);
709 static uint32_t pci_config_readl(PCIDevice
*d
, uint32_t addr
)
711 outl(0xcf8, 0x80000000 | (d
->bus
<< 16) | (d
->devfn
<< 8) | (addr
& 0xfc));
715 static uint32_t pci_config_readw(PCIDevice
*d
, uint32_t addr
)
717 outl(0xcf8, 0x80000000 | (d
->bus
<< 16) | (d
->devfn
<< 8) | (addr
& 0xfc));
718 return inw(0xcfc + (addr
& 2));
721 static uint32_t pci_config_readb(PCIDevice
*d
, uint32_t addr
)
723 outl(0xcf8, 0x80000000 | (d
->bus
<< 16) | (d
->devfn
<< 8) | (addr
& 0xfc));
724 return inb(0xcfc + (addr
& 3));
727 static void pci_set_io_region_addr(PCIDevice
*d
, int region_num
, uint32_t addr
)
730 uint32_t ofs
, old_addr
;
732 if ( region_num
== PCI_ROM_SLOT
) {
735 ofs
= 0x10 + region_num
* 4;
738 old_addr
= pci_config_readl(d
, ofs
);
740 pci_config_writel(d
, ofs
, addr
);
741 BX_INFO("region %d: 0x%08x\n", region_num
, addr
);
743 /* enable memory mappings */
744 cmd
= pci_config_readw(d
, PCI_COMMAND
);
745 if ( region_num
== PCI_ROM_SLOT
)
747 else if (old_addr
& PCI_ADDRESS_SPACE_IO
)
751 pci_config_writew(d
, PCI_COMMAND
, cmd
);
754 /* return the global irq number corresponding to a given device irq
755 pin. We could also use the bus number to have a more precise
757 static int pci_slot_get_pirq(PCIDevice
*pci_dev
, int irq_num
)
760 slot_addend
= (pci_dev
->devfn
>> 3) - 1;
761 return (irq_num
+ slot_addend
) & 3;
764 static void find_bios_table_area(void)
767 for(addr
= 0xf0000; addr
< 0x100000; addr
+= 16) {
768 if (*(uint32_t *)addr
== 0xaafb4442) {
769 bios_table_cur_addr
= addr
+ 8;
770 bios_table_end_addr
= bios_table_cur_addr
+ *(uint32_t *)(addr
+ 4);
771 BX_INFO("bios_table_addr: 0x%08lx end=0x%08lx\n",
772 bios_table_cur_addr
, bios_table_end_addr
);
779 static void bios_shadow_init(PCIDevice
*d
)
783 if (bios_table_cur_addr
== 0)
786 /* remap the BIOS to shadow RAM an keep it read/write while we
787 are writing tables */
788 v
= pci_config_readb(d
, 0x59);
790 pci_config_writeb(d
, 0x59, v
);
791 memcpy((void *)BIOS_TMP_STORAGE
, (void *)0x000f0000, 0x10000);
793 pci_config_writeb(d
, 0x59, v
);
794 memcpy((void *)0x000f0000, (void *)BIOS_TMP_STORAGE
, 0x10000);
799 static void bios_lock_shadow_ram(void)
801 PCIDevice
*d
= &i440_pcidev
;
805 v
= pci_config_readb(d
, 0x59);
806 v
= (v
& 0x0f) | (0x10);
807 pci_config_writeb(d
, 0x59, v
);
810 static void pci_bios_init_bridges(PCIDevice
*d
)
812 uint16_t vendor_id
, device_id
;
814 vendor_id
= pci_config_readw(d
, PCI_VENDOR_ID
);
815 device_id
= pci_config_readw(d
, PCI_DEVICE_ID
);
817 if (vendor_id
== PCI_VENDOR_ID_INTEL
&&
818 (device_id
== PCI_DEVICE_ID_INTEL_82371SB_0
||
819 device_id
== PCI_DEVICE_ID_INTEL_82371AB_0
)) {
823 /* PIIX3/PIIX4 PCI to ISA bridge */
827 for(i
= 0; i
< 4; i
++) {
829 /* set to trigger level */
830 elcr
[irq
>> 3] |= (1 << (irq
& 7));
831 /* activate irq remapping in PIIX */
832 pci_config_writeb(d
, 0x60 + i
, irq
);
834 outb(0x4d0, elcr
[0]);
835 outb(0x4d1, elcr
[1]);
836 BX_INFO("PIIX3/PIIX4 init: elcr=%02x %02x\n",
838 } else if (vendor_id
== PCI_VENDOR_ID_INTEL
&& device_id
== PCI_DEVICE_ID_INTEL_82441
) {
839 /* i440 PCI bridge */
844 extern uint8_t smm_relocation_start
, smm_relocation_end
;
845 extern uint8_t smm_code_start
, smm_code_end
;
848 static void smm_init(PCIDevice
*d
)
852 /* check if SMM init is already done */
853 value
= pci_config_readl(d
, 0x58);
854 if ((value
& (1 << 25)) == 0) {
856 /* enable the SMM memory window */
857 pci_config_writeb(&i440_pcidev
, 0x72, 0x02 | 0x48);
859 /* save original memory content */
860 memcpy((void *)0xa8000, (void *)0x38000, 0x8000);
862 /* copy the SMM relocation code */
863 memcpy((void *)0x38000, &smm_relocation_start
,
864 &smm_relocation_end
- &smm_relocation_start
);
866 /* enable SMI generation when writing to the APMC register */
867 pci_config_writel(d
, 0x58, value
| (1 << 25));
869 /* init APM status port */
872 /* raise an SMI interrupt */
875 /* wait until SMM code executed */
876 while (inb(0xb3) != 0x00);
878 /* restore original memory content */
879 memcpy((void *)0x38000, (void *)0xa8000, 0x8000);
881 /* copy the SMM code */
882 memcpy((void *)0xa8000, &smm_code_start
,
883 &smm_code_end
- &smm_code_start
);
886 /* close the SMM memory window and enable normal SMM */
887 pci_config_writeb(&i440_pcidev
, 0x72, 0x02 | 0x08);
892 static void piix4_pm_enable(PCIDevice
*d
)
894 /* PIIX4 Power Management device (for ACPI) */
895 pci_config_writel(d
, 0x40, PM_IO_BASE
| 1);
896 pci_config_writeb(d
, 0x80, 0x01); /* enable PM io space */
897 pci_config_writel(d
, 0x90, SMB_IO_BASE
| 1);
898 pci_config_writeb(d
, 0xd2, 0x09); /* enable SMBus io space */
904 static void pci_bios_init_device(PCIDevice
*d
)
908 int i
, pin
, pic_irq
, vendor_id
, device_id
;
910 class = pci_config_readw(d
, PCI_CLASS_DEVICE
);
911 vendor_id
= pci_config_readw(d
, PCI_VENDOR_ID
);
912 device_id
= pci_config_readw(d
, PCI_DEVICE_ID
);
913 BX_INFO("PCI: bus=%d devfn=0x%02x: vendor_id=0x%04x device_id=0x%04x class=0x%04x\n",
914 d
->bus
, d
->devfn
, vendor_id
, device_id
, class);
916 case 0x0101: /* Mass storage controller - IDE interface */
917 if (vendor_id
== PCI_VENDOR_ID_INTEL
&&
918 (device_id
== PCI_DEVICE_ID_INTEL_82371SB_1
||
919 device_id
== PCI_DEVICE_ID_INTEL_82371AB
)) {
920 /* PIIX3/PIIX4 IDE */
921 pci_config_writew(d
, 0x40, 0x8000); // enable IDE0
922 pci_config_writew(d
, 0x42, 0x8000); // enable IDE1
925 /* IDE: we map it as in ISA mode */
926 pci_set_io_region_addr(d
, 0, 0x1f0);
927 pci_set_io_region_addr(d
, 1, 0x3f4);
928 pci_set_io_region_addr(d
, 2, 0x170);
929 pci_set_io_region_addr(d
, 3, 0x374);
932 case 0x0300: /* Display controller - VGA compatible controller */
933 if (vendor_id
!= 0x1234)
935 /* VGA: map frame buffer to default Bochs VBE address */
936 pci_set_io_region_addr(d
, 0, 0xE0000000);
938 case 0x0800: /* Generic system peripheral - PIC */
939 if (vendor_id
== PCI_VENDOR_ID_IBM
) {
941 if (device_id
== 0x0046 || device_id
== 0xFFFF) {
943 pci_set_io_region_addr(d
, 0, 0x80800000 + 0x00040000);
948 if (vendor_id
== PCI_VENDOR_ID_APPLE
&&
949 (device_id
== 0x0017 || device_id
== 0x0022)) {
951 pci_set_io_region_addr(d
, 0, 0x80800000);
956 /* default memory mappings */
957 for(i
= 0; i
< PCI_NUM_REGIONS
; i
++) {
961 if (i
== PCI_ROM_SLOT
)
965 pci_config_writel(d
, ofs
, 0xffffffff);
966 val
= pci_config_readl(d
, ofs
);
968 size
= (~(val
& ~0xf)) + 1;
969 if (val
& PCI_ADDRESS_SPACE_IO
)
970 paddr
= &pci_bios_io_addr
;
971 else if (size
>= 0x04000000)
972 paddr
= &pci_bios_bigmem_addr
;
974 paddr
= &pci_bios_mem_addr
;
975 *paddr
= (*paddr
+ size
- 1) & ~(size
- 1);
976 pci_set_io_region_addr(d
, i
, *paddr
);
978 /* make memory address page aligned */
979 if (!(val
& PCI_ADDRESS_SPACE_IO
))
980 *paddr
= (*paddr
+ 0xfff) & 0xfffff000;
986 /* map the interrupt */
987 pin
= pci_config_readb(d
, PCI_INTERRUPT_PIN
);
989 pin
= pci_slot_get_pirq(d
, pin
- 1);
990 pic_irq
= pci_irqs
[pin
];
991 pci_config_writeb(d
, PCI_INTERRUPT_LINE
, pic_irq
);
994 if (vendor_id
== PCI_VENDOR_ID_INTEL
&& device_id
== PCI_DEVICE_ID_INTEL_82371AB_3
) {
995 /* PIIX4 Power Management device (for ACPI) */
997 // acpi sci is hardwired to 9
998 pci_config_writeb(d
, PCI_INTERRUPT_LINE
, 9);
1000 pm_io_base
= PM_IO_BASE
;
1001 smb_io_base
= SMB_IO_BASE
;
1002 pm_sci_int
= pci_config_readb(d
, PCI_INTERRUPT_LINE
);
1008 void pci_for_each_device(void (*init_func
)(PCIDevice
*d
))
1010 PCIDevice d1
, *d
= &d1
;
1012 uint16_t vendor_id
, device_id
;
1014 for(bus
= 0; bus
< 1; bus
++) {
1015 for(devfn
= 0; devfn
< 256; devfn
++) {
1018 vendor_id
= pci_config_readw(d
, PCI_VENDOR_ID
);
1019 device_id
= pci_config_readw(d
, PCI_DEVICE_ID
);
1020 if (vendor_id
!= 0xffff || device_id
!= 0xffff) {
1027 void pci_bios_init(void)
1029 pci_bios_io_addr
= 0xc000;
1030 pci_bios_mem_addr
= 0xf0000000;
1031 pci_bios_bigmem_addr
= ram_size
;
1032 if (pci_bios_bigmem_addr
< 0x90000000)
1033 pci_bios_bigmem_addr
= 0x90000000;
1035 pci_for_each_device(pci_bios_init_bridges
);
1037 pci_for_each_device(pci_bios_init_device
);
1040 /****************************************************/
1041 /* Multi Processor table init */
1043 static void putb(uint8_t **pp
, int val
)
1051 static void putstr(uint8_t **pp
, const char *str
)
1060 static void putle16(uint8_t **pp
, int val
)
1069 static void putle32(uint8_t **pp
, int val
)
1080 static int mpf_checksum(const uint8_t *data
, int len
)
1084 for(i
= 0; i
< len
; i
++)
1089 static unsigned long align(unsigned long addr
, unsigned long v
)
1091 return (addr
+ v
- 1) & ~(v
- 1);
1094 static void mptable_init(void)
1096 uint8_t *mp_config_table
, *q
, *float_pointer_struct
;
1097 int ioapic_id
, i
, len
;
1098 int mp_config_table_size
;
1100 #ifdef BX_USE_EBDA_TABLES
1101 mp_config_table
= (uint8_t *)(ram_size
- ACPI_DATA_SIZE
- MPTABLE_MAX_SIZE
);
1103 bios_table_cur_addr
= align(bios_table_cur_addr
, 16);
1104 mp_config_table
= (uint8_t *)bios_table_cur_addr
;
1106 q
= mp_config_table
;
1107 putstr(&q
, "PCMP"); /* "PCMP signature */
1108 putle16(&q
, 0); /* table length (patched later) */
1109 putb(&q
, 4); /* spec rev */
1110 putb(&q
, 0); /* checksum (patched later) */
1112 putstr(&q
, "QEMUCPU "); /* OEM id */
1114 putstr(&q
, "BOCHSCPU");
1116 putstr(&q
, "0.1 "); /* vendor id */
1117 putle32(&q
, 0); /* OEM table ptr */
1118 putle16(&q
, 0); /* OEM table size */
1119 putle16(&q
, MAX_CPUS
+ 18); /* entry count */
1120 putle32(&q
, 0xfee00000); /* local APIC addr */
1121 putle16(&q
, 0); /* ext table length */
1122 putb(&q
, 0); /* ext table checksum */
1123 putb(&q
, 0); /* reserved */
1125 for(i
= 0; i
< MAX_CPUS
; i
++) {
1126 putb(&q
, 0); /* entry type = processor */
1127 putb(&q
, i
); /* APIC id */
1128 putb(&q
, 0x11); /* local APIC version number */
1130 putb(&q
, 3); /* cpu flags: enabled, bootstrap cpu */
1131 else if ( i
< smp_cpus
)
1132 putb(&q
, 1); /* cpu flags: enabled */
1134 putb(&q
, 0); /* cpu flags: disabled */
1135 putb(&q
, 0); /* cpu signature */
1139 putle16(&q
, 0x201); /* feature flags */
1142 putle16(&q
, 0); /* reserved */
1149 putb(&q
, 1); /* entry type = bus */
1150 putb(&q
, 0); /* bus ID */
1154 ioapic_id
= smp_cpus
;
1155 putb(&q
, 2); /* entry type = I/O APIC */
1156 putb(&q
, ioapic_id
); /* apic ID */
1157 putb(&q
, 0x11); /* I/O APIC version number */
1158 putb(&q
, 1); /* enable */
1159 putle32(&q
, 0xfec00000); /* I/O APIC addr */
1162 for(i
= 0; i
< 16; i
++) {
1163 putb(&q
, 3); /* entry type = I/O interrupt */
1164 putb(&q
, 0); /* interrupt type = vectored interrupt */
1165 putb(&q
, 0); /* flags: po=0, el=0 */
1167 putb(&q
, 0); /* source bus ID = ISA */
1168 putb(&q
, i
); /* source bus IRQ */
1169 putb(&q
, ioapic_id
); /* dest I/O APIC ID */
1170 putb(&q
, i
); /* dest I/O APIC interrupt in */
1173 len
= q
- mp_config_table
;
1174 mp_config_table
[4] = len
;
1175 mp_config_table
[5] = len
>> 8;
1177 mp_config_table
[7] = -mpf_checksum(mp_config_table
, q
- mp_config_table
);
1179 mp_config_table_size
= q
- mp_config_table
;
1181 #ifndef BX_USE_EBDA_TABLES
1182 bios_table_cur_addr
+= mp_config_table_size
;
1185 /* floating pointer structure */
1186 #ifdef BX_USE_EBDA_TABLES
1187 ebda_cur_addr
= align(ebda_cur_addr
, 16);
1188 float_pointer_struct
= (uint8_t *)ebda_cur_addr
;
1190 bios_table_cur_addr
= align(bios_table_cur_addr
, 16);
1191 float_pointer_struct
= (uint8_t *)bios_table_cur_addr
;
1193 q
= float_pointer_struct
;
1195 /* pointer to MP config table */
1196 putle32(&q
, (unsigned long)mp_config_table
);
1198 putb(&q
, 1); /* length in 16 byte units */
1199 putb(&q
, 4); /* MP spec revision */
1200 putb(&q
, 0); /* checksum (patched later) */
1201 putb(&q
, 0); /* MP feature byte 1 */
1207 float_pointer_struct
[10] =
1208 -mpf_checksum(float_pointer_struct
, q
- float_pointer_struct
);
1209 #ifdef BX_USE_EBDA_TABLES
1210 ebda_cur_addr
+= (q
- float_pointer_struct
);
1212 bios_table_cur_addr
+= (q
- float_pointer_struct
);
1214 BX_INFO("MP table addr=0x%08lx MPC table addr=0x%08lx size=0x%x\n",
1215 (unsigned long)float_pointer_struct
,
1216 (unsigned long)mp_config_table
,
1217 mp_config_table_size
);
1220 /****************************************************/
1221 /* ACPI tables init */
1223 /* Table structure from Linux kernel (the ACPI tables are under the
1227 * All tables must be byte-packed to match the ACPI specification, since
1228 * the tables are provided by the system BIOS.
1231 #define ACPI_TABLE_HEADER_DEF /* ACPI common table header */ \
1232 uint8_t signature [4]; /* ACPI signature (4 ASCII characters) */\
1233 uint32_t length; /* Length of table, in bytes, including header */\
1234 uint8_t revision; /* ACPI Specification minor version # */\
1235 uint8_t checksum; /* To make sum of entire table == 0 */\
1236 uint8_t oem_id [6]; /* OEM identification */\
1237 uint8_t oem_table_id [8]; /* OEM table identification */\
1238 uint32_t oem_revision; /* OEM revision number */\
1239 uint8_t asl_compiler_id [4]; /* ASL compiler vendor ID */\
1240 uint32_t asl_compiler_revision; /* ASL compiler revision number */
1243 struct acpi_table_header
/* ACPI common table header */
1245 ACPI_TABLE_HEADER_DEF
1246 } __attribute__((__packed__
));
1248 struct rsdp_descriptor
/* Root System Descriptor Pointer */
1250 uint8_t signature
[8]; /* ACPI signature, contains "RSD PTR " */
1251 uint8_t checksum
; /* To make sum of struct == 0 */
1252 uint8_t oem_id
[6]; /* OEM identification */
1253 uint8_t revision
; /* Must be 0 for 1.0, 2 for 2.0 */
1254 uint32_t rsdt_physical_address
; /* 32-bit physical address of RSDT */
1255 uint32_t length
; /* XSDT Length in bytes including hdr */
1256 uint64_t xsdt_physical_address
; /* 64-bit physical address of XSDT */
1257 uint8_t extended_checksum
; /* Checksum of entire table */
1258 uint8_t reserved
[3]; /* Reserved field must be 0 */
1259 } __attribute__((__packed__
));
1262 * ACPI 1.0 Root System Description Table (RSDT)
1264 struct rsdt_descriptor_rev1
1266 ACPI_TABLE_HEADER_DEF
/* ACPI common table header */
1268 uint32_t table_offset_entry
[2]; /* Array of pointers to other */
1269 // uint32_t table_offset_entry [4]; /* Array of pointers to other */
1271 uint32_t table_offset_entry
[3]; /* Array of pointers to other */
1274 } __attribute__((__packed__
));
1277 * ACPI 1.0 Firmware ACPI Control Structure (FACS)
1279 struct facs_descriptor_rev1
1281 uint8_t signature
[4]; /* ACPI Signature */
1282 uint32_t length
; /* Length of structure, in bytes */
1283 uint32_t hardware_signature
; /* Hardware configuration signature */
1284 uint32_t firmware_waking_vector
; /* ACPI OS waking vector */
1285 uint32_t global_lock
; /* Global Lock */
1286 uint32_t S4bios_f
: 1; /* Indicates if S4BIOS support is present */
1287 uint32_t reserved1
: 31; /* Must be 0 */
1288 uint8_t resverved3
[40]; /* Reserved - must be zero */
1289 } __attribute__((__packed__
));
1293 * ACPI 1.0 Fixed ACPI Description Table (FADT)
1295 struct fadt_descriptor_rev1
1297 ACPI_TABLE_HEADER_DEF
/* ACPI common table header */
1298 uint32_t firmware_ctrl
; /* Physical address of FACS */
1299 uint32_t dsdt
; /* Physical address of DSDT */
1300 uint8_t model
; /* System Interrupt Model */
1301 uint8_t reserved1
; /* Reserved */
1302 uint16_t sci_int
; /* System vector of SCI interrupt */
1303 uint32_t smi_cmd
; /* Port address of SMI command port */
1304 uint8_t acpi_enable
; /* Value to write to smi_cmd to enable ACPI */
1305 uint8_t acpi_disable
; /* Value to write to smi_cmd to disable ACPI */
1306 uint8_t S4bios_req
; /* Value to write to SMI CMD to enter S4BIOS state */
1307 uint8_t reserved2
; /* Reserved - must be zero */
1308 uint32_t pm1a_evt_blk
; /* Port address of Power Mgt 1a acpi_event Reg Blk */
1309 uint32_t pm1b_evt_blk
; /* Port address of Power Mgt 1b acpi_event Reg Blk */
1310 uint32_t pm1a_cnt_blk
; /* Port address of Power Mgt 1a Control Reg Blk */
1311 uint32_t pm1b_cnt_blk
; /* Port address of Power Mgt 1b Control Reg Blk */
1312 uint32_t pm2_cnt_blk
; /* Port address of Power Mgt 2 Control Reg Blk */
1313 uint32_t pm_tmr_blk
; /* Port address of Power Mgt Timer Ctrl Reg Blk */
1314 uint32_t gpe0_blk
; /* Port addr of General Purpose acpi_event 0 Reg Blk */
1315 uint32_t gpe1_blk
; /* Port addr of General Purpose acpi_event 1 Reg Blk */
1316 uint8_t pm1_evt_len
; /* Byte length of ports at pm1_x_evt_blk */
1317 uint8_t pm1_cnt_len
; /* Byte length of ports at pm1_x_cnt_blk */
1318 uint8_t pm2_cnt_len
; /* Byte Length of ports at pm2_cnt_blk */
1319 uint8_t pm_tmr_len
; /* Byte Length of ports at pm_tm_blk */
1320 uint8_t gpe0_blk_len
; /* Byte Length of ports at gpe0_blk */
1321 uint8_t gpe1_blk_len
; /* Byte Length of ports at gpe1_blk */
1322 uint8_t gpe1_base
; /* Offset in gpe model where gpe1 events start */
1323 uint8_t reserved3
; /* Reserved */
1324 uint16_t plvl2_lat
; /* Worst case HW latency to enter/exit C2 state */
1325 uint16_t plvl3_lat
; /* Worst case HW latency to enter/exit C3 state */
1326 uint16_t flush_size
; /* Size of area read to flush caches */
1327 uint16_t flush_stride
; /* Stride used in flushing caches */
1328 uint8_t duty_offset
; /* Bit location of duty cycle field in p_cnt reg */
1329 uint8_t duty_width
; /* Bit width of duty cycle field in p_cnt reg */
1330 uint8_t day_alrm
; /* Index to day-of-month alarm in RTC CMOS RAM */
1331 uint8_t mon_alrm
; /* Index to month-of-year alarm in RTC CMOS RAM */
1332 uint8_t century
; /* Index to century in RTC CMOS RAM */
1333 uint8_t reserved4
; /* Reserved */
1334 uint8_t reserved4a
; /* Reserved */
1335 uint8_t reserved4b
; /* Reserved */
1337 uint32_t wb_invd
: 1; /* The wbinvd instruction works properly */
1338 uint32_t wb_invd_flush
: 1; /* The wbinvd flushes but does not invalidate */
1339 uint32_t proc_c1
: 1; /* All processors support C1 state */
1340 uint32_t plvl2_up
: 1; /* C2 state works on MP system */
1341 uint32_t pwr_button
: 1; /* Power button is handled as a generic feature */
1342 uint32_t sleep_button
: 1; /* Sleep button is handled as a generic feature, or not present */
1343 uint32_t fixed_rTC
: 1; /* RTC wakeup stat not in fixed register space */
1344 uint32_t rtcs4
: 1; /* RTC wakeup stat not possible from S4 */
1345 uint32_t tmr_val_ext
: 1; /* The tmr_val width is 32 bits (0 = 24 bits) */
1346 uint32_t reserved5
: 23; /* Reserved - must be zero */
1350 } __attribute__((__packed__
));
1353 * MADT values and structures
1356 /* Values for MADT PCATCompat */
1359 #define MULTIPLE_APIC 1
1364 struct multiple_apic_table
1366 ACPI_TABLE_HEADER_DEF
/* ACPI common table header */
1367 uint32_t local_apic_address
; /* Physical address of local APIC */
1369 uint32_t PCATcompat
: 1; /* A one indicates system also has dual 8259s */
1370 uint32_t reserved1
: 31;
1374 } __attribute__((__packed__
));
1377 /* Values for Type in APIC_HEADER_DEF */
1379 #define APIC_PROCESSOR 0
1381 #define APIC_XRUPT_OVERRIDE 2
1383 #define APIC_LOCAL_NMI 4
1384 #define APIC_ADDRESS_OVERRIDE 5
1385 #define APIC_IO_SAPIC 6
1386 #define APIC_LOCAL_SAPIC 7
1387 #define APIC_XRUPT_SOURCE 8
1388 #define APIC_RESERVED 9 /* 9 and greater are reserved */
1391 * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE)
1393 #define APIC_HEADER_DEF /* Common APIC sub-structure header */\
1397 /* Sub-structures for MADT */
1399 struct madt_processor_apic
1402 uint8_t processor_id
; /* ACPI processor id */
1403 uint8_t local_apic_id
; /* Processor's local APIC id */
1405 uint32_t processor_enabled
: 1; /* Processor is usable if set */
1406 uint32_t reserved2
: 31; /* Reserved, must be zero */
1410 } __attribute__((__packed__
));
1414 * * ACPI 2.0 Generic Address Space definition.
1416 struct acpi_20_generic_address
{
1417 uint8_t address_space_id
;
1418 uint8_t register_bit_width
;
1419 uint8_t register_bit_offset
;
1422 } __attribute__((__packed__
));
1425 * * HPET Description Table
1427 struct acpi_20_hpet
{
1428 ACPI_TABLE_HEADER_DEF
/* ACPI common table header */
1429 uint32_t timer_block_id
;
1430 struct acpi_20_generic_address addr
;
1431 uint8_t hpet_number
;
1433 uint8_t page_protect
;
1434 } __attribute__((__packed__
));
1435 #define ACPI_HPET_ADDRESS 0xFED00000UL
1441 uint8_t io_apic_id
; /* I/O APIC ID */
1442 uint8_t reserved
; /* Reserved - must be zero */
1443 uint32_t address
; /* APIC physical address */
1444 uint32_t interrupt
; /* Global system interrupt where INTI
1446 } __attribute__((__packed__
));
1449 struct madt_int_override
1452 uint8_t bus
; /* Identifies ISA Bus */
1453 uint8_t source
; /* Bus-relative interrupt source */
1454 uint32_t gsi
; /* GSI that source will signal */
1455 uint16_t flags
; /* MPS INTI flags */
1456 } __attribute__((__packed__
));
1459 #include "acpi-dsdt.hex"
1461 static inline uint16_t cpu_to_le16(uint16_t x
)
1466 static inline uint32_t cpu_to_le32(uint32_t x
)
1471 static int acpi_checksum(const uint8_t *data
, int len
)
1475 for(i
= 0; i
< len
; i
++)
1477 return (-sum
) & 0xff;
1480 static void acpi_build_table_header(struct acpi_table_header
*h
,
1481 char *sig
, int len
, uint8_t rev
)
1483 memcpy(h
->signature
, sig
, 4);
1484 h
->length
= cpu_to_le32(len
);
1487 memcpy(h
->oem_id
, "QEMU ", 6);
1488 memcpy(h
->oem_table_id
, "QEMU", 4);
1490 memcpy(h
->oem_id
, "BOCHS ", 6);
1491 memcpy(h
->oem_table_id
, "BXPC", 4);
1493 memcpy(h
->oem_table_id
+ 4, sig
, 4);
1494 h
->oem_revision
= cpu_to_le32(1);
1496 memcpy(h
->asl_compiler_id
, "QEMU", 4);
1498 memcpy(h
->asl_compiler_id
, "BXPC", 4);
1500 h
->asl_compiler_revision
= cpu_to_le32(1);
1501 h
->checksum
= acpi_checksum((void *)h
, len
);
1504 /* base_addr must be a multiple of 4KB */
1505 void acpi_bios_init(void)
1507 struct rsdp_descriptor
*rsdp
;
1508 struct rsdt_descriptor_rev1
*rsdt
;
1509 struct fadt_descriptor_rev1
*fadt
;
1510 struct facs_descriptor_rev1
*facs
;
1511 struct multiple_apic_table
*madt
;
1512 uint8_t *dsdt
, *ssdt
;
1514 struct acpi_20_hpet
*hpet
;
1517 uint32_t base_addr
, rsdt_addr
, fadt_addr
, addr
, facs_addr
, dsdt_addr
, ssdt_addr
;
1518 uint32_t acpi_tables_size
, madt_addr
, madt_size
;
1521 /* reserve memory space for tables */
1522 #ifdef BX_USE_EBDA_TABLES
1523 ebda_cur_addr
= align(ebda_cur_addr
, 16);
1524 rsdp
= (void *)(ebda_cur_addr
);
1525 ebda_cur_addr
+= sizeof(*rsdp
);
1527 bios_table_cur_addr
= align(bios_table_cur_addr
, 16);
1528 rsdp
= (void *)(bios_table_cur_addr
);
1529 bios_table_cur_addr
+= sizeof(*rsdp
);
1532 addr
= base_addr
= ram_size
- ACPI_DATA_SIZE
;
1534 rsdt
= (void *)(addr
);
1535 addr
+= sizeof(*rsdt
);
1538 fadt
= (void *)(addr
);
1539 addr
+= sizeof(*fadt
);
1541 /* XXX: FACS should be in RAM */
1542 addr
= (addr
+ 63) & ~63; /* 64 byte alignment for FACS */
1544 facs
= (void *)(addr
);
1545 addr
+= sizeof(*facs
);
1548 dsdt
= (void *)(addr
);
1549 addr
+= sizeof(AmlCode
);
1551 addr
= (addr
+ 7) & ~7;
1553 madt_size
= sizeof(*madt
) +
1554 sizeof(struct madt_processor_apic
) * MAX_CPUS
+
1556 sizeof(struct madt_io_apic
) /* + sizeof(struct madt_int_override) */;
1558 sizeof(struct madt_io_apic
);
1560 madt
= (void *)(addr
);
1564 #ifdef HPET_WORKS_IN_KVM
1565 addr
= (addr
+ 7) & ~7;
1567 hpet
= (void *)(addr
);
1568 addr
+= sizeof(*hpet
);
1572 acpi_tables_size
= addr
- base_addr
;
1574 BX_INFO("ACPI tables: RSDP addr=0x%08lx ACPI DATA addr=0x%08lx size=0x%x\n",
1575 (unsigned long)rsdp
,
1576 (unsigned long)rsdt
, acpi_tables_size
);
1579 memset(rsdp
, 0, sizeof(*rsdp
));
1580 memcpy(rsdp
->signature
, "RSD PTR ", 8);
1582 memcpy(rsdp
->oem_id
, "QEMU ", 6);
1584 memcpy(rsdp
->oem_id
, "BOCHS ", 6);
1586 rsdp
->rsdt_physical_address
= cpu_to_le32(rsdt_addr
);
1587 rsdp
->checksum
= acpi_checksum((void *)rsdp
, 20);
1590 memset(rsdt
, 0, sizeof(*rsdt
));
1591 rsdt
->table_offset_entry
[0] = cpu_to_le32(fadt_addr
);
1592 rsdt
->table_offset_entry
[1] = cpu_to_le32(madt_addr
);
1593 //rsdt->table_offset_entry[2] = cpu_to_le32(ssdt_addr);
1595 //rsdt->table_offset_entry[3] = cpu_to_le32(hpet_addr);
1597 acpi_build_table_header((struct acpi_table_header
*)rsdt
,
1598 "RSDT", sizeof(*rsdt
), 1);
1601 memset(fadt
, 0, sizeof(*fadt
));
1602 fadt
->firmware_ctrl
= cpu_to_le32(facs_addr
);
1603 fadt
->dsdt
= cpu_to_le32(dsdt_addr
);
1605 fadt
->reserved1
= 0;
1606 fadt
->sci_int
= cpu_to_le16(pm_sci_int
);
1607 fadt
->smi_cmd
= cpu_to_le32(SMI_CMD_IO_ADDR
);
1608 fadt
->acpi_enable
= 0xf1;
1609 fadt
->acpi_disable
= 0xf0;
1610 fadt
->pm1a_evt_blk
= cpu_to_le32(pm_io_base
);
1611 fadt
->pm1a_cnt_blk
= cpu_to_le32(pm_io_base
+ 0x04);
1612 fadt
->pm_tmr_blk
= cpu_to_le32(pm_io_base
+ 0x08);
1613 fadt
->pm1_evt_len
= 4;
1614 fadt
->pm1_cnt_len
= 2;
1615 fadt
->pm_tmr_len
= 4;
1616 fadt
->plvl2_lat
= cpu_to_le16(0xfff); // C2 state not supported
1617 fadt
->plvl3_lat
= cpu_to_le16(0xfff); // C3 state not supported
1618 fadt
->gpe0_blk
= cpu_to_le32(0xafe0);
1619 fadt
->gpe0_blk_len
= 4;
1620 /* WBINVD + PROC_C1 + SLP_BUTTON + FIX_RTC */
1621 fadt
->flags
= cpu_to_le32((1 << 0) | (1 << 2) | (1 << 5) | (1 << 6));
1622 acpi_build_table_header((struct acpi_table_header
*)fadt
, "FACP",
1626 memset(facs
, 0, sizeof(*facs
));
1627 memcpy(facs
->signature
, "FACS", 4);
1628 facs
->length
= cpu_to_le32(sizeof(*facs
));
1629 BX_INFO("Firmware waking vector %p\n", &facs
->firmware_waking_vector
);
1632 memcpy(dsdt
, AmlCode
, sizeof(AmlCode
));
1636 struct madt_processor_apic
*apic
;
1637 struct madt_io_apic
*io_apic
;
1639 struct madt_int_override
*int_override
;
1642 memset(madt
, 0, madt_size
);
1643 madt
->local_apic_address
= cpu_to_le32(0xfee00000);
1644 madt
->flags
= cpu_to_le32(1);
1645 apic
= (void *)(madt
+ 1);
1646 for(i
=0;i
<MAX_CPUS
;i
++) {
1647 apic
->type
= APIC_PROCESSOR
;
1648 apic
->length
= sizeof(*apic
);
1649 apic
->processor_id
= i
;
1650 apic
->local_apic_id
= i
;
1652 apic
->flags
= cpu_to_le32(1);
1657 io_apic
= (void *)apic
;
1658 io_apic
->type
= APIC_IO
;
1659 io_apic
->length
= sizeof(*io_apic
);
1660 io_apic
->io_apic_id
= smp_cpus
;
1661 io_apic
->address
= cpu_to_le32(0xfec00000);
1662 io_apic
->interrupt
= cpu_to_le32(0);
1664 #ifdef HPET_WORKS_IN_KVM
1667 int_override
= (void *)io_apic
;
1668 int_override
->type
= APIC_XRUPT_OVERRIDE
;
1669 int_override
->length
= sizeof(*int_override
);
1670 int_override
->bus
= cpu_to_le32(0);
1671 int_override
->source
= cpu_to_le32(0);
1672 int_override
->gsi
= cpu_to_le32(2);
1673 int_override
->flags
= cpu_to_le32(0);
1677 int_override
= (struct madt_int_override
*)(io_apic
+ 1);
1678 for ( i
= 0; i
< 16; i
++ ) {
1679 if ( PCI_ISA_IRQ_MASK
& (1U << i
) ) {
1680 memset(int_override
, 0, sizeof(*int_override
));
1681 int_override
->type
= APIC_XRUPT_OVERRIDE
;
1682 int_override
->length
= sizeof(*int_override
);
1683 int_override
->source
= i
;
1684 int_override
->gsi
= i
;
1685 int_override
->flags
= 0xd; /* active high, level triggered */
1687 /* No need for a INT source override structure. */
1691 madt_size
+= sizeof(struct madt_int_override
);
1693 acpi_build_table_header((struct acpi_table_header
*)madt
,
1694 "APIC", madt_size
, 1);
1699 #ifdef HPET_WORKS_IN_KVM
1700 memset(hpet
, 0, sizeof(*hpet
));
1701 /* Note timer_block_id value must be kept in sync with value advertised by
1704 hpet
->timer_block_id
= cpu_to_le32(0x8086a201);
1705 hpet
->addr
.address
= cpu_to_le32(ACPI_HPET_ADDRESS
);
1706 acpi_build_table_header((struct acpi_table_header
*)hpet
,
1707 "HPET", sizeof(*hpet
), 1);
1713 /* SMBIOS entry point -- must be written to a 16-bit aligned address
1714 between 0xf0000 and 0xfffff.
1716 struct smbios_entry_point
{
1717 char anchor_string
[4];
1720 uint8_t smbios_major_version
;
1721 uint8_t smbios_minor_version
;
1722 uint16_t max_structure_size
;
1723 uint8_t entry_point_revision
;
1724 uint8_t formatted_area
[5];
1725 char intermediate_anchor_string
[5];
1726 uint8_t intermediate_checksum
;
1727 uint16_t structure_table_length
;
1728 uint32_t structure_table_address
;
1729 uint16_t number_of_structures
;
1730 uint8_t smbios_bcd_revision
;
1731 } __attribute__((__packed__
));
1733 /* This goes at the beginning of every SMBIOS structure. */
1734 struct smbios_structure_header
{
1738 } __attribute__((__packed__
));
1740 /* SMBIOS type 0 - BIOS Information */
1741 struct smbios_type_0
{
1742 struct smbios_structure_header header
;
1744 uint8_t bios_version_str
;
1745 uint16_t bios_starting_address_segment
;
1746 uint8_t bios_release_date_str
;
1747 uint8_t bios_rom_size
;
1748 uint8_t bios_characteristics
[8];
1749 uint8_t bios_characteristics_extension_bytes
[2];
1750 uint8_t system_bios_major_release
;
1751 uint8_t system_bios_minor_release
;
1752 uint8_t embedded_controller_major_release
;
1753 uint8_t embedded_controller_minor_release
;
1754 } __attribute__((__packed__
));
1756 /* SMBIOS type 1 - System Information */
1757 struct smbios_type_1
{
1758 struct smbios_structure_header header
;
1759 uint8_t manufacturer_str
;
1760 uint8_t product_name_str
;
1761 uint8_t version_str
;
1762 uint8_t serial_number_str
;
1764 uint8_t wake_up_type
;
1765 uint8_t sku_number_str
;
1767 } __attribute__((__packed__
));
1769 /* SMBIOS type 3 - System Enclosure (v2.3) */
1770 struct smbios_type_3
{
1771 struct smbios_structure_header header
;
1772 uint8_t manufacturer_str
;
1774 uint8_t version_str
;
1775 uint8_t serial_number_str
;
1776 uint8_t asset_tag_number_str
;
1777 uint8_t boot_up_state
;
1778 uint8_t power_supply_state
;
1779 uint8_t thermal_state
;
1780 uint8_t security_status
;
1781 uint32_t oem_defined
;
1783 uint8_t number_of_power_cords
;
1784 uint8_t contained_element_count
;
1785 // contained elements follow
1786 } __attribute__((__packed__
));
1788 /* SMBIOS type 4 - Processor Information (v2.0) */
1789 struct smbios_type_4
{
1790 struct smbios_structure_header header
;
1791 uint8_t socket_designation_str
;
1792 uint8_t processor_type
;
1793 uint8_t processor_family
;
1794 uint8_t processor_manufacturer_str
;
1795 uint32_t processor_id
[2];
1796 uint8_t processor_version_str
;
1798 uint16_t external_clock
;
1800 uint16_t current_speed
;
1802 uint8_t processor_upgrade
;
1803 uint16_t l1_cache_handle
;
1804 uint16_t l2_cache_handle
;
1805 uint16_t l3_cache_handle
;
1806 } __attribute__((__packed__
));
1808 /* SMBIOS type 16 - Physical Memory Array
1809 * Associated with one type 17 (Memory Device).
1811 struct smbios_type_16
{
1812 struct smbios_structure_header header
;
1815 uint8_t error_correction
;
1816 uint32_t maximum_capacity
;
1817 uint16_t memory_error_information_handle
;
1818 uint16_t number_of_memory_devices
;
1819 } __attribute__((__packed__
));
1821 /* SMBIOS type 17 - Memory Device
1822 * Associated with one type 19
1824 struct smbios_type_17
{
1825 struct smbios_structure_header header
;
1826 uint16_t physical_memory_array_handle
;
1827 uint16_t memory_error_information_handle
;
1828 uint16_t total_width
;
1829 uint16_t data_width
;
1831 uint8_t form_factor
;
1833 uint8_t device_locator_str
;
1834 uint8_t bank_locator_str
;
1835 uint8_t memory_type
;
1836 uint16_t type_detail
;
1837 } __attribute__((__packed__
));
1839 /* SMBIOS type 19 - Memory Array Mapped Address */
1840 struct smbios_type_19
{
1841 struct smbios_structure_header header
;
1842 uint32_t starting_address
;
1843 uint32_t ending_address
;
1844 uint16_t memory_array_handle
;
1845 uint8_t partition_width
;
1846 } __attribute__((__packed__
));
1848 /* SMBIOS type 20 - Memory Device Mapped Address */
1849 struct smbios_type_20
{
1850 struct smbios_structure_header header
;
1851 uint32_t starting_address
;
1852 uint32_t ending_address
;
1853 uint16_t memory_device_handle
;
1854 uint16_t memory_array_mapped_address_handle
;
1855 uint8_t partition_row_position
;
1856 uint8_t interleave_position
;
1857 uint8_t interleaved_data_depth
;
1858 } __attribute__((__packed__
));
1860 /* SMBIOS type 32 - System Boot Information */
1861 struct smbios_type_32
{
1862 struct smbios_structure_header header
;
1863 uint8_t reserved
[6];
1864 uint8_t boot_status
;
1865 } __attribute__((__packed__
));
1867 /* SMBIOS type 127 -- End-of-table */
1868 struct smbios_type_127
{
1869 struct smbios_structure_header header
;
1870 } __attribute__((__packed__
));
1873 smbios_entry_point_init(void *start
,
1874 uint16_t max_structure_size
,
1875 uint16_t structure_table_length
,
1876 uint32_t structure_table_address
,
1877 uint16_t number_of_structures
)
1881 struct smbios_entry_point
*ep
= (struct smbios_entry_point
*)start
;
1883 memcpy(ep
->anchor_string
, "_SM_", 4);
1885 ep
->smbios_major_version
= 2;
1886 ep
->smbios_minor_version
= 4;
1887 ep
->max_structure_size
= max_structure_size
;
1888 ep
->entry_point_revision
= 0;
1889 memset(ep
->formatted_area
, 0, 5);
1890 memcpy(ep
->intermediate_anchor_string
, "_DMI_", 5);
1892 ep
->structure_table_length
= structure_table_length
;
1893 ep
->structure_table_address
= structure_table_address
;
1894 ep
->number_of_structures
= number_of_structures
;
1895 ep
->smbios_bcd_revision
= 0x24;
1898 ep
->intermediate_checksum
= 0;
1901 for (i
= 0; i
< 0x10; i
++)
1902 sum
+= ((int8_t *)start
)[i
];
1903 ep
->checksum
= -sum
;
1906 for (i
= 0x10; i
< ep
->length
; i
++)
1907 sum
+= ((int8_t *)start
)[i
];
1908 ep
->intermediate_checksum
= -sum
;
1911 /* Type 0 -- BIOS Information */
1912 #define RELEASE_DATE_STR "01/01/2007"
1914 smbios_type_0_init(void *start
)
1916 struct smbios_type_0
*p
= (struct smbios_type_0
*)start
;
1919 p
->header
.length
= sizeof(struct smbios_type_0
);
1920 p
->header
.handle
= 0;
1923 p
->bios_version_str
= 1;
1924 p
->bios_starting_address_segment
= 0xe800;
1925 p
->bios_release_date_str
= 2;
1926 p
->bios_rom_size
= 0; /* FIXME */
1928 memset(p
->bios_characteristics
, 0, 8);
1929 p
->bios_characteristics
[0] = 0x08; /* BIOS characteristics not supported */
1930 p
->bios_characteristics_extension_bytes
[0] = 0;
1931 p
->bios_characteristics_extension_bytes
[1] = 0;
1933 p
->system_bios_major_release
= 1;
1934 p
->system_bios_minor_release
= 0;
1935 p
->embedded_controller_major_release
= 0xff;
1936 p
->embedded_controller_minor_release
= 0xff;
1938 start
+= sizeof(struct smbios_type_0
);
1939 memcpy((char *)start
, BX_APPNAME
, sizeof(BX_APPNAME
));
1940 start
+= sizeof(BX_APPNAME
);
1941 memcpy((char *)start
, RELEASE_DATE_STR
, sizeof(RELEASE_DATE_STR
));
1942 start
+= sizeof(RELEASE_DATE_STR
);
1943 *((uint8_t *)start
) = 0;
1948 /* Type 1 -- System Information */
1950 smbios_type_1_init(void *start
)
1952 struct smbios_type_1
*p
= (struct smbios_type_1
*)start
;
1954 p
->header
.length
= sizeof(struct smbios_type_1
);
1955 p
->header
.handle
= 0x100;
1957 p
->manufacturer_str
= 0;
1958 p
->product_name_str
= 0;
1960 p
->serial_number_str
= 0;
1962 memcpy(p
->uuid
, bios_uuid
, 16);
1964 p
->wake_up_type
= 0x06; /* power switch */
1965 p
->sku_number_str
= 0;
1968 start
+= sizeof(struct smbios_type_1
);
1969 *((uint16_t *)start
) = 0;
1974 /* Type 3 -- System Enclosure */
1976 smbios_type_3_init(void *start
)
1978 struct smbios_type_3
*p
= (struct smbios_type_3
*)start
;
1981 p
->header
.length
= sizeof(struct smbios_type_3
);
1982 p
->header
.handle
= 0x300;
1984 p
->manufacturer_str
= 0;
1985 p
->type
= 0x01; /* other */
1987 p
->serial_number_str
= 0;
1988 p
->asset_tag_number_str
= 0;
1989 p
->boot_up_state
= 0x03; /* safe */
1990 p
->power_supply_state
= 0x03; /* safe */
1991 p
->thermal_state
= 0x03; /* safe */
1992 p
->security_status
= 0x02; /* unknown */
1995 p
->number_of_power_cords
= 0;
1996 p
->contained_element_count
= 0;
1998 start
+= sizeof(struct smbios_type_3
);
1999 *((uint16_t *)start
) = 0;
2004 /* Type 4 -- Processor Information */
2006 smbios_type_4_init(void *start
, unsigned int cpu_number
)
2008 struct smbios_type_4
*p
= (struct smbios_type_4
*)start
;
2011 p
->header
.length
= sizeof(struct smbios_type_4
);
2012 p
->header
.handle
= 0x400 + cpu_number
;
2014 p
->socket_designation_str
= 1;
2015 p
->processor_type
= 0x03; /* CPU */
2016 p
->processor_family
= 0x01; /* other */
2017 p
->processor_manufacturer_str
= 0;
2019 p
->processor_id
[0] = cpuid_signature
;
2020 p
->processor_id
[1] = cpuid_features
;
2022 p
->processor_version_str
= 0;
2024 p
->external_clock
= 0;
2026 p
->max_speed
= 0; /* unknown */
2027 p
->current_speed
= 0; /* unknown */
2029 p
->status
= 0x41; /* socket populated, CPU enabled */
2030 p
->processor_upgrade
= 0x01; /* other */
2032 p
->l1_cache_handle
= 0xffff; /* cache information structure not provided */
2033 p
->l2_cache_handle
= 0xffff;
2034 p
->l3_cache_handle
= 0xffff;
2036 start
+= sizeof(struct smbios_type_4
);
2038 memcpy((char *)start
, "CPU " "\0" "" "\0" "", 7);
2039 ((char *)start
)[4] = cpu_number
+ '0';
2044 /* Type 16 -- Physical Memory Array */
2046 smbios_type_16_init(void *start
, uint32_t memsize
, int nr_mem_devs
)
2048 struct smbios_type_16
*p
= (struct smbios_type_16
*)start
;
2050 p
->header
.type
= 16;
2051 p
->header
.length
= sizeof(struct smbios_type_16
);
2052 p
->header
.handle
= 0x1000;
2054 p
->location
= 0x01; /* other */
2055 p
->use
= 0x03; /* system memory */
2056 p
->error_correction
= 0x01; /* other */
2057 p
->maximum_capacity
= memsize
* 1024;
2058 p
->memory_error_information_handle
= 0xfffe; /* none provided */
2059 p
->number_of_memory_devices
= nr_mem_devs
;
2061 start
+= sizeof(struct smbios_type_16
);
2062 *((uint16_t *)start
) = 0;
2067 /* Type 17 -- Memory Device */
2069 smbios_type_17_init(void *start
, uint32_t memory_size_mb
, int instance
)
2071 struct smbios_type_17
*p
= (struct smbios_type_17
*)start
;
2073 p
->header
.type
= 17;
2074 p
->header
.length
= sizeof(struct smbios_type_17
);
2075 p
->header
.handle
= 0x1100 + instance
;
2077 p
->physical_memory_array_handle
= 0x1000;
2078 p
->total_width
= 64;
2080 /* TODO: should assert in case something is wrong ASSERT((memory_size_mb & ~0x7fff) == 0); */
2081 p
->size
= memory_size_mb
;
2082 p
->form_factor
= 0x09; /* DIMM */
2084 p
->device_locator_str
= 1;
2085 p
->bank_locator_str
= 0;
2086 p
->memory_type
= 0x07; /* RAM */
2089 start
+= sizeof(struct smbios_type_17
);
2090 snprintf(start
, 8, "DIMM %d", instance
);
2091 start
+= strlen(start
) + 1;
2092 *((uint8_t *)start
) = 0;
2097 /* Type 19 -- Memory Array Mapped Address */
2099 smbios_type_19_init(void *start
, uint32_t memory_size_mb
, int instance
)
2101 struct smbios_type_19
*p
= (struct smbios_type_19
*)start
;
2103 p
->header
.type
= 19;
2104 p
->header
.length
= sizeof(struct smbios_type_19
);
2105 p
->header
.handle
= 0x1300 + instance
;
2107 p
->starting_address
= instance
<< 24;
2108 p
->ending_address
= p
->starting_address
+ (memory_size_mb
<< 10) - 1;
2109 p
->memory_array_handle
= 0x1000;
2110 p
->partition_width
= 1;
2112 start
+= sizeof(struct smbios_type_19
);
2113 *((uint16_t *)start
) = 0;
2118 /* Type 20 -- Memory Device Mapped Address */
2120 smbios_type_20_init(void *start
, uint32_t memory_size_mb
, int instance
)
2122 struct smbios_type_20
*p
= (struct smbios_type_20
*)start
;
2124 p
->header
.type
= 20;
2125 p
->header
.length
= sizeof(struct smbios_type_20
);
2126 p
->header
.handle
= 0x1400 + instance
;
2128 p
->starting_address
= instance
<< 24;
2129 p
->ending_address
= p
->starting_address
+ (memory_size_mb
<< 10) - 1;
2130 p
->memory_device_handle
= 0x1100 + instance
;
2131 p
->memory_array_mapped_address_handle
= 0x1300 + instance
;
2132 p
->partition_row_position
= 1;
2133 p
->interleave_position
= 0;
2134 p
->interleaved_data_depth
= 0;
2136 start
+= sizeof(struct smbios_type_20
);
2138 *((uint16_t *)start
) = 0;
2142 /* Type 32 -- System Boot Information */
2144 smbios_type_32_init(void *start
)
2146 struct smbios_type_32
*p
= (struct smbios_type_32
*)start
;
2148 p
->header
.type
= 32;
2149 p
->header
.length
= sizeof(struct smbios_type_32
);
2150 p
->header
.handle
= 0x2000;
2151 memset(p
->reserved
, 0, 6);
2152 p
->boot_status
= 0; /* no errors detected */
2154 start
+= sizeof(struct smbios_type_32
);
2155 *((uint16_t *)start
) = 0;
2160 /* Type 127 -- End of Table */
2162 smbios_type_127_init(void *start
)
2164 struct smbios_type_127
*p
= (struct smbios_type_127
*)start
;
2166 p
->header
.type
= 127;
2167 p
->header
.length
= sizeof(struct smbios_type_127
);
2168 p
->header
.handle
= 0x7f00;
2170 start
+= sizeof(struct smbios_type_127
);
2171 *((uint16_t *)start
) = 0;
2176 void smbios_init(void)
2178 unsigned cpu_num
, nr_structs
= 0, max_struct_size
= 0;
2179 char *start
, *p
, *q
;
2180 int memsize
= (ram_end
== ram_size
) ? ram_size
/ (1024 * 1024) :
2181 (ram_end
- (1ull << 32) + ram_size
) / (1024 * 1024);
2184 #ifdef BX_USE_EBDA_TABLES
2185 ebda_cur_addr
= align(ebda_cur_addr
, 16);
2186 start
= (void *)(ebda_cur_addr
);
2188 bios_table_cur_addr
= align(bios_table_cur_addr
, 16);
2189 start
= (void *)(bios_table_cur_addr
);
2192 p
= (char *)start
+ sizeof(struct smbios_entry_point
);
2194 #define add_struct(fn) do{ \
2197 if ((q - p) > max_struct_size) \
2198 max_struct_size = q - p; \
2202 add_struct(smbios_type_0_init(p
));
2203 add_struct(smbios_type_1_init(p
));
2204 add_struct(smbios_type_3_init(p
));
2205 for (cpu_num
= 1; cpu_num
<= smp_cpus
; cpu_num
++)
2206 add_struct(smbios_type_4_init(p
, cpu_num
));
2208 /* Each 'memory device' covers up to 16GB of address space. */
2209 nr_mem_devs
= (memsize
+ 0x3fff) >> 14;
2210 add_struct(smbios_type_16_init(p
, memsize
, nr_mem_devs
));
2211 for ( i
= 0; i
< nr_mem_devs
; i
++ )
2213 uint32_t dev_memsize
= ((i
== (nr_mem_devs
- 1))
2214 ? (((memsize
-1) & 0x3fff)+1) : 0x4000);
2215 add_struct(smbios_type_17_init(p
, dev_memsize
, i
));
2216 add_struct(smbios_type_19_init(p
, dev_memsize
, i
));
2217 add_struct(smbios_type_20_init(p
, dev_memsize
, i
));
2220 add_struct(smbios_type_32_init(p
));
2221 add_struct(smbios_type_127_init(p
));
2225 smbios_entry_point_init(
2226 start
, max_struct_size
,
2227 (p
- (char *)start
) - sizeof(struct smbios_entry_point
),
2228 (uint32_t)(start
+ sizeof(struct smbios_entry_point
)),
2231 #ifdef BX_USE_EBDA_TABLES
2232 ebda_cur_addr
+= (p
- (char *)start
);
2234 bios_table_cur_addr
+= (p
- (char *)start
);
2237 BX_INFO("SMBIOS table addr=0x%08lx\n", (unsigned long)start
);
2240 static uint32_t find_resume_vector(void)
2242 unsigned long addr
, start
, end
;
2244 #ifdef BX_USE_EBDA_TABLES
2245 start
= align(ebda_cur_addr
, 16);
2248 if (bios_table_cur_addr
== 0)
2250 start
= align(bios_table_cur_addr
, 16);
2251 end
= bios_table_end_addr
;
2254 for (addr
= start
; addr
< end
; addr
+= 16) {
2255 if (!memcmp((void*)addr
, "RSD PTR ", 8)) {
2256 struct rsdp_descriptor
*rsdp
= (void*)addr
;
2257 struct rsdt_descriptor_rev1
*rsdt
= (void*)rsdp
->rsdt_physical_address
;
2258 struct fadt_descriptor_rev1
*fadt
= (void*)rsdt
->table_offset_entry
[0];
2259 struct facs_descriptor_rev1
*facs
= (void*)fadt
->firmware_ctrl
;
2260 return facs
->firmware_waking_vector
;
2267 static void find_440fx(PCIDevice
*d
)
2269 uint16_t vendor_id
, device_id
;
2271 vendor_id
= pci_config_readw(d
, PCI_VENDOR_ID
);
2272 device_id
= pci_config_readw(d
, PCI_DEVICE_ID
);
2274 if (vendor_id
== PCI_VENDOR_ID_INTEL
&& device_id
== PCI_DEVICE_ID_INTEL_82441
)
2278 static void reinit_piix4_pm(PCIDevice
*d
)
2280 uint16_t vendor_id
, device_id
;
2282 vendor_id
= pci_config_readw(d
, PCI_VENDOR_ID
);
2283 device_id
= pci_config_readw(d
, PCI_DEVICE_ID
);
2285 if (vendor_id
== PCI_VENDOR_ID_INTEL
&& device_id
== PCI_DEVICE_ID_INTEL_82371AB_3
)
2289 void rombios32_init(uint32_t *s3_resume_vector
, uint8_t *shutdown_flag
)
2291 BX_INFO("Starting rombios32\n");
2292 BX_INFO("Shutdown flag %x\n", *shutdown_flag
);
2295 qemu_cfg_port
= qemu_cfg_port_probe();
2308 find_bios_table_area();
2310 if (*shutdown_flag
== 0xfe) {
2311 /* redirect bios read access to RAM */
2312 pci_for_each_device(find_440fx
);
2313 bios_lock_shadow_ram(); /* bios is already copied */
2314 *s3_resume_vector
= find_resume_vector();
2315 if (!*s3_resume_vector
) {
2316 BX_INFO("This is S3 resume but wakeup vector is NULL\n");
2318 BX_INFO("S3 resume vector %p\n", *s3_resume_vector
);
2319 pci_for_each_device(reinit_piix4_pm
);
2326 if (bios_table_cur_addr
!= 0) {
2337 bios_lock_shadow_ram();
2339 BX_INFO("bios_table_cur_addr: 0x%08lx\n", bios_table_cur_addr
);
2340 if (bios_table_cur_addr
> bios_table_end_addr
)
2341 BX_PANIC("bios_table_end_addr overflow!\n");
2342 #ifdef BX_USE_EBDA_TABLES
2343 BX_INFO("ebda_cur_addr: 0x%08lx\n", ebda_cur_addr
);
2344 if (ebda_cur_addr
> 0xA0000)
2345 BX_PANIC("ebda_cur_addr overflow!\n");