Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 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> |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 36 | #include <asm/proto.h> |
| 37 | #include <asm/efi.h> |
Huang, Ying | 4de0d4a | 2008-02-13 17:22:41 +0800 | [diff] [blame] | 38 | #include <asm/cacheflush.h> |
Brian Gerst | 3819cd4 | 2009-01-23 11:03:29 +0900 | [diff] [blame] | 39 | #include <asm/fixmap.h> |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 40 | |
| 41 | static pgd_t save_pgd __initdata; |
| 42 | static unsigned long efi_flags __initdata; |
| 43 | |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 44 | static void __init early_code_mapping_set_exec(int executable) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 45 | { |
| 46 | efi_memory_desc_t *md; |
| 47 | void *p; |
| 48 | |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 49 | if (!(__supported_pte_mask & _PAGE_NX)) |
| 50 | return; |
| 51 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 52 | /* Make EFI runtime service code area executable */ |
| 53 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 54 | md = p; |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 55 | if (md->type == EFI_RUNTIME_SERVICES_CODE) |
| 56 | efi_set_executable(md, executable); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | void __init efi_call_phys_prelog(void) |
| 61 | { |
| 62 | unsigned long vaddress; |
| 63 | |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 64 | early_code_mapping_set_exec(1); |
Huang, Ying | 4de0d4a | 2008-02-13 17:22:41 +0800 | [diff] [blame] | 65 | local_irq_save(efi_flags); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 66 | vaddress = (unsigned long)__va(0x0UL); |
Jeremy Fitzhardinge | b899c5e | 2008-01-30 13:32:44 +0100 | [diff] [blame] | 67 | save_pgd = *pgd_offset_k(0x0UL); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 68 | set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress)); |
| 69 | __flush_tlb_all(); |
| 70 | } |
| 71 | |
| 72 | void __init efi_call_phys_epilog(void) |
| 73 | { |
| 74 | /* |
| 75 | * After the lock is released, the original page table is restored. |
| 76 | */ |
| 77 | set_pgd(pgd_offset_k(0x0UL), save_pgd); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 78 | __flush_tlb_all(); |
| 79 | local_irq_restore(efi_flags); |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 80 | early_code_mapping_set_exec(0); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Paul Mackerras | 6a7bbd5 | 2009-08-03 22:38:10 +1000 | [diff] [blame] | 83 | void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size, |
| 84 | u32 type) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 85 | { |
Huang Ying | dd39ecf | 2009-03-04 10:58:33 +0800 | [diff] [blame] | 86 | unsigned long last_map_pfn; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 87 | |
Paul Mackerras | 6a7bbd5 | 2009-08-03 22:38:10 +1000 | [diff] [blame] | 88 | if (type == EFI_MEMORY_MAPPED_IO) |
| 89 | return ioremap(phys_addr, size); |
| 90 | |
Huang Ying | dd39ecf | 2009-03-04 10:58:33 +0800 | [diff] [blame] | 91 | last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size); |
| 92 | if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 93 | return NULL; |
| 94 | |
Huang Ying | dd39ecf | 2009-03-04 10:58:33 +0800 | [diff] [blame] | 95 | return (void __iomem *)__va(phys_addr); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 96 | } |