[PATCH v2 0/2] acpi: consider XSDT in acpi_find_table()

The RSDT table is deprecated and does not exist on all systems.
By preference scan XSDT for the table to find. If no XSDT table exists, try to use the RSDT table.
Provide a unit test for acpi_find_table().
v2: Consider that map_sysmem(0, 0) != NULL. Add unit test.
*** BLURB HERE ***
Heinrich Schuchardt (2): acpi: consider XSDT in acpi_find_table() test: unit test for acpi_find_table()
lib/acpi/acpi.c | 20 ++++++++--- test/dm/acpi.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 4 deletions(-)

The RSDT table is deprecated and does not exist on all systems.
By preference scan XSDT for the table to find. If no XSDT table exists, try to use the RSDT table.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- v2: consider that map_sysmem(0, 0) != NULL --- lib/acpi/acpi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c index 14b15754f4..f21e509461 100644 --- a/lib/acpi/acpi.c +++ b/lib/acpi/acpi.c @@ -16,18 +16,30 @@ struct acpi_table_header *acpi_find_table(const char *sig) { struct acpi_rsdp *rsdp; struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; int len, i, count;
rsdp = map_sysmem(gd_acpi_start(), 0); if (!rsdp) return NULL; - rsdt = map_sysmem(rsdp->rsdt_address, 0); - len = rsdt->header.length - sizeof(rsdt->header); - count = len / sizeof(u32); + if (rsdp->xsdt_address) { + xsdt = map_sysmem(rsdp->xsdt_address, 0); + len = xsdt->header.length - sizeof(xsdt->header); + count = len / sizeof(u64); + } else { + if (!rsdp->rsdt_address) + return NULL; + rsdt = map_sysmem(rsdp->rsdt_address, 0); + len = rsdt->header.length - sizeof(rsdt->header); + count = len / sizeof(u32); + } for (i = 0; i < count; i++) { struct acpi_table_header *hdr;
- hdr = map_sysmem(rsdt->entry[i], 0); + if (rsdp->xsdt_address) + hdr = map_sysmem(xsdt->entry[i], 0); + else + hdr = map_sysmem(rsdt->entry[i], 0); if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) return hdr; if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) {

On Sat, 18 Nov 2023 at 14:57, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
The RSDT table is deprecated and does not exist on all systems.
By preference scan XSDT for the table to find. If no XSDT table exists, try to use the RSDT table.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: consider that map_sysmem(0, 0) != NULL
lib/acpi/acpi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Sun, 19 Nov 2023 at 02:45, Simon Glass sjg@chromium.org wrote:
On Sat, 18 Nov 2023 at 14:57, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
The RSDT table is deprecated and does not exist on all systems.
By preference scan XSDT for the table to find. If no XSDT table exists, try to use the RSDT table.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: consider that map_sysmem(0, 0) != NULL
lib/acpi/acpi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Reviewed-by: Ilias Apalodimas ilias.apalodimas@linaro.org

On Sun, 19 Nov 2023 at 02:45, Simon Glass sjg@chromium.org wrote:
On Sat, 18 Nov 2023 at 14:57, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
The RSDT table is deprecated and does not exist on all systems.
By preference scan XSDT for the table to find. If no XSDT table exists, try to use the RSDT table.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: consider that map_sysmem(0, 0) != NULL
lib/acpi/acpi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Reviewed-by: Ilias Apalodimas ilias.apalodimas@linaro.org
Applied to u-boot-dm/next, thanks!

Provide a unit test for acpi_find_table()
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- v2: new patch --- test/dm/acpi.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)
diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 5997bda649..58cc6c3474 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -651,3 +651,99 @@ static int dm_test_acpi_cmd_set(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_cmd_set, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/** + * dm_test_write_test_table() - create test ACPI table + * + * Create an ACPI table TSTn, where n is given by @index. + * + * @ctx: ACPI table writing context + * @index: table index + * Return: generated table + */ +static struct acpi_table_header +*dm_test_write_test_table(struct acpi_ctx *ctx, int index) +{ + struct acpi_table_header *tbl = ctx->current; + char signature[5]; + + snprintf(signature, sizeof(signature), "TST%1d", index); + memset(tbl, 0, sizeof(*tbl)); + acpi_fill_header(tbl, signature); + acpi_inc(ctx, sizeof(struct acpi_table_header)); + tbl->length = (u8 *)ctx->current - (u8 *)tbl; + tbl->checksum = table_compute_checksum(tbl, tbl->length); + acpi_add_table(ctx, tbl); + + return tbl; +} + +/* Test acpi_find_table() */ +static int dm_test_acpi_find_table(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + ulong acpi_start, addr; + void *buf; + struct acpi_table_header *table, *table1, *table2, *table3; + struct acpi_rsdp *rsdp; + ulong rsdt; + ulong xsdt; + + /* Keep reference to original ACPI tables */ + acpi_start = gd_acpi_start(); + + /* Setup new ACPI tables */ + buf = memalign(16, BUF_SIZE); + ut_assertnonnull(buf); + addr = map_to_sysmem(buf); + ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr)); + table3 = dm_test_write_test_table(&ctx, 3); + table1 = dm_test_write_test_table(&ctx, 1); + table2 = dm_test_write_test_table(&ctx, 2); + + /* Retrieve RSDP, RSDT, XSDT */ + rsdp = map_sysmem(gd_acpi_start(), 0); + ut_assertnonnull(rsdp); + rsdt = rsdp->rsdt_address; + ut_assert(rsdt); + xsdt = rsdp->xsdt_address; + ut_assert(xsdt); + + /* Find with both RSDT and XSDT */ + table = acpi_find_table("TST1"); + ut_asserteq_ptr(table1, table); + ut_asserteq_strn("TST1", table->signature); + table = acpi_find_table("TST2"); + ut_asserteq_ptr(table2, table); + ut_asserteq_strn("TST2", table->signature); + table = acpi_find_table("TST3"); + ut_asserteq_ptr(table3, table); + ut_asserteq_strn("TST3", table->signature); + + /* Find with XSDT only */ + rsdp->rsdt_address = 0; + table = acpi_find_table("TST1"); + ut_asserteq_ptr(table1, table); + table = acpi_find_table("TST2"); + ut_asserteq_ptr(table2, table); + table = acpi_find_table("TST3"); + ut_asserteq_ptr(table3, table); + rsdp->rsdt_address = rsdt; + + /* Find with RSDT only */ + rsdp->xsdt_address = 0; + table = acpi_find_table("TST1"); + ut_asserteq_ptr(table1, table); + table = acpi_find_table("TST2"); + ut_asserteq_ptr(table2, table); + table = acpi_find_table("TST3"); + ut_asserteq_ptr(table3, table); + rsdp->xsdt_address = xsdt; + + /* Restore previous ACPI tables */ + gd_set_acpi_start(acpi_start); + free(buf); + + return 0; +} +DM_TEST(dm_test_acpi_find_table, 0);

On Sat, 18 Nov 2023 at 14:57, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
Provide a unit test for acpi_find_table()
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: new patch
test/dm/acpi.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Sat, 18 Nov 2023 at 14:57, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
Provide a unit test for acpi_find_table()
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: new patch
test/dm/acpi.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm/next, thanks!
participants (3)
-
Heinrich Schuchardt
-
Ilias Apalodimas
-
Simon Glass