Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Write an ACPI Secondary System Descriptor Table (SSDT) table |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | */ |
| 7 | |
| 8 | #define LOG_CATEGORY LOGC_ACPI |
| 9 | |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 10 | #include <acpi/acpi_table.h> |
| 11 | #include <dm/acpi.h> |
| 12 | #include <tables_csum.h> |
Tom Rini | a877ce1 | 2023-12-14 13:16:58 -0500 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | #include <linux/string.h> |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 15 | |
| 16 | int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 17 | { |
| 18 | struct acpi_table_header *ssdt; |
| 19 | int ret; |
| 20 | |
| 21 | ssdt = ctx->current; |
Heinrich Schuchardt | f252dfc | 2023-11-18 22:52:37 +0100 | [diff] [blame] | 22 | memset(ssdt, '\0', sizeof(struct acpi_table_header)); |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 23 | |
| 24 | acpi_fill_header(ssdt, "SSDT"); |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 25 | ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT); |
Heinrich Schuchardt | 10de8a8 | 2024-01-21 12:52:48 +0100 | [diff] [blame] | 26 | ssdt->creator_revision = 1; |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 27 | ssdt->length = sizeof(struct acpi_table_header); |
| 28 | |
| 29 | acpi_inc(ctx, sizeof(struct acpi_table_header)); |
| 30 | |
| 31 | ret = acpi_fill_ssdt(ctx); |
| 32 | if (ret) { |
| 33 | ctx->current = ssdt; |
| 34 | return log_msg_ret("fill", ret); |
| 35 | } |
| 36 | |
| 37 | /* (Re)calculate length and checksum */ |
| 38 | ssdt->length = ctx->current - (void *)ssdt; |
| 39 | ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length); |
| 40 | log_debug("SSDT at %p, length %x\n", ssdt, ssdt->length); |
| 41 | |
| 42 | /* Drop the table if it is empty */ |
| 43 | if (ssdt->length == sizeof(struct acpi_table_header)) |
| 44 | return log_msg_ret("fill", -ENOENT); |
| 45 | acpi_add_table(ctx, ssdt); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | ACPI_WRITER(6ssdt, "SSDT", acpi_write_ssdt, 0); |