2017-02-17 02:15:38 +03:00
|
|
|
/*
|
|
|
|
* Utilities for working with ACPI tables
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Michael S. Tsirkin <mst@redhat.com>,
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TEST_ACPI_UTILS_H
|
|
|
|
#define TEST_ACPI_UTILS_H
|
|
|
|
|
|
|
|
#include "hw/acpi/acpi-defs.h"
|
|
|
|
#include "libqtest.h"
|
|
|
|
|
|
|
|
/* DSDT and SSDTs format */
|
|
|
|
typedef struct {
|
|
|
|
AcpiTableHeader header;
|
|
|
|
gchar *aml; /* aml bytecode from guest */
|
|
|
|
gsize aml_len;
|
|
|
|
gchar *aml_file;
|
|
|
|
gchar *asl; /* asl code generated from aml */
|
|
|
|
gsize asl_len;
|
|
|
|
gchar *asl_file;
|
|
|
|
bool tmp_files_retain; /* do not delete the temp asl/aml */
|
2017-03-30 18:30:59 +03:00
|
|
|
} AcpiSdtTable;
|
2017-02-17 02:15:38 +03:00
|
|
|
|
2017-11-16 15:17:02 +03:00
|
|
|
#define ACPI_READ_FIELD(field, addr) \
|
|
|
|
do { \
|
|
|
|
memread(addr, &field, sizeof(field)); \
|
2017-02-17 02:15:38 +03:00
|
|
|
addr += sizeof(field); \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define ACPI_READ_ARRAY_PTR(arr, length, addr) \
|
|
|
|
do { \
|
|
|
|
int idx; \
|
|
|
|
for (idx = 0; idx < length; ++idx) { \
|
|
|
|
ACPI_READ_FIELD(arr[idx], addr); \
|
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define ACPI_READ_ARRAY(arr, addr) \
|
|
|
|
ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
|
|
|
|
|
|
|
|
#define ACPI_READ_TABLE_HEADER(table, addr) \
|
|
|
|
do { \
|
|
|
|
ACPI_READ_FIELD((table)->signature, addr); \
|
|
|
|
ACPI_READ_FIELD((table)->length, addr); \
|
|
|
|
ACPI_READ_FIELD((table)->revision, addr); \
|
|
|
|
ACPI_READ_FIELD((table)->checksum, addr); \
|
|
|
|
ACPI_READ_ARRAY((table)->oem_id, addr); \
|
|
|
|
ACPI_READ_ARRAY((table)->oem_table_id, addr); \
|
|
|
|
ACPI_READ_FIELD((table)->oem_revision, addr); \
|
|
|
|
ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \
|
|
|
|
ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define ACPI_ASSERT_CMP(actual, expected) do { \
|
|
|
|
char ACPI_ASSERT_CMP_str[5] = {}; \
|
2017-11-16 15:17:02 +03:00
|
|
|
memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \
|
2017-02-17 02:15:38 +03:00
|
|
|
g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ACPI_ASSERT_CMP64(actual, expected) do { \
|
|
|
|
char ACPI_ASSERT_CMP_str[9] = {}; \
|
2017-11-16 15:17:02 +03:00
|
|
|
memcpy(ACPI_ASSERT_CMP_str, &actual, 8); \
|
2017-02-17 02:15:38 +03:00
|
|
|
g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
|
|
|
|
} while (0)
|
|
|
|
|
2017-03-15 09:20:26 +03:00
|
|
|
#define ACPI_READ_GENERIC_ADDRESS(field, addr) \
|
|
|
|
do { \
|
|
|
|
ACPI_READ_FIELD((field).space_id, addr); \
|
|
|
|
ACPI_READ_FIELD((field).bit_width, addr); \
|
|
|
|
ACPI_READ_FIELD((field).bit_offset, addr); \
|
|
|
|
ACPI_READ_FIELD((field).access_width, addr); \
|
|
|
|
ACPI_READ_FIELD((field).address, addr); \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
2017-02-17 02:15:38 +03:00
|
|
|
uint8_t acpi_calc_checksum(const uint8_t *data, int len);
|
|
|
|
uint32_t acpi_find_rsdp_address(void);
|
|
|
|
void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
|
|
|
|
|
|
|
|
#endif /* TEST_ACPI_UTILS_H */
|