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