hvmloader: don't hard-code IO-APIC parameters
PATCH v2 1/1 hvmloader: don't hard-code IO-APIC parameters
The IO-APIC address has variable bits determined by the PCI-to-ISA bridge (albeit for now we refrain from actually evaluating them, as there's still implicit rather than explicit agreement on the IO-APIC base address between qemu and the hypervisor), and the IO-APIC version should be read from the IO-APIC.
---
v2: Comment out ioapic_base_address adjustment for now (see comment
in apic_setup()).
tools/firmware/hvmloader/acpi/build.c +1 -1
@@ -137,7 +137,7 @@ static struct acpi_20_madt *construct_ma io_apic->type =ACPI_IO_APIC ; io_apic->length =sizeof (*io_apic); io_apic->ioapic_id =IOAPIC_ID ; - io_apic->ioapic_addr =IOAPIC_BASE_ADDRESS ; + io_apic->ioapic_addr = ioapic_base_address; lapic = (struct acpi_20_madt_lapic *)(io_apic +1 ); info->nr_cpus = hvm_info->nr_vcpus;
tools/firmware/hvmloader/config.h +3 -2
@@ -42,9 +42,10 @@ extern struct bios_config ovmf_config;#define PAGE_SHIFT 12#define PAGE_SIZE (1ul << PAGE_SHIFT) -#define IOAPIC_BASE_ADDRESS 0xfec00000 +extern uint32_t ioapic_base_address; +extern uint8_t ioapic_version; +#define IOAPIC_ID 0x01 -#define IOAPIC_VERSION 0x11#define LAPIC_BASE_ADDRESS 0xfee00000#define LAPIC_ID (vcpu_id) ((vcpu_id) * 2)
tools/firmware/hvmloader/hvmloader.c +11 -0
@@ -108,6 +108,9 @@ asm (unsigned long scratch_start =SCRATCH_PHYSICAL_ADDRESS ; +uint32_t ioapic_base_address =0xfec00000 ; +uint8_t ioapic_version; +static void init_hypercalls (void ) {uint32_t eax, ebx, ecx, edx;
@@ -185,6 +188,14 @@ static void init_vm86_tss(void)static void apic_setup (void ) { +/* +* This would the The Right Thing To Do (tm), if only qemu +* negotiated with Xen where the IO-APIC actually sits. Uncomment +* this code once that is the case. +ioapic_base_address |= (pci_readb(PCI_ISA_DEVFN, 0x80) & 0x3f) << 10; +*/ + ioapic_version =ioapic_read (0x01 ) &0xff ; +/* Set the IOAPIC ID to the static value used in the MP/ACPI tables. */ ioapic_write (0x00 ,IOAPIC_ID );
tools/firmware/hvmloader/mp_tables.c +2 -2
@@ -227,9 +227,9 @@ static void fill_mp_ioapic_entry(struct { mpie->type =ENTRY_TYPE_IOAPIC ; mpie->ioapic_id =IOAPIC_ID ; - mpie->ioapic_version =IOAPIC_VERSION ; + mpie->ioapic_version = ioapic_version; mpie->ioapic_flags =1 ;/* enabled */ - mpie->ioapic_addr =IOAPIC_BASE_ADDRESS ; + mpie->ioapic_addr = ioapic_base_address; }
tools/firmware/hvmloader/util.c +4 -4
@@ -490,14 +490,14 @@ void *scratch_alloc(uint32_t size, uint3uint32_t ioapic_read (uint32_t reg) { - *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x00 ) = reg; -return *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x10 ); + *(volatile uint32_t *)(ioapic_base_address +0x00 ) = reg; +return *(volatile uint32_t *)(ioapic_base_address +0x10 ); }void ioapic_write (uint32_t reg,uint32_t val) { - *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x00 ) = reg; - *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x10 ) = val; + *(volatile uint32_t *)(ioapic_base_address +0x00 ) = reg; + *(volatile uint32_t *)(ioapic_base_address +0x10 ) = val; }uint32_t lapic_read (uint32_t reg)
hvmloader: don't hard-code IO-APIC parameters
The IO-APIC address has variable bits determined by the PCI-to-ISA bridge (albeit for now we refrain from actually evaluating them, as there's still implicit rather than explicit agreement on the IO-APIC base address between qemu and the hypervisor), and the IO-APIC version should be read from the IO-APIC.
---
v2: Comment out ioapic_base_address adjustment for now (see comment
in apic_setup()).
tools/firmware/hvmloader/acpi/build.c +1 -1
@@ -137,7 +137,7 @@ static struct acpi_20_madt *construct_ma io_apic->type =ACPI_IO_APIC ; io_apic->length =sizeof (*io_apic); io_apic->ioapic_id =IOAPIC_ID ; - io_apic->ioapic_addr =IOAPIC_BASE_ADDRESS ; + io_apic->ioapic_addr = ioapic_base_address; lapic = (struct acpi_20_madt_lapic *)(io_apic +1 ); info->nr_cpus = hvm_info->nr_vcpus;
tools/firmware/hvmloader/config.h +3 -2
@@ -42,9 +42,10 @@ extern struct bios_config ovmf_config;#define PAGE_SHIFT 12#define PAGE_SIZE (1ul << PAGE_SHIFT) -#define IOAPIC_BASE_ADDRESS 0xfec00000 +extern uint32_t ioapic_base_address; +extern uint8_t ioapic_version; +#define IOAPIC_ID 0x01 -#define IOAPIC_VERSION 0x11#define LAPIC_BASE_ADDRESS 0xfee00000#define LAPIC_ID (vcpu_id) ((vcpu_id) * 2)
tools/firmware/hvmloader/hvmloader.c +11 -0
@@ -108,6 +108,9 @@ asm (unsigned long scratch_start =SCRATCH_PHYSICAL_ADDRESS ; +uint32_t ioapic_base_address =0xfec00000 ; +uint8_t ioapic_version; +static void init_hypercalls (void ) {uint32_t eax, ebx, ecx, edx;
@@ -185,6 +188,14 @@ static void init_vm86_tss(void)static void apic_setup (void ) { +/* +* This would the The Right Thing To Do (tm), if only qemu +* negotiated with Xen where the IO-APIC actually sits. Uncomment +* this code once that is the case. +ioapic_base_address |= (pci_readb(PCI_ISA_DEVFN, 0x80) & 0x3f) << 10; +*/ + ioapic_version =ioapic_read (0x01 ) &0xff ; +/* Set the IOAPIC ID to the static value used in the MP/ACPI tables. */ ioapic_write (0x00 ,IOAPIC_ID );
tools/firmware/hvmloader/mp_tables.c +2 -2
@@ -227,9 +227,9 @@ static void fill_mp_ioapic_entry(struct { mpie->type =ENTRY_TYPE_IOAPIC ; mpie->ioapic_id =IOAPIC_ID ; - mpie->ioapic_version =IOAPIC_VERSION ; + mpie->ioapic_version = ioapic_version; mpie->ioapic_flags =1 ;/* enabled */ - mpie->ioapic_addr =IOAPIC_BASE_ADDRESS ; + mpie->ioapic_addr = ioapic_base_address; }
tools/firmware/hvmloader/util.c +4 -4
@@ -490,14 +490,14 @@ void *scratch_alloc(uint32_t size, uint3uint32_t ioapic_read (uint32_t reg) { - *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x00 ) = reg; -return *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x10 ); + *(volatile uint32_t *)(ioapic_base_address +0x00 ) = reg; +return *(volatile uint32_t *)(ioapic_base_address +0x10 ); }void ioapic_write (uint32_t reg,uint32_t val) { - *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x00 ) = reg; - *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x10 ) = val; + *(volatile uint32_t *)(ioapic_base_address +0x00 ) = reg; + *(volatile uint32_t *)(ioapic_base_address +0x10 ) = val; }uint32_t lapic_read (uint32_t reg)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
tools/firmware/hvmloader/hvmloader.c static void init_vm86_tss(void) · line 194
Quoted 8 lines · Jan Beulich
tools/firmware/hvmloader/hvmloader.c +4
-0@@ -185,6 +188,14 @@ static void init_vm86_tss(void)static void apic_setup (void ) { +/* +* This would the The Right Thing To Do (tm), if only qemu +* negotiated with Xen where the IO-APIC actually sits. Uncomment +* this code once that is the case.
I would possibly extend the text with "This is currently hard coded in Xen and can't be controlled externally."
Either way, Reviewed-by: Andrew Cooper <[email protected]>
tools/firmware/hvmloader/hvmloader.c static void init_vm86_tss(void) · line 201
Quoted 7 lines
tools/firmware/hvmloader/hvmloader.c +4
-0+ioapic_base_address |= (pci_readb(PCI_ISA_DEVFN, 0x80) & 0x3f) << 10; +*/ + ioapic_version =ioapic_read (0x01 ) &0xff ; +/* Set the IOAPIC ID to the static value used in the MP/ACPI tables. */ ioapic_write (0x00 ,IOAPIC_ID );
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel