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