hw/arm/virt: generate 64-bit addressable ACPI objects
PATCH v2 1/1 hw/arm/virt: generate 64-bit addressable ACPI objects
Our current ACPI table generation code limits the placement of ACPI tables to 32-bit addressable memory, in order to be able to emit the root pointer (RSDP) and root table (RSDT) using table types from the ACPI 1.0 days.
Since ARM was not supported by ACPI before version 5.0, it makes sense to lift this restriction. This is not crucial for mach-virt, which is guaranteed to have some memory available below the 4 GB mark, but it is a nice to have for QEMU machines that do not have any 32-bit addressable memory, which is not uncommon for real world 64-bit ARM systems.
Since we already emit a version of the RSDP root pointer that has a secondary 64-bit wide address field for the 64-bit root table (XSDT), all we need to do is replace the RSDT generation with the generation of an XSDT table, and use a different slot in the FADT table to refer to the DSDT.
---
v2: - move new build_xsdt() function to hw/acpi/aml-build.c
- tweak commit log text
- add Drew's and Laszlo's acks
hw/acpi/aml-build.c | 27 ++++++++++++++++++++ hw/arm/virt-acpi-build.c | 26 +++++++++---------- include/hw/acpi/acpi-defs.h | 11 ++++++++ include/hw/acpi/aml-build.h | 3 +++ 4 files changed, 54 insertions(+), 13 deletions(-)
hw/acpi/aml-build.c +27 -0
@@ -1599,6 +1599,33 @@ build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id); } +/* Build xsdt table */ +void +build_xsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets, +const char *oem_id,const char *oem_table_id) +{ +int i; +unsigned xsdt_entries_offset; +AcpiXsdtDescriptorRev2 *xsdt; +const unsigned table_data_len = (sizeof (uint64_t ) * table_offsets->len); +const unsigned xsdt_entry_size =sizeof (xsdt->table_offset_entry[0 ]); +const size_t xsdt_len =sizeof (*xsdt) + table_data_len; + + xsdt =acpi_data_push (table_data, xsdt_len); + xsdt_entries_offset = (char *)xsdt->table_offset_entry - table_data->data; +for (i =0 ; i < table_offsets->len; ++i) { +uint64_t ref_tbl_offset =g_array_index (table_offsets, uint32_t, i); +uint64_t xsdt_entry_offset = xsdt_entries_offset + xsdt_entry_size * i; + +/* xsdt->table_offset_entry to be filled by Guest linker */ +bios_linker_loader_add_pointer (linker, +ACPI_BUILD_TABLE_FILE , xsdt_entry_offset, xsdt_entry_size, +ACPI_BUILD_TABLE_FILE , ref_tbl_offset); + } +build_header (linker, table_data, + (void *)xsdt,"XSDT" , xsdt_len,1 , oem_id, oem_table_id); +} +void build_srat_memory (AcpiSratMemoryAffinity *numamem,uint64_t base,uint64_t len,int node,MemoryAffinityFlags flags) {
hw/arm/virt-acpi-build.c +13 -13
@@ -391,12 +391,12 @@ static void acpi_dsdt_add_power_button(Aml *scope)/* RSDP */ static GArray * -build_rsdp (GArray *rsdp_table,BIOSLinker *linker,unsigned rsdt_tbl_offset) +build_rsdp (GArray *rsdp_table,BIOSLinker *linker,unsigned xsdt_tbl_offset) {AcpiRsdpDescriptor *rsdp =acpi_data_push (rsdp_table,sizeof *rsdp); -unsigned rsdt_pa_size =sizeof (rsdp->rsdt_physical_address); -unsigned rsdt_pa_offset = - (char *)&rsdp->rsdt_physical_address - rsdp_table->data; +unsigned xsdt_pa_size =sizeof (rsdp->xsdt_physical_address); +unsigned xsdt_pa_offset = + (char *)&rsdp->xsdt_physical_address - rsdp_table->data;bios_linker_loader_alloc (linker,ACPI_BUILD_RSDP_FILE , rsdp_table,16 , true/* fseg memory */ );
@@ -408,8 +408,8 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)/* Address to be filled by Guest linker */ bios_linker_loader_add_pointer (linker, -ACPI_BUILD_RSDP_FILE , rsdt_pa_offset, rsdt_pa_size, -ACPI_BUILD_TABLE_FILE , rsdt_tbl_offset); +ACPI_BUILD_RSDP_FILE , xsdt_pa_offset, xsdt_pa_size, +ACPI_BUILD_TABLE_FILE , xsdt_tbl_offset);/* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
@@ -686,7 +686,7 @@ static void build_fadt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms, unsigned dsdt_tbl_offset) {AcpiFadtDescriptorRev5_1 *fadt =acpi_data_push (table_data,sizeof (*fadt)); -unsigned dsdt_entry_offset = (char *)&fadt->dsdt - table_data->data; +unsigned xdsdt_entry_offset = (char *)&fadt->Xdsdt - table_data->data;uint16_t bootflags;switch (vms->psci_conduit) {
@@ -712,7 +712,7 @@ static void build_fadt(GArray *table_data, BIOSLinker *linker,/* DSDT address to be filled by Guest linker */ bios_linker_loader_add_pointer (linker, -ACPI_BUILD_TABLE_FILE , dsdt_entry_offset,sizeof (fadt->dsdt), +ACPI_BUILD_TABLE_FILE , xdsdt_entry_offset,sizeof (fadt->Xdsdt),ACPI_BUILD_TABLE_FILE , dsdt_tbl_offset); build_header(linker, table_data,
@@ -777,7 +777,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) {VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms);GArray *table_offsets; -unsigned dsdt, rsdt; +unsigned dsdt, xsdt;GArray *tables_blob = tables->table_data; table_offsets = g_array_new(false, true /* clear */,
@@ -817,12 +817,12 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_iort (tables_blob, tables->linker); } -/* RSDT is pointed to by RSDP */ - rsdt = tables_blob->len; -build_rsdt (tables_blob, tables->linker, table_offsets,NULL ,NULL ); +/* XSDT is pointed to by RSDP */ + xsdt = tables_blob->len; +build_xsdt (tables_blob, tables->linker, table_offsets,NULL ,NULL );/* RSDP is in FSEG memory, so allocate it separately */ -build_rsdp (tables->rsdp, tables->linker, rsdt); +build_rsdp (tables->rsdp, tables->linker, xsdt);/* Cleanup memory that's no longer used. */ g_array_free (table_offsets, true);
include/hw/acpi/acpi-defs.h +11 -0
@@ -238,6 +238,17 @@ struct AcpiRsdtDescriptorRev1typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1 ;/* +* ACPI 2.0 eXtended System Description Table (XSDT) +*/ +struct AcpiXsdtDescriptorRev2 +{ +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 AcpiXsdtDescriptorRev2 AcpiXsdtDescriptorRev2 ; + +/* * ACPI 1.0 Firmware ACPI Control Structure (FACS) */ struct AcpiFacsDescriptorRev1
include/hw/acpi/aml-build.h +3 -0
@@ -381,6 +381,9 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);void build_rsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets,const char *oem_id,const char *oem_table_id); +void +build_xsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets, +const char *oem_id,const char *oem_table_id);int build_append_named_dword (GArray *array,const char *name_format, ...)
Signature · 1 line
2.9.3
Quoted 103 lines · Ard Biesheuvel
Our current ACPI table generation code limits the placement of ACPI tables to 32-bit addressable memory, in order to be able to emit the root pointer (RSDP) and root table (RSDT) using table types from the ACPI 1.0 days.
Since ARM was not supported by ACPI before version 5.0, it makes sense to lift this restriction. This is not crucial for mach-virt, which is guaranteed to have some memory available below the 4 GB mark, but it is a nice to have for QEMU machines that do not have any 32-bit addressable memory, which is not uncommon for real world 64-bit ARM systems.
Since we already emit a version of the RSDP root pointer that has a secondary 64-bit wide address field for the 64-bit root table (XSDT), all we need to do is replace the RSDT generation with the generation of an XSDT table, and use a different slot in the FADT table to refer to the DSDT.
Signed-off-by Ard Biesheuvel <[email protected]>Reviewed-by Andrew Jones <[email protected]>Acked-by Laszlo Ersek <[email protected]>---
v2: - move newbuild_xsdt()function tohw/acpi/aml-build.c
- tweak commit log text
- add Drew's and Laszlo's ackshw/acpi/aml-build.c | 27 ++++++++++++++++++++ hw/arm/virt-acpi-build.c | 26 +++++++++---------- include/hw/acpi/acpi-defs.h | 11 ++++++++ include/hw/acpi/aml-build.h | 3 +++ 4 files changed, 54 insertions(+), 13 deletions(-)hw/acpi/aml-build.c +27
-0@@ -1599,6 +1599,33 @@ build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id); } +/* Build xsdt table */ +void +build_xsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets, +const char *oem_id,const char *oem_table_id) +{ +int i; +unsigned xsdt_entries_offset; +AcpiXsdtDescriptorRev2 *xsdt; +const unsigned table_data_len = (sizeof (uint64_t ) * table_offsets->len); +const unsigned xsdt_entry_size =sizeof (xsdt->table_offset_entry[0 ]); +const size_t xsdt_len =sizeof (*xsdt) + table_data_len; + + xsdt =acpi_data_push (table_data, xsdt_len); + xsdt_entries_offset = (char *)xsdt->table_offset_entry - table_data->data; +for (i =0 ; i < table_offsets->len; ++i) { +uint64_t ref_tbl_offset =g_array_index (table_offsets, uint32_t, i); +uint64_t xsdt_entry_offset = xsdt_entries_offset + xsdt_entry_size * i; + +/* xsdt->table_offset_entry to be filled by Guest linker */ +bios_linker_loader_add_pointer (linker, +ACPI_BUILD_TABLE_FILE , xsdt_entry_offset, xsdt_entry_size, +ACPI_BUILD_TABLE_FILE , ref_tbl_offset); + } +build_header (linker, table_data, + (void *)xsdt,"XSDT" , xsdt_len,1 , oem_id, oem_table_id); +} +void build_srat_memory (AcpiSratMemoryAffinity *numamem,uint64_t base,uint64_t len,int node,MemoryAffinityFlags flags) {hw/arm/virt-acpi-build.c +6
-6@@ -391,12 +391,12 @@ static void acpi_dsdt_add_power_button(Aml *scope)/* RSDP */ static GArray * -build_rsdp (GArray *rsdp_table,BIOSLinker *linker,unsigned rsdt_tbl_offset) +build_rsdp (GArray *rsdp_table,BIOSLinker *linker,unsigned xsdt_tbl_offset) {AcpiRsdpDescriptor *rsdp =acpi_data_push (rsdp_table,sizeof *rsdp); -unsigned rsdt_pa_size =sizeof (rsdp->rsdt_physical_address); -unsigned rsdt_pa_offset = - (char *)&rsdp->rsdt_physical_address - rsdp_table->data; +unsigned xsdt_pa_size =sizeof (rsdp->xsdt_physical_address); +unsigned xsdt_pa_offset = + (char *)&rsdp->xsdt_physical_address - rsdp_table->data;bios_linker_loader_alloc (linker,ACPI_BUILD_RSDP_FILE , rsdp_table,16 , true/* fseg memory */ );@@ -408,8 +408,8 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)/* Address to be filled by Guest linker */ bios_linker_loader_add_pointer (linker, -ACPI_BUILD_RSDP_FILE , rsdt_pa_offset, rsdt_pa_size, -ACPI_BUILD_TABLE_FILE , rsdt_tbl_offset); +ACPI_BUILD_RSDP_FILE , xsdt_pa_offset, xsdt_pa_size, +ACPI_BUILD_TABLE_FILE , xsdt_tbl_offset);/* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
hw/arm/virt-acpi-build.c static void build_fadt(GArray *table_data, BIOSLinker *linker, · line 692
Quoted 8 lines
hw/arm/virt-acpi-build.c +1
-1@@ -686,7 +686,7 @@ static void build_fadt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms, unsigned dsdt_tbl_offset) {AcpiFadtDescriptorRev5_1 *fadt =acpi_data_push (table_data,sizeof (*fadt)); -unsigned dsdt_entry_offset = (char *)&fadt->dsdt - table_data->data; +unsigned xdsdt_entry_offset = (char *)&fadt->Xdsdt - table_data->data;uint16_t bootflags;switch (vms->psci_conduit) {
This is a bug in acpi-defs.h - pls rename that field to x_dsdt, no upper case letters.
Quoted 73 lines
hw/arm/virt-acpi-build.c +6
-6@@ -712,7 +712,7 @@ static void build_fadt(GArray *table_data, BIOSLinker *linker,/* DSDT address to be filled by Guest linker */ bios_linker_loader_add_pointer (linker, -ACPI_BUILD_TABLE_FILE , dsdt_entry_offset,sizeof (fadt->dsdt), +ACPI_BUILD_TABLE_FILE , xdsdt_entry_offset,sizeof (fadt->XXdsdtdsdt),ACPI_BUILD_TABLE_FILE , dsdt_tbl_offset); build_header(linker, table_data,@@ -777,7 +777,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) {VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms);GArray *table_offsets; -unsigned dsdt, rsdt; +unsigned dsdt, xsdt;GArray *tables_blob = tables->table_data; table_offsets = g_array_new(false, true /* clear */,@@ -817,12 +817,12 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_iort (tables_blob, tables->linker); } -/* RSDT is pointed to by RSDP */ - rsdt = tables_blob->len; -build_rsdt (tables_blob, tables->linker, table_offsets,NULL ,NULL ); +/* XSDT is pointed to by RSDP */ + xsdt = tables_blob->len; +build_xsdt (tables_blob, tables->linker, table_offsets,NULL ,NULL );/* RSDP is in FSEG memory, so allocate it separately */ -build_rsdp (tables->rsdp, tables->linker, rsdt); +build_rsdp (tables->rsdp, tables->linker, xsdt);/* Cleanup memory that's no longer used. */ g_array_free (table_offsets, true);include/hw/acpi/acpi-defs.h +11
-0@@ -238,6 +238,17 @@ struct AcpiRsdtDescriptorRev1typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1 ;/* +* ACPI 2.0 eXtended System Description Table (XSDT) +*/ +struct AcpiXsdtDescriptorRev2 +{ +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 AcpiXsdtDescriptorRev2 AcpiXsdtDescriptorRev2 ; + +/* * ACPI 1.0 Firmware ACPI Control Structure (FACS) */ struct AcpiFacsDescriptorRev1 include/hw/acpi/aml-build.h +3
-0@@ -381,6 +381,9 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);void build_rsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets,const char *oem_id,const char *oem_table_id); +void +build_xsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets, +const char *oem_id,const char *oem_table_id);int build_append_named_dword (GArray *array,const char *name_format, ...)Signature · 1 line
2.9.3
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2] hw/arm/virt: generate 64-bit addressable ACPI objects
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
c63a33e hw/arm/virt: generate 64-bit addressable ACPI objects
=== OUTPUT BEGIN ===
Checking PATCH 1/1: hw/arm/virt: generate 64-bit addressable ACPI objects...
ERROR: open brace '{' following struct go on the same line
#154: FILE: include/hw/acpi/acpi-defs.h:244:
+struct AcpiXsdtDescriptorRev2
+{
total: 1 errors, 0 warnings, 125 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 41 lines · On Fri, 7 Apr 2017 15:41:38 +0100 Ard Biesheuvel <[email protected]>…
Our current ACPI table generation code limits the placement of ACPI tables to 32-bit addressable memory, in order to be able to emit the root pointer (RSDP) and root table (RSDT) using table types from the ACPI 1.0 days.
Since ARM was not supported by ACPI before version 5.0, it makes sense to lift this restriction. This is not crucial for mach-virt, which is guaranteed to have some memory available below the 4 GB mark, but it is a nice to have for QEMU machines that do not have any 32-bit addressable memory, which is not uncommon for real world 64-bit ARM systems.
Since we already emit a version of the RSDP root pointer that has a secondary 64-bit wide address field for the 64-bit root table (XSDT), all we need to do is replace the RSDT generation with the generation of an XSDT table, and use a different slot in the FADT table to refer to the DSDT.
Signed-off-by Ard Biesheuvel <[email protected]>Reviewed-by Andrew Jones <[email protected]>Acked-by Laszlo Ersek <[email protected]>---
v2: - move newbuild_xsdt()function tohw/acpi/aml-build.c
- tweak commit log text
- add Drew's and Laszlo's ackshw/acpi/aml-build.c | 27 ++++++++++++++++++++ hw/arm/virt-acpi-build.c | 26 +++++++++---------- include/hw/acpi/acpi-defs.h | 11 ++++++++ include/hw/acpi/aml-build.h | 3 +++ 4 files changed, 54 insertions(+), 13 deletions(-)hw/acpi/aml-build.c +1
-0@@ -1599,6 +1599,33 @@ build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id); } +/* Build xsdt table */
hw/acpi/aml-build.c build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, · line 1612
Quoted 10 lines
hw/acpi/aml-build.c +9
-0+void +build_xsdt (GArray *table_data,BIOSLinker *linker,GArray *table_offsets, +const char *oem_id,const char *oem_table_id) +{ +int i; +unsigned xsdt_entries_offset; +AcpiXsdtDescriptorRev2 *xsdt; +const unsigned table_data_len = (sizeof (uint64_t ) * table_offsets->len); +const unsigned xsdt_entry_size =sizeof (xsdt->table_offset_entry[0 ]);
nit, I know it was mostly copy/paste but how about:
const unsigned xsdt_entry_size = sizeof(xsdt->table_offset_entry[0]); const unsigned table_data_len = xsdt_entry_size * table_offsets->len;
Quoted 7 lines
hw/acpi/aml-build.c +7
-0+const size_t xsdt_len =sizeof (*xsdt) + table_data_len; + + xsdt =acpi_data_push (table_data, xsdt_len); + xsdt_entries_offset = (char *)xsdt->table_offset_entry - table_data->data; +for (i =0 ; i < table_offsets->len; ++i) { +uint64_t ref_tbl_offset =g_array_index (table_offsets, uint32_t, i); +uint64_t xsdt_entry_offset = xsdt_entries_offset + xsdt_entry_size * i;
hw/acpi/aml-build.c build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, · line 1628
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ +/* xsdt->table_offset_entry to be filled by Guest linker */ +bios_linker_loader_add_pointer (linker, +ACPI_BUILD_TABLE_FILE , xsdt_entry_offset, xsdt_entry_size, +ACPI_BUILD_TABLE_FILE , ref_tbl_offset); + } +build_header (linker, table_data, + (void *)xsdt,"XSDT" , xsdt_len,1 , oem_id, oem_table_id); +} +
The rest looks fine to me, so with above fixup