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