blob: 8d2ef6deb51477a484835dc40ff149e61bef4fde [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>
Heinrich Schuchardt34e97aa2024-01-03 09:07:20 +010016#include <asm/global_data.h>
17
18DECLARE_GLOBAL_DATA_PTR;
Simon Glassaadec122023-09-20 07:29:51 -060019
Simon Glass97236702023-12-31 08:25:49 -070020const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID;
21
Simon Glassaadec122023-09-20 07:29:51 -060022enum {
23 TABLE_SIZE = SZ_4K,
24};
Alexander Graf66f96e12016-08-19 01:23:29 +020025
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010026/*
27 * Install the SMBIOS table as a configuration table.
28 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010029 * Return: status code
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010030 */
31efi_status_t efi_smbios_register(void)
Alexander Graf66f96e12016-08-19 01:23:29 +020032{
Simon Glassaadec122023-09-20 07:29:51 -060033 ulong addr;
Heinrich Schuchardt7a369c42018-03-03 15:28:54 +010034 efi_status_t ret;
Simon Glass97236702023-12-31 08:25:49 -070035 void *buf;
Simon Glassaadec122023-09-20 07:29:51 -060036
Simon Glass42b7da52023-12-31 08:25:48 -070037 addr = gd_smbios_start();
Simon Glassaadec122023-09-20 07:29:51 -060038 if (!addr) {
39 log_err("No SMBIOS tables to install\n");
40 return EFI_NOT_FOUND;
41 }
42
43 /* 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);
Alexander Graf66f96e12016-08-19 01:23:29 +020049
Simon Glassaadec122023-09-20 07:29:51 -060050 /* Install SMBIOS information as configuration table */
Simon Glass97236702023-12-31 08:25:49 -070051 buf = map_sysmem(addr, 0);
Simon Glass70f99592023-12-31 08:25:52 -070052 ret = efi_install_configuration_table(&smbios3_guid, buf);
Simon Glass97236702023-12-31 08:25:49 -070053 unmap_sysmem(buf);
54
55 return ret;
Simon Glassaadec122023-09-20 07:29:51 -060056}
57
58static int install_smbios_table(void)
59{
Simon Glass2802f092023-12-31 08:25:55 -070060 ulong addr;
61 void *buf;
Alexander Graf17990072018-06-18 17:23:00 +020062
Heinrich Schuchardt08d931a2023-12-23 02:03:34 +010063 if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) ||
64 IS_ENABLED(CONFIG_X86) ||
65 IS_ENABLED(CONFIG_QFW_SMBIOS))
Simon Glassaadec122023-09-20 07:29:51 -060066 return 0;
Alexander Graf17990072018-06-18 17:23:00 +020067
Simon Glass2802f092023-12-31 08:25:55 -070068 /* Align the table to a 4KB boundary to keep EFI happy */
69 buf = memalign(SZ_4K, TABLE_SIZE);
70 if (!buf)
Simon Glassaadec122023-09-20 07:29:51 -060071 return log_msg_ret("mem", -ENOMEM);
72
Simon Glass2802f092023-12-31 08:25:55 -070073 addr = map_to_sysmem(buf);
Simon Glassaadec122023-09-20 07:29:51 -060074 if (!write_smbios_table(addr)) {
75 log_err("Failed to write SMBIOS table\n");
76 return log_msg_ret("smbios", -EINVAL);
Alexander Graf17990072018-06-18 17:23:00 +020077 }
Alexander Graf66f96e12016-08-19 01:23:29 +020078
Simon Glassaadec122023-09-20 07:29:51 -060079 /* Make a note of where we put it */
Simon Glass2802f092023-12-31 08:25:55 -070080 log_debug("SMBIOS tables written to %lx\n", addr);
Simon Glassaadec122023-09-20 07:29:51 -060081 gd->arch.smbios_start = addr;
82
83 return 0;
Alexander Graf66f96e12016-08-19 01:23:29 +020084}
Simon Glassaadec122023-09-20 07:29:51 -060085EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);