1 // SPDX-License-Identifier: GPL-2.0+
3 * Write an ACPI Secondary System Descriptor Table (SSDT) table
5 * Copyright 2021 Google LLC
8 #define LOG_CATEGORY LOGC_ACPI
11 #include <acpi/acpi_table.h>
13 #include <tables_csum.h>
15 int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
17 struct acpi_table_header *ssdt;
21 memset((void *)ssdt, '\0', sizeof(struct acpi_table_header));
23 acpi_fill_header(ssdt, "SSDT");
24 memcpy(ssdt->oem_table_id, OEM_TABLE_ID, sizeof(ssdt->oem_table_id));
25 ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT);
26 ssdt->aslc_revision = 1;
27 ssdt->length = sizeof(struct acpi_table_header);
29 acpi_inc(ctx, sizeof(struct acpi_table_header));
31 ret = acpi_fill_ssdt(ctx);
34 return log_msg_ret("fill", ret);
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);
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);
49 ACPI_WRITER(6ssdt, "SSDT", acpi_write_ssdt, 0);