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 * MiB, 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 * MiB, 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 * MiB, 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 * MiB, 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_aarch64_virt_tcg_acpi_spcr(void) 1793 { 1794 test_data data = { 1795 .machine = "virt", 1796 .arch = "aarch64", 1797 .tcg_only = true, 1798 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 1799 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 1800 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 1801 .ram_start = 0x40000000ULL, 1802 .scan_len = 128ULL * 1024 * 1024, 1803 .variant = ".acpispcr", 1804 }; 1805 1806 test_acpi_one("-cpu cortex-a57 " 1807 " -machine spcr=off", &data); 1808 free_test_data(&data); 1809 } 1810 1811 static void test_acpi_riscv64_virt_tcg_acpi_spcr(void) 1812 { 1813 test_data data = { 1814 .machine = "virt", 1815 .arch = "riscv64", 1816 .tcg_only = true, 1817 .uefi_fl1 = "pc-bios/edk2-riscv-code.fd", 1818 .uefi_fl2 = "pc-bios/edk2-riscv-vars.fd", 1819 .cd = "tests/data/uefi-boot-images/bios-tables-test.riscv64.iso.qcow2", 1820 .ram_start = 0x80000000ULL, 1821 .scan_len = 128ULL * 1024 * 1024, 1822 .variant = ".acpispcr", 1823 }; 1824 1825 test_acpi_one("-cpu rva22s64 " 1826 "-machine spcr=off", &data); 1827 free_test_data(&data); 1828 } 1829 1830 static void test_acpi_tcg_acpi_hmat(const char *machine, const char *arch) 1831 { 1832 test_data data = {}; 1833 1834 data.machine = machine; 1835 data.arch = arch; 1836 data.variant = ".acpihmat"; 1837 test_acpi_one(" -machine hmat=on" 1838 " -smp 2,sockets=2" 1839 " -m 128M,slots=2,maxmem=1G" 1840 " -object memory-backend-ram,size=64M,id=m0" 1841 " -object memory-backend-ram,size=64M,id=m1" 1842 " -numa node,nodeid=0,memdev=m0" 1843 " -numa node,nodeid=1,memdev=m1,initiator=0" 1844 " -numa cpu,node-id=0,socket-id=0" 1845 " -numa cpu,node-id=0,socket-id=1" 1846 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 1847 "data-type=access-latency,latency=1" 1848 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 1849 "data-type=access-bandwidth,bandwidth=65534M" 1850 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," 1851 "data-type=access-latency,latency=65534" 1852 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," 1853 "data-type=access-bandwidth,bandwidth=32767M" 1854 " -numa hmat-cache,node-id=0,size=10K,level=1," 1855 "associativity=direct,policy=write-back,line=8" 1856 " -numa hmat-cache,node-id=1,size=10K,level=1," 1857 "associativity=direct,policy=write-back,line=8", 1858 &data); 1859 free_test_data(&data); 1860 } 1861 1862 static void test_acpi_q35_tcg_acpi_hmat(void) 1863 { 1864 test_acpi_tcg_acpi_hmat(MACHINE_Q35, "x86"); 1865 } 1866 1867 static void test_acpi_piix4_tcg_acpi_hmat(void) 1868 { 1869 test_acpi_tcg_acpi_hmat(MACHINE_PC, "x86"); 1870 } 1871 1872 static void test_acpi_aarch64_virt_tcg_acpi_hmat(void) 1873 { 1874 test_data data = { 1875 .machine = "virt", 1876 .arch = "aarch64", 1877 .tcg_only = true, 1878 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 1879 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 1880 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 1881 .ram_start = 0x40000000ULL, 1882 .scan_len = 128ULL * MiB, 1883 }; 1884 1885 data.variant = ".acpihmatvirt"; 1886 1887 test_acpi_one(" -machine hmat=on" 1888 " -cpu cortex-a57" 1889 " -smp 4,sockets=2" 1890 " -m 384M" 1891 " -object memory-backend-ram,size=128M,id=ram0" 1892 " -object memory-backend-ram,size=128M,id=ram1" 1893 " -object memory-backend-ram,size=128M,id=ram2" 1894 " -numa node,nodeid=0,memdev=ram0" 1895 " -numa node,nodeid=1,memdev=ram1" 1896 " -numa node,nodeid=2,memdev=ram2" 1897 " -numa cpu,node-id=0,socket-id=0" 1898 " -numa cpu,node-id=0,socket-id=0" 1899 " -numa cpu,node-id=1,socket-id=1" 1900 " -numa cpu,node-id=1,socket-id=1" 1901 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 1902 "data-type=access-latency,latency=10" 1903 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 1904 "data-type=access-bandwidth,bandwidth=10485760" 1905 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," 1906 "data-type=access-latency,latency=20" 1907 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," 1908 "data-type=access-bandwidth,bandwidth=5242880" 1909 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory," 1910 "data-type=access-latency,latency=30" 1911 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory," 1912 "data-type=access-bandwidth,bandwidth=1048576" 1913 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory," 1914 "data-type=access-latency,latency=20" 1915 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory," 1916 "data-type=access-bandwidth,bandwidth=5242880" 1917 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory," 1918 "data-type=access-latency,latency=10" 1919 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory," 1920 "data-type=access-bandwidth,bandwidth=10485760" 1921 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory," 1922 "data-type=access-latency,latency=30" 1923 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory," 1924 "data-type=access-bandwidth,bandwidth=1048576", 1925 &data); 1926 1927 free_test_data(&data); 1928 } 1929 1930 static void test_acpi_q35_tcg_acpi_hmat_noinitiator(void) 1931 { 1932 test_data data = {}; 1933 1934 data.machine = MACHINE_Q35; 1935 data.arch = "x86"; 1936 data.variant = ".acpihmat-noinitiator"; 1937 test_acpi_one(" -machine hmat=on" 1938 " -smp 4,sockets=2" 1939 " -m 128M" 1940 " -object memory-backend-ram,size=32M,id=ram0" 1941 " -object memory-backend-ram,size=32M,id=ram1" 1942 " -object memory-backend-ram,size=64M,id=ram2" 1943 " -numa node,nodeid=0,memdev=ram0" 1944 " -numa node,nodeid=1,memdev=ram1" 1945 " -numa node,nodeid=2,memdev=ram2" 1946 " -numa cpu,node-id=0,socket-id=0" 1947 " -numa cpu,node-id=0,socket-id=0" 1948 " -numa cpu,node-id=1,socket-id=1" 1949 " -numa cpu,node-id=1,socket-id=1" 1950 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 1951 "data-type=access-latency,latency=10" 1952 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 1953 "data-type=access-bandwidth,bandwidth=10485760" 1954 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," 1955 "data-type=access-latency,latency=20" 1956 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," 1957 "data-type=access-bandwidth,bandwidth=5242880" 1958 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory," 1959 "data-type=access-latency,latency=30" 1960 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory," 1961 "data-type=access-bandwidth,bandwidth=1048576" 1962 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory," 1963 "data-type=access-latency,latency=20" 1964 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory," 1965 "data-type=access-bandwidth,bandwidth=5242880" 1966 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory," 1967 "data-type=access-latency,latency=10" 1968 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory," 1969 "data-type=access-bandwidth,bandwidth=10485760" 1970 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory," 1971 "data-type=access-latency,latency=30" 1972 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory," 1973 "data-type=access-bandwidth,bandwidth=1048576", 1974 &data); 1975 free_test_data(&data); 1976 } 1977 1978 /* Test intended to hit corner cases of SRAT and HMAT */ 1979 static void test_acpi_q35_tcg_acpi_hmat_generic_x(void) 1980 { 1981 test_data data = {}; 1982 1983 data.machine = MACHINE_Q35; 1984 data.arch = "x86"; 1985 data.variant = ".acpihmat-generic-x"; 1986 test_acpi_one(" -machine hmat=on,cxl=on" 1987 " -smp 3,sockets=3" 1988 " -m 128M,maxmem=384M,slots=2" 1989 " -device pcie-root-port,chassis=1,id=pci.1" 1990 " -device pci-testdev,bus=pci.1," 1991 "multifunction=on,addr=00.0" 1992 " -device pci-testdev,bus=pci.1,addr=00.1" 1993 " -device pci-testdev,bus=pci.1,id=gidev,addr=00.2" 1994 " -device pxb-cxl,bus_nr=64,bus=pcie.0,id=cxl.1" 1995 " -object memory-backend-ram,size=64M,id=ram0" 1996 " -object memory-backend-ram,size=64M,id=ram1" 1997 " -numa node,nodeid=0,cpus=0,memdev=ram0" 1998 " -numa node,nodeid=1" 1999 " -object acpi-generic-initiator,id=gi0,pci-dev=gidev,node=1" 2000 " -numa node,nodeid=2" 2001 " -object acpi-generic-port,id=gp0,pci-bus=cxl.1,node=2" 2002 " -numa node,nodeid=3,cpus=1" 2003 " -numa node,nodeid=4,memdev=ram1" 2004 " -numa node,nodeid=5,cpus=2" 2005 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 2006 "data-type=access-latency,latency=10" 2007 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," 2008 "data-type=access-bandwidth,bandwidth=800M" 2009 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory," 2010 "data-type=access-latency,latency=100" 2011 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory," 2012 "data-type=access-bandwidth,bandwidth=200M" 2013 " -numa hmat-lb,initiator=0,target=4,hierarchy=memory," 2014 "data-type=access-latency,latency=100" 2015 " -numa hmat-lb,initiator=0,target=4,hierarchy=memory," 2016 "data-type=access-bandwidth,bandwidth=200M" 2017 " -numa hmat-lb,initiator=0,target=5,hierarchy=memory," 2018 "data-type=access-latency,latency=200" 2019 " -numa hmat-lb,initiator=0,target=5,hierarchy=memory," 2020 "data-type=access-bandwidth,bandwidth=400M" 2021 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory," 2022 "data-type=access-latency,latency=500" 2023 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory," 2024 "data-type=access-bandwidth,bandwidth=100M" 2025 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory," 2026 "data-type=access-latency,latency=50" 2027 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory," 2028 "data-type=access-bandwidth,bandwidth=400M" 2029 " -numa hmat-lb,initiator=1,target=4,hierarchy=memory," 2030 "data-type=access-latency,latency=50" 2031 " -numa hmat-lb,initiator=1,target=4,hierarchy=memory," 2032 "data-type=access-bandwidth,bandwidth=800M" 2033 " -numa hmat-lb,initiator=1,target=5,hierarchy=memory," 2034 "data-type=access-latency,latency=500" 2035 " -numa hmat-lb,initiator=1,target=5,hierarchy=memory," 2036 "data-type=access-bandwidth,bandwidth=100M" 2037 " -numa hmat-lb,initiator=3,target=0,hierarchy=memory," 2038 "data-type=access-latency,latency=20" 2039 " -numa hmat-lb,initiator=3,target=0,hierarchy=memory," 2040 "data-type=access-bandwidth,bandwidth=400M" 2041 " -numa hmat-lb,initiator=3,target=2,hierarchy=memory," 2042 "data-type=access-latency,latency=80" 2043 " -numa hmat-lb,initiator=3,target=2,hierarchy=memory," 2044 "data-type=access-bandwidth,bandwidth=200M" 2045 " -numa hmat-lb,initiator=3,target=4,hierarchy=memory," 2046 "data-type=access-latency,latency=80" 2047 " -numa hmat-lb,initiator=3,target=4,hierarchy=memory," 2048 "data-type=access-bandwidth,bandwidth=200M" 2049 " -numa hmat-lb,initiator=3,target=5,hierarchy=memory," 2050 "data-type=access-latency,latency=20" 2051 " -numa hmat-lb,initiator=3,target=5,hierarchy=memory," 2052 "data-type=access-bandwidth,bandwidth=400M" 2053 " -numa hmat-lb,initiator=5,target=0,hierarchy=memory," 2054 "data-type=access-latency,latency=20" 2055 " -numa hmat-lb,initiator=5,target=0,hierarchy=memory," 2056 "data-type=access-bandwidth,bandwidth=400M" 2057 " -numa hmat-lb,initiator=5,target=2,hierarchy=memory," 2058 "data-type=access-latency,latency=80" 2059 " -numa hmat-lb,initiator=5,target=4,hierarchy=memory," 2060 "data-type=access-bandwidth,bandwidth=200M" 2061 " -numa hmat-lb,initiator=5,target=4,hierarchy=memory," 2062 "data-type=access-latency,latency=80" 2063 " -numa hmat-lb,initiator=5,target=2,hierarchy=memory," 2064 "data-type=access-bandwidth,bandwidth=200M" 2065 " -numa hmat-lb,initiator=5,target=5,hierarchy=memory," 2066 "data-type=access-latency,latency=10" 2067 " -numa hmat-lb,initiator=5,target=5,hierarchy=memory," 2068 "data-type=access-bandwidth,bandwidth=800M", 2069 &data); 2070 free_test_data(&data); 2071 } 2072 2073 #ifdef CONFIG_POSIX 2074 static void test_acpi_erst(const char *machine, const char *arch) 2075 { 2076 gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL); 2077 gchar *params; 2078 test_data data = {}; 2079 2080 data.machine = machine; 2081 data.arch = arch; 2082 data.variant = ".acpierst"; 2083 params = g_strdup_printf( 2084 " -object memory-backend-file,id=erstnvram," 2085 "mem-path=%s,size=0x10000,share=on" 2086 " -device acpi-erst,memdev=erstnvram", tmp_path); 2087 test_acpi_one(params, &data); 2088 free_test_data(&data); 2089 g_free(params); 2090 g_assert(g_rmdir(tmp_path) == 0); 2091 g_free(tmp_path); 2092 } 2093 2094 static void test_acpi_piix4_acpi_erst(void) 2095 { 2096 test_acpi_erst(MACHINE_PC, "x86"); 2097 } 2098 2099 static void test_acpi_q35_acpi_erst(void) 2100 { 2101 test_acpi_erst(MACHINE_Q35, "x86"); 2102 } 2103 2104 static void test_acpi_microvm_acpi_erst(void) 2105 { 2106 gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL); 2107 gchar *params; 2108 test_data data = {}; 2109 2110 test_acpi_microvm_prepare(&data); 2111 data.variant = ".pcie"; 2112 data.tcg_only = true; /* need constant host-phys-bits */ 2113 params = g_strdup_printf(" -machine microvm," 2114 "acpi=on,ioapic2=off,rtc=off,pcie=on" 2115 " -object memory-backend-file,id=erstnvram," 2116 "mem-path=%s,size=0x10000,share=on" 2117 " -device acpi-erst,memdev=erstnvram", tmp_path); 2118 test_acpi_one(params, &data); 2119 g_free(params); 2120 g_assert(g_rmdir(tmp_path) == 0); 2121 g_free(tmp_path); 2122 free_test_data(&data); 2123 } 2124 #endif /* CONFIG_POSIX */ 2125 2126 static void test_acpi_riscv64_virt_tcg(void) 2127 { 2128 test_data data = { 2129 .machine = "virt", 2130 .arch = "riscv64", 2131 .tcg_only = true, 2132 .uefi_fl1 = "pc-bios/edk2-riscv-code.fd", 2133 .uefi_fl2 = "pc-bios/edk2-riscv-vars.fd", 2134 .cd = "tests/data/uefi-boot-images/bios-tables-test.riscv64.iso.qcow2", 2135 .ram_start = 0x80000000ULL, 2136 .scan_len = 128ULL * MiB, 2137 }; 2138 2139 /* 2140 * RHCT will have ISA string encoded. To reduce the effort 2141 * of updating expected AML file for any new default ISA extension, 2142 * use the profile rva22s64. 2143 */ 2144 test_acpi_one("-cpu rva22s64 ", &data); 2145 free_test_data(&data); 2146 } 2147 2148 static void test_acpi_aarch64_virt_tcg(void) 2149 { 2150 test_data data = { 2151 .machine = "virt", 2152 .arch = "aarch64", 2153 .tcg_only = true, 2154 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 2155 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 2156 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 2157 .ram_start = 0x40000000ULL, 2158 .scan_len = 128ULL * MiB, 2159 }; 2160 2161 data.smbios_cpu_max_speed = 2900; 2162 data.smbios_cpu_curr_speed = 2700; 2163 test_acpi_one("-cpu cortex-a57 " 2164 "-smbios type=4,max-speed=2900,current-speed=2700", &data); 2165 free_test_data(&data); 2166 } 2167 2168 static void test_acpi_aarch64_virt_tcg_topology(void) 2169 { 2170 test_data data = { 2171 .machine = "virt", 2172 .arch = "aarch64", 2173 .variant = ".topology", 2174 .tcg_only = true, 2175 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 2176 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 2177 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 2178 .ram_start = 0x40000000ULL, 2179 .scan_len = 128ULL * MiB, 2180 }; 2181 2182 test_acpi_one("-cpu cortex-a57 " 2183 "-smp sockets=1,clusters=2,cores=2,threads=2", &data); 2184 free_test_data(&data); 2185 } 2186 2187 static void test_acpi_aarch64_virt_tcg_its_off(void) 2188 { 2189 test_data data = { 2190 .machine = "virt", 2191 .arch = "aarch64", 2192 .variant = ".its_off", 2193 .tcg_only = true, 2194 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 2195 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 2196 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 2197 .ram_start = 0x40000000ULL, 2198 .scan_len = 128ULL * 1024 * 1024, 2199 }; 2200 2201 test_acpi_one("-cpu cortex-a57 " 2202 "-M gic-version=3,iommu=smmuv3,its=off", &data); 2203 free_test_data(&data); 2204 } 2205 2206 static void test_acpi_q35_viot(void) 2207 { 2208 test_data data = { 2209 .machine = MACHINE_Q35, 2210 .arch = "x86", 2211 .variant = ".viot", 2212 }; 2213 2214 /* 2215 * To keep things interesting, two buses bypass the IOMMU. 2216 * VIOT should only describes the other two buses. 2217 */ 2218 test_acpi_one("-machine default_bus_bypass_iommu=on " 2219 "-device virtio-iommu-pci " 2220 "-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 " 2221 "-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on " 2222 "-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0", 2223 &data); 2224 free_test_data(&data); 2225 } 2226 2227 #ifdef CONFIG_POSIX 2228 static void test_acpi_q35_cxl(void) 2229 { 2230 gchar *tmp_path = g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL); 2231 gchar *params; 2232 2233 test_data data = { 2234 .machine = MACHINE_Q35, 2235 .arch = "x86", 2236 .variant = ".cxl", 2237 }; 2238 /* 2239 * A complex CXL setup. 2240 */ 2241 params = g_strdup_printf(" -machine cxl=on" 2242 " -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M" 2243 " -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M" 2244 " -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M" 2245 " -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M" 2246 " -object memory-backend-file,id=lsa1,mem-path=%s,size=256M" 2247 " -object memory-backend-file,id=lsa2,mem-path=%s,size=256M" 2248 " -object memory-backend-file,id=lsa3,mem-path=%s,size=256M" 2249 " -object memory-backend-file,id=lsa4,mem-path=%s,size=256M" 2250 " -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1" 2251 " -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2" 2252 " -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2" 2253 " -device cxl-type3,bus=rp1,persistent-memdev=cxl-mem1,lsa=lsa1" 2254 " -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3" 2255 " -device cxl-type3,bus=rp2,persistent-memdev=cxl-mem2,lsa=lsa2" 2256 " -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5" 2257 " -device cxl-type3,bus=rp3,persistent-memdev=cxl-mem3,lsa=lsa3" 2258 " -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6" 2259 " -device cxl-type3,bus=rp4,persistent-memdev=cxl-mem4,lsa=lsa4" 2260 " -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k," 2261 "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", 2262 tmp_path, tmp_path, tmp_path, tmp_path, 2263 tmp_path, tmp_path, tmp_path, tmp_path); 2264 test_acpi_one(params, &data); 2265 2266 g_free(params); 2267 g_assert(g_rmdir(tmp_path) == 0); 2268 g_free(tmp_path); 2269 free_test_data(&data); 2270 } 2271 #endif /* CONFIG_POSIX */ 2272 2273 static void test_acpi_aarch64_virt_viot(void) 2274 { 2275 test_data data = { 2276 .machine = "virt", 2277 .arch = "aarch64", 2278 .tcg_only = true, 2279 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 2280 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 2281 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 2282 .ram_start = 0x40000000ULL, 2283 .scan_len = 128ULL * MiB, 2284 }; 2285 2286 test_acpi_one("-cpu cortex-a57 " 2287 "-device virtio-iommu-pci", &data); 2288 free_test_data(&data); 2289 } 2290 2291 #ifndef _WIN32 2292 # define DEV_NULL "/dev/null" 2293 #else 2294 # define DEV_NULL "nul" 2295 #endif 2296 2297 static void test_acpi_q35_slic(void) 2298 { 2299 test_data data = { 2300 .machine = MACHINE_Q35, 2301 .arch = "x86", 2302 .variant = ".slic", 2303 }; 2304 2305 test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME," 2306 "oem_rev=00002210,asl_compiler_id=qemu," 2307 "asl_compiler_rev=00000000,data=" DEV_NULL, 2308 &data); 2309 free_test_data(&data); 2310 } 2311 2312 static void test_acpi_q35_applesmc(void) 2313 { 2314 test_data data = { 2315 .machine = MACHINE_Q35, 2316 .arch = "x86", 2317 .variant = ".applesmc", 2318 }; 2319 2320 /* supply fake 64-byte OSK to silence missing key warning */ 2321 test_acpi_one("-device isa-applesmc,osk=any64characterfakeoskisenough" 2322 "topreventinvalidkeywarningsonstderr", &data); 2323 free_test_data(&data); 2324 } 2325 2326 static void test_acpi_q35_pvpanic_isa(void) 2327 { 2328 test_data data = { 2329 .machine = MACHINE_Q35, 2330 .arch = "x86", 2331 .variant = ".pvpanic-isa", 2332 }; 2333 2334 test_acpi_one("-device pvpanic", &data); 2335 free_test_data(&data); 2336 } 2337 2338 static void test_acpi_pc_smbios_options(void) 2339 { 2340 uint8_t req_type11[] = { 11 }; 2341 test_data data = { 2342 .machine = MACHINE_PC, 2343 .arch = "x86", 2344 .variant = ".pc_smbios_options", 2345 .required_struct_types = req_type11, 2346 .required_struct_types_len = ARRAY_SIZE(req_type11), 2347 }; 2348 2349 test_smbios("-smbios type=11,value=TEST", &data); 2350 free_test_data(&data); 2351 } 2352 2353 static void test_acpi_pc_smbios_blob(void) 2354 { 2355 uint8_t req_type11[] = { 11 }; 2356 test_data data = { 2357 .machine = MACHINE_PC, 2358 .arch = "x86", 2359 .variant = ".pc_smbios_blob", 2360 .required_struct_types = req_type11, 2361 .required_struct_types_len = ARRAY_SIZE(req_type11), 2362 }; 2363 2364 test_smbios("-machine smbios-entry-point-type=32 " 2365 "-smbios file=tests/data/smbios/type11_blob", &data); 2366 free_test_data(&data); 2367 } 2368 2369 static void test_acpi_isapc_smbios_legacy(void) 2370 { 2371 uint8_t req_type11[] = { 1, 11 }; 2372 test_data data = { 2373 .machine = "isapc", 2374 .variant = ".pc_smbios_legacy", 2375 .required_struct_types = req_type11, 2376 .required_struct_types_len = ARRAY_SIZE(req_type11), 2377 }; 2378 2379 test_smbios("-smbios file=tests/data/smbios/type11_blob.legacy " 2380 "-smbios type=1,family=TEST", &data); 2381 free_test_data(&data); 2382 } 2383 2384 static void test_oem_fields(test_data *data) 2385 { 2386 int i; 2387 2388 for (i = 0; i < data->tables->len; ++i) { 2389 AcpiSdtTable *sdt; 2390 2391 sdt = &g_array_index(data->tables, AcpiSdtTable, i); 2392 /* FACS doesn't have OEMID and OEMTABLEID fields */ 2393 if (compare_signature(sdt, "FACS")) { 2394 continue; 2395 } 2396 2397 g_assert(strncmp((char *)sdt->aml + 10, OEM_ID, 6) == 0); 2398 g_assert(strncmp((char *)sdt->aml + 16, OEM_TABLE_ID, 8) == 0); 2399 } 2400 } 2401 2402 static void test_acpi_piix4_oem_fields(void) 2403 { 2404 char *args; 2405 test_data data = {}; 2406 2407 data.machine = MACHINE_PC; 2408 data.arch = "x86"; 2409 data.required_struct_types = base_required_struct_types; 2410 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); 2411 2412 args = test_acpi_create_args(&data, OEM_TEST_ARGS); 2413 data.qts = qtest_init(args); 2414 test_acpi_load_tables(&data); 2415 test_oem_fields(&data); 2416 qtest_quit(data.qts); 2417 free_test_data(&data); 2418 g_free(args); 2419 } 2420 2421 static void test_acpi_q35_oem_fields(void) 2422 { 2423 char *args; 2424 test_data data = {}; 2425 2426 data.machine = MACHINE_Q35; 2427 data.arch = "x86"; 2428 data.required_struct_types = base_required_struct_types; 2429 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); 2430 2431 args = test_acpi_create_args(&data, OEM_TEST_ARGS); 2432 data.qts = qtest_init(args); 2433 test_acpi_load_tables(&data); 2434 test_oem_fields(&data); 2435 qtest_quit(data.qts); 2436 free_test_data(&data); 2437 g_free(args); 2438 } 2439 2440 static void test_acpi_microvm_oem_fields(void) 2441 { 2442 test_data data = {}; 2443 char *args; 2444 2445 test_acpi_microvm_prepare(&data); 2446 2447 args = test_acpi_create_args(&data, 2448 OEM_TEST_ARGS",acpi=on"); 2449 data.qts = qtest_init(args); 2450 test_acpi_load_tables(&data); 2451 test_oem_fields(&data); 2452 qtest_quit(data.qts); 2453 free_test_data(&data); 2454 g_free(args); 2455 } 2456 2457 static void test_acpi_aarch64_virt_oem_fields(void) 2458 { 2459 test_data data = { 2460 .machine = "virt", 2461 .arch = "aarch64", 2462 .tcg_only = true, 2463 .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", 2464 .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", 2465 .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", 2466 .ram_start = 0x40000000ULL, 2467 .scan_len = 128ULL * MiB, 2468 }; 2469 char *args; 2470 2471 args = test_acpi_create_args(&data, "-cpu cortex-a57 "OEM_TEST_ARGS); 2472 data.qts = qtest_init(args); 2473 test_acpi_load_tables(&data); 2474 test_oem_fields(&data); 2475 qtest_quit(data.qts); 2476 free_test_data(&data); 2477 g_free(args); 2478 } 2479 2480 #define LOONGARCH64_INIT_TEST_DATA(data) \ 2481 test_data data = { \ 2482 .machine = "virt", \ 2483 .arch = "loongarch64", \ 2484 .tcg_only = true, \ 2485 .uefi_fl1 = "pc-bios/edk2-loongarch64-code.fd", \ 2486 .uefi_fl2 = "pc-bios/edk2-loongarch64-vars.fd", \ 2487 .cd = "tests/data/uefi-boot-images/" \ 2488 "bios-tables-test.loongarch64.iso.qcow2", \ 2489 .ram_start = 0, \ 2490 .scan_len = 128ULL * MiB, \ 2491 } 2492 2493 static void test_acpi_loongarch64_virt(void) 2494 { 2495 LOONGARCH64_INIT_TEST_DATA(data); 2496 2497 test_acpi_one("-cpu la464 ", &data); 2498 free_test_data(&data); 2499 } 2500 2501 static void test_acpi_loongarch64_virt_topology(void) 2502 { 2503 LOONGARCH64_INIT_TEST_DATA(data); 2504 2505 data.variant = ".topology"; 2506 test_acpi_one("-cpu la464 -smp sockets=1,cores=2,threads=2", &data); 2507 free_test_data(&data); 2508 } 2509 2510 static void test_acpi_loongarch64_virt_numamem(void) 2511 { 2512 LOONGARCH64_INIT_TEST_DATA(data); 2513 2514 data.variant = ".numamem"; 2515 test_acpi_one(" -cpu la464 -m 128" 2516 " -object memory-backend-ram,id=ram0,size=64M" 2517 " -object memory-backend-ram,id=ram1,size=64M" 2518 " -numa node,memdev=ram0 -numa node,memdev=ram1" 2519 " -numa dist,src=0,dst=1,val=21", 2520 &data); 2521 free_test_data(&data); 2522 } 2523 2524 static void test_acpi_loongarch64_virt_memhp(void) 2525 { 2526 LOONGARCH64_INIT_TEST_DATA(data); 2527 2528 data.variant = ".memhp"; 2529 test_acpi_one(" -cpu la464 -m 128,slots=2,maxmem=256M" 2530 " -object memory-backend-ram,id=ram0,size=128M", 2531 &data); 2532 free_test_data(&data); 2533 } 2534 2535 static void test_acpi_loongarch64_virt_oem_fields(void) 2536 { 2537 LOONGARCH64_INIT_TEST_DATA(data); 2538 char *args; 2539 2540 args = test_acpi_create_args(&data, "-cpu la464 "OEM_TEST_ARGS); 2541 data.qts = qtest_init(args); 2542 test_acpi_load_tables(&data); 2543 test_oem_fields(&data); 2544 qtest_quit(data.qts); 2545 free_test_data(&data); 2546 g_free(args); 2547 } 2548 2549 int main(int argc, char *argv[]) 2550 { 2551 const char *arch = qtest_get_arch(); 2552 bool has_kvm, has_tcg; 2553 char *v_env = getenv("V"); 2554 int ret; 2555 2556 if (v_env) { 2557 verbosity_level = atoi(v_env); 2558 } 2559 2560 g_test_init(&argc, &argv, NULL); 2561 2562 has_kvm = qtest_has_accel("kvm"); 2563 has_tcg = qtest_has_accel("tcg"); 2564 2565 if (!has_tcg && !has_kvm) { 2566 g_test_skip("No KVM or TCG accelerator available"); 2567 return 0; 2568 } 2569 2570 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { 2571 ret = boot_sector_init(disk); 2572 if (ret) { 2573 return ret; 2574 } 2575 if (qtest_has_machine(MACHINE_PC)) { 2576 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg); 2577 qtest_add_func("acpi/piix4/oem-fields", test_acpi_piix4_oem_fields); 2578 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge); 2579 qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug", 2580 test_acpi_piix4_no_root_hotplug); 2581 qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug", 2582 test_acpi_piix4_no_bridge_hotplug); 2583 qtest_add_func("acpi/piix4/pci-hotplug/off", 2584 test_acpi_piix4_no_acpi_pci_hotplug); 2585 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi); 2586 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp); 2587 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem); 2588 qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm); 2589 qtest_add_func("acpi/piix4/smm-compat", 2590 test_acpi_piix4_tcg_smm_compat); 2591 qtest_add_func("acpi/piix4/smm-compat-nosmm", 2592 test_acpi_piix4_tcg_smm_compat_nosmm); 2593 qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet); 2594 2595 /* i386 does not support memory hotplug */ 2596 if (strcmp(arch, "i386")) { 2597 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp); 2598 qtest_add_func("acpi/piix4/dimmpxm", 2599 test_acpi_piix4_tcg_dimm_pxm); 2600 qtest_add_func("acpi/piix4/acpihmat", 2601 test_acpi_piix4_tcg_acpi_hmat); 2602 } 2603 #ifdef CONFIG_POSIX 2604 qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst); 2605 #endif 2606 qtest_add_func("acpi/piix4/smbios-options", 2607 test_acpi_pc_smbios_options); 2608 qtest_add_func("acpi/piix4/smbios-blob", 2609 test_acpi_pc_smbios_blob); 2610 qtest_add_func("acpi/piix4/smbios-legacy", 2611 test_acpi_isapc_smbios_legacy); 2612 } 2613 if (qtest_has_machine(MACHINE_Q35)) { 2614 qtest_add_func("acpi/q35", test_acpi_q35_tcg); 2615 qtest_add_func("acpi/q35/oem-fields", test_acpi_q35_oem_fields); 2616 if (tpm_model_is_available("-machine q35", "tpm-tis")) { 2617 qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis); 2618 qtest_add_func("acpi/q35/tpm12-tis", 2619 test_acpi_q35_tcg_tpm12_tis); 2620 } 2621 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge); 2622 qtest_add_func("acpi/q35/no-acpi-hotplug", 2623 test_acpi_q35_tcg_no_acpi_hotplug); 2624 qtest_add_func("acpi/q35/multif-bridge", 2625 test_acpi_q35_multif_bridge); 2626 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi); 2627 qtest_add_func("acpi/q35/smbus/ipmi", test_acpi_q35_tcg_smbus_ipmi); 2628 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp); 2629 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem); 2630 qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm); 2631 qtest_add_func("acpi/q35/smm-compat", 2632 test_acpi_q35_tcg_smm_compat); 2633 qtest_add_func("acpi/q35/smm-compat-nosmm", 2634 test_acpi_q35_tcg_smm_compat_nosmm); 2635 qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet); 2636 qtest_add_func("acpi/q35/acpihmat-noinitiator", 2637 test_acpi_q35_tcg_acpi_hmat_noinitiator); 2638 qtest_add_func("acpi/q35/acpihmat-genericx", 2639 test_acpi_q35_tcg_acpi_hmat_generic_x); 2640 2641 /* i386 does not support memory hotplug */ 2642 if (strcmp(arch, "i386")) { 2643 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp); 2644 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm); 2645 qtest_add_func("acpi/q35/acpihmat", 2646 test_acpi_q35_tcg_acpi_hmat); 2647 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64); 2648 } 2649 #ifdef CONFIG_POSIX 2650 qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst); 2651 #endif 2652 qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc); 2653 qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa); 2654 if (has_tcg) { 2655 qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs); 2656 } 2657 if (has_kvm) { 2658 qtest_add_func("acpi/q35/kvm/xapic", test_acpi_q35_kvm_xapic); 2659 qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar); 2660 qtest_add_func("acpi/q35/type4-count", 2661 test_acpi_q35_kvm_type4_count); 2662 qtest_add_func("acpi/q35/core-count", 2663 test_acpi_q35_kvm_core_count); 2664 qtest_add_func("acpi/q35/core-count2", 2665 test_acpi_q35_kvm_core_count2); 2666 qtest_add_func("acpi/q35/thread-count", 2667 test_acpi_q35_kvm_thread_count); 2668 qtest_add_func("acpi/q35/thread-count2", 2669 test_acpi_q35_kvm_thread_count2); 2670 } 2671 if (qtest_has_device("virtio-iommu-pci")) { 2672 qtest_add_func("acpi/q35/viot", test_acpi_q35_viot); 2673 } 2674 #ifdef CONFIG_POSIX 2675 qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl); 2676 #endif 2677 qtest_add_func("acpi/q35/slic", test_acpi_q35_slic); 2678 } 2679 if (qtest_has_machine("microvm")) { 2680 qtest_add_func("acpi/microvm", test_acpi_microvm_tcg); 2681 qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg); 2682 qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg); 2683 qtest_add_func("acpi/microvm/ioapic2", 2684 test_acpi_microvm_ioapic2_tcg); 2685 qtest_add_func("acpi/microvm/oem-fields", 2686 test_acpi_microvm_oem_fields); 2687 if (has_tcg) { 2688 if (strcmp(arch, "x86_64") == 0) { 2689 qtest_add_func("acpi/microvm/pcie", 2690 test_acpi_microvm_pcie_tcg); 2691 #ifdef CONFIG_POSIX 2692 qtest_add_func("acpi/microvm/acpierst", 2693 test_acpi_microvm_acpi_erst); 2694 #endif 2695 } 2696 } 2697 } 2698 } else if (strcmp(arch, "aarch64") == 0) { 2699 if (has_tcg && qtest_has_device("virtio-blk-pci")) { 2700 qtest_add_func("acpi/virt", test_acpi_aarch64_virt_tcg); 2701 qtest_add_func("acpi/virt/acpihmatvirt", 2702 test_acpi_aarch64_virt_tcg_acpi_hmat); 2703 qtest_add_func("acpi/virt/topology", 2704 test_acpi_aarch64_virt_tcg_topology); 2705 qtest_add_func("acpi/virt/its_off", 2706 test_acpi_aarch64_virt_tcg_its_off); 2707 qtest_add_func("acpi/virt/numamem", 2708 test_acpi_aarch64_virt_tcg_numamem); 2709 qtest_add_func("acpi/virt/memhp", test_acpi_aarch64_virt_tcg_memhp); 2710 qtest_add_func("acpi/virt/pxb", test_acpi_aarch64_virt_tcg_pxb); 2711 qtest_add_func("acpi/virt/oem-fields", 2712 test_acpi_aarch64_virt_oem_fields); 2713 qtest_add_func("acpi/virt/acpispcr", 2714 test_acpi_aarch64_virt_tcg_acpi_spcr); 2715 if (qtest_has_device("virtio-iommu-pci")) { 2716 qtest_add_func("acpi/virt/viot", test_acpi_aarch64_virt_viot); 2717 } 2718 } 2719 } else if (strcmp(arch, "riscv64") == 0) { 2720 if (has_tcg && qtest_has_device("virtio-blk-pci")) { 2721 qtest_add_func("acpi/virt", test_acpi_riscv64_virt_tcg); 2722 qtest_add_func("acpi/virt/numamem", 2723 test_acpi_riscv64_virt_tcg_numamem); 2724 qtest_add_func("acpi/virt/acpispcr", 2725 test_acpi_riscv64_virt_tcg_acpi_spcr); 2726 } 2727 } else if (strcmp(arch, "loongarch64") == 0) { 2728 if (has_tcg) { 2729 qtest_add_func("acpi/virt", test_acpi_loongarch64_virt); 2730 qtest_add_func("acpi/virt/topology", 2731 test_acpi_loongarch64_virt_topology); 2732 qtest_add_func("acpi/virt/numamem", 2733 test_acpi_loongarch64_virt_numamem); 2734 qtest_add_func("acpi/virt/memhp", test_acpi_loongarch64_virt_memhp); 2735 qtest_add_func("acpi/virt/oem-fields", 2736 test_acpi_loongarch64_virt_oem_fields); 2737 } 2738 } 2739 ret = g_test_run(); 2740 boot_sector_cleanup(disk); 2741 return ret; 2742 } 2743