xref: /openbmc/linux/arch/x86/platform/efi/efi_32.c (revision 82df5b73)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Extensible Firmware Interface
4  *
5  * Based on Extensible Firmware Interface Specification version 1.0
6  *
7  * Copyright (C) 1999 VA Linux Systems
8  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
9  * Copyright (C) 1999-2002 Hewlett-Packard Co.
10  *	David Mosberger-Tang <davidm@hpl.hp.com>
11  *	Stephane Eranian <eranian@hpl.hp.com>
12  *
13  * All EFI Runtime Services are not implemented yet as EFI only
14  * supports physical mode addressing on SoftSDV. This is to be fixed
15  * in a future version.  --drummond 1999-07-20
16  *
17  * Implemented EFI runtime services and virtual mode calls.  --davidm
18  *
19  * Goutham Rao: <goutham.rao@intel.com>
20  *	Skip non-WB memory and ignore empty memory ranges.
21  */
22 
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/ioport.h>
26 #include <linux/efi.h>
27 #include <linux/pgtable.h>
28 
29 #include <asm/io.h>
30 #include <asm/desc.h>
31 #include <asm/page.h>
32 #include <asm/tlbflush.h>
33 #include <asm/efi.h>
34 
35 /*
36  * To make EFI call EFI runtime service in physical addressing mode we need
37  * prolog/epilog before/after the invocation to claim the EFI runtime service
38  * handler exclusively and to duplicate a memory mapping in low memory space,
39  * say 0 - 3G.
40  */
41 
42 int __init efi_alloc_page_tables(void)
43 {
44 	return 0;
45 }
46 
47 void efi_sync_low_kernel_mappings(void) {}
48 
49 void __init efi_dump_pagetable(void)
50 {
51 #ifdef CONFIG_EFI_PGT_DUMP
52 	ptdump_walk_pgd_level(NULL, &init_mm);
53 #endif
54 }
55 
56 int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
57 {
58 	return 0;
59 }
60 
61 void __init efi_map_region(efi_memory_desc_t *md)
62 {
63 	old_map_region(md);
64 }
65 
66 void __init efi_map_region_fixed(efi_memory_desc_t *md) {}
67 void __init parse_efi_setup(u64 phys_addr, u32 data_len) {}
68 
69 efi_status_t efi_call_svam(efi_runtime_services_t * const *,
70 			   u32, u32, u32, void *, u32);
71 
72 efi_status_t __init efi_set_virtual_address_map(unsigned long memory_map_size,
73 						unsigned long descriptor_size,
74 						u32 descriptor_version,
75 						efi_memory_desc_t *virtual_map,
76 						unsigned long systab_phys)
77 {
78 	const efi_system_table_t *systab = (efi_system_table_t *)systab_phys;
79 	struct desc_ptr gdt_descr;
80 	efi_status_t status;
81 	unsigned long flags;
82 	pgd_t *save_pgd;
83 
84 	/* Current pgd is swapper_pg_dir, we'll restore it later: */
85 	save_pgd = swapper_pg_dir;
86 	load_cr3(initial_page_table);
87 	__flush_tlb_all();
88 
89 	gdt_descr.address = get_cpu_gdt_paddr(0);
90 	gdt_descr.size = GDT_SIZE - 1;
91 	load_gdt(&gdt_descr);
92 
93 	/* Disable interrupts around EFI calls: */
94 	local_irq_save(flags);
95 	status = efi_call_svam(&systab->runtime,
96 			       memory_map_size, descriptor_size,
97 			       descriptor_version, virtual_map,
98 			       __pa(&efi.runtime));
99 	local_irq_restore(flags);
100 
101 	load_fixmap_gdt(0);
102 	load_cr3(save_pgd);
103 	__flush_tlb_all();
104 
105 	return status;
106 }
107 
108 void __init efi_runtime_update_mappings(void)
109 {
110 	if (__supported_pte_mask & _PAGE_NX)
111 		runtime_code_page_mkexec();
112 }
113