This series exports the MADT (APIC) ACPI table under the new "etc/acpi/APIC" fw_cfg file. I sought to follow the requirements set forth in [1], the new table is only visible in the patched/patched case. I cross-tested { master, patched } qemu with { master, patched } seabios (the APIC, DSDT and RSDT tables) using guest acpidump and dmesg.
The -acpitable command line option is purposely ignored based on the last paragraph of [2]; the user isn't supposed to pass APIC with that option.
checkpatch.pl complains a little but (as last time) it's a false alarm.
The series is bisectable.
[1] http://thread.gmane.org/gmane.comp.emulators.qemu/202005/focus=202072 [2] http://thread.gmane.org/gmane.comp.bios.coreboot.seabios/5960/focus=6008
Laszlo Ersek (5): refer to FWCfgState explicitly hw/acpi: extract standard table headers as a standalone structure hw/acpi: export default ACPI headers using the type just introduced hw/acpi: export acpi_checksum() i386/pc: build ACPI MADT (APIC) for fw_cfg clients
hw/acpi.h | 15 +++++ hw/loader.h | 3 +- hw/multiboot.h | 4 +- hw/pc.h | 20 ++++--- hw/acpi.c | 89 ++++++++++++++------------- hw/acpi_piix4.c | 2 +- hw/i386/multiboot.c | 2 +- hw/i386/pc.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++---- hw/i386/pc_piix.c | 4 +- hw/i386/pc_q35.c | 10 ++- hw/loader.c | 2 +- hw/sparc/sun4m.c | 6 +- hw/sparc64/sun4u.c | 2 +- 13 files changed, 248 insertions(+), 77 deletions(-)
Soon we'll declare a function in "hw/pc.h" that takes a pointer-to-FWCfgState. That would be inconsistent with current usage -- some places use pointer-to-void now even though they mean pointer-to-FWCfgState. Clean them up.
Signed-off-by: Laszlo Ersek lersek@redhat.com --- hw/loader.h | 3 ++- hw/multiboot.h | 4 +++- hw/pc.h | 19 ++++++++++--------- hw/acpi_piix4.c | 2 +- hw/i386/multiboot.c | 2 +- hw/i386/pc.c | 24 ++++++++++++------------ hw/i386/pc_piix.c | 2 +- hw/loader.c | 2 +- hw/sparc/sun4m.c | 6 +++--- hw/sparc64/sun4u.c | 2 +- 10 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/hw/loader.h b/hw/loader.h index 0958f06..6b8b1e1 100644 --- a/hw/loader.h +++ b/hw/loader.h @@ -1,6 +1,7 @@ #ifndef LOADER_H #define LOADER_H #include "qapi/qmp/qdict.h" +#include "hw/fw_cfg.h"
/* loader.c */ int get_image_size(const char *filename); @@ -30,7 +31,7 @@ int rom_add_blob(const char *name, const void *blob, size_t len, int rom_add_elf_program(const char *name, void *data, size_t datasize, size_t romsize, hwaddr addr); int rom_load_all(void); -void rom_set_fw(void *f); +void rom_set_fw(FWCfgState *f); int rom_copy(uint8_t *dest, hwaddr addr, size_t size); void *rom_ptr(hwaddr addr); void do_info_roms(Monitor *mon, const QDict *qdict); diff --git a/hw/multiboot.h b/hw/multiboot.h index 98fb1b7..25589e3 100644 --- a/hw/multiboot.h +++ b/hw/multiboot.h @@ -1,7 +1,9 @@ #ifndef QEMU_MULTIBOOT_H #define QEMU_MULTIBOOT_H
-int load_multiboot(void *fw_cfg, +#include "hw/fw_cfg.h" + +int load_multiboot(FWCfgState *fw_cfg, FILE *f, const char *kernel_filename, const char *initrd_filename, diff --git a/hw/pc.h b/hw/pc.h index 55964ce..5e5dd3d 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -9,6 +9,7 @@ #include "net/net.h" #include "exec/memory.h" #include "hw/ioapic.h" +#include "hw/fw_cfg.h"
/* PC-style peripherals (also used by other machines). */
@@ -80,14 +81,14 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
void pc_cpus_init(const char *cpu_model); void pc_acpi_init(const char *default_dsdt); -void *pc_memory_init(MemoryRegion *system_memory, - const char *kernel_filename, - const char *kernel_cmdline, - const char *initrd_filename, - ram_addr_t below_4g_mem_size, - ram_addr_t above_4g_mem_size, - MemoryRegion *rom_memory, - MemoryRegion **ram_memory); +FWCfgState *pc_memory_init(MemoryRegion *system_memory, + const char *kernel_filename, + const char *kernel_cmdline, + const char *initrd_filename, + ram_addr_t below_4g_mem_size, + ram_addr_t above_4g_mem_size, + MemoryRegion *rom_memory, + MemoryRegion **ram_memory); qemu_irq *pc_allocate_cpu_irq(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, @@ -119,7 +120,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp);
i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qemu_irq sci_irq, qemu_irq smi_irq, - int kvm_enabled, void *fw_cfg); + int kvm_enabled, FWCfgState *fw_cfg); void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
/* hpet.c */ diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 48a32b5..e168d0d 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -435,7 +435,7 @@ static int piix4_pm_initfn(PCIDevice *dev)
i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qemu_irq sci_irq, qemu_irq smi_irq, - int kvm_enabled, void *fw_cfg) + int kvm_enabled, FWCfgState *fw_cfg) { PCIDevice *dev; PIIX4PMState *s; diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index 3cb228f..b4ce1fc 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -124,7 +124,7 @@ static void mb_add_mod(MultibootState *s, s->mb_mods_count++; }
-int load_multiboot(void *fw_cfg, +int load_multiboot(FWCfgState *fw_cfg, FILE *f, const char *kernel_filename, const char *initrd_filename, diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ebbf059..e7c88c4 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -568,9 +568,9 @@ static unsigned int pc_apic_id_limit(unsigned int max_cpus) return x86_cpu_apic_id_from_index(max_cpus - 1) + 1; }
-static void *bochs_bios_init(void) +static FWCfgState *bochs_bios_init(void) { - void *fw_cfg; + FWCfgState *fw_cfg; uint8_t *smbios_table; size_t smbios_len; uint64_t *numa_fw_cfg; @@ -647,7 +647,7 @@ static long get_file_size(FILE *f) return size; }
-static void load_linux(void *fw_cfg, +static void load_linux(FWCfgState *fw_cfg, const char *kernel_filename, const char *initrd_filename, const char *kernel_cmdline, @@ -923,19 +923,19 @@ void pc_acpi_init(const char *default_dsdt) } }
-void *pc_memory_init(MemoryRegion *system_memory, - const char *kernel_filename, - const char *kernel_cmdline, - const char *initrd_filename, - ram_addr_t below_4g_mem_size, - ram_addr_t above_4g_mem_size, - MemoryRegion *rom_memory, - MemoryRegion **ram_memory) +FWCfgState *pc_memory_init(MemoryRegion *system_memory, + const char *kernel_filename, + const char *kernel_cmdline, + const char *initrd_filename, + ram_addr_t below_4g_mem_size, + ram_addr_t above_4g_mem_size, + MemoryRegion *rom_memory, + MemoryRegion **ram_memory) { int linux_boot, i; MemoryRegion *ram, *option_rom_mr; MemoryRegion *ram_below_4g, *ram_above_4g; - void *fw_cfg; + FWCfgState *fw_cfg;
linux_boot = (kernel_filename != NULL);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 0abc9f1..7761077 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -84,7 +84,7 @@ static void pc_init1(MemoryRegion *system_memory, MemoryRegion *ram_memory; MemoryRegion *pci_memory; MemoryRegion *rom_memory; - void *fw_cfg = NULL; + FWCfgState *fw_cfg = NULL;
pc_cpus_init(cpu_model); pc_acpi_init("acpi-dsdt.aml"); diff --git a/hw/loader.c b/hw/loader.c index 6ce66fb..16bb8f4 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -733,7 +733,7 @@ int rom_load_all(void) return 0; }
-void rom_set_fw(void *f) +void rom_set_fw(FWCfgState *f) { fw_cfg = f; } diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 9ebda02..ef72f0c 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -874,7 +874,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, qemu_irq *cpu_halt; unsigned long kernel_size; DriveInfo *fd[MAX_FD]; - void *fw_cfg; + FWCfgState *fw_cfg; unsigned int num_vsimms;
/* init CPUs */ @@ -1592,7 +1592,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, espdma_irq, ledma_irq; qemu_irq esp_reset, dma_enable; unsigned long kernel_size; - void *fw_cfg; + FWCfgState *fw_cfg; DeviceState *dev;
/* init CPUs */ @@ -1793,7 +1793,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, qemu_irq fdc_tc; unsigned long kernel_size; DriveInfo *fd[MAX_FD]; - void *fw_cfg; + FWCfgState *fw_cfg; DeviceState *dev; unsigned int i;
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 4c39cf6..08a0ffe 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -818,7 +818,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem, qemu_irq *ivec_irqs, *pbm_irqs; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; DriveInfo *fd[MAX_FD]; - void *fw_cfg; + FWCfgState *fw_cfg;
/* init CPUs */ cpu = cpu_devinit(cpu_model, hwdef);
This enables reuse when preparing per-table fw_cfg blobs later.
Signed-off-by: Laszlo Ersek lersek@redhat.com --- hw/acpi.h | 11 +++++++++++ hw/acpi.c | 48 +++++++++++++++++++++--------------------------- 2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/hw/acpi.h b/hw/acpi.h index e18ef28..d69b6ef 100644 --- a/hw/acpi.h +++ b/hw/acpi.h @@ -154,4 +154,15 @@ void acpi_gpe_reset(ACPIREGS *ar); void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val); uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
+typedef struct acpi_table_std_header { + char sig[4]; /* ACPI signature (4 ASCII characters) */ + uint32_t length; /* Length of table, in bytes, including header */ + uint8_t revision; /* ACPI Specification minor version # */ + uint8_t checksum; /* To make sum of entire table == 0 */ + char oem_id[6]; /* OEM identification */ + char oem_table_id[8]; /* OEM table identification */ + uint32_t oem_revision; /* OEM revision number */ + char asl_compiler_id[4]; /* ASL compiler vendor ID */ + uint32_t asl_compiler_revision; /* ASL compiler revision number */ +} QEMU_PACKED AcpiTableStdHdr; #endif /* !QEMU_HW_ACPI_H */ diff --git a/hw/acpi.c b/hw/acpi.c index 856da81..73af4bd 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -31,21 +31,13 @@ struct acpi_table_header { uint16_t _length; /* our length, not actual part of the hdr */ /* allows easier parsing for fw_cfg clients */ - char sig[4]; /* ACPI signature (4 ASCII characters) */ - uint32_t length; /* Length of table, in bytes, including header */ - uint8_t revision; /* ACPI Specification minor version # */ - uint8_t checksum; /* To make sum of entire table == 0 */ - char oem_id[6]; /* OEM identification */ - char oem_table_id[8]; /* OEM table identification */ - uint32_t oem_revision; /* OEM revision number */ - char asl_compiler_id[4]; /* ASL compiler vendor ID */ - uint32_t asl_compiler_revision; /* ASL compiler revision number */ + AcpiTableStdHdr std; } QEMU_PACKED;
-#define ACPI_TABLE_HDR_SIZE sizeof(struct acpi_table_header) -#define ACPI_TABLE_PFX_SIZE sizeof(uint16_t) /* size of the extra prefix */ +/* size of the extra prefix */ +#define ACPI_TABLE_PFX_SIZE offsetof(struct acpi_table_header, std)
-static const char unsigned dfl_hdr[ACPI_TABLE_HDR_SIZE - ACPI_TABLE_PFX_SIZE] = +static const char unsigned dfl_hdr[sizeof(AcpiTableStdHdr)] = "QEMU\0\0\0\0\1\0" /* sig (4), len(4), revno (1), csum (1) */ "QEMUQEQEMUQEMU\1\0\0\0" /* OEM id (6), table (8), revno (4) */ "QEMU\1\0\0\0" /* ASL compiler ID (4), version (4) */ @@ -105,6 +97,7 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen, size_t body_size, acpi_payload_size; struct acpi_table_header *ext_hdr; unsigned changed_fields; + AcpiTableStdHdr *std;
/* Calculate where the ACPI table body starts within the blob, plus where * to copy the ACPI table header from. @@ -177,46 +170,47 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen, changed_fields = 0; ext_hdr->_length = cpu_to_le16(acpi_payload_size);
+ std = &ext_hdr->std; if (hdrs->has_sig) { - strncpy(ext_hdr->sig, hdrs->sig, sizeof ext_hdr->sig); + strncpy(std->sig, hdrs->sig, sizeof std->sig); ++changed_fields; }
- if (has_header && le32_to_cpu(ext_hdr->length) != acpi_payload_size) { + if (has_header && le32_to_cpu(std->length) != acpi_payload_size) { fprintf(stderr, "warning: ACPI table has wrong length, header says " "%" PRIu32 ", actual size %zu bytes\n", - le32_to_cpu(ext_hdr->length), acpi_payload_size); + le32_to_cpu(std->length), acpi_payload_size); } - ext_hdr->length = cpu_to_le32(acpi_payload_size); + std->length = cpu_to_le32(acpi_payload_size);
if (hdrs->has_rev) { - ext_hdr->revision = hdrs->rev; + std->revision = hdrs->rev; ++changed_fields; }
- ext_hdr->checksum = 0; + std->checksum = 0;
if (hdrs->has_oem_id) { - strncpy(ext_hdr->oem_id, hdrs->oem_id, sizeof ext_hdr->oem_id); + strncpy(std->oem_id, hdrs->oem_id, sizeof std->oem_id); ++changed_fields; } if (hdrs->has_oem_table_id) { - strncpy(ext_hdr->oem_table_id, hdrs->oem_table_id, - sizeof ext_hdr->oem_table_id); + strncpy(std->oem_table_id, hdrs->oem_table_id, + sizeof std->oem_table_id); ++changed_fields; } if (hdrs->has_oem_rev) { - ext_hdr->oem_revision = cpu_to_le32(hdrs->oem_rev); + std->oem_revision = cpu_to_le32(hdrs->oem_rev); ++changed_fields; } if (hdrs->has_asl_compiler_id) { - strncpy(ext_hdr->asl_compiler_id, hdrs->asl_compiler_id, - sizeof ext_hdr->asl_compiler_id); + strncpy(std->asl_compiler_id, hdrs->asl_compiler_id, + sizeof std->asl_compiler_id); ++changed_fields; } if (hdrs->has_asl_compiler_rev) { - ext_hdr->asl_compiler_revision = cpu_to_le32(hdrs->asl_compiler_rev); + std->asl_compiler_revision = cpu_to_le32(hdrs->asl_compiler_rev); ++changed_fields; }
@@ -225,8 +219,8 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen, }
/* recalculate checksum */ - ext_hdr->checksum = acpi_checksum((const char unsigned *)ext_hdr + - ACPI_TABLE_PFX_SIZE, acpi_payload_size); + std->checksum = acpi_checksum((const char unsigned *)std, + acpi_payload_size); }
void acpi_table_add(const QemuOpts *opts, Error **errp)
This enables reuse when preparing per-table fw_cfg blobs later.
Signed-off-by: Laszlo Ersek lersek@redhat.com --- hw/acpi.h | 2 ++ hw/acpi.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/hw/acpi.h b/hw/acpi.h index d69b6ef..e3e17e9 100644 --- a/hw/acpi.h +++ b/hw/acpi.h @@ -165,4 +165,6 @@ typedef struct acpi_table_std_header { char asl_compiler_id[4]; /* ASL compiler vendor ID */ uint32_t asl_compiler_revision; /* ASL compiler revision number */ } QEMU_PACKED AcpiTableStdHdr; + +extern const AcpiTableStdHdr acpi_dfl_hdr; #endif /* !QEMU_HW_ACPI_H */ diff --git a/hw/acpi.c b/hw/acpi.c index 73af4bd..f24be53 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -37,11 +37,20 @@ struct acpi_table_header { /* size of the extra prefix */ #define ACPI_TABLE_PFX_SIZE offsetof(struct acpi_table_header, std)
-static const char unsigned dfl_hdr[sizeof(AcpiTableStdHdr)] = - "QEMU\0\0\0\0\1\0" /* sig (4), len(4), revno (1), csum (1) */ - "QEMUQEQEMUQEMU\1\0\0\0" /* OEM id (6), table (8), revno (4) */ - "QEMU\1\0\0\0" /* ASL compiler ID (4), version (4) */ - ; +const AcpiTableStdHdr acpi_dfl_hdr = { + .sig = "QEMU", + .revision = 1, + .oem_id = "QEMUQE", + .oem_table_id = "QEMUQEMU", + .asl_compiler_id = "QEMU", +#ifdef HOST_WORDS_BIGENDIAN + .oem_revision = 0x01000000, + .asl_compiler_revision = 0x01000000 +#else + .oem_revision = 1, + .asl_compiler_revision = 1 +#endif +};
char unsigned *acpi_tables; size_t acpi_tables_len; @@ -74,8 +83,8 @@ static int acpi_checksum(const uint8_t *data, int len) /* Install a copy of the ACPI table specified in @blob. * * If @has_header is set, @blob starts with the System Description Table Header - * structure. Otherwise, "dfl_hdr" is prepended. In any case, each header field - * is optionally overwritten from @hdrs. + * structure. Otherwise, "acpi_dfl_hdr" is prepended. In any case, each header + * field is optionally overwritten from @hdrs. * * It is valid to call this function with * (@blob == NULL && bloblen == 0 && !has_header). @@ -105,13 +114,13 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen, if (has_header) { /* _length | ACPI header in blob | blob body * ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ - * ACPI_TABLE_PFX_SIZE sizeof dfl_hdr body_size + * ACPI_TABLE_PFX_SIZE sizeof acpi_dfl_hdr body_size * == body_start * * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * acpi_payload_size == bloblen */ - body_start = sizeof dfl_hdr; + body_start = sizeof acpi_dfl_hdr;
if (bloblen < body_start) { error_setg(errp, "ACPI table claiming to have header is too " @@ -123,17 +132,17 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen, } else { /* _length | ACPI header in template | blob body * ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ - * ACPI_TABLE_PFX_SIZE sizeof dfl_hdr body_size + * ACPI_TABLE_PFX_SIZE sizeof acpi_dfl_hdr body_size * == bloblen * * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * acpi_payload_size */ body_start = 0; - hdr_src = dfl_hdr; + hdr_src = (const char unsigned *)&acpi_dfl_hdr; } body_size = bloblen - body_start; - acpi_payload_size = sizeof dfl_hdr + body_size; + acpi_payload_size = sizeof acpi_dfl_hdr + body_size;
if (acpi_payload_size > UINT16_MAX) { error_setg(errp, "ACPI table too big, requested: %zu, max: %u", @@ -149,13 +158,13 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen,
acpi_tables = g_realloc(acpi_tables, acpi_tables_len + ACPI_TABLE_PFX_SIZE + - sizeof dfl_hdr + body_size); + sizeof acpi_dfl_hdr + body_size);
ext_hdr = (struct acpi_table_header *)(acpi_tables + acpi_tables_len); acpi_tables_len += ACPI_TABLE_PFX_SIZE;
- memcpy(acpi_tables + acpi_tables_len, hdr_src, sizeof dfl_hdr); - acpi_tables_len += sizeof dfl_hdr; + memcpy(acpi_tables + acpi_tables_len, hdr_src, sizeof acpi_dfl_hdr); + acpi_tables_len += sizeof acpi_dfl_hdr;
if (blob != NULL) { memcpy(acpi_tables + acpi_tables_len, blob + body_start, body_size);
Again, this enables reuse when preparing per-table fw_cfg blobs later.
Signed-off-by: Laszlo Ersek lersek@redhat.com --- hw/acpi.h | 2 ++ hw/acpi.c | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/hw/acpi.h b/hw/acpi.h index e3e17e9..2c89e59 100644 --- a/hw/acpi.h +++ b/hw/acpi.h @@ -167,4 +167,6 @@ typedef struct acpi_table_std_header { } QEMU_PACKED AcpiTableStdHdr;
extern const AcpiTableStdHdr acpi_dfl_hdr; + +int acpi_checksum(const uint8_t *data, int len); #endif /* !QEMU_HW_ACPI_H */ diff --git a/hw/acpi.c b/hw/acpi.c index f24be53..07634e1 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -69,7 +69,7 @@ static void acpi_register_config(void)
machine_init(acpi_register_config);
-static int acpi_checksum(const uint8_t *data, int len) +int acpi_checksum(const uint8_t *data, int len) { int sum, i; sum = 0;
The set of per-table fw_cfg files is installed with the new function pc_acpi_fw_cfg_init().
This function is called at the end of pc_init1() and pc_q35_init():
pc_init1() or pc_q35_init() pc_acpi_init() <---- very early /* bunch of setup code */ pc_acpi_fw_cfg_init() <---- added now
rather than from within pc_acpi_init() for two reasons:
(1) In general, calculation of ACPI tables could logically depend on machine data set up by pc_init1() / pc_q35_init() *after* their respective calls to pc_acpi_init().
(2) pc_acpi_fw_cfg_init() obviously depends on the FWCfgState object, which is not available when pc_acpi_init() is called:
pc_init1() and pc_q35_init() pc_acpi_init() ... pc_memory_init() bochs_bios_init() fw_cfg_init() <---- FWCfgState object set up here sysbus_mmio_map() fw_cfg_add_bytes(..., acpi_tables, ...); ... pc_acpi_fw_cfg_init() <---- added now, depends on FWCfgState
The following movements have been considered and rejected:
(2a) Pushing pc_acpi_init() below pc_memory_init(), and sinking the call to the new function pc_acpi_fw_cfg_init() into pc_acpi_init():
pc_init1() and pc_q35_init() ... pc_memory_init() bochs_bios_init() fw_cfg_init() sysbus_mmio_map() fw_cfg_add_bytes(..., acpi_tables, ...); ... pc_acpi_init() <---- ordered after rest of setup code pc_acpi_fw_cfg_init() <---- added now
Unfortunately, "acpi_tables" is modified by pc_acpi_init(), hence this move would violate a data dependency in pc_memory_init().
(2b) Alternatively, based on (2), hoisting the fw_cfg_init() call to just before pc_acpi_init(), and again sinking the call to the new function pc_acpi_fw_cfg_init() into pc_acpi_init():
pc_init1() and pc_q35_init() fw_cfg_init() <---- pulled up from bochs_bios_init() sysbus_mmio_map() pc_acpi_init() pc_acpi_fw_cfg_init() <---- added now ... pc_memory_init() bochs_bios_init() fw_cfg_add_bytes(..., acpi_tables, ...);
Alas, sysbus_mmio_map() in fw_cfg_init() depends on the memory layout prepared by pc_memory_init().
Ultimately we have the following dependencies: - pc_acpi_fw_cfg_init() depends on fw_cfg_init() [2], - fw_cfg_init() depends on pc_memory_init() [2b], - pc_memory_init() depends on pc_acpi_init() [2a]
This yields the total ordering visible in the patch.
Signed-off-by: Laszlo Ersek lersek@redhat.com --- hw/pc.h | 1 + hw/i386/pc.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 2 + hw/i386/pc_q35.c | 10 +++- 4 files changed, 152 insertions(+), 3 deletions(-)
diff --git a/hw/pc.h b/hw/pc.h index 5e5dd3d..0718d8f 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -107,6 +107,7 @@ typedef void (*cpu_set_smm_t)(int smm, void *arg); void cpu_smm_register(cpu_set_smm_t callback, void *arg);
void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); +void pc_acpi_fw_cfg_init(FWCfgState *fw_cfg);
/* acpi.c */ extern int acpi_enabled; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e7c88c4..7dd9c60 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -52,6 +52,7 @@ #include "sysemu/arch_init.h" #include "qemu/bitmap.h" #include "qemu/config-file.h" +#include "hw/acpi.h"
/* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -1178,3 +1179,144 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); } } + +static void pc_acpi_install(FWCfgState *fw_cfg, AcpiTableStdHdr *std_hdr, + size_t blob_size, const char *sig) +{ + char *pathname; + + g_assert(blob_size >= sizeof *std_hdr); + + *std_hdr = acpi_dfl_hdr; + strncpy(std_hdr->sig, sig, sizeof std_hdr->sig); + strncpy(std_hdr->oem_id, "QEMU ", sizeof std_hdr->oem_id); + strncpy(std_hdr->oem_table_id + 4, sig, sizeof std_hdr->oem_table_id - 4); + std_hdr->length = cpu_to_le32(blob_size); + std_hdr->checksum = acpi_checksum((uint8_t *)std_hdr, blob_size); + + pathname = g_strdup_printf("etc/acpi/%s", sig); + fw_cfg_add_file(fw_cfg, pathname, std_hdr, blob_size); + g_free(pathname); +} + +static void pc_acpi_madt(FWCfgState *fw_cfg) +{ + typedef struct { + uint8_t type; + uint8_t length; + } QEMU_PACKED AcpiSubHdr; + + AcpiTableStdHdr *std_hdr; + struct { + uint32_t lapic_addr; /* Local Interrupt Controller Address */ + uint32_t flags; /* Multiple APIC flags */ + } QEMU_PACKED *madt; + struct { + AcpiSubHdr hdr; + uint8_t processor_id; /* ACPI Processor ID */ + uint8_t apic_id; /* APIC ID */ + uint32_t flags; /* LOcal APIC flags */ + } QEMU_PACKED *lapic; + struct { + AcpiSubHdr hdr; + uint8_t io_apic_id; /* The I/O APIC's ID */ + uint8_t reserved; /* constant zero */ + uint32_t io_apic_addr; /* 32-bit physical address to access */ + uint32_t gsi_base; /* interrupt inputs start here */ + } QEMU_PACKED *io_apic; + struct { + AcpiSubHdr hdr; + uint8_t bus; /* constant zero: ISA */ + uint8_t source; /* this bus-relative interrupt source... */ + uint32_t gsi; /* ... will signal this global system interrupt */ + uint16_t flags; /* MPS INTI Flags: Polarity, Trigger Mode */ + } QEMU_PACKED *int_src_ovr; + struct { + AcpiSubHdr hdr; + uint8_t processor_id; /* ACPI Processor ID */ + uint16_t flags; /* MPS INTI Flags: Polarity, Trigger Mode */ + uint8_t lint; /* LAPIC interrupt input for NMI */ + } QEMU_PACKED *lapic_nmi; + + static const uint8_t pci_isa_irq[] = { 5, 9, 10, 11 }; + + unsigned num_lapic, num_int_src_ovr, i; + size_t blob_size; + char unsigned *blob; + + /* see note on FW_CFG_MAX_CPUS in bochs_bios_init() */ + num_lapic = pc_apic_id_limit(max_cpus); + num_int_src_ovr = sizeof pci_isa_irq + kvm_allows_irq0_override(); + + blob_size = (sizeof *std_hdr) * 1 + + (sizeof *madt) * 1 + + (sizeof *lapic) * num_lapic + + (sizeof *io_apic) * 1 + + (sizeof *int_src_ovr) * num_int_src_ovr + + (sizeof *lapic_nmi) * 1; + blob = g_malloc(blob_size); + + std_hdr = (void *)blob; + madt = (void *)(std_hdr + 1 ); + lapic = (void *)(madt + 1 ); + io_apic = (void *)(lapic + num_lapic ); + int_src_ovr = (void *)(io_apic + 1 ); + lapic_nmi = (void *)(int_src_ovr + num_int_src_ovr); + + madt->lapic_addr = cpu_to_le32(APIC_DEFAULT_ADDRESS); + madt->flags = cpu_to_le32(1); /* PCAT_COMPAT */ + + /* create a Local APIC structure for each possible APIC ID */ + for (i = 0; i < num_lapic; ++i) { + lapic[i].hdr.type = 0; /* Processor Local APIC */ + lapic[i].hdr.length = sizeof *lapic; + lapic[i].processor_id = i; + lapic[i].apic_id = i; + lapic[i].flags = cpu_to_le32(0); /* disabled */ + } + /* enable the CPUs with a CPU index in the [0..smp_cpus-1] range */ + for (i = 0; i < smp_cpus; ++i) { + lapic[x86_cpu_apic_id_from_index(i)].flags = cpu_to_le32(1); + } + + io_apic->hdr.type = 1; /* I/O APIC */ + io_apic->hdr.length = sizeof *io_apic; + io_apic->io_apic_id = 0; + io_apic->reserved = 0; + io_apic->io_apic_addr = cpu_to_le32(IO_APIC_DEFAULT_ADDRESS); + io_apic->gsi_base = cpu_to_le32(0); + + for (i = 0; i < sizeof pci_isa_irq; ++i) { + int_src_ovr[i].hdr.type = 2; /* Interrupt Source Override */ + int_src_ovr[i].hdr.length = sizeof *int_src_ovr; + int_src_ovr[i].bus = 0; + int_src_ovr[i].source = pci_isa_irq[i]; + int_src_ovr[i].gsi = cpu_to_le32(pci_isa_irq[i]); + int_src_ovr[i].flags = cpu_to_le16(0xd); + /* active high, level-triggered */ + } + if (kvm_allows_irq0_override()) { + int_src_ovr[i].hdr.type = 2; /* Interrupt Source Override */ + int_src_ovr[i].hdr.length = sizeof *int_src_ovr; + int_src_ovr[i].bus = 0; + int_src_ovr[i].source = 0; + int_src_ovr[i].gsi = cpu_to_le32(2); + int_src_ovr[i].flags = cpu_to_le16(0); /* conforms to bus spec */ + } + + lapic_nmi->hdr.type = 4; /* Local APIC NMI */ + lapic_nmi->hdr.length = sizeof *lapic_nmi; + lapic_nmi->processor_id = 0xff; /* all processors */ + lapic_nmi->flags = cpu_to_le16(0); /* conforms to bus spec */ + lapic_nmi->lint = 1; /* NMI connected to LAPIC input LINT1 */ + + pc_acpi_install(fw_cfg, std_hdr, blob_size, "APIC"); +} + +void pc_acpi_fw_cfg_init(FWCfgState *fw_cfg) +{ + if (fw_cfg == NULL) { + return; + } + pc_acpi_madt(fw_cfg); +} diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 7761077..c261d50 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -217,6 +217,8 @@ static void pc_init1(MemoryRegion *system_memory, if (pci_enabled) { pc_pci_device_init(pci_bus); } + + pc_acpi_fw_cfg_init(fw_cfg); }
static void pc_init_pci(QEMUMachineInitArgs *args) diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 4f5f347..c852a90 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -85,6 +85,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args) ICH9LPCState *ich9_lpc; PCIDevice *ahci; qemu_irq *cmos_s3; + FWCfgState *fw_cfg = NULL;
pc_cpus_init(cpu_model); pc_acpi_init("q35-acpi-dsdt.aml"); @@ -111,9 +112,10 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
/* allocate ram and load rom/bios */ if (!xen_enabled()) { - pc_memory_init(get_system_memory(), kernel_filename, kernel_cmdline, - initrd_filename, below_4g_mem_size, above_4g_mem_size, - rom_memory, &ram_memory); + fw_cfg = pc_memory_init(get_system_memory(), kernel_filename, + kernel_cmdline, initrd_filename, + below_4g_mem_size, above_4g_mem_size, + rom_memory, &ram_memory); }
/* irq lines */ @@ -207,6 +209,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) if (pci_enabled) { pc_pci_device_init(host_bus); } + + pc_acpi_fw_cfg_init(fw_cfg); }
static QEMUMachine pc_q35_machine_v1_5 = {