2 * runtime-wrappers.c - Runtime Services function call wrappers
4 * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
6 * Split off from arch/x86/platform/efi/efi.c
8 * Copyright (C) 1999 VA Linux Systems
9 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
10 * Copyright (C) 1999-2002 Hewlett-Packard Co.
11 * Copyright (C) 2005-2008 Intel Co.
12 * Copyright (C) 2013 SuSE Labs
14 * This file is released under the GPLv2.
17 #include <linux/efi.h>
18 #include <linux/spinlock.h> /* spinlock_t */
22 * As per commit ef68c8f87ed1 ("x86: Serialize EFI time accesses on rtc_lock"),
23 * the EFI specification requires that callers of the time related runtime
24 * functions serialize with other CMOS accesses in the kernel, as the EFI time
25 * functions may choose to also use the legacy CMOS RTC.
27 __weak DEFINE_SPINLOCK(rtc_lock);
29 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
34 spin_lock_irqsave(&rtc_lock, flags);
35 status = efi_call_virt(get_time, tm, tc);
36 spin_unlock_irqrestore(&rtc_lock, flags);
40 static efi_status_t virt_efi_set_time(efi_time_t *tm)
45 spin_lock_irqsave(&rtc_lock, flags);
46 status = efi_call_virt(set_time, tm);
47 spin_unlock_irqrestore(&rtc_lock, flags);
51 static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
58 spin_lock_irqsave(&rtc_lock, flags);
59 status = efi_call_virt(get_wakeup_time, enabled, pending, tm);
60 spin_unlock_irqrestore(&rtc_lock, flags);
64 static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
69 spin_lock_irqsave(&rtc_lock, flags);
70 status = efi_call_virt(set_wakeup_time, enabled, tm);
71 spin_unlock_irqrestore(&rtc_lock, flags);
75 static efi_status_t virt_efi_get_variable(efi_char16_t *name,
78 unsigned long *data_size,
81 return efi_call_virt(get_variable, name, vendor, attr, data_size, data);
84 static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
88 return efi_call_virt(get_next_variable, name_size, name, vendor);
91 static efi_status_t virt_efi_set_variable(efi_char16_t *name,
94 unsigned long data_size,
97 return efi_call_virt(set_variable, name, vendor, attr, data_size, data);
100 static efi_status_t virt_efi_query_variable_info(u32 attr,
102 u64 *remaining_space,
103 u64 *max_variable_size)
105 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
106 return EFI_UNSUPPORTED;
108 return efi_call_virt(query_variable_info, attr, storage_space,
109 remaining_space, max_variable_size);
112 static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
114 return efi_call_virt(get_next_high_mono_count, count);
117 static void virt_efi_reset_system(int reset_type,
119 unsigned long data_size,
122 __efi_call_virt(reset_system, reset_type, status, data_size, data);
125 static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
127 unsigned long sg_list)
129 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
130 return EFI_UNSUPPORTED;
132 return efi_call_virt(update_capsule, capsules, count, sg_list);
135 static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
140 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
141 return EFI_UNSUPPORTED;
143 return efi_call_virt(query_capsule_caps, capsules, count, max_size,
147 void efi_native_runtime_setup(void)
149 efi.get_time = virt_efi_get_time;
150 efi.set_time = virt_efi_set_time;
151 efi.get_wakeup_time = virt_efi_get_wakeup_time;
152 efi.set_wakeup_time = virt_efi_set_wakeup_time;
153 efi.get_variable = virt_efi_get_variable;
154 efi.get_next_variable = virt_efi_get_next_variable;
155 efi.set_variable = virt_efi_set_variable;
156 efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
157 efi.reset_system = virt_efi_reset_system;
158 efi.query_variable_info = virt_efi_query_variable_info;
159 efi.update_capsule = virt_efi_update_capsule;
160 efi.query_capsule_caps = virt_efi_query_capsule_caps;