aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/include/asm/efi.h28
-rw-r--r--arch/x86/kernel/tboot.c78
-rw-r--r--arch/x86/mm/init_64.c9
-rw-r--r--arch/x86/mm/ioremap.c105
-rw-r--r--arch/x86/mm/pageattr.c10
-rw-r--r--arch/x86/platform/efi/efi-bgrt.c2
-rw-r--r--arch/x86/platform/efi/efi.c30
-rw-r--r--arch/x86/platform/efi/efi_64.c15
-rw-r--r--arch/x86/realmode/init.c17
9 files changed, 181 insertions, 113 deletions
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 6e8fdf5ad11..fd13815fe85 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -69,23 +69,37 @@ extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
69 efi_call6((void *)(f), (u64)(a1), (u64)(a2), (u64)(a3), \ 69 efi_call6((void *)(f), (u64)(a1), (u64)(a2), (u64)(a3), \
70 (u64)(a4), (u64)(a5), (u64)(a6)) 70 (u64)(a4), (u64)(a5), (u64)(a6))
71 71
72extern unsigned long efi_call_virt_prelog(void);
73extern void efi_call_virt_epilog(unsigned long);
74
75#define efi_callx(x, func, ...) \
76 ({ \
77 efi_status_t __status; \
78 unsigned long __pgd; \
79 \
80 __pgd = efi_call_virt_prelog(); \
81 __status = efi_call##x(func, __VA_ARGS__); \
82 efi_call_virt_epilog(__pgd); \
83 __status; \
84 })
85
72#define efi_call_virt0(f) \ 86#define efi_call_virt0(f) \
73 efi_call0((void *)(efi.systab->runtime->f)) 87 efi_callx(0, (void *)(efi.systab->runtime->f))
74#define efi_call_virt1(f, a1) \ 88#define efi_call_virt1(f, a1) \
75 efi_call1((void *)(efi.systab->runtime->f), (u64)(a1)) 89 efi_callx(1, (void *)(efi.systab->runtime->f), (u64)(a1))
76#define efi_call_virt2(f, a1, a2) \ 90#define efi_call_virt2(f, a1, a2) \
77 efi_call2((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2)) 91 efi_callx(2, (void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2))
78#define efi_call_virt3(f, a1, a2, a3) \ 92#define efi_call_virt3(f, a1, a2, a3) \
79 efi_call3((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ 93 efi_callx(3, (void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \
80 (u64)(a3)) 94 (u64)(a3))
81#define efi_call_virt4(f, a1, a2, a3, a4) \ 95#define efi_call_virt4(f, a1, a2, a3, a4) \
82 efi_call4((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ 96 efi_callx(4, (void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \
83 (u64)(a3), (u64)(a4)) 97 (u64)(a3), (u64)(a4))
84#define efi_call_virt5(f, a1, a2, a3, a4, a5) \ 98#define efi_call_virt5(f, a1, a2, a3, a4, a5) \
85 efi_call5((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ 99 efi_callx(5, (void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \
86 (u64)(a3), (u64)(a4), (u64)(a5)) 100 (u64)(a3), (u64)(a4), (u64)(a5))
87#define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \ 101#define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \
88 efi_call6((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ 102 efi_callx(6, (void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \
89 (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6)) 103 (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6))
90 104
91extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size, 105extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f84fe00fad4..d4f460f962e 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -103,71 +103,13 @@ void __init tboot_probe(void)
103 pr_debug("tboot_size: 0x%x\n", tboot->tboot_size); 103 pr_debug("tboot_size: 0x%x\n", tboot->tboot_size);
104} 104}
105 105
106static pgd_t *tboot_pg_dir;
107static struct mm_struct tboot_mm = {
108 .mm_rb = RB_ROOT,
109 .pgd = swapper_pg_dir,
110 .mm_users = ATOMIC_INIT(2),
111 .mm_count = ATOMIC_INIT(1),
112 .mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem),
113 .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
114 .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
115};
116
117static inline void switch_to_tboot_pt(void) 106static inline void switch_to_tboot_pt(void)
118{ 107{
119 write_cr3(virt_to_phys(tboot_pg_dir)); 108#ifdef CONFIG_X86_32
120} 109 load_cr3(initial_page_table);
121 110#else
122static int map_tboot_page(unsigned long vaddr, unsigned long pfn, 111 write_cr3(real_mode_header->trampoline_pgd);
123 pgprot_t prot) 112#endif
124{
125 pgd_t *pgd;
126 pud_t *pud;
127 pmd_t *pmd;
128 pte_t *pte;
129
130 pgd = pgd_offset(&tboot_mm, vaddr);
131 pud = pud_alloc(&tboot_mm, pgd, vaddr);
132 if (!pud)
133 return -1;
134 pmd = pmd_alloc(&tboot_mm, pud, vaddr);
135 if (!pmd)
136 return -1;
137 pte = pte_alloc_map(&tboot_mm, NULL, pmd, vaddr);
138 if (!pte)
139 return -1;
140 set_pte_at(&tboot_mm, vaddr, pte, pfn_pte(pfn, prot));
141 pte_unmap(pte);
142 return 0;
143}
144
145static int map_tboot_pages(unsigned long vaddr, unsigned long start_pfn,
146 unsigned long nr)
147{
148 /* Reuse the original kernel mapping */
149 tboot_pg_dir = pgd_alloc(&tboot_mm);
150 if (!tboot_pg_dir)
151 return -1;
152
153 for (; nr > 0; nr--, vaddr += PAGE_SIZE, start_pfn++) {
154 if (map_tboot_page(vaddr, start_pfn, PAGE_KERNEL_EXEC))
155 return -1;
156 }
157
158 return 0;
159}
160
161static void tboot_create_trampoline(void)
162{
163 u32 map_base, map_size;
164
165 /* Create identity map for tboot shutdown code. */
166 map_base = PFN_DOWN(tboot->tboot_base);
167 map_size = PFN_UP(tboot->tboot_size);
168 if (map_tboot_pages(map_base << PAGE_SHIFT, map_base, map_size))
169 panic("tboot: Error mapping tboot pages (mfns) @ 0x%x, 0x%x\n",
170 map_base, map_size);
171} 113}
172 114
173#ifdef CONFIG_ACPI_SLEEP 115#ifdef CONFIG_ACPI_SLEEP
@@ -225,14 +167,6 @@ void tboot_shutdown(u32 shutdown_type)
225 if (!tboot_enabled()) 167 if (!tboot_enabled())
226 return; 168 return;
227 169
228 /*
229 * if we're being called before the 1:1 mapping is set up then just
230 * return and let the normal shutdown happen; this should only be
231 * due to very early panic()
232 */
233 if (!tboot_pg_dir)
234 return;
235
236 /* if this is S3 then set regions to MAC */ 170 /* if this is S3 then set regions to MAC */
237 if (shutdown_type == TB_SHUTDOWN_S3) 171 if (shutdown_type == TB_SHUTDOWN_S3)
238 if (tboot_setup_sleep()) 172 if (tboot_setup_sleep())
@@ -343,8 +277,6 @@ static __init int tboot_late_init(void)
343 if (!tboot_enabled()) 277 if (!tboot_enabled())
344 return 0; 278 return 0;
345 279
346 tboot_create_trampoline();
347
348 atomic_set(&ap_wfs_count, 0); 280 atomic_set(&ap_wfs_count, 0);
349 register_hotcpu_notifier(&tboot_cpu_notifier); 281 register_hotcpu_notifier(&tboot_cpu_notifier);
350 282
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 2ead3c8a4c8..07519a12044 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -108,13 +108,13 @@ void sync_global_pgds(unsigned long start, unsigned long end)
108 for (address = start; address <= end; address += PGDIR_SIZE) { 108 for (address = start; address <= end; address += PGDIR_SIZE) {
109 const pgd_t *pgd_ref = pgd_offset_k(address); 109 const pgd_t *pgd_ref = pgd_offset_k(address);
110 struct page *page; 110 struct page *page;
111 pgd_t *pgd;
111 112
112 if (pgd_none(*pgd_ref)) 113 if (pgd_none(*pgd_ref))
113 continue; 114 continue;
114 115
115 spin_lock(&pgd_lock); 116 spin_lock(&pgd_lock);
116 list_for_each_entry(page, &pgd_list, lru) { 117 list_for_each_entry(page, &pgd_list, lru) {
117 pgd_t *pgd;
118 spinlock_t *pgt_lock; 118 spinlock_t *pgt_lock;
119 119
120 pgd = (pgd_t *)page_address(page) + pgd_index(address); 120 pgd = (pgd_t *)page_address(page) + pgd_index(address);
@@ -130,6 +130,13 @@ void sync_global_pgds(unsigned long start, unsigned long end)
130 130
131 spin_unlock(pgt_lock); 131 spin_unlock(pgt_lock);
132 } 132 }
133
134 pgd = __va(real_mode_header->trampoline_pgd);
135 pgd += pgd_index(address);
136
137 if (pgd_none(*pgd))
138 set_pgd(pgd, *pgd_ref);
139
133 spin_unlock(&pgd_lock); 140 spin_unlock(&pgd_lock);
134 } 141 }
135} 142}
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 78fe3f1ac49..e190f7b5665 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -50,6 +50,107 @@ int ioremap_change_attr(unsigned long vaddr, unsigned long size,
50 return err; 50 return err;
51} 51}
52 52
53#ifdef CONFIG_X86_64
54static void ident_pte_range(unsigned long paddr, unsigned long vaddr,
55 pmd_t *ppmd, pmd_t *vpmd, unsigned long end)
56{
57 pte_t *ppte = pte_offset_kernel(ppmd, paddr);
58 pte_t *vpte = pte_offset_kernel(vpmd, vaddr);
59
60 do {
61 set_pte(ppte, *vpte);
62 } while (ppte++, vpte++, vaddr += PAGE_SIZE, vaddr != end);
63}
64
65static int ident_pmd_range(unsigned long paddr, unsigned long vaddr,
66 pud_t *ppud, pud_t *vpud, unsigned long end)
67{
68 pmd_t *ppmd = pmd_offset(ppud, paddr);
69 pmd_t *vpmd = pmd_offset(vpud, vaddr);
70 unsigned long next;
71
72 do {
73 next = pmd_addr_end(vaddr, end);
74
75 if (!pmd_present(*ppmd)) {
76 pte_t *ppte = (pte_t *)get_zeroed_page(GFP_KERNEL);
77 if (!ppte)
78 return 1;
79
80 set_pmd(ppmd, __pmd(_KERNPG_TABLE | __pa(ppte)));
81 }
82
83 ident_pte_range(paddr, vaddr, ppmd, vpmd, next);
84 } while (ppmd++, vpmd++, vaddr = next, vaddr != end);
85
86 return 0;
87}
88
89static int ident_pud_range(unsigned long paddr, unsigned long vaddr,
90 pgd_t *ppgd, pgd_t *vpgd, unsigned long end)
91{
92 pud_t *ppud = pud_offset(ppgd, paddr);
93 pud_t *vpud = pud_offset(vpgd, vaddr);
94 unsigned long next;
95
96 do {
97 next = pud_addr_end(vaddr, end);
98
99 if (!pud_present(*ppud)) {
100 pmd_t *ppmd = (pmd_t *)get_zeroed_page(GFP_KERNEL);
101 if (!ppmd)
102 return 1;
103
104 set_pud(ppud, __pud(_KERNPG_TABLE | __pa(ppmd)));
105 }
106
107 if (ident_pmd_range(paddr, vaddr, ppud, vpud, next))
108 return 1;
109 } while (ppud++, vpud++, vaddr = next, vaddr != end);
110
111 return 0;
112}
113
114static int insert_identity_mapping(resource_size_t paddr, unsigned long vaddr,
115 unsigned long size)
116{
117 unsigned long end = vaddr + size;
118 unsigned long next;
119 pgd_t *vpgd, *ppgd;
120
121 /* Don't map over the guard hole. */
122 if (paddr >= 0x800000000000 || paddr + size > 0x800000000000)
123 return 1;
124
125 ppgd = __va(real_mode_header->trampoline_pgd) + pgd_index(paddr);
126
127 vpgd = pgd_offset_k(vaddr);
128 do {
129 next = pgd_addr_end(vaddr, end);
130
131 if (!pgd_present(*ppgd)) {
132 pud_t *ppud = (pud_t *)get_zeroed_page(GFP_KERNEL);
133 if (!ppud)
134 return 1;
135
136 set_pgd(ppgd, __pgd(_KERNPG_TABLE | __pa(ppud)));
137 }
138
139 if (ident_pud_range(paddr, vaddr, ppgd, vpgd, next))
140 return 1;
141 } while (ppgd++, vpgd++, vaddr = next, vaddr != end);
142
143 return 0;
144}
145#else
146static inline int insert_identity_mapping(resource_size_t paddr,
147 unsigned long vaddr,
148 unsigned long size)
149{
150 return 0;
151}
152#endif /* CONFIG_X86_64 */
153
53/* 154/*
54 * Remap an arbitrary physical address space into the kernel virtual 155 * Remap an arbitrary physical address space into the kernel virtual
55 * address space. Needed when the kernel wants to access high addresses 156 * address space. Needed when the kernel wants to access high addresses
@@ -163,6 +264,10 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
163 ret_addr = (void __iomem *) (vaddr + offset); 264 ret_addr = (void __iomem *) (vaddr + offset);
164 mmiotrace_ioremap(unaligned_phys_addr, unaligned_size, ret_addr); 265 mmiotrace_ioremap(unaligned_phys_addr, unaligned_size, ret_addr);
165 266
267 if (insert_identity_mapping(phys_addr, vaddr, size))
268 printk(KERN_WARNING "ioremap: unable to map 0x%llx in identity pagetable\n",
269 (unsigned long long)phys_addr);
270
166 /* 271 /*
167 * Check if the request spans more than any BAR in the iomem resource 272 * Check if the request spans more than any BAR in the iomem resource
168 * tree. 273 * tree.
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index a718e0d2350..931930a9616 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -919,11 +919,13 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
919 919
920 /* 920 /*
921 * On success we use clflush, when the CPU supports it to 921 * On success we use clflush, when the CPU supports it to
922 * avoid the wbindv. If the CPU does not support it and in the 922 * avoid the wbindv. If the CPU does not support it, in the
923 * error case we fall back to cpa_flush_all (which uses 923 * error case, and during early boot (for EFI) we fall back
924 * wbindv): 924 * to cpa_flush_all (which uses wbinvd):
925 */ 925 */
926 if (!ret && cpu_has_clflush) { 926 if (early_boot_irqs_disabled)
927 __cpa_flush_all((void *)(long)cache);
928 else if (!ret && cpu_has_clflush) {
927 if (cpa.flags & (CPA_PAGES_ARRAY | CPA_ARRAY)) { 929 if (cpa.flags & (CPA_PAGES_ARRAY | CPA_ARRAY)) {
928 cpa_flush_array(addr, numpages, cache, 930 cpa_flush_array(addr, numpages, cache,
929 cpa.flags, pages); 931 cpa.flags, pages);
diff --git a/arch/x86/platform/efi/efi-bgrt.c b/arch/x86/platform/efi/efi-bgrt.c
index f6a0c1b8e51..d9c1b95af17 100644
--- a/arch/x86/platform/efi/efi-bgrt.c
+++ b/arch/x86/platform/efi/efi-bgrt.c
@@ -39,6 +39,8 @@ void efi_bgrt_init(void)
39 if (ACPI_FAILURE(status)) 39 if (ACPI_FAILURE(status))
40 return; 40 return;
41 41
42 if (bgrt_tab->header.length < sizeof(*bgrt_tab))
43 return;
42 if (bgrt_tab->version != 1) 44 if (bgrt_tab->version != 1)
43 return; 45 return;
44 if (bgrt_tab->image_type != 0 || !bgrt_tab->image_address) 46 if (bgrt_tab->image_type != 0 || !bgrt_tab->image_address)
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index ad4439145f8..0a34d9e9c26 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -239,22 +239,7 @@ static efi_status_t __init phys_efi_set_virtual_address_map(
239 return status; 239 return status;
240} 240}
241 241
242static efi_status_t __init phys_efi_get_time(efi_time_t *tm, 242static int efi_set_rtc_mmss(unsigned long nowtime)
243 efi_time_cap_t *tc)
244{
245 unsigned long flags;
246 efi_status_t status;
247
248 spin_lock_irqsave(&rtc_lock, flags);
249 efi_call_phys_prelog();
250 status = efi_call_phys2(efi_phys.get_time, virt_to_phys(tm),
251 virt_to_phys(tc));
252 efi_call_phys_epilog();
253 spin_unlock_irqrestore(&rtc_lock, flags);
254 return status;
255}
256
257int efi_set_rtc_mmss(unsigned long nowtime)
258{ 243{
259 int real_seconds, real_minutes; 244 int real_seconds, real_minutes;
260 efi_status_t status; 245 efi_status_t status;
@@ -283,7 +268,7 @@ int efi_set_rtc_mmss(unsigned long nowtime)
283 return 0; 268 return 0;
284} 269}
285 270
286unsigned long efi_get_time(void) 271static unsigned long efi_get_time(void)
287{ 272{
288 efi_status_t status; 273 efi_status_t status;
289 efi_time_t eft; 274 efi_time_t eft;
@@ -639,18 +624,13 @@ static int __init efi_runtime_init(void)
639 } 624 }
640 /* 625 /*
641 * We will only need *early* access to the following 626 * We will only need *early* access to the following
642 * two EFI runtime services before set_virtual_address_map 627 * EFI runtime service before set_virtual_address_map
643 * is invoked. 628 * is invoked.
644 */ 629 */
645 efi_phys.get_time = (efi_get_time_t *)runtime->get_time;
646 efi_phys.set_virtual_address_map = 630 efi_phys.set_virtual_address_map =
647 (efi_set_virtual_address_map_t *) 631 (efi_set_virtual_address_map_t *)
648 runtime->set_virtual_address_map; 632 runtime->set_virtual_address_map;
649 /* 633
650 * Make efi_get_time can be called before entering
651 * virtual mode.
652 */
653 efi.get_time = phys_efi_get_time;
654 early_iounmap(runtime, sizeof(efi_runtime_services_t)); 634 early_iounmap(runtime, sizeof(efi_runtime_services_t));
655 635
656 return 0; 636 return 0;
@@ -736,12 +716,10 @@ void __init efi_init(void)
736 efi_enabled = 0; 716 efi_enabled = 0;
737 return; 717 return;
738 } 718 }
739#ifdef CONFIG_X86_32
740 if (efi_is_native()) { 719 if (efi_is_native()) {
741 x86_platform.get_wallclock = efi_get_time; 720 x86_platform.get_wallclock = efi_get_time;
742 x86_platform.set_wallclock = efi_set_rtc_mmss; 721 x86_platform.set_wallclock = efi_set_rtc_mmss;
743 } 722 }
744#endif
745 723
746#if EFI_DEBUG 724#if EFI_DEBUG
747 print_efi_memmap(); 725 print_efi_memmap();
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index 95fd505dfeb..06c8b2e662a 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -58,6 +58,21 @@ static void __init early_code_mapping_set_exec(int executable)
58 } 58 }
59} 59}
60 60
61unsigned long efi_call_virt_prelog(void)
62{
63 unsigned long saved;
64
65 saved = read_cr3();
66 write_cr3(real_mode_header->trampoline_pgd);
67
68 return saved;
69}
70
71void efi_call_virt_epilog(unsigned long saved)
72{
73 write_cr3(saved);
74}
75
61void __init efi_call_phys_prelog(void) 76void __init efi_call_phys_prelog(void)
62{ 77{
63 unsigned long vaddress; 78 unsigned long vaddress;
diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
index cbca565af5b..8e6ab613785 100644
--- a/arch/x86/realmode/init.c
+++ b/arch/x86/realmode/init.c
@@ -78,8 +78,21 @@ void __init setup_real_mode(void)
78 *trampoline_cr4_features = read_cr4(); 78 *trampoline_cr4_features = read_cr4();
79 79
80 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd); 80 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
81 trampoline_pgd[0] = __pa(level3_ident_pgt) + _KERNPG_TABLE; 81
82 trampoline_pgd[511] = __pa(level3_kernel_pgt) + _KERNPG_TABLE; 82 /*
83 * Create an identity mapping for all of physical memory.
84 */
85 for (i = 0; i <= pgd_index(max_pfn << PAGE_SHIFT); i++) {
86 int index = pgd_index(PAGE_OFFSET) + i;
87
88 trampoline_pgd[i] = (u64)pgd_val(swapper_pg_dir[index]);
89 }
90
91 /*
92 * Copy the upper-half of the kernel pages tables.
93 */
94 for (i = pgd_index(PAGE_OFFSET); i < PTRS_PER_PGD; i++)
95 trampoline_pgd[i] = (u64)pgd_val(swapper_pg_dir[i]);
83#endif 96#endif
84} 97}
85 98