aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86/lib/acpi_table.c6
-rw-r--r--include/acpi/acpi_table.h10
-rw-r--r--include/dm/acpi.h12
-rw-r--r--lib/acpi/Makefile1
-rw-r--r--lib/acpi/acpi_table.c11
-rw-r--r--lib/acpi/acpi_writer.c22
-rw-r--r--test/dm/acpi.c31
7 files changed, 65 insertions, 28 deletions
diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 3f847711e2b..f57323b5c3f 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -522,17 +522,17 @@ ulong write_acpi_tables(ulong start_addr)
int ret;
int i;
- ctx = calloc(1, sizeof(*ctx));
+ ctx = malloc(sizeof(*ctx));
if (!ctx)
return log_msg_ret("mem", -ENOMEM);
- gd->acpi_ctx = ctx;
start = map_sysmem(start_addr, 0);
debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
acpi_reset_items();
- acpi_setup_base_tables(ctx, start);
+ acpi_setup_ctx(ctx, start);
+ acpi_setup_base_tables(ctx);
debug("ACPI: * FACS\n");
facs = ctx->current;
diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index d3fbdc1de2b..f34bd6311a1 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -679,14 +679,14 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount);
int acpi_add_table(struct acpi_ctx *ctx, void *table);
/**
- * acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT
+ * acpi_setup_base_tables() - Set up base tables - RSDP, RSDT and XSDT
*
- * Set up the context with the given start position. Some basic tables are
- * always needed, so set them up as well.
+ * Writes the basic tables to the given context, which must first be set up with
+ * acpi_setup_ctx().
*
- * @ctx: Context to set up
+ * @ctx: Context to write base tables to
*/
-void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start);
+void acpi_setup_base_tables(struct acpi_ctx *ctx);
/**
* acpi_write_rsdp() - Write out an RSDP indicating where the ACPI tables are
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index 2f52950d16e..f6e54793f79 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -297,6 +297,18 @@ void acpi_reset_items(void);
*/
int acpi_write_one(struct acpi_ctx *ctx, const struct acpi_writer *entry);
+/**
+ * acpi_setup_ctx() - Set up a new ACPI context
+ *
+ * This zeros the context and sets up the base and current pointers, ensuring
+ * that they are aligned. Then it writes the acpi_start and acpi_ctx values in
+ * global_data
+ *
+ * @ctx: ACPI context to set up
+ * @start: Start address for ACPI table
+ */
+void acpi_setup_ctx(struct acpi_ctx *ctx, ulong start);
+
#endif /* __ACPI__ */
#endif
diff --git a/lib/acpi/Makefile b/lib/acpi/Makefile
index f5d58aba908..1318e83dfc4 100644
--- a/lib/acpi/Makefile
+++ b/lib/acpi/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_$(SPL_)ACPIGEN) += acpigen.o
obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi_device.o
obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi_dp.o
obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi_table.o
+obj-y += acpi_writer.o
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 3a72718df89..284b5a9afb8 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -253,15 +253,8 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
sizeof(struct acpi_xsdt));
}
-void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)
+void acpi_setup_base_tables(struct acpi_ctx *ctx)
{
- ctx->base = start;
- ctx->current = start;
-
- /* Align ACPI tables to 16 byte */
- acpi_align(ctx);
- gd_set_acpi_start(map_to_sysmem(ctx->current));
-
/* We need at least an RSDP and an RSDT Table */
ctx->rsdp = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
@@ -271,7 +264,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)
acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
/* clear all table memory */
- memset((void *)start, '\0', ctx->current - start);
+ memset(ctx->base, '\0', ctx->current - ctx->base);
acpi_write_rsdp(ctx->rsdp, ctx->rsdt, ctx->xsdt);
acpi_write_rsdt(ctx->rsdt);
diff --git a/lib/acpi/acpi_writer.c b/lib/acpi/acpi_writer.c
index 5ddffc87343..7779bf38aab 100644
--- a/lib/acpi/acpi_writer.c
+++ b/lib/acpi/acpi_writer.c
@@ -60,23 +60,20 @@ static int acpi_write_all(struct acpi_ctx *ctx)
/*
* QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
*/
-ulong write_acpi_tables(ulong start_addr)
+ulong new_write_acpi_tables(ulong start_addr)
{
struct acpi_ctx *ctx;
ulong addr;
- void *start;
int ret;
- ctx = calloc(1, sizeof(*ctx));
+ ctx = malloc(sizeof(*ctx));
if (!ctx)
return log_msg_ret("mem", -ENOMEM);
- gd->acpi_ctx = ctx;
-
- start = map_sysmem(start_addr, 0);
log_debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
acpi_reset_items();
+ acpi_setup_ctx(ctx, start_addr);
ret = acpi_write_all(ctx);
if (ret) {
@@ -89,3 +86,16 @@ ulong write_acpi_tables(ulong start_addr)
return addr;
}
+
+void acpi_setup_ctx(struct acpi_ctx *ctx, ulong start)
+{
+ gd->acpi_ctx = ctx;
+ memset(ctx, '\0', sizeof(*ctx));
+
+ /* Align ACPI tables to 16-byte boundary */
+ start = ALIGN(start, 16);
+ ctx->base = map_sysmem(start, 0);
+ ctx->current = ctx->base;
+
+ gd_set_acpi_start(start);
+}
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 804124df9e9..a1d70b58597 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -45,6 +45,22 @@ struct testacpi_plat {
bool no_name;
};
+/**
+ * setup_ctx_and_base_tables() - Set up context along with RSDP, RSDT and XSDT
+ *
+ * Set up the context with the given start position. Some basic tables are
+ * always needed, so set them up as well.
+ *
+ * @ctx: Context to set up
+ */
+static int setup_ctx_and_base_tables(struct acpi_ctx *ctx, ulong start)
+{
+ acpi_setup_ctx(ctx, start);
+ acpi_setup_base_tables(ctx);
+
+ return 0;
+}
+
static int testacpi_write_tables(const struct udevice *dev,
struct acpi_ctx *ctx)
{
@@ -240,13 +256,15 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)
{
struct acpi_dmar *dmar;
struct acpi_ctx ctx;
+ ulong addr;
void *buf;
int i;
buf = malloc(BUF_SIZE);
ut_assertnonnull(buf);
+ addr = map_to_sysmem(buf);
- acpi_setup_base_tables(&ctx, buf);
+ setup_ctx_and_base_tables(&ctx, addr);
dmar = ctx.current;
ut_assertok(acpi_write_dev_tables(&ctx));
@@ -312,6 +330,7 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts)
struct acpi_xsdt *xsdt;
struct acpi_ctx ctx;
void *buf, *end;
+ ulong addr;
/*
* Use an unaligned address deliberately, by allocating an aligned
@@ -319,7 +338,8 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts)
*/
buf = memalign(64, BUF_SIZE);
ut_assertnonnull(buf);
- acpi_setup_base_tables(&ctx, buf + 4);
+ addr = map_to_sysmem(buf);
+ setup_ctx_and_base_tables(&ctx, addr + 4);
ut_asserteq(map_to_sysmem(PTR_ALIGN(buf + 4, 16)), gd_acpi_start());
rsdp = buf + 16;
@@ -361,13 +381,13 @@ static int dm_test_acpi_cmd_list(struct unit_test_state *uts)
buf = memalign(16, BUF_SIZE);
ut_assertnonnull(buf);
- acpi_setup_base_tables(&ctx, buf);
+ addr = map_to_sysmem(buf);
+ setup_ctx_and_base_tables(&ctx, addr);
ut_assertok(acpi_write_dev_tables(&ctx));
console_record_reset();
run_command("acpi list", 0);
- addr = (ulong)map_to_sysmem(buf);
ut_assert_nextline("ACPI tables start at %lx", addr);
ut_assert_nextline("RSDP %08lx %06zx (v02 U-BOOT)", addr,
sizeof(struct acpi_rsdp));
@@ -403,7 +423,8 @@ static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
buf = memalign(16, BUF_SIZE);
ut_assertnonnull(buf);
- acpi_setup_base_tables(&ctx, buf);
+ addr = map_to_sysmem(buf);
+ setup_ctx_and_base_tables(&ctx, addr);
ut_assertok(acpi_write_dev_tables(&ctx));