]>
Commit | Line | Data |
---|---|---|
ad6423a7 MT |
1 | /* |
2 | * Boot order test cases. | |
3 | * | |
4 | * Copyright (c) 2013 Red Hat Inc. | |
5 | * | |
6 | * Authors: | |
7 | * Michael S. Tsirkin <[email protected]>, | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
10 | * See the COPYING file in the top-level directory. | |
11 | */ | |
12 | ||
681c28a3 | 13 | #include "qemu/osdep.h" |
4500bc98 | 14 | #include <glib/gstdio.h> |
53333801 | 15 | #include "qemu-common.h" |
a2eb5c0c | 16 | #include "hw/firmware/smbios.h" |
eb386aac | 17 | #include "qemu/bitmap.h" |
3248f1b4 | 18 | #include "acpi-utils.h" |
4e082566 | 19 | #include "boot-sector.h" |
ad6423a7 | 20 | |
9e8458c0 MA |
21 | #define MACHINE_PC "pc" |
22 | #define MACHINE_Q35 "q35" | |
23 | ||
4500bc98 MA |
24 | #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" |
25 | ||
53333801 | 26 | typedef struct { |
9e8458c0 | 27 | const char *machine; |
3a9c86df | 28 | const char *variant; |
53333801 | 29 | uint32_t rsdp_addr; |
d6caf363 | 30 | uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; |
a3a74ab9 | 31 | GArray *tables; |
eb386aac | 32 | uint32_t smbios_ep_addr; |
86299120 | 33 | struct smbios_21_entry_point smbios_ep_table; |
f4eda2d4 CM |
34 | uint8_t *required_struct_types; |
35 | int required_struct_types_len; | |
273e3d92 | 36 | QTestState *qts; |
53333801 | 37 | } test_data; |
ad6423a7 | 38 | |
3e353773 | 39 | static char disk[] = "tests/acpi-test-disk-XXXXXX"; |
438c78da | 40 | static const char *data_dir = "tests/data/acpi"; |
cc8fa0e8 MA |
41 | #ifdef CONFIG_IASL |
42 | static const char *iasl = stringify(CONFIG_IASL); | |
43 | #else | |
44 | static const char *iasl; | |
45 | #endif | |
ad6423a7 | 46 | |
b137522c IM |
47 | static bool compare_signature(const AcpiSdtTable *sdt, const char *signature) |
48 | { | |
49 | return !memcmp(sdt->aml, signature, 4); | |
50 | } | |
51 | ||
569afd84 IM |
52 | static void cleanup_table_descriptor(AcpiSdtTable *table) |
53 | { | |
54 | g_free(table->aml); | |
55 | if (table->aml_file && | |
56 | !table->tmp_files_retain && | |
57 | g_strstr_len(table->aml_file, -1, "aml-")) { | |
58 | unlink(table->aml_file); | |
59 | } | |
60 | g_free(table->aml_file); | |
61 | g_free(table->asl); | |
62 | if (table->asl_file && | |
63 | !table->tmp_files_retain) { | |
64 | unlink(table->asl_file); | |
65 | } | |
66 | g_free(table->asl_file); | |
67 | } | |
68 | ||
8ac2adf7 MA |
69 | static void free_test_data(test_data *data) |
70 | { | |
71 | int i; | |
72 | ||
a3a74ab9 | 73 | for (i = 0; i < data->tables->len; ++i) { |
569afd84 | 74 | cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i)); |
8ac2adf7 | 75 | } |
9e8458c0 | 76 | |
f11dc27b | 77 | g_array_free(data->tables, true); |
8ac2adf7 MA |
78 | } |
79 | ||
53333801 MA |
80 | static void test_acpi_rsdp_address(test_data *data) |
81 | { | |
273e3d92 | 82 | uint32_t off = acpi_find_rsdp_address(data->qts); |
53333801 MA |
83 | g_assert_cmphex(off, <, 0x100000); |
84 | data->rsdp_addr = off; | |
85 | } | |
86 | ||
87 | static void test_acpi_rsdp_table(test_data *data) | |
88 | { | |
d6caf363 | 89 | uint8_t *rsdp_table = data->rsdp_table, revision; |
53333801 MA |
90 | uint32_t addr = data->rsdp_addr; |
91 | ||
273e3d92 | 92 | acpi_parse_rsdp_table(data->qts, addr, rsdp_table); |
d6caf363 SO |
93 | revision = rsdp_table[15 /* Revision offset */]; |
94 | ||
95 | switch (revision) { | |
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)); | |
99 | break; | |
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)); | |
104 | break; | |
105 | default: | |
106 | g_assert_not_reached(); | |
107 | } | |
53333801 MA |
108 | } |
109 | ||
110 | static void test_acpi_rsdt_table(test_data *data) | |
111 | { | |
569afd84 | 112 | AcpiSdtTable rsdt = {}; |
acee774b | 113 | uint8_t *ent; |
569afd84 | 114 | |
acee774b IM |
115 | /* read RSDT table */ |
116 | acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len, | |
117 | &data->rsdp_table[16 /* RsdtAddress */], "RSDT", true); | |
569afd84 IM |
118 | |
119 | /* Load all tables and add to test list directly RSDT referenced tables */ | |
acee774b | 120 | ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, 4 /* Entry size */) { |
569afd84 IM |
121 | AcpiSdtTable ssdt_table = {}; |
122 | ||
acee774b IM |
123 | acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent, |
124 | NULL, true); | |
569afd84 IM |
125 | /* Add table to ASL test tables list */ |
126 | g_array_append_val(data->tables, ssdt_table); | |
127 | } | |
128 | cleanup_table_descriptor(&rsdt); | |
53333801 MA |
129 | } |
130 | ||
db575449 | 131 | static void test_acpi_fadt_table(test_data *data) |
53333801 | 132 | { |
db575449 | 133 | /* FADT table is 1st */ |
59f9c6cc IM |
134 | AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0); |
135 | uint8_t *fadt_aml = table.aml; | |
b997a04a | 136 | uint32_t fadt_len = table.aml_len; |
53333801 | 137 | |
b137522c | 138 | g_assert(compare_signature(&table, "FACP")); |
89d47c19 | 139 | |
59f9c6cc | 140 | /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */ |
acee774b IM |
141 | acpi_fetch_table(data->qts, &table.aml, &table.aml_len, |
142 | fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false); | |
59f9c6cc IM |
143 | g_array_append_val(data->tables, table); |
144 | ||
acee774b IM |
145 | acpi_fetch_table(data->qts, &table.aml, &table.aml_len, |
146 | fadt_aml + 40 /* DSDT */, "DSDT", true); | |
59f9c6cc | 147 | g_array_append_val(data->tables, table); |
92146b7a | 148 | |
b997a04a IM |
149 | memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */ |
150 | memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */ | |
151 | if (fadt_aml[8 /* FADT Major Version */] >= 3) { | |
152 | memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */ | |
153 | memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */ | |
92146b7a | 154 | } |
b997a04a IM |
155 | |
156 | /* update checksum */ | |
157 | fadt_aml[9 /* Checksum */] = 0; | |
158 | fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len); | |
92146b7a IM |
159 | } |
160 | ||
4500bc98 | 161 | static void dump_aml_files(test_data *data, bool rebuild) |
9e8458c0 MA |
162 | { |
163 | AcpiSdtTable *sdt; | |
164 | GError *error = NULL; | |
4500bc98 | 165 | gchar *aml_file = NULL; |
9e8458c0 MA |
166 | gint fd; |
167 | ssize_t ret; | |
168 | int i; | |
169 | ||
a3a74ab9 | 170 | for (i = 0; i < data->tables->len; ++i) { |
3a9c86df | 171 | const char *ext = data->variant ? data->variant : ""; |
a3a74ab9 | 172 | sdt = &g_array_index(data->tables, AcpiSdtTable, i); |
9e8458c0 MA |
173 | g_assert(sdt->aml); |
174 | ||
4500bc98 | 175 | if (rebuild) { |
3a9c86df | 176 | aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine, |
b137522c | 177 | sdt->aml, ext); |
4500bc98 MA |
178 | fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, |
179 | S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); | |
180 | } else { | |
181 | fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error); | |
182 | g_assert_no_error(error); | |
183 | } | |
184 | g_assert(fd >= 0); | |
9e8458c0 | 185 | |
9e8458c0 MA |
186 | ret = qemu_write_full(fd, sdt->aml, sdt->aml_len); |
187 | g_assert(ret == sdt->aml_len); | |
188 | ||
189 | close(fd); | |
4500bc98 | 190 | |
ef1e1e07 | 191 | g_free(aml_file); |
9e8458c0 MA |
192 | } |
193 | } | |
194 | ||
15d914b1 | 195 | static bool load_asl(GArray *sdts, AcpiSdtTable *sdt) |
9e8458c0 MA |
196 | { |
197 | AcpiSdtTable *temp; | |
198 | GError *error = NULL; | |
cc8fa0e8 | 199 | GString *command_line = g_string_new(iasl); |
9e8458c0 MA |
200 | gint fd; |
201 | gchar *out, *out_err; | |
202 | gboolean ret; | |
203 | int i; | |
204 | ||
205 | fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error); | |
206 | g_assert_no_error(error); | |
207 | close(fd); | |
208 | ||
209 | /* build command line */ | |
cc8fa0e8 | 210 | g_string_append_printf(command_line, " -p %s ", sdt->asl_file); |
c225aa3c MT |
211 | if (compare_signature(sdt, "DSDT") || |
212 | compare_signature(sdt, "SSDT")) { | |
69d09245 MA |
213 | for (i = 0; i < sdts->len; ++i) { |
214 | temp = &g_array_index(sdts, AcpiSdtTable, i); | |
c225aa3c MT |
215 | if (compare_signature(temp, "DSDT") || |
216 | compare_signature(temp, "SSDT")) { | |
69d09245 MA |
217 | g_string_append_printf(command_line, "-e %s ", temp->aml_file); |
218 | } | |
219 | } | |
9e8458c0 MA |
220 | } |
221 | g_string_append_printf(command_line, "-d %s", sdt->aml_file); | |
222 | ||
223 | /* pass 'out' and 'out_err' in order to be redirected */ | |
15d914b1 | 224 | ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error); |
9e8458c0 | 225 | g_assert_no_error(error); |
15d914b1 | 226 | if (ret) { |
cc80b01a | 227 | ret = g_file_get_contents(sdt->asl_file, &sdt->asl, |
15d914b1 MA |
228 | &sdt->asl_len, &error); |
229 | g_assert(ret); | |
230 | g_assert_no_error(error); | |
dac23a6c | 231 | ret = (sdt->asl_len > 0); |
15d914b1 | 232 | } |
9e8458c0 MA |
233 | |
234 | g_free(out); | |
235 | g_free(out_err); | |
236 | g_string_free(command_line, true); | |
15d914b1 MA |
237 | |
238 | return !ret; | |
9e8458c0 MA |
239 | } |
240 | ||
241 | #define COMMENT_END "*/" | |
242 | #define DEF_BLOCK "DefinitionBlock (" | |
a3973f55 | 243 | #define BLOCK_NAME_END "," |
9e8458c0 MA |
244 | |
245 | static GString *normalize_asl(gchar *asl_code) | |
246 | { | |
247 | GString *asl = g_string_new(asl_code); | |
248 | gchar *comment, *block_name; | |
249 | ||
250 | /* strip comments (different generation days) */ | |
251 | comment = g_strstr_len(asl->str, asl->len, COMMENT_END); | |
252 | if (comment) { | |
cb348985 PB |
253 | comment += strlen(COMMENT_END); |
254 | while (*comment == '\n') { | |
255 | comment++; | |
256 | } | |
257 | asl = g_string_erase(asl, 0, comment - asl->str); | |
9e8458c0 MA |
258 | } |
259 | ||
260 | /* strip def block name (it has file path in it) */ | |
261 | if (g_str_has_prefix(asl->str, DEF_BLOCK)) { | |
262 | block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END); | |
263 | g_assert(block_name); | |
264 | asl = g_string_erase(asl, 0, | |
265 | block_name + sizeof(BLOCK_NAME_END) - asl->str); | |
266 | } | |
267 | ||
268 | return asl; | |
269 | } | |
270 | ||
271 | static GArray *load_expected_aml(test_data *data) | |
272 | { | |
273 | int i; | |
274 | AcpiSdtTable *sdt; | |
9e8458c0 MA |
275 | GError *error = NULL; |
276 | gboolean ret; | |
acee774b | 277 | gsize aml_len; |
9e8458c0 | 278 | |
a3a74ab9 | 279 | GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable)); |
fe17cca6 PMD |
280 | if (getenv("V")) { |
281 | fputc('\n', stderr); | |
282 | } | |
a3a74ab9 | 283 | for (i = 0; i < data->tables->len; ++i) { |
9e8458c0 | 284 | AcpiSdtTable exp_sdt; |
d19587db | 285 | gchar *aml_file = NULL; |
3a9c86df | 286 | const char *ext = data->variant ? data->variant : ""; |
c225aa3c | 287 | |
a3a74ab9 | 288 | sdt = &g_array_index(data->tables, AcpiSdtTable, i); |
9e8458c0 MA |
289 | |
290 | memset(&exp_sdt, 0, sizeof(exp_sdt)); | |
9e8458c0 | 291 | |
3a9c86df IM |
292 | try_again: |
293 | aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine, | |
b137522c | 294 | sdt->aml, ext); |
d19587db | 295 | if (getenv("V")) { |
fe17cca6 | 296 | fprintf(stderr, "Looking for expected file '%s'\n", aml_file); |
d19587db IM |
297 | } |
298 | if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) { | |
299 | exp_sdt.aml_file = aml_file; | |
300 | } else if (*ext != '\0') { | |
e50a6121 | 301 | /* try fallback to generic (extension less) expected file */ |
3a9c86df | 302 | ext = ""; |
d19587db | 303 | g_free(aml_file); |
3a9c86df IM |
304 | goto try_again; |
305 | } | |
d19587db IM |
306 | g_assert(exp_sdt.aml_file); |
307 | if (getenv("V")) { | |
fe17cca6 | 308 | fprintf(stderr, "Using expected file '%s'\n", aml_file); |
d19587db | 309 | } |
81eb530d | 310 | ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml, |
acee774b IM |
311 | &aml_len, &error); |
312 | exp_sdt.aml_len = aml_len; | |
9e8458c0 MA |
313 | g_assert(ret); |
314 | g_assert_no_error(error); | |
315 | g_assert(exp_sdt.aml); | |
316 | g_assert(exp_sdt.aml_len); | |
317 | ||
a3a74ab9 | 318 | g_array_append_val(exp_tables, exp_sdt); |
9e8458c0 MA |
319 | } |
320 | ||
a3a74ab9 | 321 | return exp_tables; |
9e8458c0 MA |
322 | } |
323 | ||
ab20bbd2 | 324 | /* test the list of tables in @data->tables against reference tables */ |
9e8458c0 MA |
325 | static void test_acpi_asl(test_data *data) |
326 | { | |
327 | int i; | |
328 | AcpiSdtTable *sdt, *exp_sdt; | |
329 | test_data exp_data; | |
15d914b1 | 330 | gboolean exp_err, err; |
9e8458c0 MA |
331 | |
332 | memset(&exp_data, 0, sizeof(exp_data)); | |
a3a74ab9 | 333 | exp_data.tables = load_expected_aml(data); |
4500bc98 | 334 | dump_aml_files(data, false); |
a3a74ab9 | 335 | for (i = 0; i < data->tables->len; ++i) { |
9e8458c0 MA |
336 | GString *asl, *exp_asl; |
337 | ||
a3a74ab9 MA |
338 | sdt = &g_array_index(data->tables, AcpiSdtTable, i); |
339 | exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i); | |
9e8458c0 | 340 | |
15d914b1 | 341 | err = load_asl(data->tables, sdt); |
9e8458c0 MA |
342 | asl = normalize_asl(sdt->asl); |
343 | ||
15d914b1 | 344 | exp_err = load_asl(exp_data.tables, exp_sdt); |
9e8458c0 MA |
345 | exp_asl = normalize_asl(exp_sdt->asl); |
346 | ||
15d914b1 MA |
347 | /* TODO: check for warnings */ |
348 | g_assert(!err || exp_err); | |
349 | ||
0651596c | 350 | if (g_strcmp0(asl->str, exp_asl->str)) { |
dac23a6c MA |
351 | if (exp_err) { |
352 | fprintf(stderr, | |
353 | "Warning! iasl couldn't parse the expected aml\n"); | |
354 | } else { | |
dac23a6c MA |
355 | sdt->tmp_files_retain = true; |
356 | exp_sdt->tmp_files_retain = true; | |
357 | fprintf(stderr, | |
358 | "acpi-test: Warning! %.4s mismatch. " | |
359 | "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n", | |
b137522c | 360 | exp_sdt->aml, sdt->asl_file, sdt->aml_file, |
dac23a6c | 361 | exp_sdt->asl_file, exp_sdt->aml_file); |
7cb08cb2 IM |
362 | if (getenv("V")) { |
363 | const char *diff_cmd = getenv("DIFF"); | |
364 | if (diff_cmd) { | |
365 | int ret G_GNUC_UNUSED; | |
366 | char *diff = g_strdup_printf("%s %s %s", diff_cmd, | |
367 | exp_sdt->asl_file, sdt->asl_file); | |
368 | ret = system(diff) ; | |
369 | g_free(diff); | |
370 | } else { | |
371 | fprintf(stderr, "acpi-test: Warning. not showing " | |
372 | "difference since no diff utility is specified. " | |
373 | "Set 'DIFF' environment variable to a preferred " | |
374 | "diff utility and run 'make V=1 check' again to " | |
375 | "see ASL difference."); | |
376 | } | |
377 | } | |
dac23a6c | 378 | } |
0651596c | 379 | } |
9e8458c0 MA |
380 | g_string_free(asl, true); |
381 | g_string_free(exp_asl, true); | |
382 | } | |
383 | ||
384 | free_test_data(&exp_data); | |
53333801 MA |
385 | } |
386 | ||
5efed5a1 | 387 | static bool smbios_ep_table_ok(test_data *data) |
eb386aac | 388 | { |
86299120 | 389 | struct smbios_21_entry_point *ep_table = &data->smbios_ep_table; |
eb386aac GS |
390 | uint32_t addr = data->smbios_ep_addr; |
391 | ||
3314778d | 392 | qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table)); |
5efed5a1 GS |
393 | if (memcmp(ep_table->anchor_string, "_SM_", 4)) { |
394 | return false; | |
395 | } | |
5efed5a1 GS |
396 | if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) { |
397 | return false; | |
398 | } | |
5efed5a1 GS |
399 | if (ep_table->structure_table_length == 0) { |
400 | return false; | |
401 | } | |
5efed5a1 GS |
402 | if (ep_table->number_of_structures == 0) { |
403 | return false; | |
404 | } | |
3248f1b4 BW |
405 | if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) || |
406 | acpi_calc_checksum((uint8_t *)ep_table + 0x10, | |
407 | sizeof *ep_table - 0x10)) { | |
5efed5a1 GS |
408 | return false; |
409 | } | |
410 | return true; | |
411 | } | |
412 | ||
413 | static void test_smbios_entry_point(test_data *data) | |
414 | { | |
415 | uint32_t off; | |
416 | ||
417 | /* find smbios entry point structure */ | |
418 | for (off = 0xf0000; off < 0x100000; off += 0x10) { | |
419 | uint8_t sig[] = "_SM_"; | |
420 | int i; | |
421 | ||
422 | for (i = 0; i < sizeof sig - 1; ++i) { | |
273e3d92 | 423 | sig[i] = qtest_readb(data->qts, off + i); |
5efed5a1 GS |
424 | } |
425 | ||
426 | if (!memcmp(sig, "_SM_", sizeof sig)) { | |
427 | /* signature match, but is this a valid entry point? */ | |
428 | data->smbios_ep_addr = off; | |
429 | if (smbios_ep_table_ok(data)) { | |
430 | break; | |
431 | } | |
432 | } | |
433 | } | |
434 | ||
435 | g_assert_cmphex(off, <, 0x100000); | |
eb386aac GS |
436 | } |
437 | ||
438 | static inline bool smbios_single_instance(uint8_t type) | |
439 | { | |
440 | switch (type) { | |
441 | case 0: | |
442 | case 1: | |
443 | case 2: | |
444 | case 3: | |
445 | case 16: | |
446 | case 32: | |
447 | case 127: | |
448 | return true; | |
449 | default: | |
450 | return false; | |
451 | } | |
452 | } | |
453 | ||
454 | static void test_smbios_structs(test_data *data) | |
455 | { | |
456 | DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 }; | |
86299120 | 457 | struct smbios_21_entry_point *ep_table = &data->smbios_ep_table; |
3831c07b | 458 | uint32_t addr = le32_to_cpu(ep_table->structure_table_address); |
eb386aac GS |
459 | int i, len, max_len = 0; |
460 | uint8_t type, prv, crt; | |
eb386aac GS |
461 | |
462 | /* walk the smbios tables */ | |
3831c07b | 463 | for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) { |
eb386aac GS |
464 | |
465 | /* grab type and formatted area length from struct header */ | |
273e3d92 | 466 | type = qtest_readb(data->qts, addr); |
eb386aac | 467 | g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE); |
273e3d92 | 468 | len = qtest_readb(data->qts, addr + 1); |
eb386aac GS |
469 | |
470 | /* single-instance structs must not have been encountered before */ | |
471 | if (smbios_single_instance(type)) { | |
472 | g_assert(!test_bit(type, struct_bitmap)); | |
473 | } | |
474 | set_bit(type, struct_bitmap); | |
475 | ||
476 | /* seek to end of unformatted string area of this struct ("\0\0") */ | |
477 | prv = crt = 1; | |
478 | while (prv || crt) { | |
479 | prv = crt; | |
273e3d92 | 480 | crt = qtest_readb(data->qts, addr + len); |
eb386aac GS |
481 | len++; |
482 | } | |
483 | ||
484 | /* keep track of max. struct size */ | |
485 | if (max_len < len) { | |
486 | max_len = len; | |
487 | g_assert_cmpuint(max_len, <=, ep_table->max_structure_size); | |
488 | } | |
489 | ||
490 | /* start of next structure */ | |
491 | addr += len; | |
492 | } | |
493 | ||
494 | /* total table length and max struct size must match entry point values */ | |
3831c07b TH |
495 | g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==, |
496 | addr - le32_to_cpu(ep_table->structure_table_address)); | |
497 | g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len); | |
eb386aac GS |
498 | |
499 | /* required struct types must all be present */ | |
f4eda2d4 CM |
500 | for (i = 0; i < data->required_struct_types_len; i++) { |
501 | g_assert(test_bit(data->required_struct_types[i], struct_bitmap)); | |
eb386aac GS |
502 | } |
503 | } | |
504 | ||
8ac2adf7 | 505 | static void test_acpi_one(const char *params, test_data *data) |
ad6423a7 MT |
506 | { |
507 | char *args; | |
ad6423a7 | 508 | |
947b205f MA |
509 | /* Disable kernel irqchip to be able to override apic irq0. */ |
510 | args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off " | |
511 | "-net none -display none %s " | |
b8e665e4 | 512 | "-drive id=hd0,if=none,file=%s,format=raw " |
6b9e03a4 | 513 | "-device ide-hd,drive=hd0 ", |
947b205f | 514 | data->machine, "kvm:tcg", |
6b9e03a4 | 515 | params ? params : "", disk); |
9e8458c0 | 516 | |
273e3d92 | 517 | data->qts = qtest_init(args); |
ad6423a7 | 518 | |
273e3d92 | 519 | boot_sector_test(data->qts); |
ad6423a7 | 520 | |
b24b9d94 | 521 | data->tables = g_array_new(false, true, sizeof(AcpiSdtTable)); |
8ac2adf7 MA |
522 | test_acpi_rsdp_address(data); |
523 | test_acpi_rsdp_table(data); | |
524 | test_acpi_rsdt_table(data); | |
db575449 | 525 | test_acpi_fadt_table(data); |
ad6423a7 | 526 | |
cc8fa0e8 | 527 | if (iasl) { |
4500bc98 MA |
528 | if (getenv(ACPI_REBUILD_EXPECTED_AML)) { |
529 | dump_aml_files(data, true); | |
530 | } else { | |
531 | test_acpi_asl(data); | |
532 | } | |
9e8458c0 MA |
533 | } |
534 | ||
5efed5a1 | 535 | test_smbios_entry_point(data); |
eb386aac GS |
536 | test_smbios_structs(data); |
537 | ||
273e3d92 EB |
538 | assert(!global_qtest); |
539 | qtest_quit(data->qts); | |
ad6423a7 MT |
540 | g_free(args); |
541 | } | |
542 | ||
f4eda2d4 CM |
543 | static uint8_t base_required_struct_types[] = { |
544 | 0, 1, 3, 4, 16, 17, 19, 32, 127 | |
545 | }; | |
546 | ||
71f4be25 | 547 | static void test_acpi_piix4_tcg(void) |
ad6423a7 | 548 | { |
8ac2adf7 MA |
549 | test_data data; |
550 | ||
ad6423a7 MT |
551 | /* Supplying -machine accel argument overrides the default (qtest). |
552 | * This is to make guest actually run. | |
553 | */ | |
9e8458c0 MA |
554 | memset(&data, 0, sizeof(data)); |
555 | data.machine = MACHINE_PC; | |
f4eda2d4 CM |
556 | data.required_struct_types = base_required_struct_types; |
557 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 558 | test_acpi_one(NULL, &data); |
9e8458c0 | 559 | free_test_data(&data); |
71f4be25 PB |
560 | } |
561 | ||
3a9c86df IM |
562 | static void test_acpi_piix4_tcg_bridge(void) |
563 | { | |
564 | test_data data; | |
565 | ||
566 | memset(&data, 0, sizeof(data)); | |
567 | data.machine = MACHINE_PC; | |
568 | data.variant = ".bridge"; | |
f4eda2d4 CM |
569 | data.required_struct_types = base_required_struct_types; |
570 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 571 | test_acpi_one("-device pci-bridge,chassis_nr=1", &data); |
3a9c86df IM |
572 | free_test_data(&data); |
573 | } | |
574 | ||
71f4be25 PB |
575 | static void test_acpi_q35_tcg(void) |
576 | { | |
577 | test_data data; | |
8ac2adf7 | 578 | |
9e8458c0 MA |
579 | memset(&data, 0, sizeof(data)); |
580 | data.machine = MACHINE_Q35; | |
f4eda2d4 CM |
581 | data.required_struct_types = base_required_struct_types; |
582 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 583 | test_acpi_one(NULL, &data); |
8ac2adf7 | 584 | free_test_data(&data); |
ad6423a7 MT |
585 | } |
586 | ||
3a9c86df IM |
587 | static void test_acpi_q35_tcg_bridge(void) |
588 | { | |
589 | test_data data; | |
590 | ||
591 | memset(&data, 0, sizeof(data)); | |
592 | data.machine = MACHINE_Q35; | |
593 | data.variant = ".bridge"; | |
f4eda2d4 CM |
594 | data.required_struct_types = base_required_struct_types; |
595 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 596 | test_acpi_one("-device pci-bridge,chassis_nr=1", |
3a9c86df IM |
597 | &data); |
598 | free_test_data(&data); | |
599 | } | |
600 | ||
0259e966 LE |
601 | static void test_acpi_q35_tcg_mmio64(void) |
602 | { | |
603 | test_data data = { | |
604 | .machine = MACHINE_Q35, | |
605 | .variant = ".mmio64", | |
606 | .required_struct_types = base_required_struct_types, | |
607 | .required_struct_types_len = ARRAY_SIZE(base_required_struct_types) | |
608 | }; | |
609 | ||
610 | test_acpi_one("-m 128M,slots=1,maxmem=2G " | |
611 | "-device pci-testdev,membar=2G", | |
612 | &data); | |
613 | free_test_data(&data); | |
614 | } | |
615 | ||
6b9c1dd2 IM |
616 | static void test_acpi_piix4_tcg_cphp(void) |
617 | { | |
618 | test_data data; | |
619 | ||
620 | memset(&data, 0, sizeof(data)); | |
621 | data.machine = MACHINE_PC; | |
622 | data.variant = ".cphp"; | |
d6309c17 | 623 | test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6" |
fda4096f HC |
624 | " -numa node -numa node" |
625 | " -numa dist,src=0,dst=1,val=21", | |
6b9c1dd2 IM |
626 | &data); |
627 | free_test_data(&data); | |
628 | } | |
629 | ||
630 | static void test_acpi_q35_tcg_cphp(void) | |
631 | { | |
632 | test_data data; | |
633 | ||
634 | memset(&data, 0, sizeof(data)); | |
635 | data.machine = MACHINE_Q35; | |
636 | data.variant = ".cphp"; | |
d6309c17 | 637 | test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6" |
fda4096f HC |
638 | " -numa node -numa node" |
639 | " -numa dist,src=0,dst=1,val=21", | |
6b9c1dd2 IM |
640 | &data); |
641 | free_test_data(&data); | |
642 | } | |
643 | ||
f4eda2d4 CM |
644 | static uint8_t ipmi_required_struct_types[] = { |
645 | 0, 1, 3, 4, 16, 17, 19, 32, 38, 127 | |
646 | }; | |
647 | ||
648 | static void test_acpi_q35_tcg_ipmi(void) | |
649 | { | |
650 | test_data data; | |
651 | ||
652 | memset(&data, 0, sizeof(data)); | |
653 | data.machine = MACHINE_Q35; | |
654 | data.variant = ".ipmibt"; | |
655 | data.required_struct_types = ipmi_required_struct_types; | |
656 | data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types); | |
947b205f | 657 | test_acpi_one("-device ipmi-bmc-sim,id=bmc0" |
f4eda2d4 CM |
658 | " -device isa-ipmi-bt,bmc=bmc0", |
659 | &data); | |
660 | free_test_data(&data); | |
661 | } | |
662 | ||
663 | static void test_acpi_piix4_tcg_ipmi(void) | |
664 | { | |
665 | test_data data; | |
666 | ||
667 | /* Supplying -machine accel argument overrides the default (qtest). | |
668 | * This is to make guest actually run. | |
669 | */ | |
670 | memset(&data, 0, sizeof(data)); | |
671 | data.machine = MACHINE_PC; | |
672 | data.variant = ".ipmikcs"; | |
673 | data.required_struct_types = ipmi_required_struct_types; | |
674 | data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types); | |
947b205f | 675 | test_acpi_one("-device ipmi-bmc-sim,id=bmc0" |
f4eda2d4 CM |
676 | " -device isa-ipmi-kcs,irq=0,bmc=bmc0", |
677 | &data); | |
678 | free_test_data(&data); | |
679 | } | |
680 | ||
4462fc60 IM |
681 | static void test_acpi_q35_tcg_memhp(void) |
682 | { | |
683 | test_data data; | |
684 | ||
685 | memset(&data, 0, sizeof(data)); | |
686 | data.machine = MACHINE_Q35; | |
687 | data.variant = ".memhp"; | |
fda4096f HC |
688 | test_acpi_one(" -m 128,slots=3,maxmem=1G" |
689 | " -numa node -numa node" | |
690 | " -numa dist,src=0,dst=1,val=21", | |
691 | &data); | |
4462fc60 IM |
692 | free_test_data(&data); |
693 | } | |
694 | ||
695 | static void test_acpi_piix4_tcg_memhp(void) | |
696 | { | |
697 | test_data data; | |
698 | ||
699 | memset(&data, 0, sizeof(data)); | |
700 | data.machine = MACHINE_PC; | |
701 | data.variant = ".memhp"; | |
fda4096f HC |
702 | test_acpi_one(" -m 128,slots=3,maxmem=1G" |
703 | " -numa node -numa node" | |
704 | " -numa dist,src=0,dst=1,val=21", | |
705 | &data); | |
4462fc60 IM |
706 | free_test_data(&data); |
707 | } | |
708 | ||
d82c4f82 DL |
709 | static void test_acpi_q35_tcg_numamem(void) |
710 | { | |
711 | test_data data; | |
712 | ||
713 | memset(&data, 0, sizeof(data)); | |
714 | data.machine = MACHINE_Q35; | |
715 | data.variant = ".numamem"; | |
716 | test_acpi_one(" -numa node -numa node,mem=128", &data); | |
717 | free_test_data(&data); | |
718 | } | |
719 | ||
720 | static void test_acpi_piix4_tcg_numamem(void) | |
721 | { | |
722 | test_data data; | |
723 | ||
724 | memset(&data, 0, sizeof(data)); | |
725 | data.machine = MACHINE_PC; | |
726 | data.variant = ".numamem"; | |
727 | test_acpi_one(" -numa node -numa node,mem=128", &data); | |
728 | free_test_data(&data); | |
729 | } | |
730 | ||
adae91ce HZ |
731 | static void test_acpi_tcg_dimm_pxm(const char *machine) |
732 | { | |
733 | test_data data; | |
734 | ||
735 | memset(&data, 0, sizeof(data)); | |
736 | data.machine = machine; | |
737 | data.variant = ".dimmpxm"; | |
11c39b5c | 738 | test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu" |
adae91ce HZ |
739 | " -smp 4,sockets=4" |
740 | " -m 128M,slots=3,maxmem=1G" | |
741 | " -numa node,mem=32M,nodeid=0" | |
742 | " -numa node,mem=32M,nodeid=1" | |
743 | " -numa node,mem=32M,nodeid=2" | |
744 | " -numa node,mem=32M,nodeid=3" | |
745 | " -numa cpu,node-id=0,socket-id=0" | |
746 | " -numa cpu,node-id=1,socket-id=1" | |
747 | " -numa cpu,node-id=2,socket-id=2" | |
748 | " -numa cpu,node-id=3,socket-id=3" | |
749 | " -object memory-backend-ram,id=ram0,size=128M" | |
750 | " -object memory-backend-ram,id=nvm0,size=128M" | |
751 | " -device pc-dimm,id=dimm0,memdev=ram0,node=1" | |
752 | " -device nvdimm,id=dimm1,memdev=nvm0,node=2", | |
753 | &data); | |
754 | free_test_data(&data); | |
755 | } | |
756 | ||
757 | static void test_acpi_q35_tcg_dimm_pxm(void) | |
758 | { | |
759 | test_acpi_tcg_dimm_pxm(MACHINE_Q35); | |
760 | } | |
761 | ||
762 | static void test_acpi_piix4_tcg_dimm_pxm(void) | |
763 | { | |
764 | test_acpi_tcg_dimm_pxm(MACHINE_PC); | |
765 | } | |
766 | ||
ad6423a7 MT |
767 | int main(int argc, char *argv[]) |
768 | { | |
769 | const char *arch = qtest_get_arch(); | |
5862ad0f | 770 | int ret; |
c39a28a4 | 771 | |
4e082566 VK |
772 | ret = boot_sector_init(disk); |
773 | if(ret) | |
774 | return ret; | |
ad6423a7 MT |
775 | |
776 | g_test_init(&argc, &argv, NULL); | |
777 | ||
778 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { | |
947b205f MA |
779 | qtest_add_func("acpi/piix4", test_acpi_piix4_tcg); |
780 | qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge); | |
781 | qtest_add_func("acpi/q35", test_acpi_q35_tcg); | |
782 | qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge); | |
0259e966 | 783 | qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64); |
947b205f MA |
784 | qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi); |
785 | qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi); | |
786 | qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp); | |
787 | qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp); | |
4462fc60 IM |
788 | qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp); |
789 | qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp); | |
d82c4f82 DL |
790 | qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem); |
791 | qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem); | |
adae91ce HZ |
792 | qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm); |
793 | qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm); | |
ad6423a7 | 794 | } |
5862ad0f | 795 | ret = g_test_run(); |
4e082566 | 796 | boot_sector_cleanup(disk); |
5862ad0f | 797 | return ret; |
ad6423a7 | 798 | } |