1 #ifndef __M68K_MMU_CONTEXT_H
2 #define __M68K_MMU_CONTEXT_H
4 #include <asm-generic/mm_hooks.h>
6 static inline void enter_lazy_tlb(struct mm_struct
*mm
, struct task_struct
*tsk
)
12 #if defined(CONFIG_COLDFIRE)
14 #include <asm/atomic.h>
15 #include <asm/bitops.h>
16 #include <asm/mcfmmu.h>
19 #define NO_CONTEXT 256
20 #define LAST_CONTEXT 255
21 #define FIRST_CONTEXT 1
23 extern unsigned long context_map
[];
24 extern mm_context_t next_mmu_context
;
26 extern atomic_t nr_free_contexts
;
27 extern struct mm_struct
*context_mm
[LAST_CONTEXT
+1];
28 extern void steal_context(void);
30 static inline void get_mmu_context(struct mm_struct
*mm
)
34 if (mm
->context
!= NO_CONTEXT
)
36 while (atomic_dec_and_test_lt(&nr_free_contexts
)) {
37 atomic_inc(&nr_free_contexts
);
40 ctx
= next_mmu_context
;
41 while (test_and_set_bit(ctx
, context_map
)) {
42 ctx
= find_next_zero_bit(context_map
, LAST_CONTEXT
+1, ctx
);
43 if (ctx
> LAST_CONTEXT
)
46 next_mmu_context
= (ctx
+ 1) & LAST_CONTEXT
;
52 * Set up the context for a new address space.
54 #define init_new_context(tsk, mm) (((mm)->context = NO_CONTEXT), 0)
57 * We're finished using the context for an address space.
59 static inline void destroy_context(struct mm_struct
*mm
)
61 if (mm
->context
!= NO_CONTEXT
) {
62 clear_bit(mm
->context
, context_map
);
63 mm
->context
= NO_CONTEXT
;
64 atomic_inc(&nr_free_contexts
);
68 static inline void set_context(mm_context_t context
, pgd_t
*pgd
)
70 __asm__
__volatile__ ("movec %0,%%asid" : : "d" (context
));
73 static inline void switch_mm(struct mm_struct
*prev
, struct mm_struct
*next
,
74 struct task_struct
*tsk
)
76 get_mmu_context(tsk
->mm
);
77 set_context(tsk
->mm
->context
, next
->pgd
);
81 * After we have set current->mm to a new value, this activates
82 * the context for the new mm so we see the new mappings.
84 static inline void activate_mm(struct mm_struct
*active_mm
,
88 set_context(mm
->context
, mm
->pgd
);
91 #define deactivate_mm(tsk, mm) do { } while (0)
93 extern void mmu_context_init(void);
94 #define prepare_arch_switch(next) load_ksp_mmu(next)
96 static inline void load_ksp_mmu(struct task_struct
*task
)
106 local_irq_save(flags
);
107 mmuar
= task
->thread
.ksp
;
109 /* Search for a valid TLB entry, if one is found, don't remap */
110 mmu_write(MMUAR
, mmuar
);
111 mmu_write(MMUOR
, MMUOR_STLB
| MMUOR_ADR
);
112 if (mmu_read(MMUSR
) & MMUSR_HIT
)
115 if (mmuar
>= PAGE_OFFSET
) {
118 pr_info("load_ksp_mmu: non-kernel mm found: 0x%p\n", task
->mm
);
125 pgd
= pgd_offset(mm
, mmuar
);
129 pmd
= pmd_offset(pgd
, mmuar
);
133 pte
= (mmuar
>= PAGE_OFFSET
) ? pte_offset_kernel(pmd
, mmuar
)
134 : pte_offset_map(pmd
, mmuar
);
135 if (pte_none(*pte
) || !pte_present(*pte
))
138 set_pte(pte
, pte_mkyoung(*pte
));
139 asid
= mm
->context
& 0xff;
140 if (!pte_dirty(*pte
) && mmuar
<= PAGE_OFFSET
)
141 set_pte(pte
, pte_wrprotect(*pte
));
143 mmu_write(MMUTR
, (mmuar
& PAGE_MASK
) | (asid
<< MMUTR_IDN
) |
144 (((int)(pte
->pte
) & (int)CF_PAGE_MMUTR_MASK
)
145 >> CF_PAGE_MMUTR_SHIFT
) | MMUTR_V
);
147 mmu_write(MMUDR
, (pte_val(*pte
) & PAGE_MASK
) |
148 ((pte
->pte
) & CF_PAGE_MMUDR_MASK
) | MMUDR_SZ_8KB
| MMUDR_X
);
150 mmu_write(MMUOR
, MMUOR_ACC
| MMUOR_UAA
);
155 pr_info("ksp load failed: mm=0x%p ksp=0x08%lx\n", mm
, mmuar
);
157 local_irq_restore(flags
);
160 #elif defined(CONFIG_SUN3)
161 #include <asm/sun3mmu.h>
162 #include <linux/sched.h>
164 extern unsigned long get_free_context(struct mm_struct
*mm
);
165 extern void clear_context(unsigned long context
);
167 /* set the context for a new task to unmapped */
168 static inline int init_new_context(struct task_struct
*tsk
,
169 struct mm_struct
*mm
)
171 mm
->context
= SUN3_INVALID_CONTEXT
;
175 /* find the context given to this process, and if it hasn't already
176 got one, go get one for it. */
177 static inline void get_mmu_context(struct mm_struct
*mm
)
179 if (mm
->context
== SUN3_INVALID_CONTEXT
)
180 mm
->context
= get_free_context(mm
);
183 /* flush context if allocated... */
184 static inline void destroy_context(struct mm_struct
*mm
)
186 if (mm
->context
!= SUN3_INVALID_CONTEXT
)
187 clear_context(mm
->context
);
190 static inline void activate_context(struct mm_struct
*mm
)
193 sun3_put_context(mm
->context
);
196 static inline void switch_mm(struct mm_struct
*prev
, struct mm_struct
*next
,
197 struct task_struct
*tsk
)
199 activate_context(tsk
->mm
);
202 #define deactivate_mm(tsk, mm) do { } while (0)
204 static inline void activate_mm(struct mm_struct
*prev_mm
,
205 struct mm_struct
*next_mm
)
207 activate_context(next_mm
);
212 #include <asm/setup.h>
213 #include <asm/page.h>
214 #include <asm/pgalloc.h>
216 static inline int init_new_context(struct task_struct
*tsk
,
217 struct mm_struct
*mm
)
219 mm
->context
= virt_to_phys(mm
->pgd
);
223 #define destroy_context(mm) do { } while(0)
225 static inline void switch_mm_0230(struct mm_struct
*mm
)
227 unsigned long crp
[2] = {
228 0x80000000 | _PAGE_TABLE
, mm
->context
232 asm volatile (".chip 68030");
234 /* flush MC68030/MC68020 caches (they are virtually addressed) */
239 : "=d" (tmp
) : "di" (FLUSH_I_AND_D
));
241 /* Switch the root pointer. For a 030-only kernel,
242 * avoid flushing the whole ATC, we only need to
243 * flush the user entries. The 68851 does this by
244 * itself. Avoid a runtime check here.
247 #ifdef CPU_M68030_ONLY
255 asm volatile (".chip 68k");
258 static inline void switch_mm_0460(struct mm_struct
*mm
)
260 asm volatile (".chip 68040");
262 /* flush address translation cache (user entries) */
263 asm volatile ("pflushan");
265 /* switch the root pointer */
266 asm volatile ("movec %0,%%urp" : : "r" (mm
->context
));
271 /* clear user entries in the branch cache */
276 : "=d" (tmp
): "di" (0x00200000));
279 asm volatile (".chip 68k");
282 static inline void switch_mm(struct mm_struct
*prev
, struct mm_struct
*next
, struct task_struct
*tsk
)
285 if (CPU_IS_020_OR_030
)
286 switch_mm_0230(next
);
288 switch_mm_0460(next
);
292 #define deactivate_mm(tsk,mm) do { } while (0)
294 static inline void activate_mm(struct mm_struct
*prev_mm
,
295 struct mm_struct
*next_mm
)
297 next_mm
->context
= virt_to_phys(next_mm
->pgd
);
299 if (CPU_IS_020_OR_030
)
300 switch_mm_0230(next_mm
);
302 switch_mm_0460(next_mm
);
307 #else /* !CONFIG_MMU */
309 static inline int init_new_context(struct task_struct
*tsk
, struct mm_struct
*mm
)
315 static inline void switch_mm(struct mm_struct
*prev
, struct mm_struct
*next
, struct task_struct
*tsk
)
319 #define destroy_context(mm) do { } while (0)
320 #define deactivate_mm(tsk,mm) do { } while (0)
322 static inline void activate_mm(struct mm_struct
*prev_mm
, struct mm_struct
*next_mm
)
326 #endif /* CONFIG_MMU */
327 #endif /* __M68K_MMU_CONTEXT_H */