1
2
3
4
5
6
7
8#define LOG_CATEGORY LOGC_ACPI
9
10#include <common.h>
11#include <acpi/acpi_table.h>
12#include <dm/acpi.h>
13#include <tables_csum.h>
14
15
16
17
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
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
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);
56