11e8a1faeSThomas Huth /* 21e8a1faeSThomas Huth * Utilities for working with ACPI tables 31e8a1faeSThomas Huth * 41e8a1faeSThomas Huth * Copyright (c) 2013 Red Hat Inc. 51e8a1faeSThomas Huth * 61e8a1faeSThomas Huth * Authors: 71e8a1faeSThomas Huth * Michael S. Tsirkin <mst@redhat.com>, 81e8a1faeSThomas Huth * 91e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later. 101e8a1faeSThomas Huth * See the COPYING file in the top-level directory. 111e8a1faeSThomas Huth */ 121e8a1faeSThomas Huth 131e8a1faeSThomas Huth #ifndef TEST_ACPI_UTILS_H 141e8a1faeSThomas Huth #define TEST_ACPI_UTILS_H 151e8a1faeSThomas Huth 16*907b5105SMarc-André Lureau #include "libqtest.h" 171e8a1faeSThomas Huth 181e8a1faeSThomas Huth /* DSDT and SSDTs format */ 191e8a1faeSThomas Huth typedef struct { 201e8a1faeSThomas Huth uint8_t *aml; /* aml bytecode from guest */ 211e8a1faeSThomas Huth uint32_t aml_len; 221e8a1faeSThomas Huth gchar *aml_file; 231e8a1faeSThomas Huth gchar *asl; /* asl code generated from aml */ 241e8a1faeSThomas Huth gsize asl_len; 251e8a1faeSThomas Huth gchar *asl_file; 261e8a1faeSThomas Huth bool tmp_files_retain; /* do not delete the temp asl/aml */ 271e8a1faeSThomas Huth } AcpiSdtTable; 281e8a1faeSThomas Huth 291e8a1faeSThomas Huth #define ACPI_ASSERT_CMP(actual, expected) do { \ 301e8a1faeSThomas Huth char ACPI_ASSERT_CMP_str[5] = {}; \ 311e8a1faeSThomas Huth memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \ 321e8a1faeSThomas Huth g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ 331e8a1faeSThomas Huth } while (0) 341e8a1faeSThomas Huth 351e8a1faeSThomas Huth #define ACPI_ASSERT_CMP64(actual, expected) do { \ 361e8a1faeSThomas Huth char ACPI_ASSERT_CMP_str[9] = {}; \ 371e8a1faeSThomas Huth memcpy(ACPI_ASSERT_CMP_str, &actual, 8); \ 381e8a1faeSThomas Huth g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ 391e8a1faeSThomas Huth } while (0) 401e8a1faeSThomas Huth 411e8a1faeSThomas Huth 421e8a1faeSThomas Huth #define ACPI_FOREACH_RSDT_ENTRY(table, table_len, entry_ptr, entry_size) \ 431e8a1faeSThomas Huth for (entry_ptr = table + 36 /* 1st Entry */; \ 441e8a1faeSThomas Huth entry_ptr < table + table_len; \ 451e8a1faeSThomas Huth entry_ptr += entry_size) 461e8a1faeSThomas Huth 471e8a1faeSThomas Huth uint8_t acpi_calc_checksum(const uint8_t *data, int len); 481e8a1faeSThomas Huth uint32_t acpi_find_rsdp_address(QTestState *qts); 491e8a1faeSThomas Huth uint64_t acpi_find_rsdp_address_uefi(QTestState *qts, uint64_t start, 501e8a1faeSThomas Huth uint64_t size); 511e8a1faeSThomas Huth void acpi_fetch_rsdp_table(QTestState *qts, uint64_t addr, uint8_t *rsdp_table); 521e8a1faeSThomas Huth void acpi_fetch_table(QTestState *qts, uint8_t **aml, uint32_t *aml_len, 531e8a1faeSThomas Huth const uint8_t *addr_ptr, int addr_size, const char *sig, 541e8a1faeSThomas Huth bool verify_checksum); 551e8a1faeSThomas Huth 561e8a1faeSThomas Huth #endif /* TEST_ACPI_UTILS_H */ 57