xref: /openbmc/u-boot/lib/efi_loader/efi_smbios.c (revision 57efeb04)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  EFI application tables support
4  *
5  *  Copyright (c) 2016 Alexander Graf
6  */
7 
8 #include <common.h>
9 #include <efi_loader.h>
10 #include <mapmem.h>
11 #include <smbios.h>
12 
13 static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
14 
15 /*
16  * Install the SMBIOS table as a configuration table.
17  *
18  * @return	status code
19  */
20 efi_status_t efi_smbios_register(void)
21 {
22 	/* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
23 	u64 dmi_addr = U32_MAX;
24 	efi_status_t ret;
25 	void *dmi;
26 
27 	/* Reserve 4kiB page for SMBIOS */
28 	ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
29 				 EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr);
30 
31 	if (ret != EFI_SUCCESS) {
32 		/* Could not find space in lowmem, use highmem instead */
33 		ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
34 					 EFI_RUNTIME_SERVICES_DATA, 1,
35 					 &dmi_addr);
36 
37 		if (ret != EFI_SUCCESS)
38 			return ret;
39 	}
40 
41 	/*
42 	 * Generate SMBIOS tables - we know that efi_allocate_pages() returns
43 	 * a 4k-aligned address, so it is safe to assume that
44 	 * write_smbios_table() will write the table at that address.
45 	 *
46 	 * Note that on sandbox, efi_allocate_pages() unfortunately returns a
47 	 * pointer even though it uses a uint64_t type. Convert it.
48 	 */
49 	assert(!(dmi_addr & 0xf));
50 	dmi = (void *)(uintptr_t)dmi_addr;
51 	write_smbios_table(map_to_sysmem(dmi));
52 
53 	/* And expose them to our EFI payload */
54 	return efi_install_configuration_table(&smbios_guid, dmi);
55 }
56