[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 42/57] acpi: arm: virt: build_iort: use acpi_table_begin()/acpi_ta
From: |
Michael S. Tsirkin |
Subject: |
[PULL 42/57] acpi: arm: virt: build_iort: use acpi_table_begin()/acpi_table_end() instead of build_header() |
Date: |
Tue, 5 Oct 2021 12:03:50 -0400 |
From: Igor Mammedov <imammedo@redhat.com>
it replaces error-prone pointer arithmetic for build_header() API,
with 2 calls to start and finish table creation,
which hides offsets magic from API user.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
Message-Id: <20210924122802.1455362-29-imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/acpi/acpi-defs.h | 14 ------------
hw/arm/virt-acpi-build.c | 44 +++++++++++++++----------------------
2 files changed, 18 insertions(+), 40 deletions(-)
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index bcada37601..195f90caf6 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -188,20 +188,6 @@ struct AcpiGenericTimerTable {
} QEMU_PACKED;
typedef struct AcpiGenericTimerTable AcpiGenericTimerTable;
-/*
- * Input Output Remapping Table (IORT)
- * Conforms to "IO Remapping Table System Software on ARM Platforms",
- * Document number: ARM DEN 0049B, October 2015
- */
-
-struct AcpiIortTable {
- ACPI_TABLE_HEADER_DEF /* ACPI common table header */
- uint32_t node_count;
- uint32_t node_offset;
- uint32_t reserved;
-} QEMU_PACKED;
-typedef struct AcpiIortTable AcpiIortTable;
-
/*
* IORT node types
*/
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 4b9687439d..42ea460313 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -273,20 +273,26 @@ static int iort_idmap_compare(gconstpointer a,
gconstpointer b)
return idmap_a->input_base - idmap_b->input_base;
}
+/*
+ * Input Output Remapping Table (IORT)
+ * Conforms to "IO Remapping Table System Software on ARM Platforms",
+ * Document number: ARM DEN 0049B, October 2015
+ */
static void
build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
{
- int i, nb_nodes, rc_mapping_count, iort_start = table_data->len;
+ int i, nb_nodes, rc_mapping_count;
AcpiIortIdMapping *idmap;
AcpiIortItsGroup *its;
- AcpiIortTable *iort;
AcpiIortSmmu3 *smmu;
- size_t node_size, iort_node_offset, iort_length, smmu_offset = 0;
AcpiIortRC *rc;
+ const uint32_t iort_node_offset = 48;
+ size_t node_size, smmu_offset = 0;
GArray *smmu_idmaps = g_array_new(false, true, sizeof(AcpiIortIdMapping));
GArray *its_idmaps = g_array_new(false, true, sizeof(AcpiIortIdMapping));
- iort = acpi_data_push(table_data, sizeof(*iort));
+ AcpiTable table = { .sig = "IORT", .rev = 0, .oem_id = vms->oem_id,
+ .oem_table_id = vms->oem_table_id };
if (vms->iommu == VIRT_IOMMU_SMMUV3) {
AcpiIortIdMapping next_range = {0};
@@ -325,18 +331,16 @@ build_iort(GArray *table_data, BIOSLinker *linker,
VirtMachineState *vms)
rc_mapping_count = 1;
}
- iort_length = sizeof(*iort);
- iort->node_count = cpu_to_le32(nb_nodes);
- /*
- * Use a copy in case table_data->data moves during acpi_data_push
- * operations.
- */
- iort_node_offset = sizeof(*iort);
- iort->node_offset = cpu_to_le32(iort_node_offset);
+ /* Table 2 The IORT */
+ acpi_table_begin(&table, table_data);
+ /* Number of IORT Nodes */
+ build_append_int_noprefix(table_data, nb_nodes, 4);
+ /* Offset to Array of IORT Nodes */
+ build_append_int_noprefix(table_data, iort_node_offset, 4);
+ build_append_int_noprefix(table_data, 0, 4); /* Reserved */
/* ITS group node */
node_size = sizeof(*its) + sizeof(uint32_t);
- iort_length += node_size;
its = acpi_data_push(table_data, node_size);
its->type = ACPI_IORT_NODE_ITS_GROUP;
@@ -350,7 +354,6 @@ build_iort(GArray *table_data, BIOSLinker *linker,
VirtMachineState *vms)
/* SMMUv3 node */
smmu_offset = iort_node_offset + node_size;
node_size = sizeof(*smmu) + sizeof(*idmap);
- iort_length += node_size;
smmu = acpi_data_push(table_data, node_size);
smmu->type = ACPI_IORT_NODE_SMMU_V3;
@@ -375,7 +378,6 @@ build_iort(GArray *table_data, BIOSLinker *linker,
VirtMachineState *vms)
/* Root Complex Node */
node_size = sizeof(*rc) + sizeof(*idmap) * rc_mapping_count;
- iort_length += node_size;
rc = acpi_data_push(table_data, node_size);
rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX;
@@ -424,19 +426,9 @@ build_iort(GArray *table_data, BIOSLinker *linker,
VirtMachineState *vms)
idmap->output_reference = cpu_to_le32(iort_node_offset);
}
+ acpi_table_end(linker, &table);
g_array_free(smmu_idmaps, true);
g_array_free(its_idmaps, true);
-
- /*
- * Update the pointer address in case table_data->data moves during above
- * acpi_data_push operations.
- */
- iort = (AcpiIortTable *)(table_data->data + iort_start);
- iort->length = cpu_to_le32(iort_length);
-
- build_header(linker, table_data, (void *)(table_data->data + iort_start),
- "IORT", table_data->len - iort_start, 0, vms->oem_id,
- vms->oem_table_id);
}
static void
--
MST
- [PULL 31/57] acpi: use build_append_int_noprefix() API to compose SRAT table, (continued)
- [PULL 31/57] acpi: use build_append_int_noprefix() API to compose SRAT table, Michael S. Tsirkin, 2021/10/05
- [PULL 29/57] acpi: build_tpm_tcpa: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 32/57] acpi: build_dmar_q35: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 34/57] acpi: build_amd_iommu: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 36/57] acpi: x86: remove dead code, Michael S. Tsirkin, 2021/10/05
- [PULL 37/57] acpi: x86: set enabled when composing _MAT entries, Michael S. Tsirkin, 2021/10/05
- [PULL 35/57] acpi: madt: arm/x86: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 38/57] acpi: x86: madt: use build_append_int_noprefix() API to compose MADT table, Michael S. Tsirkin, 2021/10/05
- [PULL 39/57] acpi: arm/virt: madt: use build_append_int_noprefix() API to compose MADT table, Michael S. Tsirkin, 2021/10/05
- [PULL 40/57] acpi: build_dsdt_microvm: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 42/57] acpi: arm: virt: build_iort: use acpi_table_begin()/acpi_table_end() instead of build_header(),
Michael S. Tsirkin <=
- [PULL 01/57] hw/virtio: Acquire RCU read lock in virtqueue_packed_drop_all(), Michael S. Tsirkin, 2021/10/05
- [PULL 44/57] acpi: arm/virt: build_spcr: fix invalid cast, Michael S. Tsirkin, 2021/10/05
- [PULL 41/57] acpi: arm: virt: build_dsdt: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 43/57] acpi: arm/virt: convert build_iort() to endian agnostic build_append_FOO() API, Michael S. Tsirkin, 2021/10/05
- [PULL 46/57] acpi: arm/virt: build_gtdt: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 47/57] acpi: build_facs: use build_append_int_noprefix() API to compose table, Michael S. Tsirkin, 2021/10/05
- [PULL 50/57] bios-tables-test: allow changes in DSDT ACPI tables for q35, Michael S. Tsirkin, 2021/10/05
- [PULL 06/57] vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *, Michael S. Tsirkin, 2021/10/05
- [PULL 48/57] acpi: remove no longer used build_header(), Michael S. Tsirkin, 2021/10/05
- [PULL 45/57] acpi: arm/virt: build_spcr: use acpi_table_begin()/acpi_table_end() instead of build_header(), Michael S. Tsirkin, 2021/10/05