// SPDX-License-Identifier: GPL-2.0-only /* * runtime-wrappers.c - Runtime Services function call wrappers * * Implementation summary: * ----------------------- * 1. When user/kernel thread requests to execute efi_runtime_service(), * enqueue work to efi_rts_wq. * 2. Caller thread waits for completion until the work is finished * because it's dependent on the return status and execution of * efi_runtime_service(). * For instance, get_variable() and get_next_variable(). * * Copyright (C) 2014 Linaro Ltd. <[email protected]> * * Split off from arch/x86/platform/efi/efi.c * * Copyright (C) 1999 VA Linux Systems * Copyright (C) 1999 Walt Drummond <[email protected]> * Copyright (C) 1999-2002 Hewlett-Packard Co. * Copyright (C) 2005-2008 Intel Co. * Copyright (C) 2013 SuSE Labs */ #define pr_fmt(fmt) … #include <linux/bug.h> #include <linux/efi.h> #include <linux/irqflags.h> #include <linux/mutex.h> #include <linux/semaphore.h> #include <linux/stringify.h> #include <linux/workqueue.h> #include <linux/completion.h> #include <asm/efi.h> /* * Wrap around the new efi_call_virt_generic() macros so that the * code doesn't get too cluttered: */ #define efi_call_virt(f, args...) … efi_rts_args; struct efi_runtime_work efi_rts_work; /* * efi_queue_work: Queue EFI runtime service call and wait for completion * @_rts: EFI runtime service function identifier * @_args: Arguments to pass to the EFI runtime service * * Accesses to efi_runtime_services() are serialized by a binary * semaphore (efi_runtime_lock) and caller waits until the work is * finished, hence _only_ one work is queued at a time and the caller * thread waits for completion. */ #define efi_queue_work(_rts, _args...) … #ifndef arch_efi_save_flags #define arch_efi_save_flags(state_flags) … #define arch_efi_restore_flags(state_flags) … #endif unsigned long efi_call_virt_save_flags(void) { … } void efi_call_virt_check_flags(unsigned long flags, const void *caller) { … } /* * According to section 7.1 of the UEFI spec, Runtime Services are not fully * reentrant, and there are particular combinations of calls that need to be * serialized. (source: UEFI Specification v2.4A) * * Table 31. Rules for Reentry Into Runtime Services * +------------------------------------+-------------------------------+ * | If previous call is busy in | Forbidden to call | * +------------------------------------+-------------------------------+ * | Any | SetVirtualAddressMap() | * +------------------------------------+-------------------------------+ * | ConvertPointer() | ConvertPointer() | * +------------------------------------+-------------------------------+ * | SetVariable() | ResetSystem() | * | UpdateCapsule() | | * | SetTime() | | * | SetWakeupTime() | | * | GetNextHighMonotonicCount() | | * +------------------------------------+-------------------------------+ * | GetVariable() | GetVariable() | * | GetNextVariableName() | GetNextVariableName() | * | SetVariable() | SetVariable() | * | QueryVariableInfo() | QueryVariableInfo() | * | UpdateCapsule() | UpdateCapsule() | * | QueryCapsuleCapabilities() | QueryCapsuleCapabilities() | * | GetNextHighMonotonicCount() | GetNextHighMonotonicCount() | * +------------------------------------+-------------------------------+ * | GetTime() | GetTime() | * | SetTime() | SetTime() | * | GetWakeupTime() | GetWakeupTime() | * | SetWakeupTime() | SetWakeupTime() | * +------------------------------------+-------------------------------+ * * Due to the fact that the EFI pstore may write to the variable store in * interrupt context, we need to use a lock for at least the groups that * contain SetVariable() and QueryVariableInfo(). That leaves little else, as * none of the remaining functions are actually ever called at runtime. * So let's just use a single lock to serialize all Runtime Services calls. */ static DEFINE_SEMAPHORE(efi_runtime_lock, 1); /* * Expose the EFI runtime lock to the UV platform */ #ifdef CONFIG_X86_UV extern struct semaphore __efi_uv_runtime_lock __alias(…); #endif /* * Calls the appropriate efi_runtime_service() with the appropriate * arguments. */ static void __nocfi efi_call_rts(struct work_struct *work) { … } static efi_status_t __efi_queue_work(enum efi_rts_ids id, union efi_rts_args *args) { … } static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) { … } static efi_status_t virt_efi_set_time(efi_time_t *tm) { … } static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending, efi_time_t *tm) { … } static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) { … } static efi_status_t virt_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor, u32 *attr, unsigned long *data_size, void *data) { … } static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, efi_char16_t *name, efi_guid_t *vendor) { … } static efi_status_t virt_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor, u32 attr, unsigned long data_size, void *data) { … } static efi_status_t __nocfi virt_efi_set_variable_nb(efi_char16_t *name, efi_guid_t *vendor, u32 attr, unsigned long data_size, void *data) { … } static efi_status_t virt_efi_query_variable_info(u32 attr, u64 *storage_space, u64 *remaining_space, u64 *max_variable_size) { … } static efi_status_t __nocfi virt_efi_query_variable_info_nb(u32 attr, u64 *storage_space, u64 *remaining_space, u64 *max_variable_size) { … } static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) { … } static void __nocfi virt_efi_reset_system(int reset_type, efi_status_t status, unsigned long data_size, efi_char16_t *data) { … } static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules, unsigned long count, unsigned long sg_list) { … } static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules, unsigned long count, u64 *max_size, int *reset_type) { … } void __init efi_native_runtime_setup(void) { … } #ifdef CONFIG_ACPI_PRMT efi_status_t efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *), u64 param_buffer_addr, void *context) { … } #endif