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 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
7 * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Ralf Baechle (ralf@gnu.org)
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10 #include <linux/hardirq.h>
11 #include <linux/init.h>
12 #include <linux/highmem.h>
13 #include <linux/kernel.h>
14 #include <linux/linkage.h>
15 #include <linux/sched.h>
17 #include <linux/bitops.h>
19 #include <asm/bcache.h>
20 #include <asm/bootinfo.h>
21 #include <asm/cache.h>
22 #include <asm/cacheops.h>
24 #include <asm/cpu-features.h>
27 #include <asm/pgtable.h>
28 #include <asm/r4kcache.h>
29 #include <asm/sections.h>
30 #include <asm/system.h>
31 #include <asm/mmu_context.h>
33 #include <asm/cacheflush.h> /* for run_uncached() */
37 * Special Variant of smp_call_function for use by cache functions:
40 * o collapses to normal function call on UP kernels
41 * o collapses to normal function call on systems with a single shared
44 static inline void r4k_on_each_cpu(void (*func
) (void *info
), void *info
,
49 #if !defined(CONFIG_MIPS_MT_SMP) && !defined(CONFIG_MIPS_MT_SMTC)
50 smp_call_function(func
, info
, retry
, wait
);
59 static unsigned long icache_size __read_mostly
;
60 static unsigned long dcache_size __read_mostly
;
61 static unsigned long scache_size __read_mostly
;
64 * Dummy cache handling routines for machines without boardcaches
66 static void cache_noop(void) {}
68 static struct bcache_ops no_sc_ops
= {
69 .bc_enable
= (void *)cache_noop
,
70 .bc_disable
= (void *)cache_noop
,
71 .bc_wback_inv
= (void *)cache_noop
,
72 .bc_inv
= (void *)cache_noop
75 struct bcache_ops
*bcops
= &no_sc_ops
;
77 #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
78 #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
80 #define R4600_HIT_CACHEOP_WAR_IMPL \
82 if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x()) \
83 *(volatile unsigned long *)CKSEG1; \
84 if (R4600_V1_HIT_CACHEOP_WAR) \
85 __asm__ __volatile__("nop;nop;nop;nop"); \
88 static void (*r4k_blast_dcache_page
)(unsigned long addr
);
90 static inline void r4k_blast_dcache_page_dc32(unsigned long addr
)
92 R4600_HIT_CACHEOP_WAR_IMPL
;
93 blast_dcache32_page(addr
);
96 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
97 static void __init
r4k_blast_dcache_page_setup(void)
99 static void __cpuinit
r4k_blast_dcache_page_setup(void)
100 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
102 unsigned long dc_lsize
= cpu_dcache_line_size();
105 r4k_blast_dcache_page
= (void *)cache_noop
;
106 else if (dc_lsize
== 16)
107 r4k_blast_dcache_page
= blast_dcache16_page
;
108 else if (dc_lsize
== 32)
109 r4k_blast_dcache_page
= r4k_blast_dcache_page_dc32
;
112 static void (* r4k_blast_dcache_page_indexed
)(unsigned long addr
);
114 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
115 static void __init
r4k_blast_dcache_page_indexed_setup(void)
117 static void __cpuinit
r4k_blast_dcache_page_indexed_setup(void)
118 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
120 unsigned long dc_lsize
= cpu_dcache_line_size();
123 r4k_blast_dcache_page_indexed
= (void *)cache_noop
;
124 else if (dc_lsize
== 16)
125 r4k_blast_dcache_page_indexed
= blast_dcache16_page_indexed
;
126 else if (dc_lsize
== 32)
127 r4k_blast_dcache_page_indexed
= blast_dcache32_page_indexed
;
130 static void (* r4k_blast_dcache
)(void);
132 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
133 static void __init
r4k_blast_dcache_setup(void)
135 static void __cpuinit
r4k_blast_dcache_setup(void)
136 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
138 unsigned long dc_lsize
= cpu_dcache_line_size();
141 r4k_blast_dcache
= (void *)cache_noop
;
142 else if (dc_lsize
== 16)
143 r4k_blast_dcache
= blast_dcache16
;
144 else if (dc_lsize
== 32)
145 r4k_blast_dcache
= blast_dcache32
;
148 /* force code alignment (used for TX49XX_ICACHE_INDEX_INV_WAR) */
149 #define JUMP_TO_ALIGN(order) \
150 __asm__ __volatile__( \
152 ".align\t" #order "\n\t" \
155 #define CACHE32_UNROLL32_ALIGN JUMP_TO_ALIGN(10) /* 32 * 32 = 1024 */
156 #define CACHE32_UNROLL32_ALIGN2 JUMP_TO_ALIGN(11)
158 static inline void blast_r4600_v1_icache32(void)
162 local_irq_save(flags
);
164 local_irq_restore(flags
);
167 static inline void tx49_blast_icache32(void)
169 unsigned long start
= INDEX_BASE
;
170 unsigned long end
= start
+ current_cpu_data
.icache
.waysize
;
171 unsigned long ws_inc
= 1UL << current_cpu_data
.icache
.waybit
;
172 unsigned long ws_end
= current_cpu_data
.icache
.ways
<<
173 current_cpu_data
.icache
.waybit
;
174 unsigned long ws
, addr
;
176 CACHE32_UNROLL32_ALIGN2
;
177 /* I'm in even chunk. blast odd chunks */
178 for (ws
= 0; ws
< ws_end
; ws
+= ws_inc
)
179 for (addr
= start
+ 0x400; addr
< end
; addr
+= 0x400 * 2)
180 cache32_unroll32(addr
|ws
, Index_Invalidate_I
);
181 CACHE32_UNROLL32_ALIGN
;
182 /* I'm in odd chunk. blast even chunks */
183 for (ws
= 0; ws
< ws_end
; ws
+= ws_inc
)
184 for (addr
= start
; addr
< end
; addr
+= 0x400 * 2)
185 cache32_unroll32(addr
|ws
, Index_Invalidate_I
);
188 static inline void blast_icache32_r4600_v1_page_indexed(unsigned long page
)
192 local_irq_save(flags
);
193 blast_icache32_page_indexed(page
);
194 local_irq_restore(flags
);
197 static inline void tx49_blast_icache32_page_indexed(unsigned long page
)
199 unsigned long indexmask
= current_cpu_data
.icache
.waysize
- 1;
200 unsigned long start
= INDEX_BASE
+ (page
& indexmask
);
201 unsigned long end
= start
+ PAGE_SIZE
;
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
;
207 CACHE32_UNROLL32_ALIGN2
;
208 /* I'm in even chunk. blast odd chunks */
209 for (ws
= 0; ws
< ws_end
; ws
+= ws_inc
)
210 for (addr
= start
+ 0x400; addr
< end
; addr
+= 0x400 * 2)
211 cache32_unroll32(addr
|ws
, Index_Invalidate_I
);
212 CACHE32_UNROLL32_ALIGN
;
213 /* I'm in odd chunk. blast even chunks */
214 for (ws
= 0; ws
< ws_end
; ws
+= ws_inc
)
215 for (addr
= start
; addr
< end
; addr
+= 0x400 * 2)
216 cache32_unroll32(addr
|ws
, Index_Invalidate_I
);
219 static void (* r4k_blast_icache_page
)(unsigned long addr
);
221 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
222 static void __init
r4k_blast_icache_page_setup(void)
224 static void __cpuinit
r4k_blast_icache_page_setup(void)
225 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
227 unsigned long ic_lsize
= cpu_icache_line_size();
230 r4k_blast_icache_page
= (void *)cache_noop
;
231 else if (ic_lsize
== 16)
232 r4k_blast_icache_page
= blast_icache16_page
;
233 else if (ic_lsize
== 32)
234 r4k_blast_icache_page
= blast_icache32_page
;
235 else if (ic_lsize
== 64)
236 r4k_blast_icache_page
= blast_icache64_page
;
240 static void (* r4k_blast_icache_page_indexed
)(unsigned long addr
);
242 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
243 static void __init
r4k_blast_icache_page_indexed_setup(void)
245 static void __cpuinit
r4k_blast_icache_page_indexed_setup(void)
246 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
248 unsigned long ic_lsize
= cpu_icache_line_size();
251 r4k_blast_icache_page_indexed
= (void *)cache_noop
;
252 else if (ic_lsize
== 16)
253 r4k_blast_icache_page_indexed
= blast_icache16_page_indexed
;
254 else if (ic_lsize
== 32) {
255 if (R4600_V1_INDEX_ICACHEOP_WAR
&& cpu_is_r4600_v1_x())
256 r4k_blast_icache_page_indexed
=
257 blast_icache32_r4600_v1_page_indexed
;
258 else if (TX49XX_ICACHE_INDEX_INV_WAR
)
259 r4k_blast_icache_page_indexed
=
260 tx49_blast_icache32_page_indexed
;
262 r4k_blast_icache_page_indexed
=
263 blast_icache32_page_indexed
;
264 } else if (ic_lsize
== 64)
265 r4k_blast_icache_page_indexed
= blast_icache64_page_indexed
;
268 static void (* r4k_blast_icache
)(void);
270 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
271 static void __init
r4k_blast_icache_setup(void)
273 static void __cpuinit
r4k_blast_icache_setup(void)
274 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
276 unsigned long ic_lsize
= cpu_icache_line_size();
279 r4k_blast_icache
= (void *)cache_noop
;
280 else if (ic_lsize
== 16)
281 r4k_blast_icache
= blast_icache16
;
282 else if (ic_lsize
== 32) {
283 if (R4600_V1_INDEX_ICACHEOP_WAR
&& cpu_is_r4600_v1_x())
284 r4k_blast_icache
= blast_r4600_v1_icache32
;
285 else if (TX49XX_ICACHE_INDEX_INV_WAR
)
286 r4k_blast_icache
= tx49_blast_icache32
;
288 r4k_blast_icache
= blast_icache32
;
289 } else if (ic_lsize
== 64)
290 r4k_blast_icache
= blast_icache64
;
293 static void (* r4k_blast_scache_page
)(unsigned long addr
);
295 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
296 static void __init
r4k_blast_scache_page_setup(void)
298 static void __cpuinit
r4k_blast_scache_page_setup(void)
299 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
301 unsigned long sc_lsize
= cpu_scache_line_size();
303 if (scache_size
== 0)
304 r4k_blast_scache_page
= (void *)cache_noop
;
305 else if (sc_lsize
== 16)
306 r4k_blast_scache_page
= blast_scache16_page
;
307 else if (sc_lsize
== 32)
308 r4k_blast_scache_page
= blast_scache32_page
;
309 else if (sc_lsize
== 64)
310 r4k_blast_scache_page
= blast_scache64_page
;
311 else if (sc_lsize
== 128)
312 r4k_blast_scache_page
= blast_scache128_page
;
315 static void (* r4k_blast_scache_page_indexed
)(unsigned long addr
);
317 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
318 static void __init
r4k_blast_scache_page_indexed_setup(void)
320 static void __cpuinit
r4k_blast_scache_page_indexed_setup(void)
321 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
323 unsigned long sc_lsize
= cpu_scache_line_size();
325 if (scache_size
== 0)
326 r4k_blast_scache_page_indexed
= (void *)cache_noop
;
327 else if (sc_lsize
== 16)
328 r4k_blast_scache_page_indexed
= blast_scache16_page_indexed
;
329 else if (sc_lsize
== 32)
330 r4k_blast_scache_page_indexed
= blast_scache32_page_indexed
;
331 else if (sc_lsize
== 64)
332 r4k_blast_scache_page_indexed
= blast_scache64_page_indexed
;
333 else if (sc_lsize
== 128)
334 r4k_blast_scache_page_indexed
= blast_scache128_page_indexed
;
337 static void (* r4k_blast_scache
)(void);
339 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
340 static void __init
r4k_blast_scache_setup(void)
342 static void __cpuinit
r4k_blast_scache_setup(void)
343 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
345 unsigned long sc_lsize
= cpu_scache_line_size();
347 if (scache_size
== 0)
348 r4k_blast_scache
= (void *)cache_noop
;
349 else if (sc_lsize
== 16)
350 r4k_blast_scache
= blast_scache16
;
351 else if (sc_lsize
== 32)
352 r4k_blast_scache
= blast_scache32
;
353 else if (sc_lsize
== 64)
354 r4k_blast_scache
= blast_scache64
;
355 else if (sc_lsize
== 128)
356 r4k_blast_scache
= blast_scache128
;
359 static inline void local_r4k___flush_cache_all(void * args
)
361 #if defined(CONFIG_CPU_LOONGSON2)
368 switch (current_cpu_type()) {
380 static void r4k___flush_cache_all(void)
382 r4k_on_each_cpu(local_r4k___flush_cache_all
, NULL
, 1, 1);
385 static inline int has_valid_asid(const struct mm_struct
*mm
)
387 #if defined(CONFIG_MIPS_MT_SMP) || defined(CONFIG_MIPS_MT_SMTC)
390 for_each_online_cpu(i
)
391 if (cpu_context(i
, mm
))
396 return cpu_context(smp_processor_id(), mm
);
400 static inline void local_r4k_flush_cache_range(void * args
)
402 struct vm_area_struct
*vma
= args
;
403 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
405 int exec
= vma
->vm_flags
& VM_EXEC
;
406 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
408 if (!(has_valid_asid(vma
->vm_mm
)))
412 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
416 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
419 static void r4k_flush_cache_range(struct vm_area_struct
*vma
,
420 unsigned long start
, unsigned long end
)
422 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
423 if (!cpu_has_dc_aliases
)
426 int exec
= vma
->vm_flags
& VM_EXEC
;
427 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
429 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
430 r4k_on_each_cpu(local_r4k_flush_cache_range
, vma
, 1, 1);
432 if (cpu_has_dc_aliases
|| (exec
&& !cpu_has_ic_fills_f_dc
))
433 r4k_on_each_cpu(local_r4k_flush_cache_range
, vma
, 1, 1);
434 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
437 static inline void local_r4k_flush_cache_mm(void * args
)
439 struct mm_struct
*mm
= args
;
441 if (!has_valid_asid(mm
))
445 * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we
446 * only flush the primary caches but R10000 and R12000 behave sane ...
447 * R4000SC and R4400SC indexed S-cache ops also invalidate primary
448 * caches, so we can bail out early.
450 if (current_cpu_type() == CPU_R4000SC
||
451 current_cpu_type() == CPU_R4000MC
||
452 current_cpu_type() == CPU_R4400SC
||
453 current_cpu_type() == CPU_R4400MC
) {
461 static void r4k_flush_cache_mm(struct mm_struct
*mm
)
463 if (!cpu_has_dc_aliases
)
466 r4k_on_each_cpu(local_r4k_flush_cache_mm
, mm
, 1, 1);
469 struct flush_cache_page_args
{
470 struct vm_area_struct
*vma
;
475 static inline void local_r4k_flush_cache_page(void *args
)
477 struct flush_cache_page_args
*fcp_args
= args
;
478 struct vm_area_struct
*vma
= fcp_args
->vma
;
479 unsigned long addr
= fcp_args
->addr
;
480 struct page
*page
= pfn_to_page(fcp_args
->pfn
);
481 int exec
= vma
->vm_flags
& VM_EXEC
;
482 struct mm_struct
*mm
= vma
->vm_mm
;
490 * If ownes no valid ASID yet, cannot possibly have gotten
491 * this page into the cache.
493 if (!has_valid_asid(mm
))
497 pgdp
= pgd_offset(mm
, addr
);
498 pudp
= pud_offset(pgdp
, addr
);
499 pmdp
= pmd_offset(pudp
, addr
);
500 ptep
= pte_offset(pmdp
, addr
);
503 * If the page isn't marked valid, the page cannot possibly be
506 if (!(pte_present(*ptep
)))
509 if ((mm
== current
->active_mm
) && (pte_val(*ptep
) & _PAGE_VALID
))
513 * Use kmap_coherent or kmap_atomic to do flushes for
514 * another ASID than the current one.
516 if (cpu_has_dc_aliases
)
517 vaddr
= kmap_coherent(page
, addr
);
519 vaddr
= kmap_atomic(page
, KM_USER0
);
520 addr
= (unsigned long)vaddr
;
523 if (cpu_has_dc_aliases
|| (exec
&& !cpu_has_ic_fills_f_dc
)) {
524 r4k_blast_dcache_page(addr
);
527 if (vaddr
&& cpu_has_vtag_icache
&& mm
== current
->active_mm
) {
528 int cpu
= smp_processor_id();
530 if (cpu_context(cpu
, mm
) != 0)
531 drop_mmu_context(mm
, cpu
);
533 r4k_blast_icache_page(addr
);
537 if (cpu_has_dc_aliases
)
540 kunmap_atomic(vaddr
, KM_USER0
);
544 static void r4k_flush_cache_page(struct vm_area_struct
*vma
,
545 unsigned long addr
, unsigned long pfn
)
547 struct flush_cache_page_args args
;
553 r4k_on_each_cpu(local_r4k_flush_cache_page
, &args
, 1, 1);
556 static inline void local_r4k_flush_data_cache_page(void * addr
)
558 r4k_blast_dcache_page((unsigned long) addr
);
561 static void r4k_flush_data_cache_page(unsigned long addr
)
564 local_r4k_flush_data_cache_page((void *)addr
);
566 r4k_on_each_cpu(local_r4k_flush_data_cache_page
, (void *) addr
,
570 struct flush_icache_range_args
{
575 static inline void local_r4k_flush_icache_range(void *args
)
577 struct flush_icache_range_args
*fir_args
= args
;
578 unsigned long start
= fir_args
->start
;
579 unsigned long end
= fir_args
->end
;
581 if (!cpu_has_ic_fills_f_dc
) {
582 if (end
- start
>= dcache_size
) {
585 R4600_HIT_CACHEOP_WAR_IMPL
;
586 protected_blast_dcache_range(start
, end
);
590 if (end
- start
> icache_size
)
593 protected_blast_icache_range(start
, end
);
596 static void r4k_flush_icache_range(unsigned long start
, unsigned long end
)
598 struct flush_icache_range_args args
;
603 r4k_on_each_cpu(local_r4k_flush_icache_range
, &args
, 1, 1);
604 instruction_hazard();
607 #ifdef CONFIG_DMA_NONCOHERENT
609 static void r4k_dma_cache_wback_inv(unsigned long addr
, unsigned long size
)
611 /* Catch bad driver code */
614 if (cpu_has_inclusive_pcaches
) {
615 if (size
>= scache_size
)
618 blast_scache_range(addr
, addr
+ size
);
623 * Either no secondary cache or the available caches don't have the
624 * subset property so we have to flush the primary caches
627 if (size
>= dcache_size
) {
630 R4600_HIT_CACHEOP_WAR_IMPL
;
631 blast_dcache_range(addr
, addr
+ size
);
634 bc_wback_inv(addr
, size
);
637 static void r4k_dma_cache_inv(unsigned long addr
, unsigned long size
)
639 /* Catch bad driver code */
642 if (cpu_has_inclusive_pcaches
) {
643 if (size
>= scache_size
)
646 blast_inv_scache_range(addr
, addr
+ size
);
650 if (size
>= dcache_size
) {
653 R4600_HIT_CACHEOP_WAR_IMPL
;
654 blast_inv_dcache_range(addr
, addr
+ size
);
659 #endif /* CONFIG_DMA_NONCOHERENT */
662 * While we're protected against bad userland addresses we don't care
663 * very much about what happens in that case. Usually a segmentation
664 * fault will dump the process later on anyway ...
666 static void local_r4k_flush_cache_sigtramp(void * arg
)
668 unsigned long ic_lsize
= cpu_icache_line_size();
669 unsigned long dc_lsize
= cpu_dcache_line_size();
670 unsigned long sc_lsize
= cpu_scache_line_size();
671 unsigned long addr
= (unsigned long) arg
;
673 R4600_HIT_CACHEOP_WAR_IMPL
;
675 protected_writeback_dcache_line(addr
& ~(dc_lsize
- 1));
676 if (!cpu_icache_snoops_remote_store
&& scache_size
)
677 protected_writeback_scache_line(addr
& ~(sc_lsize
- 1));
679 protected_flush_icache_line(addr
& ~(ic_lsize
- 1));
680 if (MIPS4K_ICACHE_REFILL_WAR
) {
681 __asm__
__volatile__ (
696 : "i" (Hit_Invalidate_I
));
698 if (MIPS_CACHE_SYNC_WAR
)
699 __asm__
__volatile__ ("sync");
702 static void r4k_flush_cache_sigtramp(unsigned long addr
)
704 r4k_on_each_cpu(local_r4k_flush_cache_sigtramp
, (void *) addr
, 1, 1);
707 static void r4k_flush_icache_all(void)
709 if (cpu_has_vtag_icache
)
713 static inline void rm7k_erratum31(void)
715 const unsigned long ic_lsize
= 32;
718 /* RM7000 erratum #31. The icache is screwed at startup. */
722 for (addr
= INDEX_BASE
; addr
<= INDEX_BASE
+ 4096; addr
+= ic_lsize
) {
723 __asm__
__volatile__ (
727 "cache\t%1, 0(%0)\n\t"
728 "cache\t%1, 0x1000(%0)\n\t"
729 "cache\t%1, 0x2000(%0)\n\t"
730 "cache\t%1, 0x3000(%0)\n\t"
731 "cache\t%2, 0(%0)\n\t"
732 "cache\t%2, 0x1000(%0)\n\t"
733 "cache\t%2, 0x2000(%0)\n\t"
734 "cache\t%2, 0x3000(%0)\n\t"
735 "cache\t%1, 0(%0)\n\t"
736 "cache\t%1, 0x1000(%0)\n\t"
737 "cache\t%1, 0x2000(%0)\n\t"
738 "cache\t%1, 0x3000(%0)\n\t"
741 : "r" (addr
), "i" (Index_Store_Tag_I
), "i" (Fill
));
745 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
746 static char *way_string
[] __initdata
= { NULL
, "direct mapped", "2-way",
748 static char *way_string
[] __cpuinitdata
= { NULL
, "direct mapped", "2-way",
749 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
750 "3-way", "4-way", "5-way", "6-way", "7-way", "8-way"
753 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
754 static void __init
probe_pcache(void)
756 static void __cpuinit
probe_pcache(void)
757 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
759 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
760 unsigned int config
= read_c0_config();
761 unsigned int prid
= read_c0_prid();
762 unsigned long config1
;
765 switch (c
->cputype
) {
766 case CPU_R4600
: /* QED style two way caches? */
770 icache_size
= 1 << (12 + ((config
& CONF_IC
) >> 9));
771 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
773 c
->icache
.waybit
= __ffs(icache_size
/2);
775 dcache_size
= 1 << (12 + ((config
& CONF_DC
) >> 6));
776 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
778 c
->dcache
.waybit
= __ffs(dcache_size
/2);
780 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
785 icache_size
= 1 << (12 + ((config
& CONF_IC
) >> 9));
786 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
790 dcache_size
= 1 << (12 + ((config
& CONF_DC
) >> 6));
791 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
793 c
->dcache
.waybit
= 0;
795 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
799 icache_size
= 1 << (12 + ((config
& CONF_IC
) >> 9));
800 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
804 dcache_size
= 1 << (12 + ((config
& CONF_DC
) >> 6));
805 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
807 c
->dcache
.waybit
= 0;
809 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
810 c
->options
|= MIPS_CPU_PREFETCH
;
820 icache_size
= 1 << (12 + ((config
& CONF_IC
) >> 9));
821 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
823 c
->icache
.waybit
= 0; /* doesn't matter */
825 dcache_size
= 1 << (12 + ((config
& CONF_DC
) >> 6));
826 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
828 c
->dcache
.waybit
= 0; /* does not matter */
830 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
836 icache_size
= 1 << (12 + ((config
& R10K_CONF_IC
) >> 29));
837 c
->icache
.linesz
= 64;
839 c
->icache
.waybit
= 0;
841 dcache_size
= 1 << (12 + ((config
& R10K_CONF_DC
) >> 26));
842 c
->dcache
.linesz
= 32;
844 c
->dcache
.waybit
= 0;
846 c
->options
|= MIPS_CPU_PREFETCH
;
850 write_c0_config(config
& ~VR41_CONF_P4K
);
852 /* Workaround for cache instruction bug of VR4131 */
853 if (c
->processor_id
== 0x0c80U
|| c
->processor_id
== 0x0c81U
||
854 c
->processor_id
== 0x0c82U
) {
855 config
|= 0x00400000U
;
856 if (c
->processor_id
== 0x0c80U
)
857 config
|= VR41_CONF_BP
;
858 write_c0_config(config
);
860 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
862 icache_size
= 1 << (10 + ((config
& CONF_IC
) >> 9));
863 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
865 c
->icache
.waybit
= __ffs(icache_size
/2);
867 dcache_size
= 1 << (10 + ((config
& CONF_DC
) >> 6));
868 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
870 c
->dcache
.waybit
= __ffs(dcache_size
/2);
879 icache_size
= 1 << (10 + ((config
& CONF_IC
) >> 9));
880 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
882 c
->icache
.waybit
= 0; /* doesn't matter */
884 dcache_size
= 1 << (10 + ((config
& CONF_DC
) >> 6));
885 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
887 c
->dcache
.waybit
= 0; /* does not matter */
889 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
896 icache_size
= 1 << (12 + ((config
& CONF_IC
) >> 9));
897 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
899 c
->icache
.waybit
= __ffs(icache_size
/ c
->icache
.ways
);
901 dcache_size
= 1 << (12 + ((config
& CONF_DC
) >> 6));
902 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
904 c
->dcache
.waybit
= __ffs(dcache_size
/ c
->dcache
.ways
);
906 #if !defined(CONFIG_SMP) || !defined(RM9000_CDEX_SMP_WAR)
907 c
->options
|= MIPS_CPU_CACHE_CDEX_P
;
909 c
->options
|= MIPS_CPU_PREFETCH
;
913 icache_size
= 1 << (12 + ((config
& CONF_IC
) >> 9));
914 c
->icache
.linesz
= 16 << ((config
& CONF_IB
) >> 5);
919 c
->icache
.waybit
= 0;
921 dcache_size
= 1 << (12 + ((config
& CONF_DC
) >> 6));
922 c
->dcache
.linesz
= 16 << ((config
& CONF_DB
) >> 4);
927 c
->dcache
.waybit
= 0;
931 if (!(config
& MIPS_CONF_M
))
932 panic("Don't know how to probe P-caches on this cpu.");
935 * So we seem to be a MIPS32 or MIPS64 CPU
936 * So let's probe the I-cache ...
938 config1
= read_c0_config1();
940 if ((lsize
= ((config1
>> 19) & 7)))
941 c
->icache
.linesz
= 2 << lsize
;
943 c
->icache
.linesz
= lsize
;
944 c
->icache
.sets
= 64 << ((config1
>> 22) & 7);
945 c
->icache
.ways
= 1 + ((config1
>> 16) & 7);
947 icache_size
= c
->icache
.sets
*
950 c
->icache
.waybit
= __ffs(icache_size
/c
->icache
.ways
);
952 if (config
& 0x8) /* VI bit */
953 c
->icache
.flags
|= MIPS_CACHE_VTAG
;
956 * Now probe the MIPS32 / MIPS64 data cache.
960 if ((lsize
= ((config1
>> 10) & 7)))
961 c
->dcache
.linesz
= 2 << lsize
;
963 c
->dcache
.linesz
= lsize
;
964 c
->dcache
.sets
= 64 << ((config1
>> 13) & 7);
965 c
->dcache
.ways
= 1 + ((config1
>> 7) & 7);
967 dcache_size
= c
->dcache
.sets
*
970 c
->dcache
.waybit
= __ffs(dcache_size
/c
->dcache
.ways
);
972 c
->options
|= MIPS_CPU_PREFETCH
;
977 * Processor configuration sanity check for the R4000SC erratum
978 * #5. With page sizes larger than 32kB there is no possibility
979 * to get a VCE exception anymore so we don't care about this
980 * misconfiguration. The case is rather theoretical anyway;
981 * presumably no vendor is shipping his hardware in the "bad"
984 if ((prid
& 0xff00) == PRID_IMP_R4000
&& (prid
& 0xff) < 0x40 &&
985 !(config
& CONF_SC
) && c
->icache
.linesz
!= 16 &&
987 panic("Improper R4000SC processor configuration detected");
989 /* compute a couple of other cache variables */
990 c
->icache
.waysize
= icache_size
/ c
->icache
.ways
;
991 c
->dcache
.waysize
= dcache_size
/ c
->dcache
.ways
;
993 c
->icache
.sets
= c
->icache
.linesz
?
994 icache_size
/ (c
->icache
.linesz
* c
->icache
.ways
) : 0;
995 c
->dcache
.sets
= c
->dcache
.linesz
?
996 dcache_size
/ (c
->dcache
.linesz
* c
->dcache
.ways
) : 0;
999 * R10000 and R12000 P-caches are odd in a positive way. They're 32kB
1000 * 2-way virtually indexed so normally would suffer from aliases. So
1001 * normally they'd suffer from aliases but magic in the hardware deals
1002 * with that for us so we don't need to take care ourselves.
1004 switch (c
->cputype
) {
1009 c
->dcache
.flags
|= MIPS_CACHE_PINDEX
;
1020 if ((read_c0_config7() & (1 << 16))) {
1021 /* effectively physically indexed dcache,
1022 thus no virtual aliases. */
1023 c
->dcache
.flags
|= MIPS_CACHE_PINDEX
;
1027 if (c
->dcache
.waysize
> PAGE_SIZE
)
1028 c
->dcache
.flags
|= MIPS_CACHE_ALIASES
;
1031 switch (c
->cputype
) {
1034 * Some older 20Kc chips doesn't have the 'VI' bit in
1035 * the config register.
1037 c
->icache
.flags
|= MIPS_CACHE_VTAG
;
1047 c
->icache
.flags
|= MIPS_CACHE_IC_F_DC
;
1051 #ifdef CONFIG_CPU_LOONGSON2
1053 * LOONGSON2 has 4 way icache, but when using indexed cache op,
1054 * one op will act on all 4 ways
1059 printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
1061 cpu_has_vtag_icache
? "VIVT" : "VIPT",
1062 way_string
[c
->icache
.ways
], c
->icache
.linesz
);
1064 printk("Primary data cache %ldkB, %s, %s, %s, linesize %d bytes\n",
1065 dcache_size
>> 10, way_string
[c
->dcache
.ways
],
1066 (c
->dcache
.flags
& MIPS_CACHE_PINDEX
) ? "PIPT" : "VIPT",
1067 (c
->dcache
.flags
& MIPS_CACHE_ALIASES
) ?
1068 "cache aliases" : "no aliases",
1073 * If you even _breathe_ on this function, look at the gcc output and make sure
1074 * it does not pop things on and off the stack for the cache sizing loop that
1075 * executes in KSEG1 space or else you will crash and burn badly. You have
1078 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
1079 static int __init
probe_scache(void)
1081 static int __cpuinit
probe_scache(void)
1082 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
1084 unsigned long flags
, addr
, begin
, end
, pow2
;
1085 unsigned int config
= read_c0_config();
1086 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
1089 if (config
& CONF_SC
)
1092 begin
= (unsigned long) &_stext
;
1093 begin
&= ~((4 * 1024 * 1024) - 1);
1094 end
= begin
+ (4 * 1024 * 1024);
1097 * This is such a bitch, you'd think they would make it easy to do
1098 * this. Away you daemons of stupidity!
1100 local_irq_save(flags
);
1102 /* Fill each size-multiple cache line with a valid tag. */
1104 for (addr
= begin
; addr
< end
; addr
= (begin
+ pow2
)) {
1105 unsigned long *p
= (unsigned long *) addr
;
1106 __asm__
__volatile__("nop" : : "r" (*p
)); /* whee... */
1110 /* Load first line with zero (therefore invalid) tag. */
1113 __asm__
__volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
1114 cache_op(Index_Store_Tag_I
, begin
);
1115 cache_op(Index_Store_Tag_D
, begin
);
1116 cache_op(Index_Store_Tag_SD
, begin
);
1118 /* Now search for the wrap around point. */
1119 pow2
= (128 * 1024);
1121 for (addr
= begin
+ (128 * 1024); addr
< end
; addr
= begin
+ pow2
) {
1122 cache_op(Index_Load_Tag_SD
, addr
);
1123 __asm__
__volatile__("nop; nop; nop; nop;"); /* hazard... */
1124 if (!read_c0_taglo())
1128 local_irq_restore(flags
);
1132 c
->scache
.linesz
= 16 << ((config
& R4K_CONF_SB
) >> 22);
1134 c
->dcache
.waybit
= 0; /* does not matter */
1139 #if defined(CONFIG_CPU_LOONGSON2)
1140 static void __init
loongson2_sc_init(void)
1142 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
1144 scache_size
= 512*1024;
1145 c
->scache
.linesz
= 32;
1147 c
->scache
.waybit
= 0;
1148 c
->scache
.waysize
= scache_size
/ (c
->scache
.ways
);
1149 c
->scache
.sets
= scache_size
/ (c
->scache
.linesz
* c
->scache
.ways
);
1150 pr_info("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
1151 scache_size
>> 10, way_string
[c
->scache
.ways
], c
->scache
.linesz
);
1153 c
->options
|= MIPS_CPU_INCLUSIVE_CACHES
;
1157 extern int r5k_sc_init(void);
1158 extern int rm7k_sc_init(void);
1159 extern int mips_sc_init(void);
1161 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
1162 static void __init
setup_scache(void)
1164 static void __cpuinit
setup_scache(void)
1165 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
1167 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
1168 unsigned int config
= read_c0_config();
1172 * Do the probing thing on R4000SC and R4400SC processors. Other
1173 * processors don't have a S-cache that would be relevant to the
1174 * Linux memory management.
1176 switch (c
->cputype
) {
1181 sc_present
= run_uncached(probe_scache
);
1183 c
->options
|= MIPS_CPU_CACHE_CDEX_S
;
1189 scache_size
= 0x80000 << ((config
& R10K_CONF_SS
) >> 16);
1190 c
->scache
.linesz
= 64 << ((config
>> 13) & 1);
1192 c
->scache
.waybit
= 0;
1198 #ifdef CONFIG_R5000_CPU_SCACHE
1205 #ifdef CONFIG_RM7000_CPU_SCACHE
1210 #if defined(CONFIG_CPU_LOONGSON2)
1212 loongson2_sc_init();
1217 if (c
->isa_level
== MIPS_CPU_ISA_M32R1
||
1218 c
->isa_level
== MIPS_CPU_ISA_M32R2
||
1219 c
->isa_level
== MIPS_CPU_ISA_M64R1
||
1220 c
->isa_level
== MIPS_CPU_ISA_M64R2
) {
1221 #ifdef CONFIG_MIPS_CPU_SCACHE
1222 if (mips_sc_init ()) {
1223 scache_size
= c
->scache
.ways
* c
->scache
.sets
* c
->scache
.linesz
;
1224 printk("MIPS secondary cache %ldkB, %s, linesize %d bytes.\n",
1226 way_string
[c
->scache
.ways
], c
->scache
.linesz
);
1229 if (!(c
->scache
.flags
& MIPS_CACHE_NOT_PRESENT
))
1230 panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
1240 /* compute a couple of other cache variables */
1241 c
->scache
.waysize
= scache_size
/ c
->scache
.ways
;
1243 c
->scache
.sets
= scache_size
/ (c
->scache
.linesz
* c
->scache
.ways
);
1245 printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
1246 scache_size
>> 10, way_string
[c
->scache
.ways
], c
->scache
.linesz
);
1248 c
->options
|= MIPS_CPU_INCLUSIVE_CACHES
;
1251 void au1x00_fixup_config_od(void)
1254 * c0_config.od (bit 19) was write only (and read as 0)
1255 * on the early revisions of Alchemy SOCs. It disables the bus
1256 * transaction overlapping and needs to be set to fix various errata.
1258 switch (read_c0_prid()) {
1259 case 0x00030100: /* Au1000 DA */
1260 case 0x00030201: /* Au1000 HA */
1261 case 0x00030202: /* Au1000 HB */
1262 case 0x01030200: /* Au1500 AB */
1264 * Au1100 errata actually keeps silence about this bit, so we set it
1265 * just in case for those revisions that require it to be set according
1266 * to arch/mips/au1000/common/cputable.c
1268 case 0x02030200: /* Au1100 AB */
1269 case 0x02030201: /* Au1100 BA */
1270 case 0x02030202: /* Au1100 BC */
1271 set_c0_config(1 << 19);
1276 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
1277 static void __init
coherency_setup(void)
1279 static void __cpuinit
coherency_setup(void)
1280 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
1282 change_c0_config(CONF_CM_CMASK
, CONF_CM_DEFAULT
);
1285 * c0_status.cu=0 specifies that updates by the sc instruction use
1286 * the coherency mode specified by the TLB; 1 means cachable
1287 * coherent update on write will be used. Not all processors have
1288 * this bit and; some wire it to zero, others like Toshiba had the
1289 * silly idea of putting something else there ...
1291 switch (current_cpu_type()) {
1298 clear_c0_config(CONF_CU
);
1301 * We need to catch the early Alchemy SOCs with
1302 * the write-only co_config.od bit and set it back to one...
1304 case CPU_AU1000
: /* rev. DA, HA, HB */
1305 case CPU_AU1100
: /* rev. AB, BA, BC ?? */
1306 case CPU_AU1500
: /* rev. AB */
1307 au1x00_fixup_config_od();
1312 <<<<<<< HEAD
:arch
/mips
/mm
/c
-r4k
.c
1313 void __init
r4k_cache_init(void)
1315 void __cpuinit
r4k_cache_init(void)
1316 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/mips
/mm
/c
-r4k
.c
1318 extern void build_clear_page(void);
1319 extern void build_copy_page(void);
1320 extern char __weak except_vec2_generic
;
1321 extern char __weak except_vec2_sb1
;
1322 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
1324 switch (c
->cputype
) {
1327 set_uncached_handler(0x100, &except_vec2_sb1
, 0x80);
1331 set_uncached_handler(0x100, &except_vec2_generic
, 0x80);
1338 r4k_blast_dcache_page_setup();
1339 r4k_blast_dcache_page_indexed_setup();
1340 r4k_blast_dcache_setup();
1341 r4k_blast_icache_page_setup();
1342 r4k_blast_icache_page_indexed_setup();
1343 r4k_blast_icache_setup();
1344 r4k_blast_scache_page_setup();
1345 r4k_blast_scache_page_indexed_setup();
1346 r4k_blast_scache_setup();
1349 * Some MIPS32 and MIPS64 processors have physically indexed caches.
1350 * This code supports virtually indexed processors and will be
1351 * unnecessarily inefficient on physically indexed processors.
1353 if (c
->dcache
.linesz
)
1354 shm_align_mask
= max_t( unsigned long,
1355 c
->dcache
.sets
* c
->dcache
.linesz
- 1,
1358 shm_align_mask
= PAGE_SIZE
-1;
1359 flush_cache_all
= cache_noop
;
1360 __flush_cache_all
= r4k___flush_cache_all
;
1361 flush_cache_mm
= r4k_flush_cache_mm
;
1362 flush_cache_page
= r4k_flush_cache_page
;
1363 flush_cache_range
= r4k_flush_cache_range
;
1365 flush_cache_sigtramp
= r4k_flush_cache_sigtramp
;
1366 flush_icache_all
= r4k_flush_icache_all
;
1367 local_flush_data_cache_page
= local_r4k_flush_data_cache_page
;
1368 flush_data_cache_page
= r4k_flush_data_cache_page
;
1369 flush_icache_range
= r4k_flush_icache_range
;
1371 #ifdef CONFIG_DMA_NONCOHERENT
1372 _dma_cache_wback_inv
= r4k_dma_cache_wback_inv
;
1373 _dma_cache_wback
= r4k_dma_cache_wback_inv
;
1374 _dma_cache_inv
= r4k_dma_cache_inv
;
1379 local_r4k___flush_cache_all(NULL
);