x86: acpi: Store the ACPI context in global_data
authorSimon Glass <sjg@chromium.org>
Wed, 4 Nov 2020 16:57:19 +0000 (09:57 -0700)
committerBin Meng <bmeng.cn@gmail.com>
Thu, 5 Nov 2020 06:58:45 +0000 (14:58 +0800)
At present we create the ACPI context but then drop it after generation of
tables is complete. This is annoying because we have to then search for
tables later.

To fix this, allocate the context and store it in global_data.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/lib/acpi_table.c
include/asm-generic/global_data.h

index 6d405b0..f0f342d 100644 (file)
@@ -494,7 +494,7 @@ void acpi_create_ssdt(struct acpi_ctx *ctx, struct acpi_table_header *ssdt,
  */
 ulong write_acpi_tables(ulong start_addr)
 {
-       struct acpi_ctx sctx, *ctx = &sctx;
+       struct acpi_ctx *ctx;
        struct acpi_facs *facs;
        struct acpi_table_header *dsdt;
        struct acpi_fadt *fadt;
@@ -509,6 +509,11 @@ ulong write_acpi_tables(ulong start_addr)
        int ret;
        int i;
 
+       ctx = calloc(1, 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);
index f392043..87d827d 100644 (file)
@@ -24,6 +24,7 @@
 #include <membuff.h>
 #include <linux/list.h>
 
+struct acpi_ctx;
 struct driver_rt;
 
 typedef struct global_data gd_t;
@@ -420,6 +421,12 @@ struct global_data {
         */
        struct udevice *watchdog_dev;
 #endif
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+       /**
+        * @acpi_ctx: ACPI context pointer
+        */
+       struct acpi_ctx *acpi_ctx;
+#endif
 };
 
 /**
@@ -452,6 +459,12 @@ struct global_data {
 #define gd_dm_driver_rt()              NULL
 #endif
 
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+#define gd_acpi_ctx()          gd->acpi_ctx
+#else
+#define gd_acpi_ctx()          NULL
+#endif
+
 /**
  * enum gd_flags - global data flags
  *