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