blob: b2ec1f791940485f0e228efb1f78471e91fb6c49 [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 <efi_loader.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glass53fab132023-09-20 07:29:51 -060012#include <malloc.h>
Simon Glassa2505fc2018-11-22 13:46:37 -070013#include <mapmem.h>
Alexander Grafe663b352016-08-19 01:23:29 +020014#include <smbios.h>
Simon Glass53fab132023-09-20 07:29:51 -060015#include <linux/sizes.h>
Heinrich Schuchardtefe441a2024-01-03 09:07:20 +010016#include <asm/global_data.h>
17
18DECLARE_GLOBAL_DATA_PTR;
Simon Glass53fab132023-09-20 07:29:51 -060019
Simon Glass138e6912023-12-31 08:25:49 -070020const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID;
21
Simon Glass53fab132023-09-20 07:29:51 -060022enum {
23 TABLE_SIZE = SZ_4K,
24};
Alexander Grafe663b352016-08-19 01:23:29 +020025
Heinrich Schuchardt76571522018-03-03 15:28:54 +010026/*
27 * Install the SMBIOS table as a configuration table.
28 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010029 * Return: status code
Heinrich Schuchardt76571522018-03-03 15:28:54 +010030 */
31efi_status_t efi_smbios_register(void)
Alexander Grafe663b352016-08-19 01:23:29 +020032{
Simon Glass53fab132023-09-20 07:29:51 -060033 ulong addr;
Heinrich Schuchardt76571522018-03-03 15:28:54 +010034 efi_status_t ret;
Simon Glass138e6912023-12-31 08:25:49 -070035 void *buf;
Alexander Grafe663b352016-08-19 01:23:29 +020036
Simon Glassb2b58e12023-12-31 08:25:48 -070037 addr = gd_smbios_start();
Simon Glass53fab132023-09-20 07:29:51 -060038 if (!addr) {
39 log_err("No SMBIOS tables to install\n");
40 return EFI_NOT_FOUND;
Alexander Graf62f37572018-06-18 17:23:00 +020041 }
Alexander Grafe663b352016-08-19 01:23:29 +020042
Simon Glass53fab132023-09-20 07:29:51 -060043 /* Mark space used for tables */
44 ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
45 if (ret)
46 return ret;
47
48 log_debug("EFI using SMBIOS tables at %lx\n", addr);
49
50 /* Install SMBIOS information as configuration table */
Simon Glass138e6912023-12-31 08:25:49 -070051 buf = map_sysmem(addr, 0);
Simon Glassaa849962023-12-31 08:25:52 -070052 ret = efi_install_configuration_table(&smbios3_guid, buf);
Simon Glass138e6912023-12-31 08:25:49 -070053 unmap_sysmem(buf);
54
55 return ret;
Alexander Grafe663b352016-08-19 01:23:29 +020056}
Simon Glass53fab132023-09-20 07:29:51 -060057
58static int install_smbios_table(void)
59{
Simon Glass06ef8082023-12-31 08:25:55 -070060 ulong addr;
61 void *buf;
Simon Glass53fab132023-09-20 07:29:51 -060062
63 if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
64 return 0;
65
Simon Glass06ef8082023-12-31 08:25:55 -070066 /* Align the table to a 4KB boundary to keep EFI happy */
67 buf = memalign(SZ_4K, TABLE_SIZE);
68 if (!buf)
Simon Glass53fab132023-09-20 07:29:51 -060069 return log_msg_ret("mem", -ENOMEM);
70
Simon Glass06ef8082023-12-31 08:25:55 -070071 addr = map_to_sysmem(buf);
Simon Glass53fab132023-09-20 07:29:51 -060072 if (!write_smbios_table(addr)) {
73 log_err("Failed to write SMBIOS table\n");
74 return log_msg_ret("smbios", -EINVAL);
75 }
76
77 /* Make a note of where we put it */
Simon Glass06ef8082023-12-31 08:25:55 -070078 log_debug("SMBIOS tables written to %lx\n", addr);
Simon Glass53fab132023-09-20 07:29:51 -060079 gd->arch.smbios_start = addr;
80
81 return 0;
82}
83EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);