blob: a81488495e27f7f205a06719ea3d25abc6a6dbe5 [file] [log] [blame]
Tom Rinif739fcd2018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Grafe663b352016-08-19 01:23:29 +02002/*
3 * EFI application tables support
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Grafe663b352016-08-19 01:23:29 +02006 */
7
8#include <common.h>
9#include <efi_loader.h>
Simon Glassa2505fc2018-11-22 13:46:37 -070010#include <mapmem.h>
Alexander Grafe663b352016-08-19 01:23:29 +020011#include <smbios.h>
12
13static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
14
Heinrich Schuchardt76571522018-03-03 15:28:54 +010015/*
16 * Install the SMBIOS table as a configuration table.
17 *
18 * @return status code
19 */
20efi_status_t efi_smbios_register(void)
Alexander Grafe663b352016-08-19 01:23:29 +020021{
22 /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
Simon Glassa2505fc2018-11-22 13:46:37 -070023 u64 dmi_addr = U32_MAX;
Heinrich Schuchardt76571522018-03-03 15:28:54 +010024 efi_status_t ret;
Simon Glassa2505fc2018-11-22 13:46:37 -070025 void *dmi;
Alexander Grafe663b352016-08-19 01:23:29 +020026
Heinrich Schuchardt76571522018-03-03 15:28:54 +010027 /* Reserve 4kiB page for SMBIOS */
28 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
Simon Glassa2505fc2018-11-22 13:46:37 -070029 EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr);
Alexander Graf62f37572018-06-18 17:23:00 +020030
31 if (ret != EFI_SUCCESS) {
32 /* Could not find space in lowmem, use highmem instead */
33 ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
Simon Glassa2505fc2018-11-22 13:46:37 -070034 EFI_RUNTIME_SERVICES_DATA, 1,
35 &dmi_addr);
Alexander Graf62f37572018-06-18 17:23:00 +020036
37 if (ret != EFI_SUCCESS)
38 return ret;
39 }
Alexander Grafe663b352016-08-19 01:23:29 +020040
Simon Glass0864c562018-05-16 09:42:19 -060041 /*
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.
Simon Glassa2505fc2018-11-22 13:46:37 -070045 *
46 * Note that on sandbox, efi_allocate_pages() unfortunately returns a
47 * pointer even though it uses a uint64_t type. Convert it.
Simon Glass0864c562018-05-16 09:42:19 -060048 */
Simon Glassa2505fc2018-11-22 13:46:37 -070049 assert(!(dmi_addr & 0xf));
50 dmi = (void *)(uintptr_t)dmi_addr;
51 write_smbios_table(map_to_sysmem(dmi));
Alexander Grafe663b352016-08-19 01:23:29 +020052
53 /* And expose them to our EFI payload */
Simon Glassa2505fc2018-11-22 13:46:37 -070054 return efi_install_configuration_table(&smbios_guid, dmi);
Alexander Grafe663b352016-08-19 01:23:29 +020055}