dsdt.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Write the ACPI Differentiated System Description Table (DSDT)
  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. /*
  13. * IASL compiles the dsdt entries and writes the hex values
  14. * to a C array AmlCode[] (see dsdt.c).
  15. */
  16. extern const unsigned char AmlCode[];
  17. int acpi_write_dsdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
  18. {
  19. const int thl = sizeof(struct acpi_table_header);
  20. struct acpi_table_header *dsdt = ctx->current;
  21. int aml_len;
  22. /* Put the table header first */
  23. memcpy(dsdt, &AmlCode, thl);
  24. acpi_inc(ctx, thl);
  25. log_debug("DSDT starts at %p, hdr ends at %p\n", dsdt, ctx->current);
  26. /* If the table is not empty, allow devices to inject things */
  27. aml_len = dsdt->length - thl;
  28. if (aml_len) {
  29. void *base = ctx->current;
  30. int ret;
  31. ret = acpi_inject_dsdt(ctx);
  32. if (ret)
  33. return log_msg_ret("inject", ret);
  34. log_debug("Added %lx bytes from inject_dsdt, now at %p\n",
  35. (ulong)(ctx->current - base), ctx->current);
  36. log_debug("Copy AML code size %x to %p\n", aml_len,
  37. ctx->current);
  38. memcpy(ctx->current, AmlCode + thl, aml_len);
  39. acpi_inc(ctx, aml_len);
  40. }
  41. ctx->dsdt = dsdt;
  42. dsdt->length = ctx->current - (void *)dsdt;
  43. log_debug("Updated DSDT length to %x\n", dsdt->length);
  44. return 0;
  45. }
  46. ACPI_WRITER(3dsdt, "DSDT", acpi_write_dsdt, 0);