]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qtest/bios-tables-test.c
bios-tables-test: use 128M numa nodes on aarch64
[mirror_qemu.git] / tests / qtest / bios-tables-test.c
CommitLineData
ad6423a7
MT
1/*
2 * Boot order test cases.
3 *
4 * Copyright (c) 2013 Red Hat Inc.
5 *
6 * Authors:
7 * Michael S. Tsirkin <mst@redhat.com>,
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
30c63d4f 13/*
07f5903c 14 * How to add or update the tests or commit changes that affect ACPI tables:
30c63d4f
MT
15 * Contributor:
16 * 1. add empty files for new tables, if any, under tests/data/acpi
c66e8ab0 17 * 2. list any changed files in tests/qtest/bios-tables-test-allowed-diff.h
30c63d4f 18 * 3. commit the above *before* making changes that affect the tables
3c2ab559
MT
19 *
20 * Contributor or ACPI Maintainer (steps 4-7 need to be redone to resolve conflicts
21 * in binary commit created in step 6):
22 *
30c63d4f 23 * After 1-3 above tests will pass but ignore differences with the expected files.
c66e8ab0 24 * You will also notice that tests/qtest/bios-tables-test-allowed-diff.h lists
30c63d4f
MT
25 * a bunch of files. This is your hint that you need to do the below:
26 * 4. Run
4ffa3a1b 27 * make check V=2
30c63d4f
MT
28 * this will produce a bunch of warnings about differences
29 * beween actual and expected ACPI tables. If you have IASL installed,
30 * they will also be disassembled so you can look at the disassembled
31 * output. If not - disassemble them yourself in any way you like.
32 * Look at the differences - make sure they make sense and match what the
33 * changes you are merging are supposed to do.
3c2ab559
MT
34 * Save the changes, preferably in form of ASL diff for the commit log in
35 * step 6.
30c63d4f
MT
36 *
37 * 5. From build directory, run:
38 * $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh
3c2ab559
MT
39 * 6. Now commit any changes to the expected binary, include diff from step 4
40 * in commit log.
07f5903c
AS
41 * Expected binary updates needs to be a separate patch from the code that
42 * introduces changes to ACPI tables. It lets the maintainer drop
43 * and regenerate binary updates in case of merge conflicts. Further, a code
44 * change is easily reviewable but a binary blob is not (without doing a
45 * disassembly).
3c2ab559
MT
46 * 7. Before sending patches to the list (Contributor)
47 * or before doing a pull request (Maintainer), make sure
c66e8ab0 48 * tests/qtest/bios-tables-test-allowed-diff.h is empty - this will ensure
3c2ab559
MT
49 * following changes to ACPI tables will be noticed.
50 *
51 * The resulting patchset/pull request then looks like this:
c66e8ab0 52 * - patch 1: list changed files in tests/qtest/bios-tables-test-allowed-diff.h.
3c2ab559
MT
53 * - patches 2 - n: real changes, may contain multiple patches.
54 * - patch n + 1: update golden master binaries and empty
c66e8ab0 55 * tests/qtest/bios-tables-test-allowed-diff.h
30c63d4f
MT
56 */
57
681c28a3 58#include "qemu/osdep.h"
4500bc98 59#include <glib/gstdio.h>
a2eb5c0c 60#include "hw/firmware/smbios.h"
eb386aac 61#include "qemu/bitmap.h"
3248f1b4 62#include "acpi-utils.h"
4e082566 63#include "boot-sector.h"
5da7c35e
EA
64#include "tpm-emu.h"
65#include "hw/acpi/tpm.h"
4b1f8882 66#include "qemu/cutils.h"
ad6423a7 67
9e8458c0
MA
68#define MACHINE_PC "pc"
69#define MACHINE_Q35 "q35"
70
4500bc98
MA
71#define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
72
408ca926
IM
73#define OEM_ID "TEST"
74#define OEM_TABLE_ID "OEM"
75#define OEM_TEST_ARGS "-machine x-oem-id=" OEM_ID ",x-oem-table-id=" \
76 OEM_TABLE_ID
4b1f8882 77
53333801 78typedef struct {
6f6e1698 79 bool tcg_only;
9e8458c0 80 const char *machine;
9a2112f9 81 const char *machine_param;
3a9c86df 82 const char *variant;
97256e79
IM
83 const char *uefi_fl1;
84 const char *uefi_fl2;
3cac3784 85 const char *blkdev;
97256e79
IM
86 const char *cd;
87 const uint64_t ram_start;
88 const uint64_t scan_len;
9c041885 89 uint64_t rsdp_addr;
d6caf363 90 uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
a3a74ab9 91 GArray *tables;
33bff4a8
JS
92 uint64_t smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE__MAX];
93 SmbiosEntryPoint smbios_ep_table;
e1647539
YF
94 uint16_t smbios_cpu_max_speed;
95 uint16_t smbios_cpu_curr_speed;
2d80b338
JS
96 uint8_t smbios_core_count;
97 uint16_t smbios_core_count2;
f4eda2d4
CM
98 uint8_t *required_struct_types;
99 int required_struct_types_len;
273e3d92 100 QTestState *qts;
53333801 101} test_data;
ad6423a7 102
3e353773 103static char disk[] = "tests/acpi-test-disk-XXXXXX";
438c78da 104static const char *data_dir = "tests/data/acpi";
cc8fa0e8 105#ifdef CONFIG_IASL
859aef02 106static const char *iasl = CONFIG_IASL;
cc8fa0e8
MA
107#else
108static const char *iasl;
109#endif
ad6423a7 110
4ffa3a1b
TH
111static int verbosity_level;
112
b137522c
IM
113static bool compare_signature(const AcpiSdtTable *sdt, const char *signature)
114{
115 return !memcmp(sdt->aml, signature, 4);
116}
117
569afd84
IM
118static void cleanup_table_descriptor(AcpiSdtTable *table)
119{
120 g_free(table->aml);
121 if (table->aml_file &&
122 !table->tmp_files_retain &&
123 g_strstr_len(table->aml_file, -1, "aml-")) {
124 unlink(table->aml_file);
125 }
126 g_free(table->aml_file);
127 g_free(table->asl);
128 if (table->asl_file &&
129 !table->tmp_files_retain) {
130 unlink(table->asl_file);
131 }
132 g_free(table->asl_file);
133}
134
8ac2adf7
MA
135static void free_test_data(test_data *data)
136{
137 int i;
138
c51a5a23
CF
139 if (!data->tables) {
140 return;
141 }
a3a74ab9 142 for (i = 0; i < data->tables->len; ++i) {
569afd84 143 cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
8ac2adf7 144 }
9e8458c0 145
f11dc27b 146 g_array_free(data->tables, true);
8ac2adf7
MA
147}
148
53333801
MA
149static void test_acpi_rsdp_table(test_data *data)
150{
9c041885 151 uint8_t *rsdp_table = data->rsdp_table;
53333801 152
9c041885 153 acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
d6caf363 154
9c041885 155 switch (rsdp_table[15 /* Revision offset */]) {
d6caf363
SO
156 case 0: /* ACPI 1.0 RSDP */
157 /* With rev 1, checksum is only for the first 20 bytes */
158 g_assert(!acpi_calc_checksum(rsdp_table, 20));
159 break;
160 case 2: /* ACPI 2.0+ RSDP */
161 /* With revision 2, we have 2 checksums */
162 g_assert(!acpi_calc_checksum(rsdp_table, 20));
163 g_assert(!acpi_calc_checksum(rsdp_table, 36));
164 break;
165 default:
166 g_assert_not_reached();
167 }
53333801
MA
168}
169
f2f616ce 170static void test_acpi_rxsdt_table(test_data *data)
53333801 171{
f2f616ce 172 const char *sig = "RSDT";
569afd84 173 AcpiSdtTable rsdt = {};
f2f616ce
IM
174 int entry_size = 4;
175 int addr_off = 16 /* RsdtAddress */;
acee774b 176 uint8_t *ent;
569afd84 177
f2f616ce
IM
178 if (data->rsdp_table[15 /* Revision offset */] != 0) {
179 addr_off = 24 /* XsdtAddress */;
180 entry_size = 8;
181 sig = "XSDT";
182 }
183 /* read [RX]SDT table */
acee774b 184 acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
f2f616ce 185 &data->rsdp_table[addr_off], entry_size, sig, true);
569afd84
IM
186
187 /* Load all tables and add to test list directly RSDT referenced tables */
f2f616ce 188 ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
569afd84
IM
189 AcpiSdtTable ssdt_table = {};
190
acee774b 191 acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
f2f616ce 192 entry_size, NULL, true);
569afd84
IM
193 /* Add table to ASL test tables list */
194 g_array_append_val(data->tables, ssdt_table);
195 }
196 cleanup_table_descriptor(&rsdt);
53333801
MA
197}
198
db575449 199static void test_acpi_fadt_table(test_data *data)
53333801 200{
db575449 201 /* FADT table is 1st */
59f9c6cc
IM
202 AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
203 uint8_t *fadt_aml = table.aml;
b997a04a 204 uint32_t fadt_len = table.aml_len;
55089fa2
IM
205 uint32_t val;
206 int dsdt_offset = 40 /* DSDT */;
207 int dsdt_entry_size = 4;
53333801 208
b137522c 209 g_assert(compare_signature(&table, "FACP"));
89d47c19 210
59f9c6cc 211 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
40dfd0a8
IM
212 memcpy(&val, fadt_aml + 112 /* Flags */, 4);
213 val = le32_to_cpu(val);
214 if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
215 acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
216 fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
217 g_array_append_val(data->tables, table);
218 }
59f9c6cc 219
55089fa2
IM
220 memcpy(&val, fadt_aml + dsdt_offset, 4);
221 val = le32_to_cpu(val);
222 if (!val) {
223 dsdt_offset = 140 /* X_DSDT */;
224 dsdt_entry_size = 8;
225 }
acee774b 226 acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
55089fa2 227 fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
59f9c6cc 228 g_array_append_val(data->tables, table);
92146b7a 229
b997a04a
IM
230 memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
231 memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
232 if (fadt_aml[8 /* FADT Major Version */] >= 3) {
233 memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
234 memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
92146b7a 235 }
b997a04a
IM
236
237 /* update checksum */
238 fadt_aml[9 /* Checksum */] = 0;
239 fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
92146b7a
IM
240}
241
4500bc98 242static void dump_aml_files(test_data *data, bool rebuild)
9e8458c0
MA
243{
244 AcpiSdtTable *sdt;
245 GError *error = NULL;
4500bc98 246 gchar *aml_file = NULL;
9e8458c0
MA
247 gint fd;
248 ssize_t ret;
249 int i;
250
a3a74ab9 251 for (i = 0; i < data->tables->len; ++i) {
3a9c86df 252 const char *ext = data->variant ? data->variant : "";
a3a74ab9 253 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
9e8458c0
MA
254 g_assert(sdt->aml);
255
4500bc98 256 if (rebuild) {
3a9c86df 257 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
b137522c 258 sdt->aml, ext);
4500bc98
MA
259 fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
260 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
ba02ff90
IM
261 if (fd < 0) {
262 perror(aml_file);
263 }
264 g_assert(fd >= 0);
4500bc98
MA
265 } else {
266 fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
267 g_assert_no_error(error);
268 }
9e8458c0 269
9e8458c0
MA
270 ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
271 g_assert(ret == sdt->aml_len);
272
273 close(fd);
4500bc98 274
ef1e1e07 275 g_free(aml_file);
9e8458c0
MA
276 }
277}
278
81d72286
MT
279static bool create_tmp_asl(AcpiSdtTable *sdt)
280{
281 GError *error = NULL;
282 gint fd;
283
284 fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
285 g_assert_no_error(error);
286 close(fd);
287
288 return false;
289}
290
15d914b1 291static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
9e8458c0
MA
292{
293 AcpiSdtTable *temp;
294 GError *error = NULL;
cc8fa0e8 295 GString *command_line = g_string_new(iasl);
9e8458c0
MA
296 gchar *out, *out_err;
297 gboolean ret;
298 int i;
299
81d72286 300 create_tmp_asl(sdt);
9e8458c0
MA
301
302 /* build command line */
cc8fa0e8 303 g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
c225aa3c
MT
304 if (compare_signature(sdt, "DSDT") ||
305 compare_signature(sdt, "SSDT")) {
69d09245
MA
306 for (i = 0; i < sdts->len; ++i) {
307 temp = &g_array_index(sdts, AcpiSdtTable, i);
c225aa3c
MT
308 if (compare_signature(temp, "DSDT") ||
309 compare_signature(temp, "SSDT")) {
69d09245
MA
310 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
311 }
312 }
9e8458c0
MA
313 }
314 g_string_append_printf(command_line, "-d %s", sdt->aml_file);
315
316 /* pass 'out' and 'out_err' in order to be redirected */
15d914b1 317 ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
9e8458c0 318 g_assert_no_error(error);
15d914b1 319 if (ret) {
cc80b01a 320 ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
15d914b1
MA
321 &sdt->asl_len, &error);
322 g_assert(ret);
323 g_assert_no_error(error);
dac23a6c 324 ret = (sdt->asl_len > 0);
15d914b1 325 }
9e8458c0
MA
326
327 g_free(out);
328 g_free(out_err);
329 g_string_free(command_line, true);
15d914b1
MA
330
331 return !ret;
9e8458c0
MA
332}
333
334#define COMMENT_END "*/"
335#define DEF_BLOCK "DefinitionBlock ("
a3973f55 336#define BLOCK_NAME_END ","
9e8458c0
MA
337
338static GString *normalize_asl(gchar *asl_code)
339{
340 GString *asl = g_string_new(asl_code);
341 gchar *comment, *block_name;
342
343 /* strip comments (different generation days) */
344 comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
345 if (comment) {
cb348985
PB
346 comment += strlen(COMMENT_END);
347 while (*comment == '\n') {
348 comment++;
349 }
350 asl = g_string_erase(asl, 0, comment - asl->str);
9e8458c0
MA
351 }
352
353 /* strip def block name (it has file path in it) */
354 if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
355 block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
356 g_assert(block_name);
357 asl = g_string_erase(asl, 0,
358 block_name + sizeof(BLOCK_NAME_END) - asl->str);
359 }
360
361 return asl;
362}
363
364static GArray *load_expected_aml(test_data *data)
365{
366 int i;
367 AcpiSdtTable *sdt;
9e8458c0
MA
368 GError *error = NULL;
369 gboolean ret;
acee774b 370 gsize aml_len;
9e8458c0 371
a3a74ab9 372 GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
4ffa3a1b 373 if (verbosity_level >= 2) {
fe17cca6
PMD
374 fputc('\n', stderr);
375 }
a3a74ab9 376 for (i = 0; i < data->tables->len; ++i) {
9e8458c0 377 AcpiSdtTable exp_sdt;
d19587db 378 gchar *aml_file = NULL;
3a9c86df 379 const char *ext = data->variant ? data->variant : "";
c225aa3c 380
a3a74ab9 381 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
9e8458c0
MA
382
383 memset(&exp_sdt, 0, sizeof(exp_sdt));
9e8458c0 384
3a9c86df
IM
385try_again:
386 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
b137522c 387 sdt->aml, ext);
4ffa3a1b 388 if (verbosity_level >= 2) {
fe17cca6 389 fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
d19587db
IM
390 }
391 if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
392 exp_sdt.aml_file = aml_file;
393 } else if (*ext != '\0') {
e50a6121 394 /* try fallback to generic (extension less) expected file */
3a9c86df 395 ext = "";
d19587db 396 g_free(aml_file);
3a9c86df
IM
397 goto try_again;
398 }
d19587db 399 g_assert(exp_sdt.aml_file);
4ffa3a1b 400 if (verbosity_level >= 2) {
fe17cca6 401 fprintf(stderr, "Using expected file '%s'\n", aml_file);
d19587db 402 }
81eb530d 403 ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
acee774b
IM
404 &aml_len, &error);
405 exp_sdt.aml_len = aml_len;
9e8458c0
MA
406 g_assert(ret);
407 g_assert_no_error(error);
408 g_assert(exp_sdt.aml);
4eb74c4f
MT
409 if (!exp_sdt.aml_len) {
410 fprintf(stderr, "Warning! zero length expected file '%s'\n",
411 aml_file);
412 }
9e8458c0 413
a3a74ab9 414 g_array_append_val(exp_tables, exp_sdt);
9e8458c0
MA
415 }
416
a3a74ab9 417 return exp_tables;
9e8458c0
MA
418}
419
ab50f223
MT
420static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt)
421{
422 const gchar *allowed_diff_file[] = {
423#include "bios-tables-test-allowed-diff.h"
424 NULL
425 };
426 const gchar **f;
427
428 for (f = allowed_diff_file; *f; ++f) {
429 if (!g_strcmp0(sdt->aml_file, *f)) {
430 return true;
431 }
432 }
433 return false;
434}
435
ab20bbd2 436/* test the list of tables in @data->tables against reference tables */
9e8458c0
MA
437static void test_acpi_asl(test_data *data)
438{
439 int i;
440 AcpiSdtTable *sdt, *exp_sdt;
441 test_data exp_data;
df7cafde 442 gboolean exp_err, err, all_tables_match = true;
9e8458c0
MA
443
444 memset(&exp_data, 0, sizeof(exp_data));
a3a74ab9 445 exp_data.tables = load_expected_aml(data);
4500bc98 446 dump_aml_files(data, false);
a3a74ab9 447 for (i = 0; i < data->tables->len; ++i) {
9e8458c0
MA
448 GString *asl, *exp_asl;
449
a3a74ab9
MA
450 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
451 exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
9e8458c0 452
7f36f093
MT
453 if (sdt->aml_len == exp_sdt->aml_len &&
454 !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
455 /* Identical table binaries: no need to disassemble. */
456 continue;
457 }
458
459 fprintf(stderr,
460 "acpi-test: Warning! %.4s binary file mismatch. "
a7b4384f
MT
461 "Actual [aml:%s], Expected [aml:%s].\n"
462 "See source file tests/qtest/bios-tables-test.c "
463 "for instructions on how to update expected files.\n",
7f36f093
MT
464 exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file);
465
466 all_tables_match = all_tables_match &&
467 test_acpi_find_diff_allowed(exp_sdt);
468
7b9829bc
IM
469 /*
470 * don't try to decompile if IASL isn't present, in this case user
471 * will just 'get binary file mismatch' warnings and test failure
472 */
473 if (!iasl) {
474 continue;
475 }
476
15d914b1 477 err = load_asl(data->tables, sdt);
9e8458c0
MA
478 asl = normalize_asl(sdt->asl);
479
81d72286
MT
480 /*
481 * If expected file is empty - it's likely that it was a stub just
482 * created for step 1 above: we do want to decompile the actual one.
483 */
484 if (exp_sdt->aml_len) {
485 exp_err = load_asl(exp_data.tables, exp_sdt);
486 exp_asl = normalize_asl(exp_sdt->asl);
487 } else {
488 exp_err = create_tmp_asl(exp_sdt);
489 exp_asl = g_string_new("");
490 }
9e8458c0 491
15d914b1 492 /* TODO: check for warnings */
81d72286 493 g_assert(!err || exp_err || !exp_sdt->aml_len);
15d914b1 494
0651596c 495 if (g_strcmp0(asl->str, exp_asl->str)) {
6c77aa90 496 sdt->tmp_files_retain = true;
dac23a6c
MA
497 if (exp_err) {
498 fprintf(stderr,
499 "Warning! iasl couldn't parse the expected aml\n");
500 } else {
dac23a6c
MA
501 exp_sdt->tmp_files_retain = true;
502 fprintf(stderr,
503 "acpi-test: Warning! %.4s mismatch. "
504 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
b137522c 505 exp_sdt->aml, sdt->asl_file, sdt->aml_file,
dac23a6c 506 exp_sdt->asl_file, exp_sdt->aml_file);
c01e905f 507 fflush(stderr);
4ffa3a1b 508 if (verbosity_level >= 1) {
34b1429c 509 const char *diff_env = getenv("DIFF");
b20fdf2c 510 const char *diff_cmd = diff_env ? diff_env : "diff -U 16";
34b1429c
MT
511 char *diff = g_strdup_printf("%s %s %s", diff_cmd,
512 exp_sdt->asl_file, sdt->asl_file);
513 int out = dup(STDOUT_FILENO);
514 int ret G_GNUC_UNUSED;
3c65e439 515 int dupret;
34b1429c 516
3c65e439
PM
517 g_assert(out >= 0);
518 dupret = dup2(STDERR_FILENO, STDOUT_FILENO);
519 g_assert(dupret >= 0);
34b1429c 520 ret = system(diff) ;
3c65e439
PM
521 dupret = dup2(out, STDOUT_FILENO);
522 g_assert(dupret >= 0);
34b1429c
MT
523 close(out);
524 g_free(diff);
7cb08cb2 525 }
ab50f223 526 }
0651596c 527 }
9e8458c0
MA
528 g_string_free(asl, true);
529 g_string_free(exp_asl, true);
530 }
7b9829bc
IM
531 if (!iasl && !all_tables_match) {
532 fprintf(stderr, "to see ASL diff between mismatched files install IASL,"
533 " rebuild QEMU from scratch and re-run tests with V=1"
534 " environment variable set");
535 }
df7cafde 536 g_assert(all_tables_match);
9e8458c0
MA
537
538 free_test_data(&exp_data);
53333801
MA
539}
540
33bff4a8 541static bool smbios_ep2_table_ok(test_data *data, uint32_t addr)
eb386aac 542{
33bff4a8 543 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table.ep21;
eb386aac 544
3314778d 545 qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
5efed5a1
GS
546 if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
547 return false;
548 }
5efed5a1
GS
549 if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
550 return false;
551 }
5efed5a1
GS
552 if (ep_table->structure_table_length == 0) {
553 return false;
554 }
5efed5a1
GS
555 if (ep_table->number_of_structures == 0) {
556 return false;
557 }
3248f1b4
BW
558 if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
559 acpi_calc_checksum((uint8_t *)ep_table + 0x10,
560 sizeof *ep_table - 0x10)) {
5efed5a1
GS
561 return false;
562 }
563 return true;
564}
565
33bff4a8
JS
566static bool smbios_ep3_table_ok(test_data *data, uint64_t addr)
567{
568 struct smbios_30_entry_point *ep_table = &data->smbios_ep_table.ep30;
569
570 qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
571 if (memcmp(ep_table->anchor_string, "_SM3_", 5)) {
572 return false;
573 }
574
575 if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table)) {
576 return false;
577 }
578
579 return true;
580}
581
582static SmbiosEntryPointType test_smbios_entry_point(test_data *data)
5efed5a1
GS
583{
584 uint32_t off;
585
586 /* find smbios entry point structure */
587 for (off = 0xf0000; off < 0x100000; off += 0x10) {
33bff4a8 588 uint8_t sig[] = "_SM_", sig3[] = "_SM3_";
5efed5a1
GS
589 int i;
590
591 for (i = 0; i < sizeof sig - 1; ++i) {
273e3d92 592 sig[i] = qtest_readb(data->qts, off + i);
5efed5a1
GS
593 }
594
595 if (!memcmp(sig, "_SM_", sizeof sig)) {
596 /* signature match, but is this a valid entry point? */
33bff4a8
JS
597 if (smbios_ep2_table_ok(data, off)) {
598 data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] = off;
599 }
600 }
601
602 for (i = 0; i < sizeof sig3 - 1; ++i) {
603 sig3[i] = qtest_readb(data->qts, off + i);
604 }
605
606 if (!memcmp(sig3, "_SM3_", sizeof sig3)) {
607 if (smbios_ep3_table_ok(data, off)) {
608 data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] = off;
609 /* found 64-bit entry point, no need to look for 32-bit one */
5efed5a1
GS
610 break;
611 }
612 }
613 }
614
33bff4a8
JS
615 /* found at least one entry point */
616 g_assert_true(data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] ||
617 data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64]);
618
619 return data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] ?
620 SMBIOS_ENTRY_POINT_TYPE_64 : SMBIOS_ENTRY_POINT_TYPE_32;
eb386aac
GS
621}
622
623static inline bool smbios_single_instance(uint8_t type)
624{
625 switch (type) {
626 case 0:
627 case 1:
628 case 2:
629 case 3:
630 case 16:
631 case 32:
632 case 127:
633 return true;
634 default:
635 return false;
636 }
637}
638
2d80b338
JS
639static void smbios_cpu_test(test_data *data, uint32_t addr,
640 SmbiosEntryPointType ep_type)
e1647539 641{
2d80b338
JS
642 uint8_t core_count, expected_core_count = data->smbios_core_count;
643 uint16_t speed, expected_speed[2];
644 uint16_t core_count2, expected_core_count2 = data->smbios_core_count2;
e1647539
YF
645 int offset[2];
646 int i;
647
648 /* Check CPU speed for backward compatibility */
649 offset[0] = offsetof(struct smbios_type_4, max_speed);
650 offset[1] = offsetof(struct smbios_type_4, current_speed);
2d80b338
JS
651 expected_speed[0] = data->smbios_cpu_max_speed ? : 2000;
652 expected_speed[1] = data->smbios_cpu_curr_speed ? : 2000;
e1647539
YF
653
654 for (i = 0; i < 2; i++) {
2d80b338
JS
655 speed = qtest_readw(data->qts, addr + offset[i]);
656 g_assert_cmpuint(speed, ==, expected_speed[i]);
e1647539
YF
657 }
658
2d80b338
JS
659 core_count = qtest_readb(data->qts,
660 addr + offsetof(struct smbios_type_4, core_count));
661
662 if (expected_core_count) {
663 g_assert_cmpuint(core_count, ==, expected_core_count);
664 }
665
666 if (ep_type == SMBIOS_ENTRY_POINT_TYPE_64) {
667 core_count2 = qtest_readw(data->qts,
668 addr + offsetof(struct smbios_type_4, core_count2));
669
670 /* Core Count has reached its limit, checking Core Count 2 */
671 if (expected_core_count == 0xFF && expected_core_count2) {
672 g_assert_cmpuint(core_count2, ==, expected_core_count2);
673 }
674 }
e1647539
YF
675}
676
33bff4a8 677static void test_smbios_structs(test_data *data, SmbiosEntryPointType ep_type)
eb386aac
GS
678{
679 DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
33bff4a8
JS
680
681 SmbiosEntryPoint *ep_table = &data->smbios_ep_table;
682 int i = 0, len, max_len = 0;
eb386aac 683 uint8_t type, prv, crt;
33bff4a8
JS
684 uint64_t addr;
685
686 if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32) {
687 addr = le32_to_cpu(ep_table->ep21.structure_table_address);
688 } else {
689 addr = le64_to_cpu(ep_table->ep30.structure_table_address);
690 }
eb386aac
GS
691
692 /* walk the smbios tables */
33bff4a8 693 do {
eb386aac
GS
694
695 /* grab type and formatted area length from struct header */
273e3d92 696 type = qtest_readb(data->qts, addr);
eb386aac 697 g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
273e3d92 698 len = qtest_readb(data->qts, addr + 1);
eb386aac
GS
699
700 /* single-instance structs must not have been encountered before */
701 if (smbios_single_instance(type)) {
702 g_assert(!test_bit(type, struct_bitmap));
703 }
704 set_bit(type, struct_bitmap);
705
e1647539 706 if (type == 4) {
2d80b338 707 smbios_cpu_test(data, addr, ep_type);
e1647539
YF
708 }
709
eb386aac
GS
710 /* seek to end of unformatted string area of this struct ("\0\0") */
711 prv = crt = 1;
712 while (prv || crt) {
713 prv = crt;
273e3d92 714 crt = qtest_readb(data->qts, addr + len);
eb386aac
GS
715 len++;
716 }
717
718 /* keep track of max. struct size */
33bff4a8 719 if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32 && max_len < len) {
eb386aac 720 max_len = len;
33bff4a8 721 g_assert_cmpuint(max_len, <=, ep_table->ep21.max_structure_size);
eb386aac
GS
722 }
723
724 /* start of next structure */
725 addr += len;
eb386aac 726
33bff4a8
JS
727 /*
728 * Until all structures have been scanned (ep21)
729 * or an EOF structure is found (ep30)
730 */
731 } while (ep_type == SMBIOS_ENTRY_POINT_TYPE_32 ?
732 ++i < le16_to_cpu(ep_table->ep21.number_of_structures) :
733 type != 127);
734
735 if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32) {
736 /*
737 * Total table length and max struct size
738 * must match entry point values
739 */
740 g_assert_cmpuint(le16_to_cpu(ep_table->ep21.structure_table_length), ==,
741 addr - le32_to_cpu(ep_table->ep21.structure_table_address));
742
743 g_assert_cmpuint(le16_to_cpu(ep_table->ep21.max_structure_size), ==,
744 max_len);
745 }
eb386aac
GS
746
747 /* required struct types must all be present */
f4eda2d4
CM
748 for (i = 0; i < data->required_struct_types_len; i++) {
749 g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
eb386aac
GS
750 }
751}
752
c1a9ac9b 753static void test_acpi_load_tables(test_data *data)
ad6423a7 754{
c1a9ac9b 755 if (data->uefi_fl1 && data->uefi_fl2) { /* use UEFI */
4b1f8882
MP
756 g_assert(data->scan_len);
757 data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts,
758 data->ram_start, data->scan_len);
759 } else {
760 boot_sector_test(data->qts);
761 data->rsdp_addr = acpi_find_rsdp_address(data->qts);
762 g_assert_cmphex(data->rsdp_addr, <, 0x100000);
c51a5a23 763 }
4b1f8882
MP
764
765 data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
766 test_acpi_rsdp_table(data);
767 test_acpi_rxsdt_table(data);
768 test_acpi_fadt_table(data);
769}
770
c1a9ac9b 771static char *test_acpi_create_args(test_data *data, const char *params)
4b1f8882
MP
772{
773 char *args;
c51a5a23 774
c1a9ac9b 775 if (data->uefi_fl1 && data->uefi_fl2) { /* use UEFI */
97256e79
IM
776 /*
777 * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
778 * when arm/virt boad starts to support it.
779 */
1da638b1 780 if (data->cd) {
9a2112f9 781 args = g_strdup_printf("-machine %s%s %s -accel tcg "
1da638b1 782 "-nodefaults -nographic "
991c180d 783 "-drive if=pflash,format=raw,file=%s,readonly=on "
1da638b1 784 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
9a2112f9
TH
785 data->machine, data->machine_param ?: "",
786 data->tcg_only ? "" : "-accel kvm",
1da638b1
YM
787 data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
788 } else {
9a2112f9 789 args = g_strdup_printf("-machine %s%s %s -accel tcg "
1da638b1 790 "-nodefaults -nographic "
991c180d 791 "-drive if=pflash,format=raw,file=%s,readonly=on "
1da638b1 792 "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
9a2112f9
TH
793 data->machine, data->machine_param ?: "",
794 data->tcg_only ? "" : "-accel kvm",
1da638b1
YM
795 data->uefi_fl1, data->uefi_fl2, params ? params : "");
796 }
97256e79 797 } else {
9a2112f9 798 args = g_strdup_printf("-machine %s%s %s -accel tcg "
f15cfe41 799 "-net none %s "
97256e79 800 "-drive id=hd0,if=none,file=%s,format=raw "
3cac3784 801 "-device %s,drive=hd0 ",
9a2112f9
TH
802 data->machine, data->machine_param ?: "",
803 data->tcg_only ? "" : "-accel kvm",
3cac3784
GH
804 params ? params : "", disk,
805 data->blkdev ?: "ide-hd");
97256e79 806 }
4b1f8882
MP
807 return args;
808}
9e8458c0 809
2f447a36 810static void test_vm_prepare(const char *params, test_data *data)
4b1f8882 811{
2f447a36 812 char *args = test_acpi_create_args(data, params);
4b1f8882 813 data->qts = qtest_init(args);
2f447a36
IM
814 g_free(args);
815}
816
c0d19126 817static void process_acpi_tables_noexit(test_data *data)
2f447a36 818{
c1a9ac9b 819 test_acpi_load_tables(data);
ad6423a7 820
ab31b337
IM
821 if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
822 dump_aml_files(data, true);
7b9829bc 823 } else {
ab31b337 824 test_acpi_asl(data);
9e8458c0
MA
825 }
826
ce513b46
IM
827 /*
828 * TODO: make SMBIOS tests work with UEFI firmware,
829 * Bug on uefi-test-tools to provide entry point:
830 * https://bugs.launchpad.net/qemu/+bug/1821884
831 */
c1a9ac9b 832 if (!(data->uefi_fl1 && data->uefi_fl2)) {
33bff4a8
JS
833 SmbiosEntryPointType ep_type = test_smbios_entry_point(data);
834 test_smbios_structs(data, ep_type);
ce513b46 835 }
c0d19126 836}
eb386aac 837
c0d19126
IM
838static void process_acpi_tables(test_data *data)
839{
840 process_acpi_tables_noexit(data);
273e3d92 841 qtest_quit(data->qts);
2f447a36
IM
842}
843
844static void test_acpi_one(const char *params, test_data *data)
845{
846 test_vm_prepare(params, data);
847 process_acpi_tables(data);
ad6423a7
MT
848}
849
f4eda2d4
CM
850static uint8_t base_required_struct_types[] = {
851 0, 1, 3, 4, 16, 17, 19, 32, 127
852};
853
71f4be25 854static void test_acpi_piix4_tcg(void)
ad6423a7 855{
8ac2adf7
MA
856 test_data data;
857
ad6423a7
MT
858 /* Supplying -machine accel argument overrides the default (qtest).
859 * This is to make guest actually run.
860 */
9e8458c0
MA
861 memset(&data, 0, sizeof(data));
862 data.machine = MACHINE_PC;
f4eda2d4
CM
863 data.required_struct_types = base_required_struct_types;
864 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
947b205f 865 test_acpi_one(NULL, &data);
9e8458c0 866 free_test_data(&data);
71f4be25
PB
867}
868
3a9c86df
IM
869static void test_acpi_piix4_tcg_bridge(void)
870{
871 test_data data;
872
873 memset(&data, 0, sizeof(data));
874 data.machine = MACHINE_PC;
875 data.variant = ".bridge";
f4eda2d4
CM
876 data.required_struct_types = base_required_struct_types;
877 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
2f447a36
IM
878 test_vm_prepare("-S"
879 " -device pci-bridge,chassis_nr=1"
be8e3331
IM
880 " -device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2"
881 " -device pci-testdev,bus=pci.0,addr=5.0"
882 " -device pci-testdev,bus=pci.1", &data);
2f447a36
IM
883
884 /* hotplugged bridges section */
885 qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr",
886 "{'bus': 'pci.1', 'addr': '2.0', 'chassis_nr': 3 }");
887 qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr_multifunc",
888 "{'bus': 'pci.1', 'addr': '0xf.1', 'chassis_nr': 4 }");
889 qtest_qmp_device_add(data.qts, "pci-bridge", "hpbrhost",
890 "{'bus': 'pci.0', 'addr': '4.0', 'chassis_nr': 5 }");
be8e3331
IM
891 qtest_qmp_device_add(data.qts, "pci-testdev", "d1", "{'bus': 'pci.0' }");
892 qtest_qmp_device_add(data.qts, "pci-testdev", "d2", "{'bus': 'pci.1' }");
893 qtest_qmp_device_add(data.qts, "pci-testdev", "d3", "{'bus': 'hpbr', "
894 "'addr': '1.0' }");
2f447a36
IM
895 qtest_qmp_send(data.qts, "{'execute':'cont' }");
896 qtest_qmp_eventwait(data.qts, "RESUME");
897
c0d19126
IM
898 process_acpi_tables_noexit(&data);
899 free_test_data(&data);
900
901 /* check that reboot/reset doesn't change any ACPI tables */
902 qtest_qmp_send(data.qts, "{'execute':'system_reset' }");
2f447a36 903 process_acpi_tables(&data);
3a9c86df
IM
904 free_test_data(&data);
905}
906
27476395
AS
907static void test_acpi_piix4_no_root_hotplug(void)
908{
909 test_data data;
910
911 memset(&data, 0, sizeof(data));
912 data.machine = MACHINE_PC;
913 data.variant = ".roothp";
914 data.required_struct_types = base_required_struct_types;
915 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
916 test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
9ebb74d6 917 "-device pci-bridge,chassis_nr=1 "
be8e3331
IM
918 "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
919 "-device pci-testdev,bus=pci.0 "
920 "-device pci-testdev,bus=pci.1", &data);
27476395
AS
921 free_test_data(&data);
922}
923
5e3a4862
AS
924static void test_acpi_piix4_no_bridge_hotplug(void)
925{
926 test_data data;
927
928 memset(&data, 0, sizeof(data));
929 data.machine = MACHINE_PC;
930 data.variant = ".hpbridge";
931 data.required_struct_types = base_required_struct_types;
932 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
933 test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
9ebb74d6 934 "-device pci-bridge,chassis_nr=1 "
be8e3331
IM
935 "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
936 "-device pci-testdev,bus=pci.0 "
937 "-device pci-testdev,bus=pci.1,addr=2.0", &data);
5e3a4862
AS
938 free_test_data(&data);
939}
940
5645f996
AS
941static void test_acpi_piix4_no_acpi_pci_hotplug(void)
942{
943 test_data data;
944
945 memset(&data, 0, sizeof(data));
946 data.machine = MACHINE_PC;
947 data.variant = ".hpbrroot";
948 data.required_struct_types = base_required_struct_types;
949 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
950 test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
951 "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
b0b3b99e
IM
952 "-device pci-bridge,chassis_nr=1,addr=4.0 "
953 "-device pci-testdev,bus=pci.0,addr=5.0 "
954 "-device pci-testdev,bus=pci.0,addr=6.0,acpi-index=101 "
955 "-device pci-testdev,bus=pci.1,addr=1.0 "
956 "-device pci-testdev,bus=pci.1,addr=2.0,acpi-index=201 "
957 "-device pci-bridge,id=nhpbr,chassis_nr=2,shpc=off,addr=7.0 "
958 "-device pci-testdev,bus=nhpbr,addr=1.0,acpi-index=301 "
959 , &data);
5645f996
AS
960 free_test_data(&data);
961}
962
71f4be25
PB
963static void test_acpi_q35_tcg(void)
964{
965 test_data data;
8ac2adf7 966
9e8458c0
MA
967 memset(&data, 0, sizeof(data));
968 data.machine = MACHINE_Q35;
f4eda2d4
CM
969 data.required_struct_types = base_required_struct_types;
970 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
947b205f 971 test_acpi_one(NULL, &data);
8ac2adf7 972 free_test_data(&data);
e1647539
YF
973
974 data.smbios_cpu_max_speed = 3000;
975 data.smbios_cpu_curr_speed = 2600;
976 test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data);
977 free_test_data(&data);
ad6423a7
MT
978}
979
2d80b338
JS
980static void test_acpi_q35_tcg_core_count2(void)
981{
982 test_data data = {
983 .machine = MACHINE_Q35,
984 .variant = ".core-count2",
985 .required_struct_types = base_required_struct_types,
986 .required_struct_types_len = ARRAY_SIZE(base_required_struct_types),
987 .smbios_core_count = 0xFF,
988 .smbios_core_count2 = 275,
989 };
990
991 test_acpi_one("-machine smbios-entry-point-type=64 -smp 275", &data);
992 free_test_data(&data);
993}
994
3a9c86df
IM
995static void test_acpi_q35_tcg_bridge(void)
996{
997 test_data data;
998
999 memset(&data, 0, sizeof(data));
1000 data.machine = MACHINE_Q35;
1001 data.variant = ".bridge";
f4eda2d4
CM
1002 data.required_struct_types = base_required_struct_types;
1003 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
be8e3331
IM
1004 test_acpi_one("-device pci-bridge,chassis_nr=1,id=br1"
1005 " -device pci-testdev,bus=pcie.0"
1006 " -device pci-testdev,bus=br1", &data);
3a9c86df
IM
1007 free_test_data(&data);
1008}
1009
b0b3b99e
IM
1010static void test_acpi_q35_tcg_no_acpi_hotplug(void)
1011{
1012 test_data data;
1013
1014 memset(&data, 0, sizeof(data));
1015 data.machine = MACHINE_Q35;
1016 data.variant = ".noacpihp";
1017 data.required_struct_types = base_required_struct_types;
1018 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
1019 test_acpi_one("-global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=off"
1020 " -device pci-testdev,bus=pcie.0,acpi-index=101,addr=3.0"
1021 " -device pci-bridge,chassis_nr=1,id=shpcbr,addr=4.0"
1022 " -device pci-testdev,bus=shpcbr,addr=1.0,acpi-index=201"
1023 " -device pci-bridge,chassis_nr=2,shpc=off,id=noshpcbr,addr=5.0"
1024 " -device pci-testdev,bus=noshpcbr,addr=1.0,acpi-index=301"
1025 " -device pcie-root-port,id=hprp,port=0x0,chassis=1,addr=6.0"
1026 " -device pci-testdev,bus=hprp,acpi-index=401"
1027 " -device pcie-root-port,id=nohprp,port=0x0,chassis=2,hotplug=off,"
1028 "addr=7.0"
1029 " -device pci-testdev,bus=nohprp,acpi-index=501"
1030 " -device pcie-root-port,id=nohprpint,port=0x0,chassis=3,hotplug=off,"
bf5fde79
IM
1031 "multifunction=on,addr=8.0"
1032 " -device pci-testdev,bus=nohprpint,acpi-index=601,addr=8.1"
b0b3b99e
IM
1033 " -device pcie-root-port,id=hprp2,port=0x0,chassis=4,bus=nohprpint,"
1034 "addr=9.0"
bf5fde79 1035 " -device pci-testdev,bus=hprp2,acpi-index=602"
b0b3b99e
IM
1036 , &data);
1037 free_test_data(&data);
1038}
1039
04dd78b9
AS
1040static void test_acpi_q35_multif_bridge(void)
1041{
1042 test_data data = {
1043 .machine = MACHINE_Q35,
1044 .variant = ".multi-bridge",
1045 };
2f447a36 1046 test_vm_prepare("-S"
36773fae
IM
1047 " -device virtio-balloon,id=balloon0,addr=0x4.0x2"
1048 " -device pcie-root-port,id=rp0,multifunction=on,"
1049 "port=0x0,chassis=1,addr=0x2"
9ebb74d6
IM
1050 " -device pcie-root-port,id=rp1,port=0x1,chassis=2,addr=0x3.0x1"
1051 " -device pcie-root-port,id=rp2,port=0x0,chassis=3,bus=rp1,addr=0.0"
1052 " -device pci-bridge,bus=rp2,chassis_nr=4,id=br1"
1053 " -device pcie-root-port,id=rphptgt1,port=0x0,chassis=5,addr=2.1"
1054 " -device pcie-root-port,id=rphptgt2,port=0x0,chassis=6,addr=2.2"
be8e3331
IM
1055 " -device pcie-root-port,id=rphptgt3,port=0x0,chassis=7,addr=2.3"
1056 " -device pci-testdev,bus=pcie.0,addr=2.4"
bf5fde79 1057 " -device pci-testdev,bus=pcie.0,addr=2.5,acpi-index=102"
be8e3331 1058 " -device pci-testdev,bus=pcie.0,addr=5.0"
22c8dd00 1059 " -device pci-testdev,bus=pcie.0,addr=0xf.0,acpi-index=101"
be8e3331 1060 " -device pci-testdev,bus=rp0,addr=0.0"
0c3bf7c4
IM
1061 " -device pci-testdev,bus=br1"
1062 " -device pcie-root-port,id=rpnohp,chassis=8,addr=0xA.0,hotplug=off"
1063 " -device pcie-root-port,id=rp3,chassis=9,bus=rpnohp"
1064 , &data);
9ebb74d6 1065
2f447a36
IM
1066 /* hotplugged bridges section */
1067 qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr1",
1068 "{'bus': 'br1', 'addr': '6.0', 'chassis_nr': 128 }");
1069 qtest_qmp_device_add(data.qts, "pci-bridge", "hpbr2-multiif",
1070 "{ 'bus': 'br1', 'addr': '2.2', 'chassis_nr': 129 }");
1071 qtest_qmp_device_add(data.qts, "pcie-pci-bridge", "hpbr3",
be8e3331
IM
1072 "{'bus': 'rphptgt1', 'addr': '0.0' }");
1073 qtest_qmp_device_add(data.qts, "pcie-root-port", "hprp",
1074 "{'bus': 'rphptgt2', 'addr': '0.0' }");
1075 qtest_qmp_device_add(data.qts, "pci-testdev", "hpnic",
1076 "{'bus': 'rphptgt3', 'addr': '0.0' }");
2f447a36
IM
1077 qtest_qmp_send(data.qts, "{'execute':'cont' }");
1078 qtest_qmp_eventwait(data.qts, "RESUME");
1079
c0d19126
IM
1080 process_acpi_tables_noexit(&data);
1081 free_test_data(&data);
1082
1083 /* check that reboot/reset doesn't change any ACPI tables */
1084 qtest_qmp_send(data.qts, "{'execute':'system_reset' }");
2f447a36 1085 process_acpi_tables(&data);
04dd78b9
AS
1086 free_test_data(&data);
1087}
1088
0259e966
LE
1089static void test_acpi_q35_tcg_mmio64(void)
1090{
1091 test_data data = {
1092 .machine = MACHINE_Q35,
1093 .variant = ".mmio64",
1094 .required_struct_types = base_required_struct_types,
1095 .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
1096 };
1097
1098 test_acpi_one("-m 128M,slots=1,maxmem=2G "
af135030
IM
1099 "-object memory-backend-ram,id=ram0,size=128M "
1100 "-numa node,memdev=ram0 "
0259e966
LE
1101 "-device pci-testdev,membar=2G",
1102 &data);
1103 free_test_data(&data);
1104}
1105
6b9c1dd2
IM
1106static void test_acpi_piix4_tcg_cphp(void)
1107{
1108 test_data data;
1109
1110 memset(&data, 0, sizeof(data));
1111 data.machine = MACHINE_PC;
1112 data.variant = ".cphp";
d6309c17 1113 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
af135030
IM
1114 " -object memory-backend-ram,id=ram0,size=64M"
1115 " -object memory-backend-ram,id=ram1,size=64M"
1116 " -numa node,memdev=ram0 -numa node,memdev=ram1"
fda4096f 1117 " -numa dist,src=0,dst=1,val=21",
6b9c1dd2
IM
1118 &data);
1119 free_test_data(&data);
1120}
1121
1122static void test_acpi_q35_tcg_cphp(void)
1123{
1124 test_data data;
1125
1126 memset(&data, 0, sizeof(data));
1127 data.machine = MACHINE_Q35;
1128 data.variant = ".cphp";
d6309c17 1129 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
af135030
IM
1130 " -object memory-backend-ram,id=ram0,size=64M"
1131 " -object memory-backend-ram,id=ram1,size=64M"
1132 " -numa node,memdev=ram0 -numa node,memdev=ram1"
fda4096f 1133 " -numa dist,src=0,dst=1,val=21",
6b9c1dd2
IM
1134 &data);
1135 free_test_data(&data);
1136}
1137
f4eda2d4
CM
1138static uint8_t ipmi_required_struct_types[] = {
1139 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
1140};
1141
1142static void test_acpi_q35_tcg_ipmi(void)
1143{
1144 test_data data;
1145
1146 memset(&data, 0, sizeof(data));
1147 data.machine = MACHINE_Q35;
1148 data.variant = ".ipmibt";
1149 data.required_struct_types = ipmi_required_struct_types;
1150 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
947b205f 1151 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
f4eda2d4
CM
1152 " -device isa-ipmi-bt,bmc=bmc0",
1153 &data);
1154 free_test_data(&data);
1155}
1156
ac70b4a3
IM
1157static void test_acpi_q35_tcg_smbus_ipmi(void)
1158{
1159 test_data data;
1160
1161 memset(&data, 0, sizeof(data));
1162 data.machine = MACHINE_Q35;
1163 data.variant = ".ipmismbus";
1164 data.required_struct_types = ipmi_required_struct_types;
1165 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
1166 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1167 " -device smbus-ipmi,bmc=bmc0",
1168 &data);
1169 free_test_data(&data);
1170}
1171
f4eda2d4
CM
1172static void test_acpi_piix4_tcg_ipmi(void)
1173{
1174 test_data data;
1175
1176 /* Supplying -machine accel argument overrides the default (qtest).
1177 * This is to make guest actually run.
1178 */
1179 memset(&data, 0, sizeof(data));
1180 data.machine = MACHINE_PC;
1181 data.variant = ".ipmikcs";
1182 data.required_struct_types = ipmi_required_struct_types;
1183 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
947b205f 1184 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
f4eda2d4
CM
1185 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
1186 &data);
1187 free_test_data(&data);
1188}
1189
4462fc60
IM
1190static void test_acpi_q35_tcg_memhp(void)
1191{
1192 test_data data;
1193
1194 memset(&data, 0, sizeof(data));
1195 data.machine = MACHINE_Q35;
1196 data.variant = ".memhp";
fda4096f 1197 test_acpi_one(" -m 128,slots=3,maxmem=1G"
af135030
IM
1198 " -object memory-backend-ram,id=ram0,size=64M"
1199 " -object memory-backend-ram,id=ram1,size=64M"
1200 " -numa node,memdev=ram0 -numa node,memdev=ram1"
fda4096f
HC
1201 " -numa dist,src=0,dst=1,val=21",
1202 &data);
4462fc60
IM
1203 free_test_data(&data);
1204}
1205
1206static void test_acpi_piix4_tcg_memhp(void)
1207{
1208 test_data data;
1209
1210 memset(&data, 0, sizeof(data));
1211 data.machine = MACHINE_PC;
1212 data.variant = ".memhp";
fda4096f 1213 test_acpi_one(" -m 128,slots=3,maxmem=1G"
af135030
IM
1214 " -object memory-backend-ram,id=ram0,size=64M"
1215 " -object memory-backend-ram,id=ram1,size=64M"
1216 " -numa node,memdev=ram0 -numa node,memdev=ram1"
fda4096f
HC
1217 " -numa dist,src=0,dst=1,val=21",
1218 &data);
4462fc60
IM
1219 free_test_data(&data);
1220}
1221
0dabb2e8
IY
1222static void test_acpi_piix4_tcg_nosmm(void)
1223{
1224 test_data data;
1225
1226 memset(&data, 0, sizeof(data));
1227 data.machine = MACHINE_PC;
1228 data.variant = ".nosmm";
1229 test_acpi_one("-machine smm=off", &data);
1230 free_test_data(&data);
1231}
1232
1233static void test_acpi_piix4_tcg_smm_compat(void)
1234{
1235 test_data data;
1236
1237 memset(&data, 0, sizeof(data));
1238 data.machine = MACHINE_PC;
1239 data.variant = ".smm-compat";
1240 test_acpi_one("-global PIIX4_PM.smm-compat=on", &data);
1241 free_test_data(&data);
1242}
1243
1244static void test_acpi_piix4_tcg_smm_compat_nosmm(void)
1245{
1246 test_data data;
1247
1248 memset(&data, 0, sizeof(data));
1249 data.machine = MACHINE_PC;
1250 data.variant = ".smm-compat-nosmm";
1251 test_acpi_one("-global PIIX4_PM.smm-compat=on -machine smm=off", &data);
1252 free_test_data(&data);
1253}
1254
9a70e043
IY
1255static void test_acpi_piix4_tcg_nohpet(void)
1256{
1257 test_data data;
1258
1259 memset(&data, 0, sizeof(data));
1260 data.machine = MACHINE_PC;
9a2112f9 1261 data.machine_param = ",hpet=off";
9a70e043 1262 data.variant = ".nohpet";
9a2112f9 1263 test_acpi_one(NULL, &data);
9a70e043
IY
1264 free_test_data(&data);
1265}
1266
d82c4f82
DL
1267static void test_acpi_q35_tcg_numamem(void)
1268{
1269 test_data data;
1270
1271 memset(&data, 0, sizeof(data));
1272 data.machine = MACHINE_Q35;
1273 data.variant = ".numamem";
af135030
IM
1274 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1275 " -numa node -numa node,memdev=ram0", &data);
d82c4f82
DL
1276 free_test_data(&data);
1277}
1278
80a2f338
IM
1279static void test_acpi_q35_kvm_xapic(void)
1280{
1281 test_data data;
1282
1283 memset(&data, 0, sizeof(data));
1284 data.machine = MACHINE_Q35;
1285 data.variant = ".xapic";
1286 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1287 " -numa node -numa node,memdev=ram0"
1288 " -machine kernel-irqchip=on -smp 1,maxcpus=288", &data);
1289 free_test_data(&data);
1290}
1291
0dabb2e8
IY
1292static void test_acpi_q35_tcg_nosmm(void)
1293{
1294 test_data data;
1295
1296 memset(&data, 0, sizeof(data));
1297 data.machine = MACHINE_Q35;
1298 data.variant = ".nosmm";
1299 test_acpi_one("-machine smm=off", &data);
1300 free_test_data(&data);
1301}
1302
1303static void test_acpi_q35_tcg_smm_compat(void)
1304{
1305 test_data data;
1306
1307 memset(&data, 0, sizeof(data));
1308 data.machine = MACHINE_Q35;
1309 data.variant = ".smm-compat";
1310 test_acpi_one("-global ICH9-LPC.smm-compat=on", &data);
1311 free_test_data(&data);
1312}
1313
1314static void test_acpi_q35_tcg_smm_compat_nosmm(void)
1315{
1316 test_data data;
1317
1318 memset(&data, 0, sizeof(data));
1319 data.machine = MACHINE_Q35;
1320 data.variant = ".smm-compat-nosmm";
1321 test_acpi_one("-global ICH9-LPC.smm-compat=on -machine smm=off", &data);
1322 free_test_data(&data);
1323}
1324
9a70e043
IY
1325static void test_acpi_q35_tcg_nohpet(void)
1326{
1327 test_data data;
1328
1329 memset(&data, 0, sizeof(data));
1330 data.machine = MACHINE_Q35;
9a2112f9 1331 data.machine_param = ",hpet=off";
9a70e043 1332 data.variant = ".nohpet";
9a2112f9 1333 test_acpi_one(NULL, &data);
9a70e043
IY
1334 free_test_data(&data);
1335}
1336
0ff92b6d
IM
1337static void test_acpi_q35_kvm_dmar(void)
1338{
1339 test_data data;
1340
1341 memset(&data, 0, sizeof(data));
1342 data.machine = MACHINE_Q35;
1343 data.variant = ".dmar";
1344 test_acpi_one("-machine kernel-irqchip=split -accel kvm"
1345 " -device intel-iommu,intremap=on,device-iotlb=on", &data);
1346 free_test_data(&data);
1347}
1348
a4c730cb
IM
1349static void test_acpi_q35_tcg_ivrs(void)
1350{
1351 test_data data;
1352
1353 memset(&data, 0, sizeof(data));
1354 data.machine = MACHINE_Q35;
1355 data.variant = ".ivrs";
1356 data.tcg_only = true,
1357 test_acpi_one(" -device amd-iommu", &data);
1358 free_test_data(&data);
1359}
1360
d82c4f82
DL
1361static void test_acpi_piix4_tcg_numamem(void)
1362{
1363 test_data data;
1364
1365 memset(&data, 0, sizeof(data));
1366 data.machine = MACHINE_PC;
1367 data.variant = ".numamem";
af135030
IM
1368 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1369 " -numa node -numa node,memdev=ram0", &data);
d82c4f82
DL
1370 free_test_data(&data);
1371}
1372
5da7c35e
EA
1373uint64_t tpm_tis_base_addr;
1374
1375static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
09b20a14 1376 uint64_t base, enum TPMVersion tpm_version)
5da7c35e
EA
1377{
1378 gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
1379 machine, tpm_if);
1380 char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
9bd0e32a 1381 TPMTestState test;
5da7c35e
EA
1382 test_data data;
1383 GThread *thread;
bf8443ef
SB
1384 const char *suffix = tpm_version == TPM_VERSION_2_0 ? "tpm2" : "tpm12";
1385 char *args, *variant = g_strdup_printf(".%s.%s", tpm_if, suffix);
5da7c35e
EA
1386
1387 tpm_tis_base_addr = base;
1388
1389 module_call_init(MODULE_INIT_QOM);
1390
1391 test.addr = g_new0(SocketAddress, 1);
1392 test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
1393 test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
1394 g_mutex_init(&test.data_mutex);
1395 g_cond_init(&test.data_cond);
1396 test.data_cond_signal = false;
09b20a14 1397 test.tpm_version = tpm_version;
5da7c35e
EA
1398
1399 thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
1400 tpm_emu_test_wait_cond(&test);
1401
1402 memset(&data, 0, sizeof(data));
1403 data.machine = machine;
1404 data.variant = variant;
1405
1406 args = g_strdup_printf(
1407 " -chardev socket,id=chr,path=%s"
1408 " -tpmdev emulator,id=dev,chardev=chr"
1409 " -device tpm-%s,tpmdev=dev",
1410 test.addr->u.q_unix.path, tpm_if);
1411
1412 test_acpi_one(args, &data);
1413
1414 g_thread_join(thread);
1415 g_unlink(test.addr->u.q_unix.path);
1416 qapi_free_SocketAddress(test.addr);
1417 g_rmdir(tmp_path);
1418 g_free(variant);
1419 g_free(tmp_path);
1420 g_free(tmp_dir_name);
82e258db 1421 g_free(args);
5da7c35e
EA
1422 free_test_data(&data);
1423}
1424
33660128 1425static void test_acpi_q35_tcg_tpm2_tis(void)
5da7c35e 1426{
09b20a14 1427 test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_2_0);
5da7c35e
EA
1428}
1429
33660128
SB
1430static void test_acpi_q35_tcg_tpm12_tis(void)
1431{
1432 test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_1_2);
1433}
1434
adae91ce
HZ
1435static void test_acpi_tcg_dimm_pxm(const char *machine)
1436{
1437 test_data data;
1438
1439 memset(&data, 0, sizeof(data));
1440 data.machine = machine;
1441 data.variant = ".dimmpxm";
11c39b5c 1442 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
adae91ce
HZ
1443 " -smp 4,sockets=4"
1444 " -m 128M,slots=3,maxmem=1G"
af135030
IM
1445 " -object memory-backend-ram,id=ram0,size=32M"
1446 " -object memory-backend-ram,id=ram1,size=32M"
1447 " -object memory-backend-ram,id=ram2,size=32M"
1448 " -object memory-backend-ram,id=ram3,size=32M"
1449 " -numa node,memdev=ram0,nodeid=0"
1450 " -numa node,memdev=ram1,nodeid=1"
1451 " -numa node,memdev=ram2,nodeid=2"
1452 " -numa node,memdev=ram3,nodeid=3"
adae91ce
HZ
1453 " -numa cpu,node-id=0,socket-id=0"
1454 " -numa cpu,node-id=1,socket-id=1"
1455 " -numa cpu,node-id=2,socket-id=2"
1456 " -numa cpu,node-id=3,socket-id=3"
af135030 1457 " -object memory-backend-ram,id=ram4,size=128M"
adae91ce 1458 " -object memory-backend-ram,id=nvm0,size=128M"
af135030 1459 " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
adae91ce
HZ
1460 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
1461 &data);
1462 free_test_data(&data);
1463}
1464
1465static void test_acpi_q35_tcg_dimm_pxm(void)
1466{
1467 test_acpi_tcg_dimm_pxm(MACHINE_Q35);
1468}
1469
1470static void test_acpi_piix4_tcg_dimm_pxm(void)
1471{
1472 test_acpi_tcg_dimm_pxm(MACHINE_PC);
1473}
1474
669c7743
SK
1475static void test_acpi_virt_tcg_memhp(void)
1476{
1477 test_data data = {
1478 .machine = "virt",
6f6e1698 1479 .tcg_only = true,
669c7743
SK
1480 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1481 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1482 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1483 .ram_start = 0x40000000ULL,
1484 .scan_len = 256ULL * 1024 * 1024,
1485 };
1486
1487 data.variant = ".memhp";
62293b4f
SK
1488 test_acpi_one(" -machine nvdimm=on"
1489 " -cpu cortex-a57"
669c7743
SK
1490 " -m 256M,slots=3,maxmem=1G"
1491 " -object memory-backend-ram,id=ram0,size=128M"
1492 " -object memory-backend-ram,id=ram1,size=128M"
1493 " -numa node,memdev=ram0 -numa node,memdev=ram1"
62293b4f
SK
1494 " -numa dist,src=0,dst=1,val=21"
1495 " -object memory-backend-ram,id=ram2,size=128M"
1496 " -object memory-backend-ram,id=nvm0,size=128M"
1497 " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
1498 " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
669c7743 1499 &data);
7cb23078 1500
669c7743
SK
1501 free_test_data(&data);
1502
1503}
1504
62b61b85
GH
1505static void test_acpi_microvm_prepare(test_data *data)
1506{
1507 memset(data, 0, sizeof(*data));
1508 data->machine = "microvm";
1509 data->required_struct_types = NULL; /* no smbios */
1510 data->required_struct_types_len = 0;
1511 data->blkdev = "virtio-blk-device";
1512}
1513
c06cbf3d
GH
1514static void test_acpi_microvm_tcg(void)
1515{
1516 test_data data;
1517
62b61b85 1518 test_acpi_microvm_prepare(&data);
4d01b899 1519 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off",
c06cbf3d
GH
1520 &data);
1521 free_test_data(&data);
1522}
1523
f072fd2f
GH
1524static void test_acpi_microvm_usb_tcg(void)
1525{
1526 test_data data;
1527
1528 test_acpi_microvm_prepare(&data);
1529 data.variant = ".usb";
4d01b899 1530 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off",
f072fd2f
GH
1531 &data);
1532 free_test_data(&data);
1533}
1534
0c491c84
GH
1535static void test_acpi_microvm_rtc_tcg(void)
1536{
1537 test_data data;
1538
1539 test_acpi_microvm_prepare(&data);
1540 data.variant = ".rtc";
4d01b899 1541 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on",
0c491c84
GH
1542 &data);
1543 free_test_data(&data);
1544}
1545
18bb73b3
GH
1546static void test_acpi_microvm_pcie_tcg(void)
1547{
1548 test_data data;
1549
1550 test_acpi_microvm_prepare(&data);
1551 data.variant = ".pcie";
1552 data.tcg_only = true; /* need constant host-phys-bits */
4d01b899 1553 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on",
18bb73b3
GH
1554 &data);
1555 free_test_data(&data);
1556}
1557
38ee397f
GH
1558static void test_acpi_microvm_ioapic2_tcg(void)
1559{
1560 test_data data;
1561
1562 test_acpi_microvm_prepare(&data);
1563 data.variant = ".ioapic2";
1564 test_acpi_one(" -machine microvm,acpi=on,ioapic2=on,rtc=off",
1565 &data);
1566 free_test_data(&data);
1567}
1568
669c7743
SK
1569static void test_acpi_virt_tcg_numamem(void)
1570{
1571 test_data data = {
1572 .machine = "virt",
6f6e1698 1573 .tcg_only = true,
669c7743
SK
1574 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1575 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1576 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1577 .ram_start = 0x40000000ULL,
1578 .scan_len = 128ULL * 1024 * 1024,
1579 };
1580
1581 data.variant = ".numamem";
1582 test_acpi_one(" -cpu cortex-a57"
1583 " -object memory-backend-ram,id=ram0,size=128M"
1584 " -numa node,memdev=ram0",
1585 &data);
1586
1587 free_test_data(&data);
1588
1589}
1590
1da638b1
YM
1591static void test_acpi_virt_tcg_pxb(void)
1592{
1593 test_data data = {
1594 .machine = "virt",
1595 .tcg_only = true,
1596 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1597 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1598 .ram_start = 0x40000000ULL,
1599 .scan_len = 128ULL * 1024 * 1024,
1600 };
1601 /*
1602 * While using -cdrom, the cdrom would auto plugged into pxb-pcie,
1603 * the reason is the bus of pxb-pcie is also root bus, it would lead
1604 * to the error only PCI/PCIE bridge could plug onto pxb.
1605 * Therefore,thr cdrom is defined and plugged onto the scsi controller
1606 * to solve the conflicts.
1607 */
1608 data.variant = ".pxb";
1609 test_acpi_one(" -device pcie-root-port,chassis=1,id=pci.1"
1610 " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
1611 " -drive file="
1612 "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2,"
1613 "if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on"
1614 " -device scsi-cd,bus=scsi0.0,scsi-id=0,"
1615 "drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1"
1616 " -cpu cortex-a57"
1617 " -device pxb-pcie,bus_nr=128",
1618 &data);
7cb23078 1619
1da638b1
YM
1620 free_test_data(&data);
1621}
1da638b1 1622
1c8f85d9
TX
1623static void test_acpi_tcg_acpi_hmat(const char *machine)
1624{
1625 test_data data;
1626
1627 memset(&data, 0, sizeof(data));
1628 data.machine = machine;
1629 data.variant = ".acpihmat";
1630 test_acpi_one(" -machine hmat=on"
1631 " -smp 2,sockets=2"
1632 " -m 128M,slots=2,maxmem=1G"
1633 " -object memory-backend-ram,size=64M,id=m0"
1634 " -object memory-backend-ram,size=64M,id=m1"
1635 " -numa node,nodeid=0,memdev=m0"
1636 " -numa node,nodeid=1,memdev=m1,initiator=0"
1637 " -numa cpu,node-id=0,socket-id=0"
1638 " -numa cpu,node-id=0,socket-id=1"
1639 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1640 "data-type=access-latency,latency=1"
1641 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1642 "data-type=access-bandwidth,bandwidth=65534M"
1643 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1644 "data-type=access-latency,latency=65534"
1645 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1646 "data-type=access-bandwidth,bandwidth=32767M"
1647 " -numa hmat-cache,node-id=0,size=10K,level=1,"
1648 "associativity=direct,policy=write-back,line=8"
1649 " -numa hmat-cache,node-id=1,size=10K,level=1,"
1650 "associativity=direct,policy=write-back,line=8",
1651 &data);
1652 free_test_data(&data);
1653}
1654
1655static void test_acpi_q35_tcg_acpi_hmat(void)
1656{
1657 test_acpi_tcg_acpi_hmat(MACHINE_Q35);
1658}
1659
1660static void test_acpi_piix4_tcg_acpi_hmat(void)
1661{
1662 test_acpi_tcg_acpi_hmat(MACHINE_PC);
1663}
1664
b077b070
HA
1665static void test_acpi_virt_tcg_acpi_hmat(void)
1666{
1667 test_data data = {
1668 .machine = "virt",
1669 .tcg_only = true,
1670 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1671 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1672 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1673 .ram_start = 0x40000000ULL,
1674 .scan_len = 128ULL * 1024 * 1024,
1675 };
1676
1677 data.variant = ".acpihmatvirt";
1678
1679 test_acpi_one(" -machine hmat=on"
1680 " -cpu cortex-a57"
1681 " -smp 4,sockets=2"
e8d1e0cd
GH
1682 " -m 384M"
1683 " -object memory-backend-ram,size=128M,id=ram0"
1684 " -object memory-backend-ram,size=128M,id=ram1"
b077b070
HA
1685 " -object memory-backend-ram,size=128M,id=ram2"
1686 " -numa node,nodeid=0,memdev=ram0"
1687 " -numa node,nodeid=1,memdev=ram1"
1688 " -numa node,nodeid=2,memdev=ram2"
1689 " -numa cpu,node-id=0,socket-id=0"
1690 " -numa cpu,node-id=0,socket-id=0"
1691 " -numa cpu,node-id=1,socket-id=1"
1692 " -numa cpu,node-id=1,socket-id=1"
1693 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1694 "data-type=access-latency,latency=10"
1695 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1696 "data-type=access-bandwidth,bandwidth=10485760"
1697 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1698 "data-type=access-latency,latency=20"
1699 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1700 "data-type=access-bandwidth,bandwidth=5242880"
1701 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1702 "data-type=access-latency,latency=30"
1703 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1704 "data-type=access-bandwidth,bandwidth=1048576"
1705 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1706 "data-type=access-latency,latency=20"
1707 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1708 "data-type=access-bandwidth,bandwidth=5242880"
1709 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1710 "data-type=access-latency,latency=10"
1711 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1712 "data-type=access-bandwidth,bandwidth=10485760"
1713 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1714 "data-type=access-latency,latency=30"
1715 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1716 "data-type=access-bandwidth,bandwidth=1048576",
1717 &data);
1718
1719 free_test_data(&data);
1720}
1721
a046f1d7
BG
1722static void test_acpi_q35_tcg_acpi_hmat_noinitiator(void)
1723{
1724 test_data data;
1725
1726 memset(&data, 0, sizeof(data));
1727 data.machine = MACHINE_Q35;
1728 data.variant = ".acpihmat-noinitiator";
1729 test_acpi_one(" -machine hmat=on"
1730 " -smp 4,sockets=2"
1731 " -m 128M"
1732 " -object memory-backend-ram,size=32M,id=ram0"
1733 " -object memory-backend-ram,size=32M,id=ram1"
1734 " -object memory-backend-ram,size=64M,id=ram2"
1735 " -numa node,nodeid=0,memdev=ram0"
1736 " -numa node,nodeid=1,memdev=ram1"
1737 " -numa node,nodeid=2,memdev=ram2"
1738 " -numa cpu,node-id=0,socket-id=0"
1739 " -numa cpu,node-id=0,socket-id=0"
1740 " -numa cpu,node-id=1,socket-id=1"
1741 " -numa cpu,node-id=1,socket-id=1"
1742 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1743 "data-type=access-latency,latency=10"
1744 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1745 "data-type=access-bandwidth,bandwidth=10485760"
1746 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1747 "data-type=access-latency,latency=20"
1748 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1749 "data-type=access-bandwidth,bandwidth=5242880"
1750 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1751 "data-type=access-latency,latency=30"
1752 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1753 "data-type=access-bandwidth,bandwidth=1048576"
1754 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1755 "data-type=access-latency,latency=20"
1756 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1757 "data-type=access-bandwidth,bandwidth=5242880"
1758 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1759 "data-type=access-latency,latency=10"
1760 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1761 "data-type=access-bandwidth,bandwidth=10485760"
1762 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1763 "data-type=access-latency,latency=30"
1764 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1765 "data-type=access-bandwidth,bandwidth=1048576",
1766 &data);
1767 free_test_data(&data);
1768}
1769
84efa8aa 1770#ifdef CONFIG_POSIX
646a793c
ED
1771static void test_acpi_erst(const char *machine)
1772{
1773 gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
1774 gchar *params;
1775 test_data data;
1776
1777 memset(&data, 0, sizeof(data));
1778 data.machine = machine;
1779 data.variant = ".acpierst";
1780 params = g_strdup_printf(
1781 " -object memory-backend-file,id=erstnvram,"
1782 "mem-path=%s,size=0x10000,share=on"
1783 " -device acpi-erst,memdev=erstnvram", tmp_path);
1784 test_acpi_one(params, &data);
1785 free_test_data(&data);
1786 g_free(params);
1787 g_assert(g_rmdir(tmp_path) == 0);
1788 g_free(tmp_path);
1789}
1790
1791static void test_acpi_piix4_acpi_erst(void)
1792{
1793 test_acpi_erst(MACHINE_PC);
1794}
1795
1796static void test_acpi_q35_acpi_erst(void)
1797{
1798 test_acpi_erst(MACHINE_Q35);
1799}
1800
1801static void test_acpi_microvm_acpi_erst(void)
1802{
1803 gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
1804 gchar *params;
1805 test_data data;
1806
1807 test_acpi_microvm_prepare(&data);
1808 data.variant = ".pcie";
1809 data.tcg_only = true; /* need constant host-phys-bits */
1810 params = g_strdup_printf(" -machine microvm,"
1811 "acpi=on,ioapic2=off,rtc=off,pcie=on"
1812 " -object memory-backend-file,id=erstnvram,"
1813 "mem-path=%s,size=0x10000,share=on"
1814 " -device acpi-erst,memdev=erstnvram", tmp_path);
1815 test_acpi_one(params, &data);
1816 g_free(params);
1817 g_assert(g_rmdir(tmp_path) == 0);
1818 g_free(tmp_path);
1819 free_test_data(&data);
1820}
84efa8aa 1821#endif /* CONFIG_POSIX */
646a793c 1822
ab6b6a77
IM
1823static void test_acpi_virt_tcg(void)
1824{
1825 test_data data = {
1826 .machine = "virt",
6f6e1698 1827 .tcg_only = true,
ab6b6a77
IM
1828 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1829 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1830 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1831 .ram_start = 0x40000000ULL,
1832 .scan_len = 128ULL * 1024 * 1024,
1833 };
1834
e1647539
YF
1835 data.smbios_cpu_max_speed = 2900;
1836 data.smbios_cpu_curr_speed = 2700;
1837 test_acpi_one("-cpu cortex-a57 "
1838 "-smbios type=4,max-speed=2900,current-speed=2700", &data);
1839 free_test_data(&data);
ab6b6a77
IM
1840}
1841
46bda3e4
YY
1842static void test_acpi_virt_tcg_topology(void)
1843{
1844 test_data data = {
1845 .machine = "virt",
1846 .variant = ".topology",
1847 .tcg_only = true,
1848 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1849 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1850 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1851 .ram_start = 0x40000000ULL,
1852 .scan_len = 128ULL * 1024 * 1024,
1853 };
1854
1855 test_acpi_one("-cpu cortex-a57 "
1856 "-smp sockets=1,clusters=2,cores=2,threads=2", &data);
1857 free_test_data(&data);
1858}
1859
39d7554b
JPB
1860static void test_acpi_q35_viot(void)
1861{
1862 test_data data = {
1863 .machine = MACHINE_Q35,
1864 .variant = ".viot",
1865 };
1866
1867 /*
1868 * To keep things interesting, two buses bypass the IOMMU.
1869 * VIOT should only describes the other two buses.
1870 */
1871 test_acpi_one("-machine default_bus_bypass_iommu=on "
1872 "-device virtio-iommu-pci "
1873 "-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 "
1874 "-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on "
1875 "-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0",
1876 &data);
1877 free_test_data(&data);
1878}
1879
84efa8aa 1880#ifdef CONFIG_POSIX
65fc04ff
JC
1881static void test_acpi_q35_cxl(void)
1882{
1883 gchar *tmp_path = g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL);
1884 gchar *params;
1885
1886 test_data data = {
1887 .machine = MACHINE_Q35,
1888 .variant = ".cxl",
1889 };
1890 /*
1891 * A complex CXL setup.
1892 */
1893 params = g_strdup_printf(" -machine cxl=on"
1894 " -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M"
1895 " -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M"
1896 " -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M"
1897 " -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M"
1898 " -object memory-backend-file,id=lsa1,mem-path=%s,size=256M"
1899 " -object memory-backend-file,id=lsa2,mem-path=%s,size=256M"
1900 " -object memory-backend-file,id=lsa3,mem-path=%s,size=256M"
1901 " -object memory-backend-file,id=lsa4,mem-path=%s,size=256M"
1902 " -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1"
1903 " -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2"
1904 " -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2"
1905 " -device cxl-type3,bus=rp1,memdev=cxl-mem1,lsa=lsa1"
1906 " -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3"
1907 " -device cxl-type3,bus=rp2,memdev=cxl-mem2,lsa=lsa2"
1908 " -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5"
1909 " -device cxl-type3,bus=rp3,memdev=cxl-mem3,lsa=lsa3"
1910 " -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6"
1911 " -device cxl-type3,bus=rp4,memdev=cxl-mem4,lsa=lsa4"
03b39fcf
JC
1912 " -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k,"
1913 "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",
65fc04ff
JC
1914 tmp_path, tmp_path, tmp_path, tmp_path,
1915 tmp_path, tmp_path, tmp_path, tmp_path);
1916 test_acpi_one(params, &data);
1917
1918 g_free(params);
1919 g_assert(g_rmdir(tmp_path) == 0);
1920 g_free(tmp_path);
1921 free_test_data(&data);
1922}
84efa8aa 1923#endif /* CONFIG_POSIX */
65fc04ff 1924
39d7554b
JPB
1925static void test_acpi_virt_viot(void)
1926{
1927 test_data data = {
1928 .machine = "virt",
69a80f14 1929 .tcg_only = true,
39d7554b
JPB
1930 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1931 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1932 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1933 .ram_start = 0x40000000ULL,
1934 .scan_len = 128ULL * 1024 * 1024,
1935 };
1936
7cb23078
IM
1937 test_acpi_one("-cpu cortex-a57 "
1938 "-device virtio-iommu-pci", &data);
39d7554b
JPB
1939 free_test_data(&data);
1940}
1941
4b83dd0e
BM
1942#ifndef _WIN32
1943# define DEV_NULL "/dev/null"
1944#else
1945# define DEV_NULL "nul"
1946#endif
1947
11edfabe
IM
1948static void test_acpi_q35_slic(void)
1949{
1950 test_data data = {
1951 .machine = MACHINE_Q35,
1952 .variant = ".slic",
1953 };
1954
4b83dd0e
BM
1955 test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
1956 "oem_rev=00002210,asl_compiler_id=qemu,"
1957 "asl_compiler_rev=00000000,data=" DEV_NULL,
11edfabe
IM
1958 &data);
1959 free_test_data(&data);
1960}
1961
cde55744
IM
1962static void test_acpi_q35_applesmc(void)
1963{
1964 test_data data = {
1965 .machine = MACHINE_Q35,
1966 .variant = ".applesmc",
1967 };
1968
888fbaaf
IM
1969 /* supply fake 64-byte OSK to silence missing key warning */
1970 test_acpi_one("-device isa-applesmc,osk=any64characterfakeoskisenough"
1971 "topreventinvalidkeywarningsonstderr", &data);
cde55744
IM
1972 free_test_data(&data);
1973}
1974
fd7bcffe
IM
1975static void test_acpi_q35_pvpanic_isa(void)
1976{
1977 test_data data = {
1978 .machine = MACHINE_Q35,
1979 .variant = ".pvpanic-isa",
1980 };
1981
1982 test_acpi_one("-device pvpanic", &data);
1983 free_test_data(&data);
1984}
1985
4b1f8882
MP
1986static void test_oem_fields(test_data *data)
1987{
1988 int i;
4b1f8882 1989
4b1f8882
MP
1990 for (i = 0; i < data->tables->len; ++i) {
1991 AcpiSdtTable *sdt;
1992
1993 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
1994 /* FACS doesn't have OEMID and OEMTABLEID fields */
1995 if (compare_signature(sdt, "FACS")) {
1996 continue;
1997 }
1998
408ca926
IM
1999 g_assert(strncmp((char *)sdt->aml + 10, OEM_ID, 6) == 0);
2000 g_assert(strncmp((char *)sdt->aml + 16, OEM_TABLE_ID, 8) == 0);
4b1f8882
MP
2001 }
2002}
2003
b3ad62c1 2004static void test_acpi_piix4_oem_fields(void)
4b1f8882
MP
2005{
2006 test_data data;
2007 char *args;
2008
2009 memset(&data, 0, sizeof(data));
2010 data.machine = MACHINE_PC;
2011 data.required_struct_types = base_required_struct_types;
2012 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
2013
c1a9ac9b 2014 args = test_acpi_create_args(&data, OEM_TEST_ARGS);
4b1f8882 2015 data.qts = qtest_init(args);
c1a9ac9b 2016 test_acpi_load_tables(&data);
4b1f8882
MP
2017 test_oem_fields(&data);
2018 qtest_quit(data.qts);
2019 free_test_data(&data);
2020 g_free(args);
2021}
2022
b3ad62c1 2023static void test_acpi_q35_oem_fields(void)
4b1f8882
MP
2024{
2025 test_data data;
2026 char *args;
2027
2028 memset(&data, 0, sizeof(data));
2029 data.machine = MACHINE_Q35;
2030 data.required_struct_types = base_required_struct_types;
2031 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
2032
c1a9ac9b 2033 args = test_acpi_create_args(&data, OEM_TEST_ARGS);
4b1f8882 2034 data.qts = qtest_init(args);
c1a9ac9b 2035 test_acpi_load_tables(&data);
4b1f8882
MP
2036 test_oem_fields(&data);
2037 qtest_quit(data.qts);
2038 free_test_data(&data);
2039 g_free(args);
2040}
2041
b3ad62c1 2042static void test_acpi_microvm_oem_fields(void)
4b1f8882
MP
2043{
2044 test_data data;
2045 char *args;
2046
2047 test_acpi_microvm_prepare(&data);
2048
2049 args = test_acpi_create_args(&data,
c1a9ac9b 2050 OEM_TEST_ARGS",acpi=on");
4b1f8882 2051 data.qts = qtest_init(args);
c1a9ac9b 2052 test_acpi_load_tables(&data);
4b1f8882
MP
2053 test_oem_fields(&data);
2054 qtest_quit(data.qts);
2055 free_test_data(&data);
2056 g_free(args);
2057}
2058
b3ad62c1 2059static void test_acpi_virt_oem_fields(void)
4b1f8882
MP
2060{
2061 test_data data = {
2062 .machine = "virt",
2063 .tcg_only = true,
2064 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
2065 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
2066 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
2067 .ram_start = 0x40000000ULL,
2068 .scan_len = 128ULL * 1024 * 1024,
2069 };
2070 char *args;
2071
c1a9ac9b 2072 args = test_acpi_create_args(&data, "-cpu cortex-a57 "OEM_TEST_ARGS);
4b1f8882 2073 data.qts = qtest_init(args);
c1a9ac9b 2074 test_acpi_load_tables(&data);
4b1f8882
MP
2075 test_oem_fields(&data);
2076 qtest_quit(data.qts);
2077 free_test_data(&data);
2078 g_free(args);
2079}
2080
2081
ad6423a7
MT
2082int main(int argc, char *argv[])
2083{
2084 const char *arch = qtest_get_arch();
80a2f338 2085 const bool has_kvm = qtest_has_accel("kvm");
220ffd94 2086 const bool has_tcg = qtest_has_accel("tcg");
4ffa3a1b 2087 char *v_env = getenv("V");
5862ad0f 2088 int ret;
4ffa3a1b
TH
2089
2090 if (v_env) {
2091 verbosity_level = atoi(v_env);
2092 }
c39a28a4 2093
ad6423a7
MT
2094 g_test_init(&argc, &argv, NULL);
2095
2096 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
d47a5d64
IM
2097 ret = boot_sector_init(disk);
2098 if (ret) {
2099 return ret;
2100 }
34b1f2c6
JQ
2101 if (qtest_has_machine(MACHINE_PC)) {
2102 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
2103 qtest_add_func("acpi/piix4/oem-fields", test_acpi_piix4_oem_fields);
2104 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
2105 qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
2106 test_acpi_piix4_no_root_hotplug);
2107 qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
2108 test_acpi_piix4_no_bridge_hotplug);
2109 qtest_add_func("acpi/piix4/pci-hotplug/off",
2110 test_acpi_piix4_no_acpi_pci_hotplug);
2111 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
2112 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
2113 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
2114 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
2115 qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm);
2116 qtest_add_func("acpi/piix4/smm-compat",
2117 test_acpi_piix4_tcg_smm_compat);
2118 qtest_add_func("acpi/piix4/smm-compat-nosmm",
2119 test_acpi_piix4_tcg_smm_compat_nosmm);
2120 qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet);
2121 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
2122 qtest_add_func("acpi/piix4/acpihmat",
2123 test_acpi_piix4_tcg_acpi_hmat);
d007981a 2124#ifdef CONFIG_POSIX
34b1f2c6 2125 qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst);
d007981a 2126#endif
d007981a 2127 }
34b1f2c6
JQ
2128 if (qtest_has_machine(MACHINE_Q35)) {
2129 qtest_add_func("acpi/q35", test_acpi_q35_tcg);
2130 qtest_add_func("acpi/q35/oem-fields", test_acpi_q35_oem_fields);
2131 if (tpm_model_is_available("-machine q35", "tpm-tis")) {
2132 qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis);
2133 qtest_add_func("acpi/q35/tpm12-tis",
2134 test_acpi_q35_tcg_tpm12_tis);
2135 }
2136 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
b0b3b99e
IM
2137 qtest_add_func("acpi/q35/no-acpi-hotplug",
2138 test_acpi_q35_tcg_no_acpi_hotplug);
34b1f2c6
JQ
2139 qtest_add_func("acpi/q35/multif-bridge",
2140 test_acpi_q35_multif_bridge);
2141 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
2142 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
2143 qtest_add_func("acpi/q35/smbus/ipmi", test_acpi_q35_tcg_smbus_ipmi);
2144 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
2145 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
2146 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
2147 qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
2148 qtest_add_func("acpi/q35/smm-compat",
2149 test_acpi_q35_tcg_smm_compat);
2150 qtest_add_func("acpi/q35/smm-compat-nosmm",
2151 test_acpi_q35_tcg_smm_compat_nosmm);
2152 qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
2153 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
2154 qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
a046f1d7
BG
2155 qtest_add_func("acpi/q35/acpihmat-noinitiator",
2156 test_acpi_q35_tcg_acpi_hmat_noinitiator);
84efa8aa 2157#ifdef CONFIG_POSIX
34b1f2c6 2158 qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst);
84efa8aa 2159#endif
34b1f2c6
JQ
2160 qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc);
2161 qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa);
2162 if (has_tcg) {
2163 qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs);
2164 }
2165 if (has_kvm) {
2166 qtest_add_func("acpi/q35/kvm/xapic", test_acpi_q35_kvm_xapic);
2167 qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar);
2d80b338
JS
2168 qtest_add_func("acpi/q35/core-count2",
2169 test_acpi_q35_tcg_core_count2);
34b1f2c6
JQ
2170 }
2171 qtest_add_func("acpi/q35/viot", test_acpi_q35_viot);
d007981a 2172#ifdef CONFIG_POSIX
34b1f2c6 2173 qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl);
d007981a 2174#endif
34b1f2c6
JQ
2175 qtest_add_func("acpi/q35/slic", test_acpi_q35_slic);
2176 }
2177 if (qtest_has_machine("microvm")) {
2178 qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
2179 qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
2180 qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
2181 qtest_add_func("acpi/microvm/ioapic2",
2182 test_acpi_microvm_ioapic2_tcg);
2183 qtest_add_func("acpi/microvm/oem-fields",
2184 test_acpi_microvm_oem_fields);
2185 if (has_tcg) {
2186 if (strcmp(arch, "x86_64") == 0) {
2187 qtest_add_func("acpi/microvm/pcie",
2188 test_acpi_microvm_pcie_tcg);
84efa8aa 2189#ifdef CONFIG_POSIX
34b1f2c6
JQ
2190 qtest_add_func("acpi/microvm/acpierst",
2191 test_acpi_microvm_acpi_erst);
84efa8aa 2192#endif
34b1f2c6 2193 }
220ffd94 2194 }
18bb73b3 2195 }
ab6b6a77 2196 } else if (strcmp(arch, "aarch64") == 0) {
220ffd94
IM
2197 if (has_tcg) {
2198 qtest_add_func("acpi/virt", test_acpi_virt_tcg);
b077b070
HA
2199 qtest_add_func("acpi/virt/acpihmatvirt",
2200 test_acpi_virt_tcg_acpi_hmat);
46bda3e4 2201 qtest_add_func("acpi/virt/topology", test_acpi_virt_tcg_topology);
220ffd94
IM
2202 qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
2203 qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
2204 qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb);
b3ad62c1 2205 qtest_add_func("acpi/virt/oem-fields", test_acpi_virt_oem_fields);
39d7554b 2206 qtest_add_func("acpi/virt/viot", test_acpi_virt_viot);
220ffd94 2207 }
ad6423a7 2208 }
5862ad0f 2209 ret = g_test_run();
4e082566 2210 boot_sector_cleanup(disk);
5862ad0f 2211 return ret;
ad6423a7 2212}