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>
12 #include <linux/bitops.h>
14 #include <asm/addrspace.h>
15 #include <asm/bcache.h>
16 #include <asm/cacheops.h>
17 #include <asm/mipsregs.h>
18 #include <asm/processor.h>
19 #include <asm/sections.h>
20 #include <asm/cacheflush.h> /* for run_uncached() */
22 /* Primary cache parameters. */
24 #define tc_pagesize (32*128)
26 /* Secondary cache parameters. */
27 #define scache_size (256*1024) /* Fixed to 256KiB on RM7000 */
29 /* Tertiary cache parameters */
32 extern unsigned long icache_way_size
, dcache_way_size
;
33 static unsigned long tcache_size
;
35 #include <asm/r4kcache.h>
37 static int rm7k_tcache_init
;
40 * Writeback and invalidate the primary cache dcache before DMA.
41 * (XXX These need to be fixed ...)
43 static void rm7k_sc_wback_inv(unsigned long addr
, unsigned long size
)
47 pr_debug("rm7k_sc_wback_inv[%08lx,%08lx]", addr
, size
);
49 /* Catch bad driver code */
52 blast_scache_range(addr
, addr
+ size
);
54 if (!rm7k_tcache_init
)
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 blast_inv_scache_range(addr
, addr
+ size
);
78 if (!rm7k_tcache_init
)
81 a
= addr
& ~(tc_pagesize
- 1);
82 end
= (addr
+ size
- 1) & ~(tc_pagesize
- 1);
84 invalidate_tcache_page(a
); /* Page_Invalidate_T */
91 static void blast_rm7k_tcache(void)
93 unsigned long start
= CKSEG0ADDR(0);
94 unsigned long end
= start
+ tcache_size
;
99 cache_op(Page_Invalidate_T
, start
);
100 start
+= tc_pagesize
;
105 * This function is executed in uncached address space.
107 static __cpuinit
void __rm7k_tc_enable(void)
111 set_c0_config(RM7K_CONF_TE
);
116 for (i
= 0; i
< tcache_size
; i
+= tc_lsize
)
117 cache_op(Index_Store_Tag_T
, CKSEG0ADDR(i
));
120 static __cpuinit
void rm7k_tc_enable(void)
122 if (read_c0_config() & RM7K_CONF_TE
)
125 BUG_ON(tcache_size
== 0);
127 run_uncached(__rm7k_tc_enable
);
131 * This function is executed in uncached address space.
133 static __cpuinit
void __rm7k_sc_enable(void)
137 set_c0_config(RM7K_CONF_SE
);
142 for (i
= 0; i
< scache_size
; i
+= sc_lsize
)
143 cache_op(Index_Store_Tag_SD
, CKSEG0ADDR(i
));
146 static __cpuinit
void rm7k_sc_enable(void)
148 if (read_c0_config() & RM7K_CONF_SE
)
151 pr_info("Enabling secondary cache...\n");
152 run_uncached(__rm7k_sc_enable
);
154 if (rm7k_tcache_init
)
158 static void rm7k_tc_disable(void)
162 local_irq_save(flags
);
164 clear_c0_config(RM7K_CONF_TE
);
165 local_irq_save(flags
);
168 static void rm7k_sc_disable(void)
170 clear_c0_config(RM7K_CONF_SE
);
172 if (rm7k_tcache_init
)
176 static struct bcache_ops rm7k_sc_ops
= {
177 .bc_enable
= rm7k_sc_enable
,
178 .bc_disable
= rm7k_sc_disable
,
179 .bc_wback_inv
= rm7k_sc_wback_inv
,
180 .bc_inv
= rm7k_sc_inv
184 * This is a probing function like the one found in c-r4k.c, we look for the
185 * wrap around point with different addresses.
187 static __cpuinit
void __probe_tcache(void)
189 unsigned long flags
, addr
, begin
, end
, pow2
;
191 begin
= (unsigned long) &_stext
;
192 begin
&= ~((8 * 1024 * 1024) - 1);
193 end
= begin
+ (8 * 1024 * 1024);
195 local_irq_save(flags
);
197 set_c0_config(RM7K_CONF_TE
);
199 /* Fill size-multiple lines with a valid tag */
201 for (addr
= begin
; addr
<= end
; addr
= (begin
+ pow2
)) {
202 unsigned long *p
= (unsigned long *) addr
;
203 __asm__
__volatile__("nop" : : "r" (*p
));
207 /* Load first line with a 0 tag, to check after */
210 cache_op(Index_Store_Tag_T
, begin
);
212 /* Look for the wrap-around */
214 for (addr
= begin
+ (512 * 1024); addr
<= end
; addr
= begin
+ pow2
) {
215 cache_op(Index_Load_Tag_T
, addr
);
216 if (!read_c0_taglo())
224 clear_c0_config(RM7K_CONF_TE
);
226 local_irq_restore(flags
);
229 void __cpuinit
rm7k_sc_init(void)
231 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
232 unsigned int config
= read_c0_config();
234 if ((config
& RM7K_CONF_SC
))
237 c
->scache
.linesz
= sc_lsize
;
239 c
->scache
.waybit
= __ffs(scache_size
/ c
->scache
.ways
);
240 c
->scache
.waysize
= scache_size
/ c
->scache
.ways
;
241 c
->scache
.sets
= scache_size
/ (c
->scache
.linesz
* c
->scache
.ways
);
242 printk(KERN_INFO
"Secondary cache size %dK, linesize %d bytes.\n",
243 (scache_size
>> 10), sc_lsize
);
245 if (!(config
& RM7K_CONF_SE
))
248 bcops
= &rm7k_sc_ops
;
251 * While we're at it let's deal with the tertiary cache.
254 rm7k_tcache_init
= 0;
257 if (config
& RM7K_CONF_TC
)
261 * No efficient way to ask the hardware for the size of the tcache,
262 * so must probe for it.
264 run_uncached(__probe_tcache
);
266 rm7k_tcache_init
= 1;
267 c
->tcache
.linesz
= tc_lsize
;
269 pr_info("Tertiary cache size %ldK.\n", (tcache_size
>> 10));