aboutsummaryrefslogtreecommitdiff
path: root/tests/acpi-utils.c
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2018-12-27 15:13:31 +0100
committerMichael S. Tsirkin <mst@redhat.com>2019-01-17 21:10:57 -0500
commitacee774b3dbeb7fcd294b1f96c1a286d39d9b495 (patch)
treed54da65345c7929b26683024e295f4b1910c2223 /tests/acpi-utils.c
parent59f9c6cc014309cde537842af2104b2f9956b0d6 (diff)
tests: acpi: reuse fetch_table() in vmgenid-test
Move fetch_table() into acpi-utils.c renaming it to acpi_fetch_table() and reuse it in vmgenid-test that reads RSDT and then tables it references, to find and parse VMGNEID SSDT. While at it wrap RSDT referenced tables enumeration into FOREACH macro (similar to what we do with QLIST_FOREACH & co) to reuse it with bios and vmgenid tests. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Acked-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'tests/acpi-utils.c')
-rw-r--r--tests/acpi-utils.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/tests/acpi-utils.c b/tests/acpi-utils.c
index 17abcc43a4..cc33b460ab 100644
--- a/tests/acpi-utils.c
+++ b/tests/acpi-utils.c
@@ -51,14 +51,6 @@ uint32_t acpi_find_rsdp_address(QTestState *qts)
return off;
}
-uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table)
-{
- uint32_t rsdt_physical_address;
-
- memcpy(&rsdt_physical_address, &rsdp_table[16 /* RsdtAddress offset */], 4);
- return le32_to_cpu(rsdt_physical_address);
-}
-
uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table)
{
uint64_t xsdt_physical_address;
@@ -92,3 +84,30 @@ void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr, uint8_t *rsdp_table)
ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table)), "RSD PTR ");
}
+
+/** acpi_fetch_table
+ * load ACPI table at @addr_ptr offset pointer into buffer and return it in
+ * @aml, its length in @aml_len and check that signature/checksum matches
+ * actual one.
+ */
+void acpi_fetch_table(QTestState *qts, uint8_t **aml, uint32_t *aml_len,
+ const uint8_t *addr_ptr, const char *sig,
+ bool verify_checksum)
+{
+ uint32_t addr, len;
+
+ memcpy(&addr, addr_ptr , sizeof(addr));
+ addr = le32_to_cpu(addr);
+ qtest_memread(qts, addr + 4, &len, 4); /* Length of ACPI table */
+ *aml_len = le32_to_cpu(len);
+ *aml = g_malloc0(*aml_len);
+ /* get whole table */
+ qtest_memread(qts, addr, *aml, *aml_len);
+
+ if (sig) {
+ ACPI_ASSERT_CMP(**aml, sig);
+ }
+ if (verify_checksum) {
+ g_assert(!acpi_calc_checksum(*aml, *aml_len));
+ }
+}