2 * Boot order test cases.
4 * Copyright (c) 2013 Red Hat Inc.
7 * Michael S. Tsirkin <mst@redhat.com>,
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.
13 #include "qemu/osdep.h"
14 #include <glib/gstdio.h>
15 #include "qemu-common.h"
16 #include "hw/firmware/smbios.h"
17 #include "qemu/bitmap.h"
18 #include "acpi-utils.h"
19 #include "boot-sector.h"
21 #define MACHINE_PC "pc"
22 #define MACHINE_Q35 "q35"
24 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
30 uint8_t rsdp_table
[36 /* ACPI 2.0+ RSDP size */];
33 AcpiFacsDescriptorRev1 facs_table
;
35 uint32_t smbios_ep_addr
;
36 struct smbios_21_entry_point smbios_ep_table
;
37 uint8_t *required_struct_types
;
38 int required_struct_types_len
;
42 static char disk
[] = "tests/acpi-test-disk-XXXXXX";
43 static const char *data_dir
= "tests/data/acpi";
45 static const char *iasl
= stringify(CONFIG_IASL
);
47 static const char *iasl
;
50 static void cleanup_table_descriptor(AcpiSdtTable
*table
)
53 if (table
->aml_file
&&
54 !table
->tmp_files_retain
&&
55 g_strstr_len(table
->aml_file
, -1, "aml-")) {
56 unlink(table
->aml_file
);
58 g_free(table
->aml_file
);
60 if (table
->asl_file
&&
61 !table
->tmp_files_retain
) {
62 unlink(table
->asl_file
);
64 g_free(table
->asl_file
);
67 static void free_test_data(test_data
*data
)
71 for (i
= 0; i
< data
->tables
->len
; ++i
) {
72 cleanup_table_descriptor(&g_array_index(data
->tables
, AcpiSdtTable
, i
));
75 g_array_free(data
->tables
, true);
79 * load ACPI table at @addr into table descriptor @sdt_table
80 * and check that header checksum matches actual one.
82 static void fetch_table(QTestState
*qts
, AcpiSdtTable
*sdt_table
, uint32_t addr
)
84 qtest_memread(qts
, addr
+ 4 /* Length of ACPI table */,
85 &sdt_table
->aml_len
, 4);
86 sdt_table
->aml_len
= le32_to_cpu(sdt_table
->aml_len
);
87 sdt_table
->aml
= g_malloc0(sdt_table
->aml_len
);
89 qtest_memread(qts
, addr
, sdt_table
->aml
, sdt_table
->aml_len
);
91 g_assert(!acpi_calc_checksum(sdt_table
->aml
, sdt_table
->aml_len
));
94 static void test_acpi_rsdp_address(test_data
*data
)
96 uint32_t off
= acpi_find_rsdp_address(data
->qts
);
97 g_assert_cmphex(off
, <, 0x100000);
98 data
->rsdp_addr
= off
;
101 static void test_acpi_rsdp_table(test_data
*data
)
103 uint8_t *rsdp_table
= data
->rsdp_table
, revision
;
104 uint32_t addr
= data
->rsdp_addr
;
106 acpi_parse_rsdp_table(data
->qts
, addr
, rsdp_table
);
107 revision
= rsdp_table
[15 /* Revision offset */];
110 case 0: /* ACPI 1.0 RSDP */
111 /* With rev 1, checksum is only for the first 20 bytes */
112 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
114 case 2: /* ACPI 2.0+ RSDP */
115 /* With revision 2, we have 2 checksums */
116 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
117 g_assert(!acpi_calc_checksum(rsdp_table
, 36));
120 g_assert_not_reached();
124 static void test_acpi_rsdt_table(test_data
*data
)
126 uint32_t addr
= acpi_get_rsdt_address(data
->rsdp_table
);
127 const int entry_size
= 4 /* 32-bit Entry size */;
128 const int tables_off
= 36 /* 1st Entry */;
129 AcpiSdtTable rsdt
= {};
130 int i
, table_len
, table_nr
;
133 fetch_table(data
->qts
, &rsdt
, addr
);
134 ACPI_ASSERT_CMP(rsdt
.header
->signature
, "RSDT");
136 /* Load all tables and add to test list directly RSDT referenced tables */
137 table_len
= le32_to_cpu(rsdt
.header
->length
);
138 table_nr
= (table_len
- tables_off
) / entry_size
;
139 for (i
= 0; i
< table_nr
; i
++) {
140 AcpiSdtTable ssdt_table
= {};
142 entry
= (uint32_t *)(rsdt
.aml
+ tables_off
+ i
* entry_size
);
143 addr
= le32_to_cpu(*entry
);
144 fetch_table(data
->qts
, &ssdt_table
, addr
);
146 /* Add table to ASL test tables list */
147 g_array_append_val(data
->tables
, ssdt_table
);
149 cleanup_table_descriptor(&rsdt
);
152 static void test_acpi_fadt_table(test_data
*data
)
154 /* FADT table is 1st */
155 AcpiSdtTable
*fadt
= &g_array_index(data
->tables
, typeof(*fadt
), 0);
157 ACPI_ASSERT_CMP(fadt
->header
->signature
, "FACP");
159 memcpy(&data
->facs_addr
, fadt
->aml
+ 36 /* FIRMWARE_CTRL */, 4);
160 memcpy(&data
->dsdt_addr
, fadt
->aml
+ 40 /* DSDT */, 4);
163 static void sanitize_fadt_ptrs(test_data
*data
)
165 /* fixup pointers in FADT */
168 for (i
= 0; i
< data
->tables
->len
; i
++) {
169 AcpiSdtTable
*sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
171 if (memcmp(&sdt
->header
->signature
, "FACP", 4)) {
175 /* check original FADT checksum before sanitizing table */
176 g_assert(!acpi_calc_checksum(sdt
->aml
, sdt
->aml_len
));
178 memset(sdt
->aml
+ 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
179 memset(sdt
->aml
+ 40, 0, 4); /* sanitize DSDT ptr */
180 if (sdt
->header
->revision
>= 3) {
181 memset(sdt
->aml
+ 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
182 memset(sdt
->aml
+ 140, 0, 8); /* sanitize X_DSDT ptr */
185 /* update checksum */
186 sdt
->header
->checksum
= 0;
187 sdt
->header
->checksum
-= acpi_calc_checksum(sdt
->aml
, sdt
->aml_len
);
192 static void test_acpi_facs_table(test_data
*data
)
194 AcpiFacsDescriptorRev1
*facs_table
= &data
->facs_table
;
195 uint32_t addr
= le32_to_cpu(data
->facs_addr
);
197 ACPI_READ_FIELD(data
->qts
, facs_table
->signature
, addr
);
198 ACPI_READ_FIELD(data
->qts
, facs_table
->length
, addr
);
199 ACPI_READ_FIELD(data
->qts
, facs_table
->hardware_signature
, addr
);
200 ACPI_READ_FIELD(data
->qts
, facs_table
->firmware_waking_vector
, addr
);
201 ACPI_READ_FIELD(data
->qts
, facs_table
->global_lock
, addr
);
202 ACPI_READ_FIELD(data
->qts
, facs_table
->flags
, addr
);
203 ACPI_READ_ARRAY(data
->qts
, facs_table
->resverved3
, addr
);
205 ACPI_ASSERT_CMP(facs_table
->signature
, "FACS");
208 static void test_acpi_dsdt_table(test_data
*data
)
210 AcpiSdtTable dsdt_table
= {};
211 uint32_t addr
= le32_to_cpu(data
->dsdt_addr
);
213 fetch_table(data
->qts
, &dsdt_table
, addr
);
214 ACPI_ASSERT_CMP(dsdt_table
.header
->signature
, "DSDT");
216 /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually */
217 g_array_append_val(data
->tables
, dsdt_table
);
220 static void dump_aml_files(test_data
*data
, bool rebuild
)
223 GError
*error
= NULL
;
224 gchar
*aml_file
= NULL
;
229 for (i
= 0; i
< data
->tables
->len
; ++i
) {
230 const char *ext
= data
->variant
? data
->variant
: "";
231 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
235 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
236 (gchar
*)&sdt
->header
->signature
, ext
);
237 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
238 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
240 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
241 g_assert_no_error(error
);
245 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
246 g_assert(ret
== sdt
->aml_len
);
254 static bool compare_signature(AcpiSdtTable
*sdt
, const char *signature
)
256 return !memcmp(&sdt
->header
->signature
, signature
, 4);
259 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
262 GError
*error
= NULL
;
263 GString
*command_line
= g_string_new(iasl
);
265 gchar
*out
, *out_err
;
269 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
270 g_assert_no_error(error
);
273 /* build command line */
274 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
275 if (compare_signature(sdt
, "DSDT") ||
276 compare_signature(sdt
, "SSDT")) {
277 for (i
= 0; i
< sdts
->len
; ++i
) {
278 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
279 if (compare_signature(temp
, "DSDT") ||
280 compare_signature(temp
, "SSDT")) {
281 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
285 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
287 /* pass 'out' and 'out_err' in order to be redirected */
288 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
289 g_assert_no_error(error
);
291 ret
= g_file_get_contents(sdt
->asl_file
, &sdt
->asl
,
292 &sdt
->asl_len
, &error
);
294 g_assert_no_error(error
);
295 ret
= (sdt
->asl_len
> 0);
300 g_string_free(command_line
, true);
305 #define COMMENT_END "*/"
306 #define DEF_BLOCK "DefinitionBlock ("
307 #define BLOCK_NAME_END ","
309 static GString
*normalize_asl(gchar
*asl_code
)
311 GString
*asl
= g_string_new(asl_code
);
312 gchar
*comment
, *block_name
;
314 /* strip comments (different generation days) */
315 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
317 comment
+= strlen(COMMENT_END
);
318 while (*comment
== '\n') {
321 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
324 /* strip def block name (it has file path in it) */
325 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
326 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
327 g_assert(block_name
);
328 asl
= g_string_erase(asl
, 0,
329 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
335 static GArray
*load_expected_aml(test_data
*data
)
339 GError
*error
= NULL
;
342 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
346 for (i
= 0; i
< data
->tables
->len
; ++i
) {
347 AcpiSdtTable exp_sdt
;
348 gchar
*aml_file
= NULL
;
349 const char *ext
= data
->variant
? data
->variant
: "";
351 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
353 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
356 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
357 (gchar
*)&sdt
->header
->signature
, ext
);
359 fprintf(stderr
, "Looking for expected file '%s'\n", aml_file
);
361 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
362 exp_sdt
.aml_file
= aml_file
;
363 } else if (*ext
!= '\0') {
364 /* try fallback to generic (extension less) expected file */
369 g_assert(exp_sdt
.aml_file
);
371 fprintf(stderr
, "Using expected file '%s'\n", aml_file
);
373 ret
= g_file_get_contents(aml_file
, (gchar
**)&exp_sdt
.aml
,
374 &exp_sdt
.aml_len
, &error
);
376 g_assert_no_error(error
);
377 g_assert(exp_sdt
.aml
);
378 g_assert(exp_sdt
.aml_len
);
380 g_array_append_val(exp_tables
, exp_sdt
);
386 /* test the list of tables in @data->tables against reference tables */
387 static void test_acpi_asl(test_data
*data
)
390 AcpiSdtTable
*sdt
, *exp_sdt
;
392 gboolean exp_err
, err
;
394 memset(&exp_data
, 0, sizeof(exp_data
));
395 exp_data
.tables
= load_expected_aml(data
);
396 dump_aml_files(data
, false);
397 for (i
= 0; i
< data
->tables
->len
; ++i
) {
398 GString
*asl
, *exp_asl
;
400 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
401 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
403 err
= load_asl(data
->tables
, sdt
);
404 asl
= normalize_asl(sdt
->asl
);
406 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
407 exp_asl
= normalize_asl(exp_sdt
->asl
);
409 /* TODO: check for warnings */
410 g_assert(!err
|| exp_err
);
412 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
415 "Warning! iasl couldn't parse the expected aml\n");
417 uint32_t signature
= cpu_to_le32(exp_sdt
->header
->signature
);
418 sdt
->tmp_files_retain
= true;
419 exp_sdt
->tmp_files_retain
= true;
421 "acpi-test: Warning! %.4s mismatch. "
422 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
424 sdt
->asl_file
, sdt
->aml_file
,
425 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
427 const char *diff_cmd
= getenv("DIFF");
429 int ret G_GNUC_UNUSED
;
430 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
431 exp_sdt
->asl_file
, sdt
->asl_file
);
435 fprintf(stderr
, "acpi-test: Warning. not showing "
436 "difference since no diff utility is specified. "
437 "Set 'DIFF' environment variable to a preferred "
438 "diff utility and run 'make V=1 check' again to "
439 "see ASL difference.");
444 g_string_free(asl
, true);
445 g_string_free(exp_asl
, true);
448 free_test_data(&exp_data
);
451 static bool smbios_ep_table_ok(test_data
*data
)
453 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
454 uint32_t addr
= data
->smbios_ep_addr
;
456 ACPI_READ_ARRAY(data
->qts
, ep_table
->anchor_string
, addr
);
457 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
460 ACPI_READ_FIELD(data
->qts
, ep_table
->checksum
, addr
);
461 ACPI_READ_FIELD(data
->qts
, ep_table
->length
, addr
);
462 ACPI_READ_FIELD(data
->qts
, ep_table
->smbios_major_version
, addr
);
463 ACPI_READ_FIELD(data
->qts
, ep_table
->smbios_minor_version
, addr
);
464 ACPI_READ_FIELD(data
->qts
, ep_table
->max_structure_size
, addr
);
465 ACPI_READ_FIELD(data
->qts
, ep_table
->entry_point_revision
, addr
);
466 ACPI_READ_ARRAY(data
->qts
, ep_table
->formatted_area
, addr
);
467 ACPI_READ_ARRAY(data
->qts
, ep_table
->intermediate_anchor_string
, addr
);
468 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
471 ACPI_READ_FIELD(data
->qts
, ep_table
->intermediate_checksum
, addr
);
472 ACPI_READ_FIELD(data
->qts
, ep_table
->structure_table_length
, addr
);
473 if (ep_table
->structure_table_length
== 0) {
476 ACPI_READ_FIELD(data
->qts
, ep_table
->structure_table_address
, addr
);
477 ACPI_READ_FIELD(data
->qts
, ep_table
->number_of_structures
, addr
);
478 if (ep_table
->number_of_structures
== 0) {
481 ACPI_READ_FIELD(data
->qts
, ep_table
->smbios_bcd_revision
, addr
);
482 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
483 acpi_calc_checksum((uint8_t *)ep_table
+ 0x10,
484 sizeof *ep_table
- 0x10)) {
490 static void test_smbios_entry_point(test_data
*data
)
494 /* find smbios entry point structure */
495 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
496 uint8_t sig
[] = "_SM_";
499 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
500 sig
[i
] = qtest_readb(data
->qts
, off
+ i
);
503 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
504 /* signature match, but is this a valid entry point? */
505 data
->smbios_ep_addr
= off
;
506 if (smbios_ep_table_ok(data
)) {
512 g_assert_cmphex(off
, <, 0x100000);
515 static inline bool smbios_single_instance(uint8_t type
)
531 static void test_smbios_structs(test_data
*data
)
533 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
534 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
535 uint32_t addr
= le32_to_cpu(ep_table
->structure_table_address
);
536 int i
, len
, max_len
= 0;
537 uint8_t type
, prv
, crt
;
539 /* walk the smbios tables */
540 for (i
= 0; i
< le16_to_cpu(ep_table
->number_of_structures
); i
++) {
542 /* grab type and formatted area length from struct header */
543 type
= qtest_readb(data
->qts
, addr
);
544 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
545 len
= qtest_readb(data
->qts
, addr
+ 1);
547 /* single-instance structs must not have been encountered before */
548 if (smbios_single_instance(type
)) {
549 g_assert(!test_bit(type
, struct_bitmap
));
551 set_bit(type
, struct_bitmap
);
553 /* seek to end of unformatted string area of this struct ("\0\0") */
557 crt
= qtest_readb(data
->qts
, addr
+ len
);
561 /* keep track of max. struct size */
564 g_assert_cmpuint(max_len
, <=, ep_table
->max_structure_size
);
567 /* start of next structure */
571 /* total table length and max struct size must match entry point values */
572 g_assert_cmpuint(le16_to_cpu(ep_table
->structure_table_length
), ==,
573 addr
- le32_to_cpu(ep_table
->structure_table_address
));
574 g_assert_cmpuint(le16_to_cpu(ep_table
->max_structure_size
), ==, max_len
);
576 /* required struct types must all be present */
577 for (i
= 0; i
< data
->required_struct_types_len
; i
++) {
578 g_assert(test_bit(data
->required_struct_types
[i
], struct_bitmap
));
582 static void test_acpi_one(const char *params
, test_data
*data
)
586 /* Disable kernel irqchip to be able to override apic irq0. */
587 args
= g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
588 "-net none -display none %s "
589 "-drive id=hd0,if=none,file=%s,format=raw "
590 "-device ide-hd,drive=hd0 ",
591 data
->machine
, "kvm:tcg",
592 params
? params
: "", disk
);
594 data
->qts
= qtest_init(args
);
596 boot_sector_test(data
->qts
);
598 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
599 test_acpi_rsdp_address(data
);
600 test_acpi_rsdp_table(data
);
601 test_acpi_rsdt_table(data
);
602 test_acpi_fadt_table(data
);
603 test_acpi_facs_table(data
);
604 test_acpi_dsdt_table(data
);
606 sanitize_fadt_ptrs(data
);
609 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
610 dump_aml_files(data
, true);
616 test_smbios_entry_point(data
);
617 test_smbios_structs(data
);
619 assert(!global_qtest
);
620 qtest_quit(data
->qts
);
624 static uint8_t base_required_struct_types
[] = {
625 0, 1, 3, 4, 16, 17, 19, 32, 127
628 static void test_acpi_piix4_tcg(void)
632 /* Supplying -machine accel argument overrides the default (qtest).
633 * This is to make guest actually run.
635 memset(&data
, 0, sizeof(data
));
636 data
.machine
= MACHINE_PC
;
637 data
.required_struct_types
= base_required_struct_types
;
638 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
639 test_acpi_one(NULL
, &data
);
640 free_test_data(&data
);
643 static void test_acpi_piix4_tcg_bridge(void)
647 memset(&data
, 0, sizeof(data
));
648 data
.machine
= MACHINE_PC
;
649 data
.variant
= ".bridge";
650 data
.required_struct_types
= base_required_struct_types
;
651 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
652 test_acpi_one("-device pci-bridge,chassis_nr=1", &data
);
653 free_test_data(&data
);
656 static void test_acpi_q35_tcg(void)
660 memset(&data
, 0, sizeof(data
));
661 data
.machine
= MACHINE_Q35
;
662 data
.required_struct_types
= base_required_struct_types
;
663 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
664 test_acpi_one(NULL
, &data
);
665 free_test_data(&data
);
668 static void test_acpi_q35_tcg_bridge(void)
672 memset(&data
, 0, sizeof(data
));
673 data
.machine
= MACHINE_Q35
;
674 data
.variant
= ".bridge";
675 data
.required_struct_types
= base_required_struct_types
;
676 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
677 test_acpi_one("-device pci-bridge,chassis_nr=1",
679 free_test_data(&data
);
682 static void test_acpi_q35_tcg_mmio64(void)
685 .machine
= MACHINE_Q35
,
686 .variant
= ".mmio64",
687 .required_struct_types
= base_required_struct_types
,
688 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
)
691 test_acpi_one("-m 128M,slots=1,maxmem=2G "
692 "-device pci-testdev,membar=2G",
694 free_test_data(&data
);
697 static void test_acpi_piix4_tcg_cphp(void)
701 memset(&data
, 0, sizeof(data
));
702 data
.machine
= MACHINE_PC
;
703 data
.variant
= ".cphp";
704 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
705 " -numa node -numa node"
706 " -numa dist,src=0,dst=1,val=21",
708 free_test_data(&data
);
711 static void test_acpi_q35_tcg_cphp(void)
715 memset(&data
, 0, sizeof(data
));
716 data
.machine
= MACHINE_Q35
;
717 data
.variant
= ".cphp";
718 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
719 " -numa node -numa node"
720 " -numa dist,src=0,dst=1,val=21",
722 free_test_data(&data
);
725 static uint8_t ipmi_required_struct_types
[] = {
726 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
729 static void test_acpi_q35_tcg_ipmi(void)
733 memset(&data
, 0, sizeof(data
));
734 data
.machine
= MACHINE_Q35
;
735 data
.variant
= ".ipmibt";
736 data
.required_struct_types
= ipmi_required_struct_types
;
737 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
738 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
739 " -device isa-ipmi-bt,bmc=bmc0",
741 free_test_data(&data
);
744 static void test_acpi_piix4_tcg_ipmi(void)
748 /* Supplying -machine accel argument overrides the default (qtest).
749 * This is to make guest actually run.
751 memset(&data
, 0, sizeof(data
));
752 data
.machine
= MACHINE_PC
;
753 data
.variant
= ".ipmikcs";
754 data
.required_struct_types
= ipmi_required_struct_types
;
755 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
756 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
757 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
759 free_test_data(&data
);
762 static void test_acpi_q35_tcg_memhp(void)
766 memset(&data
, 0, sizeof(data
));
767 data
.machine
= MACHINE_Q35
;
768 data
.variant
= ".memhp";
769 test_acpi_one(" -m 128,slots=3,maxmem=1G"
770 " -numa node -numa node"
771 " -numa dist,src=0,dst=1,val=21",
773 free_test_data(&data
);
776 static void test_acpi_piix4_tcg_memhp(void)
780 memset(&data
, 0, sizeof(data
));
781 data
.machine
= MACHINE_PC
;
782 data
.variant
= ".memhp";
783 test_acpi_one(" -m 128,slots=3,maxmem=1G"
784 " -numa node -numa node"
785 " -numa dist,src=0,dst=1,val=21",
787 free_test_data(&data
);
790 static void test_acpi_q35_tcg_numamem(void)
794 memset(&data
, 0, sizeof(data
));
795 data
.machine
= MACHINE_Q35
;
796 data
.variant
= ".numamem";
797 test_acpi_one(" -numa node -numa node,mem=128", &data
);
798 free_test_data(&data
);
801 static void test_acpi_piix4_tcg_numamem(void)
805 memset(&data
, 0, sizeof(data
));
806 data
.machine
= MACHINE_PC
;
807 data
.variant
= ".numamem";
808 test_acpi_one(" -numa node -numa node,mem=128", &data
);
809 free_test_data(&data
);
812 static void test_acpi_tcg_dimm_pxm(const char *machine
)
816 memset(&data
, 0, sizeof(data
));
817 data
.machine
= machine
;
818 data
.variant
= ".dimmpxm";
819 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
821 " -m 128M,slots=3,maxmem=1G"
822 " -numa node,mem=32M,nodeid=0"
823 " -numa node,mem=32M,nodeid=1"
824 " -numa node,mem=32M,nodeid=2"
825 " -numa node,mem=32M,nodeid=3"
826 " -numa cpu,node-id=0,socket-id=0"
827 " -numa cpu,node-id=1,socket-id=1"
828 " -numa cpu,node-id=2,socket-id=2"
829 " -numa cpu,node-id=3,socket-id=3"
830 " -object memory-backend-ram,id=ram0,size=128M"
831 " -object memory-backend-ram,id=nvm0,size=128M"
832 " -device pc-dimm,id=dimm0,memdev=ram0,node=1"
833 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
835 free_test_data(&data
);
838 static void test_acpi_q35_tcg_dimm_pxm(void)
840 test_acpi_tcg_dimm_pxm(MACHINE_Q35
);
843 static void test_acpi_piix4_tcg_dimm_pxm(void)
845 test_acpi_tcg_dimm_pxm(MACHINE_PC
);
848 int main(int argc
, char *argv
[])
850 const char *arch
= qtest_get_arch();
853 ret
= boot_sector_init(disk
);
857 g_test_init(&argc
, &argv
, NULL
);
859 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
860 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg
);
861 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge
);
862 qtest_add_func("acpi/q35", test_acpi_q35_tcg
);
863 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge
);
864 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64
);
865 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi
);
866 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi
);
867 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp
);
868 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp
);
869 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp
);
870 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp
);
871 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem
);
872 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem
);
873 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm
);
874 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm
);
877 boot_sector_cleanup(disk
);