blob: 38e42fa243234eb53c0fadbb8f76724c832c662c [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>
Alexander Grafe663b352016-08-19 01:23:29 +020010#include <smbios.h>
11
12static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
13
Heinrich Schuchardt76571522018-03-03 15:28:54 +010014/*
15 * Install the SMBIOS table as a configuration table.
16 *
17 * @return status code
18 */
19efi_status_t efi_smbios_register(void)
Alexander Grafe663b352016-08-19 01:23:29 +020020{
21 /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
Heinrich Schuchardt76571522018-03-03 15:28:54 +010022 u64 dmi = U32_MAX;
23 efi_status_t ret;
Alexander Grafe663b352016-08-19 01:23:29 +020024
Heinrich Schuchardt76571522018-03-03 15:28:54 +010025 /* Reserve 4kiB page for SMBIOS */
26 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
27 EFI_RUNTIME_SERVICES_DATA, 1, &dmi);
Alexander Graf62f37572018-06-18 17:23:00 +020028
29 if (ret != EFI_SUCCESS) {
30 /* Could not find space in lowmem, use highmem instead */
31 ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
32 EFI_RUNTIME_SERVICES_DATA, 1, &dmi);
33
34 if (ret != EFI_SUCCESS)
35 return ret;
36 }
Alexander Grafe663b352016-08-19 01:23:29 +020037
Simon Glass0864c562018-05-16 09:42:19 -060038 /*
39 * Generate SMBIOS tables - we know that efi_allocate_pages() returns
40 * a 4k-aligned address, so it is safe to assume that
41 * write_smbios_table() will write the table at that address.
42 */
43 assert(!(dmi & 0xf));
Alexander Grafe663b352016-08-19 01:23:29 +020044 write_smbios_table(dmi);
45
46 /* And expose them to our EFI payload */
Heinrich Schuchardt76571522018-03-03 15:28:54 +010047 return efi_install_configuration_table(&smbios_guid,
48 (void *)(uintptr_t)dmi);
Alexander Grafe663b352016-08-19 01:23:29 +020049}