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 <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>
|
2024-01-03 08:07:20 +00:00
|
|
|
#include <asm/global_data.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2023-09-20 13:29:51 +00:00
|
|
|
|
2023-12-31 15:25:49 +00:00
|
|
|
const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID;
|
|
|
|
|
2023-09-20 13:29:51 +00:00
|
|
|
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;
|
2023-12-31 15:25:49 +00:00
|
|
|
void *buf;
|
2016-08-18 23:23:29 +00:00
|
|
|
|
2023-12-31 15:25:48 +00:00
|
|
|
addr = gd_smbios_start();
|
2023-09-20 13:29:51 +00:00
|
|
|
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 */
|
2023-12-31 15:25:49 +00:00
|
|
|
buf = map_sysmem(addr, 0);
|
2023-12-31 15:25:52 +00:00
|
|
|
ret = efi_install_configuration_table(&smbios3_guid, buf);
|
2023-12-31 15:25:49 +00:00
|
|
|
unmap_sysmem(buf);
|
|
|
|
|
|
|
|
return ret;
|
2023-09-20 13:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int install_smbios_table(void)
|
|
|
|
{
|
2023-12-31 15:25:55 +00:00
|
|
|
ulong addr;
|
|
|
|
void *buf;
|
2018-06-18 15:23:00 +00:00
|
|
|
|
2023-12-23 01:03:34 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) ||
|
|
|
|
IS_ENABLED(CONFIG_X86) ||
|
|
|
|
IS_ENABLED(CONFIG_QFW_SMBIOS))
|
2023-09-20 13:29:51 +00:00
|
|
|
return 0;
|
2018-06-18 15:23:00 +00:00
|
|
|
|
2023-12-31 15:25:55 +00:00
|
|
|
/* Align the table to a 4KB boundary to keep EFI happy */
|
|
|
|
buf = memalign(SZ_4K, TABLE_SIZE);
|
|
|
|
if (!buf)
|
2023-09-20 13:29:51 +00:00
|
|
|
return log_msg_ret("mem", -ENOMEM);
|
|
|
|
|
2023-12-31 15:25:55 +00:00
|
|
|
addr = map_to_sysmem(buf);
|
2023-09-20 13:29:51 +00:00
|
|
|
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 */
|
2023-12-31 15:25:55 +00:00
|
|
|
log_debug("SMBIOS tables written to %lx\n", addr);
|
2023-09-20 13:29:51 +00:00
|
|
|
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);
|