Commit | Line | Data |
---|---|---|
5b83683f HY |
1 | /* |
2 | * x86_64 specific EFI support functions | |
3 | * Based on Extensible Firmware Interface Specification version 1.0 | |
4 | * | |
5 | * Copyright (C) 2005-2008 Intel Co. | |
6 | * Fenghua Yu <fenghua.yu@intel.com> | |
7 | * Bibo Mao <bibo.mao@intel.com> | |
8 | * Chandramouli Narayanan <mouli@linux.intel.com> | |
9 | * Huang Ying <ying.huang@intel.com> | |
10 | * | |
11 | * Code to convert EFI to E820 map has been implemented in elilo bootloader | |
12 | * based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table | |
13 | * is setup appropriately for EFI runtime code. | |
14 | * - mouli 06/14/2007. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include <linux/kernel.h> | |
19 | #include <linux/init.h> | |
20 | #include <linux/mm.h> | |
21 | #include <linux/types.h> | |
22 | #include <linux/spinlock.h> | |
23 | #include <linux/bootmem.h> | |
24 | #include <linux/ioport.h> | |
25 | #include <linux/module.h> | |
26 | #include <linux/efi.h> | |
27 | #include <linux/uaccess.h> | |
28 | #include <linux/io.h> | |
29 | #include <linux/reboot.h> | |
30 | ||
31 | #include <asm/setup.h> | |
32 | #include <asm/page.h> | |
33 | #include <asm/e820.h> | |
34 | #include <asm/pgtable.h> | |
35 | #include <asm/tlbflush.h> | |
5b83683f HY |
36 | #include <asm/proto.h> |
37 | #include <asm/efi.h> | |
4de0d4a6 | 38 | #include <asm/cacheflush.h> |
5b83683f HY |
39 | |
40 | static pgd_t save_pgd __initdata; | |
41 | static unsigned long efi_flags __initdata; | |
42 | ||
5b83683f HY |
43 | static void __init early_mapping_set_exec(unsigned long start, |
44 | unsigned long end, | |
45 | int executable) | |
46 | { | |
4de0d4a6 HY |
47 | unsigned long num_pages; |
48 | ||
49 | start &= PMD_MASK; | |
50 | end = (end + PMD_SIZE - 1) & PMD_MASK; | |
51 | num_pages = (end - start) >> PAGE_SHIFT; | |
52 | if (executable) | |
53 | set_memory_x((unsigned long)__va(start), num_pages); | |
54 | else | |
55 | set_memory_nx((unsigned long)__va(start), num_pages); | |
5b83683f HY |
56 | } |
57 | ||
58 | static void __init early_runtime_code_mapping_set_exec(int executable) | |
59 | { | |
60 | efi_memory_desc_t *md; | |
61 | void *p; | |
62 | ||
a2172e25 HY |
63 | if (!(__supported_pte_mask & _PAGE_NX)) |
64 | return; | |
65 | ||
5b83683f HY |
66 | /* Make EFI runtime service code area executable */ |
67 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | |
68 | md = p; | |
69 | if (md->type == EFI_RUNTIME_SERVICES_CODE) { | |
70 | unsigned long end; | |
4de0d4a6 | 71 | end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT); |
5b83683f HY |
72 | early_mapping_set_exec(md->phys_addr, end, executable); |
73 | } | |
74 | } | |
75 | } | |
76 | ||
77 | void __init efi_call_phys_prelog(void) | |
78 | { | |
79 | unsigned long vaddress; | |
80 | ||
5b83683f | 81 | early_runtime_code_mapping_set_exec(1); |
4de0d4a6 | 82 | local_irq_save(efi_flags); |
5b83683f | 83 | vaddress = (unsigned long)__va(0x0UL); |
b899c5ed | 84 | save_pgd = *pgd_offset_k(0x0UL); |
5b83683f HY |
85 | set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress)); |
86 | __flush_tlb_all(); | |
87 | } | |
88 | ||
89 | void __init efi_call_phys_epilog(void) | |
90 | { | |
91 | /* | |
92 | * After the lock is released, the original page table is restored. | |
93 | */ | |
94 | set_pgd(pgd_offset_k(0x0UL), save_pgd); | |
5b83683f HY |
95 | __flush_tlb_all(); |
96 | local_irq_restore(efi_flags); | |
4de0d4a6 | 97 | early_runtime_code_mapping_set_exec(0); |
5b83683f HY |
98 | } |
99 | ||
5b83683f HY |
100 | void __init efi_reserve_bootmem(void) |
101 | { | |
102 | reserve_bootmem_generic((unsigned long)memmap.phys_map, | |
103 | memmap.nr_map * memmap.desc_size); | |
104 | } | |
105 | ||
1c083eb2 | 106 | void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size) |
5b83683f | 107 | { |
4a3575fd | 108 | static unsigned pages_mapped __initdata; |
5b83683f | 109 | unsigned i, pages; |
4a3575fd | 110 | unsigned long offset; |
5b83683f | 111 | |
4a3575fd HY |
112 | pages = PFN_UP(phys_addr + size) - PFN_DOWN(phys_addr); |
113 | offset = phys_addr & ~PAGE_MASK; | |
114 | phys_addr &= PAGE_MASK; | |
1c083eb2 | 115 | |
5b83683f HY |
116 | if (pages_mapped + pages > MAX_EFI_IO_PAGES) |
117 | return NULL; | |
118 | ||
119 | for (i = 0; i < pages; i++) { | |
a2172e25 | 120 | __set_fixmap(FIX_EFI_IO_MAP_FIRST_PAGE - pages_mapped, |
1c083eb2 HY |
121 | phys_addr, PAGE_KERNEL); |
122 | phys_addr += PAGE_SIZE; | |
5b83683f HY |
123 | pages_mapped++; |
124 | } | |
125 | ||
126 | return (void __iomem *)__fix_to_virt(FIX_EFI_IO_MAP_FIRST_PAGE - \ | |
4a3575fd | 127 | (pages_mapped - pages)) + offset; |
5b83683f | 128 | } |