update ipp2p to 0.8.1rc1, add it to 2.6 as well
[openwrt.git] / target / linux / brcm-2.6 / patches / 003-bcm4710_cache_fixes.patch
1 diff -urN linux.old/arch/mips/kernel/genex.S linux.dev/arch/mips/kernel/genex.S
2 --- linux.old/arch/mips/kernel/genex.S 2006-03-20 06:53:29.000000000 +0100
3 +++ linux.dev/arch/mips/kernel/genex.S 2006-03-21 12:19:26.000000000 +0100
4 @@ -72,6 +72,10 @@
5 .set push
6 .set mips3
7 .set noat
8 +#ifdef CONFIG_BCM4710
9 + nop
10 + nop
11 +#endif
12 mfc0 k1, CP0_CAUSE
13 li k0, 31<<2
14 andi k1, k1, 0x7c
15 diff -urN linux.old/arch/mips/mm/c-r4k.c linux.dev/arch/mips/mm/c-r4k.c
16 --- linux.old/arch/mips/mm/c-r4k.c 2006-03-20 06:53:29.000000000 +0100
17 +++ linux.dev/arch/mips/mm/c-r4k.c 2006-03-21 12:19:26.000000000 +0100
18 @@ -14,6 +14,12 @@
19 #include <linux/mm.h>
20 #include <linux/bitops.h>
21
22 +#ifdef CONFIG_BCM4710
23 +#include "../bcm947xx/include/typedefs.h"
24 +#include "../bcm947xx/include/sbconfig.h"
25 +#include <asm/paccess.h>
26 +#endif
27 +
28 #include <asm/bcache.h>
29 #include <asm/bootinfo.h>
30 #include <asm/cache.h>
31 @@ -29,6 +35,9 @@
32 #include <asm/war.h>
33 #include <asm/cacheflush.h> /* for run_uncached() */
34
35 +/* For enabling BCM4710 cache workarounds */
36 +int bcm4710 = 0;
37 +
38 /*
39 * Must die.
40 */
41 @@ -73,7 +82,9 @@
42 {
43 unsigned long dc_lsize = cpu_dcache_line_size();
44
45 - if (dc_lsize == 16)
46 + if (bcm4710)
47 + r4k_blast_dcache_page = blast_dcache_page;
48 + else if (dc_lsize == 16)
49 r4k_blast_dcache_page = blast_dcache16_page;
50 else if (dc_lsize == 32)
51 r4k_blast_dcache_page = r4k_blast_dcache_page_dc32;
52 @@ -85,7 +96,9 @@
53 {
54 unsigned long dc_lsize = cpu_dcache_line_size();
55
56 - if (dc_lsize == 16)
57 + if (bcm4710)
58 + r4k_blast_dcache_page_indexed = blast_dcache_page_indexed;
59 + else if (dc_lsize == 16)
60 r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed;
61 else if (dc_lsize == 32)
62 r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed;
63 @@ -97,7 +110,9 @@
64 {
65 unsigned long dc_lsize = cpu_dcache_line_size();
66
67 - if (dc_lsize == 16)
68 + if (bcm4710)
69 + r4k_blast_dcache = blast_dcache;
70 + else if (dc_lsize == 16)
71 r4k_blast_dcache = blast_dcache16;
72 else if (dc_lsize == 32)
73 r4k_blast_dcache = blast_dcache32;
74 @@ -660,6 +675,8 @@
75 unsigned long addr = (unsigned long) arg;
76
77 R4600_HIT_CACHEOP_WAR_IMPL;
78 + BCM4710_PROTECTED_FILL_TLB(addr);
79 + BCM4710_PROTECTED_FILL_TLB(addr + 4);
80 protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
81 if (!cpu_icache_snoops_remote_store && scache_size)
82 protected_writeback_scache_line(addr & ~(sc_lsize - 1));
83 @@ -1136,6 +1153,16 @@
84 static inline void coherency_setup(void)
85 {
86 change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
87 +#if defined(CONFIG_BCM4310) || defined(CONFIG_BCM4704) || defined(CONFIG_BCM5365)
88 + if (BCM330X(current_cpu_data.processor_id)) {
89 + __u32 cm = read_c0_diag();
90 + /* Enable icache */
91 + cm |= (1 << 31);
92 + /* Enable dcache */
93 + cm |= (1 << 30);
94 + write_c0_diag(cm);
95 + }
96 +#endif
97
98 /*
99 * c0_status.cu=0 specifies that updates by the sc instruction use
100 @@ -1165,6 +1192,15 @@
101
102 /* Default cache error handler for R4000 and R5000 family */
103 set_uncached_handler (0x100, &except_vec2_generic, 0x80);
104 +
105 + /* Check if special workarounds are required */
106 +#ifdef CONFIG_BCM4710
107 + if (current_cpu_data.cputype == CPU_BCM4710 && (current_cpu_data.processor_id & 0xff) == 0) {
108 + printk("Enabling BCM4710A0 cache workarounds.\n");
109 + bcm4710 = 1;
110 + } else
111 +#endif
112 + bcm4710 = 0;
113
114 probe_pcache();
115 setup_scache();
116 diff -urN linux.old/arch/mips/mm/tlbex.c linux.dev/arch/mips/mm/tlbex.c
117 --- linux.old/arch/mips/mm/tlbex.c 2006-03-21 12:12:38.000000000 +0100
118 +++ linux.dev/arch/mips/mm/tlbex.c 2006-03-21 12:19:26.000000000 +0100
119 @@ -28,6 +28,10 @@
120
121 /* #define DEBUG_TLB */
122
123 +#ifdef CONFIG_BCM4710
124 +extern int bcm4710;
125 +#endif
126 +
127 static __init int __attribute__((unused)) r45k_bvahwbug(void)
128 {
129 /* XXX: We should probe for the presence of this bug, but we don't. */
130 @@ -1152,6 +1156,12 @@
131 memset(relocs, 0, sizeof(relocs));
132 memset(final_handler, 0, sizeof(final_handler));
133
134 +#ifdef CONFIG_BCM4710
135 + if (bcm4710) {
136 + i_nop(&p);
137 + }
138 +#endif
139 +
140 /*
141 * create the plain linear handler
142 */
143 diff -urN linux.old/include/asm-mips/r4kcache.h linux.dev/include/asm-mips/r4kcache.h
144 --- linux.old/include/asm-mips/r4kcache.h 2006-03-20 06:53:29.000000000 +0100
145 +++ linux.dev/include/asm-mips/r4kcache.h 2006-03-21 18:40:32.000000000 +0100
146 @@ -16,6 +16,18 @@
147 #include <asm/cacheops.h>
148 #include <asm/cpu-features.h>
149
150 +#ifdef CONFIG_BCM4710
151 +#define BCM4710_DUMMY_RREG() (((sbconfig_t *)(KSEG1ADDR(SB_ENUM_BASE + SBCONFIGOFF)))->sbimstate)
152 +
153 +#define BCM4710_FILL_TLB(addr) (*(volatile unsigned long *)(addr))
154 +#define BCM4710_PROTECTED_FILL_TLB(addr) ({ unsigned long x; get_dbe(x, (volatile unsigned long *)(addr)); })
155 +#else
156 +#define BCM4710_DUMMY_RREG()
157 +
158 +#define BCM4710_FILL_TLB(addr)
159 +#define BCM4710_PROTECTED_FILL_TLB(addr)
160 +#endif
161 +
162 /*
163 * This macro return a properly sign-extended address suitable as base address
164 * for indexed cache operations. Two issues here:
165 @@ -46,6 +58,7 @@
166
167 static inline void flush_dcache_line_indexed(unsigned long addr)
168 {
169 + BCM4710_DUMMY_RREG();
170 cache_op(Index_Writeback_Inv_D, addr);
171 }
172
173 @@ -61,11 +74,13 @@
174
175 static inline void flush_dcache_line(unsigned long addr)
176 {
177 + BCM4710_DUMMY_RREG();
178 cache_op(Hit_Writeback_Inv_D, addr);
179 }
180
181 static inline void invalidate_dcache_line(unsigned long addr)
182 {
183 + BCM4710_DUMMY_RREG();
184 cache_op(Hit_Invalidate_D, addr);
185 }
186
187 @@ -97,6 +112,7 @@
188 */
189 static inline void protected_flush_icache_line(unsigned long addr)
190 {
191 + BCM4710_DUMMY_RREG();
192 protected_cache_op(Hit_Invalidate_I, addr);
193 }
194
195 @@ -108,6 +124,7 @@
196 */
197 static inline void protected_writeback_dcache_line(unsigned long addr)
198 {
199 + BCM4710_DUMMY_RREG();
200 protected_cache_op(Hit_Writeback_Inv_D, addr);
201 }
202
203 @@ -228,8 +245,52 @@
204 : "r" (base), \
205 "i" (op));
206
207 +static inline void blast_dcache(void)
208 +{
209 + unsigned long start = KSEG0;
210 + unsigned long dcache_size = current_cpu_data.dcache.waysize * current_cpu_data.dcache.ways;
211 + unsigned long end = (start + dcache_size);
212 +
213 + do {
214 + BCM4710_DUMMY_RREG();
215 + cache_op(Index_Writeback_Inv_D, start);
216 + start += current_cpu_data.dcache.linesz;
217 + } while(start < end);
218 +}
219 +
220 +static inline void blast_dcache_page(unsigned long page)
221 +{
222 + unsigned long start = page;
223 + unsigned long end = start + PAGE_SIZE;
224 +
225 + BCM4710_FILL_TLB(start);
226 + do {
227 + BCM4710_DUMMY_RREG();
228 + cache_op(Hit_Writeback_Inv_D, start);
229 + start += current_cpu_data.dcache.linesz;
230 + } while(start < end);
231 +}
232 +
233 +static inline void blast_dcache_page_indexed(unsigned long page)
234 +{
235 + unsigned long start = page;
236 + unsigned long end = start + PAGE_SIZE;
237 + unsigned long ws_inc = 1UL << current_cpu_data.dcache.waybit;
238 + unsigned long ws_end = current_cpu_data.dcache.ways <<
239 + current_cpu_data.dcache.waybit;
240 + unsigned long ws, addr;
241 + for (ws = 0; ws < ws_end; ws += ws_inc) {
242 + start = page + ws;
243 + for (addr = start; addr < end; addr += current_cpu_data.dcache.linesz) {
244 + BCM4710_DUMMY_RREG();
245 + cache_op(Index_Writeback_Inv_D, addr);
246 + }
247 + }
248 +}
249 +
250 +
251 /* build blast_xxx, blast_xxx_page, blast_xxx_page_indexed */
252 -#define __BUILD_BLAST_CACHE(pfx, desc, indexop, hitop, lsize) \
253 +#define __BUILD_BLAST_CACHE(pfx, desc, indexop, hitop, lsize, war) \
254 static inline void blast_##pfx##cache##lsize(void) \
255 { \
256 unsigned long start = INDEX_BASE; \
257 @@ -239,6 +300,7 @@
258 current_cpu_data.desc.waybit; \
259 unsigned long ws, addr; \
260 \
261 + war \
262 for (ws = 0; ws < ws_end; ws += ws_inc) \
263 for (addr = start; addr < end; addr += lsize * 32) \
264 cache##lsize##_unroll32(addr|ws,indexop); \
265 @@ -249,6 +311,7 @@
266 unsigned long start = page; \
267 unsigned long end = page + PAGE_SIZE; \
268 \
269 + war \
270 do { \
271 cache##lsize##_unroll32(start,hitop); \
272 start += lsize * 32; \
273 @@ -265,29 +328,31 @@
274 current_cpu_data.desc.waybit; \
275 unsigned long ws, addr; \
276 \
277 + war \
278 for (ws = 0; ws < ws_end; ws += ws_inc) \
279 for (addr = start; addr < end; addr += lsize * 32) \
280 cache##lsize##_unroll32(addr|ws,indexop); \
281 }
282
283 -__BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 16)
284 -__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16)
285 -__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16)
286 -__BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 32)
287 -__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32)
288 -__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32)
289 -__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64)
290 -__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 64)
291 -__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128)
292 +__BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 16, )
293 +__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16, BCM4710_FILL_TLB(start);)
294 +__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16, )
295 +__BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 32, )
296 +__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32, BCM4710_FILL_TLB(start);)
297 +__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32, )
298 +__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64, BCM4710_FILL_TLB(start);)
299 +__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 64, )
300 +__BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128, )
301
302 /* build blast_xxx_range, protected_blast_xxx_range */
303 -#define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot) \
304 +#define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot, war) \
305 static inline void prot##blast_##pfx##cache##_range(unsigned long start, \
306 unsigned long end) \
307 { \
308 unsigned long lsize = cpu_##desc##_line_size(); \
309 unsigned long addr = start & ~(lsize - 1); \
310 unsigned long aend = (end - 1) & ~(lsize - 1); \
311 + war \
312 while (1) { \
313 prot##cache_op(hitop, addr); \
314 if (addr == aend) \
315 @@ -296,12 +361,12 @@
316 } \
317 }
318
319 -__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_)
320 -__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_)
321 -__BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_)
322 -__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, )
323 -__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, )
324 +__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_, BCM4710_PROTECTED_FILL_TLB(addr); BCM4710_PROTECTED_FILL_TLB(aend);)
325 +__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_, )
326 +__BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_, )
327 +__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, , BCM4710_FILL_TLB(addr); BCM4710_FILL_TLB(aend);)
328 +__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, , )
329 /* blast_inv_dcache_range */
330 -__BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, )
331 +__BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, , )
332
333 #endif /* _ASM_R4KCACHE_H */
334 diff -urN linux.old/include/asm-mips/stackframe.h linux.dev/include/asm-mips/stackframe.h
335 --- linux.old/include/asm-mips/stackframe.h 2006-03-20 06:53:29.000000000 +0100
336 +++ linux.dev/include/asm-mips/stackframe.h 2006-03-21 12:19:26.000000000 +0100
337 @@ -285,6 +285,10 @@
338 .macro RESTORE_SP_AND_RET
339 LONG_L sp, PT_R29(sp)
340 .set mips3
341 +#ifdef CONFIG_BCM4710
342 + nop
343 + nop
344 +#endif
345 eret
346 .set mips0
347 .endm
This page took 0.059986 seconds and 5 git commands to generate.