]>
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 | ||
30c63d4f MT |
13 | /* |
14 | * How to add or update the tests: | |
15 | * Contributor: | |
16 | * 1. add empty files for new tables, if any, under tests/data/acpi | |
c66e8ab0 | 17 | * 2. list any changed files in tests/qtest/bios-tables-test-allowed-diff.h |
30c63d4f | 18 | * 3. commit the above *before* making changes that affect the tables |
3c2ab559 MT |
19 | * |
20 | * Contributor or ACPI Maintainer (steps 4-7 need to be redone to resolve conflicts | |
21 | * in binary commit created in step 6): | |
22 | * | |
30c63d4f | 23 | * After 1-3 above tests will pass but ignore differences with the expected files. |
c66e8ab0 | 24 | * You will also notice that tests/qtest/bios-tables-test-allowed-diff.h lists |
30c63d4f MT |
25 | * a bunch of files. This is your hint that you need to do the below: |
26 | * 4. Run | |
27 | * make check V=1 | |
28 | * this will produce a bunch of warnings about differences | |
29 | * beween actual and expected ACPI tables. If you have IASL installed, | |
30 | * they will also be disassembled so you can look at the disassembled | |
31 | * output. If not - disassemble them yourself in any way you like. | |
32 | * Look at the differences - make sure they make sense and match what the | |
33 | * changes you are merging are supposed to do. | |
3c2ab559 MT |
34 | * Save the changes, preferably in form of ASL diff for the commit log in |
35 | * step 6. | |
30c63d4f MT |
36 | * |
37 | * 5. From build directory, run: | |
38 | * $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh | |
3c2ab559 MT |
39 | * 6. Now commit any changes to the expected binary, include diff from step 4 |
40 | * in commit log. | |
41 | * 7. Before sending patches to the list (Contributor) | |
42 | * or before doing a pull request (Maintainer), make sure | |
c66e8ab0 | 43 | * tests/qtest/bios-tables-test-allowed-diff.h is empty - this will ensure |
3c2ab559 MT |
44 | * following changes to ACPI tables will be noticed. |
45 | * | |
46 | * The resulting patchset/pull request then looks like this: | |
c66e8ab0 | 47 | * - patch 1: list changed files in tests/qtest/bios-tables-test-allowed-diff.h. |
3c2ab559 MT |
48 | * - patches 2 - n: real changes, may contain multiple patches. |
49 | * - patch n + 1: update golden master binaries and empty | |
c66e8ab0 | 50 | * tests/qtest/bios-tables-test-allowed-diff.h |
30c63d4f MT |
51 | */ |
52 | ||
681c28a3 | 53 | #include "qemu/osdep.h" |
4500bc98 | 54 | #include <glib/gstdio.h> |
53333801 | 55 | #include "qemu-common.h" |
a2eb5c0c | 56 | #include "hw/firmware/smbios.h" |
eb386aac | 57 | #include "qemu/bitmap.h" |
3248f1b4 | 58 | #include "acpi-utils.h" |
4e082566 | 59 | #include "boot-sector.h" |
5da7c35e EA |
60 | #include "tpm-emu.h" |
61 | #include "hw/acpi/tpm.h" | |
62 | ||
ad6423a7 | 63 | |
9e8458c0 MA |
64 | #define MACHINE_PC "pc" |
65 | #define MACHINE_Q35 "q35" | |
66 | ||
4500bc98 MA |
67 | #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" |
68 | ||
53333801 | 69 | typedef struct { |
6f6e1698 | 70 | bool tcg_only; |
9e8458c0 | 71 | const char *machine; |
3a9c86df | 72 | const char *variant; |
97256e79 IM |
73 | const char *uefi_fl1; |
74 | const char *uefi_fl2; | |
3cac3784 | 75 | const char *blkdev; |
97256e79 IM |
76 | const char *cd; |
77 | const uint64_t ram_start; | |
78 | const uint64_t scan_len; | |
9c041885 | 79 | uint64_t rsdp_addr; |
d6caf363 | 80 | uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; |
a3a74ab9 | 81 | GArray *tables; |
eb386aac | 82 | uint32_t smbios_ep_addr; |
86299120 | 83 | struct smbios_21_entry_point smbios_ep_table; |
e1647539 YF |
84 | uint16_t smbios_cpu_max_speed; |
85 | uint16_t smbios_cpu_curr_speed; | |
f4eda2d4 CM |
86 | uint8_t *required_struct_types; |
87 | int required_struct_types_len; | |
273e3d92 | 88 | QTestState *qts; |
53333801 | 89 | } test_data; |
ad6423a7 | 90 | |
3e353773 | 91 | static char disk[] = "tests/acpi-test-disk-XXXXXX"; |
438c78da | 92 | static const char *data_dir = "tests/data/acpi"; |
cc8fa0e8 | 93 | #ifdef CONFIG_IASL |
859aef02 | 94 | static const char *iasl = CONFIG_IASL; |
cc8fa0e8 MA |
95 | #else |
96 | static const char *iasl; | |
97 | #endif | |
ad6423a7 | 98 | |
b137522c IM |
99 | static bool compare_signature(const AcpiSdtTable *sdt, const char *signature) |
100 | { | |
101 | return !memcmp(sdt->aml, signature, 4); | |
102 | } | |
103 | ||
569afd84 IM |
104 | static void cleanup_table_descriptor(AcpiSdtTable *table) |
105 | { | |
106 | g_free(table->aml); | |
107 | if (table->aml_file && | |
108 | !table->tmp_files_retain && | |
109 | g_strstr_len(table->aml_file, -1, "aml-")) { | |
110 | unlink(table->aml_file); | |
111 | } | |
112 | g_free(table->aml_file); | |
113 | g_free(table->asl); | |
114 | if (table->asl_file && | |
115 | !table->tmp_files_retain) { | |
116 | unlink(table->asl_file); | |
117 | } | |
118 | g_free(table->asl_file); | |
119 | } | |
120 | ||
8ac2adf7 MA |
121 | static void free_test_data(test_data *data) |
122 | { | |
123 | int i; | |
124 | ||
a3a74ab9 | 125 | for (i = 0; i < data->tables->len; ++i) { |
569afd84 | 126 | cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i)); |
8ac2adf7 | 127 | } |
9e8458c0 | 128 | |
f11dc27b | 129 | g_array_free(data->tables, true); |
8ac2adf7 MA |
130 | } |
131 | ||
53333801 MA |
132 | static void test_acpi_rsdp_table(test_data *data) |
133 | { | |
9c041885 | 134 | uint8_t *rsdp_table = data->rsdp_table; |
53333801 | 135 | |
9c041885 | 136 | acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table); |
d6caf363 | 137 | |
9c041885 | 138 | switch (rsdp_table[15 /* Revision offset */]) { |
d6caf363 SO |
139 | case 0: /* ACPI 1.0 RSDP */ |
140 | /* With rev 1, checksum is only for the first 20 bytes */ | |
141 | g_assert(!acpi_calc_checksum(rsdp_table, 20)); | |
142 | break; | |
143 | case 2: /* ACPI 2.0+ RSDP */ | |
144 | /* With revision 2, we have 2 checksums */ | |
145 | g_assert(!acpi_calc_checksum(rsdp_table, 20)); | |
146 | g_assert(!acpi_calc_checksum(rsdp_table, 36)); | |
147 | break; | |
148 | default: | |
149 | g_assert_not_reached(); | |
150 | } | |
53333801 MA |
151 | } |
152 | ||
f2f616ce | 153 | static void test_acpi_rxsdt_table(test_data *data) |
53333801 | 154 | { |
f2f616ce | 155 | const char *sig = "RSDT"; |
569afd84 | 156 | AcpiSdtTable rsdt = {}; |
f2f616ce IM |
157 | int entry_size = 4; |
158 | int addr_off = 16 /* RsdtAddress */; | |
acee774b | 159 | uint8_t *ent; |
569afd84 | 160 | |
f2f616ce IM |
161 | if (data->rsdp_table[15 /* Revision offset */] != 0) { |
162 | addr_off = 24 /* XsdtAddress */; | |
163 | entry_size = 8; | |
164 | sig = "XSDT"; | |
165 | } | |
166 | /* read [RX]SDT table */ | |
acee774b | 167 | acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len, |
f2f616ce | 168 | &data->rsdp_table[addr_off], entry_size, sig, true); |
569afd84 IM |
169 | |
170 | /* Load all tables and add to test list directly RSDT referenced tables */ | |
f2f616ce | 171 | ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) { |
569afd84 IM |
172 | AcpiSdtTable ssdt_table = {}; |
173 | ||
acee774b | 174 | acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent, |
f2f616ce | 175 | entry_size, NULL, true); |
569afd84 IM |
176 | /* Add table to ASL test tables list */ |
177 | g_array_append_val(data->tables, ssdt_table); | |
178 | } | |
179 | cleanup_table_descriptor(&rsdt); | |
53333801 MA |
180 | } |
181 | ||
db575449 | 182 | static void test_acpi_fadt_table(test_data *data) |
53333801 | 183 | { |
db575449 | 184 | /* FADT table is 1st */ |
59f9c6cc IM |
185 | AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0); |
186 | uint8_t *fadt_aml = table.aml; | |
b997a04a | 187 | uint32_t fadt_len = table.aml_len; |
55089fa2 IM |
188 | uint32_t val; |
189 | int dsdt_offset = 40 /* DSDT */; | |
190 | int dsdt_entry_size = 4; | |
53333801 | 191 | |
b137522c | 192 | g_assert(compare_signature(&table, "FACP")); |
89d47c19 | 193 | |
59f9c6cc | 194 | /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */ |
40dfd0a8 IM |
195 | memcpy(&val, fadt_aml + 112 /* Flags */, 4); |
196 | val = le32_to_cpu(val); | |
197 | if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) { | |
198 | acpi_fetch_table(data->qts, &table.aml, &table.aml_len, | |
199 | fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false); | |
200 | g_array_append_val(data->tables, table); | |
201 | } | |
59f9c6cc | 202 | |
55089fa2 IM |
203 | memcpy(&val, fadt_aml + dsdt_offset, 4); |
204 | val = le32_to_cpu(val); | |
205 | if (!val) { | |
206 | dsdt_offset = 140 /* X_DSDT */; | |
207 | dsdt_entry_size = 8; | |
208 | } | |
acee774b | 209 | acpi_fetch_table(data->qts, &table.aml, &table.aml_len, |
55089fa2 | 210 | fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true); |
59f9c6cc | 211 | g_array_append_val(data->tables, table); |
92146b7a | 212 | |
b997a04a IM |
213 | memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */ |
214 | memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */ | |
215 | if (fadt_aml[8 /* FADT Major Version */] >= 3) { | |
216 | memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */ | |
217 | memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */ | |
92146b7a | 218 | } |
b997a04a IM |
219 | |
220 | /* update checksum */ | |
221 | fadt_aml[9 /* Checksum */] = 0; | |
222 | fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len); | |
92146b7a IM |
223 | } |
224 | ||
4500bc98 | 225 | static void dump_aml_files(test_data *data, bool rebuild) |
9e8458c0 MA |
226 | { |
227 | AcpiSdtTable *sdt; | |
228 | GError *error = NULL; | |
4500bc98 | 229 | gchar *aml_file = NULL; |
9e8458c0 MA |
230 | gint fd; |
231 | ssize_t ret; | |
232 | int i; | |
233 | ||
a3a74ab9 | 234 | for (i = 0; i < data->tables->len; ++i) { |
3a9c86df | 235 | const char *ext = data->variant ? data->variant : ""; |
a3a74ab9 | 236 | sdt = &g_array_index(data->tables, AcpiSdtTable, i); |
9e8458c0 MA |
237 | g_assert(sdt->aml); |
238 | ||
4500bc98 | 239 | if (rebuild) { |
3a9c86df | 240 | aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine, |
b137522c | 241 | sdt->aml, ext); |
4500bc98 MA |
242 | fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, |
243 | S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); | |
ba02ff90 IM |
244 | if (fd < 0) { |
245 | perror(aml_file); | |
246 | } | |
247 | g_assert(fd >= 0); | |
4500bc98 MA |
248 | } else { |
249 | fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error); | |
250 | g_assert_no_error(error); | |
251 | } | |
9e8458c0 | 252 | |
9e8458c0 MA |
253 | ret = qemu_write_full(fd, sdt->aml, sdt->aml_len); |
254 | g_assert(ret == sdt->aml_len); | |
255 | ||
256 | close(fd); | |
4500bc98 | 257 | |
ef1e1e07 | 258 | g_free(aml_file); |
9e8458c0 MA |
259 | } |
260 | } | |
261 | ||
15d914b1 | 262 | static bool load_asl(GArray *sdts, AcpiSdtTable *sdt) |
9e8458c0 MA |
263 | { |
264 | AcpiSdtTable *temp; | |
265 | GError *error = NULL; | |
cc8fa0e8 | 266 | GString *command_line = g_string_new(iasl); |
9e8458c0 MA |
267 | gint fd; |
268 | gchar *out, *out_err; | |
269 | gboolean ret; | |
270 | int i; | |
271 | ||
272 | fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error); | |
273 | g_assert_no_error(error); | |
274 | close(fd); | |
275 | ||
276 | /* build command line */ | |
cc8fa0e8 | 277 | g_string_append_printf(command_line, " -p %s ", sdt->asl_file); |
c225aa3c MT |
278 | if (compare_signature(sdt, "DSDT") || |
279 | compare_signature(sdt, "SSDT")) { | |
69d09245 MA |
280 | for (i = 0; i < sdts->len; ++i) { |
281 | temp = &g_array_index(sdts, AcpiSdtTable, i); | |
c225aa3c MT |
282 | if (compare_signature(temp, "DSDT") || |
283 | compare_signature(temp, "SSDT")) { | |
69d09245 MA |
284 | g_string_append_printf(command_line, "-e %s ", temp->aml_file); |
285 | } | |
286 | } | |
9e8458c0 MA |
287 | } |
288 | g_string_append_printf(command_line, "-d %s", sdt->aml_file); | |
289 | ||
290 | /* pass 'out' and 'out_err' in order to be redirected */ | |
15d914b1 | 291 | ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error); |
9e8458c0 | 292 | g_assert_no_error(error); |
15d914b1 | 293 | if (ret) { |
cc80b01a | 294 | ret = g_file_get_contents(sdt->asl_file, &sdt->asl, |
15d914b1 MA |
295 | &sdt->asl_len, &error); |
296 | g_assert(ret); | |
297 | g_assert_no_error(error); | |
dac23a6c | 298 | ret = (sdt->asl_len > 0); |
15d914b1 | 299 | } |
9e8458c0 MA |
300 | |
301 | g_free(out); | |
302 | g_free(out_err); | |
303 | g_string_free(command_line, true); | |
15d914b1 MA |
304 | |
305 | return !ret; | |
9e8458c0 MA |
306 | } |
307 | ||
308 | #define COMMENT_END "*/" | |
309 | #define DEF_BLOCK "DefinitionBlock (" | |
a3973f55 | 310 | #define BLOCK_NAME_END "," |
9e8458c0 MA |
311 | |
312 | static GString *normalize_asl(gchar *asl_code) | |
313 | { | |
314 | GString *asl = g_string_new(asl_code); | |
315 | gchar *comment, *block_name; | |
316 | ||
317 | /* strip comments (different generation days) */ | |
318 | comment = g_strstr_len(asl->str, asl->len, COMMENT_END); | |
319 | if (comment) { | |
cb348985 PB |
320 | comment += strlen(COMMENT_END); |
321 | while (*comment == '\n') { | |
322 | comment++; | |
323 | } | |
324 | asl = g_string_erase(asl, 0, comment - asl->str); | |
9e8458c0 MA |
325 | } |
326 | ||
327 | /* strip def block name (it has file path in it) */ | |
328 | if (g_str_has_prefix(asl->str, DEF_BLOCK)) { | |
329 | block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END); | |
330 | g_assert(block_name); | |
331 | asl = g_string_erase(asl, 0, | |
332 | block_name + sizeof(BLOCK_NAME_END) - asl->str); | |
333 | } | |
334 | ||
335 | return asl; | |
336 | } | |
337 | ||
338 | static GArray *load_expected_aml(test_data *data) | |
339 | { | |
340 | int i; | |
341 | AcpiSdtTable *sdt; | |
9e8458c0 MA |
342 | GError *error = NULL; |
343 | gboolean ret; | |
acee774b | 344 | gsize aml_len; |
9e8458c0 | 345 | |
a3a74ab9 | 346 | GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable)); |
fe17cca6 PMD |
347 | if (getenv("V")) { |
348 | fputc('\n', stderr); | |
349 | } | |
a3a74ab9 | 350 | for (i = 0; i < data->tables->len; ++i) { |
9e8458c0 | 351 | AcpiSdtTable exp_sdt; |
d19587db | 352 | gchar *aml_file = NULL; |
3a9c86df | 353 | const char *ext = data->variant ? data->variant : ""; |
c225aa3c | 354 | |
a3a74ab9 | 355 | sdt = &g_array_index(data->tables, AcpiSdtTable, i); |
9e8458c0 MA |
356 | |
357 | memset(&exp_sdt, 0, sizeof(exp_sdt)); | |
9e8458c0 | 358 | |
3a9c86df IM |
359 | try_again: |
360 | aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine, | |
b137522c | 361 | sdt->aml, ext); |
d19587db | 362 | if (getenv("V")) { |
fe17cca6 | 363 | fprintf(stderr, "Looking for expected file '%s'\n", aml_file); |
d19587db IM |
364 | } |
365 | if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) { | |
366 | exp_sdt.aml_file = aml_file; | |
367 | } else if (*ext != '\0') { | |
e50a6121 | 368 | /* try fallback to generic (extension less) expected file */ |
3a9c86df | 369 | ext = ""; |
d19587db | 370 | g_free(aml_file); |
3a9c86df IM |
371 | goto try_again; |
372 | } | |
d19587db IM |
373 | g_assert(exp_sdt.aml_file); |
374 | if (getenv("V")) { | |
fe17cca6 | 375 | fprintf(stderr, "Using expected file '%s'\n", aml_file); |
d19587db | 376 | } |
81eb530d | 377 | ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml, |
acee774b IM |
378 | &aml_len, &error); |
379 | exp_sdt.aml_len = aml_len; | |
9e8458c0 MA |
380 | g_assert(ret); |
381 | g_assert_no_error(error); | |
382 | g_assert(exp_sdt.aml); | |
4eb74c4f MT |
383 | if (!exp_sdt.aml_len) { |
384 | fprintf(stderr, "Warning! zero length expected file '%s'\n", | |
385 | aml_file); | |
386 | } | |
9e8458c0 | 387 | |
a3a74ab9 | 388 | g_array_append_val(exp_tables, exp_sdt); |
9e8458c0 MA |
389 | } |
390 | ||
a3a74ab9 | 391 | return exp_tables; |
9e8458c0 MA |
392 | } |
393 | ||
ab50f223 MT |
394 | static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt) |
395 | { | |
396 | const gchar *allowed_diff_file[] = { | |
397 | #include "bios-tables-test-allowed-diff.h" | |
398 | NULL | |
399 | }; | |
400 | const gchar **f; | |
401 | ||
402 | for (f = allowed_diff_file; *f; ++f) { | |
403 | if (!g_strcmp0(sdt->aml_file, *f)) { | |
404 | return true; | |
405 | } | |
406 | } | |
407 | return false; | |
408 | } | |
409 | ||
ab20bbd2 | 410 | /* test the list of tables in @data->tables against reference tables */ |
9e8458c0 MA |
411 | static void test_acpi_asl(test_data *data) |
412 | { | |
413 | int i; | |
414 | AcpiSdtTable *sdt, *exp_sdt; | |
415 | test_data exp_data; | |
df7cafde | 416 | gboolean exp_err, err, all_tables_match = true; |
9e8458c0 MA |
417 | |
418 | memset(&exp_data, 0, sizeof(exp_data)); | |
a3a74ab9 | 419 | exp_data.tables = load_expected_aml(data); |
4500bc98 | 420 | dump_aml_files(data, false); |
a3a74ab9 | 421 | for (i = 0; i < data->tables->len; ++i) { |
9e8458c0 MA |
422 | GString *asl, *exp_asl; |
423 | ||
a3a74ab9 MA |
424 | sdt = &g_array_index(data->tables, AcpiSdtTable, i); |
425 | exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i); | |
9e8458c0 | 426 | |
7f36f093 MT |
427 | if (sdt->aml_len == exp_sdt->aml_len && |
428 | !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) { | |
429 | /* Identical table binaries: no need to disassemble. */ | |
430 | continue; | |
431 | } | |
432 | ||
433 | fprintf(stderr, | |
434 | "acpi-test: Warning! %.4s binary file mismatch. " | |
a7b4384f MT |
435 | "Actual [aml:%s], Expected [aml:%s].\n" |
436 | "See source file tests/qtest/bios-tables-test.c " | |
437 | "for instructions on how to update expected files.\n", | |
7f36f093 MT |
438 | exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file); |
439 | ||
440 | all_tables_match = all_tables_match && | |
441 | test_acpi_find_diff_allowed(exp_sdt); | |
442 | ||
7b9829bc IM |
443 | /* |
444 | * don't try to decompile if IASL isn't present, in this case user | |
445 | * will just 'get binary file mismatch' warnings and test failure | |
446 | */ | |
447 | if (!iasl) { | |
448 | continue; | |
449 | } | |
450 | ||
15d914b1 | 451 | err = load_asl(data->tables, sdt); |
9e8458c0 MA |
452 | asl = normalize_asl(sdt->asl); |
453 | ||
15d914b1 | 454 | exp_err = load_asl(exp_data.tables, exp_sdt); |
9e8458c0 MA |
455 | exp_asl = normalize_asl(exp_sdt->asl); |
456 | ||
15d914b1 MA |
457 | /* TODO: check for warnings */ |
458 | g_assert(!err || exp_err); | |
459 | ||
0651596c | 460 | if (g_strcmp0(asl->str, exp_asl->str)) { |
6c77aa90 | 461 | sdt->tmp_files_retain = true; |
dac23a6c MA |
462 | if (exp_err) { |
463 | fprintf(stderr, | |
464 | "Warning! iasl couldn't parse the expected aml\n"); | |
465 | } else { | |
dac23a6c MA |
466 | exp_sdt->tmp_files_retain = true; |
467 | fprintf(stderr, | |
468 | "acpi-test: Warning! %.4s mismatch. " | |
469 | "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n", | |
b137522c | 470 | exp_sdt->aml, sdt->asl_file, sdt->aml_file, |
dac23a6c | 471 | exp_sdt->asl_file, exp_sdt->aml_file); |
c01e905f | 472 | fflush(stderr); |
7cb08cb2 | 473 | if (getenv("V")) { |
34b1429c | 474 | const char *diff_env = getenv("DIFF"); |
b20fdf2c | 475 | const char *diff_cmd = diff_env ? diff_env : "diff -U 16"; |
34b1429c MT |
476 | char *diff = g_strdup_printf("%s %s %s", diff_cmd, |
477 | exp_sdt->asl_file, sdt->asl_file); | |
478 | int out = dup(STDOUT_FILENO); | |
479 | int ret G_GNUC_UNUSED; | |
480 | ||
481 | dup2(STDERR_FILENO, STDOUT_FILENO); | |
482 | ret = system(diff) ; | |
483 | dup2(out, STDOUT_FILENO); | |
484 | close(out); | |
485 | g_free(diff); | |
7cb08cb2 | 486 | } |
ab50f223 | 487 | } |
0651596c | 488 | } |
9e8458c0 MA |
489 | g_string_free(asl, true); |
490 | g_string_free(exp_asl, true); | |
491 | } | |
7b9829bc IM |
492 | if (!iasl && !all_tables_match) { |
493 | fprintf(stderr, "to see ASL diff between mismatched files install IASL," | |
494 | " rebuild QEMU from scratch and re-run tests with V=1" | |
495 | " environment variable set"); | |
496 | } | |
df7cafde | 497 | g_assert(all_tables_match); |
9e8458c0 MA |
498 | |
499 | free_test_data(&exp_data); | |
53333801 MA |
500 | } |
501 | ||
5efed5a1 | 502 | static bool smbios_ep_table_ok(test_data *data) |
eb386aac | 503 | { |
86299120 | 504 | struct smbios_21_entry_point *ep_table = &data->smbios_ep_table; |
eb386aac GS |
505 | uint32_t addr = data->smbios_ep_addr; |
506 | ||
3314778d | 507 | qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table)); |
5efed5a1 GS |
508 | if (memcmp(ep_table->anchor_string, "_SM_", 4)) { |
509 | return false; | |
510 | } | |
5efed5a1 GS |
511 | if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) { |
512 | return false; | |
513 | } | |
5efed5a1 GS |
514 | if (ep_table->structure_table_length == 0) { |
515 | return false; | |
516 | } | |
5efed5a1 GS |
517 | if (ep_table->number_of_structures == 0) { |
518 | return false; | |
519 | } | |
3248f1b4 BW |
520 | if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) || |
521 | acpi_calc_checksum((uint8_t *)ep_table + 0x10, | |
522 | sizeof *ep_table - 0x10)) { | |
5efed5a1 GS |
523 | return false; |
524 | } | |
525 | return true; | |
526 | } | |
527 | ||
528 | static void test_smbios_entry_point(test_data *data) | |
529 | { | |
530 | uint32_t off; | |
531 | ||
532 | /* find smbios entry point structure */ | |
533 | for (off = 0xf0000; off < 0x100000; off += 0x10) { | |
534 | uint8_t sig[] = "_SM_"; | |
535 | int i; | |
536 | ||
537 | for (i = 0; i < sizeof sig - 1; ++i) { | |
273e3d92 | 538 | sig[i] = qtest_readb(data->qts, off + i); |
5efed5a1 GS |
539 | } |
540 | ||
541 | if (!memcmp(sig, "_SM_", sizeof sig)) { | |
542 | /* signature match, but is this a valid entry point? */ | |
543 | data->smbios_ep_addr = off; | |
544 | if (smbios_ep_table_ok(data)) { | |
545 | break; | |
546 | } | |
547 | } | |
548 | } | |
549 | ||
550 | g_assert_cmphex(off, <, 0x100000); | |
eb386aac GS |
551 | } |
552 | ||
553 | static inline bool smbios_single_instance(uint8_t type) | |
554 | { | |
555 | switch (type) { | |
556 | case 0: | |
557 | case 1: | |
558 | case 2: | |
559 | case 3: | |
560 | case 16: | |
561 | case 32: | |
562 | case 127: | |
563 | return true; | |
564 | default: | |
565 | return false; | |
566 | } | |
567 | } | |
568 | ||
e1647539 YF |
569 | static bool smbios_cpu_test(test_data *data, uint32_t addr) |
570 | { | |
571 | uint16_t expect_speed[2]; | |
572 | uint16_t real; | |
573 | int offset[2]; | |
574 | int i; | |
575 | ||
576 | /* Check CPU speed for backward compatibility */ | |
577 | offset[0] = offsetof(struct smbios_type_4, max_speed); | |
578 | offset[1] = offsetof(struct smbios_type_4, current_speed); | |
579 | expect_speed[0] = data->smbios_cpu_max_speed ? : 2000; | |
580 | expect_speed[1] = data->smbios_cpu_curr_speed ? : 2000; | |
581 | ||
582 | for (i = 0; i < 2; i++) { | |
583 | real = qtest_readw(data->qts, addr + offset[i]); | |
584 | if (real != expect_speed[i]) { | |
585 | fprintf(stderr, "Unexpected SMBIOS CPU speed: real %u expect %u\n", | |
586 | real, expect_speed[i]); | |
587 | return false; | |
588 | } | |
589 | } | |
590 | ||
591 | return true; | |
592 | } | |
593 | ||
eb386aac GS |
594 | static void test_smbios_structs(test_data *data) |
595 | { | |
596 | DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 }; | |
86299120 | 597 | struct smbios_21_entry_point *ep_table = &data->smbios_ep_table; |
3831c07b | 598 | uint32_t addr = le32_to_cpu(ep_table->structure_table_address); |
eb386aac GS |
599 | int i, len, max_len = 0; |
600 | uint8_t type, prv, crt; | |
eb386aac GS |
601 | |
602 | /* walk the smbios tables */ | |
3831c07b | 603 | for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) { |
eb386aac GS |
604 | |
605 | /* grab type and formatted area length from struct header */ | |
273e3d92 | 606 | type = qtest_readb(data->qts, addr); |
eb386aac | 607 | g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE); |
273e3d92 | 608 | len = qtest_readb(data->qts, addr + 1); |
eb386aac GS |
609 | |
610 | /* single-instance structs must not have been encountered before */ | |
611 | if (smbios_single_instance(type)) { | |
612 | g_assert(!test_bit(type, struct_bitmap)); | |
613 | } | |
614 | set_bit(type, struct_bitmap); | |
615 | ||
e1647539 YF |
616 | if (type == 4) { |
617 | g_assert(smbios_cpu_test(data, addr)); | |
618 | } | |
619 | ||
eb386aac GS |
620 | /* seek to end of unformatted string area of this struct ("\0\0") */ |
621 | prv = crt = 1; | |
622 | while (prv || crt) { | |
623 | prv = crt; | |
273e3d92 | 624 | crt = qtest_readb(data->qts, addr + len); |
eb386aac GS |
625 | len++; |
626 | } | |
627 | ||
628 | /* keep track of max. struct size */ | |
629 | if (max_len < len) { | |
630 | max_len = len; | |
631 | g_assert_cmpuint(max_len, <=, ep_table->max_structure_size); | |
632 | } | |
633 | ||
634 | /* start of next structure */ | |
635 | addr += len; | |
636 | } | |
637 | ||
638 | /* total table length and max struct size must match entry point values */ | |
3831c07b TH |
639 | g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==, |
640 | addr - le32_to_cpu(ep_table->structure_table_address)); | |
641 | g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len); | |
eb386aac GS |
642 | |
643 | /* required struct types must all be present */ | |
f4eda2d4 CM |
644 | for (i = 0; i < data->required_struct_types_len; i++) { |
645 | g_assert(test_bit(data->required_struct_types[i], struct_bitmap)); | |
eb386aac GS |
646 | } |
647 | } | |
648 | ||
8ac2adf7 | 649 | static void test_acpi_one(const char *params, test_data *data) |
ad6423a7 MT |
650 | { |
651 | char *args; | |
97256e79 IM |
652 | bool use_uefi = data->uefi_fl1 && data->uefi_fl2; |
653 | ||
654 | if (use_uefi) { | |
655 | /* | |
656 | * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3) | |
657 | * when arm/virt boad starts to support it. | |
658 | */ | |
6f6e1698 | 659 | args = g_strdup_printf("-machine %s %s -accel tcg -nodefaults -nographic " |
97256e79 IM |
660 | "-drive if=pflash,format=raw,file=%s,readonly " |
661 | "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s", | |
6f6e1698 | 662 | data->machine, data->tcg_only ? "" : "-accel kvm", |
3dc01874 | 663 | data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : ""); |
97256e79 IM |
664 | |
665 | } else { | |
d1e2d464 | 666 | args = g_strdup_printf("-machine %s %s -accel tcg " |
97256e79 IM |
667 | "-net none -display none %s " |
668 | "-drive id=hd0,if=none,file=%s,format=raw " | |
3cac3784 | 669 | "-device %s,drive=hd0 ", |
6f6e1698 | 670 | data->machine, data->tcg_only ? "" : "-accel kvm", |
3cac3784 GH |
671 | params ? params : "", disk, |
672 | data->blkdev ?: "ide-hd"); | |
97256e79 | 673 | } |
9e8458c0 | 674 | |
273e3d92 | 675 | data->qts = qtest_init(args); |
ad6423a7 | 676 | |
97256e79 IM |
677 | if (use_uefi) { |
678 | g_assert(data->scan_len); | |
679 | data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts, | |
680 | data->ram_start, data->scan_len); | |
681 | } else { | |
682 | boot_sector_test(data->qts); | |
683 | data->rsdp_addr = acpi_find_rsdp_address(data->qts); | |
684 | g_assert_cmphex(data->rsdp_addr, <, 0x100000); | |
685 | } | |
ad6423a7 | 686 | |
b24b9d94 | 687 | data->tables = g_array_new(false, true, sizeof(AcpiSdtTable)); |
8ac2adf7 | 688 | test_acpi_rsdp_table(data); |
f2f616ce | 689 | test_acpi_rxsdt_table(data); |
db575449 | 690 | test_acpi_fadt_table(data); |
ad6423a7 | 691 | |
ab31b337 IM |
692 | if (getenv(ACPI_REBUILD_EXPECTED_AML)) { |
693 | dump_aml_files(data, true); | |
7b9829bc | 694 | } else { |
ab31b337 | 695 | test_acpi_asl(data); |
9e8458c0 MA |
696 | } |
697 | ||
ce513b46 IM |
698 | /* |
699 | * TODO: make SMBIOS tests work with UEFI firmware, | |
700 | * Bug on uefi-test-tools to provide entry point: | |
701 | * https://bugs.launchpad.net/qemu/+bug/1821884 | |
702 | */ | |
703 | if (!use_uefi) { | |
704 | test_smbios_entry_point(data); | |
705 | test_smbios_structs(data); | |
706 | } | |
eb386aac | 707 | |
273e3d92 | 708 | qtest_quit(data->qts); |
ad6423a7 MT |
709 | g_free(args); |
710 | } | |
711 | ||
f4eda2d4 CM |
712 | static uint8_t base_required_struct_types[] = { |
713 | 0, 1, 3, 4, 16, 17, 19, 32, 127 | |
714 | }; | |
715 | ||
71f4be25 | 716 | static void test_acpi_piix4_tcg(void) |
ad6423a7 | 717 | { |
8ac2adf7 MA |
718 | test_data data; |
719 | ||
ad6423a7 MT |
720 | /* Supplying -machine accel argument overrides the default (qtest). |
721 | * This is to make guest actually run. | |
722 | */ | |
9e8458c0 MA |
723 | memset(&data, 0, sizeof(data)); |
724 | data.machine = MACHINE_PC; | |
f4eda2d4 CM |
725 | data.required_struct_types = base_required_struct_types; |
726 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 727 | test_acpi_one(NULL, &data); |
9e8458c0 | 728 | free_test_data(&data); |
71f4be25 PB |
729 | } |
730 | ||
3a9c86df IM |
731 | static void test_acpi_piix4_tcg_bridge(void) |
732 | { | |
733 | test_data data; | |
734 | ||
735 | memset(&data, 0, sizeof(data)); | |
736 | data.machine = MACHINE_PC; | |
737 | data.variant = ".bridge"; | |
f4eda2d4 CM |
738 | data.required_struct_types = base_required_struct_types; |
739 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 740 | test_acpi_one("-device pci-bridge,chassis_nr=1", &data); |
3a9c86df IM |
741 | free_test_data(&data); |
742 | } | |
743 | ||
27476395 AS |
744 | static void test_acpi_piix4_no_root_hotplug(void) |
745 | { | |
746 | test_data data; | |
747 | ||
748 | memset(&data, 0, sizeof(data)); | |
749 | data.machine = MACHINE_PC; | |
750 | data.variant = ".roothp"; | |
751 | data.required_struct_types = base_required_struct_types; | |
752 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
753 | test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off " | |
754 | "-device pci-bridge,chassis_nr=1", &data); | |
755 | free_test_data(&data); | |
756 | } | |
757 | ||
5e3a4862 AS |
758 | static void test_acpi_piix4_no_bridge_hotplug(void) |
759 | { | |
760 | test_data data; | |
761 | ||
762 | memset(&data, 0, sizeof(data)); | |
763 | data.machine = MACHINE_PC; | |
764 | data.variant = ".hpbridge"; | |
765 | data.required_struct_types = base_required_struct_types; | |
766 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
767 | test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off " | |
768 | "-device pci-bridge,chassis_nr=1", &data); | |
769 | free_test_data(&data); | |
770 | } | |
771 | ||
5645f996 AS |
772 | static void test_acpi_piix4_no_acpi_pci_hotplug(void) |
773 | { | |
774 | test_data data; | |
775 | ||
776 | memset(&data, 0, sizeof(data)); | |
777 | data.machine = MACHINE_PC; | |
778 | data.variant = ".hpbrroot"; | |
779 | data.required_struct_types = base_required_struct_types; | |
780 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
781 | test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off " | |
782 | "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off " | |
783 | "-device pci-bridge,chassis_nr=1", &data); | |
784 | free_test_data(&data); | |
785 | } | |
786 | ||
71f4be25 PB |
787 | static void test_acpi_q35_tcg(void) |
788 | { | |
789 | test_data data; | |
8ac2adf7 | 790 | |
9e8458c0 MA |
791 | memset(&data, 0, sizeof(data)); |
792 | data.machine = MACHINE_Q35; | |
f4eda2d4 CM |
793 | data.required_struct_types = base_required_struct_types; |
794 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 795 | test_acpi_one(NULL, &data); |
8ac2adf7 | 796 | free_test_data(&data); |
e1647539 YF |
797 | |
798 | data.smbios_cpu_max_speed = 3000; | |
799 | data.smbios_cpu_curr_speed = 2600; | |
800 | test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data); | |
801 | free_test_data(&data); | |
ad6423a7 MT |
802 | } |
803 | ||
3a9c86df IM |
804 | static void test_acpi_q35_tcg_bridge(void) |
805 | { | |
806 | test_data data; | |
807 | ||
808 | memset(&data, 0, sizeof(data)); | |
809 | data.machine = MACHINE_Q35; | |
810 | data.variant = ".bridge"; | |
f4eda2d4 CM |
811 | data.required_struct_types = base_required_struct_types; |
812 | data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); | |
947b205f | 813 | test_acpi_one("-device pci-bridge,chassis_nr=1", |
3a9c86df IM |
814 | &data); |
815 | free_test_data(&data); | |
816 | } | |
817 | ||
0259e966 LE |
818 | static void test_acpi_q35_tcg_mmio64(void) |
819 | { | |
820 | test_data data = { | |
821 | .machine = MACHINE_Q35, | |
822 | .variant = ".mmio64", | |
823 | .required_struct_types = base_required_struct_types, | |
824 | .required_struct_types_len = ARRAY_SIZE(base_required_struct_types) | |
825 | }; | |
826 | ||
827 | test_acpi_one("-m 128M,slots=1,maxmem=2G " | |
af135030 IM |
828 | "-object memory-backend-ram,id=ram0,size=128M " |
829 | "-numa node,memdev=ram0 " | |
0259e966 LE |
830 | "-device pci-testdev,membar=2G", |
831 | &data); | |
832 | free_test_data(&data); | |
833 | } | |
834 | ||
6b9c1dd2 IM |
835 | static void test_acpi_piix4_tcg_cphp(void) |
836 | { | |
837 | test_data data; | |
838 | ||
839 | memset(&data, 0, sizeof(data)); | |
840 | data.machine = MACHINE_PC; | |
841 | data.variant = ".cphp"; | |
d6309c17 | 842 | test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6" |
af135030 IM |
843 | " -object memory-backend-ram,id=ram0,size=64M" |
844 | " -object memory-backend-ram,id=ram1,size=64M" | |
845 | " -numa node,memdev=ram0 -numa node,memdev=ram1" | |
fda4096f | 846 | " -numa dist,src=0,dst=1,val=21", |
6b9c1dd2 IM |
847 | &data); |
848 | free_test_data(&data); | |
849 | } | |
850 | ||
851 | static void test_acpi_q35_tcg_cphp(void) | |
852 | { | |
853 | test_data data; | |
854 | ||
855 | memset(&data, 0, sizeof(data)); | |
856 | data.machine = MACHINE_Q35; | |
857 | data.variant = ".cphp"; | |
d6309c17 | 858 | test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6" |
af135030 IM |
859 | " -object memory-backend-ram,id=ram0,size=64M" |
860 | " -object memory-backend-ram,id=ram1,size=64M" | |
861 | " -numa node,memdev=ram0 -numa node,memdev=ram1" | |
fda4096f | 862 | " -numa dist,src=0,dst=1,val=21", |
6b9c1dd2 IM |
863 | &data); |
864 | free_test_data(&data); | |
865 | } | |
866 | ||
f4eda2d4 CM |
867 | static uint8_t ipmi_required_struct_types[] = { |
868 | 0, 1, 3, 4, 16, 17, 19, 32, 38, 127 | |
869 | }; | |
870 | ||
871 | static void test_acpi_q35_tcg_ipmi(void) | |
872 | { | |
873 | test_data data; | |
874 | ||
875 | memset(&data, 0, sizeof(data)); | |
876 | data.machine = MACHINE_Q35; | |
877 | data.variant = ".ipmibt"; | |
878 | data.required_struct_types = ipmi_required_struct_types; | |
879 | data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types); | |
947b205f | 880 | test_acpi_one("-device ipmi-bmc-sim,id=bmc0" |
f4eda2d4 CM |
881 | " -device isa-ipmi-bt,bmc=bmc0", |
882 | &data); | |
883 | free_test_data(&data); | |
884 | } | |
885 | ||
886 | static void test_acpi_piix4_tcg_ipmi(void) | |
887 | { | |
888 | test_data data; | |
889 | ||
890 | /* Supplying -machine accel argument overrides the default (qtest). | |
891 | * This is to make guest actually run. | |
892 | */ | |
893 | memset(&data, 0, sizeof(data)); | |
894 | data.machine = MACHINE_PC; | |
895 | data.variant = ".ipmikcs"; | |
896 | data.required_struct_types = ipmi_required_struct_types; | |
897 | data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types); | |
947b205f | 898 | test_acpi_one("-device ipmi-bmc-sim,id=bmc0" |
f4eda2d4 CM |
899 | " -device isa-ipmi-kcs,irq=0,bmc=bmc0", |
900 | &data); | |
901 | free_test_data(&data); | |
902 | } | |
903 | ||
4462fc60 IM |
904 | static void test_acpi_q35_tcg_memhp(void) |
905 | { | |
906 | test_data data; | |
907 | ||
908 | memset(&data, 0, sizeof(data)); | |
909 | data.machine = MACHINE_Q35; | |
910 | data.variant = ".memhp"; | |
fda4096f | 911 | test_acpi_one(" -m 128,slots=3,maxmem=1G" |
af135030 IM |
912 | " -object memory-backend-ram,id=ram0,size=64M" |
913 | " -object memory-backend-ram,id=ram1,size=64M" | |
914 | " -numa node,memdev=ram0 -numa node,memdev=ram1" | |
fda4096f HC |
915 | " -numa dist,src=0,dst=1,val=21", |
916 | &data); | |
4462fc60 IM |
917 | free_test_data(&data); |
918 | } | |
919 | ||
920 | static void test_acpi_piix4_tcg_memhp(void) | |
921 | { | |
922 | test_data data; | |
923 | ||
924 | memset(&data, 0, sizeof(data)); | |
925 | data.machine = MACHINE_PC; | |
926 | data.variant = ".memhp"; | |
fda4096f | 927 | test_acpi_one(" -m 128,slots=3,maxmem=1G" |
af135030 IM |
928 | " -object memory-backend-ram,id=ram0,size=64M" |
929 | " -object memory-backend-ram,id=ram1,size=64M" | |
930 | " -numa node,memdev=ram0 -numa node,memdev=ram1" | |
fda4096f HC |
931 | " -numa dist,src=0,dst=1,val=21", |
932 | &data); | |
4462fc60 IM |
933 | free_test_data(&data); |
934 | } | |
935 | ||
d82c4f82 DL |
936 | static void test_acpi_q35_tcg_numamem(void) |
937 | { | |
938 | test_data data; | |
939 | ||
940 | memset(&data, 0, sizeof(data)); | |
941 | data.machine = MACHINE_Q35; | |
942 | data.variant = ".numamem"; | |
af135030 IM |
943 | test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M" |
944 | " -numa node -numa node,memdev=ram0", &data); | |
d82c4f82 DL |
945 | free_test_data(&data); |
946 | } | |
947 | ||
948 | static void test_acpi_piix4_tcg_numamem(void) | |
949 | { | |
950 | test_data data; | |
951 | ||
952 | memset(&data, 0, sizeof(data)); | |
953 | data.machine = MACHINE_PC; | |
954 | data.variant = ".numamem"; | |
af135030 IM |
955 | test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M" |
956 | " -numa node -numa node,memdev=ram0", &data); | |
d82c4f82 DL |
957 | free_test_data(&data); |
958 | } | |
959 | ||
5da7c35e EA |
960 | uint64_t tpm_tis_base_addr; |
961 | ||
962 | static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if, | |
963 | uint64_t base) | |
964 | { | |
55b9757c | 965 | #ifdef CONFIG_TPM |
5da7c35e EA |
966 | gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX", |
967 | machine, tpm_if); | |
968 | char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL); | |
969 | TestState test; | |
970 | test_data data; | |
971 | GThread *thread; | |
972 | char *args, *variant = g_strdup_printf(".%s", tpm_if); | |
973 | ||
974 | tpm_tis_base_addr = base; | |
975 | ||
976 | module_call_init(MODULE_INIT_QOM); | |
977 | ||
978 | test.addr = g_new0(SocketAddress, 1); | |
979 | test.addr->type = SOCKET_ADDRESS_TYPE_UNIX; | |
980 | test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL); | |
981 | g_mutex_init(&test.data_mutex); | |
982 | g_cond_init(&test.data_cond); | |
983 | test.data_cond_signal = false; | |
984 | ||
985 | thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test); | |
986 | tpm_emu_test_wait_cond(&test); | |
987 | ||
988 | memset(&data, 0, sizeof(data)); | |
989 | data.machine = machine; | |
990 | data.variant = variant; | |
991 | ||
992 | args = g_strdup_printf( | |
993 | " -chardev socket,id=chr,path=%s" | |
994 | " -tpmdev emulator,id=dev,chardev=chr" | |
995 | " -device tpm-%s,tpmdev=dev", | |
996 | test.addr->u.q_unix.path, tpm_if); | |
997 | ||
998 | test_acpi_one(args, &data); | |
999 | ||
1000 | g_thread_join(thread); | |
1001 | g_unlink(test.addr->u.q_unix.path); | |
1002 | qapi_free_SocketAddress(test.addr); | |
1003 | g_rmdir(tmp_path); | |
1004 | g_free(variant); | |
1005 | g_free(tmp_path); | |
1006 | g_free(tmp_dir_name); | |
82e258db | 1007 | g_free(args); |
5da7c35e | 1008 | free_test_data(&data); |
55b9757c EA |
1009 | #else |
1010 | g_test_skip("TPM disabled"); | |
1011 | #endif | |
5da7c35e EA |
1012 | } |
1013 | ||
1014 | static void test_acpi_q35_tcg_tpm_tis(void) | |
1015 | { | |
1016 | test_acpi_tcg_tpm("q35", "tis", 0xFED40000); | |
1017 | } | |
1018 | ||
adae91ce HZ |
1019 | static void test_acpi_tcg_dimm_pxm(const char *machine) |
1020 | { | |
1021 | test_data data; | |
1022 | ||
1023 | memset(&data, 0, sizeof(data)); | |
1024 | data.machine = machine; | |
1025 | data.variant = ".dimmpxm"; | |
11c39b5c | 1026 | test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu" |
adae91ce HZ |
1027 | " -smp 4,sockets=4" |
1028 | " -m 128M,slots=3,maxmem=1G" | |
af135030 IM |
1029 | " -object memory-backend-ram,id=ram0,size=32M" |
1030 | " -object memory-backend-ram,id=ram1,size=32M" | |
1031 | " -object memory-backend-ram,id=ram2,size=32M" | |
1032 | " -object memory-backend-ram,id=ram3,size=32M" | |
1033 | " -numa node,memdev=ram0,nodeid=0" | |
1034 | " -numa node,memdev=ram1,nodeid=1" | |
1035 | " -numa node,memdev=ram2,nodeid=2" | |
1036 | " -numa node,memdev=ram3,nodeid=3" | |
adae91ce HZ |
1037 | " -numa cpu,node-id=0,socket-id=0" |
1038 | " -numa cpu,node-id=1,socket-id=1" | |
1039 | " -numa cpu,node-id=2,socket-id=2" | |
1040 | " -numa cpu,node-id=3,socket-id=3" | |
af135030 | 1041 | " -object memory-backend-ram,id=ram4,size=128M" |
adae91ce | 1042 | " -object memory-backend-ram,id=nvm0,size=128M" |
af135030 | 1043 | " -device pc-dimm,id=dimm0,memdev=ram4,node=1" |
adae91ce HZ |
1044 | " -device nvdimm,id=dimm1,memdev=nvm0,node=2", |
1045 | &data); | |
1046 | free_test_data(&data); | |
1047 | } | |
1048 | ||
1049 | static void test_acpi_q35_tcg_dimm_pxm(void) | |
1050 | { | |
1051 | test_acpi_tcg_dimm_pxm(MACHINE_Q35); | |
1052 | } | |
1053 | ||
1054 | static void test_acpi_piix4_tcg_dimm_pxm(void) | |
1055 | { | |
1056 | test_acpi_tcg_dimm_pxm(MACHINE_PC); | |
1057 | } | |
1058 | ||
669c7743 SK |
1059 | static void test_acpi_virt_tcg_memhp(void) |
1060 | { | |
1061 | test_data data = { | |
1062 | .machine = "virt", | |
6f6e1698 | 1063 | .tcg_only = true, |
669c7743 SK |
1064 | .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", |
1065 | .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", | |
1066 | .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", | |
1067 | .ram_start = 0x40000000ULL, | |
1068 | .scan_len = 256ULL * 1024 * 1024, | |
1069 | }; | |
1070 | ||
1071 | data.variant = ".memhp"; | |
62293b4f SK |
1072 | test_acpi_one(" -machine nvdimm=on" |
1073 | " -cpu cortex-a57" | |
669c7743 SK |
1074 | " -m 256M,slots=3,maxmem=1G" |
1075 | " -object memory-backend-ram,id=ram0,size=128M" | |
1076 | " -object memory-backend-ram,id=ram1,size=128M" | |
1077 | " -numa node,memdev=ram0 -numa node,memdev=ram1" | |
62293b4f SK |
1078 | " -numa dist,src=0,dst=1,val=21" |
1079 | " -object memory-backend-ram,id=ram2,size=128M" | |
1080 | " -object memory-backend-ram,id=nvm0,size=128M" | |
1081 | " -device pc-dimm,id=dimm0,memdev=ram2,node=0" | |
1082 | " -device nvdimm,id=dimm1,memdev=nvm0,node=1", | |
669c7743 SK |
1083 | &data); |
1084 | ||
1085 | free_test_data(&data); | |
1086 | ||
1087 | } | |
1088 | ||
62b61b85 GH |
1089 | static void test_acpi_microvm_prepare(test_data *data) |
1090 | { | |
1091 | memset(data, 0, sizeof(*data)); | |
1092 | data->machine = "microvm"; | |
1093 | data->required_struct_types = NULL; /* no smbios */ | |
1094 | data->required_struct_types_len = 0; | |
1095 | data->blkdev = "virtio-blk-device"; | |
1096 | } | |
1097 | ||
c06cbf3d GH |
1098 | static void test_acpi_microvm_tcg(void) |
1099 | { | |
1100 | test_data data; | |
1101 | ||
62b61b85 | 1102 | test_acpi_microvm_prepare(&data); |
c06cbf3d GH |
1103 | test_acpi_one(" -machine microvm,acpi=on,rtc=off", |
1104 | &data); | |
1105 | free_test_data(&data); | |
1106 | } | |
1107 | ||
18bb73b3 GH |
1108 | static void test_acpi_microvm_pcie_tcg(void) |
1109 | { | |
1110 | test_data data; | |
1111 | ||
1112 | test_acpi_microvm_prepare(&data); | |
1113 | data.variant = ".pcie"; | |
1114 | data.tcg_only = true; /* need constant host-phys-bits */ | |
1115 | test_acpi_one(" -machine microvm,acpi=on,rtc=off,pcie=on", | |
1116 | &data); | |
1117 | free_test_data(&data); | |
1118 | } | |
1119 | ||
669c7743 SK |
1120 | static void test_acpi_virt_tcg_numamem(void) |
1121 | { | |
1122 | test_data data = { | |
1123 | .machine = "virt", | |
6f6e1698 | 1124 | .tcg_only = true, |
669c7743 SK |
1125 | .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", |
1126 | .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", | |
1127 | .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", | |
1128 | .ram_start = 0x40000000ULL, | |
1129 | .scan_len = 128ULL * 1024 * 1024, | |
1130 | }; | |
1131 | ||
1132 | data.variant = ".numamem"; | |
1133 | test_acpi_one(" -cpu cortex-a57" | |
1134 | " -object memory-backend-ram,id=ram0,size=128M" | |
1135 | " -numa node,memdev=ram0", | |
1136 | &data); | |
1137 | ||
1138 | free_test_data(&data); | |
1139 | ||
1140 | } | |
1141 | ||
1c8f85d9 TX |
1142 | static void test_acpi_tcg_acpi_hmat(const char *machine) |
1143 | { | |
1144 | test_data data; | |
1145 | ||
1146 | memset(&data, 0, sizeof(data)); | |
1147 | data.machine = machine; | |
1148 | data.variant = ".acpihmat"; | |
1149 | test_acpi_one(" -machine hmat=on" | |
1150 | " -smp 2,sockets=2" | |
1151 | " -m 128M,slots=2,maxmem=1G" | |
1152 | " -object memory-backend-ram,size=64M,id=m0" | |
1153 | " -object memory-backend-ram,size=64M,id=m1" | |
1154 | " -numa node,nodeid=0,memdev=m0" | |
1155 | " -numa node,nodeid=1,memdev=m1,initiator=0" | |
1156 | " -numa cpu,node-id=0,socket-id=0" | |
1157 | " -numa cpu,node-id=0,socket-id=1" | |
1158 | " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," | |
1159 | "data-type=access-latency,latency=1" | |
1160 | " -numa hmat-lb,initiator=0,target=0,hierarchy=memory," | |
1161 | "data-type=access-bandwidth,bandwidth=65534M" | |
1162 | " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," | |
1163 | "data-type=access-latency,latency=65534" | |
1164 | " -numa hmat-lb,initiator=0,target=1,hierarchy=memory," | |
1165 | "data-type=access-bandwidth,bandwidth=32767M" | |
1166 | " -numa hmat-cache,node-id=0,size=10K,level=1," | |
1167 | "associativity=direct,policy=write-back,line=8" | |
1168 | " -numa hmat-cache,node-id=1,size=10K,level=1," | |
1169 | "associativity=direct,policy=write-back,line=8", | |
1170 | &data); | |
1171 | free_test_data(&data); | |
1172 | } | |
1173 | ||
1174 | static void test_acpi_q35_tcg_acpi_hmat(void) | |
1175 | { | |
1176 | test_acpi_tcg_acpi_hmat(MACHINE_Q35); | |
1177 | } | |
1178 | ||
1179 | static void test_acpi_piix4_tcg_acpi_hmat(void) | |
1180 | { | |
1181 | test_acpi_tcg_acpi_hmat(MACHINE_PC); | |
1182 | } | |
1183 | ||
ab6b6a77 IM |
1184 | static void test_acpi_virt_tcg(void) |
1185 | { | |
1186 | test_data data = { | |
1187 | .machine = "virt", | |
6f6e1698 | 1188 | .tcg_only = true, |
ab6b6a77 IM |
1189 | .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", |
1190 | .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", | |
1191 | .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", | |
1192 | .ram_start = 0x40000000ULL, | |
1193 | .scan_len = 128ULL * 1024 * 1024, | |
1194 | }; | |
1195 | ||
1196 | test_acpi_one("-cpu cortex-a57", &data); | |
1197 | free_test_data(&data); | |
e1647539 YF |
1198 | |
1199 | data.smbios_cpu_max_speed = 2900; | |
1200 | data.smbios_cpu_curr_speed = 2700; | |
1201 | test_acpi_one("-cpu cortex-a57 " | |
1202 | "-smbios type=4,max-speed=2900,current-speed=2700", &data); | |
1203 | free_test_data(&data); | |
ab6b6a77 IM |
1204 | } |
1205 | ||
ad6423a7 MT |
1206 | int main(int argc, char *argv[]) |
1207 | { | |
1208 | const char *arch = qtest_get_arch(); | |
5862ad0f | 1209 | int ret; |
c39a28a4 | 1210 | |
ad6423a7 MT |
1211 | g_test_init(&argc, &argv, NULL); |
1212 | ||
1213 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { | |
d47a5d64 IM |
1214 | ret = boot_sector_init(disk); |
1215 | if (ret) { | |
1216 | return ret; | |
1217 | } | |
1218 | ||
5da7c35e | 1219 | qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis); |
947b205f MA |
1220 | qtest_add_func("acpi/piix4", test_acpi_piix4_tcg); |
1221 | qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge); | |
27476395 AS |
1222 | qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug", |
1223 | test_acpi_piix4_no_root_hotplug); | |
5e3a4862 AS |
1224 | qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug", |
1225 | test_acpi_piix4_no_bridge_hotplug); | |
5645f996 AS |
1226 | qtest_add_func("acpi/piix4/pci-hotplug/off", |
1227 | test_acpi_piix4_no_acpi_pci_hotplug); | |
947b205f MA |
1228 | qtest_add_func("acpi/q35", test_acpi_q35_tcg); |
1229 | qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge); | |
0259e966 | 1230 | qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64); |
947b205f MA |
1231 | qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi); |
1232 | qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi); | |
1233 | qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp); | |
1234 | qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp); | |
4462fc60 IM |
1235 | qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp); |
1236 | qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp); | |
d82c4f82 DL |
1237 | qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem); |
1238 | qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem); | |
adae91ce HZ |
1239 | qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm); |
1240 | qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm); | |
1c8f85d9 TX |
1241 | qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat); |
1242 | qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat); | |
c06cbf3d | 1243 | qtest_add_func("acpi/microvm", test_acpi_microvm_tcg); |
18bb73b3 GH |
1244 | if (strcmp(arch, "x86_64") == 0) { |
1245 | qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg); | |
1246 | } | |
ab6b6a77 IM |
1247 | } else if (strcmp(arch, "aarch64") == 0) { |
1248 | qtest_add_func("acpi/virt", test_acpi_virt_tcg); | |
669c7743 SK |
1249 | qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem); |
1250 | qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp); | |
ad6423a7 | 1251 | } |
5862ad0f | 1252 | ret = g_test_run(); |
4e082566 | 1253 | boot_sector_cleanup(disk); |
5862ad0f | 1254 | return ret; |
ad6423a7 | 1255 | } |