2 * x86_64 specific EFI support functions
3 * Based on Extensible Firmware Interface Specification version 1.0
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>
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.
18 #include <linux/kernel.h>
19 #include <linux/init.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>
29 #include <linux/reboot.h>
31 #include <asm/setup.h>
34 #include <asm/pgtable.h>
35 #include <asm/tlbflush.h>
36 #include <asm/proto.h>
38 #include <asm/cacheflush.h>
39 #include <asm/fixmap.h>
41 static pgd_t save_pgd __initdata;
42 static unsigned long efi_flags __initdata;
44 static void __init early_mapping_set_exec(unsigned long start,
48 unsigned long num_pages;
51 end = (end + PMD_SIZE - 1) & PMD_MASK;
52 num_pages = (end - start) >> PAGE_SHIFT;
54 set_memory_x((unsigned long)__va(start), num_pages);
56 set_memory_nx((unsigned long)__va(start), num_pages);
59 static void __init early_runtime_code_mapping_set_exec(int executable)
61 efi_memory_desc_t *md;
64 if (!(__supported_pte_mask & _PAGE_NX))
67 /* Make EFI runtime service code area executable */
68 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
70 if (md->type == EFI_RUNTIME_SERVICES_CODE) {
72 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
73 early_mapping_set_exec(md->phys_addr, end, executable);
78 void __init efi_call_phys_prelog(void)
80 unsigned long vaddress;
82 early_runtime_code_mapping_set_exec(1);
83 local_irq_save(efi_flags);
84 vaddress = (unsigned long)__va(0x0UL);
85 save_pgd = *pgd_offset_k(0x0UL);
86 set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress));
90 void __init efi_call_phys_epilog(void)
93 * After the lock is released, the original page table is restored.
95 set_pgd(pgd_offset_k(0x0UL), save_pgd);
97 local_irq_restore(efi_flags);
98 early_runtime_code_mapping_set_exec(0);
101 void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size)
103 unsigned long last_map_pfn;
105 last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
106 if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size)
109 return (void __iomem *)__va(phys_addr);