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/export.h>
35 #include <linux/bootmem.h>
36 #include <linux/memblock.h>
37 #include <linux/spinlock.h>
38 #include <linux/uaccess.h>
39 #include <linux/time.h>
41 #include <linux/reboot.h>
42 #include <linux/bcd.h>
44 #include <asm/setup.h>
47 #include <asm/cacheflush.h>
48 #include <asm/tlbflush.h>
49 #include <asm/x86_init.h>
54 EXPORT_SYMBOL(efi_enabled
);
56 struct efi __read_mostly efi
= {
57 .mps
= EFI_INVALID_TABLE_ADDR
,
58 .acpi
= EFI_INVALID_TABLE_ADDR
,
59 .acpi20
= EFI_INVALID_TABLE_ADDR
,
60 .smbios
= EFI_INVALID_TABLE_ADDR
,
61 .sal_systab
= EFI_INVALID_TABLE_ADDR
,
62 .boot_info
= EFI_INVALID_TABLE_ADDR
,
63 .hcdp
= EFI_INVALID_TABLE_ADDR
,
64 .uga
= EFI_INVALID_TABLE_ADDR
,
65 .uv_systab
= EFI_INVALID_TABLE_ADDR
,
69 struct efi_memory_map memmap
;
72 static bool efi_native
;
74 static struct efi efi_phys __initdata
;
75 static efi_system_table_t efi_systab __initdata
;
77 static int __init
setup_noefi(char *arg
)
82 early_param("noefi", setup_noefi
);
85 EXPORT_SYMBOL(add_efi_memmap
);
87 static int __init
setup_add_efi_memmap(char *arg
)
92 early_param("add_efi_memmap", setup_add_efi_memmap
);
95 static efi_status_t
virt_efi_get_time(efi_time_t
*tm
, efi_time_cap_t
*tc
)
100 spin_lock_irqsave(&rtc_lock
, flags
);
101 status
= efi_call_virt2(get_time
, tm
, tc
);
102 spin_unlock_irqrestore(&rtc_lock
, flags
);
106 static efi_status_t
virt_efi_set_time(efi_time_t
*tm
)
111 spin_lock_irqsave(&rtc_lock
, flags
);
112 status
= efi_call_virt1(set_time
, tm
);
113 spin_unlock_irqrestore(&rtc_lock
, flags
);
117 static efi_status_t
virt_efi_get_wakeup_time(efi_bool_t
*enabled
,
124 spin_lock_irqsave(&rtc_lock
, flags
);
125 status
= efi_call_virt3(get_wakeup_time
,
126 enabled
, pending
, tm
);
127 spin_unlock_irqrestore(&rtc_lock
, flags
);
131 static efi_status_t
virt_efi_set_wakeup_time(efi_bool_t enabled
, efi_time_t
*tm
)
136 spin_lock_irqsave(&rtc_lock
, flags
);
137 status
= efi_call_virt2(set_wakeup_time
,
139 spin_unlock_irqrestore(&rtc_lock
, flags
);
143 static efi_status_t
virt_efi_get_variable(efi_char16_t
*name
,
146 unsigned long *data_size
,
149 return efi_call_virt5(get_variable
,
154 static efi_status_t
virt_efi_get_next_variable(unsigned long *name_size
,
158 return efi_call_virt3(get_next_variable
,
159 name_size
, name
, vendor
);
162 static efi_status_t
virt_efi_set_variable(efi_char16_t
*name
,
165 unsigned long data_size
,
168 return efi_call_virt5(set_variable
,
173 static efi_status_t
virt_efi_query_variable_info(u32 attr
,
175 u64
*remaining_space
,
176 u64
*max_variable_size
)
178 if (efi
.runtime_version
< EFI_2_00_SYSTEM_TABLE_REVISION
)
179 return EFI_UNSUPPORTED
;
181 return efi_call_virt4(query_variable_info
, attr
, storage_space
,
182 remaining_space
, max_variable_size
);
185 static efi_status_t
virt_efi_get_next_high_mono_count(u32
*count
)
187 return efi_call_virt1(get_next_high_mono_count
, count
);
190 static void virt_efi_reset_system(int reset_type
,
192 unsigned long data_size
,
195 efi_call_virt4(reset_system
, reset_type
, status
,
199 static efi_status_t
virt_efi_update_capsule(efi_capsule_header_t
**capsules
,
201 unsigned long sg_list
)
203 if (efi
.runtime_version
< EFI_2_00_SYSTEM_TABLE_REVISION
)
204 return EFI_UNSUPPORTED
;
206 return efi_call_virt3(update_capsule
, capsules
, count
, sg_list
);
209 static efi_status_t
virt_efi_query_capsule_caps(efi_capsule_header_t
**capsules
,
214 if (efi
.runtime_version
< EFI_2_00_SYSTEM_TABLE_REVISION
)
215 return EFI_UNSUPPORTED
;
217 return efi_call_virt4(query_capsule_caps
, capsules
, count
, max_size
,
221 static efi_status_t __init
phys_efi_set_virtual_address_map(
222 unsigned long memory_map_size
,
223 unsigned long descriptor_size
,
224 u32 descriptor_version
,
225 efi_memory_desc_t
*virtual_map
)
229 efi_call_phys_prelog();
230 status
= efi_call_phys4(efi_phys
.set_virtual_address_map
,
231 memory_map_size
, descriptor_size
,
232 descriptor_version
, virtual_map
);
233 efi_call_phys_epilog();
237 static int efi_set_rtc_mmss(unsigned long nowtime
)
239 int real_seconds
, real_minutes
;
244 status
= efi
.get_time(&eft
, &cap
);
245 if (status
!= EFI_SUCCESS
) {
246 pr_err("Oops: efitime: can't read time!\n");
250 real_seconds
= nowtime
% 60;
251 real_minutes
= nowtime
/ 60;
252 if (((abs(real_minutes
- eft
.minute
) + 15)/30) & 1)
255 eft
.minute
= real_minutes
;
256 eft
.second
= real_seconds
;
258 status
= efi
.set_time(&eft
);
259 if (status
!= EFI_SUCCESS
) {
260 pr_err("Oops: efitime: can't write time!\n");
266 static unsigned long efi_get_time(void)
272 status
= efi
.get_time(&eft
, &cap
);
273 if (status
!= EFI_SUCCESS
)
274 pr_err("Oops: efitime: can't read time!\n");
276 return mktime(eft
.year
, eft
.month
, eft
.day
, eft
.hour
,
277 eft
.minute
, eft
.second
);
281 * Tell the kernel about the EFI memory map. This might include
282 * more than the max 128 entries that can fit in the e820 legacy
283 * (zeropage) memory map.
286 static void __init
do_add_efi_memmap(void)
290 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
291 efi_memory_desc_t
*md
= p
;
292 unsigned long long start
= md
->phys_addr
;
293 unsigned long long size
= md
->num_pages
<< EFI_PAGE_SHIFT
;
297 case EFI_LOADER_CODE
:
298 case EFI_LOADER_DATA
:
299 case EFI_BOOT_SERVICES_CODE
:
300 case EFI_BOOT_SERVICES_DATA
:
301 case EFI_CONVENTIONAL_MEMORY
:
302 if (md
->attribute
& EFI_MEMORY_WB
)
303 e820_type
= E820_RAM
;
305 e820_type
= E820_RESERVED
;
307 case EFI_ACPI_RECLAIM_MEMORY
:
308 e820_type
= E820_ACPI
;
310 case EFI_ACPI_MEMORY_NVS
:
311 e820_type
= E820_NVS
;
313 case EFI_UNUSABLE_MEMORY
:
314 e820_type
= E820_UNUSABLE
;
318 * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE
319 * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO
320 * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE
322 e820_type
= E820_RESERVED
;
325 e820_add_region(start
, size
, e820_type
);
327 sanitize_e820_map(e820
.map
, ARRAY_SIZE(e820
.map
), &e820
.nr_map
);
330 int __init
efi_memblock_x86_reserve_range(void)
335 /* Can't handle data above 4GB at this time */
336 if (boot_params
.efi_info
.efi_memmap_hi
) {
337 pr_err("Memory map is above 4GB, disabling EFI.\n");
340 pmap
= boot_params
.efi_info
.efi_memmap
;
342 pmap
= (boot_params
.efi_info
.efi_memmap
|
343 ((__u64
)boot_params
.efi_info
.efi_memmap_hi
<<32));
345 memmap
.phys_map
= (void *)pmap
;
346 memmap
.nr_map
= boot_params
.efi_info
.efi_memmap_size
/
347 boot_params
.efi_info
.efi_memdesc_size
;
348 memmap
.desc_version
= boot_params
.efi_info
.efi_memdesc_version
;
349 memmap
.desc_size
= boot_params
.efi_info
.efi_memdesc_size
;
350 memblock_reserve(pmap
, memmap
.nr_map
* memmap
.desc_size
);
356 static void __init
print_efi_memmap(void)
358 efi_memory_desc_t
*md
;
362 for (p
= memmap
.map
, i
= 0;
364 p
+= memmap
.desc_size
, i
++) {
366 pr_info("mem%02u: type=%u, attr=0x%llx, "
367 "range=[0x%016llx-0x%016llx) (%lluMB)\n",
368 i
, md
->type
, md
->attribute
, md
->phys_addr
,
369 md
->phys_addr
+ (md
->num_pages
<< EFI_PAGE_SHIFT
),
370 (md
->num_pages
>> (20 - EFI_PAGE_SHIFT
)));
373 #endif /* EFI_DEBUG */
375 void __init
efi_reserve_boot_services(void)
379 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
380 efi_memory_desc_t
*md
= p
;
381 u64 start
= md
->phys_addr
;
382 u64 size
= md
->num_pages
<< EFI_PAGE_SHIFT
;
384 if (md
->type
!= EFI_BOOT_SERVICES_CODE
&&
385 md
->type
!= EFI_BOOT_SERVICES_DATA
)
387 /* Only reserve where possible:
388 * - Not within any already allocated areas
389 * - Not over any memory area (really needed, if above?)
390 * - Not within any part of the kernel
391 * - Not the bios reserved area
393 if ((start
+size
>= virt_to_phys(_text
)
394 && start
<= virt_to_phys(_end
)) ||
395 !e820_all_mapped(start
, start
+size
, E820_RAM
) ||
396 memblock_is_region_reserved(start
, size
)) {
397 /* Could not reserve, skip it */
399 memblock_dbg("Could not reserve boot range "
400 "[0x%010llx-0x%010llx]\n",
401 start
, start
+size
-1);
403 memblock_reserve(start
, size
);
407 static void __init
efi_free_boot_services(void)
411 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
412 efi_memory_desc_t
*md
= p
;
413 unsigned long long start
= md
->phys_addr
;
414 unsigned long long size
= md
->num_pages
<< EFI_PAGE_SHIFT
;
416 if (md
->type
!= EFI_BOOT_SERVICES_CODE
&&
417 md
->type
!= EFI_BOOT_SERVICES_DATA
)
420 /* Could not reserve boot area */
424 free_bootmem_late(start
, size
);
428 static int __init
efi_systab_init(void *phys
)
431 efi_system_table_64_t
*systab64
;
434 systab64
= early_ioremap((unsigned long)phys
,
436 if (systab64
== NULL
) {
437 pr_err("Couldn't map the system table!\n");
441 efi_systab
.hdr
= systab64
->hdr
;
442 efi_systab
.fw_vendor
= systab64
->fw_vendor
;
443 tmp
|= systab64
->fw_vendor
;
444 efi_systab
.fw_revision
= systab64
->fw_revision
;
445 efi_systab
.con_in_handle
= systab64
->con_in_handle
;
446 tmp
|= systab64
->con_in_handle
;
447 efi_systab
.con_in
= systab64
->con_in
;
448 tmp
|= systab64
->con_in
;
449 efi_systab
.con_out_handle
= systab64
->con_out_handle
;
450 tmp
|= systab64
->con_out_handle
;
451 efi_systab
.con_out
= systab64
->con_out
;
452 tmp
|= systab64
->con_out
;
453 efi_systab
.stderr_handle
= systab64
->stderr_handle
;
454 tmp
|= systab64
->stderr_handle
;
455 efi_systab
.stderr
= systab64
->stderr
;
456 tmp
|= systab64
->stderr
;
457 efi_systab
.runtime
= (void *)(unsigned long)systab64
->runtime
;
458 tmp
|= systab64
->runtime
;
459 efi_systab
.boottime
= (void *)(unsigned long)systab64
->boottime
;
460 tmp
|= systab64
->boottime
;
461 efi_systab
.nr_tables
= systab64
->nr_tables
;
462 efi_systab
.tables
= systab64
->tables
;
463 tmp
|= systab64
->tables
;
465 early_iounmap(systab64
, sizeof(*systab64
));
468 pr_err("EFI data located above 4GB, disabling EFI.\n");
473 efi_system_table_32_t
*systab32
;
475 systab32
= early_ioremap((unsigned long)phys
,
477 if (systab32
== NULL
) {
478 pr_err("Couldn't map the system table!\n");
482 efi_systab
.hdr
= systab32
->hdr
;
483 efi_systab
.fw_vendor
= systab32
->fw_vendor
;
484 efi_systab
.fw_revision
= systab32
->fw_revision
;
485 efi_systab
.con_in_handle
= systab32
->con_in_handle
;
486 efi_systab
.con_in
= systab32
->con_in
;
487 efi_systab
.con_out_handle
= systab32
->con_out_handle
;
488 efi_systab
.con_out
= systab32
->con_out
;
489 efi_systab
.stderr_handle
= systab32
->stderr_handle
;
490 efi_systab
.stderr
= systab32
->stderr
;
491 efi_systab
.runtime
= (void *)(unsigned long)systab32
->runtime
;
492 efi_systab
.boottime
= (void *)(unsigned long)systab32
->boottime
;
493 efi_systab
.nr_tables
= systab32
->nr_tables
;
494 efi_systab
.tables
= systab32
->tables
;
496 early_iounmap(systab32
, sizeof(*systab32
));
499 efi
.systab
= &efi_systab
;
502 * Verify the EFI Table
504 if (efi
.systab
->hdr
.signature
!= EFI_SYSTEM_TABLE_SIGNATURE
) {
505 pr_err("System table signature incorrect!\n");
508 if ((efi
.systab
->hdr
.revision
>> 16) == 0)
509 pr_err("Warning: System table version "
510 "%d.%02d, expected 1.00 or greater!\n",
511 efi
.systab
->hdr
.revision
>> 16,
512 efi
.systab
->hdr
.revision
& 0xffff);
517 static int __init
efi_config_init(u64 tables
, int nr_tables
)
519 void *config_tables
, *tablep
;
523 sz
= sizeof(efi_config_table_64_t
);
525 sz
= sizeof(efi_config_table_32_t
);
528 * Let's see what config tables the firmware passed to us.
530 config_tables
= early_ioremap(tables
, nr_tables
* sz
);
531 if (config_tables
== NULL
) {
532 pr_err("Could not map Configuration table!\n");
536 tablep
= config_tables
;
538 for (i
= 0; i
< efi
.systab
->nr_tables
; i
++) {
544 guid
= ((efi_config_table_64_t
*)tablep
)->guid
;
545 table64
= ((efi_config_table_64_t
*)tablep
)->table
;
550 pr_err("Table located above 4GB, disabling EFI.\n");
551 early_iounmap(config_tables
,
552 efi
.systab
->nr_tables
* sz
);
557 guid
= ((efi_config_table_32_t
*)tablep
)->guid
;
558 table
= ((efi_config_table_32_t
*)tablep
)->table
;
560 if (!efi_guidcmp(guid
, MPS_TABLE_GUID
)) {
562 pr_cont(" MPS=0x%lx ", table
);
563 } else if (!efi_guidcmp(guid
, ACPI_20_TABLE_GUID
)) {
565 pr_cont(" ACPI 2.0=0x%lx ", table
);
566 } else if (!efi_guidcmp(guid
, ACPI_TABLE_GUID
)) {
568 pr_cont(" ACPI=0x%lx ", table
);
569 } else if (!efi_guidcmp(guid
, SMBIOS_TABLE_GUID
)) {
571 pr_cont(" SMBIOS=0x%lx ", table
);
573 } else if (!efi_guidcmp(guid
, UV_SYSTEM_TABLE_GUID
)) {
574 efi
.uv_systab
= table
;
575 pr_cont(" UVsystab=0x%lx ", table
);
577 } else if (!efi_guidcmp(guid
, HCDP_TABLE_GUID
)) {
579 pr_cont(" HCDP=0x%lx ", table
);
580 } else if (!efi_guidcmp(guid
, UGA_IO_PROTOCOL_GUID
)) {
582 pr_cont(" UGA=0x%lx ", table
);
587 early_iounmap(config_tables
, efi
.systab
->nr_tables
* sz
);
591 static int __init
efi_runtime_init(void)
593 efi_runtime_services_t
*runtime
;
596 * Check out the runtime services table. We need to map
597 * the runtime services table so that we can grab the physical
598 * address of several of the EFI runtime functions, needed to
599 * set the firmware into virtual mode.
601 runtime
= early_ioremap((unsigned long)efi
.systab
->runtime
,
602 sizeof(efi_runtime_services_t
));
604 pr_err("Could not map the runtime service table!\n");
608 * We will only need *early* access to the following
609 * EFI runtime service before set_virtual_address_map
612 efi_phys
.set_virtual_address_map
=
613 (efi_set_virtual_address_map_t
*)
614 runtime
->set_virtual_address_map
;
616 early_iounmap(runtime
, sizeof(efi_runtime_services_t
));
621 static int __init
efi_memmap_init(void)
623 /* Map the EFI memory map */
624 memmap
.map
= early_ioremap((unsigned long)memmap
.phys_map
,
625 memmap
.nr_map
* memmap
.desc_size
);
626 if (memmap
.map
== NULL
) {
627 pr_err("Could not map the memory map!\n");
630 memmap
.map_end
= memmap
.map
+ (memmap
.nr_map
* memmap
.desc_size
);
638 void __init
efi_init(void)
641 char vendor
[100] = "unknown";
646 if (boot_params
.efi_info
.efi_systab_hi
||
647 boot_params
.efi_info
.efi_memmap_hi
) {
648 pr_info("Table located above 4GB, disabling EFI.\n");
652 efi_phys
.systab
= (efi_system_table_t
*)boot_params
.efi_info
.efi_systab
;
653 efi_native
= !efi_64bit
;
655 efi_phys
.systab
= (efi_system_table_t
*)
656 (boot_params
.efi_info
.efi_systab
|
657 ((__u64
)boot_params
.efi_info
.efi_systab_hi
<<32));
658 efi_native
= efi_64bit
;
661 if (efi_systab_init(efi_phys
.systab
)) {
667 * Show what we know for posterity
669 c16
= tmp
= early_ioremap(efi
.systab
->fw_vendor
, 2);
671 for (i
= 0; i
< sizeof(vendor
) - 1 && *c16
; ++i
)
675 pr_err("Could not map the firmware vendor!\n");
676 early_iounmap(tmp
, 2);
678 pr_info("EFI v%u.%.02u by %s\n",
679 efi
.systab
->hdr
.revision
>> 16,
680 efi
.systab
->hdr
.revision
& 0xffff, vendor
);
682 if (efi_config_init(efi
.systab
->tables
, efi
.systab
->nr_tables
)) {
688 * Note: We currently don't support runtime services on an EFI
689 * that doesn't match the kernel 32/64-bit mode.
693 pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n");
694 else if (efi_runtime_init()) {
699 if (efi_memmap_init()) {
704 x86_platform
.get_wallclock
= efi_get_time
;
705 x86_platform
.set_wallclock
= efi_set_rtc_mmss
;
713 void __init
efi_set_executable(efi_memory_desc_t
*md
, bool executable
)
717 addr
= md
->virt_addr
;
718 npages
= md
->num_pages
;
720 memrange_efi_to_native(&addr
, &npages
);
723 set_memory_x(addr
, npages
);
725 set_memory_nx(addr
, npages
);
728 static void __init
runtime_code_page_mkexec(void)
730 efi_memory_desc_t
*md
;
733 /* Make EFI runtime service code area executable */
734 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
737 if (md
->type
!= EFI_RUNTIME_SERVICES_CODE
)
740 efi_set_executable(md
, true);
745 * This function will switch the EFI runtime services to virtual mode.
746 * Essentially, look through the EFI memmap and map every region that
747 * has the runtime attribute bit set in its memory descriptor and update
748 * that memory descriptor with the virtual address obtained from ioremap().
749 * This enables the runtime services to be called without having to
750 * thunk back into physical mode for every invocation.
752 void __init
efi_enter_virtual_mode(void)
754 efi_memory_desc_t
*md
, *prev_md
= NULL
;
757 u64 end
, systab
, addr
, npages
, end_pfn
;
758 void *p
, *va
, *new_memmap
= NULL
;
764 * We don't do virtual mode, since we don't do runtime services, on
771 /* Merge contiguous regions of the same type and attribute */
772 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
781 if (prev_md
->type
!= md
->type
||
782 prev_md
->attribute
!= md
->attribute
) {
787 prev_size
= prev_md
->num_pages
<< EFI_PAGE_SHIFT
;
789 if (md
->phys_addr
== (prev_md
->phys_addr
+ prev_size
)) {
790 prev_md
->num_pages
+= md
->num_pages
;
791 md
->type
= EFI_RESERVED_TYPE
;
798 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
800 if (!(md
->attribute
& EFI_MEMORY_RUNTIME
) &&
801 md
->type
!= EFI_BOOT_SERVICES_CODE
&&
802 md
->type
!= EFI_BOOT_SERVICES_DATA
)
805 size
= md
->num_pages
<< EFI_PAGE_SHIFT
;
806 end
= md
->phys_addr
+ size
;
808 end_pfn
= PFN_UP(end
);
809 if (end_pfn
<= max_low_pfn_mapped
810 || (end_pfn
> (1UL << (32 - PAGE_SHIFT
))
811 && end_pfn
<= max_pfn_mapped
))
812 va
= __va(md
->phys_addr
);
814 va
= efi_ioremap(md
->phys_addr
, size
, md
->type
);
816 md
->virt_addr
= (u64
) (unsigned long) va
;
819 pr_err("ioremap of 0x%llX failed!\n",
820 (unsigned long long)md
->phys_addr
);
824 if (!(md
->attribute
& EFI_MEMORY_WB
)) {
825 addr
= md
->virt_addr
;
826 npages
= md
->num_pages
;
827 memrange_efi_to_native(&addr
, &npages
);
828 set_memory_uc(addr
, npages
);
831 systab
= (u64
) (unsigned long) efi_phys
.systab
;
832 if (md
->phys_addr
<= systab
&& systab
< end
) {
833 systab
+= md
->virt_addr
- md
->phys_addr
;
834 efi
.systab
= (efi_system_table_t
*) (unsigned long) systab
;
836 new_memmap
= krealloc(new_memmap
,
837 (count
+ 1) * memmap
.desc_size
,
839 memcpy(new_memmap
+ (count
* memmap
.desc_size
), md
,
846 status
= phys_efi_set_virtual_address_map(
847 memmap
.desc_size
* count
,
850 (efi_memory_desc_t
*)__pa(new_memmap
));
852 if (status
!= EFI_SUCCESS
) {
853 pr_alert("Unable to switch EFI into virtual mode "
854 "(status=%lx)!\n", status
);
855 panic("EFI call to SetVirtualAddressMap() failed!");
859 * Thankfully, it does seem that no runtime services other than
860 * SetVirtualAddressMap() will touch boot services code, so we can
861 * get rid of it all at this point
863 efi_free_boot_services();
866 * Now that EFI is in virtual mode, update the function
867 * pointers in the runtime service table to the new virtual addresses.
869 * Call EFI services through wrapper functions.
871 efi
.get_time
= virt_efi_get_time
;
872 efi
.set_time
= virt_efi_set_time
;
873 efi
.get_wakeup_time
= virt_efi_get_wakeup_time
;
874 efi
.set_wakeup_time
= virt_efi_set_wakeup_time
;
875 efi
.get_variable
= virt_efi_get_variable
;
876 efi
.get_next_variable
= virt_efi_get_next_variable
;
877 efi
.set_variable
= virt_efi_set_variable
;
878 efi
.get_next_high_mono_count
= virt_efi_get_next_high_mono_count
;
879 efi
.reset_system
= virt_efi_reset_system
;
880 efi
.set_virtual_address_map
= NULL
;
881 efi
.query_variable_info
= virt_efi_query_variable_info
;
882 efi
.update_capsule
= virt_efi_update_capsule
;
883 efi
.query_capsule_caps
= virt_efi_query_capsule_caps
;
884 if (__supported_pte_mask
& _PAGE_NX
)
885 runtime_code_page_mkexec();
888 early_iounmap(memmap
.map
, memmap
.nr_map
* memmap
.desc_size
);
894 * Convenience functions to obtain memory types and attributes
896 u32
efi_mem_type(unsigned long phys_addr
)
898 efi_memory_desc_t
*md
;
901 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
903 if ((md
->phys_addr
<= phys_addr
) &&
904 (phys_addr
< (md
->phys_addr
+
905 (md
->num_pages
<< EFI_PAGE_SHIFT
))))
911 u64
efi_mem_attributes(unsigned long phys_addr
)
913 efi_memory_desc_t
*md
;
916 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
918 if ((md
->phys_addr
<= phys_addr
) &&
919 (phys_addr
< (md
->phys_addr
+
920 (md
->num_pages
<< EFI_PAGE_SHIFT
))))
921 return md
->attribute
;