summaryrefslogtreecommitdiff
path: root/lib/acpi/dsdt.c
blob: db98cc20e1d04576c076de62c8002ffd0c8f9f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: GPL-2.0+
/*
 * Write the ACPI Differentiated System Description Table (DSDT)
 *
 * Copyright 2021 Google LLC
 */

#define LOG_CATEGORY LOGC_ACPI

#include <common.h>
#include <acpi/acpi_table.h>
#include <dm/acpi.h>
#include <tables_csum.h>

/*
 * IASL compiles the dsdt entries and writes the hex values
 * to a C array AmlCode[] (see dsdt.c).
 */
extern const unsigned char AmlCode[];

int acpi_write_dsdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
{
	const int thl = sizeof(struct acpi_table_header);
	struct acpi_table_header *dsdt = ctx->current;
	int aml_len;

	/* Put the table header first */
	memcpy(dsdt, &AmlCode, thl);
	acpi_inc(ctx, thl);
	log_debug("DSDT starts at %p, hdr ends at %p\n", dsdt, ctx->current);

	/* If the table is not empty, allow devices to inject things */
	aml_len = dsdt->length - thl;
	if (aml_len) {
		void *base = ctx->current;
		int ret;

		ret = acpi_inject_dsdt(ctx);
		if (ret)
			return log_msg_ret("inject", ret);
		log_debug("Added %lx bytes from inject_dsdt, now at %p\n",
			  (ulong)(ctx->current - base), ctx->current);
		log_debug("Copy AML code size %x to %p\n", aml_len,
			  ctx->current);
		memcpy(ctx->current, AmlCode + thl, aml_len);
		acpi_inc(ctx, aml_len);
	}

	ctx->dsdt = dsdt;
	dsdt->length = ctx->current - (void *)dsdt;
	log_debug("Updated DSDT length to %x\n", dsdt->length);

	return 0;
}
ACPI_WRITER(3dsdt, "DSDT", acpi_write_dsdt, 0);