x86: cleanup tlbflush.h variants
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-x86 / tlbflush_64.h
blob0bed440ba9fe978f06ff1ea869fe38ef2956b6cb
1 #ifndef _X86_TLBFLUSH_H
2 #define _X86_TLBFLUSH_H
4 #include <linux/mm.h>
5 #include <linux/sched.h>
7 #include <asm/processor.h>
8 #include <asm/system.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 write_cr3(read_cr3());
23 static inline void __native_flush_tlb_global(void)
25 unsigned long cr4 = read_cr4();
27 /* clear PGE */
28 write_cr4(cr4 & ~X86_CR4_PGE);
29 /* write old PGE again and flush TLBs */
30 write_cr4(cr4);
33 static inline void __native_flush_tlb_single(unsigned long addr)
35 __asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory");
38 static inline void __flush_tlb_all(void)
40 if (cpu_has_pge)
41 __flush_tlb_global();
42 else
43 __flush_tlb();
46 static inline void __flush_tlb_one(unsigned long addr)
48 if (cpu_has_invlpg)
49 __flush_tlb_single(addr);
50 else
51 __flush_tlb();
55 * TLB flushing:
57 * - flush_tlb() flushes the current mm struct TLBs
58 * - flush_tlb_all() flushes all processes TLBs
59 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
60 * - flush_tlb_page(vma, vmaddr) flushes one page
61 * - flush_tlb_range(vma, start, end) flushes a range of pages
62 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
64 * x86-64 can only flush individual pages or full VMs. For a range flush
65 * we always do the full VM. Might be worth trying if for a small
66 * range a few INVLPGs in a row are a win.
69 #define TLB_FLUSH_ALL -1ULL
71 #ifndef CONFIG_SMP
73 #define flush_tlb() __flush_tlb()
74 #define flush_tlb_all() __flush_tlb_all()
75 #define local_flush_tlb() __flush_tlb()
77 static inline void flush_tlb_mm(struct mm_struct *mm)
79 if (mm == current->active_mm)
80 __flush_tlb();
83 static inline void flush_tlb_page(struct vm_area_struct *vma,
84 unsigned long addr)
86 if (vma->vm_mm == current->active_mm)
87 __flush_tlb_one(addr);
90 static inline void flush_tlb_range(struct vm_area_struct *vma,
91 unsigned long start, unsigned long end)
93 if (vma->vm_mm == current->active_mm)
94 __flush_tlb();
97 static inline void native_flush_tlb_others(const cpumask_t *cpumask,
98 struct mm_struct *mm,
99 unsigned long va)
103 #else /* SMP */
105 #include <asm/smp.h>
107 #define local_flush_tlb() __flush_tlb()
109 extern void flush_tlb_all(void);
110 extern void flush_tlb_current_task(void);
111 extern void flush_tlb_mm(struct mm_struct *);
112 extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
114 #define flush_tlb() flush_tlb_current_task()
116 static inline void flush_tlb_range(struct vm_area_struct *vma,
117 unsigned long start, unsigned long end)
119 flush_tlb_mm(vma->vm_mm);
122 void native_flush_tlb_others(const cpumask_t *cpumask, struct mm_struct *mm,
123 unsigned long va);
125 #define TLBSTATE_OK 1
126 #define TLBSTATE_LAZY 2
128 #endif /* SMP */
130 #ifndef CONFIG_PARAVIRT
131 #define flush_tlb_others(mask, mm, va) native_flush_tlb_others(&mask, mm, va)
132 #endif
134 static inline void flush_tlb_kernel_range(unsigned long start,
135 unsigned long end)
137 flush_tlb_all();
140 #endif /* _X86_TLBFLUSH_H */