qtest/bios-tables: Add DMAR unit test on intel_iommu for q35
PATCH 1/1 qtest/bios-tables: Add DMAR unit test on intel_iommu for q35
The test enables intel_iommu on q35 and reads the DMAR table and its only DRHC structure (for now), checking only the header and checksums.
--- tests/bios-tables-test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
tests/bios-tables-test.c +33 -1
@@ -45,6 +45,8 @@ typedef struct {AcpiRsdtDescriptorRev1 rsdt_table;AcpiFadtDescriptorRev1 fadt_table;AcpiFacsDescriptorRev1 facs_table; +AcpiTableDmar dmar_table; +AcpiDmarHardwareUnit drhd;uint32_t *rsdt_tables_addr;int rsdt_tables_nr;GArray *tables;
@@ -371,6 +373,33 @@ static void test_acpi_dsdt_table(test_data *data)g_array_append_val (data->tables, dsdt_table); } +static void test_acpi_dmar_table (test_data *data) +{ +AcpiTableDmar *dmar_table = &data->dmar_table; +AcpiDmarHardwareUnit *drhd = &data->drhd; +struct AcpiTableHeader *header = (struct AcpiTableHeader *) dmar_table; +int tables_nr = data->rsdt_tables_nr -1 ; +uint32_t addr = data->rsdt_tables_addr[tables_nr];/* dmar is last */ + +memset (dmar_table,0 ,sizeof (*dmar_table)); +ACPI_READ_TABLE_HEADER (dmar_table, addr); +ACPI_ASSERT_CMP (header->signature,"DMAR" ); + +ACPI_READ_FIELD (dmar_table->host_address_width, addr); +ACPI_READ_FIELD (dmar_table->flags, addr); +ACPI_READ_ARRAY_PTR (dmar_table->reserved,10 , addr); + +memset (drhd,0 ,sizeof (*drhd)); +ACPI_READ_FIELD (drhd->type, addr); +ACPI_READ_FIELD (drhd->length, addr); +ACPI_READ_FIELD (drhd->flags, addr); +ACPI_READ_FIELD (drhd->pci_segment, addr); +ACPI_READ_FIELD (drhd->address, addr); +g_assert (!acpi_checksum ((uint8_t *)dmar_table,sizeof (AcpiTableDmar) + + drhd->length)); + +} +static void test_acpi_tables (test_data *data) {int tables_nr = data->rsdt_tables_nr -1 ;/* fadt is first */
@@ -747,6 +776,9 @@ static void test_acpi_one(const char *params, test_data *data)test_acpi_fadt_table (data);test_acpi_facs_table (data);test_acpi_dsdt_table (data); +if (strstr (params,"iommu=on" )) { +test_acpi_dmar_table (data); + }test_acpi_tables (data);if (iasl) {
@@ -779,7 +811,7 @@ static void test_acpi_tcg(void)memset (&data,0 ,sizeof (data)); data.machine =MACHINE_Q35 ; -test_acpi_one ("-machine q35,accel=tcg" , &data); +test_acpi_one ("-machine q35,accel=tcg,iommu=on" , &data);free_test_data (&data); }
Signature · 1 line
1.9.1
Quoted 22 lines · Vasilis Liaskovitis
The test enables
intel_iommuon q35 and reads the DMAR table and its only DRHC structure (for now), checking only the header and checksums.Signed-off-by Vasilis Liaskovitis <[email protected]>--- tests/bios-tables-test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)tests/bios-tables-test.c +2
-0@@ -45,6 +45,8 @@ typedef struct {AcpiRsdtDescriptorRev1 rsdt_table;AcpiFadtDescriptorRev1 fadt_table;AcpiFacsDescriptorRev1 facs_table; +AcpiTableDmar dmar_table; +AcpiDmarHardwareUnit drhd;uint32_t *rsdt_tables_addr;int rsdt_tables_nr;GArray *tables;
tests/bios-tables-test.c static void test_acpi_dsdt_table(test_data *data) · line 382
Quoted 10 lines
tests/bios-tables-test.c +7
-0@@ -371,6 +373,33 @@ static void test_acpi_dsdt_table(test_data *data)g_array_append_val (data->tables, dsdt_table); } +static void test_acpi_dmar_table (test_data *data) +{ +AcpiTableDmar *dmar_table = &data->dmar_table; +AcpiDmarHardwareUnit *drhd = &data->drhd; +struct AcpiTableHeader *header = (struct AcpiTableHeader *) dmar_table; +int tables_nr = data->rsdt_tables_nr -1 ; +uint32_t addr = data->rsdt_tables_addr[tables_nr];/* dmar is last */
Hi,
The DMAR table is always last? If not, it will break when we add another table test. I suggest going over the tables and looking for the DMAR signature.
Thanks,
Marcel
Quoted 42 lines
tests/bios-tables-test.c +24
-1+ +memset (dmar_table,0 ,sizeof (*dmar_table)); +ACPI_READ_TABLE_HEADER (dmar_table, addr); +ACPI_ASSERT_CMP (header->signature,"DMAR" ); + +ACPI_READ_FIELD (dmar_table->host_address_width, addr); +ACPI_READ_FIELD (dmar_table->flags, addr); +ACPI_READ_ARRAY_PTR (dmar_table->reserved,10 , addr); + +memset (drhd,0 ,sizeof (*drhd)); +ACPI_READ_FIELD (drhd->type, addr); +ACPI_READ_FIELD (drhd->length, addr); +ACPI_READ_FIELD (drhd->flags, addr); +ACPI_READ_FIELD (drhd->pci_segment, addr); +ACPI_READ_FIELD (drhd->address, addr); +g_assert (!acpi_checksum ((uint8_t *)dmar_table,sizeof (AcpiTableDmar) + + drhd->length)); + +} +static void test_acpi_tables (test_data *data) {int tables_nr = data->rsdt_tables_nr -1 ;/* fadt is first */ @@ -747,6 +776,9 @@ static void test_acpi_one(const char *params, test_data *data)test_acpi_fadt_table (data);test_acpi_facs_table (data);test_acpi_dsdt_table (data); +if (strstr (params,"iommu=on" )) { +test_acpi_dmar_table (data); + }test_acpi_tables (data);if (iasl) {@@ -779,7 +811,7 @@ static void test_acpi_tcg(void)memset (&data,0 ,sizeof (data)); data.machine =MACHINE_Q35 ; -test_acpi_one ("-machine q35,accel=tcg" , &data); +test_acpi_one ("-machine q35,accel=tcg,iommu=on" , &data);free_test_data (&data); }
Hi,
Quoted 35 lines · Marcel Apfelbaum
Quoted 22 lines · Vasilis Liaskovitis
The test enables
intel_iommuon q35 and reads the DMAR table and its only DRHC structure (for now), checking only the header and checksums.Signed-off-by Vasilis Liaskovitis <[email protected]>--- tests/bios-tables-test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)tests/bios-tables-test.c +2
-0@@ -45,6 +45,8 @@ typedef struct {AcpiRsdtDescriptorRev1 rsdt_table;AcpiFadtDescriptorRev1 fadt_table;AcpiFacsDescriptorRev1 facs_table; +AcpiTableDmar dmar_table; +AcpiDmarHardwareUnit drhd;uint32_t *rsdt_tables_addr;int rsdt_tables_nr;GArray *tables;tests/bios-tables-test.c static void test_acpi_dsdt_table(test_data *data) · line 382
Quoted 10 lines
tests/bios-tables-test.c +7
-0@@ -371,6 +373,33 @@ static void test_acpi_dsdt_table(test_data *data)g_array_append_val (data->tables, dsdt_table); } +static void test_acpi_dmar_table (test_data *data) +{ +AcpiTableDmar *dmar_table = &data->dmar_table; +AcpiDmarHardwareUnit *drhd = &data->drhd; +struct AcpiTableHeader *header = (struct AcpiTableHeader *) dmar_table; +int tables_nr = data->rsdt_tables_nr -1 ; +uint32_t addr = data->rsdt_tables_addr[tables_nr];/* dmar is last */ Hi,
Quoted 2 lines
The DMAR table is always last? If not, it will break when we add another table test. I suggest going over the tables and looking for the DMAR signature.
agreed, it would also break if hw/i386/acpi-build.c adds other tables after DMAR. I posted v2 following your suggestion.
thanks,
- Vasilis