blob: 5cbce6dc4eb2ef3275b0c3c2f97af3cfef0636d5 [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Graf66f96e12016-08-19 01:23:29 +02002/*
3 * EFI application tables support
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Graf66f96e12016-08-19 01:23:29 +02006 */
7
Heinrich Schuchardt21da91f2021-05-15 18:07:47 +02008#define LOG_CATEGORY LOGC_EFI
9
Alexander Graf66f96e12016-08-19 01:23:29 +020010#include <efi_loader.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glassaadec122023-09-20 07:29:51 -060012#include <malloc.h>
Simon Glass2d93add2018-11-22 13:46:37 -070013#include <mapmem.h>
Alexander Graf66f96e12016-08-19 01:23:29 +020014#include <smbios.h>
Simon Glassaadec122023-09-20 07:29:51 -060015#include <linux/sizes.h>
16
Simon Glass97236702023-12-31 08:25:49 -070017const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID;
18
Simon Glassaadec122023-09-20 07:29:51 -060019enum {
20 TABLE_SIZE = SZ_4K,
21};
Alexander Graf66f96e12016-08-19 01:23:29 +020022
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010023/*
24 * Install the SMBIOS table as a configuration table.
25 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010026 * Return: status code
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010027 */
28efi_status_t efi_smbios_register(void)
Alexander Graf66f96e12016-08-19 01:23:29 +020029{
Simon Glass97236702023-12-31 08:25:49 -070030 const efi_guid_t *guid;
Simon Glassaadec122023-09-20 07:29:51 -060031 ulong addr;
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010032 efi_status_t ret;
Simon Glass97236702023-12-31 08:25:49 -070033 void *buf;
Simon Glassaadec122023-09-20 07:29:51 -060034
Simon Glass42b7da52023-12-31 08:25:48 -070035 addr = gd_smbios_start();
Simon Glassaadec122023-09-20 07:29:51 -060036 if (!addr) {
37 log_err("No SMBIOS tables to install\n");
38 return EFI_NOT_FOUND;
39 }
40
41 /* Mark space used for tables */
42 ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
43 if (ret)
44 return ret;
45
46 log_debug("EFI using SMBIOS tables at %lx\n", addr);
Alexander Graf66f96e12016-08-19 01:23:29 +020047
Simon Glassaadec122023-09-20 07:29:51 -060048 /* Install SMBIOS information as configuration table */
Simon Glass97236702023-12-31 08:25:49 -070049 buf = map_sysmem(addr, 0);
50 guid = !memcmp(buf, "_SM_", 4) ? &smbios_guid : &smbios3_guid;
51 ret = efi_install_configuration_table(guid, buf);
52 unmap_sysmem(buf);
53
54 return ret;
Simon Glassaadec122023-09-20 07:29:51 -060055}
56
57static int install_smbios_table(void)
58{
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010059 u64 addr;
60 efi_status_t ret;
Alexander Graf17990072018-06-18 17:23:00 +020061
Simon Glassaadec122023-09-20 07:29:51 -060062 if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
63 return 0;
Alexander Graf17990072018-06-18 17:23:00 +020064
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010065 addr = SZ_4G;
66 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
67 EFI_RUNTIME_SERVICES_DATA,
68 efi_size_in_pages(TABLE_SIZE), &addr);
69 if (ret != EFI_SUCCESS)
Simon Glassaadec122023-09-20 07:29:51 -060070 return log_msg_ret("mem", -ENOMEM);
71
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010072 addr = map_to_sysmem((void *)(uintptr_t)addr);
Simon Glassaadec122023-09-20 07:29:51 -060073 if (!write_smbios_table(addr)) {
74 log_err("Failed to write SMBIOS table\n");
75 return log_msg_ret("smbios", -EINVAL);
Alexander Graf17990072018-06-18 17:23:00 +020076 }
Alexander Graf66f96e12016-08-19 01:23:29 +020077
Simon Glassaadec122023-09-20 07:29:51 -060078 /* Make a note of where we put it */
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010079 log_debug("SMBIOS tables written to %llx\n", addr);
Simon Glassaadec122023-09-20 07:29:51 -060080 gd->arch.smbios_start = addr;
81
82 return 0;
Alexander Graf66f96e12016-08-19 01:23:29 +020083}
Simon Glassaadec122023-09-20 07:29:51 -060084EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);