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 */];
31 AcpiRsdtDescriptorRev1 rsdt_table
;
34 AcpiFacsDescriptorRev1 facs_table
;
35 uint32_t *rsdt_tables_addr
;
38 uint32_t smbios_ep_addr
;
39 struct smbios_21_entry_point smbios_ep_table
;
40 uint8_t *required_struct_types
;
41 int required_struct_types_len
;
45 static char disk
[] = "tests/acpi-test-disk-XXXXXX";
46 static const char *data_dir
= "tests/data/acpi";
48 static const char *iasl
= stringify(CONFIG_IASL
);
50 static const char *iasl
;
53 static void free_test_data(test_data
*data
)
58 g_free(data
->rsdt_tables_addr
);
60 for (i
= 0; i
< data
->tables
->len
; ++i
) {
61 temp
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
64 !temp
->tmp_files_retain
&&
65 g_strstr_len(temp
->aml_file
, -1, "aml-")) {
66 unlink(temp
->aml_file
);
68 g_free(temp
->aml_file
);
71 !temp
->tmp_files_retain
) {
72 unlink(temp
->asl_file
);
74 g_free(temp
->asl_file
);
77 g_array_free(data
->tables
, true);
80 static void test_acpi_rsdp_address(test_data
*data
)
82 uint32_t off
= acpi_find_rsdp_address(data
->qts
);
83 g_assert_cmphex(off
, <, 0x100000);
84 data
->rsdp_addr
= off
;
87 static void test_acpi_rsdp_table(test_data
*data
)
89 uint8_t *rsdp_table
= data
->rsdp_table
, revision
;
90 uint32_t addr
= data
->rsdp_addr
;
92 acpi_parse_rsdp_table(data
->qts
, addr
, rsdp_table
);
93 revision
= rsdp_table
[15 /* Revision offset */];
96 case 0: /* ACPI 1.0 RSDP */
97 /* With rev 1, checksum is only for the first 20 bytes */
98 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
100 case 2: /* ACPI 2.0+ RSDP */
101 /* With revision 2, we have 2 checksums */
102 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
103 g_assert(!acpi_calc_checksum(rsdp_table
, 36));
106 g_assert_not_reached();
110 static void test_acpi_rsdt_table(test_data
*data
)
112 AcpiRsdtDescriptorRev1
*rsdt_table
= &data
->rsdt_table
;
113 uint32_t addr
= acpi_get_rsdt_address(data
->rsdp_table
);
117 uint32_t rsdt_table_length
;
119 /* read the header */
120 ACPI_READ_TABLE_HEADER(data
->qts
, rsdt_table
, addr
);
121 ACPI_ASSERT_CMP(rsdt_table
->signature
, "RSDT");
123 rsdt_table_length
= le32_to_cpu(rsdt_table
->length
);
125 /* compute the table entries in rsdt */
126 tables_nr
= (rsdt_table_length
- sizeof(AcpiRsdtDescriptorRev1
)) /
128 g_assert(tables_nr
> 0);
130 /* get the addresses of the tables pointed by rsdt */
131 tables
= g_new0(uint32_t, tables_nr
);
132 ACPI_READ_ARRAY_PTR(data
->qts
, tables
, tables_nr
, addr
);
134 checksum
= acpi_calc_checksum((uint8_t *)rsdt_table
, rsdt_table_length
) +
135 acpi_calc_checksum((uint8_t *)tables
,
136 tables_nr
* sizeof(uint32_t));
139 /* SSDT tables after FADT */
140 data
->rsdt_tables_addr
= tables
;
141 data
->rsdt_tables_nr
= tables_nr
;
144 static void fadt_fetch_facs_and_dsdt_ptrs(test_data
*data
)
149 /* FADT table comes first */
150 addr
= le32_to_cpu(data
->rsdt_tables_addr
[0]);
151 ACPI_READ_TABLE_HEADER(data
->qts
, &hdr
, addr
);
152 ACPI_ASSERT_CMP(hdr
.signature
, "FACP");
154 ACPI_READ_FIELD(data
->qts
, data
->facs_addr
, addr
);
155 ACPI_READ_FIELD(data
->qts
, data
->dsdt_addr
, addr
);
158 static void sanitize_fadt_ptrs(test_data
*data
)
160 /* fixup pointers in FADT */
163 for (i
= 0; i
< data
->tables
->len
; i
++) {
164 AcpiSdtTable
*sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
166 if (memcmp(&sdt
->header
.signature
, "FACP", 4)) {
170 /* check original FADT checksum before sanitizing table */
172 acpi_calc_checksum((uint8_t *)sdt
, sizeof(AcpiTableHeader
)) +
173 acpi_calc_checksum((uint8_t *)sdt
->aml
, sdt
->aml_len
)
176 /* sdt->aml field offset := spec offset - header size */
177 memset(sdt
->aml
+ 0, 0, 4); /* sanitize FIRMWARE_CTRL(36) ptr */
178 memset(sdt
->aml
+ 4, 0, 4); /* sanitize DSDT(40) ptr */
179 if (sdt
->header
.revision
>= 3) {
180 memset(sdt
->aml
+ 96, 0, 8); /* sanitize X_FIRMWARE_CTRL(132) ptr */
181 memset(sdt
->aml
+ 104, 0, 8); /* sanitize X_DSDT(140) ptr */
184 /* update checksum */
185 sdt
->header
.checksum
= 0;
186 sdt
->header
.checksum
-=
187 acpi_calc_checksum((uint8_t *)sdt
, sizeof(AcpiTableHeader
)) +
188 acpi_calc_checksum((uint8_t *)sdt
->aml
, sdt
->aml_len
);
193 static void test_acpi_facs_table(test_data
*data
)
195 AcpiFacsDescriptorRev1
*facs_table
= &data
->facs_table
;
196 uint32_t addr
= le32_to_cpu(data
->facs_addr
);
198 ACPI_READ_FIELD(data
->qts
, facs_table
->signature
, addr
);
199 ACPI_READ_FIELD(data
->qts
, facs_table
->length
, addr
);
200 ACPI_READ_FIELD(data
->qts
, facs_table
->hardware_signature
, addr
);
201 ACPI_READ_FIELD(data
->qts
, facs_table
->firmware_waking_vector
, addr
);
202 ACPI_READ_FIELD(data
->qts
, facs_table
->global_lock
, addr
);
203 ACPI_READ_FIELD(data
->qts
, facs_table
->flags
, addr
);
204 ACPI_READ_ARRAY(data
->qts
, facs_table
->resverved3
, addr
);
206 ACPI_ASSERT_CMP(facs_table
->signature
, "FACS");
210 * load ACPI table at @addr into table descriptor @sdt_table
211 * and check that header checksum matches actual one.
213 static void fetch_table(QTestState
*qts
, AcpiSdtTable
*sdt_table
, uint32_t addr
)
217 memset(sdt_table
, 0, sizeof(*sdt_table
));
218 ACPI_READ_TABLE_HEADER(qts
, &sdt_table
->header
, addr
);
220 sdt_table
->aml_len
= le32_to_cpu(sdt_table
->header
.length
)
221 - sizeof(AcpiTableHeader
);
222 sdt_table
->aml
= g_malloc0(sdt_table
->aml_len
);
223 ACPI_READ_ARRAY_PTR(qts
, sdt_table
->aml
, sdt_table
->aml_len
, addr
);
225 checksum
= acpi_calc_checksum((uint8_t *)sdt_table
,
226 sizeof(AcpiTableHeader
)) +
227 acpi_calc_checksum((uint8_t *)sdt_table
->aml
,
232 static void test_acpi_dsdt_table(test_data
*data
)
234 AcpiSdtTable dsdt_table
;
235 uint32_t addr
= le32_to_cpu(data
->dsdt_addr
);
237 fetch_table(data
->qts
, &dsdt_table
, addr
);
238 ACPI_ASSERT_CMP(dsdt_table
.header
.signature
, "DSDT");
240 /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually */
241 g_array_append_val(data
->tables
, dsdt_table
);
244 /* Load all tables and add to test list directly RSDT referenced tables */
245 static void fetch_rsdt_referenced_tables(test_data
*data
)
247 int tables_nr
= data
->rsdt_tables_nr
;
250 for (i
= 0; i
< tables_nr
; i
++) {
251 AcpiSdtTable ssdt_table
;
254 addr
= le32_to_cpu(data
->rsdt_tables_addr
[i
]);
255 fetch_table(data
->qts
, &ssdt_table
, addr
);
257 /* Add table to ASL test tables list */
258 g_array_append_val(data
->tables
, ssdt_table
);
262 static void dump_aml_files(test_data
*data
, bool rebuild
)
265 GError
*error
= NULL
;
266 gchar
*aml_file
= NULL
;
271 for (i
= 0; i
< data
->tables
->len
; ++i
) {
272 const char *ext
= data
->variant
? data
->variant
: "";
273 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
277 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
278 (gchar
*)&sdt
->header
.signature
, ext
);
279 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
280 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
282 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
283 g_assert_no_error(error
);
287 ret
= qemu_write_full(fd
, sdt
, sizeof(AcpiTableHeader
));
288 g_assert(ret
== sizeof(AcpiTableHeader
));
289 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
290 g_assert(ret
== sdt
->aml_len
);
298 static bool compare_signature(AcpiSdtTable
*sdt
, const char *signature
)
300 return !memcmp(&sdt
->header
.signature
, signature
, 4);
303 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
306 GError
*error
= NULL
;
307 GString
*command_line
= g_string_new(iasl
);
309 gchar
*out
, *out_err
;
313 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
314 g_assert_no_error(error
);
317 /* build command line */
318 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
319 if (compare_signature(sdt
, "DSDT") ||
320 compare_signature(sdt
, "SSDT")) {
321 for (i
= 0; i
< sdts
->len
; ++i
) {
322 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
323 if (compare_signature(temp
, "DSDT") ||
324 compare_signature(temp
, "SSDT")) {
325 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
329 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
331 /* pass 'out' and 'out_err' in order to be redirected */
332 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
333 g_assert_no_error(error
);
335 ret
= g_file_get_contents(sdt
->asl_file
, &sdt
->asl
,
336 &sdt
->asl_len
, &error
);
338 g_assert_no_error(error
);
339 ret
= (sdt
->asl_len
> 0);
344 g_string_free(command_line
, true);
349 #define COMMENT_END "*/"
350 #define DEF_BLOCK "DefinitionBlock ("
351 #define BLOCK_NAME_END ","
353 static GString
*normalize_asl(gchar
*asl_code
)
355 GString
*asl
= g_string_new(asl_code
);
356 gchar
*comment
, *block_name
;
358 /* strip comments (different generation days) */
359 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
361 comment
+= strlen(COMMENT_END
);
362 while (*comment
== '\n') {
365 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
368 /* strip def block name (it has file path in it) */
369 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
370 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
371 g_assert(block_name
);
372 asl
= g_string_erase(asl
, 0,
373 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
379 static GArray
*load_expected_aml(test_data
*data
)
383 GError
*error
= NULL
;
386 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
390 for (i
= 0; i
< data
->tables
->len
; ++i
) {
391 AcpiSdtTable exp_sdt
;
392 gchar
*aml_file
= NULL
;
393 const char *ext
= data
->variant
? data
->variant
: "";
395 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
397 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
398 exp_sdt
.header
.signature
= sdt
->header
.signature
;
401 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
402 (gchar
*)&sdt
->header
.signature
, ext
);
404 fprintf(stderr
, "Looking for expected file '%s'\n", aml_file
);
406 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
407 exp_sdt
.aml_file
= aml_file
;
408 } else if (*ext
!= '\0') {
409 /* try fallback to generic (extension less) expected file */
414 g_assert(exp_sdt
.aml_file
);
416 fprintf(stderr
, "Using expected file '%s'\n", aml_file
);
418 ret
= g_file_get_contents(aml_file
, &exp_sdt
.aml
,
419 &exp_sdt
.aml_len
, &error
);
421 g_assert_no_error(error
);
422 g_assert(exp_sdt
.aml
);
423 g_assert(exp_sdt
.aml_len
);
425 g_array_append_val(exp_tables
, exp_sdt
);
431 /* test the list of tables in @data->tables against reference tables */
432 static void test_acpi_asl(test_data
*data
)
435 AcpiSdtTable
*sdt
, *exp_sdt
;
437 gboolean exp_err
, err
;
439 memset(&exp_data
, 0, sizeof(exp_data
));
440 exp_data
.tables
= load_expected_aml(data
);
441 dump_aml_files(data
, false);
442 for (i
= 0; i
< data
->tables
->len
; ++i
) {
443 GString
*asl
, *exp_asl
;
445 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
446 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
448 err
= load_asl(data
->tables
, sdt
);
449 asl
= normalize_asl(sdt
->asl
);
451 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
452 exp_asl
= normalize_asl(exp_sdt
->asl
);
454 /* TODO: check for warnings */
455 g_assert(!err
|| exp_err
);
457 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
460 "Warning! iasl couldn't parse the expected aml\n");
462 uint32_t signature
= cpu_to_le32(exp_sdt
->header
.signature
);
463 sdt
->tmp_files_retain
= true;
464 exp_sdt
->tmp_files_retain
= true;
466 "acpi-test: Warning! %.4s mismatch. "
467 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
469 sdt
->asl_file
, sdt
->aml_file
,
470 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
472 const char *diff_cmd
= getenv("DIFF");
474 int ret G_GNUC_UNUSED
;
475 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
476 exp_sdt
->asl_file
, sdt
->asl_file
);
480 fprintf(stderr
, "acpi-test: Warning. not showing "
481 "difference since no diff utility is specified. "
482 "Set 'DIFF' environment variable to a preferred "
483 "diff utility and run 'make V=1 check' again to "
484 "see ASL difference.");
489 g_string_free(asl
, true);
490 g_string_free(exp_asl
, true);
493 free_test_data(&exp_data
);
496 static bool smbios_ep_table_ok(test_data
*data
)
498 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
499 uint32_t addr
= data
->smbios_ep_addr
;
501 ACPI_READ_ARRAY(data
->qts
, ep_table
->anchor_string
, addr
);
502 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
505 ACPI_READ_FIELD(data
->qts
, ep_table
->checksum
, addr
);
506 ACPI_READ_FIELD(data
->qts
, ep_table
->length
, addr
);
507 ACPI_READ_FIELD(data
->qts
, ep_table
->smbios_major_version
, addr
);
508 ACPI_READ_FIELD(data
->qts
, ep_table
->smbios_minor_version
, addr
);
509 ACPI_READ_FIELD(data
->qts
, ep_table
->max_structure_size
, addr
);
510 ACPI_READ_FIELD(data
->qts
, ep_table
->entry_point_revision
, addr
);
511 ACPI_READ_ARRAY(data
->qts
, ep_table
->formatted_area
, addr
);
512 ACPI_READ_ARRAY(data
->qts
, ep_table
->intermediate_anchor_string
, addr
);
513 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
516 ACPI_READ_FIELD(data
->qts
, ep_table
->intermediate_checksum
, addr
);
517 ACPI_READ_FIELD(data
->qts
, ep_table
->structure_table_length
, addr
);
518 if (ep_table
->structure_table_length
== 0) {
521 ACPI_READ_FIELD(data
->qts
, ep_table
->structure_table_address
, addr
);
522 ACPI_READ_FIELD(data
->qts
, ep_table
->number_of_structures
, addr
);
523 if (ep_table
->number_of_structures
== 0) {
526 ACPI_READ_FIELD(data
->qts
, ep_table
->smbios_bcd_revision
, addr
);
527 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
528 acpi_calc_checksum((uint8_t *)ep_table
+ 0x10,
529 sizeof *ep_table
- 0x10)) {
535 static void test_smbios_entry_point(test_data
*data
)
539 /* find smbios entry point structure */
540 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
541 uint8_t sig
[] = "_SM_";
544 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
545 sig
[i
] = qtest_readb(data
->qts
, off
+ i
);
548 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
549 /* signature match, but is this a valid entry point? */
550 data
->smbios_ep_addr
= off
;
551 if (smbios_ep_table_ok(data
)) {
557 g_assert_cmphex(off
, <, 0x100000);
560 static inline bool smbios_single_instance(uint8_t type
)
576 static void test_smbios_structs(test_data
*data
)
578 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
579 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
580 uint32_t addr
= le32_to_cpu(ep_table
->structure_table_address
);
581 int i
, len
, max_len
= 0;
582 uint8_t type
, prv
, crt
;
584 /* walk the smbios tables */
585 for (i
= 0; i
< le16_to_cpu(ep_table
->number_of_structures
); i
++) {
587 /* grab type and formatted area length from struct header */
588 type
= qtest_readb(data
->qts
, addr
);
589 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
590 len
= qtest_readb(data
->qts
, addr
+ 1);
592 /* single-instance structs must not have been encountered before */
593 if (smbios_single_instance(type
)) {
594 g_assert(!test_bit(type
, struct_bitmap
));
596 set_bit(type
, struct_bitmap
);
598 /* seek to end of unformatted string area of this struct ("\0\0") */
602 crt
= qtest_readb(data
->qts
, addr
+ len
);
606 /* keep track of max. struct size */
609 g_assert_cmpuint(max_len
, <=, ep_table
->max_structure_size
);
612 /* start of next structure */
616 /* total table length and max struct size must match entry point values */
617 g_assert_cmpuint(le16_to_cpu(ep_table
->structure_table_length
), ==,
618 addr
- le32_to_cpu(ep_table
->structure_table_address
));
619 g_assert_cmpuint(le16_to_cpu(ep_table
->max_structure_size
), ==, max_len
);
621 /* required struct types must all be present */
622 for (i
= 0; i
< data
->required_struct_types_len
; i
++) {
623 g_assert(test_bit(data
->required_struct_types
[i
], struct_bitmap
));
627 static void test_acpi_one(const char *params
, test_data
*data
)
631 /* Disable kernel irqchip to be able to override apic irq0. */
632 args
= g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
633 "-net none -display none %s "
634 "-drive id=hd0,if=none,file=%s,format=raw "
635 "-device ide-hd,drive=hd0 ",
636 data
->machine
, "kvm:tcg",
637 params
? params
: "", disk
);
639 data
->qts
= qtest_init(args
);
641 boot_sector_test(data
->qts
);
643 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
644 test_acpi_rsdp_address(data
);
645 test_acpi_rsdp_table(data
);
646 test_acpi_rsdt_table(data
);
647 fadt_fetch_facs_and_dsdt_ptrs(data
);
648 test_acpi_facs_table(data
);
649 test_acpi_dsdt_table(data
);
650 fetch_rsdt_referenced_tables(data
);
652 sanitize_fadt_ptrs(data
);
655 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
656 dump_aml_files(data
, true);
662 test_smbios_entry_point(data
);
663 test_smbios_structs(data
);
665 assert(!global_qtest
);
666 qtest_quit(data
->qts
);
670 static uint8_t base_required_struct_types
[] = {
671 0, 1, 3, 4, 16, 17, 19, 32, 127
674 static void test_acpi_piix4_tcg(void)
678 /* Supplying -machine accel argument overrides the default (qtest).
679 * This is to make guest actually run.
681 memset(&data
, 0, sizeof(data
));
682 data
.machine
= MACHINE_PC
;
683 data
.required_struct_types
= base_required_struct_types
;
684 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
685 test_acpi_one(NULL
, &data
);
686 free_test_data(&data
);
689 static void test_acpi_piix4_tcg_bridge(void)
693 memset(&data
, 0, sizeof(data
));
694 data
.machine
= MACHINE_PC
;
695 data
.variant
= ".bridge";
696 data
.required_struct_types
= base_required_struct_types
;
697 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
698 test_acpi_one("-device pci-bridge,chassis_nr=1", &data
);
699 free_test_data(&data
);
702 static void test_acpi_q35_tcg(void)
706 memset(&data
, 0, sizeof(data
));
707 data
.machine
= MACHINE_Q35
;
708 data
.required_struct_types
= base_required_struct_types
;
709 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
710 test_acpi_one(NULL
, &data
);
711 free_test_data(&data
);
714 static void test_acpi_q35_tcg_bridge(void)
718 memset(&data
, 0, sizeof(data
));
719 data
.machine
= MACHINE_Q35
;
720 data
.variant
= ".bridge";
721 data
.required_struct_types
= base_required_struct_types
;
722 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
723 test_acpi_one("-device pci-bridge,chassis_nr=1",
725 free_test_data(&data
);
728 static void test_acpi_q35_tcg_mmio64(void)
731 .machine
= MACHINE_Q35
,
732 .variant
= ".mmio64",
733 .required_struct_types
= base_required_struct_types
,
734 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
)
737 test_acpi_one("-m 128M,slots=1,maxmem=2G "
738 "-device pci-testdev,membar=2G",
740 free_test_data(&data
);
743 static void test_acpi_piix4_tcg_cphp(void)
747 memset(&data
, 0, sizeof(data
));
748 data
.machine
= MACHINE_PC
;
749 data
.variant
= ".cphp";
750 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
751 " -numa node -numa node"
752 " -numa dist,src=0,dst=1,val=21",
754 free_test_data(&data
);
757 static void test_acpi_q35_tcg_cphp(void)
761 memset(&data
, 0, sizeof(data
));
762 data
.machine
= MACHINE_Q35
;
763 data
.variant
= ".cphp";
764 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
765 " -numa node -numa node"
766 " -numa dist,src=0,dst=1,val=21",
768 free_test_data(&data
);
771 static uint8_t ipmi_required_struct_types
[] = {
772 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
775 static void test_acpi_q35_tcg_ipmi(void)
779 memset(&data
, 0, sizeof(data
));
780 data
.machine
= MACHINE_Q35
;
781 data
.variant
= ".ipmibt";
782 data
.required_struct_types
= ipmi_required_struct_types
;
783 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
784 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
785 " -device isa-ipmi-bt,bmc=bmc0",
787 free_test_data(&data
);
790 static void test_acpi_piix4_tcg_ipmi(void)
794 /* Supplying -machine accel argument overrides the default (qtest).
795 * This is to make guest actually run.
797 memset(&data
, 0, sizeof(data
));
798 data
.machine
= MACHINE_PC
;
799 data
.variant
= ".ipmikcs";
800 data
.required_struct_types
= ipmi_required_struct_types
;
801 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
802 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
803 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
805 free_test_data(&data
);
808 static void test_acpi_q35_tcg_memhp(void)
812 memset(&data
, 0, sizeof(data
));
813 data
.machine
= MACHINE_Q35
;
814 data
.variant
= ".memhp";
815 test_acpi_one(" -m 128,slots=3,maxmem=1G"
816 " -numa node -numa node"
817 " -numa dist,src=0,dst=1,val=21",
819 free_test_data(&data
);
822 static void test_acpi_piix4_tcg_memhp(void)
826 memset(&data
, 0, sizeof(data
));
827 data
.machine
= MACHINE_PC
;
828 data
.variant
= ".memhp";
829 test_acpi_one(" -m 128,slots=3,maxmem=1G"
830 " -numa node -numa node"
831 " -numa dist,src=0,dst=1,val=21",
833 free_test_data(&data
);
836 static void test_acpi_q35_tcg_numamem(void)
840 memset(&data
, 0, sizeof(data
));
841 data
.machine
= MACHINE_Q35
;
842 data
.variant
= ".numamem";
843 test_acpi_one(" -numa node -numa node,mem=128", &data
);
844 free_test_data(&data
);
847 static void test_acpi_piix4_tcg_numamem(void)
851 memset(&data
, 0, sizeof(data
));
852 data
.machine
= MACHINE_PC
;
853 data
.variant
= ".numamem";
854 test_acpi_one(" -numa node -numa node,mem=128", &data
);
855 free_test_data(&data
);
858 static void test_acpi_tcg_dimm_pxm(const char *machine
)
862 memset(&data
, 0, sizeof(data
));
863 data
.machine
= machine
;
864 data
.variant
= ".dimmpxm";
865 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
867 " -m 128M,slots=3,maxmem=1G"
868 " -numa node,mem=32M,nodeid=0"
869 " -numa node,mem=32M,nodeid=1"
870 " -numa node,mem=32M,nodeid=2"
871 " -numa node,mem=32M,nodeid=3"
872 " -numa cpu,node-id=0,socket-id=0"
873 " -numa cpu,node-id=1,socket-id=1"
874 " -numa cpu,node-id=2,socket-id=2"
875 " -numa cpu,node-id=3,socket-id=3"
876 " -object memory-backend-ram,id=ram0,size=128M"
877 " -object memory-backend-ram,id=nvm0,size=128M"
878 " -device pc-dimm,id=dimm0,memdev=ram0,node=1"
879 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
881 free_test_data(&data
);
884 static void test_acpi_q35_tcg_dimm_pxm(void)
886 test_acpi_tcg_dimm_pxm(MACHINE_Q35
);
889 static void test_acpi_piix4_tcg_dimm_pxm(void)
891 test_acpi_tcg_dimm_pxm(MACHINE_PC
);
894 int main(int argc
, char *argv
[])
896 const char *arch
= qtest_get_arch();
899 ret
= boot_sector_init(disk
);
903 g_test_init(&argc
, &argv
, NULL
);
905 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
906 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg
);
907 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge
);
908 qtest_add_func("acpi/q35", test_acpi_q35_tcg
);
909 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge
);
910 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64
);
911 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi
);
912 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi
);
913 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp
);
914 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp
);
915 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp
);
916 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp
);
917 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem
);
918 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem
);
919 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm
);
920 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm
);
923 boot_sector_cleanup(disk
);