blob: 306c0bc54f90b0d4bae98c8c5a72bce4504e49d0 [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
Heinrich Schuchardtc193d9b2021-05-15 18:07:47 +02008#define LOG_CATEGORY LOGC_EFI
9
Alexander Grafe663b352016-08-19 01:23:29 +020010#include <common.h>
11#include <efi_loader.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Simon Glassa2505fc2018-11-22 13:46:37 -070013#include <mapmem.h>
Alexander Grafe663b352016-08-19 01:23:29 +020014#include <smbios.h>
15
Heinrich Schuchardt76571522018-03-03 15:28:54 +010016/*
17 * Install the SMBIOS table as a configuration table.
18 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010019 * Return: status code
Heinrich Schuchardt76571522018-03-03 15:28:54 +010020 */
21efi_status_t efi_smbios_register(void)
Alexander Grafe663b352016-08-19 01:23:29 +020022{
23 /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
Simon Glassa2505fc2018-11-22 13:46:37 -070024 u64 dmi_addr = U32_MAX;
Heinrich Schuchardt76571522018-03-03 15:28:54 +010025 efi_status_t ret;
Simon Glassa2505fc2018-11-22 13:46:37 -070026 void *dmi;
Alexander Grafe663b352016-08-19 01:23:29 +020027
Heinrich Schuchardt76571522018-03-03 15:28:54 +010028 /* Reserve 4kiB page for SMBIOS */
29 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
Simon Glassa2505fc2018-11-22 13:46:37 -070030 EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr);
Alexander Graf62f37572018-06-18 17:23:00 +020031
32 if (ret != EFI_SUCCESS) {
33 /* Could not find space in lowmem, use highmem instead */
34 ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
Simon Glassa2505fc2018-11-22 13:46:37 -070035 EFI_RUNTIME_SERVICES_DATA, 1,
36 &dmi_addr);
Alexander Graf62f37572018-06-18 17:23:00 +020037
38 if (ret != EFI_SUCCESS)
39 return ret;
40 }
Alexander Grafe663b352016-08-19 01:23:29 +020041
Simon Glass0864c562018-05-16 09:42:19 -060042 /*
43 * Generate SMBIOS tables - we know that efi_allocate_pages() returns
44 * a 4k-aligned address, so it is safe to assume that
45 * write_smbios_table() will write the table at that address.
46 */
Simon Glassa2505fc2018-11-22 13:46:37 -070047 assert(!(dmi_addr & 0xf));
48 dmi = (void *)(uintptr_t)dmi_addr;
Heinrich Schuchardtc193d9b2021-05-15 18:07:47 +020049 if (write_smbios_table(map_to_sysmem(dmi)))
50 /* Install SMBIOS information as configuration table */
51 return efi_install_configuration_table(&smbios_guid, dmi);
52 efi_free_pages(dmi_addr, 1);
53 log_err("Cannot create SMBIOS table\n");
54 return EFI_SUCCESS;
Alexander Grafe663b352016-08-19 01:23:29 +020055}