blob: 206e1e2678ff6b76aab6699148fb3f58bd937c16 [file] [log] [blame]
Simon Glasseacb6d02021-12-01 09:02:52 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Write the ACPI Differentiated System Description Table (DSDT)
4 *
5 * Copyright 2021 Google LLC
6 */
7
8#define LOG_CATEGORY LOGC_ACPI
9
Simon Glasseacb6d02021-12-01 09:02:52 -070010#include <acpi/acpi_table.h>
11#include <dm/acpi.h>
12#include <tables_csum.h>
Tom Rini467382c2023-12-14 13:16:58 -050013#include <linux/string.h>
Simon Glasseacb6d02021-12-01 09:02:52 -070014
15/*
16 * IASL compiles the dsdt entries and writes the hex values
17 * to a C array AmlCode[] (see dsdt.c).
18 */
19extern const unsigned char AmlCode[];
20
21int acpi_write_dsdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
22{
23 const int thl = sizeof(struct acpi_table_header);
24 struct acpi_table_header *dsdt = ctx->current;
25 int aml_len;
26
27 /* Put the table header first */
28 memcpy(dsdt, &AmlCode, thl);
29 acpi_inc(ctx, thl);
30 log_debug("DSDT starts at %p, hdr ends at %p\n", dsdt, ctx->current);
31
32 /* If the table is not empty, allow devices to inject things */
33 aml_len = dsdt->length - thl;
34 if (aml_len) {
35 void *base = ctx->current;
36 int ret;
37
38 ret = acpi_inject_dsdt(ctx);
39 if (ret)
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,
44 ctx->current);
45 memcpy(ctx->current, AmlCode + thl, aml_len);
46 acpi_inc(ctx, aml_len);
47 }
48
49 ctx->dsdt = dsdt;
50 dsdt->length = ctx->current - (void *)dsdt;
51 log_debug("Updated DSDT length to %x\n", dsdt->length);
52
53 return 0;
54}
55ACPI_WRITER(3dsdt, "DSDT", acpi_write_dsdt, 0);