qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] acpi: xsdt support
@ 2015-06-04 16:21 Michael S. Tsirkin
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets Michael S. Tsirkin
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-04 16:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: ghammer, pbonzini, lersek, shannon.zhao, imammedo

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(-)

-- 
MST

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets
  2015-06-04 16:21 [Qemu-devel] [PATCH 0/4] acpi: xsdt support Michael S. Tsirkin
@ 2015-06-04 16:21 ` Michael S. Tsirkin
  2015-06-05  2:38   ` Shannon Zhao
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 2/4] i386/acpi: collect 64 bit offsets for xsdt Michael S. Tsirkin
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-04 16:21 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Eduardo Habkost, ghammer, shannon.zhao, imammedo,
	pbonzini, lersek, Richard Henderson

Collecting these is useful for implementing the XSDT.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index e3afa13..edc1dfa 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -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
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 0d4b324..4c930b6 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -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)
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index a9373cc..42c8dd9 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -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 */
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index db32fd1..e5b0b7a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
     }
 
-- 
MST

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 2/4] i386/acpi: collect 64 bit offsets for xsdt
  2015-06-04 16:21 [Qemu-devel] [PATCH 0/4] acpi: xsdt support Michael S. Tsirkin
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets Michael S. Tsirkin
@ 2015-06-04 16:21 ` Michael S. Tsirkin
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT Michael S. Tsirkin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-04 16:21 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, ghammer, shannon.zhao, imammedo, pbonzini,
	lersek, Richard Henderson

collect then discard, they are unused for now.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index e5b0b7a..aaa149b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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)
-- 
MST

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT
  2015-06-04 16:21 [Qemu-devel] [PATCH 0/4] acpi: xsdt support Michael S. Tsirkin
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets Michael S. Tsirkin
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 2/4] i386/acpi: collect 64 bit offsets for xsdt Michael S. Tsirkin
@ 2015-06-04 16:21 ` Michael S. Tsirkin
  2015-06-05  2:38   ` Shannon Zhao
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation Michael S. Tsirkin
  2015-06-05  2:48 ` [Qemu-devel] [PATCH 0/4] acpi: xsdt support Shannon Zhao
  4 siblings, 1 reply; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-04 16:21 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, ghammer, shannon.zhao, imammedo, pbonzini,
	lersek, Richard Henderson

At the moment it mirrors RSDT exactly.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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(-)

diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 59cf277..fe1dc7d 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -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
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index edc1dfa..0a00402 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -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
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 4c930b6..d0e52c4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -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,
+                                       entry_size);
     }
-    build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1);
+    build_header(linker, table_data, sdt, sig, sdt_len, 1);
+}
+
+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));
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index aaa149b..3551a08 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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.
-- 
MST

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-04 16:21 [Qemu-devel] [PATCH 0/4] acpi: xsdt support Michael S. Tsirkin
                   ` (2 preceding siblings ...)
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT Michael S. Tsirkin
@ 2015-06-04 16:21 ` Michael S. Tsirkin
  2015-06-05  2:47   ` Shannon Zhao
  2015-06-05  2:48 ` [Qemu-devel] [PATCH 0/4] acpi: xsdt support Shannon Zhao
  4 siblings, 1 reply; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-04 16:21 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Eduardo Habkost, ghammer, shannon.zhao, imammedo,
	pbonzini, lersek, Richard Henderson

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

Warning: untested.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 0a00402..ae169fa 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -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
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d0e52c4..d0bd953 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -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;
+}
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 42c8dd9..c164f65 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -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);
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 3551a08..8c6d7f5 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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). */
-- 
MST

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT Michael S. Tsirkin
@ 2015-06-05  2:38   ` Shannon Zhao
  2015-06-07  9:42     ` Michael S. Tsirkin
  0 siblings, 1 reply; 16+ messages in thread
From: Shannon Zhao @ 2015-06-05  2:38 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Eduardo Habkost, ghammer, shannon.zhao, pbonzini, imammedo,
	lersek, Richard Henderson



On 2015/6/5 0:21, Michael S. Tsirkin wrote:
> At the moment it mirrors RSDT exactly.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  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(-)
> 
> diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
> index 59cf277..fe1dc7d 100644
> --- a/include/hw/acpi/acpi-defs.h
> +++ b/include/hw/acpi/acpi-defs.h
> @@ -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
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index edc1dfa..0a00402 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -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
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 4c930b6..d0e52c4 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -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,
> +                                       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.

> +}
> +
> +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));
>  }
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index aaa149b..3551a08 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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?

>  {
>      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);

cpu_to_le64(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.
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets Michael S. Tsirkin
@ 2015-06-05  2:38   ` Shannon Zhao
  0 siblings, 0 replies; 16+ messages in thread
From: Shannon Zhao @ 2015-06-05  2:38 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Peter Maydell, Eduardo Habkost, ghammer, shannon.zhao, pbonzini,
	imammedo, lersek, Richard Henderson



On 2015/6/5 0:21, Michael S. Tsirkin wrote:
> Collecting these is useful for implementing the XSDT.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  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(-)
> 
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index e3afa13..edc1dfa 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -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
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 0d4b324..4c930b6 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -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);

Maybe move them into below if{} separately.

> +    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)
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index a9373cc..42c8dd9 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -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 */
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index db32fd1..e5b0b7a 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>      }
>  
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation Michael S. Tsirkin
@ 2015-06-05  2:47   ` Shannon Zhao
  2015-06-07  9:45     ` Michael S. Tsirkin
  0 siblings, 1 reply; 16+ messages in thread
From: Shannon Zhao @ 2015-06-05  2:47 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Peter Maydell, Eduardo Habkost, ghammer, shannon.zhao, pbonzini,
	imammedo, lersek, Richard Henderson



On 2015/6/5 0:21, Michael S. Tsirkin wrote:
> Now that both i386 and arm use v2 tables,
> use common code for both.
> 
> Warning: untested.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  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(-)
> 
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 0a00402..ae169fa 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -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
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index d0e52c4..d0bd953 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -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;
> +}
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index 42c8dd9..c164f65 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -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);
>  

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

>      /* Cleanup memory that's no longer used. */
>      g_array_free(table_offsets, true);
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 3551a08..8c6d7f5 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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). */
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 0/4] acpi: xsdt support
  2015-06-04 16:21 [Qemu-devel] [PATCH 0/4] acpi: xsdt support Michael S. Tsirkin
                   ` (3 preceding siblings ...)
  2015-06-04 16:21 ` [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation Michael S. Tsirkin
@ 2015-06-05  2:48 ` Shannon Zhao
  4 siblings, 0 replies; 16+ messages in thread
From: Shannon Zhao @ 2015-06-05  2:48 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: ghammer, pbonzini, lersek, shannon.zhao, imammedo



On 2015/6/5 0:21, Michael S. Tsirkin wrote:
> 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.
> 

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

> 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(-)
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT
  2015-06-05  2:38   ` Shannon Zhao
@ 2015-06-07  9:42     ` Michael S. Tsirkin
  2015-06-08  1:49       ` Shannon Zhao
  0 siblings, 1 reply; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-07  9:42 UTC (permalink / raw)
  To: Shannon Zhao
  Cc: Eduardo Habkost, ghammer, qemu-devel, shannon.zhao, pbonzini,
	imammedo, lersek, Richard Henderson

On Fri, Jun 05, 2015 at 10:38:24AM +0800, Shannon Zhao wrote:
> 
> 
> On 2015/6/5 0:21, Michael S. Tsirkin wrote:
> > At the moment it mirrors RSDT exactly.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  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(-)
> > 
> > diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
> > index 59cf277..fe1dc7d 100644
> > --- a/include/hw/acpi/acpi-defs.h
> > +++ b/include/hw/acpi/acpi-defs.h
> > @@ -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
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index edc1dfa..0a00402 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -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
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 4c930b6..d0e52c4 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -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,
> > +                                       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.

> > +}
> > +
> > +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));
> >  }
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index aaa149b..3551a08 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -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?

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.

> >  {
> >      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);
> 
> cpu_to_le64(xsdt) ?

Good catch. Will fix, thanks!

> > +    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.
> > 
> 
> -- 
> Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-05  2:47   ` Shannon Zhao
@ 2015-06-07  9:45     ` Michael S. Tsirkin
  2015-06-08  1:52       ` Shannon Zhao
  0 siblings, 1 reply; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-07  9:45 UTC (permalink / raw)
  To: Shannon Zhao
  Cc: Peter Maydell, Eduardo Habkost, ghammer, qemu-devel, shannon.zhao,
	pbonzini, imammedo, lersek, Richard Henderson

On Fri, Jun 05, 2015 at 10:47:16AM +0800, Shannon Zhao wrote:
> 
> 
> On 2015/6/5 0:21, Michael S. Tsirkin wrote:
> > Now that both i386 and arm use v2 tables,
> > use common code for both.
> > 
> > Warning: untested.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  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(-)
> > 
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index 0a00402..ae169fa 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -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
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index d0e52c4..d0bd953 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -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;
> > +}
> > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> > index 42c8dd9..c164f65 100644
> > --- a/hw/arm/virt-acpi-build.c
> > +++ b/hw/arm/virt-acpi-build.c
> > @@ -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);
> >  
> 
> 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


> >      /* Cleanup memory that's no longer used. */
> >      g_array_free(table_offsets, true);
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 3551a08..8c6d7f5 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -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). */
> > 
> 
> -- 
> Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT
  2015-06-07  9:42     ` Michael S. Tsirkin
@ 2015-06-08  1:49       ` Shannon Zhao
  0 siblings, 0 replies; 16+ messages in thread
From: Shannon Zhao @ 2015-06-08  1:49 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Eduardo Habkost, ghammer, qemu-devel, shannon.zhao, pbonzini,
	imammedo, lersek, Richard Henderson



On 2015/6/7 17:42, Michael S. Tsirkin wrote:
> On Fri, Jun 05, 2015 at 10:38:24AM +0800, Shannon Zhao wrote:
>>
>>
>> On 2015/6/5 0:21, Michael S. Tsirkin wrote:
>>> At the moment it mirrors RSDT exactly.
>>>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> ---
>>>  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(-)
>>>
>>> diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
>>> index 59cf277..fe1dc7d 100644
>>> --- a/include/hw/acpi/acpi-defs.h
>>> +++ b/include/hw/acpi/acpi-defs.h
>>> @@ -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
>>> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
>>> index edc1dfa..0a00402 100644
>>> --- a/include/hw/acpi/aml-build.h
>>> +++ b/include/hw/acpi/aml-build.h
>>> @@ -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
>>> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
>>> index 4c930b6..d0e52c4 100644
>>> --- a/hw/acpi/aml-build.c
>>> +++ b/hw/acpi/aml-build.c
>>> @@ -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,
>>> +                                       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.
>

Oh, sorry, ignore this.

>>> +}
>>> +
>>> +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));
>>>  }
>>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>>> index aaa149b..3551a08 100644
>>> --- a/hw/i386/acpi-build.c
>>> +++ b/hw/i386/acpi-build.c
>>> @@ -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?
> 
> 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.
> 
>>>  {
>>>      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);
>>
>> cpu_to_le64(xsdt) ?
> 
> Good catch. Will fix, thanks!
> 
>>> +    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.
>>>
>>
>> -- 
>> Shannon
> 
> .
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-07  9:45     ` Michael S. Tsirkin
@ 2015-06-08  1:52       ` Shannon Zhao
  2015-06-08  7:24         ` Michael S. Tsirkin
  0 siblings, 1 reply; 16+ messages in thread
From: Shannon Zhao @ 2015-06-08  1:52 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Peter Maydell, Eduardo Habkost, ghammer, qemu-devel, shannon.zhao,
	pbonzini, imammedo, lersek, Richard Henderson



On 2015/6/7 17:45, Michael S. Tsirkin wrote:
> On Fri, Jun 05, 2015 at 10:47:16AM +0800, Shannon Zhao wrote:
>>
>>
>> On 2015/6/5 0:21, Michael S. Tsirkin wrote:
>>> Now that both i386 and arm use v2 tables,
>>> use common code for both.
>>>
>>> Warning: untested.
>>>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> ---
>>>  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(-)
>>>
>>> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
>>> index 0a00402..ae169fa 100644
>>> --- a/include/hw/acpi/aml-build.h
>>> +++ b/include/hw/acpi/aml-build.h
>>> @@ -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
>>> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
>>> index d0e52c4..d0bd953 100644
>>> --- a/hw/acpi/aml-build.c
>>> +++ b/hw/acpi/aml-build.c
>>> @@ -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;
>>> +}
>>> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
>>> index 42c8dd9..c164f65 100644
>>> --- a/hw/arm/virt-acpi-build.c
>>> +++ b/hw/arm/virt-acpi-build.c
>>> @@ -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);
>>>  
>>
>> 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
> 

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

> 
>>>      /* Cleanup memory that's no longer used. */
>>>      g_array_free(table_offsets, true);
>>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>>> index 3551a08..8c6d7f5 100644
>>> --- a/hw/i386/acpi-build.c
>>> +++ b/hw/i386/acpi-build.c
>>> @@ -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). */
>>>
>>
>> -- 
>> Shannon
> 
> .
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-08  1:52       ` Shannon Zhao
@ 2015-06-08  7:24         ` Michael S. Tsirkin
  2015-06-08 12:59           ` Stefan Hajnoczi
  2015-06-08 13:02           ` Stefan Hajnoczi
  0 siblings, 2 replies; 16+ messages in thread
From: Michael S. Tsirkin @ 2015-06-08  7:24 UTC (permalink / raw)
  To: Shannon Zhao
  Cc: Peter Maydell, Eduardo Habkost, ghammer, qemu-devel, shannon.zhao,
	stefanha, pbonzini, imammedo, lersek, Richard Henderson

On Mon, Jun 08, 2015 at 09:52:22AM +0800, Shannon Zhao wrote:
> > 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?

-- 
MST

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-08  7:24         ` Michael S. Tsirkin
@ 2015-06-08 12:59           ` Stefan Hajnoczi
  2015-06-08 13:02           ` Stefan Hajnoczi
  1 sibling, 0 replies; 16+ messages in thread
From: Stefan Hajnoczi @ 2015-06-08 12:59 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Peter Maydell, Eduardo Habkost, ghammer, qemu-devel, pbonzini,
	shannon.zhao, Shannon Zhao, imammedo, lersek, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 430 bytes --]

On Mon, Jun 08, 2015 at 09:24:30AM +0200, Michael S. Tsirkin wrote:
> On Mon, Jun 08, 2015 at 09:52:22AM +0800, Shannon Zhao wrote:
> > > 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

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation
  2015-06-08  7:24         ` Michael S. Tsirkin
  2015-06-08 12:59           ` Stefan Hajnoczi
@ 2015-06-08 13:02           ` Stefan Hajnoczi
  1 sibling, 0 replies; 16+ messages in thread
From: Stefan Hajnoczi @ 2015-06-08 13:02 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Peter Maydell, Eduardo Habkost, ghammer, qemu-devel, pbonzini,
	shannon.zhao, Shannon Zhao, imammedo, lersek, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

On Mon, Jun 08, 2015 at 09:24:30AM +0200, Michael S. Tsirkin wrote:
> On Mon, Jun 08, 2015 at 09:52:22AM +0800, Shannon Zhao wrote:
> > > 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

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-06-08 13:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-04 16:21 [Qemu-devel] [PATCH 0/4] acpi: xsdt support Michael S. Tsirkin
2015-06-04 16:21 ` [Qemu-devel] [PATCH 1/4] acpi: add API for 64 bit offsets Michael S. Tsirkin
2015-06-05  2:38   ` Shannon Zhao
2015-06-04 16:21 ` [Qemu-devel] [PATCH 2/4] i386/acpi: collect 64 bit offsets for xsdt Michael S. Tsirkin
2015-06-04 16:21 ` [Qemu-devel] [PATCH 3/4] i386/acpi: add XSDT Michael S. Tsirkin
2015-06-05  2:38   ` Shannon Zhao
2015-06-07  9:42     ` Michael S. Tsirkin
2015-06-08  1:49       ` Shannon Zhao
2015-06-04 16:21 ` [Qemu-devel] [PATCH 4/4] acpi: unify rsdp generation Michael S. Tsirkin
2015-06-05  2:47   ` Shannon Zhao
2015-06-07  9:45     ` Michael S. Tsirkin
2015-06-08  1:52       ` Shannon Zhao
2015-06-08  7:24         ` Michael S. Tsirkin
2015-06-08 12:59           ` Stefan Hajnoczi
2015-06-08 13:02           ` Stefan Hajnoczi
2015-06-05  2:48 ` [Qemu-devel] [PATCH 0/4] acpi: xsdt support Shannon Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).