efi_acpi.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EFI application ACPI tables support
  4. *
  5. * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
  6. */
  7. #include <common.h>
  8. #include <efi_loader.h>
  9. #include <acpi/acpi_table.h>
  10. static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
  11. /*
  12. * Install the ACPI table as a configuration table.
  13. *
  14. * @return status code
  15. */
  16. efi_status_t efi_acpi_register(void)
  17. {
  18. /* Map within the low 32 bits, to allow for 32bit ACPI tables */
  19. u64 acpi = U32_MAX;
  20. efi_status_t ret;
  21. /* Reserve 64kiB page for ACPI */
  22. ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
  23. EFI_RUNTIME_SERVICES_DATA, 16, &acpi);
  24. if (ret != EFI_SUCCESS)
  25. return ret;
  26. /*
  27. * Generate ACPI tables - we know that efi_allocate_pages() returns
  28. * a 4k-aligned address, so it is safe to assume that
  29. * write_acpi_tables() will write the table at that address.
  30. */
  31. assert(!(acpi & 0xf));
  32. write_acpi_tables(acpi);
  33. /* And expose them to our EFI payload */
  34. return efi_install_configuration_table(&acpi_guid,
  35. (void *)(uintptr_t)acpi);
  36. }