]> Pileus Git - ~andy/linux/blob - arch/x86/platform/efi/efi_64.c
Merge branch 'core-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~andy/linux] / arch / x86 / platform / efi / efi_64.c
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>
36 #include <asm/proto.h>
37 #include <asm/efi.h>
38 #include <asm/cacheflush.h>
39 #include <asm/fixmap.h>
40
41 static pgd_t save_pgd __initdata;
42 static unsigned long efi_flags __initdata;
43
44 static void __init early_code_mapping_set_exec(int executable)
45 {
46         efi_memory_desc_t *md;
47         void *p;
48
49         if (!(__supported_pte_mask & _PAGE_NX))
50                 return;
51
52         /* Make EFI service code area executable */
53         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
54                 md = p;
55                 if (md->type == EFI_RUNTIME_SERVICES_CODE ||
56                     md->type == EFI_BOOT_SERVICES_CODE)
57                         efi_set_executable(md, executable);
58         }
59 }
60
61 unsigned long efi_call_virt_prelog(void)
62 {
63         unsigned long saved;
64
65         saved = read_cr3();
66         write_cr3(real_mode_header->trampoline_pgd);
67
68         return saved;
69 }
70
71 void efi_call_virt_epilog(unsigned long saved)
72 {
73         write_cr3(saved);
74 }
75
76 void __init efi_call_phys_prelog(void)
77 {
78         unsigned long vaddress;
79
80         early_code_mapping_set_exec(1);
81         local_irq_save(efi_flags);
82         vaddress = (unsigned long)__va(0x0UL);
83         save_pgd = *pgd_offset_k(0x0UL);
84         set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress));
85         __flush_tlb_all();
86 }
87
88 void __init efi_call_phys_epilog(void)
89 {
90         /*
91          * After the lock is released, the original page table is restored.
92          */
93         set_pgd(pgd_offset_k(0x0UL), save_pgd);
94         __flush_tlb_all();
95         local_irq_restore(efi_flags);
96         early_code_mapping_set_exec(0);
97 }
98
99 void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
100                                  u32 type, u64 attribute)
101 {
102         unsigned long last_map_pfn;
103
104         if (type == EFI_MEMORY_MAPPED_IO)
105                 return ioremap(phys_addr, size);
106
107         last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
108         if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) {
109                 unsigned long top = last_map_pfn << PAGE_SHIFT;
110                 efi_ioremap(top, size - (top - phys_addr), type, attribute);
111         }
112
113         if (!(attribute & EFI_MEMORY_WB))
114                 efi_memory_uc((u64)(unsigned long)__va(phys_addr), size);
115
116         return (void __iomem *)__va(phys_addr);
117 }