efi_smbios.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <mapmem.h>
  10. #include <smbios.h>
  11. static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
  12. /*
  13. * Install the SMBIOS table as a configuration table.
  14. *
  15. * @return status code
  16. */
  17. efi_status_t efi_smbios_register(void)
  18. {
  19. /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
  20. u64 dmi_addr = U32_MAX;
  21. efi_status_t ret;
  22. void *dmi;
  23. /* Reserve 4kiB page for SMBIOS */
  24. ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
  25. EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr);
  26. if (ret != EFI_SUCCESS) {
  27. /* Could not find space in lowmem, use highmem instead */
  28. ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
  29. EFI_RUNTIME_SERVICES_DATA, 1,
  30. &dmi_addr);
  31. if (ret != EFI_SUCCESS)
  32. return ret;
  33. }
  34. /*
  35. * Generate SMBIOS tables - we know that efi_allocate_pages() returns
  36. * a 4k-aligned address, so it is safe to assume that
  37. * write_smbios_table() will write the table at that address.
  38. *
  39. * Note that on sandbox, efi_allocate_pages() unfortunately returns a
  40. * pointer even though it uses a uint64_t type. Convert it.
  41. */
  42. assert(!(dmi_addr & 0xf));
  43. dmi = (void *)(uintptr_t)dmi_addr;
  44. write_smbios_table(map_to_sysmem(dmi));
  45. /* And expose them to our EFI payload */
  46. return efi_install_configuration_table(&smbios_guid, dmi);
  47. }