1
2
3
4
5
6
7#undef DEBUG
8
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/mm.h>
12
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>
18
19
20#define sc_lsize 32
21#define tc_pagesize (32*128)
22
23
24#define scache_size (256*1024)
25
26extern unsigned long icache_way_size, dcache_way_size;
27
28#include <asm/r4kcache.h>
29
30int rm7k_tcache_enabled;
31
32
33
34
35
36static void rm7k_sc_wback_inv(unsigned long addr, unsigned long size)
37{
38 unsigned long end, a;
39
40 pr_debug("rm7k_sc_wback_inv[%08lx,%08lx]", addr, size);
41
42
43 BUG_ON(size == 0);
44
45 a = addr & ~(sc_lsize - 1);
46 end = (addr + size - 1) & ~(sc_lsize - 1);
47 while (1) {
48 flush_scache_line(a);
49 if (a == end)
50 break;
51 a += sc_lsize;
52 }
53
54 if (!rm7k_tcache_enabled)
55 return;
56
57 a = addr & ~(tc_pagesize - 1);
58 end = (addr + size - 1) & ~(tc_pagesize - 1);
59 while(1) {
60 invalidate_tcache_page(a);
61 if (a == end)
62 break;
63 a += tc_pagesize;
64 }
65}
66
67static void rm7k_sc_inv(unsigned long addr, unsigned long size)
68{
69 unsigned long end, a;
70
71 pr_debug("rm7k_sc_inv[%08lx,%08lx]", addr, size);
72
73
74 BUG_ON(size == 0);
75
76 a = addr & ~(sc_lsize - 1);
77 end = (addr + size - 1) & ~(sc_lsize - 1);
78 while (1) {
79 invalidate_scache_line(a);
80 if (a == end)
81 break;
82 a += sc_lsize;
83 }
84
85 if (!rm7k_tcache_enabled)
86 return;
87
88 a = addr & ~(tc_pagesize - 1);
89 end = (addr + size - 1) & ~(tc_pagesize - 1);
90 while(1) {
91 invalidate_tcache_page(a);
92 if (a == end)
93 break;
94 a += tc_pagesize;
95 }
96}
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113static __init void __rm7k_sc_enable(void)
114{
115 int i;
116
117 set_c0_config(1 << 3);
118
119 write_c0_taglo(0);
120 write_c0_taghi(0);
121
122 for (i = 0; i < scache_size; i += sc_lsize) {
123 __asm__ __volatile__ (
124 ".set noreorder\n\t"
125 ".set mips3\n\t"
126 "cache %1, (%0)\n\t"
127 ".set mips0\n\t"
128 ".set reorder"
129 :
130 : "r" (KSEG0ADDR(i)), "i" (Index_Store_Tag_SD));
131 }
132}
133
134static __init void rm7k_sc_enable(void)
135{
136 void (*func)(void) = (void *) KSEG1ADDR(&__rm7k_sc_enable);
137
138 if (read_c0_config() & 0x08)
139 return;
140
141 printk(KERN_INFO "Enabling secondary cache...");
142 func();
143}
144
145static void rm7k_sc_disable(void)
146{
147 clear_c0_config(1<<3);
148}
149
150struct 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
155};
156
157void __init rm7k_sc_init(void)
158{
159 unsigned int config = read_c0_config();
160
161 if ((config >> 31) & 1)
162 return;
163
164 printk(KERN_INFO "Secondary cache size %dK, linesize %d bytes.\n",
165 (scache_size >> 10), sc_lsize);
166
167 if (!((config >> 3) & 1))
168 rm7k_sc_enable();
169
170
171
172
173 if (!((config >> 17) & 1)) {
174
175
176
177
178
179
180
181
182
183
184
185 printk(KERN_INFO "Tertiary cache present, %s enabled\n",
186 config&(1<<12) ? "already" : "not (yet)");
187
188 if ((config >> 12) & 1)
189 rm7k_tcache_enabled = 1;
190 }
191
192 bcops = &rm7k_sc_ops;
193}
194