root / tests / acpi-test.c @ 8ac2adf7
History | View | Annotate | Download (12.6 kB)
1 | ad6423a7 | Michael S. Tsirkin | /*
|
---|---|---|---|
2 | ad6423a7 | Michael S. Tsirkin | * Boot order test cases.
|
3 | ad6423a7 | Michael S. Tsirkin | *
|
4 | ad6423a7 | Michael S. Tsirkin | * Copyright (c) 2013 Red Hat Inc.
|
5 | ad6423a7 | Michael S. Tsirkin | *
|
6 | ad6423a7 | Michael S. Tsirkin | * Authors:
|
7 | ad6423a7 | Michael S. Tsirkin | * Michael S. Tsirkin <mst@redhat.com>,
|
8 | ad6423a7 | Michael S. Tsirkin | *
|
9 | ad6423a7 | Michael S. Tsirkin | * This work is licensed under the terms of the GNU GPL, version 2 or later.
|
10 | ad6423a7 | Michael S. Tsirkin | * See the COPYING file in the top-level directory.
|
11 | ad6423a7 | Michael S. Tsirkin | */
|
12 | ad6423a7 | Michael S. Tsirkin | |
13 | ad6423a7 | Michael S. Tsirkin | #include <string.h> |
14 | ad6423a7 | Michael S. Tsirkin | #include <stdio.h> |
15 | ad6423a7 | Michael S. Tsirkin | #include <glib.h> |
16 | 53333801 | Marcel Apfelbaum | #include "qemu-common.h" |
17 | ad6423a7 | Michael S. Tsirkin | #include "libqtest.h" |
18 | 53333801 | Marcel Apfelbaum | #include "qemu/compiler.h" |
19 | 53333801 | Marcel Apfelbaum | #include "hw/i386/acpi-defs.h" |
20 | ad6423a7 | Michael S. Tsirkin | |
21 | 53333801 | Marcel Apfelbaum | /* DSDT and SSDTs format */
|
22 | ad6423a7 | Michael S. Tsirkin | typedef struct { |
23 | 53333801 | Marcel Apfelbaum | AcpiTableHeader header; |
24 | 53333801 | Marcel Apfelbaum | uint8_t *aml; |
25 | 53333801 | Marcel Apfelbaum | int aml_len;
|
26 | 53333801 | Marcel Apfelbaum | } AcpiSdtTable; |
27 | 53333801 | Marcel Apfelbaum | |
28 | 53333801 | Marcel Apfelbaum | typedef struct { |
29 | 53333801 | Marcel Apfelbaum | uint32_t rsdp_addr; |
30 | 53333801 | Marcel Apfelbaum | AcpiRsdpDescriptor rsdp_table; |
31 | 53333801 | Marcel Apfelbaum | AcpiRsdtDescriptorRev1 rsdt_table; |
32 | 53333801 | Marcel Apfelbaum | AcpiFadtDescriptorRev1 fadt_table; |
33 | 15650602 | Marcel Apfelbaum | AcpiFacsDescriptorRev1 facs_table; |
34 | 53333801 | Marcel Apfelbaum | uint32_t *rsdt_tables_addr; |
35 | 53333801 | Marcel Apfelbaum | int rsdt_tables_nr;
|
36 | 53333801 | Marcel Apfelbaum | AcpiSdtTable dsdt_table; |
37 | 8ac2adf7 | Marcel Apfelbaum | GArray *ssdt_tables; |
38 | 53333801 | Marcel Apfelbaum | } test_data; |
39 | ad6423a7 | Michael S. Tsirkin | |
40 | ad6423a7 | Michael S. Tsirkin | #define LOW(x) ((x) & 0xff) |
41 | ad6423a7 | Michael S. Tsirkin | #define HIGH(x) ((x) >> 8) |
42 | ad6423a7 | Michael S. Tsirkin | |
43 | ad6423a7 | Michael S. Tsirkin | #define SIGNATURE 0xdead |
44 | ad6423a7 | Michael S. Tsirkin | #define SIGNATURE_OFFSET 0x10 |
45 | ad6423a7 | Michael S. Tsirkin | #define BOOT_SECTOR_ADDRESS 0x7c00 |
46 | ad6423a7 | Michael S. Tsirkin | |
47 | 53333801 | Marcel Apfelbaum | #define ACPI_READ_FIELD(field, addr) \
|
48 | 53333801 | Marcel Apfelbaum | do { \
|
49 | 53333801 | Marcel Apfelbaum | switch (sizeof(field)) { \ |
50 | 53333801 | Marcel Apfelbaum | case 1: \ |
51 | 53333801 | Marcel Apfelbaum | field = readb(addr); \ |
52 | 53333801 | Marcel Apfelbaum | break; \
|
53 | 53333801 | Marcel Apfelbaum | case 2: \ |
54 | 53333801 | Marcel Apfelbaum | field = le16_to_cpu(readw(addr)); \ |
55 | 53333801 | Marcel Apfelbaum | break; \
|
56 | 53333801 | Marcel Apfelbaum | case 4: \ |
57 | 53333801 | Marcel Apfelbaum | field = le32_to_cpu(readl(addr)); \ |
58 | 53333801 | Marcel Apfelbaum | break; \
|
59 | 53333801 | Marcel Apfelbaum | case 8: \ |
60 | 53333801 | Marcel Apfelbaum | field = le64_to_cpu(readq(addr)); \ |
61 | 53333801 | Marcel Apfelbaum | break; \
|
62 | 53333801 | Marcel Apfelbaum | default: \
|
63 | 53333801 | Marcel Apfelbaum | g_assert(false); \
|
64 | 53333801 | Marcel Apfelbaum | } \ |
65 | 53333801 | Marcel Apfelbaum | addr += sizeof(field); \
|
66 | 53333801 | Marcel Apfelbaum | } while (0); |
67 | 53333801 | Marcel Apfelbaum | |
68 | 53333801 | Marcel Apfelbaum | #define ACPI_READ_ARRAY_PTR(arr, length, addr) \
|
69 | 53333801 | Marcel Apfelbaum | do { \
|
70 | 53333801 | Marcel Apfelbaum | int idx; \
|
71 | 53333801 | Marcel Apfelbaum | for (idx = 0; idx < length; ++idx) { \ |
72 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(arr[idx], addr); \ |
73 | 53333801 | Marcel Apfelbaum | } \ |
74 | 53333801 | Marcel Apfelbaum | } while (0); |
75 | 53333801 | Marcel Apfelbaum | |
76 | 53333801 | Marcel Apfelbaum | #define ACPI_READ_ARRAY(arr, addr) \
|
77 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY_PTR(arr, sizeof(arr)/sizeof(arr[0]), addr) |
78 | 53333801 | Marcel Apfelbaum | |
79 | 53333801 | Marcel Apfelbaum | #define ACPI_READ_TABLE_HEADER(table, addr) \
|
80 | 53333801 | Marcel Apfelbaum | do { \
|
81 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD((table)->signature, addr); \ |
82 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD((table)->length, addr); \ |
83 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD((table)->revision, addr); \ |
84 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD((table)->checksum, addr); \ |
85 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY((table)->oem_id, addr); \ |
86 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY((table)->oem_table_id, addr); \ |
87 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD((table)->oem_revision, addr); \ |
88 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \ |
89 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \ |
90 | 53333801 | Marcel Apfelbaum | } while (0); |
91 | 53333801 | Marcel Apfelbaum | |
92 | ad6423a7 | Michael S. Tsirkin | /* Boot sector code: write SIGNATURE into memory,
|
93 | ad6423a7 | Michael S. Tsirkin | * then halt.
|
94 | ad6423a7 | Michael S. Tsirkin | */
|
95 | ad6423a7 | Michael S. Tsirkin | static uint8_t boot_sector[0x200] = { |
96 | ad6423a7 | Michael S. Tsirkin | /* 7c00: mov $0xdead,%ax */
|
97 | ad6423a7 | Michael S. Tsirkin | [0x00] = 0xb8, |
98 | ad6423a7 | Michael S. Tsirkin | [0x01] = LOW(SIGNATURE),
|
99 | ad6423a7 | Michael S. Tsirkin | [0x02] = HIGH(SIGNATURE),
|
100 | ad6423a7 | Michael S. Tsirkin | /* 7c03: mov %ax,0x7c10 */
|
101 | ad6423a7 | Michael S. Tsirkin | [0x03] = 0xa3, |
102 | ad6423a7 | Michael S. Tsirkin | [0x04] = LOW(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
|
103 | ad6423a7 | Michael S. Tsirkin | [0x05] = HIGH(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
|
104 | ad6423a7 | Michael S. Tsirkin | /* 7c06: cli */
|
105 | ad6423a7 | Michael S. Tsirkin | [0x06] = 0xfa, |
106 | ad6423a7 | Michael S. Tsirkin | /* 7c07: hlt */
|
107 | ad6423a7 | Michael S. Tsirkin | [0x07] = 0xf4, |
108 | ad6423a7 | Michael S. Tsirkin | /* 7c08: jmp 0x7c07=0x7c0a-3 */
|
109 | ad6423a7 | Michael S. Tsirkin | [0x08] = 0xeb, |
110 | ad6423a7 | Michael S. Tsirkin | [0x09] = LOW(-3), |
111 | ad6423a7 | Michael S. Tsirkin | /* We mov 0xdead here: set value to make debugging easier */
|
112 | ad6423a7 | Michael S. Tsirkin | [SIGNATURE_OFFSET] = LOW(0xface),
|
113 | ad6423a7 | Michael S. Tsirkin | [SIGNATURE_OFFSET + 1] = HIGH(0xface), |
114 | ad6423a7 | Michael S. Tsirkin | /* End of boot sector marker */
|
115 | ad6423a7 | Michael S. Tsirkin | [0x1FE] = 0x55, |
116 | ad6423a7 | Michael S. Tsirkin | [0x1FF] = 0xAA, |
117 | ad6423a7 | Michael S. Tsirkin | }; |
118 | ad6423a7 | Michael S. Tsirkin | |
119 | ad6423a7 | Michael S. Tsirkin | static const char *disk = "tests/acpi-test-disk.raw"; |
120 | ad6423a7 | Michael S. Tsirkin | |
121 | 8ac2adf7 | Marcel Apfelbaum | static void free_test_data(test_data *data) |
122 | 8ac2adf7 | Marcel Apfelbaum | { |
123 | 8ac2adf7 | Marcel Apfelbaum | int i;
|
124 | 8ac2adf7 | Marcel Apfelbaum | |
125 | 8ac2adf7 | Marcel Apfelbaum | g_free(data->rsdt_tables_addr); |
126 | 8ac2adf7 | Marcel Apfelbaum | for (i = 0; i < data->ssdt_tables->len; ++i) { |
127 | 8ac2adf7 | Marcel Apfelbaum | g_free(g_array_index(data->ssdt_tables, AcpiSdtTable, i).aml); |
128 | 8ac2adf7 | Marcel Apfelbaum | } |
129 | 8ac2adf7 | Marcel Apfelbaum | g_array_free(data->ssdt_tables, false);
|
130 | 8ac2adf7 | Marcel Apfelbaum | g_free(data->dsdt_table.aml); |
131 | 8ac2adf7 | Marcel Apfelbaum | } |
132 | 8ac2adf7 | Marcel Apfelbaum | |
133 | 53333801 | Marcel Apfelbaum | static uint8_t acpi_checksum(const uint8_t *data, int len) |
134 | 53333801 | Marcel Apfelbaum | { |
135 | 53333801 | Marcel Apfelbaum | int i;
|
136 | 53333801 | Marcel Apfelbaum | uint8_t sum = 0;
|
137 | 53333801 | Marcel Apfelbaum | |
138 | 53333801 | Marcel Apfelbaum | for (i = 0; i < len; i++) { |
139 | 53333801 | Marcel Apfelbaum | sum += data[i]; |
140 | 53333801 | Marcel Apfelbaum | } |
141 | 53333801 | Marcel Apfelbaum | |
142 | 53333801 | Marcel Apfelbaum | return sum;
|
143 | 53333801 | Marcel Apfelbaum | } |
144 | 53333801 | Marcel Apfelbaum | |
145 | 53333801 | Marcel Apfelbaum | static void test_acpi_rsdp_address(test_data *data) |
146 | 53333801 | Marcel Apfelbaum | { |
147 | 53333801 | Marcel Apfelbaum | uint32_t off; |
148 | 53333801 | Marcel Apfelbaum | |
149 | 53333801 | Marcel Apfelbaum | /* OK, now find RSDP */
|
150 | 53333801 | Marcel Apfelbaum | for (off = 0xf0000; off < 0x100000; off += 0x10) { |
151 | 53333801 | Marcel Apfelbaum | uint8_t sig[] = "RSD PTR ";
|
152 | 53333801 | Marcel Apfelbaum | int i;
|
153 | 53333801 | Marcel Apfelbaum | |
154 | 53333801 | Marcel Apfelbaum | for (i = 0; i < sizeof sig - 1; ++i) { |
155 | 53333801 | Marcel Apfelbaum | sig[i] = readb(off + i); |
156 | 53333801 | Marcel Apfelbaum | } |
157 | 53333801 | Marcel Apfelbaum | |
158 | 53333801 | Marcel Apfelbaum | if (!memcmp(sig, "RSD PTR ", sizeof sig)) { |
159 | 53333801 | Marcel Apfelbaum | break;
|
160 | 53333801 | Marcel Apfelbaum | } |
161 | 53333801 | Marcel Apfelbaum | } |
162 | 53333801 | Marcel Apfelbaum | |
163 | 53333801 | Marcel Apfelbaum | g_assert_cmphex(off, <, 0x100000);
|
164 | 53333801 | Marcel Apfelbaum | data->rsdp_addr = off; |
165 | 53333801 | Marcel Apfelbaum | } |
166 | 53333801 | Marcel Apfelbaum | |
167 | 53333801 | Marcel Apfelbaum | static void test_acpi_rsdp_table(test_data *data) |
168 | 53333801 | Marcel Apfelbaum | { |
169 | 53333801 | Marcel Apfelbaum | AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table; |
170 | 53333801 | Marcel Apfelbaum | uint32_t addr = data->rsdp_addr; |
171 | 53333801 | Marcel Apfelbaum | |
172 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(rsdp_table->signature, addr); |
173 | 53333801 | Marcel Apfelbaum | g_assert_cmphex(rsdp_table->signature, ==, ACPI_RSDP_SIGNATURE); |
174 | 53333801 | Marcel Apfelbaum | |
175 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(rsdp_table->checksum, addr); |
176 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY(rsdp_table->oem_id, addr); |
177 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(rsdp_table->revision, addr); |
178 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(rsdp_table->rsdt_physical_address, addr); |
179 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(rsdp_table->length, addr); |
180 | 53333801 | Marcel Apfelbaum | |
181 | 53333801 | Marcel Apfelbaum | /* rsdp checksum is not for the whole table, but for the first 20 bytes */
|
182 | 53333801 | Marcel Apfelbaum | g_assert(!acpi_checksum((uint8_t *)rsdp_table, 20));
|
183 | 53333801 | Marcel Apfelbaum | } |
184 | 53333801 | Marcel Apfelbaum | |
185 | 53333801 | Marcel Apfelbaum | static void test_acpi_rsdt_table(test_data *data) |
186 | 53333801 | Marcel Apfelbaum | { |
187 | 53333801 | Marcel Apfelbaum | AcpiRsdtDescriptorRev1 *rsdt_table = &data->rsdt_table; |
188 | 53333801 | Marcel Apfelbaum | uint32_t addr = data->rsdp_table.rsdt_physical_address; |
189 | 53333801 | Marcel Apfelbaum | uint32_t *tables; |
190 | 53333801 | Marcel Apfelbaum | int tables_nr;
|
191 | 53333801 | Marcel Apfelbaum | uint8_t checksum; |
192 | 53333801 | Marcel Apfelbaum | |
193 | 53333801 | Marcel Apfelbaum | /* read the header */
|
194 | 53333801 | Marcel Apfelbaum | ACPI_READ_TABLE_HEADER(rsdt_table, addr); |
195 | 53333801 | Marcel Apfelbaum | g_assert_cmphex(rsdt_table->signature, ==, ACPI_RSDT_SIGNATURE); |
196 | 53333801 | Marcel Apfelbaum | |
197 | 53333801 | Marcel Apfelbaum | /* compute the table entries in rsdt */
|
198 | 53333801 | Marcel Apfelbaum | tables_nr = (rsdt_table->length - sizeof(AcpiRsdtDescriptorRev1)) /
|
199 | 53333801 | Marcel Apfelbaum | sizeof(uint32_t);
|
200 | 53333801 | Marcel Apfelbaum | g_assert_cmpint(tables_nr, >, 0);
|
201 | 53333801 | Marcel Apfelbaum | |
202 | 53333801 | Marcel Apfelbaum | /* get the addresses of the tables pointed by rsdt */
|
203 | 53333801 | Marcel Apfelbaum | tables = g_new0(uint32_t, tables_nr); |
204 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY_PTR(tables, tables_nr, addr); |
205 | 53333801 | Marcel Apfelbaum | |
206 | 53333801 | Marcel Apfelbaum | checksum = acpi_checksum((uint8_t *)rsdt_table, rsdt_table->length) + |
207 | 53333801 | Marcel Apfelbaum | acpi_checksum((uint8_t *)tables, tables_nr * sizeof(uint32_t));
|
208 | 53333801 | Marcel Apfelbaum | g_assert(!checksum); |
209 | 53333801 | Marcel Apfelbaum | |
210 | 53333801 | Marcel Apfelbaum | /* SSDT tables after FADT */
|
211 | 53333801 | Marcel Apfelbaum | data->rsdt_tables_addr = tables; |
212 | 53333801 | Marcel Apfelbaum | data->rsdt_tables_nr = tables_nr; |
213 | 53333801 | Marcel Apfelbaum | } |
214 | 53333801 | Marcel Apfelbaum | |
215 | 53333801 | Marcel Apfelbaum | static void test_acpi_fadt_table(test_data *data) |
216 | 53333801 | Marcel Apfelbaum | { |
217 | 53333801 | Marcel Apfelbaum | AcpiFadtDescriptorRev1 *fadt_table = &data->fadt_table; |
218 | 53333801 | Marcel Apfelbaum | uint32_t addr; |
219 | 53333801 | Marcel Apfelbaum | |
220 | 53333801 | Marcel Apfelbaum | /* FADT table comes first */
|
221 | 53333801 | Marcel Apfelbaum | addr = data->rsdt_tables_addr[0];
|
222 | 53333801 | Marcel Apfelbaum | ACPI_READ_TABLE_HEADER(fadt_table, addr); |
223 | 53333801 | Marcel Apfelbaum | |
224 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->firmware_ctrl, addr); |
225 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->dsdt, addr); |
226 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->model, addr); |
227 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->reserved1, addr); |
228 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->sci_int, addr); |
229 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->smi_cmd, addr); |
230 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->acpi_enable, addr); |
231 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->acpi_disable, addr); |
232 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->S4bios_req, addr); |
233 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->reserved2, addr); |
234 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm1a_evt_blk, addr); |
235 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm1b_evt_blk, addr); |
236 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm1a_cnt_blk, addr); |
237 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm1b_cnt_blk, addr); |
238 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm2_cnt_blk, addr); |
239 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm_tmr_blk, addr); |
240 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->gpe0_blk, addr); |
241 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->gpe1_blk, addr); |
242 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm1_evt_len, addr); |
243 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm1_cnt_len, addr); |
244 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm2_cnt_len, addr); |
245 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->pm_tmr_len, addr); |
246 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->gpe0_blk_len, addr); |
247 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->gpe1_blk_len, addr); |
248 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->gpe1_base, addr); |
249 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->reserved3, addr); |
250 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->plvl2_lat, addr); |
251 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->plvl3_lat, addr); |
252 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->flush_size, addr); |
253 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->flush_stride, addr); |
254 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->duty_offset, addr); |
255 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->duty_width, addr); |
256 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->day_alrm, addr); |
257 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->mon_alrm, addr); |
258 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->century, addr); |
259 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->reserved4, addr); |
260 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->reserved4a, addr); |
261 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->reserved4b, addr); |
262 | 53333801 | Marcel Apfelbaum | ACPI_READ_FIELD(fadt_table->flags, addr); |
263 | 53333801 | Marcel Apfelbaum | |
264 | 53333801 | Marcel Apfelbaum | g_assert_cmphex(fadt_table->signature, ==, ACPI_FACP_SIGNATURE); |
265 | 53333801 | Marcel Apfelbaum | g_assert(!acpi_checksum((uint8_t *)fadt_table, fadt_table->length)); |
266 | 53333801 | Marcel Apfelbaum | } |
267 | 53333801 | Marcel Apfelbaum | |
268 | 15650602 | Marcel Apfelbaum | static void test_acpi_facs_table(test_data *data) |
269 | 15650602 | Marcel Apfelbaum | { |
270 | 15650602 | Marcel Apfelbaum | AcpiFacsDescriptorRev1 *facs_table = &data->facs_table; |
271 | 15650602 | Marcel Apfelbaum | uint32_t addr = data->fadt_table.firmware_ctrl; |
272 | 15650602 | Marcel Apfelbaum | |
273 | 15650602 | Marcel Apfelbaum | ACPI_READ_FIELD(facs_table->signature, addr); |
274 | 15650602 | Marcel Apfelbaum | ACPI_READ_FIELD(facs_table->length, addr); |
275 | 15650602 | Marcel Apfelbaum | ACPI_READ_FIELD(facs_table->hardware_signature, addr); |
276 | 15650602 | Marcel Apfelbaum | ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr); |
277 | 15650602 | Marcel Apfelbaum | ACPI_READ_FIELD(facs_table->global_lock, addr); |
278 | 15650602 | Marcel Apfelbaum | ACPI_READ_FIELD(facs_table->flags, addr); |
279 | 15650602 | Marcel Apfelbaum | ACPI_READ_ARRAY(facs_table->resverved3, addr); |
280 | 15650602 | Marcel Apfelbaum | |
281 | 15650602 | Marcel Apfelbaum | g_assert_cmphex(facs_table->signature, ==, ACPI_FACS_SIGNATURE); |
282 | 15650602 | Marcel Apfelbaum | } |
283 | 15650602 | Marcel Apfelbaum | |
284 | 53333801 | Marcel Apfelbaum | static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr) |
285 | 53333801 | Marcel Apfelbaum | { |
286 | 53333801 | Marcel Apfelbaum | uint8_t checksum; |
287 | 53333801 | Marcel Apfelbaum | |
288 | 53333801 | Marcel Apfelbaum | ACPI_READ_TABLE_HEADER(&sdt_table->header, addr); |
289 | 53333801 | Marcel Apfelbaum | |
290 | 53333801 | Marcel Apfelbaum | sdt_table->aml_len = sdt_table->header.length - sizeof(AcpiTableHeader);
|
291 | 53333801 | Marcel Apfelbaum | sdt_table->aml = g_malloc0(sdt_table->aml_len); |
292 | 53333801 | Marcel Apfelbaum | ACPI_READ_ARRAY_PTR(sdt_table->aml, sdt_table->aml_len, addr); |
293 | 53333801 | Marcel Apfelbaum | |
294 | 53333801 | Marcel Apfelbaum | checksum = acpi_checksum((uint8_t *)sdt_table, sizeof(AcpiTableHeader)) +
|
295 | 53333801 | Marcel Apfelbaum | acpi_checksum(sdt_table->aml, sdt_table->aml_len); |
296 | 53333801 | Marcel Apfelbaum | g_assert(!checksum); |
297 | 53333801 | Marcel Apfelbaum | } |
298 | 53333801 | Marcel Apfelbaum | |
299 | 53333801 | Marcel Apfelbaum | static void test_acpi_dsdt_table(test_data *data) |
300 | 53333801 | Marcel Apfelbaum | { |
301 | 53333801 | Marcel Apfelbaum | AcpiSdtTable *dsdt_table = &data->dsdt_table; |
302 | 53333801 | Marcel Apfelbaum | uint32_t addr = data->fadt_table.dsdt; |
303 | 53333801 | Marcel Apfelbaum | |
304 | 53333801 | Marcel Apfelbaum | test_dst_table(dsdt_table, addr); |
305 | 53333801 | Marcel Apfelbaum | g_assert_cmphex(dsdt_table->header.signature, ==, ACPI_DSDT_SIGNATURE); |
306 | 53333801 | Marcel Apfelbaum | } |
307 | 53333801 | Marcel Apfelbaum | |
308 | 53333801 | Marcel Apfelbaum | static void test_acpi_ssdt_tables(test_data *data) |
309 | 53333801 | Marcel Apfelbaum | { |
310 | 8ac2adf7 | Marcel Apfelbaum | GArray *ssdt_tables; |
311 | 53333801 | Marcel Apfelbaum | int ssdt_tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */ |
312 | 53333801 | Marcel Apfelbaum | int i;
|
313 | 53333801 | Marcel Apfelbaum | |
314 | 8ac2adf7 | Marcel Apfelbaum | ssdt_tables = g_array_sized_new(false, true, sizeof(AcpiSdtTable), |
315 | 8ac2adf7 | Marcel Apfelbaum | ssdt_tables_nr); |
316 | 53333801 | Marcel Apfelbaum | for (i = 0; i < ssdt_tables_nr; i++) { |
317 | 8ac2adf7 | Marcel Apfelbaum | AcpiSdtTable ssdt_table; |
318 | 53333801 | Marcel Apfelbaum | uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */ |
319 | 8ac2adf7 | Marcel Apfelbaum | test_dst_table(&ssdt_table, addr); |
320 | 8ac2adf7 | Marcel Apfelbaum | g_array_append_val(ssdt_tables, ssdt_table); |
321 | 53333801 | Marcel Apfelbaum | } |
322 | 53333801 | Marcel Apfelbaum | data->ssdt_tables = ssdt_tables; |
323 | 53333801 | Marcel Apfelbaum | } |
324 | 53333801 | Marcel Apfelbaum | |
325 | 8ac2adf7 | Marcel Apfelbaum | static void test_acpi_one(const char *params, test_data *data) |
326 | ad6423a7 | Michael S. Tsirkin | { |
327 | ad6423a7 | Michael S. Tsirkin | char *args;
|
328 | ad6423a7 | Michael S. Tsirkin | uint8_t signature_low; |
329 | ad6423a7 | Michael S. Tsirkin | uint8_t signature_high; |
330 | ad6423a7 | Michael S. Tsirkin | uint16_t signature; |
331 | ad6423a7 | Michael S. Tsirkin | int i;
|
332 | ad6423a7 | Michael S. Tsirkin | |
333 | 8ac2adf7 | Marcel Apfelbaum | memset(data, 0, sizeof(*data)); |
334 | ad6423a7 | Michael S. Tsirkin | args = g_strdup_printf("-net none -display none %s %s",
|
335 | ad6423a7 | Michael S. Tsirkin | params ? params : "", disk);
|
336 | ad6423a7 | Michael S. Tsirkin | qtest_start(args); |
337 | ad6423a7 | Michael S. Tsirkin | |
338 | ad6423a7 | Michael S. Tsirkin | /* Wait at most 1 minute */
|
339 | ad6423a7 | Michael S. Tsirkin | #define TEST_DELAY (1 * G_USEC_PER_SEC / 10) |
340 | ad6423a7 | Michael S. Tsirkin | #define TEST_CYCLES MAX((60 * G_USEC_PER_SEC / TEST_DELAY), 1) |
341 | ad6423a7 | Michael S. Tsirkin | |
342 | ad6423a7 | Michael S. Tsirkin | /* Poll until code has run and modified memory. Once it has we know BIOS
|
343 | ad6423a7 | Michael S. Tsirkin | * initialization is done. TODO: check that IP reached the halt
|
344 | ad6423a7 | Michael S. Tsirkin | * instruction.
|
345 | ad6423a7 | Michael S. Tsirkin | */
|
346 | ad6423a7 | Michael S. Tsirkin | for (i = 0; i < TEST_CYCLES; ++i) { |
347 | ad6423a7 | Michael S. Tsirkin | signature_low = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET); |
348 | ad6423a7 | Michael S. Tsirkin | signature_high = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
|
349 | ad6423a7 | Michael S. Tsirkin | signature = (signature_high << 8) | signature_low;
|
350 | ad6423a7 | Michael S. Tsirkin | if (signature == SIGNATURE) {
|
351 | ad6423a7 | Michael S. Tsirkin | break;
|
352 | ad6423a7 | Michael S. Tsirkin | } |
353 | ad6423a7 | Michael S. Tsirkin | g_usleep(TEST_DELAY); |
354 | ad6423a7 | Michael S. Tsirkin | } |
355 | ad6423a7 | Michael S. Tsirkin | g_assert_cmphex(signature, ==, SIGNATURE); |
356 | ad6423a7 | Michael S. Tsirkin | |
357 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_rsdp_address(data); |
358 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_rsdp_table(data); |
359 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_rsdt_table(data); |
360 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_fadt_table(data); |
361 | 15650602 | Marcel Apfelbaum | test_acpi_facs_table(data); |
362 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_dsdt_table(data); |
363 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_ssdt_tables(data); |
364 | ad6423a7 | Michael S. Tsirkin | |
365 | ad6423a7 | Michael S. Tsirkin | qtest_quit(global_qtest); |
366 | ad6423a7 | Michael S. Tsirkin | g_free(args); |
367 | ad6423a7 | Michael S. Tsirkin | } |
368 | ad6423a7 | Michael S. Tsirkin | |
369 | ad6423a7 | Michael S. Tsirkin | static void test_acpi_tcg(void) |
370 | ad6423a7 | Michael S. Tsirkin | { |
371 | 8ac2adf7 | Marcel Apfelbaum | test_data data; |
372 | 8ac2adf7 | Marcel Apfelbaum | |
373 | ad6423a7 | Michael S. Tsirkin | /* Supplying -machine accel argument overrides the default (qtest).
|
374 | ad6423a7 | Michael S. Tsirkin | * This is to make guest actually run.
|
375 | ad6423a7 | Michael S. Tsirkin | */
|
376 | 8ac2adf7 | Marcel Apfelbaum | test_acpi_one("-machine accel=tcg", &data);
|
377 | 8ac2adf7 | Marcel Apfelbaum | |
378 | 8ac2adf7 | Marcel Apfelbaum | free_test_data(&data); |
379 | ad6423a7 | Michael S. Tsirkin | } |
380 | ad6423a7 | Michael S. Tsirkin | |
381 | ad6423a7 | Michael S. Tsirkin | int main(int argc, char *argv[]) |
382 | ad6423a7 | Michael S. Tsirkin | { |
383 | ad6423a7 | Michael S. Tsirkin | const char *arch = qtest_get_arch(); |
384 | ad6423a7 | Michael S. Tsirkin | FILE *f = fopen(disk, "w");
|
385 | ad6423a7 | Michael S. Tsirkin | fwrite(boot_sector, 1, sizeof boot_sector, f); |
386 | ad6423a7 | Michael S. Tsirkin | fclose(f); |
387 | ad6423a7 | Michael S. Tsirkin | |
388 | ad6423a7 | Michael S. Tsirkin | g_test_init(&argc, &argv, NULL);
|
389 | ad6423a7 | Michael S. Tsirkin | |
390 | ad6423a7 | Michael S. Tsirkin | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
391 | ad6423a7 | Michael S. Tsirkin | qtest_add_func("acpi/tcg", test_acpi_tcg);
|
392 | ad6423a7 | Michael S. Tsirkin | } |
393 | ad6423a7 | Michael S. Tsirkin | return g_test_run();
|
394 | ad6423a7 | Michael S. Tsirkin | } |