efi_smbios.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EFI application tables support
  4. *
  5. * Copyright (c) 2016 Alexander Graf
  6. */
  7. #include <common.h>
  8. #include <efi_loader.h>
  9. #include <smbios.h>
  10. static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
  11. /*
  12. * Install the SMBIOS table as a configuration table.
  13. *
  14. * @return status code
  15. */
  16. efi_status_t efi_smbios_register(void)
  17. {
  18. /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
  19. u64 dmi = U32_MAX;
  20. efi_status_t ret;
  21. /* Reserve 4kiB page for SMBIOS */
  22. ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
  23. EFI_RUNTIME_SERVICES_DATA, 1, &dmi);
  24. if (ret != EFI_SUCCESS) {
  25. /* Could not find space in lowmem, use highmem instead */
  26. ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
  27. EFI_RUNTIME_SERVICES_DATA, 1, &dmi);
  28. if (ret != EFI_SUCCESS)
  29. return ret;
  30. }
  31. /*
  32. * Generate SMBIOS tables - we know that efi_allocate_pages() returns
  33. * a 4k-aligned address, so it is safe to assume that
  34. * write_smbios_table() will write the table at that address.
  35. */
  36. assert(!(dmi & 0xf));
  37. write_smbios_table(dmi);
  38. /* And expose them to our EFI payload */
  39. return efi_install_configuration_table(&smbios_guid,
  40. (void *)(uintptr_t)dmi);
  41. }