hw/ppc/mac_newworld, mac_oldworld: Don't use load_image()
[qemu/ar7.git] / tests / bios-tables-test.c
blobd661d9be62c0b3fc86567d0e3227347e4dfeb2a1
1 /*
2 * Boot order test cases.
4 * Copyright (c) 2013 Red Hat Inc.
6 * Authors:
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/smbios/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"
26 typedef struct {
27 const char *machine;
28 const char *variant;
29 uint32_t rsdp_addr;
30 AcpiRsdpDescriptor rsdp_table;
31 AcpiRsdtDescriptorRev1 rsdt_table;
32 uint32_t dsdt_addr;
33 uint32_t facs_addr;
34 AcpiFacsDescriptorRev1 facs_table;
35 uint32_t *rsdt_tables_addr;
36 int rsdt_tables_nr;
37 GArray *tables;
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;
42 } test_data;
44 static char disk[] = "tests/acpi-test-disk-XXXXXX";
45 static const char *data_dir = "tests/data/acpi";
46 #ifdef CONFIG_IASL
47 static const char *iasl = stringify(CONFIG_IASL);
48 #else
49 static const char *iasl;
50 #endif
52 static void free_test_data(test_data *data)
54 AcpiSdtTable *temp;
55 int i;
57 g_free(data->rsdt_tables_addr);
59 for (i = 0; i < data->tables->len; ++i) {
60 temp = &g_array_index(data->tables, AcpiSdtTable, i);
61 g_free(temp->aml);
62 if (temp->aml_file &&
63 !temp->tmp_files_retain &&
64 g_strstr_len(temp->aml_file, -1, "aml-")) {
65 unlink(temp->aml_file);
67 g_free(temp->aml_file);
68 g_free(temp->asl);
69 if (temp->asl_file &&
70 !temp->tmp_files_retain) {
71 unlink(temp->asl_file);
73 g_free(temp->asl_file);
76 g_array_free(data->tables, true);
79 static void test_acpi_rsdp_address(test_data *data)
81 uint32_t off = acpi_find_rsdp_address();
82 g_assert_cmphex(off, <, 0x100000);
83 data->rsdp_addr = off;
86 static void test_acpi_rsdp_table(test_data *data)
88 AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
89 uint32_t addr = data->rsdp_addr;
91 acpi_parse_rsdp_table(addr, rsdp_table);
93 /* rsdp checksum is not for the whole table, but for the first 20 bytes */
94 g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
97 static void test_acpi_rsdt_table(test_data *data)
99 AcpiRsdtDescriptorRev1 *rsdt_table = &data->rsdt_table;
100 uint32_t addr = le32_to_cpu(data->rsdp_table.rsdt_physical_address);
101 uint32_t *tables;
102 int tables_nr;
103 uint8_t checksum;
104 uint32_t rsdt_table_length;
106 /* read the header */
107 ACPI_READ_TABLE_HEADER(rsdt_table, addr);
108 ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
110 rsdt_table_length = le32_to_cpu(rsdt_table->length);
112 /* compute the table entries in rsdt */
113 tables_nr = (rsdt_table_length - sizeof(AcpiRsdtDescriptorRev1)) /
114 sizeof(uint32_t);
115 g_assert(tables_nr > 0);
117 /* get the addresses of the tables pointed by rsdt */
118 tables = g_new0(uint32_t, tables_nr);
119 ACPI_READ_ARRAY_PTR(tables, tables_nr, addr);
121 checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table_length) +
122 acpi_calc_checksum((uint8_t *)tables,
123 tables_nr * sizeof(uint32_t));
124 g_assert(!checksum);
126 /* SSDT tables after FADT */
127 data->rsdt_tables_addr = tables;
128 data->rsdt_tables_nr = tables_nr;
131 static void fadt_fetch_facs_and_dsdt_ptrs(test_data *data)
133 uint32_t addr;
134 AcpiTableHeader hdr;
136 /* FADT table comes first */
137 addr = le32_to_cpu(data->rsdt_tables_addr[0]);
138 ACPI_READ_TABLE_HEADER(&hdr, addr);
139 ACPI_ASSERT_CMP(hdr.signature, "FACP");
141 ACPI_READ_FIELD(data->facs_addr, addr);
142 ACPI_READ_FIELD(data->dsdt_addr, addr);
145 static void sanitize_fadt_ptrs(test_data *data)
147 /* fixup pointers in FADT */
148 int i;
150 for (i = 0; i < data->tables->len; i++) {
151 AcpiSdtTable *sdt = &g_array_index(data->tables, AcpiSdtTable, i);
153 if (memcmp(&sdt->header.signature, "FACP", 4)) {
154 continue;
157 /* check original FADT checksum before sanitizing table */
158 g_assert(!(uint8_t)(
159 acpi_calc_checksum((uint8_t *)sdt, sizeof(AcpiTableHeader)) +
160 acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len)
163 /* sdt->aml field offset := spec offset - header size */
164 memset(sdt->aml + 0, 0, 4); /* sanitize FIRMWARE_CTRL(36) ptr */
165 memset(sdt->aml + 4, 0, 4); /* sanitize DSDT(40) ptr */
166 if (sdt->header.revision >= 3) {
167 memset(sdt->aml + 96, 0, 8); /* sanitize X_FIRMWARE_CTRL(132) ptr */
168 memset(sdt->aml + 104, 0, 8); /* sanitize X_DSDT(140) ptr */
171 /* update checksum */
172 sdt->header.checksum = 0;
173 sdt->header.checksum -=
174 acpi_calc_checksum((uint8_t *)sdt, sizeof(AcpiTableHeader)) +
175 acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len);
176 break;
180 static void test_acpi_facs_table(test_data *data)
182 AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
183 uint32_t addr = le32_to_cpu(data->facs_addr);
185 ACPI_READ_FIELD(facs_table->signature, addr);
186 ACPI_READ_FIELD(facs_table->length, addr);
187 ACPI_READ_FIELD(facs_table->hardware_signature, addr);
188 ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr);
189 ACPI_READ_FIELD(facs_table->global_lock, addr);
190 ACPI_READ_FIELD(facs_table->flags, addr);
191 ACPI_READ_ARRAY(facs_table->resverved3, addr);
193 ACPI_ASSERT_CMP(facs_table->signature, "FACS");
196 /** fetch_table
197 * load ACPI table at @addr into table descriptor @sdt_table
198 * and check that header checksum matches actual one.
200 static void fetch_table(AcpiSdtTable *sdt_table, uint32_t addr)
202 uint8_t checksum;
204 memset(sdt_table, 0, sizeof(*sdt_table));
205 ACPI_READ_TABLE_HEADER(&sdt_table->header, addr);
207 sdt_table->aml_len = le32_to_cpu(sdt_table->header.length)
208 - sizeof(AcpiTableHeader);
209 sdt_table->aml = g_malloc0(sdt_table->aml_len);
210 ACPI_READ_ARRAY_PTR(sdt_table->aml, sdt_table->aml_len, addr);
212 checksum = acpi_calc_checksum((uint8_t *)sdt_table,
213 sizeof(AcpiTableHeader)) +
214 acpi_calc_checksum((uint8_t *)sdt_table->aml,
215 sdt_table->aml_len);
216 g_assert(!checksum);
219 static void test_acpi_dsdt_table(test_data *data)
221 AcpiSdtTable dsdt_table;
222 uint32_t addr = le32_to_cpu(data->dsdt_addr);
224 fetch_table(&dsdt_table, addr);
225 ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT");
227 /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually */
228 g_array_append_val(data->tables, dsdt_table);
231 /* Load all tables and add to test list directly RSDT referenced tables */
232 static void fetch_rsdt_referenced_tables(test_data *data)
234 int tables_nr = data->rsdt_tables_nr;
235 int i;
237 for (i = 0; i < tables_nr; i++) {
238 AcpiSdtTable ssdt_table;
239 uint32_t addr;
241 addr = le32_to_cpu(data->rsdt_tables_addr[i]);
242 fetch_table(&ssdt_table, addr);
244 /* Add table to ASL test tables list */
245 g_array_append_val(data->tables, ssdt_table);
249 static void dump_aml_files(test_data *data, bool rebuild)
251 AcpiSdtTable *sdt;
252 GError *error = NULL;
253 gchar *aml_file = NULL;
254 gint fd;
255 ssize_t ret;
256 int i;
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 g_assert(sdt->aml);
263 if (rebuild) {
264 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
265 (gchar *)&sdt->header.signature, ext);
266 fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
267 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
268 } else {
269 fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
270 g_assert_no_error(error);
272 g_assert(fd >= 0);
274 ret = qemu_write_full(fd, sdt, sizeof(AcpiTableHeader));
275 g_assert(ret == sizeof(AcpiTableHeader));
276 ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
277 g_assert(ret == sdt->aml_len);
279 close(fd);
281 g_free(aml_file);
285 static bool compare_signature(AcpiSdtTable *sdt, const char *signature)
287 return !memcmp(&sdt->header.signature, signature, 4);
290 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
292 AcpiSdtTable *temp;
293 GError *error = NULL;
294 GString *command_line = g_string_new(iasl);
295 gint fd;
296 gchar *out, *out_err;
297 gboolean ret;
298 int i;
300 fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
301 g_assert_no_error(error);
302 close(fd);
304 /* build command line */
305 g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
306 if (compare_signature(sdt, "DSDT") ||
307 compare_signature(sdt, "SSDT")) {
308 for (i = 0; i < sdts->len; ++i) {
309 temp = &g_array_index(sdts, AcpiSdtTable, i);
310 if (compare_signature(temp, "DSDT") ||
311 compare_signature(temp, "SSDT")) {
312 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
316 g_string_append_printf(command_line, "-d %s", sdt->aml_file);
318 /* pass 'out' and 'out_err' in order to be redirected */
319 ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
320 g_assert_no_error(error);
321 if (ret) {
322 ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
323 &sdt->asl_len, &error);
324 g_assert(ret);
325 g_assert_no_error(error);
326 ret = (sdt->asl_len > 0);
329 g_free(out);
330 g_free(out_err);
331 g_string_free(command_line, true);
333 return !ret;
336 #define COMMENT_END "*/"
337 #define DEF_BLOCK "DefinitionBlock ("
338 #define BLOCK_NAME_END ","
340 static GString *normalize_asl(gchar *asl_code)
342 GString *asl = g_string_new(asl_code);
343 gchar *comment, *block_name;
345 /* strip comments (different generation days) */
346 comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
347 if (comment) {
348 comment += strlen(COMMENT_END);
349 while (*comment == '\n') {
350 comment++;
352 asl = g_string_erase(asl, 0, comment - asl->str);
355 /* strip def block name (it has file path in it) */
356 if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
357 block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
358 g_assert(block_name);
359 asl = g_string_erase(asl, 0,
360 block_name + sizeof(BLOCK_NAME_END) - asl->str);
363 return asl;
366 static GArray *load_expected_aml(test_data *data)
368 int i;
369 AcpiSdtTable *sdt;
370 GError *error = NULL;
371 gboolean ret;
373 GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
374 for (i = 0; i < data->tables->len; ++i) {
375 AcpiSdtTable exp_sdt;
376 gchar *aml_file = NULL;
377 const char *ext = data->variant ? data->variant : "";
379 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
381 memset(&exp_sdt, 0, sizeof(exp_sdt));
382 exp_sdt.header.signature = sdt->header.signature;
384 try_again:
385 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
386 (gchar *)&sdt->header.signature, ext);
387 if (getenv("V")) {
388 fprintf(stderr, "\nLooking for expected file '%s'\n", aml_file);
390 if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
391 exp_sdt.aml_file = aml_file;
392 } else if (*ext != '\0') {
393 /* try fallback to generic (extension less) expected file */
394 ext = "";
395 g_free(aml_file);
396 goto try_again;
398 g_assert(exp_sdt.aml_file);
399 if (getenv("V")) {
400 fprintf(stderr, "\nUsing expected file '%s'\n", aml_file);
402 ret = g_file_get_contents(aml_file, &exp_sdt.aml,
403 &exp_sdt.aml_len, &error);
404 g_assert(ret);
405 g_assert_no_error(error);
406 g_assert(exp_sdt.aml);
407 g_assert(exp_sdt.aml_len);
409 g_array_append_val(exp_tables, exp_sdt);
412 return exp_tables;
415 /* test the list of tables in @data->tables against reference tables */
416 static void test_acpi_asl(test_data *data)
418 int i;
419 AcpiSdtTable *sdt, *exp_sdt;
420 test_data exp_data;
421 gboolean exp_err, err;
423 memset(&exp_data, 0, sizeof(exp_data));
424 exp_data.tables = load_expected_aml(data);
425 dump_aml_files(data, false);
426 for (i = 0; i < data->tables->len; ++i) {
427 GString *asl, *exp_asl;
429 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
430 exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
432 err = load_asl(data->tables, sdt);
433 asl = normalize_asl(sdt->asl);
435 exp_err = load_asl(exp_data.tables, exp_sdt);
436 exp_asl = normalize_asl(exp_sdt->asl);
438 /* TODO: check for warnings */
439 g_assert(!err || exp_err);
441 if (g_strcmp0(asl->str, exp_asl->str)) {
442 if (exp_err) {
443 fprintf(stderr,
444 "Warning! iasl couldn't parse the expected aml\n");
445 } else {
446 uint32_t signature = cpu_to_le32(exp_sdt->header.signature);
447 sdt->tmp_files_retain = true;
448 exp_sdt->tmp_files_retain = true;
449 fprintf(stderr,
450 "acpi-test: Warning! %.4s mismatch. "
451 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
452 (gchar *)&signature,
453 sdt->asl_file, sdt->aml_file,
454 exp_sdt->asl_file, exp_sdt->aml_file);
455 if (getenv("V")) {
456 const char *diff_cmd = getenv("DIFF");
457 if (diff_cmd) {
458 int ret G_GNUC_UNUSED;
459 char *diff = g_strdup_printf("%s %s %s", diff_cmd,
460 exp_sdt->asl_file, sdt->asl_file);
461 ret = system(diff) ;
462 g_free(diff);
463 } else {
464 fprintf(stderr, "acpi-test: Warning. not showing "
465 "difference since no diff utility is specified. "
466 "Set 'DIFF' environment variable to a preferred "
467 "diff utility and run 'make V=1 check' again to "
468 "see ASL difference.");
473 g_string_free(asl, true);
474 g_string_free(exp_asl, true);
477 free_test_data(&exp_data);
480 static bool smbios_ep_table_ok(test_data *data)
482 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
483 uint32_t addr = data->smbios_ep_addr;
485 ACPI_READ_ARRAY(ep_table->anchor_string, addr);
486 if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
487 return false;
489 ACPI_READ_FIELD(ep_table->checksum, addr);
490 ACPI_READ_FIELD(ep_table->length, addr);
491 ACPI_READ_FIELD(ep_table->smbios_major_version, addr);
492 ACPI_READ_FIELD(ep_table->smbios_minor_version, addr);
493 ACPI_READ_FIELD(ep_table->max_structure_size, addr);
494 ACPI_READ_FIELD(ep_table->entry_point_revision, addr);
495 ACPI_READ_ARRAY(ep_table->formatted_area, addr);
496 ACPI_READ_ARRAY(ep_table->intermediate_anchor_string, addr);
497 if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
498 return false;
500 ACPI_READ_FIELD(ep_table->intermediate_checksum, addr);
501 ACPI_READ_FIELD(ep_table->structure_table_length, addr);
502 if (ep_table->structure_table_length == 0) {
503 return false;
505 ACPI_READ_FIELD(ep_table->structure_table_address, addr);
506 ACPI_READ_FIELD(ep_table->number_of_structures, addr);
507 if (ep_table->number_of_structures == 0) {
508 return false;
510 ACPI_READ_FIELD(ep_table->smbios_bcd_revision, addr);
511 if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
512 acpi_calc_checksum((uint8_t *)ep_table + 0x10,
513 sizeof *ep_table - 0x10)) {
514 return false;
516 return true;
519 static void test_smbios_entry_point(test_data *data)
521 uint32_t off;
523 /* find smbios entry point structure */
524 for (off = 0xf0000; off < 0x100000; off += 0x10) {
525 uint8_t sig[] = "_SM_";
526 int i;
528 for (i = 0; i < sizeof sig - 1; ++i) {
529 sig[i] = readb(off + i);
532 if (!memcmp(sig, "_SM_", sizeof sig)) {
533 /* signature match, but is this a valid entry point? */
534 data->smbios_ep_addr = off;
535 if (smbios_ep_table_ok(data)) {
536 break;
541 g_assert_cmphex(off, <, 0x100000);
544 static inline bool smbios_single_instance(uint8_t type)
546 switch (type) {
547 case 0:
548 case 1:
549 case 2:
550 case 3:
551 case 16:
552 case 32:
553 case 127:
554 return true;
555 default:
556 return false;
560 static void test_smbios_structs(test_data *data)
562 DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
563 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
564 uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
565 int i, len, max_len = 0;
566 uint8_t type, prv, crt;
568 /* walk the smbios tables */
569 for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
571 /* grab type and formatted area length from struct header */
572 type = readb(addr);
573 g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
574 len = readb(addr + 1);
576 /* single-instance structs must not have been encountered before */
577 if (smbios_single_instance(type)) {
578 g_assert(!test_bit(type, struct_bitmap));
580 set_bit(type, struct_bitmap);
582 /* seek to end of unformatted string area of this struct ("\0\0") */
583 prv = crt = 1;
584 while (prv || crt) {
585 prv = crt;
586 crt = readb(addr + len);
587 len++;
590 /* keep track of max. struct size */
591 if (max_len < len) {
592 max_len = len;
593 g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
596 /* start of next structure */
597 addr += len;
600 /* total table length and max struct size must match entry point values */
601 g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
602 addr - le32_to_cpu(ep_table->structure_table_address));
603 g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
605 /* required struct types must all be present */
606 for (i = 0; i < data->required_struct_types_len; i++) {
607 g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
611 static void test_acpi_one(const char *params, test_data *data)
613 char *args;
615 /* Disable kernel irqchip to be able to override apic irq0. */
616 args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
617 "-net none -display none %s "
618 "-drive id=hd0,if=none,file=%s,format=raw "
619 "-device ide-hd,drive=hd0 ",
620 data->machine, "kvm:tcg",
621 params ? params : "", disk);
623 qtest_start(args);
625 boot_sector_test(global_qtest);
627 data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
628 test_acpi_rsdp_address(data);
629 test_acpi_rsdp_table(data);
630 test_acpi_rsdt_table(data);
631 fadt_fetch_facs_and_dsdt_ptrs(data);
632 test_acpi_facs_table(data);
633 test_acpi_dsdt_table(data);
634 fetch_rsdt_referenced_tables(data);
636 sanitize_fadt_ptrs(data);
638 if (iasl) {
639 if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
640 dump_aml_files(data, true);
641 } else {
642 test_acpi_asl(data);
646 test_smbios_entry_point(data);
647 test_smbios_structs(data);
649 qtest_quit(global_qtest);
650 g_free(args);
653 static uint8_t base_required_struct_types[] = {
654 0, 1, 3, 4, 16, 17, 19, 32, 127
657 static void test_acpi_piix4_tcg(void)
659 test_data data;
661 /* Supplying -machine accel argument overrides the default (qtest).
662 * This is to make guest actually run.
664 memset(&data, 0, sizeof(data));
665 data.machine = MACHINE_PC;
666 data.required_struct_types = base_required_struct_types;
667 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
668 test_acpi_one(NULL, &data);
669 free_test_data(&data);
672 static void test_acpi_piix4_tcg_bridge(void)
674 test_data data;
676 memset(&data, 0, sizeof(data));
677 data.machine = MACHINE_PC;
678 data.variant = ".bridge";
679 data.required_struct_types = base_required_struct_types;
680 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
681 test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
682 free_test_data(&data);
685 static void test_acpi_q35_tcg(void)
687 test_data data;
689 memset(&data, 0, sizeof(data));
690 data.machine = MACHINE_Q35;
691 data.required_struct_types = base_required_struct_types;
692 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
693 test_acpi_one(NULL, &data);
694 free_test_data(&data);
697 static void test_acpi_q35_tcg_bridge(void)
699 test_data data;
701 memset(&data, 0, sizeof(data));
702 data.machine = MACHINE_Q35;
703 data.variant = ".bridge";
704 data.required_struct_types = base_required_struct_types;
705 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
706 test_acpi_one("-device pci-bridge,chassis_nr=1",
707 &data);
708 free_test_data(&data);
711 static void test_acpi_q35_tcg_mmio64(void)
713 test_data data = {
714 .machine = MACHINE_Q35,
715 .variant = ".mmio64",
716 .required_struct_types = base_required_struct_types,
717 .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
720 test_acpi_one("-m 128M,slots=1,maxmem=2G "
721 "-device pci-testdev,membar=2G",
722 &data);
723 free_test_data(&data);
726 static void test_acpi_piix4_tcg_cphp(void)
728 test_data data;
730 memset(&data, 0, sizeof(data));
731 data.machine = MACHINE_PC;
732 data.variant = ".cphp";
733 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
734 " -numa node -numa node"
735 " -numa dist,src=0,dst=1,val=21",
736 &data);
737 free_test_data(&data);
740 static void test_acpi_q35_tcg_cphp(void)
742 test_data data;
744 memset(&data, 0, sizeof(data));
745 data.machine = MACHINE_Q35;
746 data.variant = ".cphp";
747 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
748 " -numa node -numa node"
749 " -numa dist,src=0,dst=1,val=21",
750 &data);
751 free_test_data(&data);
754 static uint8_t ipmi_required_struct_types[] = {
755 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
758 static void test_acpi_q35_tcg_ipmi(void)
760 test_data data;
762 memset(&data, 0, sizeof(data));
763 data.machine = MACHINE_Q35;
764 data.variant = ".ipmibt";
765 data.required_struct_types = ipmi_required_struct_types;
766 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
767 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
768 " -device isa-ipmi-bt,bmc=bmc0",
769 &data);
770 free_test_data(&data);
773 static void test_acpi_piix4_tcg_ipmi(void)
775 test_data data;
777 /* Supplying -machine accel argument overrides the default (qtest).
778 * This is to make guest actually run.
780 memset(&data, 0, sizeof(data));
781 data.machine = MACHINE_PC;
782 data.variant = ".ipmikcs";
783 data.required_struct_types = ipmi_required_struct_types;
784 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
785 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
786 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
787 &data);
788 free_test_data(&data);
791 static void test_acpi_q35_tcg_memhp(void)
793 test_data data;
795 memset(&data, 0, sizeof(data));
796 data.machine = MACHINE_Q35;
797 data.variant = ".memhp";
798 test_acpi_one(" -m 128,slots=3,maxmem=1G"
799 " -numa node -numa node"
800 " -numa dist,src=0,dst=1,val=21",
801 &data);
802 free_test_data(&data);
805 static void test_acpi_piix4_tcg_memhp(void)
807 test_data data;
809 memset(&data, 0, sizeof(data));
810 data.machine = MACHINE_PC;
811 data.variant = ".memhp";
812 test_acpi_one(" -m 128,slots=3,maxmem=1G"
813 " -numa node -numa node"
814 " -numa dist,src=0,dst=1,val=21",
815 &data);
816 free_test_data(&data);
819 static void test_acpi_q35_tcg_numamem(void)
821 test_data data;
823 memset(&data, 0, sizeof(data));
824 data.machine = MACHINE_Q35;
825 data.variant = ".numamem";
826 test_acpi_one(" -numa node -numa node,mem=128", &data);
827 free_test_data(&data);
830 static void test_acpi_piix4_tcg_numamem(void)
832 test_data data;
834 memset(&data, 0, sizeof(data));
835 data.machine = MACHINE_PC;
836 data.variant = ".numamem";
837 test_acpi_one(" -numa node -numa node,mem=128", &data);
838 free_test_data(&data);
841 static void test_acpi_tcg_dimm_pxm(const char *machine)
843 test_data data;
845 memset(&data, 0, sizeof(data));
846 data.machine = machine;
847 data.variant = ".dimmpxm";
848 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
849 " -smp 4,sockets=4"
850 " -m 128M,slots=3,maxmem=1G"
851 " -numa node,mem=32M,nodeid=0"
852 " -numa node,mem=32M,nodeid=1"
853 " -numa node,mem=32M,nodeid=2"
854 " -numa node,mem=32M,nodeid=3"
855 " -numa cpu,node-id=0,socket-id=0"
856 " -numa cpu,node-id=1,socket-id=1"
857 " -numa cpu,node-id=2,socket-id=2"
858 " -numa cpu,node-id=3,socket-id=3"
859 " -object memory-backend-ram,id=ram0,size=128M"
860 " -object memory-backend-ram,id=nvm0,size=128M"
861 " -device pc-dimm,id=dimm0,memdev=ram0,node=1"
862 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
863 &data);
864 free_test_data(&data);
867 static void test_acpi_q35_tcg_dimm_pxm(void)
869 test_acpi_tcg_dimm_pxm(MACHINE_Q35);
872 static void test_acpi_piix4_tcg_dimm_pxm(void)
874 test_acpi_tcg_dimm_pxm(MACHINE_PC);
877 int main(int argc, char *argv[])
879 const char *arch = qtest_get_arch();
880 int ret;
882 ret = boot_sector_init(disk);
883 if(ret)
884 return ret;
886 g_test_init(&argc, &argv, NULL);
888 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
889 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
890 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
891 qtest_add_func("acpi/q35", test_acpi_q35_tcg);
892 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
893 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
894 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
895 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
896 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
897 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
898 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
899 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
900 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
901 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
902 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
903 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
905 ret = g_test_run();
906 boot_sector_cleanup(disk);
907 return ret;