1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/m68k/mm/memory.c
5 * Copyright (C) 1995 Hamish Macdonald
8 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/pagemap.h>
15 #include <linux/gfp.h>
17 #include <asm/setup.h>
18 #include <asm/segment.h>
20 #include <asm/pgalloc.h>
21 #include <asm/traps.h>
22 #include <asm/machdep.h>
25 /* invalidate page in both caches */
26 static inline void clear040(unsigned long paddr)
36 /* invalidate page in i-cache */
37 static inline void cleari040(unsigned long paddr)
47 /* push page in both caches */
48 /* RZ: cpush %bc DOES invalidate %ic, regardless of DPI */
49 static inline void push040(unsigned long paddr)
54 "cpushp %%bc,(%0)\n\t"
59 /* push and invalidate page in both caches, must disable ints
60 * to avoid invalidating valid data */
61 static inline void pushcl040(unsigned long paddr)
65 local_irq_save(flags);
69 local_irq_restore(flags);
73 * 040: Hit every page containing an address in the range paddr..paddr+len-1.
74 * (Low order bits of the ea of a CINVP/CPUSHP are "don't care"s).
75 * Hit every page until there is a page or less to go. Hit the next page,
76 * and the one after that if the range hits it.
78 /* ++roman: A little bit more care is required here: The CINVP instruction
79 * invalidates cache entries WITHOUT WRITING DIRTY DATA BACK! So the beginning
80 * and the end of the region must be treated differently if they are not
81 * exactly at the beginning or end of a page boundary. Else, maybe too much
82 * data becomes invalidated and thus lost forever. CPUSHP does what we need:
83 * it invalidates the page after pushing dirty data to memory. (Thanks to Jes
84 * for discovering the problem!)
86 /* ... but on the '060, CPUSH doesn't invalidate (for us, since we have set
87 * the DPI bit in the CACR; would it cause problems with temporarily changing
88 * this?). So we have to push first and then additionally to invalidate.
93 * cache_clear() semantics: Clear any cache entries for the area in question,
94 * without writing back dirty entries first. This is useful if the data will
95 * be overwritten anyway, e.g. by DMA to memory. The range is defined by a
99 void cache_clear (unsigned long paddr, int len)
101 if (CPU_IS_COLDFIRE) {
102 clear_cf_bcache(0, DCACHE_MAX_ADDR);
103 } else if (CPU_IS_040_OR_060) {
107 * We need special treatment for the first page, in case it
108 * is not page-aligned. Page align the addresses to work
109 * around bug I17 in the 68060.
111 if ((tmp = -paddr & (PAGE_SIZE - 1))) {
112 pushcl040(paddr & PAGE_MASK);
113 if ((len -= tmp) <= 0)
119 while ((len -= tmp) >= 0) {
124 /* a page boundary gets crossed at the end */
127 else /* 68030 or 68020 */
128 asm volatile ("movec %/cacr,%/d0\n\t"
131 : : "i" (FLUSH_I_AND_D)
133 #ifdef CONFIG_M68K_L2_CACHE
138 EXPORT_SYMBOL(cache_clear);
142 * cache_push() semantics: Write back any dirty cache data in the given area,
143 * and invalidate the range in the instruction cache. It needs not (but may)
144 * invalidate those entries also in the data cache. The range is defined by a
145 * _physical_ address.
148 void cache_push (unsigned long paddr, int len)
150 if (CPU_IS_COLDFIRE) {
151 flush_cf_bcache(0, DCACHE_MAX_ADDR);
152 } else if (CPU_IS_040_OR_060) {
156 * on 68040 or 68060, push cache lines for pages in the range;
157 * on the '040 this also invalidates the pushed lines, but not on
160 len += paddr & (PAGE_SIZE - 1);
163 * Work around bug I17 in the 68060 affecting some instruction
164 * lines not being invalidated properly.
171 } while ((len -= tmp) > 0);
174 * 68030/68020 have no writeback cache. On the other hand,
175 * cache_push is actually a superset of cache_clear (the lines
176 * get written back and invalidated), so we should make sure
177 * to perform the corresponding actions. After all, this is getting
178 * called in places where we've just loaded code, or whatever, so
179 * flushing the icache is appropriate; flushing the dcache shouldn't
182 else /* 68030 or 68020 */
183 asm volatile ("movec %/cacr,%/d0\n\t"
188 #ifdef CONFIG_M68K_L2_CACHE
193 EXPORT_SYMBOL(cache_push);