Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 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 | |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 10 | #include <mapmem.h> |
| 11 | #include <tables_csum.h> |
| 12 | #include <acpi/acpi_table.h> |
| 13 | #include <dm/acpi.h> |
Tom Rini | a877ce1 | 2023-12-14 13:16:58 -0500 | [diff] [blame] | 14 | #include <linux/string.h> |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 15 | |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 16 | __weak int acpi_fill_csrt(struct acpi_ctx *ctx) |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 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; |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 25 | int ret; |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 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"); |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 34 | header->revision = 0; |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 35 | acpi_inc(ctx, sizeof(*header)); |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 36 | |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 37 | ret = acpi_fill_csrt(ctx); |
| 38 | if (ret) |
| 39 | return log_msg_ret("fill", ret); |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 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); |
Simon Glass | 6e6bc9b | 2021-12-01 09:03:00 -0700 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | ACPI_WRITER(5csrt, "CSRT", acpi_write_csrt, 0); |