]>
Commit | Line | Data |
---|---|---|
f50cc952 SG |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * Tests for ACPI table generation | |
4 | * | |
5 | * Copyright 2019 Google LLC | |
6 | * Written by Simon Glass <sjg@chromium.org> | |
7 | */ | |
8 | ||
9 | #include <common.h> | |
0b885bcf | 10 | #include <console.h> |
f50cc952 | 11 | #include <dm.h> |
7e586f69 | 12 | #include <malloc.h> |
29b35112 | 13 | #include <mapmem.h> |
121a165c | 14 | #include <timestamp.h> |
0b885bcf | 15 | #include <version.h> |
7e586f69 | 16 | #include <tables_csum.h> |
93f7f827 | 17 | #include <version.h> |
b5183172 | 18 | #include <acpi/acpigen.h> |
1361a53c | 19 | #include <acpi/acpi_device.h> |
91fe8b79 | 20 | #include <acpi/acpi_table.h> |
401d1c4f | 21 | #include <asm/global_data.h> |
f50cc952 SG |
22 | #include <dm/acpi.h> |
23 | #include <dm/test.h> | |
24 | #include <test/ut.h> | |
82659cc9 | 25 | #include "acpi.h" |
f50cc952 | 26 | |
93f7f827 SG |
27 | #define BUF_SIZE 4096 |
28 | ||
1361a53c | 29 | /** |
8a8d24bd | 30 | * struct testacpi_plat - Platform data for the test ACPI device |
1361a53c SG |
31 | * |
32 | * @no_name: true to emit an empty ACPI name from testacpi_get_name() | |
33 | * @return_error: true to return an error instead of a name | |
34 | */ | |
8a8d24bd | 35 | struct testacpi_plat { |
1361a53c SG |
36 | bool return_error; |
37 | bool no_name; | |
38 | }; | |
39 | ||
93f7f827 SG |
40 | static int testacpi_write_tables(const struct udevice *dev, |
41 | struct acpi_ctx *ctx) | |
42 | { | |
43 | struct acpi_dmar *dmar; | |
29b35112 | 44 | int ret; |
93f7f827 SG |
45 | |
46 | dmar = (struct acpi_dmar *)ctx->current; | |
47 | acpi_create_dmar(dmar, DMAR_INTR_REMAP); | |
48 | ctx->current += sizeof(struct acpi_dmar); | |
29b35112 SG |
49 | ret = acpi_add_table(ctx, dmar); |
50 | if (ret) | |
51 | return log_msg_ret("add", ret); | |
93f7f827 SG |
52 | |
53 | return 0; | |
54 | } | |
f50cc952 SG |
55 | |
56 | static int testacpi_get_name(const struct udevice *dev, char *out_name) | |
57 | { | |
8a8d24bd | 58 | struct testacpi_plat *plat = dev_get_plat(dev); |
1361a53c SG |
59 | |
60 | if (plat->return_error) | |
61 | return -EINVAL; | |
62 | if (plat->no_name) { | |
63 | *out_name = '\0'; | |
64 | return 0; | |
65 | } | |
66 | if (device_get_uclass_id(dev->parent) == UCLASS_TEST_ACPI) | |
67 | return acpi_copy_name(out_name, ACPI_TEST_CHILD_NAME); | |
68 | else | |
69 | return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME); | |
f50cc952 SG |
70 | } |
71 | ||
b5183172 SG |
72 | static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx) |
73 | { | |
74 | const char *data; | |
75 | ||
76 | data = dev_read_string(dev, "acpi-ssdt-test-data"); | |
77 | if (data) { | |
78 | while (*data) | |
79 | acpigen_emit_byte(ctx, *data++); | |
80 | } | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
01694589 SG |
85 | static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx *ctx) |
86 | { | |
87 | const char *data; | |
88 | ||
89 | data = dev_read_string(dev, "acpi-dsdt-test-data"); | |
90 | if (data) { | |
91 | while (*data) | |
92 | acpigen_emit_byte(ctx, *data++); | |
93 | } | |
94 | ||
95 | return 0; | |
96 | } | |
97 | ||
f50cc952 SG |
98 | struct acpi_ops testacpi_ops = { |
99 | .get_name = testacpi_get_name, | |
93f7f827 | 100 | .write_tables = testacpi_write_tables, |
b5183172 | 101 | .fill_ssdt = testacpi_fill_ssdt, |
01694589 | 102 | .inject_dsdt = testacpi_inject_dsdt, |
f50cc952 SG |
103 | }; |
104 | ||
105 | static const struct udevice_id testacpi_ids[] = { | |
106 | { .compatible = "denx,u-boot-acpi-test" }, | |
107 | { } | |
108 | }; | |
109 | ||
110 | U_BOOT_DRIVER(testacpi_drv) = { | |
111 | .name = "testacpi_drv", | |
112 | .of_match = testacpi_ids, | |
113 | .id = UCLASS_TEST_ACPI, | |
1361a53c | 114 | .bind = dm_scan_fdt_dev, |
8a8d24bd | 115 | .plat_auto = sizeof(struct testacpi_plat), |
f50cc952 SG |
116 | ACPI_OPS_PTR(&testacpi_ops) |
117 | }; | |
118 | ||
119 | UCLASS_DRIVER(testacpi) = { | |
120 | .name = "testacpi", | |
121 | .id = UCLASS_TEST_ACPI, | |
122 | }; | |
123 | ||
124 | /* Test ACPI get_name() */ | |
125 | static int dm_test_acpi_get_name(struct unit_test_state *uts) | |
126 | { | |
127 | char name[ACPI_NAME_MAX]; | |
d1e85308 | 128 | struct udevice *dev, *dev2, *i2c, *spi, *timer, *sound; |
fefac0b0 | 129 | struct udevice *pci, *root; |
f50cc952 | 130 | |
fefac0b0 | 131 | /* Test getting the name from the driver */ |
f50cc952 SG |
132 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); |
133 | ut_assertok(acpi_get_name(dev, name)); | |
134 | ut_asserteq_str(ACPI_TEST_DEV_NAME, name); | |
135 | ||
fefac0b0 SG |
136 | /* Test getting the name from the device tree */ |
137 | ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test", | |
138 | &dev2)); | |
139 | ut_assertok(acpi_get_name(dev2, name)); | |
140 | ut_asserteq_str("GHIJ", name); | |
141 | ||
142 | /* Test getting the name from acpi_device_get_name() */ | |
143 | ut_assertok(uclass_first_device(UCLASS_I2C, &i2c)); | |
144 | ut_assertok(acpi_get_name(i2c, name)); | |
145 | ut_asserteq_str("I2C0", name); | |
146 | ||
147 | ut_assertok(uclass_first_device(UCLASS_SPI, &spi)); | |
148 | ut_assertok(acpi_get_name(spi, name)); | |
149 | ut_asserteq_str("SPI0", name); | |
150 | ||
fefac0b0 SG |
151 | /* ACPI doesn't know about the timer */ |
152 | ut_assertok(uclass_first_device(UCLASS_TIMER, &timer)); | |
153 | ut_asserteq(-ENOENT, acpi_get_name(timer, name)); | |
154 | ||
155 | /* May as well test the rest of the cases */ | |
156 | ut_assertok(uclass_first_device(UCLASS_SOUND, &sound)); | |
157 | ut_assertok(acpi_get_name(sound, name)); | |
158 | ut_asserteq_str("HDAS", name); | |
159 | ||
160 | ut_assertok(uclass_first_device(UCLASS_PCI, &pci)); | |
161 | ut_assertok(acpi_get_name(pci, name)); | |
162 | ut_asserteq_str("PCI0", name); | |
163 | ||
164 | ut_assertok(uclass_first_device(UCLASS_ROOT, &root)); | |
165 | ut_assertok(acpi_get_name(root, name)); | |
166 | ut_asserteq_str("\\_SB", name); | |
167 | ||
168 | /* Note that we don't have tests for acpi_name_from_id() */ | |
169 | ||
f50cc952 SG |
170 | return 0; |
171 | } | |
e180c2b1 | 172 | DM_TEST(dm_test_acpi_get_name, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
91fe8b79 SG |
173 | |
174 | /* Test acpi_get_table_revision() */ | |
175 | static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) | |
176 | { | |
177 | ut_asserteq(1, acpi_get_table_revision(ACPITAB_MCFG)); | |
178 | ut_asserteq(2, acpi_get_table_revision(ACPITAB_RSDP)); | |
179 | ut_asserteq(4, acpi_get_table_revision(ACPITAB_TPM2)); | |
180 | ut_asserteq(-EINVAL, acpi_get_table_revision(ACPITAB_COUNT)); | |
181 | ||
182 | return 0; | |
183 | } | |
184 | DM_TEST(dm_test_acpi_get_table_revision, | |
e180c2b1 | 185 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
bfeb5d46 | 186 | |
bfeb5d46 SG |
187 | /* Test acpi_create_dmar() */ |
188 | static int dm_test_acpi_create_dmar(struct unit_test_state *uts) | |
189 | { | |
190 | struct acpi_dmar dmar; | |
331caeaf | 191 | struct udevice *cpu; |
bfeb5d46 | 192 | |
331caeaf HS |
193 | ut_assertok(uclass_first_device(UCLASS_CPU, &cpu)); |
194 | ut_assertnonnull(cpu); | |
bfeb5d46 SG |
195 | ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP)); |
196 | ut_asserteq(DMAR_INTR_REMAP, dmar.flags); | |
197 | ut_asserteq(32 - 1, dmar.host_address_width); | |
198 | ||
199 | return 0; | |
200 | } | |
e180c2b1 | 201 | DM_TEST(dm_test_acpi_create_dmar, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
93f7f827 SG |
202 | |
203 | /* Test acpi_fill_header() */ | |
204 | static int dm_test_acpi_fill_header(struct unit_test_state *uts) | |
205 | { | |
206 | struct acpi_table_header hdr; | |
207 | ||
208 | /* Make sure these 5 fields are not changed */ | |
209 | hdr.length = 0x11; | |
210 | hdr.revision = 0x22; | |
211 | hdr.checksum = 0x33; | |
212 | hdr.aslc_revision = 0x44; | |
213 | acpi_fill_header(&hdr, "ABCD"); | |
214 | ||
215 | ut_asserteq_mem("ABCD", hdr.signature, sizeof(hdr.signature)); | |
216 | ut_asserteq(0x11, hdr.length); | |
217 | ut_asserteq(0x22, hdr.revision); | |
218 | ut_asserteq(0x33, hdr.checksum); | |
219 | ut_asserteq_mem(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id)); | |
220 | ut_asserteq_mem(OEM_TABLE_ID, hdr.oem_table_id, | |
221 | sizeof(hdr.oem_table_id)); | |
222 | ut_asserteq(U_BOOT_BUILD_DATE, hdr.oem_revision); | |
223 | ut_asserteq_mem(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)); | |
224 | ut_asserteq(0x44, hdr.aslc_revision); | |
225 | ||
226 | return 0; | |
227 | } | |
e180c2b1 | 228 | DM_TEST(dm_test_acpi_fill_header, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
93f7f827 SG |
229 | |
230 | /* Test ACPI write_tables() */ | |
231 | static int dm_test_acpi_write_tables(struct unit_test_state *uts) | |
232 | { | |
233 | struct acpi_dmar *dmar; | |
234 | struct acpi_ctx ctx; | |
235 | void *buf; | |
1361a53c | 236 | int i; |
93f7f827 SG |
237 | |
238 | buf = malloc(BUF_SIZE); | |
239 | ut_assertnonnull(buf); | |
240 | ||
7e586f69 | 241 | acpi_setup_base_tables(&ctx, buf); |
29b35112 | 242 | dmar = ctx.current; |
93f7f827 | 243 | ut_assertok(acpi_write_dev_tables(&ctx)); |
93f7f827 SG |
244 | |
245 | /* | |
1361a53c SG |
246 | * We should have three dmar tables, one for each |
247 | * "denx,u-boot-acpi-test" device | |
93f7f827 | 248 | */ |
1361a53c | 249 | ut_asserteq_ptr(dmar + 3, ctx.current); |
93f7f827 SG |
250 | ut_asserteq(DMAR_INTR_REMAP, dmar->flags); |
251 | ut_asserteq(32 - 1, dmar->host_address_width); | |
252 | ||
253 | ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags); | |
254 | ut_asserteq(32 - 1, dmar[1].host_address_width); | |
255 | ||
1361a53c SG |
256 | ut_asserteq(DMAR_INTR_REMAP, dmar[2].flags); |
257 | ut_asserteq(32 - 1, dmar[2].host_address_width); | |
7e586f69 | 258 | |
1361a53c SG |
259 | /* Check that the pointers were added correctly */ |
260 | for (i = 0; i < 3; i++) { | |
261 | ut_asserteq(map_to_sysmem(dmar + i), ctx.rsdt->entry[i]); | |
262 | ut_asserteq(map_to_sysmem(dmar + i), ctx.xsdt->entry[i]); | |
263 | } | |
264 | ut_asserteq(0, ctx.rsdt->entry[3]); | |
265 | ut_asserteq(0, ctx.xsdt->entry[3]); | |
b38309b7 | 266 | |
93f7f827 SG |
267 | return 0; |
268 | } | |
e180c2b1 | 269 | DM_TEST(dm_test_acpi_write_tables, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
86e1778d SG |
270 | |
271 | /* Test basic ACPI functions */ | |
272 | static int dm_test_acpi_basic(struct unit_test_state *uts) | |
273 | { | |
274 | struct acpi_ctx ctx; | |
275 | ||
276 | /* Check align works */ | |
277 | ctx.current = (void *)5; | |
278 | acpi_align(&ctx); | |
279 | ut_asserteq_ptr((void *)16, ctx.current); | |
280 | ||
281 | /* Check that align does nothing if already aligned */ | |
282 | acpi_align(&ctx); | |
283 | ut_asserteq_ptr((void *)16, ctx.current); | |
284 | acpi_align64(&ctx); | |
285 | ut_asserteq_ptr((void *)64, ctx.current); | |
286 | acpi_align64(&ctx); | |
287 | ut_asserteq_ptr((void *)64, ctx.current); | |
288 | ||
289 | /* Check incrementing */ | |
290 | acpi_inc(&ctx, 3); | |
291 | ut_asserteq_ptr((void *)67, ctx.current); | |
292 | acpi_inc_align(&ctx, 3); | |
293 | ut_asserteq_ptr((void *)80, ctx.current); | |
294 | ||
295 | return 0; | |
296 | } | |
e180c2b1 | 297 | DM_TEST(dm_test_acpi_basic, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
7e586f69 SG |
298 | |
299 | /* Test acpi_setup_base_tables */ | |
300 | static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) | |
301 | { | |
302 | struct acpi_rsdp *rsdp; | |
303 | struct acpi_rsdt *rsdt; | |
304 | struct acpi_xsdt *xsdt; | |
305 | struct acpi_ctx ctx; | |
306 | void *buf, *end; | |
307 | ||
308 | /* | |
309 | * Use an unaligned address deliberately, by allocating an aligned | |
310 | * address and then adding 4 to it | |
311 | */ | |
312 | buf = memalign(64, BUF_SIZE); | |
313 | ut_assertnonnull(buf); | |
314 | acpi_setup_base_tables(&ctx, buf + 4); | |
0b885bcf | 315 | ut_asserteq(map_to_sysmem(PTR_ALIGN(buf + 4, 16)), gd->arch.acpi_start); |
7e586f69 SG |
316 | |
317 | rsdp = buf + 16; | |
318 | ut_asserteq_ptr(rsdp, ctx.rsdp); | |
f91f366b | 319 | ut_asserteq_mem(RSDP_SIG, rsdp->signature, sizeof(rsdp->signature)); |
7e586f69 SG |
320 | ut_asserteq(sizeof(*rsdp), rsdp->length); |
321 | ut_assertok(table_compute_checksum(rsdp, 20)); | |
322 | ut_assertok(table_compute_checksum(rsdp, sizeof(*rsdp))); | |
323 | ||
324 | rsdt = PTR_ALIGN((void *)rsdp + sizeof(*rsdp), 16); | |
325 | ut_asserteq_ptr(rsdt, ctx.rsdt); | |
f91f366b | 326 | ut_asserteq_mem("RSDT", rsdt->header.signature, ACPI_NAME_LEN); |
7e586f69 SG |
327 | ut_asserteq(sizeof(*rsdt), rsdt->header.length); |
328 | ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt))); | |
329 | ||
330 | xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16); | |
b38309b7 | 331 | ut_asserteq_ptr(xsdt, ctx.xsdt); |
f91f366b | 332 | ut_asserteq_mem("XSDT", xsdt->header.signature, ACPI_NAME_LEN); |
7e586f69 SG |
333 | ut_asserteq(sizeof(*xsdt), xsdt->header.length); |
334 | ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt))); | |
335 | ||
336 | end = PTR_ALIGN((void *)xsdt + sizeof(*xsdt), 64); | |
337 | ut_asserteq_ptr(end, ctx.current); | |
338 | ||
339 | ut_asserteq(map_to_sysmem(rsdt), rsdp->rsdt_address); | |
340 | ut_asserteq(map_to_sysmem(xsdt), rsdp->xsdt_address); | |
341 | ||
342 | return 0; | |
343 | } | |
344 | DM_TEST(dm_test_acpi_setup_base_tables, | |
e180c2b1 | 345 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
0b885bcf SG |
346 | |
347 | /* Test 'acpi list' command */ | |
348 | static int dm_test_acpi_cmd_list(struct unit_test_state *uts) | |
349 | { | |
350 | struct acpi_ctx ctx; | |
351 | ulong addr; | |
352 | void *buf; | |
353 | ||
354 | buf = memalign(16, BUF_SIZE); | |
355 | ut_assertnonnull(buf); | |
356 | acpi_setup_base_tables(&ctx, buf); | |
357 | ||
358 | ut_assertok(acpi_write_dev_tables(&ctx)); | |
359 | ||
360 | console_record_reset(); | |
361 | run_command("acpi list", 0); | |
362 | addr = (ulong)map_to_sysmem(buf); | |
363 | ut_assert_nextline("ACPI tables start at %lx", addr); | |
634f5ad3 | 364 | ut_assert_nextline("RSDP %08lx %06zx (v02 U-BOOT)", addr, |
0b885bcf SG |
365 | sizeof(struct acpi_rsdp)); |
366 | addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16); | |
634f5ad3 | 367 | ut_assert_nextline("RSDT %08lx %06zx (v01 U-BOOT U-BOOTBL %x INTL 0)", |
0b885bcf | 368 | addr, sizeof(struct acpi_table_header) + |
1361a53c | 369 | 3 * sizeof(u32), U_BOOT_BUILD_DATE); |
0b885bcf | 370 | addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16); |
634f5ad3 | 371 | ut_assert_nextline("XSDT %08lx %06zx (v01 U-BOOT U-BOOTBL %x INTL 0)", |
0b885bcf | 372 | addr, sizeof(struct acpi_table_header) + |
1361a53c | 373 | 3 * sizeof(u64), U_BOOT_BUILD_DATE); |
0b885bcf | 374 | addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64); |
634f5ad3 | 375 | ut_assert_nextline("DMAR %08lx %06zx (v01 U-BOOT U-BOOTBL %x INTL 0)", |
0b885bcf SG |
376 | addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); |
377 | addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); | |
634f5ad3 | 378 | ut_assert_nextline("DMAR %08lx %06zx (v01 U-BOOT U-BOOTBL %x INTL 0)", |
1361a53c SG |
379 | addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); |
380 | addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); | |
634f5ad3 | 381 | ut_assert_nextline("DMAR %08lx %06zx (v01 U-BOOT U-BOOTBL %x INTL 0)", |
0b885bcf SG |
382 | addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); |
383 | ut_assert_console_end(); | |
384 | ||
385 | return 0; | |
386 | } | |
e180c2b1 | 387 | DM_TEST(dm_test_acpi_cmd_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
0b885bcf SG |
388 | |
389 | /* Test 'acpi dump' command */ | |
390 | static int dm_test_acpi_cmd_dump(struct unit_test_state *uts) | |
391 | { | |
392 | struct acpi_ctx ctx; | |
393 | ulong addr; | |
394 | void *buf; | |
395 | ||
396 | buf = memalign(16, BUF_SIZE); | |
397 | ut_assertnonnull(buf); | |
398 | acpi_setup_base_tables(&ctx, buf); | |
399 | ||
400 | ut_assertok(acpi_write_dev_tables(&ctx)); | |
401 | ||
402 | /* First search for a non-existent table */ | |
403 | console_record_reset(); | |
404 | run_command("acpi dump rdst", 0); | |
405 | ut_assert_nextline("Table 'RDST' not found"); | |
406 | ut_assert_console_end(); | |
407 | ||
408 | /* Now a real table */ | |
409 | console_record_reset(); | |
410 | run_command("acpi dump dmar", 0); | |
411 | addr = ALIGN(map_to_sysmem(ctx.xsdt) + sizeof(struct acpi_xsdt), 64); | |
412 | ut_assert_nextline("DMAR @ %08lx", addr); | |
413 | ut_assert_nextlines_are_dump(0x30); | |
414 | ut_assert_console_end(); | |
415 | ||
416 | return 0; | |
417 | } | |
e180c2b1 | 418 | DM_TEST(dm_test_acpi_cmd_dump, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
1361a53c SG |
419 | |
420 | /* Test acpi_device_path() */ | |
421 | static int dm_test_acpi_device_path(struct unit_test_state *uts) | |
422 | { | |
8a8d24bd | 423 | struct testacpi_plat *plat; |
1361a53c SG |
424 | char buf[ACPI_PATH_MAX]; |
425 | struct udevice *dev, *child; | |
426 | ||
427 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); | |
428 | ut_assertok(acpi_device_path(dev, buf, sizeof(buf))); | |
429 | ut_asserteq_str("\\_SB." ACPI_TEST_DEV_NAME, buf); | |
430 | ||
431 | /* Test running out of space */ | |
432 | buf[5] = '\0'; | |
433 | ut_asserteq(-ENOSPC, acpi_device_path(dev, buf, 5)); | |
434 | ut_asserteq('\0', buf[5]); | |
435 | ||
436 | /* Test a three-component name */ | |
437 | ut_assertok(device_first_child_err(dev, &child)); | |
438 | ut_assertok(acpi_device_path(child, buf, sizeof(buf))); | |
439 | ut_asserteq_str("\\_SB." ACPI_TEST_DEV_NAME "." ACPI_TEST_CHILD_NAME, | |
440 | buf); | |
441 | ||
442 | /* Test handling of a device which doesn't produce a name */ | |
c69cda25 | 443 | plat = dev_get_plat(dev); |
1361a53c SG |
444 | plat->no_name = true; |
445 | ut_assertok(acpi_device_path(child, buf, sizeof(buf))); | |
446 | ut_asserteq_str("\\_SB." ACPI_TEST_CHILD_NAME, buf); | |
447 | ||
448 | /* Test handling of a device which returns an error */ | |
c69cda25 | 449 | plat = dev_get_plat(dev); |
1361a53c SG |
450 | plat->return_error = true; |
451 | ut_asserteq(-EINVAL, acpi_device_path(child, buf, sizeof(buf))); | |
452 | ||
453 | return 0; | |
454 | } | |
e180c2b1 | 455 | DM_TEST(dm_test_acpi_device_path, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
2715b362 SG |
456 | |
457 | /* Test acpi_device_status() */ | |
458 | static int dm_test_acpi_device_status(struct unit_test_state *uts) | |
459 | { | |
460 | struct udevice *dev; | |
461 | ||
462 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); | |
463 | ut_asserteq(ACPI_DSTATUS_ALL_ON, acpi_device_status(dev)); | |
464 | ||
465 | return 0; | |
466 | } | |
e180c2b1 | 467 | DM_TEST(dm_test_acpi_device_status, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
b5183172 SG |
468 | |
469 | /* Test acpi_fill_ssdt() */ | |
470 | static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) | |
471 | { | |
472 | struct acpi_ctx ctx; | |
473 | u8 *buf; | |
474 | ||
475 | buf = malloc(BUF_SIZE); | |
476 | ut_assertnonnull(buf); | |
477 | ||
18434aec | 478 | acpi_reset_items(); |
b5183172 SG |
479 | ctx.current = buf; |
480 | buf[4] = 'z'; /* sentinel */ | |
481 | ut_assertok(acpi_fill_ssdt(&ctx)); | |
482 | ||
0f7b111f SG |
483 | /* |
484 | * These values come from acpi-test2's acpi-ssdt-test-data property. | |
485 | * This device comes first because of u-boot,acpi-ssdt-order | |
486 | */ | |
487 | ut_asserteq('c', buf[0]); | |
488 | ut_asserteq('d', buf[1]); | |
b5183172 | 489 | |
0f7b111f SG |
490 | /* These values come from acpi-test's acpi-ssdt-test-data property */ |
491 | ut_asserteq('a', buf[2]); | |
492 | ut_asserteq('b', buf[3]); | |
b5183172 SG |
493 | |
494 | ut_asserteq('z', buf[4]); | |
495 | ||
496 | return 0; | |
497 | } | |
e180c2b1 | 498 | DM_TEST(dm_test_acpi_fill_ssdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
01694589 SG |
499 | |
500 | /* Test acpi_inject_dsdt() */ | |
501 | static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts) | |
502 | { | |
503 | struct acpi_ctx ctx; | |
504 | u8 *buf; | |
505 | ||
506 | buf = malloc(BUF_SIZE); | |
507 | ut_assertnonnull(buf); | |
508 | ||
18434aec | 509 | acpi_reset_items(); |
01694589 SG |
510 | ctx.current = buf; |
511 | buf[4] = 'z'; /* sentinel */ | |
512 | ut_assertok(acpi_inject_dsdt(&ctx)); | |
513 | ||
514 | /* | |
515 | * These values come from acpi-test's acpi-dsdt-test-data property. | |
516 | * There is no u-boot,acpi-dsdt-order so device-tree order is used. | |
517 | */ | |
518 | ut_asserteq('h', buf[0]); | |
519 | ut_asserteq('i', buf[1]); | |
520 | ||
521 | /* These values come from acpi-test's acpi-dsdt-test-data property */ | |
522 | ut_asserteq('j', buf[2]); | |
523 | ut_asserteq('k', buf[3]); | |
524 | ||
525 | ut_asserteq('z', buf[4]); | |
526 | ||
527 | return 0; | |
528 | } | |
e180c2b1 | 529 | DM_TEST(dm_test_acpi_inject_dsdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
a4f82089 SG |
530 | |
531 | /* Test 'acpi items' command */ | |
532 | static int dm_test_acpi_cmd_items(struct unit_test_state *uts) | |
533 | { | |
534 | struct acpi_ctx ctx; | |
535 | void *buf; | |
536 | ||
537 | buf = malloc(BUF_SIZE); | |
538 | ut_assertnonnull(buf); | |
539 | ||
18434aec | 540 | acpi_reset_items(); |
a4f82089 SG |
541 | ctx.current = buf; |
542 | ut_assertok(acpi_fill_ssdt(&ctx)); | |
543 | console_record_reset(); | |
544 | run_command("acpi items", 0); | |
545 | ut_assert_nextline("dev 'acpi-test', type 1, size 2"); | |
546 | ut_assert_nextline("dev 'acpi-test2', type 1, size 2"); | |
547 | ut_assert_console_end(); | |
548 | ||
18434aec | 549 | acpi_reset_items(); |
a4f82089 SG |
550 | ctx.current = buf; |
551 | ut_assertok(acpi_inject_dsdt(&ctx)); | |
552 | console_record_reset(); | |
553 | run_command("acpi items", 0); | |
554 | ut_assert_nextline("dev 'acpi-test', type 2, size 2"); | |
555 | ut_assert_nextline("dev 'acpi-test2', type 2, size 2"); | |
556 | ut_assert_console_end(); | |
557 | ||
558 | console_record_reset(); | |
559 | run_command("acpi items -d", 0); | |
560 | ut_assert_nextline("dev 'acpi-test', type 2, size 2"); | |
561 | ut_assert_nextlines_are_dump(2); | |
562 | ut_assert_nextline("%s", ""); | |
563 | ut_assert_nextline("dev 'acpi-test2', type 2, size 2"); | |
564 | ut_assert_nextlines_are_dump(2); | |
565 | ut_assert_nextline("%s", ""); | |
566 | ut_assert_console_end(); | |
567 | ||
568 | return 0; | |
569 | } | |
e180c2b1 | 570 | DM_TEST(dm_test_acpi_cmd_items, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |