From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v1 49/54] efi: runtime: add runtime service support after ExitBootServices
Date: Thu, 18 Dec 2025 11:38:09 +0100 [thread overview]
Message-ID: <20251218111242.1527495-50-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251218111242.1527495-1-a.fatoum@pengutronix.de>
Before supporting ExitBootServices, we need the runtime service table to
be located completely in the .efi_runtime section and not reference
anything outside.
This is easiest by just maintaining a second runtime-only EFI runtime
service table, so do just that.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/Kconfig | 1 +
efi/runtime/Makefile | 1 +
efi/runtime/services.c | 303 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 305 insertions(+)
create mode 100644 efi/runtime/services.c
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ae3de9504a9b..5123e9b1402c 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -317,6 +317,7 @@ config AEABI
config AAPCS64
bool "Observe ARM64 Procedure Call Standard" if COMPILE_TEST
depends on CPU_V8
+ default EFI_RUNTIME
help
This option instructs barebox to observe the AAPCS64 for
interoperability with other firmware.
diff --git a/efi/runtime/Makefile b/efi/runtime/Makefile
index 90ed3ef454be..a9af06de60ab 100644
--- a/efi/runtime/Makefile
+++ b/efi/runtime/Makefile
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
+lib-y += services.o
lib-y += efi_var_mem.o efi_variable.o
KASAN_SANITIZE := n
diff --git a/efi/runtime/services.c b/efi/runtime/services.c
new file mode 100644
index 000000000000..11a1c5cb6cb6
--- /dev/null
+++ b/efi/runtime/services.c
@@ -0,0 +1,303 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2022 Ahmad Fatoum <a.fatoum@pengutronix.de>
+/*
+ * EFI application runtime services - detached callbacks after
+ * boot services have been exited.
+ */
+
+/* LSP-Workaround as our compile_commands.json target doesn't handle lib-y yet */
+#include "common.h"
+
+#include <efi/loader.h>
+#include <efi/runtime.h>
+#include <efi/loader/variable.h>
+#include <efi/variable.h>
+#include <efi/error.h>
+#include <generated/version.h>
+#include <poweroff.h>
+#include <restart.h>
+#include <barebox.h>
+#include <debug_ll.h>
+
+/**
+ * efirt_unimplemented() - replacement macro, returns EFI_UNSUPPORTED
+ *
+ * This macro is used after SetVirtualAddressMap() to be called as replacement
+ * for services that are not available anymore due to constraints of the barebox
+ * implementation.
+ *
+ * Return: EFI_UNSUPPORTED
+ */
+#define efirt_unimplemented() ({ \
+ EFI_ENTRY(L""); \
+ EFI_EXIT(EFI_UNSUPPORTED); \
+})
+
+/**
+ * efirt_reset_system() - reset system at runtime
+ *
+ * This function implements the ResetSystem() runtime service after
+ * SetVirtualAddressMap() is called. As this placeholder cannot reset the
+ * system it simply return to the caller.
+ *
+ * Boards may override the helpers below to implement reset functionality.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @reset_type: type of reset to perform
+ * @reset_status: status code for the reset
+ * @data_size: size of reset_data
+ * @reset_data: information about the reset
+ */
+static void EFIAPI efirt_reset_system(enum efi_reset_type reset_type,
+ efi_status_t reset_status,
+ size_t data_size, void *reset_data)
+{
+ switch (reset_type) {
+ case EFI_RESET_WARM:
+ EFI_ENTRY(L"warm");
+ rt_restart_machine(RESTART_WARM);
+ break;
+ case EFI_RESET_COLD:
+ EFI_ENTRY(L"cold");
+ rt_restart_machine(0);
+ break;
+ case EFI_RESET_PLATFORM_SPECIFIC:
+ EFI_ENTRY(L"platform");
+ rt_restart_machine(0);
+ break;
+ case EFI_RESET_SHUTDOWN:
+ EFI_ENTRY(L"shutdown");
+ rt_poweroff_machine(0);
+ break;
+ }
+
+ __hang();
+}
+
+/**
+ * efirt_get_time() - get current time
+ *
+ * This function implements the GetTime runtime service after
+ * SetVirtualAddressMap() is called. As the barebox driver are not available
+ * anymore only an error code is returned.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification
+ * for details.
+ *
+ * @time: pointer to structure to receive current time
+ * @capabilities: pointer to structure to receive RTC properties
+ * Returns: status code
+ */
+static efi_status_t EFIAPI efirt_get_time(
+ struct efi_time *time,
+ struct efi_time_cap *capabilities)
+{
+ return efirt_unimplemented();
+}
+
+/**
+ * efirt_set_time() - set current time
+ *
+ * This function implements the SetTime runtime service after
+ * SetVirtualAddressMap() is called. As the barebox driver are not available
+ * anymore only an error code is returned.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification
+ * for details.
+ *
+ * @time: pointer to structure to with current time
+ * Returns: status code
+ */
+static efi_status_t EFIAPI efirt_set_time(struct efi_time *time)
+{
+ return efirt_unimplemented();
+}
+
+/**
+ * efirt_update_capsule_unsupported() - process information from operating system
+ *
+ * This function implements the UpdateCapsule() runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @capsule_header_array: pointer to array of virtual pointers
+ * @capsule_count: number of pointers in capsule_header_array
+ * @scatter_gather_list: pointer to array of physical pointers
+ * Returns: status code
+ */
+static efi_status_t EFIAPI efirt_update_capsule_unsupported(
+ struct efi_capsule_header **capsule_header_array,
+ size_t capsule_count,
+ u64 scatter_gather_list)
+{
+ return efirt_unimplemented();
+}
+
+/**
+ * efirt_query_capsule_caps_unsupported() - check if capsule is supported
+ *
+ * This function implements the QueryCapsuleCapabilities() runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @capsule_header_array: pointer to array of virtual pointers
+ * @capsule_count: number of pointers in capsule_header_array
+ * @maximum_capsule_size: maximum capsule size
+ * @reset_type: type of reset needed for capsule update
+ * Returns: status code
+ */
+static efi_status_t EFIAPI efirt_query_capsule_caps_unsupported(
+ struct efi_capsule_header **capsule_header_array,
+ size_t capsule_count,
+ u64 *maximum_capsule_size,
+ u32 *reset_type)
+{
+ return efirt_unimplemented();
+}
+
+static efi_status_t EFIAPI efirt_get_wakeup_time(char *enabled, char *pending,
+ struct efi_time *time)
+{
+ return efirt_unimplemented();
+}
+
+static efi_status_t EFIAPI efirt_set_wakeup_time(char enabled,
+ struct efi_time *time)
+{
+ return efirt_unimplemented();
+}
+
+static efi_status_t EFIAPI efirt_set_virtual_address_map(size_t memory_map_size,
+ size_t descriptor_size,
+ uint32_t descriptor_version,
+ struct efi_memory_desc *virtmap)
+{
+ return efirt_unimplemented();
+}
+
+static efi_status_t EFIAPI efirt_convert_pointer(unsigned long dbg, void **address)
+{
+ return efirt_unimplemented();
+}
+
+static efi_status_t EFIAPI
+efirt_get_variable(u16 *variable_name, const efi_guid_t *guid,
+ u32 *attributes, efi_uintn_t *data_size, void *data)
+{
+ efi_status_t ret;
+
+ EFI_ENTRY(variable_name);
+
+ ret = efi_get_variable_mem(variable_name, guid, attributes, data_size,
+ data, NULL, EFI_VARIABLE_RUNTIME_ACCESS);
+
+ /* Remove EFI_VARIABLE_READ_ONLY flag */
+ if (attributes)
+ *attributes &= EFI_VARIABLE_MASK;
+
+ return EFI_EXIT(ret);
+}
+
+static efi_status_t EFIAPI
+efirt_get_next_variable_name(efi_uintn_t *variable_name_size,
+ u16 *variable_name, efi_guid_t *guid)
+{
+ efi_status_t ret;
+
+ EFI_ENTRY(variable_name);
+
+ ret = efi_get_next_variable_name_mem(variable_name_size, variable_name,
+ guid, EFI_VARIABLE_RUNTIME_ACCESS);
+
+ return EFI_EXIT(ret);
+}
+
+/**
+ * efirt_query_variable_info_runtime() - runtime implementation of
+ * QueryVariableInfo()
+ *
+ * @attributes: bitmask to select variables to be
+ * queried
+ * @maximum_variable_storage_size: maximum size of storage area for the
+ * selected variable types
+ * @remaining_variable_storage_size: remaining size of storage are for the
+ * selected variable types
+ * @maximum_variable_size: maximum size of a variable of the
+ * selected type
+ * Returns: status code
+ */
+static efi_status_t EFIAPI
+efirt_query_variable_info(u32 attributes,
+ u64 *maximum_variable_storage_size,
+ u64 *remaining_variable_storage_size,
+ u64 *maximum_variable_size)
+{
+ efi_status_t ret;
+
+ EFI_ENTRY(L"");
+
+ if (!(attributes & EFI_VARIABLE_RUNTIME_ACCESS))
+ return EFI_INVALID_PARAMETER;
+ if ((attributes & (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
+ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS |
+ EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS)))
+ return EFI_UNSUPPORTED;
+
+ ret = efi_query_variable_info_int(attributes,
+ maximum_variable_storage_size,
+ remaining_variable_storage_size,
+ maximum_variable_size);
+
+ return EFI_EXIT(ret);
+}
+
+static efi_status_t EFIAPI efirt_get_next_high_mono_count(uint32_t *high_count)
+{
+ return efirt_unimplemented();
+}
+
+static struct efi_runtime_services efi_runtime_services_detached = {
+ .hdr = {
+ .signature = EFI_RUNTIME_SERVICES_SIGNATURE,
+ .revision = EFI_SPECIFICATION_VERSION,
+ .headersize = sizeof(struct efi_runtime_services),
+ },
+ .get_time = efirt_get_time,
+ .set_time = efirt_set_time,
+ .get_wakeup_time = efirt_get_wakeup_time,
+ .set_wakeup_time = efirt_set_wakeup_time,
+ .set_virtual_address_map = efirt_set_virtual_address_map,
+ .convert_pointer = efirt_convert_pointer,
+ .get_variable = efirt_get_variable,
+ .get_next_variable = efirt_get_next_variable_name,
+ .set_variable = efirt_set_variable,
+ .get_next_high_mono_count = efirt_get_next_high_mono_count,
+ .reset_system = efirt_reset_system,
+ .update_capsule = efirt_update_capsule_unsupported,
+ .query_capsule_caps = efirt_query_capsule_caps_unsupported,
+ .query_variable_info = efirt_query_variable_info,
+};
+
+void efi_runtime_detach(struct efi_system_table *systab)
+{
+ /* Disable boot time services */
+ systab->con_in_handle = NULL;
+ systab->con_in = NULL;
+ systab->con_out_handle = NULL;
+ systab->con_out = NULL;
+ systab->stderr_handle = NULL;
+ systab->std_err = NULL;
+ systab->boottime = NULL;
+
+ systab->runtime = &efi_runtime_services_detached;
+
+ /* Recalculate CRC32 */
+ efi_update_table_header_crc32(&systab->hdr);
+ efi_update_table_header_crc32(&systab->runtime->hdr);
+
+ puts_ll("detached\n");
+}
--
2.47.3
next prev parent reply other threads:[~2025-12-18 11:38 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 10:37 [PATCH v1 00/54] efi: implement EFI loader support in barebox Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 01/54] efi: payload: initrd: fix type mismatch on 32-bit Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 02/54] efi: loader: switch over event/memory key type to efi_uintn_t Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 03/54] lib: vsprintf: print human-readable EFI GUIDs with %pUs Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 04/54] fs: fat: don't duplicate dentries when resolving differently cased paths Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 05/54] efi: loader: add memory accounting Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 06/54] efi: loader: add pool allocator Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 07/54] efi: types: add EFI_RUNTIME_SECTION Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 08/54] resource: assign memory banks a default type and attr Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 09/54] ARM: lds: add EFI runtime service section Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 10/54] ARM: move needed assembly routines into EFI runtime section Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 11/54] crypto: crc32: implement position independent CRC32 Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 12/54] efi: loader: add support for tracing calls back into UEFI Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 13/54] efi: loader: add table utility functions Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 14/54] lib: add charset helpers Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 15/54] efi: loader: add object handling API Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 16/54] efi: loader: add devicepath support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 17/54] efi: loader: add debug support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 18/54] efi: loader: add boot services support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 19/54] efi: loader: add support for runtime services before ExitBootServices Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 20/54] efi: loader: setup root node Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 21/54] efi: loader: add watchdog support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 22/54] efi: loader: move PE implementation out of common code Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 23/54] efi: loader: protocol: add file protocol support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 24/54] efi: loader: protocol: add Block IO support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 25/54] efi: loader: protocol: implement efi_file_from_path Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 26/54] efi: loader: boot: implement LoadImage BootService Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 27/54] efi: loader: add EFI load option handling Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 28/54] efi: loader: protocol: add graphical output protocol support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 29/54] efi: loader: protocol: add console support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 30/54] efi: loader: protocol: add HII support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 31/54] efi: loader: protocol: add unicode collation support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 32/54] efi: loader: protocol: add random number generator protocol Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 33/54] efi: loader: protocol: add device_path_utilities Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 34/54] efi: loader: support formatting only first device path node to text Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 35/54] efi: loader: protocol: add efi_device_path_to_text support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 36/54] restart: allow drivers to register runtime restart handler Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 37/54] poweroff: allow drivers to register runtime poweroff handler Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 38/54] ARM: psci: client: register runtime service " Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 39/54] ARM: psci: client: register runtime service restart handler Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 40/54] hardening: disable some features when EFI runtime support is enabled Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 41/54] filetype: add new filetype for efi-stubbed ARM zImages Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 42/54] bootm: add global.bootm.efi toggle Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 43/54] efi: loader: add ESP boot entry provider Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 44/54] efi: loader: add rudimentary EFI boot manager Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 45/54] efi: loader: implement bootm handler Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 46/54] efi: runtime: add EFI variable support Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 47/54] efi: loader: populate OsIndicationsSupported/PlatformLang variables Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 48/54] ARM: don't disable MMU when EFI booting Ahmad Fatoum
2025-12-18 10:38 ` Ahmad Fatoum [this message]
2025-12-18 10:38 ` [PATCH v1 50/54] efi: runtime: add relocation check Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 51/54] efi: loader: CONFIG_EFI_RT_VOLATILE_STORE Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 52/54] efi: loader: support ExitBootServices Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 53/54] efi: loader: pass along SMBIOS table Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 54/54] ARM: configs: add multi_v7/8_efiloader_defconfig Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251218111242.1527495-50-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox