summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-12-01 09:02:52 -0700
committerSimon Glass <sjg@chromium.org>2022-01-25 11:44:36 -0700
commiteacb6d0ba205cae472c46a974fb16fcd783680b1 (patch)
tree00afb259abc994ce05bcda9e90d51af538c147e7 /lib
parenta53d38f80a1b7833a7efad6412fbd0b17cc33a99 (diff)
x86: Move DSDT table to a writer function
Move this table over to use a writer function, moving the code from the x86 implementation. Add a pointer to the DSDT in struct acpi_ctx so we can reference it later. Disable this table for sandbox since we don't actually compile real ASL code. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/acpi/Makefile6
-rw-r--r--lib/acpi/base.c2
-rw-r--r--lib/acpi/dsdt.c55
-rw-r--r--lib/acpi/facs.c2
4 files changed, 65 insertions, 0 deletions
diff --git a/lib/acpi/Makefile b/lib/acpi/Makefile
index 9f70fe69d3..ccdf42896d 100644
--- a/lib/acpi/Makefile
+++ b/lib/acpi/Makefile
@@ -10,5 +10,11 @@ obj-y += acpi_writer.o
# With QEMU the ACPI tables come from there, not from U-Boot
ifndef CONFIG_QEMU
obj-y += base.o
+
+# Sandbox does not build a .asl file
+ifndef CONFIG_SANDBOX
+obj-y += dsdt.o
+endif
+
obj-y += facs.o
endif
diff --git a/lib/acpi/base.c b/lib/acpi/base.c
index 3e8d703934..2057bd2bef 100644
--- a/lib/acpi/base.c
+++ b/lib/acpi/base.c
@@ -5,6 +5,8 @@
* Copyright 2021 Google LLC
*/
+#define LOG_CATEGORY LOGC_ACPI
+
#include <common.h>
#include <acpi/acpi_table.h>
#include <dm/acpi.h>
diff --git a/lib/acpi/dsdt.c b/lib/acpi/dsdt.c
new file mode 100644
index 0000000000..db98cc20e1
--- /dev/null
+++ b/lib/acpi/dsdt.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Write the ACPI Differentiated System Description Table (DSDT)
+ *
+ * Copyright 2021 Google LLC
+ */
+
+#define LOG_CATEGORY LOGC_ACPI
+
+#include <common.h>
+#include <acpi/acpi_table.h>
+#include <dm/acpi.h>
+#include <tables_csum.h>
+
+/*
+ * IASL compiles the dsdt entries and writes the hex values
+ * to a C array AmlCode[] (see dsdt.c).
+ */
+extern const unsigned char AmlCode[];
+
+int acpi_write_dsdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
+{
+ const int thl = sizeof(struct acpi_table_header);
+ struct acpi_table_header *dsdt = ctx->current;
+ int aml_len;
+
+ /* Put the table header first */
+ memcpy(dsdt, &AmlCode, thl);
+ acpi_inc(ctx, thl);
+ log_debug("DSDT starts at %p, hdr ends at %p\n", dsdt, ctx->current);
+
+ /* If the table is not empty, allow devices to inject things */
+ aml_len = dsdt->length - thl;
+ if (aml_len) {
+ void *base = ctx->current;
+ int ret;
+
+ ret = acpi_inject_dsdt(ctx);
+ if (ret)
+ return log_msg_ret("inject", ret);
+ log_debug("Added %lx bytes from inject_dsdt, now at %p\n",
+ (ulong)(ctx->current - base), ctx->current);
+ log_debug("Copy AML code size %x to %p\n", aml_len,
+ ctx->current);
+ memcpy(ctx->current, AmlCode + thl, aml_len);
+ acpi_inc(ctx, aml_len);
+ }
+
+ ctx->dsdt = dsdt;
+ dsdt->length = ctx->current - (void *)dsdt;
+ log_debug("Updated DSDT length to %x\n", dsdt->length);
+
+ return 0;
+}
+ACPI_WRITER(3dsdt, "DSDT", acpi_write_dsdt, 0);
diff --git a/lib/acpi/facs.c b/lib/acpi/facs.c
index 8a1568fbaa..e89f43ca5c 100644
--- a/lib/acpi/facs.c
+++ b/lib/acpi/facs.c
@@ -5,6 +5,8 @@
* Copyright 2021 Google LLC
*/
+#define LOG_CATEGORY LOGC_ACPI
+
#include <common.h>
#include <acpi/acpi_table.h>
#include <dm/acpi.h>