2 * sc-rm7k.c: RM7000 cache management functions.
4 * Copyright (C) 1997, 2001, 2003, 2004 Ralf Baechle (ralf@linux-mips.org)
9 #include <linux/init.h>
10 #include <linux/kernel.h>
13 #include <asm/addrspace.h>
14 #include <asm/bcache.h>
15 #include <asm/cacheops.h>
16 #include <asm/mipsregs.h>
17 #include <asm/processor.h>
19 /* Primary cache parameters. */
21 #define tc_pagesize (32*128)
23 /* Secondary cache parameters. */
24 #define scache_size (256*1024) /* Fixed to 256KiB on RM7000 */
26 extern unsigned long icache_way_size, dcache_way_size;
28 #include <asm/r4kcache.h>
30 int rm7k_tcache_enabled;
33 * Writeback and invalidate the primary cache dcache before DMA.
34 * (XXX These need to be fixed ...)
36 static void rm7k_sc_wback_inv(unsigned long addr, unsigned long size)
40 pr_debug("rm7k_sc_wback_inv[%08lx,%08lx]", addr, size);
42 /* Catch bad driver code */
45 a = addr & ~(sc_lsize - 1);
46 end = (addr + size - 1) & ~(sc_lsize - 1);
48 flush_scache_line(a); /* Hit_Writeback_Inv_SD */
54 if (!rm7k_tcache_enabled)
57 a = addr & ~(tc_pagesize - 1);
58 end = (addr + size - 1) & ~(tc_pagesize - 1);
60 invalidate_tcache_page(a); /* Page_Invalidate_T */
67 static void rm7k_sc_inv(unsigned long addr, unsigned long size)
71 pr_debug("rm7k_sc_inv[%08lx,%08lx]", addr, size);
73 /* Catch bad driver code */
76 a = addr & ~(sc_lsize - 1);
77 end = (addr + size - 1) & ~(sc_lsize - 1);
79 invalidate_scache_line(a); /* Hit_Invalidate_SD */
85 if (!rm7k_tcache_enabled)
88 a = addr & ~(tc_pagesize - 1);
89 end = (addr + size - 1) & ~(tc_pagesize - 1);
91 invalidate_tcache_page(a); /* Page_Invalidate_T */
99 * This function is executed in the uncached segment CKSEG1.
100 * It must not touch the stack, because the stack pointer still points
104 * - Write it in assembly and guarantee that we don't use the stack.
105 * - Disable caching for CKSEG0 before calling it.
106 * - Pray that GCC doesn't randomly start using the stack.
108 * This being Linux, we obviously take the least sane of those options -
109 * following DaveM's lead in c-r4k.c
111 * It seems we get our kicks from relying on unguaranteed behaviour in GCC
113 static __init void __rm7k_sc_enable(void)
117 set_c0_config(1 << 3); /* CONF_SE */
122 for (i = 0; i < scache_size; i += sc_lsize) {
123 __asm__ __volatile__ (
130 : "r" (KSEG0ADDR(i)), "i" (Index_Store_Tag_SD));
134 static __init void rm7k_sc_enable(void)
136 void (*func)(void) = (void *) KSEG1ADDR(&__rm7k_sc_enable);
138 if (read_c0_config() & 0x08) /* CONF_SE */
141 printk(KERN_INFO "Enabling secondary cache...");
145 static void rm7k_sc_disable(void)
147 clear_c0_config(1<<3); /* CONF_SE */
150 struct bcache_ops rm7k_sc_ops = {
151 .bc_enable = rm7k_sc_enable,
152 .bc_disable = rm7k_sc_disable,
153 .bc_wback_inv = rm7k_sc_wback_inv,
154 .bc_inv = rm7k_sc_inv
157 void __init rm7k_sc_init(void)
159 unsigned int config = read_c0_config();
161 if ((config >> 31) & 1) /* Bit 31 set -> no S-Cache */
164 printk(KERN_INFO "Secondary cache size %dK, linesize %d bytes.\n",
165 (scache_size >> 10), sc_lsize);
167 if (!((config >> 3) & 1)) /* CONF_SE */
171 * While we're at it let's deal with the tertiary cache.
173 if (!((config >> 17) & 1)) {
176 * We can't enable the L3 cache yet. There may be board-specific
177 * magic necessary to turn it on, and blindly asking the CPU to
178 * start using it would may give cache errors.
180 * Also, board-specific knowledge may allow us to use the
181 * CACHE Flash_Invalidate_T instruction if the tag RAM supports
182 * it, and may specify the size of the L3 cache so we don't have
185 printk(KERN_INFO "Tertiary cache present, %s enabled\n",
186 config&(1<<12) ? "already" : "not (yet)");
188 if ((config >> 12) & 1)
189 rm7k_tcache_enabled = 1;
192 bcops = &rm7k_sc_ops;