Optimize andes_clear_page() and andes_copy_page() with prefetch
[linux-2.6/linux-mips.git] / include / asm-mips / r4kcache.h
blob561be48b836b506572c25566e67fa4e886843645
1 /*
2 * r4kcache.h: Inline assembly cache operations.
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
6 * $Id: r4kcache.h,v 1.7 1997/12/18 13:00:45 ralf Exp $
8 * FIXME: Handle split L2 caches.
9 */
10 #ifndef _MIPS_R4KCACHE_H
11 #define _MIPS_R4KCACHE_H
13 #include <asm/asm.h>
14 #include <asm/cacheops.h>
16 extern inline void flush_icache_line_indexed(unsigned long addr)
18 __asm__ __volatile__(
19 ".set noreorder\n\t"
20 ".set mips3\n\t"
21 "cache %1, (%0)\n\t"
22 ".set mips0\n\t"
23 ".set reorder"
25 : "r" (addr),
26 "i" (Index_Invalidate_I));
29 extern inline void flush_dcache_line_indexed(unsigned long addr)
31 __asm__ __volatile__(
32 ".set noreorder\n\t"
33 ".set mips3\n\t"
34 "cache %1, (%0)\n\t"
35 ".set mips0\n\t"
36 ".set reorder"
38 : "r" (addr),
39 "i" (Index_Writeback_Inv_D));
42 extern inline void flush_scache_line_indexed(unsigned long addr)
44 __asm__ __volatile__(
45 ".set noreorder\n\t"
46 ".set mips3\n\t"
47 "cache %1, (%0)\n\t"
48 ".set mips0\n\t"
49 ".set reorder"
51 : "r" (addr),
52 "i" (Index_Writeback_Inv_SD));
55 extern inline void flush_icache_line(unsigned long addr)
57 __asm__ __volatile__(
58 ".set noreorder\n\t"
59 ".set mips3\n\t"
60 "cache %1, (%0)\n\t"
61 ".set mips0\n\t"
62 ".set reorder"
64 : "r" (addr),
65 "i" (Hit_Invalidate_I));
68 extern inline void flush_dcache_line(unsigned long addr)
70 __asm__ __volatile__(
71 ".set noreorder\n\t"
72 ".set mips3\n\t"
73 "cache %1, (%0)\n\t"
74 ".set mips0\n\t"
75 ".set reorder"
77 : "r" (addr),
78 "i" (Hit_Writeback_Inv_D));
81 extern inline void invalidate_dcache_line(unsigned long addr)
83 __asm__ __volatile__(
84 ".set noreorder\n\t"
85 ".set mips3\n\t"
86 "cache %1, (%0)\n\t"
87 ".set mips0\n\t"
88 ".set reorder"
90 : "r" (addr),
91 "i" (Hit_Invalidate_D));
94 extern inline void invalidate_scache_line(unsigned long addr)
96 __asm__ __volatile__(
97 ".set noreorder\n\t"
98 ".set mips3\n\t"
99 "cache %1, (%0)\n\t"
100 ".set mips0\n\t"
101 ".set reorder"
103 : "r" (addr),
104 "i" (Hit_Invalidate_SD));
107 extern inline void flush_scache_line(unsigned long addr)
109 __asm__ __volatile__(
110 ".set noreorder\n\t"
111 ".set mips3\n\t"
112 "cache %1, (%0)\n\t"
113 ".set mips0\n\t"
114 ".set reorder"
116 : "r" (addr),
117 "i" (Hit_Writeback_Inv_SD));
121 * The next two are for badland addresses like signal trampolines.
123 extern inline void protected_flush_icache_line(unsigned long addr)
125 __asm__ __volatile__(
126 ".set noreorder\n\t"
127 ".set mips3\n"
128 "1:\tcache %1,(%0)\n"
129 "2:\t.set mips0\n\t"
130 ".set reorder\n\t"
131 ".section\t__ex_table,\"a\"\n\t"
132 STR(PTR)"\t1b,2b\n\t"
133 ".previous"
135 : "r" (addr),
136 "i" (Hit_Invalidate_I));
139 extern inline void protected_writeback_dcache_line(unsigned long addr)
141 __asm__ __volatile__(
142 ".set noreorder\n\t"
143 ".set mips3\n"
144 "1:\tcache %1,(%0)\n"
145 "2:\t.set mips0\n\t"
146 ".set reorder\n\t"
147 ".section\t__ex_table,\"a\"\n\t"
148 STR(PTR)"\t1b,2b\n\t"
149 ".previous"
151 : "r" (addr),
152 "i" (Hit_Writeback_D));
155 #define cache16_unroll32(base,op) \
156 __asm__ __volatile__(" \
157 .set noreorder; \
158 .set mips3; \
159 cache %1, 0x000(%0); cache %1, 0x010(%0); \
160 cache %1, 0x020(%0); cache %1, 0x030(%0); \
161 cache %1, 0x040(%0); cache %1, 0x050(%0); \
162 cache %1, 0x060(%0); cache %1, 0x070(%0); \
163 cache %1, 0x080(%0); cache %1, 0x090(%0); \
164 cache %1, 0x0a0(%0); cache %1, 0x0b0(%0); \
165 cache %1, 0x0c0(%0); cache %1, 0x0d0(%0); \
166 cache %1, 0x0e0(%0); cache %1, 0x0f0(%0); \
167 cache %1, 0x100(%0); cache %1, 0x110(%0); \
168 cache %1, 0x120(%0); cache %1, 0x130(%0); \
169 cache %1, 0x140(%0); cache %1, 0x150(%0); \
170 cache %1, 0x160(%0); cache %1, 0x170(%0); \
171 cache %1, 0x180(%0); cache %1, 0x190(%0); \
172 cache %1, 0x1a0(%0); cache %1, 0x1b0(%0); \
173 cache %1, 0x1c0(%0); cache %1, 0x1d0(%0); \
174 cache %1, 0x1e0(%0); cache %1, 0x1f0(%0); \
175 .set mips0; \
176 .set reorder" \
178 : "r" (base), \
179 "i" (op));
181 extern inline void blast_dcache16(void)
183 unsigned long start = KSEG0;
184 unsigned long end = (start + dcache_size);
186 while(start < end) {
187 cache16_unroll32(start,Index_Writeback_Inv_D);
188 start += 0x200;
192 extern inline void blast_dcache16_page(unsigned long page)
194 unsigned long start = page;
195 unsigned long end = (start + PAGE_SIZE);
197 while(start < end) {
198 cache16_unroll32(start,Hit_Writeback_Inv_D);
199 start += 0x200;
203 extern inline void blast_dcache16_page_indexed(unsigned long page)
205 unsigned long start = page;
206 unsigned long end = (start + PAGE_SIZE);
208 while(start < end) {
209 cache16_unroll32(start,Index_Writeback_Inv_D);
210 start += 0x200;
214 extern inline void blast_icache16(void)
216 unsigned long start = KSEG0;
217 unsigned long end = (start + icache_size);
219 while(start < end) {
220 cache16_unroll32(start,Index_Invalidate_I);
221 start += 0x200;
225 extern inline void blast_icache16_page(unsigned long page)
227 unsigned long start = page;
228 unsigned long end = (start + PAGE_SIZE);
230 while(start < end) {
231 cache16_unroll32(start,Hit_Invalidate_I);
232 start += 0x200;
236 extern inline void blast_icache16_page_indexed(unsigned long page)
238 unsigned long start = page;
239 unsigned long end = (start + PAGE_SIZE);
241 while(start < end) {
242 cache16_unroll32(start,Index_Invalidate_I);
243 start += 0x200;
247 extern inline void blast_scache16(void)
249 unsigned long start = KSEG0;
250 unsigned long end = KSEG0 + scache_size;
252 while(start < end) {
253 cache16_unroll32(start,Index_Writeback_Inv_SD);
254 start += 0x200;
258 extern inline void blast_scache16_page(unsigned long page)
260 unsigned long start = page;
261 unsigned long end = page + PAGE_SIZE;
263 while(start < end) {
264 cache16_unroll32(start,Hit_Writeback_Inv_SD);
265 start += 0x200;
269 extern inline void blast_scache16_page_indexed(unsigned long page)
271 unsigned long start = page;
272 unsigned long end = page + PAGE_SIZE;
274 while(start < end) {
275 cache16_unroll32(start,Index_Writeback_Inv_SD);
276 start += 0x200;
280 #define cache32_unroll32(base,op) \
281 __asm__ __volatile__(" \
282 .set noreorder; \
283 .set mips3; \
284 cache %1, 0x000(%0); cache %1, 0x020(%0); \
285 cache %1, 0x040(%0); cache %1, 0x060(%0); \
286 cache %1, 0x080(%0); cache %1, 0x0a0(%0); \
287 cache %1, 0x0c0(%0); cache %1, 0x0e0(%0); \
288 cache %1, 0x100(%0); cache %1, 0x120(%0); \
289 cache %1, 0x140(%0); cache %1, 0x160(%0); \
290 cache %1, 0x180(%0); cache %1, 0x1a0(%0); \
291 cache %1, 0x1c0(%0); cache %1, 0x1e0(%0); \
292 cache %1, 0x200(%0); cache %1, 0x220(%0); \
293 cache %1, 0x240(%0); cache %1, 0x260(%0); \
294 cache %1, 0x280(%0); cache %1, 0x2a0(%0); \
295 cache %1, 0x2c0(%0); cache %1, 0x2e0(%0); \
296 cache %1, 0x300(%0); cache %1, 0x320(%0); \
297 cache %1, 0x340(%0); cache %1, 0x360(%0); \
298 cache %1, 0x380(%0); cache %1, 0x3a0(%0); \
299 cache %1, 0x3c0(%0); cache %1, 0x3e0(%0); \
300 .set mips0; \
301 .set reorder" \
303 : "r" (base), \
304 "i" (op));
306 extern inline void blast_dcache32(void)
308 unsigned long start = KSEG0;
309 unsigned long end = (start + dcache_size);
311 while(start < end) {
312 cache32_unroll32(start,Index_Writeback_Inv_D);
313 start += 0x400;
318 * Call this function only with interrupts disabled or R4600 V2.0 may blow
319 * up on you.
321 * R4600 v2.0 bug: "The CACHE instructions Hit_Writeback_Inv_D,
322 * Hit_Writeback_D, Hit_Invalidate_D and Create_Dirty_Excl_D will only
323 * operate correctly if the internal data cache refill buffer is empty. These
324 * CACHE instructions should be separated from any potential data cache miss
325 * by a load instruction to an uncached address to empty the response buffer."
326 * (Revision 2.0 device errata from IDT available on http://www.idt.com/
327 * in .pdf format.)
329 extern inline void blast_dcache32_page(unsigned long page)
331 unsigned long start = page;
332 unsigned long end = (start + PAGE_SIZE);
335 * Sigh ... workaround for R4600 v1.7 bug. Explanation see above.
337 *(volatile unsigned long *)KSEG1;
339 __asm__ __volatile__("nop;nop;nop;nop");
340 while(start < end) {
341 cache32_unroll32(start,Hit_Writeback_Inv_D);
342 start += 0x400;
346 extern inline void blast_dcache32_page_indexed(unsigned long page)
348 unsigned long start = page;
349 unsigned long end = (start + PAGE_SIZE);
351 while(start < end) {
352 cache32_unroll32(start,Index_Writeback_Inv_D);
353 start += 0x400;
357 extern inline void blast_icache32(void)
359 unsigned long start = KSEG0;
360 unsigned long end = (start + icache_size);
362 while(start < end) {
363 cache32_unroll32(start,Index_Invalidate_I);
364 start += 0x400;
368 extern inline void blast_icache32_page(unsigned long page)
370 unsigned long start = page;
371 unsigned long end = (start + PAGE_SIZE);
373 while(start < end) {
374 cache32_unroll32(start,Hit_Invalidate_I);
375 start += 0x400;
379 extern inline void blast_icache32_page_indexed(unsigned long page)
381 unsigned long start = page;
382 unsigned long end = (start + PAGE_SIZE);
384 while(start < end) {
385 cache32_unroll32(start,Index_Invalidate_I);
386 start += 0x400;
390 extern inline void blast_scache32(void)
392 unsigned long start = KSEG0;
393 unsigned long end = KSEG0 + scache_size;
395 while(start < end) {
396 cache32_unroll32(start,Index_Writeback_Inv_SD);
397 start += 0x400;
401 extern inline void blast_scache32_page(unsigned long page)
403 unsigned long start = page;
404 unsigned long end = page + PAGE_SIZE;
406 while(start < end) {
407 cache32_unroll32(start,Hit_Writeback_Inv_SD);
408 start += 0x400;
412 extern inline void blast_scache32_page_indexed(unsigned long page)
414 unsigned long start = page;
415 unsigned long end = page + PAGE_SIZE;
417 while(start < end) {
418 cache32_unroll32(start,Index_Writeback_Inv_SD);
419 start += 0x400;
423 #define cache64_unroll32(base,op) \
424 __asm__ __volatile__(" \
425 .set noreorder; \
426 .set mips3; \
427 cache %1, 0x000(%0); cache %1, 0x040(%0); \
428 cache %1, 0x080(%0); cache %1, 0x0c0(%0); \
429 cache %1, 0x100(%0); cache %1, 0x140(%0); \
430 cache %1, 0x180(%0); cache %1, 0x1c0(%0); \
431 cache %1, 0x200(%0); cache %1, 0x240(%0); \
432 cache %1, 0x280(%0); cache %1, 0x2c0(%0); \
433 cache %1, 0x300(%0); cache %1, 0x340(%0); \
434 cache %1, 0x380(%0); cache %1, 0x3c0(%0); \
435 cache %1, 0x400(%0); cache %1, 0x440(%0); \
436 cache %1, 0x480(%0); cache %1, 0x4c0(%0); \
437 cache %1, 0x500(%0); cache %1, 0x540(%0); \
438 cache %1, 0x580(%0); cache %1, 0x5c0(%0); \
439 cache %1, 0x600(%0); cache %1, 0x640(%0); \
440 cache %1, 0x680(%0); cache %1, 0x6c0(%0); \
441 cache %1, 0x700(%0); cache %1, 0x740(%0); \
442 cache %1, 0x780(%0); cache %1, 0x7c0(%0); \
443 .set mips0; \
444 .set reorder" \
446 : "r" (base), \
447 "i" (op));
449 extern inline void blast_scache64(void)
451 unsigned long start = KSEG0;
452 unsigned long end = KSEG0 + scache_size;
454 while(start < end) {
455 cache64_unroll32(start,Index_Writeback_Inv_SD);
456 start += 0x800;
460 extern inline void blast_scache64_page(unsigned long page)
462 unsigned long start = page;
463 unsigned long end = page + PAGE_SIZE;
465 while(start < end) {
466 cache64_unroll32(start,Hit_Writeback_Inv_SD);
467 start += 0x800;
471 extern inline void blast_scache64_page_indexed(unsigned long page)
473 unsigned long start = page;
474 unsigned long end = page + PAGE_SIZE;
476 while(start < end) {
477 cache64_unroll32(start,Index_Writeback_Inv_SD);
478 start += 0x800;
482 #define cache128_unroll32(base,op) \
483 __asm__ __volatile__(" \
484 .set noreorder; \
485 .set mips3; \
486 cache %1, 0x000(%0); cache %1, 0x080(%0); \
487 cache %1, 0x100(%0); cache %1, 0x180(%0); \
488 cache %1, 0x200(%0); cache %1, 0x280(%0); \
489 cache %1, 0x300(%0); cache %1, 0x380(%0); \
490 cache %1, 0x400(%0); cache %1, 0x480(%0); \
491 cache %1, 0x500(%0); cache %1, 0x580(%0); \
492 cache %1, 0x600(%0); cache %1, 0x680(%0); \
493 cache %1, 0x700(%0); cache %1, 0x780(%0); \
494 cache %1, 0x800(%0); cache %1, 0x880(%0); \
495 cache %1, 0x900(%0); cache %1, 0x980(%0); \
496 cache %1, 0xa00(%0); cache %1, 0xa80(%0); \
497 cache %1, 0xb00(%0); cache %1, 0xb80(%0); \
498 cache %1, 0xc00(%0); cache %1, 0xc80(%0); \
499 cache %1, 0xd00(%0); cache %1, 0xd80(%0); \
500 cache %1, 0xe00(%0); cache %1, 0xe80(%0); \
501 cache %1, 0xf00(%0); cache %1, 0xf80(%0); \
502 .set mips0; \
503 .set reorder" \
505 : "r" (base), \
506 "i" (op));
508 extern inline void blast_scache128(void)
510 unsigned long start = KSEG0;
511 unsigned long end = KSEG0 + scache_size;
513 while(start < end) {
514 cache128_unroll32(start,Index_Writeback_Inv_SD);
515 start += 0x1000;
519 extern inline void blast_scache128_page(unsigned long page)
521 cache128_unroll32(page,Hit_Writeback_Inv_SD);
524 extern inline void blast_scache128_page_indexed(unsigned long page)
526 cache128_unroll32(page,Index_Writeback_Inv_SD);
529 #endif /* !(_MIPS_R4KCACHE_H) */