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/config.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
15 #include <linux/bitops.h>
17 #include <asm/bcache.h>
18 #include <asm/bootinfo.h>
22 #include <asm/pgtable.h>
23 #include <asm/system.h>
24 #include <asm/mmu_context.h>
27 /* Primary cache parameters. */
28 static unsigned long icache_size, dcache_size, scache_size;
29 unsigned long icache_way_size, dcache_way_size, scache_way_size;
30 static unsigned long scache_size;
32 #include <asm/cacheops.h>
33 #include <asm/r4kcache.h>
35 extern void andes_clear_page(void * page);
36 extern void r4k_clear_page32_d16(void * page);
37 extern void r4k_clear_page32_d32(void * page);
38 extern void r4k_clear_page_d16(void * page);
39 extern void r4k_clear_page_d32(void * page);
40 extern void r4k_clear_page_r4600_v1(void * page);
41 extern void r4k_clear_page_r4600_v2(void * page);
42 extern void r4k_clear_page_s16(void * page);
43 extern void r4k_clear_page_s32(void * page);
44 extern void r4k_clear_page_s64(void * page);
45 extern void r4k_clear_page_s128(void * page);
46 extern void andes_copy_page(void * to, void * from);
47 extern void r4k_copy_page_d16(void * to, void * from);
48 extern void r4k_copy_page_d32(void * to, void * from);
49 extern void r4k_copy_page_r4600_v1(void * to, void * from);
50 extern void r4k_copy_page_r4600_v2(void * to, void * from);
51 extern void r4k_copy_page_s16(void * to, void * from);
52 extern void r4k_copy_page_s32(void * to, void * from);
53 extern void r4k_copy_page_s64(void * to, void * from);
54 extern void r4k_copy_page_s128(void * to, void * from);
57 * Dummy cache handling routines for machines without boardcaches
59 static void no_sc_noop(void) {}
61 static struct bcache_ops no_sc_ops = {
62 .bc_enable = (void *)no_sc_noop,
63 .bc_disable = (void *)no_sc_noop,
64 .bc_wback_inv = (void *)no_sc_noop,
65 .bc_inv = (void *)no_sc_noop
68 struct bcache_ops *bcops = &no_sc_ops;
70 #define R4600_HIT_CACHEOP_WAR_IMPL \
72 if (R4600_V2_HIT_CACHEOP_WAR && \
73 (read_c0_prid() & 0xfff0) == 0x2020) { /* R4600 V2.0 */\
74 *(volatile unsigned long *)KSEG1; \
76 if (R4600_V1_HIT_CACHEOP_WAR) \
77 __asm__ __volatile__("nop;nop;nop;nop"); \
80 static void r4k_blast_dcache_page(unsigned long addr)
82 static void *l = &&init;
83 unsigned long dc_lsize;
88 blast_dcache16_page(addr);
92 R4600_HIT_CACHEOP_WAR_IMPL;
93 blast_dcache32_page(addr);
97 dc_lsize = current_cpu_data.dcache.linesz;
101 else if (dc_lsize == 32)
106 static void r4k_blast_dcache_page_indexed(unsigned long addr)
108 static void *l = &&init;
109 unsigned long dc_lsize;
114 blast_dcache16_page_indexed(addr);
118 blast_dcache32_page_indexed(addr);
122 dc_lsize = current_cpu_data.dcache.linesz;
126 else if (dc_lsize == 32)
131 static void r4k_blast_dcache(void)
133 static void *l = &&init;
134 unsigned long dc_lsize;
147 dc_lsize = current_cpu_data.dcache.linesz;
151 else if (dc_lsize == 32)
156 static void r4k_blast_icache_page(unsigned long addr)
158 unsigned long ic_lsize = current_cpu_data.icache.linesz;
159 static void *l = &&init;
164 blast_icache16_page(addr);
168 blast_icache32_page(addr);
172 blast_icache64_page(addr);
178 else if (ic_lsize == 32)
180 else if (ic_lsize == 64)
185 static void r4k_blast_icache_page_indexed(unsigned long addr)
187 unsigned long ic_lsize = current_cpu_data.icache.linesz;
188 static void *l = &&init;
193 blast_icache16_page_indexed(addr);
197 blast_icache32_page_indexed(addr);
201 blast_icache64_page_indexed(addr);
207 else if (ic_lsize == 32)
209 else if (ic_lsize == 64)
214 static void r4k_blast_icache(void)
216 unsigned long ic_lsize = current_cpu_data.icache.linesz;
217 static void *l = &&init;
236 else if (ic_lsize == 32)
238 else if (ic_lsize == 64)
243 static void r4k_blast_scache_page(unsigned long addr)
245 unsigned long sc_lsize = current_cpu_data.scache.linesz;
246 static void *l = &&init;
251 blast_scache16_page(addr);
255 blast_scache32_page(addr);
259 blast_scache64_page(addr);
263 blast_scache128_page(addr);
269 else if (sc_lsize == 32)
271 else if (sc_lsize == 64)
273 else if (sc_lsize == 128)
278 static void r4k_blast_scache(void)
280 unsigned long sc_lsize = current_cpu_data.scache.linesz;
281 static void *l = &&init;
304 else if (sc_lsize == 32)
306 else if (sc_lsize == 64)
308 else if (sc_lsize == 128)
313 static void r4k_flush_cache_all(void)
315 if (!cpu_has_dc_aliases)
322 static void r4k___flush_cache_all(void)
327 switch (current_cpu_data.cputype) {
338 static void r4k_flush_cache_range(struct vm_area_struct *vma,
339 unsigned long start, unsigned long end)
341 if (cpu_context(smp_processor_id(), vma->vm_mm) != 0) {
343 if (vma->vm_flags & VM_EXEC)
348 static void r4k_flush_cache_mm(struct mm_struct *mm)
350 if (!cpu_has_dc_aliases)
353 if (!cpu_context(smp_processor_id(), mm))
360 * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we
361 * only flush the primary caches but R10000 and R12000 behave sane ...
363 if (current_cpu_data.cputype == CPU_R4000SC ||
364 current_cpu_data.cputype == CPU_R4000MC ||
365 current_cpu_data.cputype == CPU_R4400SC ||
366 current_cpu_data.cputype == CPU_R4400MC)
370 static void r4k_flush_cache_page(struct vm_area_struct *vma,
373 int exec = vma->vm_flags & VM_EXEC;
374 struct mm_struct *mm = vma->vm_mm;
380 * If ownes no valid ASID yet, cannot possibly have gotten
381 * this page into the cache.
383 if (cpu_context(smp_processor_id(), mm) == 0)
387 pgdp = pgd_offset(mm, page);
388 pmdp = pmd_offset(pgdp, page);
389 ptep = pte_offset(pmdp, page);
392 * If the page isn't marked valid, the page cannot possibly be
395 if (!(pte_val(*ptep) & _PAGE_PRESENT))
399 * Doing flushes for another ASID than the current one is
400 * too difficult since stupid R4k caches do a TLB translation
401 * for every cache flush operation. So we do indexed flushes
402 * in that case, which doesn't overly flush the cache too much.
404 if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) {
405 if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc))
406 r4k_blast_dcache_page(page);
408 r4k_blast_icache_page(page);
414 * Do indexed flush, too much work to get the (possible) TLB refills
417 page = (KSEG0 + (page & (dcache_size - 1)));
418 if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc))
419 r4k_blast_dcache_page_indexed(page);
421 if (cpu_has_vtag_icache) {
422 int cpu = smp_processor_id();
424 if (cpu_context(cpu, vma->vm_mm) != 0)
425 drop_mmu_context(vma->vm_mm, cpu);
427 r4k_blast_icache_page_indexed(page);
431 static void r4k_flush_data_cache_page(unsigned long addr)
433 r4k_blast_dcache_page(addr);
436 static void r4k_flush_icache_range(unsigned long start, unsigned long end)
438 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
439 unsigned long addr, aend;
441 if (!cpu_has_ic_fills_f_dc) {
442 if (end - start > dcache_size)
445 addr = start & ~(dc_lsize - 1);
446 aend = (end - 1) & ~(dc_lsize - 1);
449 /* Hit_Writeback_Inv_D */
450 protected_writeback_dcache_line(addr);
458 if (end - start > icache_size)
461 addr = start & ~(dc_lsize - 1);
462 aend = (end - 1) & ~(dc_lsize - 1);
464 /* Hit_Invalidate_I */
465 protected_flush_icache_line(addr);
474 * Ok, this seriously sucks. We use them to flush a user page but don't
475 * know the virtual address, so we have to blast away the whole icache
476 * which is significantly more expensive than the real thing. Otoh we at
477 * least know the kernel address of the page so we can flush it
480 static void r4k_flush_icache_page(struct vm_area_struct *vma,
484 * If there's no context yet, or the page isn't executable, no icache
487 if (!(vma->vm_flags & VM_EXEC))
491 * Tricky ... Because we don't know the virtual address we've got the
492 * choice of either invalidating the entire primary and secondary
493 * caches or invalidating the secondary caches also. With the subset
494 * enforcment on R4000SC, R4400SC, R10000 and R12000 invalidating the
495 * secondary cache will result in any entries in the primary caches
496 * also getting invalidated which hopefully is a bit more economical.
498 if (cpu_has_subset_pcaches) {
499 unsigned long addr = (unsigned long) page_address(page);
500 r4k_blast_scache_page(addr);
505 if (!cpu_has_ic_fills_f_dc) {
506 unsigned long addr = (unsigned long) page_address(page);
507 r4k_blast_dcache_page(addr);
511 * We're not sure of the virtual address(es) involved here, so
512 * we have to flush the entire I-cache.
514 if (cpu_has_vtag_icache) {
515 int cpu = smp_processor_id();
517 if (cpu_context(cpu, vma->vm_mm) != 0)
518 drop_mmu_context(vma->vm_mm, cpu);
523 #ifdef CONFIG_NONCOHERENT_IO
525 static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
527 unsigned long end, a;
529 if (cpu_has_subset_pcaches) {
530 unsigned long sc_lsize = current_cpu_data.scache.linesz;
532 if (size >= scache_size) {
537 a = addr & ~(sc_lsize - 1);
538 end = (addr + size - 1) & ~(sc_lsize - 1);
540 flush_scache_line(a); /* Hit_Writeback_Inv_SD */
549 * Either no secondary cache or the available caches don't have the
550 * subset property so we have to flush the primary caches
553 if (size >= dcache_size) {
556 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
558 R4600_HIT_CACHEOP_WAR_IMPL;
559 a = addr & ~(dc_lsize - 1);
560 end = (addr + size - 1) & ~(dc_lsize - 1);
562 flush_dcache_line(a); /* Hit_Writeback_Inv_D */
569 bc_wback_inv(addr, size);
572 static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
574 unsigned long end, a;
576 if (cpu_has_subset_pcaches) {
577 unsigned long sc_lsize = current_cpu_data.scache.linesz;
579 if (size >= scache_size) {
584 a = addr & ~(sc_lsize - 1);
585 end = (addr + size - 1) & ~(sc_lsize - 1);
587 flush_scache_line(a); /* Hit_Writeback_Inv_SD */
595 if (size >= dcache_size) {
598 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
600 R4600_HIT_CACHEOP_WAR_IMPL;
601 a = addr & ~(dc_lsize - 1);
602 end = (addr + size - 1) & ~(dc_lsize - 1);
604 flush_dcache_line(a); /* Hit_Writeback_Inv_D */
613 #endif /* CONFIG_NONCOHERENT_IO */
616 * While we're protected against bad userland addresses we don't care
617 * very much about what happens in that case. Usually a segmentation
618 * fault will dump the process later on anyway ...
620 static void r4k_flush_cache_sigtramp(unsigned long addr)
622 unsigned long ic_lsize = current_cpu_data.icache.linesz;
623 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
625 R4600_HIT_CACHEOP_WAR_IMPL;
626 protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
627 protected_flush_icache_line(addr & ~(ic_lsize - 1));
630 static void r4k_flush_icache_all(void)
632 if (cpu_has_vtag_icache)
636 static inline void rm7k_erratum31(void)
638 const unsigned long ic_lsize = 32;
641 /* RM7000 erratum #31. The icache is screwed at startup. */
645 for (addr = KSEG0; addr <= KSEG0 + 4096; addr += ic_lsize) {
646 __asm__ __volatile__ (
649 "cache\t%1, 0(%0)\n\t"
650 "cache\t%1, 0x1000(%0)\n\t"
651 "cache\t%1, 0x2000(%0)\n\t"
652 "cache\t%1, 0x3000(%0)\n\t"
653 "cache\t%2, 0(%0)\n\t"
654 "cache\t%2, 0x1000(%0)\n\t"
655 "cache\t%2, 0x2000(%0)\n\t"
656 "cache\t%2, 0x3000(%0)\n\t"
657 "cache\t%1, 0(%0)\n\t"
658 "cache\t%1, 0x1000(%0)\n\t"
659 "cache\t%1, 0x2000(%0)\n\t"
660 "cache\t%1, 0x3000(%0)\n\t"
664 : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill));
668 static char *way_string[] = { NULL, "direct mapped", "2-way", "3-way", "4-way",
669 "5-way", "6-way", "7-way", "8-way"
672 static void __init probe_pcache(void)
674 struct cpuinfo_mips *c = ¤t_cpu_data;
675 unsigned int config = read_c0_config();
676 unsigned int prid = read_c0_prid();
677 unsigned long config1;
680 switch (current_cpu_data.cputype) {
681 case CPU_R4600: /* QED style two way caches? */
685 icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
686 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
688 c->icache.waybit = ffs(icache_size/2) - 1;
690 dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
691 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
693 c->dcache.waybit= ffs(dcache_size/2) - 1;
698 icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
699 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
703 dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
704 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
706 c->dcache.waybit = 0;
710 icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
711 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
715 dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
716 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
718 c->dcache.waybit = 0;
727 icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
728 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
730 c->icache.waybit = 0; /* doesn't matter */
732 dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
733 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
735 c->dcache.waybit = 0; /* does not matter */
740 icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
741 c->icache.linesz = 64;
743 c->icache.waybit = 0;
745 dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26));
746 c->dcache.linesz = 32;
748 c->dcache.waybit = 0;
752 icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
753 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
755 c->icache.waybit = ffs(icache_size/2) - 1;
757 dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
758 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
760 c->dcache.waybit = ffs(dcache_size/2) - 1;
769 icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
770 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
772 c->icache.waybit = 0; /* doesn't matter */
774 dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
775 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
777 c->dcache.waybit = 0; /* does not matter */
783 icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
784 c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
786 c->icache.waybit = ffs(icache_size / c->icache.ways) - 1;
788 dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
789 c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
791 c->dcache.waybit = ffs(dcache_size / c->dcache.ways) - 1;
795 if (!(config & MIPS_CONF_M))
796 panic("Don't know how to probe P-caches on this cpu.");
799 * So we seem to be a MIPS32 or MIPS64 CPU
800 * So let's probe the I-cache ...
802 config1 = read_c0_config1();
804 if ((lsize = ((config1 >> 19) & 7)))
805 c->icache.linesz = 2 << lsize;
807 c->icache.linesz = lsize;
808 c->icache.sets = 64 << ((config1 >> 22) & 7);
809 c->icache.ways = 1 + ((config1 >> 16) & 7);
811 icache_size = c->icache.sets *
814 c->icache.waybit = ffs(icache_size/c->icache.ways) - 1;
817 * Now probe the MIPS32 / MIPS64 data cache.
821 if ((lsize = ((config1 >> 10) & 7)))
822 c->dcache.linesz = 2 << lsize;
824 c->dcache.linesz= lsize;
825 c->dcache.sets = 64 << ((config1 >> 13) & 7);
826 c->dcache.ways = 1 + ((config1 >> 7) & 7);
828 dcache_size = c->dcache.sets *
831 c->dcache.waybit = ffs(dcache_size/c->dcache.ways) - 1;
836 * Processor configuration sanity check for the R4000SC erratum
837 * #5. With page sizes larger than 32kB there is no possibility
838 * to get a VCE exception anymore so we don't care about this
839 * misconfiguration. The case is rather theoretical anyway;
840 * presumably no vendor is shipping his hardware in the "bad"
843 if ((prid & 0xff00) == PRID_IMP_R4000 && (prid & 0xff) < 0x40 &&
844 !(config & CONF_SC) && c->icache.linesz != 16 &&
846 panic("Improper R4000SC processor configuration detected");
848 /* compute a couple of other cache variables */
849 icache_way_size = icache_size / c->icache.ways;
850 dcache_way_size = dcache_size / c->dcache.ways;
852 c->icache.sets = icache_size / (c->icache.linesz * c->icache.ways);
853 c->dcache.sets = dcache_size / (c->dcache.linesz * c->dcache.ways);
856 * R10000 and R12000 P-caches are odd in a positive way. They're 32kB
857 * 2-way virtually indexed so normally would suffer from aliases. So
858 * normally they'd suffer from aliases but magic in the hardware deals
859 * with that for us so we don't need to take care ourselves.
861 if (current_cpu_data.cputype != CPU_R10000 &&
862 current_cpu_data.cputype != CPU_R12000)
863 if (dcache_way_size > PAGE_SIZE)
864 c->dcache.flags |= MIPS_CACHE_ALIASES;
866 if (config & 0x8) /* VI bit */
867 c->icache.flags |= MIPS_CACHE_VTAG;
869 switch (c->cputype) {
872 * Some older 20Kc chips doesn't have the 'VI' bit in
873 * the config register.
875 c->icache.flags |= MIPS_CACHE_VTAG;
879 c->icache.flags |= MIPS_CACHE_IC_F_DC;
883 printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
885 cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
886 way_string[c->icache.ways], c->icache.linesz);
888 printk("Primary data cache %ldkB %s, linesize %d bytes.\n",
889 dcache_size >> 10, way_string[c->dcache.ways], c->dcache.linesz);
893 * If you even _breathe_ on this function, look at the gcc output and make sure
894 * it does not pop things on and off the stack for the cache sizing loop that
895 * executes in KSEG1 space or else you will crash and burn badly. You have
898 static int __init probe_scache(void)
900 extern unsigned long stext;
901 unsigned long flags, addr, begin, end, pow2;
902 unsigned int config = read_c0_config();
903 struct cpuinfo_mips *c = ¤t_cpu_data;
906 if (config & CONF_SC)
909 begin = (unsigned long) &stext;
910 begin &= ~((4 * 1024 * 1024) - 1);
911 end = begin + (4 * 1024 * 1024);
914 * This is such a bitch, you'd think they would make it easy to do
915 * this. Away you daemons of stupidity!
917 local_irq_save(flags);
919 /* Fill each size-multiple cache line with a valid tag. */
921 for (addr = begin; addr < end; addr = (begin + pow2)) {
922 unsigned long *p = (unsigned long *) addr;
923 __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */
927 /* Load first line with zero (therefore invalid) tag. */
930 __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
931 cache_op(Index_Store_Tag_I, begin);
932 cache_op(Index_Store_Tag_D, begin);
933 cache_op(Index_Store_Tag_SD, begin);
935 /* Now search for the wrap around point. */
938 for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) {
939 cache_op(Index_Load_Tag_SD, addr);
940 __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */
941 if (!read_c0_taglo())
945 local_irq_restore(flags);
948 c = ¤t_cpu_data;
950 c->scache.linesz = 16 << ((config & R4K_CONF_SB) >> 22);
952 c->dcache.waybit = 0; /* does not matter */
957 static void __init setup_noscache_funcs(void)
961 switch (current_cpu_data.dcache.linesz) {
964 _clear_page = r4k_clear_page_d16;
966 _clear_page = r4k_clear_page32_d16;
967 _copy_page = r4k_copy_page_d16;
971 prid = read_c0_prid() & 0xfff0;
972 if (prid == 0x2010) { /* R4600 V1.7 */
973 _clear_page = r4k_clear_page_r4600_v1;
974 _copy_page = r4k_copy_page_r4600_v1;
975 } else if (prid == 0x2020) { /* R4600 V2.0 */
976 _clear_page = r4k_clear_page_r4600_v2;
977 _copy_page = r4k_copy_page_r4600_v2;
980 _clear_page = r4k_clear_page_d32;
982 _clear_page = r4k_clear_page32_d32;
983 _copy_page = r4k_copy_page_d32;
989 static void __init setup_scache_funcs(void)
991 if (current_cpu_data.dcache.linesz > current_cpu_data.scache.linesz)
992 panic("Invalid primary cache configuration detected");
994 if (current_cpu_data.cputype == CPU_R10000 ||
995 current_cpu_data.cputype == CPU_R12000) {
996 _clear_page = andes_clear_page;
997 _copy_page = andes_copy_page;
1001 switch (current_cpu_data.scache.linesz) {
1003 _clear_page = r4k_clear_page_s16;
1004 _copy_page = r4k_copy_page_s16;
1007 _clear_page = r4k_clear_page_s32;
1008 _copy_page = r4k_copy_page_s32;
1011 _clear_page = r4k_clear_page_s64;
1012 _copy_page = r4k_copy_page_s64;
1015 _clear_page = r4k_clear_page_s128;
1016 _copy_page = r4k_copy_page_s128;
1021 typedef int (*probe_func_t)(unsigned long);
1022 extern int r5k_sc_init(void);
1023 extern int rm7k_sc_init(void);
1025 static void __init setup_scache(void)
1027 struct cpuinfo_mips *c = ¤t_cpu_data;
1028 unsigned int config = read_c0_config();
1029 probe_func_t probe_scache_kseg1;
1033 * Do the probing thing on R4000SC and R4400SC processors. Other
1034 * processors don't have a S-cache that would be relevant to the
1035 * Linux memory managment.
1037 switch (current_cpu_data.cputype) {
1044 probe_scache_kseg1 = (probe_func_t) (KSEG1ADDR(&probe_scache));
1045 sc_present = probe_scache_kseg1(config);
1050 scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
1051 c->scache.linesz = 64 << ((config >> 13) & 1);
1053 c->scache.waybit= 0;
1059 setup_noscache_funcs();
1060 #ifdef CONFIG_R5000_CPU_SCACHE
1066 setup_noscache_funcs();
1067 #ifdef CONFIG_RM7000_CPU_SCACHE
1077 setup_noscache_funcs();
1081 if ((current_cpu_data.isa_level == MIPS_CPU_ISA_M32 ||
1082 current_cpu_data.isa_level == MIPS_CPU_ISA_M64) &&
1083 !(current_cpu_data.scache.flags & MIPS_CACHE_NOT_PRESENT))
1084 panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
1086 printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
1087 scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
1089 current_cpu_data.options |= MIPS_CPU_SUBSET_CACHES;
1090 setup_scache_funcs();
1093 static inline void coherency_setup(void)
1095 change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
1098 * c0_status.cu=0 specifies that updates by the sc instruction use
1099 * the coherency mode specified by the TLB; 1 means cachable
1100 * coherent update on write will be used. Not all processors have
1101 * this bit and; some wire it to zero, others like Toshiba had the
1102 * silly idea of putting something else there ...
1104 switch (current_cpu_data.cputype) {
1111 clear_c0_config(CONF_CU);
1117 void __init ld_mmu_r4xx0(void)
1119 extern char except_vec2_generic;
1121 /* Default cache error handler for R4000 and R5000 family */
1122 memcpy((void *)(KSEG0 + 0x100), &except_vec2_generic, 0x80);
1123 memcpy((void *)(KSEG1 + 0x100), &except_vec2_generic, 0x80);
1129 if (current_cpu_data.dcache.sets *
1130 current_cpu_data.dcache.ways > PAGE_SIZE)
1131 current_cpu_data.dcache.flags |= MIPS_CACHE_ALIASES;
1134 * Some MIPS32 and MIPS64 processors have physically indexed caches.
1135 * This code supports virtually indexed processors and will be
1136 * unnecessarily unefficient on physically indexed processors.
1138 shm_align_mask = max_t(unsigned long,
1139 current_cpu_data.dcache.sets * current_cpu_data.dcache.linesz - 1,
1142 flush_cache_all = r4k_flush_cache_all;
1143 __flush_cache_all = r4k___flush_cache_all;
1144 flush_cache_mm = r4k_flush_cache_mm;
1145 flush_cache_page = r4k_flush_cache_page;
1146 flush_icache_page = r4k_flush_icache_page;
1147 flush_cache_range = r4k_flush_cache_range;
1149 flush_cache_sigtramp = r4k_flush_cache_sigtramp;
1150 flush_icache_all = r4k_flush_icache_all;
1151 flush_data_cache_page = r4k_flush_data_cache_page;
1152 flush_icache_range = r4k_flush_icache_range;
1154 #ifdef CONFIG_NONCOHERENT_IO
1155 _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
1156 _dma_cache_wback = r4k_dma_cache_wback_inv;
1157 _dma_cache_inv = r4k_dma_cache_inv;
1160 __flush_cache_all();