]> rtime.felk.cvut.cz Git - mcf548x/linux.git/blob - arch/m68k/include/asm/mmu_context.h
Various compilation fixes.
[mcf548x/linux.git] / arch / m68k / include / asm / mmu_context.h
1 #ifndef __M68K_MMU_CONTEXT_H
2 #define __M68K_MMU_CONTEXT_H
3
4 #include <asm-generic/mm_hooks.h>
5
6 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
7 {
8 }
9
10 #ifdef CONFIG_MMU
11 #if !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE)
12
13 #include <asm/setup.h>
14 #include <asm/page.h>
15 #include <asm/pgalloc.h>
16
17 static inline int init_new_context(struct task_struct *tsk,
18                                    struct mm_struct *mm)
19 {
20         mm->context = virt_to_phys(mm->pgd);
21         return 0;
22 }
23
24 #define destroy_context(mm)             do { } while(0)
25
26 static inline void switch_mm_0230(struct mm_struct *mm)
27 {
28         unsigned long crp[2] = {
29                 0x80000000 | _PAGE_TABLE, mm->context
30         };
31         unsigned long tmp;
32
33         asm volatile (".chip 68030");
34
35         /* flush MC68030/MC68020 caches (they are virtually addressed) */
36         asm volatile (
37                 "movec %%cacr,%0;"
38                 "orw %1,%0; "
39                 "movec %0,%%cacr"
40                 : "=d" (tmp) : "di" (FLUSH_I_AND_D));
41
42         /* Switch the root pointer. For a 030-only kernel,
43          * avoid flushing the whole ATC, we only need to
44          * flush the user entries. The 68851 does this by
45          * itself. Avoid a runtime check here.
46          */
47         asm volatile (
48 #ifdef CPU_M68030_ONLY
49                 "pmovefd %0,%%crp; "
50                 "pflush #0,#4"
51 #else
52                 "pmove %0,%%crp"
53 #endif
54                 : : "m" (crp[0]));
55
56         asm volatile (".chip 68k");
57 }
58
59 static inline void switch_mm_0460(struct mm_struct *mm)
60 {
61         asm volatile (".chip 68040");
62
63         /* flush address translation cache (user entries) */
64         asm volatile ("pflushan");
65
66         /* switch the root pointer */
67         asm volatile ("movec %0,%%urp" : : "r" (mm->context));
68
69         if (CPU_IS_060) {
70                 unsigned long tmp;
71
72                 /* clear user entries in the branch cache */
73                 asm volatile (
74                         "movec %%cacr,%0; "
75                         "orl %1,%0; "
76                         "movec %0,%%cacr"
77                         : "=d" (tmp): "di" (0x00200000));
78         }
79
80         asm volatile (".chip 68k");
81 }
82
83 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk)
84 {
85         if (prev != next) {
86                 if (CPU_IS_020_OR_030)
87                         switch_mm_0230(next);
88                 else
89                         switch_mm_0460(next);
90         }
91 }
92
93 #define deactivate_mm(tsk,mm)   do { } while (0)
94
95 static inline void activate_mm(struct mm_struct *prev_mm,
96                                struct mm_struct *next_mm)
97 {
98         next_mm->context = virt_to_phys(next_mm->pgd);
99
100         if (CPU_IS_020_OR_030)
101                 switch_mm_0230(next_mm);
102         else
103                 switch_mm_0460(next_mm);
104 }
105
106 #elif defined(CONFIG_SUN3)
107 #include <asm/sun3mmu.h>
108 #include <linux/sched.h>
109
110 extern unsigned long get_free_context(struct mm_struct *mm);
111 extern void clear_context(unsigned long context);
112
113 /* set the context for a new task to unmapped */
114 static inline int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
115 {
116         mm->context = SUN3_INVALID_CONTEXT;
117         return 0;
118 }
119
120 /* find the context given to this process, and if it hasn't already
121    got one, go get one for it. */
122 static inline void get_mmu_context(struct mm_struct *mm)
123 {
124         if(mm->context == SUN3_INVALID_CONTEXT)
125                 mm->context = get_free_context(mm);
126 }
127
128 /* flush context if allocated... */
129 static inline void destroy_context(struct mm_struct *mm)
130 {
131         if(mm->context != SUN3_INVALID_CONTEXT)
132                 clear_context(mm->context);
133 }
134
135 static inline void activate_context(struct mm_struct *mm)
136 {
137         get_mmu_context(mm);
138         sun3_put_context(mm->context);
139 }
140
141 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk)
142 {
143         activate_context(tsk->mm);
144 }
145
146 #define deactivate_mm(tsk,mm)   do { } while (0)
147
148 static inline void activate_mm(struct mm_struct *prev_mm,
149                                struct mm_struct *next_mm)
150 {
151         activate_context(next_mm);
152 }
153
154 #else /* CONFIG_COLDFIRE */
155
156 #include <asm/coldfire.h>
157 #include <asm/atomic.h>
158 #include <asm/bitops.h>
159 #include <asm/mmu.h>
160
161 #define NO_CONTEXT              256
162 #define LAST_CONTEXT            255
163 #define FIRST_CONTEXT           1
164
165 extern void set_context(mm_context_t context, pgd_t *pgd);
166 extern unsigned long context_map[];
167 extern mm_context_t next_mmu_context;
168
169 extern atomic_t nr_free_contexts;
170 extern struct mm_struct *context_mm[LAST_CONTEXT+1];
171 extern void steal_context(void);
172
173 static inline void get_mmu_context(struct mm_struct *mm)
174 {
175         mm_context_t ctx;
176
177         if (mm->context != NO_CONTEXT)
178                 return;
179         while (atomic_dec_and_test_lt(&nr_free_contexts)) {
180                 atomic_inc(&nr_free_contexts);
181                 steal_context();
182         }
183         ctx = next_mmu_context;
184         while (test_and_set_bit(ctx, context_map)) {
185                 ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);
186                 if (ctx > LAST_CONTEXT)
187                         ctx = 0;
188         }
189         next_mmu_context = (ctx + 1) & LAST_CONTEXT;
190         mm->context = ctx;
191         context_mm[ctx] = mm;
192 }
193
194 /*
195  * Set up the context for a new address space.
196  */
197 #define init_new_context(tsk, mm)       (((mm)->context = NO_CONTEXT), 0)
198
199 /*
200  * We're finished using the context for an address space.
201  */
202 static inline void destroy_context(struct mm_struct *mm)
203 {
204         if (mm->context != NO_CONTEXT) {
205                 clear_bit(mm->context, context_map);
206                 mm->context = NO_CONTEXT;
207                 atomic_inc(&nr_free_contexts);
208         }
209 }
210
211 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
212         struct task_struct *tsk)
213 {
214         get_mmu_context(tsk->mm);
215         set_context(tsk->mm->context, next->pgd);
216 }
217
218 /*
219  * After we have set current->mm to a new value, this activates
220  * the context for the new mm so we see the new mappings.
221  */
222 static inline void activate_mm(struct mm_struct *active_mm,
223         struct mm_struct *mm)
224 {
225         get_mmu_context(mm);
226         set_context(mm->context, mm->pgd);
227 }
228
229 #define deactivate_mm(tsk, mm) do { } while (0)
230
231 extern void mmu_context_init(void);
232 #ifdef CONFIG_M547X_8X
233 #define prepare_arch_switch(next) load_ksp_mmu(next)
234
235 //FIXME: Don't use TLB here for kernel stacks
236
237 static inline void load_ksp_mmu(struct task_struct *task)
238 {
239         int flags;
240         struct mm_struct *mm;
241         int asid;
242         pgd_t *pgd;
243         pmd_t *pmd;
244         pte_t *pte;
245         unsigned long mmuar;
246
247         local_irq_save(flags);
248         mmuar = task->thread.ksp;
249
250         /* Search for a valid TLB entry, if one is found, don't remap */
251         *MMUAR = mmuar;
252         *MMUOR = MMUOR_STLB | MMUOR_ADR;
253         
254         //better wait
255         asm ("nop");
256         
257         if ((*MMUSR) & MMUSR_HIT)
258                 goto end;
259
260         if (mmuar >= PAGE_OFFSET) {
261                 mm = &init_mm;
262         } else {
263                 printk ("load_ksp_mmu: non-kernel mm found: 0x%08x\n", (unsigned int) task->mm);
264                 mm = task->mm;
265         }
266
267         if (!mm)
268             goto bug;
269
270         pgd = pgd_offset(mm, mmuar);
271         if (pgd_none(*pgd))
272             goto bug;
273             
274         pmd = pmd_offset(pgd, mmuar);
275         if (pmd_none(*pmd))
276             goto bug;
277         
278         pte = (mmuar >= PAGE_OFFSET) ? pte_offset_kernel(pmd, mmuar)
279                                      : pte_offset_map(pmd, mmuar);
280         if (pte_none(*pte) || !pte_present(*pte))
281             goto bug;
282
283         set_pte(pte, pte_mkyoung(*pte));
284         asid = mm->context & 0xff;
285         if (!pte_dirty(*pte) && mmuar<=PAGE_OFFSET)
286             set_pte(pte, pte_wrprotect(*pte));
287
288         *MMUTR = (mmuar & PAGE_MASK) | (asid << CF_ASID_MMU_SHIFT)
289                | (((int)(pte->pte) & (int)CF_PAGE_MMUTR_MASK ) >> CF_PAGE_MMUTR_SHIFT)
290                | MMUTR_V;
291
292         *MMUDR = (pte_val(*pte) & PAGE_MASK) 
293                | ((pte->pte) & CF_PAGE_MMUDR_MASK)
294                | MMUDR_SZ8K | MMUDR_X;
295             
296         *MMUOR = MMUOR_ACC | MMUOR_UAA;
297         asm ("nop");
298
299         goto end;
300
301 bug:
302         printk ("ksp load failed: mm=0x%08x ksp=0x%08x\n", (unsigned int) mm, (unsigned int) mmuar);
303
304 end:
305         local_irq_restore(flags);
306 }
307
308 #endif /* CONFIG_M547X_8X */
309
310 #endif /* CONFIG_COLDFIRE */
311
312 #else /* !CONFIG_MMU */
313
314 static inline int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
315 {
316         return 0;
317 }
318
319
320 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk)
321 {
322 }
323
324 #define destroy_context(mm)     do { } while (0)
325 #define deactivate_mm(tsk,mm)   do { } while (0)
326
327 static inline void activate_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm)
328 {
329 }
330
331 #endif /* CONFIG_MMU */
332 #endif /* __M68K_MMU_CONTEXT_H */