2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Inline assembly cache operations.
8 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
9 * Copyright (C) 1997 - 2002 Ralf Baechle (ralf@gnu.org)
10 * Copyright (C) 2004 Ralf Baechle (ralf@linux-mips.org)
12 #ifndef _ASM_R4KCACHE_H
13 #define _ASM_R4KCACHE_H
15 #include <linux/stringify.h>
18 #include <asm/cacheops.h>
19 #include <asm/compiler.h>
20 #include <asm/cpu-features.h>
21 #include <asm/cpu-type.h>
22 #include <asm/mipsmtregs.h>
23 #include <linux/uaccess.h> /* for uaccess_kernel() */
25 extern void (*r4k_blast_dcache)(void);
26 extern void (*r4k_blast_icache)(void);
29 * This macro return a properly sign-extended address suitable as base address
30 * for indexed cache operations. Two issues here:
32 * - The MIPS32 and MIPS64 specs permit an implementation to directly derive
33 * the index bits from the virtual address. This breaks with tradition
34 * set by the R4000. To keep unpleasant surprises from happening we pick
35 * an address in KSEG0 / CKSEG0.
36 * - We need a properly sign extended address for 64-bit code. To get away
37 * without ifdefs we let the compiler do it by a type cast.
39 #define INDEX_BASE CKSEG0
41 #define cache_op(op,addr) \
42 __asm__ __volatile__( \
44 " .set noreorder \n" \
45 " .set "MIPS_ISA_ARCH_LEVEL" \n" \
49 : "i" (op), "R" (*(unsigned char *)(addr)))
51 static inline void flush_icache_line_indexed(unsigned long addr)
53 cache_op(Index_Invalidate_I, addr);
56 static inline void flush_dcache_line_indexed(unsigned long addr)
58 cache_op(Index_Writeback_Inv_D, addr);
61 static inline void flush_scache_line_indexed(unsigned long addr)
63 cache_op(Index_Writeback_Inv_SD, addr);
66 static inline void flush_icache_line(unsigned long addr)
68 switch (boot_cpu_type()) {
70 cache_op(Hit_Invalidate_I_Loongson2, addr);
74 cache_op(Hit_Invalidate_I, addr);
79 static inline void flush_dcache_line(unsigned long addr)
81 cache_op(Hit_Writeback_Inv_D, addr);
84 static inline void invalidate_dcache_line(unsigned long addr)
86 cache_op(Hit_Invalidate_D, addr);
89 static inline void invalidate_scache_line(unsigned long addr)
91 cache_op(Hit_Invalidate_SD, addr);
94 static inline void flush_scache_line(unsigned long addr)
96 cache_op(Hit_Writeback_Inv_SD, addr);
99 #define protected_cache_op(op,addr) \
102 __asm__ __volatile__( \
104 " .set noreorder \n" \
105 " .set "MIPS_ISA_ARCH_LEVEL" \n" \
106 "1: cache %1, (%2) \n" \
109 " .section .fixup,\"ax\" \n" \
113 " .section __ex_table,\"a\" \n" \
114 " "STR(PTR)" 1b, 3b \n" \
117 : "i" (op), "r" (addr), "i" (-EFAULT)); \
122 #define protected_cachee_op(op,addr) \
125 __asm__ __volatile__( \
127 " .set noreorder \n" \
130 "1: cachee %1, (%2) \n" \
133 " .section .fixup,\"ax\" \n" \
137 " .section __ex_table,\"a\" \n" \
138 " "STR(PTR)" 1b, 3b \n" \
141 : "i" (op), "r" (addr), "i" (-EFAULT)); \
146 * The next two are for badland addresses like signal trampolines.
148 static inline int protected_flush_icache_line(unsigned long addr)
150 switch (boot_cpu_type()) {
152 return protected_cache_op(Hit_Invalidate_I_Loongson2, addr);
156 return protected_cachee_op(Hit_Invalidate_I, addr);
158 return protected_cache_op(Hit_Invalidate_I, addr);
164 * R10000 / R12000 hazard - these processors don't support the Hit_Writeback_D
165 * cacheop so we use Hit_Writeback_Inv_D which is supported by all R4000-style
166 * caches. We're talking about one cacheline unnecessarily getting invalidated
167 * here so the penalty isn't overly hard.
169 static inline int protected_writeback_dcache_line(unsigned long addr)
172 return protected_cachee_op(Hit_Writeback_Inv_D, addr);
174 return protected_cache_op(Hit_Writeback_Inv_D, addr);
178 static inline int protected_writeback_scache_line(unsigned long addr)
181 return protected_cachee_op(Hit_Writeback_Inv_SD, addr);
183 return protected_cache_op(Hit_Writeback_Inv_SD, addr);
188 * This one is RM7000-specific
190 static inline void invalidate_tcache_page(unsigned long addr)
192 cache_op(Page_Invalidate_T, addr);
195 #ifndef CONFIG_CPU_MIPSR6
196 #define cache16_unroll32(base,op) \
197 __asm__ __volatile__( \
199 " .set noreorder \n" \
201 " cache %1, 0x000(%0); cache %1, 0x010(%0) \n" \
202 " cache %1, 0x020(%0); cache %1, 0x030(%0) \n" \
203 " cache %1, 0x040(%0); cache %1, 0x050(%0) \n" \
204 " cache %1, 0x060(%0); cache %1, 0x070(%0) \n" \
205 " cache %1, 0x080(%0); cache %1, 0x090(%0) \n" \
206 " cache %1, 0x0a0(%0); cache %1, 0x0b0(%0) \n" \
207 " cache %1, 0x0c0(%0); cache %1, 0x0d0(%0) \n" \
208 " cache %1, 0x0e0(%0); cache %1, 0x0f0(%0) \n" \
209 " cache %1, 0x100(%0); cache %1, 0x110(%0) \n" \
210 " cache %1, 0x120(%0); cache %1, 0x130(%0) \n" \
211 " cache %1, 0x140(%0); cache %1, 0x150(%0) \n" \
212 " cache %1, 0x160(%0); cache %1, 0x170(%0) \n" \
213 " cache %1, 0x180(%0); cache %1, 0x190(%0) \n" \
214 " cache %1, 0x1a0(%0); cache %1, 0x1b0(%0) \n" \
215 " cache %1, 0x1c0(%0); cache %1, 0x1d0(%0) \n" \
216 " cache %1, 0x1e0(%0); cache %1, 0x1f0(%0) \n" \
222 #define cache32_unroll32(base,op) \
223 __asm__ __volatile__( \
225 " .set noreorder \n" \
227 " cache %1, 0x000(%0); cache %1, 0x020(%0) \n" \
228 " cache %1, 0x040(%0); cache %1, 0x060(%0) \n" \
229 " cache %1, 0x080(%0); cache %1, 0x0a0(%0) \n" \
230 " cache %1, 0x0c0(%0); cache %1, 0x0e0(%0) \n" \
231 " cache %1, 0x100(%0); cache %1, 0x120(%0) \n" \
232 " cache %1, 0x140(%0); cache %1, 0x160(%0) \n" \
233 " cache %1, 0x180(%0); cache %1, 0x1a0(%0) \n" \
234 " cache %1, 0x1c0(%0); cache %1, 0x1e0(%0) \n" \
235 " cache %1, 0x200(%0); cache %1, 0x220(%0) \n" \
236 " cache %1, 0x240(%0); cache %1, 0x260(%0) \n" \
237 " cache %1, 0x280(%0); cache %1, 0x2a0(%0) \n" \
238 " cache %1, 0x2c0(%0); cache %1, 0x2e0(%0) \n" \
239 " cache %1, 0x300(%0); cache %1, 0x320(%0) \n" \
240 " cache %1, 0x340(%0); cache %1, 0x360(%0) \n" \
241 " cache %1, 0x380(%0); cache %1, 0x3a0(%0) \n" \
242 " cache %1, 0x3c0(%0); cache %1, 0x3e0(%0) \n" \
248 #define cache64_unroll32(base,op) \
249 __asm__ __volatile__( \
251 " .set noreorder \n" \
253 " cache %1, 0x000(%0); cache %1, 0x040(%0) \n" \
254 " cache %1, 0x080(%0); cache %1, 0x0c0(%0) \n" \
255 " cache %1, 0x100(%0); cache %1, 0x140(%0) \n" \
256 " cache %1, 0x180(%0); cache %1, 0x1c0(%0) \n" \
257 " cache %1, 0x200(%0); cache %1, 0x240(%0) \n" \
258 " cache %1, 0x280(%0); cache %1, 0x2c0(%0) \n" \
259 " cache %1, 0x300(%0); cache %1, 0x340(%0) \n" \
260 " cache %1, 0x380(%0); cache %1, 0x3c0(%0) \n" \
261 " cache %1, 0x400(%0); cache %1, 0x440(%0) \n" \
262 " cache %1, 0x480(%0); cache %1, 0x4c0(%0) \n" \
263 " cache %1, 0x500(%0); cache %1, 0x540(%0) \n" \
264 " cache %1, 0x580(%0); cache %1, 0x5c0(%0) \n" \
265 " cache %1, 0x600(%0); cache %1, 0x640(%0) \n" \
266 " cache %1, 0x680(%0); cache %1, 0x6c0(%0) \n" \
267 " cache %1, 0x700(%0); cache %1, 0x740(%0) \n" \
268 " cache %1, 0x780(%0); cache %1, 0x7c0(%0) \n" \
274 #define cache128_unroll32(base,op) \
275 __asm__ __volatile__( \
277 " .set noreorder \n" \
279 " cache %1, 0x000(%0); cache %1, 0x080(%0) \n" \
280 " cache %1, 0x100(%0); cache %1, 0x180(%0) \n" \
281 " cache %1, 0x200(%0); cache %1, 0x280(%0) \n" \
282 " cache %1, 0x300(%0); cache %1, 0x380(%0) \n" \
283 " cache %1, 0x400(%0); cache %1, 0x480(%0) \n" \
284 " cache %1, 0x500(%0); cache %1, 0x580(%0) \n" \
285 " cache %1, 0x600(%0); cache %1, 0x680(%0) \n" \
286 " cache %1, 0x700(%0); cache %1, 0x780(%0) \n" \
287 " cache %1, 0x800(%0); cache %1, 0x880(%0) \n" \
288 " cache %1, 0x900(%0); cache %1, 0x980(%0) \n" \
289 " cache %1, 0xa00(%0); cache %1, 0xa80(%0) \n" \
290 " cache %1, 0xb00(%0); cache %1, 0xb80(%0) \n" \
291 " cache %1, 0xc00(%0); cache %1, 0xc80(%0) \n" \
292 " cache %1, 0xd00(%0); cache %1, 0xd80(%0) \n" \
293 " cache %1, 0xe00(%0); cache %1, 0xe80(%0) \n" \
294 " cache %1, 0xf00(%0); cache %1, 0xf80(%0) \n" \
302 * MIPS R6 changed the cache opcode and moved to a 8-bit offset field.
303 * This means we now need to increment the base register before we flush
306 #define cache16_unroll32(base,op) \
307 __asm__ __volatile__( \
309 " .set noreorder\n" \
312 " cache %1, 0x000(%0); cache %1, 0x010(%0)\n" \
313 " cache %1, 0x020(%0); cache %1, 0x030(%0)\n" \
314 " cache %1, 0x040(%0); cache %1, 0x050(%0)\n" \
315 " cache %1, 0x060(%0); cache %1, 0x070(%0)\n" \
316 " cache %1, 0x080(%0); cache %1, 0x090(%0)\n" \
317 " cache %1, 0x0a0(%0); cache %1, 0x0b0(%0)\n" \
318 " cache %1, 0x0c0(%0); cache %1, 0x0d0(%0)\n" \
319 " cache %1, 0x0e0(%0); cache %1, 0x0f0(%0)\n" \
320 " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
321 " cache %1, 0x000($1); cache %1, 0x010($1)\n" \
322 " cache %1, 0x020($1); cache %1, 0x030($1)\n" \
323 " cache %1, 0x040($1); cache %1, 0x050($1)\n" \
324 " cache %1, 0x060($1); cache %1, 0x070($1)\n" \
325 " cache %1, 0x080($1); cache %1, 0x090($1)\n" \
326 " cache %1, 0x0a0($1); cache %1, 0x0b0($1)\n" \
327 " cache %1, 0x0c0($1); cache %1, 0x0d0($1)\n" \
328 " cache %1, 0x0e0($1); cache %1, 0x0f0($1)\n" \
334 #define cache32_unroll32(base,op) \
335 __asm__ __volatile__( \
337 " .set noreorder\n" \
340 " cache %1, 0x000(%0); cache %1, 0x020(%0)\n" \
341 " cache %1, 0x040(%0); cache %1, 0x060(%0)\n" \
342 " cache %1, 0x080(%0); cache %1, 0x0a0(%0)\n" \
343 " cache %1, 0x0c0(%0); cache %1, 0x0e0(%0)\n" \
344 " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
345 " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
346 " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
347 " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
348 " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
349 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
350 " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
351 " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
352 " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
353 " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
354 " "__stringify(LONG_ADDIU)" $1, $1, 0x100\n" \
355 " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
356 " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
357 " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
358 " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
364 #define cache64_unroll32(base,op) \
365 __asm__ __volatile__( \
367 " .set noreorder\n" \
370 " cache %1, 0x000(%0); cache %1, 0x040(%0)\n" \
371 " cache %1, 0x080(%0); cache %1, 0x0c0(%0)\n" \
372 " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
373 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
374 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
375 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
376 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
377 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
378 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
379 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
380 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
381 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
382 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
383 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
384 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
385 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
386 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
387 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
388 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
389 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
390 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
391 " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
392 " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
398 #define cache128_unroll32(base,op) \
399 __asm__ __volatile__( \
401 " .set noreorder\n" \
404 " cache %1, 0x000(%0); cache %1, 0x080(%0)\n" \
405 " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
406 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
407 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
408 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
409 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
410 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
411 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
412 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
413 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
414 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
415 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
416 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
417 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
418 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
419 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
420 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
421 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
422 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
423 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
424 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
425 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
426 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
427 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
428 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
429 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
430 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
431 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
432 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
433 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
434 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
435 " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
436 " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
441 #endif /* CONFIG_CPU_MIPSR6 */
444 * Perform the cache operation specified by op using a user mode virtual
445 * address while in kernel mode.
447 #define cache16_unroll32_user(base,op) \
448 __asm__ __volatile__( \
450 " .set noreorder \n" \
453 " cachee %1, 0x000(%0); cachee %1, 0x010(%0) \n" \
454 " cachee %1, 0x020(%0); cachee %1, 0x030(%0) \n" \
455 " cachee %1, 0x040(%0); cachee %1, 0x050(%0) \n" \
456 " cachee %1, 0x060(%0); cachee %1, 0x070(%0) \n" \
457 " cachee %1, 0x080(%0); cachee %1, 0x090(%0) \n" \
458 " cachee %1, 0x0a0(%0); cachee %1, 0x0b0(%0) \n" \
459 " cachee %1, 0x0c0(%0); cachee %1, 0x0d0(%0) \n" \
460 " cachee %1, 0x0e0(%0); cachee %1, 0x0f0(%0) \n" \
461 " cachee %1, 0x100(%0); cachee %1, 0x110(%0) \n" \
462 " cachee %1, 0x120(%0); cachee %1, 0x130(%0) \n" \
463 " cachee %1, 0x140(%0); cachee %1, 0x150(%0) \n" \
464 " cachee %1, 0x160(%0); cachee %1, 0x170(%0) \n" \
465 " cachee %1, 0x180(%0); cachee %1, 0x190(%0) \n" \
466 " cachee %1, 0x1a0(%0); cachee %1, 0x1b0(%0) \n" \
467 " cachee %1, 0x1c0(%0); cachee %1, 0x1d0(%0) \n" \
468 " cachee %1, 0x1e0(%0); cachee %1, 0x1f0(%0) \n" \
474 #define cache32_unroll32_user(base, op) \
475 __asm__ __volatile__( \
477 " .set noreorder \n" \
480 " cachee %1, 0x000(%0); cachee %1, 0x020(%0) \n" \
481 " cachee %1, 0x040(%0); cachee %1, 0x060(%0) \n" \
482 " cachee %1, 0x080(%0); cachee %1, 0x0a0(%0) \n" \
483 " cachee %1, 0x0c0(%0); cachee %1, 0x0e0(%0) \n" \
484 " cachee %1, 0x100(%0); cachee %1, 0x120(%0) \n" \
485 " cachee %1, 0x140(%0); cachee %1, 0x160(%0) \n" \
486 " cachee %1, 0x180(%0); cachee %1, 0x1a0(%0) \n" \
487 " cachee %1, 0x1c0(%0); cachee %1, 0x1e0(%0) \n" \
488 " cachee %1, 0x200(%0); cachee %1, 0x220(%0) \n" \
489 " cachee %1, 0x240(%0); cachee %1, 0x260(%0) \n" \
490 " cachee %1, 0x280(%0); cachee %1, 0x2a0(%0) \n" \
491 " cachee %1, 0x2c0(%0); cachee %1, 0x2e0(%0) \n" \
492 " cachee %1, 0x300(%0); cachee %1, 0x320(%0) \n" \
493 " cachee %1, 0x340(%0); cachee %1, 0x360(%0) \n" \
494 " cachee %1, 0x380(%0); cachee %1, 0x3a0(%0) \n" \
495 " cachee %1, 0x3c0(%0); cachee %1, 0x3e0(%0) \n" \
501 #define cache64_unroll32_user(base, op) \
502 __asm__ __volatile__( \
504 " .set noreorder \n" \
507 " cachee %1, 0x000(%0); cachee %1, 0x040(%0) \n" \
508 " cachee %1, 0x080(%0); cachee %1, 0x0c0(%0) \n" \
509 " cachee %1, 0x100(%0); cachee %1, 0x140(%0) \n" \
510 " cachee %1, 0x180(%0); cachee %1, 0x1c0(%0) \n" \
511 " cachee %1, 0x200(%0); cachee %1, 0x240(%0) \n" \
512 " cachee %1, 0x280(%0); cachee %1, 0x2c0(%0) \n" \
513 " cachee %1, 0x300(%0); cachee %1, 0x340(%0) \n" \
514 " cachee %1, 0x380(%0); cachee %1, 0x3c0(%0) \n" \
515 " cachee %1, 0x400(%0); cachee %1, 0x440(%0) \n" \
516 " cachee %1, 0x480(%0); cachee %1, 0x4c0(%0) \n" \
517 " cachee %1, 0x500(%0); cachee %1, 0x540(%0) \n" \
518 " cachee %1, 0x580(%0); cachee %1, 0x5c0(%0) \n" \
519 " cachee %1, 0x600(%0); cachee %1, 0x640(%0) \n" \
520 " cachee %1, 0x680(%0); cachee %1, 0x6c0(%0) \n" \
521 " cachee %1, 0x700(%0); cachee %1, 0x740(%0) \n" \
522 " cachee %1, 0x780(%0); cachee %1, 0x7c0(%0) \n" \
528 /* build blast_xxx, blast_xxx_page, blast_xxx_page_indexed */
529 #define __BUILD_BLAST_CACHE(pfx, desc, indexop, hitop, lsize, extra) \
530 static inline void extra##blast_##pfx##cache##lsize(void) \
532 unsigned long start = INDEX_BASE; \
533 unsigned long end = start + current_cpu_data.desc.waysize; \
534 unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \
535 unsigned long ws_end = current_cpu_data.desc.ways << \
536 current_cpu_data.desc.waybit; \
537 unsigned long ws, addr; \
539 for (ws = 0; ws < ws_end; ws += ws_inc) \
540 for (addr = start; addr < end; addr += lsize * 32) \
541 cache##lsize##_unroll32(addr|ws, indexop); \
544 static inline void extra##blast_##pfx##cache##lsize##_page(unsigned long page) \
546 unsigned long start = page; \
547 unsigned long end = page + PAGE_SIZE; \
550 cache##lsize##_unroll32(start, hitop); \
551 start += lsize * 32; \
552 } while (start < end); \
555 static inline void extra##blast_##pfx##cache##lsize##_page_indexed(unsigned long page) \
557 unsigned long indexmask = current_cpu_data.desc.waysize - 1; \
558 unsigned long start = INDEX_BASE + (page & indexmask); \
559 unsigned long end = start + PAGE_SIZE; \
560 unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \
561 unsigned long ws_end = current_cpu_data.desc.ways << \
562 current_cpu_data.desc.waybit; \
563 unsigned long ws, addr; \
565 for (ws = 0; ws < ws_end; ws += ws_inc) \
566 for (addr = start; addr < end; addr += lsize * 32) \
567 cache##lsize##_unroll32(addr|ws, indexop); \
570 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 16, )
571 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16, )
572 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16, )
573 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 32, )
574 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32, )
575 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I_Loongson2, 32, loongson2_)
576 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32, )
577 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 64, )
578 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64, )
579 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 64, )
580 __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 128, )
581 __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 128, )
582 __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128, )
584 __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 16, )
585 __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 32, )
586 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 16, )
587 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 32, )
588 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 64, )
589 __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 128, )
591 #define __BUILD_BLAST_USER_CACHE(pfx, desc, indexop, hitop, lsize) \
592 static inline void blast_##pfx##cache##lsize##_user_page(unsigned long page) \
594 unsigned long start = page; \
595 unsigned long end = page + PAGE_SIZE; \
598 cache##lsize##_unroll32_user(start, hitop); \
599 start += lsize * 32; \
600 } while (start < end); \
603 __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
605 __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16)
606 __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
608 __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32)
609 __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
611 __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64)
613 /* build blast_xxx_range, protected_blast_xxx_range */
614 #define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot, extra) \
615 static inline void prot##extra##blast_##pfx##cache##_range(unsigned long start, \
618 unsigned long lsize = cpu_##desc##_line_size(); \
619 unsigned long addr = start & ~(lsize - 1); \
620 unsigned long aend = (end - 1) & ~(lsize - 1); \
623 prot##cache_op(hitop, addr); \
632 __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_, )
633 __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_, )
637 #define __BUILD_PROT_BLAST_CACHE_RANGE(pfx, desc, hitop) \
638 static inline void protected_blast_##pfx##cache##_range(unsigned long start,\
641 unsigned long lsize = cpu_##desc##_line_size(); \
642 unsigned long addr = start & ~(lsize - 1); \
643 unsigned long aend = (end - 1) & ~(lsize - 1); \
645 if (!uaccess_kernel()) { \
647 protected_cachee_op(hitop, addr); \
654 protected_cache_op(hitop, addr); \
663 __BUILD_PROT_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D)
664 __BUILD_PROT_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I)
667 __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_, )
668 __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I_Loongson2, \
669 protected_, loongson2_)
670 __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, , )
671 __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, , )
672 __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, , )
673 /* blast_inv_dcache_range */
674 __BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, , )
675 __BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, , )
677 #endif /* _ASM_R4KCACHE_H */