x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / x86 / include / asm / tlbflush.h
blobe6d90babc245c1c2713bea64d436fb2a736b83e6
1 #ifndef _ASM_X86_TLBFLUSH_H
2 #define _ASM_X86_TLBFLUSH_H
4 #include <linux/mm.h>
5 #include <linux/sched.h>
7 #include <asm/processor.h>
8 #include <asm/special_insns.h>
10 #ifdef CONFIG_PARAVIRT
11 #include <asm/paravirt.h>
12 #else
13 #define __flush_tlb() __native_flush_tlb()
14 #define __flush_tlb_global() __native_flush_tlb_global()
15 #define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
16 #endif
18 static inline void __native_flush_tlb(void)
20 native_write_cr3(native_read_cr3());
23 static inline void __native_flush_tlb_global_irq_disabled(void)
25 unsigned long cr4;
27 cr4 = native_read_cr4();
28 /* clear PGE */
29 native_write_cr4(cr4 & ~X86_CR4_PGE);
30 /* write old PGE again and flush TLBs */
31 native_write_cr4(cr4);
34 static inline void __native_flush_tlb_global(void)
36 unsigned long flags;
39 * Read-modify-write to CR4 - protect it from preemption and
40 * from interrupts. (Use the raw variant because this code can
41 * be called from deep inside debugging code.)
43 raw_local_irq_save(flags);
45 __native_flush_tlb_global_irq_disabled();
47 raw_local_irq_restore(flags);
50 static inline void __native_flush_tlb_single(unsigned long addr)
52 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
55 static inline void __flush_tlb_all(void)
57 if (cpu_has_pge)
58 __flush_tlb_global();
59 else
60 __flush_tlb();
63 static inline void __flush_tlb_one(unsigned long addr)
65 count_vm_event(NR_TLB_LOCAL_FLUSH_ONE);
66 __flush_tlb_single(addr);
69 #define TLB_FLUSH_ALL -1UL
72 * TLB flushing:
74 * - flush_tlb() flushes the current mm struct TLBs
75 * - flush_tlb_all() flushes all processes TLBs
76 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
77 * - flush_tlb_page(vma, vmaddr) flushes one page
78 * - flush_tlb_range(vma, start, end) flushes a range of pages
79 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
80 * - flush_tlb_others(cpumask, mm, start, end) flushes TLBs on other cpus
82 * ..but the i386 has somewhat limited tlb flushing capabilities,
83 * and page-granular flushes are available only on i486 and up.
86 #ifndef CONFIG_SMP
88 /* "_up" is for UniProcessor.
90 * This is a helper for other header functions. *Not* intended to be called
91 * directly. All global TLB flushes need to either call this, or to bump the
92 * vm statistics themselves.
94 static inline void __flush_tlb_up(void)
96 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL);
97 __flush_tlb();
100 static inline void flush_tlb_all(void)
102 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL);
103 __flush_tlb_all();
106 static inline void flush_tlb(void)
108 __flush_tlb_up();
111 static inline void local_flush_tlb(void)
113 __flush_tlb_up();
116 static inline void flush_tlb_mm(struct mm_struct *mm)
118 if (mm == current->active_mm)
119 __flush_tlb_up();
122 static inline void flush_tlb_page(struct vm_area_struct *vma,
123 unsigned long addr)
125 if (vma->vm_mm == current->active_mm)
126 __flush_tlb_one(addr);
129 static inline void flush_tlb_range(struct vm_area_struct *vma,
130 unsigned long start, unsigned long end)
132 if (vma->vm_mm == current->active_mm)
133 __flush_tlb_up();
136 static inline void flush_tlb_mm_range(struct mm_struct *mm,
137 unsigned long start, unsigned long end, unsigned long vmflag)
139 if (mm == current->active_mm)
140 __flush_tlb_up();
143 static inline void native_flush_tlb_others(const struct cpumask *cpumask,
144 struct mm_struct *mm,
145 unsigned long start,
146 unsigned long end)
150 static inline void reset_lazy_tlbstate(void)
154 static inline void flush_tlb_kernel_range(unsigned long start,
155 unsigned long end)
157 flush_tlb_all();
160 #else /* SMP */
162 #include <asm/smp.h>
164 #define local_flush_tlb() __flush_tlb()
166 #define flush_tlb_mm(mm) flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL)
168 #define flush_tlb_range(vma, start, end) \
169 flush_tlb_mm_range(vma->vm_mm, start, end, vma->vm_flags)
171 extern void flush_tlb_all(void);
172 extern void flush_tlb_current_task(void);
173 extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
174 extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
175 unsigned long end, unsigned long vmflag);
176 extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
178 #define flush_tlb() flush_tlb_current_task()
180 void native_flush_tlb_others(const struct cpumask *cpumask,
181 struct mm_struct *mm,
182 unsigned long start, unsigned long end);
184 #define TLBSTATE_OK 1
185 #define TLBSTATE_LAZY 2
187 struct tlb_state {
188 struct mm_struct *active_mm;
189 int state;
191 DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
193 static inline void reset_lazy_tlbstate(void)
195 this_cpu_write(cpu_tlbstate.state, 0);
196 this_cpu_write(cpu_tlbstate.active_mm, &init_mm);
199 #endif /* SMP */
201 #ifndef CONFIG_PARAVIRT
202 #define flush_tlb_others(mask, mm, start, end) \
203 native_flush_tlb_others(mask, mm, start, end)
204 #endif
206 #endif /* _ASM_X86_TLBFLUSH_H */