xref: /qemu/tests/qtest/acpi-utils.h (revision abff1abf)
1 /*
2  * Utilities for working with ACPI tables
3  *
4  * Copyright (c) 2013 Red Hat Inc.
5  *
6  * Authors:
7  *  Michael S. Tsirkin <mst@redhat.com>,
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #ifndef TEST_ACPI_UTILS_H
14 #define TEST_ACPI_UTILS_H
15 
16 #include "libqos/libqtest.h"
17 
18 /* DSDT and SSDTs format */
19 typedef struct {
20     uint8_t *aml;            /* aml bytecode from guest */
21     uint32_t aml_len;
22     gchar *aml_file;
23     gchar *asl;            /* asl code generated from aml */
24     gsize asl_len;
25     gchar *asl_file;
26     bool tmp_files_retain;   /* do not delete the temp asl/aml */
27 } AcpiSdtTable;
28 
29 #define ACPI_ASSERT_CMP(actual, expected) do { \
30     char ACPI_ASSERT_CMP_str[5] = {}; \
31     memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \
32     g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
33 } while (0)
34 
35 #define ACPI_ASSERT_CMP64(actual, expected) do { \
36     char ACPI_ASSERT_CMP_str[9] = {}; \
37     memcpy(ACPI_ASSERT_CMP_str, &actual, 8); \
38     g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
39 } while (0)
40 
41 
42 #define ACPI_FOREACH_RSDT_ENTRY(table, table_len, entry_ptr, entry_size) \
43     for (entry_ptr = table + 36 /* 1st Entry */;                         \
44          entry_ptr < table + table_len;                                  \
45          entry_ptr += entry_size)
46 
47 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
48 uint32_t acpi_find_rsdp_address(QTestState *qts);
49 uint64_t acpi_find_rsdp_address_uefi(QTestState *qts, uint64_t start,
50                                      uint64_t size);
51 void acpi_fetch_rsdp_table(QTestState *qts, uint64_t addr, uint8_t *rsdp_table);
52 void acpi_fetch_table(QTestState *qts, uint8_t **aml, uint32_t *aml_len,
53                       const uint8_t *addr_ptr, int addr_size, const char *sig,
54                       bool verify_checksum);
55 
56 #endif /* TEST_ACPI_UTILS_H */
57