Skip to contentSkip to conversation

acpi: xsdt support

PATCH Superseded Michael S. Tsirkin 3 participants 16 messages Jun 4, 2015 – Jun 8, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover acpi: xsdt support

XSDT support allows using ACPI 2 features while avoiding breaking legacy windows XP guests:
ACPI 2 tables are linked from XSDT only,
ACPI 1 tables from both RSDT and XSDT, this way XP does not see ACPI 2 tables.

As a first step, this patchset generates v2 RSDP and fills in XSDT matching RSDT exactly.

ARM patch is untested: I don't know how to test ARM ACPI. Testing reports would be greatly appreciated.

Michael S. Tsirkin (4):
acpi: add API for 64 bit offsets
i386/acpi: collect 64 bit offsets for xsdt
i386/acpi: add XSDT
acpi: unify rsdp generation

 include/hw/acpi/acpi-defs.h | 15 +++++--
 include/hw/acpi/aml-build.h |  7 +++-
 hw/acpi/aml-build.c         | 99 +++++++++++++++++++++++++++++++++++++--------
 hw/arm/virt-acpi-build.c    | 39 +++---------------
 hw/i386/acpi-build.c        | 64 +++++++++++------------------
 5 files changed, 129 insertions(+), 95 deletions(-)
Signature · 1 line
MST
#1 lore raw

PATCH 1/4 acpi: add API for 64 bit offsets

Collecting these is useful for implementing the XSDT.

---
 include/hw/acpi/aml-build.h |  3 ++-
 hw/acpi/aml-build.c         | 13 ++++++++++---
 hw/arm/virt-acpi-build.c    |  8 ++++----
 hw/i386/acpi-build.c        | 20 ++++++++++----------
 4 files changed, 26 insertions(+), 18 deletions(-)
include/hw/acpi/aml-build.h +2 -1
index e3afa13..edc1dfa 100644
@@ -281,7 +281,8 @@ build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev);
 void *acpi_data_push(GArray *table_data, unsigned size);
 unsigned acpi_data_len(GArray *table);
-void acpi_add_table(GArray *table_offsets, GArray *table_data);
+void acpi_add_table(GArray *table_offsets32, GArray *table_offsets64,
+                    GArray *table_data);
 void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
hw/acpi/aml-build.c +10 -3
index 0d4b324..4c930b6 100644
@@ -1169,10 +1169,17 @@ unsigned acpi_data_len(GArray *table)
     return table->len;
 }
 
-void acpi_add_table(GArray *table_offsets, GArray *table_data)
+void acpi_add_table(GArray *table_offsets32, GArray *table_offsets64,
+                    GArray *table_data)
 {
-    uint32_t offset = cpu_to_le32(table_data->len);
-    g_array_append_val(table_offsets, offset);
+    uint32_t offset32 = cpu_to_le32(table_data->len);
+    uint64_t offset64 = cpu_to_le64(table_data->len);
+    if (table_offsets32) {
+        g_array_append_val(table_offsets32, offset32);
+    }
+    if (table_offsets64) {
+        g_array_append_val(table_offsets64, offset64);
+    }
 }
 
 void acpi_build_tables_init(AcpiBuildTables *tables)
hw/arm/virt-acpi-build.c +4 -4
index a9373cc..42c8dd9 100644
@@ -515,16 +515,16 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
     build_dsdt(tables_blob, tables->linker, guest_info);
 
     /* FADT MADT GTDT pointed to by RSDT */
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_fadt(tables_blob, tables->linker, dsdt);
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_madt(tables_blob, tables->linker, guest_info, &cpuinfo);
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_gtdt(tables_blob, tables->linker);
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_mcfg(tables_blob, tables->linker, guest_info);
 
     /* RSDT is pointed to by RSDP */
hw/i386/acpi-build.c +10 -10
index db32fd1..e5b0b7a 100644
@@ -1706,27 +1706,27 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     aml_len += tables_blob->len - dsdt;
 
     /* ACPI tables pointed to by RSDT */
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
 
     ssdt = tables_blob->len;
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
                guest_info);
     aml_len += tables_blob->len - ssdt;
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_madt(tables_blob, tables->linker, &cpu, guest_info);
 
     if (misc.has_hpet) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_hpet(tables_blob, tables->linker);
     }
     if (misc.tpm_version != TPM_VERSION_UNSPEC) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         switch (misc.tpm_version) {
         case TPM_VERSION_1_2:
             build_tpm_ssdt(tables_blob, tables->linker);
@@ -1739,15 +1739,15 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         }
     }
     if (guest_info->numa_nodes) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_srat(tables_blob, tables->linker, guest_info);
     }
     if (acpi_get_mcfg(&mcfg)) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_mcfg_q35(tables_blob, tables->linker, &mcfg);
     }
     if (acpi_has_iommu()) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_dmar_q35(tables_blob, tables->linker);
     }
 
@@ -1755,7 +1755,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
         unsigned len = acpi_table_len(u);
 
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         g_array_append_vals(tables_blob, u, len);
     }
 
Signature · 1 line
MST
#3 lore raw

PATCH 2/4 i386/acpi: collect 64 bit offsets for xsdt

In reply to Michael S. Tsirkin

collect then discard, they are unused for now.

---
 hw/i386/acpi-build.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
hw/i386/acpi-build.c +18 -14
index e5b0b7a..aaa149b 100644
@@ -1663,7 +1663,8 @@ static bool acpi_has_iommu(void)
 static
 void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 {
-    GArray *table_offsets;
+    GArray *rsdt_table_offsets;
+    GArray *xsdt_table_offsets;
     unsigned facs, ssdt, dsdt, rsdt;
     AcpiCpuInfo cpu;
     AcpiPmInfo pm;
@@ -1680,8 +1681,10 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     acpi_get_misc_info(&misc);
     acpi_get_pci_info(&pci);
 
-    table_offsets = g_array_new(false, true /* clear */,
+    rsdt_table_offsets = g_array_new(false, true /* clear */,
                                         sizeof(uint32_t));
+    xsdt_table_offsets = g_array_new(false, true /* clear */,
+                                        sizeof(uint64_t));
     ACPI_BUILD_DPRINTF("init ACPI tables\n");
 
     bios_linker_loader_alloc(tables->linker, ACPI_BUILD_TABLE_FILE,
@@ -1706,27 +1709,27 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     aml_len += tables_blob->len - dsdt;
 
     /* ACPI tables pointed to by RSDT */
-    acpi_add_table(table_offsets, NULL, tables_blob);
+    acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
     build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
 
     ssdt = tables_blob->len;
-    acpi_add_table(table_offsets, NULL, tables_blob);
+    acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
     build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
                guest_info);
     aml_len += tables_blob->len - ssdt;
 
-    acpi_add_table(table_offsets, NULL, tables_blob);
+    acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
     build_madt(tables_blob, tables->linker, &cpu, guest_info);
 
     if (misc.has_hpet) {
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         build_hpet(tables_blob, tables->linker);
     }
     if (misc.tpm_version != TPM_VERSION_UNSPEC) {
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         switch (misc.tpm_version) {
         case TPM_VERSION_1_2:
             build_tpm_ssdt(tables_blob, tables->linker);
@@ -1739,15 +1742,15 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         }
     }
     if (guest_info->numa_nodes) {
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         build_srat(tables_blob, tables->linker, guest_info);
     }
     if (acpi_get_mcfg(&mcfg)) {
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         build_mcfg_q35(tables_blob, tables->linker, &mcfg);
     }
     if (acpi_has_iommu()) {
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         build_dmar_q35(tables_blob, tables->linker);
     }
 
@@ -1755,13 +1758,13 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
         unsigned len = acpi_table_len(u);
 
-        acpi_add_table(table_offsets, NULL, tables_blob);
+        acpi_add_table(rsdt_table_offsets, xsdt_table_offsets, tables_blob);
         g_array_append_vals(tables_blob, u, len);
     }
 
     /* RSDT is pointed to by RSDP */
     rsdt = tables_blob->len;
-    build_rsdt(tables_blob, tables->linker, table_offsets);
+    build_rsdt(tables_blob, tables->linker, rsdt_table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
     build_rsdp(tables->rsdp, tables->linker, rsdt);
@@ -1813,7 +1816,8 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     acpi_align_size(tables->linker, ACPI_BUILD_ALIGN_SIZE);
 
     /* Cleanup memory that's no longer used. */
-    g_array_free(table_offsets, true);
+    g_array_free(xsdt_table_offsets, true);
+    g_array_free(rsdt_table_offsets, true);
 }
 
 static void acpi_ram_update(MemoryRegion *mr, GArray *data)
Signature · 1 line
MST
#8 lore raw

PATCH 4/4 acpi: unify rsdp generation

In reply to Michael S. Tsirkin

Now that both i386 and arm use v2 tables,
use common code for both.

Warning: untested.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 31 +------------------------------
 hw/i386/acpi-build.c        | 41 -----------------------------------------
 4 files changed, 48 insertions(+), 71 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0a00402..ae169fa 100644
@@ -289,5 +289,7 @@ void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 void
 build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt);
 
 #endif
hw/acpi/aml-build.c +45 -0

48 lines not on this page · raw message

hw/arm/virt-acpi-build.c +1 -30
index 42c8dd9..c164f65 100644
@@ -304,35 +304,6 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, int irq)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
-    rsdp->length = cpu_to_le32(sizeof(*rsdp));
-    rsdp->revision = 0x02;
-
-    /* Point to RSDT */
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
-
-    return rsdp_table;
-}
-
 static void
 build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {
@@ -532,7 +503,7 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
     build_rsdt(tables_blob, tables->linker, table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, 0);
 
     /* Cleanup memory that's no longer used. */
     g_array_free(table_offsets, true);
hw/i386/acpi-build.c +0 -41

47 lines not on this page · raw message

Signature · 1 line
MST
#4 lore raw

PATCH 3/4 i386/acpi: add XSDT

In reply to Michael S. Tsirkin

At the moment it mirrors RSDT exactly.

---
 include/hw/acpi/acpi-defs.h | 15 ++++++++++++---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 41 ++++++++++++++++++++++++++++-------------
 hw/i386/acpi-build.c        | 29 ++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 21 deletions(-)
include/hw/acpi/acpi-defs.h +12 -3
index 59cf277..fe1dc7d 100644
@@ -201,13 +201,22 @@ enum {
  */
 struct AcpiRsdtDescriptorRev1
 {
-    ACPI_TABLE_HEADER_DEF       /* ACPI common table header */
-    uint32_t table_offset_entry[0];  /* Array of pointers to other */
-    /* ACPI tables */
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint32_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
 } QEMU_PACKED;
 typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
 
 /*
+ * ACPI 2.0 Extended System Description Table (XSDT)
+ */
+struct AcpiXsdtDescriptor
+{
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint64_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
+} QEMU_PACKED;
+typedef struct AcpiXsdtDescriptor AcpiXsdtDescriptor;
+
+/*
  * ACPI 1.0 Firmware ACPI Control Structure (FACS)
  */
 struct AcpiFacsDescriptorRev1
include/hw/acpi/aml-build.h +2 -0
index edc1dfa..0a00402 100644
@@ -287,5 +287,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 
 #endif
hw/acpi/aml-build.c +28 -13

53 lines not on this page · raw message

hw/i386/acpi-build.c +24 -5
index aaa149b..3551a08 100644
@@ -1593,7 +1593,7 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
 }
 
 static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
 
@@ -1602,16 +1602,33 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 
     memcpy(&rsdp->signature, "RSD PTR ", 8);
     memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
     rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
     /* Address to be filled by Guest linker */
     bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
                                    ACPI_BUILD_TABLE_FILE,
                                    rsdp_table, &rsdp->rsdt_physical_address,
                                    sizeof rsdp->rsdt_physical_address);
+
+    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   rsdp_table, &rsdp->xsdt_physical_address,
+                                   sizeof rsdp->xsdt_physical_address);
     rsdp->checksum = 0;
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
 
     return rsdp_table;
 }
@@ -1665,7 +1682,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 {
     GArray *rsdt_table_offsets;
     GArray *xsdt_table_offsets;
-    unsigned facs, ssdt, dsdt, rsdt;
+    unsigned facs, ssdt, dsdt, rsdt, xsdt;
     AcpiCpuInfo cpu;
     AcpiPmInfo pm;
     AcpiMiscInfo misc;
@@ -1762,12 +1779,14 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         g_array_append_vals(tables_blob, u, len);
     }
 
-    /* RSDT is pointed to by RSDP */
+    /* RSDT and XSDT pointed to by RSDP */
     rsdt = tables_blob->len;
     build_rsdt(tables_blob, tables->linker, rsdt_table_offsets);
+    xsdt = tables_blob->len;
+    build_xsdt(tables_blob, tables->linker, xsdt_table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, xsdt);
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
Signature · 1 line
MST
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets

In reply to Michael S. Tsirkin
Quoted 30 lines · Michael S. Tsirkin

Collecting these is useful for implementing the XSDT.

---
 include/hw/acpi/aml-build.h |  3 ++-
 hw/acpi/aml-build.c         | 13 ++++++++++---
 hw/arm/virt-acpi-build.c    |  8 ++++----
 hw/i386/acpi-build.c        | 20 ++++++++++----------
 4 files changed, 26 insertions(+), 18 deletions(-)
include/hw/acpi/aml-build.h +2 -1
index e3afa13..edc1dfa 100644
@@ -281,7 +281,8 @@ build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev);
 void *acpi_data_push(GArray *table_data, unsigned size);
 unsigned acpi_data_len(GArray *table);
-void acpi_add_table(GArray *table_offsets, GArray *table_data);
+void acpi_add_table(GArray *table_offsets32, GArray *table_offsets64,
+                    GArray *table_data);
 void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
hw/acpi/aml-build.c +0 -0
index 0d4b324..4c930b6 100644
@@ -1169,10 +1169,17 @@ unsigned acpi_data_len(GArray *table)
     return table->len;

hw/acpi/aml-build.c unsigned acpi_data_len(GArray *table) · line 1176

Quoted 10 lines
hw/acpi/aml-build.c +4 -3
 }
 
-void acpi_add_table(GArray *table_offsets, GArray *table_data)
+void acpi_add_table(GArray *table_offsets32, GArray *table_offsets64,
+                    GArray *table_data)
 {
-    uint32_t offset = cpu_to_le32(table_data->len);
-    g_array_append_val(table_offsets, offset);
+    uint32_t offset32 = cpu_to_le32(table_data->len);
+    uint64_t offset64 = cpu_to_le64(table_data->len);

Maybe move them into below if{} separately.

Quoted 101 lines
hw/acpi/aml-build.c +6 -0
+    if (table_offsets32) {
+        g_array_append_val(table_offsets32, offset32);
+    }
+    if (table_offsets64) {
+        g_array_append_val(table_offsets64, offset64);
+    }
 }
 
 void acpi_build_tables_init(AcpiBuildTables *tables)
hw/arm/virt-acpi-build.c +4 -4
index a9373cc..42c8dd9 100644
@@ -515,16 +515,16 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
     build_dsdt(tables_blob, tables->linker, guest_info);
 
     /* FADT MADT GTDT pointed to by RSDT */
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_fadt(tables_blob, tables->linker, dsdt);
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_madt(tables_blob, tables->linker, guest_info, &cpuinfo);
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_gtdt(tables_blob, tables->linker);
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_mcfg(tables_blob, tables->linker, guest_info);
 
     /* RSDT is pointed to by RSDP */
hw/i386/acpi-build.c +10 -10
index db32fd1..e5b0b7a 100644
@@ -1706,27 +1706,27 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     aml_len += tables_blob->len - dsdt;
 
     /* ACPI tables pointed to by RSDT */
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
 
     ssdt = tables_blob->len;
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
                guest_info);
     aml_len += tables_blob->len - ssdt;
 
-    acpi_add_table(table_offsets, tables_blob);
+    acpi_add_table(table_offsets, NULL, tables_blob);
     build_madt(tables_blob, tables->linker, &cpu, guest_info);
 
     if (misc.has_hpet) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_hpet(tables_blob, tables->linker);
     }
     if (misc.tpm_version != TPM_VERSION_UNSPEC) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         switch (misc.tpm_version) {
         case TPM_VERSION_1_2:
             build_tpm_ssdt(tables_blob, tables->linker);
@@ -1739,15 +1739,15 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         }
     }
     if (guest_info->numa_nodes) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_srat(tables_blob, tables->linker, guest_info);
     }
     if (acpi_get_mcfg(&mcfg)) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_mcfg_q35(tables_blob, tables->linker, &mcfg);
     }
     if (acpi_has_iommu()) {
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         build_dmar_q35(tables_blob, tables->linker);
     }
 
@@ -1755,7 +1755,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
         unsigned len = acpi_table_len(u);
 
-        acpi_add_table(table_offsets, tables_blob);
+        acpi_add_table(table_offsets, NULL, tables_blob);
         g_array_append_vals(tables_blob, u, len);
     }
 
Signature · 1 line
Shannon
#5 lore raw

Re: [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT

In reply to Michael S. Tsirkin
Quoted 86 lines · Michael S. Tsirkin

At the moment it mirrors RSDT exactly.

---
 include/hw/acpi/acpi-defs.h | 15 ++++++++++++---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 41 ++++++++++++++++++++++++++++-------------
 hw/i386/acpi-build.c        | 29 ++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 21 deletions(-)
include/hw/acpi/acpi-defs.h +12 -3
index 59cf277..fe1dc7d 100644
@@ -201,13 +201,22 @@ enum {
  */
 struct AcpiRsdtDescriptorRev1
 {
-    ACPI_TABLE_HEADER_DEF       /* ACPI common table header */
-    uint32_t table_offset_entry[0];  /* Array of pointers to other */
-    /* ACPI tables */
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint32_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
 } QEMU_PACKED;
 typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
 
 /*
+ * ACPI 2.0 Extended System Description Table (XSDT)
+ */
+struct AcpiXsdtDescriptor
+{
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint64_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
+} QEMU_PACKED;
+typedef struct AcpiXsdtDescriptor AcpiXsdtDescriptor;
+
+/*
  * ACPI 1.0 Firmware ACPI Control Structure (FACS)
  */
 struct AcpiFacsDescriptorRev1
include/hw/acpi/aml-build.h +2 -0
index edc1dfa..0a00402 100644
@@ -287,5 +287,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 
 #endif
hw/acpi/aml-build.c +12 -9
index 4c930b6..d0e52c4 100644
@@ -1200,25 +1200,40 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 }
 
 /* Build rsdt table */
-void
-build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+static void
+build_sdt(GArray *table_data, GArray *linker, GArray *table_offsets,
+          const char *sig, int entry_size)
 {
-    AcpiRsdtDescriptorRev1 *rsdt;
-    size_t rsdt_len;
+    AcpiTableHeader *sdt;
+    size_t sdt_len;
     int i;
-    const int table_data_len = (sizeof(uint32_t) * table_offsets->len);
+    const int table_data_len = (entry_size * table_offsets->len);
+    char *entries;
 
-    rsdt_len = sizeof(*rsdt) + table_data_len;
-    rsdt = acpi_data_push(table_data, rsdt_len);
-    memcpy(rsdt->table_offset_entry, table_offsets->data, table_data_len);
+    sdt_len = sizeof(*sdt) + table_data_len;
+    sdt = acpi_data_push(table_data, sdt_len);
+    entries = ((char *)sdt) + sizeof(*sdt);
+    memcpy(entries, table_offsets->data, table_data_len);
     for (i = 0; i < table_offsets->len; ++i) {
-        /* rsdt->table_offset_entry to be filled by Guest linker */
+        /* entry to be filled by Guest linker */
         bios_linker_loader_add_pointer(linker,

hw/acpi/aml-build.c void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) · line 1225

Quoted 10 lines
hw/acpi/aml-build.c +3 -4
                                        ACPI_BUILD_TABLE_FILE,
                                        ACPI_BUILD_TABLE_FILE,
-                                       table_data, &rsdt->table_offset_entry[i],
-                                       sizeof(uint32_t));
+                                       table_data, entries + i * entry_size,
+                                       entry_size);
     }
-    build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1);
+    build_header(linker, table_data, sdt, sig, sdt_len, 1);

The table revision should update as well. Make it as a parameter of build_sdt.

Quoted 19 lines
hw/acpi/aml-build.c +13 -0
+}
+
+void
+build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+    build_sdt(table_data, linker, table_offsets, "RSDT", sizeof(uint32_t));
+}
+
+/* Build xsdt table */
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+    build_sdt(table_data, linker, table_offsets, "XSDT", sizeof(uint64_t));
 }
hw/i386/acpi-build.c +0 -0
index aaa149b..3551a08 100644

hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc) · line 1596

Quoted 5 lines
hw/i386/acpi-build.c +1 -1
@@ -1593,7 +1593,7 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
 }
 
 static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)

uint64_t xsdt?

Quoted 9 lines
hw/i386/acpi-build.c +2 -0
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
 
@@ -1602,16 +1602,33 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 
     memcpy(&rsdp->signature, "RSD PTR ", 8);
     memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;

hw/i386/acpi-build.c build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt) · line 1616

Quoted 10 lines
hw/i386/acpi-build.c +4 -0
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
     rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
     /* Address to be filled by Guest linker */
     bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
                                    ACPI_BUILD_TABLE_FILE,
                                    rsdp_table, &rsdp->rsdt_physical_address,
                                    sizeof rsdp->rsdt_physical_address);
+
+    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);

cpu_to_le64(xsdt) ?

Quoted 46 lines
hw/i386/acpi-build.c +17 -4
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   rsdp_table, &rsdp->xsdt_physical_address,
+                                   sizeof rsdp->xsdt_physical_address);
     rsdp->checksum = 0;
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
 
     return rsdp_table;
 }
@@ -1665,7 +1682,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 {
     GArray *rsdt_table_offsets;
     GArray *xsdt_table_offsets;
-    unsigned facs, ssdt, dsdt, rsdt;
+    unsigned facs, ssdt, dsdt, rsdt, xsdt;
     AcpiCpuInfo cpu;
     AcpiPmInfo pm;
     AcpiMiscInfo misc;
@@ -1762,12 +1779,14 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         g_array_append_vals(tables_blob, u, len);
     }
 
-    /* RSDT is pointed to by RSDP */
+    /* RSDT and XSDT pointed to by RSDP */
     rsdt = tables_blob->len;
     build_rsdt(tables_blob, tables->linker, rsdt_table_offsets);
+    xsdt = tables_blob->len;
+    build_xsdt(tables_blob, tables->linker, xsdt_table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, xsdt);
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
Signature · 1 line
Shannon
#15 lore raw
In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin

XSDT support allows using ACPI 2 features while avoiding breaking legacy windows XP guests:
ACPI 2 tables are linked from XSDT only,
ACPI 1 tables from both RSDT and XSDT, this way XP does not see ACPI 2 tables.

Quoted 6 lines

As a first step, this patchset generates v2 RSDP and fills in XSDT matching RSDT exactly.

ARM patch is untested: I don't know how to test ARM ACPI. Testing reports would be greatly appreciated.

I've tested it on ARM, no error appears.

Quoted 13 lines

Michael S. Tsirkin (4):
acpi: add API for 64 bit offsets
i386/acpi: collect 64 bit offsets for xsdt
i386/acpi: add XSDT
acpi: unify rsdp generation

 include/hw/acpi/acpi-defs.h | 15 +++++--
 include/hw/acpi/aml-build.h |  7 +++-
 hw/acpi/aml-build.c         | 99 +++++++++++++++++++++++++++++++++++++--------
 hw/arm/virt-acpi-build.c    | 39 +++---------------
 hw/i386/acpi-build.c        | 64 +++++++++++------------------
 5 files changed, 129 insertions(+), 95 deletions(-)
Signature · 1 line
Shannon
#9 lore raw

Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation

In reply to Michael S. Tsirkin
Quoted 119 lines · Michael S. Tsirkin

Now that both i386 and arm use v2 tables,
use common code for both.

Warning: untested.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 31 +------------------------------
 hw/i386/acpi-build.c        | 41 -----------------------------------------
 4 files changed, 48 insertions(+), 71 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0a00402..ae169fa 100644
@@ -289,5 +289,7 @@ void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 void
 build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt);
 
 #endif
hw/acpi/aml-build.c +45 -0
index d0e52c4..d0bd953 100644
@@ -1237,3 +1237,48 @@ build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
 {
     build_sdt(table_data, linker, table_offsets, "XSDT", sizeof(uint64_t));
 }
+
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
+{
+    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
+
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
+                             true /* fseg memory */);
+
+    memcpy(&rsdp->signature, "RSD PTR ", 8);
+    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
+    if (rsdt) {
+        rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
+        /* Address to be filled by Guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       rsdp_table, &rsdp->rsdt_physical_address,
+                                       sizeof rsdp->rsdt_physical_address);
+    }
+
+    if (xsdt) {
+        rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       rsdp_table, &rsdp->xsdt_physical_address,
+                                       sizeof rsdp->xsdt_physical_address);
+    }
+    rsdp->checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
+
+    return rsdp_table;
+}
hw/arm/virt-acpi-build.c +0 -29
index 42c8dd9..c164f65 100644
@@ -304,35 +304,6 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, int irq)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
-    rsdp->length = cpu_to_le32(sizeof(*rsdp));
-    rsdp->revision = 0x02;
-
-    /* Point to RSDT */
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
-
-    return rsdp_table;
-}
-
 static void
 build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {

hw/arm/virt-acpi-build.c void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables) · line 507

Quoted 6 lines
hw/arm/virt-acpi-build.c +1 -1
@@ -532,7 +503,7 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
     build_rsdt(tables_blob, tables->linker, table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, 0);
 

So ARM virt can use xsdt as well. Maybe could do by another patch on top of this.

Quoted 55 lines
hw/arm/virt-acpi-build.c +0 -0
     /* Cleanup memory that's no longer used. */
     g_array_free(table_offsets, true);
hw/i386/acpi-build.c +0 -41
index 3551a08..8c6d7f5 100644
@@ -1592,47 +1592,6 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
                  misc->dsdt_size, 1);
 }
 
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", 8);
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
-
-    rsdp->revision = 0x02;
-    rsdp->length = cpu_to_le32(sizeof *rsdp);
-
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-
-    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->xsdt_physical_address,
-                                   sizeof rsdp->xsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
-                                    &rsdp->checksum);
-
-    rsdp->extended_checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp,
-                                    &rsdp->extended_checksum);
-
-    return rsdp_table;
-}
-
 typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
Signature · 1 line
Shannon
#6 lore raw

Re: [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT

In reply to Shannon Zhao
Quoted 94 lines · Shannon Zhao
Quoted 91 lines · Michael S. Tsirkin

At the moment it mirrors RSDT exactly.

---
 include/hw/acpi/acpi-defs.h | 15 ++++++++++++---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 41 ++++++++++++++++++++++++++++-------------
 hw/i386/acpi-build.c        | 29 ++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 21 deletions(-)
include/hw/acpi/acpi-defs.h +12 -3
index 59cf277..fe1dc7d 100644
@@ -201,13 +201,22 @@ enum {
  */
 struct AcpiRsdtDescriptorRev1
 {
-    ACPI_TABLE_HEADER_DEF       /* ACPI common table header */
-    uint32_t table_offset_entry[0];  /* Array of pointers to other */
-    /* ACPI tables */
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint32_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
 } QEMU_PACKED;
 typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
 
 /*
+ * ACPI 2.0 Extended System Description Table (XSDT)
+ */
+struct AcpiXsdtDescriptor
+{
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint64_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
+} QEMU_PACKED;
+typedef struct AcpiXsdtDescriptor AcpiXsdtDescriptor;
+
+/*
  * ACPI 1.0 Firmware ACPI Control Structure (FACS)
  */
 struct AcpiFacsDescriptorRev1
include/hw/acpi/aml-build.h +2 -0
index edc1dfa..0a00402 100644
@@ -287,5 +287,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 
 #endif
hw/acpi/aml-build.c +13 -11
index 4c930b6..d0e52c4 100644
@@ -1200,25 +1200,40 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 }
 
 /* Build rsdt table */
-void
-build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+static void
+build_sdt(GArray *table_data, GArray *linker, GArray *table_offsets,
+          const char *sig, int entry_size)
 {
-    AcpiRsdtDescriptorRev1 *rsdt;
-    size_t rsdt_len;
+    AcpiTableHeader *sdt;
+    size_t sdt_len;
     int i;
-    const int table_data_len = (sizeof(uint32_t) * table_offsets->len);
+    const int table_data_len = (entry_size * table_offsets->len);
+    char *entries;
 
-    rsdt_len = sizeof(*rsdt) + table_data_len;
-    rsdt = acpi_data_push(table_data, rsdt_len);
-    memcpy(rsdt->table_offset_entry, table_offsets->data, table_data_len);
+    sdt_len = sizeof(*sdt) + table_data_len;
+    sdt = acpi_data_push(table_data, sdt_len);
+    entries = ((char *)sdt) + sizeof(*sdt);
+    memcpy(entries, table_offsets->data, table_data_len);
     for (i = 0; i < table_offsets->len; ++i) {
-        /* rsdt->table_offset_entry to be filled by Guest linker */
+        /* entry to be filled by Guest linker */
         bios_linker_loader_add_pointer(linker,
                                        ACPI_BUILD_TABLE_FILE,
                                        ACPI_BUILD_TABLE_FILE,
-                                       table_data, &rsdt->table_offset_entry[i],
-                                       sizeof(uint32_t));
+                                       table_data, entries + i * entry_size,
Quoted 8 lines

hw/acpi/aml-build.c void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) · line 1225

Quoted 5 lines
hw/acpi/aml-build.c +2 -2
+                                       entry_size);
     }
-    build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1);
+    build_header(linker, table_data, sdt, sig, sdt_len, 1);

The table revision should update as well. Make it as a parameter of build_sdt.

How do you figure this?
The spec I have lists XSDT revision as 1.

Quoted 21 lines
Quoted 21 lines
hw/acpi/aml-build.c +13 -0
+}
+
+void
+build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+    build_sdt(table_data, linker, table_offsets, "RSDT", sizeof(uint32_t));
+}
+
+/* Build xsdt table */
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+    build_sdt(table_data, linker, table_offsets, "XSDT", sizeof(uint64_t));
 }
hw/i386/acpi-build.c +0 -0
index aaa149b..3551a08 100644
@@ -1593,7 +1593,7 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
 }
 
Quoted 5 lines

hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc) · line 1596

Quoted 3 lines
hw/i386/acpi-build.c +1 -1
 static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)

uint64_t xsdt?

No, because it's an offset within the blob, not the physical address. We can't really ask bios to allocate > 4G blob for us.

Quoted 5 lines
Quoted 5 lines
hw/i386/acpi-build.c +0 -0
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
 
@@ -1602,16 +1602,33 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 
Quoted 16 lines
Quoted 4 lines
hw/i386/acpi-build.c +2 -0
     memcpy(&rsdp->signature, "RSD PTR ", 8);
     memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;

hw/i386/acpi-build.c build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt) · line 1616

Quoted 10 lines
hw/i386/acpi-build.c +4 -0
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
     rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
     /* Address to be filled by Guest linker */
     bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
                                    ACPI_BUILD_TABLE_FILE,
                                    rsdp_table, &rsdp->rsdt_physical_address,
                                    sizeof rsdp->rsdt_physical_address);
+
+    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);

cpu_to_le64(xsdt) ?

Good catch. Will fix, thanks!

Quoted 49 lines
Quoted 46 lines
hw/i386/acpi-build.c +17 -4
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   rsdp_table, &rsdp->xsdt_physical_address,
+                                   sizeof rsdp->xsdt_physical_address);
     rsdp->checksum = 0;
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
 
     return rsdp_table;
 }
@@ -1665,7 +1682,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 {
     GArray *rsdt_table_offsets;
     GArray *xsdt_table_offsets;
-    unsigned facs, ssdt, dsdt, rsdt;
+    unsigned facs, ssdt, dsdt, rsdt, xsdt;
     AcpiCpuInfo cpu;
     AcpiPmInfo pm;
     AcpiMiscInfo misc;
@@ -1762,12 +1779,14 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         g_array_append_vals(tables_blob, u, len);
     }
 
-    /* RSDT is pointed to by RSDP */
+    /* RSDT and XSDT pointed to by RSDP */
     rsdt = tables_blob->len;
     build_rsdt(tables_blob, tables->linker, rsdt_table_offsets);
+    xsdt = tables_blob->len;
+    build_xsdt(tables_blob, tables->linker, xsdt_table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, xsdt);
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
Signature · 1 line
Shannon
#10 lore raw

Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation

In reply to Shannon Zhao
Quoted 124 lines · Shannon Zhao
Quoted 121 lines · Michael S. Tsirkin

Now that both i386 and arm use v2 tables,
use common code for both.

Warning: untested.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 31 +------------------------------
 hw/i386/acpi-build.c        | 41 -----------------------------------------
 4 files changed, 48 insertions(+), 71 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0a00402..ae169fa 100644
@@ -289,5 +289,7 @@ void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 void
 build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt);
 
 #endif
hw/acpi/aml-build.c +45 -0
index d0e52c4..d0bd953 100644
@@ -1237,3 +1237,48 @@ build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
 {
     build_sdt(table_data, linker, table_offsets, "XSDT", sizeof(uint64_t));
 }
+
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
+{
+    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
+
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
+                             true /* fseg memory */);
+
+    memcpy(&rsdp->signature, "RSD PTR ", 8);
+    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
+    if (rsdt) {
+        rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
+        /* Address to be filled by Guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       rsdp_table, &rsdp->rsdt_physical_address,
+                                       sizeof rsdp->rsdt_physical_address);
+    }
+
+    if (xsdt) {
+        rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       rsdp_table, &rsdp->xsdt_physical_address,
+                                       sizeof rsdp->xsdt_physical_address);
+    }
+    rsdp->checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
+
+    return rsdp_table;
+}
hw/arm/virt-acpi-build.c +0 -29
index 42c8dd9..c164f65 100644
@@ -304,35 +304,6 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, int irq)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
-    rsdp->length = cpu_to_le32(sizeof(*rsdp));
-    rsdp->revision = 0x02;
-
-    /* Point to RSDT */
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
-
-    return rsdp_table;
-}
-
 static void
 build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {
@@ -532,7 +503,7 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
     build_rsdt(tables_blob, tables->linker, table_offsets);
 
Quoted 7 lines

hw/arm/virt-acpi-build.c void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables) · line 507

Quoted 4 lines
hw/arm/virt-acpi-build.c +1 -1
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, 0);
 

So ARM virt can use xsdt as well. Maybe could do by another patch on top of this.

In fact, there's probably no reason to have an rsdt at all.

But how does one test ARM ACPI code?
Could you upload an image with instructions to the wiki?
http://wiki.qemu.org/System_Images

Quoted 58 lines
Quoted 55 lines
hw/arm/virt-acpi-build.c +0 -0
     /* Cleanup memory that's no longer used. */
     g_array_free(table_offsets, true);
hw/i386/acpi-build.c +0 -41
index 3551a08..8c6d7f5 100644
@@ -1592,47 +1592,6 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
                  misc->dsdt_size, 1);
 }
 
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", 8);
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
-
-    rsdp->revision = 0x02;
-    rsdp->length = cpu_to_le32(sizeof *rsdp);
-
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-
-    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->xsdt_physical_address,
-                                   sizeof rsdp->xsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
-                                    &rsdp->checksum);
-
-    rsdp->extended_checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp,
-                                    &rsdp->extended_checksum);
-
-    return rsdp_table;
-}
-
 typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
Signature · 1 line
Shannon
#7 lore raw

Re: [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT

In reply to Michael S. Tsirkin
Quoted 104 lines · Michael S. Tsirkin
Quoted 94 lines · Shannon Zhao
Quoted 91 lines · Michael S. Tsirkin

At the moment it mirrors RSDT exactly.

---
 include/hw/acpi/acpi-defs.h | 15 ++++++++++++---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 41 ++++++++++++++++++++++++++++-------------
 hw/i386/acpi-build.c        | 29 ++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 21 deletions(-)
include/hw/acpi/acpi-defs.h +12 -3
index 59cf277..fe1dc7d 100644
@@ -201,13 +201,22 @@ enum {
  */
 struct AcpiRsdtDescriptorRev1
 {
-    ACPI_TABLE_HEADER_DEF       /* ACPI common table header */
-    uint32_t table_offset_entry[0];  /* Array of pointers to other */
-    /* ACPI tables */
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint32_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
 } QEMU_PACKED;
 typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
 
 /*
+ * ACPI 2.0 Extended System Description Table (XSDT)
+ */
+struct AcpiXsdtDescriptor
+{
+    ACPI_TABLE_HEADER_DEF           /* ACPI common table header */
+    uint64_t table_offset_entry[0]; /* Array of pointers to other ACPI tables */
+} QEMU_PACKED;
+typedef struct AcpiXsdtDescriptor AcpiXsdtDescriptor;
+
+/*
  * ACPI 1.0 Firmware ACPI Control Structure (FACS)
  */
 struct AcpiFacsDescriptorRev1
include/hw/acpi/aml-build.h +2 -0
index edc1dfa..0a00402 100644
@@ -287,5 +287,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 
 #endif
hw/acpi/aml-build.c +13 -11
index 4c930b6..d0e52c4 100644
@@ -1200,25 +1200,40 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 }
 
 /* Build rsdt table */
-void
-build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+static void
+build_sdt(GArray *table_data, GArray *linker, GArray *table_offsets,
+          const char *sig, int entry_size)
 {
-    AcpiRsdtDescriptorRev1 *rsdt;
-    size_t rsdt_len;
+    AcpiTableHeader *sdt;
+    size_t sdt_len;
     int i;
-    const int table_data_len = (sizeof(uint32_t) * table_offsets->len);
+    const int table_data_len = (entry_size * table_offsets->len);
+    char *entries;
 
-    rsdt_len = sizeof(*rsdt) + table_data_len;
-    rsdt = acpi_data_push(table_data, rsdt_len);
-    memcpy(rsdt->table_offset_entry, table_offsets->data, table_data_len);
+    sdt_len = sizeof(*sdt) + table_data_len;
+    sdt = acpi_data_push(table_data, sdt_len);
+    entries = ((char *)sdt) + sizeof(*sdt);
+    memcpy(entries, table_offsets->data, table_data_len);
     for (i = 0; i < table_offsets->len; ++i) {
-        /* rsdt->table_offset_entry to be filled by Guest linker */
+        /* entry to be filled by Guest linker */
         bios_linker_loader_add_pointer(linker,
                                        ACPI_BUILD_TABLE_FILE,
                                        ACPI_BUILD_TABLE_FILE,
-                                       table_data, &rsdt->table_offset_entry[i],
-                                       sizeof(uint32_t));
+                                       table_data, entries + i * entry_size,
Quoted 8 lines

hw/acpi/aml-build.c void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) · line 1225

Quoted 5 lines
hw/acpi/aml-build.c +2 -2
+                                       entry_size);
     }
-    build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1);
+    build_header(linker, table_data, sdt, sig, sdt_len, 1);

The table revision should update as well. Make it as a parameter of build_sdt.

Quoted 3 lines

How do you figure this?
The spec I have lists XSDT revision as 1.

Oh, sorry, ignore this.

Quoted 106 lines
Quoted 21 lines
Quoted 21 lines
hw/acpi/aml-build.c +13 -0
+}
+
+void
+build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+    build_sdt(table_data, linker, table_offsets, "RSDT", sizeof(uint32_t));
+}
+
+/* Build xsdt table */
+void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+    build_sdt(table_data, linker, table_offsets, "XSDT", sizeof(uint64_t));
 }
hw/i386/acpi-build.c +0 -0
index aaa149b..3551a08 100644
@@ -1593,7 +1593,7 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
 }
 
Quoted 5 lines

hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc) · line 1596

Quoted 3 lines
hw/i386/acpi-build.c +1 -1
 static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)

uint64_t xsdt?

No, because it's an offset within the blob, not the physical address. We can't really ask bios to allocate > 4G blob for us.

Quoted 5 lines
Quoted 5 lines
hw/i386/acpi-build.c +0 -0
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
 
@@ -1602,16 +1602,33 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 
Quoted 16 lines
Quoted 4 lines
hw/i386/acpi-build.c +2 -0
     memcpy(&rsdp->signature, "RSD PTR ", 8);
     memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;

hw/i386/acpi-build.c build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt) · line 1616

Quoted 10 lines
hw/i386/acpi-build.c +4 -0
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
     rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
     /* Address to be filled by Guest linker */
     bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
                                    ACPI_BUILD_TABLE_FILE,
                                    rsdp_table, &rsdp->rsdt_physical_address,
                                    sizeof rsdp->rsdt_physical_address);
+
+    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);

cpu_to_le64(xsdt) ?

Good catch. Will fix, thanks!

Quoted 39 lines
Quoted 39 lines
hw/i386/acpi-build.c +16 -3
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   rsdp_table, &rsdp->xsdt_physical_address,
+                                   sizeof rsdp->xsdt_physical_address);
     rsdp->checksum = 0;
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
 
     return rsdp_table;
 }
@@ -1665,7 +1682,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 {
     GArray *rsdt_table_offsets;
     GArray *xsdt_table_offsets;
-    unsigned facs, ssdt, dsdt, rsdt;
+    unsigned facs, ssdt, dsdt, rsdt, xsdt;
     AcpiCpuInfo cpu;
     AcpiPmInfo pm;
     AcpiMiscInfo misc;
@@ -1762,12 +1779,14 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         g_array_append_vals(tables_blob, u, len);
     }
 
-    /* RSDT is pointed to by RSDP */
+    /* RSDT and XSDT pointed to by RSDP */
     rsdt = tables_blob->len;
     build_rsdt(tables_blob, tables->linker, rsdt_table_offsets);
+    xsdt = tables_blob->len;
+    build_xsdt(tables_blob, tables->linker, xsdt_table_offsets);
 
Quoted 10 lines
Quoted 7 lines
hw/i386/acpi-build.c +1 -1
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, xsdt);
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
Signature · 1 line
Shannon

.

Signature · 1 line
Shannon
#11 lore raw

Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation

In reply to Michael S. Tsirkin
Quoted 133 lines · Michael S. Tsirkin
Quoted 124 lines · Shannon Zhao
Quoted 121 lines · Michael S. Tsirkin

Now that both i386 and arm use v2 tables,
use common code for both.

Warning: untested.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 31 +------------------------------
 hw/i386/acpi-build.c        | 41 -----------------------------------------
 4 files changed, 48 insertions(+), 71 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0a00402..ae169fa 100644
@@ -289,5 +289,7 @@ void
 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
 void
 build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt);
 
 #endif
hw/acpi/aml-build.c +45 -0
index d0e52c4..d0bd953 100644
@@ -1237,3 +1237,48 @@ build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
 {
     build_sdt(table_data, linker, table_offsets, "XSDT", sizeof(uint64_t));
 }
+
+GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
+{
+    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
+
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
+                             true /* fseg memory */);
+
+    memcpy(&rsdp->signature, "RSD PTR ", 8);
+    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    rsdp->revision = 0x02;
+    rsdp->length = cpu_to_le32(sizeof *rsdp);
+
+    if (rsdt) {
+        rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
+        /* Address to be filled by Guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       rsdp_table, &rsdp->rsdt_physical_address,
+                                       sizeof rsdp->rsdt_physical_address);
+    }
+
+    if (xsdt) {
+        rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       rsdp_table, &rsdp->xsdt_physical_address,
+                                       sizeof rsdp->xsdt_physical_address);
+    }
+    rsdp->checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
+                                    &rsdp->checksum);
+
+    rsdp->extended_checksum = 0;
+    /* Checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    rsdp, rsdp, sizeof *rsdp,
+                                    &rsdp->extended_checksum);
+
+    return rsdp_table;
+}
hw/arm/virt-acpi-build.c +0 -29
index 42c8dd9..c164f65 100644
@@ -304,35 +304,6 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, int irq)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
-    rsdp->length = cpu_to_le32(sizeof(*rsdp));
-    rsdp->revision = 0x02;
-
-    /* Point to RSDT */
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
-
-    return rsdp_table;
-}
-
 static void
 build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {
@@ -532,7 +503,7 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
     build_rsdt(tables_blob, tables->linker, table_offsets);
 
Quoted 7 lines

hw/arm/virt-acpi-build.c void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables) · line 507

Quoted 4 lines
hw/arm/virt-acpi-build.c +1 -1
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    build_rsdp(tables->rsdp, tables->linker, rsdt, 0);
 

So ARM virt can use xsdt as well. Maybe could do by another patch on top of this.

Quoted 6 lines

In fact, there's probably no reason to have an rsdt at all.

But how does one test ARM ACPI code?
Could you upload an image with instructions to the wiki?
http://wiki.qemu.org/System_Images

Ok, no problem. But I don't have an account of the wiki.

Quoted 62 lines
Quoted 48 lines
Quoted 48 lines
hw/arm/virt-acpi-build.c +0 -0
     /* Cleanup memory that's no longer used. */
     g_array_free(table_offsets, true);
hw/i386/acpi-build.c +0 -37
index 3551a08..8c6d7f5 100644
@@ -1592,47 +1592,6 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
                  misc->dsdt_size, 1);
 }
 
-static GArray *
-build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt, unsigned xsdt)
-{
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", 8);
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
-
-    rsdp->revision = 0x02;
-    rsdp->length = cpu_to_le32(sizeof *rsdp);
-
-    rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->rsdt_physical_address,
-                                   sizeof rsdp->rsdt_physical_address);
-
-    rsdp->xsdt_physical_address = cpu_to_le32(xsdt);
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   rsdp_table, &rsdp->xsdt_physical_address,
-                                   sizeof rsdp->xsdt_physical_address);
-    rsdp->checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, offsetof(AcpiRsdpDescriptor, length),
-                                    &rsdp->checksum);
-
-    rsdp->extended_checksum = 0;
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    rsdp, rsdp, sizeof *rsdp,
-                                    &rsdp->extended_checksum);
Quoted 11 lines
Quoted 8 lines
hw/i386/acpi-build.c +0 -4
-
-    return rsdp_table;
-}
-
 typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
Signature · 1 line
Shannon

.

Signature · 1 line
Shannon
#12 lore raw

Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation

Quoted 6 lines · Shannon Zhao
Quoted 4 lines

But how does one test ARM ACPI code?
Could you upload an image with instructions to the wiki?
http://wiki.qemu.org/System_Images

Ok, no problem. But I don't have an account of the wiki.

Stefan, you have admin rights there, right?

Signature · 1 line
MST
#13 lore raw

Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation

Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Shannon Zhao
Quoted 4 lines

But how does one test ARM ACPI code?
Could you upload an image with instructions to the wiki?
http://wiki.qemu.org/System_Images

Ok, no problem. But I don't have an account of the wiki.

Stefan, you have admin rights there, right?

Done.

Stefan

#14 lore raw

Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation

In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Shannon Zhao
Quoted 4 lines

But how does one test ARM ACPI code?
Could you upload an image with instructions to the wiki?
http://wiki.qemu.org/System_Images

Ok, no problem. But I don't have an account of the wiki.

Stefan, you have admin rights there, right?

For the record, all existing users can can create new accounts:

1. Log in: http://qemu-project.org/Special:UserLogin
2. Go to the login page again: http://qemu-project.org/Special:UserLogin
3. Click "Create account"

No special privileges are required.

Stefan