1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _M68K_TLBFLUSH_H
3 #define _M68K_TLBFLUSH_H
8 #include <asm/current.h>
9 #include <asm/mcfmmu.h>
11 static inline void flush_tlb_kernel_page(void *addr)
13 if (CPU_IS_COLDFIRE) {
14 mmu_write(MMUOR, MMUOR_CNL);
15 } else if (CPU_IS_040_OR_060) {
17 __asm__ __volatile__(".chip 68040\n\t"
22 } else if (CPU_IS_020_OR_030)
23 __asm__ __volatile__("pflush #4,#4,(%0)" : : "a" (addr));
27 * flush all user-space atc entries.
29 static inline void __flush_tlb(void)
31 if (CPU_IS_COLDFIRE) {
32 mmu_write(MMUOR, MMUOR_CNL);
33 } else if (CPU_IS_040_OR_060) {
34 __asm__ __volatile__(".chip 68040\n\t"
37 } else if (CPU_IS_020_OR_030) {
38 __asm__ __volatile__("pflush #0,#4");
42 static inline void __flush_tlb040_one(unsigned long addr)
44 __asm__ __volatile__(".chip 68040\n\t"
50 static inline void __flush_tlb_one(unsigned long addr)
53 mmu_write(MMUOR, MMUOR_CNL);
54 else if (CPU_IS_040_OR_060)
55 __flush_tlb040_one(addr);
56 else if (CPU_IS_020_OR_030)
57 __asm__ __volatile__("pflush #0,#4,(%0)" : : "a" (addr));
60 #define flush_tlb() __flush_tlb()
63 * flush all atc entries (both kernel and user-space entries).
65 static inline void flush_tlb_all(void)
67 if (CPU_IS_COLDFIRE) {
68 mmu_write(MMUOR, MMUOR_CNL);
69 } else if (CPU_IS_040_OR_060) {
70 __asm__ __volatile__(".chip 68040\n\t"
73 } else if (CPU_IS_020_OR_030) {
74 __asm__ __volatile__("pflusha");
78 static inline void flush_tlb_mm(struct mm_struct *mm)
80 if (mm == current->active_mm)
84 static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
86 if (vma->vm_mm == current->active_mm)
87 __flush_tlb_one(addr);
90 static inline void flush_tlb_range(struct vm_area_struct *vma,
91 unsigned long start, unsigned long end)
93 if (vma->vm_mm == current->active_mm)
97 static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
105 /* Reserved PMEGs. */
106 extern char sun3_reserved_pmeg[SUN3_PMEGS_NUM];
107 extern unsigned long pmeg_vaddr[SUN3_PMEGS_NUM];
108 extern unsigned char pmeg_alloc[SUN3_PMEGS_NUM];
109 extern unsigned char pmeg_ctx[SUN3_PMEGS_NUM];
111 /* Flush all userspace mappings one by one... (why no flush command,
113 static inline void flush_tlb_all(void)
116 unsigned char ctx, oldctx;
118 oldctx = sun3_get_context();
119 for(addr = 0x00000000; addr < TASK_SIZE; addr += SUN3_PMEG_SIZE) {
120 for(ctx = 0; ctx < 8; ctx++) {
121 sun3_put_context(ctx);
122 sun3_put_segmap(addr, SUN3_INVALID_PMEG);
126 sun3_put_context(oldctx);
127 /* erase all of the userspace pmeg maps, we've clobbered them
129 for(addr = 0; addr < SUN3_INVALID_PMEG; addr++) {
130 if(pmeg_alloc[addr] == 1) {
131 pmeg_alloc[addr] = 0;
133 pmeg_vaddr[addr] = 0;
139 /* Clear user TLB entries within the context named in mm */
140 static inline void flush_tlb_mm (struct mm_struct *mm)
142 unsigned char oldctx;
146 oldctx = sun3_get_context();
147 sun3_put_context(mm->context);
149 for(i = 0; i < TASK_SIZE; i += SUN3_PMEG_SIZE) {
150 seg = sun3_get_segmap(i);
151 if(seg == SUN3_INVALID_PMEG)
154 sun3_put_segmap(i, SUN3_INVALID_PMEG);
160 sun3_put_context(oldctx);
164 /* Flush a single TLB page. In this case, we're limited to flushing a
166 static inline void flush_tlb_page (struct vm_area_struct *vma,
169 unsigned char oldctx;
172 oldctx = sun3_get_context();
173 sun3_put_context(vma->vm_mm->context);
174 addr &= ~SUN3_PMEG_MASK;
175 if((i = sun3_get_segmap(addr)) != SUN3_INVALID_PMEG)
180 sun3_put_segmap (addr, SUN3_INVALID_PMEG);
182 sun3_put_context(oldctx);
185 /* Flush a range of pages from TLB. */
187 static inline void flush_tlb_range (struct vm_area_struct *vma,
188 unsigned long start, unsigned long end)
190 struct mm_struct *mm = vma->vm_mm;
191 unsigned char seg, oldctx;
193 start &= ~SUN3_PMEG_MASK;
195 oldctx = sun3_get_context();
196 sun3_put_context(mm->context);
200 if((seg = sun3_get_segmap(start)) == SUN3_INVALID_PMEG)
202 if(pmeg_ctx[seg] == mm->context) {
207 sun3_put_segmap(start, SUN3_INVALID_PMEG);
209 start += SUN3_PMEG_SIZE;
213 static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
218 /* Flush kernel page from TLB. */
219 static inline void flush_tlb_kernel_page (unsigned long addr)
221 sun3_put_segmap (addr & ~(SUN3_PMEG_SIZE - 1), SUN3_INVALID_PMEG);
226 #else /* !CONFIG_MMU */
229 * flush all user-space atc entries.
231 static inline void __flush_tlb(void)
236 static inline void __flush_tlb_one(unsigned long addr)
241 #define flush_tlb() __flush_tlb()
244 * flush all atc entries (both kernel and user-space entries).
246 static inline void flush_tlb_all(void)
251 static inline void flush_tlb_mm(struct mm_struct *mm)
256 static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
261 static inline void flush_tlb_range(struct vm_area_struct *vma,
262 unsigned long start, unsigned long end)
267 static inline void flush_tlb_kernel_page(unsigned long addr)
272 #endif /* CONFIG_MMU */
274 #endif /* _M68K_TLBFLUSH_H */