blob: 5c755b14c161cf25077aaff596b29e169b590e91 [file] [log] [blame]
Simon Glasse9f6e6a2021-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 Glass83c3cb52021-12-01 09:02:52 -07008#define LOG_CATEGORY LOGC_ACPI
9
Simon Glasse9f6e6a2021-12-01 09:02:50 -070010#include <acpi/acpi_table.h>
11#include <dm/acpi.h>
12#include <mapmem.h>
13#include <tables_csum.h>
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010014#include <linux/sizes.h>
Tom Rinia877ce12023-12-14 13:16:58 -050015#include <linux/errno.h>
16#include <linux/string.h>
Simon Glasse9f6e6a2021-12-01 09:02:50 -070017
18void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
19 struct acpi_xsdt *xsdt)
20{
21 memset(rsdp, 0, sizeof(struct acpi_rsdp));
22
23 memcpy(rsdp->signature, RSDP_SIG, 8);
24 memcpy(rsdp->oem_id, OEM_ID, 6);
25
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010026 if (rsdt)
Simon Glass919f8352023-12-31 08:25:54 -070027 rsdp->rsdt_address = nomap_to_sysmem(rsdt);
Simon Glasse9f6e6a2021-12-01 09:02:50 -070028
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010029 if (xsdt)
Simon Glass919f8352023-12-31 08:25:54 -070030 rsdp->xsdt_address = nomap_to_sysmem(xsdt);
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010031
32 rsdp->length = sizeof(struct acpi_rsdp);
Simon Glasse9f6e6a2021-12-01 09:02:50 -070033 rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
34
35 /* Calculate checksums */
36 rsdp->checksum = table_compute_checksum(rsdp, 20);
37 rsdp->ext_checksum = table_compute_checksum(rsdp,
38 sizeof(struct acpi_rsdp));
39}
40
41static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
42{
43 struct acpi_table_header *header = &rsdt->header;
44
45 /* Fill out header fields */
46 acpi_fill_header(header, "RSDT");
47 header->length = sizeof(struct acpi_rsdt);
48 header->revision = 1;
49
50 /* Entries are filled in later, we come with an empty set */
51
52 /* Fix checksum */
Heinrich Schuchardt7b332b52025-03-22 00:21:17 +010053 acpi_update_checksum(header);
Simon Glasse9f6e6a2021-12-01 09:02:50 -070054}
55
56static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
57{
58 struct acpi_table_header *header = &xsdt->header;
59
60 /* Fill out header fields */
61 acpi_fill_header(header, "XSDT");
62 header->length = sizeof(struct acpi_xsdt);
63 header->revision = 1;
64
65 /* Entries are filled in later, we come with an empty set */
66
67 /* Fix checksum */
Heinrich Schuchardt7b332b52025-03-22 00:21:17 +010068 acpi_update_checksum(header);
Simon Glasse9f6e6a2021-12-01 09:02:50 -070069}
70
71static int acpi_write_base(struct acpi_ctx *ctx,
72 const struct acpi_writer *entry)
73{
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010074 /* We need at least an RSDP and an XSDT Table */
Simon Glasse9f6e6a2021-12-01 09:02:50 -070075 ctx->rsdp = ctx->current;
76 acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010077 if (map_to_sysmem(ctx->current) < SZ_4G - SZ_64K) {
78 ctx->rsdt = ctx->current;
79 acpi_inc_align(ctx, sizeof(struct acpi_rsdt));
80 } else {
81 ctx->rsdt = 0;
82 }
Simon Glasse9f6e6a2021-12-01 09:02:50 -070083 ctx->xsdt = ctx->current;
84 acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
85
86 /* clear all table memory */
87 memset(ctx->base, '\0', ctx->current - ctx->base);
88
89 acpi_write_rsdp(ctx->rsdp, ctx->rsdt, ctx->xsdt);
Heinrich Schuchardt266e8e22023-11-13 00:53:56 +010090 if (ctx->rsdt)
91 acpi_write_rsdt(ctx->rsdt);
Simon Glasse9f6e6a2021-12-01 09:02:50 -070092 acpi_write_xsdt(ctx->xsdt);
93
94 return 0;
95}
96/*
97 * Per ACPI spec, the FACS table address must be aligned to a 64-byte boundary
98 * (Windows checks this, but Linux does not).
99 *
100 * Use the '0' prefix to put this one first
101 */
102ACPI_WRITER(0base, NULL, acpi_write_base, ACPIWF_ALIGN64);