1 // SPDX-License-Identifier: GPL-2.0
3 * x86_64 specific EFI support functions
4 * Based on Extensible Firmware Interface Specification version 1.0
6 * Copyright (C) 2005-2008 Intel Co.
7 * Fenghua Yu <fenghua.yu@intel.com>
8 * Bibo Mao <bibo.mao@intel.com>
9 * Chandramouli Narayanan <mouli@linux.intel.com>
10 * Huang Ying <ying.huang@intel.com>
12 * Code to convert EFI to E820 map has been implemented in elilo bootloader
13 * based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table
14 * is setup appropriately for EFI runtime code.
19 #define pr_fmt(fmt) "efi: " fmt
21 #include <linux/kernel.h>
22 #include <linux/init.h>
24 #include <linux/types.h>
25 #include <linux/spinlock.h>
26 #include <linux/memblock.h>
27 #include <linux/ioport.h>
28 #include <linux/mc146818rtc.h>
29 #include <linux/efi.h>
30 #include <linux/export.h>
31 #include <linux/uaccess.h>
33 #include <linux/reboot.h>
34 #include <linux/slab.h>
35 #include <linux/ucs2_string.h>
36 #include <linux/mem_encrypt.h>
37 #include <linux/sched/task.h>
39 #include <asm/setup.h>
41 #include <asm/e820/api.h>
42 #include <asm/pgtable.h>
43 #include <asm/tlbflush.h>
44 #include <asm/proto.h>
46 #include <asm/cacheflush.h>
47 #include <asm/fixmap.h>
48 #include <asm/realmode.h>
50 #include <asm/pgalloc.h>
53 * We allocate runtime services regions top-down, starting from -4G, i.e.
54 * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
56 static u64 efi_va = EFI_VA_START;
58 struct efi_scratch efi_scratch;
60 EXPORT_SYMBOL_GPL(efi_mm);
63 * We need our own copy of the higher levels of the page tables
64 * because we want to avoid inserting EFI region mappings (EFI_VA_END
65 * to EFI_VA_START) into the standard kernel page tables. Everything
66 * else can be shared, see efi_sync_low_kernel_mappings().
68 * We don't want the pgd on the pgd_list and cannot use pgd_alloc() for the
71 int __init efi_alloc_page_tables(void)
78 if (efi_have_uv1_memmap())
81 gfp_mask = GFP_KERNEL | __GFP_ZERO;
82 efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
86 pgd = efi_pgd + pgd_index(EFI_VA_END);
87 p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
89 free_page((unsigned long)efi_pgd);
93 pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
95 if (pgtable_l5_enabled())
96 free_page((unsigned long) pgd_page_vaddr(*pgd));
97 free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
101 efi_mm.pgd = efi_pgd;
102 mm_init_cpumask(&efi_mm);
103 init_new_context(NULL, &efi_mm);
109 * Add low kernel mappings for passing arguments to EFI functions.
111 void efi_sync_low_kernel_mappings(void)
113 unsigned num_entries;
114 pgd_t *pgd_k, *pgd_efi;
115 p4d_t *p4d_k, *p4d_efi;
116 pud_t *pud_k, *pud_efi;
117 pgd_t *efi_pgd = efi_mm.pgd;
119 if (efi_have_uv1_memmap())
123 * We can share all PGD entries apart from the one entry that
124 * covers the EFI runtime mapping space.
126 * Make sure the EFI runtime region mappings are guaranteed to
127 * only span a single PGD entry and that the entry also maps
128 * other important kernel regions.
130 MAYBE_BUILD_BUG_ON(pgd_index(EFI_VA_END) != pgd_index(MODULES_END));
131 MAYBE_BUILD_BUG_ON((EFI_VA_START & PGDIR_MASK) !=
132 (EFI_VA_END & PGDIR_MASK));
134 pgd_efi = efi_pgd + pgd_index(PAGE_OFFSET);
135 pgd_k = pgd_offset_k(PAGE_OFFSET);
137 num_entries = pgd_index(EFI_VA_END) - pgd_index(PAGE_OFFSET);
138 memcpy(pgd_efi, pgd_k, sizeof(pgd_t) * num_entries);
141 * As with PGDs, we share all P4D entries apart from the one entry
142 * that covers the EFI runtime mapping space.
144 BUILD_BUG_ON(p4d_index(EFI_VA_END) != p4d_index(MODULES_END));
145 BUILD_BUG_ON((EFI_VA_START & P4D_MASK) != (EFI_VA_END & P4D_MASK));
147 pgd_efi = efi_pgd + pgd_index(EFI_VA_END);
148 pgd_k = pgd_offset_k(EFI_VA_END);
149 p4d_efi = p4d_offset(pgd_efi, 0);
150 p4d_k = p4d_offset(pgd_k, 0);
152 num_entries = p4d_index(EFI_VA_END);
153 memcpy(p4d_efi, p4d_k, sizeof(p4d_t) * num_entries);
156 * We share all the PUD entries apart from those that map the
157 * EFI regions. Copy around them.
159 BUILD_BUG_ON((EFI_VA_START & ~PUD_MASK) != 0);
160 BUILD_BUG_ON((EFI_VA_END & ~PUD_MASK) != 0);
162 p4d_efi = p4d_offset(pgd_efi, EFI_VA_END);
163 p4d_k = p4d_offset(pgd_k, EFI_VA_END);
164 pud_efi = pud_offset(p4d_efi, 0);
165 pud_k = pud_offset(p4d_k, 0);
167 num_entries = pud_index(EFI_VA_END);
168 memcpy(pud_efi, pud_k, sizeof(pud_t) * num_entries);
170 pud_efi = pud_offset(p4d_efi, EFI_VA_START);
171 pud_k = pud_offset(p4d_k, EFI_VA_START);
173 num_entries = PTRS_PER_PUD - pud_index(EFI_VA_START);
174 memcpy(pud_efi, pud_k, sizeof(pud_t) * num_entries);
178 * Wrapper for slow_virt_to_phys() that handles NULL addresses.
180 static inline phys_addr_t
181 virt_to_phys_or_null_size(void *va, unsigned long size)
188 if (virt_addr_valid(va))
189 return virt_to_phys(va);
191 pa = slow_virt_to_phys(va);
193 /* check if the object crosses a page boundary */
194 if (WARN_ON((pa ^ (pa + size - 1)) & PAGE_MASK))
200 #define virt_to_phys_or_null(addr) \
201 virt_to_phys_or_null_size((addr), sizeof(*(addr)))
203 int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
205 unsigned long pfn, text, pf, rodata;
208 pgd_t *pgd = efi_mm.pgd;
210 if (efi_have_uv1_memmap())
214 * It can happen that the physical address of new_memmap lands in memory
215 * which is not mapped in the EFI page table. Therefore we need to go
216 * and ident-map those pages containing the map before calling
217 * phys_efi_set_virtual_address_map().
219 pfn = pa_memmap >> PAGE_SHIFT;
220 pf = _PAGE_NX | _PAGE_RW | _PAGE_ENC;
221 if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, pf)) {
222 pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
227 * Certain firmware versions are way too sentimential and still believe
228 * they are exclusive and unquestionable owners of the first physical page,
229 * even though they explicitly mark it as EFI_CONVENTIONAL_MEMORY
230 * (but then write-access it later during SetVirtualAddressMap()).
232 * Create a 1:1 mapping for this page, to avoid triple faults during early
233 * boot with such firmware. We are free to hand this page to the BIOS,
234 * as trim_bios_range() will reserve the first page and isolate it away
235 * from memory allocators anyway.
237 if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, pf)) {
238 pr_err("Failed to create 1:1 mapping for the first page!\n");
243 * When making calls to the firmware everything needs to be 1:1
244 * mapped and addressable with 32-bit pointers. Map the kernel
245 * text and allocate a new stack because we can't rely on the
246 * stack pointer being < 4GB.
251 page = alloc_page(GFP_KERNEL|__GFP_DMA32);
253 pr_err("Unable to allocate EFI runtime stack < 4GB\n");
257 efi_scratch.phys_stack = page_to_phys(page + 1); /* stack grows down */
259 npages = (_etext - _text) >> PAGE_SHIFT;
261 pfn = text >> PAGE_SHIFT;
264 if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, pf)) {
265 pr_err("Failed to map kernel text 1:1\n");
269 npages = (__end_rodata - __start_rodata) >> PAGE_SHIFT;
270 rodata = __pa(__start_rodata);
271 pfn = rodata >> PAGE_SHIFT;
272 if (kernel_map_pages_in_pgd(pgd, pfn, rodata, npages, pf)) {
273 pr_err("Failed to map kernel rodata 1:1\n");
280 static void __init __map_region(efi_memory_desc_t *md, u64 va)
282 unsigned long flags = _PAGE_RW;
284 pgd_t *pgd = efi_mm.pgd;
287 * EFI_RUNTIME_SERVICES_CODE regions typically cover PE/COFF
288 * executable images in memory that consist of both R-X and
289 * RW- sections, so we cannot apply read-only or non-exec
290 * permissions just yet. However, modern EFI systems provide
291 * a memory attributes table that describes those sections
292 * with the appropriate restricted permissions, which are
293 * applied in efi_runtime_update_mappings() below. All other
294 * regions can be mapped non-executable at this point, with
295 * the exception of boot services code regions, but those will
296 * be unmapped again entirely in efi_free_boot_services().
298 if (md->type != EFI_BOOT_SERVICES_CODE &&
299 md->type != EFI_RUNTIME_SERVICES_CODE)
302 if (!(md->attribute & EFI_MEMORY_WB))
305 if (sev_active() && md->type != EFI_MEMORY_MAPPED_IO)
308 pfn = md->phys_addr >> PAGE_SHIFT;
309 if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
310 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
314 void __init efi_map_region(efi_memory_desc_t *md)
316 unsigned long size = md->num_pages << PAGE_SHIFT;
317 u64 pa = md->phys_addr;
319 if (efi_have_uv1_memmap())
320 return old_map_region(md);
323 * Make sure the 1:1 mappings are present as a catch-all for b0rked
324 * firmware which doesn't update all internal pointers after switching
325 * to virtual mode and would otherwise crap on us.
327 __map_region(md, md->phys_addr);
330 * Enforce the 1:1 mapping as the default virtual address when
331 * booting in EFI mixed mode, because even though we may be
332 * running a 64-bit kernel, the firmware may only be 32-bit.
334 if (efi_is_mixed()) {
335 md->virt_addr = md->phys_addr;
341 /* Is PA 2M-aligned? */
342 if (!(pa & (PMD_SIZE - 1))) {
345 u64 pa_offset = pa & (PMD_SIZE - 1);
346 u64 prev_va = efi_va;
348 /* get us the same offset within this 2M page */
349 efi_va = (efi_va & PMD_MASK) + pa_offset;
351 if (efi_va > prev_va)
355 if (efi_va < EFI_VA_END) {
356 pr_warn(FW_WARN "VA address range overflow!\n");
361 __map_region(md, efi_va);
362 md->virt_addr = efi_va;
366 * kexec kernel will use efi_map_region_fixed to map efi runtime memory ranges.
367 * md->virt_addr is the original virtual address which had been mapped in kexec
370 void __init efi_map_region_fixed(efi_memory_desc_t *md)
372 __map_region(md, md->phys_addr);
373 __map_region(md, md->virt_addr);
376 void __init parse_efi_setup(u64 phys_addr, u32 data_len)
378 efi_setup = phys_addr + sizeof(struct setup_data);
381 static int __init efi_update_mappings(efi_memory_desc_t *md, unsigned long pf)
384 pgd_t *pgd = efi_mm.pgd;
387 /* Update the 1:1 mapping */
388 pfn = md->phys_addr >> PAGE_SHIFT;
389 err1 = kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, md->num_pages, pf);
391 pr_err("Error while updating 1:1 mapping PA 0x%llx -> VA 0x%llx!\n",
392 md->phys_addr, md->virt_addr);
395 err2 = kernel_map_pages_in_pgd(pgd, pfn, md->virt_addr, md->num_pages, pf);
397 pr_err("Error while updating VA mapping PA 0x%llx -> VA 0x%llx!\n",
398 md->phys_addr, md->virt_addr);
404 static int __init efi_update_mem_attr(struct mm_struct *mm, efi_memory_desc_t *md)
406 unsigned long pf = 0;
408 if (md->attribute & EFI_MEMORY_XP)
411 if (!(md->attribute & EFI_MEMORY_RO))
417 return efi_update_mappings(md, pf);
420 void __init efi_runtime_update_mappings(void)
422 efi_memory_desc_t *md;
424 if (efi_have_uv1_memmap()) {
425 if (__supported_pte_mask & _PAGE_NX)
426 runtime_code_page_mkexec();
431 * Use the EFI Memory Attribute Table for mapping permissions if it
432 * exists, since it is intended to supersede EFI_PROPERTIES_TABLE.
434 if (efi_enabled(EFI_MEM_ATTR)) {
435 efi_memattr_apply_permissions(NULL, efi_update_mem_attr);
440 * EFI_MEMORY_ATTRIBUTES_TABLE is intended to replace
441 * EFI_PROPERTIES_TABLE. So, use EFI_PROPERTIES_TABLE to update
442 * permissions only if EFI_MEMORY_ATTRIBUTES_TABLE is not
443 * published by the firmware. Even if we find a buggy implementation of
444 * EFI_MEMORY_ATTRIBUTES_TABLE, don't fall back to
445 * EFI_PROPERTIES_TABLE, because of the same reason.
448 if (!efi_enabled(EFI_NX_PE_DATA))
451 for_each_efi_memory_desc(md) {
452 unsigned long pf = 0;
454 if (!(md->attribute & EFI_MEMORY_RUNTIME))
457 if (!(md->attribute & EFI_MEMORY_WB))
460 if ((md->attribute & EFI_MEMORY_XP) ||
461 (md->type == EFI_RUNTIME_SERVICES_DATA))
464 if (!(md->attribute & EFI_MEMORY_RO) &&
465 (md->type != EFI_RUNTIME_SERVICES_CODE))
471 efi_update_mappings(md, pf);
475 void __init efi_dump_pagetable(void)
477 #ifdef CONFIG_EFI_PGT_DUMP
478 if (efi_have_uv1_memmap())
479 ptdump_walk_pgd_level(NULL, &init_mm);
481 ptdump_walk_pgd_level(NULL, &efi_mm);
486 * Makes the calling thread switch to/from efi_mm context. Can be used
487 * in a kernel thread and user context. Preemption needs to remain disabled
488 * while the EFI-mm is borrowed. mmgrab()/mmdrop() is not used because the mm
489 * can not change under us.
490 * It should be ensured that there are no concurent calls to this function.
492 void efi_switch_mm(struct mm_struct *mm)
494 efi_scratch.prev_mm = current->active_mm;
495 current->active_mm = mm;
496 switch_mm(efi_scratch.prev_mm, mm, NULL);
499 static DEFINE_SPINLOCK(efi_runtime_lock);
502 * DS and ES contain user values. We need to save them.
503 * The 32-bit EFI code needs a valid DS, ES, and SS. There's no
504 * need to save the old SS: __KERNEL_DS is always acceptable.
506 #define __efi_thunk(func, ...) \
508 unsigned short __ds, __es; \
509 efi_status_t ____s; \
511 savesegment(ds, __ds); \
512 savesegment(es, __es); \
514 loadsegment(ss, __KERNEL_DS); \
515 loadsegment(ds, __KERNEL_DS); \
516 loadsegment(es, __KERNEL_DS); \
518 ____s = efi64_thunk(efi.runtime->mixed_mode.func, __VA_ARGS__); \
520 loadsegment(ds, __ds); \
521 loadsegment(es, __es); \
523 ____s ^= (____s & BIT(31)) | (____s & BIT_ULL(31)) << 32; \
528 * Switch to the EFI page tables early so that we can access the 1:1
529 * runtime services mappings which are not mapped in any other page
532 * Also, disable interrupts because the IDT points to 64-bit handlers,
533 * which aren't going to function correctly when we switch to 32-bit.
535 #define efi_thunk(func...) \
539 arch_efi_call_virt_setup(); \
541 __s = __efi_thunk(func); \
543 arch_efi_call_virt_teardown(); \
548 static efi_status_t __init __no_sanitize_address
549 efi_thunk_set_virtual_address_map(unsigned long memory_map_size,
550 unsigned long descriptor_size,
551 u32 descriptor_version,
552 efi_memory_desc_t *virtual_map)
557 efi_sync_low_kernel_mappings();
558 local_irq_save(flags);
560 efi_switch_mm(&efi_mm);
562 status = __efi_thunk(set_virtual_address_map, memory_map_size,
563 descriptor_size, descriptor_version, virtual_map);
565 efi_switch_mm(efi_scratch.prev_mm);
566 local_irq_restore(flags);
571 static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc)
573 return EFI_UNSUPPORTED;
576 static efi_status_t efi_thunk_set_time(efi_time_t *tm)
578 return EFI_UNSUPPORTED;
582 efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
585 return EFI_UNSUPPORTED;
589 efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
591 return EFI_UNSUPPORTED;
594 static unsigned long efi_name_size(efi_char16_t *name)
596 return ucs2_strsize(name, EFI_VAR_NAME_LEN) + 1;
600 efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
601 u32 *attr, unsigned long *data_size, void *data)
603 u8 buf[24] __aligned(8);
604 efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
606 u32 phys_name, phys_vendor, phys_attr;
607 u32 phys_data_size, phys_data;
610 spin_lock_irqsave(&efi_runtime_lock, flags);
614 phys_data_size = virt_to_phys_or_null(data_size);
615 phys_vendor = virt_to_phys_or_null(vnd);
616 phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
617 phys_attr = virt_to_phys_or_null(attr);
618 phys_data = virt_to_phys_or_null_size(data, *data_size);
620 if (!phys_name || (data && !phys_data))
621 status = EFI_INVALID_PARAMETER;
623 status = efi_thunk(get_variable, phys_name, phys_vendor,
624 phys_attr, phys_data_size, phys_data);
626 spin_unlock_irqrestore(&efi_runtime_lock, flags);
632 efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
633 u32 attr, unsigned long data_size, void *data)
635 u8 buf[24] __aligned(8);
636 efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
637 u32 phys_name, phys_vendor, phys_data;
641 spin_lock_irqsave(&efi_runtime_lock, flags);
645 phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
646 phys_vendor = virt_to_phys_or_null(vnd);
647 phys_data = virt_to_phys_or_null_size(data, data_size);
649 if (!phys_name || (data && !phys_data))
650 status = EFI_INVALID_PARAMETER;
652 status = efi_thunk(set_variable, phys_name, phys_vendor,
653 attr, data_size, phys_data);
655 spin_unlock_irqrestore(&efi_runtime_lock, flags);
661 efi_thunk_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
662 u32 attr, unsigned long data_size,
665 u8 buf[24] __aligned(8);
666 efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
667 u32 phys_name, phys_vendor, phys_data;
671 if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
672 return EFI_NOT_READY;
676 phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
677 phys_vendor = virt_to_phys_or_null(vnd);
678 phys_data = virt_to_phys_or_null_size(data, data_size);
680 if (!phys_name || (data && !phys_data))
681 status = EFI_INVALID_PARAMETER;
683 status = efi_thunk(set_variable, phys_name, phys_vendor,
684 attr, data_size, phys_data);
686 spin_unlock_irqrestore(&efi_runtime_lock, flags);
692 efi_thunk_get_next_variable(unsigned long *name_size,
696 u8 buf[24] __aligned(8);
697 efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
699 u32 phys_name_size, phys_name, phys_vendor;
702 spin_lock_irqsave(&efi_runtime_lock, flags);
706 phys_name_size = virt_to_phys_or_null(name_size);
707 phys_vendor = virt_to_phys_or_null(vnd);
708 phys_name = virt_to_phys_or_null_size(name, *name_size);
711 status = EFI_INVALID_PARAMETER;
713 status = efi_thunk(get_next_variable, phys_name_size,
714 phys_name, phys_vendor);
716 spin_unlock_irqrestore(&efi_runtime_lock, flags);
723 efi_thunk_get_next_high_mono_count(u32 *count)
725 return EFI_UNSUPPORTED;
729 efi_thunk_reset_system(int reset_type, efi_status_t status,
730 unsigned long data_size, efi_char16_t *data)
735 spin_lock_irqsave(&efi_runtime_lock, flags);
737 phys_data = virt_to_phys_or_null_size(data, data_size);
739 efi_thunk(reset_system, reset_type, status, data_size, phys_data);
741 spin_unlock_irqrestore(&efi_runtime_lock, flags);
745 efi_thunk_update_capsule(efi_capsule_header_t **capsules,
746 unsigned long count, unsigned long sg_list)
749 * To properly support this function we would need to repackage
750 * 'capsules' because the firmware doesn't understand 64-bit
753 return EFI_UNSUPPORTED;
757 efi_thunk_query_variable_info(u32 attr, u64 *storage_space,
758 u64 *remaining_space,
759 u64 *max_variable_size)
762 u32 phys_storage, phys_remaining, phys_max;
765 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
766 return EFI_UNSUPPORTED;
768 spin_lock_irqsave(&efi_runtime_lock, flags);
770 phys_storage = virt_to_phys_or_null(storage_space);
771 phys_remaining = virt_to_phys_or_null(remaining_space);
772 phys_max = virt_to_phys_or_null(max_variable_size);
774 status = efi_thunk(query_variable_info, attr, phys_storage,
775 phys_remaining, phys_max);
777 spin_unlock_irqrestore(&efi_runtime_lock, flags);
783 efi_thunk_query_variable_info_nonblocking(u32 attr, u64 *storage_space,
784 u64 *remaining_space,
785 u64 *max_variable_size)
788 u32 phys_storage, phys_remaining, phys_max;
791 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
792 return EFI_UNSUPPORTED;
794 if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
795 return EFI_NOT_READY;
797 phys_storage = virt_to_phys_or_null(storage_space);
798 phys_remaining = virt_to_phys_or_null(remaining_space);
799 phys_max = virt_to_phys_or_null(max_variable_size);
801 status = efi_thunk(query_variable_info, attr, phys_storage,
802 phys_remaining, phys_max);
804 spin_unlock_irqrestore(&efi_runtime_lock, flags);
810 efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules,
811 unsigned long count, u64 *max_size,
815 * To properly support this function we would need to repackage
816 * 'capsules' because the firmware doesn't understand 64-bit
819 return EFI_UNSUPPORTED;
822 void __init efi_thunk_runtime_setup(void)
824 if (!IS_ENABLED(CONFIG_EFI_MIXED))
827 efi.get_time = efi_thunk_get_time;
828 efi.set_time = efi_thunk_set_time;
829 efi.get_wakeup_time = efi_thunk_get_wakeup_time;
830 efi.set_wakeup_time = efi_thunk_set_wakeup_time;
831 efi.get_variable = efi_thunk_get_variable;
832 efi.get_next_variable = efi_thunk_get_next_variable;
833 efi.set_variable = efi_thunk_set_variable;
834 efi.set_variable_nonblocking = efi_thunk_set_variable_nonblocking;
835 efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
836 efi.reset_system = efi_thunk_reset_system;
837 efi.query_variable_info = efi_thunk_query_variable_info;
838 efi.query_variable_info_nonblocking = efi_thunk_query_variable_info_nonblocking;
839 efi.update_capsule = efi_thunk_update_capsule;
840 efi.query_capsule_caps = efi_thunk_query_capsule_caps;
843 efi_status_t __init __no_sanitize_address
844 efi_set_virtual_address_map(unsigned long memory_map_size,
845 unsigned long descriptor_size,
846 u32 descriptor_version,
847 efi_memory_desc_t *virtual_map,
848 unsigned long systab_phys)
850 const efi_system_table_t *systab = (efi_system_table_t *)systab_phys;
853 pgd_t *save_pgd = NULL;
856 return efi_thunk_set_virtual_address_map(memory_map_size,
861 if (efi_have_uv1_memmap()) {
862 save_pgd = efi_uv1_memmap_phys_prolog();
866 efi_switch_mm(&efi_mm);
871 /* Disable interrupts around EFI calls: */
872 local_irq_save(flags);
873 status = efi_call(efi.runtime->set_virtual_address_map,
874 memory_map_size, descriptor_size,
875 descriptor_version, virtual_map);
876 local_irq_restore(flags);
880 /* grab the virtually remapped EFI runtime services table pointer */
881 efi.runtime = READ_ONCE(systab->runtime);
884 efi_uv1_memmap_phys_epilog(save_pgd);
886 efi_switch_mm(efi_scratch.prev_mm);