mirror of https://github.com/xemu-project/xemu.git
acpi: arm: virt: build_iort: use acpi_table_begin()/acpi_table_end() instead of build_header()
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>
This commit is contained in:
parent
fc02b86982
commit
3548494e49
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue