1 // SPDX-License-Identifier: GPL-2.0+
3 * Write the ACPI Differentiated System Description Table (DSDT)
5 * Copyright 2021 Google LLC
8 #define LOG_CATEGORY LOGC_ACPI
10 #include <acpi/acpi_table.h>
12 #include <tables_csum.h>
13 #include <linux/string.h>
16 * IASL compiles the dsdt entries and writes the hex values
17 * to a C array AmlCode[] (see dsdt.c).
19 extern const unsigned char AmlCode[];
21 int acpi_write_dsdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
23 const int thl = sizeof(struct acpi_table_header);
24 struct acpi_table_header *dsdt = ctx->current;
27 /* Put the table header first */
28 memcpy(dsdt, &AmlCode, thl);
30 log_debug("DSDT starts at %p, hdr ends at %p\n", dsdt, ctx->current);
32 /* If the table is not empty, allow devices to inject things */
33 aml_len = dsdt->length - thl;
35 void *base = ctx->current;
38 ret = acpi_inject_dsdt(ctx);
40 return log_msg_ret("inject", ret);
41 log_debug("Added %lx bytes from inject_dsdt, now at %p\n",
42 (ulong)(ctx->current - base), ctx->current);
43 log_debug("Copy AML code size %x to %p\n", aml_len,
45 memcpy(ctx->current, AmlCode + thl, aml_len);
46 acpi_inc(ctx, aml_len);
50 dsdt->length = ctx->current - (void *)dsdt;
51 log_debug("Updated DSDT length to %x\n", dsdt->length);
55 ACPI_WRITER(3dsdt, "DSDT", acpi_write_dsdt, 0);