1 --- a/arch/mips/kernel/entry.S
2 +++ b/arch/mips/kernel/entry.S
3 @@ -100,6 +100,10 @@ END(except_vec1_generic)
4 * and R4400 SC and MC versions.
6 NESTED(except_vec3_generic, 0, sp)
11 #if R5432_CP0_INTERRUPT_WAR
14 --- a/arch/mips/mm/c-r4k.c
15 +++ b/arch/mips/mm/c-r4k.c
18 #include <linux/bitops.h>
20 +#ifdef CONFIG_BCM4710
21 +#include "../bcm947xx/include/typedefs.h"
22 +#include "../bcm947xx/include/sbconfig.h"
23 +#include <asm/paccess.h>
26 #include <asm/bcache.h>
27 #include <asm/bootinfo.h>
28 #include <asm/cacheops.h>
29 @@ -40,6 +46,7 @@ static struct bcache_ops no_sc_ops = {
30 .bc_inv = (void *)no_sc_noop
34 struct bcache_ops *bcops = &no_sc_ops;
36 #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x2010)
37 @@ -64,8 +71,10 @@ static inline void r4k_blast_dcache_page
38 static inline void r4k_blast_dcache_page_setup(void)
40 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
45 + r4k_blast_dcache_page = blast_dcache_page;
46 + else if (dc_lsize == 16)
47 r4k_blast_dcache_page = blast_dcache16_page;
48 else if (dc_lsize == 32)
49 r4k_blast_dcache_page = r4k_blast_dcache_page_dc32;
50 @@ -77,7 +86,9 @@ static void r4k_blast_dcache_page_indexe
52 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
56 + r4k_blast_dcache_page_indexed = blast_dcache_page_indexed;
57 + else if (dc_lsize == 16)
58 r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed;
59 else if (dc_lsize == 32)
60 r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed;
61 @@ -89,7 +100,9 @@ static inline void r4k_blast_dcache_setu
63 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
67 + r4k_blast_dcache = blast_dcache;
68 + else if (dc_lsize == 16)
69 r4k_blast_dcache = blast_dcache16;
70 else if (dc_lsize == 32)
71 r4k_blast_dcache = blast_dcache32;
72 @@ -266,6 +279,7 @@ static void r4k___flush_cache_all(void)
77 switch (current_cpu_data.cputype) {
80 @@ -304,10 +318,10 @@ static void r4k_flush_cache_mm(struct mm
81 * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we
82 * only flush the primary caches but R10000 and R12000 behave sane ...
84 - if (current_cpu_data.cputype == CPU_R4000SC ||
85 + if (!bcm4710 && (current_cpu_data.cputype == CPU_R4000SC ||
86 current_cpu_data.cputype == CPU_R4000MC ||
87 current_cpu_data.cputype == CPU_R4400SC ||
88 - current_cpu_data.cputype == CPU_R4400MC)
89 + current_cpu_data.cputype == CPU_R4400MC))
93 @@ -383,12 +397,15 @@ static void r4k_flush_icache_range(unsig
94 unsigned long ic_lsize = current_cpu_data.icache.linesz;
95 unsigned long addr, aend;
97 + addr = start & ~(dc_lsize - 1);
98 + aend = (end - 1) & ~(dc_lsize - 1);
100 if (!cpu_has_ic_fills_f_dc) {
101 if (end - start > dcache_size)
104 - addr = start & ~(dc_lsize - 1);
105 - aend = (end - 1) & ~(dc_lsize - 1);
106 + BCM4710_PROTECTED_FILL_TLB(addr);
107 + BCM4710_PROTECTED_FILL_TLB(aend);
110 /* Hit_Writeback_Inv_D */
111 @@ -403,8 +420,6 @@ static void r4k_flush_icache_range(unsig
112 if (end - start > icache_size)
115 - addr = start & ~(ic_lsize - 1);
116 - aend = (end - 1) & ~(ic_lsize - 1);
118 /* Hit_Invalidate_I */
119 protected_flush_icache_line(addr);
120 @@ -413,6 +428,9 @@ static void r4k_flush_icache_range(unsig
130 @@ -443,7 +461,8 @@ static void r4k_flush_icache_page(struct
131 if (cpu_has_subset_pcaches) {
132 unsigned long addr = (unsigned long) page_address(page);
134 - r4k_blast_scache_page(addr);
136 + r4k_blast_scache_page(addr);
137 ClearPageDcacheDirty(page);
140 @@ -451,6 +470,7 @@ static void r4k_flush_icache_page(struct
142 if (!cpu_has_ic_fills_f_dc) {
143 unsigned long addr = (unsigned long) page_address(page);
145 r4k_blast_dcache_page(addr);
146 ClearPageDcacheDirty(page);
148 @@ -477,7 +497,7 @@ static void r4k_dma_cache_wback_inv(unsi
149 /* Catch bad driver code */
152 - if (cpu_has_subset_pcaches) {
153 + if (!bcm4710 && cpu_has_subset_pcaches) {
154 unsigned long sc_lsize = current_cpu_data.scache.linesz;
156 if (size >= scache_size) {
157 @@ -509,6 +529,8 @@ static void r4k_dma_cache_wback_inv(unsi
158 R4600_HIT_CACHEOP_WAR_IMPL;
159 a = addr & ~(dc_lsize - 1);
160 end = (addr + size - 1) & ~(dc_lsize - 1);
161 + BCM4710_FILL_TLB(a);
162 + BCM4710_FILL_TLB(end);
164 flush_dcache_line(a); /* Hit_Writeback_Inv_D */
166 @@ -527,7 +549,7 @@ static void r4k_dma_cache_inv(unsigned l
167 /* Catch bad driver code */
170 - if (cpu_has_subset_pcaches) {
171 + if (!bcm4710 && (cpu_has_subset_pcaches)) {
172 unsigned long sc_lsize = current_cpu_data.scache.linesz;
174 if (size >= scache_size) {
175 @@ -554,6 +576,8 @@ static void r4k_dma_cache_inv(unsigned l
176 R4600_HIT_CACHEOP_WAR_IMPL;
177 a = addr & ~(dc_lsize - 1);
178 end = (addr + size - 1) & ~(dc_lsize - 1);
179 + BCM4710_FILL_TLB(a);
180 + BCM4710_FILL_TLB(end);
182 flush_dcache_line(a); /* Hit_Writeback_Inv_D */
184 @@ -577,6 +601,8 @@ static void r4k_flush_cache_sigtramp(uns
185 unsigned long dc_lsize = current_cpu_data.dcache.linesz;
187 R4600_HIT_CACHEOP_WAR_IMPL;
188 + BCM4710_PROTECTED_FILL_TLB(addr);
189 + BCM4710_PROTECTED_FILL_TLB(addr + 4);
190 protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
191 protected_flush_icache_line(addr & ~(ic_lsize - 1));
192 if (MIPS4K_ICACHE_REFILL_WAR) {
193 @@ -986,10 +1012,12 @@ static void __init setup_scache(void)
197 - probe_scache_kseg1 = (probe_func_t) (KSEG1ADDR(&probe_scache));
198 - sc_present = probe_scache_kseg1(config);
200 - c->options |= MIPS_CPU_CACHE_CDEX_S;
202 + probe_scache_kseg1 = (probe_func_t) (KSEG1ADDR(&probe_scache));
203 + sc_present = probe_scache_kseg1(config);
205 + c->options |= MIPS_CPU_CACHE_CDEX_S;
210 @@ -1041,6 +1069,19 @@ static void __init setup_scache(void)
211 static inline void coherency_setup(void)
213 change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
215 +#if defined(CONFIG_BCM4310) || defined(CONFIG_BCM4704) || defined(CONFIG_BCM5365)
216 + if (BCM330X(current_cpu_data.processor_id)) {
219 + cm = read_c0_diag();
220 + /* Enable icache */
222 + /* Enable dcache */
229 * c0_status.cu=0 specifies that updates by the sc instruction use
230 @@ -1073,6 +1114,12 @@ void __init ld_mmu_r4xx0(void)
231 memcpy((void *)(KSEG0 + 0x100), &except_vec2_generic, 0x80);
232 memcpy((void *)(KSEG1 + 0x100), &except_vec2_generic, 0x80);
234 + if (current_cpu_data.cputype == CPU_BCM4710 && (current_cpu_data.processor_id & PRID_REV_MASK) == 0) {
235 + printk("Enabling BCM4710A0 cache workarounds.\n");
243 --- a/arch/mips/mm/tlbex-mips32.S
244 +++ b/arch/mips/mm/tlbex-mips32.S
247 LEAF(except_vec0_r4000)
249 +#ifdef CONFIG_BCM4704
255 --- a/include/asm-mips/r4kcache.h
256 +++ b/include/asm-mips/r4kcache.h
259 #include <asm/cacheops.h>
261 +#ifdef CONFIG_BCM4710
262 +#define BCM4710_DUMMY_RREG() (((sbconfig_t *)(KSEG1ADDR(SB_ENUM_BASE + SBCONFIGOFF)))->sbimstate)
264 +#define BCM4710_FILL_TLB(addr) (*(volatile unsigned long *)(addr))
265 +#define BCM4710_PROTECTED_FILL_TLB(addr) ({ unsigned long x; get_dbe(x, (volatile unsigned long *)(addr)); })
267 +#define BCM4710_DUMMY_RREG()
269 +#define BCM4710_FILL_TLB(addr)
270 +#define BCM4710_PROTECTED_FILL_TLB(addr)
273 #define cache_op(op,addr) \
274 __asm__ __volatile__( \
275 " .set noreorder \n" \
278 static inline void flush_icache_line_indexed(unsigned long addr)
280 - cache_op(Index_Invalidate_I, addr);
282 + unsigned long ws_inc = 1UL << current_cpu_data.dcache.waybit;
284 + for (way = 0; way < current_cpu_data.dcache.ways; way++) {
285 + cache_op(Index_Invalidate_I, addr);
290 static inline void flush_dcache_line_indexed(unsigned long addr)
292 - cache_op(Index_Writeback_Inv_D, addr);
294 + unsigned long ws_inc = 1UL << current_cpu_data.dcache.waybit;
296 + for (way = 0; way < current_cpu_data.dcache.ways; way++) {
297 + BCM4710_DUMMY_RREG();
298 + cache_op(Index_Writeback_Inv_D, addr);
303 static inline void flush_scache_line_indexed(unsigned long addr)
304 @@ -47,6 +72,7 @@ static inline void flush_icache_line(uns
306 static inline void flush_dcache_line(unsigned long addr)
308 + BCM4710_DUMMY_RREG();
309 cache_op(Hit_Writeback_Inv_D, addr);
312 @@ -91,6 +117,7 @@ static inline void protected_flush_icach
314 static inline void protected_writeback_dcache_line(unsigned long addr)
316 + BCM4710_DUMMY_RREG();
317 __asm__ __volatile__(
320 @@ -138,6 +165,62 @@ static inline void invalidate_tcache_pag
324 +#define cache_unroll(base,op) \
325 + __asm__ __volatile__(" \
336 +static inline void blast_dcache(void)
338 + unsigned long start = KSEG0;
339 + unsigned long dcache_size = current_cpu_data.dcache.waysize * current_cpu_data.dcache.ways;
340 + unsigned long end = (start + dcache_size);
342 + while(start < end) {
343 + BCM4710_DUMMY_RREG();
344 + cache_unroll(start,Index_Writeback_Inv_D);
345 + start += current_cpu_data.dcache.linesz;
349 +static inline void blast_dcache_page(unsigned long page)
351 + unsigned long start = page;
352 + unsigned long end = start + PAGE_SIZE;
354 + BCM4710_FILL_TLB(start);
356 + BCM4710_DUMMY_RREG();
357 + cache_unroll(start,Hit_Writeback_Inv_D);
358 + start += current_cpu_data.dcache.linesz;
359 + } while (start < end);
362 +static inline void blast_dcache_page_indexed(unsigned long page)
364 + unsigned long start = page;
365 + unsigned long end = start + PAGE_SIZE;
366 + unsigned long ws_inc = 1UL << current_cpu_data.dcache.waybit;
367 + unsigned long ws_end = current_cpu_data.dcache.ways <<
368 + current_cpu_data.dcache.waybit;
369 + unsigned long ws, addr;
371 + for (ws = 0; ws < ws_end; ws += ws_inc) {
373 + for (addr = start; addr < end; addr += current_cpu_data.dcache.linesz) {
374 + BCM4710_DUMMY_RREG();
375 + cache_unroll(addr,Index_Writeback_Inv_D);
380 static inline void blast_dcache16(void)
382 unsigned long start = KSEG0;
383 @@ -148,8 +231,9 @@ static inline void blast_dcache16(void)
384 unsigned long ws, addr;
386 for (ws = 0; ws < ws_end; ws += ws_inc)
387 - for (addr = start; addr < end; addr += 0x200)
388 + for (addr = start; addr < end; addr += 0x200) {
389 cache16_unroll32(addr|ws,Index_Writeback_Inv_D);
393 static inline void blast_dcache16_page(unsigned long page)
394 @@ -173,8 +257,9 @@ static inline void blast_dcache16_page_i
395 unsigned long ws, addr;
397 for (ws = 0; ws < ws_end; ws += ws_inc)
398 - for (addr = start; addr < end; addr += 0x200)
399 + for (addr = start; addr < end; addr += 0x200) {
400 cache16_unroll32(addr|ws,Index_Writeback_Inv_D);
404 static inline void blast_icache16(void)
405 @@ -196,6 +281,7 @@ static inline void blast_icache16_page(u
406 unsigned long start = page;
407 unsigned long end = start + PAGE_SIZE;
409 + BCM4710_FILL_TLB(start);
411 cache16_unroll32(start,Hit_Invalidate_I);
413 @@ -281,6 +367,7 @@ static inline void blast_scache16_page_i
418 static inline void blast_dcache32(void)
420 unsigned long start = KSEG0;
421 @@ -291,8 +378,9 @@ static inline void blast_dcache32(void)
422 unsigned long ws, addr;
424 for (ws = 0; ws < ws_end; ws += ws_inc)
425 - for (addr = start; addr < end; addr += 0x400)
426 + for (addr = start; addr < end; addr += 0x400) {
427 cache32_unroll32(addr|ws,Index_Writeback_Inv_D);
431 static inline void blast_dcache32_page(unsigned long page)
432 @@ -316,8 +404,9 @@ static inline void blast_dcache32_page_i
433 unsigned long ws, addr;
435 for (ws = 0; ws < ws_end; ws += ws_inc)
436 - for (addr = start; addr < end; addr += 0x400)
437 + for (addr = start; addr < end; addr += 0x400) {
438 cache32_unroll32(addr|ws,Index_Writeback_Inv_D);
442 static inline void blast_icache32(void)
443 @@ -339,6 +428,7 @@ static inline void blast_icache32_page(u
444 unsigned long start = page;
445 unsigned long end = start + PAGE_SIZE;
447 + BCM4710_FILL_TLB(start);
449 cache32_unroll32(start,Hit_Invalidate_I);
451 @@ -443,6 +533,7 @@ static inline void blast_icache64_page(u
452 unsigned long start = page;
453 unsigned long end = start + PAGE_SIZE;
455 + BCM4710_FILL_TLB(start);
457 cache64_unroll32(start,Hit_Invalidate_I);
459 --- a/include/asm-mips/stackframe.h
460 +++ b/include/asm-mips/stackframe.h
465 +#if defined(CONFIG_BCM4710) || defined(CONFIG_BCM4704)
467 +#undef RESTORE_SP_AND_RET
468 +#define RESTORE_SP_AND_RET \
469 + lw sp, PT_R29(sp); \
484 @@ -927,6 +927,7 @@ static inline void break_cow(struct vm_a
485 flush_page_to_ram(new_page);
486 flush_cache_page(vma, address);
487 establish_pte(vma, address, page_table, pte_mkwrite(pte_mkdirty(mk_pte(new_page, vma->vm_page_prot))));
488 + flush_icache_page(vma, new_page);