linux-user/sparc: Put address for data faults where linux-user expects it
[qemu/ar7.git] / tests / acpi-utils.h
blobf8d87236c60bd0d4f9b35870cd91f310494f945e
1 /*
2 * Utilities for working with ACPI tables
4 * Copyright (c) 2013 Red Hat Inc.
6 * Authors:
7 * Michael S. Tsirkin <mst@redhat.com>,
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.
13 #ifndef TEST_ACPI_UTILS_H
14 #define TEST_ACPI_UTILS_H
16 #include "hw/acpi/acpi-defs.h"
17 #include "libqtest.h"
19 /* DSDT and SSDTs format */
20 typedef struct {
21 AcpiTableHeader header;
22 gchar *aml; /* aml bytecode from guest */
23 gsize aml_len;
24 gchar *aml_file;
25 gchar *asl; /* asl code generated from aml */
26 gsize asl_len;
27 gchar *asl_file;
28 bool tmp_files_retain; /* do not delete the temp asl/aml */
29 } AcpiSdtTable;
31 #define ACPI_READ_FIELD(field, addr) \
32 do { \
33 switch (sizeof(field)) { \
34 case 1: \
35 field = readb(addr); \
36 break; \
37 case 2: \
38 field = readw(addr); \
39 break; \
40 case 4: \
41 field = readl(addr); \
42 break; \
43 case 8: \
44 field = readq(addr); \
45 break; \
46 default: \
47 g_assert(false); \
48 } \
49 addr += sizeof(field); \
50 } while (0);
52 #define ACPI_READ_ARRAY_PTR(arr, length, addr) \
53 do { \
54 int idx; \
55 for (idx = 0; idx < length; ++idx) { \
56 ACPI_READ_FIELD(arr[idx], addr); \
57 } \
58 } while (0);
60 #define ACPI_READ_ARRAY(arr, addr) \
61 ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
63 #define ACPI_READ_TABLE_HEADER(table, addr) \
64 do { \
65 ACPI_READ_FIELD((table)->signature, addr); \
66 ACPI_READ_FIELD((table)->length, addr); \
67 ACPI_READ_FIELD((table)->revision, addr); \
68 ACPI_READ_FIELD((table)->checksum, addr); \
69 ACPI_READ_ARRAY((table)->oem_id, addr); \
70 ACPI_READ_ARRAY((table)->oem_table_id, addr); \
71 ACPI_READ_FIELD((table)->oem_revision, addr); \
72 ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \
73 ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \
74 } while (0);
76 #define ACPI_ASSERT_CMP(actual, expected) do { \
77 uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \
78 char ACPI_ASSERT_CMP_str[5] = {}; \
79 memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \
80 g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
81 } while (0)
83 #define ACPI_ASSERT_CMP64(actual, expected) do { \
84 uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \
85 char ACPI_ASSERT_CMP_str[9] = {}; \
86 memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \
87 g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
88 } while (0)
90 #define ACPI_READ_GENERIC_ADDRESS(field, addr) \
91 do { \
92 ACPI_READ_FIELD((field).space_id, addr); \
93 ACPI_READ_FIELD((field).bit_width, addr); \
94 ACPI_READ_FIELD((field).bit_offset, addr); \
95 ACPI_READ_FIELD((field).access_width, addr); \
96 ACPI_READ_FIELD((field).address, addr); \
97 } while (0);
100 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
101 uint32_t acpi_find_rsdp_address(void);
102 void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
104 #endif /* TEST_ACPI_UTILS_H */