blob: f3f936ff4d609c191a39e63a3299499d96dc9b56 [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>
Caleb Connolly87ff7402023-10-23 15:06:26 +010012#include <lmb.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Simon Glass53fab132023-09-20 07:29:51 -060014#include <malloc.h>
Simon Glassa2505fc2018-11-22 13:46:37 -070015#include <mapmem.h>
Alexander Grafe663b352016-08-19 01:23:29 +020016#include <smbios.h>
Simon Glass53fab132023-09-20 07:29:51 -060017#include <linux/sizes.h>
18
19enum {
20 TABLE_SIZE = SZ_4K,
21};
Alexander Grafe663b352016-08-19 01:23:29 +020022
Heinrich Schuchardt76571522018-03-03 15:28:54 +010023/*
24 * Install the SMBIOS table as a configuration table.
25 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010026 * Return: status code
Heinrich Schuchardt76571522018-03-03 15:28:54 +010027 */
28efi_status_t efi_smbios_register(void)
Alexander Grafe663b352016-08-19 01:23:29 +020029{
Simon Glass53fab132023-09-20 07:29:51 -060030 ulong addr;
Heinrich Schuchardt76571522018-03-03 15:28:54 +010031 efi_status_t ret;
Alexander Grafe663b352016-08-19 01:23:29 +020032
Simon Glass53fab132023-09-20 07:29:51 -060033 addr = gd->arch.smbios_start;
34 if (!addr) {
35 log_err("No SMBIOS tables to install\n");
36 return EFI_NOT_FOUND;
Alexander Graf62f37572018-06-18 17:23:00 +020037 }
Alexander Grafe663b352016-08-19 01:23:29 +020038
Simon Glass53fab132023-09-20 07:29:51 -060039 /* Mark space used for tables */
40 ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
41 if (ret)
42 return ret;
43
44 log_debug("EFI using SMBIOS tables at %lx\n", addr);
45
46 /* Install SMBIOS information as configuration table */
47 return efi_install_configuration_table(&smbios_guid,
48 map_sysmem(addr, 0));
Alexander Grafe663b352016-08-19 01:23:29 +020049}
Simon Glass53fab132023-09-20 07:29:51 -060050
51static int install_smbios_table(void)
52{
Caleb Connolly87ff7402023-10-23 15:06:26 +010053 struct lmb lmb;
54 phys_addr_t addr;
Simon Glass53fab132023-09-20 07:29:51 -060055
56 if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
57 return 0;
58
Caleb Connolly87ff7402023-10-23 15:06:26 +010059 lmb_init_and_reserve(&lmb, gd->bd, (void*)gd->fdt_blob);
Simon Glass53fab132023-09-20 07:29:51 -060060
Caleb Connolly87ff7402023-10-23 15:06:26 +010061 addr = lmb_alloc_base(&lmb, TABLE_SIZE, SZ_4K, UINT_MAX);
62 addr = map_to_sysmem((void*)addr);
63
Simon Glass53fab132023-09-20 07:29:51 -060064 if (!write_smbios_table(addr)) {
65 log_err("Failed to write SMBIOS table\n");
66 return log_msg_ret("smbios", -EINVAL);
67 }
68
69 /* Make a note of where we put it */
Caleb Connolly87ff7402023-10-23 15:06:26 +010070 log_debug("SMBIOS tables written to %llx\n", addr);
Simon Glass53fab132023-09-20 07:29:51 -060071 gd->arch.smbios_start = addr;
72
73 return 0;
74}
75EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);