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 | |
| 10 | #include <common.h> |
| 11 | #include <acpi/acpi_table.h> |
| 12 | #include <dm/acpi.h> |
| 13 | #include <tables_csum.h> |
| 14 | |
| 15 | int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 16 | { |
| 17 | struct acpi_table_header *ssdt; |
| 18 | int ret; |
| 19 | |
| 20 | ssdt = ctx->current; |
Heinrich Schuchardt | f252dfc | 2023-11-18 22:52:37 +0100 | [diff] [blame^] | 21 | memset(ssdt, '\0', sizeof(struct acpi_table_header)); |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 22 | |
| 23 | acpi_fill_header(ssdt, "SSDT"); |
Simon Glass | 6800095 | 2021-12-01 09:02:56 -0700 | [diff] [blame] | 24 | ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT); |
| 25 | ssdt->aslc_revision = 1; |
| 26 | ssdt->length = sizeof(struct acpi_table_header); |
| 27 | |
| 28 | acpi_inc(ctx, sizeof(struct acpi_table_header)); |
| 29 | |
| 30 | ret = acpi_fill_ssdt(ctx); |
| 31 | if (ret) { |
| 32 | ctx->current = ssdt; |
| 33 | return log_msg_ret("fill", ret); |
| 34 | } |
| 35 | |
| 36 | /* (Re)calculate length and checksum */ |
| 37 | ssdt->length = ctx->current - (void *)ssdt; |
| 38 | ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length); |
| 39 | log_debug("SSDT at %p, length %x\n", ssdt, ssdt->length); |
| 40 | |
| 41 | /* Drop the table if it is empty */ |
| 42 | if (ssdt->length == sizeof(struct acpi_table_header)) |
| 43 | return log_msg_ret("fill", -ENOENT); |
| 44 | acpi_add_table(ctx, ssdt); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | ACPI_WRITER(6ssdt, "SSDT", acpi_write_ssdt, 0); |