2018-05-07 21:02:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-08-18 23:23:29 +00:00
|
|
|
/*
|
|
|
|
* EFI application tables support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Alexander Graf
|
|
|
|
*/
|
|
|
|
|
2021-05-15 16:07:47 +00:00
|
|
|
#define LOG_CATEGORY LOGC_EFI
|
|
|
|
|
2016-08-18 23:23:29 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <efi_loader.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2023-09-20 13:29:51 +00:00
|
|
|
#include <malloc.h>
|
2018-11-22 20:46:37 +00:00
|
|
|
#include <mapmem.h>
|
2016-08-18 23:23:29 +00:00
|
|
|
#include <smbios.h>
|
2023-09-20 13:29:51 +00:00
|
|
|
#include <linux/sizes.h>
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TABLE_SIZE = SZ_4K,
|
|
|
|
};
|
2016-08-18 23:23:29 +00:00
|
|
|
|
2018-03-03 14:28:54 +00:00
|
|
|
/*
|
|
|
|
* Install the SMBIOS table as a configuration table.
|
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: status code
|
2018-03-03 14:28:54 +00:00
|
|
|
*/
|
|
|
|
efi_status_t efi_smbios_register(void)
|
2016-08-18 23:23:29 +00:00
|
|
|
{
|
2023-09-20 13:29:51 +00:00
|
|
|
ulong addr;
|
2018-03-03 14:28:54 +00:00
|
|
|
efi_status_t ret;
|
2016-08-18 23:23:29 +00:00
|
|
|
|
2023-09-20 13:29:51 +00:00
|
|
|
addr = gd->arch.smbios_start;
|
|
|
|
if (!addr) {
|
|
|
|
log_err("No SMBIOS tables to install\n");
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark space used for tables */
|
|
|
|
ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
log_debug("EFI using SMBIOS tables at %lx\n", addr);
|
|
|
|
|
|
|
|
/* Install SMBIOS information as configuration table */
|
|
|
|
return efi_install_configuration_table(&smbios_guid,
|
|
|
|
map_sysmem(addr, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int install_smbios_table(void)
|
|
|
|
{
|
|
|
|
ulong addr;
|
|
|
|
void *buf;
|
2018-06-18 15:23:00 +00:00
|
|
|
|
2023-09-20 13:29:51 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
|
|
|
|
return 0;
|
2018-06-18 15:23:00 +00:00
|
|
|
|
2023-09-20 13:29:51 +00:00
|
|
|
/* Align the table to a 4KB boundary to keep EFI happy */
|
|
|
|
buf = memalign(SZ_4K, TABLE_SIZE);
|
|
|
|
if (!buf)
|
|
|
|
return log_msg_ret("mem", -ENOMEM);
|
|
|
|
|
|
|
|
addr = map_to_sysmem(buf);
|
|
|
|
if (!write_smbios_table(addr)) {
|
|
|
|
log_err("Failed to write SMBIOS table\n");
|
|
|
|
return log_msg_ret("smbios", -EINVAL);
|
2018-06-18 15:23:00 +00:00
|
|
|
}
|
2016-08-18 23:23:29 +00:00
|
|
|
|
2023-09-20 13:29:51 +00:00
|
|
|
/* Make a note of where we put it */
|
|
|
|
log_debug("SMBIOS tables written to %lx\n", addr);
|
|
|
|
gd->arch.smbios_start = addr;
|
|
|
|
|
|
|
|
return 0;
|
2016-08-18 23:23:29 +00:00
|
|
|
}
|
2023-09-20 13:29:51 +00:00
|
|
|
EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);
|