]> Git Repo - J-u-boot.git/blob - lib/acpi/dsdt.c
Revert "acpi_table: Fix coverity defect in acpi_write_spcr"
[J-u-boot.git] / lib / acpi / dsdt.c
1 // 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
10 #include <acpi/acpi_table.h>
11 #include <dm/acpi.h>
12 #include <tables_csum.h>
13 #include <linux/string.h>
14
15 /*
16  * IASL compiles the dsdt entries and writes the hex values
17  * to a C array AmlCode[] (see dsdt.c).
18  */
19 extern const unsigned char AmlCode[];
20
21 int 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 }
55 ACPI_WRITER(3dsdt, "DSDT", acpi_write_dsdt, 0);
This page took 0.02815 seconds and 4 git commands to generate.