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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/kernel.h>
32 #include <linux/init.h>
33 #include <linux/efi.h>
34 #include <linux/efi-bgrt.h>
35 #include <linux/export.h>
36 #include <linux/bootmem.h>
37 #include <linux/memblock.h>
38 #include <linux/spinlock.h>
39 #include <linux/uaccess.h>
40 #include <linux/time.h>
42 #include <linux/reboot.h>
43 #include <linux/bcd.h>
45 #include <asm/setup.h>
48 #include <asm/cacheflush.h>
49 #include <asm/tlbflush.h>
50 #include <asm/x86_init.h>
55 EXPORT_SYMBOL(efi_enabled);
57 struct efi __read_mostly efi = {
58 .mps = EFI_INVALID_TABLE_ADDR,
59 .acpi = EFI_INVALID_TABLE_ADDR,
60 .acpi20 = EFI_INVALID_TABLE_ADDR,
61 .smbios = EFI_INVALID_TABLE_ADDR,
62 .sal_systab = EFI_INVALID_TABLE_ADDR,
63 .boot_info = EFI_INVALID_TABLE_ADDR,
64 .hcdp = EFI_INVALID_TABLE_ADDR,
65 .uga = EFI_INVALID_TABLE_ADDR,
66 .uv_systab = EFI_INVALID_TABLE_ADDR,
70 struct efi_memory_map memmap;
73 static bool efi_native;
75 static struct efi efi_phys __initdata;
76 static efi_system_table_t efi_systab __initdata;
78 static int __init setup_noefi(char *arg)
83 early_param("noefi", setup_noefi);
86 EXPORT_SYMBOL(add_efi_memmap);
88 static int __init setup_add_efi_memmap(char *arg)
93 early_param("add_efi_memmap", setup_add_efi_memmap);
96 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
101 spin_lock_irqsave(&rtc_lock, flags);
102 status = efi_call_virt2(get_time, tm, tc);
103 spin_unlock_irqrestore(&rtc_lock, flags);
107 static efi_status_t virt_efi_set_time(efi_time_t *tm)
112 spin_lock_irqsave(&rtc_lock, flags);
113 status = efi_call_virt1(set_time, tm);
114 spin_unlock_irqrestore(&rtc_lock, flags);
118 static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
125 spin_lock_irqsave(&rtc_lock, flags);
126 status = efi_call_virt3(get_wakeup_time,
127 enabled, pending, tm);
128 spin_unlock_irqrestore(&rtc_lock, flags);
132 static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
137 spin_lock_irqsave(&rtc_lock, flags);
138 status = efi_call_virt2(set_wakeup_time,
140 spin_unlock_irqrestore(&rtc_lock, flags);
144 static efi_status_t virt_efi_get_variable(efi_char16_t *name,
147 unsigned long *data_size,
150 return efi_call_virt5(get_variable,
155 static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
159 return efi_call_virt3(get_next_variable,
160 name_size, name, vendor);
163 static efi_status_t virt_efi_set_variable(efi_char16_t *name,
166 unsigned long data_size,
169 return efi_call_virt5(set_variable,
174 static efi_status_t virt_efi_query_variable_info(u32 attr,
176 u64 *remaining_space,
177 u64 *max_variable_size)
179 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
180 return EFI_UNSUPPORTED;
182 return efi_call_virt4(query_variable_info, attr, storage_space,
183 remaining_space, max_variable_size);
186 static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
188 return efi_call_virt1(get_next_high_mono_count, count);
191 static void virt_efi_reset_system(int reset_type,
193 unsigned long data_size,
196 efi_call_virt4(reset_system, reset_type, status,
200 static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
202 unsigned long sg_list)
204 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
205 return EFI_UNSUPPORTED;
207 return efi_call_virt3(update_capsule, capsules, count, sg_list);
210 static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
215 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
216 return EFI_UNSUPPORTED;
218 return efi_call_virt4(query_capsule_caps, capsules, count, max_size,
222 static efi_status_t __init phys_efi_set_virtual_address_map(
223 unsigned long memory_map_size,
224 unsigned long descriptor_size,
225 u32 descriptor_version,
226 efi_memory_desc_t *virtual_map)
230 efi_call_phys_prelog();
231 status = efi_call_phys4(efi_phys.set_virtual_address_map,
232 memory_map_size, descriptor_size,
233 descriptor_version, virtual_map);
234 efi_call_phys_epilog();
238 static efi_status_t __init phys_efi_get_time(efi_time_t *tm,
244 spin_lock_irqsave(&rtc_lock, flags);
245 efi_call_phys_prelog();
246 status = efi_call_phys2(efi_phys.get_time, virt_to_phys(tm),
248 efi_call_phys_epilog();
249 spin_unlock_irqrestore(&rtc_lock, flags);
253 int efi_set_rtc_mmss(unsigned long nowtime)
255 int real_seconds, real_minutes;
260 status = efi.get_time(&eft, &cap);
261 if (status != EFI_SUCCESS) {
262 pr_err("Oops: efitime: can't read time!\n");
266 real_seconds = nowtime % 60;
267 real_minutes = nowtime / 60;
268 if (((abs(real_minutes - eft.minute) + 15)/30) & 1)
271 eft.minute = real_minutes;
272 eft.second = real_seconds;
274 status = efi.set_time(&eft);
275 if (status != EFI_SUCCESS) {
276 pr_err("Oops: efitime: can't write time!\n");
282 unsigned long efi_get_time(void)
288 status = efi.get_time(&eft, &cap);
289 if (status != EFI_SUCCESS)
290 pr_err("Oops: efitime: can't read time!\n");
292 return mktime(eft.year, eft.month, eft.day, eft.hour,
293 eft.minute, eft.second);
297 * Tell the kernel about the EFI memory map. This might include
298 * more than the max 128 entries that can fit in the e820 legacy
299 * (zeropage) memory map.
302 static void __init do_add_efi_memmap(void)
306 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
307 efi_memory_desc_t *md = p;
308 unsigned long long start = md->phys_addr;
309 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
313 case EFI_LOADER_CODE:
314 case EFI_LOADER_DATA:
315 case EFI_BOOT_SERVICES_CODE:
316 case EFI_BOOT_SERVICES_DATA:
317 case EFI_CONVENTIONAL_MEMORY:
318 if (md->attribute & EFI_MEMORY_WB)
319 e820_type = E820_RAM;
321 e820_type = E820_RESERVED;
323 case EFI_ACPI_RECLAIM_MEMORY:
324 e820_type = E820_ACPI;
326 case EFI_ACPI_MEMORY_NVS:
327 e820_type = E820_NVS;
329 case EFI_UNUSABLE_MEMORY:
330 e820_type = E820_UNUSABLE;
334 * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE
335 * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO
336 * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE
338 e820_type = E820_RESERVED;
341 e820_add_region(start, size, e820_type);
343 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
346 int __init efi_memblock_x86_reserve_range(void)
351 /* Can't handle data above 4GB at this time */
352 if (boot_params.efi_info.efi_memmap_hi) {
353 pr_err("Memory map is above 4GB, disabling EFI.\n");
356 pmap = boot_params.efi_info.efi_memmap;
358 pmap = (boot_params.efi_info.efi_memmap |
359 ((__u64)boot_params.efi_info.efi_memmap_hi<<32));
361 memmap.phys_map = (void *)pmap;
362 memmap.nr_map = boot_params.efi_info.efi_memmap_size /
363 boot_params.efi_info.efi_memdesc_size;
364 memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
365 memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
366 memblock_reserve(pmap, memmap.nr_map * memmap.desc_size);
372 static void __init print_efi_memmap(void)
374 efi_memory_desc_t *md;
378 for (p = memmap.map, i = 0;
380 p += memmap.desc_size, i++) {
382 pr_info("mem%02u: type=%u, attr=0x%llx, "
383 "range=[0x%016llx-0x%016llx) (%lluMB)\n",
384 i, md->type, md->attribute, md->phys_addr,
385 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
386 (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
389 #endif /* EFI_DEBUG */
391 void __init efi_reserve_boot_services(void)
395 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
396 efi_memory_desc_t *md = p;
397 u64 start = md->phys_addr;
398 u64 size = md->num_pages << EFI_PAGE_SHIFT;
400 if (md->type != EFI_BOOT_SERVICES_CODE &&
401 md->type != EFI_BOOT_SERVICES_DATA)
403 /* Only reserve where possible:
404 * - Not within any already allocated areas
405 * - Not over any memory area (really needed, if above?)
406 * - Not within any part of the kernel
407 * - Not the bios reserved area
409 if ((start+size >= virt_to_phys(_text)
410 && start <= virt_to_phys(_end)) ||
411 !e820_all_mapped(start, start+size, E820_RAM) ||
412 memblock_is_region_reserved(start, size)) {
413 /* Could not reserve, skip it */
415 memblock_dbg("Could not reserve boot range "
416 "[0x%010llx-0x%010llx]\n",
417 start, start+size-1);
419 memblock_reserve(start, size);
423 static void __init efi_unmap_memmap(void)
426 early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
431 void __init efi_free_boot_services(void)
438 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
439 efi_memory_desc_t *md = p;
440 unsigned long long start = md->phys_addr;
441 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
443 if (md->type != EFI_BOOT_SERVICES_CODE &&
444 md->type != EFI_BOOT_SERVICES_DATA)
447 /* Could not reserve boot area */
451 free_bootmem_late(start, size);
457 static int __init efi_systab_init(void *phys)
460 efi_system_table_64_t *systab64;
463 systab64 = early_ioremap((unsigned long)phys,
465 if (systab64 == NULL) {
466 pr_err("Couldn't map the system table!\n");
470 efi_systab.hdr = systab64->hdr;
471 efi_systab.fw_vendor = systab64->fw_vendor;
472 tmp |= systab64->fw_vendor;
473 efi_systab.fw_revision = systab64->fw_revision;
474 efi_systab.con_in_handle = systab64->con_in_handle;
475 tmp |= systab64->con_in_handle;
476 efi_systab.con_in = systab64->con_in;
477 tmp |= systab64->con_in;
478 efi_systab.con_out_handle = systab64->con_out_handle;
479 tmp |= systab64->con_out_handle;
480 efi_systab.con_out = systab64->con_out;
481 tmp |= systab64->con_out;
482 efi_systab.stderr_handle = systab64->stderr_handle;
483 tmp |= systab64->stderr_handle;
484 efi_systab.stderr = systab64->stderr;
485 tmp |= systab64->stderr;
486 efi_systab.runtime = (void *)(unsigned long)systab64->runtime;
487 tmp |= systab64->runtime;
488 efi_systab.boottime = (void *)(unsigned long)systab64->boottime;
489 tmp |= systab64->boottime;
490 efi_systab.nr_tables = systab64->nr_tables;
491 efi_systab.tables = systab64->tables;
492 tmp |= systab64->tables;
494 early_iounmap(systab64, sizeof(*systab64));
497 pr_err("EFI data located above 4GB, disabling EFI.\n");
502 efi_system_table_32_t *systab32;
504 systab32 = early_ioremap((unsigned long)phys,
506 if (systab32 == NULL) {
507 pr_err("Couldn't map the system table!\n");
511 efi_systab.hdr = systab32->hdr;
512 efi_systab.fw_vendor = systab32->fw_vendor;
513 efi_systab.fw_revision = systab32->fw_revision;
514 efi_systab.con_in_handle = systab32->con_in_handle;
515 efi_systab.con_in = systab32->con_in;
516 efi_systab.con_out_handle = systab32->con_out_handle;
517 efi_systab.con_out = systab32->con_out;
518 efi_systab.stderr_handle = systab32->stderr_handle;
519 efi_systab.stderr = systab32->stderr;
520 efi_systab.runtime = (void *)(unsigned long)systab32->runtime;
521 efi_systab.boottime = (void *)(unsigned long)systab32->boottime;
522 efi_systab.nr_tables = systab32->nr_tables;
523 efi_systab.tables = systab32->tables;
525 early_iounmap(systab32, sizeof(*systab32));
528 efi.systab = &efi_systab;
531 * Verify the EFI Table
533 if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
534 pr_err("System table signature incorrect!\n");
537 if ((efi.systab->hdr.revision >> 16) == 0)
538 pr_err("Warning: System table version "
539 "%d.%02d, expected 1.00 or greater!\n",
540 efi.systab->hdr.revision >> 16,
541 efi.systab->hdr.revision & 0xffff);
546 static int __init efi_config_init(u64 tables, int nr_tables)
548 void *config_tables, *tablep;
552 sz = sizeof(efi_config_table_64_t);
554 sz = sizeof(efi_config_table_32_t);
557 * Let's see what config tables the firmware passed to us.
559 config_tables = early_ioremap(tables, nr_tables * sz);
560 if (config_tables == NULL) {
561 pr_err("Could not map Configuration table!\n");
565 tablep = config_tables;
567 for (i = 0; i < efi.systab->nr_tables; i++) {
573 guid = ((efi_config_table_64_t *)tablep)->guid;
574 table64 = ((efi_config_table_64_t *)tablep)->table;
579 pr_err("Table located above 4GB, disabling EFI.\n");
580 early_iounmap(config_tables,
581 efi.systab->nr_tables * sz);
586 guid = ((efi_config_table_32_t *)tablep)->guid;
587 table = ((efi_config_table_32_t *)tablep)->table;
589 if (!efi_guidcmp(guid, MPS_TABLE_GUID)) {
591 pr_cont(" MPS=0x%lx ", table);
592 } else if (!efi_guidcmp(guid, ACPI_20_TABLE_GUID)) {
594 pr_cont(" ACPI 2.0=0x%lx ", table);
595 } else if (!efi_guidcmp(guid, ACPI_TABLE_GUID)) {
597 pr_cont(" ACPI=0x%lx ", table);
598 } else if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID)) {
600 pr_cont(" SMBIOS=0x%lx ", table);
602 } else if (!efi_guidcmp(guid, UV_SYSTEM_TABLE_GUID)) {
603 efi.uv_systab = table;
604 pr_cont(" UVsystab=0x%lx ", table);
606 } else if (!efi_guidcmp(guid, HCDP_TABLE_GUID)) {
608 pr_cont(" HCDP=0x%lx ", table);
609 } else if (!efi_guidcmp(guid, UGA_IO_PROTOCOL_GUID)) {
611 pr_cont(" UGA=0x%lx ", table);
616 early_iounmap(config_tables, efi.systab->nr_tables * sz);
620 static int __init efi_runtime_init(void)
622 efi_runtime_services_t *runtime;
625 * Check out the runtime services table. We need to map
626 * the runtime services table so that we can grab the physical
627 * address of several of the EFI runtime functions, needed to
628 * set the firmware into virtual mode.
630 runtime = early_ioremap((unsigned long)efi.systab->runtime,
631 sizeof(efi_runtime_services_t));
633 pr_err("Could not map the runtime service table!\n");
637 * We will only need *early* access to the following
638 * two EFI runtime services before set_virtual_address_map
641 efi_phys.get_time = (efi_get_time_t *)runtime->get_time;
642 efi_phys.set_virtual_address_map =
643 (efi_set_virtual_address_map_t *)
644 runtime->set_virtual_address_map;
646 * Make efi_get_time can be called before entering
649 efi.get_time = phys_efi_get_time;
650 early_iounmap(runtime, sizeof(efi_runtime_services_t));
655 static int __init efi_memmap_init(void)
657 /* Map the EFI memory map */
658 memmap.map = early_ioremap((unsigned long)memmap.phys_map,
659 memmap.nr_map * memmap.desc_size);
660 if (memmap.map == NULL) {
661 pr_err("Could not map the memory map!\n");
664 memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
672 void __init efi_init(void)
675 char vendor[100] = "unknown";
680 if (boot_params.efi_info.efi_systab_hi ||
681 boot_params.efi_info.efi_memmap_hi) {
682 pr_info("Table located above 4GB, disabling EFI.\n");
686 efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab;
687 efi_native = !efi_64bit;
689 efi_phys.systab = (efi_system_table_t *)
690 (boot_params.efi_info.efi_systab |
691 ((__u64)boot_params.efi_info.efi_systab_hi<<32));
692 efi_native = efi_64bit;
695 if (efi_systab_init(efi_phys.systab)) {
701 * Show what we know for posterity
703 c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2);
705 for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i)
709 pr_err("Could not map the firmware vendor!\n");
710 early_iounmap(tmp, 2);
712 pr_info("EFI v%u.%.02u by %s\n",
713 efi.systab->hdr.revision >> 16,
714 efi.systab->hdr.revision & 0xffff, vendor);
716 if (efi_config_init(efi.systab->tables, efi.systab->nr_tables)) {
722 * Note: We currently don't support runtime services on an EFI
723 * that doesn't match the kernel 32/64-bit mode.
727 pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n");
728 else if (efi_runtime_init()) {
733 if (efi_memmap_init()) {
739 x86_platform.get_wallclock = efi_get_time;
740 x86_platform.set_wallclock = efi_set_rtc_mmss;
749 void __init efi_late_init(void)
754 void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
758 addr = md->virt_addr;
759 npages = md->num_pages;
761 memrange_efi_to_native(&addr, &npages);
764 set_memory_x(addr, npages);
766 set_memory_nx(addr, npages);
769 static void __init runtime_code_page_mkexec(void)
771 efi_memory_desc_t *md;
774 /* Make EFI runtime service code area executable */
775 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
778 if (md->type != EFI_RUNTIME_SERVICES_CODE)
781 efi_set_executable(md, true);
786 * We can't ioremap data in EFI boot services RAM, because we've already mapped
787 * it as RAM. So, look it up in the existing EFI memory map instead. Only
788 * callable after efi_enter_virtual_mode and before efi_free_boot_services.
790 void __iomem *efi_lookup_mapped_addr(u64 phys_addr)
793 if (WARN_ON(!memmap.map))
795 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
796 efi_memory_desc_t *md = p;
797 u64 size = md->num_pages << EFI_PAGE_SHIFT;
798 u64 end = md->phys_addr + size;
799 if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
800 md->type != EFI_BOOT_SERVICES_CODE &&
801 md->type != EFI_BOOT_SERVICES_DATA)
805 if (phys_addr >= md->phys_addr && phys_addr < end) {
806 phys_addr += md->virt_addr - md->phys_addr;
807 return (__force void __iomem *)(unsigned long)phys_addr;
814 * This function will switch the EFI runtime services to virtual mode.
815 * Essentially, look through the EFI memmap and map every region that
816 * has the runtime attribute bit set in its memory descriptor and update
817 * that memory descriptor with the virtual address obtained from ioremap().
818 * This enables the runtime services to be called without having to
819 * thunk back into physical mode for every invocation.
821 void __init efi_enter_virtual_mode(void)
823 efi_memory_desc_t *md, *prev_md = NULL;
826 u64 end, systab, addr, npages, end_pfn;
827 void *p, *va, *new_memmap = NULL;
833 * We don't do virtual mode, since we don't do runtime services, on
842 /* Merge contiguous regions of the same type and attribute */
843 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
852 if (prev_md->type != md->type ||
853 prev_md->attribute != md->attribute) {
858 prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;
860 if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
861 prev_md->num_pages += md->num_pages;
862 md->type = EFI_RESERVED_TYPE;
869 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
871 if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
872 md->type != EFI_BOOT_SERVICES_CODE &&
873 md->type != EFI_BOOT_SERVICES_DATA)
876 size = md->num_pages << EFI_PAGE_SHIFT;
877 end = md->phys_addr + size;
879 end_pfn = PFN_UP(end);
880 if (end_pfn <= max_low_pfn_mapped
881 || (end_pfn > (1UL << (32 - PAGE_SHIFT))
882 && end_pfn <= max_pfn_mapped))
883 va = __va(md->phys_addr);
885 va = efi_ioremap(md->phys_addr, size, md->type);
887 md->virt_addr = (u64) (unsigned long) va;
890 pr_err("ioremap of 0x%llX failed!\n",
891 (unsigned long long)md->phys_addr);
895 if (!(md->attribute & EFI_MEMORY_WB)) {
896 addr = md->virt_addr;
897 npages = md->num_pages;
898 memrange_efi_to_native(&addr, &npages);
899 set_memory_uc(addr, npages);
902 systab = (u64) (unsigned long) efi_phys.systab;
903 if (md->phys_addr <= systab && systab < end) {
904 systab += md->virt_addr - md->phys_addr;
905 efi.systab = (efi_system_table_t *) (unsigned long) systab;
907 new_memmap = krealloc(new_memmap,
908 (count + 1) * memmap.desc_size,
910 memcpy(new_memmap + (count * memmap.desc_size), md,
917 status = phys_efi_set_virtual_address_map(
918 memmap.desc_size * count,
921 (efi_memory_desc_t *)__pa(new_memmap));
923 if (status != EFI_SUCCESS) {
924 pr_alert("Unable to switch EFI into virtual mode "
925 "(status=%lx)!\n", status);
926 panic("EFI call to SetVirtualAddressMap() failed!");
930 * Now that EFI is in virtual mode, update the function
931 * pointers in the runtime service table to the new virtual addresses.
933 * Call EFI services through wrapper functions.
935 efi.runtime_version = efi_systab.fw_revision;
936 efi.get_time = virt_efi_get_time;
937 efi.set_time = virt_efi_set_time;
938 efi.get_wakeup_time = virt_efi_get_wakeup_time;
939 efi.set_wakeup_time = virt_efi_set_wakeup_time;
940 efi.get_variable = virt_efi_get_variable;
941 efi.get_next_variable = virt_efi_get_next_variable;
942 efi.set_variable = virt_efi_set_variable;
943 efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
944 efi.reset_system = virt_efi_reset_system;
945 efi.set_virtual_address_map = NULL;
946 efi.query_variable_info = virt_efi_query_variable_info;
947 efi.update_capsule = virt_efi_update_capsule;
948 efi.query_capsule_caps = virt_efi_query_capsule_caps;
949 if (__supported_pte_mask & _PAGE_NX)
950 runtime_code_page_mkexec();
956 * Convenience functions to obtain memory types and attributes
958 u32 efi_mem_type(unsigned long phys_addr)
960 efi_memory_desc_t *md;
963 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
965 if ((md->phys_addr <= phys_addr) &&
966 (phys_addr < (md->phys_addr +
967 (md->num_pages << EFI_PAGE_SHIFT))))
973 u64 efi_mem_attributes(unsigned long phys_addr)
975 efi_memory_desc_t *md;
978 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
980 if ((md->phys_addr <= phys_addr) &&
981 (phys_addr < (md->phys_addr +
982 (md->num_pages << EFI_PAGE_SHIFT))))
983 return md->attribute;