Commit | Line | Data |
---|---|---|
1965aae3 PA |
1 | #ifndef _ASM_X86_TLBFLUSH_H |
2 | #define _ASM_X86_TLBFLUSH_H | |
d291cf83 TG |
3 | |
4 | #include <linux/mm.h> | |
5 | #include <linux/sched.h> | |
6 | ||
7 | #include <asm/processor.h> | |
f05e798a | 8 | #include <asm/special_insns.h> |
d291cf83 TG |
9 | |
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 | |
17 | ||
18 | static inline void __native_flush_tlb(void) | |
19 | { | |
d7285c6b | 20 | native_write_cr3(native_read_cr3()); |
d291cf83 TG |
21 | } |
22 | ||
23 | static inline void __native_flush_tlb_global(void) | |
24 | { | |
b1979a5f IM |
25 | unsigned long flags; |
26 | unsigned long cr4; | |
d291cf83 | 27 | |
b1979a5f IM |
28 | /* |
29 | * Read-modify-write to CR4 - protect it from preemption and | |
30 | * from interrupts. (Use the raw variant because this code can | |
31 | * be called from deep inside debugging code.) | |
32 | */ | |
33 | raw_local_irq_save(flags); | |
34 | ||
d7285c6b | 35 | cr4 = native_read_cr4(); |
d291cf83 | 36 | /* clear PGE */ |
d7285c6b | 37 | native_write_cr4(cr4 & ~X86_CR4_PGE); |
d291cf83 | 38 | /* write old PGE again and flush TLBs */ |
d7285c6b | 39 | native_write_cr4(cr4); |
b1979a5f IM |
40 | |
41 | raw_local_irq_restore(flags); | |
d291cf83 TG |
42 | } |
43 | ||
44 | static inline void __native_flush_tlb_single(unsigned long addr) | |
45 | { | |
94cf8de0 | 46 | asm volatile("invlpg (%0)" ::"r" (addr) : "memory"); |
d291cf83 TG |
47 | } |
48 | ||
49 | static inline void __flush_tlb_all(void) | |
50 | { | |
51 | if (cpu_has_pge) | |
52 | __flush_tlb_global(); | |
53 | else | |
54 | __flush_tlb(); | |
55 | } | |
56 | ||
57 | static inline void __flush_tlb_one(unsigned long addr) | |
58 | { | |
59 | if (cpu_has_invlpg) | |
60 | __flush_tlb_single(addr); | |
61 | else | |
62 | __flush_tlb(); | |
63 | } | |
64 | ||
3e7f3db0 | 65 | #define TLB_FLUSH_ALL -1UL |
d291cf83 TG |
66 | |
67 | /* | |
68 | * TLB flushing: | |
69 | * | |
70 | * - flush_tlb() flushes the current mm struct TLBs | |
71 | * - flush_tlb_all() flushes all processes TLBs | |
72 | * - flush_tlb_mm(mm) flushes the specified mm context TLB's | |
73 | * - flush_tlb_page(vma, vmaddr) flushes one page | |
74 | * - flush_tlb_range(vma, start, end) flushes a range of pages | |
75 | * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages | |
e7b52ffd | 76 | * - flush_tlb_others(cpumask, mm, start, end) flushes TLBs on other cpus |
d291cf83 TG |
77 | * |
78 | * ..but the i386 has somewhat limited tlb flushing capabilities, | |
79 | * and page-granular flushes are available only on i486 and up. | |
d291cf83 TG |
80 | */ |
81 | ||
82 | #ifndef CONFIG_SMP | |
83 | ||
84 | #define flush_tlb() __flush_tlb() | |
85 | #define flush_tlb_all() __flush_tlb_all() | |
86 | #define local_flush_tlb() __flush_tlb() | |
87 | ||
88 | static inline void flush_tlb_mm(struct mm_struct *mm) | |
89 | { | |
90 | if (mm == current->active_mm) | |
91 | __flush_tlb(); | |
92 | } | |
93 | ||
94 | static inline void flush_tlb_page(struct vm_area_struct *vma, | |
95 | unsigned long addr) | |
96 | { | |
97 | if (vma->vm_mm == current->active_mm) | |
98 | __flush_tlb_one(addr); | |
99 | } | |
100 | ||
101 | static inline void flush_tlb_range(struct vm_area_struct *vma, | |
102 | unsigned long start, unsigned long end) | |
103 | { | |
104 | if (vma->vm_mm == current->active_mm) | |
105 | __flush_tlb(); | |
106 | } | |
107 | ||
611ae8e3 AS |
108 | static inline void flush_tlb_mm_range(struct vm_area_struct *vma, |
109 | unsigned long start, unsigned long end, unsigned long vmflag) | |
110 | { | |
111 | if (vma->vm_mm == current->active_mm) | |
112 | __flush_tlb(); | |
113 | } | |
114 | ||
4595f962 | 115 | static inline void native_flush_tlb_others(const struct cpumask *cpumask, |
d291cf83 | 116 | struct mm_struct *mm, |
e7b52ffd AS |
117 | unsigned long start, |
118 | unsigned long end) | |
d291cf83 TG |
119 | { |
120 | } | |
121 | ||
913da64b AN |
122 | static inline void reset_lazy_tlbstate(void) |
123 | { | |
124 | } | |
125 | ||
effee4b9 AS |
126 | static inline void flush_tlb_kernel_range(unsigned long start, |
127 | unsigned long end) | |
128 | { | |
129 | flush_tlb_all(); | |
130 | } | |
131 | ||
d291cf83 TG |
132 | #else /* SMP */ |
133 | ||
134 | #include <asm/smp.h> | |
135 | ||
136 | #define local_flush_tlb() __flush_tlb() | |
137 | ||
611ae8e3 AS |
138 | #define flush_tlb_mm(mm) flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL) |
139 | ||
140 | #define flush_tlb_range(vma, start, end) \ | |
141 | flush_tlb_mm_range(vma->vm_mm, start, end, vma->vm_flags) | |
142 | ||
d291cf83 TG |
143 | extern void flush_tlb_all(void); |
144 | extern void flush_tlb_current_task(void); | |
d291cf83 | 145 | extern void flush_tlb_page(struct vm_area_struct *, unsigned long); |
611ae8e3 AS |
146 | extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, |
147 | unsigned long end, unsigned long vmflag); | |
effee4b9 | 148 | extern void flush_tlb_kernel_range(unsigned long start, unsigned long end); |
d291cf83 TG |
149 | |
150 | #define flush_tlb() flush_tlb_current_task() | |
151 | ||
4595f962 | 152 | void native_flush_tlb_others(const struct cpumask *cpumask, |
e7b52ffd AS |
153 | struct mm_struct *mm, |
154 | unsigned long start, unsigned long end); | |
d291cf83 TG |
155 | |
156 | #define TLBSTATE_OK 1 | |
157 | #define TLBSTATE_LAZY 2 | |
158 | ||
94cf8de0 | 159 | struct tlb_state { |
d291cf83 TG |
160 | struct mm_struct *active_mm; |
161 | int state; | |
d291cf83 | 162 | }; |
9b8de747 | 163 | DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate); |
913da64b | 164 | |
913da64b AN |
165 | static inline void reset_lazy_tlbstate(void) |
166 | { | |
c6ae41e7 AS |
167 | this_cpu_write(cpu_tlbstate.state, 0); |
168 | this_cpu_write(cpu_tlbstate.active_mm, &init_mm); | |
913da64b | 169 | } |
d291cf83 TG |
170 | |
171 | #endif /* SMP */ | |
172 | ||
173 | #ifndef CONFIG_PARAVIRT | |
e7b52ffd AS |
174 | #define flush_tlb_others(mask, mm, start, end) \ |
175 | native_flush_tlb_others(mask, mm, start, end) | |
96a388de | 176 | #endif |
d291cf83 | 177 | |
1965aae3 | 178 | #endif /* _ASM_X86_TLBFLUSH_H */ |