Skip to content

Commit 022ee6c

Browse files
Ard BiesheuvelMatt Fleming
authored andcommitted
efi/x86: Move UEFI Runtime Services wrappers to generic code
In order for other archs (such as arm64) to be able to reuse the virtual mode function call wrappers, move them to drivers/firmware/efi/runtime-wrappers.c. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
1 parent f49182e commit 022ee6c

6 files changed

Lines changed: 170 additions & 142 deletions

File tree

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ config EFI
15221522
bool "EFI runtime service support"
15231523
depends on ACPI
15241524
select UCS2_STRING
1525+
select EFI_RUNTIME_WRAPPERS
15251526
---help---
15261527
This enables the kernel to use EFI runtime services that are
15271528
available (such as the EFI variable services).

‎arch/x86/platform/efi/efi.c‎

Lines changed: 2 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -88,130 +88,6 @@ static int __init setup_add_efi_memmap(char *arg)
8888
}
8989
early_param("add_efi_memmap", setup_add_efi_memmap);
9090

91-
static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
92-
{
93-
unsigned long flags;
94-
efi_status_t status;
95-
96-
spin_lock_irqsave(&rtc_lock, flags);
97-
status = efi_call_virt(get_time, tm, tc);
98-
spin_unlock_irqrestore(&rtc_lock, flags);
99-
return status;
100-
}
101-
102-
static efi_status_t virt_efi_set_time(efi_time_t *tm)
103-
{
104-
unsigned long flags;
105-
efi_status_t status;
106-
107-
spin_lock_irqsave(&rtc_lock, flags);
108-
status = efi_call_virt(set_time, tm);
109-
spin_unlock_irqrestore(&rtc_lock, flags);
110-
return status;
111-
}
112-
113-
static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
114-
efi_bool_t *pending,
115-
efi_time_t *tm)
116-
{
117-
unsigned long flags;
118-
efi_status_t status;
119-
120-
spin_lock_irqsave(&rtc_lock, flags);
121-
status = efi_call_virt(get_wakeup_time, enabled, pending, tm);
122-
spin_unlock_irqrestore(&rtc_lock, flags);
123-
return status;
124-
}
125-
126-
static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
127-
{
128-
unsigned long flags;
129-
efi_status_t status;
130-
131-
spin_lock_irqsave(&rtc_lock, flags);
132-
status = efi_call_virt(set_wakeup_time, enabled, tm);
133-
spin_unlock_irqrestore(&rtc_lock, flags);
134-
return status;
135-
}
136-
137-
static efi_status_t virt_efi_get_variable(efi_char16_t *name,
138-
efi_guid_t *vendor,
139-
u32 *attr,
140-
unsigned long *data_size,
141-
void *data)
142-
{
143-
return efi_call_virt(get_variable,
144-
name, vendor, attr,
145-
data_size, data);
146-
}
147-
148-
static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
149-
efi_char16_t *name,
150-
efi_guid_t *vendor)
151-
{
152-
return efi_call_virt(get_next_variable,
153-
name_size, name, vendor);
154-
}
155-
156-
static efi_status_t virt_efi_set_variable(efi_char16_t *name,
157-
efi_guid_t *vendor,
158-
u32 attr,
159-
unsigned long data_size,
160-
void *data)
161-
{
162-
return efi_call_virt(set_variable,
163-
name, vendor, attr,
164-
data_size, data);
165-
}
166-
167-
static efi_status_t virt_efi_query_variable_info(u32 attr,
168-
u64 *storage_space,
169-
u64 *remaining_space,
170-
u64 *max_variable_size)
171-
{
172-
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
173-
return EFI_UNSUPPORTED;
174-
175-
return efi_call_virt(query_variable_info, attr, storage_space,
176-
remaining_space, max_variable_size);
177-
}
178-
179-
static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
180-
{
181-
return efi_call_virt(get_next_high_mono_count, count);
182-
}
183-
184-
static void virt_efi_reset_system(int reset_type,
185-
efi_status_t status,
186-
unsigned long data_size,
187-
efi_char16_t *data)
188-
{
189-
__efi_call_virt(reset_system, reset_type, status,
190-
data_size, data);
191-
}
192-
193-
static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
194-
unsigned long count,
195-
unsigned long sg_list)
196-
{
197-
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
198-
return EFI_UNSUPPORTED;
199-
200-
return efi_call_virt(update_capsule, capsules, count, sg_list);
201-
}
202-
203-
static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
204-
unsigned long count,
205-
u64 *max_size,
206-
int *reset_type)
207-
{
208-
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
209-
return EFI_UNSUPPORTED;
210-
211-
return efi_call_virt(query_capsule_caps, capsules, count, max_size,
212-
reset_type);
213-
}
214-
21591
static efi_status_t __init phys_efi_set_virtual_address_map(
21692
unsigned long memory_map_size,
21793
unsigned long descriptor_size,
@@ -721,22 +597,6 @@ void __init old_map_region(efi_memory_desc_t *md)
721597
(unsigned long long)md->phys_addr);
722598
}
723599

724-
static void native_runtime_setup(void)
725-
{
726-
efi.get_time = virt_efi_get_time;
727-
efi.set_time = virt_efi_set_time;
728-
efi.get_wakeup_time = virt_efi_get_wakeup_time;
729-
efi.set_wakeup_time = virt_efi_set_wakeup_time;
730-
efi.get_variable = virt_efi_get_variable;
731-
efi.get_next_variable = virt_efi_get_next_variable;
732-
efi.set_variable = virt_efi_set_variable;
733-
efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
734-
efi.reset_system = virt_efi_reset_system;
735-
efi.query_variable_info = virt_efi_query_variable_info;
736-
efi.update_capsule = virt_efi_update_capsule;
737-
efi.query_capsule_caps = virt_efi_query_capsule_caps;
738-
}
739-
740600
/* Merge contiguous regions of the same type and attribute */
741601
static void __init efi_merge_regions(void)
742602
{
@@ -923,7 +783,7 @@ static void __init kexec_enter_virtual_mode(void)
923783
*/
924784
efi.runtime_version = efi_systab.hdr.revision;
925785

926-
native_runtime_setup();
786+
efi_native_runtime_setup();
927787

928788
efi.set_virtual_address_map = NULL;
929789

@@ -1012,7 +872,7 @@ static void __init __efi_enter_virtual_mode(void)
1012872
efi.runtime_version = efi_systab.hdr.revision;
1013873

1014874
if (efi_is_native())
1015-
native_runtime_setup();
875+
efi_native_runtime_setup();
1016876
else
1017877
efi_thunk_runtime_setup();
1018878

‎drivers/firmware/efi/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ config EFI_PARAMS_FROM_FDT
5454
the EFI runtime support gets system table address, memory
5555
map address, and other parameters from the device tree.
5656

57+
config EFI_RUNTIME_WRAPPERS
58+
bool
59+
5760
endmenu
5861

5962
config UEFI_CPER

‎drivers/firmware/efi/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ obj-$(CONFIG_EFI_VARS) += efivars.o
66
obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o
77
obj-$(CONFIG_UEFI_CPER) += cper.o
88
obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o
9+
obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* runtime-wrappers.c - Runtime Services function call wrappers
3+
*
4+
* Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
5+
*
6+
* Split off from arch/x86/platform/efi/efi.c
7+
*
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
13+
*
14+
* This file is released under the GPLv2.
15+
*/
16+
17+
#include <linux/efi.h>
18+
#include <linux/spinlock.h> /* spinlock_t */
19+
#include <asm/efi.h>
20+
21+
/*
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.
26+
*/
27+
__weak DEFINE_SPINLOCK(rtc_lock);
28+
29+
static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
30+
{
31+
unsigned long flags;
32+
efi_status_t status;
33+
34+
spin_lock_irqsave(&rtc_lock, flags);
35+
status = efi_call_virt(get_time, tm, tc);
36+
spin_unlock_irqrestore(&rtc_lock, flags);
37+
return status;
38+
}
39+
40+
static efi_status_t virt_efi_set_time(efi_time_t *tm)
41+
{
42+
unsigned long flags;
43+
efi_status_t status;
44+
45+
spin_lock_irqsave(&rtc_lock, flags);
46+
status = efi_call_virt(set_time, tm);
47+
spin_unlock_irqrestore(&rtc_lock, flags);
48+
return status;
49+
}
50+
51+
static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
52+
efi_bool_t *pending,
53+
efi_time_t *tm)
54+
{
55+
unsigned long flags;
56+
efi_status_t status;
57+
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);
61+
return status;
62+
}
63+
64+
static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
65+
{
66+
unsigned long flags;
67+
efi_status_t status;
68+
69+
spin_lock_irqsave(&rtc_lock, flags);
70+
status = efi_call_virt(set_wakeup_time, enabled, tm);
71+
spin_unlock_irqrestore(&rtc_lock, flags);
72+
return status;
73+
}
74+
75+
static efi_status_t virt_efi_get_variable(efi_char16_t *name,
76+
efi_guid_t *vendor,
77+
u32 *attr,
78+
unsigned long *data_size,
79+
void *data)
80+
{
81+
return efi_call_virt(get_variable, name, vendor, attr, data_size, data);
82+
}
83+
84+
static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
85+
efi_char16_t *name,
86+
efi_guid_t *vendor)
87+
{
88+
return efi_call_virt(get_next_variable, name_size, name, vendor);
89+
}
90+
91+
static efi_status_t virt_efi_set_variable(efi_char16_t *name,
92+
efi_guid_t *vendor,
93+
u32 attr,
94+
unsigned long data_size,
95+
void *data)
96+
{
97+
return efi_call_virt(set_variable, name, vendor, attr, data_size, data);
98+
}
99+
100+
static efi_status_t virt_efi_query_variable_info(u32 attr,
101+
u64 *storage_space,
102+
u64 *remaining_space,
103+
u64 *max_variable_size)
104+
{
105+
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
106+
return EFI_UNSUPPORTED;
107+
108+
return efi_call_virt(query_variable_info, attr, storage_space,
109+
remaining_space, max_variable_size);
110+
}
111+
112+
static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
113+
{
114+
return efi_call_virt(get_next_high_mono_count, count);
115+
}
116+
117+
static void virt_efi_reset_system(int reset_type,
118+
efi_status_t status,
119+
unsigned long data_size,
120+
efi_char16_t *data)
121+
{
122+
__efi_call_virt(reset_system, reset_type, status, data_size, data);
123+
}
124+
125+
static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
126+
unsigned long count,
127+
unsigned long sg_list)
128+
{
129+
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
130+
return EFI_UNSUPPORTED;
131+
132+
return efi_call_virt(update_capsule, capsules, count, sg_list);
133+
}
134+
135+
static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
136+
unsigned long count,
137+
u64 *max_size,
138+
int *reset_type)
139+
{
140+
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
141+
return EFI_UNSUPPORTED;
142+
143+
return efi_call_virt(query_capsule_caps, capsules, count, max_size,
144+
reset_type);
145+
}
146+
147+
void efi_native_runtime_setup(void)
148+
{
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;
161+
}

‎include/linux/efi.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
521521
int *reset_type);
522522
typedef efi_status_t efi_query_variable_store_t(u32 attributes, unsigned long size);
523523

524+
void efi_native_runtime_setup(void);
525+
524526
/*
525527
* EFI Configuration Table and GUID definitions
526528
*/

0 commit comments

Comments
 (0)