1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/m68k/mm/cache.c
5 * Instruction cache handling
7 * Copyright (C) 1995 Hamish Macdonald
10 #include <linux/module.h>
11 #include <asm/cacheflush.h>
12 #include <asm/traps.h>
15 static unsigned long virt_to_phys_slow(unsigned long vaddr
)
20 /* The PLPAR instruction causes an access error if the translation
21 * is not possible. To catch this we use the same exception mechanism
22 * as for user space accesses in <asm/uaccess.h>. */
23 asm volatile (".chip 68060\n"
27 ".section .fixup,\"ax\"\n"
32 ".section __ex_table,\"a\"\n"
39 } else if (CPU_IS_040
) {
42 asm volatile (".chip 68040\n\t"
44 "movec %%mmusr, %0\n\t"
49 if (mmusr
& MMU_R_040
)
50 return (mmusr
& PAGE_MASK
) | (vaddr
& ~PAGE_MASK
);
53 unsigned long *descaddr
;
55 asm volatile ("ptestr %3,%2@,#7,%0\n\t"
57 : "=a&" (descaddr
), "=m" (mmusr
)
58 : "a" (vaddr
), "d" (get_fs().seg
));
59 if (mmusr
& (MMU_I
|MMU_B
|MMU_L
))
61 descaddr
= phys_to_virt((unsigned long)descaddr
);
62 switch (mmusr
& MMU_NUM
) {
64 return (*descaddr
& 0xfe000000) | (vaddr
& 0x01ffffff);
66 return (*descaddr
& 0xfffc0000) | (vaddr
& 0x0003ffff);
68 return (*descaddr
& PAGE_MASK
) | (vaddr
& ~PAGE_MASK
);
74 /* Push n pages at kernel virtual address and clear the icache */
75 /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */
76 void flush_icache_user_range(unsigned long address
, unsigned long endaddr
)
78 if (CPU_IS_COLDFIRE
) {
79 unsigned long start
, end
;
80 start
= address
& ICACHE_SET_MASK
;
81 end
= endaddr
& ICACHE_SET_MASK
;
83 flush_cf_icache(0, end
);
84 end
= ICACHE_MAX_ADDR
;
86 flush_cf_icache(start
, end
);
87 } else if (CPU_IS_040_OR_060
) {
91 asm volatile ("nop\n\t"
93 "cpushp %%bc,(%0)\n\t"
95 : : "a" (virt_to_phys_slow(address
)));
97 } while (address
< endaddr
);
100 asm volatile ("movec %%cacr,%0\n\t"
108 void flush_icache_range(unsigned long address
, unsigned long endaddr
)
110 mm_segment_t old_fs
= get_fs();
113 flush_icache_user_range(address
, endaddr
);
116 EXPORT_SYMBOL(flush_icache_range
);
118 void flush_icache_user_page(struct vm_area_struct
*vma
, struct page
*page
,
119 unsigned long addr
, int len
)
121 if (CPU_IS_COLDFIRE
) {
122 unsigned long start
, end
;
123 start
= addr
& ICACHE_SET_MASK
;
124 end
= (addr
+ len
) & ICACHE_SET_MASK
;
126 flush_cf_icache(0, end
);
127 end
= ICACHE_MAX_ADDR
;
129 flush_cf_icache(start
, end
);
131 } else if (CPU_IS_040_OR_060
) {
132 asm volatile ("nop\n\t"
134 "cpushp %%bc,(%0)\n\t"
136 : : "a" (page_to_phys(page
)));
139 asm volatile ("movec %%cacr,%0\n\t"