Commit | Line | Data |
---|---|---|
5b83683f HY |
1 | /* |
2 | * Common EFI (Extensible Firmware Interface) support functions | |
3 | * Based on Extensible Firmware Interface Specification version 1.0 | |
4 | * | |
5 | * Copyright (C) 1999 VA Linux Systems | |
6 | * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> | |
7 | * Copyright (C) 1999-2002 Hewlett-Packard Co. | |
8 | * David Mosberger-Tang <davidm@hpl.hp.com> | |
9 | * Stephane Eranian <eranian@hpl.hp.com> | |
10 | * Copyright (C) 2005-2008 Intel Co. | |
11 | * Fenghua Yu <fenghua.yu@intel.com> | |
12 | * Bibo Mao <bibo.mao@intel.com> | |
13 | * Chandramouli Narayanan <mouli@linux.intel.com> | |
14 | * Huang Ying <ying.huang@intel.com> | |
d2f7cbe7 BP |
15 | * Copyright (C) 2013 SuSE Labs |
16 | * Borislav Petkov <bp@suse.de> - runtime services VA mapping | |
5b83683f HY |
17 | * |
18 | * Copied from efi_32.c to eliminate the duplicated code between EFI | |
19 | * 32/64 support code. --ying 2007-10-26 | |
20 | * | |
21 | * All EFI Runtime Services are not implemented yet as EFI only | |
22 | * supports physical mode addressing on SoftSDV. This is to be fixed | |
23 | * in a future version. --drummond 1999-07-20 | |
24 | * | |
25 | * Implemented EFI runtime services and virtual mode calls. --davidm | |
26 | * | |
27 | * Goutham Rao: <goutham.rao@intel.com> | |
28 | * Skip non-WB memory and ignore empty memory ranges. | |
29 | */ | |
30 | ||
e3cb3f5a OJ |
31 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
32 | ||
5b83683f HY |
33 | #include <linux/kernel.h> |
34 | #include <linux/init.h> | |
35 | #include <linux/efi.h> | |
2223af38 | 36 | #include <linux/efi-bgrt.h> |
69c60c88 | 37 | #include <linux/export.h> |
5b83683f | 38 | #include <linux/bootmem.h> |
0d01ff25 | 39 | #include <linux/slab.h> |
a9ce6bc1 | 40 | #include <linux/memblock.h> |
5b83683f HY |
41 | #include <linux/spinlock.h> |
42 | #include <linux/uaccess.h> | |
43 | #include <linux/time.h> | |
44 | #include <linux/io.h> | |
45 | #include <linux/reboot.h> | |
46 | #include <linux/bcd.h> | |
47 | ||
48 | #include <asm/setup.h> | |
49 | #include <asm/efi.h> | |
50 | #include <asm/time.h> | |
a2172e25 HY |
51 | #include <asm/cacheflush.h> |
52 | #include <asm/tlbflush.h> | |
7bd867df | 53 | #include <asm/x86_init.h> |
3195ef59 | 54 | #include <asm/rtc.h> |
5b83683f | 55 | |
f4fccac0 | 56 | #define EFI_DEBUG |
5b83683f | 57 | |
f8b84043 MG |
58 | #define EFI_MIN_RESERVE 5120 |
59 | ||
60 | #define EFI_DUMMY_GUID \ | |
61 | EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) | |
62 | ||
63 | static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; | |
31ff2f20 | 64 | |
5b83683f HY |
65 | struct efi_memory_map memmap; |
66 | ||
ecaea42e | 67 | static struct efi efi_phys __initdata; |
5b83683f HY |
68 | static efi_system_table_t efi_systab __initdata; |
69 | ||
83e68189 MF |
70 | unsigned long x86_efi_facility; |
71 | ||
272686bf LL |
72 | static __initdata efi_config_table_type_t arch_tables[] = { |
73 | #ifdef CONFIG_X86_UV | |
74 | {UV_SYSTEM_TABLE_GUID, "UVsystab", &efi.uv_systab}, | |
75 | #endif | |
722da9d2 | 76 | {NULL_GUID, NULL, NULL}, |
272686bf LL |
77 | }; |
78 | ||
83e68189 MF |
79 | /* |
80 | * Returns 1 if 'facility' is enabled, 0 otherwise. | |
81 | */ | |
82 | int efi_enabled(int facility) | |
83 | { | |
84 | return test_bit(facility, &x86_efi_facility) != 0; | |
5189c2a7 | 85 | } |
83e68189 | 86 | EXPORT_SYMBOL(efi_enabled); |
5189c2a7 | 87 | |
058e7b58 | 88 | static bool __initdata disable_runtime = false; |
8b2cb7a8 HY |
89 | static int __init setup_noefi(char *arg) |
90 | { | |
fb834c7a | 91 | disable_runtime = true; |
8b2cb7a8 HY |
92 | return 0; |
93 | } | |
94 | early_param("noefi", setup_noefi); | |
95 | ||
200001eb PJ |
96 | int add_efi_memmap; |
97 | EXPORT_SYMBOL(add_efi_memmap); | |
98 | ||
99 | static int __init setup_add_efi_memmap(char *arg) | |
100 | { | |
101 | add_efi_memmap = 1; | |
102 | return 0; | |
103 | } | |
104 | early_param("add_efi_memmap", setup_add_efi_memmap); | |
105 | ||
8c58bf3e RW |
106 | static bool efi_no_storage_paranoia; |
107 | ||
108 | static int __init setup_storage_paranoia(char *arg) | |
109 | { | |
110 | efi_no_storage_paranoia = true; | |
111 | return 0; | |
112 | } | |
113 | early_param("efi_no_storage_paranoia", setup_storage_paranoia); | |
114 | ||
200001eb | 115 | |
5b83683f HY |
116 | static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) |
117 | { | |
ef68c8f8 JB |
118 | unsigned long flags; |
119 | efi_status_t status; | |
120 | ||
121 | spin_lock_irqsave(&rtc_lock, flags); | |
122 | status = efi_call_virt2(get_time, tm, tc); | |
123 | spin_unlock_irqrestore(&rtc_lock, flags); | |
124 | return status; | |
5b83683f HY |
125 | } |
126 | ||
127 | static efi_status_t virt_efi_set_time(efi_time_t *tm) | |
128 | { | |
ef68c8f8 JB |
129 | unsigned long flags; |
130 | efi_status_t status; | |
131 | ||
132 | spin_lock_irqsave(&rtc_lock, flags); | |
133 | status = efi_call_virt1(set_time, tm); | |
134 | spin_unlock_irqrestore(&rtc_lock, flags); | |
135 | return status; | |
5b83683f HY |
136 | } |
137 | ||
138 | static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, | |
139 | efi_bool_t *pending, | |
140 | efi_time_t *tm) | |
141 | { | |
ef68c8f8 JB |
142 | unsigned long flags; |
143 | efi_status_t status; | |
144 | ||
145 | spin_lock_irqsave(&rtc_lock, flags); | |
146 | status = efi_call_virt3(get_wakeup_time, | |
147 | enabled, pending, tm); | |
148 | spin_unlock_irqrestore(&rtc_lock, flags); | |
149 | return status; | |
5b83683f HY |
150 | } |
151 | ||
152 | static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) | |
153 | { | |
ef68c8f8 JB |
154 | unsigned long flags; |
155 | efi_status_t status; | |
156 | ||
157 | spin_lock_irqsave(&rtc_lock, flags); | |
158 | status = efi_call_virt2(set_wakeup_time, | |
159 | enabled, tm); | |
160 | spin_unlock_irqrestore(&rtc_lock, flags); | |
161 | return status; | |
5b83683f HY |
162 | } |
163 | ||
164 | static efi_status_t virt_efi_get_variable(efi_char16_t *name, | |
165 | efi_guid_t *vendor, | |
166 | u32 *attr, | |
167 | unsigned long *data_size, | |
168 | void *data) | |
169 | { | |
170 | return efi_call_virt5(get_variable, | |
171 | name, vendor, attr, | |
172 | data_size, data); | |
173 | } | |
174 | ||
175 | static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, | |
176 | efi_char16_t *name, | |
177 | efi_guid_t *vendor) | |
178 | { | |
f8b84043 MG |
179 | return efi_call_virt3(get_next_variable, |
180 | name_size, name, vendor); | |
5b83683f HY |
181 | } |
182 | ||
183 | static efi_status_t virt_efi_set_variable(efi_char16_t *name, | |
184 | efi_guid_t *vendor, | |
f7a2d73f | 185 | u32 attr, |
5b83683f HY |
186 | unsigned long data_size, |
187 | void *data) | |
188 | { | |
f8b84043 MG |
189 | return efi_call_virt5(set_variable, |
190 | name, vendor, attr, | |
191 | data_size, data); | |
5b83683f HY |
192 | } |
193 | ||
3b370237 MG |
194 | static efi_status_t virt_efi_query_variable_info(u32 attr, |
195 | u64 *storage_space, | |
196 | u64 *remaining_space, | |
197 | u64 *max_variable_size) | |
198 | { | |
199 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) | |
200 | return EFI_UNSUPPORTED; | |
201 | ||
202 | return efi_call_virt4(query_variable_info, attr, storage_space, | |
203 | remaining_space, max_variable_size); | |
204 | } | |
205 | ||
5b83683f HY |
206 | static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) |
207 | { | |
208 | return efi_call_virt1(get_next_high_mono_count, count); | |
209 | } | |
210 | ||
211 | static void virt_efi_reset_system(int reset_type, | |
212 | efi_status_t status, | |
213 | unsigned long data_size, | |
214 | efi_char16_t *data) | |
215 | { | |
216 | efi_call_virt4(reset_system, reset_type, status, | |
217 | data_size, data); | |
218 | } | |
219 | ||
3b370237 MG |
220 | static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules, |
221 | unsigned long count, | |
222 | unsigned long sg_list) | |
223 | { | |
224 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) | |
225 | return EFI_UNSUPPORTED; | |
226 | ||
227 | return efi_call_virt3(update_capsule, capsules, count, sg_list); | |
228 | } | |
229 | ||
230 | static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules, | |
231 | unsigned long count, | |
232 | u64 *max_size, | |
233 | int *reset_type) | |
234 | { | |
235 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) | |
236 | return EFI_UNSUPPORTED; | |
237 | ||
238 | return efi_call_virt4(query_capsule_caps, capsules, count, max_size, | |
239 | reset_type); | |
240 | } | |
241 | ||
5b83683f HY |
242 | static efi_status_t __init phys_efi_set_virtual_address_map( |
243 | unsigned long memory_map_size, | |
244 | unsigned long descriptor_size, | |
245 | u32 descriptor_version, | |
246 | efi_memory_desc_t *virtual_map) | |
247 | { | |
248 | efi_status_t status; | |
249 | ||
250 | efi_call_phys_prelog(); | |
251 | status = efi_call_phys4(efi_phys.set_virtual_address_map, | |
252 | memory_map_size, descriptor_size, | |
253 | descriptor_version, virtual_map); | |
254 | efi_call_phys_epilog(); | |
255 | return status; | |
256 | } | |
257 | ||
11520e5e LT |
258 | static efi_status_t __init phys_efi_get_time(efi_time_t *tm, |
259 | efi_time_cap_t *tc) | |
260 | { | |
261 | unsigned long flags; | |
262 | efi_status_t status; | |
263 | ||
264 | spin_lock_irqsave(&rtc_lock, flags); | |
265 | efi_call_phys_prelog(); | |
266 | status = efi_call_phys2(efi_phys.get_time, virt_to_phys(tm), | |
267 | virt_to_phys(tc)); | |
268 | efi_call_phys_epilog(); | |
269 | spin_unlock_irqrestore(&rtc_lock, flags); | |
270 | return status; | |
271 | } | |
272 | ||
3565184e | 273 | int efi_set_rtc_mmss(const struct timespec *now) |
5b83683f | 274 | { |
3565184e | 275 | unsigned long nowtime = now->tv_sec; |
5b83683f HY |
276 | efi_status_t status; |
277 | efi_time_t eft; | |
278 | efi_time_cap_t cap; | |
3195ef59 | 279 | struct rtc_time tm; |
5b83683f HY |
280 | |
281 | status = efi.get_time(&eft, &cap); | |
282 | if (status != EFI_SUCCESS) { | |
e3cb3f5a | 283 | pr_err("Oops: efitime: can't read time!\n"); |
5b83683f HY |
284 | return -1; |
285 | } | |
286 | ||
3195ef59 PB |
287 | rtc_time_to_tm(nowtime, &tm); |
288 | if (!rtc_valid_tm(&tm)) { | |
289 | eft.year = tm.tm_year + 1900; | |
290 | eft.month = tm.tm_mon + 1; | |
291 | eft.day = tm.tm_mday; | |
292 | eft.minute = tm.tm_min; | |
293 | eft.second = tm.tm_sec; | |
294 | eft.nanosecond = 0; | |
295 | } else { | |
296 | printk(KERN_ERR | |
297 | "%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n", | |
298 | __FUNCTION__, nowtime); | |
299 | return -1; | |
300 | } | |
5b83683f HY |
301 | |
302 | status = efi.set_time(&eft); | |
303 | if (status != EFI_SUCCESS) { | |
e3cb3f5a | 304 | pr_err("Oops: efitime: can't write time!\n"); |
5b83683f HY |
305 | return -1; |
306 | } | |
307 | return 0; | |
308 | } | |
309 | ||
3565184e | 310 | void efi_get_time(struct timespec *now) |
5b83683f HY |
311 | { |
312 | efi_status_t status; | |
313 | efi_time_t eft; | |
314 | efi_time_cap_t cap; | |
315 | ||
316 | status = efi.get_time(&eft, &cap); | |
317 | if (status != EFI_SUCCESS) | |
e3cb3f5a | 318 | pr_err("Oops: efitime: can't read time!\n"); |
5b83683f | 319 | |
3565184e DV |
320 | now->tv_sec = mktime(eft.year, eft.month, eft.day, eft.hour, |
321 | eft.minute, eft.second); | |
322 | now->tv_nsec = 0; | |
5b83683f HY |
323 | } |
324 | ||
69c91893 PJ |
325 | /* |
326 | * Tell the kernel about the EFI memory map. This might include | |
327 | * more than the max 128 entries that can fit in the e820 legacy | |
328 | * (zeropage) memory map. | |
329 | */ | |
330 | ||
200001eb | 331 | static void __init do_add_efi_memmap(void) |
69c91893 PJ |
332 | { |
333 | void *p; | |
334 | ||
335 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | |
336 | efi_memory_desc_t *md = p; | |
337 | unsigned long long start = md->phys_addr; | |
338 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; | |
339 | int e820_type; | |
340 | ||
e2a71476 CW |
341 | switch (md->type) { |
342 | case EFI_LOADER_CODE: | |
343 | case EFI_LOADER_DATA: | |
344 | case EFI_BOOT_SERVICES_CODE: | |
345 | case EFI_BOOT_SERVICES_DATA: | |
346 | case EFI_CONVENTIONAL_MEMORY: | |
347 | if (md->attribute & EFI_MEMORY_WB) | |
348 | e820_type = E820_RAM; | |
349 | else | |
350 | e820_type = E820_RESERVED; | |
351 | break; | |
352 | case EFI_ACPI_RECLAIM_MEMORY: | |
353 | e820_type = E820_ACPI; | |
354 | break; | |
355 | case EFI_ACPI_MEMORY_NVS: | |
356 | e820_type = E820_NVS; | |
357 | break; | |
358 | case EFI_UNUSABLE_MEMORY: | |
359 | e820_type = E820_UNUSABLE; | |
360 | break; | |
361 | default: | |
362 | /* | |
363 | * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE | |
364 | * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO | |
365 | * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE | |
366 | */ | |
69c91893 | 367 | e820_type = E820_RESERVED; |
e2a71476 CW |
368 | break; |
369 | } | |
d0be6bde | 370 | e820_add_region(start, size, e820_type); |
69c91893 PJ |
371 | } |
372 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); | |
373 | } | |
374 | ||
1adbfa35 | 375 | int __init efi_memblock_x86_reserve_range(void) |
ecacf09f | 376 | { |
15b9c359 | 377 | struct efi_info *e = &boot_params.efi_info; |
ecacf09f HY |
378 | unsigned long pmap; |
379 | ||
05486fa7 | 380 | #ifdef CONFIG_X86_32 |
1adbfa35 | 381 | /* Can't handle data above 4GB at this time */ |
15b9c359 | 382 | if (e->efi_memmap_hi) { |
1adbfa35 OJ |
383 | pr_err("Memory map is above 4GB, disabling EFI.\n"); |
384 | return -EINVAL; | |
385 | } | |
15b9c359 | 386 | pmap = e->efi_memmap; |
05486fa7 | 387 | #else |
15b9c359 | 388 | pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32)); |
ecacf09f | 389 | #endif |
15b9c359 BP |
390 | memmap.phys_map = (void *)pmap; |
391 | memmap.nr_map = e->efi_memmap_size / | |
392 | e->efi_memdesc_size; | |
393 | memmap.desc_size = e->efi_memdesc_size; | |
394 | memmap.desc_version = e->efi_memdesc_version; | |
395 | ||
24aa0788 | 396 | memblock_reserve(pmap, memmap.nr_map * memmap.desc_size); |
1adbfa35 | 397 | |
258f6fd7 LL |
398 | efi.memmap = &memmap; |
399 | ||
1adbfa35 | 400 | return 0; |
ecacf09f HY |
401 | } |
402 | ||
5b83683f HY |
403 | static void __init print_efi_memmap(void) |
404 | { | |
f4fccac0 | 405 | #ifdef EFI_DEBUG |
5b83683f HY |
406 | efi_memory_desc_t *md; |
407 | void *p; | |
408 | int i; | |
409 | ||
410 | for (p = memmap.map, i = 0; | |
411 | p < memmap.map_end; | |
412 | p += memmap.desc_size, i++) { | |
413 | md = p; | |
e3cb3f5a | 414 | pr_info("mem%02u: type=%u, attr=0x%llx, " |
5b83683f HY |
415 | "range=[0x%016llx-0x%016llx) (%lluMB)\n", |
416 | i, md->type, md->attribute, md->phys_addr, | |
417 | md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT), | |
418 | (md->num_pages >> (20 - EFI_PAGE_SHIFT))); | |
419 | } | |
5b83683f | 420 | #endif /* EFI_DEBUG */ |
f4fccac0 | 421 | } |
5b83683f | 422 | |
916f676f MG |
423 | void __init efi_reserve_boot_services(void) |
424 | { | |
425 | void *p; | |
426 | ||
427 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | |
428 | efi_memory_desc_t *md = p; | |
7d68dc3f ML |
429 | u64 start = md->phys_addr; |
430 | u64 size = md->num_pages << EFI_PAGE_SHIFT; | |
916f676f MG |
431 | |
432 | if (md->type != EFI_BOOT_SERVICES_CODE && | |
433 | md->type != EFI_BOOT_SERVICES_DATA) | |
434 | continue; | |
7d68dc3f ML |
435 | /* Only reserve where possible: |
436 | * - Not within any already allocated areas | |
437 | * - Not over any memory area (really needed, if above?) | |
438 | * - Not within any part of the kernel | |
439 | * - Not the bios reserved area | |
440 | */ | |
a7f84f03 | 441 | if ((start + size > __pa_symbol(_text) |
fc8d7826 | 442 | && start <= __pa_symbol(_end)) || |
7d68dc3f | 443 | !e820_all_mapped(start, start+size, E820_RAM) || |
bf61549a | 444 | memblock_is_region_reserved(start, size)) { |
7d68dc3f ML |
445 | /* Could not reserve, skip it */ |
446 | md->num_pages = 0; | |
e3cb3f5a | 447 | memblock_dbg("Could not reserve boot range " |
7d68dc3f ML |
448 | "[0x%010llx-0x%010llx]\n", |
449 | start, start+size-1); | |
450 | } else | |
24aa0788 | 451 | memblock_reserve(start, size); |
916f676f MG |
452 | } |
453 | } | |
454 | ||
5189c2a7 | 455 | void __init efi_unmap_memmap(void) |
78510792 | 456 | { |
83e68189 | 457 | clear_bit(EFI_MEMMAP, &x86_efi_facility); |
78510792 JT |
458 | if (memmap.map) { |
459 | early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size); | |
460 | memmap.map = NULL; | |
461 | } | |
462 | } | |
463 | ||
464 | void __init efi_free_boot_services(void) | |
916f676f MG |
465 | { |
466 | void *p; | |
467 | ||
5189c2a7 | 468 | if (!efi_is_native()) |
78510792 JT |
469 | return; |
470 | ||
916f676f MG |
471 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
472 | efi_memory_desc_t *md = p; | |
473 | unsigned long long start = md->phys_addr; | |
474 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; | |
475 | ||
476 | if (md->type != EFI_BOOT_SERVICES_CODE && | |
477 | md->type != EFI_BOOT_SERVICES_DATA) | |
478 | continue; | |
479 | ||
7d68dc3f ML |
480 | /* Could not reserve boot area */ |
481 | if (!size) | |
482 | continue; | |
483 | ||
916f676f MG |
484 | free_bootmem_late(start, size); |
485 | } | |
78510792 JT |
486 | |
487 | efi_unmap_memmap(); | |
916f676f MG |
488 | } |
489 | ||
140bf275 | 490 | static int __init efi_systab_init(void *phys) |
5b83683f | 491 | { |
83e68189 | 492 | if (efi_enabled(EFI_64BIT)) { |
1adbfa35 OJ |
493 | efi_system_table_64_t *systab64; |
494 | u64 tmp = 0; | |
495 | ||
496 | systab64 = early_ioremap((unsigned long)phys, | |
497 | sizeof(*systab64)); | |
498 | if (systab64 == NULL) { | |
499 | pr_err("Couldn't map the system table!\n"); | |
500 | return -ENOMEM; | |
501 | } | |
502 | ||
503 | efi_systab.hdr = systab64->hdr; | |
504 | efi_systab.fw_vendor = systab64->fw_vendor; | |
505 | tmp |= systab64->fw_vendor; | |
506 | efi_systab.fw_revision = systab64->fw_revision; | |
507 | efi_systab.con_in_handle = systab64->con_in_handle; | |
508 | tmp |= systab64->con_in_handle; | |
509 | efi_systab.con_in = systab64->con_in; | |
510 | tmp |= systab64->con_in; | |
511 | efi_systab.con_out_handle = systab64->con_out_handle; | |
512 | tmp |= systab64->con_out_handle; | |
513 | efi_systab.con_out = systab64->con_out; | |
514 | tmp |= systab64->con_out; | |
515 | efi_systab.stderr_handle = systab64->stderr_handle; | |
516 | tmp |= systab64->stderr_handle; | |
517 | efi_systab.stderr = systab64->stderr; | |
518 | tmp |= systab64->stderr; | |
519 | efi_systab.runtime = (void *)(unsigned long)systab64->runtime; | |
520 | tmp |= systab64->runtime; | |
521 | efi_systab.boottime = (void *)(unsigned long)systab64->boottime; | |
522 | tmp |= systab64->boottime; | |
523 | efi_systab.nr_tables = systab64->nr_tables; | |
524 | efi_systab.tables = systab64->tables; | |
525 | tmp |= systab64->tables; | |
526 | ||
527 | early_iounmap(systab64, sizeof(*systab64)); | |
528 | #ifdef CONFIG_X86_32 | |
529 | if (tmp >> 32) { | |
530 | pr_err("EFI data located above 4GB, disabling EFI.\n"); | |
531 | return -EINVAL; | |
532 | } | |
533 | #endif | |
534 | } else { | |
535 | efi_system_table_32_t *systab32; | |
536 | ||
537 | systab32 = early_ioremap((unsigned long)phys, | |
538 | sizeof(*systab32)); | |
539 | if (systab32 == NULL) { | |
540 | pr_err("Couldn't map the system table!\n"); | |
541 | return -ENOMEM; | |
542 | } | |
543 | ||
544 | efi_systab.hdr = systab32->hdr; | |
545 | efi_systab.fw_vendor = systab32->fw_vendor; | |
546 | efi_systab.fw_revision = systab32->fw_revision; | |
547 | efi_systab.con_in_handle = systab32->con_in_handle; | |
548 | efi_systab.con_in = systab32->con_in; | |
549 | efi_systab.con_out_handle = systab32->con_out_handle; | |
550 | efi_systab.con_out = systab32->con_out; | |
551 | efi_systab.stderr_handle = systab32->stderr_handle; | |
552 | efi_systab.stderr = systab32->stderr; | |
553 | efi_systab.runtime = (void *)(unsigned long)systab32->runtime; | |
554 | efi_systab.boottime = (void *)(unsigned long)systab32->boottime; | |
555 | efi_systab.nr_tables = systab32->nr_tables; | |
556 | efi_systab.tables = systab32->tables; | |
557 | ||
558 | early_iounmap(systab32, sizeof(*systab32)); | |
140bf275 | 559 | } |
1adbfa35 | 560 | |
5b83683f HY |
561 | efi.systab = &efi_systab; |
562 | ||
563 | /* | |
564 | * Verify the EFI Table | |
565 | */ | |
140bf275 | 566 | if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { |
e3cb3f5a | 567 | pr_err("System table signature incorrect!\n"); |
140bf275 OJ |
568 | return -EINVAL; |
569 | } | |
5b83683f | 570 | if ((efi.systab->hdr.revision >> 16) == 0) |
e3cb3f5a | 571 | pr_err("Warning: System table version " |
5b83683f HY |
572 | "%d.%02d, expected 1.00 or greater!\n", |
573 | efi.systab->hdr.revision >> 16, | |
574 | efi.systab->hdr.revision & 0xffff); | |
140bf275 OJ |
575 | |
576 | return 0; | |
83e7ee66 | 577 | } |
5b83683f | 578 | |
140bf275 | 579 | static int __init efi_runtime_init(void) |
83e7ee66 OJ |
580 | { |
581 | efi_runtime_services_t *runtime; | |
5b83683f HY |
582 | |
583 | /* | |
584 | * Check out the runtime services table. We need to map | |
585 | * the runtime services table so that we can grab the physical | |
586 | * address of several of the EFI runtime functions, needed to | |
587 | * set the firmware into virtual mode. | |
588 | */ | |
beacfaac HY |
589 | runtime = early_ioremap((unsigned long)efi.systab->runtime, |
590 | sizeof(efi_runtime_services_t)); | |
140bf275 | 591 | if (!runtime) { |
e3cb3f5a | 592 | pr_err("Could not map the runtime service table!\n"); |
140bf275 OJ |
593 | return -ENOMEM; |
594 | } | |
595 | /* | |
596 | * We will only need *early* access to the following | |
11520e5e | 597 | * two EFI runtime services before set_virtual_address_map |
140bf275 OJ |
598 | * is invoked. |
599 | */ | |
11520e5e | 600 | efi_phys.get_time = (efi_get_time_t *)runtime->get_time; |
140bf275 OJ |
601 | efi_phys.set_virtual_address_map = |
602 | (efi_set_virtual_address_map_t *) | |
603 | runtime->set_virtual_address_map; | |
11520e5e LT |
604 | /* |
605 | * Make efi_get_time can be called before entering | |
606 | * virtual mode. | |
607 | */ | |
608 | efi.get_time = phys_efi_get_time; | |
beacfaac | 609 | early_iounmap(runtime, sizeof(efi_runtime_services_t)); |
140bf275 OJ |
610 | |
611 | return 0; | |
83e7ee66 | 612 | } |
5b83683f | 613 | |
140bf275 | 614 | static int __init efi_memmap_init(void) |
83e7ee66 | 615 | { |
5b83683f | 616 | /* Map the EFI memory map */ |
beacfaac HY |
617 | memmap.map = early_ioremap((unsigned long)memmap.phys_map, |
618 | memmap.nr_map * memmap.desc_size); | |
140bf275 | 619 | if (memmap.map == NULL) { |
e3cb3f5a | 620 | pr_err("Could not map the memory map!\n"); |
140bf275 OJ |
621 | return -ENOMEM; |
622 | } | |
5b83683f | 623 | memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size); |
175e438f | 624 | |
200001eb PJ |
625 | if (add_efi_memmap) |
626 | do_add_efi_memmap(); | |
140bf275 OJ |
627 | |
628 | return 0; | |
83e7ee66 OJ |
629 | } |
630 | ||
631 | void __init efi_init(void) | |
632 | { | |
633 | efi_char16_t *c16; | |
634 | char vendor[100] = "unknown"; | |
635 | int i = 0; | |
636 | void *tmp; | |
637 | ||
638 | #ifdef CONFIG_X86_32 | |
1adbfa35 OJ |
639 | if (boot_params.efi_info.efi_systab_hi || |
640 | boot_params.efi_info.efi_memmap_hi) { | |
641 | pr_info("Table located above 4GB, disabling EFI.\n"); | |
1adbfa35 OJ |
642 | return; |
643 | } | |
83e7ee66 OJ |
644 | efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; |
645 | #else | |
646 | efi_phys.systab = (efi_system_table_t *) | |
1adbfa35 OJ |
647 | (boot_params.efi_info.efi_systab | |
648 | ((__u64)boot_params.efi_info.efi_systab_hi<<32)); | |
83e7ee66 OJ |
649 | #endif |
650 | ||
83e68189 | 651 | if (efi_systab_init(efi_phys.systab)) |
140bf275 | 652 | return; |
83e68189 MF |
653 | |
654 | set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility); | |
83e7ee66 OJ |
655 | |
656 | /* | |
657 | * Show what we know for posterity | |
658 | */ | |
659 | c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2); | |
660 | if (c16) { | |
661 | for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i) | |
662 | vendor[i] = *c16++; | |
663 | vendor[i] = '\0'; | |
664 | } else | |
e3cb3f5a | 665 | pr_err("Could not map the firmware vendor!\n"); |
83e7ee66 OJ |
666 | early_iounmap(tmp, 2); |
667 | ||
e3cb3f5a OJ |
668 | pr_info("EFI v%u.%.02u by %s\n", |
669 | efi.systab->hdr.revision >> 16, | |
670 | efi.systab->hdr.revision & 0xffff, vendor); | |
83e7ee66 | 671 | |
272686bf | 672 | if (efi_config_init(arch_tables)) |
140bf275 | 673 | return; |
83e68189 MF |
674 | |
675 | set_bit(EFI_CONFIG_TABLES, &x86_efi_facility); | |
83e7ee66 | 676 | |
1adbfa35 OJ |
677 | /* |
678 | * Note: We currently don't support runtime services on an EFI | |
679 | * that doesn't match the kernel 32/64-bit mode. | |
680 | */ | |
681 | ||
5189c2a7 | 682 | if (!efi_is_native()) |
1adbfa35 | 683 | pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n"); |
83e68189 | 684 | else { |
fb834c7a | 685 | if (disable_runtime || efi_runtime_init()) |
83e68189 MF |
686 | return; |
687 | set_bit(EFI_RUNTIME_SERVICES, &x86_efi_facility); | |
140bf275 | 688 | } |
83e7ee66 | 689 | |
83e68189 | 690 | if (efi_memmap_init()) |
140bf275 | 691 | return; |
83e68189 MF |
692 | |
693 | set_bit(EFI_MEMMAP, &x86_efi_facility); | |
694 | ||
11520e5e | 695 | #ifdef CONFIG_X86_32 |
5189c2a7 | 696 | if (efi_is_native()) { |
1adbfa35 OJ |
697 | x86_platform.get_wallclock = efi_get_time; |
698 | x86_platform.set_wallclock = efi_set_rtc_mmss; | |
699 | } | |
11520e5e | 700 | #endif |
5b83683f | 701 | print_efi_memmap(); |
5b83683f HY |
702 | } |
703 | ||
2223af38 JT |
704 | void __init efi_late_init(void) |
705 | { | |
706 | efi_bgrt_init(); | |
707 | } | |
708 | ||
9cd2b07c MG |
709 | void __init efi_set_executable(efi_memory_desc_t *md, bool executable) |
710 | { | |
711 | u64 addr, npages; | |
712 | ||
713 | addr = md->virt_addr; | |
714 | npages = md->num_pages; | |
715 | ||
716 | memrange_efi_to_native(&addr, &npages); | |
717 | ||
718 | if (executable) | |
719 | set_memory_x(addr, npages); | |
720 | else | |
721 | set_memory_nx(addr, npages); | |
722 | } | |
723 | ||
a2172e25 HY |
724 | static void __init runtime_code_page_mkexec(void) |
725 | { | |
726 | efi_memory_desc_t *md; | |
a2172e25 HY |
727 | void *p; |
728 | ||
a2172e25 HY |
729 | /* Make EFI runtime service code area executable */ |
730 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | |
731 | md = p; | |
1c083eb2 HY |
732 | |
733 | if (md->type != EFI_RUNTIME_SERVICES_CODE) | |
734 | continue; | |
735 | ||
9cd2b07c | 736 | efi_set_executable(md, true); |
a2172e25 | 737 | } |
a2172e25 | 738 | } |
a2172e25 | 739 | |
3e8fa263 MF |
740 | void efi_memory_uc(u64 addr, unsigned long size) |
741 | { | |
742 | unsigned long page_shift = 1UL << EFI_PAGE_SHIFT; | |
743 | u64 npages; | |
744 | ||
745 | npages = round_up(size, page_shift) / page_shift; | |
746 | memrange_efi_to_native(&addr, &npages); | |
747 | set_memory_uc(addr, npages); | |
748 | } | |
749 | ||
d2f7cbe7 BP |
750 | void __init old_map_region(efi_memory_desc_t *md) |
751 | { | |
752 | u64 start_pfn, end_pfn, end; | |
753 | unsigned long size; | |
754 | void *va; | |
755 | ||
756 | start_pfn = PFN_DOWN(md->phys_addr); | |
757 | size = md->num_pages << PAGE_SHIFT; | |
758 | end = md->phys_addr + size; | |
759 | end_pfn = PFN_UP(end); | |
760 | ||
761 | if (pfn_range_is_mapped(start_pfn, end_pfn)) { | |
762 | va = __va(md->phys_addr); | |
763 | ||
764 | if (!(md->attribute & EFI_MEMORY_WB)) | |
765 | efi_memory_uc((u64)(unsigned long)va, size); | |
766 | } else | |
767 | va = efi_ioremap(md->phys_addr, size, | |
768 | md->type, md->attribute); | |
769 | ||
770 | md->virt_addr = (u64) (unsigned long) va; | |
771 | if (!va) | |
772 | pr_err("ioremap of 0x%llX failed!\n", | |
773 | (unsigned long long)md->phys_addr); | |
774 | } | |
775 | ||
481f75c0 DY |
776 | /* Merge contiguous regions of the same type and attribute */ |
777 | static void __init efi_merge_regions(void) | |
5b83683f | 778 | { |
481f75c0 | 779 | void *p; |
202f9d0a | 780 | efi_memory_desc_t *md, *prev_md = NULL; |
202f9d0a | 781 | |
202f9d0a MG |
782 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
783 | u64 prev_size; | |
784 | md = p; | |
785 | ||
786 | if (!prev_md) { | |
787 | prev_md = md; | |
788 | continue; | |
789 | } | |
790 | ||
791 | if (prev_md->type != md->type || | |
792 | prev_md->attribute != md->attribute) { | |
793 | prev_md = md; | |
794 | continue; | |
795 | } | |
796 | ||
797 | prev_size = prev_md->num_pages << EFI_PAGE_SHIFT; | |
798 | ||
799 | if (md->phys_addr == (prev_md->phys_addr + prev_size)) { | |
800 | prev_md->num_pages += md->num_pages; | |
801 | md->type = EFI_RESERVED_TYPE; | |
802 | md->attribute = 0; | |
803 | continue; | |
804 | } | |
805 | prev_md = md; | |
481f75c0 DY |
806 | } |
807 | } | |
808 | ||
809 | static void __init get_systab_virt_addr(efi_memory_desc_t *md) | |
810 | { | |
811 | unsigned long size; | |
812 | u64 end, systab; | |
d2f7cbe7 | 813 | |
481f75c0 DY |
814 | size = md->num_pages << EFI_PAGE_SHIFT; |
815 | end = md->phys_addr + size; | |
816 | systab = (u64)(unsigned long)efi_phys.systab; | |
817 | if (md->phys_addr <= systab && systab < end) { | |
818 | systab += md->virt_addr - md->phys_addr; | |
819 | efi.systab = (efi_system_table_t *)(unsigned long)systab; | |
202f9d0a | 820 | } |
481f75c0 DY |
821 | } |
822 | ||
823 | /* | |
824 | * Map efi memory ranges for runtime serivce and update new_memmap with virtual | |
825 | * addresses. | |
826 | */ | |
827 | static void * __init efi_map_regions(int *count) | |
828 | { | |
829 | efi_memory_desc_t *md; | |
830 | void *p, *tmp, *new_memmap = NULL; | |
202f9d0a | 831 | |
5b83683f HY |
832 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
833 | md = p; | |
70087011 JB |
834 | if (!(md->attribute & EFI_MEMORY_RUNTIME)) { |
835 | #ifdef CONFIG_X86_64 | |
836 | if (md->type != EFI_BOOT_SERVICES_CODE && | |
837 | md->type != EFI_BOOT_SERVICES_DATA) | |
838 | #endif | |
839 | continue; | |
840 | } | |
1c083eb2 | 841 | |
d2f7cbe7 | 842 | efi_map_region(md); |
481f75c0 DY |
843 | get_systab_virt_addr(md); |
844 | ||
845 | tmp = krealloc(new_memmap, (*count + 1) * memmap.desc_size, | |
846 | GFP_KERNEL); | |
847 | if (!tmp) | |
848 | goto out_krealloc; | |
849 | new_memmap = tmp; | |
850 | memcpy(new_memmap + (*count * memmap.desc_size), md, | |
851 | memmap.desc_size); | |
852 | (*count)++; | |
853 | } | |
d2f7cbe7 | 854 | |
481f75c0 DY |
855 | return new_memmap; |
856 | out_krealloc: | |
857 | kfree(new_memmap); | |
858 | return NULL; | |
859 | } | |
860 | ||
861 | /* | |
862 | * This function will switch the EFI runtime services to virtual mode. | |
863 | * Essentially, we look through the EFI memmap and map every region that | |
864 | * has the runtime attribute bit set in its memory descriptor into the | |
865 | * ->trampoline_pgd page table using a top-down VA allocation scheme. | |
866 | * | |
867 | * The old method which used to update that memory descriptor with the | |
868 | * virtual address obtained from ioremap() is still supported when the | |
869 | * kernel is booted with efi=old_map on its command line. Same old | |
870 | * method enabled the runtime services to be called without having to | |
871 | * thunk back into physical mode for every invocation. | |
872 | * | |
873 | * The new method does a pagetable switch in a preemption-safe manner | |
874 | * so that we're in a different address space when calling a runtime | |
875 | * function. For function arguments passing we do copy the PGDs of the | |
876 | * kernel page table into ->trampoline_pgd prior to each call. | |
877 | */ | |
878 | void __init efi_enter_virtual_mode(void) | |
879 | { | |
880 | efi_status_t status; | |
881 | void *new_memmap = NULL; | |
882 | int count = 0; | |
1c083eb2 | 883 | |
481f75c0 | 884 | efi.systab = NULL; |
d2f7cbe7 | 885 | |
481f75c0 DY |
886 | /* |
887 | * We don't do virtual mode, since we don't do runtime services, on | |
888 | * non-native EFI | |
889 | */ | |
890 | if (!efi_is_native()) { | |
891 | efi_unmap_memmap(); | |
892 | return; | |
893 | } | |
d2f7cbe7 | 894 | |
481f75c0 | 895 | efi_merge_regions(); |
ee411430 | 896 | |
481f75c0 DY |
897 | new_memmap = efi_map_regions(&count); |
898 | if (!new_memmap) { | |
899 | pr_err("Error reallocating memory, EFI runtime non-functional!\n"); | |
900 | return; | |
5b83683f HY |
901 | } |
902 | ||
903 | BUG_ON(!efi.systab); | |
904 | ||
d2f7cbe7 BP |
905 | efi_setup_page_tables(); |
906 | efi_sync_low_kernel_mappings(); | |
907 | ||
5b83683f | 908 | status = phys_efi_set_virtual_address_map( |
7cb00b72 | 909 | memmap.desc_size * count, |
5b83683f HY |
910 | memmap.desc_size, |
911 | memmap.desc_version, | |
7cb00b72 | 912 | (efi_memory_desc_t *)__pa(new_memmap)); |
5b83683f HY |
913 | |
914 | if (status != EFI_SUCCESS) { | |
e3cb3f5a OJ |
915 | pr_alert("Unable to switch EFI into virtual mode " |
916 | "(status=%lx)!\n", status); | |
5b83683f HY |
917 | panic("EFI call to SetVirtualAddressMap() failed!"); |
918 | } | |
919 | ||
920 | /* | |
921 | * Now that EFI is in virtual mode, update the function | |
922 | * pointers in the runtime service table to the new virtual addresses. | |
923 | * | |
924 | * Call EFI services through wrapper functions. | |
925 | */ | |
712ba9e9 | 926 | efi.runtime_version = efi_systab.hdr.revision; |
5b83683f HY |
927 | efi.get_time = virt_efi_get_time; |
928 | efi.set_time = virt_efi_set_time; | |
929 | efi.get_wakeup_time = virt_efi_get_wakeup_time; | |
930 | efi.set_wakeup_time = virt_efi_set_wakeup_time; | |
931 | efi.get_variable = virt_efi_get_variable; | |
932 | efi.get_next_variable = virt_efi_get_next_variable; | |
933 | efi.set_variable = virt_efi_set_variable; | |
934 | efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; | |
935 | efi.reset_system = virt_efi_reset_system; | |
2b5e8ef3 | 936 | efi.set_virtual_address_map = NULL; |
3b370237 MG |
937 | efi.query_variable_info = virt_efi_query_variable_info; |
938 | efi.update_capsule = virt_efi_update_capsule; | |
939 | efi.query_capsule_caps = virt_efi_query_capsule_caps; | |
d2f7cbe7 BP |
940 | |
941 | if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) | |
4de0d4a6 | 942 | runtime_code_page_mkexec(); |
1adbfa35 | 943 | |
7cb00b72 | 944 | kfree(new_memmap); |
f8b84043 MG |
945 | |
946 | /* clean DUMMY object */ | |
947 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | |
948 | EFI_VARIABLE_NON_VOLATILE | | |
949 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | |
950 | EFI_VARIABLE_RUNTIME_ACCESS, | |
951 | 0, NULL); | |
ee411430 BP |
952 | |
953 | return; | |
5b83683f HY |
954 | } |
955 | ||
956 | /* | |
957 | * Convenience functions to obtain memory types and attributes | |
958 | */ | |
959 | u32 efi_mem_type(unsigned long phys_addr) | |
960 | { | |
961 | efi_memory_desc_t *md; | |
962 | void *p; | |
963 | ||
83e68189 MF |
964 | if (!efi_enabled(EFI_MEMMAP)) |
965 | return 0; | |
966 | ||
5b83683f HY |
967 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
968 | md = p; | |
969 | if ((md->phys_addr <= phys_addr) && | |
970 | (phys_addr < (md->phys_addr + | |
971 | (md->num_pages << EFI_PAGE_SHIFT)))) | |
972 | return md->type; | |
973 | } | |
974 | return 0; | |
975 | } | |
976 | ||
977 | u64 efi_mem_attributes(unsigned long phys_addr) | |
978 | { | |
979 | efi_memory_desc_t *md; | |
980 | void *p; | |
981 | ||
982 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | |
983 | md = p; | |
984 | if ((md->phys_addr <= phys_addr) && | |
985 | (phys_addr < (md->phys_addr + | |
986 | (md->num_pages << EFI_PAGE_SHIFT)))) | |
987 | return md->attribute; | |
988 | } | |
989 | return 0; | |
990 | } | |
a6e4d5a0 MF |
991 | |
992 | /* | |
993 | * Some firmware has serious problems when using more than 50% of the EFI | |
994 | * variable store, i.e. it triggers bugs that can brick machines. Ensure that | |
995 | * we never use more than this safe limit. | |
996 | * | |
997 | * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable | |
998 | * store. | |
999 | */ | |
1000 | efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) | |
1001 | { | |
1002 | efi_status_t status; | |
1003 | u64 storage_size, remaining_size, max_size; | |
1004 | ||
f8b84043 MG |
1005 | if (!(attributes & EFI_VARIABLE_NON_VOLATILE)) |
1006 | return 0; | |
1007 | ||
a6e4d5a0 MF |
1008 | status = efi.query_variable_info(attributes, &storage_size, |
1009 | &remaining_size, &max_size); | |
1010 | if (status != EFI_SUCCESS) | |
1011 | return status; | |
1012 | ||
31ff2f20 MG |
1013 | /* |
1014 | * Some firmware implementations refuse to boot if there's insufficient | |
1015 | * space in the variable store. We account for that by refusing the | |
1016 | * write if permitting it would reduce the available space to under | |
f8b84043 | 1017 | * 5KB. This figure was provided by Samsung, so should be safe. |
31ff2f20 | 1018 | */ |
f8b84043 MG |
1019 | if ((remaining_size - size < EFI_MIN_RESERVE) && |
1020 | !efi_no_storage_paranoia) { | |
1021 | ||
1022 | /* | |
1023 | * Triggering garbage collection may require that the firmware | |
1024 | * generate a real EFI_OUT_OF_RESOURCES error. We can force | |
1025 | * that by attempting to use more space than is available. | |
1026 | */ | |
1027 | unsigned long dummy_size = remaining_size + 1024; | |
b8cb62f8 BH |
1028 | void *dummy = kzalloc(dummy_size, GFP_ATOMIC); |
1029 | ||
1030 | if (!dummy) | |
1031 | return EFI_OUT_OF_RESOURCES; | |
f8b84043 MG |
1032 | |
1033 | status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | |
1034 | EFI_VARIABLE_NON_VOLATILE | | |
1035 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | |
1036 | EFI_VARIABLE_RUNTIME_ACCESS, | |
1037 | dummy_size, dummy); | |
1038 | ||
1039 | if (status == EFI_SUCCESS) { | |
1040 | /* | |
1041 | * This should have failed, so if it didn't make sure | |
1042 | * that we delete it... | |
1043 | */ | |
1044 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | |
1045 | EFI_VARIABLE_NON_VOLATILE | | |
1046 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | |
1047 | EFI_VARIABLE_RUNTIME_ACCESS, | |
1048 | 0, dummy); | |
1049 | } | |
7791c842 | 1050 | |
b8cb62f8 BH |
1051 | kfree(dummy); |
1052 | ||
f8b84043 MG |
1053 | /* |
1054 | * The runtime code may now have triggered a garbage collection | |
1055 | * run, so check the variable info again | |
1056 | */ | |
1057 | status = efi.query_variable_info(attributes, &storage_size, | |
1058 | &remaining_size, &max_size); | |
8c58bf3e | 1059 | |
f8b84043 MG |
1060 | if (status != EFI_SUCCESS) |
1061 | return status; | |
1062 | ||
1063 | /* | |
1064 | * There still isn't enough room, so return an error | |
1065 | */ | |
1066 | if (remaining_size - size < EFI_MIN_RESERVE) | |
1067 | return EFI_OUT_OF_RESOURCES; | |
1068 | } | |
a6e4d5a0 MF |
1069 | |
1070 | return EFI_SUCCESS; | |
1071 | } | |
3668011d | 1072 | EXPORT_SYMBOL_GPL(efi_query_variable_store); |
d2f7cbe7 BP |
1073 | |
1074 | static int __init parse_efi_cmdline(char *str) | |
1075 | { | |
1076 | if (*str == '=') | |
1077 | str++; | |
1078 | ||
1079 | if (!strncmp(str, "old_map", 7)) | |
1080 | set_bit(EFI_OLD_MEMMAP, &x86_efi_facility); | |
1081 | ||
1082 | return 0; | |
1083 | } | |
1084 | early_param("efi", parse_efi_cmdline); |