fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / asm-i386 / tlbflush.h
1 #ifndef _I386_TLBFLUSH_H
2 #define _I386_TLBFLUSH_H
3
4 #include <linux/mm.h>
5 #include <asm/processor.h>
6
7 #ifdef CONFIG_PARAVIRT
8 #include <asm/paravirt.h>
9 #else
10 #define __flush_tlb() __native_flush_tlb()
11 #define __flush_tlb_global() __native_flush_tlb_global()
12 #define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
13 #endif
14
15 #define __native_flush_tlb()                                            \
16         do {                                                            \
17                 unsigned int tmpreg;                                    \
18                                                                         \
19                 __asm__ __volatile__(                                   \
20                         "movl %%cr3, %0;              \n"               \
21                         "movl %0, %%cr3;  # flush TLB \n"               \
22                         : "=r" (tmpreg)                                 \
23                         :: "memory");                                   \
24         } while (0)
25
26 /*
27  * Global pages have to be flushed a bit differently. Not a real
28  * performance problem because this does not happen often.
29  */
30 #define __native_flush_tlb_global()                                     \
31         do {                                                            \
32                 unsigned int tmpreg, cr4, cr4_orig;                     \
33                                                                         \
34                 __asm__ __volatile__(                                   \
35                         "movl %%cr4, %2;  # turn off PGE     \n"        \
36                         "movl %2, %1;                        \n"        \
37                         "andl %3, %1;                        \n"        \
38                         "movl %1, %%cr4;                     \n"        \
39                         "movl %%cr3, %0;                     \n"        \
40                         "movl %0, %%cr3;  # flush TLB        \n"        \
41                         "movl %2, %%cr4;  # turn PGE back on \n"        \
42                         : "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig) \
43                         : "i" (~X86_CR4_PGE)                            \
44                         : "memory");                                    \
45         } while (0)
46
47 #define __native_flush_tlb_single(addr)                                 \
48         __asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory")
49
50 # define __flush_tlb_all()                                              \
51         do {                                                            \
52                 if (cpu_has_pge)                                        \
53                         __flush_tlb_global();                           \
54                 else                                                    \
55                         __flush_tlb();                                  \
56         } while (0)
57
58 #define cpu_has_invlpg  (boot_cpu_data.x86 > 3)
59
60 #ifdef CONFIG_X86_INVLPG
61 # define __flush_tlb_one(addr) __flush_tlb_single(addr)
62 #else
63 # define __flush_tlb_one(addr)                                          \
64         do {                                                            \
65                 if (cpu_has_invlpg)                                     \
66                         __flush_tlb_single(addr);                       \
67                 else                                                    \
68                         __flush_tlb();                                  \
69         } while (0)
70 #endif
71
72 /*
73  * TLB flushing:
74  *
75  *  - flush_tlb() flushes the current mm struct TLBs
76  *  - flush_tlb_all() flushes all processes TLBs
77  *  - flush_tlb_mm(mm) flushes the specified mm context TLB's
78  *  - flush_tlb_page(vma, vmaddr) flushes one page
79  *  - flush_tlb_range(vma, start, end) flushes a range of pages
80  *  - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
81  *  - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
82  *
83  * ..but the i386 has somewhat limited tlb flushing capabilities,
84  * and page-granular flushes are available only on i486 and up.
85  */
86
87 #ifndef CONFIG_SMP
88
89 #define flush_tlb() __flush_tlb()
90 #define flush_tlb_all() __flush_tlb_all()
91 #define local_flush_tlb() __flush_tlb()
92
93 static inline void flush_tlb_mm(struct mm_struct *mm)
94 {
95         if (mm == current->active_mm)
96                 __flush_tlb();
97 }
98
99 static inline void flush_tlb_page(struct vm_area_struct *vma,
100         unsigned long addr)
101 {
102         if (vma->vm_mm == current->active_mm)
103                 __flush_tlb_one(addr);
104 }
105
106 static inline void flush_tlb_range(struct vm_area_struct *vma,
107         unsigned long start, unsigned long end)
108 {
109         if (vma->vm_mm == current->active_mm)
110                 __flush_tlb();
111 }
112
113 #else
114
115 #include <asm/smp.h>
116
117 #define local_flush_tlb() \
118         __flush_tlb()
119
120 extern void flush_tlb_all(void);
121 extern void flush_tlb_current_task(void);
122 extern void flush_tlb_mm(struct mm_struct *);
123 extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
124
125 #define flush_tlb()     flush_tlb_current_task()
126
127 static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long start, unsigned long end)
128 {
129         flush_tlb_mm(vma->vm_mm);
130 }
131
132 #define TLBSTATE_OK     1
133 #define TLBSTATE_LAZY   2
134
135 struct tlb_state
136 {
137         struct mm_struct *active_mm;
138         int state;
139         char __cacheline_padding[L1_CACHE_BYTES-8];
140 };
141 DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate);
142
143
144 #endif
145
146 #define flush_tlb_kernel_range(start, end) flush_tlb_all()
147
148 static inline void flush_tlb_pgtables(struct mm_struct *mm,
149                                       unsigned long start, unsigned long end)
150 {
151         /* i386 does not keep any page table caches in TLB */
152 }
153
154 #endif /* _I386_TLBFLUSH_H */