patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-m68k / tlbflush.h
1 #ifndef _M68K_TLBFLUSH_H
2 #define _M68K_TLBFLUSH_H
3
4 #ifndef CONFIG_SUN3
5
6 #include <asm/current.h>
7
8 static inline void flush_tlb_kernel_page(void *addr)
9 {
10         if (CPU_IS_040_OR_060) {
11                 mm_segment_t old_fs = get_fs();
12                 set_fs(KERNEL_DS);
13                 __asm__ __volatile__(".chip 68040\n\t"
14                                      "pflush (%0)\n\t"
15                                      ".chip 68k"
16                                      : : "a" (addr));
17                 set_fs(old_fs);
18         } else
19                 __asm__ __volatile__("pflush #4,#4,(%0)" : : "a" (addr));
20 }
21
22 /*
23  * flush all user-space atc entries.
24  */
25 static inline void __flush_tlb(void)
26 {
27         if (CPU_IS_040_OR_060)
28                 __asm__ __volatile__(".chip 68040\n\t"
29                                      "pflushan\n\t"
30                                      ".chip 68k");
31         else
32                 __asm__ __volatile__("pflush #0,#4");
33 }
34
35 static inline void __flush_tlb040_one(unsigned long addr)
36 {
37         __asm__ __volatile__(".chip 68040\n\t"
38                              "pflush (%0)\n\t"
39                              ".chip 68k"
40                              : : "a" (addr));
41 }
42
43 static inline void __flush_tlb_one(unsigned long addr)
44 {
45         if (CPU_IS_040_OR_060)
46                 __flush_tlb040_one(addr);
47         else
48                 __asm__ __volatile__("pflush #0,#4,(%0)" : : "a" (addr));
49 }
50
51 #define flush_tlb() __flush_tlb()
52
53 /*
54  * flush all atc entries (both kernel and user-space entries).
55  */
56 static inline void flush_tlb_all(void)
57 {
58         if (CPU_IS_040_OR_060)
59                 __asm__ __volatile__(".chip 68040\n\t"
60                                      "pflusha\n\t"
61                                      ".chip 68k");
62         else
63                 __asm__ __volatile__("pflusha");
64 }
65
66 static inline void flush_tlb_mm(struct mm_struct *mm)
67 {
68         if (mm == current->active_mm)
69                 __flush_tlb();
70 }
71
72 static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
73 {
74         if (vma->vm_mm == current->active_mm) {
75                 mm_segment_t old_fs = get_fs();
76                 set_fs(USER_DS);
77                 __flush_tlb_one(addr);
78                 set_fs(old_fs);
79         }
80 }
81
82 static inline void flush_tlb_range(struct vm_area_struct *vma,
83                                    unsigned long start, unsigned long end)
84 {
85         if (vma->vm_mm == current->active_mm)
86                 __flush_tlb();
87 }
88
89 static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
90 {
91         flush_tlb_all();
92 }
93
94 static inline void flush_tlb_pgtables(struct mm_struct *mm,
95                                       unsigned long start, unsigned long end)
96 {
97 }
98
99 #else
100
101
102 /* Reserved PMEGs. */
103 extern char sun3_reserved_pmeg[SUN3_PMEGS_NUM];
104 extern unsigned long pmeg_vaddr[SUN3_PMEGS_NUM];
105 extern unsigned char pmeg_alloc[SUN3_PMEGS_NUM];
106 extern unsigned char pmeg_ctx[SUN3_PMEGS_NUM];
107
108 /* Flush all userspace mappings one by one...  (why no flush command,
109    sun?) */
110 static inline void flush_tlb_all(void)
111 {
112        unsigned long addr;
113        unsigned char ctx, oldctx;
114
115        oldctx = sun3_get_context();
116        for(addr = 0x00000000; addr < TASK_SIZE; addr += SUN3_PMEG_SIZE) {
117                for(ctx = 0; ctx < 8; ctx++) {
118                        sun3_put_context(ctx);
119                        sun3_put_segmap(addr, SUN3_INVALID_PMEG);
120                }
121        }
122
123        sun3_put_context(oldctx);
124        /* erase all of the userspace pmeg maps, we've clobbered them
125           all anyway */
126        for(addr = 0; addr < SUN3_INVALID_PMEG; addr++) {
127                if(pmeg_alloc[addr] == 1) {
128                        pmeg_alloc[addr] = 0;
129                        pmeg_ctx[addr] = 0;
130                        pmeg_vaddr[addr] = 0;
131                }
132        }
133
134 }
135
136 /* Clear user TLB entries within the context named in mm */
137 static inline void flush_tlb_mm (struct mm_struct *mm)
138 {
139      unsigned char oldctx;
140      unsigned char seg;
141      unsigned long i;
142
143      oldctx = sun3_get_context();
144      sun3_put_context(mm->context);
145
146      for(i = 0; i < TASK_SIZE; i += SUN3_PMEG_SIZE) {
147              seg = sun3_get_segmap(i);
148              if(seg == SUN3_INVALID_PMEG)
149                      continue;
150
151              sun3_put_segmap(i, SUN3_INVALID_PMEG);
152              pmeg_alloc[seg] = 0;
153              pmeg_ctx[seg] = 0;
154              pmeg_vaddr[seg] = 0;
155      }
156
157      sun3_put_context(oldctx);
158
159 }
160
161 /* Flush a single TLB page. In this case, we're limited to flushing a
162    single PMEG */
163 static inline void flush_tlb_page (struct vm_area_struct *vma,
164                                    unsigned long addr)
165 {
166         unsigned char oldctx;
167         unsigned char i;
168
169         oldctx = sun3_get_context();
170         sun3_put_context(vma->vm_mm->context);
171         addr &= ~SUN3_PMEG_MASK;
172         if((i = sun3_get_segmap(addr)) != SUN3_INVALID_PMEG)
173         {
174                 pmeg_alloc[i] = 0;
175                 pmeg_ctx[i] = 0;
176                 pmeg_vaddr[i] = 0;
177                 sun3_put_segmap (addr,  SUN3_INVALID_PMEG);
178         }
179         sun3_put_context(oldctx);
180
181 }
182 /* Flush a range of pages from TLB. */
183
184 static inline void flush_tlb_range (struct vm_area_struct *vma,
185                       unsigned long start, unsigned long end)
186 {
187         struct mm_struct *mm = vma->vm_mm;
188         unsigned char seg, oldctx;
189
190         start &= ~SUN3_PMEG_MASK;
191
192         oldctx = sun3_get_context();
193         sun3_put_context(mm->context);
194
195         while(start < end)
196         {
197                 if((seg = sun3_get_segmap(start)) == SUN3_INVALID_PMEG)
198                      goto next;
199                 if(pmeg_ctx[seg] == mm->context) {
200                         pmeg_alloc[seg] = 0;
201                         pmeg_ctx[seg] = 0;
202                         pmeg_vaddr[seg] = 0;
203                 }
204                 sun3_put_segmap(start, SUN3_INVALID_PMEG);
205         next:
206                 start += SUN3_PMEG_SIZE;
207         }
208 }
209
210 static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
211 {
212         flush_tlb_all();
213 }
214
215 /* Flush kernel page from TLB. */
216 static inline void flush_tlb_kernel_page (unsigned long addr)
217 {
218         sun3_put_segmap (addr & ~(SUN3_PMEG_SIZE - 1), SUN3_INVALID_PMEG);
219 }
220
221 static inline void flush_tlb_pgtables(struct mm_struct *mm,
222                                       unsigned long start, unsigned long end)
223 {
224 }
225
226 #endif
227
228 #endif /* _M68K_TLBFLUSH_H */