blob: 5cab48ee61a4a6e61e522117d97bbfdabaa95a6d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/efi.h>
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/io.h>
28#include <asm/page.h>
29#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/tlbflush.h>
Harvey Harrisoncc7e73f2008-02-13 13:26:39 -080031#include <asm/efi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
34 * To make EFI call EFI runtime service in physical addressing mode we need
35 * prelog/epilog before/after the invocation to disable interrupt, to
36 * claim EFI runtime service handler exclusively and to duplicate a memory in
37 * low memory space say 0 - 3G.
38 */
39
40static unsigned long efi_rt_eflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static pgd_t efi_bak_pg_dir_pointer[2];
42
Huang, Ying8b2cb7a2008-01-30 13:32:11 +010043void efi_call_phys_prelog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 unsigned long cr4;
46 unsigned long temp;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010047 struct desc_ptr gdt_descr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 local_irq_save(efi_rt_eflags);
50
51 /*
Hugh Dickins216705d2008-07-02 22:48:03 +010052 * If I don't have PAE, I should just duplicate two entries in page
53 * directory. If I have PAE, I just need to duplicate one entry in
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * page directory.
55 */
David Friese532c062008-08-17 23:03:40 -050056 cr4 = read_cr4_safe();
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Hugh Dickins216705d2008-07-02 22:48:03 +010058 if (cr4 & X86_CR4_PAE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 efi_bak_pg_dir_pointer[0].pgd =
60 swapper_pg_dir[pgd_index(0)].pgd;
61 swapper_pg_dir[0].pgd =
62 swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
63 } else {
64 efi_bak_pg_dir_pointer[0].pgd =
65 swapper_pg_dir[pgd_index(0)].pgd;
66 efi_bak_pg_dir_pointer[1].pgd =
67 swapper_pg_dir[pgd_index(0x400000)].pgd;
68 swapper_pg_dir[pgd_index(0)].pgd =
69 swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
70 temp = PAGE_OFFSET + 0x400000;
71 swapper_pg_dir[pgd_index(0x400000)].pgd =
72 swapper_pg_dir[pgd_index(temp)].pgd;
73 }
74
75 /*
76 * After the lock is released, the original page table is restored.
77 */
Huang, Ying8b2cb7a2008-01-30 13:32:11 +010078 __flush_tlb_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Rusty Russell4fbb5962007-05-02 19:27:11 +020080 gdt_descr.address = __pa(get_cpu_gdt_table(0));
81 gdt_descr.size = GDT_SIZE - 1;
82 load_gdt(&gdt_descr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Huang, Ying8b2cb7a2008-01-30 13:32:11 +010085void efi_call_phys_epilog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 unsigned long cr4;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010088 struct desc_ptr gdt_descr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Rusty Russell4fbb5962007-05-02 19:27:11 +020090 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
91 gdt_descr.size = GDT_SIZE - 1;
92 load_gdt(&gdt_descr);
James Bottomley2b932f62006-02-24 13:04:14 -080093
David Friese532c062008-08-17 23:03:40 -050094 cr4 = read_cr4_safe();
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Hugh Dickins216705d2008-07-02 22:48:03 +010096 if (cr4 & X86_CR4_PAE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 swapper_pg_dir[pgd_index(0)].pgd =
98 efi_bak_pg_dir_pointer[0].pgd;
99 } else {
100 swapper_pg_dir[pgd_index(0)].pgd =
101 efi_bak_pg_dir_pointer[0].pgd;
102 swapper_pg_dir[pgd_index(0x400000)].pgd =
103 efi_bak_pg_dir_pointer[1].pgd;
104 }
105
106 /*
107 * After the lock is released, the original page table is restored.
108 */
Huang, Ying8b2cb7a2008-01-30 13:32:11 +0100109 __flush_tlb_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 local_irq_restore(efi_rt_eflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}