Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Extensible Firmware Interface |
| 3 | * |
| 4 | * Based on Extensible Firmware Interface Specification version 1.0 |
| 5 | * |
| 6 | * Copyright (C) 1999 VA Linux Systems |
| 7 | * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> |
| 8 | * Copyright (C) 1999-2002 Hewlett-Packard Co. |
| 9 | * David Mosberger-Tang <davidm@hpl.hp.com> |
| 10 | * Stephane Eranian <eranian@hpl.hp.com> |
| 11 | * |
| 12 | * All EFI Runtime Services are not implemented yet as EFI only |
| 13 | * supports physical mode addressing on SoftSDV. This is to be fixed |
| 14 | * in a future version. --drummond 1999-07-20 |
| 15 | * |
| 16 | * Implemented EFI runtime services and virtual mode calls. --davidm |
| 17 | * |
| 18 | * Goutham Rao: <goutham.rao@intel.com> |
| 19 | * Skip non-WB memory and ignore empty memory ranges. |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/efi.h> |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/io.h> |
Paul Gortmaker | 783ac47 | 2011-05-27 14:46:07 -0400 | [diff] [blame^] | 28 | #include <asm/desc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/page.h> |
| 30 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/tlbflush.h> |
Harvey Harrison | cc7e73f | 2008-02-13 13:26:39 -0800 | [diff] [blame] | 32 | #include <asm/efi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* |
| 35 | * To make EFI call EFI runtime service in physical addressing mode we need |
| 36 | * prelog/epilog before/after the invocation to disable interrupt, to |
| 37 | * claim EFI runtime service handler exclusively and to duplicate a memory in |
| 38 | * low memory space say 0 - 3G. |
| 39 | */ |
| 40 | |
| 41 | static unsigned long efi_rt_eflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static pgd_t efi_bak_pg_dir_pointer[2]; |
| 43 | |
Huang, Ying | 8b2cb7a | 2008-01-30 13:32:11 +0100 | [diff] [blame] | 44 | void efi_call_phys_prelog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
| 46 | unsigned long cr4; |
| 47 | unsigned long temp; |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 48 | struct desc_ptr gdt_descr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | local_irq_save(efi_rt_eflags); |
| 51 | |
| 52 | /* |
Hugh Dickins | 216705d | 2008-07-02 22:48:03 +0100 | [diff] [blame] | 53 | * If I don't have PAE, I should just duplicate two entries in page |
| 54 | * directory. If I have PAE, I just need to duplicate one entry in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * page directory. |
| 56 | */ |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 57 | cr4 = read_cr4_safe(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Hugh Dickins | 216705d | 2008-07-02 22:48:03 +0100 | [diff] [blame] | 59 | if (cr4 & X86_CR4_PAE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | efi_bak_pg_dir_pointer[0].pgd = |
| 61 | swapper_pg_dir[pgd_index(0)].pgd; |
| 62 | swapper_pg_dir[0].pgd = |
| 63 | swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd; |
| 64 | } else { |
| 65 | efi_bak_pg_dir_pointer[0].pgd = |
| 66 | swapper_pg_dir[pgd_index(0)].pgd; |
| 67 | efi_bak_pg_dir_pointer[1].pgd = |
| 68 | swapper_pg_dir[pgd_index(0x400000)].pgd; |
| 69 | swapper_pg_dir[pgd_index(0)].pgd = |
| 70 | swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd; |
| 71 | temp = PAGE_OFFSET + 0x400000; |
| 72 | swapper_pg_dir[pgd_index(0x400000)].pgd = |
| 73 | swapper_pg_dir[pgd_index(temp)].pgd; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * After the lock is released, the original page table is restored. |
| 78 | */ |
Huang, Ying | 8b2cb7a | 2008-01-30 13:32:11 +0100 | [diff] [blame] | 79 | __flush_tlb_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Rusty Russell | 4fbb596 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 81 | gdt_descr.address = __pa(get_cpu_gdt_table(0)); |
| 82 | gdt_descr.size = GDT_SIZE - 1; |
| 83 | load_gdt(&gdt_descr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Huang, Ying | 8b2cb7a | 2008-01-30 13:32:11 +0100 | [diff] [blame] | 86 | void efi_call_phys_epilog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | unsigned long cr4; |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 89 | struct desc_ptr gdt_descr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Rusty Russell | 4fbb596 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 91 | gdt_descr.address = (unsigned long)get_cpu_gdt_table(0); |
| 92 | gdt_descr.size = GDT_SIZE - 1; |
| 93 | load_gdt(&gdt_descr); |
James Bottomley | 2b932f6 | 2006-02-24 13:04:14 -0800 | [diff] [blame] | 94 | |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 95 | cr4 = read_cr4_safe(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Hugh Dickins | 216705d | 2008-07-02 22:48:03 +0100 | [diff] [blame] | 97 | if (cr4 & X86_CR4_PAE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | swapper_pg_dir[pgd_index(0)].pgd = |
| 99 | efi_bak_pg_dir_pointer[0].pgd; |
| 100 | } else { |
| 101 | swapper_pg_dir[pgd_index(0)].pgd = |
| 102 | efi_bak_pg_dir_pointer[0].pgd; |
| 103 | swapper_pg_dir[pgd_index(0x400000)].pgd = |
| 104 | efi_bak_pg_dir_pointer[1].pgd; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * After the lock is released, the original page table is restored. |
| 109 | */ |
Huang, Ying | 8b2cb7a | 2008-01-30 13:32:11 +0100 | [diff] [blame] | 110 | __flush_tlb_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | local_irq_restore(efi_rt_eflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |