blob: 2057bd2bef8897c50255c4cd1e39d207a0c93857 [file] [log] [blame]
Simon Glass94ba15a2021-12-01 09:02:50 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Write base ACPI tables
4 *
5 * Copyright 2021 Google LLC
6 */
7
Simon Glasseacb6d02021-12-01 09:02:52 -07008#define LOG_CATEGORY LOGC_ACPI
9
Simon Glass94ba15a2021-12-01 09:02:50 -070010#include <common.h>
11#include <acpi/acpi_table.h>
12#include <dm/acpi.h>
13#include <mapmem.h>
14#include <tables_csum.h>
15
16void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
17 struct acpi_xsdt *xsdt)
18{
19 memset(rsdp, 0, sizeof(struct acpi_rsdp));
20
21 memcpy(rsdp->signature, RSDP_SIG, 8);
22 memcpy(rsdp->oem_id, OEM_ID, 6);
23
24 rsdp->length = sizeof(struct acpi_rsdp);
25 rsdp->rsdt_address = map_to_sysmem(rsdt);
26
27 rsdp->xsdt_address = map_to_sysmem(xsdt);
28 rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
29
30 /* Calculate checksums */
31 rsdp->checksum = table_compute_checksum(rsdp, 20);
32 rsdp->ext_checksum = table_compute_checksum(rsdp,
33 sizeof(struct acpi_rsdp));
34}
35
36static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
37{
38 struct acpi_table_header *header = &rsdt->header;
39
40 /* Fill out header fields */
41 acpi_fill_header(header, "RSDT");
42 header->length = sizeof(struct acpi_rsdt);
43 header->revision = 1;
44
45 /* Entries are filled in later, we come with an empty set */
46
47 /* Fix checksum */
48 header->checksum = table_compute_checksum(rsdt,
49 sizeof(struct acpi_rsdt));
50}
51
52static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
53{
54 struct acpi_table_header *header = &xsdt->header;
55
56 /* Fill out header fields */
57 acpi_fill_header(header, "XSDT");
58 header->length = sizeof(struct acpi_xsdt);
59 header->revision = 1;
60
61 /* Entries are filled in later, we come with an empty set */
62
63 /* Fix checksum */
64 header->checksum = table_compute_checksum(xsdt,
65 sizeof(struct acpi_xsdt));
66}
67
68static int acpi_write_base(struct acpi_ctx *ctx,
69 const struct acpi_writer *entry)
70{
71 /* We need at least an RSDP and an RSDT Table */
72 ctx->rsdp = ctx->current;
73 acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
74 ctx->rsdt = ctx->current;
75 acpi_inc_align(ctx, sizeof(struct acpi_rsdt));
76 ctx->xsdt = ctx->current;
77 acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
78
79 /* clear all table memory */
80 memset(ctx->base, '\0', ctx->current - ctx->base);
81
82 acpi_write_rsdp(ctx->rsdp, ctx->rsdt, ctx->xsdt);
83 acpi_write_rsdt(ctx->rsdt);
84 acpi_write_xsdt(ctx->xsdt);
85
86 return 0;
87}
88/*
89 * Per ACPI spec, the FACS table address must be aligned to a 64-byte boundary
90 * (Windows checks this, but Linux does not).
91 *
92 * Use the '0' prefix to put this one first
93 */
94ACPI_WRITER(0base, NULL, acpi_write_base, ACPIWF_ALIGN64);