acpi.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Utility functions for ACPI
  4. *
  5. * Copyright 2023 Google LLC
  6. */
  7. #include <common.h>
  8. #include <mapmem.h>
  9. #include <acpi/acpi_table.h>
  10. #include <asm/global_data.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. struct acpi_table_header *acpi_find_table(const char *sig)
  13. {
  14. struct acpi_rsdp *rsdp;
  15. struct acpi_rsdt *rsdt;
  16. int len, i, count;
  17. rsdp = map_sysmem(gd_acpi_start(), 0);
  18. if (!rsdp)
  19. return NULL;
  20. rsdt = map_sysmem(rsdp->rsdt_address, 0);
  21. len = rsdt->header.length - sizeof(rsdt->header);
  22. count = len / sizeof(u32);
  23. for (i = 0; i < count; i++) {
  24. struct acpi_table_header *hdr;
  25. hdr = map_sysmem(rsdt->entry[i], 0);
  26. if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN))
  27. return hdr;
  28. if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) {
  29. struct acpi_fadt *fadt = (struct acpi_fadt *)hdr;
  30. if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt)
  31. return map_sysmem(fadt->dsdt, 0);
  32. if (!memcmp(sig, "FACS", ACPI_NAME_LEN) &&
  33. fadt->firmware_ctrl)
  34. return map_sysmem(fadt->firmware_ctrl, 0);
  35. }
  36. }
  37. return NULL;
  38. }