xref: /openbmc/qemu/tests/qtest/bios-tables-test.c (revision 7cc25f6c)
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 "qemu-common.h"
61 #include "hw/firmware/smbios.h"
62 #include "qemu/bitmap.h"
63 #include "acpi-utils.h"
64 #include "boot-sector.h"
65 #include "tpm-emu.h"
66 #include "hw/acpi/tpm.h"
67 
68 
69 #define MACHINE_PC "pc"
70 #define MACHINE_Q35 "q35"
71 
72 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
73 
74 typedef struct {
75     bool tcg_only;
76     const char *machine;
77     const char *variant;
78     const char *uefi_fl1;
79     const char *uefi_fl2;
80     const char *blkdev;
81     const char *cd;
82     const uint64_t ram_start;
83     const uint64_t scan_len;
84     uint64_t rsdp_addr;
85     uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
86     GArray *tables;
87     uint32_t smbios_ep_addr;
88     struct smbios_21_entry_point smbios_ep_table;
89     uint16_t smbios_cpu_max_speed;
90     uint16_t smbios_cpu_curr_speed;
91     uint8_t *required_struct_types;
92     int required_struct_types_len;
93     QTestState *qts;
94 } test_data;
95 
96 static char disk[] = "tests/acpi-test-disk-XXXXXX";
97 static const char *data_dir = "tests/data/acpi";
98 #ifdef CONFIG_IASL
99 static const char *iasl = CONFIG_IASL;
100 #else
101 static const char *iasl;
102 #endif
103 
104 static bool compare_signature(const AcpiSdtTable *sdt, const char *signature)
105 {
106    return !memcmp(sdt->aml, signature, 4);
107 }
108 
109 static void cleanup_table_descriptor(AcpiSdtTable *table)
110 {
111     g_free(table->aml);
112     if (table->aml_file &&
113         !table->tmp_files_retain &&
114         g_strstr_len(table->aml_file, -1, "aml-")) {
115         unlink(table->aml_file);
116     }
117     g_free(table->aml_file);
118     g_free(table->asl);
119     if (table->asl_file &&
120         !table->tmp_files_retain) {
121         unlink(table->asl_file);
122     }
123     g_free(table->asl_file);
124 }
125 
126 static void free_test_data(test_data *data)
127 {
128     int i;
129 
130     if (!data->tables) {
131         return;
132     }
133     for (i = 0; i < data->tables->len; ++i) {
134         cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
135     }
136 
137     g_array_free(data->tables, true);
138 }
139 
140 static void test_acpi_rsdp_table(test_data *data)
141 {
142     uint8_t *rsdp_table = data->rsdp_table;
143 
144     acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
145 
146     switch (rsdp_table[15 /* Revision offset */]) {
147     case 0: /* ACPI 1.0 RSDP */
148         /* With rev 1, checksum is only for the first 20 bytes */
149         g_assert(!acpi_calc_checksum(rsdp_table,  20));
150         break;
151     case 2: /* ACPI 2.0+ RSDP */
152         /* With revision 2, we have 2 checksums */
153         g_assert(!acpi_calc_checksum(rsdp_table, 20));
154         g_assert(!acpi_calc_checksum(rsdp_table, 36));
155         break;
156     default:
157         g_assert_not_reached();
158     }
159 }
160 
161 static void test_acpi_rxsdt_table(test_data *data)
162 {
163     const char *sig = "RSDT";
164     AcpiSdtTable rsdt = {};
165     int entry_size = 4;
166     int addr_off = 16 /* RsdtAddress */;
167     uint8_t *ent;
168 
169     if (data->rsdp_table[15 /* Revision offset */] != 0) {
170         addr_off = 24 /* XsdtAddress */;
171         entry_size = 8;
172         sig = "XSDT";
173     }
174     /* read [RX]SDT table */
175     acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
176                      &data->rsdp_table[addr_off], entry_size, sig, true);
177 
178     /* Load all tables and add to test list directly RSDT referenced tables */
179     ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
180         AcpiSdtTable ssdt_table = {};
181 
182         acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
183                          entry_size, NULL, true);
184         /* Add table to ASL test tables list */
185         g_array_append_val(data->tables, ssdt_table);
186     }
187     cleanup_table_descriptor(&rsdt);
188 }
189 
190 static void test_acpi_fadt_table(test_data *data)
191 {
192     /* FADT table is 1st */
193     AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
194     uint8_t *fadt_aml = table.aml;
195     uint32_t fadt_len = table.aml_len;
196     uint32_t val;
197     int dsdt_offset = 40 /* DSDT */;
198     int dsdt_entry_size = 4;
199 
200     g_assert(compare_signature(&table, "FACP"));
201 
202     /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
203     memcpy(&val, fadt_aml + 112 /* Flags */, 4);
204     val = le32_to_cpu(val);
205     if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
206         acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
207                          fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
208         g_array_append_val(data->tables, table);
209     }
210 
211     memcpy(&val, fadt_aml + dsdt_offset, 4);
212     val = le32_to_cpu(val);
213     if (!val) {
214         dsdt_offset = 140 /* X_DSDT */;
215         dsdt_entry_size = 8;
216     }
217     acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
218                      fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
219     g_array_append_val(data->tables, table);
220 
221     memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
222     memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
223     if (fadt_aml[8 /* FADT Major Version */] >= 3) {
224         memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
225         memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
226     }
227 
228     /* update checksum */
229     fadt_aml[9 /* Checksum */] = 0;
230     fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
231 }
232 
233 static void dump_aml_files(test_data *data, bool rebuild)
234 {
235     AcpiSdtTable *sdt;
236     GError *error = NULL;
237     gchar *aml_file = NULL;
238     gint fd;
239     ssize_t ret;
240     int i;
241 
242     for (i = 0; i < data->tables->len; ++i) {
243         const char *ext = data->variant ? data->variant : "";
244         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
245         g_assert(sdt->aml);
246 
247         if (rebuild) {
248             aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
249                                        sdt->aml, ext);
250             fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
251                         S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
252             if (fd < 0) {
253                 perror(aml_file);
254             }
255             g_assert(fd >= 0);
256         } else {
257             fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
258             g_assert_no_error(error);
259         }
260 
261         ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
262         g_assert(ret == sdt->aml_len);
263 
264         close(fd);
265 
266         g_free(aml_file);
267     }
268 }
269 
270 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
271 {
272     AcpiSdtTable *temp;
273     GError *error = NULL;
274     GString *command_line = g_string_new(iasl);
275     gint fd;
276     gchar *out, *out_err;
277     gboolean ret;
278     int i;
279 
280     fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
281     g_assert_no_error(error);
282     close(fd);
283 
284     /* build command line */
285     g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
286     if (compare_signature(sdt, "DSDT") ||
287         compare_signature(sdt, "SSDT")) {
288         for (i = 0; i < sdts->len; ++i) {
289             temp = &g_array_index(sdts, AcpiSdtTable, i);
290             if (compare_signature(temp, "DSDT") ||
291                 compare_signature(temp, "SSDT")) {
292                 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
293             }
294         }
295     }
296     g_string_append_printf(command_line, "-d %s", sdt->aml_file);
297 
298     /* pass 'out' and 'out_err' in order to be redirected */
299     ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
300     g_assert_no_error(error);
301     if (ret) {
302         ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
303                                   &sdt->asl_len, &error);
304         g_assert(ret);
305         g_assert_no_error(error);
306         ret = (sdt->asl_len > 0);
307     }
308 
309     g_free(out);
310     g_free(out_err);
311     g_string_free(command_line, true);
312 
313     return !ret;
314 }
315 
316 #define COMMENT_END "*/"
317 #define DEF_BLOCK "DefinitionBlock ("
318 #define BLOCK_NAME_END ","
319 
320 static GString *normalize_asl(gchar *asl_code)
321 {
322     GString *asl = g_string_new(asl_code);
323     gchar *comment, *block_name;
324 
325     /* strip comments (different generation days) */
326     comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
327     if (comment) {
328         comment += strlen(COMMENT_END);
329         while (*comment == '\n') {
330             comment++;
331         }
332         asl = g_string_erase(asl, 0, comment - asl->str);
333     }
334 
335     /* strip def block name (it has file path in it) */
336     if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
337         block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
338         g_assert(block_name);
339         asl = g_string_erase(asl, 0,
340                              block_name + sizeof(BLOCK_NAME_END) - asl->str);
341     }
342 
343     return asl;
344 }
345 
346 static GArray *load_expected_aml(test_data *data)
347 {
348     int i;
349     AcpiSdtTable *sdt;
350     GError *error = NULL;
351     gboolean ret;
352     gsize aml_len;
353 
354     GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
355     if (getenv("V")) {
356         fputc('\n', stderr);
357     }
358     for (i = 0; i < data->tables->len; ++i) {
359         AcpiSdtTable exp_sdt;
360         gchar *aml_file = NULL;
361         const char *ext = data->variant ? data->variant : "";
362 
363         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
364 
365         memset(&exp_sdt, 0, sizeof(exp_sdt));
366 
367 try_again:
368         aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
369                                    sdt->aml, ext);
370         if (getenv("V")) {
371             fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
372         }
373         if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
374             exp_sdt.aml_file = aml_file;
375         } else if (*ext != '\0') {
376             /* try fallback to generic (extension less) expected file */
377             ext = "";
378             g_free(aml_file);
379             goto try_again;
380         }
381         g_assert(exp_sdt.aml_file);
382         if (getenv("V")) {
383             fprintf(stderr, "Using expected file '%s'\n", aml_file);
384         }
385         ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
386                                   &aml_len, &error);
387         exp_sdt.aml_len = aml_len;
388         g_assert(ret);
389         g_assert_no_error(error);
390         g_assert(exp_sdt.aml);
391         if (!exp_sdt.aml_len) {
392             fprintf(stderr, "Warning! zero length expected file '%s'\n",
393                     aml_file);
394         }
395 
396         g_array_append_val(exp_tables, exp_sdt);
397     }
398 
399     return exp_tables;
400 }
401 
402 static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt)
403 {
404     const gchar *allowed_diff_file[] = {
405 #include "bios-tables-test-allowed-diff.h"
406         NULL
407     };
408     const gchar **f;
409 
410     for (f = allowed_diff_file; *f; ++f) {
411         if (!g_strcmp0(sdt->aml_file, *f)) {
412             return true;
413         }
414     }
415     return false;
416 }
417 
418 /* test the list of tables in @data->tables against reference tables */
419 static void test_acpi_asl(test_data *data)
420 {
421     int i;
422     AcpiSdtTable *sdt, *exp_sdt;
423     test_data exp_data;
424     gboolean exp_err, err, all_tables_match = true;
425 
426     memset(&exp_data, 0, sizeof(exp_data));
427     exp_data.tables = load_expected_aml(data);
428     dump_aml_files(data, false);
429     for (i = 0; i < data->tables->len; ++i) {
430         GString *asl, *exp_asl;
431 
432         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
433         exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
434 
435         if (sdt->aml_len == exp_sdt->aml_len &&
436             !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
437             /* Identical table binaries: no need to disassemble. */
438             continue;
439         }
440 
441         fprintf(stderr,
442                 "acpi-test: Warning! %.4s binary file mismatch. "
443                 "Actual [aml:%s], Expected [aml:%s].\n"
444                 "See source file tests/qtest/bios-tables-test.c "
445                 "for instructions on how to update expected files.\n",
446                 exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file);
447 
448         all_tables_match = all_tables_match &&
449             test_acpi_find_diff_allowed(exp_sdt);
450 
451         /*
452          *  don't try to decompile if IASL isn't present, in this case user
453          * will just 'get binary file mismatch' warnings and test failure
454          */
455         if (!iasl) {
456             continue;
457         }
458 
459         err = load_asl(data->tables, sdt);
460         asl = normalize_asl(sdt->asl);
461 
462         exp_err = load_asl(exp_data.tables, exp_sdt);
463         exp_asl = normalize_asl(exp_sdt->asl);
464 
465         /* TODO: check for warnings */
466         g_assert(!err || exp_err);
467 
468         if (g_strcmp0(asl->str, exp_asl->str)) {
469             sdt->tmp_files_retain = true;
470             if (exp_err) {
471                 fprintf(stderr,
472                         "Warning! iasl couldn't parse the expected aml\n");
473             } else {
474                 exp_sdt->tmp_files_retain = true;
475                 fprintf(stderr,
476                         "acpi-test: Warning! %.4s mismatch. "
477                         "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
478                         exp_sdt->aml, sdt->asl_file, sdt->aml_file,
479                         exp_sdt->asl_file, exp_sdt->aml_file);
480                 fflush(stderr);
481                 if (getenv("V")) {
482                     const char *diff_env = getenv("DIFF");
483                     const char *diff_cmd = diff_env ? diff_env : "diff -U 16";
484                     char *diff = g_strdup_printf("%s %s %s", diff_cmd,
485                                                  exp_sdt->asl_file, sdt->asl_file);
486                     int out = dup(STDOUT_FILENO);
487                     int ret G_GNUC_UNUSED;
488 
489                     dup2(STDERR_FILENO, STDOUT_FILENO);
490                     ret = system(diff) ;
491                     dup2(out, STDOUT_FILENO);
492                     close(out);
493                     g_free(diff);
494                 }
495             }
496         }
497         g_string_free(asl, true);
498         g_string_free(exp_asl, true);
499     }
500     if (!iasl && !all_tables_match) {
501         fprintf(stderr, "to see ASL diff between mismatched files install IASL,"
502                 " rebuild QEMU from scratch and re-run tests with V=1"
503                 " environment variable set");
504     }
505     g_assert(all_tables_match);
506 
507     free_test_data(&exp_data);
508 }
509 
510 static bool smbios_ep_table_ok(test_data *data)
511 {
512     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
513     uint32_t addr = data->smbios_ep_addr;
514 
515     qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
516     if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
517         return false;
518     }
519     if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
520         return false;
521     }
522     if (ep_table->structure_table_length == 0) {
523         return false;
524     }
525     if (ep_table->number_of_structures == 0) {
526         return false;
527     }
528     if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
529         acpi_calc_checksum((uint8_t *)ep_table + 0x10,
530                            sizeof *ep_table - 0x10)) {
531         return false;
532     }
533     return true;
534 }
535 
536 static void test_smbios_entry_point(test_data *data)
537 {
538     uint32_t off;
539 
540     /* find smbios entry point structure */
541     for (off = 0xf0000; off < 0x100000; off += 0x10) {
542         uint8_t sig[] = "_SM_";
543         int i;
544 
545         for (i = 0; i < sizeof sig - 1; ++i) {
546             sig[i] = qtest_readb(data->qts, off + i);
547         }
548 
549         if (!memcmp(sig, "_SM_", sizeof sig)) {
550             /* signature match, but is this a valid entry point? */
551             data->smbios_ep_addr = off;
552             if (smbios_ep_table_ok(data)) {
553                 break;
554             }
555         }
556     }
557 
558     g_assert_cmphex(off, <, 0x100000);
559 }
560 
561 static inline bool smbios_single_instance(uint8_t type)
562 {
563     switch (type) {
564     case 0:
565     case 1:
566     case 2:
567     case 3:
568     case 16:
569     case 32:
570     case 127:
571         return true;
572     default:
573         return false;
574     }
575 }
576 
577 static bool smbios_cpu_test(test_data *data, uint32_t addr)
578 {
579     uint16_t expect_speed[2];
580     uint16_t real;
581     int offset[2];
582     int i;
583 
584     /* Check CPU speed for backward compatibility */
585     offset[0] = offsetof(struct smbios_type_4, max_speed);
586     offset[1] = offsetof(struct smbios_type_4, current_speed);
587     expect_speed[0] = data->smbios_cpu_max_speed ? : 2000;
588     expect_speed[1] = data->smbios_cpu_curr_speed ? : 2000;
589 
590     for (i = 0; i < 2; i++) {
591         real = qtest_readw(data->qts, addr + offset[i]);
592         if (real != expect_speed[i]) {
593             fprintf(stderr, "Unexpected SMBIOS CPU speed: real %u expect %u\n",
594                     real, expect_speed[i]);
595             return false;
596         }
597     }
598 
599     return true;
600 }
601 
602 static void test_smbios_structs(test_data *data)
603 {
604     DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
605     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
606     uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
607     int i, len, max_len = 0;
608     uint8_t type, prv, crt;
609 
610     /* walk the smbios tables */
611     for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
612 
613         /* grab type and formatted area length from struct header */
614         type = qtest_readb(data->qts, addr);
615         g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
616         len = qtest_readb(data->qts, addr + 1);
617 
618         /* single-instance structs must not have been encountered before */
619         if (smbios_single_instance(type)) {
620             g_assert(!test_bit(type, struct_bitmap));
621         }
622         set_bit(type, struct_bitmap);
623 
624         if (type == 4) {
625             g_assert(smbios_cpu_test(data, addr));
626         }
627 
628         /* seek to end of unformatted string area of this struct ("\0\0") */
629         prv = crt = 1;
630         while (prv || crt) {
631             prv = crt;
632             crt = qtest_readb(data->qts, addr + len);
633             len++;
634         }
635 
636         /* keep track of max. struct size */
637         if (max_len < len) {
638             max_len = len;
639             g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
640         }
641 
642         /* start of next structure */
643         addr += len;
644     }
645 
646     /* total table length and max struct size must match entry point values */
647     g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
648                      addr - le32_to_cpu(ep_table->structure_table_address));
649     g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
650 
651     /* required struct types must all be present */
652     for (i = 0; i < data->required_struct_types_len; i++) {
653         g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
654     }
655 }
656 
657 static void test_acpi_one(const char *params, test_data *data)
658 {
659     char *args;
660     bool use_uefi = data->uefi_fl1 && data->uefi_fl2;
661 
662 #ifndef CONFIG_TCG
663     if (data->tcg_only) {
664         g_test_skip("TCG disabled, skipping ACPI tcg_only test");
665         return;
666     }
667 #endif /* CONFIG_TCG */
668 
669     if (use_uefi) {
670         /*
671          * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
672          * when arm/virt boad starts to support it.
673          */
674         if (data->cd) {
675             args = g_strdup_printf("-machine %s %s -accel tcg "
676                 "-nodefaults -nographic "
677                 "-drive if=pflash,format=raw,file=%s,readonly=on "
678                 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
679                 data->machine, data->tcg_only ? "" : "-accel kvm",
680                 data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
681         } else {
682             args = g_strdup_printf("-machine %s %s -accel tcg "
683                 "-nodefaults -nographic "
684                 "-drive if=pflash,format=raw,file=%s,readonly=on "
685                 "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
686                 data->machine, data->tcg_only ? "" : "-accel kvm",
687                 data->uefi_fl1, data->uefi_fl2, params ? params : "");
688         }
689     } else {
690         args = g_strdup_printf("-machine %s %s -accel tcg "
691             "-net none -display none %s "
692             "-drive id=hd0,if=none,file=%s,format=raw "
693             "-device %s,drive=hd0 ",
694              data->machine, data->tcg_only ? "" : "-accel kvm",
695              params ? params : "", disk,
696              data->blkdev ?: "ide-hd");
697     }
698 
699     data->qts = qtest_init(args);
700 
701     if (use_uefi) {
702         g_assert(data->scan_len);
703         data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts,
704             data->ram_start, data->scan_len);
705     } else {
706         boot_sector_test(data->qts);
707         data->rsdp_addr = acpi_find_rsdp_address(data->qts);
708         g_assert_cmphex(data->rsdp_addr, <, 0x100000);
709     }
710 
711     data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
712     test_acpi_rsdp_table(data);
713     test_acpi_rxsdt_table(data);
714     test_acpi_fadt_table(data);
715 
716     if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
717         dump_aml_files(data, true);
718     } else {
719         test_acpi_asl(data);
720     }
721 
722     /*
723      * TODO: make SMBIOS tests work with UEFI firmware,
724      * Bug on uefi-test-tools to provide entry point:
725      * https://bugs.launchpad.net/qemu/+bug/1821884
726      */
727     if (!use_uefi) {
728         test_smbios_entry_point(data);
729         test_smbios_structs(data);
730     }
731 
732     qtest_quit(data->qts);
733     g_free(args);
734 }
735 
736 static uint8_t base_required_struct_types[] = {
737     0, 1, 3, 4, 16, 17, 19, 32, 127
738 };
739 
740 static void test_acpi_piix4_tcg(void)
741 {
742     test_data data;
743 
744     /* Supplying -machine accel argument overrides the default (qtest).
745      * This is to make guest actually run.
746      */
747     memset(&data, 0, sizeof(data));
748     data.machine = MACHINE_PC;
749     data.required_struct_types = base_required_struct_types;
750     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
751     test_acpi_one(NULL, &data);
752     free_test_data(&data);
753 }
754 
755 static void test_acpi_piix4_tcg_bridge(void)
756 {
757     test_data data;
758 
759     memset(&data, 0, sizeof(data));
760     data.machine = MACHINE_PC;
761     data.variant = ".bridge";
762     data.required_struct_types = base_required_struct_types;
763     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
764     test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
765     free_test_data(&data);
766 }
767 
768 static void test_acpi_piix4_no_root_hotplug(void)
769 {
770     test_data data;
771 
772     memset(&data, 0, sizeof(data));
773     data.machine = MACHINE_PC;
774     data.variant = ".roothp";
775     data.required_struct_types = base_required_struct_types;
776     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
777     test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
778                   "-device pci-bridge,chassis_nr=1", &data);
779     free_test_data(&data);
780 }
781 
782 static void test_acpi_piix4_no_bridge_hotplug(void)
783 {
784     test_data data;
785 
786     memset(&data, 0, sizeof(data));
787     data.machine = MACHINE_PC;
788     data.variant = ".hpbridge";
789     data.required_struct_types = base_required_struct_types;
790     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
791     test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
792                   "-device pci-bridge,chassis_nr=1", &data);
793     free_test_data(&data);
794 }
795 
796 static void test_acpi_piix4_no_acpi_pci_hotplug(void)
797 {
798     test_data data;
799 
800     memset(&data, 0, sizeof(data));
801     data.machine = MACHINE_PC;
802     data.variant = ".hpbrroot";
803     data.required_struct_types = base_required_struct_types;
804     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
805     test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
806                   "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
807                   "-device pci-bridge,chassis_nr=1", &data);
808     free_test_data(&data);
809 }
810 
811 static void test_acpi_q35_tcg(void)
812 {
813     test_data data;
814 
815     memset(&data, 0, sizeof(data));
816     data.machine = MACHINE_Q35;
817     data.required_struct_types = base_required_struct_types;
818     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
819     test_acpi_one(NULL, &data);
820     free_test_data(&data);
821 
822     data.smbios_cpu_max_speed = 3000;
823     data.smbios_cpu_curr_speed = 2600;
824     test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data);
825     free_test_data(&data);
826 }
827 
828 static void test_acpi_q35_tcg_bridge(void)
829 {
830     test_data data;
831 
832     memset(&data, 0, sizeof(data));
833     data.machine = MACHINE_Q35;
834     data.variant = ".bridge";
835     data.required_struct_types = base_required_struct_types;
836     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
837     test_acpi_one("-device pci-bridge,chassis_nr=1",
838                   &data);
839     free_test_data(&data);
840 }
841 
842 static void test_acpi_q35_tcg_mmio64(void)
843 {
844     test_data data = {
845         .machine = MACHINE_Q35,
846         .variant = ".mmio64",
847         .required_struct_types = base_required_struct_types,
848         .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
849     };
850 
851     test_acpi_one("-m 128M,slots=1,maxmem=2G "
852                   "-object memory-backend-ram,id=ram0,size=128M "
853                   "-numa node,memdev=ram0 "
854                   "-device pci-testdev,membar=2G",
855                   &data);
856     free_test_data(&data);
857 }
858 
859 static void test_acpi_piix4_tcg_cphp(void)
860 {
861     test_data data;
862 
863     memset(&data, 0, sizeof(data));
864     data.machine = MACHINE_PC;
865     data.variant = ".cphp";
866     test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
867                   " -object memory-backend-ram,id=ram0,size=64M"
868                   " -object memory-backend-ram,id=ram1,size=64M"
869                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
870                   " -numa dist,src=0,dst=1,val=21",
871                   &data);
872     free_test_data(&data);
873 }
874 
875 static void test_acpi_q35_tcg_cphp(void)
876 {
877     test_data data;
878 
879     memset(&data, 0, sizeof(data));
880     data.machine = MACHINE_Q35;
881     data.variant = ".cphp";
882     test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
883                   " -object memory-backend-ram,id=ram0,size=64M"
884                   " -object memory-backend-ram,id=ram1,size=64M"
885                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
886                   " -numa dist,src=0,dst=1,val=21",
887                   &data);
888     free_test_data(&data);
889 }
890 
891 static uint8_t ipmi_required_struct_types[] = {
892     0, 1, 3, 4, 16, 17, 19, 32, 38, 127
893 };
894 
895 static void test_acpi_q35_tcg_ipmi(void)
896 {
897     test_data data;
898 
899     memset(&data, 0, sizeof(data));
900     data.machine = MACHINE_Q35;
901     data.variant = ".ipmibt";
902     data.required_struct_types = ipmi_required_struct_types;
903     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
904     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
905                   " -device isa-ipmi-bt,bmc=bmc0",
906                   &data);
907     free_test_data(&data);
908 }
909 
910 static void test_acpi_piix4_tcg_ipmi(void)
911 {
912     test_data data;
913 
914     /* Supplying -machine accel argument overrides the default (qtest).
915      * This is to make guest actually run.
916      */
917     memset(&data, 0, sizeof(data));
918     data.machine = MACHINE_PC;
919     data.variant = ".ipmikcs";
920     data.required_struct_types = ipmi_required_struct_types;
921     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
922     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
923                   " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
924                   &data);
925     free_test_data(&data);
926 }
927 
928 static void test_acpi_q35_tcg_memhp(void)
929 {
930     test_data data;
931 
932     memset(&data, 0, sizeof(data));
933     data.machine = MACHINE_Q35;
934     data.variant = ".memhp";
935     test_acpi_one(" -m 128,slots=3,maxmem=1G"
936                   " -object memory-backend-ram,id=ram0,size=64M"
937                   " -object memory-backend-ram,id=ram1,size=64M"
938                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
939                   " -numa dist,src=0,dst=1,val=21",
940                   &data);
941     free_test_data(&data);
942 }
943 
944 static void test_acpi_piix4_tcg_memhp(void)
945 {
946     test_data data;
947 
948     memset(&data, 0, sizeof(data));
949     data.machine = MACHINE_PC;
950     data.variant = ".memhp";
951     test_acpi_one(" -m 128,slots=3,maxmem=1G"
952                   " -object memory-backend-ram,id=ram0,size=64M"
953                   " -object memory-backend-ram,id=ram1,size=64M"
954                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
955                   " -numa dist,src=0,dst=1,val=21",
956                   &data);
957     free_test_data(&data);
958 }
959 
960 static void test_acpi_q35_tcg_numamem(void)
961 {
962     test_data data;
963 
964     memset(&data, 0, sizeof(data));
965     data.machine = MACHINE_Q35;
966     data.variant = ".numamem";
967     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
968                   " -numa node -numa node,memdev=ram0", &data);
969     free_test_data(&data);
970 }
971 
972 static void test_acpi_piix4_tcg_numamem(void)
973 {
974     test_data data;
975 
976     memset(&data, 0, sizeof(data));
977     data.machine = MACHINE_PC;
978     data.variant = ".numamem";
979     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
980                   " -numa node -numa node,memdev=ram0", &data);
981     free_test_data(&data);
982 }
983 
984 uint64_t tpm_tis_base_addr;
985 
986 static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
987                               uint64_t base)
988 {
989 #ifdef CONFIG_TPM
990     gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
991                                           machine, tpm_if);
992     char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
993     TestState test;
994     test_data data;
995     GThread *thread;
996     char *args, *variant = g_strdup_printf(".%s", tpm_if);
997 
998     tpm_tis_base_addr = base;
999 
1000     module_call_init(MODULE_INIT_QOM);
1001 
1002     test.addr = g_new0(SocketAddress, 1);
1003     test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
1004     test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
1005     g_mutex_init(&test.data_mutex);
1006     g_cond_init(&test.data_cond);
1007     test.data_cond_signal = false;
1008 
1009     thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
1010     tpm_emu_test_wait_cond(&test);
1011 
1012     memset(&data, 0, sizeof(data));
1013     data.machine = machine;
1014     data.variant = variant;
1015 
1016     args = g_strdup_printf(
1017         " -chardev socket,id=chr,path=%s"
1018         " -tpmdev emulator,id=dev,chardev=chr"
1019         " -device tpm-%s,tpmdev=dev",
1020         test.addr->u.q_unix.path, tpm_if);
1021 
1022     test_acpi_one(args, &data);
1023 
1024     g_thread_join(thread);
1025     g_unlink(test.addr->u.q_unix.path);
1026     qapi_free_SocketAddress(test.addr);
1027     g_rmdir(tmp_path);
1028     g_free(variant);
1029     g_free(tmp_path);
1030     g_free(tmp_dir_name);
1031     g_free(args);
1032     free_test_data(&data);
1033 #else
1034     g_test_skip("TPM disabled");
1035 #endif
1036 }
1037 
1038 static void test_acpi_q35_tcg_tpm_tis(void)
1039 {
1040     test_acpi_tcg_tpm("q35", "tis", 0xFED40000);
1041 }
1042 
1043 static void test_acpi_tcg_dimm_pxm(const char *machine)
1044 {
1045     test_data data;
1046 
1047     memset(&data, 0, sizeof(data));
1048     data.machine = machine;
1049     data.variant = ".dimmpxm";
1050     test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
1051                   " -smp 4,sockets=4"
1052                   " -m 128M,slots=3,maxmem=1G"
1053                   " -object memory-backend-ram,id=ram0,size=32M"
1054                   " -object memory-backend-ram,id=ram1,size=32M"
1055                   " -object memory-backend-ram,id=ram2,size=32M"
1056                   " -object memory-backend-ram,id=ram3,size=32M"
1057                   " -numa node,memdev=ram0,nodeid=0"
1058                   " -numa node,memdev=ram1,nodeid=1"
1059                   " -numa node,memdev=ram2,nodeid=2"
1060                   " -numa node,memdev=ram3,nodeid=3"
1061                   " -numa cpu,node-id=0,socket-id=0"
1062                   " -numa cpu,node-id=1,socket-id=1"
1063                   " -numa cpu,node-id=2,socket-id=2"
1064                   " -numa cpu,node-id=3,socket-id=3"
1065                   " -object memory-backend-ram,id=ram4,size=128M"
1066                   " -object memory-backend-ram,id=nvm0,size=128M"
1067                   " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
1068                   " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
1069                   &data);
1070     free_test_data(&data);
1071 }
1072 
1073 static void test_acpi_q35_tcg_dimm_pxm(void)
1074 {
1075     test_acpi_tcg_dimm_pxm(MACHINE_Q35);
1076 }
1077 
1078 static void test_acpi_piix4_tcg_dimm_pxm(void)
1079 {
1080     test_acpi_tcg_dimm_pxm(MACHINE_PC);
1081 }
1082 
1083 static void test_acpi_virt_tcg_memhp(void)
1084 {
1085     test_data data = {
1086         .machine = "virt",
1087         .tcg_only = true,
1088         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1089         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1090         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1091         .ram_start = 0x40000000ULL,
1092         .scan_len = 256ULL * 1024 * 1024,
1093     };
1094 
1095     data.variant = ".memhp";
1096     test_acpi_one(" -machine nvdimm=on"
1097                   " -cpu cortex-a57"
1098                   " -m 256M,slots=3,maxmem=1G"
1099                   " -object memory-backend-ram,id=ram0,size=128M"
1100                   " -object memory-backend-ram,id=ram1,size=128M"
1101                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
1102                   " -numa dist,src=0,dst=1,val=21"
1103                   " -object memory-backend-ram,id=ram2,size=128M"
1104                   " -object memory-backend-ram,id=nvm0,size=128M"
1105                   " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
1106                   " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
1107                   &data);
1108 
1109     free_test_data(&data);
1110 
1111 }
1112 
1113 static void test_acpi_microvm_prepare(test_data *data)
1114 {
1115     memset(data, 0, sizeof(*data));
1116     data->machine = "microvm";
1117     data->required_struct_types = NULL; /* no smbios */
1118     data->required_struct_types_len = 0;
1119     data->blkdev = "virtio-blk-device";
1120 }
1121 
1122 static void test_acpi_microvm_tcg(void)
1123 {
1124     test_data data;
1125 
1126     test_acpi_microvm_prepare(&data);
1127     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off",
1128                   &data);
1129     free_test_data(&data);
1130 }
1131 
1132 static void test_acpi_microvm_usb_tcg(void)
1133 {
1134     test_data data;
1135 
1136     test_acpi_microvm_prepare(&data);
1137     data.variant = ".usb";
1138     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off",
1139                   &data);
1140     free_test_data(&data);
1141 }
1142 
1143 static void test_acpi_microvm_rtc_tcg(void)
1144 {
1145     test_data data;
1146 
1147     test_acpi_microvm_prepare(&data);
1148     data.variant = ".rtc";
1149     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on",
1150                   &data);
1151     free_test_data(&data);
1152 }
1153 
1154 static void test_acpi_microvm_pcie_tcg(void)
1155 {
1156     test_data data;
1157 
1158     test_acpi_microvm_prepare(&data);
1159     data.variant = ".pcie";
1160     data.tcg_only = true; /* need constant host-phys-bits */
1161     test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on",
1162                   &data);
1163     free_test_data(&data);
1164 }
1165 
1166 static void test_acpi_microvm_ioapic2_tcg(void)
1167 {
1168     test_data data;
1169 
1170     test_acpi_microvm_prepare(&data);
1171     data.variant = ".ioapic2";
1172     test_acpi_one(" -machine microvm,acpi=on,ioapic2=on,rtc=off",
1173                   &data);
1174     free_test_data(&data);
1175 }
1176 
1177 static void test_acpi_virt_tcg_numamem(void)
1178 {
1179     test_data data = {
1180         .machine = "virt",
1181         .tcg_only = true,
1182         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1183         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1184         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1185         .ram_start = 0x40000000ULL,
1186         .scan_len = 128ULL * 1024 * 1024,
1187     };
1188 
1189     data.variant = ".numamem";
1190     test_acpi_one(" -cpu cortex-a57"
1191                   " -object memory-backend-ram,id=ram0,size=128M"
1192                   " -numa node,memdev=ram0",
1193                   &data);
1194 
1195     free_test_data(&data);
1196 
1197 }
1198 
1199 #ifdef CONFIG_PXB
1200 static void test_acpi_virt_tcg_pxb(void)
1201 {
1202     test_data data = {
1203         .machine = "virt",
1204         .tcg_only = true,
1205         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1206         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1207         .ram_start = 0x40000000ULL,
1208         .scan_len = 128ULL * 1024 * 1024,
1209     };
1210     /*
1211      * While using -cdrom, the cdrom would auto plugged into pxb-pcie,
1212      * the reason is the bus of pxb-pcie is also root bus, it would lead
1213      * to the error only PCI/PCIE bridge could plug onto pxb.
1214      * Therefore,thr cdrom is defined and plugged onto the scsi controller
1215      * to solve the conflicts.
1216      */
1217     data.variant = ".pxb";
1218     test_acpi_one(" -device pcie-root-port,chassis=1,id=pci.1"
1219                   " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
1220                   " -drive file="
1221                   "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2,"
1222                   "if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on"
1223                   " -device scsi-cd,bus=scsi0.0,scsi-id=0,"
1224                   "drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1"
1225                   " -cpu cortex-a57"
1226                   " -device pxb-pcie,bus_nr=128",
1227                   &data);
1228 
1229     free_test_data(&data);
1230 }
1231 #endif
1232 
1233 static void test_acpi_tcg_acpi_hmat(const char *machine)
1234 {
1235     test_data data;
1236 
1237     memset(&data, 0, sizeof(data));
1238     data.machine = machine;
1239     data.variant = ".acpihmat";
1240     test_acpi_one(" -machine hmat=on"
1241                   " -smp 2,sockets=2"
1242                   " -m 128M,slots=2,maxmem=1G"
1243                   " -object memory-backend-ram,size=64M,id=m0"
1244                   " -object memory-backend-ram,size=64M,id=m1"
1245                   " -numa node,nodeid=0,memdev=m0"
1246                   " -numa node,nodeid=1,memdev=m1,initiator=0"
1247                   " -numa cpu,node-id=0,socket-id=0"
1248                   " -numa cpu,node-id=0,socket-id=1"
1249                   " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1250                   "data-type=access-latency,latency=1"
1251                   " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1252                   "data-type=access-bandwidth,bandwidth=65534M"
1253                   " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1254                   "data-type=access-latency,latency=65534"
1255                   " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1256                   "data-type=access-bandwidth,bandwidth=32767M"
1257                   " -numa hmat-cache,node-id=0,size=10K,level=1,"
1258                   "associativity=direct,policy=write-back,line=8"
1259                   " -numa hmat-cache,node-id=1,size=10K,level=1,"
1260                   "associativity=direct,policy=write-back,line=8",
1261                   &data);
1262     free_test_data(&data);
1263 }
1264 
1265 static void test_acpi_q35_tcg_acpi_hmat(void)
1266 {
1267     test_acpi_tcg_acpi_hmat(MACHINE_Q35);
1268 }
1269 
1270 static void test_acpi_piix4_tcg_acpi_hmat(void)
1271 {
1272     test_acpi_tcg_acpi_hmat(MACHINE_PC);
1273 }
1274 
1275 static void test_acpi_virt_tcg(void)
1276 {
1277     test_data data = {
1278         .machine = "virt",
1279         .tcg_only = true,
1280         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1281         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1282         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1283         .ram_start = 0x40000000ULL,
1284         .scan_len = 128ULL * 1024 * 1024,
1285     };
1286 
1287     test_acpi_one("-cpu cortex-a57", &data);
1288     free_test_data(&data);
1289 
1290     data.smbios_cpu_max_speed = 2900;
1291     data.smbios_cpu_curr_speed = 2700;
1292     test_acpi_one("-cpu cortex-a57 "
1293                   "-smbios type=4,max-speed=2900,current-speed=2700", &data);
1294     free_test_data(&data);
1295 }
1296 
1297 int main(int argc, char *argv[])
1298 {
1299     const char *arch = qtest_get_arch();
1300     int ret;
1301 
1302     g_test_init(&argc, &argv, NULL);
1303 
1304     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
1305         ret = boot_sector_init(disk);
1306         if (ret) {
1307             return ret;
1308         }
1309 
1310         qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis);
1311         qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
1312         qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
1313         qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
1314                        test_acpi_piix4_no_root_hotplug);
1315         qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
1316                        test_acpi_piix4_no_bridge_hotplug);
1317         qtest_add_func("acpi/piix4/pci-hotplug/off",
1318                        test_acpi_piix4_no_acpi_pci_hotplug);
1319         qtest_add_func("acpi/q35", test_acpi_q35_tcg);
1320         qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
1321         qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
1322         qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
1323         qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
1324         qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
1325         qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
1326         qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
1327         qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
1328         qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
1329         qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
1330         qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
1331         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
1332         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
1333         qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
1334         qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
1335         qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
1336         qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
1337         qtest_add_func("acpi/microvm/ioapic2", test_acpi_microvm_ioapic2_tcg);
1338         if (strcmp(arch, "x86_64") == 0) {
1339             qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg);
1340         }
1341     } else if (strcmp(arch, "aarch64") == 0) {
1342         qtest_add_func("acpi/virt", test_acpi_virt_tcg);
1343         qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
1344         qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
1345 #ifdef CONFIG_PXB
1346         qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb);
1347 #endif
1348     }
1349     ret = g_test_run();
1350     boot_sector_cleanup(disk);
1351     return ret;
1352 }
1353