blob: afd2c3b039d61879572d38e75f7793762a8f8c16 [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>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * To make EFI call EFI runtime service in physical addressing mode we need
34 * prelog/epilog before/after the invocation to disable interrupt, to
35 * claim EFI runtime service handler exclusively and to duplicate a memory in
36 * low memory space say 0 - 3G.
37 */
38
39static unsigned long efi_rt_eflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static pgd_t efi_bak_pg_dir_pointer[2];
41
Huang, Ying8b2cb7a2008-01-30 13:32:11 +010042void efi_call_phys_prelog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 unsigned long cr4;
45 unsigned long temp;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010046 struct desc_ptr gdt_descr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 local_irq_save(efi_rt_eflags);
49
50 /*
51 * If I don't have PSE, I should just duplicate two entries in page
52 * directory. If I have PSE, I just need to duplicate one entry in
53 * page directory.
54 */
Zachary Amsden4bb0d3e2005-09-03 15:56:36 -070055 cr4 = read_cr4();
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 if (cr4 & X86_CR4_PSE) {
58 efi_bak_pg_dir_pointer[0].pgd =
59 swapper_pg_dir[pgd_index(0)].pgd;
60 swapper_pg_dir[0].pgd =
61 swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
62 } else {
63 efi_bak_pg_dir_pointer[0].pgd =
64 swapper_pg_dir[pgd_index(0)].pgd;
65 efi_bak_pg_dir_pointer[1].pgd =
66 swapper_pg_dir[pgd_index(0x400000)].pgd;
67 swapper_pg_dir[pgd_index(0)].pgd =
68 swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
69 temp = PAGE_OFFSET + 0x400000;
70 swapper_pg_dir[pgd_index(0x400000)].pgd =
71 swapper_pg_dir[pgd_index(temp)].pgd;
72 }
73
74 /*
75 * After the lock is released, the original page table is restored.
76 */
Huang, Ying8b2cb7a2008-01-30 13:32:11 +010077 __flush_tlb_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Rusty Russell4fbb5962007-05-02 19:27:11 +020079 gdt_descr.address = __pa(get_cpu_gdt_table(0));
80 gdt_descr.size = GDT_SIZE - 1;
81 load_gdt(&gdt_descr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Huang, Ying8b2cb7a2008-01-30 13:32:11 +010084void efi_call_phys_epilog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 unsigned long cr4;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010087 struct desc_ptr gdt_descr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Rusty Russell4fbb5962007-05-02 19:27:11 +020089 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
90 gdt_descr.size = GDT_SIZE - 1;
91 load_gdt(&gdt_descr);
James Bottomley2b932f62006-02-24 13:04:14 -080092
Zachary Amsden4bb0d3e2005-09-03 15:56:36 -070093 cr4 = read_cr4();
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 if (cr4 & X86_CR4_PSE) {
96 swapper_pg_dir[pgd_index(0)].pgd =
97 efi_bak_pg_dir_pointer[0].pgd;
98 } else {
99 swapper_pg_dir[pgd_index(0)].pgd =
100 efi_bak_pg_dir_pointer[0].pgd;
101 swapper_pg_dir[pgd_index(0x400000)].pgd =
102 efi_bak_pg_dir_pointer[1].pgd;
103 }
104
105 /*
106 * After the lock is released, the original page table is restored.
107 */
Huang, Ying8b2cb7a2008-01-30 13:32:11 +0100108 __flush_tlb_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 local_irq_restore(efi_rt_eflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*
114 * We need to map the EFI memory map again after paging_init().
115 */
116void __init efi_map_memmap(void)
117{
118 memmap.map = NULL;
119
Matt Tolentino7ae65fd2005-09-03 15:56:27 -0700120 memmap.map = bt_ioremap((unsigned long) memmap.phys_map,
121 (memmap.nr_map * memmap.desc_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (memmap.map == NULL)
Huang, Ying8b2cb7a2008-01-30 13:32:11 +0100123 printk(KERN_ERR "Could not remap the EFI memmap!\n");
Matt Tolentino7ae65fd2005-09-03 15:56:27 -0700124
125 memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}