2017-02-16 23:15:38 +00: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 {
|
2018-12-27 14:13:27 +00:00
|
|
|
union {
|
|
|
|
AcpiTableHeader *header;
|
|
|
|
uint8_t *aml; /* aml bytecode from guest */
|
|
|
|
};
|
2017-02-16 23:15:38 +00:00
|
|
|
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 15:30:59 +00:00
|
|
|
} AcpiSdtTable;
|
2017-02-16 23:15:38 +00:00
|
|
|
|
2017-09-11 17:20:08 +00:00
|
|
|
#define ACPI_READ_FIELD(qts, field, addr) \
|
|
|
|
do { \
|
|
|
|
qtest_memread(qts, addr, &field, sizeof(field)); \
|
|
|
|
addr += sizeof(field); \
|
maint: Fix macros with broken 'do/while(0); ' usage
The point of writing a macro embedded in a 'do { ... } while (0)'
loop (particularly if the macro has multiple statements or would
otherwise end with an 'if' statement) is so that the macro can be
used as a drop-in statement with the caller supplying the
trailing ';'. Although our coding style frowns on brace-less 'if':
if (cond)
statement;
else
something else;
that is the classic case where failure to use do/while(0) wrapping
would cause the 'else' to pair with any embedded 'if' in the macro
rather than the intended outer 'if'. But conversely, if the macro
includes an embedded ';', then the same brace-less coding style
would now have two statements, making the 'else' a syntax error
rather than pairing with the outer 'if'. Thus, even though our
coding style with required braces is not impacted, ending a macro
with ';' makes our code harder to port to projects that use
brace-less styles.
The change should have no semantic impact. I was not able to
fully compile-test all of the changes (as some of them are
examples of the ugly bit-rotting debug print statements that are
completely elided by default, and I didn't want to recompile
with the necessary -D witnesses - cleaning those up is left as a
bite-sized task for another day); I did, however, audit that for
all files touched, all callers of the changed macros DID supply
a trailing ';' at the callsite, and did not appear to be used
as part of a brace-less conditional.
Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20171201232433.25193-7-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-12-01 23:24:32 +00:00
|
|
|
} while (0)
|
2017-02-16 23:15:38 +00:00
|
|
|
|
2017-09-11 17:20:08 +00:00
|
|
|
#define ACPI_READ_ARRAY_PTR(qts, arr, length, addr) \
|
|
|
|
do { \
|
|
|
|
int idx; \
|
|
|
|
for (idx = 0; idx < length; ++idx) { \
|
|
|
|
ACPI_READ_FIELD(qts, arr[idx], addr); \
|
|
|
|
} \
|
maint: Fix macros with broken 'do/while(0); ' usage
The point of writing a macro embedded in a 'do { ... } while (0)'
loop (particularly if the macro has multiple statements or would
otherwise end with an 'if' statement) is so that the macro can be
used as a drop-in statement with the caller supplying the
trailing ';'. Although our coding style frowns on brace-less 'if':
if (cond)
statement;
else
something else;
that is the classic case where failure to use do/while(0) wrapping
would cause the 'else' to pair with any embedded 'if' in the macro
rather than the intended outer 'if'. But conversely, if the macro
includes an embedded ';', then the same brace-less coding style
would now have two statements, making the 'else' a syntax error
rather than pairing with the outer 'if'. Thus, even though our
coding style with required braces is not impacted, ending a macro
with ';' makes our code harder to port to projects that use
brace-less styles.
The change should have no semantic impact. I was not able to
fully compile-test all of the changes (as some of them are
examples of the ugly bit-rotting debug print statements that are
completely elided by default, and I didn't want to recompile
with the necessary -D witnesses - cleaning those up is left as a
bite-sized task for another day); I did, however, audit that for
all files touched, all callers of the changed macros DID supply
a trailing ';' at the callsite, and did not appear to be used
as part of a brace-less conditional.
Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20171201232433.25193-7-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-12-01 23:24:32 +00:00
|
|
|
} while (0)
|
2017-02-16 23:15:38 +00:00
|
|
|
|
2017-09-11 17:20:08 +00:00
|
|
|
#define ACPI_READ_ARRAY(qts, arr, addr) \
|
|
|
|
ACPI_READ_ARRAY_PTR(qts, arr, sizeof(arr) / sizeof(arr[0]), addr)
|
2017-02-16 23:15:38 +00:00
|
|
|
|
2017-09-11 17:20:08 +00:00
|
|
|
#define ACPI_READ_TABLE_HEADER(qts, table, addr) \
|
2017-02-16 23:15:38 +00:00
|
|
|
do { \
|
2017-09-11 17:20:08 +00:00
|
|
|
ACPI_READ_FIELD(qts, (table)->signature, addr); \
|
|
|
|
ACPI_READ_FIELD(qts, (table)->length, addr); \
|
|
|
|
ACPI_READ_FIELD(qts, (table)->revision, addr); \
|
|
|
|
ACPI_READ_FIELD(qts, (table)->checksum, addr); \
|
|
|
|
ACPI_READ_ARRAY(qts, (table)->oem_id, addr); \
|
|
|
|
ACPI_READ_ARRAY(qts, (table)->oem_table_id, addr); \
|
|
|
|
ACPI_READ_FIELD(qts, (table)->oem_revision, addr); \
|
|
|
|
ACPI_READ_ARRAY(qts, (table)->asl_compiler_id, addr); \
|
|
|
|
ACPI_READ_FIELD(qts, (table)->asl_compiler_revision, addr); \
|
maint: Fix macros with broken 'do/while(0); ' usage
The point of writing a macro embedded in a 'do { ... } while (0)'
loop (particularly if the macro has multiple statements or would
otherwise end with an 'if' statement) is so that the macro can be
used as a drop-in statement with the caller supplying the
trailing ';'. Although our coding style frowns on brace-less 'if':
if (cond)
statement;
else
something else;
that is the classic case where failure to use do/while(0) wrapping
would cause the 'else' to pair with any embedded 'if' in the macro
rather than the intended outer 'if'. But conversely, if the macro
includes an embedded ';', then the same brace-less coding style
would now have two statements, making the 'else' a syntax error
rather than pairing with the outer 'if'. Thus, even though our
coding style with required braces is not impacted, ending a macro
with ';' makes our code harder to port to projects that use
brace-less styles.
The change should have no semantic impact. I was not able to
fully compile-test all of the changes (as some of them are
examples of the ugly bit-rotting debug print statements that are
completely elided by default, and I didn't want to recompile
with the necessary -D witnesses - cleaning those up is left as a
bite-sized task for another day); I did, however, audit that for
all files touched, all callers of the changed macros DID supply
a trailing ';' at the callsite, and did not appear to be used
as part of a brace-less conditional.
Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20171201232433.25193-7-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-12-01 23:24:32 +00:00
|
|
|
} while (0)
|
2017-02-16 23:15:38 +00:00
|
|
|
|
|
|
|
#define ACPI_ASSERT_CMP(actual, expected) do { \
|
|
|
|
char ACPI_ASSERT_CMP_str[5] = {}; \
|
2017-11-16 12:17:02 +00:00
|
|
|
memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \
|
2017-02-16 23:15:38 +00: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 12:17:02 +00:00
|
|
|
memcpy(ACPI_ASSERT_CMP_str, &actual, 8); \
|
2017-02-16 23:15:38 +00:00
|
|
|
g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
|
|
|
|
} while (0)
|
|
|
|
|
2017-03-15 06:20:26 +00:00
|
|
|
|
|
|
|
|
2017-02-16 23:15:38 +00:00
|
|
|
uint8_t acpi_calc_checksum(const uint8_t *data, int len);
|
2017-09-11 17:20:08 +00:00
|
|
|
uint32_t acpi_find_rsdp_address(QTestState *qts);
|
2018-12-20 15:02:55 +00:00
|
|
|
uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table);
|
|
|
|
uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table);
|
|
|
|
void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr, uint8_t *rsdp_table);
|
2017-02-16 23:15:38 +00:00
|
|
|
|
|
|
|
#endif /* TEST_ACPI_UTILS_H */
|