ssdt.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #define LOG_CATEGORY LOGC_ACPI
  8. #include <common.h>
  9. #include <acpi/acpi_table.h>
  10. #include <dm/acpi.h>
  11. #include <tables_csum.h>
  12. int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
  13. {
  14. struct acpi_table_header *ssdt;
  15. int ret;
  16. ssdt = ctx->current;
  17. memset((void *)ssdt, '\0', sizeof(struct acpi_table_header));
  18. acpi_fill_header(ssdt, "SSDT");
  19. memcpy(ssdt->oem_table_id, OEM_TABLE_ID, sizeof(ssdt->oem_table_id));
  20. ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT);
  21. ssdt->aslc_revision = 1;
  22. ssdt->length = sizeof(struct acpi_table_header);
  23. acpi_inc(ctx, sizeof(struct acpi_table_header));
  24. ret = acpi_fill_ssdt(ctx);
  25. if (ret) {
  26. ctx->current = ssdt;
  27. return log_msg_ret("fill", ret);
  28. }
  29. /* (Re)calculate length and checksum */
  30. ssdt->length = ctx->current - (void *)ssdt;
  31. ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length);
  32. log_debug("SSDT at %p, length %x\n", ssdt, ssdt->length);
  33. /* Drop the table if it is empty */
  34. if (ssdt->length == sizeof(struct acpi_table_header))
  35. return log_msg_ret("fill", -ENOENT);
  36. acpi_add_table(ctx, ssdt);
  37. return 0;
  38. }
  39. ACPI_WRITER(6ssdt, "SSDT", acpi_write_ssdt, 0);