apb: move the two secondary PCI bridges objects into APBState
[qemu/ar7.git] / tests / bios-tables-test.c
blobe28e0c98cfad8fad44eb6a45b85083f92649810d
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 AcpiFadtDescriptorRev3 fadt_table;
33 AcpiFacsDescriptorRev1 facs_table;
34 uint32_t *rsdt_tables_addr;
35 int rsdt_tables_nr;
36 GArray *tables;
37 uint32_t smbios_ep_addr;
38 struct smbios_21_entry_point smbios_ep_table;
39 uint8_t *required_struct_types;
40 int required_struct_types_len;
41 } test_data;
43 static char disk[] = "tests/acpi-test-disk-XXXXXX";
44 static const char *data_dir = "tests/acpi-test-data";
45 #ifdef CONFIG_IASL
46 static const char *iasl = stringify(CONFIG_IASL);
47 #else
48 static const char *iasl;
49 #endif
51 static void free_test_data(test_data *data)
53 AcpiSdtTable *temp;
54 int i;
56 g_free(data->rsdt_tables_addr);
58 for (i = 0; i < data->tables->len; ++i) {
59 temp = &g_array_index(data->tables, AcpiSdtTable, i);
60 g_free(temp->aml);
61 if (temp->aml_file &&
62 !temp->tmp_files_retain &&
63 g_strstr_len(temp->aml_file, -1, "aml-")) {
64 unlink(temp->aml_file);
66 g_free(temp->aml_file);
67 g_free(temp->asl);
68 if (temp->asl_file &&
69 !temp->tmp_files_retain) {
70 unlink(temp->asl_file);
72 g_free(temp->asl_file);
75 g_array_free(data->tables, true);
78 static void test_acpi_rsdp_address(test_data *data)
80 uint32_t off = acpi_find_rsdp_address();
81 g_assert_cmphex(off, <, 0x100000);
82 data->rsdp_addr = off;
85 static void test_acpi_rsdp_table(test_data *data)
87 AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
88 uint32_t addr = data->rsdp_addr;
90 acpi_parse_rsdp_table(addr, rsdp_table);
92 /* rsdp checksum is not for the whole table, but for the first 20 bytes */
93 g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
96 static void test_acpi_rsdt_table(test_data *data)
98 AcpiRsdtDescriptorRev1 *rsdt_table = &data->rsdt_table;
99 uint32_t addr = le32_to_cpu(data->rsdp_table.rsdt_physical_address);
100 uint32_t *tables;
101 int tables_nr;
102 uint8_t checksum;
103 uint32_t rsdt_table_length;
105 /* read the header */
106 ACPI_READ_TABLE_HEADER(rsdt_table, addr);
107 ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
109 rsdt_table_length = le32_to_cpu(rsdt_table->length);
111 /* compute the table entries in rsdt */
112 tables_nr = (rsdt_table_length - sizeof(AcpiRsdtDescriptorRev1)) /
113 sizeof(uint32_t);
114 g_assert(tables_nr > 0);
116 /* get the addresses of the tables pointed by rsdt */
117 tables = g_new0(uint32_t, tables_nr);
118 ACPI_READ_ARRAY_PTR(tables, tables_nr, addr);
120 checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table_length) +
121 acpi_calc_checksum((uint8_t *)tables,
122 tables_nr * sizeof(uint32_t));
123 g_assert(!checksum);
125 /* SSDT tables after FADT */
126 data->rsdt_tables_addr = tables;
127 data->rsdt_tables_nr = tables_nr;
130 static void test_acpi_fadt_table(test_data *data)
132 AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table;
133 uint32_t addr;
135 /* FADT table comes first */
136 addr = le32_to_cpu(data->rsdt_tables_addr[0]);
137 ACPI_READ_TABLE_HEADER(fadt_table, addr);
139 ACPI_READ_FIELD(fadt_table->firmware_ctrl, addr);
140 ACPI_READ_FIELD(fadt_table->dsdt, addr);
141 ACPI_READ_FIELD(fadt_table->model, addr);
142 ACPI_READ_FIELD(fadt_table->reserved1, addr);
143 ACPI_READ_FIELD(fadt_table->sci_int, addr);
144 ACPI_READ_FIELD(fadt_table->smi_cmd, addr);
145 ACPI_READ_FIELD(fadt_table->acpi_enable, addr);
146 ACPI_READ_FIELD(fadt_table->acpi_disable, addr);
147 ACPI_READ_FIELD(fadt_table->S4bios_req, addr);
148 ACPI_READ_FIELD(fadt_table->reserved2, addr);
149 ACPI_READ_FIELD(fadt_table->pm1a_evt_blk, addr);
150 ACPI_READ_FIELD(fadt_table->pm1b_evt_blk, addr);
151 ACPI_READ_FIELD(fadt_table->pm1a_cnt_blk, addr);
152 ACPI_READ_FIELD(fadt_table->pm1b_cnt_blk, addr);
153 ACPI_READ_FIELD(fadt_table->pm2_cnt_blk, addr);
154 ACPI_READ_FIELD(fadt_table->pm_tmr_blk, addr);
155 ACPI_READ_FIELD(fadt_table->gpe0_blk, addr);
156 ACPI_READ_FIELD(fadt_table->gpe1_blk, addr);
157 ACPI_READ_FIELD(fadt_table->pm1_evt_len, addr);
158 ACPI_READ_FIELD(fadt_table->pm1_cnt_len, addr);
159 ACPI_READ_FIELD(fadt_table->pm2_cnt_len, addr);
160 ACPI_READ_FIELD(fadt_table->pm_tmr_len, addr);
161 ACPI_READ_FIELD(fadt_table->gpe0_blk_len, addr);
162 ACPI_READ_FIELD(fadt_table->gpe1_blk_len, addr);
163 ACPI_READ_FIELD(fadt_table->gpe1_base, addr);
164 ACPI_READ_FIELD(fadt_table->reserved3, addr);
165 ACPI_READ_FIELD(fadt_table->plvl2_lat, addr);
166 ACPI_READ_FIELD(fadt_table->plvl3_lat, addr);
167 ACPI_READ_FIELD(fadt_table->flush_size, addr);
168 ACPI_READ_FIELD(fadt_table->flush_stride, addr);
169 ACPI_READ_FIELD(fadt_table->duty_offset, addr);
170 ACPI_READ_FIELD(fadt_table->duty_width, addr);
171 ACPI_READ_FIELD(fadt_table->day_alrm, addr);
172 ACPI_READ_FIELD(fadt_table->mon_alrm, addr);
173 ACPI_READ_FIELD(fadt_table->century, addr);
174 ACPI_READ_FIELD(fadt_table->boot_flags, addr);
175 ACPI_READ_FIELD(fadt_table->reserved, addr);
176 ACPI_READ_FIELD(fadt_table->flags, addr);
177 ACPI_READ_GENERIC_ADDRESS(fadt_table->reset_register, addr);
178 ACPI_READ_FIELD(fadt_table->reset_value, addr);
179 ACPI_READ_FIELD(fadt_table->arm_boot_flags, addr);
180 ACPI_READ_FIELD(fadt_table->minor_revision, addr);
181 ACPI_READ_FIELD(fadt_table->x_facs, addr);
182 ACPI_READ_FIELD(fadt_table->x_dsdt, addr);
183 ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_event_block, addr);
184 ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_event_block, addr);
185 ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_control_block, addr);
186 ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_control_block, addr);
187 ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm2_control_block, addr);
188 ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm_timer_block, addr);
189 ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe0_block, addr);
190 ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe1_block, addr);
192 ACPI_ASSERT_CMP(fadt_table->signature, "FACP");
193 g_assert(!acpi_calc_checksum((uint8_t *)fadt_table,
194 le32_to_cpu(fadt_table->length)));
197 static void test_acpi_facs_table(test_data *data)
199 AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
200 uint32_t addr = le32_to_cpu(data->fadt_table.firmware_ctrl);
202 ACPI_READ_FIELD(facs_table->signature, addr);
203 ACPI_READ_FIELD(facs_table->length, addr);
204 ACPI_READ_FIELD(facs_table->hardware_signature, addr);
205 ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr);
206 ACPI_READ_FIELD(facs_table->global_lock, addr);
207 ACPI_READ_FIELD(facs_table->flags, addr);
208 ACPI_READ_ARRAY(facs_table->resverved3, addr);
210 ACPI_ASSERT_CMP(facs_table->signature, "FACS");
213 static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr)
215 uint8_t checksum;
217 ACPI_READ_TABLE_HEADER(&sdt_table->header, addr);
219 sdt_table->aml_len = le32_to_cpu(sdt_table->header.length)
220 - sizeof(AcpiTableHeader);
221 sdt_table->aml = g_malloc0(sdt_table->aml_len);
222 ACPI_READ_ARRAY_PTR(sdt_table->aml, sdt_table->aml_len, addr);
224 checksum = acpi_calc_checksum((uint8_t *)sdt_table,
225 sizeof(AcpiTableHeader)) +
226 acpi_calc_checksum((uint8_t *)sdt_table->aml,
227 sdt_table->aml_len);
228 g_assert(!checksum);
231 static void test_acpi_dsdt_table(test_data *data)
233 AcpiSdtTable dsdt_table;
234 uint32_t addr = le32_to_cpu(data->fadt_table.dsdt);
236 memset(&dsdt_table, 0, sizeof(dsdt_table));
237 data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
239 test_dst_table(&dsdt_table, addr);
240 ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT");
242 /* Place DSDT first */
243 g_array_append_val(data->tables, dsdt_table);
246 static void test_acpi_tables(test_data *data)
248 int tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */
249 int i;
251 for (i = 0; i < tables_nr; i++) {
252 AcpiSdtTable ssdt_table;
253 uint32_t addr;
255 memset(&ssdt_table, 0, sizeof(ssdt_table));
256 addr = le32_to_cpu(data->rsdt_tables_addr[i + 1]); /* fadt is first */
257 test_dst_table(&ssdt_table, addr);
258 g_array_append_val(data->tables, ssdt_table);
262 static void dump_aml_files(test_data *data, bool rebuild)
264 AcpiSdtTable *sdt;
265 GError *error = NULL;
266 gchar *aml_file = NULL;
267 gint fd;
268 ssize_t ret;
269 int i;
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);
274 g_assert(sdt->aml);
276 if (rebuild) {
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);
281 } else {
282 fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
283 g_assert_no_error(error);
285 g_assert(fd >= 0);
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);
292 close(fd);
294 g_free(aml_file);
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)
305 AcpiSdtTable *temp;
306 GError *error = NULL;
307 GString *command_line = g_string_new(iasl);
308 gint fd;
309 gchar *out, *out_err;
310 gboolean ret;
311 int i;
313 fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
314 g_assert_no_error(error);
315 close(fd);
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);
334 if (ret) {
335 ret = g_file_get_contents(sdt->asl_file, (gchar **)&sdt->asl,
336 &sdt->asl_len, &error);
337 g_assert(ret);
338 g_assert_no_error(error);
339 ret = (sdt->asl_len > 0);
342 g_free(out);
343 g_free(out_err);
344 g_string_free(command_line, true);
346 return !ret;
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);
360 if (comment) {
361 comment += strlen(COMMENT_END);
362 while (*comment == '\n') {
363 comment++;
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);
376 return asl;
379 static GArray *load_expected_aml(test_data *data)
381 int i;
382 AcpiSdtTable *sdt;
383 GError *error = NULL;
384 gboolean ret;
386 GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
387 for (i = 0; i < data->tables->len; ++i) {
388 AcpiSdtTable exp_sdt;
389 gchar *aml_file = NULL;
390 const char *ext = data->variant ? data->variant : "";
392 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
394 memset(&exp_sdt, 0, sizeof(exp_sdt));
395 exp_sdt.header.signature = sdt->header.signature;
397 try_again:
398 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
399 (gchar *)&sdt->header.signature, ext);
400 if (getenv("V")) {
401 fprintf(stderr, "\nLooking for expected file '%s'\n", aml_file);
403 if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
404 exp_sdt.aml_file = aml_file;
405 } else if (*ext != '\0') {
406 /* try fallback to generic (extention less) expected file */
407 ext = "";
408 g_free(aml_file);
409 goto try_again;
411 g_assert(exp_sdt.aml_file);
412 if (getenv("V")) {
413 fprintf(stderr, "\nUsing expected file '%s'\n", aml_file);
415 ret = g_file_get_contents(aml_file, &exp_sdt.aml,
416 &exp_sdt.aml_len, &error);
417 g_assert(ret);
418 g_assert_no_error(error);
419 g_assert(exp_sdt.aml);
420 g_assert(exp_sdt.aml_len);
422 g_array_append_val(exp_tables, exp_sdt);
425 return exp_tables;
428 static void test_acpi_asl(test_data *data)
430 int i;
431 AcpiSdtTable *sdt, *exp_sdt;
432 test_data exp_data;
433 gboolean exp_err, err;
435 memset(&exp_data, 0, sizeof(exp_data));
436 exp_data.tables = load_expected_aml(data);
437 dump_aml_files(data, false);
438 for (i = 0; i < data->tables->len; ++i) {
439 GString *asl, *exp_asl;
441 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
442 exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
444 err = load_asl(data->tables, sdt);
445 asl = normalize_asl(sdt->asl);
447 exp_err = load_asl(exp_data.tables, exp_sdt);
448 exp_asl = normalize_asl(exp_sdt->asl);
450 /* TODO: check for warnings */
451 g_assert(!err || exp_err);
453 if (g_strcmp0(asl->str, exp_asl->str)) {
454 if (exp_err) {
455 fprintf(stderr,
456 "Warning! iasl couldn't parse the expected aml\n");
457 } else {
458 uint32_t signature = cpu_to_le32(exp_sdt->header.signature);
459 sdt->tmp_files_retain = true;
460 exp_sdt->tmp_files_retain = true;
461 fprintf(stderr,
462 "acpi-test: Warning! %.4s mismatch. "
463 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
464 (gchar *)&signature,
465 sdt->asl_file, sdt->aml_file,
466 exp_sdt->asl_file, exp_sdt->aml_file);
467 if (getenv("V")) {
468 const char *diff_cmd = getenv("DIFF");
469 if (diff_cmd) {
470 int ret G_GNUC_UNUSED;
471 char *diff = g_strdup_printf("%s %s %s", diff_cmd,
472 exp_sdt->asl_file, sdt->asl_file);
473 ret = system(diff) ;
474 g_free(diff);
475 } else {
476 fprintf(stderr, "acpi-test: Warning. not showing "
477 "difference since no diff utility is specified. "
478 "Set 'DIFF' environment variable to a preferred "
479 "diff utility and run 'make V=1 check' again to "
480 "see ASL difference.");
485 g_string_free(asl, true);
486 g_string_free(exp_asl, true);
489 free_test_data(&exp_data);
492 static bool smbios_ep_table_ok(test_data *data)
494 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
495 uint32_t addr = data->smbios_ep_addr;
497 ACPI_READ_ARRAY(ep_table->anchor_string, addr);
498 if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
499 return false;
501 ACPI_READ_FIELD(ep_table->checksum, addr);
502 ACPI_READ_FIELD(ep_table->length, addr);
503 ACPI_READ_FIELD(ep_table->smbios_major_version, addr);
504 ACPI_READ_FIELD(ep_table->smbios_minor_version, addr);
505 ACPI_READ_FIELD(ep_table->max_structure_size, addr);
506 ACPI_READ_FIELD(ep_table->entry_point_revision, addr);
507 ACPI_READ_ARRAY(ep_table->formatted_area, addr);
508 ACPI_READ_ARRAY(ep_table->intermediate_anchor_string, addr);
509 if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
510 return false;
512 ACPI_READ_FIELD(ep_table->intermediate_checksum, addr);
513 ACPI_READ_FIELD(ep_table->structure_table_length, addr);
514 if (ep_table->structure_table_length == 0) {
515 return false;
517 ACPI_READ_FIELD(ep_table->structure_table_address, addr);
518 ACPI_READ_FIELD(ep_table->number_of_structures, addr);
519 if (ep_table->number_of_structures == 0) {
520 return false;
522 ACPI_READ_FIELD(ep_table->smbios_bcd_revision, addr);
523 if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
524 acpi_calc_checksum((uint8_t *)ep_table + 0x10,
525 sizeof *ep_table - 0x10)) {
526 return false;
528 return true;
531 static void test_smbios_entry_point(test_data *data)
533 uint32_t off;
535 /* find smbios entry point structure */
536 for (off = 0xf0000; off < 0x100000; off += 0x10) {
537 uint8_t sig[] = "_SM_";
538 int i;
540 for (i = 0; i < sizeof sig - 1; ++i) {
541 sig[i] = readb(off + i);
544 if (!memcmp(sig, "_SM_", sizeof sig)) {
545 /* signature match, but is this a valid entry point? */
546 data->smbios_ep_addr = off;
547 if (smbios_ep_table_ok(data)) {
548 break;
553 g_assert_cmphex(off, <, 0x100000);
556 static inline bool smbios_single_instance(uint8_t type)
558 switch (type) {
559 case 0:
560 case 1:
561 case 2:
562 case 3:
563 case 16:
564 case 32:
565 case 127:
566 return true;
567 default:
568 return false;
572 static void test_smbios_structs(test_data *data)
574 DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
575 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
576 uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
577 int i, len, max_len = 0;
578 uint8_t type, prv, crt;
580 /* walk the smbios tables */
581 for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
583 /* grab type and formatted area length from struct header */
584 type = readb(addr);
585 g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
586 len = readb(addr + 1);
588 /* single-instance structs must not have been encountered before */
589 if (smbios_single_instance(type)) {
590 g_assert(!test_bit(type, struct_bitmap));
592 set_bit(type, struct_bitmap);
594 /* seek to end of unformatted string area of this struct ("\0\0") */
595 prv = crt = 1;
596 while (prv || crt) {
597 prv = crt;
598 crt = readb(addr + len);
599 len++;
602 /* keep track of max. struct size */
603 if (max_len < len) {
604 max_len = len;
605 g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
608 /* start of next structure */
609 addr += len;
612 /* total table length and max struct size must match entry point values */
613 g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
614 addr - le32_to_cpu(ep_table->structure_table_address));
615 g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
617 /* required struct types must all be present */
618 for (i = 0; i < data->required_struct_types_len; i++) {
619 g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
623 static void test_acpi_one(const char *params, test_data *data)
625 char *args;
627 /* Disable kernel irqchip to be able to override apic irq0. */
628 args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
629 "-net none -display none %s "
630 "-drive id=hd0,if=none,file=%s,format=raw "
631 "-device ide-hd,drive=hd0 ",
632 data->machine, "kvm:tcg",
633 params ? params : "", disk);
635 qtest_start(args);
637 boot_sector_test();
639 test_acpi_rsdp_address(data);
640 test_acpi_rsdp_table(data);
641 test_acpi_rsdt_table(data);
642 test_acpi_fadt_table(data);
643 test_acpi_facs_table(data);
644 test_acpi_dsdt_table(data);
645 test_acpi_tables(data);
647 if (iasl) {
648 if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
649 dump_aml_files(data, true);
650 } else {
651 test_acpi_asl(data);
655 test_smbios_entry_point(data);
656 test_smbios_structs(data);
658 qtest_quit(global_qtest);
659 g_free(args);
662 static uint8_t base_required_struct_types[] = {
663 0, 1, 3, 4, 16, 17, 19, 32, 127
666 static void test_acpi_piix4_tcg(void)
668 test_data data;
670 /* Supplying -machine accel argument overrides the default (qtest).
671 * This is to make guest actually run.
673 memset(&data, 0, sizeof(data));
674 data.machine = MACHINE_PC;
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(NULL, &data);
678 free_test_data(&data);
681 static void test_acpi_piix4_tcg_bridge(void)
683 test_data data;
685 memset(&data, 0, sizeof(data));
686 data.machine = MACHINE_PC;
687 data.variant = ".bridge";
688 data.required_struct_types = base_required_struct_types;
689 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
690 test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
691 free_test_data(&data);
694 static void test_acpi_q35_tcg(void)
696 test_data data;
698 memset(&data, 0, sizeof(data));
699 data.machine = MACHINE_Q35;
700 data.required_struct_types = base_required_struct_types;
701 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
702 test_acpi_one(NULL, &data);
703 free_test_data(&data);
706 static void test_acpi_q35_tcg_bridge(void)
708 test_data data;
710 memset(&data, 0, sizeof(data));
711 data.machine = MACHINE_Q35;
712 data.variant = ".bridge";
713 data.required_struct_types = base_required_struct_types;
714 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
715 test_acpi_one("-device pci-bridge,chassis_nr=1",
716 &data);
717 free_test_data(&data);
720 static void test_acpi_piix4_tcg_cphp(void)
722 test_data data;
724 memset(&data, 0, sizeof(data));
725 data.machine = MACHINE_PC;
726 data.variant = ".cphp";
727 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
728 " -numa node -numa node"
729 " -numa dist,src=0,dst=1,val=21",
730 &data);
731 free_test_data(&data);
734 static void test_acpi_q35_tcg_cphp(void)
736 test_data data;
738 memset(&data, 0, sizeof(data));
739 data.machine = MACHINE_Q35;
740 data.variant = ".cphp";
741 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
742 " -numa node -numa node"
743 " -numa dist,src=0,dst=1,val=21",
744 &data);
745 free_test_data(&data);
748 static uint8_t ipmi_required_struct_types[] = {
749 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
752 static void test_acpi_q35_tcg_ipmi(void)
754 test_data data;
756 memset(&data, 0, sizeof(data));
757 data.machine = MACHINE_Q35;
758 data.variant = ".ipmibt";
759 data.required_struct_types = ipmi_required_struct_types;
760 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
761 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
762 " -device isa-ipmi-bt,bmc=bmc0",
763 &data);
764 free_test_data(&data);
767 static void test_acpi_piix4_tcg_ipmi(void)
769 test_data data;
771 /* Supplying -machine accel argument overrides the default (qtest).
772 * This is to make guest actually run.
774 memset(&data, 0, sizeof(data));
775 data.machine = MACHINE_PC;
776 data.variant = ".ipmikcs";
777 data.required_struct_types = ipmi_required_struct_types;
778 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
779 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
780 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
781 &data);
782 free_test_data(&data);
785 static void test_acpi_q35_tcg_memhp(void)
787 test_data data;
789 memset(&data, 0, sizeof(data));
790 data.machine = MACHINE_Q35;
791 data.variant = ".memhp";
792 test_acpi_one(" -m 128,slots=3,maxmem=1G"
793 " -numa node -numa node"
794 " -numa dist,src=0,dst=1,val=21",
795 &data);
796 free_test_data(&data);
799 static void test_acpi_piix4_tcg_memhp(void)
801 test_data data;
803 memset(&data, 0, sizeof(data));
804 data.machine = MACHINE_PC;
805 data.variant = ".memhp";
806 test_acpi_one(" -m 128,slots=3,maxmem=1G"
807 " -numa node -numa node"
808 " -numa dist,src=0,dst=1,val=21",
809 &data);
810 free_test_data(&data);
813 int main(int argc, char *argv[])
815 const char *arch = qtest_get_arch();
816 int ret;
818 ret = boot_sector_init(disk);
819 if(ret)
820 return ret;
822 g_test_init(&argc, &argv, NULL);
824 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
825 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
826 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
827 qtest_add_func("acpi/q35", test_acpi_q35_tcg);
828 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
829 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
830 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
831 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
832 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
833 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
834 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
836 ret = g_test_run();
837 boot_sector_cleanup(disk);
838 return ret;