Bring seabios and qemu pcbios closer together
cover Bring seabios and qemu pcbios closer together
That is for now.
Gleb Natapov (21):
Add support for passing additional acpi tables from qemu. Load SMBIOS entries and files from qemu
Always create PCI interrupt override acpi tables. Correct default pci irq links
irq0override provided by qemu.
Check at runtime if VM is KVM.
Remove CONFIG_KVM compile option.
Add rule to compile DSDT to make file.
Use preprocessor for pci link routing.
Advertise pci irqs as active high in DSDT Restrict pci interrupts to irq 5/9/10/11
Use extended interrupt descriptor for pci irqs. Remove irq 9 from the pci interrupt link resources. Provide gpe _L0x methods.
Pci hotplug support.
HPET support.
Add 26 pci slots, bringing the total to 32.
Add SRAT ACPI table support.
Read max number of cpus from VM.
Move qemu cfg init before smp init.
Use MaxCountCPUs during building of per cpu tables.
Makefile | 7 ++ src/acpi-dsdt.dsl | 311 +++++++++++++++++++++++++++++++++++++++++------------ src/acpi.c | 245 ++++++++++++++++++++++++++++++++++++++---- src/config.h | 6 +- src/mptable.c | 27 ++--- src/paravirt.c | 221 +++++++++++++++++++++++++++++++++++++ src/paravirt.h | 12 ++ src/pciinit.c | 4 - src/post.c | 6 +- src/smbios.c | 188 +++++++++++++++++++------------- src/smp.c | 9 ++- src/util.h | 4 +- 12 files changed, 846 insertions(+), 194 deletions(-)
PATCH v2 1/21 Add support for passing additional acpi tables from qemu.
---v1->v2
- drop CONFIG_KVM change. That was unintentional
src/acpi.c | 18 +++++++++++++++++- src/paravirt.c | 27 +++++++++++++++++++++++++++ src/paravirt.h | 3 +++ 3 files changed, 47 insertions(+), 1 deletions(-)
src/acpi.c +17 -1
@@ -11,7 +11,7 @@#include "biosvar.h" // GET_EBDA #include "pci_ids.h" // PCI_VENDOR_ID_INTEL #include "pci_regs.h" // PCI_INTERRUPT_LINE - +#include "paravirt.h" /****************************************************/ /* ACPI tables init */
@@ -444,6 +444,22 @@ acpi_bios_init(void)ACPI_INIT_TABLE (build_ssdt ());ACPI_INIT_TABLE (build_madt ()); +u16 i, external_tables =qemu_cfg_acpi_additional_tables (); + +for (i =0 ; i < external_tables; i++) { +u16 len =qemu_cfg_next_acpi_table_len (); +void *addr =malloc_high (len); +if (!addr) { +dprintf (1 ,"Not enogh memory of ext acpi table of size %d!\n" , len); +continue ; + } +ACPI_INIT_TABLE (qemu_cfg_next_acpi_table_load (addr, len)); +if (tbl_idx ==MAX_ACPI_TABLES ) { +dprintf (1 ,"To many external table!\n" ); +break ; + } + } +struct rsdt_descriptor_rev1 *rsdt;size_t rsdt_len =sizeof (*rsdt) +sizeof (u32) * tbl_idx; rsdt =malloc_high (rsdt_len);
src/paravirt.c +27 -0
@@ -72,3 +72,30 @@ int qemu_cfg_show_boot_menu(void)return v; } +u16 qemu_cfg_acpi_additional_tables (void ) +{ +u16 cnt; + +if (!qemu_cfg_present) +return 0 ; + +qemu_cfg_read_entry (&cnt,QEMU_CFG_ACPI_TABLES ,sizeof (cnt)); + +return cnt; +} + +u16 qemu_cfg_next_acpi_table_len (void ) +{ +u16 len; + +qemu_cfg_read ((u8 *)&len,sizeof (len)); + +return len; +} + +void *qemu_cfg_next_acpi_table_load (void *addr,u16 len) +{ +qemu_cfg_read (addr, len); +return addr; +} +
src/paravirt.h +3 -0
@@ -40,5 +40,8 @@ extern int qemu_cfg_present;void qemu_cfg_port_probe (void );int qemu_cfg_show_boot_menu (void );void qemu_cfg_get_uuid (u8 *uuid); +u16 qemu_cfg_acpi_additional_tables (void ); +u16 qemu_cfg_next_acpi_table_len (void ); +void *qemu_cfg_next_acpi_table_load (void *addr,u16 len);#endif
Signature · 1 line
1.6.3.3
PATCH 3/21 Always create PCI interrupt override acpi tables.
In reply to Gleb NatapovThis is what qemu pcbios does since commitda5ff65dc9473e3f069736d38b9a189ea14a67eb.
Qemu implements PCI interrupts as active high, but OSes assume that they are active low as per PCI spec. Qemu works without override only because ioapic there doesn't implement polarity bit.
--- src/acpi.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
src/acpi.c +0 -5
@@ -196,12 +196,7 @@ struct madt_io_apic* lines start */ }PACKED ; -#if CONFIG_KVM -/* IRQs 5,9,10,11 */ #define PCI_ISA_IRQ_MASK 0x0e20 -#else -#define PCI_ISA_IRQ_MASK 0x0000 -#endif struct madt_intsrcovr {APIC_HEADER_DEF
Signature · 1 line
1.6.3.3
PATCH 4/21 Correct default pci irq links
In reply to Gleb NatapovThe hardware uses irqs 10 and 11, so change the bios to reflect that.
Qemu pcbios commit b0a155cfddc57e93b641a24fb198fdd8d738f143
--- src/pciinit.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
src/pciinit.c +0 -4
@@ -19,11 +19,7 @@ static u32 pci_bios_mem_addr;static u32 pci_bios_bigmem_addr;/* host irqs corresponding to PCI irqs A-D */ static u8 pci_irqs[4 ] = { -#if CONFIG_KVM 10 ,10 ,11 ,11 -#else - 11, 9, 11, 9 -#endif };static void pci_set_io_region_addr (u16 bdf,int region_num,u32 addr)
Signature · 1 line
1.6.3.3
PATCH 5/21 irq0override provided by qemu.
In reply to Gleb NatapovRead it instead of relying on compile time flag.
--- src/acpi.c | 2 +- src/mptable.c | 9 ++------- src/paravirt.c | 12 ++++++++++++ src/paravirt.h | 2 ++ src/util.h | 3 --- 5 files changed, 17 insertions(+), 11 deletions(-)
src/acpi.c +1 -1
@@ -314,7 +314,7 @@ build_madt(void) io_apic->interrupt =cpu_to_le32 (0 );struct madt_intsrcovr *intsrcovr = (void *)&io_apic[1 ]; -if (irq0override) { +if (qemu_cfg_irq0_override ()) {memset (intsrcovr,0 ,sizeof (*intsrcovr)); intsrcovr->type =APIC_XRUPT_OVERRIDE ; intsrcovr->length =sizeof (*intsrcovr);
src/mptable.c +2 -7
@@ -8,12 +8,7 @@#include "util.h" // dprintf #include "config.h" // CONFIG_* #include "mptable.h" // MPTABLE_SIGNATURE - -#if CONFIG_KVM -int irq0override =1 ; -#else -int irq0override =0 ; -#endif +#include "paravirt.h" void mptable_init (void )
@@ -103,7 +98,7 @@ mptable_init(void) intsrc->srcbusirq = i; intsrc->dstapic = ioapic_id; intsrc->dstirq = i; -if (irq0override) { +if (qemu_cfg_irq0_override ()) {/* Destination 2 is covered by irq0->inti2 override (i == 0). Source IRQ 2 is unused */ if (i ==0 )
src/paravirt.c +12 -0
@@ -79,6 +79,18 @@ int qemu_cfg_show_boot_menu(void)return v; } +int qemu_cfg_irq0_override (void ) +{ +u8 v; + +if (!qemu_cfg_present) +return 0 ; + +qemu_cfg_read_entry (&v,QEMU_CFG_IRQ0_OVERRIDE ,sizeof (v)); + +return v; +} +u16 qemu_cfg_acpi_additional_tables (void ) {u16 cnt;
src/paravirt.h +2 -0
@@ -34,12 +34,14 @@ static inline int kvm_para_available(void)#define QEMU_CFG_ARCH_LOCAL 0x8000#define QEMU_CFG_ACPI_TABLES (QEMU_CFG_ARCH_LOCAL + 0)#define QEMU_CFG_SMBIOS_ENTRIES (QEMU_CFG_ARCH_LOCAL + 1) +#define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 1)extern int qemu_cfg_present;void qemu_cfg_port_probe (void );int qemu_cfg_show_boot_menu (void );void qemu_cfg_get_uuid (u8 *uuid); +int qemu_cfg_irq0_override (void );u16 qemu_cfg_acpi_additional_tables (void );u16 qemu_cfg_next_acpi_table_len (void );void *qemu_cfg_next_acpi_table_load (void *addr,u16 len);
src/util.h +0 -3
@@ -302,9 +302,6 @@ void reset_vector() __attribute__ ((noreturn));// misc.c extern u8 BiosChecksum; -// mptable.c -extern int irq0override; -// version (auto generated file out/version.c) extern const char VERSION [];
Signature · 1 line
1.6.3.3
PATCH 6/21 Check at runtime if VM is KVM.
In reply to Gleb Natapov--- src/post.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
src/post.c +1 -1
@@ -129,7 +129,7 @@ ram_probe(void) , E820_RESERVED);add_e820 (BUILD_BIOS_ADDR ,BUILD_BIOS_SIZE ,E820_RESERVED ); -if (CONFIG_KVM ) +if (kvm_para_available ())// 4 pages before the bios, 3 pages for vmx tss pages, the // other page for EPT real mode pagetable add_e820 (0xfffbc000 ,4 *4096 ,E820_RESERVED );
Signature · 1 line
1.6.3.3
PATCH 7/21 Remove CONFIG_KVM compile option.
In reply to Gleb NatapovQemu and KVM should use the same bios build. All differences should be handled in runtime.
--- src/config.h | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
src/config.h +0 -2
@@ -12,8 +12,6 @@#define CONFIG_APPNAME6 "BOCHS "#define CONFIG_APPNAME4 "BXPC" -// Configure for use with KVM. -#define CONFIG_KVM 0// Configure as a coreboot payload. #define CONFIG_COREBOOT 0
Signature · 1 line
1.6.3.3
PATCH 8/21 Add rule to compile DSDT to make file.
In reply to Gleb Natapov--- Makefile | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
Makefile +7 -0
@@ -175,6 +175,13 @@ $(OUT)vgabios.bin: $(OUT)vgabios.bin.raw tools/buildrom.py @echo " Finalizing rom $@" $(Q)./tools/buildrom.py $< $@ +####### dsdt buld rules +src/acpi-dsdt.hex: src/acpi-dsdt.dsl + @echo "Compiling DSDT" + $(Q)cpp -P $< > $(OUT)acpi-dsdt.dsl.i + $(Q)iasl -tc -p $@ $(OUT)acpi-dsdt.dsl.i + $(Q)rm $(OUT)acpi-dsdt.dsl.i + ####### Generic rules clean: $(Q)rm -rf $(OUT)
Signature · 1 line
1.6.3.3
PATCH v2 2/21 Load SMBIOS entries and files from qemu
In reply to Gleb NatapovAllow SMBIOS fields to be overridden and entries replaced by those read from qemu.
This is port of commit f4a09e759469be74e2598758bfae623b555c4cae from qemu pc-bios tree.
---v1->v2:
check that additional tables do not overflow allocated memory.
src/paravirt.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++ src/paravirt.h | 4 + src/smbios.c | 182 ++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 269 insertions(+), 71 deletions(-)
src/paravirt.c +154 -0
@@ -27,6 +27,13 @@ qemu_cfg_read(u8 *buf, int len) }static void +qemu_cfg_skip (int len) +{ +while (len--) +inb (PORT_QEMU_CFG_DATA ); +} + +static void qemu_cfg_read_entry (void *buf,int e,int len) {qemu_cfg_select (e);
@@ -99,3 +106,150 @@ void* qemu_cfg_next_acpi_table_load(void *addr, u16 len)return addr; } +u16 qemu_cfg_smbios_entries (void ) +{ +u16 cnt; + +if (!qemu_cfg_present) +return 0 ; + +qemu_cfg_read_entry (&cnt,QEMU_CFG_SMBIOS_ENTRIES ,sizeof (cnt)); + +return cnt; +} + +struct smbios_header { +u16 length; +u8 type; +}PACKED ; + +struct smbios_field { +struct smbios_header header; +u8 type; +u16 offset; +u8 data[]; +}PACKED ; + +struct smbios_table { +struct smbios_header header; +u8 data[]; +}PACKED ; + +#define SMBIOS_FIELD_ENTRY 0 +#define SMBIOS_TABLE_ENTRY 1 + +size_t qemu_cfg_smbios_load_field (int type,size_t offset,void *addr) +{ +int i; + +for (i =qemu_cfg_smbios_entries (); i >0 ; i--) { +struct smbios_field field; + +qemu_cfg_read ((u8 *)&field,sizeof (struct smbios_header )); + field.header.length -=sizeof (struct smbios_header ); + +if (field.header.type !=SMBIOS_FIELD_ENTRY ) { +qemu_cfg_skip (field.header.length); +continue ; + } + +qemu_cfg_read ((u8 *)&field.type, +sizeof (field) -sizeof (struct smbios_header )); + field.header.length -=sizeof (field) -sizeof (struct smbios_header ); + +if (field.type != type || field.offset != offset) { +qemu_cfg_skip (field.header.length); +continue ; + } + +qemu_cfg_read (addr, field.header.length); +return (size_t )field.header.length; + } +return 0 ; +} + +/* This goes at the beginning of every SMBIOS structure. */ +struct smbios_structure_header { +u8 type; +u8 length; +u16 handle; +}PACKED ; + +int qemu_cfg_smbios_load_external (int type,char **p,unsigned *nr_structs, +unsigned *max_struct_size,char *end) +{ +static u64 used_bitmap[4 ] = {0 }; +char *start = *p; +int i; + +/* Check if we've already reported these tables */ +if (used_bitmap[(type >>6 ) &0x3 ] & (1ULL << (type &0x3f ))) +return 1 ; + +/* Don't introduce spurious end markers */ +if (type ==127 ) +return 0 ; + +for (i =qemu_cfg_smbios_entries (); i >0 ; i--) { +struct smbios_table table; +struct smbios_structure_header *header = (void *)*p; +int string; + +qemu_cfg_read ((u8 *)&table,sizeof (struct smbios_header )); + table.header.length -=sizeof (struct smbios_header ); + +if (table.header.type !=SMBIOS_TABLE_ENTRY ) { +qemu_cfg_skip (table.header.length); +continue ; + } + +if (end - *p <sizeof (struct smbios_structure_header )) { +dprintf (1 ,"No more memory for additional smbios tables\n" ); +break ; + } + +qemu_cfg_read ((u8 *)*p,sizeof (struct smbios_structure_header )); + table.header.length -=sizeof (struct smbios_structure_header ); + +if (header->type != type) { +qemu_cfg_skip (table.header.length); +continue ; + } + + *p +=sizeof (struct smbios_structure_header ); + +/* Entries end with a double NULL char, if there's a string at +* the end (length is greater than formatted length), the string +* terminator provides the first NULL. */ + string = header->length < table.header.length + +sizeof (struct smbios_structure_header ); + +/* Read the rest and terminate the entry */ +if (end - *p < table.header.length) { +dprintf (1 ,"No memory for smbios table %d\n" , header->type); + *p -=sizeof (struct smbios_structure_header ); +continue ; + } +qemu_cfg_read ((u8 *)*p, table.header.length); + *p += table.header.length; + *((u8 *)*p) =0 ; + (*p)++; +if (!string) { + *((u8 *)*p) =0 ; + (*p)++; + } + + (*nr_structs)++; +if (*p - (char *)header > *max_struct_size) + *max_struct_size = *p - (char *)header; + } + +if (start != *p) { +/* Mark that we've reported on this type */ + used_bitmap[(type >>6 ) &0x3 ] |= (1ULL << (type &0x3f )); +return 1 ; + } + +return 0 ; +} +
src/paravirt.h +4 -0
@@ -43,5 +43,9 @@ void qemu_cfg_get_uuid(u8 *uuid);u16 qemu_cfg_acpi_additional_tables (void );u16 qemu_cfg_next_acpi_table_len (void );void *qemu_cfg_next_acpi_table_load (void *addr,u16 len); +u16 qemu_cfg_smbios_entries (void ); +size_t qemu_cfg_smbios_load_field (int type,size_t offset,void *addr); +int qemu_cfg_smbios_load_external (int type,char **p,unsigned *nr_structs, +unsigned *max_struct_size,char *end);#endif
src/smbios.c +111 -71
296 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 9/21 Use preprocessor for pci link routing.
In reply to Gleb NatapovQemu pcbios commit 297a5cd68d2883215571634b2f8c627364c87f2c
--- src/acpi-dsdt.dsl | 50 +++++++++++++++----------------------------------- 1 files changed, 15 insertions(+), 35 deletions(-)
src/acpi-dsdt.dsl +15 -35
@@ -47,42 +47,22 @@ DefinitionBlock ( section 6.2.8.1 */ /* Note: we provide the same info as the PCI routing table of the Bochs BIOS */ +#define prt_slot(nr, lnk0, lnk1, lnk2, lnk3) \ + Package() { nr##ffff, 0, lnk0, 0 }, \ + Package() { nr##ffff, 1, lnk1, 0 }, \ + Package() { nr##ffff, 2, lnk2, 0 }, \ + Package() { nr##ffff, 3, lnk3, 0 } - // PCI Slot 0 - Package() {0x0000ffff, 0, LNKD, 0}, - Package() {0x0000ffff, 1, LNKA, 0}, - Package() {0x0000ffff, 2, LNKB, 0}, - Package() {0x0000ffff, 3, LNKC, 0}, - - // PCI Slot 1 - Package() {0x0001ffff, 0, LNKA, 0}, - Package() {0x0001ffff, 1, LNKB, 0}, - Package() {0x0001ffff, 2, LNKC, 0}, - Package() {0x0001ffff, 3, LNKD, 0}, - - // PCI Slot 2 - Package() {0x0002ffff, 0, LNKB, 0}, - Package() {0x0002ffff, 1, LNKC, 0}, - Package() {0x0002ffff, 2, LNKD, 0}, - Package() {0x0002ffff, 3, LNKA, 0}, - - // PCI Slot 3 - Package() {0x0003ffff, 0, LNKC, 0}, - Package() {0x0003ffff, 1, LNKD, 0}, - Package() {0x0003ffff, 2, LNKA, 0}, - Package() {0x0003ffff, 3, LNKB, 0}, - - // PCI Slot 4 - Package() {0x0004ffff, 0, LNKD, 0}, - Package() {0x0004ffff, 1, LNKA, 0}, - Package() {0x0004ffff, 2, LNKB, 0}, - Package() {0x0004ffff, 3, LNKC, 0}, - - // PCI Slot 5 - Package() {0x0005ffff, 0, LNKA, 0}, - Package() {0x0005ffff, 1, LNKB, 0}, - Package() {0x0005ffff, 2, LNKC, 0}, - Package() {0x0005ffff, 3, LNKD, 0}, +#define prt_slot0(nr) prt_slot(nr, LNKD, LNKA, LNKB, LNKC) +#define prt_slot1(nr) prt_slot(nr, LNKA, LNKB, LNKC, LNKD) +#define prt_slot2(nr) prt_slot(nr, LNKB, LNKC, LNKD, LNKA) +#define prt_slot3(nr) prt_slot(nr, LNKC, LNKD, LNKA, LNKB) + prt_slot0(0x0000), + prt_slot1(0x0001), + prt_slot2(0x0002), + prt_slot3(0x0003), + prt_slot0(0x0004), + prt_slot1(0x0005), }) Name (_CRS, ResourceTemplate ()
Signature · 1 line
1.6.3.3
PATCH 10/21 Advertise pci irqs as active high in DSDT
In reply to Gleb NatapovNow that kvm emulates the ioapic polarity correctly, we must describe the polarity correctly in the acpi tables. Otherwise pci interrupts won't be delivered correctly.
Qemu pcbios commit 0c8d4b40a1eec2369c016b9be1c9175607e64a4b
--- src/acpi-dsdt.dsl | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
src/acpi-dsdt.dsl +8 -8
@@ -340,7 +340,7 @@ DefinitionBlock ( Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 1) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {3,4,5,6,7,9,10,11,12} }) Method (_STA, 0, NotSerialized)
@@ -360,7 +360,7 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {1} }) CreateWordField (PRR0, 0x01, TMP)
@@ -387,7 +387,7 @@ DefinitionBlock ( Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 2) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {3,4,5,6,7,9,10,11,12} }) Method (_STA, 0, NotSerialized)
@@ -407,7 +407,7 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {1} }) CreateWordField (PRR0, 0x01, TMP)
@@ -434,7 +434,7 @@ DefinitionBlock ( Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 3) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {3,4,5,6,7,9,10,11,12} }) Method (_STA, 0, NotSerialized)
@@ -454,7 +454,7 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {1} }) CreateWordField (PRR0, 0x01, TMP)
@@ -481,7 +481,7 @@ DefinitionBlock ( Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 4) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {3,4,5,6,7,9,10,11,12} }) Method (_STA, 0, NotSerialized)
@@ -501,7 +501,7 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveLow, Shared) + IRQ (Level, ActiveHigh, Shared) {1} }) CreateWordField (PRR0, 0x01, TMP)
Signature · 1 line
1.6.3.3
Re: [Qemu-devel] [PATCH 10/21] Advertise pci irqs as active high in DSDT
Quoted 3 lines · Gleb Natapov
Now that kvm emulates the ioapic polarity correctly, we must describe the polarity correctly in the acpi tables. Otherwise pci interrupts won't be delivered correctly.
In another thread recently, wasn't it mentioned that the in-kernel ioapic handles polarity correctly but the out-of-kernel ioapic does not yet?
-- Jamie
Re: [Qemu-devel] [PATCH 10/21] Advertise pci irqs as active high in DSDT
Quoted 9 lines · Jamie Lokier
Quoted 3 lines · Gleb Natapov
Now that kvm emulates the ioapic polarity correctly, we must describe the polarity correctly in the acpi tables. Otherwise pci interrupts won't be delivered correctly.
In another thread recently, wasn't it mentioned that the in-kernel ioapic handles polarity correctly but the out-of-kernel ioapic does not yet?
Correct and that is why out-of-kernel doesn't care about polarity. It just ignores the bit. So for in-kernel ioapic to work you need this change and it is nop for out-of-kernel one
--
Gleb.
PATCH 11/21 Restrict pci interrupts to irq 5/9/10/11
In reply to Gleb Natapovwe need to specify the pci interrupts as active high; this reduces the number of override entries we have to add.
Qemu pcbios commit 0f79abf26ff3e61dab712dbccdbc08a04619e7c0
--- src/acpi-dsdt.dsl | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
src/acpi-dsdt.dsl +4 -4
@@ -341,7 +341,7 @@ DefinitionBlock ( Name(_UID, 1) Name(_PRS, ResourceTemplate(){ IRQ (Level, ActiveHigh, Shared) - {3,4,5,6,7,9,10,11,12} + { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized) {
@@ -388,7 +388,7 @@ DefinitionBlock ( Name(_UID, 2) Name(_PRS, ResourceTemplate(){ IRQ (Level, ActiveHigh, Shared) - {3,4,5,6,7,9,10,11,12} + { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized) {
@@ -435,7 +435,7 @@ DefinitionBlock ( Name(_UID, 3) Name(_PRS, ResourceTemplate(){ IRQ (Level, ActiveHigh, Shared) - {3,4,5,6,7,9,10,11,12} + { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized) {
@@ -482,7 +482,7 @@ DefinitionBlock ( Name(_UID, 4) Name(_PRS, ResourceTemplate(){ IRQ (Level, ActiveHigh, Shared) - {3,4,5,6,7,9,10,11,12} + { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized) {
Signature · 1 line
1.6.3.3
PATCH 12/21 Use extended interrupt descriptor for pci irqs.
In reply to Gleb NatapovThis is necessary to allow freebsd to boot; freebsd chokes if a regular interrupt descriptor specifies an active high pic irq.
Qemu pcbios commit aaff1cc0ce8de3c45eec49b9b0e7624576058eda
--- src/acpi-dsdt.dsl | 56 ++++++++++++++++++++++------------------------------ 1 files changed, 24 insertions(+), 32 deletions(-)
src/acpi-dsdt.dsl +24 -32
@@ -340,7 +340,7 @@ DefinitionBlock ( Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 1) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized)
@@ -360,14 +360,14 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) {1} }) - CreateWordField (PRR0, 0x01, TMP) + CreateDWordField (PRR0, 0x05, TMP) Store (PRQ0, Local0) If (LLess (Local0, 0x80)) { - ShiftLeft (One, Local0, TMP) + Store (Local0, TMP) } Else {
@@ -377,17 +377,15 @@ DefinitionBlock ( } Method (_SRS, 1, NotSerialized) { - CreateWordField (Arg0, 0x01, TMP) - FindSetRightBit (TMP, Local0) - Decrement (Local0) - Store (Local0, PRQ0) + CreateDWordField (Arg0, 0x05, TMP) + Store (TMP, PRQ0) } } Device(LNKB){ Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 2) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized)
@@ -407,14 +405,14 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) {1} }) - CreateWordField (PRR0, 0x01, TMP) + CreateDWordField (PRR0, 0x05, TMP) Store (PRQ1, Local0) If (LLess (Local0, 0x80)) { - ShiftLeft (One, Local0, TMP) + Store (Local0, TMP) } Else {
@@ -424,17 +422,15 @@ DefinitionBlock ( } Method (_SRS, 1, NotSerialized) { - CreateWordField (Arg0, 0x01, TMP) - FindSetRightBit (TMP, Local0) - Decrement (Local0) - Store (Local0, PRQ1) + CreateDWordField (Arg0, 0x05, TMP) + Store (TMP, PRQ1) } } Device(LNKC){ Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 3) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized)
@@ -454,14 +450,14 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) {1} }) - CreateWordField (PRR0, 0x01, TMP) + CreateDWordField (PRR0, 0x05, TMP) Store (PRQ2, Local0) If (LLess (Local0, 0x80)) { - ShiftLeft (One, Local0, TMP) + Store (Local0, TMP) } Else {
@@ -471,17 +467,15 @@ DefinitionBlock ( } Method (_SRS, 1, NotSerialized) { - CreateWordField (Arg0, 0x01, TMP) - FindSetRightBit (TMP, Local0) - Decrement (Local0) - Store (Local0, PRQ2) + CreateDWordField (Arg0, 0x05, TMP) + Store (TMP, PRQ2) } } Device(LNKD){ Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link Name(_UID, 4) Name(_PRS, ResourceTemplate(){ - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) { 5, 9, 10, 11 } }) Method (_STA, 0, NotSerialized)
@@ -501,14 +495,14 @@ DefinitionBlock ( { Name (PRR0, ResourceTemplate () { - IRQ (Level, ActiveHigh, Shared) + Interrupt (, Level, ActiveHigh, Shared) {1} }) - CreateWordField (PRR0, 0x01, TMP) + CreateDWordField (PRR0, 0x05, TMP) Store (PRQ3, Local0) If (LLess (Local0, 0x80)) { - ShiftLeft (One, Local0, TMP) + Store (Local0, TMP) } Else {
@@ -518,10 +512,8 @@ DefinitionBlock ( } Method (_SRS, 1, NotSerialized) { - CreateWordField (Arg0, 0x01, TMP) - FindSetRightBit (TMP, Local0) - Decrement (Local0) - Store (Local0, PRQ3) + CreateDWordField (Arg0, 0x05, TMP) + Store (TMP, PRQ3) } } }
Signature · 1 line
1.6.3.3
PATCH 13/21 Remove irq 9 from the pci interrupt link resources.
In reply to Gleb Natapovqemu can't share isa irqs (which is how the acpi sci interrupt is implemente with the pci irqs, so remove the sci interrupt from the pci link interrupt candidate list.
Qemu pcbios commit 713939c93b9caa1a31c49211fe83525bcbee5948
--- src/acpi-dsdt.dsl | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
src/acpi-dsdt.dsl +4 -4
@@ -341,7 +341,7 @@ DefinitionBlock ( Name(_UID, 1) Name(_PRS, ResourceTemplate(){ Interrupt (, Level, ActiveHigh, Shared) - { 5, 9, 10, 11 } + { 5, 10, 11 } }) Method (_STA, 0, NotSerialized) {
@@ -386,7 +386,7 @@ DefinitionBlock ( Name(_UID, 2) Name(_PRS, ResourceTemplate(){ Interrupt (, Level, ActiveHigh, Shared) - { 5, 9, 10, 11 } + { 5, 10, 11 } }) Method (_STA, 0, NotSerialized) {
@@ -431,7 +431,7 @@ DefinitionBlock ( Name(_UID, 3) Name(_PRS, ResourceTemplate(){ Interrupt (, Level, ActiveHigh, Shared) - { 5, 9, 10, 11 } + { 5, 10, 11 } }) Method (_STA, 0, NotSerialized) {
@@ -476,7 +476,7 @@ DefinitionBlock ( Name(_UID, 4) Name(_PRS, ResourceTemplate(){ Interrupt (, Level, ActiveHigh, Shared) - { 5, 9, 10, 11 } + { 5, 10, 11 } }) Method (_STA, 0, NotSerialized) {
Signature · 1 line
1.6.3.3
PATCH 14/21 Provide gpe _L0x methods.
In reply to Gleb NatapovProvide methods for gpe blk 0, even though they do nothing atm.
Qemu pcbios commit 37c3845e38cb8ee4a98960bf1fc31563d071838d
--- src/acpi-dsdt.dsl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/acpi.c | 2 + 2 files changed, 57 insertions(+), 0 deletions(-)
src/acpi-dsdt.dsl +55 -0
@@ -543,4 +543,59 @@ DefinitionBlock ( Zero, /* reserved */ Zero /* reserved */ }) + + Scope (\_GPE) + { + Name(_HID, "ACPI0006") + + Method(_L00) { + Return(0x01) + } + Method(_L01) { + Return(0x01) + } + Method(_L02) { + Return(0x01) + } + Method(_L03) { + Return(0x01) + } + Method(_L04) { + Return(0x01) + } + Method(_L05) { + Return(0x01) + } + Method(_L06) { + Return(0x01) + } + Method(_L07) { + Return(0x01) + } + Method(_L08) { + Return(0x01) + } + Method(_L09) { + Return(0x01) + } + Method(_L0A) { + Return(0x01) + } + Method(_L0B) { + Return(0x01) + } + Method(_L0C) { + Return(0x01) + } + Method(_L0D) { + Return(0x01) + } + Method(_L0E) { + Return(0x01) + } + Method(_L0F) { + Return(0x01) + } + } + }
src/acpi.c +2 -0
@@ -272,6 +272,8 @@ build_fadt(int bdf) fadt->pm_tmr_len =4 ; fadt->plvl2_lat =cpu_to_le16 (0xfff );// C2 state not supported fadt->plvl3_lat =cpu_to_le16 (0xfff );// C3 state not supported + fadt->gpe0_blk =cpu_to_le32 (0xafe0 ); + fadt->gpe0_blk_len =4 ;/* WBINVD + PROC_C1 + PWR_BUTTON + SLP_BUTTON + FIX_RTC */ fadt->flags =cpu_to_le32 ((1 <<0 ) | (1 <<2 ) | (1 <<4 ) | (1 <<5 ) | (1 <<6 ));
Signature · 1 line
1.6.3.3
PATCH 15/21 Pci hotplug support.
In reply to Gleb NatapovQemy pcbios commit e88ec0d97b464915281d27d5714784d2215cbdef
--- src/acpi-dsdt.dsl | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 98 insertions(+), 1 deletions(-)
src/acpi-dsdt.dsl +98 -1
@@ -65,6 +65,61 @@ DefinitionBlock ( prt_slot1(0x0005), }) + OperationRegion(PCST, SystemIO, 0xae00, 0x08) + Field (PCST, DWordAcc, NoLock, WriteAsZeros) + { + PCIU, 32, + PCID, 32, + } + + OperationRegion(SEJ, SystemIO, 0xae08, 0x04) + Field (SEJ, DWordAcc, NoLock, WriteAsZeros) + { + B0EJ, 32, + } + +#define hotplug_slot(name, nr) \ + Device (S##name) { \ + Name (_ADR, nr##0000) \ + Method (_EJ0,1) { \ + Store(ShiftLeft(1, nr), B0EJ) \ + Return (0x0) \ + } \ + Name (_SUN, name) \ + } + + hotplug_slot(1, 0x0001) + hotplug_slot(2, 0x0002) + hotplug_slot(3, 0x0003) + hotplug_slot(4, 0x0004) + hotplug_slot(5, 0x0005) + hotplug_slot(6, 0x0006) + hotplug_slot(7, 0x0007) + hotplug_slot(8, 0x0008) + hotplug_slot(9, 0x0009) + hotplug_slot(10, 0x000a) + hotplug_slot(11, 0x000b) + hotplug_slot(12, 0x000c) + hotplug_slot(13, 0x000d) + hotplug_slot(14, 0x000e) + hotplug_slot(15, 0x000f) + hotplug_slot(16, 0x0010) + hotplug_slot(17, 0x0011) + hotplug_slot(18, 0x0012) + hotplug_slot(19, 0x0013) + hotplug_slot(20, 0x0014) + hotplug_slot(21, 0x0015) + hotplug_slot(22, 0x0016) + hotplug_slot(23, 0x0017) + hotplug_slot(24, 0x0018) + hotplug_slot(25, 0x0019) + hotplug_slot(26, 0x001a) + hotplug_slot(27, 0x001b) + hotplug_slot(28, 0x001c) + hotplug_slot(29, 0x001d) + hotplug_slot(30, 0x001e) + hotplug_slot(31, 0x001f) + Name (_CRS, ResourceTemplate () { WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
@@ -551,8 +606,50 @@ DefinitionBlock ( Method(_L00) { Return(0x01) } + +#define gen_pci_hotplug(nr) \ + If (And(\_SB.PCI0.PCIU, ShiftLeft(1, nr))) { \ + Notify(\_SB.PCI0.S##nr, 1) \ + } \ + If (And(\_SB.PCI0.PCID, ShiftLeft(1, nr))) { \ + Notify(\_SB.PCI0.S##nr, 3) \ + } + Method(_L01) { - Return(0x01) + gen_pci_hotplug(1) + gen_pci_hotplug(2) + gen_pci_hotplug(3) + gen_pci_hotplug(4) + gen_pci_hotplug(5) + gen_pci_hotplug(6) + gen_pci_hotplug(7) + gen_pci_hotplug(8) + gen_pci_hotplug(9) + gen_pci_hotplug(10) + gen_pci_hotplug(11) + gen_pci_hotplug(12) + gen_pci_hotplug(13) + gen_pci_hotplug(14) + gen_pci_hotplug(15) + gen_pci_hotplug(16) + gen_pci_hotplug(17) + gen_pci_hotplug(18) + gen_pci_hotplug(19) + gen_pci_hotplug(20) + gen_pci_hotplug(21) + gen_pci_hotplug(22) + gen_pci_hotplug(23) + gen_pci_hotplug(24) + gen_pci_hotplug(25) + gen_pci_hotplug(26) + gen_pci_hotplug(27) + gen_pci_hotplug(28) + gen_pci_hotplug(29) + gen_pci_hotplug(30) + gen_pci_hotplug(31) + + Return (0x01) + } Method(_L02) { Return(0x01)
Signature · 1 line
1.6.3.3
PATCH 16/21 HPET support.
In reply to Gleb NatapovPart of qemu pcbios commit e04da91178f0e11febbbd61d9795e49cc27e9ad4
--- src/acpi-dsdt.dsl | 19 +++++++++++++++++++ src/acpi.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 0 deletions(-)
src/acpi-dsdt.dsl +19 -0
@@ -165,6 +165,25 @@ DefinitionBlock ( ,, , AddressRangeMemory, TypeStatic) }) } + + Device(HPET) { + Name(_HID, EISAID("PNP0103")) + Name(_UID, 0) + Method (_STA, 0, NotSerialized) { + Return(0x0F) + } + Name(_CRS, ResourceTemplate() { + DWordMemory( + ResourceConsumer, PosDecode, MinFixed, MaxFixed, + NonCacheable, ReadWrite, + 0x00000000, + 0xFED00000, + 0xFED003FF, + 0x00000000, + 0x00000400 /* 1K memory: FED00000 - FED003FF */ + ) + }) + } } Scope(\_SB.PCI0) {
src/acpi.c +46 -0
64 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 17/21 Add 26 pci slots, bringing the total to 32.
In reply to Gleb NatapovLack of pci slots causes Windows to complain when installing too many device.
Qemu pcbios commit 001fd46e3b551de05c62590ba5ed4cbf6cbe3510
--- src/acpi-dsdt.dsl | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
src/acpi-dsdt.dsl +26 -0
@@ -63,6 +63,32 @@ DefinitionBlock ( prt_slot3(0x0003), prt_slot0(0x0004), prt_slot1(0x0005), + prt_slot2(0x0006), + prt_slot3(0x0007), + prt_slot0(0x0008), + prt_slot1(0x0009), + prt_slot2(0x000a), + prt_slot3(0x000b), + prt_slot0(0x000c), + prt_slot1(0x000d), + prt_slot2(0x000e), + prt_slot3(0x000f), + prt_slot0(0x0010), + prt_slot1(0x0011), + prt_slot2(0x0012), + prt_slot3(0x0013), + prt_slot0(0x0014), + prt_slot1(0x0015), + prt_slot2(0x0016), + prt_slot3(0x0017), + prt_slot0(0x0018), + prt_slot1(0x0019), + prt_slot2(0x001a), + prt_slot3(0x001b), + prt_slot0(0x001c), + prt_slot1(0x001d), + prt_slot2(0x001e), + prt_slot3(0x001f), }) OperationRegion(PCST, SystemIO, 0xae00, 0x08)
Signature · 1 line
1.6.3.3
PATCH 18/21 Add SRAT ACPI table support.
In reply to Gleb NatapovTake NUMA topology info from the QEMU firmware configuration interface (number of nodes, node for each (V)CPU and amount of memory) and build a SRAT table describing this topology for the guest OS. Handles more than 4 GB of RAM by including a hole for 32bit PCI memory mapping.
Qemu pcbios commit 444f1226c11082d374b7e1361c6f5696e479642a
--- src/acpi.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/paravirt.c | 16 ++++++ src/paravirt.h | 2 + 3 files changed, 170 insertions(+), 5 deletions(-)
src/acpi.c +152 -5
@@ -151,7 +151,7 @@ struct multiple_apic_table }PACKED ; -/* Values for Type in APIC_HEADER_DEF */ +/* Values for Type in APIC sub-headers */ #define APIC_PROCESSOR 0#define APIC_IO 1
@@ -167,7 +167,7 @@ struct multiple_apic_table/* * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE) */ -#define APIC_HEADER_DEF /* Common APIC sub-structure header */ \ +#define ACPI_SUB_HEADER_DEF /* Common ACPI sub-structure header */ \ u8 type; \ u8 length;
@@ -175,7 +175,7 @@ struct multiple_apic_tablestruct madt_processor_apic { -APIC_HEADER_DEF +ACPI_SUB_HEADER_DEF u8 processor_id; /* ACPI processor id */u8 local_apic_id;/* Processor's local APIC id */ #if 0
@@ -188,7 +188,7 @@ struct madt_processor_apicstruct madt_io_apic { -APIC_HEADER_DEF +ACPI_SUB_HEADER_DEF u8 io_apic_id; /* I/O APIC ID */u8 reserved;/* Reserved - must be zero */ u32 address;/* APIC physical address */
@@ -199,7 +199,7 @@ struct madt_io_apic#define PCI_ISA_IRQ_MASK 0x0e20struct madt_intsrcovr { -APIC_HEADER_DEF +ACPI_SUB_HEADER_DEF u8 bus;u8 source;u32 gsi;
@@ -230,6 +230,43 @@ struct acpi_20_hpet { }PACKED ;#define ACPI_HPET_ADDRESS 0xFED00000UL +/* +* SRAT (NUMA topology description) table +*/ + +#define SRAT_PROCESSOR 0 +#define SRAT_MEMORY 1 + +struct system_resource_affinity_table +{ +ACPI_TABLE_HEADER_DEF + u32 reserved1; +u32 reserved2[2 ]; +}PACKED ; + +struct srat_processor_affinity +{ +ACPI_SUB_HEADER_DEF + u8 proximity_lo; +u8 local_apic_id; +u32 flags; +u8 local_sapic_eid; +u8 proximity_hi[3 ]; +u32 reserved; +}PACKED ; + +struct srat_memory_affinity +{ +ACPI_SUB_HEADER_DEF + u8 proximity[4]; +u16 reserved1; +u32 base_addr_low,base_addr_high; +u32 length_low,length_high; +u32 reserved2; +u32 flags; +u32 reserved3[2 ]; +}PACKED ; +#include "acpi-dsdt.hex" static inline u16 cpu_to_le16 (u16 x)
@@ -447,6 +484,115 @@ build_hpet(void)return hpet; } +static void +acpi_build_srat_memory (struct srat_memory_affinity *numamem, +u64 base,u64 len,int node,int enabled) +{ + numamem->type =SRAT_MEMORY ; + numamem->length =sizeof (*numamem); +memset (numamem->proximity,0 ,4 ); + numamem->proximity[0 ] = node; + numamem->flags =cpu_to_le32 (!!enabled); + numamem->base_addr_low = base &0xFFFFFFFF ; + numamem->base_addr_high = base >>32 ; + numamem->length_low = len &0xFFFFFFFF ; + numamem->length_high = len >>32 ; +} + +#define SRAT_SIGNATURE 0x54415253 //HPET +static void * +build_srat (void ) +{ +int nb_numa_nodes =qemu_cfg_get_numa_nodes (); + +if (nb_numa_nodes ==0 ) +return NULL ; + +u64 *numadata =malloc_tmphigh (sizeof (u64) * (CountCPUs + nb_numa_nodes)); +if (!numadata) { +dprintf (1 ,"Not enough memory for read numa data from VM!\n" ); +return NULL ; + } + +qemu_cfg_get_numa_data (numadata, CountCPUs + nb_numa_nodes); + +struct system_resource_affinity_table *srat; +int srat_size =sizeof (*srat) + +sizeof (struct srat_processor_affinity ) * CountCPUs + +sizeof (struct srat_memory_affinity ) * (nb_numa_nodes +2 ); + + srat =malloc_high (srat_size); +if (!srat) { +dprintf (1 ,"Not enough memory for srat table!\n" ); +return NULL ; + } + +memset (srat,0 , srat_size); + srat->reserved1=1 ; +struct srat_processor_affinity *core = (void *)(srat +1 ); +int i; +u64 curnode; + +for (i =0 ; i < CountCPUs; ++i) { + core->type =SRAT_PROCESSOR ; + core->length =sizeof (*core); + core->local_apic_id = i; + curnode = *numadata++; + core->proximity_lo = curnode; +memset (core->proximity_hi,0 ,3 ); + core->local_sapic_eid =0 ; +if (i < CountCPUs) + core->flags =cpu_to_le32 (1 ); +else + core->flags =0 ; + core++; + } + + +/* the memory map is a bit tricky, it contains at least one hole +* from 640k-1M and possibly another one from 3.5G-4G. +*/ +struct srat_memory_affinity *numamem = (void *)core; +int slots =0 ; +u64 mem_len, mem_base, next_base =0 ; + +acpi_build_srat_memory (numamem,0 ,640 *1024 ,0 ,1 ); + next_base =1024 *1024 ; + numamem++; + slots++; +for (i =1 ; i < nb_numa_nodes +1 ; ++i) { + mem_base = next_base; + mem_len = *numadata++; +if (i ==1 ) + mem_len -=1024 *1024 ; + next_base = mem_base + mem_len; + +/* Cut out the PCI hole */ +if (mem_base <= RamSize && next_base > RamSize) { + mem_len -= next_base - RamSize; +if (mem_len >0 ) { +acpi_build_srat_memory (numamem, mem_base, mem_len, i-1 ,1 ); + numamem++; + slots++; + } + mem_base =1ULL <<32 ; + mem_len = next_base - RamSize; + next_base += (1ULL <<32 ) - RamSize; + } +acpi_build_srat_memory (numamem, mem_base, mem_len, i-1 ,1 ); + numamem++; + slots++; + } +for (; slots < nb_numa_nodes +2 ; slots++) { +acpi_build_srat_memory (numamem,0 ,0 ,0 ,0 ); + numamem++; + } + +build_header ((void *)srat,SRAT_SIGNATURE , srat_size,1 ); + +return srat; +} +struct rsdp_descriptor *RsdpAddr;#define MAX_ACPI_TABLES 20
@@ -486,6 +632,7 @@ acpi_bios_init(void)ACPI_INIT_TABLE (build_ssdt ());ACPI_INIT_TABLE (build_madt ());ACPI_INIT_TABLE (build_hpet ()); +ACPI_INIT_TABLE (build_srat ());u16 i, external_tables =qemu_cfg_acpi_additional_tables ();
src/paravirt.c +16 -0
@@ -265,3 +265,19 @@ int qemu_cfg_smbios_load_external(int type, char **p, unsigned *nr_structs,return 0 ; } +int qemu_cfg_get_numa_nodes (void ) +{ +u64 cnt; + +qemu_cfg_read_entry (&cnt,QEMU_CFG_NUMA ,sizeof (cnt)); + +return (int )cnt; +} + +void qemu_cfg_get_numa_data (u64 *data,int n) +{ +int i; + +for (i =0 ; i < n; i++) +qemu_cfg_read ((u8 *)(data + i),sizeof (u64)); +}
src/paravirt.h +2 -0
@@ -49,5 +49,7 @@ u16 qemu_cfg_smbios_entries(void);size_t qemu_cfg_smbios_load_field (int type,size_t offset,void *addr);int qemu_cfg_smbios_load_external (int type,char **p,unsigned *nr_structs,unsigned *max_struct_size,char *end); +int qemu_cfg_get_numa_nodes (void ); +void qemu_cfg_get_numa_data (u64 *data,int n);#endif
Signature · 1 line
1.6.3.3
PATCH 19/21 Read max number of cpus from VM.
In reply to Gleb Natapov--- src/paravirt.c | 12 ++++++++++++ src/paravirt.h | 1 + src/smp.c | 9 ++++++++- src/util.h | 1 + 4 files changed, 22 insertions(+), 1 deletions(-)
src/paravirt.c +12 -0
@@ -281,3 +281,15 @@ void qemu_cfg_get_numa_data(u64 *data, int n)for (i =0 ; i < n; i++)qemu_cfg_read ((u8 *)(data + i),sizeof (u64)); } + +u16 qemu_cfg_get_max_cpus (void ) +{ +u16 cnt; + +if (!qemu_cfg_present) +return 0 ; + +qemu_cfg_read_entry (&cnt,QEMU_CFG_MAX_CPUS ,sizeof (cnt)); + +return cnt; +}
src/paravirt.h +1 -0
@@ -51,5 +51,6 @@ int qemu_cfg_smbios_load_external(int type, char **p, unsigned *nr_structs, unsigned *max_struct_size, char *end);int qemu_cfg_get_numa_nodes (void );void qemu_cfg_get_numa_data (u64 *data,int n); +u16 qemu_cfg_get_max_cpus (void );#endif
src/smp.c +8 -1
@@ -9,6 +9,7 @@#include "config.h" // CONFIG_* #include "cmos.h" // CMOS_BIOS_SMP_COUNT #include "farptr.h" // ASSERT32 +#include "paravirt.h" #define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300)#define APIC_SVR ((u8*)BUILD_APIC_ADDR + 0x0F0)
@@ -61,6 +62,7 @@ wrmsr_smp(u32 index, u64 val) } u32 CountCPUs VAR16VISIBLE; +u32 MaxCountCPUs VAR16VISIBLE;extern void smp_ap_boot_code ();ASM16 ( " .global smp_ap_boot_code\n"
@@ -134,7 +136,12 @@ smp_probe(void)// Restore memory. *(u64 *)BUILD_AP_BOOT_ADDR = old; -dprintf (1 ,"Found %d cpu(s)\n" ,readl (&CountCPUs)); + MaxCountCPUs =qemu_cfg_get_max_cpus (); +if (!MaxCountCPUs || MaxCountCPUs < CountCPUs) + MaxCountCPUs = CountCPUs; + +dprintf (1 ,"Found %d cpu(s) max supported %d cpu(s)\n" ,readl (&CountCPUs), + MaxCountCPUs); }// Reset variables to zero
src/util.h +1 -0
@@ -221,6 +221,7 @@ void smm_init();// smp.c extern u32 CountCPUs; +extern u32 MaxCountCPUs;void wrmsr_smp (u32 index,u64 val);void smp_probe (void );void smp_probe_setup (void );
Signature · 1 line
1.6.3.3
PATCH 20/21 Move qemu cfg init before smp init.
In reply to Gleb NatapovWe will need to read qemu config during smp init.
--- src/post.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
src/post.c +2 -2
@@ -161,6 +161,8 @@ post()init_ivt ();init_bda (); +qemu_cfg_port_probe (); +pic_setup ();timer_setup ();mathcp_setup ();
@@ -185,8 +187,6 @@ post()serial_setup ();mouse_setup (); -qemu_cfg_port_probe (); -init_bios_tables ();boot_setup ();
Signature · 1 line
1.6.3.3
[Qemu-devel] Re: [PATCH 20/21] Move qemu cfg init before smp init.
Quoted 3 lines · Gleb Natapov
We will need to read qemu config during smp init.
Signed-off-by Gleb Natapov <[email protected]>
Thanks! I applied patches 1 - 20.
-Kevin
PATCH 21/21 Use MaxCountCPUs during building of per cpu tables.
In reply to Gleb NatapovPreparation for hot pluggable CPUs.
--- src/acpi.c | 23 ++++++++++++----------- src/config.h | 4 ++-- src/mptable.c | 18 ++++++++++-------- src/smbios.c | 4 ++-- 4 files changed, 26 insertions(+), 23 deletions(-)
src/acpi.c +12 -11
@@ -346,9 +346,8 @@ build_fadt(int bdf)static void *build_madt (void ) { -int smp_cpus = CountCPUs;int madt_size = (sizeof (struct multiple_apic_table ) - +sizeof (struct madt_processor_apic ) * smp_cpus + +sizeof (struct madt_processor_apic ) * MaxCountCPUs +sizeof (struct madt_io_apic ) +sizeof (struct madt_intsrcovr ) *16 );struct multiple_apic_table *madt =malloc_high (madt_size);
@@ -361,18 +360,21 @@ build_madt(void) madt->flags =cpu_to_le32 (1 );struct madt_processor_apic *apic = (void *)&madt[1 ];int i; -for (i=0 ; i<smp_cpus; i++) { +for (i=0 ; i<MaxCountCPUs; i++) { apic->type =APIC_PROCESSOR ; apic->length =sizeof (*apic); apic->processor_id = i; apic->local_apic_id = i; - apic->flags =cpu_to_le32 (1 ); +if (i < CountCPUs) + apic->flags =cpu_to_le32 (1 ); +else + apic->flags =cpu_to_le32 (0 ); apic++; }struct madt_io_apic *io_apic = (void *)apic; io_apic->type =APIC_IO ; io_apic->length =sizeof (*io_apic); - io_apic->io_apic_id = smp_cpus; + io_apic->io_apic_id = CountCPUs; io_apic->address =cpu_to_le32 (BUILD_IOAPIC_ADDR ); io_apic->interrupt =cpu_to_le32 (0 );
@@ -407,8 +409,7 @@ build_madt(void)static void *build_ssdt (void ) { -int smp_cpus = CountCPUs; -int acpi_cpus = smp_cpus >0xff ?0xff : smp_cpus; +int acpi_cpus = MaxCountCPUs >0xff ?0xff : MaxCountCPUs;// calculate the length of processor block and scope block // excluding PkgLength int cpu_length =13 * acpi_cpus +4 ;
@@ -508,17 +509,17 @@ build_srat(void)if (nb_numa_nodes ==0 )return NULL ; -u64 *numadata =malloc_tmphigh (sizeof (u64) * (CountCPUs + nb_numa_nodes)); +u64 *numadata =malloc_tmphigh (sizeof (u64) * (MaxCountCPUs + nb_numa_nodes));if (!numadata) {dprintf (1 ,"Not enough memory for read numa data from VM!\n" );return NULL ; } -qemu_cfg_get_numa_data (numadata, CountCPUs + nb_numa_nodes); +qemu_cfg_get_numa_data (numadata, MaxCountCPUs + nb_numa_nodes);struct system_resource_affinity_table *srat;int srat_size =sizeof (*srat) + -sizeof (struct srat_processor_affinity ) * CountCPUs + +sizeof (struct srat_processor_affinity ) * MaxCountCPUs +sizeof (struct srat_memory_affinity ) * (nb_numa_nodes +2 ); srat =malloc_high (srat_size);
@@ -533,7 +534,7 @@ build_srat(void)int i;u64 curnode; -for (i =0 ; i < CountCPUs; ++i) { +for (i =0 ; i < MaxCountCPUs; ++i) { core->type =SRAT_PROCESSOR ; core->length =sizeof (*core); core->local_apic_id = i;
src/config.h +2 -2
@@ -16,9 +16,9 @@#define CONFIG_COREBOOT 0// Control how verbose debug output is. -#define CONFIG_DEBUG_LEVEL 1 +#define CONFIG_DEBUG_LEVEL 2// Send debugging information to serial port -#define CONFIG_DEBUG_SERIAL 0 +#define CONFIG_DEBUG_SERIAL 1// Screen writes are also sent to debug ports. #define CONFIG_SCREEN_AND_DEBUG 1
src/mptable.c +10 -8
@@ -18,13 +18,12 @@ mptable_init(void)dprintf (3 ,"init MPTable\n" ); -int smp_cpus = CountCPUs; -if (smp_cpus <=1 ) +if (MaxCountCPUs <=1 )// Building an mptable on uniprocessor machines confuses some OSes. return ;int length = (sizeof (struct mptable_config_s ) - +sizeof (struct mpt_cpu ) * smp_cpus + +sizeof (struct mpt_cpu ) * MaxCountCPUs +sizeof (struct mpt_bus ) +sizeof (struct mpt_ioapic ) +sizeof (struct mpt_intsrc ) *16 );
@@ -49,7 +48,7 @@ mptable_init(void) config->spec =4 ;memcpy (config->oemid,CONFIG_CPUNAME8 ,sizeof (config->oemid));memcpy (config->productid,"0.1 " ,sizeof (config->productid)); - config->entrycount = smp_cpus +2 +16 ; + config->entrycount = MaxCountCPUs +2 +16 ; config->lapic =BUILD_APIC_ADDR ;// CPU definitions.
@@ -57,14 +56,17 @@ mptable_init(void)cpuid (1 , &cpuid_signature, &ebx, &ecx, &cpuid_features);struct mpt_cpu *cpus = (void *)&config[1 ];int i; -for (i =0 ; i < smp_cpus; i++) { +for (i =0 ; i < MaxCountCPUs; i++) {struct mpt_cpu *cpu = &cpus[i];memset (cpu,0 ,sizeof (*cpu)); cpu->type =MPT_TYPE_CPU ; cpu->apicid = i; cpu->apicver =0x11 ;/* cpu flags: enabled, bootstrap cpu */ - cpu->cpuflag = (i ==0 ?3 :1 ); +if (i < CountCPUs) + cpu->cpuflag =1 | (i ==0 ) ?2 :0 ; +else + cpu->cpuflag =0 ;if (cpuid_signature) { cpu->cpusignature = cpuid_signature; cpu->featureflag = cpuid_features;
@@ -75,13 +77,13 @@ mptable_init(void) }/* isa bus */ -struct mpt_bus *bus = (void *)&cpus[smp_cpus]; +struct mpt_bus *bus = (void *)&cpus[MaxCountCPUs];memset (bus,0 ,sizeof (*bus)); bus->type =MPT_TYPE_BUS ;memcpy (bus->bustype,"ISA " ,sizeof (bus->bustype));/* ioapic */ -u8 ioapic_id = smp_cpus; +u8 ioapic_id = CountCPUs;struct mpt_ioapic *ioapic = (void *)&bus[1 ];memset (ioapic,0 ,sizeof (*ioapic)); ioapic->type =MPT_TYPE_IOAPIC ;
src/smbios.c +2 -2
@@ -560,8 +560,8 @@ smbios_init(void)add_struct (1 , p);add_struct (3 , p); -int cpu_num, smp_cpus = CountCPUs; -for (cpu_num =1 ; cpu_num <= smp_cpus; cpu_num++) +int cpu_num; +for (cpu_num =1 ; cpu_num <= MaxCountCPUs; cpu_num++)add_struct (4 , p, cpu_num);u64 memsize = RamSizeOver4G;if (memsize)
Signature · 1 line
1.6.3.3
[Qemu-devel] Re: [PATCH 21/21] Use MaxCountCPUs during building of per cpu tables.
Quoted 3 lines · Gleb Natapov
Preparation for hot pluggable CPUs.
Signed-off-by Gleb Natapov <[email protected]>
Thanks - this patch looks like it is pulling in unrelated changes to config.h:
Quoted 4 lines
src/config.h +0
-0@@ -16,9 +16,9 @@#define CONFIG_COREBOOT 0
src/config.h line 24
Quoted 10 lines
src/config.h +2
-2// Control how verbose debug output is. -#define CONFIG_DEBUG_LEVEL 1 +#define CONFIG_DEBUG_LEVEL 2// Send debugging information to serial port -#define CONFIG_DEBUG_SERIAL 0 +#define CONFIG_DEBUG_SERIAL 1// Screen writes are also sent to debug ports. #define CONFIG_SCREEN_AND_DEBUG 1
Otherwise, it looks okay to me.
-Kevin
[Qemu-devel] Re: [PATCH 21/21] Use MaxCountCPUs during building of per cpu tables.
Quoted 13 lines · Kevin O'Connor
Quoted 3 lines · Gleb Natapov
Preparation for hot pluggable CPUs.
Signed-off-by Gleb Natapov <[email protected]>Thanks - this patch looks like it is pulling in unrelated changes to
config.h:Quoted 5 lines
src/config.h +0
-0@@ -16,9 +16,9 @@#define CONFIG_COREBOOT 0
Quoted 12 lines
src/config.h line 24
Quoted 9 lines
src/config.h +2
-2// Control how verbose debug output is. -#define CONFIG_DEBUG_LEVEL 1 +#define CONFIG_DEBUG_LEVEL 2// Send debugging information to serial port -#define CONFIG_DEBUG_SERIAL 0 +#define CONFIG_DEBUG_SERIAL 1// Screen writes are also sent to debug ports. #define CONFIG_SCREEN_AND_DEBUG 1Otherwise, it looks okay to me.
This is once more by accident. Can you drop them and apply please.
Quoted 1 line
-Kevin
--
Gleb.
[Qemu-devel] Re: [PATCH 21/21] Use MaxCountCPUs during building of per cpu tables.
Quoted 9 lines · Gleb Natapov
Quoted 7 lines · Kevin O'Connor
Quoted 3 lines · Gleb Natapov
Preparation for hot pluggable CPUs.
Signed-off-by Gleb Natapov <[email protected]>Thanks - this patch looks like it is pulling in unrelated changes to
config.h:This is once more by accident. Can you drop them and apply please.
Okay - it's commit a26df9bd7c8dc3a901994be17ec067abb87c2f1a
Thanks,
-Kevin