11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * Boot order test cases.
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2013 Red Hat Inc.
51e8a1faeSThomas Huth *
61e8a1faeSThomas Huth * Authors:
71e8a1faeSThomas Huth * Michael S. Tsirkin <mst@redhat.com>,
81e8a1faeSThomas Huth *
91e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
101e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
111e8a1faeSThomas Huth */
121e8a1faeSThomas Huth
131e8a1faeSThomas Huth /*
1407f5903cSAni Sinha * How to add or update the tests or commit changes that affect ACPI tables:
151e8a1faeSThomas Huth * Contributor:
161e8a1faeSThomas Huth * 1. add empty files for new tables, if any, under tests/data/acpi
17c66e8ab0SHeyi Guo * 2. list any changed files in tests/qtest/bios-tables-test-allowed-diff.h
181e8a1faeSThomas Huth * 3. commit the above *before* making changes that affect the tables
193c2ab559SMichael S. Tsirkin *
203c2ab559SMichael S. Tsirkin * Contributor or ACPI Maintainer (steps 4-7 need to be redone to resolve conflicts
213c2ab559SMichael S. Tsirkin * in binary commit created in step 6):
223c2ab559SMichael S. Tsirkin *
231e8a1faeSThomas Huth * After 1-3 above tests will pass but ignore differences with the expected files.
24c66e8ab0SHeyi Guo * You will also notice that tests/qtest/bios-tables-test-allowed-diff.h lists
251e8a1faeSThomas Huth * a bunch of files. This is your hint that you need to do the below:
261e8a1faeSThomas Huth * 4. Run
274ffa3a1bSThomas Huth * make check V=2
281e8a1faeSThomas Huth * this will produce a bunch of warnings about differences
2996420a30SMichael Tokarev * between actual and expected ACPI tables. If you have IASL installed,
301e8a1faeSThomas Huth * they will also be disassembled so you can look at the disassembled
311e8a1faeSThomas Huth * output. If not - disassemble them yourself in any way you like.
321e8a1faeSThomas Huth * Look at the differences - make sure they make sense and match what the
331e8a1faeSThomas Huth * changes you are merging are supposed to do.
343c2ab559SMichael S. Tsirkin * Save the changes, preferably in form of ASL diff for the commit log in
353c2ab559SMichael S. Tsirkin * step 6.
361e8a1faeSThomas Huth *
371e8a1faeSThomas Huth * 5. From build directory, run:
381e8a1faeSThomas Huth * $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh
393c2ab559SMichael S. Tsirkin * 6. Now commit any changes to the expected binary, include diff from step 4
403c2ab559SMichael S. Tsirkin * in commit log.
4107f5903cSAni Sinha * Expected binary updates needs to be a separate patch from the code that
4207f5903cSAni Sinha * introduces changes to ACPI tables. It lets the maintainer drop
4307f5903cSAni Sinha * and regenerate binary updates in case of merge conflicts. Further, a code
4407f5903cSAni Sinha * change is easily reviewable but a binary blob is not (without doing a
4507f5903cSAni Sinha * disassembly).
463c2ab559SMichael S. Tsirkin * 7. Before sending patches to the list (Contributor)
473c2ab559SMichael S. Tsirkin * or before doing a pull request (Maintainer), make sure
48c66e8ab0SHeyi Guo * tests/qtest/bios-tables-test-allowed-diff.h is empty - this will ensure
493c2ab559SMichael S. Tsirkin * following changes to ACPI tables will be noticed.
503c2ab559SMichael S. Tsirkin *
513c2ab559SMichael S. Tsirkin * The resulting patchset/pull request then looks like this:
52c66e8ab0SHeyi Guo * - patch 1: list changed files in tests/qtest/bios-tables-test-allowed-diff.h.
533c2ab559SMichael S. Tsirkin * - patches 2 - n: real changes, may contain multiple patches.
543c2ab559SMichael S. Tsirkin * - patch n + 1: update golden master binaries and empty
55c66e8ab0SHeyi Guo * tests/qtest/bios-tables-test-allowed-diff.h
561e8a1faeSThomas Huth */
571e8a1faeSThomas Huth
581e8a1faeSThomas Huth #include "qemu/osdep.h"
591e8a1faeSThomas Huth #include <glib/gstdio.h>
601e8a1faeSThomas Huth #include "hw/firmware/smbios.h"
611e8a1faeSThomas Huth #include "qemu/bitmap.h"
621e8a1faeSThomas Huth #include "acpi-utils.h"
631e8a1faeSThomas Huth #include "boot-sector.h"
645da7c35eSEric Auger #include "tpm-emu.h"
655da7c35eSEric Auger #include "hw/acpi/tpm.h"
664b1f8882SMarian Postevca #include "qemu/cutils.h"
671e8a1faeSThomas Huth
681e8a1faeSThomas Huth #define MACHINE_PC "pc"
691e8a1faeSThomas Huth #define MACHINE_Q35 "q35"
701e8a1faeSThomas Huth
711e8a1faeSThomas Huth #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
721e8a1faeSThomas Huth
734b1f8882SMarian Postevca #define OEM_ID "TEST"
744b1f8882SMarian Postevca #define OEM_TABLE_ID "OEM"
75408ca926SIgor Mammedov #define OEM_TEST_ARGS "-machine x-oem-id=" OEM_ID ",x-oem-table-id=" \
76408ca926SIgor Mammedov OEM_TABLE_ID
774b1f8882SMarian Postevca
781e8a1faeSThomas Huth typedef struct {
791e8a1faeSThomas Huth bool tcg_only;
801e8a1faeSThomas Huth const char *machine;
81c9ad3decSSunil V L const char *arch;
829a2112f9SThomas Huth const char *machine_param;
831e8a1faeSThomas Huth const char *variant;
841e8a1faeSThomas Huth const char *uefi_fl1;
851e8a1faeSThomas Huth const char *uefi_fl2;
863cac3784SGerd Hoffmann const char *blkdev;
871e8a1faeSThomas Huth const char *cd;
881e8a1faeSThomas Huth const uint64_t ram_start;
891e8a1faeSThomas Huth const uint64_t scan_len;
901e8a1faeSThomas Huth uint64_t rsdp_addr;
911e8a1faeSThomas Huth uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
921e8a1faeSThomas Huth GArray *tables;
9333bff4a8SJulia Suvorova uint64_t smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE__MAX];
9433bff4a8SJulia Suvorova SmbiosEntryPoint smbios_ep_table;
95e1647539SYing Fang uint16_t smbios_cpu_max_speed;
96e1647539SYing Fang uint16_t smbios_cpu_curr_speed;
972d80b338SJulia Suvorova uint8_t smbios_core_count;
982d80b338SJulia Suvorova uint16_t smbios_core_count2;
997ee18dceSZhao Liu uint8_t smbios_thread_count;
100198eee0cSZhao Liu uint16_t smbios_thread_count2;
1011e8a1faeSThomas Huth uint8_t *required_struct_types;
1021e8a1faeSThomas Huth int required_struct_types_len;
103df210963SZhao Liu int type4_count;
1041e8a1faeSThomas Huth QTestState *qts;
1051e8a1faeSThomas Huth } test_data;
1061e8a1faeSThomas Huth
1071e8a1faeSThomas Huth static char disk[] = "tests/acpi-test-disk-XXXXXX";
1081e8a1faeSThomas Huth static const char *data_dir = "tests/data/acpi";
1091e8a1faeSThomas Huth #ifdef CONFIG_IASL
110859aef02SPaolo Bonzini static const char *iasl = CONFIG_IASL;
1111e8a1faeSThomas Huth #else
1121e8a1faeSThomas Huth static const char *iasl;
1131e8a1faeSThomas Huth #endif
1141e8a1faeSThomas Huth
1154ffa3a1bSThomas Huth static int verbosity_level;
116de35244eSAni Sinha static GArray *load_expected_aml(test_data *data);
1174ffa3a1bSThomas Huth
compare_signature(const AcpiSdtTable * sdt,const char * signature)1181e8a1faeSThomas Huth static bool compare_signature(const AcpiSdtTable *sdt, const char *signature)
1191e8a1faeSThomas Huth {
1201e8a1faeSThomas Huth return !memcmp(sdt->aml, signature, 4);
1211e8a1faeSThomas Huth }
1221e8a1faeSThomas Huth
cleanup_table_descriptor(AcpiSdtTable * table)1231e8a1faeSThomas Huth static void cleanup_table_descriptor(AcpiSdtTable *table)
1241e8a1faeSThomas Huth {
1251e8a1faeSThomas Huth g_free(table->aml);
1261e8a1faeSThomas Huth if (table->aml_file &&
1271e8a1faeSThomas Huth !table->tmp_files_retain &&
1281e8a1faeSThomas Huth g_strstr_len(table->aml_file, -1, "aml-")) {
1291e8a1faeSThomas Huth unlink(table->aml_file);
1301e8a1faeSThomas Huth }
1311e8a1faeSThomas Huth g_free(table->aml_file);
1321e8a1faeSThomas Huth g_free(table->asl);
1331e8a1faeSThomas Huth if (table->asl_file &&
1341e8a1faeSThomas Huth !table->tmp_files_retain) {
1351e8a1faeSThomas Huth unlink(table->asl_file);
1361e8a1faeSThomas Huth }
1371e8a1faeSThomas Huth g_free(table->asl_file);
1381e8a1faeSThomas Huth }
1391e8a1faeSThomas Huth
free_test_data(test_data * data)1401e8a1faeSThomas Huth static void free_test_data(test_data *data)
1411e8a1faeSThomas Huth {
1421e8a1faeSThomas Huth int i;
1431e8a1faeSThomas Huth
144c51a5a23SClaudio Fontana if (!data->tables) {
145c51a5a23SClaudio Fontana return;
146c51a5a23SClaudio Fontana }
1471e8a1faeSThomas Huth for (i = 0; i < data->tables->len; ++i) {
1481e8a1faeSThomas Huth cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
1491e8a1faeSThomas Huth }
1501e8a1faeSThomas Huth
1511e8a1faeSThomas Huth g_array_free(data->tables, true);
1521e8a1faeSThomas Huth }
1531e8a1faeSThomas Huth
test_acpi_rsdp_table(test_data * data)1541e8a1faeSThomas Huth static void test_acpi_rsdp_table(test_data *data)
1551e8a1faeSThomas Huth {
1561e8a1faeSThomas Huth uint8_t *rsdp_table = data->rsdp_table;
1571e8a1faeSThomas Huth
1581e8a1faeSThomas Huth acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
1591e8a1faeSThomas Huth
1601e8a1faeSThomas Huth switch (rsdp_table[15 /* Revision offset */]) {
1611e8a1faeSThomas Huth case 0: /* ACPI 1.0 RSDP */
1621e8a1faeSThomas Huth /* With rev 1, checksum is only for the first 20 bytes */
1631e8a1faeSThomas Huth g_assert(!acpi_calc_checksum(rsdp_table, 20));
1641e8a1faeSThomas Huth break;
1651e8a1faeSThomas Huth case 2: /* ACPI 2.0+ RSDP */
1661e8a1faeSThomas Huth /* With revision 2, we have 2 checksums */
1671e8a1faeSThomas Huth g_assert(!acpi_calc_checksum(rsdp_table, 20));
1681e8a1faeSThomas Huth g_assert(!acpi_calc_checksum(rsdp_table, 36));
1691e8a1faeSThomas Huth break;
1701e8a1faeSThomas Huth default:
1711e8a1faeSThomas Huth g_assert_not_reached();
1721e8a1faeSThomas Huth }
1731e8a1faeSThomas Huth }
1741e8a1faeSThomas Huth
test_acpi_rxsdt_table(test_data * data)1751e8a1faeSThomas Huth static void test_acpi_rxsdt_table(test_data *data)
1761e8a1faeSThomas Huth {
1771e8a1faeSThomas Huth const char *sig = "RSDT";
1781e8a1faeSThomas Huth AcpiSdtTable rsdt = {};
1791e8a1faeSThomas Huth int entry_size = 4;
1801e8a1faeSThomas Huth int addr_off = 16 /* RsdtAddress */;
1811e8a1faeSThomas Huth uint8_t *ent;
1821e8a1faeSThomas Huth
1831e8a1faeSThomas Huth if (data->rsdp_table[15 /* Revision offset */] != 0) {
1841e8a1faeSThomas Huth addr_off = 24 /* XsdtAddress */;
1851e8a1faeSThomas Huth entry_size = 8;
1861e8a1faeSThomas Huth sig = "XSDT";
1871e8a1faeSThomas Huth }
1881e8a1faeSThomas Huth /* read [RX]SDT table */
1891e8a1faeSThomas Huth acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
1901e8a1faeSThomas Huth &data->rsdp_table[addr_off], entry_size, sig, true);
1911e8a1faeSThomas Huth
1921e8a1faeSThomas Huth /* Load all tables and add to test list directly RSDT referenced tables */
1931e8a1faeSThomas Huth ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
1941e8a1faeSThomas Huth AcpiSdtTable ssdt_table = {};
1951e8a1faeSThomas Huth
1961e8a1faeSThomas Huth acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
1971e8a1faeSThomas Huth entry_size, NULL, true);
1981e8a1faeSThomas Huth /* Add table to ASL test tables list */
1991e8a1faeSThomas Huth g_array_append_val(data->tables, ssdt_table);
2001e8a1faeSThomas Huth }
2011e8a1faeSThomas Huth cleanup_table_descriptor(&rsdt);
2021e8a1faeSThomas Huth }
2031e8a1faeSThomas Huth
test_acpi_fadt_table(test_data * data)2041e8a1faeSThomas Huth static void test_acpi_fadt_table(test_data *data)
2051e8a1faeSThomas Huth {
2061e8a1faeSThomas Huth /* FADT table is 1st */
2071e8a1faeSThomas Huth AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
2081e8a1faeSThomas Huth uint8_t *fadt_aml = table.aml;
2091e8a1faeSThomas Huth uint32_t fadt_len = table.aml_len;
2101e8a1faeSThomas Huth uint32_t val;
2111e8a1faeSThomas Huth int dsdt_offset = 40 /* DSDT */;
2121e8a1faeSThomas Huth int dsdt_entry_size = 4;
2131e8a1faeSThomas Huth
2141e8a1faeSThomas Huth g_assert(compare_signature(&table, "FACP"));
2151e8a1faeSThomas Huth
2161e8a1faeSThomas Huth /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
2171e8a1faeSThomas Huth memcpy(&val, fadt_aml + 112 /* Flags */, 4);
2181e8a1faeSThomas Huth val = le32_to_cpu(val);
2191e8a1faeSThomas Huth if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
2201e8a1faeSThomas Huth acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
2211e8a1faeSThomas Huth fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
2221e8a1faeSThomas Huth g_array_append_val(data->tables, table);
2231e8a1faeSThomas Huth }
2241e8a1faeSThomas Huth
2251e8a1faeSThomas Huth memcpy(&val, fadt_aml + dsdt_offset, 4);
2261e8a1faeSThomas Huth val = le32_to_cpu(val);
2271e8a1faeSThomas Huth if (!val) {
2281e8a1faeSThomas Huth dsdt_offset = 140 /* X_DSDT */;
2291e8a1faeSThomas Huth dsdt_entry_size = 8;
2301e8a1faeSThomas Huth }
2311e8a1faeSThomas Huth acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
2321e8a1faeSThomas Huth fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
2331e8a1faeSThomas Huth g_array_append_val(data->tables, table);
2341e8a1faeSThomas Huth
2351e8a1faeSThomas Huth memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
2361e8a1faeSThomas Huth memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
2371e8a1faeSThomas Huth if (fadt_aml[8 /* FADT Major Version */] >= 3) {
2381e8a1faeSThomas Huth memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
2391e8a1faeSThomas Huth memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
2401e8a1faeSThomas Huth }
2411e8a1faeSThomas Huth
2421e8a1faeSThomas Huth /* update checksum */
2431e8a1faeSThomas Huth fadt_aml[9 /* Checksum */] = 0;
2441e8a1faeSThomas Huth fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
2451e8a1faeSThomas Huth }
2461e8a1faeSThomas Huth
dump_aml_files(test_data * data,bool rebuild)2471e8a1faeSThomas Huth static void dump_aml_files(test_data *data, bool rebuild)
2481e8a1faeSThomas Huth {
249de35244eSAni Sinha AcpiSdtTable *sdt, *exp_sdt;
2501e8a1faeSThomas Huth GError *error = NULL;
2511e8a1faeSThomas Huth gchar *aml_file = NULL;
252de35244eSAni Sinha test_data exp_data = {};
2531e8a1faeSThomas Huth gint fd;
2541e8a1faeSThomas Huth ssize_t ret;
2551e8a1faeSThomas Huth int i;
2561e8a1faeSThomas Huth
257de35244eSAni Sinha exp_data.tables = load_expected_aml(data);
2581e8a1faeSThomas Huth for (i = 0; i < data->tables->len; ++i) {
2591e8a1faeSThomas Huth const char *ext = data->variant ? data->variant : "";
2601e8a1faeSThomas Huth sdt = &g_array_index(data->tables, AcpiSdtTable, i);
261de35244eSAni Sinha exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
2621e8a1faeSThomas Huth g_assert(sdt->aml);
263de35244eSAni Sinha g_assert(exp_sdt->aml);
2641e8a1faeSThomas Huth
2651e8a1faeSThomas Huth if (rebuild) {
266c9ad3decSSunil V L aml_file = g_strdup_printf("%s/%s/%s/%.4s%s", data_dir,
267c9ad3decSSunil V L data->arch, data->machine,
2681e8a1faeSThomas Huth sdt->aml, ext);
269c9ad3decSSunil V L
270de35244eSAni Sinha if (!g_file_test(aml_file, G_FILE_TEST_EXISTS) &&
271de35244eSAni Sinha sdt->aml_len == exp_sdt->aml_len &&
272de35244eSAni Sinha !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
273de35244eSAni Sinha /* identical tables, no need to write new files */
274de35244eSAni Sinha g_free(aml_file);
275de35244eSAni Sinha continue;
276de35244eSAni Sinha }
2771e8a1faeSThomas Huth fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
2781e8a1faeSThomas Huth S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
2791e8a1faeSThomas Huth if (fd < 0) {
2801e8a1faeSThomas Huth perror(aml_file);
2811e8a1faeSThomas Huth }
2821e8a1faeSThomas Huth g_assert(fd >= 0);
2831e8a1faeSThomas Huth } else {
2841e8a1faeSThomas Huth fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
2851e8a1faeSThomas Huth g_assert_no_error(error);
2861e8a1faeSThomas Huth }
2871e8a1faeSThomas Huth
2881e8a1faeSThomas Huth ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
2891e8a1faeSThomas Huth g_assert(ret == sdt->aml_len);
2901e8a1faeSThomas Huth
2911e8a1faeSThomas Huth close(fd);
2921e8a1faeSThomas Huth
2931e8a1faeSThomas Huth g_free(aml_file);
2941e8a1faeSThomas Huth }
2951e8a1faeSThomas Huth }
2961e8a1faeSThomas Huth
create_tmp_asl(AcpiSdtTable * sdt)29781d72286SMichael S. Tsirkin static bool create_tmp_asl(AcpiSdtTable *sdt)
29881d72286SMichael S. Tsirkin {
29981d72286SMichael S. Tsirkin GError *error = NULL;
30081d72286SMichael S. Tsirkin gint fd;
30181d72286SMichael S. Tsirkin
30281d72286SMichael S. Tsirkin fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
30381d72286SMichael S. Tsirkin g_assert_no_error(error);
30481d72286SMichael S. Tsirkin close(fd);
30581d72286SMichael S. Tsirkin
30681d72286SMichael S. Tsirkin return false;
30781d72286SMichael S. Tsirkin }
30881d72286SMichael S. Tsirkin
load_asl(GArray * sdts,AcpiSdtTable * sdt)3091e8a1faeSThomas Huth static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
3101e8a1faeSThomas Huth {
3111e8a1faeSThomas Huth AcpiSdtTable *temp;
3121e8a1faeSThomas Huth GError *error = NULL;
3131e8a1faeSThomas Huth GString *command_line = g_string_new(iasl);
3141e8a1faeSThomas Huth gchar *out, *out_err;
3151e8a1faeSThomas Huth gboolean ret;
3161e8a1faeSThomas Huth int i;
3171e8a1faeSThomas Huth
31881d72286SMichael S. Tsirkin create_tmp_asl(sdt);
3191e8a1faeSThomas Huth
3201e8a1faeSThomas Huth /* build command line */
3211e8a1faeSThomas Huth g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
3221e8a1faeSThomas Huth if (compare_signature(sdt, "DSDT") ||
3231e8a1faeSThomas Huth compare_signature(sdt, "SSDT")) {
3241e8a1faeSThomas Huth for (i = 0; i < sdts->len; ++i) {
3251e8a1faeSThomas Huth temp = &g_array_index(sdts, AcpiSdtTable, i);
3261e8a1faeSThomas Huth if (compare_signature(temp, "DSDT") ||
3271e8a1faeSThomas Huth compare_signature(temp, "SSDT")) {
3281e8a1faeSThomas Huth g_string_append_printf(command_line, "-e %s ", temp->aml_file);
3291e8a1faeSThomas Huth }
3301e8a1faeSThomas Huth }
3311e8a1faeSThomas Huth }
3321e8a1faeSThomas Huth g_string_append_printf(command_line, "-d %s", sdt->aml_file);
3331e8a1faeSThomas Huth
3341e8a1faeSThomas Huth /* pass 'out' and 'out_err' in order to be redirected */
3351e8a1faeSThomas Huth ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
3361e8a1faeSThomas Huth g_assert_no_error(error);
3371e8a1faeSThomas Huth if (ret) {
3381e8a1faeSThomas Huth ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
3391e8a1faeSThomas Huth &sdt->asl_len, &error);
3401e8a1faeSThomas Huth g_assert(ret);
3411e8a1faeSThomas Huth g_assert_no_error(error);
3421e8a1faeSThomas Huth ret = (sdt->asl_len > 0);
3431e8a1faeSThomas Huth }
3441e8a1faeSThomas Huth
3451e8a1faeSThomas Huth g_free(out);
3461e8a1faeSThomas Huth g_free(out_err);
3471e8a1faeSThomas Huth g_string_free(command_line, true);
3481e8a1faeSThomas Huth
3491e8a1faeSThomas Huth return !ret;
3501e8a1faeSThomas Huth }
3511e8a1faeSThomas Huth
3521e8a1faeSThomas Huth #define COMMENT_END "*/"
3531e8a1faeSThomas Huth #define DEF_BLOCK "DefinitionBlock ("
3541e8a1faeSThomas Huth #define BLOCK_NAME_END ","
3551e8a1faeSThomas Huth
normalize_asl(gchar * asl_code)3561e8a1faeSThomas Huth static GString *normalize_asl(gchar *asl_code)
3571e8a1faeSThomas Huth {
3581e8a1faeSThomas Huth GString *asl = g_string_new(asl_code);
3591e8a1faeSThomas Huth gchar *comment, *block_name;
3601e8a1faeSThomas Huth
3611e8a1faeSThomas Huth /* strip comments (different generation days) */
3621e8a1faeSThomas Huth comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
3631e8a1faeSThomas Huth if (comment) {
3641e8a1faeSThomas Huth comment += strlen(COMMENT_END);
3651e8a1faeSThomas Huth while (*comment == '\n') {
3661e8a1faeSThomas Huth comment++;
3671e8a1faeSThomas Huth }
3681e8a1faeSThomas Huth asl = g_string_erase(asl, 0, comment - asl->str);
3691e8a1faeSThomas Huth }
3701e8a1faeSThomas Huth
3711e8a1faeSThomas Huth /* strip def block name (it has file path in it) */
3721e8a1faeSThomas Huth if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
3731e8a1faeSThomas Huth block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
3741e8a1faeSThomas Huth g_assert(block_name);
3751e8a1faeSThomas Huth asl = g_string_erase(asl, 0,
3761e8a1faeSThomas Huth block_name + sizeof(BLOCK_NAME_END) - asl->str);
3771e8a1faeSThomas Huth }
3781e8a1faeSThomas Huth
3791e8a1faeSThomas Huth return asl;
3801e8a1faeSThomas Huth }
3811e8a1faeSThomas Huth
load_expected_aml(test_data * data)3821e8a1faeSThomas Huth static GArray *load_expected_aml(test_data *data)
3831e8a1faeSThomas Huth {
3841e8a1faeSThomas Huth int i;
3851e8a1faeSThomas Huth AcpiSdtTable *sdt;
3861e8a1faeSThomas Huth GError *error = NULL;
3871e8a1faeSThomas Huth gboolean ret;
3881e8a1faeSThomas Huth gsize aml_len;
3891e8a1faeSThomas Huth
3901e8a1faeSThomas Huth GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
3914ffa3a1bSThomas Huth if (verbosity_level >= 2) {
3921e8a1faeSThomas Huth fputc('\n', stderr);
3931e8a1faeSThomas Huth }
3941e8a1faeSThomas Huth for (i = 0; i < data->tables->len; ++i) {
3951e8a1faeSThomas Huth AcpiSdtTable exp_sdt;
3961e8a1faeSThomas Huth gchar *aml_file = NULL;
3971e8a1faeSThomas Huth const char *ext = data->variant ? data->variant : "";
3981e8a1faeSThomas Huth
3991e8a1faeSThomas Huth sdt = &g_array_index(data->tables, AcpiSdtTable, i);
4001e8a1faeSThomas Huth
4011e8a1faeSThomas Huth memset(&exp_sdt, 0, sizeof(exp_sdt));
4021e8a1faeSThomas Huth
4031e8a1faeSThomas Huth try_again:
404c9ad3decSSunil V L aml_file = g_strdup_printf("%s/%s/%s/%.4s%s", data_dir, data->arch,
405c9ad3decSSunil V L data->machine, sdt->aml, ext);
4064ffa3a1bSThomas Huth if (verbosity_level >= 2) {
4071e8a1faeSThomas Huth fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
4081e8a1faeSThomas Huth }
4091e8a1faeSThomas Huth if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
4101e8a1faeSThomas Huth exp_sdt.aml_file = aml_file;
4111e8a1faeSThomas Huth } else if (*ext != '\0') {
4121e8a1faeSThomas Huth /* try fallback to generic (extension less) expected file */
4131e8a1faeSThomas Huth ext = "";
4141e8a1faeSThomas Huth g_free(aml_file);
4151e8a1faeSThomas Huth goto try_again;
4161e8a1faeSThomas Huth }
4171e8a1faeSThomas Huth g_assert(exp_sdt.aml_file);
4184ffa3a1bSThomas Huth if (verbosity_level >= 2) {
4191e8a1faeSThomas Huth fprintf(stderr, "Using expected file '%s'\n", aml_file);
4201e8a1faeSThomas Huth }
4211e8a1faeSThomas Huth ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
4221e8a1faeSThomas Huth &aml_len, &error);
4231e8a1faeSThomas Huth exp_sdt.aml_len = aml_len;
4241e8a1faeSThomas Huth g_assert(ret);
4251e8a1faeSThomas Huth g_assert_no_error(error);
4261e8a1faeSThomas Huth g_assert(exp_sdt.aml);
4271e8a1faeSThomas Huth if (!exp_sdt.aml_len) {
4281e8a1faeSThomas Huth fprintf(stderr, "Warning! zero length expected file '%s'\n",
4291e8a1faeSThomas Huth aml_file);
4301e8a1faeSThomas Huth }
4311e8a1faeSThomas Huth
4321e8a1faeSThomas Huth g_array_append_val(exp_tables, exp_sdt);
4331e8a1faeSThomas Huth }
4341e8a1faeSThomas Huth
4351e8a1faeSThomas Huth return exp_tables;
4361e8a1faeSThomas Huth }
4371e8a1faeSThomas Huth
test_acpi_find_diff_allowed(AcpiSdtTable * sdt)4381e8a1faeSThomas Huth static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt)
4391e8a1faeSThomas Huth {
4401e8a1faeSThomas Huth const gchar *allowed_diff_file[] = {
4411e8a1faeSThomas Huth #include "bios-tables-test-allowed-diff.h"
4421e8a1faeSThomas Huth NULL
4431e8a1faeSThomas Huth };
4441e8a1faeSThomas Huth const gchar **f;
4451e8a1faeSThomas Huth
4461e8a1faeSThomas Huth for (f = allowed_diff_file; *f; ++f) {
4471e8a1faeSThomas Huth if (!g_strcmp0(sdt->aml_file, *f)) {
4481e8a1faeSThomas Huth return true;
4491e8a1faeSThomas Huth }
4501e8a1faeSThomas Huth }
4511e8a1faeSThomas Huth return false;
4521e8a1faeSThomas Huth }
4531e8a1faeSThomas Huth
4541e8a1faeSThomas Huth /* test the list of tables in @data->tables against reference tables */
test_acpi_asl(test_data * data)4551e8a1faeSThomas Huth static void test_acpi_asl(test_data *data)
4561e8a1faeSThomas Huth {
4571e8a1faeSThomas Huth int i;
4581e8a1faeSThomas Huth AcpiSdtTable *sdt, *exp_sdt;
459a74b0d0aSPaolo Bonzini test_data exp_data = {};
4601e8a1faeSThomas Huth gboolean exp_err, err, all_tables_match = true;
4611e8a1faeSThomas Huth
4621e8a1faeSThomas Huth exp_data.tables = load_expected_aml(data);
4631e8a1faeSThomas Huth dump_aml_files(data, false);
4641e8a1faeSThomas Huth for (i = 0; i < data->tables->len; ++i) {
4651e8a1faeSThomas Huth GString *asl, *exp_asl;
4661e8a1faeSThomas Huth
4671e8a1faeSThomas Huth sdt = &g_array_index(data->tables, AcpiSdtTable, i);
4681e8a1faeSThomas Huth exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
4691e8a1faeSThomas Huth
4701e8a1faeSThomas Huth if (sdt->aml_len == exp_sdt->aml_len &&
4711e8a1faeSThomas Huth !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
4721e8a1faeSThomas Huth /* Identical table binaries: no need to disassemble. */
4731e8a1faeSThomas Huth continue;
4741e8a1faeSThomas Huth }
4751e8a1faeSThomas Huth
4761e8a1faeSThomas Huth fprintf(stderr,
4771e8a1faeSThomas Huth "acpi-test: Warning! %.4s binary file mismatch. "
478a7b4384fSMichael S. Tsirkin "Actual [aml:%s], Expected [aml:%s].\n"
479a7b4384fSMichael S. Tsirkin "See source file tests/qtest/bios-tables-test.c "
480a7b4384fSMichael S. Tsirkin "for instructions on how to update expected files.\n",
4811e8a1faeSThomas Huth exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file);
4821e8a1faeSThomas Huth
4831e8a1faeSThomas Huth all_tables_match = all_tables_match &&
4841e8a1faeSThomas Huth test_acpi_find_diff_allowed(exp_sdt);
4851e8a1faeSThomas Huth
4861e8a1faeSThomas Huth /*
4871e8a1faeSThomas Huth * don't try to decompile if IASL isn't present, in this case user
4881e8a1faeSThomas Huth * will just 'get binary file mismatch' warnings and test failure
4891e8a1faeSThomas Huth */
4901e8a1faeSThomas Huth if (!iasl) {
4911e8a1faeSThomas Huth continue;
4921e8a1faeSThomas Huth }
4931e8a1faeSThomas Huth
4941e8a1faeSThomas Huth err = load_asl(data->tables, sdt);
4951e8a1faeSThomas Huth asl = normalize_asl(sdt->asl);
4961e8a1faeSThomas Huth
49781d72286SMichael S. Tsirkin /*
49881d72286SMichael S. Tsirkin * If expected file is empty - it's likely that it was a stub just
49981d72286SMichael S. Tsirkin * created for step 1 above: we do want to decompile the actual one.
50081d72286SMichael S. Tsirkin */
50181d72286SMichael S. Tsirkin if (exp_sdt->aml_len) {
5021e8a1faeSThomas Huth exp_err = load_asl(exp_data.tables, exp_sdt);
5031e8a1faeSThomas Huth exp_asl = normalize_asl(exp_sdt->asl);
50481d72286SMichael S. Tsirkin } else {
50581d72286SMichael S. Tsirkin exp_err = create_tmp_asl(exp_sdt);
50681d72286SMichael S. Tsirkin exp_asl = g_string_new("");
50781d72286SMichael S. Tsirkin }
5081e8a1faeSThomas Huth
5091e8a1faeSThomas Huth /* TODO: check for warnings */
51081d72286SMichael S. Tsirkin g_assert(!err || exp_err || !exp_sdt->aml_len);
5111e8a1faeSThomas Huth
5121e8a1faeSThomas Huth if (g_strcmp0(asl->str, exp_asl->str)) {
5131e8a1faeSThomas Huth sdt->tmp_files_retain = true;
5141e8a1faeSThomas Huth if (exp_err) {
5151e8a1faeSThomas Huth fprintf(stderr,
5161e8a1faeSThomas Huth "Warning! iasl couldn't parse the expected aml\n");
5171e8a1faeSThomas Huth } else {
5181e8a1faeSThomas Huth exp_sdt->tmp_files_retain = true;
5191e8a1faeSThomas Huth fprintf(stderr,
5201e8a1faeSThomas Huth "acpi-test: Warning! %.4s mismatch. "
5211e8a1faeSThomas Huth "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
5221e8a1faeSThomas Huth exp_sdt->aml, sdt->asl_file, sdt->aml_file,
5231e8a1faeSThomas Huth exp_sdt->asl_file, exp_sdt->aml_file);
524c01e905fSMichael S. Tsirkin fflush(stderr);
5254ffa3a1bSThomas Huth if (verbosity_level >= 1) {
52634b1429cSMichael S. Tsirkin const char *diff_env = getenv("DIFF");
527b20fdf2cSGerd Hoffmann const char *diff_cmd = diff_env ? diff_env : "diff -U 16";
5281e8a1faeSThomas Huth char *diff = g_strdup_printf("%s %s %s", diff_cmd,
5291e8a1faeSThomas Huth exp_sdt->asl_file, sdt->asl_file);
530c01e905fSMichael S. Tsirkin int out = dup(STDOUT_FILENO);
531c01e905fSMichael S. Tsirkin int ret G_GNUC_UNUSED;
5323c65e439SPeter Maydell int dupret;
533c01e905fSMichael S. Tsirkin
5343c65e439SPeter Maydell g_assert(out >= 0);
5353c65e439SPeter Maydell dupret = dup2(STDERR_FILENO, STDOUT_FILENO);
5363c65e439SPeter Maydell g_assert(dupret >= 0);
5371e8a1faeSThomas Huth ret = system(diff) ;
5383c65e439SPeter Maydell dupret = dup2(out, STDOUT_FILENO);
5393c65e439SPeter Maydell g_assert(dupret >= 0);
540c01e905fSMichael S. Tsirkin close(out);
5411e8a1faeSThomas Huth g_free(diff);
5421e8a1faeSThomas Huth }
5431e8a1faeSThomas Huth }
5441e8a1faeSThomas Huth }
5451e8a1faeSThomas Huth g_string_free(asl, true);
5461e8a1faeSThomas Huth g_string_free(exp_asl, true);
5471e8a1faeSThomas Huth }
5481e8a1faeSThomas Huth if (!iasl && !all_tables_match) {
5491e8a1faeSThomas Huth fprintf(stderr, "to see ASL diff between mismatched files install IASL,"
5501e8a1faeSThomas Huth " rebuild QEMU from scratch and re-run tests with V=1"
5511e8a1faeSThomas Huth " environment variable set");
5521e8a1faeSThomas Huth }
5531e8a1faeSThomas Huth g_assert(all_tables_match);
5541e8a1faeSThomas Huth
5551e8a1faeSThomas Huth free_test_data(&exp_data);
5561e8a1faeSThomas Huth }
5571e8a1faeSThomas Huth
smbios_ep2_table_ok(test_data * data,uint32_t addr)55833bff4a8SJulia Suvorova static bool smbios_ep2_table_ok(test_data *data, uint32_t addr)
5591e8a1faeSThomas Huth {
56033bff4a8SJulia Suvorova struct smbios_21_entry_point *ep_table = &data->smbios_ep_table.ep21;
5611e8a1faeSThomas Huth
5621e8a1faeSThomas Huth qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
5631e8a1faeSThomas Huth if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
5641e8a1faeSThomas Huth return false;
5651e8a1faeSThomas Huth }
5661e8a1faeSThomas Huth if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
5671e8a1faeSThomas Huth return false;
5681e8a1faeSThomas Huth }
5691e8a1faeSThomas Huth if (ep_table->structure_table_length == 0) {
5701e8a1faeSThomas Huth return false;
5711e8a1faeSThomas Huth }
5721e8a1faeSThomas Huth if (ep_table->number_of_structures == 0) {
5731e8a1faeSThomas Huth return false;
5741e8a1faeSThomas Huth }
5751e8a1faeSThomas Huth if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
5761e8a1faeSThomas Huth acpi_calc_checksum((uint8_t *)ep_table + 0x10,
5771e8a1faeSThomas Huth sizeof *ep_table - 0x10)) {
5781e8a1faeSThomas Huth return false;
5791e8a1faeSThomas Huth }
5801e8a1faeSThomas Huth return true;
5811e8a1faeSThomas Huth }
5821e8a1faeSThomas Huth
smbios_ep3_table_ok(test_data * data,uint64_t addr)58333bff4a8SJulia Suvorova static bool smbios_ep3_table_ok(test_data *data, uint64_t addr)
58433bff4a8SJulia Suvorova {
58533bff4a8SJulia Suvorova struct smbios_30_entry_point *ep_table = &data->smbios_ep_table.ep30;
58633bff4a8SJulia Suvorova
58733bff4a8SJulia Suvorova qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
58833bff4a8SJulia Suvorova if (memcmp(ep_table->anchor_string, "_SM3_", 5)) {
58933bff4a8SJulia Suvorova return false;
59033bff4a8SJulia Suvorova }
59133bff4a8SJulia Suvorova
59233bff4a8SJulia Suvorova if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table)) {
59333bff4a8SJulia Suvorova return false;
59433bff4a8SJulia Suvorova }
59533bff4a8SJulia Suvorova
59633bff4a8SJulia Suvorova return true;
59733bff4a8SJulia Suvorova }
59833bff4a8SJulia Suvorova
test_smbios_entry_point(test_data * data)59933bff4a8SJulia Suvorova static SmbiosEntryPointType test_smbios_entry_point(test_data *data)
6001e8a1faeSThomas Huth {
6011e8a1faeSThomas Huth uint32_t off;
6021e8a1faeSThomas Huth
6031e8a1faeSThomas Huth /* find smbios entry point structure */
6041e8a1faeSThomas Huth for (off = 0xf0000; off < 0x100000; off += 0x10) {
60533bff4a8SJulia Suvorova uint8_t sig[] = "_SM_", sig3[] = "_SM3_";
6061e8a1faeSThomas Huth int i;
6071e8a1faeSThomas Huth
6081e8a1faeSThomas Huth for (i = 0; i < sizeof sig - 1; ++i) {
6091e8a1faeSThomas Huth sig[i] = qtest_readb(data->qts, off + i);
6101e8a1faeSThomas Huth }
6111e8a1faeSThomas Huth
6121e8a1faeSThomas Huth if (!memcmp(sig, "_SM_", sizeof sig)) {
6131e8a1faeSThomas Huth /* signature match, but is this a valid entry point? */
61433bff4a8SJulia Suvorova if (smbios_ep2_table_ok(data, off)) {
61533bff4a8SJulia Suvorova data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] = off;
61633bff4a8SJulia Suvorova }
61733bff4a8SJulia Suvorova }
61833bff4a8SJulia Suvorova
61933bff4a8SJulia Suvorova for (i = 0; i < sizeof sig3 - 1; ++i) {
62033bff4a8SJulia Suvorova sig3[i] = qtest_readb(data->qts, off + i);
62133bff4a8SJulia Suvorova }
62233bff4a8SJulia Suvorova
62333bff4a8SJulia Suvorova if (!memcmp(sig3, "_SM3_", sizeof sig3)) {
62433bff4a8SJulia Suvorova if (smbios_ep3_table_ok(data, off)) {
62533bff4a8SJulia Suvorova data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] = off;
62633bff4a8SJulia Suvorova /* found 64-bit entry point, no need to look for 32-bit one */
6271e8a1faeSThomas Huth break;
6281e8a1faeSThomas Huth }
6291e8a1faeSThomas Huth }
6301e8a1faeSThomas Huth }
6311e8a1faeSThomas Huth
63233bff4a8SJulia Suvorova /* found at least one entry point */
63333bff4a8SJulia Suvorova g_assert_true(data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] ||
63433bff4a8SJulia Suvorova data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64]);
63533bff4a8SJulia Suvorova
63633bff4a8SJulia Suvorova return data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] ?
63733bff4a8SJulia Suvorova SMBIOS_ENTRY_POINT_TYPE_64 : SMBIOS_ENTRY_POINT_TYPE_32;
6381e8a1faeSThomas Huth }
6391e8a1faeSThomas Huth
smbios_single_instance(uint8_t type)6401e8a1faeSThomas Huth static inline bool smbios_single_instance(uint8_t type)
6411e8a1faeSThomas Huth {
6421e8a1faeSThomas Huth switch (type) {
6431e8a1faeSThomas Huth case 0:
6441e8a1faeSThomas Huth case 1:
6451e8a1faeSThomas Huth case 2:
6461e8a1faeSThomas Huth case 3:
6471e8a1faeSThomas Huth case 16:
6481e8a1faeSThomas Huth case 32:
6491e8a1faeSThomas Huth case 127:
6501e8a1faeSThomas Huth return true;
6511e8a1faeSThomas Huth default:
6521e8a1faeSThomas Huth return false;
6531e8a1faeSThomas Huth }
6541e8a1faeSThomas Huth }
6551e8a1faeSThomas Huth
smbios_cpu_test(test_data * data,uint32_t addr,SmbiosEntryPointType ep_type)6562d80b338SJulia Suvorova static void smbios_cpu_test(test_data *data, uint32_t addr,
6572d80b338SJulia Suvorova SmbiosEntryPointType ep_type)
658e1647539SYing Fang {
6592d80b338SJulia Suvorova uint8_t core_count, expected_core_count = data->smbios_core_count;
6607ee18dceSZhao Liu uint8_t thread_count, expected_thread_count = data->smbios_thread_count;
6612d80b338SJulia Suvorova uint16_t speed, expected_speed[2];
6622d80b338SJulia Suvorova uint16_t core_count2, expected_core_count2 = data->smbios_core_count2;
663198eee0cSZhao Liu uint16_t thread_count2, expected_thread_count2 = data->smbios_thread_count2;
664e1647539SYing Fang int offset[2];
665e1647539SYing Fang int i;
666e1647539SYing Fang
667e1647539SYing Fang /* Check CPU speed for backward compatibility */
668e1647539SYing Fang offset[0] = offsetof(struct smbios_type_4, max_speed);
669e1647539SYing Fang offset[1] = offsetof(struct smbios_type_4, current_speed);
6702d80b338SJulia Suvorova expected_speed[0] = data->smbios_cpu_max_speed ? : 2000;
6712d80b338SJulia Suvorova expected_speed[1] = data->smbios_cpu_curr_speed ? : 2000;
672e1647539SYing Fang
673e1647539SYing Fang for (i = 0; i < 2; i++) {
6742d80b338SJulia Suvorova speed = qtest_readw(data->qts, addr + offset[i]);
6752d80b338SJulia Suvorova g_assert_cmpuint(speed, ==, expected_speed[i]);
676e1647539SYing Fang }
677e1647539SYing Fang
6782d80b338SJulia Suvorova core_count = qtest_readb(data->qts,
6792d80b338SJulia Suvorova addr + offsetof(struct smbios_type_4, core_count));
6802d80b338SJulia Suvorova
6812d80b338SJulia Suvorova if (expected_core_count) {
6822d80b338SJulia Suvorova g_assert_cmpuint(core_count, ==, expected_core_count);
6832d80b338SJulia Suvorova }
6842d80b338SJulia Suvorova
6857ee18dceSZhao Liu thread_count = qtest_readb(data->qts,
6867ee18dceSZhao Liu addr + offsetof(struct smbios_type_4, thread_count));
6877ee18dceSZhao Liu
6887ee18dceSZhao Liu if (expected_thread_count) {
6897ee18dceSZhao Liu g_assert_cmpuint(thread_count, ==, expected_thread_count);
6907ee18dceSZhao Liu }
6917ee18dceSZhao Liu
6922d80b338SJulia Suvorova if (ep_type == SMBIOS_ENTRY_POINT_TYPE_64) {
6932d80b338SJulia Suvorova core_count2 = qtest_readw(data->qts,
6942d80b338SJulia Suvorova addr + offsetof(struct smbios_type_4, core_count2));
6952d80b338SJulia Suvorova
6962d80b338SJulia Suvorova /* Core Count has reached its limit, checking Core Count 2 */
6972d80b338SJulia Suvorova if (expected_core_count == 0xFF && expected_core_count2) {
6982d80b338SJulia Suvorova g_assert_cmpuint(core_count2, ==, expected_core_count2);
6992d80b338SJulia Suvorova }
700198eee0cSZhao Liu
701198eee0cSZhao Liu thread_count2 = qtest_readw(data->qts,
702198eee0cSZhao Liu addr + offsetof(struct smbios_type_4,
703198eee0cSZhao Liu thread_count2));
704198eee0cSZhao Liu
705198eee0cSZhao Liu /* Thread Count has reached its limit, checking Thread Count 2 */
706198eee0cSZhao Liu if (expected_thread_count == 0xFF && expected_thread_count2) {
707198eee0cSZhao Liu g_assert_cmpuint(thread_count2, ==, expected_thread_count2);
708198eee0cSZhao Liu }
7092d80b338SJulia Suvorova }
710e1647539SYing Fang }
711e1647539SYing Fang
smbios_type4_count_test(test_data * data,int type4_count)712df210963SZhao Liu static void smbios_type4_count_test(test_data *data, int type4_count)
713df210963SZhao Liu {
714df210963SZhao Liu int expected_type4_count = data->type4_count;
715df210963SZhao Liu
716df210963SZhao Liu if (expected_type4_count) {
717df210963SZhao Liu g_assert_cmpuint(type4_count, ==, expected_type4_count);
718df210963SZhao Liu }
719df210963SZhao Liu }
720df210963SZhao Liu
test_smbios_structs(test_data * data,SmbiosEntryPointType ep_type)72133bff4a8SJulia Suvorova static void test_smbios_structs(test_data *data, SmbiosEntryPointType ep_type)
7221e8a1faeSThomas Huth {
7231e8a1faeSThomas Huth DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
72433bff4a8SJulia Suvorova
72533bff4a8SJulia Suvorova SmbiosEntryPoint *ep_table = &data->smbios_ep_table;
726df210963SZhao Liu int i = 0, len, max_len = 0, type4_count = 0;
7271e8a1faeSThomas Huth uint8_t type, prv, crt;
72833bff4a8SJulia Suvorova uint64_t addr;
72933bff4a8SJulia Suvorova
73033bff4a8SJulia Suvorova if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32) {
73133bff4a8SJulia Suvorova addr = le32_to_cpu(ep_table->ep21.structure_table_address);
73233bff4a8SJulia Suvorova } else {
73333bff4a8SJulia Suvorova addr = le64_to_cpu(ep_table->ep30.structure_table_address);
73433bff4a8SJulia Suvorova }
7351e8a1faeSThomas Huth
7361e8a1faeSThomas Huth /* walk the smbios tables */
73733bff4a8SJulia Suvorova do {
7381e8a1faeSThomas Huth
7391e8a1faeSThomas Huth /* grab type and formatted area length from struct header */
7401e8a1faeSThomas Huth type = qtest_readb(data->qts, addr);
7411e8a1faeSThomas Huth g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
7421e8a1faeSThomas Huth len = qtest_readb(data->qts, addr + 1);
7431e8a1faeSThomas Huth
7441e8a1faeSThomas Huth /* single-instance structs must not have been encountered before */
7451e8a1faeSThomas Huth if (smbios_single_instance(type)) {
7461e8a1faeSThomas Huth g_assert(!test_bit(type, struct_bitmap));
7471e8a1faeSThomas Huth }
7481e8a1faeSThomas Huth set_bit(type, struct_bitmap);
7491e8a1faeSThomas Huth
750e1647539SYing Fang if (type == 4) {
7512d80b338SJulia Suvorova smbios_cpu_test(data, addr, ep_type);
752df210963SZhao Liu type4_count++;
753e1647539SYing Fang }
754e1647539SYing Fang
7551e8a1faeSThomas Huth /* seek to end of unformatted string area of this struct ("\0\0") */
7561e8a1faeSThomas Huth prv = crt = 1;
7571e8a1faeSThomas Huth while (prv || crt) {
7581e8a1faeSThomas Huth prv = crt;
7591e8a1faeSThomas Huth crt = qtest_readb(data->qts, addr + len);
7601e8a1faeSThomas Huth len++;
7611e8a1faeSThomas Huth }
7621e8a1faeSThomas Huth
7631e8a1faeSThomas Huth /* keep track of max. struct size */
76433bff4a8SJulia Suvorova if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32 && max_len < len) {
7651e8a1faeSThomas Huth max_len = len;
76633bff4a8SJulia Suvorova g_assert_cmpuint(max_len, <=, ep_table->ep21.max_structure_size);
7671e8a1faeSThomas Huth }
7681e8a1faeSThomas Huth
7691e8a1faeSThomas Huth /* start of next structure */
7701e8a1faeSThomas Huth addr += len;
7711e8a1faeSThomas Huth
77233bff4a8SJulia Suvorova /*
77333bff4a8SJulia Suvorova * Until all structures have been scanned (ep21)
77433bff4a8SJulia Suvorova * or an EOF structure is found (ep30)
77533bff4a8SJulia Suvorova */
77633bff4a8SJulia Suvorova } while (ep_type == SMBIOS_ENTRY_POINT_TYPE_32 ?
77733bff4a8SJulia Suvorova ++i < le16_to_cpu(ep_table->ep21.number_of_structures) :
77833bff4a8SJulia Suvorova type != 127);
77933bff4a8SJulia Suvorova
78033bff4a8SJulia Suvorova if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32) {
78133bff4a8SJulia Suvorova /*
78233bff4a8SJulia Suvorova * Total table length and max struct size
78333bff4a8SJulia Suvorova * must match entry point values
78433bff4a8SJulia Suvorova */
78533bff4a8SJulia Suvorova g_assert_cmpuint(le16_to_cpu(ep_table->ep21.structure_table_length), ==,
78633bff4a8SJulia Suvorova addr - le32_to_cpu(ep_table->ep21.structure_table_address));
78733bff4a8SJulia Suvorova
78833bff4a8SJulia Suvorova g_assert_cmpuint(le16_to_cpu(ep_table->ep21.max_structure_size), ==,
78933bff4a8SJulia Suvorova max_len);
79033bff4a8SJulia Suvorova }
7911e8a1faeSThomas Huth
7921e8a1faeSThomas Huth /* required struct types must all be present */
7931e8a1faeSThomas Huth for (i = 0; i < data->required_struct_types_len; i++) {
7941e8a1faeSThomas Huth g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
7951e8a1faeSThomas Huth }
796df210963SZhao Liu
797df210963SZhao Liu smbios_type4_count_test(data, type4_count);
7981e8a1faeSThomas Huth }
7991e8a1faeSThomas Huth
test_acpi_load_tables(test_data * data)800c1a9ac9bSIgor Mammedov static void test_acpi_load_tables(test_data *data)
8014b1f8882SMarian Postevca {
802c1a9ac9bSIgor Mammedov if (data->uefi_fl1 && data->uefi_fl2) { /* use UEFI */
8034b1f8882SMarian Postevca g_assert(data->scan_len);
8044b1f8882SMarian Postevca data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts,
8054b1f8882SMarian Postevca data->ram_start, data->scan_len);
8064b1f8882SMarian Postevca } else {
8074b1f8882SMarian Postevca boot_sector_test(data->qts);
8084b1f8882SMarian Postevca data->rsdp_addr = acpi_find_rsdp_address(data->qts);
8094b1f8882SMarian Postevca g_assert_cmphex(data->rsdp_addr, <, 0x100000);
8104b1f8882SMarian Postevca }
8114b1f8882SMarian Postevca
8124b1f8882SMarian Postevca data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
8134b1f8882SMarian Postevca test_acpi_rsdp_table(data);
8144b1f8882SMarian Postevca test_acpi_rxsdt_table(data);
8154b1f8882SMarian Postevca test_acpi_fadt_table(data);
8164b1f8882SMarian Postevca }
8174b1f8882SMarian Postevca
test_acpi_create_args(test_data * data,const char * params)818c1a9ac9bSIgor Mammedov static char *test_acpi_create_args(test_data *data, const char *params)
8191e8a1faeSThomas Huth {
8201e8a1faeSThomas Huth char *args;
821c51a5a23SClaudio Fontana
822c1a9ac9bSIgor Mammedov if (data->uefi_fl1 && data->uefi_fl2) { /* use UEFI */
8231e8a1faeSThomas Huth /*
8241e8a1faeSThomas Huth * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
8251e8a1faeSThomas Huth * when arm/virt boad starts to support it.
8261e8a1faeSThomas Huth */
8271da638b1SYubo Miao if (data->cd) {
8289a2112f9SThomas Huth args = g_strdup_printf("-machine %s%s %s -accel tcg "
8291da638b1SYubo Miao "-nodefaults -nographic "
830991c180dSPaolo Bonzini "-drive if=pflash,format=raw,file=%s,readonly=on "
8311e8a1faeSThomas Huth "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
8329a2112f9SThomas Huth data->machine, data->machine_param ?: "",
8339a2112f9SThomas Huth data->tcg_only ? "" : "-accel kvm",
8341e8a1faeSThomas Huth data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
8351da638b1SYubo Miao } else {
8369a2112f9SThomas Huth args = g_strdup_printf("-machine %s%s %s -accel tcg "
8371da638b1SYubo Miao "-nodefaults -nographic "
838991c180dSPaolo Bonzini "-drive if=pflash,format=raw,file=%s,readonly=on "
8391da638b1SYubo Miao "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
8409a2112f9SThomas Huth data->machine, data->machine_param ?: "",
8419a2112f9SThomas Huth data->tcg_only ? "" : "-accel kvm",
8421da638b1SYubo Miao data->uefi_fl1, data->uefi_fl2, params ? params : "");
8431da638b1SYubo Miao }
8441e8a1faeSThomas Huth } else {
8459a2112f9SThomas Huth args = g_strdup_printf("-machine %s%s %s -accel tcg "
846f15cfe41SJuan Quintela "-net none %s "
8471e8a1faeSThomas Huth "-drive id=hd0,if=none,file=%s,format=raw "
8483cac3784SGerd Hoffmann "-device %s,drive=hd0 ",
8499a2112f9SThomas Huth data->machine, data->machine_param ?: "",
8509a2112f9SThomas Huth data->tcg_only ? "" : "-accel kvm",
8513cac3784SGerd Hoffmann params ? params : "", disk,
8523cac3784SGerd Hoffmann data->blkdev ?: "ide-hd");
8531e8a1faeSThomas Huth }
8544b1f8882SMarian Postevca return args;
8551e8a1faeSThomas Huth }
8561e8a1faeSThomas Huth
test_vm_prepare(const char * params,test_data * data)8572f447a36SIgor Mammedov static void test_vm_prepare(const char *params, test_data *data)
8584b1f8882SMarian Postevca {
8592f447a36SIgor Mammedov char *args = test_acpi_create_args(data, params);
8604b1f8882SMarian Postevca data->qts = qtest_init(args);
8612f447a36SIgor Mammedov g_free(args);
8622f447a36SIgor Mammedov }
8632f447a36SIgor Mammedov
process_smbios_tables_noexit(test_data * data)86453002d90SIgor Mammedov static void process_smbios_tables_noexit(test_data *data)
86553002d90SIgor Mammedov {
86653002d90SIgor Mammedov /*
86753002d90SIgor Mammedov * TODO: make SMBIOS tests work with UEFI firmware,
86853002d90SIgor Mammedov * Bug on uefi-test-tools to provide entry point:
86953002d90SIgor Mammedov * https://bugs.launchpad.net/qemu/+bug/1821884
87053002d90SIgor Mammedov */
87153002d90SIgor Mammedov if (!(data->uefi_fl1 && data->uefi_fl2)) {
87253002d90SIgor Mammedov SmbiosEntryPointType ep_type = test_smbios_entry_point(data);
87353002d90SIgor Mammedov test_smbios_structs(data, ep_type);
87453002d90SIgor Mammedov }
87553002d90SIgor Mammedov }
87653002d90SIgor Mammedov
test_smbios(const char * params,test_data * data)87753002d90SIgor Mammedov static void test_smbios(const char *params, test_data *data)
87853002d90SIgor Mammedov {
87953002d90SIgor Mammedov test_vm_prepare(params, data);
88053002d90SIgor Mammedov boot_sector_test(data->qts);
88153002d90SIgor Mammedov process_smbios_tables_noexit(data);
88253002d90SIgor Mammedov qtest_quit(data->qts);
88353002d90SIgor Mammedov }
88453002d90SIgor Mammedov
process_acpi_tables_noexit(test_data * data)885c0d19126SIgor Mammedov static void process_acpi_tables_noexit(test_data *data)
8862f447a36SIgor Mammedov {
887c1a9ac9bSIgor Mammedov test_acpi_load_tables(data);
8881e8a1faeSThomas Huth
8891e8a1faeSThomas Huth if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
8901e8a1faeSThomas Huth dump_aml_files(data, true);
8911e8a1faeSThomas Huth } else {
8921e8a1faeSThomas Huth test_acpi_asl(data);
8931e8a1faeSThomas Huth }
8941e8a1faeSThomas Huth
89553002d90SIgor Mammedov process_smbios_tables_noexit(data);
896c0d19126SIgor Mammedov }
8971e8a1faeSThomas Huth
process_acpi_tables(test_data * data)898c0d19126SIgor Mammedov static void process_acpi_tables(test_data *data)
899c0d19126SIgor Mammedov {
900c0d19126SIgor Mammedov process_acpi_tables_noexit(data);
9011e8a1faeSThomas Huth qtest_quit(data->qts);
9022f447a36SIgor Mammedov }
9032f447a36SIgor Mammedov
test_acpi_one(const char * params,test_data * data)9042f447a36SIgor Mammedov static void test_acpi_one(const char *params, test_data *data)
9052f447a36SIgor Mammedov {
9062f447a36SIgor Mammedov test_vm_prepare(params, data);
9072f447a36SIgor Mammedov process_acpi_tables(data);
9081e8a1faeSThomas Huth }
9091e8a1faeSThomas Huth
9101e8a1faeSThomas Huth static uint8_t base_required_struct_types[] = {
9111e8a1faeSThomas Huth 0, 1, 3, 4, 16, 17, 19, 32, 127
9121e8a1faeSThomas Huth };
9131e8a1faeSThomas Huth
test_acpi_piix4_tcg(void)9141e8a1faeSThomas Huth static void test_acpi_piix4_tcg(void)
9151e8a1faeSThomas Huth {
916a74b0d0aSPaolo Bonzini test_data data = {};
9171e8a1faeSThomas Huth
9181e8a1faeSThomas Huth /* Supplying -machine accel argument overrides the default (qtest).
9191e8a1faeSThomas Huth * This is to make guest actually run.
9201e8a1faeSThomas Huth */
9211e8a1faeSThomas Huth data.machine = MACHINE_PC;
922d488c66bSSunil V L data.arch = "x86";
9231e8a1faeSThomas Huth data.required_struct_types = base_required_struct_types;
9241e8a1faeSThomas Huth data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
9251e8a1faeSThomas Huth test_acpi_one(NULL, &data);
9261e8a1faeSThomas Huth free_test_data(&data);
9271e8a1faeSThomas Huth }
9281e8a1faeSThomas Huth
test_acpi_piix4_tcg_bridge(void)9291e8a1faeSThomas Huth static void test_acpi_piix4_tcg_bridge(void)
9301e8a1faeSThomas Huth {
931a74b0d0aSPaolo Bonzini test_data data = {};
9321e8a1faeSThomas Huth
9331e8a1faeSThomas Huth data.machine = MACHINE_PC;
934d488c66bSSunil V L data.arch = "x86";
9351e8a1faeSThomas Huth data.variant = ".bridge";
9361e8a1faeSThomas Huth data.required_struct_types = base_required_struct_types;
9371e8a1faeSThomas Huth data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
9382f447a36SIgor Mammedov test_vm_prepare("-S"
9392f447a36SIgor Mammedov " -device pci-bridge,chassis_nr=1"
940be8e3331SIgor Mammedov " -device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2"
941be8e3331SIgor Mammedov " -device pci-testdev,bus=pci.0,addr=5.0"
942be8e3331SIgor Mammedov " -device pci-testdev,bus=pci.1", &data);
9432f447a36SIgor Mammedov
9442f447a36SIgor Mammedov /* hotplugged bridges section */
9452f447a36SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr",
9462f447a36SIgor Mammedov "{'bus': 'pci.1', 'addr': '2.0', 'chassis_nr': 3 }");
9472f447a36SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr_multifunc",
9482f447a36SIgor Mammedov "{'bus': 'pci.1', 'addr': '0xf.1', 'chassis_nr': 4 }");
9492f447a36SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-bridge", "hpbrhost",
9502f447a36SIgor Mammedov "{'bus': 'pci.0', 'addr': '4.0', 'chassis_nr': 5 }");
951be8e3331SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-testdev", "d1", "{'bus': 'pci.0' }");
952be8e3331SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-testdev", "d2", "{'bus': 'pci.1' }");
953be8e3331SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-testdev", "d3", "{'bus': 'hpbr', "
954be8e3331SIgor Mammedov "'addr': '1.0' }");
9552f447a36SIgor Mammedov qtest_qmp_send(data.qts, "{'execute':'cont' }");
9562f447a36SIgor Mammedov qtest_qmp_eventwait(data.qts, "RESUME");
9572f447a36SIgor Mammedov
958c0d19126SIgor Mammedov process_acpi_tables_noexit(&data);
959c0d19126SIgor Mammedov free_test_data(&data);
960c0d19126SIgor Mammedov
961c0d19126SIgor Mammedov /* check that reboot/reset doesn't change any ACPI tables */
962c0d19126SIgor Mammedov qtest_qmp_send(data.qts, "{'execute':'system_reset' }");
9632f447a36SIgor Mammedov process_acpi_tables(&data);
9641e8a1faeSThomas Huth free_test_data(&data);
9651e8a1faeSThomas Huth }
9661e8a1faeSThomas Huth
test_acpi_piix4_no_root_hotplug(void)96727476395SAni Sinha static void test_acpi_piix4_no_root_hotplug(void)
96827476395SAni Sinha {
969a74b0d0aSPaolo Bonzini test_data data = {};
97027476395SAni Sinha
97127476395SAni Sinha data.machine = MACHINE_PC;
972d488c66bSSunil V L data.arch = "x86";
97327476395SAni Sinha data.variant = ".roothp";
97427476395SAni Sinha data.required_struct_types = base_required_struct_types;
97527476395SAni Sinha data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
97627476395SAni Sinha test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
9779ebb74d6SIgor Mammedov "-device pci-bridge,chassis_nr=1 "
978be8e3331SIgor Mammedov "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
979be8e3331SIgor Mammedov "-device pci-testdev,bus=pci.0 "
980be8e3331SIgor Mammedov "-device pci-testdev,bus=pci.1", &data);
98127476395SAni Sinha free_test_data(&data);
98227476395SAni Sinha }
98327476395SAni Sinha
test_acpi_piix4_no_bridge_hotplug(void)9845e3a4862SAni Sinha static void test_acpi_piix4_no_bridge_hotplug(void)
9855e3a4862SAni Sinha {
986a74b0d0aSPaolo Bonzini test_data data = {};
9875e3a4862SAni Sinha
9885e3a4862SAni Sinha data.machine = MACHINE_PC;
989d488c66bSSunil V L data.arch = "x86";
9905e3a4862SAni Sinha data.variant = ".hpbridge";
9915e3a4862SAni Sinha data.required_struct_types = base_required_struct_types;
9925e3a4862SAni Sinha data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
9935e3a4862SAni Sinha test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
9949ebb74d6SIgor Mammedov "-device pci-bridge,chassis_nr=1 "
995be8e3331SIgor Mammedov "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
996be8e3331SIgor Mammedov "-device pci-testdev,bus=pci.0 "
997be8e3331SIgor Mammedov "-device pci-testdev,bus=pci.1,addr=2.0", &data);
9985e3a4862SAni Sinha free_test_data(&data);
9995e3a4862SAni Sinha }
10005e3a4862SAni Sinha
test_acpi_piix4_no_acpi_pci_hotplug(void)10015645f996SAni Sinha static void test_acpi_piix4_no_acpi_pci_hotplug(void)
10025645f996SAni Sinha {
1003a74b0d0aSPaolo Bonzini test_data data = {};
10045645f996SAni Sinha
10055645f996SAni Sinha data.machine = MACHINE_PC;
1006d488c66bSSunil V L data.arch = "x86";
10075645f996SAni Sinha data.variant = ".hpbrroot";
10085645f996SAni Sinha data.required_struct_types = base_required_struct_types;
10095645f996SAni Sinha data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
10105645f996SAni Sinha test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
10115645f996SAni Sinha "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
1012b0b3b99eSIgor Mammedov "-device pci-bridge,chassis_nr=1,addr=4.0 "
1013b0b3b99eSIgor Mammedov "-device pci-testdev,bus=pci.0,addr=5.0 "
1014b0b3b99eSIgor Mammedov "-device pci-testdev,bus=pci.0,addr=6.0,acpi-index=101 "
1015b0b3b99eSIgor Mammedov "-device pci-testdev,bus=pci.1,addr=1.0 "
1016b0b3b99eSIgor Mammedov "-device pci-testdev,bus=pci.1,addr=2.0,acpi-index=201 "
1017b0b3b99eSIgor Mammedov "-device pci-bridge,id=nhpbr,chassis_nr=2,shpc=off,addr=7.0 "
1018b0b3b99eSIgor Mammedov "-device pci-testdev,bus=nhpbr,addr=1.0,acpi-index=301 "
1019b0b3b99eSIgor Mammedov , &data);
10205645f996SAni Sinha free_test_data(&data);
10215645f996SAni Sinha }
10225645f996SAni Sinha
test_acpi_q35_tcg(void)10231e8a1faeSThomas Huth static void test_acpi_q35_tcg(void)
10241e8a1faeSThomas Huth {
1025a74b0d0aSPaolo Bonzini test_data data = {};
10261e8a1faeSThomas Huth
10271e8a1faeSThomas Huth data.machine = MACHINE_Q35;
1028d488c66bSSunil V L data.arch = "x86";
10291e8a1faeSThomas Huth data.required_struct_types = base_required_struct_types;
10301e8a1faeSThomas Huth data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
10311e8a1faeSThomas Huth test_acpi_one(NULL, &data);
10321e8a1faeSThomas Huth free_test_data(&data);
1033e1647539SYing Fang
1034e1647539SYing Fang data.smbios_cpu_max_speed = 3000;
1035e1647539SYing Fang data.smbios_cpu_curr_speed = 2600;
1036e1647539SYing Fang test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data);
1037e1647539SYing Fang free_test_data(&data);
10381e8a1faeSThomas Huth }
10391e8a1faeSThomas Huth
test_acpi_q35_kvm_type4_count(void)1040c40db4baSZhao Liu static void test_acpi_q35_kvm_type4_count(void)
1041df210963SZhao Liu {
1042df210963SZhao Liu test_data data = {
1043df210963SZhao Liu .machine = MACHINE_Q35,
1044d488c66bSSunil V L .arch = "x86",
1045df210963SZhao Liu .variant = ".type4-count",
1046df210963SZhao Liu .required_struct_types = base_required_struct_types,
1047df210963SZhao Liu .required_struct_types_len = ARRAY_SIZE(base_required_struct_types),
1048df210963SZhao Liu .type4_count = 5,
1049df210963SZhao Liu };
1050df210963SZhao Liu
1051df210963SZhao Liu test_acpi_one("-machine smbios-entry-point-type=64 "
1052df210963SZhao Liu "-smp cpus=100,maxcpus=120,sockets=5,"
1053df210963SZhao Liu "dies=2,cores=4,threads=3", &data);
1054df210963SZhao Liu free_test_data(&data);
1055df210963SZhao Liu }
1056df210963SZhao Liu
test_acpi_q35_kvm_core_count(void)1057c40db4baSZhao Liu static void test_acpi_q35_kvm_core_count(void)
1058148a8a1dSZhao Liu {
1059148a8a1dSZhao Liu test_data data = {
1060148a8a1dSZhao Liu .machine = MACHINE_Q35,
1061d488c66bSSunil V L .arch = "x86",
1062148a8a1dSZhao Liu .variant = ".core-count",
1063148a8a1dSZhao Liu .required_struct_types = base_required_struct_types,
1064148a8a1dSZhao Liu .required_struct_types_len = ARRAY_SIZE(base_required_struct_types),
1065148a8a1dSZhao Liu .smbios_core_count = 9,
1066148a8a1dSZhao Liu .smbios_core_count2 = 9,
1067148a8a1dSZhao Liu };
1068148a8a1dSZhao Liu
1069148a8a1dSZhao Liu test_acpi_one("-machine smbios-entry-point-type=64 "
1070148a8a1dSZhao Liu "-smp 54,sockets=2,dies=3,cores=3,threads=3",
1071148a8a1dSZhao Liu &data);
1072148a8a1dSZhao Liu free_test_data(&data);
1073148a8a1dSZhao Liu }
1074148a8a1dSZhao Liu
test_acpi_q35_kvm_core_count2(void)1075c40db4baSZhao Liu static void test_acpi_q35_kvm_core_count2(void)
10762d80b338SJulia Suvorova {
10772d80b338SJulia Suvorova test_data data = {
10782d80b338SJulia Suvorova .machine = MACHINE_Q35,
1079d488c66bSSunil V L .arch = "x86",
10802d80b338SJulia Suvorova .variant = ".core-count2",
10812d80b338SJulia Suvorova .required_struct_types = base_required_struct_types,
10822d80b338SJulia Suvorova .required_struct_types_len = ARRAY_SIZE(base_required_struct_types),
10832d80b338SJulia Suvorova .smbios_core_count = 0xFF,
10846dc82e32SZhao Liu .smbios_core_count2 = 260,
10852d80b338SJulia Suvorova };
10862d80b338SJulia Suvorova
10876dc82e32SZhao Liu test_acpi_one("-machine smbios-entry-point-type=64 "
10886dc82e32SZhao Liu "-smp 260,dies=2,cores=130,threads=1",
10896dc82e32SZhao Liu &data);
10902d80b338SJulia Suvorova free_test_data(&data);
10912d80b338SJulia Suvorova }
10922d80b338SJulia Suvorova
test_acpi_q35_kvm_thread_count(void)1093c40db4baSZhao Liu static void test_acpi_q35_kvm_thread_count(void)
10947ee18dceSZhao Liu {
10957ee18dceSZhao Liu test_data data = {
10967ee18dceSZhao Liu .machine = MACHINE_Q35,
1097d488c66bSSunil V L .arch = "x86",
10987ee18dceSZhao Liu .variant = ".thread-count",
10997ee18dceSZhao Liu .required_struct_types = base_required_struct_types,
11007ee18dceSZhao Liu .required_struct_types_len = ARRAY_SIZE(base_required_struct_types),
11017ee18dceSZhao Liu .smbios_thread_count = 27,
1102198eee0cSZhao Liu .smbios_thread_count2 = 27,
11037ee18dceSZhao Liu };
11047ee18dceSZhao Liu
11057ee18dceSZhao Liu test_acpi_one("-machine smbios-entry-point-type=64 "
11067ee18dceSZhao Liu "-smp cpus=15,maxcpus=54,sockets=2,dies=3,cores=3,threads=3",
11077ee18dceSZhao Liu &data);
11087ee18dceSZhao Liu free_test_data(&data);
11097ee18dceSZhao Liu }
11107ee18dceSZhao Liu
test_acpi_q35_kvm_thread_count2(void)1111c40db4baSZhao Liu static void test_acpi_q35_kvm_thread_count2(void)
1112198eee0cSZhao Liu {
1113198eee0cSZhao Liu test_data data = {
1114198eee0cSZhao Liu .machine = MACHINE_Q35,
1115d488c66bSSunil V L .arch = "x86",
1116198eee0cSZhao Liu .variant = ".thread-count2",
1117198eee0cSZhao Liu .required_struct_types = base_required_struct_types,
1118198eee0cSZhao Liu .required_struct_types_len = ARRAY_SIZE(base_required_struct_types),
1119198eee0cSZhao Liu .smbios_thread_count = 0xFF,
1120198eee0cSZhao Liu .smbios_thread_count2 = 260,
1121198eee0cSZhao Liu };
1122198eee0cSZhao Liu
1123198eee0cSZhao Liu test_acpi_one("-machine smbios-entry-point-type=64 "
1124198eee0cSZhao Liu "-smp cpus=210,maxcpus=260,dies=2,cores=65,threads=2",
1125198eee0cSZhao Liu &data);
1126198eee0cSZhao Liu free_test_data(&data);
1127198eee0cSZhao Liu }
1128198eee0cSZhao Liu
test_acpi_q35_tcg_bridge(void)11291e8a1faeSThomas Huth static void test_acpi_q35_tcg_bridge(void)
11301e8a1faeSThomas Huth {
1131a74b0d0aSPaolo Bonzini test_data data = {};
11321e8a1faeSThomas Huth
11331e8a1faeSThomas Huth data.machine = MACHINE_Q35;
1134d488c66bSSunil V L data.arch = "x86",
11351e8a1faeSThomas Huth data.variant = ".bridge";
11361e8a1faeSThomas Huth data.required_struct_types = base_required_struct_types;
11371e8a1faeSThomas Huth data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
1138be8e3331SIgor Mammedov test_acpi_one("-device pci-bridge,chassis_nr=1,id=br1"
1139be8e3331SIgor Mammedov " -device pci-testdev,bus=pcie.0"
1140be8e3331SIgor Mammedov " -device pci-testdev,bus=br1", &data);
11411e8a1faeSThomas Huth free_test_data(&data);
11421e8a1faeSThomas Huth }
11431e8a1faeSThomas Huth
test_acpi_q35_tcg_no_acpi_hotplug(void)1144b0b3b99eSIgor Mammedov static void test_acpi_q35_tcg_no_acpi_hotplug(void)
1145b0b3b99eSIgor Mammedov {
1146a74b0d0aSPaolo Bonzini test_data data = {};
1147b0b3b99eSIgor Mammedov
1148b0b3b99eSIgor Mammedov data.machine = MACHINE_Q35;
1149d488c66bSSunil V L data.arch = "x86",
1150b0b3b99eSIgor Mammedov data.variant = ".noacpihp";
1151b0b3b99eSIgor Mammedov data.required_struct_types = base_required_struct_types;
1152b0b3b99eSIgor Mammedov data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
1153b0b3b99eSIgor Mammedov test_acpi_one("-global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=off"
1154b0b3b99eSIgor Mammedov " -device pci-testdev,bus=pcie.0,acpi-index=101,addr=3.0"
1155b0b3b99eSIgor Mammedov " -device pci-bridge,chassis_nr=1,id=shpcbr,addr=4.0"
1156b0b3b99eSIgor Mammedov " -device pci-testdev,bus=shpcbr,addr=1.0,acpi-index=201"
1157b0b3b99eSIgor Mammedov " -device pci-bridge,chassis_nr=2,shpc=off,id=noshpcbr,addr=5.0"
1158b0b3b99eSIgor Mammedov " -device pci-testdev,bus=noshpcbr,addr=1.0,acpi-index=301"
1159b0b3b99eSIgor Mammedov " -device pcie-root-port,id=hprp,port=0x0,chassis=1,addr=6.0"
1160b0b3b99eSIgor Mammedov " -device pci-testdev,bus=hprp,acpi-index=401"
1161b0b3b99eSIgor Mammedov " -device pcie-root-port,id=nohprp,port=0x0,chassis=2,hotplug=off,"
1162b0b3b99eSIgor Mammedov "addr=7.0"
1163b0b3b99eSIgor Mammedov " -device pci-testdev,bus=nohprp,acpi-index=501"
1164b0b3b99eSIgor Mammedov " -device pcie-root-port,id=nohprpint,port=0x0,chassis=3,hotplug=off,"
1165bf5fde79SIgor Mammedov "multifunction=on,addr=8.0"
11667b0ba7b1SAni Sinha " -device pci-testdev,bus=nohprpint,acpi-index=601,addr=0.1"
1167b0b3b99eSIgor Mammedov " -device pcie-root-port,id=hprp2,port=0x0,chassis=4,bus=nohprpint,"
11687b0ba7b1SAni Sinha "addr=0.2"
1169bf5fde79SIgor Mammedov " -device pci-testdev,bus=hprp2,acpi-index=602"
1170b0b3b99eSIgor Mammedov , &data);
1171b0b3b99eSIgor Mammedov free_test_data(&data);
1172b0b3b99eSIgor Mammedov }
1173b0b3b99eSIgor Mammedov
test_acpi_q35_multif_bridge(void)117404dd78b9SAni Sinha static void test_acpi_q35_multif_bridge(void)
117504dd78b9SAni Sinha {
117604dd78b9SAni Sinha test_data data = {
117704dd78b9SAni Sinha .machine = MACHINE_Q35,
1178d488c66bSSunil V L .arch = "x86",
117904dd78b9SAni Sinha .variant = ".multi-bridge",
118004dd78b9SAni Sinha };
11812f447a36SIgor Mammedov test_vm_prepare("-S"
118236773faeSIgor Mammedov " -device virtio-balloon,id=balloon0,addr=0x4.0x2"
118336773faeSIgor Mammedov " -device pcie-root-port,id=rp0,multifunction=on,"
118436773faeSIgor Mammedov "port=0x0,chassis=1,addr=0x2"
11859ebb74d6SIgor Mammedov " -device pcie-root-port,id=rp1,port=0x1,chassis=2,addr=0x3.0x1"
11869ebb74d6SIgor Mammedov " -device pcie-root-port,id=rp2,port=0x0,chassis=3,bus=rp1,addr=0.0"
11879ebb74d6SIgor Mammedov " -device pci-bridge,bus=rp2,chassis_nr=4,id=br1"
11889ebb74d6SIgor Mammedov " -device pcie-root-port,id=rphptgt1,port=0x0,chassis=5,addr=2.1"
11899ebb74d6SIgor Mammedov " -device pcie-root-port,id=rphptgt2,port=0x0,chassis=6,addr=2.2"
1190be8e3331SIgor Mammedov " -device pcie-root-port,id=rphptgt3,port=0x0,chassis=7,addr=2.3"
1191be8e3331SIgor Mammedov " -device pci-testdev,bus=pcie.0,addr=2.4"
1192bf5fde79SIgor Mammedov " -device pci-testdev,bus=pcie.0,addr=2.5,acpi-index=102"
1193be8e3331SIgor Mammedov " -device pci-testdev,bus=pcie.0,addr=5.0"
119422c8dd00SIgor Mammedov " -device pci-testdev,bus=pcie.0,addr=0xf.0,acpi-index=101"
1195be8e3331SIgor Mammedov " -device pci-testdev,bus=rp0,addr=0.0"
11960c3bf7c4SIgor Mammedov " -device pci-testdev,bus=br1"
11970c3bf7c4SIgor Mammedov " -device pcie-root-port,id=rpnohp,chassis=8,addr=0xA.0,hotplug=off"
11980c3bf7c4SIgor Mammedov " -device pcie-root-port,id=rp3,chassis=9,bus=rpnohp"
11990c3bf7c4SIgor Mammedov , &data);
12009ebb74d6SIgor Mammedov
12012f447a36SIgor Mammedov /* hotplugged bridges section */
12022f447a36SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr1",
12032f447a36SIgor Mammedov "{'bus': 'br1', 'addr': '6.0', 'chassis_nr': 128 }");
12042f447a36SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr2-multiif",
12052f447a36SIgor Mammedov "{ 'bus': 'br1', 'addr': '2.2', 'chassis_nr': 129 }");
12062f447a36SIgor Mammedov qtest_qmp_device_add(data.qts, "pcie-pci-bridge", "hpbr3",
1207be8e3331SIgor Mammedov "{'bus': 'rphptgt1', 'addr': '0.0' }");
1208be8e3331SIgor Mammedov qtest_qmp_device_add(data.qts, "pcie-root-port", "hprp",
1209be8e3331SIgor Mammedov "{'bus': 'rphptgt2', 'addr': '0.0' }");
1210be8e3331SIgor Mammedov qtest_qmp_device_add(data.qts, "pci-testdev", "hpnic",
1211be8e3331SIgor Mammedov "{'bus': 'rphptgt3', 'addr': '0.0' }");
12122f447a36SIgor Mammedov qtest_qmp_send(data.qts, "{'execute':'cont' }");
12132f447a36SIgor Mammedov qtest_qmp_eventwait(data.qts, "RESUME");
12142f447a36SIgor Mammedov
1215c0d19126SIgor Mammedov process_acpi_tables_noexit(&data);
1216c0d19126SIgor Mammedov free_test_data(&data);
1217c0d19126SIgor Mammedov
1218c0d19126SIgor Mammedov /* check that reboot/reset doesn't change any ACPI tables */
1219c0d19126SIgor Mammedov qtest_qmp_send(data.qts, "{'execute':'system_reset' }");
12202f447a36SIgor Mammedov process_acpi_tables(&data);
122104dd78b9SAni Sinha free_test_data(&data);
122204dd78b9SAni Sinha }
122304dd78b9SAni Sinha
test_acpi_q35_tcg_mmio64(void)12241e8a1faeSThomas Huth static void test_acpi_q35_tcg_mmio64(void)
12251e8a1faeSThomas Huth {
12261e8a1faeSThomas Huth test_data data = {
12271e8a1faeSThomas Huth .machine = MACHINE_Q35,
1228d488c66bSSunil V L .arch = "x86",
12291e8a1faeSThomas Huth .variant = ".mmio64",
12307ff1b8c0SGerd Hoffmann .tcg_only = true,
12311e8a1faeSThomas Huth .required_struct_types = base_required_struct_types,
12321e8a1faeSThomas Huth .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
12331e8a1faeSThomas Huth };
12341e8a1faeSThomas Huth
12351e8a1faeSThomas Huth test_acpi_one("-m 128M,slots=1,maxmem=2G "
12367ff1b8c0SGerd Hoffmann "-cpu Opteron_G1 "
12371e8a1faeSThomas Huth "-object memory-backend-ram,id=ram0,size=128M "
12381e8a1faeSThomas Huth "-numa node,memdev=ram0 "
12391e8a1faeSThomas Huth "-device pci-testdev,membar=2G",
12401e8a1faeSThomas Huth &data);
12411e8a1faeSThomas Huth free_test_data(&data);
12421e8a1faeSThomas Huth }
12431e8a1faeSThomas Huth
test_acpi_piix4_tcg_cphp(void)12441e8a1faeSThomas Huth static void test_acpi_piix4_tcg_cphp(void)
12451e8a1faeSThomas Huth {
1246a74b0d0aSPaolo Bonzini test_data data = {};
12471e8a1faeSThomas Huth
12481e8a1faeSThomas Huth data.machine = MACHINE_PC;
1249d488c66bSSunil V L data.arch = "x86";
12501e8a1faeSThomas Huth data.variant = ".cphp";
12511e8a1faeSThomas Huth test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
12521e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=64M"
12531e8a1faeSThomas Huth " -object memory-backend-ram,id=ram1,size=64M"
12541e8a1faeSThomas Huth " -numa node,memdev=ram0 -numa node,memdev=ram1"
12551e8a1faeSThomas Huth " -numa dist,src=0,dst=1,val=21",
12561e8a1faeSThomas Huth &data);
12571e8a1faeSThomas Huth free_test_data(&data);
12581e8a1faeSThomas Huth }
12591e8a1faeSThomas Huth
test_acpi_q35_tcg_cphp(void)12601e8a1faeSThomas Huth static void test_acpi_q35_tcg_cphp(void)
12611e8a1faeSThomas Huth {
1262a74b0d0aSPaolo Bonzini test_data data = {};
12631e8a1faeSThomas Huth
12641e8a1faeSThomas Huth data.machine = MACHINE_Q35;
1265d488c66bSSunil V L data.arch = "x86",
12661e8a1faeSThomas Huth data.variant = ".cphp";
12671e8a1faeSThomas Huth test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
12681e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=64M"
12691e8a1faeSThomas Huth " -object memory-backend-ram,id=ram1,size=64M"
12701e8a1faeSThomas Huth " -numa node,memdev=ram0 -numa node,memdev=ram1"
12711e8a1faeSThomas Huth " -numa dist,src=0,dst=1,val=21",
12721e8a1faeSThomas Huth &data);
12731e8a1faeSThomas Huth free_test_data(&data);
12741e8a1faeSThomas Huth }
12751e8a1faeSThomas Huth
12761e8a1faeSThomas Huth static uint8_t ipmi_required_struct_types[] = {
12771e8a1faeSThomas Huth 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
12781e8a1faeSThomas Huth };
12791e8a1faeSThomas Huth
test_acpi_q35_tcg_ipmi(void)12801e8a1faeSThomas Huth static void test_acpi_q35_tcg_ipmi(void)
12811e8a1faeSThomas Huth {
1282a74b0d0aSPaolo Bonzini test_data data = {};
12831e8a1faeSThomas Huth
12841e8a1faeSThomas Huth data.machine = MACHINE_Q35;
1285d488c66bSSunil V L data.arch = "x86",
12861e8a1faeSThomas Huth data.variant = ".ipmibt";
12871e8a1faeSThomas Huth data.required_struct_types = ipmi_required_struct_types;
12881e8a1faeSThomas Huth data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
12891e8a1faeSThomas Huth test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
12901e8a1faeSThomas Huth " -device isa-ipmi-bt,bmc=bmc0",
12911e8a1faeSThomas Huth &data);
12921e8a1faeSThomas Huth free_test_data(&data);
12931e8a1faeSThomas Huth }
12941e8a1faeSThomas Huth
test_acpi_q35_tcg_smbus_ipmi(void)1295ac70b4a3SIgor Mammedov static void test_acpi_q35_tcg_smbus_ipmi(void)
1296ac70b4a3SIgor Mammedov {
1297a74b0d0aSPaolo Bonzini test_data data = {};
1298ac70b4a3SIgor Mammedov
1299ac70b4a3SIgor Mammedov data.machine = MACHINE_Q35;
1300d488c66bSSunil V L data.arch = "x86",
1301ac70b4a3SIgor Mammedov data.variant = ".ipmismbus";
1302ac70b4a3SIgor Mammedov data.required_struct_types = ipmi_required_struct_types;
1303ac70b4a3SIgor Mammedov data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
1304ac70b4a3SIgor Mammedov test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1305ac70b4a3SIgor Mammedov " -device smbus-ipmi,bmc=bmc0",
1306ac70b4a3SIgor Mammedov &data);
1307ac70b4a3SIgor Mammedov free_test_data(&data);
1308ac70b4a3SIgor Mammedov }
1309ac70b4a3SIgor Mammedov
test_acpi_piix4_tcg_ipmi(void)13101e8a1faeSThomas Huth static void test_acpi_piix4_tcg_ipmi(void)
13111e8a1faeSThomas Huth {
1312a74b0d0aSPaolo Bonzini test_data data = {};
13131e8a1faeSThomas Huth
13141e8a1faeSThomas Huth /* Supplying -machine accel argument overrides the default (qtest).
13151e8a1faeSThomas Huth * This is to make guest actually run.
13161e8a1faeSThomas Huth */
13171e8a1faeSThomas Huth data.machine = MACHINE_PC;
1318d488c66bSSunil V L data.arch = "x86";
13191e8a1faeSThomas Huth data.variant = ".ipmikcs";
13201e8a1faeSThomas Huth data.required_struct_types = ipmi_required_struct_types;
13211e8a1faeSThomas Huth data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
13221e8a1faeSThomas Huth test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
13231e8a1faeSThomas Huth " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
13241e8a1faeSThomas Huth &data);
13251e8a1faeSThomas Huth free_test_data(&data);
13261e8a1faeSThomas Huth }
13271e8a1faeSThomas Huth
test_acpi_q35_tcg_memhp(void)13281e8a1faeSThomas Huth static void test_acpi_q35_tcg_memhp(void)
13291e8a1faeSThomas Huth {
1330a74b0d0aSPaolo Bonzini test_data data = {};
13311e8a1faeSThomas Huth
13321e8a1faeSThomas Huth data.machine = MACHINE_Q35;
1333d488c66bSSunil V L data.arch = "x86",
13341e8a1faeSThomas Huth data.variant = ".memhp";
13351e8a1faeSThomas Huth test_acpi_one(" -m 128,slots=3,maxmem=1G"
13361e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=64M"
13371e8a1faeSThomas Huth " -object memory-backend-ram,id=ram1,size=64M"
13381e8a1faeSThomas Huth " -numa node,memdev=ram0 -numa node,memdev=ram1"
13391e8a1faeSThomas Huth " -numa dist,src=0,dst=1,val=21",
13401e8a1faeSThomas Huth &data);
13411e8a1faeSThomas Huth free_test_data(&data);
13421e8a1faeSThomas Huth }
13431e8a1faeSThomas Huth
test_acpi_piix4_tcg_memhp(void)13441e8a1faeSThomas Huth static void test_acpi_piix4_tcg_memhp(void)
13451e8a1faeSThomas Huth {
1346a74b0d0aSPaolo Bonzini test_data data = {};
13471e8a1faeSThomas Huth
13481e8a1faeSThomas Huth data.machine = MACHINE_PC;
1349d488c66bSSunil V L data.arch = "x86";
13501e8a1faeSThomas Huth data.variant = ".memhp";
13511e8a1faeSThomas Huth test_acpi_one(" -m 128,slots=3,maxmem=1G"
13521e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=64M"
13531e8a1faeSThomas Huth " -object memory-backend-ram,id=ram1,size=64M"
13541e8a1faeSThomas Huth " -numa node,memdev=ram0 -numa node,memdev=ram1"
13551e8a1faeSThomas Huth " -numa dist,src=0,dst=1,val=21",
13561e8a1faeSThomas Huth &data);
13571e8a1faeSThomas Huth free_test_data(&data);
13581e8a1faeSThomas Huth }
13591e8a1faeSThomas Huth
test_acpi_piix4_tcg_nosmm(void)13600dabb2e8SIsaku Yamahata static void test_acpi_piix4_tcg_nosmm(void)
13610dabb2e8SIsaku Yamahata {
1362a74b0d0aSPaolo Bonzini test_data data = {};
13630dabb2e8SIsaku Yamahata
13640dabb2e8SIsaku Yamahata data.machine = MACHINE_PC;
1365d488c66bSSunil V L data.arch = "x86";
13660dabb2e8SIsaku Yamahata data.variant = ".nosmm";
13670dabb2e8SIsaku Yamahata test_acpi_one("-machine smm=off", &data);
13680dabb2e8SIsaku Yamahata free_test_data(&data);
13690dabb2e8SIsaku Yamahata }
13700dabb2e8SIsaku Yamahata
test_acpi_piix4_tcg_smm_compat(void)13710dabb2e8SIsaku Yamahata static void test_acpi_piix4_tcg_smm_compat(void)
13720dabb2e8SIsaku Yamahata {
1373a74b0d0aSPaolo Bonzini test_data data = {};
13740dabb2e8SIsaku Yamahata
13750dabb2e8SIsaku Yamahata data.machine = MACHINE_PC;
1376d488c66bSSunil V L data.arch = "x86";
13770dabb2e8SIsaku Yamahata data.variant = ".smm-compat";
13780dabb2e8SIsaku Yamahata test_acpi_one("-global PIIX4_PM.smm-compat=on", &data);
13790dabb2e8SIsaku Yamahata free_test_data(&data);
13800dabb2e8SIsaku Yamahata }
13810dabb2e8SIsaku Yamahata
test_acpi_piix4_tcg_smm_compat_nosmm(void)13820dabb2e8SIsaku Yamahata static void test_acpi_piix4_tcg_smm_compat_nosmm(void)
13830dabb2e8SIsaku Yamahata {
1384a74b0d0aSPaolo Bonzini test_data data = {};
13850dabb2e8SIsaku Yamahata
13860dabb2e8SIsaku Yamahata data.machine = MACHINE_PC;
1387d488c66bSSunil V L data.arch = "x86";
13880dabb2e8SIsaku Yamahata data.variant = ".smm-compat-nosmm";
13890dabb2e8SIsaku Yamahata test_acpi_one("-global PIIX4_PM.smm-compat=on -machine smm=off", &data);
13900dabb2e8SIsaku Yamahata free_test_data(&data);
13910dabb2e8SIsaku Yamahata }
13920dabb2e8SIsaku Yamahata
test_acpi_piix4_tcg_nohpet(void)13939a70e043SIsaku Yamahata static void test_acpi_piix4_tcg_nohpet(void)
13949a70e043SIsaku Yamahata {
1395a74b0d0aSPaolo Bonzini test_data data = {};
13969a70e043SIsaku Yamahata
13979a70e043SIsaku Yamahata data.machine = MACHINE_PC;
1398d488c66bSSunil V L data.arch = "x86";
13999a2112f9SThomas Huth data.machine_param = ",hpet=off";
14009a70e043SIsaku Yamahata data.variant = ".nohpet";
14019a2112f9SThomas Huth test_acpi_one(NULL, &data);
14029a70e043SIsaku Yamahata free_test_data(&data);
14039a70e043SIsaku Yamahata }
14049a70e043SIsaku Yamahata
test_acpi_q35_tcg_numamem(void)14051e8a1faeSThomas Huth static void test_acpi_q35_tcg_numamem(void)
14061e8a1faeSThomas Huth {
1407a74b0d0aSPaolo Bonzini test_data data = {};
14081e8a1faeSThomas Huth
14091e8a1faeSThomas Huth data.machine = MACHINE_Q35;
1410d488c66bSSunil V L data.arch = "x86",
14111e8a1faeSThomas Huth data.variant = ".numamem";
14121e8a1faeSThomas Huth test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
14131e8a1faeSThomas Huth " -numa node -numa node,memdev=ram0", &data);
14141e8a1faeSThomas Huth free_test_data(&data);
14151e8a1faeSThomas Huth }
14161e8a1faeSThomas Huth
test_acpi_q35_kvm_xapic(void)141780a2f338SIgor Mammedov static void test_acpi_q35_kvm_xapic(void)
141880a2f338SIgor Mammedov {
1419a74b0d0aSPaolo Bonzini test_data data = {};
142080a2f338SIgor Mammedov
142180a2f338SIgor Mammedov data.machine = MACHINE_Q35;
1422d488c66bSSunil V L data.arch = "x86",
142380a2f338SIgor Mammedov data.variant = ".xapic";
142480a2f338SIgor Mammedov test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
142580a2f338SIgor Mammedov " -numa node -numa node,memdev=ram0"
142680a2f338SIgor Mammedov " -machine kernel-irqchip=on -smp 1,maxcpus=288", &data);
142780a2f338SIgor Mammedov free_test_data(&data);
142880a2f338SIgor Mammedov }
142980a2f338SIgor Mammedov
test_acpi_q35_tcg_nosmm(void)14300dabb2e8SIsaku Yamahata static void test_acpi_q35_tcg_nosmm(void)
14310dabb2e8SIsaku Yamahata {
1432a74b0d0aSPaolo Bonzini test_data data = {};
14330dabb2e8SIsaku Yamahata
14340dabb2e8SIsaku Yamahata data.machine = MACHINE_Q35;
1435d488c66bSSunil V L data.arch = "x86",
14360dabb2e8SIsaku Yamahata data.variant = ".nosmm";
14370dabb2e8SIsaku Yamahata test_acpi_one("-machine smm=off", &data);
14380dabb2e8SIsaku Yamahata free_test_data(&data);
14390dabb2e8SIsaku Yamahata }
14400dabb2e8SIsaku Yamahata
test_acpi_q35_tcg_smm_compat(void)14410dabb2e8SIsaku Yamahata static void test_acpi_q35_tcg_smm_compat(void)
14420dabb2e8SIsaku Yamahata {
1443a74b0d0aSPaolo Bonzini test_data data = {};
14440dabb2e8SIsaku Yamahata
14450dabb2e8SIsaku Yamahata data.machine = MACHINE_Q35;
1446d488c66bSSunil V L data.arch = "x86",
14470dabb2e8SIsaku Yamahata data.variant = ".smm-compat";
14480dabb2e8SIsaku Yamahata test_acpi_one("-global ICH9-LPC.smm-compat=on", &data);
14490dabb2e8SIsaku Yamahata free_test_data(&data);
14500dabb2e8SIsaku Yamahata }
14510dabb2e8SIsaku Yamahata
test_acpi_q35_tcg_smm_compat_nosmm(void)14520dabb2e8SIsaku Yamahata static void test_acpi_q35_tcg_smm_compat_nosmm(void)
14530dabb2e8SIsaku Yamahata {
1454a74b0d0aSPaolo Bonzini test_data data = {};
14550dabb2e8SIsaku Yamahata
14560dabb2e8SIsaku Yamahata data.machine = MACHINE_Q35;
1457d488c66bSSunil V L data.arch = "x86",
14580dabb2e8SIsaku Yamahata data.variant = ".smm-compat-nosmm";
14590dabb2e8SIsaku Yamahata test_acpi_one("-global ICH9-LPC.smm-compat=on -machine smm=off", &data);
14600dabb2e8SIsaku Yamahata free_test_data(&data);
14610dabb2e8SIsaku Yamahata }
14620dabb2e8SIsaku Yamahata
test_acpi_q35_tcg_nohpet(void)14639a70e043SIsaku Yamahata static void test_acpi_q35_tcg_nohpet(void)
14649a70e043SIsaku Yamahata {
1465a74b0d0aSPaolo Bonzini test_data data = {};
14669a70e043SIsaku Yamahata
14679a70e043SIsaku Yamahata data.machine = MACHINE_Q35;
1468d488c66bSSunil V L data.arch = "x86",
14699a2112f9SThomas Huth data.machine_param = ",hpet=off";
14709a70e043SIsaku Yamahata data.variant = ".nohpet";
14719a2112f9SThomas Huth test_acpi_one(NULL, &data);
14729a70e043SIsaku Yamahata free_test_data(&data);
14739a70e043SIsaku Yamahata }
14749a70e043SIsaku Yamahata
test_acpi_q35_kvm_dmar(void)14750ff92b6dSIgor Mammedov static void test_acpi_q35_kvm_dmar(void)
14760ff92b6dSIgor Mammedov {
1477a74b0d0aSPaolo Bonzini test_data data = {};
14780ff92b6dSIgor Mammedov
14790ff92b6dSIgor Mammedov data.machine = MACHINE_Q35;
1480d488c66bSSunil V L data.arch = "x86",
14810ff92b6dSIgor Mammedov data.variant = ".dmar";
14820ff92b6dSIgor Mammedov test_acpi_one("-machine kernel-irqchip=split -accel kvm"
14830ff92b6dSIgor Mammedov " -device intel-iommu,intremap=on,device-iotlb=on", &data);
14840ff92b6dSIgor Mammedov free_test_data(&data);
14850ff92b6dSIgor Mammedov }
14860ff92b6dSIgor Mammedov
test_acpi_q35_tcg_ivrs(void)1487a4c730cbSIgor Mammedov static void test_acpi_q35_tcg_ivrs(void)
1488a4c730cbSIgor Mammedov {
1489a74b0d0aSPaolo Bonzini test_data data = {};
1490a4c730cbSIgor Mammedov
1491a4c730cbSIgor Mammedov data.machine = MACHINE_Q35;
1492d488c66bSSunil V L data.arch = "x86",
1493a4c730cbSIgor Mammedov data.variant = ".ivrs";
1494a4c730cbSIgor Mammedov data.tcg_only = true,
1495a4c730cbSIgor Mammedov test_acpi_one(" -device amd-iommu", &data);
1496a4c730cbSIgor Mammedov free_test_data(&data);
1497a4c730cbSIgor Mammedov }
1498a4c730cbSIgor Mammedov
test_acpi_piix4_tcg_numamem(void)14991e8a1faeSThomas Huth static void test_acpi_piix4_tcg_numamem(void)
15001e8a1faeSThomas Huth {
1501a74b0d0aSPaolo Bonzini test_data data = {};
15021e8a1faeSThomas Huth
15031e8a1faeSThomas Huth data.machine = MACHINE_PC;
1504d488c66bSSunil V L data.arch = "x86";
15051e8a1faeSThomas Huth data.variant = ".numamem";
15061e8a1faeSThomas Huth test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
15071e8a1faeSThomas Huth " -numa node -numa node,memdev=ram0", &data);
15081e8a1faeSThomas Huth free_test_data(&data);
15091e8a1faeSThomas Huth }
15101e8a1faeSThomas Huth
15115da7c35eSEric Auger uint64_t tpm_tis_base_addr;
15125da7c35eSEric Auger
test_acpi_tcg_tpm(const char * machine,const char * arch,const char * tpm_if,uint64_t base,enum TPMVersion tpm_version)1513d488c66bSSunil V L static void test_acpi_tcg_tpm(const char *machine, const char *arch,
1514d488c66bSSunil V L const char *tpm_if, uint64_t base,
1515d488c66bSSunil V L enum TPMVersion tpm_version)
15165da7c35eSEric Auger {
15175da7c35eSEric Auger gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
15185da7c35eSEric Auger machine, tpm_if);
15195da7c35eSEric Auger char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
15209bd0e32aSStefan Berger TPMTestState test;
1521a74b0d0aSPaolo Bonzini test_data data = {};
15225da7c35eSEric Auger GThread *thread;
1523bf8443efSStefan Berger const char *suffix = tpm_version == TPM_VERSION_2_0 ? "tpm2" : "tpm12";
1524bf8443efSStefan Berger char *args, *variant = g_strdup_printf(".%s.%s", tpm_if, suffix);
15255da7c35eSEric Auger
15265da7c35eSEric Auger tpm_tis_base_addr = base;
15275da7c35eSEric Auger
15285da7c35eSEric Auger module_call_init(MODULE_INIT_QOM);
15295da7c35eSEric Auger
15305da7c35eSEric Auger test.addr = g_new0(SocketAddress, 1);
15315da7c35eSEric Auger test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
15325da7c35eSEric Auger test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
15335da7c35eSEric Auger g_mutex_init(&test.data_mutex);
15345da7c35eSEric Auger g_cond_init(&test.data_cond);
15355da7c35eSEric Auger test.data_cond_signal = false;
153609b20a14SStefan Berger test.tpm_version = tpm_version;
15375da7c35eSEric Auger
15385da7c35eSEric Auger thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
15395da7c35eSEric Auger tpm_emu_test_wait_cond(&test);
15405da7c35eSEric Auger
15415da7c35eSEric Auger data.machine = machine;
1542d488c66bSSunil V L data.arch = arch;
15435da7c35eSEric Auger data.variant = variant;
15445da7c35eSEric Auger
15455da7c35eSEric Auger args = g_strdup_printf(
15465da7c35eSEric Auger " -chardev socket,id=chr,path=%s"
15475da7c35eSEric Auger " -tpmdev emulator,id=dev,chardev=chr"
15485da7c35eSEric Auger " -device tpm-%s,tpmdev=dev",
15495da7c35eSEric Auger test.addr->u.q_unix.path, tpm_if);
15505da7c35eSEric Auger
15515da7c35eSEric Auger test_acpi_one(args, &data);
15525da7c35eSEric Auger
15535da7c35eSEric Auger g_thread_join(thread);
15545da7c35eSEric Auger g_unlink(test.addr->u.q_unix.path);
15555da7c35eSEric Auger qapi_free_SocketAddress(test.addr);
15565da7c35eSEric Auger g_rmdir(tmp_path);
15575da7c35eSEric Auger g_free(variant);
15585da7c35eSEric Auger g_free(tmp_path);
15595da7c35eSEric Auger g_free(tmp_dir_name);
156082e258dbSLi Qiang g_free(args);
15615da7c35eSEric Auger free_test_data(&data);
15625da7c35eSEric Auger }
15635da7c35eSEric Auger
test_acpi_q35_tcg_tpm2_tis(void)156433660128SStefan Berger static void test_acpi_q35_tcg_tpm2_tis(void)
15655da7c35eSEric Auger {
1566d488c66bSSunil V L test_acpi_tcg_tpm("q35", "x86", "tis", 0xFED40000, TPM_VERSION_2_0);
15675da7c35eSEric Auger }
15685da7c35eSEric Auger
test_acpi_q35_tcg_tpm12_tis(void)156933660128SStefan Berger static void test_acpi_q35_tcg_tpm12_tis(void)
157033660128SStefan Berger {
1571d488c66bSSunil V L test_acpi_tcg_tpm("q35", "x86", "tis", 0xFED40000, TPM_VERSION_1_2);
157233660128SStefan Berger }
157333660128SStefan Berger
test_acpi_tcg_dimm_pxm(const char * machine,const char * arch)1574d488c66bSSunil V L static void test_acpi_tcg_dimm_pxm(const char *machine, const char *arch)
15751e8a1faeSThomas Huth {
1576a74b0d0aSPaolo Bonzini test_data data = {};
15771e8a1faeSThomas Huth
15781e8a1faeSThomas Huth data.machine = machine;
1579d488c66bSSunil V L data.arch = arch;
15801e8a1faeSThomas Huth data.variant = ".dimmpxm";
15811e8a1faeSThomas Huth test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
15821e8a1faeSThomas Huth " -smp 4,sockets=4"
15831e8a1faeSThomas Huth " -m 128M,slots=3,maxmem=1G"
15841e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=32M"
15851e8a1faeSThomas Huth " -object memory-backend-ram,id=ram1,size=32M"
15861e8a1faeSThomas Huth " -object memory-backend-ram,id=ram2,size=32M"
15871e8a1faeSThomas Huth " -object memory-backend-ram,id=ram3,size=32M"
15881e8a1faeSThomas Huth " -numa node,memdev=ram0,nodeid=0"
15891e8a1faeSThomas Huth " -numa node,memdev=ram1,nodeid=1"
15901e8a1faeSThomas Huth " -numa node,memdev=ram2,nodeid=2"
15911e8a1faeSThomas Huth " -numa node,memdev=ram3,nodeid=3"
15921e8a1faeSThomas Huth " -numa cpu,node-id=0,socket-id=0"
15931e8a1faeSThomas Huth " -numa cpu,node-id=1,socket-id=1"
15941e8a1faeSThomas Huth " -numa cpu,node-id=2,socket-id=2"
15951e8a1faeSThomas Huth " -numa cpu,node-id=3,socket-id=3"
15961e8a1faeSThomas Huth " -object memory-backend-ram,id=ram4,size=128M"
15971e8a1faeSThomas Huth " -object memory-backend-ram,id=nvm0,size=128M"
15981e8a1faeSThomas Huth " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
15991e8a1faeSThomas Huth " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
16001e8a1faeSThomas Huth &data);
16011e8a1faeSThomas Huth free_test_data(&data);
16021e8a1faeSThomas Huth }
16031e8a1faeSThomas Huth
test_acpi_q35_tcg_dimm_pxm(void)16041e8a1faeSThomas Huth static void test_acpi_q35_tcg_dimm_pxm(void)
16051e8a1faeSThomas Huth {
1606d488c66bSSunil V L test_acpi_tcg_dimm_pxm(MACHINE_Q35, "x86");
16071e8a1faeSThomas Huth }
16081e8a1faeSThomas Huth
test_acpi_piix4_tcg_dimm_pxm(void)16091e8a1faeSThomas Huth static void test_acpi_piix4_tcg_dimm_pxm(void)
16101e8a1faeSThomas Huth {
1611d488c66bSSunil V L test_acpi_tcg_dimm_pxm(MACHINE_PC, "x86");
16121e8a1faeSThomas Huth }
16131e8a1faeSThomas Huth
test_acpi_aarch64_virt_tcg_memhp(void)16142fd69da2SSunil V L static void test_acpi_aarch64_virt_tcg_memhp(void)
16151e8a1faeSThomas Huth {
16161e8a1faeSThomas Huth test_data data = {
16171e8a1faeSThomas Huth .machine = "virt",
1618193e4b90SSunil V L .arch = "aarch64",
16191e8a1faeSThomas Huth .tcg_only = true,
16201e8a1faeSThomas Huth .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
16211e8a1faeSThomas Huth .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
16221e8a1faeSThomas Huth .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
16231e8a1faeSThomas Huth .ram_start = 0x40000000ULL,
16241e8a1faeSThomas Huth .scan_len = 256ULL * 1024 * 1024,
16251e8a1faeSThomas Huth };
16261e8a1faeSThomas Huth
16271e8a1faeSThomas Huth data.variant = ".memhp";
162862293b4fSShameer Kolothum test_acpi_one(" -machine nvdimm=on"
162962293b4fSShameer Kolothum " -cpu cortex-a57"
16301e8a1faeSThomas Huth " -m 256M,slots=3,maxmem=1G"
16311e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=128M"
16321e8a1faeSThomas Huth " -object memory-backend-ram,id=ram1,size=128M"
16331e8a1faeSThomas Huth " -numa node,memdev=ram0 -numa node,memdev=ram1"
163462293b4fSShameer Kolothum " -numa dist,src=0,dst=1,val=21"
163562293b4fSShameer Kolothum " -object memory-backend-ram,id=ram2,size=128M"
163662293b4fSShameer Kolothum " -object memory-backend-ram,id=nvm0,size=128M"
163762293b4fSShameer Kolothum " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
163862293b4fSShameer Kolothum " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
16391e8a1faeSThomas Huth &data);
16407cb23078SIgor Mammedov
16411e8a1faeSThomas Huth free_test_data(&data);
16421e8a1faeSThomas Huth
16431e8a1faeSThomas Huth }
16441e8a1faeSThomas Huth
test_acpi_microvm_prepare(test_data * data)164562b61b85SGerd Hoffmann static void test_acpi_microvm_prepare(test_data *data)
164662b61b85SGerd Hoffmann {
164762b61b85SGerd Hoffmann data->machine = "microvm";
1648d488c66bSSunil V L data->arch = "x86";
164962b61b85SGerd Hoffmann data->required_struct_types = NULL; /* no smbios */
165062b61b85SGerd Hoffmann data->required_struct_types_len = 0;
165162b61b85SGerd Hoffmann data->blkdev = "virtio-blk-device";
165262b61b85SGerd Hoffmann }
165362b61b85SGerd Hoffmann
test_acpi_microvm_tcg(void)1654c06cbf3dSGerd Hoffmann static void test_acpi_microvm_tcg(void)
1655c06cbf3dSGerd Hoffmann {
1656a74b0d0aSPaolo Bonzini test_data data = {};
1657c06cbf3dSGerd Hoffmann
165862b61b85SGerd Hoffmann test_acpi_microvm_prepare(&data);
16594d01b899SGerd Hoffmann test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off",
1660c06cbf3dSGerd Hoffmann &data);
1661c06cbf3dSGerd Hoffmann free_test_data(&data);
1662c06cbf3dSGerd Hoffmann }
1663c06cbf3dSGerd Hoffmann
test_acpi_microvm_usb_tcg(void)1664f072fd2fSGerd Hoffmann static void test_acpi_microvm_usb_tcg(void)
1665f072fd2fSGerd Hoffmann {
1666a74b0d0aSPaolo Bonzini test_data data = {};
1667f072fd2fSGerd Hoffmann
1668f072fd2fSGerd Hoffmann test_acpi_microvm_prepare(&data);
1669f072fd2fSGerd Hoffmann data.variant = ".usb";
16704d01b899SGerd Hoffmann test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off",
1671f072fd2fSGerd Hoffmann &data);
1672f072fd2fSGerd Hoffmann free_test_data(&data);
1673f072fd2fSGerd Hoffmann }
1674f072fd2fSGerd Hoffmann
test_acpi_microvm_rtc_tcg(void)16750c491c84SGerd Hoffmann static void test_acpi_microvm_rtc_tcg(void)
16760c491c84SGerd Hoffmann {
1677a74b0d0aSPaolo Bonzini test_data data = {};
16780c491c84SGerd Hoffmann
16790c491c84SGerd Hoffmann test_acpi_microvm_prepare(&data);
16800c491c84SGerd Hoffmann data.variant = ".rtc";
16814d01b899SGerd Hoffmann test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on",
16820c491c84SGerd Hoffmann &data);
16830c491c84SGerd Hoffmann free_test_data(&data);
16840c491c84SGerd Hoffmann }
16850c491c84SGerd Hoffmann
test_acpi_microvm_pcie_tcg(void)168618bb73b3SGerd Hoffmann static void test_acpi_microvm_pcie_tcg(void)
168718bb73b3SGerd Hoffmann {
1688a74b0d0aSPaolo Bonzini test_data data = {};
168918bb73b3SGerd Hoffmann
169018bb73b3SGerd Hoffmann test_acpi_microvm_prepare(&data);
169118bb73b3SGerd Hoffmann data.variant = ".pcie";
169218bb73b3SGerd Hoffmann data.tcg_only = true; /* need constant host-phys-bits */
16934d01b899SGerd Hoffmann test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on",
169418bb73b3SGerd Hoffmann &data);
169518bb73b3SGerd Hoffmann free_test_data(&data);
169618bb73b3SGerd Hoffmann }
169718bb73b3SGerd Hoffmann
test_acpi_microvm_ioapic2_tcg(void)169838ee397fSGerd Hoffmann static void test_acpi_microvm_ioapic2_tcg(void)
169938ee397fSGerd Hoffmann {
1700a74b0d0aSPaolo Bonzini test_data data = {};
170138ee397fSGerd Hoffmann
170238ee397fSGerd Hoffmann test_acpi_microvm_prepare(&data);
170338ee397fSGerd Hoffmann data.variant = ".ioapic2";
170438ee397fSGerd Hoffmann test_acpi_one(" -machine microvm,acpi=on,ioapic2=on,rtc=off",
170538ee397fSGerd Hoffmann &data);
170638ee397fSGerd Hoffmann free_test_data(&data);
170738ee397fSGerd Hoffmann }
170838ee397fSGerd Hoffmann
test_acpi_riscv64_virt_tcg_numamem(void)17095fd9c51dSHaibo Xu static void test_acpi_riscv64_virt_tcg_numamem(void)
17105fd9c51dSHaibo Xu {
17115fd9c51dSHaibo Xu test_data data = {
17125fd9c51dSHaibo Xu .machine = "virt",
17135fd9c51dSHaibo Xu .arch = "riscv64",
17145fd9c51dSHaibo Xu .tcg_only = true,
17155fd9c51dSHaibo Xu .uefi_fl1 = "pc-bios/edk2-riscv-code.fd",
17165fd9c51dSHaibo Xu .uefi_fl2 = "pc-bios/edk2-riscv-vars.fd",
17175fd9c51dSHaibo Xu .cd = "tests/data/uefi-boot-images/bios-tables-test.riscv64.iso.qcow2",
17185fd9c51dSHaibo Xu .ram_start = 0x80000000ULL,
17195fd9c51dSHaibo Xu .scan_len = 128ULL * 1024 * 1024,
17205fd9c51dSHaibo Xu };
17215fd9c51dSHaibo Xu
17225fd9c51dSHaibo Xu data.variant = ".numamem";
17235fd9c51dSHaibo Xu /*
17245fd9c51dSHaibo Xu * RHCT will have ISA string encoded. To reduce the effort
17255fd9c51dSHaibo Xu * of updating expected AML file for any new default ISA extension,
17265fd9c51dSHaibo Xu * use the profile rva22s64.
17275fd9c51dSHaibo Xu */
17285fd9c51dSHaibo Xu test_acpi_one(" -cpu rva22s64"
17295fd9c51dSHaibo Xu " -object memory-backend-ram,id=ram0,size=128M"
17305fd9c51dSHaibo Xu " -numa node,memdev=ram0",
17315fd9c51dSHaibo Xu &data);
17325fd9c51dSHaibo Xu free_test_data(&data);
17335fd9c51dSHaibo Xu }
17345fd9c51dSHaibo Xu
test_acpi_aarch64_virt_tcg_numamem(void)17352fd69da2SSunil V L static void test_acpi_aarch64_virt_tcg_numamem(void)
17361e8a1faeSThomas Huth {
17371e8a1faeSThomas Huth test_data data = {
17381e8a1faeSThomas Huth .machine = "virt",
1739193e4b90SSunil V L .arch = "aarch64",
17401e8a1faeSThomas Huth .tcg_only = true,
17411e8a1faeSThomas Huth .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
17421e8a1faeSThomas Huth .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
17431e8a1faeSThomas Huth .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
17441e8a1faeSThomas Huth .ram_start = 0x40000000ULL,
17451e8a1faeSThomas Huth .scan_len = 128ULL * 1024 * 1024,
17461e8a1faeSThomas Huth };
17471e8a1faeSThomas Huth
17481e8a1faeSThomas Huth data.variant = ".numamem";
17491e8a1faeSThomas Huth test_acpi_one(" -cpu cortex-a57"
17501e8a1faeSThomas Huth " -object memory-backend-ram,id=ram0,size=128M"
17511e8a1faeSThomas Huth " -numa node,memdev=ram0",
17521e8a1faeSThomas Huth &data);
17531e8a1faeSThomas Huth
17541e8a1faeSThomas Huth free_test_data(&data);
17551e8a1faeSThomas Huth
17561e8a1faeSThomas Huth }
17571e8a1faeSThomas Huth
test_acpi_aarch64_virt_tcg_pxb(void)17582fd69da2SSunil V L static void test_acpi_aarch64_virt_tcg_pxb(void)
17591da638b1SYubo Miao {
17601da638b1SYubo Miao test_data data = {
17611da638b1SYubo Miao .machine = "virt",
1762193e4b90SSunil V L .arch = "aarch64",
17631da638b1SYubo Miao .tcg_only = true,
17641da638b1SYubo Miao .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
17651da638b1SYubo Miao .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
17661da638b1SYubo Miao .ram_start = 0x40000000ULL,
17671da638b1SYubo Miao .scan_len = 128ULL * 1024 * 1024,
17681da638b1SYubo Miao };
17691da638b1SYubo Miao /*
17701da638b1SYubo Miao * While using -cdrom, the cdrom would auto plugged into pxb-pcie,
17711da638b1SYubo Miao * the reason is the bus of pxb-pcie is also root bus, it would lead
17721da638b1SYubo Miao * to the error only PCI/PCIE bridge could plug onto pxb.
17731da638b1SYubo Miao * Therefore,thr cdrom is defined and plugged onto the scsi controller
17741da638b1SYubo Miao * to solve the conflicts.
17751da638b1SYubo Miao */
17761da638b1SYubo Miao data.variant = ".pxb";
17771da638b1SYubo Miao test_acpi_one(" -device pcie-root-port,chassis=1,id=pci.1"
17781da638b1SYubo Miao " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
17791da638b1SYubo Miao " -drive file="
17801da638b1SYubo Miao "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2,"
17811da638b1SYubo Miao "if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on"
17821da638b1SYubo Miao " -device scsi-cd,bus=scsi0.0,scsi-id=0,"
17831da638b1SYubo Miao "drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1"
17841da638b1SYubo Miao " -cpu cortex-a57"
17851da638b1SYubo Miao " -device pxb-pcie,bus_nr=128",
17861da638b1SYubo Miao &data);
17877cb23078SIgor Mammedov
17881da638b1SYubo Miao free_test_data(&data);
17891da638b1SYubo Miao }
17901da638b1SYubo Miao
test_acpi_tcg_acpi_hmat(const char * machine,const char * arch)1791d488c66bSSunil V L static void test_acpi_tcg_acpi_hmat(const char *machine, const char *arch)
17921e8a1faeSThomas Huth {
1793a74b0d0aSPaolo Bonzini test_data data = {};
17941e8a1faeSThomas Huth
17951e8a1faeSThomas Huth data.machine = machine;
1796d488c66bSSunil V L data.arch = arch;
17971e8a1faeSThomas Huth data.variant = ".acpihmat";
17981e8a1faeSThomas Huth test_acpi_one(" -machine hmat=on"
17991e8a1faeSThomas Huth " -smp 2,sockets=2"
18001e8a1faeSThomas Huth " -m 128M,slots=2,maxmem=1G"
18011e8a1faeSThomas Huth " -object memory-backend-ram,size=64M,id=m0"
18021e8a1faeSThomas Huth " -object memory-backend-ram,size=64M,id=m1"
18031e8a1faeSThomas Huth " -numa node,nodeid=0,memdev=m0"
18041e8a1faeSThomas Huth " -numa node,nodeid=1,memdev=m1,initiator=0"
18051e8a1faeSThomas Huth " -numa cpu,node-id=0,socket-id=0"
18061e8a1faeSThomas Huth " -numa cpu,node-id=0,socket-id=1"
18071e8a1faeSThomas Huth " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
18081e8a1faeSThomas Huth "data-type=access-latency,latency=1"
18091e8a1faeSThomas Huth " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
18101e8a1faeSThomas Huth "data-type=access-bandwidth,bandwidth=65534M"
18111e8a1faeSThomas Huth " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
18121e8a1faeSThomas Huth "data-type=access-latency,latency=65534"
18131e8a1faeSThomas Huth " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
18141e8a1faeSThomas Huth "data-type=access-bandwidth,bandwidth=32767M"
18151e8a1faeSThomas Huth " -numa hmat-cache,node-id=0,size=10K,level=1,"
18161e8a1faeSThomas Huth "associativity=direct,policy=write-back,line=8"
18171e8a1faeSThomas Huth " -numa hmat-cache,node-id=1,size=10K,level=1,"
18181e8a1faeSThomas Huth "associativity=direct,policy=write-back,line=8",
18191e8a1faeSThomas Huth &data);
18201e8a1faeSThomas Huth free_test_data(&data);
18211e8a1faeSThomas Huth }
18221e8a1faeSThomas Huth
test_acpi_q35_tcg_acpi_hmat(void)18231e8a1faeSThomas Huth static void test_acpi_q35_tcg_acpi_hmat(void)
18241e8a1faeSThomas Huth {
1825d488c66bSSunil V L test_acpi_tcg_acpi_hmat(MACHINE_Q35, "x86");
18261e8a1faeSThomas Huth }
18271e8a1faeSThomas Huth
test_acpi_piix4_tcg_acpi_hmat(void)18281e8a1faeSThomas Huth static void test_acpi_piix4_tcg_acpi_hmat(void)
18291e8a1faeSThomas Huth {
1830d488c66bSSunil V L test_acpi_tcg_acpi_hmat(MACHINE_PC, "x86");
18311e8a1faeSThomas Huth }
18321e8a1faeSThomas Huth
test_acpi_aarch64_virt_tcg_acpi_hmat(void)18332fd69da2SSunil V L static void test_acpi_aarch64_virt_tcg_acpi_hmat(void)
1834b077b070SHesham Almatary {
1835b077b070SHesham Almatary test_data data = {
1836b077b070SHesham Almatary .machine = "virt",
1837193e4b90SSunil V L .arch = "aarch64",
1838b077b070SHesham Almatary .tcg_only = true,
1839b077b070SHesham Almatary .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1840b077b070SHesham Almatary .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1841b077b070SHesham Almatary .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1842b077b070SHesham Almatary .ram_start = 0x40000000ULL,
1843b077b070SHesham Almatary .scan_len = 128ULL * 1024 * 1024,
1844b077b070SHesham Almatary };
1845b077b070SHesham Almatary
1846b077b070SHesham Almatary data.variant = ".acpihmatvirt";
1847b077b070SHesham Almatary
1848b077b070SHesham Almatary test_acpi_one(" -machine hmat=on"
1849b077b070SHesham Almatary " -cpu cortex-a57"
1850b077b070SHesham Almatary " -smp 4,sockets=2"
1851e8d1e0cdSGerd Hoffmann " -m 384M"
1852e8d1e0cdSGerd Hoffmann " -object memory-backend-ram,size=128M,id=ram0"
1853e8d1e0cdSGerd Hoffmann " -object memory-backend-ram,size=128M,id=ram1"
1854b077b070SHesham Almatary " -object memory-backend-ram,size=128M,id=ram2"
1855b077b070SHesham Almatary " -numa node,nodeid=0,memdev=ram0"
1856b077b070SHesham Almatary " -numa node,nodeid=1,memdev=ram1"
1857b077b070SHesham Almatary " -numa node,nodeid=2,memdev=ram2"
1858b077b070SHesham Almatary " -numa cpu,node-id=0,socket-id=0"
1859b077b070SHesham Almatary " -numa cpu,node-id=0,socket-id=0"
1860b077b070SHesham Almatary " -numa cpu,node-id=1,socket-id=1"
1861b077b070SHesham Almatary " -numa cpu,node-id=1,socket-id=1"
1862b077b070SHesham Almatary " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1863b077b070SHesham Almatary "data-type=access-latency,latency=10"
1864b077b070SHesham Almatary " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1865b077b070SHesham Almatary "data-type=access-bandwidth,bandwidth=10485760"
1866b077b070SHesham Almatary " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1867b077b070SHesham Almatary "data-type=access-latency,latency=20"
1868b077b070SHesham Almatary " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1869b077b070SHesham Almatary "data-type=access-bandwidth,bandwidth=5242880"
1870b077b070SHesham Almatary " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1871b077b070SHesham Almatary "data-type=access-latency,latency=30"
1872b077b070SHesham Almatary " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1873b077b070SHesham Almatary "data-type=access-bandwidth,bandwidth=1048576"
1874b077b070SHesham Almatary " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1875b077b070SHesham Almatary "data-type=access-latency,latency=20"
1876b077b070SHesham Almatary " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1877b077b070SHesham Almatary "data-type=access-bandwidth,bandwidth=5242880"
1878b077b070SHesham Almatary " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1879b077b070SHesham Almatary "data-type=access-latency,latency=10"
1880b077b070SHesham Almatary " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1881b077b070SHesham Almatary "data-type=access-bandwidth,bandwidth=10485760"
1882b077b070SHesham Almatary " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1883b077b070SHesham Almatary "data-type=access-latency,latency=30"
1884b077b070SHesham Almatary " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1885b077b070SHesham Almatary "data-type=access-bandwidth,bandwidth=1048576",
1886b077b070SHesham Almatary &data);
1887b077b070SHesham Almatary
1888b077b070SHesham Almatary free_test_data(&data);
1889b077b070SHesham Almatary }
1890b077b070SHesham Almatary
test_acpi_q35_tcg_acpi_hmat_noinitiator(void)1891a046f1d7SBrice Goglin static void test_acpi_q35_tcg_acpi_hmat_noinitiator(void)
1892a046f1d7SBrice Goglin {
1893a74b0d0aSPaolo Bonzini test_data data = {};
1894a046f1d7SBrice Goglin
1895a046f1d7SBrice Goglin data.machine = MACHINE_Q35;
1896d488c66bSSunil V L data.arch = "x86";
1897a046f1d7SBrice Goglin data.variant = ".acpihmat-noinitiator";
1898a046f1d7SBrice Goglin test_acpi_one(" -machine hmat=on"
1899a046f1d7SBrice Goglin " -smp 4,sockets=2"
1900a046f1d7SBrice Goglin " -m 128M"
1901a046f1d7SBrice Goglin " -object memory-backend-ram,size=32M,id=ram0"
1902a046f1d7SBrice Goglin " -object memory-backend-ram,size=32M,id=ram1"
1903a046f1d7SBrice Goglin " -object memory-backend-ram,size=64M,id=ram2"
1904a046f1d7SBrice Goglin " -numa node,nodeid=0,memdev=ram0"
1905a046f1d7SBrice Goglin " -numa node,nodeid=1,memdev=ram1"
1906a046f1d7SBrice Goglin " -numa node,nodeid=2,memdev=ram2"
1907a046f1d7SBrice Goglin " -numa cpu,node-id=0,socket-id=0"
1908a046f1d7SBrice Goglin " -numa cpu,node-id=0,socket-id=0"
1909a046f1d7SBrice Goglin " -numa cpu,node-id=1,socket-id=1"
1910a046f1d7SBrice Goglin " -numa cpu,node-id=1,socket-id=1"
1911a046f1d7SBrice Goglin " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1912a046f1d7SBrice Goglin "data-type=access-latency,latency=10"
1913a046f1d7SBrice Goglin " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1914a046f1d7SBrice Goglin "data-type=access-bandwidth,bandwidth=10485760"
1915a046f1d7SBrice Goglin " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1916a046f1d7SBrice Goglin "data-type=access-latency,latency=20"
1917a046f1d7SBrice Goglin " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1918a046f1d7SBrice Goglin "data-type=access-bandwidth,bandwidth=5242880"
1919a046f1d7SBrice Goglin " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1920a046f1d7SBrice Goglin "data-type=access-latency,latency=30"
1921a046f1d7SBrice Goglin " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1922a046f1d7SBrice Goglin "data-type=access-bandwidth,bandwidth=1048576"
1923a046f1d7SBrice Goglin " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1924a046f1d7SBrice Goglin "data-type=access-latency,latency=20"
1925a046f1d7SBrice Goglin " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1926a046f1d7SBrice Goglin "data-type=access-bandwidth,bandwidth=5242880"
1927a046f1d7SBrice Goglin " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1928a046f1d7SBrice Goglin "data-type=access-latency,latency=10"
1929a046f1d7SBrice Goglin " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1930a046f1d7SBrice Goglin "data-type=access-bandwidth,bandwidth=10485760"
1931a046f1d7SBrice Goglin " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1932a046f1d7SBrice Goglin "data-type=access-latency,latency=30"
1933a046f1d7SBrice Goglin " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1934a046f1d7SBrice Goglin "data-type=access-bandwidth,bandwidth=1048576",
1935a046f1d7SBrice Goglin &data);
1936a046f1d7SBrice Goglin free_test_data(&data);
1937a046f1d7SBrice Goglin }
1938a046f1d7SBrice Goglin
1939*18afed74SJonathan Cameron /* Test intended to hit corner cases of SRAT and HMAT */
test_acpi_q35_tcg_acpi_hmat_generic_x(void)1940*18afed74SJonathan Cameron static void test_acpi_q35_tcg_acpi_hmat_generic_x(void)
1941*18afed74SJonathan Cameron {
1942*18afed74SJonathan Cameron test_data data = {};
1943*18afed74SJonathan Cameron
1944*18afed74SJonathan Cameron data.machine = MACHINE_Q35;
1945*18afed74SJonathan Cameron data.arch = "x86";
1946*18afed74SJonathan Cameron data.variant = ".acpihmat-generic-x";
1947*18afed74SJonathan Cameron test_acpi_one(" -machine hmat=on,cxl=on"
1948*18afed74SJonathan Cameron " -smp 3,sockets=3"
1949*18afed74SJonathan Cameron " -m 128M,maxmem=384M,slots=2"
1950*18afed74SJonathan Cameron " -device pcie-root-port,chassis=1,id=pci.1"
1951*18afed74SJonathan Cameron " -device pci-testdev,bus=pci.1,"
1952*18afed74SJonathan Cameron "multifunction=on,addr=00.0"
1953*18afed74SJonathan Cameron " -device pci-testdev,bus=pci.1,addr=00.1"
1954*18afed74SJonathan Cameron " -device pci-testdev,bus=pci.1,id=gidev,addr=00.2"
1955*18afed74SJonathan Cameron " -device pxb-cxl,bus_nr=64,bus=pcie.0,id=cxl.1"
1956*18afed74SJonathan Cameron " -object memory-backend-ram,size=64M,id=ram0"
1957*18afed74SJonathan Cameron " -object memory-backend-ram,size=64M,id=ram1"
1958*18afed74SJonathan Cameron " -numa node,nodeid=0,cpus=0,memdev=ram0"
1959*18afed74SJonathan Cameron " -numa node,nodeid=1"
1960*18afed74SJonathan Cameron " -object acpi-generic-initiator,id=gi0,pci-dev=gidev,node=1"
1961*18afed74SJonathan Cameron " -numa node,nodeid=2"
1962*18afed74SJonathan Cameron " -object acpi-generic-port,id=gp0,pci-bus=cxl.1,node=2"
1963*18afed74SJonathan Cameron " -numa node,nodeid=3,cpus=1"
1964*18afed74SJonathan Cameron " -numa node,nodeid=4,memdev=ram1"
1965*18afed74SJonathan Cameron " -numa node,nodeid=5,cpus=2"
1966*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1967*18afed74SJonathan Cameron "data-type=access-latency,latency=10"
1968*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1969*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=800M"
1970*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1971*18afed74SJonathan Cameron "data-type=access-latency,latency=100"
1972*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1973*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=200M"
1974*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=4,hierarchy=memory,"
1975*18afed74SJonathan Cameron "data-type=access-latency,latency=100"
1976*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=4,hierarchy=memory,"
1977*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=200M"
1978*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=5,hierarchy=memory,"
1979*18afed74SJonathan Cameron "data-type=access-latency,latency=200"
1980*18afed74SJonathan Cameron " -numa hmat-lb,initiator=0,target=5,hierarchy=memory,"
1981*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=400M"
1982*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1983*18afed74SJonathan Cameron "data-type=access-latency,latency=500"
1984*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1985*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=100M"
1986*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1987*18afed74SJonathan Cameron "data-type=access-latency,latency=50"
1988*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1989*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=400M"
1990*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=4,hierarchy=memory,"
1991*18afed74SJonathan Cameron "data-type=access-latency,latency=50"
1992*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=4,hierarchy=memory,"
1993*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=800M"
1994*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=5,hierarchy=memory,"
1995*18afed74SJonathan Cameron "data-type=access-latency,latency=500"
1996*18afed74SJonathan Cameron " -numa hmat-lb,initiator=1,target=5,hierarchy=memory,"
1997*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=100M"
1998*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=0,hierarchy=memory,"
1999*18afed74SJonathan Cameron "data-type=access-latency,latency=20"
2000*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=0,hierarchy=memory,"
2001*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=400M"
2002*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=2,hierarchy=memory,"
2003*18afed74SJonathan Cameron "data-type=access-latency,latency=80"
2004*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=2,hierarchy=memory,"
2005*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=200M"
2006*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=4,hierarchy=memory,"
2007*18afed74SJonathan Cameron "data-type=access-latency,latency=80"
2008*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=4,hierarchy=memory,"
2009*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=200M"
2010*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=5,hierarchy=memory,"
2011*18afed74SJonathan Cameron "data-type=access-latency,latency=20"
2012*18afed74SJonathan Cameron " -numa hmat-lb,initiator=3,target=5,hierarchy=memory,"
2013*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=400M"
2014*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=0,hierarchy=memory,"
2015*18afed74SJonathan Cameron "data-type=access-latency,latency=20"
2016*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=0,hierarchy=memory,"
2017*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=400M"
2018*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=2,hierarchy=memory,"
2019*18afed74SJonathan Cameron "data-type=access-latency,latency=80"
2020*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=4,hierarchy=memory,"
2021*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=200M"
2022*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=4,hierarchy=memory,"
2023*18afed74SJonathan Cameron "data-type=access-latency,latency=80"
2024*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=2,hierarchy=memory,"
2025*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=200M"
2026*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=5,hierarchy=memory,"
2027*18afed74SJonathan Cameron "data-type=access-latency,latency=10"
2028*18afed74SJonathan Cameron " -numa hmat-lb,initiator=5,target=5,hierarchy=memory,"
2029*18afed74SJonathan Cameron "data-type=access-bandwidth,bandwidth=800M",
2030*18afed74SJonathan Cameron &data);
2031*18afed74SJonathan Cameron free_test_data(&data);
2032*18afed74SJonathan Cameron }
2033*18afed74SJonathan Cameron
203484efa8aaSBin Meng #ifdef CONFIG_POSIX
test_acpi_erst(const char * machine,const char * arch)2035d488c66bSSunil V L static void test_acpi_erst(const char *machine, const char *arch)
2036646a793cSEric DeVolder {
2037646a793cSEric DeVolder gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
2038646a793cSEric DeVolder gchar *params;
2039a74b0d0aSPaolo Bonzini test_data data = {};
2040646a793cSEric DeVolder
2041646a793cSEric DeVolder data.machine = machine;
2042d488c66bSSunil V L data.arch = arch;
2043646a793cSEric DeVolder data.variant = ".acpierst";
2044646a793cSEric DeVolder params = g_strdup_printf(
2045646a793cSEric DeVolder " -object memory-backend-file,id=erstnvram,"
2046646a793cSEric DeVolder "mem-path=%s,size=0x10000,share=on"
2047646a793cSEric DeVolder " -device acpi-erst,memdev=erstnvram", tmp_path);
2048646a793cSEric DeVolder test_acpi_one(params, &data);
2049646a793cSEric DeVolder free_test_data(&data);
2050646a793cSEric DeVolder g_free(params);
2051646a793cSEric DeVolder g_assert(g_rmdir(tmp_path) == 0);
2052646a793cSEric DeVolder g_free(tmp_path);
2053646a793cSEric DeVolder }
2054646a793cSEric DeVolder
test_acpi_piix4_acpi_erst(void)2055646a793cSEric DeVolder static void test_acpi_piix4_acpi_erst(void)
2056646a793cSEric DeVolder {
2057d488c66bSSunil V L test_acpi_erst(MACHINE_PC, "x86");
2058646a793cSEric DeVolder }
2059646a793cSEric DeVolder
test_acpi_q35_acpi_erst(void)2060646a793cSEric DeVolder static void test_acpi_q35_acpi_erst(void)
2061646a793cSEric DeVolder {
2062d488c66bSSunil V L test_acpi_erst(MACHINE_Q35, "x86");
2063646a793cSEric DeVolder }
2064646a793cSEric DeVolder
test_acpi_microvm_acpi_erst(void)2065646a793cSEric DeVolder static void test_acpi_microvm_acpi_erst(void)
2066646a793cSEric DeVolder {
2067646a793cSEric DeVolder gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
2068646a793cSEric DeVolder gchar *params;
2069a74b0d0aSPaolo Bonzini test_data data = {};
2070646a793cSEric DeVolder
2071646a793cSEric DeVolder test_acpi_microvm_prepare(&data);
2072646a793cSEric DeVolder data.variant = ".pcie";
2073646a793cSEric DeVolder data.tcg_only = true; /* need constant host-phys-bits */
2074646a793cSEric DeVolder params = g_strdup_printf(" -machine microvm,"
2075646a793cSEric DeVolder "acpi=on,ioapic2=off,rtc=off,pcie=on"
2076646a793cSEric DeVolder " -object memory-backend-file,id=erstnvram,"
2077646a793cSEric DeVolder "mem-path=%s,size=0x10000,share=on"
2078646a793cSEric DeVolder " -device acpi-erst,memdev=erstnvram", tmp_path);
2079646a793cSEric DeVolder test_acpi_one(params, &data);
2080646a793cSEric DeVolder g_free(params);
2081646a793cSEric DeVolder g_assert(g_rmdir(tmp_path) == 0);
2082646a793cSEric DeVolder g_free(tmp_path);
2083646a793cSEric DeVolder free_test_data(&data);
2084646a793cSEric DeVolder }
208584efa8aaSBin Meng #endif /* CONFIG_POSIX */
2086646a793cSEric DeVolder
test_acpi_riscv64_virt_tcg(void)20875b966e54SSunil V L static void test_acpi_riscv64_virt_tcg(void)
20885b966e54SSunil V L {
20895b966e54SSunil V L test_data data = {
20905b966e54SSunil V L .machine = "virt",
20915b966e54SSunil V L .arch = "riscv64",
20925b966e54SSunil V L .tcg_only = true,
20935b966e54SSunil V L .uefi_fl1 = "pc-bios/edk2-riscv-code.fd",
20945b966e54SSunil V L .uefi_fl2 = "pc-bios/edk2-riscv-vars.fd",
20955b966e54SSunil V L .cd = "tests/data/uefi-boot-images/bios-tables-test.riscv64.iso.qcow2",
20965b966e54SSunil V L .ram_start = 0x80000000ULL,
20975b966e54SSunil V L .scan_len = 128ULL * 1024 * 1024,
20985b966e54SSunil V L };
20995b966e54SSunil V L
21005b966e54SSunil V L /*
21015b966e54SSunil V L * RHCT will have ISA string encoded. To reduce the effort
21025b966e54SSunil V L * of updating expected AML file for any new default ISA extension,
21035b966e54SSunil V L * use the profile rva22s64.
21045b966e54SSunil V L */
21055b966e54SSunil V L test_acpi_one("-cpu rva22s64 ", &data);
21065b966e54SSunil V L free_test_data(&data);
21075b966e54SSunil V L }
21085b966e54SSunil V L
test_acpi_aarch64_virt_tcg(void)21092fd69da2SSunil V L static void test_acpi_aarch64_virt_tcg(void)
21101e8a1faeSThomas Huth {
21111e8a1faeSThomas Huth test_data data = {
21121e8a1faeSThomas Huth .machine = "virt",
2113193e4b90SSunil V L .arch = "aarch64",
21141e8a1faeSThomas Huth .tcg_only = true,
21151e8a1faeSThomas Huth .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
21161e8a1faeSThomas Huth .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
21171e8a1faeSThomas Huth .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
21181e8a1faeSThomas Huth .ram_start = 0x40000000ULL,
21191e8a1faeSThomas Huth .scan_len = 128ULL * 1024 * 1024,
21201e8a1faeSThomas Huth };
21211e8a1faeSThomas Huth
2122e1647539SYing Fang data.smbios_cpu_max_speed = 2900;
2123e1647539SYing Fang data.smbios_cpu_curr_speed = 2700;
2124e1647539SYing Fang test_acpi_one("-cpu cortex-a57 "
2125e1647539SYing Fang "-smbios type=4,max-speed=2900,current-speed=2700", &data);
2126e1647539SYing Fang free_test_data(&data);
21271e8a1faeSThomas Huth }
21281e8a1faeSThomas Huth
test_acpi_aarch64_virt_tcg_topology(void)21292fd69da2SSunil V L static void test_acpi_aarch64_virt_tcg_topology(void)
213046bda3e4SYicong Yang {
213146bda3e4SYicong Yang test_data data = {
213246bda3e4SYicong Yang .machine = "virt",
2133193e4b90SSunil V L .arch = "aarch64",
213446bda3e4SYicong Yang .variant = ".topology",
213546bda3e4SYicong Yang .tcg_only = true,
213646bda3e4SYicong Yang .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
213746bda3e4SYicong Yang .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
213846bda3e4SYicong Yang .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
213946bda3e4SYicong Yang .ram_start = 0x40000000ULL,
214046bda3e4SYicong Yang .scan_len = 128ULL * 1024 * 1024,
214146bda3e4SYicong Yang };
214246bda3e4SYicong Yang
214346bda3e4SYicong Yang test_acpi_one("-cpu cortex-a57 "
214446bda3e4SYicong Yang "-smp sockets=1,clusters=2,cores=2,threads=2", &data);
214546bda3e4SYicong Yang free_test_data(&data);
214646bda3e4SYicong Yang }
214746bda3e4SYicong Yang
test_acpi_q35_viot(void)214839d7554bSJean-Philippe Brucker static void test_acpi_q35_viot(void)
214939d7554bSJean-Philippe Brucker {
215039d7554bSJean-Philippe Brucker test_data data = {
215139d7554bSJean-Philippe Brucker .machine = MACHINE_Q35,
2152d488c66bSSunil V L .arch = "x86",
215339d7554bSJean-Philippe Brucker .variant = ".viot",
215439d7554bSJean-Philippe Brucker };
215539d7554bSJean-Philippe Brucker
215639d7554bSJean-Philippe Brucker /*
215739d7554bSJean-Philippe Brucker * To keep things interesting, two buses bypass the IOMMU.
215839d7554bSJean-Philippe Brucker * VIOT should only describes the other two buses.
215939d7554bSJean-Philippe Brucker */
216039d7554bSJean-Philippe Brucker test_acpi_one("-machine default_bus_bypass_iommu=on "
216139d7554bSJean-Philippe Brucker "-device virtio-iommu-pci "
216239d7554bSJean-Philippe Brucker "-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 "
216339d7554bSJean-Philippe Brucker "-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on "
216439d7554bSJean-Philippe Brucker "-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0",
216539d7554bSJean-Philippe Brucker &data);
216639d7554bSJean-Philippe Brucker free_test_data(&data);
216739d7554bSJean-Philippe Brucker }
216839d7554bSJean-Philippe Brucker
216984efa8aaSBin Meng #ifdef CONFIG_POSIX
test_acpi_q35_cxl(void)217065fc04ffSJonathan Cameron static void test_acpi_q35_cxl(void)
217165fc04ffSJonathan Cameron {
217265fc04ffSJonathan Cameron gchar *tmp_path = g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL);
217365fc04ffSJonathan Cameron gchar *params;
217465fc04ffSJonathan Cameron
217565fc04ffSJonathan Cameron test_data data = {
217665fc04ffSJonathan Cameron .machine = MACHINE_Q35,
2177d488c66bSSunil V L .arch = "x86",
217865fc04ffSJonathan Cameron .variant = ".cxl",
217965fc04ffSJonathan Cameron };
218065fc04ffSJonathan Cameron /*
218165fc04ffSJonathan Cameron * A complex CXL setup.
218265fc04ffSJonathan Cameron */
218365fc04ffSJonathan Cameron params = g_strdup_printf(" -machine cxl=on"
218465fc04ffSJonathan Cameron " -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M"
218565fc04ffSJonathan Cameron " -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M"
218665fc04ffSJonathan Cameron " -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M"
218765fc04ffSJonathan Cameron " -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M"
218865fc04ffSJonathan Cameron " -object memory-backend-file,id=lsa1,mem-path=%s,size=256M"
218965fc04ffSJonathan Cameron " -object memory-backend-file,id=lsa2,mem-path=%s,size=256M"
219065fc04ffSJonathan Cameron " -object memory-backend-file,id=lsa3,mem-path=%s,size=256M"
219165fc04ffSJonathan Cameron " -object memory-backend-file,id=lsa4,mem-path=%s,size=256M"
219265fc04ffSJonathan Cameron " -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1"
219365fc04ffSJonathan Cameron " -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2"
219465fc04ffSJonathan Cameron " -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2"
2195adacc814SGregory Price " -device cxl-type3,bus=rp1,persistent-memdev=cxl-mem1,lsa=lsa1"
219665fc04ffSJonathan Cameron " -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3"
2197adacc814SGregory Price " -device cxl-type3,bus=rp2,persistent-memdev=cxl-mem2,lsa=lsa2"
219865fc04ffSJonathan Cameron " -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5"
2199adacc814SGregory Price " -device cxl-type3,bus=rp3,persistent-memdev=cxl-mem3,lsa=lsa3"
220065fc04ffSJonathan Cameron " -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6"
2201adacc814SGregory Price " -device cxl-type3,bus=rp4,persistent-memdev=cxl-mem4,lsa=lsa4"
220203b39fcfSJonathan Cameron " -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k,"
220303b39fcfSJonathan Cameron "cxl-fmw.1.targets.0=cxl.1,cxl-fmw.1.targets.1=cxl.2,cxl-fmw.1.size=4G,cxl-fmw.1.interleave-granularity=8k",
220465fc04ffSJonathan Cameron tmp_path, tmp_path, tmp_path, tmp_path,
220565fc04ffSJonathan Cameron tmp_path, tmp_path, tmp_path, tmp_path);
220665fc04ffSJonathan Cameron test_acpi_one(params, &data);
220765fc04ffSJonathan Cameron
220865fc04ffSJonathan Cameron g_free(params);
220965fc04ffSJonathan Cameron g_assert(g_rmdir(tmp_path) == 0);
221065fc04ffSJonathan Cameron g_free(tmp_path);
221165fc04ffSJonathan Cameron free_test_data(&data);
221265fc04ffSJonathan Cameron }
221384efa8aaSBin Meng #endif /* CONFIG_POSIX */
221465fc04ffSJonathan Cameron
test_acpi_aarch64_virt_viot(void)22152fd69da2SSunil V L static void test_acpi_aarch64_virt_viot(void)
221639d7554bSJean-Philippe Brucker {
221739d7554bSJean-Philippe Brucker test_data data = {
221839d7554bSJean-Philippe Brucker .machine = "virt",
2219193e4b90SSunil V L .arch = "aarch64",
222069a80f14SJean-Philippe Brucker .tcg_only = true,
222139d7554bSJean-Philippe Brucker .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
222239d7554bSJean-Philippe Brucker .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
222339d7554bSJean-Philippe Brucker .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
222439d7554bSJean-Philippe Brucker .ram_start = 0x40000000ULL,
222539d7554bSJean-Philippe Brucker .scan_len = 128ULL * 1024 * 1024,
222639d7554bSJean-Philippe Brucker };
222739d7554bSJean-Philippe Brucker
222839d7554bSJean-Philippe Brucker test_acpi_one("-cpu cortex-a57 "
222939d7554bSJean-Philippe Brucker "-device virtio-iommu-pci", &data);
223039d7554bSJean-Philippe Brucker free_test_data(&data);
223139d7554bSJean-Philippe Brucker }
223239d7554bSJean-Philippe Brucker
22334b83dd0eSBin Meng #ifndef _WIN32
22344b83dd0eSBin Meng # define DEV_NULL "/dev/null"
22354b83dd0eSBin Meng #else
22364b83dd0eSBin Meng # define DEV_NULL "nul"
22374b83dd0eSBin Meng #endif
22384b83dd0eSBin Meng
test_acpi_q35_slic(void)223911edfabeSIgor Mammedov static void test_acpi_q35_slic(void)
224011edfabeSIgor Mammedov {
224111edfabeSIgor Mammedov test_data data = {
224211edfabeSIgor Mammedov .machine = MACHINE_Q35,
2243d488c66bSSunil V L .arch = "x86",
224411edfabeSIgor Mammedov .variant = ".slic",
224511edfabeSIgor Mammedov };
224611edfabeSIgor Mammedov
22474b83dd0eSBin Meng test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
22484b83dd0eSBin Meng "oem_rev=00002210,asl_compiler_id=qemu,"
22494b83dd0eSBin Meng "asl_compiler_rev=00000000,data=" DEV_NULL,
225011edfabeSIgor Mammedov &data);
225111edfabeSIgor Mammedov free_test_data(&data);
225211edfabeSIgor Mammedov }
225311edfabeSIgor Mammedov
test_acpi_q35_applesmc(void)2254cde55744SIgor Mammedov static void test_acpi_q35_applesmc(void)
2255cde55744SIgor Mammedov {
2256cde55744SIgor Mammedov test_data data = {
2257cde55744SIgor Mammedov .machine = MACHINE_Q35,
2258d488c66bSSunil V L .arch = "x86",
2259cde55744SIgor Mammedov .variant = ".applesmc",
2260cde55744SIgor Mammedov };
2261cde55744SIgor Mammedov
2262888fbaafSIgor Mammedov /* supply fake 64-byte OSK to silence missing key warning */
2263888fbaafSIgor Mammedov test_acpi_one("-device isa-applesmc,osk=any64characterfakeoskisenough"
2264888fbaafSIgor Mammedov "topreventinvalidkeywarningsonstderr", &data);
2265cde55744SIgor Mammedov free_test_data(&data);
2266cde55744SIgor Mammedov }
2267cde55744SIgor Mammedov
test_acpi_q35_pvpanic_isa(void)2268fd7bcffeSIgor Mammedov static void test_acpi_q35_pvpanic_isa(void)
2269fd7bcffeSIgor Mammedov {
2270fd7bcffeSIgor Mammedov test_data data = {
2271fd7bcffeSIgor Mammedov .machine = MACHINE_Q35,
2272d488c66bSSunil V L .arch = "x86",
2273fd7bcffeSIgor Mammedov .variant = ".pvpanic-isa",
2274fd7bcffeSIgor Mammedov };
2275fd7bcffeSIgor Mammedov
2276fd7bcffeSIgor Mammedov test_acpi_one("-device pvpanic", &data);
2277fd7bcffeSIgor Mammedov free_test_data(&data);
2278fd7bcffeSIgor Mammedov }
2279fd7bcffeSIgor Mammedov
test_acpi_pc_smbios_options(void)228053002d90SIgor Mammedov static void test_acpi_pc_smbios_options(void)
228153002d90SIgor Mammedov {
228253002d90SIgor Mammedov uint8_t req_type11[] = { 11 };
228353002d90SIgor Mammedov test_data data = {
228453002d90SIgor Mammedov .machine = MACHINE_PC,
2285d488c66bSSunil V L .arch = "x86",
228653002d90SIgor Mammedov .variant = ".pc_smbios_options",
228753002d90SIgor Mammedov .required_struct_types = req_type11,
228853002d90SIgor Mammedov .required_struct_types_len = ARRAY_SIZE(req_type11),
228953002d90SIgor Mammedov };
229053002d90SIgor Mammedov
229153002d90SIgor Mammedov test_smbios("-smbios type=11,value=TEST", &data);
229253002d90SIgor Mammedov free_test_data(&data);
229353002d90SIgor Mammedov }
229453002d90SIgor Mammedov
test_acpi_pc_smbios_blob(void)2295ed75658aSIgor Mammedov static void test_acpi_pc_smbios_blob(void)
2296ed75658aSIgor Mammedov {
2297ed75658aSIgor Mammedov uint8_t req_type11[] = { 11 };
2298ed75658aSIgor Mammedov test_data data = {
2299ed75658aSIgor Mammedov .machine = MACHINE_PC,
2300d488c66bSSunil V L .arch = "x86",
2301ed75658aSIgor Mammedov .variant = ".pc_smbios_blob",
2302ed75658aSIgor Mammedov .required_struct_types = req_type11,
2303ed75658aSIgor Mammedov .required_struct_types_len = ARRAY_SIZE(req_type11),
2304ed75658aSIgor Mammedov };
2305ed75658aSIgor Mammedov
2306ed75658aSIgor Mammedov test_smbios("-machine smbios-entry-point-type=32 "
2307ed75658aSIgor Mammedov "-smbios file=tests/data/smbios/type11_blob", &data);
2308ed75658aSIgor Mammedov free_test_data(&data);
2309ed75658aSIgor Mammedov }
2310ed75658aSIgor Mammedov
test_acpi_isapc_smbios_legacy(void)2311579094cbSIgor Mammedov static void test_acpi_isapc_smbios_legacy(void)
2312579094cbSIgor Mammedov {
2313579094cbSIgor Mammedov uint8_t req_type11[] = { 1, 11 };
2314579094cbSIgor Mammedov test_data data = {
2315579094cbSIgor Mammedov .machine = "isapc",
2316579094cbSIgor Mammedov .variant = ".pc_smbios_legacy",
2317579094cbSIgor Mammedov .required_struct_types = req_type11,
2318579094cbSIgor Mammedov .required_struct_types_len = ARRAY_SIZE(req_type11),
2319579094cbSIgor Mammedov };
2320579094cbSIgor Mammedov
2321579094cbSIgor Mammedov test_smbios("-smbios file=tests/data/smbios/type11_blob.legacy "
2322579094cbSIgor Mammedov "-smbios type=1,family=TEST", &data);
2323579094cbSIgor Mammedov free_test_data(&data);
2324579094cbSIgor Mammedov }
2325579094cbSIgor Mammedov
test_oem_fields(test_data * data)23264b1f8882SMarian Postevca static void test_oem_fields(test_data *data)
23274b1f8882SMarian Postevca {
23284b1f8882SMarian Postevca int i;
23294b1f8882SMarian Postevca
23304b1f8882SMarian Postevca for (i = 0; i < data->tables->len; ++i) {
23314b1f8882SMarian Postevca AcpiSdtTable *sdt;
23324b1f8882SMarian Postevca
23334b1f8882SMarian Postevca sdt = &g_array_index(data->tables, AcpiSdtTable, i);
23344b1f8882SMarian Postevca /* FACS doesn't have OEMID and OEMTABLEID fields */
23354b1f8882SMarian Postevca if (compare_signature(sdt, "FACS")) {
23364b1f8882SMarian Postevca continue;
23374b1f8882SMarian Postevca }
23384b1f8882SMarian Postevca
2339408ca926SIgor Mammedov g_assert(strncmp((char *)sdt->aml + 10, OEM_ID, 6) == 0);
2340408ca926SIgor Mammedov g_assert(strncmp((char *)sdt->aml + 16, OEM_TABLE_ID, 8) == 0);
23414b1f8882SMarian Postevca }
23424b1f8882SMarian Postevca }
23434b1f8882SMarian Postevca
test_acpi_piix4_oem_fields(void)2344b3ad62c1SJuan Quintela static void test_acpi_piix4_oem_fields(void)
23454b1f8882SMarian Postevca {
23464b1f8882SMarian Postevca char *args;
2347a74b0d0aSPaolo Bonzini test_data data = {};
23484b1f8882SMarian Postevca
23494b1f8882SMarian Postevca data.machine = MACHINE_PC;
2350d488c66bSSunil V L data.arch = "x86";
23514b1f8882SMarian Postevca data.required_struct_types = base_required_struct_types;
23524b1f8882SMarian Postevca data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
23534b1f8882SMarian Postevca
2354c1a9ac9bSIgor Mammedov args = test_acpi_create_args(&data, OEM_TEST_ARGS);
23554b1f8882SMarian Postevca data.qts = qtest_init(args);
2356c1a9ac9bSIgor Mammedov test_acpi_load_tables(&data);
23574b1f8882SMarian Postevca test_oem_fields(&data);
23584b1f8882SMarian Postevca qtest_quit(data.qts);
23594b1f8882SMarian Postevca free_test_data(&data);
23604b1f8882SMarian Postevca g_free(args);
23614b1f8882SMarian Postevca }
23624b1f8882SMarian Postevca
test_acpi_q35_oem_fields(void)2363b3ad62c1SJuan Quintela static void test_acpi_q35_oem_fields(void)
23644b1f8882SMarian Postevca {
23654b1f8882SMarian Postevca char *args;
2366a74b0d0aSPaolo Bonzini test_data data = {};
23674b1f8882SMarian Postevca
23684b1f8882SMarian Postevca data.machine = MACHINE_Q35;
2369d488c66bSSunil V L data.arch = "x86";
23704b1f8882SMarian Postevca data.required_struct_types = base_required_struct_types;
23714b1f8882SMarian Postevca data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
23724b1f8882SMarian Postevca
2373c1a9ac9bSIgor Mammedov args = test_acpi_create_args(&data, OEM_TEST_ARGS);
23744b1f8882SMarian Postevca data.qts = qtest_init(args);
2375c1a9ac9bSIgor Mammedov test_acpi_load_tables(&data);
23764b1f8882SMarian Postevca test_oem_fields(&data);
23774b1f8882SMarian Postevca qtest_quit(data.qts);
23784b1f8882SMarian Postevca free_test_data(&data);
23794b1f8882SMarian Postevca g_free(args);
23804b1f8882SMarian Postevca }
23814b1f8882SMarian Postevca
test_acpi_microvm_oem_fields(void)2382b3ad62c1SJuan Quintela static void test_acpi_microvm_oem_fields(void)
23834b1f8882SMarian Postevca {
2384a74b0d0aSPaolo Bonzini test_data data = {};
23854b1f8882SMarian Postevca char *args;
23864b1f8882SMarian Postevca
23874b1f8882SMarian Postevca test_acpi_microvm_prepare(&data);
23884b1f8882SMarian Postevca
23894b1f8882SMarian Postevca args = test_acpi_create_args(&data,
2390c1a9ac9bSIgor Mammedov OEM_TEST_ARGS",acpi=on");
23914b1f8882SMarian Postevca data.qts = qtest_init(args);
2392c1a9ac9bSIgor Mammedov test_acpi_load_tables(&data);
23934b1f8882SMarian Postevca test_oem_fields(&data);
23944b1f8882SMarian Postevca qtest_quit(data.qts);
23954b1f8882SMarian Postevca free_test_data(&data);
23964b1f8882SMarian Postevca g_free(args);
23974b1f8882SMarian Postevca }
23984b1f8882SMarian Postevca
test_acpi_aarch64_virt_oem_fields(void)23992fd69da2SSunil V L static void test_acpi_aarch64_virt_oem_fields(void)
24004b1f8882SMarian Postevca {
24014b1f8882SMarian Postevca test_data data = {
24024b1f8882SMarian Postevca .machine = "virt",
2403193e4b90SSunil V L .arch = "aarch64",
24044b1f8882SMarian Postevca .tcg_only = true,
24054b1f8882SMarian Postevca .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
24064b1f8882SMarian Postevca .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
24074b1f8882SMarian Postevca .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
24084b1f8882SMarian Postevca .ram_start = 0x40000000ULL,
24094b1f8882SMarian Postevca .scan_len = 128ULL * 1024 * 1024,
24104b1f8882SMarian Postevca };
24114b1f8882SMarian Postevca char *args;
24124b1f8882SMarian Postevca
2413c1a9ac9bSIgor Mammedov args = test_acpi_create_args(&data, "-cpu cortex-a57 "OEM_TEST_ARGS);
24144b1f8882SMarian Postevca data.qts = qtest_init(args);
2415c1a9ac9bSIgor Mammedov test_acpi_load_tables(&data);
24164b1f8882SMarian Postevca test_oem_fields(&data);
24174b1f8882SMarian Postevca qtest_quit(data.qts);
24184b1f8882SMarian Postevca free_test_data(&data);
24194b1f8882SMarian Postevca g_free(args);
24204b1f8882SMarian Postevca }
24214b1f8882SMarian Postevca
24224b1f8882SMarian Postevca
main(int argc,char * argv[])24231e8a1faeSThomas Huth int main(int argc, char *argv[])
24241e8a1faeSThomas Huth {
24251e8a1faeSThomas Huth const char *arch = qtest_get_arch();
24260c1ae3ffSFabiano Rosas bool has_kvm, has_tcg;
24274ffa3a1bSThomas Huth char *v_env = getenv("V");
24281e8a1faeSThomas Huth int ret;
24291e8a1faeSThomas Huth
24304ffa3a1bSThomas Huth if (v_env) {
24314ffa3a1bSThomas Huth verbosity_level = atoi(v_env);
24324ffa3a1bSThomas Huth }
24334ffa3a1bSThomas Huth
24341e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
24351e8a1faeSThomas Huth
24360c1ae3ffSFabiano Rosas has_kvm = qtest_has_accel("kvm");
24370c1ae3ffSFabiano Rosas has_tcg = qtest_has_accel("tcg");
24380c1ae3ffSFabiano Rosas
24390c1ae3ffSFabiano Rosas if (!has_tcg && !has_kvm) {
24400c1ae3ffSFabiano Rosas g_test_skip("No KVM or TCG accelerator available");
24410c1ae3ffSFabiano Rosas return 0;
24420c1ae3ffSFabiano Rosas }
24430c1ae3ffSFabiano Rosas
24441e8a1faeSThomas Huth if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
24451e8a1faeSThomas Huth ret = boot_sector_init(disk);
24461e8a1faeSThomas Huth if (ret) {
24471e8a1faeSThomas Huth return ret;
24481e8a1faeSThomas Huth }
244934b1f2c6SJuan Quintela if (qtest_has_machine(MACHINE_PC)) {
24501e8a1faeSThomas Huth qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
2451b3ad62c1SJuan Quintela qtest_add_func("acpi/piix4/oem-fields", test_acpi_piix4_oem_fields);
24521e8a1faeSThomas Huth qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
245327476395SAni Sinha qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
245427476395SAni Sinha test_acpi_piix4_no_root_hotplug);
24555e3a4862SAni Sinha qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
24565e3a4862SAni Sinha test_acpi_piix4_no_bridge_hotplug);
24575645f996SAni Sinha qtest_add_func("acpi/piix4/pci-hotplug/off",
24585645f996SAni Sinha test_acpi_piix4_no_acpi_pci_hotplug);
24591e8a1faeSThomas Huth qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
24601e8a1faeSThomas Huth qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
24611e8a1faeSThomas Huth qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
24620dabb2e8SIsaku Yamahata qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm);
24630dabb2e8SIsaku Yamahata qtest_add_func("acpi/piix4/smm-compat",
24640dabb2e8SIsaku Yamahata test_acpi_piix4_tcg_smm_compat);
24650dabb2e8SIsaku Yamahata qtest_add_func("acpi/piix4/smm-compat-nosmm",
24660dabb2e8SIsaku Yamahata test_acpi_piix4_tcg_smm_compat_nosmm);
24679a70e043SIsaku Yamahata qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet);
2468cf038650SAni Sinha
2469cf038650SAni Sinha /* i386 does not support memory hotplug */
2470cf038650SAni Sinha if (strcmp(arch, "i386")) {
2471cf038650SAni Sinha qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
2472cf038650SAni Sinha qtest_add_func("acpi/piix4/dimmpxm",
2473cf038650SAni Sinha test_acpi_piix4_tcg_dimm_pxm);
247434b1f2c6SJuan Quintela qtest_add_func("acpi/piix4/acpihmat",
247534b1f2c6SJuan Quintela test_acpi_piix4_tcg_acpi_hmat);
2476cf038650SAni Sinha }
2477d007981aSJuan Quintela #ifdef CONFIG_POSIX
2478d007981aSJuan Quintela qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst);
2479d007981aSJuan Quintela #endif
248053002d90SIgor Mammedov qtest_add_func("acpi/piix4/smbios-options",
248153002d90SIgor Mammedov test_acpi_pc_smbios_options);
2482ed75658aSIgor Mammedov qtest_add_func("acpi/piix4/smbios-blob",
2483ed75658aSIgor Mammedov test_acpi_pc_smbios_blob);
2484579094cbSIgor Mammedov qtest_add_func("acpi/piix4/smbios-legacy",
2485579094cbSIgor Mammedov test_acpi_isapc_smbios_legacy);
248634b1f2c6SJuan Quintela }
248734b1f2c6SJuan Quintela if (qtest_has_machine(MACHINE_Q35)) {
2488d007981aSJuan Quintela qtest_add_func("acpi/q35", test_acpi_q35_tcg);
2489d007981aSJuan Quintela qtest_add_func("acpi/q35/oem-fields", test_acpi_q35_oem_fields);
2490d007981aSJuan Quintela if (tpm_model_is_available("-machine q35", "tpm-tis")) {
2491d007981aSJuan Quintela qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis);
249234b1f2c6SJuan Quintela qtest_add_func("acpi/q35/tpm12-tis",
249334b1f2c6SJuan Quintela test_acpi_q35_tcg_tpm12_tis);
2494d007981aSJuan Quintela }
2495d007981aSJuan Quintela qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
2496b0b3b99eSIgor Mammedov qtest_add_func("acpi/q35/no-acpi-hotplug",
2497b0b3b99eSIgor Mammedov test_acpi_q35_tcg_no_acpi_hotplug);
249834b1f2c6SJuan Quintela qtest_add_func("acpi/q35/multif-bridge",
249934b1f2c6SJuan Quintela test_acpi_q35_multif_bridge);
2500d007981aSJuan Quintela qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
2501d007981aSJuan Quintela qtest_add_func("acpi/q35/smbus/ipmi", test_acpi_q35_tcg_smbus_ipmi);
2502d007981aSJuan Quintela qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
2503d007981aSJuan Quintela qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
25040dabb2e8SIsaku Yamahata qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
25050dabb2e8SIsaku Yamahata qtest_add_func("acpi/q35/smm-compat",
25060dabb2e8SIsaku Yamahata test_acpi_q35_tcg_smm_compat);
25070dabb2e8SIsaku Yamahata qtest_add_func("acpi/q35/smm-compat-nosmm",
25080dabb2e8SIsaku Yamahata test_acpi_q35_tcg_smm_compat_nosmm);
25099a70e043SIsaku Yamahata qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
2510a046f1d7SBrice Goglin qtest_add_func("acpi/q35/acpihmat-noinitiator",
2511a046f1d7SBrice Goglin test_acpi_q35_tcg_acpi_hmat_noinitiator);
2512*18afed74SJonathan Cameron qtest_add_func("acpi/q35/acpihmat-genericx",
2513*18afed74SJonathan Cameron test_acpi_q35_tcg_acpi_hmat_generic_x);
2514cf038650SAni Sinha
2515cf038650SAni Sinha /* i386 does not support memory hotplug */
2516cf038650SAni Sinha if (strcmp(arch, "i386")) {
2517cf038650SAni Sinha qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
2518cf038650SAni Sinha qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
2519cf038650SAni Sinha qtest_add_func("acpi/q35/acpihmat",
2520cf038650SAni Sinha test_acpi_q35_tcg_acpi_hmat);
2521cf038650SAni Sinha qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
2522cf038650SAni Sinha }
252384efa8aaSBin Meng #ifdef CONFIG_POSIX
2524646a793cSEric DeVolder qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst);
252584efa8aaSBin Meng #endif
2526cde55744SIgor Mammedov qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc);
2527fd7bcffeSIgor Mammedov qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa);
2528220ffd94SIgor Mammedov if (has_tcg) {
2529220ffd94SIgor Mammedov qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs);
2530220ffd94SIgor Mammedov }
253180a2f338SIgor Mammedov if (has_kvm) {
253280a2f338SIgor Mammedov qtest_add_func("acpi/q35/kvm/xapic", test_acpi_q35_kvm_xapic);
25330ff92b6dSIgor Mammedov qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar);
2534df210963SZhao Liu qtest_add_func("acpi/q35/type4-count",
2535c40db4baSZhao Liu test_acpi_q35_kvm_type4_count);
2536148a8a1dSZhao Liu qtest_add_func("acpi/q35/core-count",
2537c40db4baSZhao Liu test_acpi_q35_kvm_core_count);
25382d80b338SJulia Suvorova qtest_add_func("acpi/q35/core-count2",
2539c40db4baSZhao Liu test_acpi_q35_kvm_core_count2);
25407ee18dceSZhao Liu qtest_add_func("acpi/q35/thread-count",
2541c40db4baSZhao Liu test_acpi_q35_kvm_thread_count);
2542198eee0cSZhao Liu qtest_add_func("acpi/q35/thread-count2",
2543c40db4baSZhao Liu test_acpi_q35_kvm_thread_count2);
254480a2f338SIgor Mammedov }
2545a864cc54SThomas Huth if (qtest_has_device("virtio-iommu-pci")) {
254639d7554bSJean-Philippe Brucker qtest_add_func("acpi/q35/viot", test_acpi_q35_viot);
2547a864cc54SThomas Huth }
254884efa8aaSBin Meng #ifdef CONFIG_POSIX
254965fc04ffSJonathan Cameron qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl);
255084efa8aaSBin Meng #endif
255111edfabeSIgor Mammedov qtest_add_func("acpi/q35/slic", test_acpi_q35_slic);
255234b1f2c6SJuan Quintela }
255334b1f2c6SJuan Quintela if (qtest_has_machine("microvm")) {
2554d007981aSJuan Quintela qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
2555d007981aSJuan Quintela qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
2556d007981aSJuan Quintela qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
255734b1f2c6SJuan Quintela qtest_add_func("acpi/microvm/ioapic2",
255834b1f2c6SJuan Quintela test_acpi_microvm_ioapic2_tcg);
255934b1f2c6SJuan Quintela qtest_add_func("acpi/microvm/oem-fields",
256034b1f2c6SJuan Quintela test_acpi_microvm_oem_fields);
2561d007981aSJuan Quintela if (has_tcg) {
2562d007981aSJuan Quintela if (strcmp(arch, "x86_64") == 0) {
256334b1f2c6SJuan Quintela qtest_add_func("acpi/microvm/pcie",
256434b1f2c6SJuan Quintela test_acpi_microvm_pcie_tcg);
2565d007981aSJuan Quintela #ifdef CONFIG_POSIX
256634b1f2c6SJuan Quintela qtest_add_func("acpi/microvm/acpierst",
256734b1f2c6SJuan Quintela test_acpi_microvm_acpi_erst);
2568d007981aSJuan Quintela #endif
2569d007981aSJuan Quintela }
2570d007981aSJuan Quintela }
257134b1f2c6SJuan Quintela }
25721e8a1faeSThomas Huth } else if (strcmp(arch, "aarch64") == 0) {
25738c730de7SThomas Huth if (has_tcg && qtest_has_device("virtio-blk-pci")) {
25742fd69da2SSunil V L qtest_add_func("acpi/virt", test_acpi_aarch64_virt_tcg);
2575b077b070SHesham Almatary qtest_add_func("acpi/virt/acpihmatvirt",
25762fd69da2SSunil V L test_acpi_aarch64_virt_tcg_acpi_hmat);
25772fd69da2SSunil V L qtest_add_func("acpi/virt/topology",
25782fd69da2SSunil V L test_acpi_aarch64_virt_tcg_topology);
25792fd69da2SSunil V L qtest_add_func("acpi/virt/numamem",
25802fd69da2SSunil V L test_acpi_aarch64_virt_tcg_numamem);
25812fd69da2SSunil V L qtest_add_func("acpi/virt/memhp", test_acpi_aarch64_virt_tcg_memhp);
25822fd69da2SSunil V L qtest_add_func("acpi/virt/pxb", test_acpi_aarch64_virt_tcg_pxb);
25832fd69da2SSunil V L qtest_add_func("acpi/virt/oem-fields",
25842fd69da2SSunil V L test_acpi_aarch64_virt_oem_fields);
2585a864cc54SThomas Huth if (qtest_has_device("virtio-iommu-pci")) {
25862fd69da2SSunil V L qtest_add_func("acpi/virt/viot", test_acpi_aarch64_virt_viot);
25871e8a1faeSThomas Huth }
2588220ffd94SIgor Mammedov }
25895b966e54SSunil V L } else if (strcmp(arch, "riscv64") == 0) {
25905b966e54SSunil V L if (has_tcg && qtest_has_device("virtio-blk-pci")) {
25915b966e54SSunil V L qtest_add_func("acpi/virt", test_acpi_riscv64_virt_tcg);
25925fd9c51dSHaibo Xu qtest_add_func("acpi/virt/numamem",
25935fd9c51dSHaibo Xu test_acpi_riscv64_virt_tcg_numamem);
25945b966e54SSunil V L }
2595a864cc54SThomas Huth }
25961e8a1faeSThomas Huth ret = g_test_run();
25971e8a1faeSThomas Huth boot_sector_cleanup(disk);
25981e8a1faeSThomas Huth return ret;
25991e8a1faeSThomas Huth }
2600