xref: /openbmc/qemu/tests/qtest/bios-tables-test.c (revision a976a99a)
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 
13 /*
14  * How to add or update the tests or commit changes that affect ACPI tables:
15  * Contributor:
16  * 1. add empty files for new tables, if any, under tests/data/acpi
17  * 2. list any changed files in tests/qtest/bios-tables-test-allowed-diff.h
18  * 3. commit the above *before* making changes that affect the tables
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  *
23  * After 1-3 above tests will pass but ignore differences with the expected files.
24  * You will also notice that tests/qtest/bios-tables-test-allowed-diff.h lists
25  * a bunch of files. This is your hint that you need to do the below:
26  * 4. Run
27  *      make check V=1
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.
34  * Save the changes, preferably in form of ASL diff for the commit log in
35  * step 6.
36  *
37  * 5. From build directory, run:
38  *      $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh
39  * 6. Now commit any changes to the expected binary, include diff from step 4
40  *    in commit log.
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).
46  * 7. Before sending patches to the list (Contributor)
47  *    or before doing a pull request (Maintainer), make sure
48  *    tests/qtest/bios-tables-test-allowed-diff.h is empty - this will ensure
49  *    following changes to ACPI tables will be noticed.
50  *
51  * The resulting patchset/pull request then looks like this:
52  * - patch 1: list changed files in tests/qtest/bios-tables-test-allowed-diff.h.
53  * - patches 2 - n: real changes, may contain multiple patches.
54  * - patch n + 1: update golden master binaries and empty
55  *   tests/qtest/bios-tables-test-allowed-diff.h
56  */
57 
58 #include "qemu/osdep.h"
59 #include <glib/gstdio.h>
60 #include "hw/firmware/smbios.h"
61 #include "qemu/bitmap.h"
62 #include "acpi-utils.h"
63 #include "boot-sector.h"
64 #include "tpm-emu.h"
65 #include "hw/acpi/tpm.h"
66 #include "qemu/cutils.h"
67 
68 #define MACHINE_PC "pc"
69 #define MACHINE_Q35 "q35"
70 
71 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
72 
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
77 
78 typedef struct {
79     bool tcg_only;
80     const char *machine;
81     const char *variant;
82     const char *uefi_fl1;
83     const char *uefi_fl2;
84     const char *blkdev;
85     const char *cd;
86     const uint64_t ram_start;
87     const uint64_t scan_len;
88     uint64_t rsdp_addr;
89     uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
90     GArray *tables;
91     uint32_t smbios_ep_addr;
92     struct smbios_21_entry_point smbios_ep_table;
93     uint16_t smbios_cpu_max_speed;
94     uint16_t smbios_cpu_curr_speed;
95     uint8_t *required_struct_types;
96     int required_struct_types_len;
97     QTestState *qts;
98 } test_data;
99 
100 static char disk[] = "tests/acpi-test-disk-XXXXXX";
101 static const char *data_dir = "tests/data/acpi";
102 #ifdef CONFIG_IASL
103 static const char *iasl = CONFIG_IASL;
104 #else
105 static const char *iasl;
106 #endif
107 
108 static bool compare_signature(const AcpiSdtTable *sdt, const char *signature)
109 {
110    return !memcmp(sdt->aml, signature, 4);
111 }
112 
113 static void cleanup_table_descriptor(AcpiSdtTable *table)
114 {
115     g_free(table->aml);
116     if (table->aml_file &&
117         !table->tmp_files_retain &&
118         g_strstr_len(table->aml_file, -1, "aml-")) {
119         unlink(table->aml_file);
120     }
121     g_free(table->aml_file);
122     g_free(table->asl);
123     if (table->asl_file &&
124         !table->tmp_files_retain) {
125         unlink(table->asl_file);
126     }
127     g_free(table->asl_file);
128 }
129 
130 static void free_test_data(test_data *data)
131 {
132     int i;
133 
134     if (!data->tables) {
135         return;
136     }
137     for (i = 0; i < data->tables->len; ++i) {
138         cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
139     }
140 
141     g_array_free(data->tables, true);
142 }
143 
144 static void test_acpi_rsdp_table(test_data *data)
145 {
146     uint8_t *rsdp_table = data->rsdp_table;
147 
148     acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
149 
150     switch (rsdp_table[15 /* Revision offset */]) {
151     case 0: /* ACPI 1.0 RSDP */
152         /* With rev 1, checksum is only for the first 20 bytes */
153         g_assert(!acpi_calc_checksum(rsdp_table,  20));
154         break;
155     case 2: /* ACPI 2.0+ RSDP */
156         /* With revision 2, we have 2 checksums */
157         g_assert(!acpi_calc_checksum(rsdp_table, 20));
158         g_assert(!acpi_calc_checksum(rsdp_table, 36));
159         break;
160     default:
161         g_assert_not_reached();
162     }
163 }
164 
165 static void test_acpi_rxsdt_table(test_data *data)
166 {
167     const char *sig = "RSDT";
168     AcpiSdtTable rsdt = {};
169     int entry_size = 4;
170     int addr_off = 16 /* RsdtAddress */;
171     uint8_t *ent;
172 
173     if (data->rsdp_table[15 /* Revision offset */] != 0) {
174         addr_off = 24 /* XsdtAddress */;
175         entry_size = 8;
176         sig = "XSDT";
177     }
178     /* read [RX]SDT table */
179     acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
180                      &data->rsdp_table[addr_off], entry_size, sig, true);
181 
182     /* Load all tables and add to test list directly RSDT referenced tables */
183     ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
184         AcpiSdtTable ssdt_table = {};
185 
186         acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
187                          entry_size, NULL, true);
188         /* Add table to ASL test tables list */
189         g_array_append_val(data->tables, ssdt_table);
190     }
191     cleanup_table_descriptor(&rsdt);
192 }
193 
194 static void test_acpi_fadt_table(test_data *data)
195 {
196     /* FADT table is 1st */
197     AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
198     uint8_t *fadt_aml = table.aml;
199     uint32_t fadt_len = table.aml_len;
200     uint32_t val;
201     int dsdt_offset = 40 /* DSDT */;
202     int dsdt_entry_size = 4;
203 
204     g_assert(compare_signature(&table, "FACP"));
205 
206     /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
207     memcpy(&val, fadt_aml + 112 /* Flags */, 4);
208     val = le32_to_cpu(val);
209     if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
210         acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
211                          fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
212         g_array_append_val(data->tables, table);
213     }
214 
215     memcpy(&val, fadt_aml + dsdt_offset, 4);
216     val = le32_to_cpu(val);
217     if (!val) {
218         dsdt_offset = 140 /* X_DSDT */;
219         dsdt_entry_size = 8;
220     }
221     acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
222                      fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
223     g_array_append_val(data->tables, table);
224 
225     memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
226     memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
227     if (fadt_aml[8 /* FADT Major Version */] >= 3) {
228         memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
229         memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
230     }
231 
232     /* update checksum */
233     fadt_aml[9 /* Checksum */] = 0;
234     fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
235 }
236 
237 static void dump_aml_files(test_data *data, bool rebuild)
238 {
239     AcpiSdtTable *sdt;
240     GError *error = NULL;
241     gchar *aml_file = NULL;
242     gint fd;
243     ssize_t ret;
244     int i;
245 
246     for (i = 0; i < data->tables->len; ++i) {
247         const char *ext = data->variant ? data->variant : "";
248         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
249         g_assert(sdt->aml);
250 
251         if (rebuild) {
252             aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
253                                        sdt->aml, ext);
254             fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
255                         S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
256             if (fd < 0) {
257                 perror(aml_file);
258             }
259             g_assert(fd >= 0);
260         } else {
261             fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
262             g_assert_no_error(error);
263         }
264 
265         ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
266         g_assert(ret == sdt->aml_len);
267 
268         close(fd);
269 
270         g_free(aml_file);
271     }
272 }
273 
274 static bool create_tmp_asl(AcpiSdtTable *sdt)
275 {
276     GError *error = NULL;
277     gint fd;
278 
279     fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
280     g_assert_no_error(error);
281     close(fd);
282 
283     return false;
284 }
285 
286 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
287 {
288     AcpiSdtTable *temp;
289     GError *error = NULL;
290     GString *command_line = g_string_new(iasl);
291     gchar *out, *out_err;
292     gboolean ret;
293     int i;
294 
295     create_tmp_asl(sdt);
296 
297     /* build command line */
298     g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
299     if (compare_signature(sdt, "DSDT") ||
300         compare_signature(sdt, "SSDT")) {
301         for (i = 0; i < sdts->len; ++i) {
302             temp = &g_array_index(sdts, AcpiSdtTable, i);
303             if (compare_signature(temp, "DSDT") ||
304                 compare_signature(temp, "SSDT")) {
305                 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
306             }
307         }
308     }
309     g_string_append_printf(command_line, "-d %s", sdt->aml_file);
310 
311     /* pass 'out' and 'out_err' in order to be redirected */
312     ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
313     g_assert_no_error(error);
314     if (ret) {
315         ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
316                                   &sdt->asl_len, &error);
317         g_assert(ret);
318         g_assert_no_error(error);
319         ret = (sdt->asl_len > 0);
320     }
321 
322     g_free(out);
323     g_free(out_err);
324     g_string_free(command_line, true);
325 
326     return !ret;
327 }
328 
329 #define COMMENT_END "*/"
330 #define DEF_BLOCK "DefinitionBlock ("
331 #define BLOCK_NAME_END ","
332 
333 static GString *normalize_asl(gchar *asl_code)
334 {
335     GString *asl = g_string_new(asl_code);
336     gchar *comment, *block_name;
337 
338     /* strip comments (different generation days) */
339     comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
340     if (comment) {
341         comment += strlen(COMMENT_END);
342         while (*comment == '\n') {
343             comment++;
344         }
345         asl = g_string_erase(asl, 0, comment - asl->str);
346     }
347 
348     /* strip def block name (it has file path in it) */
349     if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
350         block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
351         g_assert(block_name);
352         asl = g_string_erase(asl, 0,
353                              block_name + sizeof(BLOCK_NAME_END) - asl->str);
354     }
355 
356     return asl;
357 }
358 
359 static GArray *load_expected_aml(test_data *data)
360 {
361     int i;
362     AcpiSdtTable *sdt;
363     GError *error = NULL;
364     gboolean ret;
365     gsize aml_len;
366 
367     GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
368     if (getenv("V")) {
369         fputc('\n', stderr);
370     }
371     for (i = 0; i < data->tables->len; ++i) {
372         AcpiSdtTable exp_sdt;
373         gchar *aml_file = NULL;
374         const char *ext = data->variant ? data->variant : "";
375 
376         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
377 
378         memset(&exp_sdt, 0, sizeof(exp_sdt));
379 
380 try_again:
381         aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
382                                    sdt->aml, ext);
383         if (getenv("V")) {
384             fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
385         }
386         if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
387             exp_sdt.aml_file = aml_file;
388         } else if (*ext != '\0') {
389             /* try fallback to generic (extension less) expected file */
390             ext = "";
391             g_free(aml_file);
392             goto try_again;
393         }
394         g_assert(exp_sdt.aml_file);
395         if (getenv("V")) {
396             fprintf(stderr, "Using expected file '%s'\n", aml_file);
397         }
398         ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
399                                   &aml_len, &error);
400         exp_sdt.aml_len = aml_len;
401         g_assert(ret);
402         g_assert_no_error(error);
403         g_assert(exp_sdt.aml);
404         if (!exp_sdt.aml_len) {
405             fprintf(stderr, "Warning! zero length expected file '%s'\n",
406                     aml_file);
407         }
408 
409         g_array_append_val(exp_tables, exp_sdt);
410     }
411 
412     return exp_tables;
413 }
414 
415 static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt)
416 {
417     const gchar *allowed_diff_file[] = {
418 #include "bios-tables-test-allowed-diff.h"
419         NULL
420     };
421     const gchar **f;
422 
423     for (f = allowed_diff_file; *f; ++f) {
424         if (!g_strcmp0(sdt->aml_file, *f)) {
425             return true;
426         }
427     }
428     return false;
429 }
430 
431 /* test the list of tables in @data->tables against reference tables */
432 static void test_acpi_asl(test_data *data)
433 {
434     int i;
435     AcpiSdtTable *sdt, *exp_sdt;
436     test_data exp_data;
437     gboolean exp_err, err, all_tables_match = true;
438 
439     memset(&exp_data, 0, sizeof(exp_data));
440     exp_data.tables = load_expected_aml(data);
441     dump_aml_files(data, false);
442     for (i = 0; i < data->tables->len; ++i) {
443         GString *asl, *exp_asl;
444 
445         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
446         exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
447 
448         if (sdt->aml_len == exp_sdt->aml_len &&
449             !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
450             /* Identical table binaries: no need to disassemble. */
451             continue;
452         }
453 
454         fprintf(stderr,
455                 "acpi-test: Warning! %.4s binary file mismatch. "
456                 "Actual [aml:%s], Expected [aml:%s].\n"
457                 "See source file tests/qtest/bios-tables-test.c "
458                 "for instructions on how to update expected files.\n",
459                 exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file);
460 
461         all_tables_match = all_tables_match &&
462             test_acpi_find_diff_allowed(exp_sdt);
463 
464         /*
465          *  don't try to decompile if IASL isn't present, in this case user
466          * will just 'get binary file mismatch' warnings and test failure
467          */
468         if (!iasl) {
469             continue;
470         }
471 
472         err = load_asl(data->tables, sdt);
473         asl = normalize_asl(sdt->asl);
474 
475         /*
476          * If expected file is empty - it's likely that it was a stub just
477          * created for step 1 above: we do want to decompile the actual one.
478          */
479         if (exp_sdt->aml_len) {
480             exp_err = load_asl(exp_data.tables, exp_sdt);
481             exp_asl = normalize_asl(exp_sdt->asl);
482         } else {
483             exp_err = create_tmp_asl(exp_sdt);
484             exp_asl = g_string_new("");
485         }
486 
487         /* TODO: check for warnings */
488         g_assert(!err || exp_err || !exp_sdt->aml_len);
489 
490         if (g_strcmp0(asl->str, exp_asl->str)) {
491             sdt->tmp_files_retain = true;
492             if (exp_err) {
493                 fprintf(stderr,
494                         "Warning! iasl couldn't parse the expected aml\n");
495             } else {
496                 exp_sdt->tmp_files_retain = true;
497                 fprintf(stderr,
498                         "acpi-test: Warning! %.4s mismatch. "
499                         "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
500                         exp_sdt->aml, sdt->asl_file, sdt->aml_file,
501                         exp_sdt->asl_file, exp_sdt->aml_file);
502                 fflush(stderr);
503                 if (getenv("V")) {
504                     const char *diff_env = getenv("DIFF");
505                     const char *diff_cmd = diff_env ? diff_env : "diff -U 16";
506                     char *diff = g_strdup_printf("%s %s %s", diff_cmd,
507                                                  exp_sdt->asl_file, sdt->asl_file);
508                     int out = dup(STDOUT_FILENO);
509                     int ret G_GNUC_UNUSED;
510                     int dupret;
511 
512                     g_assert(out >= 0);
513                     dupret = dup2(STDERR_FILENO, STDOUT_FILENO);
514                     g_assert(dupret >= 0);
515                     ret = system(diff) ;
516                     dupret = dup2(out, STDOUT_FILENO);
517                     g_assert(dupret >= 0);
518                     close(out);
519                     g_free(diff);
520                 }
521             }
522         }
523         g_string_free(asl, true);
524         g_string_free(exp_asl, true);
525     }
526     if (!iasl && !all_tables_match) {
527         fprintf(stderr, "to see ASL diff between mismatched files install IASL,"
528                 " rebuild QEMU from scratch and re-run tests with V=1"
529                 " environment variable set");
530     }
531     g_assert(all_tables_match);
532 
533     free_test_data(&exp_data);
534 }
535 
536 static bool smbios_ep_table_ok(test_data *data)
537 {
538     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
539     uint32_t addr = data->smbios_ep_addr;
540 
541     qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
542     if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
543         return false;
544     }
545     if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
546         return false;
547     }
548     if (ep_table->structure_table_length == 0) {
549         return false;
550     }
551     if (ep_table->number_of_structures == 0) {
552         return false;
553     }
554     if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
555         acpi_calc_checksum((uint8_t *)ep_table + 0x10,
556                            sizeof *ep_table - 0x10)) {
557         return false;
558     }
559     return true;
560 }
561 
562 static void test_smbios_entry_point(test_data *data)
563 {
564     uint32_t off;
565 
566     /* find smbios entry point structure */
567     for (off = 0xf0000; off < 0x100000; off += 0x10) {
568         uint8_t sig[] = "_SM_";
569         int i;
570 
571         for (i = 0; i < sizeof sig - 1; ++i) {
572             sig[i] = qtest_readb(data->qts, off + i);
573         }
574 
575         if (!memcmp(sig, "_SM_", sizeof sig)) {
576             /* signature match, but is this a valid entry point? */
577             data->smbios_ep_addr = off;
578             if (smbios_ep_table_ok(data)) {
579                 break;
580             }
581         }
582     }
583 
584     g_assert_cmphex(off, <, 0x100000);
585 }
586 
587 static inline bool smbios_single_instance(uint8_t type)
588 {
589     switch (type) {
590     case 0:
591     case 1:
592     case 2:
593     case 3:
594     case 16:
595     case 32:
596     case 127:
597         return true;
598     default:
599         return false;
600     }
601 }
602 
603 static bool smbios_cpu_test(test_data *data, uint32_t addr)
604 {
605     uint16_t expect_speed[2];
606     uint16_t real;
607     int offset[2];
608     int i;
609 
610     /* Check CPU speed for backward compatibility */
611     offset[0] = offsetof(struct smbios_type_4, max_speed);
612     offset[1] = offsetof(struct smbios_type_4, current_speed);
613     expect_speed[0] = data->smbios_cpu_max_speed ? : 2000;
614     expect_speed[1] = data->smbios_cpu_curr_speed ? : 2000;
615 
616     for (i = 0; i < 2; i++) {
617         real = qtest_readw(data->qts, addr + offset[i]);
618         if (real != expect_speed[i]) {
619             fprintf(stderr, "Unexpected SMBIOS CPU speed: real %u expect %u\n",
620                     real, expect_speed[i]);
621             return false;
622         }
623     }
624 
625     return true;
626 }
627 
628 static void test_smbios_structs(test_data *data)
629 {
630     DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
631     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
632     uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
633     int i, len, max_len = 0;
634     uint8_t type, prv, crt;
635 
636     /* walk the smbios tables */
637     for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
638 
639         /* grab type and formatted area length from struct header */
640         type = qtest_readb(data->qts, addr);
641         g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
642         len = qtest_readb(data->qts, addr + 1);
643 
644         /* single-instance structs must not have been encountered before */
645         if (smbios_single_instance(type)) {
646             g_assert(!test_bit(type, struct_bitmap));
647         }
648         set_bit(type, struct_bitmap);
649 
650         if (type == 4) {
651             g_assert(smbios_cpu_test(data, addr));
652         }
653 
654         /* seek to end of unformatted string area of this struct ("\0\0") */
655         prv = crt = 1;
656         while (prv || crt) {
657             prv = crt;
658             crt = qtest_readb(data->qts, addr + len);
659             len++;
660         }
661 
662         /* keep track of max. struct size */
663         if (max_len < len) {
664             max_len = len;
665             g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
666         }
667 
668         /* start of next structure */
669         addr += len;
670     }
671 
672     /* total table length and max struct size must match entry point values */
673     g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
674                      addr - le32_to_cpu(ep_table->structure_table_address));
675     g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
676 
677     /* required struct types must all be present */
678     for (i = 0; i < data->required_struct_types_len; i++) {
679         g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
680     }
681 }
682 
683 static void test_acpi_load_tables(test_data *data, bool use_uefi)
684 {
685     if (use_uefi) {
686         g_assert(data->scan_len);
687         data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts,
688             data->ram_start, data->scan_len);
689     } else {
690         boot_sector_test(data->qts);
691         data->rsdp_addr = acpi_find_rsdp_address(data->qts);
692         g_assert_cmphex(data->rsdp_addr, <, 0x100000);
693     }
694 
695     data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
696     test_acpi_rsdp_table(data);
697     test_acpi_rxsdt_table(data);
698     test_acpi_fadt_table(data);
699 }
700 
701 static char *test_acpi_create_args(test_data *data, const char *params,
702                                    bool use_uefi)
703 {
704     char *args;
705 
706     if (use_uefi) {
707         /*
708          * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
709          * when arm/virt boad starts to support it.
710          */
711         if (data->cd) {
712             args = g_strdup_printf("-machine %s %s -accel tcg "
713                 "-nodefaults -nographic "
714                 "-drive if=pflash,format=raw,file=%s,readonly=on "
715                 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
716                 data->machine, data->tcg_only ? "" : "-accel kvm",
717                 data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
718         } else {
719             args = g_strdup_printf("-machine %s %s -accel tcg "
720                 "-nodefaults -nographic "
721                 "-drive if=pflash,format=raw,file=%s,readonly=on "
722                 "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
723                 data->machine, data->tcg_only ? "" : "-accel kvm",
724                 data->uefi_fl1, data->uefi_fl2, params ? params : "");
725         }
726     } else {
727         args = g_strdup_printf("-machine %s %s -accel tcg "
728             "-net none -display none %s "
729             "-drive id=hd0,if=none,file=%s,format=raw "
730             "-device %s,drive=hd0 ",
731              data->machine, data->tcg_only ? "" : "-accel kvm",
732              params ? params : "", disk,
733              data->blkdev ?: "ide-hd");
734     }
735     return args;
736 }
737 
738 static void test_acpi_one(const char *params, test_data *data)
739 {
740     char *args;
741     bool use_uefi = data->uefi_fl1 && data->uefi_fl2;
742 
743     args = test_acpi_create_args(data, params, use_uefi);
744     data->qts = qtest_init(args);
745     test_acpi_load_tables(data, use_uefi);
746 
747     if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
748         dump_aml_files(data, true);
749     } else {
750         test_acpi_asl(data);
751     }
752 
753     /*
754      * TODO: make SMBIOS tests work with UEFI firmware,
755      * Bug on uefi-test-tools to provide entry point:
756      * https://bugs.launchpad.net/qemu/+bug/1821884
757      */
758     if (!use_uefi) {
759         test_smbios_entry_point(data);
760         test_smbios_structs(data);
761     }
762 
763     qtest_quit(data->qts);
764     g_free(args);
765 }
766 
767 static uint8_t base_required_struct_types[] = {
768     0, 1, 3, 4, 16, 17, 19, 32, 127
769 };
770 
771 static void test_acpi_piix4_tcg(void)
772 {
773     test_data data;
774 
775     /* Supplying -machine accel argument overrides the default (qtest).
776      * This is to make guest actually run.
777      */
778     memset(&data, 0, sizeof(data));
779     data.machine = MACHINE_PC;
780     data.required_struct_types = base_required_struct_types;
781     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
782     test_acpi_one(NULL, &data);
783     free_test_data(&data);
784 }
785 
786 static void test_acpi_piix4_tcg_bridge(void)
787 {
788     test_data data;
789 
790     memset(&data, 0, sizeof(data));
791     data.machine = MACHINE_PC;
792     data.variant = ".bridge";
793     data.required_struct_types = base_required_struct_types;
794     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
795     test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
796     free_test_data(&data);
797 }
798 
799 static void test_acpi_piix4_no_root_hotplug(void)
800 {
801     test_data data;
802 
803     memset(&data, 0, sizeof(data));
804     data.machine = MACHINE_PC;
805     data.variant = ".roothp";
806     data.required_struct_types = base_required_struct_types;
807     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
808     test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
809                   "-device pci-bridge,chassis_nr=1", &data);
810     free_test_data(&data);
811 }
812 
813 static void test_acpi_piix4_no_bridge_hotplug(void)
814 {
815     test_data data;
816 
817     memset(&data, 0, sizeof(data));
818     data.machine = MACHINE_PC;
819     data.variant = ".hpbridge";
820     data.required_struct_types = base_required_struct_types;
821     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
822     test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
823                   "-device pci-bridge,chassis_nr=1", &data);
824     free_test_data(&data);
825 }
826 
827 static void test_acpi_piix4_no_acpi_pci_hotplug(void)
828 {
829     test_data data;
830 
831     memset(&data, 0, sizeof(data));
832     data.machine = MACHINE_PC;
833     data.variant = ".hpbrroot";
834     data.required_struct_types = base_required_struct_types;
835     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
836     test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
837                   "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
838                   "-device pci-bridge,chassis_nr=1", &data);
839     free_test_data(&data);
840 }
841 
842 static void test_acpi_q35_tcg(void)
843 {
844     test_data data;
845 
846     memset(&data, 0, sizeof(data));
847     data.machine = MACHINE_Q35;
848     data.required_struct_types = base_required_struct_types;
849     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
850     test_acpi_one(NULL, &data);
851     free_test_data(&data);
852 
853     data.smbios_cpu_max_speed = 3000;
854     data.smbios_cpu_curr_speed = 2600;
855     test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data);
856     free_test_data(&data);
857 }
858 
859 static void test_acpi_q35_tcg_bridge(void)
860 {
861     test_data data;
862 
863     memset(&data, 0, sizeof(data));
864     data.machine = MACHINE_Q35;
865     data.variant = ".bridge";
866     data.required_struct_types = base_required_struct_types;
867     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
868     test_acpi_one("-device pci-bridge,chassis_nr=1",
869                   &data);
870     free_test_data(&data);
871 }
872 
873 static void test_acpi_q35_multif_bridge(void)
874 {
875     test_data data = {
876         .machine = MACHINE_Q35,
877         .variant = ".multi-bridge",
878     };
879     test_acpi_one("-device pcie-root-port,id=pcie-root-port-0,"
880                   "multifunction=on,"
881                   "port=0x0,chassis=1,addr=0x2,bus=pcie.0 "
882                   "-device pcie-root-port,id=pcie-root-port-1,"
883                   "port=0x1,chassis=2,addr=0x3.0x1,bus=pcie.0 "
884                   "-device virtio-balloon,id=balloon0,"
885                   "bus=pcie.0,addr=0x4.0x2",
886                   &data);
887     free_test_data(&data);
888 }
889 
890 static void test_acpi_q35_tcg_mmio64(void)
891 {
892     test_data data = {
893         .machine = MACHINE_Q35,
894         .variant = ".mmio64",
895         .required_struct_types = base_required_struct_types,
896         .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
897     };
898 
899     test_acpi_one("-m 128M,slots=1,maxmem=2G "
900                   "-object memory-backend-ram,id=ram0,size=128M "
901                   "-numa node,memdev=ram0 "
902                   "-device pci-testdev,membar=2G",
903                   &data);
904     free_test_data(&data);
905 }
906 
907 static void test_acpi_piix4_tcg_cphp(void)
908 {
909     test_data data;
910 
911     memset(&data, 0, sizeof(data));
912     data.machine = MACHINE_PC;
913     data.variant = ".cphp";
914     test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
915                   " -object memory-backend-ram,id=ram0,size=64M"
916                   " -object memory-backend-ram,id=ram1,size=64M"
917                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
918                   " -numa dist,src=0,dst=1,val=21",
919                   &data);
920     free_test_data(&data);
921 }
922 
923 static void test_acpi_q35_tcg_cphp(void)
924 {
925     test_data data;
926 
927     memset(&data, 0, sizeof(data));
928     data.machine = MACHINE_Q35;
929     data.variant = ".cphp";
930     test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
931                   " -object memory-backend-ram,id=ram0,size=64M"
932                   " -object memory-backend-ram,id=ram1,size=64M"
933                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
934                   " -numa dist,src=0,dst=1,val=21",
935                   &data);
936     free_test_data(&data);
937 }
938 
939 static uint8_t ipmi_required_struct_types[] = {
940     0, 1, 3, 4, 16, 17, 19, 32, 38, 127
941 };
942 
943 static void test_acpi_q35_tcg_ipmi(void)
944 {
945     test_data data;
946 
947     memset(&data, 0, sizeof(data));
948     data.machine = MACHINE_Q35;
949     data.variant = ".ipmibt";
950     data.required_struct_types = ipmi_required_struct_types;
951     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
952     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
953                   " -device isa-ipmi-bt,bmc=bmc0",
954                   &data);
955     free_test_data(&data);
956 }
957 
958 static void test_acpi_q35_tcg_smbus_ipmi(void)
959 {
960     test_data data;
961 
962     memset(&data, 0, sizeof(data));
963     data.machine = MACHINE_Q35;
964     data.variant = ".ipmismbus";
965     data.required_struct_types = ipmi_required_struct_types;
966     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
967     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
968                   " -device smbus-ipmi,bmc=bmc0",
969                   &data);
970     free_test_data(&data);
971 }
972 
973 static void test_acpi_piix4_tcg_ipmi(void)
974 {
975     test_data data;
976 
977     /* Supplying -machine accel argument overrides the default (qtest).
978      * This is to make guest actually run.
979      */
980     memset(&data, 0, sizeof(data));
981     data.machine = MACHINE_PC;
982     data.variant = ".ipmikcs";
983     data.required_struct_types = ipmi_required_struct_types;
984     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
985     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
986                   " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
987                   &data);
988     free_test_data(&data);
989 }
990 
991 static void test_acpi_q35_tcg_memhp(void)
992 {
993     test_data data;
994 
995     memset(&data, 0, sizeof(data));
996     data.machine = MACHINE_Q35;
997     data.variant = ".memhp";
998     test_acpi_one(" -m 128,slots=3,maxmem=1G"
999                   " -object memory-backend-ram,id=ram0,size=64M"
1000                   " -object memory-backend-ram,id=ram1,size=64M"
1001                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
1002                   " -numa dist,src=0,dst=1,val=21",
1003                   &data);
1004     free_test_data(&data);
1005 }
1006 
1007 static void test_acpi_piix4_tcg_memhp(void)
1008 {
1009     test_data data;
1010 
1011     memset(&data, 0, sizeof(data));
1012     data.machine = MACHINE_PC;
1013     data.variant = ".memhp";
1014     test_acpi_one(" -m 128,slots=3,maxmem=1G"
1015                   " -object memory-backend-ram,id=ram0,size=64M"
1016                   " -object memory-backend-ram,id=ram1,size=64M"
1017                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
1018                   " -numa dist,src=0,dst=1,val=21",
1019                   &data);
1020     free_test_data(&data);
1021 }
1022 
1023 static void test_acpi_piix4_tcg_nosmm(void)
1024 {
1025     test_data data;
1026 
1027     memset(&data, 0, sizeof(data));
1028     data.machine = MACHINE_PC;
1029     data.variant = ".nosmm";
1030     test_acpi_one("-machine smm=off", &data);
1031     free_test_data(&data);
1032 }
1033 
1034 static void test_acpi_piix4_tcg_smm_compat(void)
1035 {
1036     test_data data;
1037 
1038     memset(&data, 0, sizeof(data));
1039     data.machine = MACHINE_PC;
1040     data.variant = ".smm-compat";
1041     test_acpi_one("-global PIIX4_PM.smm-compat=on", &data);
1042     free_test_data(&data);
1043 }
1044 
1045 static void test_acpi_piix4_tcg_smm_compat_nosmm(void)
1046 {
1047     test_data data;
1048 
1049     memset(&data, 0, sizeof(data));
1050     data.machine = MACHINE_PC;
1051     data.variant = ".smm-compat-nosmm";
1052     test_acpi_one("-global PIIX4_PM.smm-compat=on -machine smm=off", &data);
1053     free_test_data(&data);
1054 }
1055 
1056 static void test_acpi_piix4_tcg_nohpet(void)
1057 {
1058     test_data data;
1059 
1060     memset(&data, 0, sizeof(data));
1061     data.machine = MACHINE_PC;
1062     data.variant = ".nohpet";
1063     test_acpi_one("-no-hpet", &data);
1064     free_test_data(&data);
1065 }
1066 
1067 static void test_acpi_q35_tcg_numamem(void)
1068 {
1069     test_data data;
1070 
1071     memset(&data, 0, sizeof(data));
1072     data.machine = MACHINE_Q35;
1073     data.variant = ".numamem";
1074     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1075                   " -numa node -numa node,memdev=ram0", &data);
1076     free_test_data(&data);
1077 }
1078 
1079 static void test_acpi_q35_kvm_xapic(void)
1080 {
1081     test_data data;
1082 
1083     memset(&data, 0, sizeof(data));
1084     data.machine = MACHINE_Q35;
1085     data.variant = ".xapic";
1086     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1087                   " -numa node -numa node,memdev=ram0"
1088                   " -machine kernel-irqchip=on -smp 1,maxcpus=288", &data);
1089     free_test_data(&data);
1090 }
1091 
1092 static void test_acpi_q35_tcg_nosmm(void)
1093 {
1094     test_data data;
1095 
1096     memset(&data, 0, sizeof(data));
1097     data.machine = MACHINE_Q35;
1098     data.variant = ".nosmm";
1099     test_acpi_one("-machine smm=off", &data);
1100     free_test_data(&data);
1101 }
1102 
1103 static void test_acpi_q35_tcg_smm_compat(void)
1104 {
1105     test_data data;
1106 
1107     memset(&data, 0, sizeof(data));
1108     data.machine = MACHINE_Q35;
1109     data.variant = ".smm-compat";
1110     test_acpi_one("-global ICH9-LPC.smm-compat=on", &data);
1111     free_test_data(&data);
1112 }
1113 
1114 static void test_acpi_q35_tcg_smm_compat_nosmm(void)
1115 {
1116     test_data data;
1117 
1118     memset(&data, 0, sizeof(data));
1119     data.machine = MACHINE_Q35;
1120     data.variant = ".smm-compat-nosmm";
1121     test_acpi_one("-global ICH9-LPC.smm-compat=on -machine smm=off", &data);
1122     free_test_data(&data);
1123 }
1124 
1125 static void test_acpi_q35_tcg_nohpet(void)
1126 {
1127     test_data data;
1128 
1129     memset(&data, 0, sizeof(data));
1130     data.machine = MACHINE_Q35;
1131     data.variant = ".nohpet";
1132     test_acpi_one("-no-hpet", &data);
1133     free_test_data(&data);
1134 }
1135 
1136 static void test_acpi_q35_kvm_dmar(void)
1137 {
1138     test_data data;
1139 
1140     memset(&data, 0, sizeof(data));
1141     data.machine = MACHINE_Q35;
1142     data.variant = ".dmar";
1143     test_acpi_one("-machine kernel-irqchip=split -accel kvm"
1144                   " -device intel-iommu,intremap=on,device-iotlb=on", &data);
1145     free_test_data(&data);
1146 }
1147 
1148 static void test_acpi_q35_tcg_ivrs(void)
1149 {
1150     test_data data;
1151 
1152     memset(&data, 0, sizeof(data));
1153     data.machine = MACHINE_Q35;
1154     data.variant = ".ivrs";
1155     data.tcg_only = true,
1156     test_acpi_one(" -device amd-iommu", &data);
1157     free_test_data(&data);
1158 }
1159 
1160 static void test_acpi_piix4_tcg_numamem(void)
1161 {
1162     test_data data;
1163 
1164     memset(&data, 0, sizeof(data));
1165     data.machine = MACHINE_PC;
1166     data.variant = ".numamem";
1167     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1168                   " -numa node -numa node,memdev=ram0", &data);
1169     free_test_data(&data);
1170 }
1171 
1172 uint64_t tpm_tis_base_addr;
1173 
1174 static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
1175                               uint64_t base, enum TPMVersion tpm_version)
1176 {
1177     gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
1178                                           machine, tpm_if);
1179     char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
1180     TPMTestState test;
1181     test_data data;
1182     GThread *thread;
1183     const char *suffix = tpm_version == TPM_VERSION_2_0 ? "tpm2" : "tpm12";
1184     char *args, *variant = g_strdup_printf(".%s.%s", tpm_if, suffix);
1185 
1186     tpm_tis_base_addr = base;
1187 
1188     module_call_init(MODULE_INIT_QOM);
1189 
1190     test.addr = g_new0(SocketAddress, 1);
1191     test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
1192     test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
1193     g_mutex_init(&test.data_mutex);
1194     g_cond_init(&test.data_cond);
1195     test.data_cond_signal = false;
1196     test.tpm_version = tpm_version;
1197 
1198     thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
1199     tpm_emu_test_wait_cond(&test);
1200 
1201     memset(&data, 0, sizeof(data));
1202     data.machine = machine;
1203     data.variant = variant;
1204 
1205     args = g_strdup_printf(
1206         " -chardev socket,id=chr,path=%s"
1207         " -tpmdev emulator,id=dev,chardev=chr"
1208         " -device tpm-%s,tpmdev=dev",
1209         test.addr->u.q_unix.path, tpm_if);
1210 
1211     test_acpi_one(args, &data);
1212 
1213     g_thread_join(thread);
1214     g_unlink(test.addr->u.q_unix.path);
1215     qapi_free_SocketAddress(test.addr);
1216     g_rmdir(tmp_path);
1217     g_free(variant);
1218     g_free(tmp_path);
1219     g_free(tmp_dir_name);
1220     g_free(args);
1221     free_test_data(&data);
1222 }
1223 
1224 static void test_acpi_q35_tcg_tpm2_tis(void)
1225 {
1226     test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_2_0);
1227 }
1228 
1229 static void test_acpi_q35_tcg_tpm12_tis(void)
1230 {
1231     test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_1_2);
1232 }
1233 
1234 static void test_acpi_tcg_dimm_pxm(const char *machine)
1235 {
1236     test_data data;
1237 
1238     memset(&data, 0, sizeof(data));
1239     data.machine = machine;
1240     data.variant = ".dimmpxm";
1241     test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
1242                   " -smp 4,sockets=4"
1243                   " -m 128M,slots=3,maxmem=1G"
1244                   " -object memory-backend-ram,id=ram0,size=32M"
1245                   " -object memory-backend-ram,id=ram1,size=32M"
1246                   " -object memory-backend-ram,id=ram2,size=32M"
1247                   " -object memory-backend-ram,id=ram3,size=32M"
1248                   " -numa node,memdev=ram0,nodeid=0"
1249                   " -numa node,memdev=ram1,nodeid=1"
1250                   " -numa node,memdev=ram2,nodeid=2"
1251                   " -numa node,memdev=ram3,nodeid=3"
1252                   " -numa cpu,node-id=0,socket-id=0"
1253                   " -numa cpu,node-id=1,socket-id=1"
1254                   " -numa cpu,node-id=2,socket-id=2"
1255                   " -numa cpu,node-id=3,socket-id=3"
1256                   " -object memory-backend-ram,id=ram4,size=128M"
1257                   " -object memory-backend-ram,id=nvm0,size=128M"
1258                   " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
1259                   " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
1260                   &data);
1261     free_test_data(&data);
1262 }
1263 
1264 static void test_acpi_q35_tcg_dimm_pxm(void)
1265 {
1266     test_acpi_tcg_dimm_pxm(MACHINE_Q35);
1267 }
1268 
1269 static void test_acpi_piix4_tcg_dimm_pxm(void)
1270 {
1271     test_acpi_tcg_dimm_pxm(MACHINE_PC);
1272 }
1273 
1274 static void test_acpi_virt_tcg_memhp(void)
1275 {
1276     test_data data = {
1277         .machine = "virt",
1278         .tcg_only = true,
1279         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1280         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1281         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1282         .ram_start = 0x40000000ULL,
1283         .scan_len = 256ULL * 1024 * 1024,
1284     };
1285 
1286     data.variant = ".memhp";
1287     test_acpi_one(" -machine nvdimm=on"
1288                   " -cpu cortex-a57"
1289                   " -m 256M,slots=3,maxmem=1G"
1290                   " -object memory-backend-ram,id=ram0,size=128M"
1291                   " -object memory-backend-ram,id=ram1,size=128M"
1292                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
1293                   " -numa dist,src=0,dst=1,val=21"
1294                   " -object memory-backend-ram,id=ram2,size=128M"
1295                   " -object memory-backend-ram,id=nvm0,size=128M"
1296                   " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
1297                   " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
1298                   &data);
1299 
1300     free_test_data(&data);
1301 
1302 }
1303 
1304 static void test_acpi_microvm_prepare(test_data *data)
1305 {
1306     memset(data, 0, sizeof(*data));
1307     data->machine = "microvm";
1308     data->required_struct_types = NULL; /* no smbios */
1309     data->required_struct_types_len = 0;
1310     data->blkdev = "virtio-blk-device";
1311 }
1312 
1313 static void test_acpi_microvm_tcg(void)
1314 {
1315     test_data data;
1316 
1317     test_acpi_microvm_prepare(&data);
1318     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off",
1319                   &data);
1320     free_test_data(&data);
1321 }
1322 
1323 static void test_acpi_microvm_usb_tcg(void)
1324 {
1325     test_data data;
1326 
1327     test_acpi_microvm_prepare(&data);
1328     data.variant = ".usb";
1329     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off",
1330                   &data);
1331     free_test_data(&data);
1332 }
1333 
1334 static void test_acpi_microvm_rtc_tcg(void)
1335 {
1336     test_data data;
1337 
1338     test_acpi_microvm_prepare(&data);
1339     data.variant = ".rtc";
1340     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on",
1341                   &data);
1342     free_test_data(&data);
1343 }
1344 
1345 static void test_acpi_microvm_pcie_tcg(void)
1346 {
1347     test_data data;
1348 
1349     test_acpi_microvm_prepare(&data);
1350     data.variant = ".pcie";
1351     data.tcg_only = true; /* need constant host-phys-bits */
1352     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on",
1353                   &data);
1354     free_test_data(&data);
1355 }
1356 
1357 static void test_acpi_microvm_ioapic2_tcg(void)
1358 {
1359     test_data data;
1360 
1361     test_acpi_microvm_prepare(&data);
1362     data.variant = ".ioapic2";
1363     test_acpi_one(" -machine microvm,acpi=on,ioapic2=on,rtc=off",
1364                   &data);
1365     free_test_data(&data);
1366 }
1367 
1368 static void test_acpi_virt_tcg_numamem(void)
1369 {
1370     test_data data = {
1371         .machine = "virt",
1372         .tcg_only = true,
1373         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1374         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1375         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1376         .ram_start = 0x40000000ULL,
1377         .scan_len = 128ULL * 1024 * 1024,
1378     };
1379 
1380     data.variant = ".numamem";
1381     test_acpi_one(" -cpu cortex-a57"
1382                   " -object memory-backend-ram,id=ram0,size=128M"
1383                   " -numa node,memdev=ram0",
1384                   &data);
1385 
1386     free_test_data(&data);
1387 
1388 }
1389 
1390 static void test_acpi_virt_tcg_pxb(void)
1391 {
1392     test_data data = {
1393         .machine = "virt",
1394         .tcg_only = true,
1395         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1396         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1397         .ram_start = 0x40000000ULL,
1398         .scan_len = 128ULL * 1024 * 1024,
1399     };
1400     /*
1401      * While using -cdrom, the cdrom would auto plugged into pxb-pcie,
1402      * the reason is the bus of pxb-pcie is also root bus, it would lead
1403      * to the error only PCI/PCIE bridge could plug onto pxb.
1404      * Therefore,thr cdrom is defined and plugged onto the scsi controller
1405      * to solve the conflicts.
1406      */
1407     data.variant = ".pxb";
1408     test_acpi_one(" -device pcie-root-port,chassis=1,id=pci.1"
1409                   " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
1410                   " -drive file="
1411                   "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2,"
1412                   "if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on"
1413                   " -device scsi-cd,bus=scsi0.0,scsi-id=0,"
1414                   "drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1"
1415                   " -cpu cortex-a57"
1416                   " -device pxb-pcie,bus_nr=128",
1417                   &data);
1418 
1419     free_test_data(&data);
1420 }
1421 
1422 static void test_acpi_tcg_acpi_hmat(const char *machine)
1423 {
1424     test_data data;
1425 
1426     memset(&data, 0, sizeof(data));
1427     data.machine = machine;
1428     data.variant = ".acpihmat";
1429     test_acpi_one(" -machine hmat=on"
1430                   " -smp 2,sockets=2"
1431                   " -m 128M,slots=2,maxmem=1G"
1432                   " -object memory-backend-ram,size=64M,id=m0"
1433                   " -object memory-backend-ram,size=64M,id=m1"
1434                   " -numa node,nodeid=0,memdev=m0"
1435                   " -numa node,nodeid=1,memdev=m1,initiator=0"
1436                   " -numa cpu,node-id=0,socket-id=0"
1437                   " -numa cpu,node-id=0,socket-id=1"
1438                   " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1439                   "data-type=access-latency,latency=1"
1440                   " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1441                   "data-type=access-bandwidth,bandwidth=65534M"
1442                   " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1443                   "data-type=access-latency,latency=65534"
1444                   " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1445                   "data-type=access-bandwidth,bandwidth=32767M"
1446                   " -numa hmat-cache,node-id=0,size=10K,level=1,"
1447                   "associativity=direct,policy=write-back,line=8"
1448                   " -numa hmat-cache,node-id=1,size=10K,level=1,"
1449                   "associativity=direct,policy=write-back,line=8",
1450                   &data);
1451     free_test_data(&data);
1452 }
1453 
1454 static void test_acpi_q35_tcg_acpi_hmat(void)
1455 {
1456     test_acpi_tcg_acpi_hmat(MACHINE_Q35);
1457 }
1458 
1459 static void test_acpi_piix4_tcg_acpi_hmat(void)
1460 {
1461     test_acpi_tcg_acpi_hmat(MACHINE_PC);
1462 }
1463 
1464 #ifdef CONFIG_POSIX
1465 static void test_acpi_erst(const char *machine)
1466 {
1467     gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
1468     gchar *params;
1469     test_data data;
1470 
1471     memset(&data, 0, sizeof(data));
1472     data.machine = machine;
1473     data.variant = ".acpierst";
1474     params = g_strdup_printf(
1475         " -object memory-backend-file,id=erstnvram,"
1476             "mem-path=%s,size=0x10000,share=on"
1477         " -device acpi-erst,memdev=erstnvram", tmp_path);
1478     test_acpi_one(params, &data);
1479     free_test_data(&data);
1480     g_free(params);
1481     g_assert(g_rmdir(tmp_path) == 0);
1482     g_free(tmp_path);
1483 }
1484 
1485 static void test_acpi_piix4_acpi_erst(void)
1486 {
1487     test_acpi_erst(MACHINE_PC);
1488 }
1489 
1490 static void test_acpi_q35_acpi_erst(void)
1491 {
1492     test_acpi_erst(MACHINE_Q35);
1493 }
1494 
1495 static void test_acpi_microvm_acpi_erst(void)
1496 {
1497     gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
1498     gchar *params;
1499     test_data data;
1500 
1501     test_acpi_microvm_prepare(&data);
1502     data.variant = ".pcie";
1503     data.tcg_only = true; /* need constant host-phys-bits */
1504     params = g_strdup_printf(" -machine microvm,"
1505         "acpi=on,ioapic2=off,rtc=off,pcie=on"
1506         " -object memory-backend-file,id=erstnvram,"
1507            "mem-path=%s,size=0x10000,share=on"
1508         " -device acpi-erst,memdev=erstnvram", tmp_path);
1509     test_acpi_one(params, &data);
1510     g_free(params);
1511     g_assert(g_rmdir(tmp_path) == 0);
1512     g_free(tmp_path);
1513     free_test_data(&data);
1514 }
1515 #endif /* CONFIG_POSIX */
1516 
1517 static void test_acpi_virt_tcg(void)
1518 {
1519     test_data data = {
1520         .machine = "virt",
1521         .tcg_only = true,
1522         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1523         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1524         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1525         .ram_start = 0x40000000ULL,
1526         .scan_len = 128ULL * 1024 * 1024,
1527     };
1528 
1529     data.smbios_cpu_max_speed = 2900;
1530     data.smbios_cpu_curr_speed = 2700;
1531     test_acpi_one("-cpu cortex-a57 "
1532                   "-smbios type=4,max-speed=2900,current-speed=2700", &data);
1533     free_test_data(&data);
1534 }
1535 
1536 static void test_acpi_q35_viot(void)
1537 {
1538     test_data data = {
1539         .machine = MACHINE_Q35,
1540         .variant = ".viot",
1541     };
1542 
1543     /*
1544      * To keep things interesting, two buses bypass the IOMMU.
1545      * VIOT should only describes the other two buses.
1546      */
1547     test_acpi_one("-machine default_bus_bypass_iommu=on "
1548                   "-device virtio-iommu-pci "
1549                   "-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 "
1550                   "-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on "
1551                   "-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0",
1552                   &data);
1553     free_test_data(&data);
1554 }
1555 
1556 #ifdef CONFIG_POSIX
1557 static void test_acpi_q35_cxl(void)
1558 {
1559     gchar *tmp_path = g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL);
1560     gchar *params;
1561 
1562     test_data data = {
1563         .machine = MACHINE_Q35,
1564         .variant = ".cxl",
1565     };
1566     /*
1567      * A complex CXL setup.
1568      */
1569     params = g_strdup_printf(" -machine cxl=on"
1570                              " -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M"
1571                              " -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M"
1572                              " -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M"
1573                              " -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M"
1574                              " -object memory-backend-file,id=lsa1,mem-path=%s,size=256M"
1575                              " -object memory-backend-file,id=lsa2,mem-path=%s,size=256M"
1576                              " -object memory-backend-file,id=lsa3,mem-path=%s,size=256M"
1577                              " -object memory-backend-file,id=lsa4,mem-path=%s,size=256M"
1578                              " -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1"
1579                              " -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2"
1580                              " -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2"
1581                              " -device cxl-type3,bus=rp1,memdev=cxl-mem1,lsa=lsa1"
1582                              " -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3"
1583                              " -device cxl-type3,bus=rp2,memdev=cxl-mem2,lsa=lsa2"
1584                              " -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5"
1585                              " -device cxl-type3,bus=rp3,memdev=cxl-mem3,lsa=lsa3"
1586                              " -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6"
1587                              " -device cxl-type3,bus=rp4,memdev=cxl-mem4,lsa=lsa4"
1588                              " -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k,"
1589                              "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",
1590                              tmp_path, tmp_path, tmp_path, tmp_path,
1591                              tmp_path, tmp_path, tmp_path, tmp_path);
1592     test_acpi_one(params, &data);
1593 
1594     g_free(params);
1595     g_assert(g_rmdir(tmp_path) == 0);
1596     g_free(tmp_path);
1597     free_test_data(&data);
1598 }
1599 #endif /* CONFIG_POSIX */
1600 
1601 static void test_acpi_virt_viot(void)
1602 {
1603     test_data data = {
1604         .machine = "virt",
1605         .tcg_only = true,
1606         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1607         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1608         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1609         .ram_start = 0x40000000ULL,
1610         .scan_len = 128ULL * 1024 * 1024,
1611     };
1612 
1613     test_acpi_one("-cpu cortex-a57 "
1614                   "-device virtio-iommu-pci", &data);
1615     free_test_data(&data);
1616 }
1617 
1618 #ifndef _WIN32
1619 # define DEV_NULL "/dev/null"
1620 #else
1621 # define DEV_NULL "nul"
1622 #endif
1623 
1624 static void test_acpi_q35_slic(void)
1625 {
1626     test_data data = {
1627         .machine = MACHINE_Q35,
1628         .variant = ".slic",
1629     };
1630 
1631     test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
1632                   "oem_rev=00002210,asl_compiler_id=qemu,"
1633                   "asl_compiler_rev=00000000,data=" DEV_NULL,
1634                   &data);
1635     free_test_data(&data);
1636 }
1637 
1638 static void test_acpi_q35_applesmc(void)
1639 {
1640     test_data data = {
1641         .machine = MACHINE_Q35,
1642         .variant = ".applesmc",
1643     };
1644 
1645     /* supply fake 64-byte OSK to silence missing key warning */
1646     test_acpi_one("-device isa-applesmc,osk=any64characterfakeoskisenough"
1647                   "topreventinvalidkeywarningsonstderr", &data);
1648     free_test_data(&data);
1649 }
1650 
1651 static void test_acpi_q35_pvpanic_isa(void)
1652 {
1653     test_data data = {
1654         .machine = MACHINE_Q35,
1655         .variant = ".pvpanic-isa",
1656     };
1657 
1658     test_acpi_one("-device pvpanic", &data);
1659     free_test_data(&data);
1660 }
1661 
1662 static void test_oem_fields(test_data *data)
1663 {
1664     int i;
1665 
1666     for (i = 0; i < data->tables->len; ++i) {
1667         AcpiSdtTable *sdt;
1668 
1669         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
1670         /* FACS doesn't have OEMID and OEMTABLEID fields */
1671         if (compare_signature(sdt, "FACS")) {
1672             continue;
1673         }
1674 
1675         g_assert(strncmp((char *)sdt->aml + 10, OEM_ID, 6) == 0);
1676         g_assert(strncmp((char *)sdt->aml + 16, OEM_TABLE_ID, 8) == 0);
1677     }
1678 }
1679 
1680 static void test_acpi_piix4_oem_fields(void)
1681 {
1682     test_data data;
1683     char *args;
1684 
1685     memset(&data, 0, sizeof(data));
1686     data.machine = MACHINE_PC;
1687     data.required_struct_types = base_required_struct_types;
1688     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
1689 
1690     args = test_acpi_create_args(&data,
1691                                  OEM_TEST_ARGS, false);
1692     data.qts = qtest_init(args);
1693     test_acpi_load_tables(&data, false);
1694     test_oem_fields(&data);
1695     qtest_quit(data.qts);
1696     free_test_data(&data);
1697     g_free(args);
1698 }
1699 
1700 static void test_acpi_q35_oem_fields(void)
1701 {
1702     test_data data;
1703     char *args;
1704 
1705     memset(&data, 0, sizeof(data));
1706     data.machine = MACHINE_Q35;
1707     data.required_struct_types = base_required_struct_types;
1708     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
1709 
1710     args = test_acpi_create_args(&data,
1711                                  OEM_TEST_ARGS, false);
1712     data.qts = qtest_init(args);
1713     test_acpi_load_tables(&data, false);
1714     test_oem_fields(&data);
1715     qtest_quit(data.qts);
1716     free_test_data(&data);
1717     g_free(args);
1718 }
1719 
1720 static void test_acpi_microvm_oem_fields(void)
1721 {
1722     test_data data;
1723     char *args;
1724 
1725     test_acpi_microvm_prepare(&data);
1726 
1727     args = test_acpi_create_args(&data,
1728                                  OEM_TEST_ARGS",acpi=on", false);
1729     data.qts = qtest_init(args);
1730     test_acpi_load_tables(&data, false);
1731     test_oem_fields(&data);
1732     qtest_quit(data.qts);
1733     free_test_data(&data);
1734     g_free(args);
1735 }
1736 
1737 static void test_acpi_virt_oem_fields(void)
1738 {
1739     test_data data = {
1740         .machine = "virt",
1741         .tcg_only = true,
1742         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1743         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1744         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1745         .ram_start = 0x40000000ULL,
1746         .scan_len = 128ULL * 1024 * 1024,
1747     };
1748     char *args;
1749 
1750     args = test_acpi_create_args(&data,
1751                                  "-cpu cortex-a57 "OEM_TEST_ARGS, true);
1752     data.qts = qtest_init(args);
1753     test_acpi_load_tables(&data, true);
1754     test_oem_fields(&data);
1755     qtest_quit(data.qts);
1756     free_test_data(&data);
1757     g_free(args);
1758 }
1759 
1760 
1761 int main(int argc, char *argv[])
1762 {
1763     const char *arch = qtest_get_arch();
1764     const bool has_kvm = qtest_has_accel("kvm");
1765     const bool has_tcg = qtest_has_accel("tcg");
1766     int ret;
1767 
1768     g_test_init(&argc, &argv, NULL);
1769 
1770     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
1771         ret = boot_sector_init(disk);
1772         if (ret) {
1773             return ret;
1774         }
1775         if (qtest_has_machine(MACHINE_PC)) {
1776             qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
1777             qtest_add_func("acpi/piix4/oem-fields", test_acpi_piix4_oem_fields);
1778             qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
1779             qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
1780                            test_acpi_piix4_no_root_hotplug);
1781             qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
1782                            test_acpi_piix4_no_bridge_hotplug);
1783             qtest_add_func("acpi/piix4/pci-hotplug/off",
1784                            test_acpi_piix4_no_acpi_pci_hotplug);
1785             qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
1786             qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
1787             qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
1788             qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
1789             qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm);
1790             qtest_add_func("acpi/piix4/smm-compat",
1791                            test_acpi_piix4_tcg_smm_compat);
1792             qtest_add_func("acpi/piix4/smm-compat-nosmm",
1793                            test_acpi_piix4_tcg_smm_compat_nosmm);
1794             qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet);
1795             qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
1796             qtest_add_func("acpi/piix4/acpihmat",
1797                            test_acpi_piix4_tcg_acpi_hmat);
1798 #ifdef CONFIG_POSIX
1799             qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst);
1800 #endif
1801         }
1802         if (qtest_has_machine(MACHINE_Q35)) {
1803             qtest_add_func("acpi/q35", test_acpi_q35_tcg);
1804             qtest_add_func("acpi/q35/oem-fields", test_acpi_q35_oem_fields);
1805             if (tpm_model_is_available("-machine q35", "tpm-tis")) {
1806                 qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis);
1807                 qtest_add_func("acpi/q35/tpm12-tis",
1808                                test_acpi_q35_tcg_tpm12_tis);
1809             }
1810             qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
1811             qtest_add_func("acpi/q35/multif-bridge",
1812                            test_acpi_q35_multif_bridge);
1813             qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
1814             qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
1815             qtest_add_func("acpi/q35/smbus/ipmi", test_acpi_q35_tcg_smbus_ipmi);
1816             qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
1817             qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
1818             qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
1819             qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
1820             qtest_add_func("acpi/q35/smm-compat",
1821                            test_acpi_q35_tcg_smm_compat);
1822             qtest_add_func("acpi/q35/smm-compat-nosmm",
1823                            test_acpi_q35_tcg_smm_compat_nosmm);
1824             qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
1825             qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
1826             qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
1827 #ifdef CONFIG_POSIX
1828             qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst);
1829 #endif
1830             qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc);
1831             qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa);
1832             if (has_tcg) {
1833                 qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs);
1834             }
1835             if (has_kvm) {
1836                 qtest_add_func("acpi/q35/kvm/xapic", test_acpi_q35_kvm_xapic);
1837                 qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar);
1838             }
1839             qtest_add_func("acpi/q35/viot", test_acpi_q35_viot);
1840 #ifdef CONFIG_POSIX
1841             qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl);
1842 #endif
1843             qtest_add_func("acpi/q35/slic", test_acpi_q35_slic);
1844         }
1845         if (qtest_has_machine("microvm")) {
1846             qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
1847             qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
1848             qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
1849             qtest_add_func("acpi/microvm/ioapic2",
1850                            test_acpi_microvm_ioapic2_tcg);
1851             qtest_add_func("acpi/microvm/oem-fields",
1852                            test_acpi_microvm_oem_fields);
1853             if (has_tcg) {
1854                 if (strcmp(arch, "x86_64") == 0) {
1855                     qtest_add_func("acpi/microvm/pcie",
1856                                    test_acpi_microvm_pcie_tcg);
1857 #ifdef CONFIG_POSIX
1858                     qtest_add_func("acpi/microvm/acpierst",
1859                                    test_acpi_microvm_acpi_erst);
1860 #endif
1861                 }
1862             }
1863         }
1864     } else if (strcmp(arch, "aarch64") == 0) {
1865         if (has_tcg) {
1866             qtest_add_func("acpi/virt", test_acpi_virt_tcg);
1867             qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
1868             qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
1869             qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb);
1870             qtest_add_func("acpi/virt/oem-fields", test_acpi_virt_oem_fields);
1871             qtest_add_func("acpi/virt/viot", test_acpi_virt_viot);
1872         }
1873     }
1874     ret = g_test_run();
1875     boot_sector_cleanup(disk);
1876     return ret;
1877 }
1878