diff options
author | Simon Glass <sjg@chromium.org> | 2020-04-26 09:19:51 -0600 |
---|---|---|
committer | Bin Meng <bmeng.cn@gmail.com> | 2020-04-30 17:16:12 +0800 |
commit | 7e586f69070db02171dca77f41adbcccd6394b33 (patch) | |
tree | e3215822437a057ffbd20f8eefb6790ac22adb84 /test | |
parent | 29b351122ed23124f70473a411c65074d5a61146 (diff) | |
download | u-boot-7e586f69070db02171dca77f41adbcccd6394b33.tar.gz |
acpi: Put table-setup code in its own function
We always write three basic tables to ACPI at the start. Move this into
its own function, along with acpi_fill_header(), so we can write a test
for this code.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/acpi.c | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 99ae321e0a..beb1b6da73 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -8,7 +8,9 @@ #include <common.h> #include <dm.h> +#include <malloc.h> #include <mapmem.h> +#include <tables_csum.h> #include <version.h> #include <acpi/acpi_table.h> #include <dm/acpi.h> @@ -132,23 +134,14 @@ DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); static int dm_test_acpi_write_tables(struct unit_test_state *uts) { struct acpi_dmar *dmar; - struct acpi_xsdt *xsdt; struct acpi_ctx ctx; void *buf; buf = malloc(BUF_SIZE); ut_assertnonnull(buf); - ctx.current = buf; - ctx.rsdp = ctx.current; - acpi_inc_align(&ctx, sizeof(struct acpi_rsdp)); - ctx.rsdt = ctx.current; - acpi_inc_align(&ctx, sizeof(struct acpi_rsdt)); - xsdt = ctx.current; - acpi_inc_align(&ctx, sizeof(struct acpi_xsdt)); - ctx.rsdp->xsdt_address = map_to_sysmem(xsdt); + acpi_setup_base_tables(&ctx, buf); dmar = ctx.current; - ut_assertok(acpi_write_dev_tables(&ctx)); /* @@ -162,6 +155,11 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags); ut_asserteq(32 - 1, dmar[1].host_address_width); + /* Check that the pointers were added correctly */ + ut_asserteq(map_to_sysmem(dmar), ctx.rsdt->entry[0]); + ut_asserteq(map_to_sysmem(dmar + 1), ctx.rsdt->entry[1]); + ut_asserteq(0, ctx.rsdt->entry[2]); + return 0; } DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); @@ -193,3 +191,49 @@ static int dm_test_acpi_basic(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_basic, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test acpi_setup_base_tables */ +static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) +{ + struct acpi_rsdp *rsdp; + struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; + struct acpi_ctx ctx; + void *buf, *end; + + /* + * Use an unaligned address deliberately, by allocating an aligned + * address and then adding 4 to it + */ + buf = memalign(64, BUF_SIZE); + ut_assertnonnull(buf); + acpi_setup_base_tables(&ctx, buf + 4); + + rsdp = buf + 16; + ut_asserteq_ptr(rsdp, ctx.rsdp); + ut_assertok(memcmp(RSDP_SIG, rsdp->signature, sizeof(rsdp->signature))); + ut_asserteq(sizeof(*rsdp), rsdp->length); + ut_assertok(table_compute_checksum(rsdp, 20)); + ut_assertok(table_compute_checksum(rsdp, sizeof(*rsdp))); + + rsdt = PTR_ALIGN((void *)rsdp + sizeof(*rsdp), 16); + ut_asserteq_ptr(rsdt, ctx.rsdt); + ut_assertok(memcmp("RSDT", rsdt->header.signature, ACPI_NAME_LEN)); + ut_asserteq(sizeof(*rsdt), rsdt->header.length); + ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt))); + + xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16); + ut_assertok(memcmp("XSDT", xsdt->header.signature, ACPI_NAME_LEN)); + ut_asserteq(sizeof(*xsdt), xsdt->header.length); + ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt))); + + end = PTR_ALIGN((void *)xsdt + sizeof(*xsdt), 64); + ut_asserteq_ptr(end, ctx.current); + + ut_asserteq(map_to_sysmem(rsdt), rsdp->rsdt_address); + ut_asserteq(map_to_sysmem(xsdt), rsdp->xsdt_address); + + return 0; +} +DM_TEST(dm_test_acpi_setup_base_tables, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |