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>
30 #include <linux/slab.h>
32 #include <asm/setup.h>
35 #include <asm/pgtable.h>
36 #include <asm/tlbflush.h>
37 #include <asm/proto.h>
39 #include <asm/cacheflush.h>
40 #include <asm/fixmap.h>
42 static pgd_t
*save_pgd __initdata
;
43 static unsigned long efi_flags __initdata
;
45 static void __init
early_code_mapping_set_exec(int executable
)
47 efi_memory_desc_t
*md
;
50 if (!(__supported_pte_mask
& _PAGE_NX
))
53 /* Make EFI service code area executable */
54 for (p
= memmap
.map
; p
< memmap
.map_end
; p
+= memmap
.desc_size
) {
56 if (md
->type
== EFI_RUNTIME_SERVICES_CODE
||
57 md
->type
== EFI_BOOT_SERVICES_CODE
)
58 efi_set_executable(md
, executable
);
62 void __init
efi_call_phys_prelog(void)
64 unsigned long vaddress
;
68 early_code_mapping_set_exec(1);
69 local_irq_save(efi_flags
);
71 n_pgds
= DIV_ROUND_UP((max_pfn
<< PAGE_SHIFT
), PGDIR_SIZE
);
72 save_pgd
= kmalloc(n_pgds
* sizeof(pgd_t
), GFP_KERNEL
);
74 for (pgd
= 0; pgd
< n_pgds
; pgd
++) {
75 save_pgd
[pgd
] = *pgd_offset_k(pgd
* PGDIR_SIZE
);
76 vaddress
= (unsigned long)__va(pgd
* PGDIR_SIZE
);
77 set_pgd(pgd_offset_k(pgd
* PGDIR_SIZE
), *pgd_offset_k(vaddress
));
82 void __init
efi_call_phys_epilog(void)
85 * After the lock is released, the original page table is restored.
88 int n_pgds
= DIV_ROUND_UP((max_pfn
<< PAGE_SHIFT
) , PGDIR_SIZE
);
89 for (pgd
= 0; pgd
< n_pgds
; pgd
++)
90 set_pgd(pgd_offset_k(pgd
* PGDIR_SIZE
), save_pgd
[pgd
]);
93 local_irq_restore(efi_flags
);
94 early_code_mapping_set_exec(0);
97 void __iomem
*__init
efi_ioremap(unsigned long phys_addr
, unsigned long size
,
98 u32 type
, u64 attribute
)
100 unsigned long last_map_pfn
;
102 if (type
== EFI_MEMORY_MAPPED_IO
)
103 return ioremap(phys_addr
, size
);
105 last_map_pfn
= init_memory_mapping(phys_addr
, phys_addr
+ size
);
106 if ((last_map_pfn
<< PAGE_SHIFT
) < phys_addr
+ size
) {
107 unsigned long top
= last_map_pfn
<< PAGE_SHIFT
;
108 efi_ioremap(top
, size
- (top
- phys_addr
), type
, attribute
);
111 if (!(attribute
& EFI_MEMORY_WB
))
112 efi_memory_uc((u64
)(unsigned long)__va(phys_addr
), size
);
114 return (void __iomem
*)__va(phys_addr
);