2013-10-18 01:52:18 +04:00
|
|
|
/*
|
|
|
|
* Boot order test cases.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-10-06 00:25:55 +03:00
|
|
|
/*
|
|
|
|
* How to add or update the tests:
|
|
|
|
* Contributor:
|
|
|
|
* 1. add empty files for new tables, if any, under tests/data/acpi
|
2020-02-02 14:00:09 +03:00
|
|
|
* 2. list any changed files in tests/qtest/bios-tables-test-allowed-diff.h
|
2019-10-06 00:25:55 +03:00
|
|
|
* 3. commit the above *before* making changes that affect the tables
|
2020-01-17 15:18:18 +03:00
|
|
|
*
|
|
|
|
* Contributor or ACPI Maintainer (steps 4-7 need to be redone to resolve conflicts
|
|
|
|
* in binary commit created in step 6):
|
|
|
|
*
|
2019-10-06 00:25:55 +03:00
|
|
|
* After 1-3 above tests will pass but ignore differences with the expected files.
|
2020-02-02 14:00:09 +03:00
|
|
|
* You will also notice that tests/qtest/bios-tables-test-allowed-diff.h lists
|
2019-10-06 00:25:55 +03:00
|
|
|
* a bunch of files. This is your hint that you need to do the below:
|
|
|
|
* 4. Run
|
|
|
|
* make check V=1
|
|
|
|
* this will produce a bunch of warnings about differences
|
|
|
|
* beween actual and expected ACPI tables. If you have IASL installed,
|
|
|
|
* they will also be disassembled so you can look at the disassembled
|
|
|
|
* output. If not - disassemble them yourself in any way you like.
|
|
|
|
* Look at the differences - make sure they make sense and match what the
|
|
|
|
* changes you are merging are supposed to do.
|
2020-01-17 15:18:18 +03:00
|
|
|
* Save the changes, preferably in form of ASL diff for the commit log in
|
|
|
|
* step 6.
|
2019-10-06 00:25:55 +03:00
|
|
|
*
|
|
|
|
* 5. From build directory, run:
|
|
|
|
* $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh
|
2020-01-17 15:18:18 +03:00
|
|
|
* 6. Now commit any changes to the expected binary, include diff from step 4
|
|
|
|
* in commit log.
|
|
|
|
* 7. Before sending patches to the list (Contributor)
|
|
|
|
* or before doing a pull request (Maintainer), make sure
|
2020-02-02 14:00:09 +03:00
|
|
|
* tests/qtest/bios-tables-test-allowed-diff.h is empty - this will ensure
|
2020-01-17 15:18:18 +03:00
|
|
|
* following changes to ACPI tables will be noticed.
|
|
|
|
*
|
|
|
|
* The resulting patchset/pull request then looks like this:
|
2020-02-02 14:00:09 +03:00
|
|
|
* - patch 1: list changed files in tests/qtest/bios-tables-test-allowed-diff.h.
|
2020-01-17 15:18:18 +03:00
|
|
|
* - patches 2 - n: real changes, may contain multiple patches.
|
|
|
|
* - patch n + 1: update golden master binaries and empty
|
2020-02-02 14:00:09 +03:00
|
|
|
* tests/qtest/bios-tables-test-allowed-diff.h
|
2019-10-06 00:25:55 +03:00
|
|
|
*/
|
|
|
|
|
2016-02-08 21:08:51 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-12-26 18:54:25 +04:00
|
|
|
#include <glib/gstdio.h>
|
2013-11-12 20:32:24 +04:00
|
|
|
#include "qemu-common.h"
|
2018-12-11 19:34:06 +03:00
|
|
|
#include "hw/firmware/smbios.h"
|
2014-05-27 23:03:15 +04:00
|
|
|
#include "qemu/bitmap.h"
|
2017-02-17 02:15:38 +03:00
|
|
|
#include "acpi-utils.h"
|
2016-02-14 19:59:27 +03:00
|
|
|
#include "boot-sector.h"
|
2020-06-09 15:54:08 +03:00
|
|
|
#include "tpm-emu.h"
|
|
|
|
#include "hw/acpi/tpm.h"
|
|
|
|
|
2013-10-18 01:52:18 +04:00
|
|
|
|
2013-12-26 18:54:21 +04:00
|
|
|
#define MACHINE_PC "pc"
|
|
|
|
#define MACHINE_Q35 "q35"
|
|
|
|
|
2013-12-26 18:54:25 +04:00
|
|
|
#define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
|
|
|
|
|
2013-11-12 20:32:24 +04:00
|
|
|
typedef struct {
|
2019-11-13 12:10:47 +03:00
|
|
|
bool tcg_only;
|
2013-12-26 18:54:21 +04:00
|
|
|
const char *machine;
|
2015-02-20 21:22:14 +03:00
|
|
|
const char *variant;
|
2019-05-02 17:51:57 +03:00
|
|
|
const char *uefi_fl1;
|
|
|
|
const char *uefi_fl2;
|
2020-09-15 15:09:06 +03:00
|
|
|
const char *blkdev;
|
2019-05-02 17:51:57 +03:00
|
|
|
const char *cd;
|
|
|
|
const uint64_t ram_start;
|
|
|
|
const uint64_t scan_len;
|
2019-05-02 17:51:52 +03:00
|
|
|
uint64_t rsdp_addr;
|
2018-12-20 18:02:55 +03:00
|
|
|
uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
|
2014-01-16 19:50:46 +04:00
|
|
|
GArray *tables;
|
2014-05-27 23:03:15 +04:00
|
|
|
uint32_t smbios_ep_addr;
|
2015-09-07 12:39:28 +03:00
|
|
|
struct smbios_21_entry_point smbios_ep_table;
|
2020-08-06 06:56:34 +03:00
|
|
|
uint16_t smbios_cpu_max_speed;
|
|
|
|
uint16_t smbios_cpu_curr_speed;
|
2016-06-10 12:15:43 +03:00
|
|
|
uint8_t *required_struct_types;
|
|
|
|
int required_struct_types_len;
|
2017-09-11 20:20:08 +03:00
|
|
|
QTestState *qts;
|
2013-11-12 20:32:24 +04:00
|
|
|
} test_data;
|
2013-10-18 01:52:18 +04:00
|
|
|
|
2016-10-11 18:19:36 +03:00
|
|
|
static char disk[] = "tests/acpi-test-disk-XXXXXX";
|
tests: Move tests/acpi-test-data/ to tests/data/acpi/
Currently tests/acpi-test-data contains data files used by the
bios-tables-test, and configure individually symlinks those
data files into the build directory using a wildcard.
Using a wildcard like this is a bad idea, because if a new
data file is added, nothing causes configure to be rerun,
and so no symlink is added for the new file. This can cause
tests to spuriously fail when they can't find their data.
Instead, it's better to symlink an entire directory of
data files. We already have such a directory: tests/data.
Move the data files from tests/acpi-test-data/ to
tests/data/acpi/, and remove the unnecessary symlinking.
We can remove entirely the note in rebuild-expected-aml.sh
about copying any new data files, because now they will
be in the source directory, not the build directory, and
no copying is required.
(We can't just change the existing tests/acpi-test-data/
to being a symlinked directory, because if we did that and
a developer switched git branches from one after that change
to one before it then configure would end up trashing all
the test files by making them symlinks to themselves.
Changing their path avoids this annoyance.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-11-02 14:52:36 +03:00
|
|
|
static const char *data_dir = "tests/data/acpi";
|
2013-12-26 18:54:23 +04:00
|
|
|
#ifdef CONFIG_IASL
|
2020-08-04 19:14:26 +03:00
|
|
|
static const char *iasl = CONFIG_IASL;
|
2013-12-26 18:54:23 +04:00
|
|
|
#else
|
|
|
|
static const char *iasl;
|
|
|
|
#endif
|
2013-10-18 01:52:18 +04:00
|
|
|
|
2018-12-27 17:13:34 +03:00
|
|
|
static bool compare_signature(const AcpiSdtTable *sdt, const char *signature)
|
|
|
|
{
|
|
|
|
return !memcmp(sdt->aml, signature, 4);
|
|
|
|
}
|
|
|
|
|
2018-12-27 17:13:29 +03:00
|
|
|
static void cleanup_table_descriptor(AcpiSdtTable *table)
|
|
|
|
{
|
|
|
|
g_free(table->aml);
|
|
|
|
if (table->aml_file &&
|
|
|
|
!table->tmp_files_retain &&
|
|
|
|
g_strstr_len(table->aml_file, -1, "aml-")) {
|
|
|
|
unlink(table->aml_file);
|
|
|
|
}
|
|
|
|
g_free(table->aml_file);
|
|
|
|
g_free(table->asl);
|
|
|
|
if (table->asl_file &&
|
|
|
|
!table->tmp_files_retain) {
|
|
|
|
unlink(table->asl_file);
|
|
|
|
}
|
|
|
|
g_free(table->asl_file);
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:22 +04:00
|
|
|
static void free_test_data(test_data *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
for (i = 0; i < data->tables->len; ++i) {
|
2018-12-27 17:13:29 +03:00
|
|
|
cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
|
2013-11-21 23:33:22 +04:00
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
|
2017-02-05 13:48:20 +03:00
|
|
|
g_array_free(data->tables, true);
|
2013-11-21 23:33:22 +04:00
|
|
|
}
|
|
|
|
|
2013-11-12 20:32:24 +04:00
|
|
|
static void test_acpi_rsdp_table(test_data *data)
|
|
|
|
{
|
2019-05-02 17:51:52 +03:00
|
|
|
uint8_t *rsdp_table = data->rsdp_table;
|
2013-11-12 20:32:24 +04:00
|
|
|
|
2019-05-02 17:51:52 +03:00
|
|
|
acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
|
2018-12-20 18:02:55 +03:00
|
|
|
|
2019-05-02 17:51:52 +03:00
|
|
|
switch (rsdp_table[15 /* Revision offset */]) {
|
2018-12-20 18:02:55 +03:00
|
|
|
case 0: /* ACPI 1.0 RSDP */
|
|
|
|
/* With rev 1, checksum is only for the first 20 bytes */
|
|
|
|
g_assert(!acpi_calc_checksum(rsdp_table, 20));
|
|
|
|
break;
|
|
|
|
case 2: /* ACPI 2.0+ RSDP */
|
|
|
|
/* With revision 2, we have 2 checksums */
|
|
|
|
g_assert(!acpi_calc_checksum(rsdp_table, 20));
|
|
|
|
g_assert(!acpi_calc_checksum(rsdp_table, 36));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2013-11-12 20:32:24 +04:00
|
|
|
}
|
|
|
|
|
2019-05-02 17:51:51 +03:00
|
|
|
static void test_acpi_rxsdt_table(test_data *data)
|
2013-11-12 20:32:24 +04:00
|
|
|
{
|
2019-05-02 17:51:51 +03:00
|
|
|
const char *sig = "RSDT";
|
2018-12-27 17:13:29 +03:00
|
|
|
AcpiSdtTable rsdt = {};
|
2019-05-02 17:51:51 +03:00
|
|
|
int entry_size = 4;
|
|
|
|
int addr_off = 16 /* RsdtAddress */;
|
2018-12-27 17:13:31 +03:00
|
|
|
uint8_t *ent;
|
2018-12-27 17:13:29 +03:00
|
|
|
|
2019-05-02 17:51:51 +03:00
|
|
|
if (data->rsdp_table[15 /* Revision offset */] != 0) {
|
|
|
|
addr_off = 24 /* XsdtAddress */;
|
|
|
|
entry_size = 8;
|
|
|
|
sig = "XSDT";
|
|
|
|
}
|
|
|
|
/* read [RX]SDT table */
|
2018-12-27 17:13:31 +03:00
|
|
|
acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
|
2019-05-02 17:51:51 +03:00
|
|
|
&data->rsdp_table[addr_off], entry_size, sig, true);
|
2018-12-27 17:13:29 +03:00
|
|
|
|
|
|
|
/* Load all tables and add to test list directly RSDT referenced tables */
|
2019-05-02 17:51:51 +03:00
|
|
|
ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
|
2018-12-27 17:13:29 +03:00
|
|
|
AcpiSdtTable ssdt_table = {};
|
|
|
|
|
2018-12-27 17:13:31 +03:00
|
|
|
acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
|
2019-05-02 17:51:51 +03:00
|
|
|
entry_size, NULL, true);
|
2018-12-27 17:13:29 +03:00
|
|
|
/* Add table to ASL test tables list */
|
|
|
|
g_array_append_val(data->tables, ssdt_table);
|
|
|
|
}
|
|
|
|
cleanup_table_descriptor(&rsdt);
|
2013-11-12 20:32:24 +04:00
|
|
|
}
|
|
|
|
|
2018-12-27 17:13:28 +03:00
|
|
|
static void test_acpi_fadt_table(test_data *data)
|
2013-11-12 20:32:24 +04:00
|
|
|
{
|
2018-12-27 17:13:28 +03:00
|
|
|
/* FADT table is 1st */
|
2018-12-27 17:13:30 +03:00
|
|
|
AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
|
|
|
|
uint8_t *fadt_aml = table.aml;
|
2018-12-27 17:13:33 +03:00
|
|
|
uint32_t fadt_len = table.aml_len;
|
2019-05-02 17:51:53 +03:00
|
|
|
uint32_t val;
|
|
|
|
int dsdt_offset = 40 /* DSDT */;
|
|
|
|
int dsdt_entry_size = 4;
|
2013-11-12 20:32:24 +04:00
|
|
|
|
2018-12-27 17:13:34 +03:00
|
|
|
g_assert(compare_signature(&table, "FACP"));
|
2018-02-28 17:23:55 +03:00
|
|
|
|
2018-12-27 17:13:30 +03:00
|
|
|
/* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
|
2019-05-02 17:51:54 +03:00
|
|
|
memcpy(&val, fadt_aml + 112 /* Flags */, 4);
|
|
|
|
val = le32_to_cpu(val);
|
|
|
|
if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
|
|
|
|
acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
|
|
|
|
fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
|
|
|
|
g_array_append_val(data->tables, table);
|
|
|
|
}
|
2018-12-27 17:13:30 +03:00
|
|
|
|
2019-05-02 17:51:53 +03:00
|
|
|
memcpy(&val, fadt_aml + dsdt_offset, 4);
|
|
|
|
val = le32_to_cpu(val);
|
|
|
|
if (!val) {
|
|
|
|
dsdt_offset = 140 /* X_DSDT */;
|
|
|
|
dsdt_entry_size = 8;
|
|
|
|
}
|
2018-12-27 17:13:31 +03:00
|
|
|
acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
|
2019-05-02 17:51:53 +03:00
|
|
|
fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
|
2018-12-27 17:13:30 +03:00
|
|
|
g_array_append_val(data->tables, table);
|
2018-01-16 18:30:26 +03:00
|
|
|
|
2018-12-27 17:13:33 +03:00
|
|
|
memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
|
|
|
|
memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
|
|
|
|
if (fadt_aml[8 /* FADT Major Version */] >= 3) {
|
|
|
|
memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
|
|
|
|
memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
|
2018-01-16 18:30:26 +03:00
|
|
|
}
|
2018-12-27 17:13:33 +03:00
|
|
|
|
|
|
|
/* update checksum */
|
|
|
|
fadt_aml[9 /* Checksum */] = 0;
|
|
|
|
fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
|
2018-01-16 18:30:26 +03:00
|
|
|
}
|
|
|
|
|
2013-12-26 18:54:25 +04:00
|
|
|
static void dump_aml_files(test_data *data, bool rebuild)
|
2013-12-26 18:54:21 +04:00
|
|
|
{
|
|
|
|
AcpiSdtTable *sdt;
|
|
|
|
GError *error = NULL;
|
2013-12-26 18:54:25 +04:00
|
|
|
gchar *aml_file = NULL;
|
2013-12-26 18:54:21 +04:00
|
|
|
gint fd;
|
|
|
|
ssize_t ret;
|
|
|
|
int i;
|
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
for (i = 0; i < data->tables->len; ++i) {
|
2015-02-20 21:22:14 +03:00
|
|
|
const char *ext = data->variant ? data->variant : "";
|
2014-01-16 19:50:46 +04:00
|
|
|
sdt = &g_array_index(data->tables, AcpiSdtTable, i);
|
2013-12-26 18:54:21 +04:00
|
|
|
g_assert(sdt->aml);
|
|
|
|
|
2013-12-26 18:54:25 +04:00
|
|
|
if (rebuild) {
|
2015-02-20 21:22:14 +03:00
|
|
|
aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
|
2018-12-27 17:13:34 +03:00
|
|
|
sdt->aml, ext);
|
2013-12-26 18:54:25 +04:00
|
|
|
fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
|
|
|
|
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
|
2019-05-02 17:52:03 +03:00
|
|
|
if (fd < 0) {
|
|
|
|
perror(aml_file);
|
|
|
|
}
|
|
|
|
g_assert(fd >= 0);
|
2013-12-26 18:54:25 +04:00
|
|
|
} else {
|
|
|
|
fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
|
|
|
|
g_assert_no_error(error);
|
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
|
|
|
|
ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
|
|
|
|
g_assert(ret == sdt->aml_len);
|
|
|
|
|
|
|
|
close(fd);
|
2013-12-26 18:54:25 +04:00
|
|
|
|
2015-08-26 14:17:18 +03:00
|
|
|
g_free(aml_file);
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 18:17:32 +04:00
|
|
|
static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
|
2013-12-26 18:54:21 +04:00
|
|
|
{
|
|
|
|
AcpiSdtTable *temp;
|
|
|
|
GError *error = NULL;
|
2013-12-26 18:54:23 +04:00
|
|
|
GString *command_line = g_string_new(iasl);
|
2013-12-26 18:54:21 +04:00
|
|
|
gint fd;
|
|
|
|
gchar *out, *out_err;
|
|
|
|
gboolean ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
|
|
|
|
g_assert_no_error(error);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
/* build command line */
|
2013-12-26 18:54:23 +04:00
|
|
|
g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
|
2014-03-18 18:42:05 +04:00
|
|
|
if (compare_signature(sdt, "DSDT") ||
|
|
|
|
compare_signature(sdt, "SSDT")) {
|
2014-01-16 19:50:47 +04:00
|
|
|
for (i = 0; i < sdts->len; ++i) {
|
|
|
|
temp = &g_array_index(sdts, AcpiSdtTable, i);
|
2014-03-18 18:42:05 +04:00
|
|
|
if (compare_signature(temp, "DSDT") ||
|
|
|
|
compare_signature(temp, "SSDT")) {
|
2014-01-16 19:50:47 +04:00
|
|
|
g_string_append_printf(command_line, "-e %s ", temp->aml_file);
|
|
|
|
}
|
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
g_string_append_printf(command_line, "-d %s", sdt->aml_file);
|
|
|
|
|
|
|
|
/* pass 'out' and 'out_err' in order to be redirected */
|
2014-02-27 18:17:32 +04:00
|
|
|
ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
|
2013-12-26 18:54:21 +04:00
|
|
|
g_assert_no_error(error);
|
2014-02-27 18:17:32 +04:00
|
|
|
if (ret) {
|
2018-07-05 18:58:08 +03:00
|
|
|
ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
|
2014-02-27 18:17:32 +04:00
|
|
|
&sdt->asl_len, &error);
|
|
|
|
g_assert(ret);
|
|
|
|
g_assert_no_error(error);
|
2014-03-24 14:02:33 +04:00
|
|
|
ret = (sdt->asl_len > 0);
|
2014-02-27 18:17:32 +04:00
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
|
|
|
|
g_free(out);
|
|
|
|
g_free(out_err);
|
|
|
|
g_string_free(command_line, true);
|
2014-02-27 18:17:32 +04:00
|
|
|
|
|
|
|
return !ret;
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define COMMENT_END "*/"
|
|
|
|
#define DEF_BLOCK "DefinitionBlock ("
|
2016-04-04 20:00:57 +03:00
|
|
|
#define BLOCK_NAME_END ","
|
2013-12-26 18:54:21 +04:00
|
|
|
|
|
|
|
static GString *normalize_asl(gchar *asl_code)
|
|
|
|
{
|
|
|
|
GString *asl = g_string_new(asl_code);
|
|
|
|
gchar *comment, *block_name;
|
|
|
|
|
|
|
|
/* strip comments (different generation days) */
|
|
|
|
comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
|
|
|
|
if (comment) {
|
2014-07-28 19:34:17 +04:00
|
|
|
comment += strlen(COMMENT_END);
|
|
|
|
while (*comment == '\n') {
|
|
|
|
comment++;
|
|
|
|
}
|
|
|
|
asl = g_string_erase(asl, 0, comment - asl->str);
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* strip def block name (it has file path in it) */
|
|
|
|
if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
|
|
|
|
block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
|
|
|
|
g_assert(block_name);
|
|
|
|
asl = g_string_erase(asl, 0,
|
|
|
|
block_name + sizeof(BLOCK_NAME_END) - asl->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return asl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GArray *load_expected_aml(test_data *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
AcpiSdtTable *sdt;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret;
|
2018-12-27 17:13:31 +03:00
|
|
|
gsize aml_len;
|
2013-12-26 18:54:21 +04:00
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
|
2018-10-30 03:18:40 +03:00
|
|
|
if (getenv("V")) {
|
|
|
|
fputc('\n', stderr);
|
|
|
|
}
|
2014-01-16 19:50:46 +04:00
|
|
|
for (i = 0; i < data->tables->len; ++i) {
|
2013-12-26 18:54:21 +04:00
|
|
|
AcpiSdtTable exp_sdt;
|
2016-05-26 12:46:45 +03:00
|
|
|
gchar *aml_file = NULL;
|
2015-02-20 21:22:14 +03:00
|
|
|
const char *ext = data->variant ? data->variant : "";
|
2014-03-18 18:42:05 +04:00
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
sdt = &g_array_index(data->tables, AcpiSdtTable, i);
|
2013-12-26 18:54:21 +04:00
|
|
|
|
|
|
|
memset(&exp_sdt, 0, sizeof(exp_sdt));
|
|
|
|
|
2015-02-20 21:22:14 +03:00
|
|
|
try_again:
|
|
|
|
aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
|
2018-12-27 17:13:34 +03:00
|
|
|
sdt->aml, ext);
|
2016-05-26 12:46:45 +03:00
|
|
|
if (getenv("V")) {
|
2018-10-30 03:18:40 +03:00
|
|
|
fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
|
2016-05-26 12:46:45 +03:00
|
|
|
}
|
|
|
|
if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
|
|
|
|
exp_sdt.aml_file = aml_file;
|
|
|
|
} else if (*ext != '\0') {
|
2018-07-13 08:47:55 +03:00
|
|
|
/* try fallback to generic (extension less) expected file */
|
2015-02-20 21:22:14 +03:00
|
|
|
ext = "";
|
2016-05-26 12:46:45 +03:00
|
|
|
g_free(aml_file);
|
2015-02-20 21:22:14 +03:00
|
|
|
goto try_again;
|
|
|
|
}
|
2016-05-26 12:46:45 +03:00
|
|
|
g_assert(exp_sdt.aml_file);
|
|
|
|
if (getenv("V")) {
|
2018-10-30 03:18:40 +03:00
|
|
|
fprintf(stderr, "Using expected file '%s'\n", aml_file);
|
2016-05-26 12:46:45 +03:00
|
|
|
}
|
2018-12-27 17:13:27 +03:00
|
|
|
ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
|
2018-12-27 17:13:31 +03:00
|
|
|
&aml_len, &error);
|
|
|
|
exp_sdt.aml_len = aml_len;
|
2013-12-26 18:54:21 +04:00
|
|
|
g_assert(ret);
|
|
|
|
g_assert_no_error(error);
|
|
|
|
g_assert(exp_sdt.aml);
|
2019-10-06 00:09:17 +03:00
|
|
|
if (!exp_sdt.aml_len) {
|
|
|
|
fprintf(stderr, "Warning! zero length expected file '%s'\n",
|
|
|
|
aml_file);
|
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
g_array_append_val(exp_tables, exp_sdt);
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
return exp_tables;
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
|
2019-05-22 00:38:47 +03:00
|
|
|
static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt)
|
|
|
|
{
|
|
|
|
const gchar *allowed_diff_file[] = {
|
|
|
|
#include "bios-tables-test-allowed-diff.h"
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
const gchar **f;
|
|
|
|
|
|
|
|
for (f = allowed_diff_file; *f; ++f) {
|
|
|
|
if (!g_strcmp0(sdt->aml_file, *f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-29 18:16:41 +03:00
|
|
|
/* test the list of tables in @data->tables against reference tables */
|
2013-12-26 18:54:21 +04:00
|
|
|
static void test_acpi_asl(test_data *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
AcpiSdtTable *sdt, *exp_sdt;
|
|
|
|
test_data exp_data;
|
2019-06-03 04:29:27 +03:00
|
|
|
gboolean exp_err, err, all_tables_match = true;
|
2013-12-26 18:54:21 +04:00
|
|
|
|
|
|
|
memset(&exp_data, 0, sizeof(exp_data));
|
2014-01-16 19:50:46 +04:00
|
|
|
exp_data.tables = load_expected_aml(data);
|
2013-12-26 18:54:25 +04:00
|
|
|
dump_aml_files(data, false);
|
2014-01-16 19:50:46 +04:00
|
|
|
for (i = 0; i < data->tables->len; ++i) {
|
2013-12-26 18:54:21 +04:00
|
|
|
GString *asl, *exp_asl;
|
|
|
|
|
2014-01-16 19:50:46 +04:00
|
|
|
sdt = &g_array_index(data->tables, AcpiSdtTable, i);
|
|
|
|
exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
|
2013-12-26 18:54:21 +04:00
|
|
|
|
2019-06-05 06:41:32 +03:00
|
|
|
if (sdt->aml_len == exp_sdt->aml_len &&
|
|
|
|
!memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
|
|
|
|
/* Identical table binaries: no need to disassemble. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
"acpi-test: Warning! %.4s binary file mismatch. "
|
2020-01-22 10:20:36 +03:00
|
|
|
"Actual [aml:%s], Expected [aml:%s].\n"
|
|
|
|
"See source file tests/qtest/bios-tables-test.c "
|
|
|
|
"for instructions on how to update expected files.\n",
|
2019-06-05 06:41:32 +03:00
|
|
|
exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file);
|
|
|
|
|
|
|
|
all_tables_match = all_tables_match &&
|
|
|
|
test_acpi_find_diff_allowed(exp_sdt);
|
|
|
|
|
2019-07-08 12:24:10 +03:00
|
|
|
/*
|
|
|
|
* don't try to decompile if IASL isn't present, in this case user
|
|
|
|
* will just 'get binary file mismatch' warnings and test failure
|
|
|
|
*/
|
|
|
|
if (!iasl) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-27 18:17:32 +04:00
|
|
|
err = load_asl(data->tables, sdt);
|
2013-12-26 18:54:21 +04:00
|
|
|
asl = normalize_asl(sdt->asl);
|
|
|
|
|
2014-02-27 18:17:32 +04:00
|
|
|
exp_err = load_asl(exp_data.tables, exp_sdt);
|
2013-12-26 18:54:21 +04:00
|
|
|
exp_asl = normalize_asl(exp_sdt->asl);
|
|
|
|
|
2014-02-27 18:17:32 +04:00
|
|
|
/* TODO: check for warnings */
|
|
|
|
g_assert(!err || exp_err);
|
|
|
|
|
2014-01-16 19:50:48 +04:00
|
|
|
if (g_strcmp0(asl->str, exp_asl->str)) {
|
2019-11-20 12:02:40 +03:00
|
|
|
sdt->tmp_files_retain = true;
|
2014-03-24 14:02:33 +04:00
|
|
|
if (exp_err) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Warning! iasl couldn't parse the expected aml\n");
|
|
|
|
} else {
|
|
|
|
exp_sdt->tmp_files_retain = true;
|
|
|
|
fprintf(stderr,
|
|
|
|
"acpi-test: Warning! %.4s mismatch. "
|
|
|
|
"Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
|
2018-12-27 17:13:34 +03:00
|
|
|
exp_sdt->aml, sdt->asl_file, sdt->aml_file,
|
2014-03-24 14:02:33 +04:00
|
|
|
exp_sdt->asl_file, exp_sdt->aml_file);
|
2020-01-22 10:21:18 +03:00
|
|
|
fflush(stderr);
|
2015-12-28 20:02:08 +03:00
|
|
|
if (getenv("V")) {
|
2020-01-22 10:24:54 +03:00
|
|
|
const char *diff_env = getenv("DIFF");
|
2020-06-19 12:18:55 +03:00
|
|
|
const char *diff_cmd = diff_env ? diff_env : "diff -U 16";
|
2020-01-22 10:24:54 +03:00
|
|
|
char *diff = g_strdup_printf("%s %s %s", diff_cmd,
|
|
|
|
exp_sdt->asl_file, sdt->asl_file);
|
|
|
|
int out = dup(STDOUT_FILENO);
|
|
|
|
int ret G_GNUC_UNUSED;
|
|
|
|
|
|
|
|
dup2(STDERR_FILENO, STDOUT_FILENO);
|
|
|
|
ret = system(diff) ;
|
|
|
|
dup2(out, STDOUT_FILENO);
|
|
|
|
close(out);
|
|
|
|
g_free(diff);
|
2015-12-28 20:02:08 +03:00
|
|
|
}
|
2019-05-22 00:38:47 +03:00
|
|
|
}
|
2014-01-16 19:50:48 +04:00
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
g_string_free(asl, true);
|
|
|
|
g_string_free(exp_asl, true);
|
|
|
|
}
|
2019-07-08 12:24:10 +03:00
|
|
|
if (!iasl && !all_tables_match) {
|
|
|
|
fprintf(stderr, "to see ASL diff between mismatched files install IASL,"
|
|
|
|
" rebuild QEMU from scratch and re-run tests with V=1"
|
|
|
|
" environment variable set");
|
|
|
|
}
|
2019-06-03 04:29:27 +03:00
|
|
|
g_assert(all_tables_match);
|
2013-12-26 18:54:21 +04:00
|
|
|
|
|
|
|
free_test_data(&exp_data);
|
2013-11-12 20:32:24 +04:00
|
|
|
}
|
|
|
|
|
2015-05-18 15:47:24 +03:00
|
|
|
static bool smbios_ep_table_ok(test_data *data)
|
2014-05-27 23:03:15 +04:00
|
|
|
{
|
2015-09-07 12:39:28 +03:00
|
|
|
struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
|
2014-05-27 23:03:15 +04:00
|
|
|
uint32_t addr = data->smbios_ep_addr;
|
|
|
|
|
2018-12-27 17:13:32 +03:00
|
|
|
qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
|
2015-05-18 15:47:24 +03:00
|
|
|
if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ep_table->structure_table_length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ep_table->number_of_structures == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-17 02:15:38 +03:00
|
|
|
if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
|
|
|
|
acpi_calc_checksum((uint8_t *)ep_table + 0x10,
|
|
|
|
sizeof *ep_table - 0x10)) {
|
2015-05-18 15:47:24 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_smbios_entry_point(test_data *data)
|
|
|
|
{
|
|
|
|
uint32_t off;
|
|
|
|
|
|
|
|
/* find smbios entry point structure */
|
|
|
|
for (off = 0xf0000; off < 0x100000; off += 0x10) {
|
|
|
|
uint8_t sig[] = "_SM_";
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof sig - 1; ++i) {
|
2017-09-11 20:20:08 +03:00
|
|
|
sig[i] = qtest_readb(data->qts, off + i);
|
2015-05-18 15:47:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(sig, "_SM_", sizeof sig)) {
|
|
|
|
/* signature match, but is this a valid entry point? */
|
|
|
|
data->smbios_ep_addr = off;
|
|
|
|
if (smbios_ep_table_ok(data)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_cmphex(off, <, 0x100000);
|
2014-05-27 23:03:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool smbios_single_instance(uint8_t type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 16:
|
|
|
|
case 32:
|
|
|
|
case 127:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 06:56:34 +03:00
|
|
|
static bool smbios_cpu_test(test_data *data, uint32_t addr)
|
|
|
|
{
|
|
|
|
uint16_t expect_speed[2];
|
|
|
|
uint16_t real;
|
|
|
|
int offset[2];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Check CPU speed for backward compatibility */
|
|
|
|
offset[0] = offsetof(struct smbios_type_4, max_speed);
|
|
|
|
offset[1] = offsetof(struct smbios_type_4, current_speed);
|
|
|
|
expect_speed[0] = data->smbios_cpu_max_speed ? : 2000;
|
|
|
|
expect_speed[1] = data->smbios_cpu_curr_speed ? : 2000;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
real = qtest_readw(data->qts, addr + offset[i]);
|
|
|
|
if (real != expect_speed[i]) {
|
|
|
|
fprintf(stderr, "Unexpected SMBIOS CPU speed: real %u expect %u\n",
|
|
|
|
real, expect_speed[i]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-27 23:03:15 +04:00
|
|
|
static void test_smbios_structs(test_data *data)
|
|
|
|
{
|
|
|
|
DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
|
2015-09-07 12:39:28 +03:00
|
|
|
struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
|
2017-11-16 15:17:02 +03:00
|
|
|
uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
|
2014-05-27 23:03:15 +04:00
|
|
|
int i, len, max_len = 0;
|
|
|
|
uint8_t type, prv, crt;
|
|
|
|
|
|
|
|
/* walk the smbios tables */
|
2017-11-16 15:17:02 +03:00
|
|
|
for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
|
2014-05-27 23:03:15 +04:00
|
|
|
|
|
|
|
/* grab type and formatted area length from struct header */
|
2017-09-11 20:20:08 +03:00
|
|
|
type = qtest_readb(data->qts, addr);
|
2014-05-27 23:03:15 +04:00
|
|
|
g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
|
2017-09-11 20:20:08 +03:00
|
|
|
len = qtest_readb(data->qts, addr + 1);
|
2014-05-27 23:03:15 +04:00
|
|
|
|
|
|
|
/* single-instance structs must not have been encountered before */
|
|
|
|
if (smbios_single_instance(type)) {
|
|
|
|
g_assert(!test_bit(type, struct_bitmap));
|
|
|
|
}
|
|
|
|
set_bit(type, struct_bitmap);
|
|
|
|
|
2020-08-06 06:56:34 +03:00
|
|
|
if (type == 4) {
|
|
|
|
g_assert(smbios_cpu_test(data, addr));
|
|
|
|
}
|
|
|
|
|
2014-05-27 23:03:15 +04:00
|
|
|
/* seek to end of unformatted string area of this struct ("\0\0") */
|
|
|
|
prv = crt = 1;
|
|
|
|
while (prv || crt) {
|
|
|
|
prv = crt;
|
2017-09-11 20:20:08 +03:00
|
|
|
crt = qtest_readb(data->qts, addr + len);
|
2014-05-27 23:03:15 +04:00
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keep track of max. struct size */
|
|
|
|
if (max_len < len) {
|
|
|
|
max_len = len;
|
|
|
|
g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start of next structure */
|
|
|
|
addr += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* total table length and max struct size must match entry point values */
|
2017-11-16 15:17:02 +03:00
|
|
|
g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
|
|
|
|
addr - le32_to_cpu(ep_table->structure_table_address));
|
|
|
|
g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
|
2014-05-27 23:03:15 +04:00
|
|
|
|
|
|
|
/* required struct types must all be present */
|
2016-06-10 12:15:43 +03:00
|
|
|
for (i = 0; i < data->required_struct_types_len; i++) {
|
|
|
|
g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
|
2014-05-27 23:03:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:22 +04:00
|
|
|
static void test_acpi_one(const char *params, test_data *data)
|
2013-10-18 01:52:18 +04:00
|
|
|
{
|
|
|
|
char *args;
|
2019-05-02 17:51:57 +03:00
|
|
|
bool use_uefi = data->uefi_fl1 && data->uefi_fl2;
|
|
|
|
|
|
|
|
if (use_uefi) {
|
|
|
|
/*
|
|
|
|
* TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
|
|
|
|
* when arm/virt boad starts to support it.
|
|
|
|
*/
|
2019-11-13 12:10:47 +03:00
|
|
|
args = g_strdup_printf("-machine %s %s -accel tcg -nodefaults -nographic "
|
2019-05-02 17:51:57 +03:00
|
|
|
"-drive if=pflash,format=raw,file=%s,readonly "
|
|
|
|
"-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
|
2019-11-13 12:10:47 +03:00
|
|
|
data->machine, data->tcg_only ? "" : "-accel kvm",
|
tests: acpi: allow to override default accelerator
By default test cases were run with 'kvm:tcg' accelerators to speed up
tests execution. While it works for x86, were change of accelerator
doesn't affect ACPI tables, the approach doesn't works for ARM usecase
though.
In arm/virt case, KVM mode requires using 'host' cpu model, which
isn't available in TCG mode. That could be worked around with 'max'
cpu model, which works both for KVM and TCG. However in KVM mode it
is necessary to specify matching GIC version, which also could use
'max' value to automatically pick GIC version suitable for host's CPU.
Depending on host cpu type, different GIC versions would be used,
which in turn leads to different ACPI tables (APIC) generated.
As result while comparing with reference blobs, test would fail if
host's GIC version won't match the version on the host where
reference blobs where generated.
Let's keep testing simple for now and allow ARM tests run in TCG only
mode. To do so introduce 'accel' parameter in test configuration, so
test case could override default "kvm:tcg" with accelerator of choice.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Message-Id: <1556808723-226478-12-git-send-email-imammedo@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2019-05-02 17:51:59 +03:00
|
|
|
data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
|
2019-05-02 17:51:57 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Disable kernel irqchip to be able to override apic irq0. */
|
2019-11-13 12:10:47 +03:00
|
|
|
args = g_strdup_printf("-machine %s,kernel-irqchip=off %s -accel tcg "
|
2019-05-02 17:51:57 +03:00
|
|
|
"-net none -display none %s "
|
|
|
|
"-drive id=hd0,if=none,file=%s,format=raw "
|
2020-09-15 15:09:06 +03:00
|
|
|
"-device %s,drive=hd0 ",
|
2019-11-13 12:10:47 +03:00
|
|
|
data->machine, data->tcg_only ? "" : "-accel kvm",
|
2020-09-15 15:09:06 +03:00
|
|
|
params ? params : "", disk,
|
|
|
|
data->blkdev ?: "ide-hd");
|
2019-05-02 17:51:57 +03:00
|
|
|
}
|
2013-12-26 18:54:21 +04:00
|
|
|
|
2017-09-11 20:20:08 +03:00
|
|
|
data->qts = qtest_init(args);
|
2013-10-18 01:52:18 +04:00
|
|
|
|
2019-05-02 17:51:57 +03:00
|
|
|
if (use_uefi) {
|
|
|
|
g_assert(data->scan_len);
|
|
|
|
data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts,
|
|
|
|
data->ram_start, data->scan_len);
|
|
|
|
} else {
|
|
|
|
boot_sector_test(data->qts);
|
|
|
|
data->rsdp_addr = acpi_find_rsdp_address(data->qts);
|
|
|
|
g_assert_cmphex(data->rsdp_addr, <, 0x100000);
|
|
|
|
}
|
2013-10-18 01:52:18 +04:00
|
|
|
|
2017-12-29 18:16:38 +03:00
|
|
|
data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
|
2013-11-21 23:33:22 +04:00
|
|
|
test_acpi_rsdp_table(data);
|
2019-05-02 17:51:51 +03:00
|
|
|
test_acpi_rxsdt_table(data);
|
2018-12-27 17:13:28 +03:00
|
|
|
test_acpi_fadt_table(data);
|
2013-10-18 01:52:18 +04:00
|
|
|
|
2019-07-08 12:24:09 +03:00
|
|
|
if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
|
|
|
|
dump_aml_files(data, true);
|
2019-07-08 12:24:10 +03:00
|
|
|
} else {
|
2019-07-08 12:24:09 +03:00
|
|
|
test_acpi_asl(data);
|
2013-12-26 18:54:21 +04:00
|
|
|
}
|
|
|
|
|
2019-05-02 17:51:58 +03:00
|
|
|
/*
|
|
|
|
* TODO: make SMBIOS tests work with UEFI firmware,
|
|
|
|
* Bug on uefi-test-tools to provide entry point:
|
|
|
|
* https://bugs.launchpad.net/qemu/+bug/1821884
|
|
|
|
*/
|
|
|
|
if (!use_uefi) {
|
|
|
|
test_smbios_entry_point(data);
|
|
|
|
test_smbios_structs(data);
|
|
|
|
}
|
2014-05-27 23:03:15 +04:00
|
|
|
|
2017-09-11 20:20:08 +03:00
|
|
|
qtest_quit(data->qts);
|
2013-10-18 01:52:18 +04:00
|
|
|
g_free(args);
|
|
|
|
}
|
|
|
|
|
2016-06-10 12:15:43 +03:00
|
|
|
static uint8_t base_required_struct_types[] = {
|
|
|
|
0, 1, 3, 4, 16, 17, 19, 32, 127
|
|
|
|
};
|
|
|
|
|
2015-01-19 19:50:38 +03:00
|
|
|
static void test_acpi_piix4_tcg(void)
|
2013-10-18 01:52:18 +04:00
|
|
|
{
|
2013-11-21 23:33:22 +04:00
|
|
|
test_data data;
|
|
|
|
|
2013-10-18 01:52:18 +04:00
|
|
|
/* Supplying -machine accel argument overrides the default (qtest).
|
|
|
|
* This is to make guest actually run.
|
|
|
|
*/
|
2013-12-26 18:54:21 +04:00
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_PC;
|
2016-06-10 12:15:43 +03:00
|
|
|
data.required_struct_types = base_required_struct_types;
|
|
|
|
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
2016-09-06 22:19:22 +03:00
|
|
|
test_acpi_one(NULL, &data);
|
2013-12-26 18:54:21 +04:00
|
|
|
free_test_data(&data);
|
2015-01-19 19:50:38 +03:00
|
|
|
}
|
|
|
|
|
2015-02-20 21:22:14 +03:00
|
|
|
static void test_acpi_piix4_tcg_bridge(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_PC;
|
|
|
|
data.variant = ".bridge";
|
2016-06-10 12:15:43 +03:00
|
|
|
data.required_struct_types = base_required_struct_types;
|
|
|
|
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
2016-09-06 22:19:22 +03:00
|
|
|
test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
|
2015-02-20 21:22:14 +03:00
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2015-01-19 19:50:38 +03:00
|
|
|
static void test_acpi_q35_tcg(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
2013-11-21 23:33:22 +04:00
|
|
|
|
2013-12-26 18:54:21 +04:00
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_Q35;
|
2016-06-10 12:15:43 +03:00
|
|
|
data.required_struct_types = base_required_struct_types;
|
|
|
|
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
2016-09-06 22:19:22 +03:00
|
|
|
test_acpi_one(NULL, &data);
|
2013-11-21 23:33:22 +04:00
|
|
|
free_test_data(&data);
|
2020-08-06 06:56:34 +03:00
|
|
|
|
|
|
|
data.smbios_cpu_max_speed = 3000;
|
|
|
|
data.smbios_cpu_curr_speed = 2600;
|
|
|
|
test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data);
|
|
|
|
free_test_data(&data);
|
2013-10-18 01:52:18 +04:00
|
|
|
}
|
|
|
|
|
2015-02-20 21:22:14 +03:00
|
|
|
static void test_acpi_q35_tcg_bridge(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_Q35;
|
|
|
|
data.variant = ".bridge";
|
2016-06-10 12:15:43 +03:00
|
|
|
data.required_struct_types = base_required_struct_types;
|
|
|
|
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
2016-09-06 22:19:22 +03:00
|
|
|
test_acpi_one("-device pci-bridge,chassis_nr=1",
|
2015-02-20 21:22:14 +03:00
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
tests/bios-tables-test: add 64-bit PCI MMIO aperture round-up test on Q35
In commit 9fa99d2519cb ("hw/pci-host: Fix x86 Host Bridges 64bit PCI
hole", 2017-11-16), we meant to expose such a 64-bit PCI MMIO aperture in
the ACPI DSDT that would be at least as large as the new "pci-hole64-size"
property (2GB on i440fx, 32GB on q35). The goal was to offer "enough"
64-bit MMIO aperture to the guest OS for hotplug purposes.
Previous patch fixed the issue that the aperture is extended relative to
a possibly incorrect base. This may result in an aperture size that is
smaller than the intent of commit 9fa99d2519cb.
This patch adds a test to make sure it won't happen again.
In the test case being added:
- use 128 MB initial RAM size,
- ask for one DIMM hotplug slot,
- ask for 2 GB maximum RAM size,
- use a pci-testdev with a 64-bit BAR of 2 GB size.
Consequences:
(1) In pc_memory_init() [hw/i386/pc.c], the DIMM hotplug area size is
initially set to 2048-128 = 1920 MB. (Maximum RAM size minus initial
RAM size.)
(2) The DIMM area base is set to 4096 MB (because the initial RAM is only
128 MB -- there is no initial "high RAM").
(3) Due to commit 085f8e88ba73 ("pc: count in 1Gb hugepage alignment when
sizing hotplug-memory container", 2014-11-24), we add 1 GB for the one
DIMM hotplug slot that was specified. This sets the DIMM area size to
1920+1024 = 2944 MB.
(4) The reserved-memory-end address (exclusive) is set to 4096 + 2944 =
7040 MB (DIMM area base plus DIMM area size).
(5) The reserved-memory-end address is rounded up to GB alignment,
yielding 7 GB (7168 MB).
(6) Given the 2 GB BAR size of pci-testdev, SeaBIOS allocates said 64-bit
BAR in 64-bit address space.
(7) Because reserved-memory-end is at 7 GB, it is unaligned for the 2 GB
BAR. Therefore SeaBIOS allocates the BAR at 8 GB. QEMU then
(correctly) assigns the root bridge aperture base this BAR address, to
be exposed in \_SB.PCI0._CRS.
(8) The intent of commit 9fa99d2519cb dictates that QEMU extend the
aperture size to 32 GB, implying a 40 GB end address. However, QEMU
performs the extension relative to reserved-memory-end (7 GB), not
relative to the bridge aperture base that was correctly deduced from
SeaBIOS's BAR programming (8 GB). Therefore we see 39 GB as the
aperture end address in \_SB.PCI0._CRS:
> QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
> 0x0000000000000000, // Granularity
> 0x0000000200000000, // Range Minimum
> 0x00000009BFFFFFFF, // Range Maximum
> 0x0000000000000000, // Translation Offset
> 0x00000007C0000000, // Length
> ,, , AddressRangeMemory, TypeStatic)
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-09-28 00:24:36 +03:00
|
|
|
static void test_acpi_q35_tcg_mmio64(void)
|
|
|
|
{
|
|
|
|
test_data data = {
|
|
|
|
.machine = MACHINE_Q35,
|
|
|
|
.variant = ".mmio64",
|
|
|
|
.required_struct_types = base_required_struct_types,
|
|
|
|
.required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
|
|
|
|
};
|
|
|
|
|
|
|
|
test_acpi_one("-m 128M,slots=1,maxmem=2G "
|
2019-07-02 17:07:45 +03:00
|
|
|
"-object memory-backend-ram,id=ram0,size=128M "
|
|
|
|
"-numa node,memdev=ram0 "
|
tests/bios-tables-test: add 64-bit PCI MMIO aperture round-up test on Q35
In commit 9fa99d2519cb ("hw/pci-host: Fix x86 Host Bridges 64bit PCI
hole", 2017-11-16), we meant to expose such a 64-bit PCI MMIO aperture in
the ACPI DSDT that would be at least as large as the new "pci-hole64-size"
property (2GB on i440fx, 32GB on q35). The goal was to offer "enough"
64-bit MMIO aperture to the guest OS for hotplug purposes.
Previous patch fixed the issue that the aperture is extended relative to
a possibly incorrect base. This may result in an aperture size that is
smaller than the intent of commit 9fa99d2519cb.
This patch adds a test to make sure it won't happen again.
In the test case being added:
- use 128 MB initial RAM size,
- ask for one DIMM hotplug slot,
- ask for 2 GB maximum RAM size,
- use a pci-testdev with a 64-bit BAR of 2 GB size.
Consequences:
(1) In pc_memory_init() [hw/i386/pc.c], the DIMM hotplug area size is
initially set to 2048-128 = 1920 MB. (Maximum RAM size minus initial
RAM size.)
(2) The DIMM area base is set to 4096 MB (because the initial RAM is only
128 MB -- there is no initial "high RAM").
(3) Due to commit 085f8e88ba73 ("pc: count in 1Gb hugepage alignment when
sizing hotplug-memory container", 2014-11-24), we add 1 GB for the one
DIMM hotplug slot that was specified. This sets the DIMM area size to
1920+1024 = 2944 MB.
(4) The reserved-memory-end address (exclusive) is set to 4096 + 2944 =
7040 MB (DIMM area base plus DIMM area size).
(5) The reserved-memory-end address is rounded up to GB alignment,
yielding 7 GB (7168 MB).
(6) Given the 2 GB BAR size of pci-testdev, SeaBIOS allocates said 64-bit
BAR in 64-bit address space.
(7) Because reserved-memory-end is at 7 GB, it is unaligned for the 2 GB
BAR. Therefore SeaBIOS allocates the BAR at 8 GB. QEMU then
(correctly) assigns the root bridge aperture base this BAR address, to
be exposed in \_SB.PCI0._CRS.
(8) The intent of commit 9fa99d2519cb dictates that QEMU extend the
aperture size to 32 GB, implying a 40 GB end address. However, QEMU
performs the extension relative to reserved-memory-end (7 GB), not
relative to the bridge aperture base that was correctly deduced from
SeaBIOS's BAR programming (8 GB). Therefore we see 39 GB as the
aperture end address in \_SB.PCI0._CRS:
> QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
> 0x0000000000000000, // Granularity
> 0x0000000200000000, // Range Minimum
> 0x00000009BFFFFFFF, // Range Maximum
> 0x0000000000000000, // Translation Offset
> 0x00000007C0000000, // Length
> ,, , AddressRangeMemory, TypeStatic)
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-09-28 00:24:36 +03:00
|
|
|
"-device pci-testdev,membar=2G",
|
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2016-07-01 14:50:22 +03:00
|
|
|
static void test_acpi_piix4_tcg_cphp(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_PC;
|
|
|
|
data.variant = ".cphp";
|
2016-10-05 18:51:25 +03:00
|
|
|
test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -object memory-backend-ram,id=ram0,size=64M"
|
|
|
|
" -object memory-backend-ram,id=ram1,size=64M"
|
|
|
|
" -numa node,memdev=ram0 -numa node,memdev=ram1"
|
2017-05-03 12:17:16 +03:00
|
|
|
" -numa dist,src=0,dst=1,val=21",
|
2016-07-01 14:50:22 +03:00
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_q35_tcg_cphp(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_Q35;
|
|
|
|
data.variant = ".cphp";
|
2016-10-05 18:51:25 +03:00
|
|
|
test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -object memory-backend-ram,id=ram0,size=64M"
|
|
|
|
" -object memory-backend-ram,id=ram1,size=64M"
|
|
|
|
" -numa node,memdev=ram0 -numa node,memdev=ram1"
|
2017-05-03 12:17:16 +03:00
|
|
|
" -numa dist,src=0,dst=1,val=21",
|
2016-07-01 14:50:22 +03:00
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2016-06-10 12:15:43 +03:00
|
|
|
static uint8_t ipmi_required_struct_types[] = {
|
|
|
|
0, 1, 3, 4, 16, 17, 19, 32, 38, 127
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_acpi_q35_tcg_ipmi(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_Q35;
|
|
|
|
data.variant = ".ipmibt";
|
|
|
|
data.required_struct_types = ipmi_required_struct_types;
|
|
|
|
data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
|
2016-09-06 22:19:22 +03:00
|
|
|
test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
|
2016-06-10 12:15:43 +03:00
|
|
|
" -device isa-ipmi-bt,bmc=bmc0",
|
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_piix4_tcg_ipmi(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
/* Supplying -machine accel argument overrides the default (qtest).
|
|
|
|
* This is to make guest actually run.
|
|
|
|
*/
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_PC;
|
|
|
|
data.variant = ".ipmikcs";
|
|
|
|
data.required_struct_types = ipmi_required_struct_types;
|
|
|
|
data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
|
2016-09-06 22:19:22 +03:00
|
|
|
test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
|
2016-06-10 12:15:43 +03:00
|
|
|
" -device isa-ipmi-kcs,irq=0,bmc=bmc0",
|
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2016-12-06 02:32:20 +03:00
|
|
|
static void test_acpi_q35_tcg_memhp(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_Q35;
|
|
|
|
data.variant = ".memhp";
|
2017-05-03 12:17:16 +03:00
|
|
|
test_acpi_one(" -m 128,slots=3,maxmem=1G"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -object memory-backend-ram,id=ram0,size=64M"
|
|
|
|
" -object memory-backend-ram,id=ram1,size=64M"
|
|
|
|
" -numa node,memdev=ram0 -numa node,memdev=ram1"
|
2017-05-03 12:17:16 +03:00
|
|
|
" -numa dist,src=0,dst=1,val=21",
|
|
|
|
&data);
|
2016-12-06 02:32:20 +03:00
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_piix4_tcg_memhp(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_PC;
|
|
|
|
data.variant = ".memhp";
|
2017-05-03 12:17:16 +03:00
|
|
|
test_acpi_one(" -m 128,slots=3,maxmem=1G"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -object memory-backend-ram,id=ram0,size=64M"
|
|
|
|
" -object memory-backend-ram,id=ram1,size=64M"
|
|
|
|
" -numa node,memdev=ram0 -numa node,memdev=ram1"
|
2017-05-03 12:17:16 +03:00
|
|
|
" -numa dist,src=0,dst=1,val=21",
|
|
|
|
&data);
|
2016-12-06 02:32:20 +03:00
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2017-12-14 07:08:54 +03:00
|
|
|
static void test_acpi_q35_tcg_numamem(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_Q35;
|
|
|
|
data.variant = ".numamem";
|
2019-07-02 17:07:45 +03:00
|
|
|
test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
|
|
|
|
" -numa node -numa node,memdev=ram0", &data);
|
2017-12-14 07:08:54 +03:00
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_piix4_tcg_numamem(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = MACHINE_PC;
|
|
|
|
data.variant = ".numamem";
|
2019-07-02 17:07:45 +03:00
|
|
|
test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
|
|
|
|
" -numa node -numa node,memdev=ram0", &data);
|
2017-12-14 07:08:54 +03:00
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:08 +03:00
|
|
|
uint64_t tpm_tis_base_addr;
|
|
|
|
|
|
|
|
static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
|
|
|
|
uint64_t base)
|
|
|
|
{
|
2020-06-15 16:50:51 +03:00
|
|
|
#ifdef CONFIG_TPM
|
2020-06-09 15:54:08 +03:00
|
|
|
gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
|
|
|
|
machine, tpm_if);
|
|
|
|
char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
|
|
|
|
TestState test;
|
|
|
|
test_data data;
|
|
|
|
GThread *thread;
|
|
|
|
char *args, *variant = g_strdup_printf(".%s", tpm_if);
|
|
|
|
|
|
|
|
tpm_tis_base_addr = base;
|
|
|
|
|
|
|
|
module_call_init(MODULE_INIT_QOM);
|
|
|
|
|
|
|
|
test.addr = g_new0(SocketAddress, 1);
|
|
|
|
test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
|
|
|
|
test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
|
|
|
|
g_mutex_init(&test.data_mutex);
|
|
|
|
g_cond_init(&test.data_cond);
|
|
|
|
test.data_cond_signal = false;
|
|
|
|
|
|
|
|
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
|
|
|
|
tpm_emu_test_wait_cond(&test);
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = machine;
|
|
|
|
data.variant = variant;
|
|
|
|
|
|
|
|
args = g_strdup_printf(
|
|
|
|
" -chardev socket,id=chr,path=%s"
|
|
|
|
" -tpmdev emulator,id=dev,chardev=chr"
|
|
|
|
" -device tpm-%s,tpmdev=dev",
|
|
|
|
test.addr->u.q_unix.path, tpm_if);
|
|
|
|
|
|
|
|
test_acpi_one(args, &data);
|
|
|
|
|
|
|
|
g_thread_join(thread);
|
|
|
|
g_unlink(test.addr->u.q_unix.path);
|
|
|
|
qapi_free_SocketAddress(test.addr);
|
|
|
|
g_rmdir(tmp_path);
|
|
|
|
g_free(variant);
|
|
|
|
g_free(tmp_path);
|
|
|
|
g_free(tmp_dir_name);
|
2020-07-14 18:35:36 +03:00
|
|
|
g_free(args);
|
2020-06-09 15:54:08 +03:00
|
|
|
free_test_data(&data);
|
2020-06-15 16:50:51 +03:00
|
|
|
#else
|
|
|
|
g_test_skip("TPM disabled");
|
|
|
|
#endif
|
2020-06-09 15:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_q35_tcg_tpm_tis(void)
|
|
|
|
{
|
|
|
|
test_acpi_tcg_tpm("q35", "tis", 0xFED40000);
|
|
|
|
}
|
|
|
|
|
2018-03-11 06:02:14 +03:00
|
|
|
static void test_acpi_tcg_dimm_pxm(const char *machine)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = machine;
|
|
|
|
data.variant = ".dimmpxm";
|
2018-06-08 01:31:11 +03:00
|
|
|
test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
|
2018-03-11 06:02:14 +03:00
|
|
|
" -smp 4,sockets=4"
|
|
|
|
" -m 128M,slots=3,maxmem=1G"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -object memory-backend-ram,id=ram0,size=32M"
|
|
|
|
" -object memory-backend-ram,id=ram1,size=32M"
|
|
|
|
" -object memory-backend-ram,id=ram2,size=32M"
|
|
|
|
" -object memory-backend-ram,id=ram3,size=32M"
|
|
|
|
" -numa node,memdev=ram0,nodeid=0"
|
|
|
|
" -numa node,memdev=ram1,nodeid=1"
|
|
|
|
" -numa node,memdev=ram2,nodeid=2"
|
|
|
|
" -numa node,memdev=ram3,nodeid=3"
|
2018-03-11 06:02:14 +03:00
|
|
|
" -numa cpu,node-id=0,socket-id=0"
|
|
|
|
" -numa cpu,node-id=1,socket-id=1"
|
|
|
|
" -numa cpu,node-id=2,socket-id=2"
|
|
|
|
" -numa cpu,node-id=3,socket-id=3"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -object memory-backend-ram,id=ram4,size=128M"
|
2018-03-11 06:02:14 +03:00
|
|
|
" -object memory-backend-ram,id=nvm0,size=128M"
|
2019-07-02 17:07:45 +03:00
|
|
|
" -device pc-dimm,id=dimm0,memdev=ram4,node=1"
|
2018-03-11 06:02:14 +03:00
|
|
|
" -device nvdimm,id=dimm1,memdev=nvm0,node=2",
|
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_q35_tcg_dimm_pxm(void)
|
|
|
|
{
|
|
|
|
test_acpi_tcg_dimm_pxm(MACHINE_Q35);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_piix4_tcg_dimm_pxm(void)
|
|
|
|
{
|
|
|
|
test_acpi_tcg_dimm_pxm(MACHINE_PC);
|
|
|
|
}
|
|
|
|
|
2019-09-18 16:06:33 +03:00
|
|
|
static void test_acpi_virt_tcg_memhp(void)
|
|
|
|
{
|
|
|
|
test_data data = {
|
|
|
|
.machine = "virt",
|
2019-11-13 12:10:47 +03:00
|
|
|
.tcg_only = true,
|
2019-09-18 16:06:33 +03:00
|
|
|
.uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
|
|
|
|
.uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
|
|
|
|
.cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
|
|
|
|
.ram_start = 0x40000000ULL,
|
|
|
|
.scan_len = 256ULL * 1024 * 1024,
|
|
|
|
};
|
|
|
|
|
|
|
|
data.variant = ".memhp";
|
2020-04-21 15:59:33 +03:00
|
|
|
test_acpi_one(" -machine nvdimm=on"
|
|
|
|
" -cpu cortex-a57"
|
2019-09-18 16:06:33 +03:00
|
|
|
" -m 256M,slots=3,maxmem=1G"
|
|
|
|
" -object memory-backend-ram,id=ram0,size=128M"
|
|
|
|
" -object memory-backend-ram,id=ram1,size=128M"
|
|
|
|
" -numa node,memdev=ram0 -numa node,memdev=ram1"
|
2020-04-21 15:59:33 +03:00
|
|
|
" -numa dist,src=0,dst=1,val=21"
|
|
|
|
" -object memory-backend-ram,id=ram2,size=128M"
|
|
|
|
" -object memory-backend-ram,id=nvm0,size=128M"
|
|
|
|
" -device pc-dimm,id=dimm0,memdev=ram2,node=0"
|
|
|
|
" -device nvdimm,id=dimm1,memdev=nvm0,node=1",
|
2019-09-18 16:06:33 +03:00
|
|
|
&data);
|
|
|
|
|
|
|
|
free_test_data(&data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:09:07 +03:00
|
|
|
static void test_acpi_microvm_tcg(void)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = "microvm";
|
|
|
|
data.required_struct_types = NULL; /* no smbios */
|
|
|
|
data.required_struct_types_len = 0;
|
|
|
|
data.blkdev = "virtio-blk-device";
|
|
|
|
test_acpi_one(" -machine microvm,acpi=on,rtc=off",
|
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
2019-09-18 16:06:33 +03:00
|
|
|
static void test_acpi_virt_tcg_numamem(void)
|
|
|
|
{
|
|
|
|
test_data data = {
|
|
|
|
.machine = "virt",
|
2019-11-13 12:10:47 +03:00
|
|
|
.tcg_only = true,
|
2019-09-18 16:06:33 +03:00
|
|
|
.uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
|
|
|
|
.uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
|
|
|
|
.cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
|
|
|
|
.ram_start = 0x40000000ULL,
|
|
|
|
.scan_len = 128ULL * 1024 * 1024,
|
|
|
|
};
|
|
|
|
|
|
|
|
data.variant = ".numamem";
|
|
|
|
test_acpi_one(" -cpu cortex-a57"
|
|
|
|
" -object memory-backend-ram,id=ram0,size=128M"
|
|
|
|
" -numa node,memdev=ram0",
|
|
|
|
&data);
|
|
|
|
|
|
|
|
free_test_data(&data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-13 04:19:29 +03:00
|
|
|
static void test_acpi_tcg_acpi_hmat(const char *machine)
|
|
|
|
{
|
|
|
|
test_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
data.machine = machine;
|
|
|
|
data.variant = ".acpihmat";
|
|
|
|
test_acpi_one(" -machine hmat=on"
|
|
|
|
" -smp 2,sockets=2"
|
|
|
|
" -m 128M,slots=2,maxmem=1G"
|
|
|
|
" -object memory-backend-ram,size=64M,id=m0"
|
|
|
|
" -object memory-backend-ram,size=64M,id=m1"
|
|
|
|
" -numa node,nodeid=0,memdev=m0"
|
|
|
|
" -numa node,nodeid=1,memdev=m1,initiator=0"
|
|
|
|
" -numa cpu,node-id=0,socket-id=0"
|
|
|
|
" -numa cpu,node-id=0,socket-id=1"
|
|
|
|
" -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
|
|
|
|
"data-type=access-latency,latency=1"
|
|
|
|
" -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
|
|
|
|
"data-type=access-bandwidth,bandwidth=65534M"
|
|
|
|
" -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
|
|
|
|
"data-type=access-latency,latency=65534"
|
|
|
|
" -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
|
|
|
|
"data-type=access-bandwidth,bandwidth=32767M"
|
|
|
|
" -numa hmat-cache,node-id=0,size=10K,level=1,"
|
|
|
|
"associativity=direct,policy=write-back,line=8"
|
|
|
|
" -numa hmat-cache,node-id=1,size=10K,level=1,"
|
|
|
|
"associativity=direct,policy=write-back,line=8",
|
|
|
|
&data);
|
|
|
|
free_test_data(&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_q35_tcg_acpi_hmat(void)
|
|
|
|
{
|
|
|
|
test_acpi_tcg_acpi_hmat(MACHINE_Q35);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_acpi_piix4_tcg_acpi_hmat(void)
|
|
|
|
{
|
|
|
|
test_acpi_tcg_acpi_hmat(MACHINE_PC);
|
|
|
|
}
|
|
|
|
|
2019-06-03 14:22:09 +03:00
|
|
|
static void test_acpi_virt_tcg(void)
|
|
|
|
{
|
|
|
|
test_data data = {
|
|
|
|
.machine = "virt",
|
2019-11-13 12:10:47 +03:00
|
|
|
.tcg_only = true,
|
2019-06-03 14:22:09 +03:00
|
|
|
.uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
|
|
|
|
.uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
|
|
|
|
.cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
|
|
|
|
.ram_start = 0x40000000ULL,
|
|
|
|
.scan_len = 128ULL * 1024 * 1024,
|
|
|
|
};
|
|
|
|
|
|
|
|
test_acpi_one("-cpu cortex-a57", &data);
|
|
|
|
free_test_data(&data);
|
2020-08-06 06:56:34 +03:00
|
|
|
|
|
|
|
data.smbios_cpu_max_speed = 2900;
|
|
|
|
data.smbios_cpu_curr_speed = 2700;
|
|
|
|
test_acpi_one("-cpu cortex-a57 "
|
|
|
|
"-smbios type=4,max-speed=2900,current-speed=2700", &data);
|
|
|
|
free_test_data(&data);
|
2019-06-03 14:22:09 +03:00
|
|
|
}
|
|
|
|
|
2013-10-18 01:52:18 +04:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *arch = qtest_get_arch();
|
2013-12-26 08:53:39 +04:00
|
|
|
int ret;
|
2014-08-18 11:54:33 +04:00
|
|
|
|
2013-10-18 01:52:18 +04:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
2019-05-02 17:51:55 +03:00
|
|
|
ret = boot_sector_init(disk);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:08 +03:00
|
|
|
qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis);
|
2016-09-06 22:19:22 +03:00
|
|
|
qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
|
|
|
|
qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
|
|
|
|
qtest_add_func("acpi/q35", test_acpi_q35_tcg);
|
|
|
|
qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
|
tests/bios-tables-test: add 64-bit PCI MMIO aperture round-up test on Q35
In commit 9fa99d2519cb ("hw/pci-host: Fix x86 Host Bridges 64bit PCI
hole", 2017-11-16), we meant to expose such a 64-bit PCI MMIO aperture in
the ACPI DSDT that would be at least as large as the new "pci-hole64-size"
property (2GB on i440fx, 32GB on q35). The goal was to offer "enough"
64-bit MMIO aperture to the guest OS for hotplug purposes.
Previous patch fixed the issue that the aperture is extended relative to
a possibly incorrect base. This may result in an aperture size that is
smaller than the intent of commit 9fa99d2519cb.
This patch adds a test to make sure it won't happen again.
In the test case being added:
- use 128 MB initial RAM size,
- ask for one DIMM hotplug slot,
- ask for 2 GB maximum RAM size,
- use a pci-testdev with a 64-bit BAR of 2 GB size.
Consequences:
(1) In pc_memory_init() [hw/i386/pc.c], the DIMM hotplug area size is
initially set to 2048-128 = 1920 MB. (Maximum RAM size minus initial
RAM size.)
(2) The DIMM area base is set to 4096 MB (because the initial RAM is only
128 MB -- there is no initial "high RAM").
(3) Due to commit 085f8e88ba73 ("pc: count in 1Gb hugepage alignment when
sizing hotplug-memory container", 2014-11-24), we add 1 GB for the one
DIMM hotplug slot that was specified. This sets the DIMM area size to
1920+1024 = 2944 MB.
(4) The reserved-memory-end address (exclusive) is set to 4096 + 2944 =
7040 MB (DIMM area base plus DIMM area size).
(5) The reserved-memory-end address is rounded up to GB alignment,
yielding 7 GB (7168 MB).
(6) Given the 2 GB BAR size of pci-testdev, SeaBIOS allocates said 64-bit
BAR in 64-bit address space.
(7) Because reserved-memory-end is at 7 GB, it is unaligned for the 2 GB
BAR. Therefore SeaBIOS allocates the BAR at 8 GB. QEMU then
(correctly) assigns the root bridge aperture base this BAR address, to
be exposed in \_SB.PCI0._CRS.
(8) The intent of commit 9fa99d2519cb dictates that QEMU extend the
aperture size to 32 GB, implying a 40 GB end address. However, QEMU
performs the extension relative to reserved-memory-end (7 GB), not
relative to the bridge aperture base that was correctly deduced from
SeaBIOS's BAR programming (8 GB). Therefore we see 39 GB as the
aperture end address in \_SB.PCI0._CRS:
> QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
> 0x0000000000000000, // Granularity
> 0x0000000200000000, // Range Minimum
> 0x00000009BFFFFFFF, // Range Maximum
> 0x0000000000000000, // Translation Offset
> 0x00000007C0000000, // Length
> ,, , AddressRangeMemory, TypeStatic)
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-09-28 00:24:36 +03:00
|
|
|
qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
|
2016-09-06 22:19:22 +03:00
|
|
|
qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
|
|
|
|
qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
|
|
|
|
qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
|
|
|
|
qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
|
2016-12-06 02:32:20 +03:00
|
|
|
qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
|
|
|
|
qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
|
2017-12-14 07:08:54 +03:00
|
|
|
qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
|
|
|
|
qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
|
2018-03-11 06:02:14 +03:00
|
|
|
qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
|
|
|
|
qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
|
2019-12-13 04:19:29 +03:00
|
|
|
qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
|
|
|
|
qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
|
2020-09-15 15:09:07 +03:00
|
|
|
qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
|
2019-06-03 14:22:09 +03:00
|
|
|
} else if (strcmp(arch, "aarch64") == 0) {
|
|
|
|
qtest_add_func("acpi/virt", test_acpi_virt_tcg);
|
2019-09-18 16:06:33 +03:00
|
|
|
qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
|
|
|
|
qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
|
2013-10-18 01:52:18 +04:00
|
|
|
}
|
2013-12-26 08:53:39 +04:00
|
|
|
ret = g_test_run();
|
2016-02-14 19:59:27 +03:00
|
|
|
boot_sector_cleanup(disk);
|
2013-12-26 08:53:39 +04:00
|
|
|
return ret;
|
2013-10-18 01:52:18 +04:00
|
|
|
}
|