diff mbox series

[039/108] x86: Allow devices to write to DSDT

Message ID 20200126220508.39.I8b14735c2286701cc6be7d36b85bbad8ca58babd@changeid
State Superseded
Headers show
Series RFC: dm: Add programatic generation of ACPI tables | expand

Commit Message

Simon Glass Jan. 27, 2020, 5:05 a.m. UTC
Call the new core function to inject ASL programmatically into the DSDT.
This is made up of fragments generated by devices that have the
inject_dsdt() method. The normal, compiled ASL file is added after this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 arch/x86/lib/acpi_table.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 3b97fe162c..5e14149923 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -422,7 +422,20 @@  ulong write_acpi_tables(ulong start_addr)
 	memcpy(ctx->current,
 	       (char *)&AmlCode + sizeof(struct acpi_table_header),
 	       dsdt->length - sizeof(struct acpi_table_header));
-	acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header));
+
+	if (dsdt->length >= sizeof(struct acpi_table_header)) {
+		acpi_inject_dsdt(ctx);
+		memcpy(ctx->current,
+		       (char *)AmlCode + sizeof(struct acpi_table_header),
+		       dsdt->length - sizeof(struct acpi_table_header));
+		acpi_inc(ctx, dsdt->length - sizeof(struct acpi_table_header));
+
+		/* (Re)calculate length and checksum. */
+		dsdt->length = ctx->current - (void *)dsdt;
+		dsdt->checksum = 0;
+		dsdt->checksum = table_compute_checksum(dsdt, dsdt->length);
+	}
+	acpi_align(ctx);
 
 	/* Pack GNVS into the ACPI table area */
 	for (i = 0; i < dsdt->length; i++) {