]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
x86: Move GNVS table to a writer function
authorSimon Glass <sjg@chromium.org>
Wed, 1 Dec 2021 16:02:53 +0000 (09:02 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 25 Jan 2022 18:44:36 +0000 (11:44 -0700)
Move this table over to use a writer function, for x86 only. Handle the
two cases

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/x86/lib/acpi_table.c

index e0c76ab279f026c4a2917bcc86dc9454cb5398d5..cff47b5b386acd52c31b6bb4dd30af0596e62602 100644 (file)
@@ -479,66 +479,65 @@ static int acpi_create_ssdt(struct acpi_ctx *ctx,
        return 0;
 }
 
-/*
- * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
- */
-static int write_acpi_tables_x86(struct acpi_ctx *ctx,
-                                const struct acpi_writer *entry)
+int acpi_write_gnvs(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 {
-       struct acpi_fadt *fadt;
-       struct acpi_table_header *ssdt;
-       struct acpi_mcfg *mcfg;
-       struct acpi_tcpa *tcpa;
-       struct acpi_madt *madt;
-       struct acpi_csrt *csrt;
-       struct acpi_spcr *spcr;
        ulong addr;
-       int ret;
-       int i;
 
        if (!IS_ENABLED(CONFIG_ACPI_GNVS_EXTERNAL)) {
+               int i;
+
+               /* We need the DSDT to be done */
+               if (!ctx->dsdt)
+                       return log_msg_ret("dsdt", -EAGAIN);
+
                /* Pack GNVS into the ACPI table area */
                for (i = 0; i < ctx->dsdt->length; i++) {
                        u32 *gnvs = (u32 *)((u32)ctx->dsdt + i);
 
                        if (*gnvs == ACPI_GNVS_ADDR) {
                                *gnvs = map_to_sysmem(ctx->current);
-                               debug("Fix up global NVS in DSDT to %#08x\n",
-                                     *gnvs);
+                               log_debug("Fix up global NVS in DSDT to %#08x\n",
+                                         *gnvs);
                                break;
                        }
                }
 
                /*
-                * Fill in platform-specific global NVS variables. If this fails
-                * we cannot return the error but this should only happen while
-                * debugging.
+                * Recalculate the length and update the DSDT checksum since we
+                * patched the GNVS address. Set the checksum to zero since it
+                * is part of the region being checksummed.
                 */
-               addr = acpi_create_gnvs(ctx->current);
-               if (IS_ERR_VALUE(addr))
-                       printf("Error: Gailed to create GNVS\n");
-               acpi_inc_align(ctx, sizeof(struct acpi_global_nvs));
+               ctx->dsdt->checksum = 0;
+               ctx->dsdt->checksum = table_compute_checksum((void *)ctx->dsdt,
+                                                            ctx->dsdt->length);
        }
 
-       /*
-        * Recalculate the length and update the DSDT checksum since we patched
-        * the GNVS address. Set the checksum to zero since it is part of the
-        * region being checksummed.
-        */
-       ctx->dsdt->checksum = 0;
-       ctx->dsdt->checksum = table_compute_checksum((void *)ctx->dsdt,
-                                                    ctx->dsdt->length);
-
-       /*
-        * Fill in platform-specific global NVS variables. If this fails we
-        * cannot return the error but this should only happen while debugging.
-        */
+       /* Fill in platform-specific global NVS variables */
        addr = acpi_create_gnvs(ctx->current);
        if (IS_ERR_VALUE(addr))
-               printf("Error: Failed to create GNVS\n");
+               return log_msg_ret("gnvs", (int)addr);
 
        acpi_inc_align(ctx, sizeof(struct acpi_global_nvs));
 
+       return 0;
+}
+ACPI_WRITER(4gnvs, "GNVS", acpi_write_gnvs, 0);
+
+/*
+ * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
+ */
+int write_acpi_tables_x86(struct acpi_ctx *ctx,
+                         const struct acpi_writer *entry)
+{
+       struct acpi_fadt *fadt;
+       struct acpi_table_header *ssdt;
+       struct acpi_mcfg *mcfg;
+       struct acpi_tcpa *tcpa;
+       struct acpi_madt *madt;
+       struct acpi_csrt *csrt;
+       struct acpi_spcr *spcr;
+       int ret;
+
        debug("ACPI:    * FADT\n");
        fadt = ctx->current;
        acpi_inc_align(ctx, sizeof(struct acpi_fadt));