efi_smbios.c 1.4 KB

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