Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 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> |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 10 | #include <console.h> |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 13 | #include <mapmem.h> |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 14 | #include <version.h> |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 15 | #include <tables_csum.h> |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 16 | #include <version.h> |
Simon Glass | d43e0ba | 2020-07-07 13:12:03 -0600 | [diff] [blame] | 17 | #include <acpi/acpigen.h> |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 18 | #include <acpi/acpi_device.h> |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 19 | #include <acpi/acpi_table.h> |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 20 | #include <dm/acpi.h> |
| 21 | #include <dm/test.h> |
| 22 | #include <test/ut.h> |
| 23 | |
| 24 | #define ACPI_TEST_DEV_NAME "ABCD" |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 25 | #define ACPI_TEST_CHILD_NAME "EFGH" |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 26 | #define BUF_SIZE 4096 |
| 27 | |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 28 | /** |
| 29 | * struct testacpi_platdata - Platform data for the test ACPI device |
| 30 | * |
| 31 | * @no_name: true to emit an empty ACPI name from testacpi_get_name() |
| 32 | * @return_error: true to return an error instead of a name |
| 33 | */ |
| 34 | struct testacpi_platdata { |
| 35 | bool return_error; |
| 36 | bool no_name; |
| 37 | }; |
| 38 | |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 39 | static int testacpi_write_tables(const struct udevice *dev, |
| 40 | struct acpi_ctx *ctx) |
| 41 | { |
| 42 | struct acpi_dmar *dmar; |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 43 | int ret; |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 44 | |
| 45 | dmar = (struct acpi_dmar *)ctx->current; |
| 46 | acpi_create_dmar(dmar, DMAR_INTR_REMAP); |
| 47 | ctx->current += sizeof(struct acpi_dmar); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 48 | ret = acpi_add_table(ctx, dmar); |
| 49 | if (ret) |
| 50 | return log_msg_ret("add", ret); |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 54 | |
| 55 | static int testacpi_get_name(const struct udevice *dev, char *out_name) |
| 56 | { |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 57 | struct testacpi_platdata *plat = dev_get_platdata(dev); |
| 58 | |
| 59 | if (plat->return_error) |
| 60 | return -EINVAL; |
| 61 | if (plat->no_name) { |
| 62 | *out_name = '\0'; |
| 63 | return 0; |
| 64 | } |
| 65 | if (device_get_uclass_id(dev->parent) == UCLASS_TEST_ACPI) |
| 66 | return acpi_copy_name(out_name, ACPI_TEST_CHILD_NAME); |
| 67 | else |
| 68 | return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME); |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 69 | } |
| 70 | |
Simon Glass | d43e0ba | 2020-07-07 13:12:03 -0600 | [diff] [blame] | 71 | static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx) |
| 72 | { |
| 73 | const char *data; |
| 74 | |
| 75 | data = dev_read_string(dev, "acpi-ssdt-test-data"); |
| 76 | if (data) { |
| 77 | while (*data) |
| 78 | acpigen_emit_byte(ctx, *data++); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
Simon Glass | 990cd5b | 2020-07-07 13:12:08 -0600 | [diff] [blame^] | 84 | static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx *ctx) |
| 85 | { |
| 86 | const char *data; |
| 87 | |
| 88 | data = dev_read_string(dev, "acpi-dsdt-test-data"); |
| 89 | if (data) { |
| 90 | while (*data) |
| 91 | acpigen_emit_byte(ctx, *data++); |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 97 | struct acpi_ops testacpi_ops = { |
| 98 | .get_name = testacpi_get_name, |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 99 | .write_tables = testacpi_write_tables, |
Simon Glass | d43e0ba | 2020-07-07 13:12:03 -0600 | [diff] [blame] | 100 | .fill_ssdt = testacpi_fill_ssdt, |
Simon Glass | 990cd5b | 2020-07-07 13:12:08 -0600 | [diff] [blame^] | 101 | .inject_dsdt = testacpi_inject_dsdt, |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static const struct udevice_id testacpi_ids[] = { |
| 105 | { .compatible = "denx,u-boot-acpi-test" }, |
| 106 | { } |
| 107 | }; |
| 108 | |
| 109 | U_BOOT_DRIVER(testacpi_drv) = { |
| 110 | .name = "testacpi_drv", |
| 111 | .of_match = testacpi_ids, |
| 112 | .id = UCLASS_TEST_ACPI, |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 113 | .bind = dm_scan_fdt_dev, |
| 114 | .platdata_auto_alloc_size = sizeof(struct testacpi_platdata), |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 115 | ACPI_OPS_PTR(&testacpi_ops) |
| 116 | }; |
| 117 | |
| 118 | UCLASS_DRIVER(testacpi) = { |
| 119 | .name = "testacpi", |
| 120 | .id = UCLASS_TEST_ACPI, |
| 121 | }; |
| 122 | |
| 123 | /* Test ACPI get_name() */ |
| 124 | static int dm_test_acpi_get_name(struct unit_test_state *uts) |
| 125 | { |
| 126 | char name[ACPI_NAME_MAX]; |
| 127 | struct udevice *dev; |
| 128 | |
| 129 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); |
| 130 | ut_assertok(acpi_get_name(dev, name)); |
| 131 | ut_asserteq_str(ACPI_TEST_DEV_NAME, name); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 136 | |
| 137 | /* Test acpi_get_table_revision() */ |
| 138 | static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) |
| 139 | { |
| 140 | ut_asserteq(1, acpi_get_table_revision(ACPITAB_MCFG)); |
| 141 | ut_asserteq(2, acpi_get_table_revision(ACPITAB_RSDP)); |
| 142 | ut_asserteq(4, acpi_get_table_revision(ACPITAB_TPM2)); |
| 143 | ut_asserteq(-EINVAL, acpi_get_table_revision(ACPITAB_COUNT)); |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | DM_TEST(dm_test_acpi_get_table_revision, |
| 148 | DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 149 | |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 150 | /* Test acpi_create_dmar() */ |
| 151 | static int dm_test_acpi_create_dmar(struct unit_test_state *uts) |
| 152 | { |
| 153 | struct acpi_dmar dmar; |
| 154 | |
| 155 | ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP)); |
| 156 | ut_asserteq(DMAR_INTR_REMAP, dmar.flags); |
| 157 | ut_asserteq(32 - 1, dmar.host_address_width); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 162 | |
| 163 | /* Test acpi_fill_header() */ |
| 164 | static int dm_test_acpi_fill_header(struct unit_test_state *uts) |
| 165 | { |
| 166 | struct acpi_table_header hdr; |
| 167 | |
| 168 | /* Make sure these 5 fields are not changed */ |
| 169 | hdr.length = 0x11; |
| 170 | hdr.revision = 0x22; |
| 171 | hdr.checksum = 0x33; |
| 172 | hdr.aslc_revision = 0x44; |
| 173 | acpi_fill_header(&hdr, "ABCD"); |
| 174 | |
| 175 | ut_asserteq_mem("ABCD", hdr.signature, sizeof(hdr.signature)); |
| 176 | ut_asserteq(0x11, hdr.length); |
| 177 | ut_asserteq(0x22, hdr.revision); |
| 178 | ut_asserteq(0x33, hdr.checksum); |
| 179 | ut_asserteq_mem(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id)); |
| 180 | ut_asserteq_mem(OEM_TABLE_ID, hdr.oem_table_id, |
| 181 | sizeof(hdr.oem_table_id)); |
| 182 | ut_asserteq(U_BOOT_BUILD_DATE, hdr.oem_revision); |
| 183 | ut_asserteq_mem(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)); |
| 184 | ut_asserteq(0x44, hdr.aslc_revision); |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 189 | |
| 190 | /* Test ACPI write_tables() */ |
| 191 | static int dm_test_acpi_write_tables(struct unit_test_state *uts) |
| 192 | { |
| 193 | struct acpi_dmar *dmar; |
| 194 | struct acpi_ctx ctx; |
| 195 | void *buf; |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 196 | int i; |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 197 | |
| 198 | buf = malloc(BUF_SIZE); |
| 199 | ut_assertnonnull(buf); |
| 200 | |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 201 | acpi_setup_base_tables(&ctx, buf); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 202 | dmar = ctx.current; |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 203 | ut_assertok(acpi_write_dev_tables(&ctx)); |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 204 | |
| 205 | /* |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 206 | * We should have three dmar tables, one for each |
| 207 | * "denx,u-boot-acpi-test" device |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 208 | */ |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 209 | ut_asserteq_ptr(dmar + 3, ctx.current); |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 210 | ut_asserteq(DMAR_INTR_REMAP, dmar->flags); |
| 211 | ut_asserteq(32 - 1, dmar->host_address_width); |
| 212 | |
| 213 | ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags); |
| 214 | ut_asserteq(32 - 1, dmar[1].host_address_width); |
| 215 | |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 216 | ut_asserteq(DMAR_INTR_REMAP, dmar[2].flags); |
| 217 | ut_asserteq(32 - 1, dmar[2].host_address_width); |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 218 | |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 219 | /* Check that the pointers were added correctly */ |
| 220 | for (i = 0; i < 3; i++) { |
| 221 | ut_asserteq(map_to_sysmem(dmar + i), ctx.rsdt->entry[i]); |
| 222 | ut_asserteq(map_to_sysmem(dmar + i), ctx.xsdt->entry[i]); |
| 223 | } |
| 224 | ut_asserteq(0, ctx.rsdt->entry[3]); |
| 225 | ut_asserteq(0, ctx.xsdt->entry[3]); |
Simon Glass | abeaca8 | 2020-04-26 09:19:52 -0600 | [diff] [blame] | 226 | |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 230 | |
| 231 | /* Test basic ACPI functions */ |
| 232 | static int dm_test_acpi_basic(struct unit_test_state *uts) |
| 233 | { |
| 234 | struct acpi_ctx ctx; |
| 235 | |
| 236 | /* Check align works */ |
| 237 | ctx.current = (void *)5; |
| 238 | acpi_align(&ctx); |
| 239 | ut_asserteq_ptr((void *)16, ctx.current); |
| 240 | |
| 241 | /* Check that align does nothing if already aligned */ |
| 242 | acpi_align(&ctx); |
| 243 | ut_asserteq_ptr((void *)16, ctx.current); |
| 244 | acpi_align64(&ctx); |
| 245 | ut_asserteq_ptr((void *)64, ctx.current); |
| 246 | acpi_align64(&ctx); |
| 247 | ut_asserteq_ptr((void *)64, ctx.current); |
| 248 | |
| 249 | /* Check incrementing */ |
| 250 | acpi_inc(&ctx, 3); |
| 251 | ut_asserteq_ptr((void *)67, ctx.current); |
| 252 | acpi_inc_align(&ctx, 3); |
| 253 | ut_asserteq_ptr((void *)80, ctx.current); |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | DM_TEST(dm_test_acpi_basic, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 258 | |
| 259 | /* Test acpi_setup_base_tables */ |
| 260 | static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) |
| 261 | { |
| 262 | struct acpi_rsdp *rsdp; |
| 263 | struct acpi_rsdt *rsdt; |
| 264 | struct acpi_xsdt *xsdt; |
| 265 | struct acpi_ctx ctx; |
| 266 | void *buf, *end; |
| 267 | |
| 268 | /* |
| 269 | * Use an unaligned address deliberately, by allocating an aligned |
| 270 | * address and then adding 4 to it |
| 271 | */ |
| 272 | buf = memalign(64, BUF_SIZE); |
| 273 | ut_assertnonnull(buf); |
| 274 | acpi_setup_base_tables(&ctx, buf + 4); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 275 | ut_asserteq(map_to_sysmem(PTR_ALIGN(buf + 4, 16)), gd->arch.acpi_start); |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 276 | |
| 277 | rsdp = buf + 16; |
| 278 | ut_asserteq_ptr(rsdp, ctx.rsdp); |
Simon Glass | a3186e6 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 279 | ut_asserteq_mem(RSDP_SIG, rsdp->signature, sizeof(rsdp->signature)); |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 280 | ut_asserteq(sizeof(*rsdp), rsdp->length); |
| 281 | ut_assertok(table_compute_checksum(rsdp, 20)); |
| 282 | ut_assertok(table_compute_checksum(rsdp, sizeof(*rsdp))); |
| 283 | |
| 284 | rsdt = PTR_ALIGN((void *)rsdp + sizeof(*rsdp), 16); |
| 285 | ut_asserteq_ptr(rsdt, ctx.rsdt); |
Simon Glass | a3186e6 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 286 | ut_asserteq_mem("RSDT", rsdt->header.signature, ACPI_NAME_LEN); |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 287 | ut_asserteq(sizeof(*rsdt), rsdt->header.length); |
| 288 | ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt))); |
| 289 | |
| 290 | xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16); |
Simon Glass | abeaca8 | 2020-04-26 09:19:52 -0600 | [diff] [blame] | 291 | ut_asserteq_ptr(xsdt, ctx.xsdt); |
Simon Glass | a3186e6 | 2020-05-10 12:52:45 -0600 | [diff] [blame] | 292 | ut_asserteq_mem("XSDT", xsdt->header.signature, ACPI_NAME_LEN); |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 293 | ut_asserteq(sizeof(*xsdt), xsdt->header.length); |
| 294 | ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt))); |
| 295 | |
| 296 | end = PTR_ALIGN((void *)xsdt + sizeof(*xsdt), 64); |
| 297 | ut_asserteq_ptr(end, ctx.current); |
| 298 | |
| 299 | ut_asserteq(map_to_sysmem(rsdt), rsdp->rsdt_address); |
| 300 | ut_asserteq(map_to_sysmem(xsdt), rsdp->xsdt_address); |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | DM_TEST(dm_test_acpi_setup_base_tables, |
| 305 | DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 306 | |
| 307 | /* Test 'acpi list' command */ |
| 308 | static int dm_test_acpi_cmd_list(struct unit_test_state *uts) |
| 309 | { |
| 310 | struct acpi_ctx ctx; |
| 311 | ulong addr; |
| 312 | void *buf; |
| 313 | |
| 314 | buf = memalign(16, BUF_SIZE); |
| 315 | ut_assertnonnull(buf); |
| 316 | acpi_setup_base_tables(&ctx, buf); |
| 317 | |
| 318 | ut_assertok(acpi_write_dev_tables(&ctx)); |
| 319 | |
| 320 | console_record_reset(); |
| 321 | run_command("acpi list", 0); |
| 322 | addr = (ulong)map_to_sysmem(buf); |
| 323 | ut_assert_nextline("ACPI tables start at %lx", addr); |
| 324 | ut_assert_nextline("RSDP %08lx %06lx (v02 U-BOOT)", addr, |
| 325 | sizeof(struct acpi_rsdp)); |
| 326 | addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16); |
| 327 | ut_assert_nextline("RSDT %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", |
| 328 | addr, sizeof(struct acpi_table_header) + |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 329 | 3 * sizeof(u32), U_BOOT_BUILD_DATE); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 330 | addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16); |
| 331 | ut_assert_nextline("XSDT %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", |
| 332 | addr, sizeof(struct acpi_table_header) + |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 333 | 3 * sizeof(u64), U_BOOT_BUILD_DATE); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 334 | addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64); |
| 335 | ut_assert_nextline("DMAR %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", |
| 336 | addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); |
| 337 | addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); |
| 338 | ut_assert_nextline("DMAR %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", |
| 339 | addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 340 | addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); |
| 341 | ut_assert_nextline("DMAR %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", |
| 342 | addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 343 | ut_assert_console_end(); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | DM_TEST(dm_test_acpi_cmd_list, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 348 | |
| 349 | /* Test 'acpi dump' command */ |
| 350 | static int dm_test_acpi_cmd_dump(struct unit_test_state *uts) |
| 351 | { |
| 352 | struct acpi_ctx ctx; |
| 353 | ulong addr; |
| 354 | void *buf; |
| 355 | |
| 356 | buf = memalign(16, BUF_SIZE); |
| 357 | ut_assertnonnull(buf); |
| 358 | acpi_setup_base_tables(&ctx, buf); |
| 359 | |
| 360 | ut_assertok(acpi_write_dev_tables(&ctx)); |
| 361 | |
| 362 | /* First search for a non-existent table */ |
| 363 | console_record_reset(); |
| 364 | run_command("acpi dump rdst", 0); |
| 365 | ut_assert_nextline("Table 'RDST' not found"); |
| 366 | ut_assert_console_end(); |
| 367 | |
| 368 | /* Now a real table */ |
| 369 | console_record_reset(); |
| 370 | run_command("acpi dump dmar", 0); |
| 371 | addr = ALIGN(map_to_sysmem(ctx.xsdt) + sizeof(struct acpi_xsdt), 64); |
| 372 | ut_assert_nextline("DMAR @ %08lx", addr); |
| 373 | ut_assert_nextlines_are_dump(0x30); |
| 374 | ut_assert_console_end(); |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | DM_TEST(dm_test_acpi_cmd_dump, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 379 | |
| 380 | /* Test acpi_device_path() */ |
| 381 | static int dm_test_acpi_device_path(struct unit_test_state *uts) |
| 382 | { |
| 383 | struct testacpi_platdata *plat; |
| 384 | char buf[ACPI_PATH_MAX]; |
| 385 | struct udevice *dev, *child; |
| 386 | |
| 387 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); |
| 388 | ut_assertok(acpi_device_path(dev, buf, sizeof(buf))); |
| 389 | ut_asserteq_str("\\_SB." ACPI_TEST_DEV_NAME, buf); |
| 390 | |
| 391 | /* Test running out of space */ |
| 392 | buf[5] = '\0'; |
| 393 | ut_asserteq(-ENOSPC, acpi_device_path(dev, buf, 5)); |
| 394 | ut_asserteq('\0', buf[5]); |
| 395 | |
| 396 | /* Test a three-component name */ |
| 397 | ut_assertok(device_first_child_err(dev, &child)); |
| 398 | ut_assertok(acpi_device_path(child, buf, sizeof(buf))); |
| 399 | ut_asserteq_str("\\_SB." ACPI_TEST_DEV_NAME "." ACPI_TEST_CHILD_NAME, |
| 400 | buf); |
| 401 | |
| 402 | /* Test handling of a device which doesn't produce a name */ |
| 403 | plat = dev_get_platdata(dev); |
| 404 | plat->no_name = true; |
| 405 | ut_assertok(acpi_device_path(child, buf, sizeof(buf))); |
| 406 | ut_asserteq_str("\\_SB." ACPI_TEST_CHILD_NAME, buf); |
| 407 | |
| 408 | /* Test handling of a device which returns an error */ |
| 409 | plat = dev_get_platdata(dev); |
| 410 | plat->return_error = true; |
| 411 | ut_asserteq(-EINVAL, acpi_device_path(child, buf, sizeof(buf))); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | DM_TEST(dm_test_acpi_device_path, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 8965cc9 | 2020-07-07 13:11:40 -0600 | [diff] [blame] | 416 | |
| 417 | /* Test acpi_device_status() */ |
| 418 | static int dm_test_acpi_device_status(struct unit_test_state *uts) |
| 419 | { |
| 420 | struct udevice *dev; |
| 421 | |
| 422 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); |
| 423 | ut_asserteq(ACPI_DSTATUS_ALL_ON, acpi_device_status(dev)); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | DM_TEST(dm_test_acpi_device_status, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | d43e0ba | 2020-07-07 13:12:03 -0600 | [diff] [blame] | 428 | |
| 429 | /* Test acpi_fill_ssdt() */ |
| 430 | static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) |
| 431 | { |
| 432 | struct acpi_ctx ctx; |
| 433 | u8 *buf; |
| 434 | |
| 435 | buf = malloc(BUF_SIZE); |
| 436 | ut_assertnonnull(buf); |
| 437 | |
| 438 | ctx.current = buf; |
| 439 | buf[4] = 'z'; /* sentinel */ |
| 440 | ut_assertok(acpi_fill_ssdt(&ctx)); |
| 441 | |
Simon Glass | 3c601b1 | 2020-07-07 13:12:06 -0600 | [diff] [blame] | 442 | /* |
| 443 | * These values come from acpi-test2's acpi-ssdt-test-data property. |
| 444 | * This device comes first because of u-boot,acpi-ssdt-order |
| 445 | */ |
| 446 | ut_asserteq('c', buf[0]); |
| 447 | ut_asserteq('d', buf[1]); |
Simon Glass | d43e0ba | 2020-07-07 13:12:03 -0600 | [diff] [blame] | 448 | |
Simon Glass | 3c601b1 | 2020-07-07 13:12:06 -0600 | [diff] [blame] | 449 | /* These values come from acpi-test's acpi-ssdt-test-data property */ |
| 450 | ut_asserteq('a', buf[2]); |
| 451 | ut_asserteq('b', buf[3]); |
Simon Glass | d43e0ba | 2020-07-07 13:12:03 -0600 | [diff] [blame] | 452 | |
| 453 | ut_asserteq('z', buf[4]); |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | DM_TEST(dm_test_acpi_fill_ssdt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 990cd5b | 2020-07-07 13:12:08 -0600 | [diff] [blame^] | 458 | |
| 459 | /* Test acpi_inject_dsdt() */ |
| 460 | static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts) |
| 461 | { |
| 462 | struct acpi_ctx ctx; |
| 463 | u8 *buf; |
| 464 | |
| 465 | buf = malloc(BUF_SIZE); |
| 466 | ut_assertnonnull(buf); |
| 467 | |
| 468 | ctx.current = buf; |
| 469 | buf[4] = 'z'; /* sentinel */ |
| 470 | ut_assertok(acpi_inject_dsdt(&ctx)); |
| 471 | |
| 472 | /* |
| 473 | * These values come from acpi-test's acpi-dsdt-test-data property. |
| 474 | * There is no u-boot,acpi-dsdt-order so device-tree order is used. |
| 475 | */ |
| 476 | ut_asserteq('h', buf[0]); |
| 477 | ut_asserteq('i', buf[1]); |
| 478 | |
| 479 | /* These values come from acpi-test's acpi-dsdt-test-data property */ |
| 480 | ut_asserteq('j', buf[2]); |
| 481 | ut_asserteq('k', buf[3]); |
| 482 | |
| 483 | ut_asserteq('z', buf[4]); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | DM_TEST(dm_test_acpi_inject_dsdt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |