2 * Common EFI (Extensible Firmware Interface) support functions
3 * Based on Extensible Firmware Interface Specification version 1.0
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>
16 * Copied from efi_32.c to eliminate the duplicated code between EFI
17 * 32/64 support code. --ying 2007-10-26
19 * All EFI Runtime Services are not implemented yet as EFI only
20 * supports physical mode addressing on SoftSDV. This is to be fixed
21 * in a future version. --drummond 1999-07-20
23 * Implemented EFI runtime services and virtual mode calls. --davidm
25 * Goutham Rao: <goutham.rao@intel.com>
26 * Skip non-WB memory and ignore empty memory ranges.
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/efi.h>
32 #include <linux/export.h>
33 #include <linux/bootmem.h>
34 #include <linux/memblock.h>
35 #include <linux/spinlock.h>
36 #include <linux/uaccess.h>
37 #include <linux/time.h>
39 #include <linux/reboot.h>
40 #include <linux/bcd.h>
42 #include <asm/setup.h>
45 #include <asm/cacheflush.h>
46 #include <asm/tlbflush.h>
47 #include <asm/x86_init.h>
52 struct efi __read_mostly efi = {
53 .mps = EFI_INVALID_TABLE_ADDR,
54 .acpi = EFI_INVALID_TABLE_ADDR,
55 .acpi20 = EFI_INVALID_TABLE_ADDR,
56 .smbios = EFI_INVALID_TABLE_ADDR,
57 .sal_systab = EFI_INVALID_TABLE_ADDR,
58 .boot_info = EFI_INVALID_TABLE_ADDR,
59 .hcdp = EFI_INVALID_TABLE_ADDR,
60 .uga = EFI_INVALID_TABLE_ADDR,
61 .uv_systab = EFI_INVALID_TABLE_ADDR,
65 struct efi_memory_map memmap;
67 static struct efi efi_phys __initdata;
68 static efi_system_table_t efi_systab __initdata;
70 static inline bool efi_is_native(void)
72 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
75 unsigned long x86_efi_facility;
78 * Returns 1 if 'facility' is enabled, 0 otherwise.
80 int efi_enabled(int facility)
82 return test_bit(facility, &x86_efi_facility) != 0;
84 EXPORT_SYMBOL(efi_enabled);
86 static bool disable_runtime = false;
87 static int __init setup_noefi(char *arg)
89 disable_runtime = true;
92 early_param("noefi", setup_noefi);
95 EXPORT_SYMBOL(add_efi_memmap);
97 static int __init setup_add_efi_memmap(char *arg)
102 early_param("add_efi_memmap", setup_add_efi_memmap);
104 static bool efi_no_storage_paranoia;
106 static int __init setup_storage_paranoia(char *arg)
108 efi_no_storage_paranoia = true;
111 early_param("efi_no_storage_paranoia", setup_storage_paranoia);
114 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
119 spin_lock_irqsave(&rtc_lock, flags);
120 status = efi_call_virt2(get_time, tm, tc);
121 spin_unlock_irqrestore(&rtc_lock, flags);
125 static efi_status_t virt_efi_set_time(efi_time_t *tm)
130 spin_lock_irqsave(&rtc_lock, flags);
131 status = efi_call_virt1(set_time, tm);
132 spin_unlock_irqrestore(&rtc_lock, flags);
136 static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
143 spin_lock_irqsave(&rtc_lock, flags);
144 status = efi_call_virt3(get_wakeup_time,
145 enabled, pending, tm);
146 spin_unlock_irqrestore(&rtc_lock, flags);
150 static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
155 spin_lock_irqsave(&rtc_lock, flags);
156 status = efi_call_virt2(set_wakeup_time,
158 spin_unlock_irqrestore(&rtc_lock, flags);
162 static efi_status_t virt_efi_get_variable(efi_char16_t *name,
165 unsigned long *data_size,
168 return efi_call_virt5(get_variable,
173 static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
177 return efi_call_virt3(get_next_variable,
178 name_size, name, vendor);
181 static efi_status_t virt_efi_set_variable(efi_char16_t *name,
184 unsigned long data_size,
187 return efi_call_virt5(set_variable,
192 static efi_status_t virt_efi_query_variable_info(u32 attr,
194 u64 *remaining_space,
195 u64 *max_variable_size)
197 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
198 return EFI_UNSUPPORTED;
200 return efi_call_virt4(query_variable_info, attr, storage_space,
201 remaining_space, max_variable_size);
204 static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
206 return efi_call_virt1(get_next_high_mono_count, count);
209 static void virt_efi_reset_system(int reset_type,
211 unsigned long data_size,
214 efi_call_virt4(reset_system, reset_type, status,
218 static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
220 unsigned long sg_list)
222 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
223 return EFI_UNSUPPORTED;
225 return efi_call_virt3(update_capsule, capsules, count, sg_list);
228 static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
233 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
234 return EFI_UNSUPPORTED;
236 return efi_call_virt4(query_capsule_caps, capsules, count, max_size,
240 static efi_status_t __init phys_efi_set_virtual_address_map(
241 unsigned long memory_map_size,
242 unsigned long descriptor_size,
243 u32 descriptor_version,
244 efi_memory_desc_t *virtual_map)
248 efi_call_phys_prelog();
249 status = efi_call_phys4(efi_phys.set_virtual_address_map,
250 memory_map_size, descriptor_size,
251 descriptor_version, virtual_map);
252 efi_call_phys_epilog();
256 static efi_status_t __init phys_efi_get_time(efi_time_t *tm,
262 spin_lock_irqsave(&rtc_lock, flags);
263 efi_call_phys_prelog();
264 status = efi_call_phys2(efi_phys.get_time, tm, tc);
265 efi_call_phys_epilog();
266 spin_unlock_irqrestore(&rtc_lock, flags);
270 int efi_set_rtc_mmss(unsigned long nowtime)
272 int real_seconds, real_minutes;
277 status = efi.get_time(&eft, &cap);
278 if (status != EFI_SUCCESS) {
279 printk(KERN_ERR "Oops: efitime: can't read time!\n");
283 real_seconds = nowtime % 60;
284 real_minutes = nowtime / 60;
285 if (((abs(real_minutes - eft.minute) + 15)/30) & 1)
288 eft.minute = real_minutes;
289 eft.second = real_seconds;
291 status = efi.set_time(&eft);
292 if (status != EFI_SUCCESS) {
293 printk(KERN_ERR "Oops: efitime: can't write time!\n");
299 unsigned long efi_get_time(void)
305 status = efi.get_time(&eft, &cap);
306 if (status != EFI_SUCCESS)
307 printk(KERN_ERR "Oops: efitime: can't read time!\n");
309 return mktime(eft.year, eft.month, eft.day, eft.hour,
310 eft.minute, eft.second);
314 * Tell the kernel about the EFI memory map. This might include
315 * more than the max 128 entries that can fit in the e820 legacy
316 * (zeropage) memory map.
319 static void __init do_add_efi_memmap(void)
323 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
324 efi_memory_desc_t *md = p;
325 unsigned long long start = md->phys_addr;
326 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
330 case EFI_LOADER_CODE:
331 case EFI_LOADER_DATA:
332 case EFI_BOOT_SERVICES_CODE:
333 case EFI_BOOT_SERVICES_DATA:
334 case EFI_CONVENTIONAL_MEMORY:
335 if (md->attribute & EFI_MEMORY_WB)
336 e820_type = E820_RAM;
338 e820_type = E820_RESERVED;
340 case EFI_ACPI_RECLAIM_MEMORY:
341 e820_type = E820_ACPI;
343 case EFI_ACPI_MEMORY_NVS:
344 e820_type = E820_NVS;
346 case EFI_UNUSABLE_MEMORY:
347 e820_type = E820_UNUSABLE;
351 * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE
352 * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO
353 * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE
355 e820_type = E820_RESERVED;
358 e820_add_region(start, size, e820_type);
360 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
363 void __init efi_memblock_x86_reserve_range(void)
368 pmap = boot_params.efi_info.efi_memmap;
370 pmap = (boot_params.efi_info.efi_memmap |
371 ((__u64)boot_params.efi_info.efi_memmap_hi<<32));
373 memmap.phys_map = (void *)pmap;
374 memmap.nr_map = boot_params.efi_info.efi_memmap_size /
375 boot_params.efi_info.efi_memdesc_size;
376 memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
377 memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
378 memblock_x86_reserve_range(pmap, pmap + memmap.nr_map * memmap.desc_size,
383 static void __init print_efi_memmap(void)
385 efi_memory_desc_t *md;
389 for (p = memmap.map, i = 0;
391 p += memmap.desc_size, i++) {
393 printk(KERN_INFO PFX "mem%02u: type=%u, attr=0x%llx, "
394 "range=[0x%016llx-0x%016llx) (%lluMB)\n",
395 i, md->type, md->attribute, md->phys_addr,
396 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
397 (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
400 #endif /* EFI_DEBUG */
402 void __init efi_reserve_boot_services(void)
406 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
407 efi_memory_desc_t *md = p;
408 u64 start = md->phys_addr;
409 u64 size = md->num_pages << EFI_PAGE_SHIFT;
411 if (md->type != EFI_BOOT_SERVICES_CODE &&
412 md->type != EFI_BOOT_SERVICES_DATA)
414 /* Only reserve where possible:
415 * - Not within any already allocated areas
416 * - Not over any memory area (really needed, if above?)
417 * - Not within any part of the kernel
418 * - Not the bios reserved area
420 if ((start+size >= virt_to_phys(_text)
421 && start <= virt_to_phys(_end)) ||
422 !e820_all_mapped(start, start+size, E820_RAM) ||
423 memblock_x86_check_reserved_size(&start, &size,
424 1<<EFI_PAGE_SHIFT)) {
425 /* Could not reserve, skip it */
427 memblock_dbg(PFX "Could not reserve boot range "
428 "[0x%010llx-0x%010llx]\n",
429 start, start+size-1);
431 memblock_x86_reserve_range(start, start+size,
436 static void __init efi_free_boot_services(void)
440 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
441 efi_memory_desc_t *md = p;
442 unsigned long long start = md->phys_addr;
443 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
445 if (md->type != EFI_BOOT_SERVICES_CODE &&
446 md->type != EFI_BOOT_SERVICES_DATA)
449 /* Could not reserve boot area */
453 free_bootmem_late(start, size);
457 void __init efi_init(void)
459 efi_config_table_t *config_tables;
460 efi_runtime_services_t *runtime;
462 char vendor[100] = "unknown";
466 if (!efi_is_native())
470 efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab;
472 efi_phys.systab = (efi_system_table_t *)
473 (boot_params.efi_info.efi_systab |
474 ((__u64)boot_params.efi_info.efi_systab_hi<<32));
477 efi.systab = early_ioremap((unsigned long)efi_phys.systab,
478 sizeof(efi_system_table_t));
479 if (efi.systab == NULL)
480 printk(KERN_ERR "Couldn't map the EFI system table!\n");
481 memcpy(&efi_systab, efi.systab, sizeof(efi_system_table_t));
482 early_iounmap(efi.systab, sizeof(efi_system_table_t));
483 efi.systab = &efi_systab;
486 * Verify the EFI Table
488 if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
489 printk(KERN_ERR "EFI system table signature incorrect!\n");
490 if ((efi.systab->hdr.revision >> 16) == 0)
491 printk(KERN_ERR "Warning: EFI system table version "
492 "%d.%02d, expected 1.00 or greater!\n",
493 efi.systab->hdr.revision >> 16,
494 efi.systab->hdr.revision & 0xffff);
496 set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility);
499 * Show what we know for posterity
501 c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2);
503 for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i)
507 printk(KERN_ERR PFX "Could not map the firmware vendor!\n");
508 early_iounmap(tmp, 2);
510 printk(KERN_INFO "EFI v%u.%.02u by %s\n",
511 efi.systab->hdr.revision >> 16,
512 efi.systab->hdr.revision & 0xffff, vendor);
515 * Let's see what config tables the firmware passed to us.
517 config_tables = early_ioremap(
519 efi.systab->nr_tables * sizeof(efi_config_table_t));
520 if (config_tables == NULL)
521 printk(KERN_ERR "Could not map EFI Configuration Table!\n");
524 for (i = 0; i < efi.systab->nr_tables; i++) {
525 if (!efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID)) {
526 efi.mps = config_tables[i].table;
527 printk(" MPS=0x%lx ", config_tables[i].table);
528 } else if (!efi_guidcmp(config_tables[i].guid,
529 ACPI_20_TABLE_GUID)) {
530 efi.acpi20 = config_tables[i].table;
531 printk(" ACPI 2.0=0x%lx ", config_tables[i].table);
532 } else if (!efi_guidcmp(config_tables[i].guid,
534 efi.acpi = config_tables[i].table;
535 printk(" ACPI=0x%lx ", config_tables[i].table);
536 } else if (!efi_guidcmp(config_tables[i].guid,
537 SMBIOS_TABLE_GUID)) {
538 efi.smbios = config_tables[i].table;
539 printk(" SMBIOS=0x%lx ", config_tables[i].table);
541 } else if (!efi_guidcmp(config_tables[i].guid,
542 UV_SYSTEM_TABLE_GUID)) {
543 efi.uv_systab = config_tables[i].table;
544 printk(" UVsystab=0x%lx ", config_tables[i].table);
546 } else if (!efi_guidcmp(config_tables[i].guid,
548 efi.hcdp = config_tables[i].table;
549 printk(" HCDP=0x%lx ", config_tables[i].table);
550 } else if (!efi_guidcmp(config_tables[i].guid,
551 UGA_IO_PROTOCOL_GUID)) {
552 efi.uga = config_tables[i].table;
553 printk(" UGA=0x%lx ", config_tables[i].table);
557 early_iounmap(config_tables,
558 efi.systab->nr_tables * sizeof(efi_config_table_t));
560 set_bit(EFI_CONFIG_TABLES, &x86_efi_facility);
562 if (!disable_runtime) {
564 * Check out the runtime services table. We need to map
565 * the runtime services table so that we can grab the physical
566 * address of several of the EFI runtime functions, needed to
567 * set the firmware into virtual mode.
569 runtime = early_ioremap((unsigned long)efi.systab->runtime,
570 sizeof(efi_runtime_services_t));
571 if (runtime != NULL) {
573 * We will only need *early* access to the following
574 * two EFI runtime services before set_virtual_address_map
577 efi_phys.get_time = (efi_get_time_t *)runtime->get_time;
578 efi_phys.set_virtual_address_map =
579 (efi_set_virtual_address_map_t *)
580 runtime->set_virtual_address_map;
582 * Make efi_get_time can be called before entering
585 efi.get_time = phys_efi_get_time;
587 set_bit(EFI_RUNTIME_SERVICES, &x86_efi_facility);
589 printk(KERN_ERR "Could not map the EFI runtime service "
591 early_iounmap(runtime, sizeof(efi_runtime_services_t));
594 /* Map the EFI memory map */
595 memmap.map = early_ioremap((unsigned long)memmap.phys_map,
596 memmap.nr_map * memmap.desc_size);
597 if (memmap.map == NULL)
598 printk(KERN_ERR "Could not map the EFI memory map!\n");
599 memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
601 if (memmap.desc_size != sizeof(efi_memory_desc_t))
603 "Kernel-defined memdesc doesn't match the one from EFI!\n");
608 set_bit(EFI_MEMMAP, &x86_efi_facility);
611 x86_platform.get_wallclock = efi_get_time;
612 x86_platform.set_wallclock = efi_set_rtc_mmss;
620 void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
624 addr = md->virt_addr;
625 npages = md->num_pages;
627 memrange_efi_to_native(&addr, &npages);
630 set_memory_x(addr, npages);
632 set_memory_nx(addr, npages);
635 static void __init runtime_code_page_mkexec(void)
637 efi_memory_desc_t *md;
640 /* Make EFI runtime service code area executable */
641 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
644 if (md->type != EFI_RUNTIME_SERVICES_CODE)
647 efi_set_executable(md, true);
652 * This function will switch the EFI runtime services to virtual mode.
653 * Essentially, look through the EFI memmap and map every region that
654 * has the runtime attribute bit set in its memory descriptor and update
655 * that memory descriptor with the virtual address obtained from ioremap().
656 * This enables the runtime services to be called without having to
657 * thunk back into physical mode for every invocation.
659 void __init efi_enter_virtual_mode(void)
661 efi_memory_desc_t *md, *prev_md = NULL;
664 u64 end, systab, addr, npages, end_pfn;
665 void *p, *va, *new_memmap = NULL;
670 /* Merge contiguous regions of the same type and attribute */
671 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
680 if (prev_md->type != md->type ||
681 prev_md->attribute != md->attribute) {
686 prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;
688 if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
689 prev_md->num_pages += md->num_pages;
690 md->type = EFI_RESERVED_TYPE;
697 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
699 if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
700 md->type != EFI_BOOT_SERVICES_CODE &&
701 md->type != EFI_BOOT_SERVICES_DATA)
704 size = md->num_pages << EFI_PAGE_SHIFT;
705 end = md->phys_addr + size;
707 end_pfn = PFN_UP(end);
708 if (end_pfn <= max_low_pfn_mapped
709 || (end_pfn > (1UL << (32 - PAGE_SHIFT))
710 && end_pfn <= max_pfn_mapped))
711 va = __va(md->phys_addr);
713 va = efi_ioremap(md->phys_addr, size, md->type);
715 md->virt_addr = (u64) (unsigned long) va;
718 printk(KERN_ERR PFX "ioremap of 0x%llX failed!\n",
719 (unsigned long long)md->phys_addr);
723 if (!(md->attribute & EFI_MEMORY_WB)) {
724 addr = md->virt_addr;
725 npages = md->num_pages;
726 memrange_efi_to_native(&addr, &npages);
727 set_memory_uc(addr, npages);
730 systab = (u64) (unsigned long) efi_phys.systab;
731 if (md->phys_addr <= systab && systab < end) {
732 systab += md->virt_addr - md->phys_addr;
733 efi.systab = (efi_system_table_t *) (unsigned long) systab;
735 new_memmap = krealloc(new_memmap,
736 (count + 1) * memmap.desc_size,
738 memcpy(new_memmap + (count * memmap.desc_size), md,
745 status = phys_efi_set_virtual_address_map(
746 memmap.desc_size * count,
749 (efi_memory_desc_t *)__pa(new_memmap));
751 if (status != EFI_SUCCESS) {
752 printk(KERN_ALERT "Unable to switch EFI into virtual mode "
753 "(status=%lx)!\n", status);
754 panic("EFI call to SetVirtualAddressMap() failed!");
758 * Thankfully, it does seem that no runtime services other than
759 * SetVirtualAddressMap() will touch boot services code, so we can
760 * get rid of it all at this point
762 efi_free_boot_services();
765 * Now that EFI is in virtual mode, update the function
766 * pointers in the runtime service table to the new virtual addresses.
768 * Call EFI services through wrapper functions.
770 efi.runtime_version = efi_systab.hdr.revision;
771 efi.get_time = virt_efi_get_time;
772 efi.set_time = virt_efi_set_time;
773 efi.get_wakeup_time = virt_efi_get_wakeup_time;
774 efi.set_wakeup_time = virt_efi_set_wakeup_time;
775 efi.get_variable = virt_efi_get_variable;
776 efi.get_next_variable = virt_efi_get_next_variable;
777 efi.set_variable = virt_efi_set_variable;
778 efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
779 efi.reset_system = virt_efi_reset_system;
780 efi.set_virtual_address_map = NULL;
781 efi.query_variable_info = virt_efi_query_variable_info;
782 efi.update_capsule = virt_efi_update_capsule;
783 efi.query_capsule_caps = virt_efi_query_capsule_caps;
784 if (__supported_pte_mask & _PAGE_NX)
785 runtime_code_page_mkexec();
786 clear_bit(EFI_MEMMAP, &x86_efi_facility);
787 early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
793 * Convenience functions to obtain memory types and attributes
795 u32 efi_mem_type(unsigned long phys_addr)
797 efi_memory_desc_t *md;
800 if (!efi_enabled(EFI_MEMMAP))
803 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
805 if ((md->phys_addr <= phys_addr) &&
806 (phys_addr < (md->phys_addr +
807 (md->num_pages << EFI_PAGE_SHIFT))))
813 u64 efi_mem_attributes(unsigned long phys_addr)
815 efi_memory_desc_t *md;
818 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
820 if ((md->phys_addr <= phys_addr) &&
821 (phys_addr < (md->phys_addr +
822 (md->num_pages << EFI_PAGE_SHIFT))))
823 return md->attribute;
829 * Some firmware has serious problems when using more than 50% of the EFI
830 * variable store, i.e. it triggers bugs that can brick machines. Ensure that
831 * we never use more than this safe limit.
833 * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable
836 efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
839 u64 storage_size, remaining_size, max_size;
841 status = efi.query_variable_info(attributes, &storage_size,
842 &remaining_size, &max_size);
843 if (status != EFI_SUCCESS)
846 if (!max_size && remaining_size > size)
847 printk_once(KERN_ERR FW_BUG "Broken EFI implementation"
848 " is returning MaxVariableSize=0\n");
850 if (!storage_size || size > remaining_size ||
851 (max_size && size > max_size))
852 return EFI_OUT_OF_RESOURCES;
854 if (!efi_no_storage_paranoia &&
855 (remaining_size - size) < (storage_size / 2))
856 return EFI_OUT_OF_RESOURCES;
860 EXPORT_SYMBOL_GPL(efi_query_variable_store);