1 From 296b9882edc2e6779e6c3d97f537166aa2334b93 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 17:34:29 +0200
4 Subject: [PATCH] JZ4740 cache quirks
7 arch/mips/include/asm/r4kcache.h | 231 ++++++++++++++++++++++++++++++++++++++
8 1 files changed, 231 insertions(+), 0 deletions(-)
10 --- a/arch/mips/include/asm/r4kcache.h
11 +++ b/arch/mips/include/asm/r4kcache.h
13 #include <asm/cpu-features.h>
14 #include <asm/mipsmtregs.h>
20 + unsigned long __k0_addr; \
22 + __asm__ __volatile__( \
24 + "or %0, %0, %1\n\t" \
28 + : "=&r"(__k0_addr) \
29 + : "r" (0x20000000) ); \
34 + unsigned long __k0_addr; \
35 + __asm__ __volatile__( \
36 + "nop;nop;nop;nop;nop;nop;nop\n\t" \
41 + : "=&r" (__k0_addr)); \
44 +#define INVALIDATE_BTB() \
46 + unsigned long tmp; \
47 + __asm__ __volatile__( \
49 + "mfc0 %0, $16, 7\n\t" \
52 + "mtc0 %0, $16, 7\n\t" \
57 +#define SYNC_WB() __asm__ __volatile__ ("sync")
59 +#else /* CONFIG_JZRISC */
61 +#define K0_TO_K1() do { } while (0)
62 +#define K1_TO_K0() do { } while (0)
63 +#define INVALIDATE_BTB() do { } while (0)
64 +#define SYNC_WB() do { } while (0)
66 +#endif /* CONFIG_JZRISC */
69 * This macro return a properly sign-extended address suitable as base address
70 * for indexed cache operations. Two issues here:
71 @@ -144,6 +196,7 @@ static inline void flush_icache_line_ind
74 cache_op(Index_Invalidate_I, addr);
79 @@ -151,6 +204,7 @@ static inline void flush_dcache_line_ind
82 cache_op(Index_Writeback_Inv_D, addr);
87 @@ -163,6 +217,7 @@ static inline void flush_icache_line(uns
90 cache_op(Hit_Invalidate_I, addr);
95 @@ -170,6 +225,7 @@ static inline void flush_dcache_line(uns
98 cache_op(Hit_Writeback_Inv_D, addr);
103 @@ -177,6 +233,7 @@ static inline void invalidate_dcache_lin
106 cache_op(Hit_Invalidate_D, addr);
111 @@ -209,6 +266,7 @@ static inline void flush_scache_line(uns
112 static inline void protected_flush_icache_line(unsigned long addr)
114 protected_cache_op(Hit_Invalidate_I, addr);
119 @@ -220,6 +278,7 @@ static inline void protected_flush_icach
120 static inline void protected_writeback_dcache_line(unsigned long addr)
122 protected_cache_op(Hit_Writeback_Inv_D, addr);
126 static inline void protected_writeback_scache_line(unsigned long addr)
127 @@ -396,8 +455,10 @@ static inline void blast_##pfx##cache##l
128 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 16)
129 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16)
130 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16)
131 +#ifndef CONFIG_JZRISC
132 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 32)
133 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32)
135 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32)
136 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 64)
137 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64)
138 @@ -405,12 +466,122 @@ __BUILD_BLAST_CACHE(s, scache, Index_Wri
139 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128)
141 __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 16)
142 +#ifndef CONFIG_JZRISC
143 __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 32)
145 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 16)
146 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 32)
147 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 64)
148 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 128)
150 +#ifdef CONFIG_JZRISC
152 +static inline void blast_dcache32(void)
154 + unsigned long start = INDEX_BASE;
155 + unsigned long end = start + current_cpu_data.dcache.waysize;
156 + unsigned long ws_inc = 1UL << current_cpu_data.dcache.waybit;
157 + unsigned long ws_end = current_cpu_data.dcache.ways <<
158 + current_cpu_data.dcache.waybit;
159 + unsigned long ws, addr;
161 + for (ws = 0; ws < ws_end; ws += ws_inc)
162 + for (addr = start; addr < end; addr += 0x400)
163 + cache32_unroll32(addr|ws,Index_Writeback_Inv_D);
168 +static inline void blast_dcache32_page(unsigned long page)
170 + unsigned long start = page;
171 + unsigned long end = page + PAGE_SIZE;
174 + cache32_unroll32(start,Hit_Writeback_Inv_D);
176 + } while (start < end);
181 +static inline void blast_dcache32_page_indexed(unsigned long page)
183 + unsigned long indexmask = current_cpu_data.dcache.waysize - 1;
184 + unsigned long start = INDEX_BASE + (page & indexmask);
185 + unsigned long end = start + PAGE_SIZE;
186 + unsigned long ws_inc = 1UL << current_cpu_data.dcache.waybit;
187 + unsigned long ws_end = current_cpu_data.dcache.ways <<
188 + current_cpu_data.dcache.waybit;
189 + unsigned long ws, addr;
191 + for (ws = 0; ws < ws_end; ws += ws_inc)
192 + for (addr = start; addr < end; addr += 0x400)
193 + cache32_unroll32(addr|ws,Index_Writeback_Inv_D);
198 +static inline void blast_icache32(void)
200 + unsigned long start = INDEX_BASE;
201 + unsigned long end = start + current_cpu_data.icache.waysize;
202 + unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
203 + unsigned long ws_end = current_cpu_data.icache.ways <<
204 + current_cpu_data.icache.waybit;
205 + unsigned long ws, addr;
209 + for (ws = 0; ws < ws_end; ws += ws_inc)
210 + for (addr = start; addr < end; addr += 0x400)
211 + cache32_unroll32(addr|ws,Index_Invalidate_I);
218 +static inline void blast_icache32_page(unsigned long page)
220 + unsigned long start = page;
221 + unsigned long end = page + PAGE_SIZE;
226 + cache32_unroll32(start,Hit_Invalidate_I);
228 + } while (start < end);
235 +static inline void blast_icache32_page_indexed(unsigned long page)
237 + unsigned long indexmask = current_cpu_data.icache.waysize - 1;
238 + unsigned long start = INDEX_BASE + (page & indexmask);
239 + unsigned long end = start + PAGE_SIZE;
240 + unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
241 + unsigned long ws_end = current_cpu_data.icache.ways <<
242 + current_cpu_data.icache.waybit;
243 + unsigned long ws, addr;
247 + for (ws = 0; ws < ws_end; ws += ws_inc)
248 + for (addr = start; addr < end; addr += 0x400)
249 + cache32_unroll32(addr|ws,Index_Invalidate_I);
256 +#endif /* CONFIG_JZRISC */
258 /* build blast_xxx_range, protected_blast_xxx_range */
259 #define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot) \
260 static inline void prot##blast_##pfx##cache##_range(unsigned long start, \
261 @@ -432,13 +603,73 @@ static inline void prot##blast_##pfx##ca
262 __##pfx##flush_epilogue \
265 +#ifndef CONFIG_JZRISC
266 __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_)
268 __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_)
269 +#ifndef CONFIG_JZRISC
270 __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_)
271 __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, )
273 __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, )
274 /* blast_inv_dcache_range */
275 __BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, )
276 __BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, )
278 +#ifdef CONFIG_JZRISC
280 +static inline void protected_blast_dcache_range(unsigned long start,
283 + unsigned long lsize = cpu_dcache_line_size();
284 + unsigned long addr = start & ~(lsize - 1);
285 + unsigned long aend = (end - 1) & ~(lsize - 1);
288 + protected_cache_op(Hit_Writeback_Inv_D, addr);
296 +static inline void protected_blast_icache_range(unsigned long start,
299 + unsigned long lsize = cpu_icache_line_size();
300 + unsigned long addr = start & ~(lsize - 1);
301 + unsigned long aend = (end - 1) & ~(lsize - 1);
306 + protected_cache_op(Hit_Invalidate_I, addr);
316 +static inline void blast_dcache_range(unsigned long start,
319 + unsigned long lsize = cpu_dcache_line_size();
320 + unsigned long addr = start & ~(lsize - 1);
321 + unsigned long aend = (end - 1) & ~(lsize - 1);
324 + cache_op(Hit_Writeback_Inv_D, addr);
332 +#endif /* CONFIG_JZRISC */
334 #endif /* _ASM_R4KCACHE_H */