blob: 0fbf51b98d0d726efc0c19f76eee9f4b1c3598d0 [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 <common.h>
11#include <efi_loader.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glassaadec122023-09-20 07:29:51 -060013#include <malloc.h>
Simon Glass2d93add2018-11-22 13:46:37 -070014#include <mapmem.h>
Alexander Graf66f96e12016-08-19 01:23:29 +020015#include <smbios.h>
Simon Glassaadec122023-09-20 07:29:51 -060016#include <linux/sizes.h>
17
18enum {
19 TABLE_SIZE = SZ_4K,
20};
Alexander Graf66f96e12016-08-19 01:23:29 +020021
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010022/*
23 * Install the SMBIOS table as a configuration table.
24 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010025 * Return: status code
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010026 */
27efi_status_t efi_smbios_register(void)
Alexander Graf66f96e12016-08-19 01:23:29 +020028{
Simon Glassaadec122023-09-20 07:29:51 -060029 ulong addr;
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010030 efi_status_t ret;
Simon Glassaadec122023-09-20 07:29:51 -060031
32 addr = gd->arch.smbios_start;
33 if (!addr) {
34 log_err("No SMBIOS tables to install\n");
35 return EFI_NOT_FOUND;
36 }
37
38 /* Mark space used for tables */
39 ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
40 if (ret)
41 return ret;
42
43 log_debug("EFI using SMBIOS tables at %lx\n", addr);
Alexander Graf66f96e12016-08-19 01:23:29 +020044
Simon Glassaadec122023-09-20 07:29:51 -060045 /* Install SMBIOS information as configuration table */
46 return efi_install_configuration_table(&smbios_guid,
47 map_sysmem(addr, 0));
48}
49
50static int install_smbios_table(void)
51{
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010052 u64 addr;
53 efi_status_t ret;
Alexander Graf17990072018-06-18 17:23:00 +020054
Simon Glassaadec122023-09-20 07:29:51 -060055 if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
56 return 0;
Alexander Graf17990072018-06-18 17:23:00 +020057
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010058 addr = SZ_4G;
59 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
60 EFI_RUNTIME_SERVICES_DATA,
61 efi_size_in_pages(TABLE_SIZE), &addr);
62 if (ret != EFI_SUCCESS)
Simon Glassaadec122023-09-20 07:29:51 -060063 return log_msg_ret("mem", -ENOMEM);
64
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010065 addr = map_to_sysmem((void *)(uintptr_t)addr);
Simon Glassaadec122023-09-20 07:29:51 -060066 if (!write_smbios_table(addr)) {
67 log_err("Failed to write SMBIOS table\n");
68 return log_msg_ret("smbios", -EINVAL);
Alexander Graf17990072018-06-18 17:23:00 +020069 }
Alexander Graf66f96e12016-08-19 01:23:29 +020070
Simon Glassaadec122023-09-20 07:29:51 -060071 /* Make a note of where we put it */
Heinrich Schuchardt9c84c6c2023-11-20 23:25:58 +010072 log_debug("SMBIOS tables written to %llx\n", addr);
Simon Glassaadec122023-09-20 07:29:51 -060073 gd->arch.smbios_start = addr;
74
75 return 0;
Alexander Graf66f96e12016-08-19 01:23:29 +020076}
Simon Glassaadec122023-09-20 07:29:51 -060077EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);