x86: Move CSRT table to a writer function
[platform/kernel/u-boot.git] / lib / acpi / csrt.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Write an ACPI Core System Resource Table (CSRT)
4  *
5  * Copyright 2021 Google LLC
6  */
7
8 #define LOG_CATEGORY LOGC_ACPI
9
10 #include <common.h>
11 #include <mapmem.h>
12 #include <tables_csum.h>
13 #include <acpi/acpi_table.h>
14 #include <dm/acpi.h>
15
16 __weak u32 acpi_fill_csrt(u32 current)
17 {
18         return 0;
19 }
20
21 int acpi_write_csrt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
22 {
23         struct acpi_table_header *header;
24         struct acpi_csrt *csrt;
25         uint ptr;
26
27         csrt = ctx->current;
28         header = &csrt->header;
29
30         memset(csrt, '\0', sizeof(struct acpi_csrt));
31
32         /* Fill out header fields */
33         acpi_fill_header(header, "CSRT");
34         header->length = sizeof(struct acpi_csrt);
35         header->revision = 0;
36
37         ptr = acpi_fill_csrt(map_to_sysmem(csrt));
38         if (!ptr)
39                 return log_msg_ret("fill", -ENOENT);
40
41         /* (Re)calculate length and checksum */
42         header->length = (ulong)ctx->current - (ulong)csrt;
43         header->checksum = table_compute_checksum(csrt, header->length);
44
45         acpi_add_table(ctx, csrt);
46         acpi_inc(ctx, csrt->header.length);
47
48         return 0;
49 }
50 ACPI_WRITER(5csrt, "CSRT", acpi_write_csrt, 0);