Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com) |
| 7 | * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Ralf Baechle (ralf@gnu.org) |
| 8 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
| 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/bitops.h> |
| 15 | |
| 16 | #include <asm/bcache.h> |
| 17 | #include <asm/bootinfo.h> |
Ralf Baechle | ec74e36 | 2005-07-13 11:48:45 +0000 | [diff] [blame] | 18 | #include <asm/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/cacheops.h> |
| 20 | #include <asm/cpu.h> |
| 21 | #include <asm/cpu-features.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/r4kcache.h> |
Ralf Baechle | e001e52 | 2007-07-28 12:45:47 +0100 | [diff] [blame^] | 26 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/system.h> |
| 28 | #include <asm/mmu_context.h> |
| 29 | #include <asm/war.h> |
Thiemo Seufer | ba5187d | 2005-04-25 16:36:23 +0000 | [diff] [blame] | 30 | #include <asm/cacheflush.h> /* for run_uncached() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Special Variant of smp_call_function for use by cache functions: |
| 35 | * |
| 36 | * o No return value |
| 37 | * o collapses to normal function call on UP kernels |
| 38 | * o collapses to normal function call on systems with a single shared |
| 39 | * primary cache. |
| 40 | */ |
| 41 | static inline void r4k_on_each_cpu(void (*func) (void *info), void *info, |
| 42 | int retry, int wait) |
| 43 | { |
| 44 | preempt_disable(); |
| 45 | |
| 46 | #if !defined(CONFIG_MIPS_MT_SMP) && !defined(CONFIG_MIPS_MT_SMTC) |
| 47 | smp_call_function(func, info, retry, wait); |
| 48 | #endif |
| 49 | func(info); |
| 50 | preempt_enable(); |
| 51 | } |
| 52 | |
Ralf Baechle | ec74e36 | 2005-07-13 11:48:45 +0000 | [diff] [blame] | 53 | /* |
| 54 | * Must die. |
| 55 | */ |
| 56 | static unsigned long icache_size __read_mostly; |
| 57 | static unsigned long dcache_size __read_mostly; |
| 58 | static unsigned long scache_size __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Dummy cache handling routines for machines without boardcaches |
| 62 | */ |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 63 | static void cache_noop(void) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | static struct bcache_ops no_sc_ops = { |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 66 | .bc_enable = (void *)cache_noop, |
| 67 | .bc_disable = (void *)cache_noop, |
| 68 | .bc_wback_inv = (void *)cache_noop, |
| 69 | .bc_inv = (void *)cache_noop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct bcache_ops *bcops = &no_sc_ops; |
| 73 | |
Thiemo Seufer | 330cfe0 | 2005-09-01 18:33:58 +0000 | [diff] [blame] | 74 | #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010) |
| 75 | #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | #define R4600_HIT_CACHEOP_WAR_IMPL \ |
| 78 | do { \ |
| 79 | if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x()) \ |
| 80 | *(volatile unsigned long *)CKSEG1; \ |
| 81 | if (R4600_V1_HIT_CACHEOP_WAR) \ |
| 82 | __asm__ __volatile__("nop;nop;nop;nop"); \ |
| 83 | } while (0) |
| 84 | |
| 85 | static void (*r4k_blast_dcache_page)(unsigned long addr); |
| 86 | |
| 87 | static inline void r4k_blast_dcache_page_dc32(unsigned long addr) |
| 88 | { |
| 89 | R4600_HIT_CACHEOP_WAR_IMPL; |
| 90 | blast_dcache32_page(addr); |
| 91 | } |
| 92 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 93 | static void __init r4k_blast_dcache_page_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | unsigned long dc_lsize = cpu_dcache_line_size(); |
| 96 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 97 | if (dc_lsize == 0) |
| 98 | r4k_blast_dcache_page = (void *)cache_noop; |
| 99 | else if (dc_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | r4k_blast_dcache_page = blast_dcache16_page; |
| 101 | else if (dc_lsize == 32) |
| 102 | r4k_blast_dcache_page = r4k_blast_dcache_page_dc32; |
| 103 | } |
| 104 | |
| 105 | static void (* r4k_blast_dcache_page_indexed)(unsigned long addr); |
| 106 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 107 | static void __init r4k_blast_dcache_page_indexed_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
| 109 | unsigned long dc_lsize = cpu_dcache_line_size(); |
| 110 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 111 | if (dc_lsize == 0) |
| 112 | r4k_blast_dcache_page_indexed = (void *)cache_noop; |
| 113 | else if (dc_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed; |
| 115 | else if (dc_lsize == 32) |
| 116 | r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed; |
| 117 | } |
| 118 | |
| 119 | static void (* r4k_blast_dcache)(void); |
| 120 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 121 | static void __init r4k_blast_dcache_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | unsigned long dc_lsize = cpu_dcache_line_size(); |
| 124 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 125 | if (dc_lsize == 0) |
| 126 | r4k_blast_dcache = (void *)cache_noop; |
| 127 | else if (dc_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | r4k_blast_dcache = blast_dcache16; |
| 129 | else if (dc_lsize == 32) |
| 130 | r4k_blast_dcache = blast_dcache32; |
| 131 | } |
| 132 | |
| 133 | /* force code alignment (used for TX49XX_ICACHE_INDEX_INV_WAR) */ |
| 134 | #define JUMP_TO_ALIGN(order) \ |
| 135 | __asm__ __volatile__( \ |
| 136 | "b\t1f\n\t" \ |
| 137 | ".align\t" #order "\n\t" \ |
| 138 | "1:\n\t" \ |
| 139 | ) |
| 140 | #define CACHE32_UNROLL32_ALIGN JUMP_TO_ALIGN(10) /* 32 * 32 = 1024 */ |
| 141 | #define CACHE32_UNROLL32_ALIGN2 JUMP_TO_ALIGN(11) |
| 142 | |
| 143 | static inline void blast_r4600_v1_icache32(void) |
| 144 | { |
| 145 | unsigned long flags; |
| 146 | |
| 147 | local_irq_save(flags); |
| 148 | blast_icache32(); |
| 149 | local_irq_restore(flags); |
| 150 | } |
| 151 | |
| 152 | static inline void tx49_blast_icache32(void) |
| 153 | { |
| 154 | unsigned long start = INDEX_BASE; |
| 155 | unsigned long end = start + current_cpu_data.icache.waysize; |
| 156 | unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit; |
| 157 | unsigned long ws_end = current_cpu_data.icache.ways << |
| 158 | current_cpu_data.icache.waybit; |
| 159 | unsigned long ws, addr; |
| 160 | |
| 161 | CACHE32_UNROLL32_ALIGN2; |
| 162 | /* I'm in even chunk. blast odd chunks */ |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 163 | for (ws = 0; ws < ws_end; ws += ws_inc) |
| 164 | for (addr = start + 0x400; addr < end; addr += 0x400 * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | cache32_unroll32(addr|ws,Index_Invalidate_I); |
| 166 | CACHE32_UNROLL32_ALIGN; |
| 167 | /* I'm in odd chunk. blast even chunks */ |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 168 | for (ws = 0; ws < ws_end; ws += ws_inc) |
| 169 | for (addr = start; addr < end; addr += 0x400 * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | cache32_unroll32(addr|ws,Index_Invalidate_I); |
| 171 | } |
| 172 | |
| 173 | static inline void blast_icache32_r4600_v1_page_indexed(unsigned long page) |
| 174 | { |
| 175 | unsigned long flags; |
| 176 | |
| 177 | local_irq_save(flags); |
| 178 | blast_icache32_page_indexed(page); |
| 179 | local_irq_restore(flags); |
| 180 | } |
| 181 | |
| 182 | static inline void tx49_blast_icache32_page_indexed(unsigned long page) |
| 183 | { |
Atsushi Nemoto | 67a3f6d | 2006-04-04 17:34:14 +0900 | [diff] [blame] | 184 | unsigned long indexmask = current_cpu_data.icache.waysize - 1; |
| 185 | unsigned long start = INDEX_BASE + (page & indexmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | unsigned long end = start + PAGE_SIZE; |
| 187 | unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit; |
| 188 | unsigned long ws_end = current_cpu_data.icache.ways << |
| 189 | current_cpu_data.icache.waybit; |
| 190 | unsigned long ws, addr; |
| 191 | |
| 192 | CACHE32_UNROLL32_ALIGN2; |
| 193 | /* I'm in even chunk. blast odd chunks */ |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 194 | for (ws = 0; ws < ws_end; ws += ws_inc) |
| 195 | for (addr = start + 0x400; addr < end; addr += 0x400 * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | cache32_unroll32(addr|ws,Index_Invalidate_I); |
| 197 | CACHE32_UNROLL32_ALIGN; |
| 198 | /* I'm in odd chunk. blast even chunks */ |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 199 | for (ws = 0; ws < ws_end; ws += ws_inc) |
| 200 | for (addr = start; addr < end; addr += 0x400 * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | cache32_unroll32(addr|ws,Index_Invalidate_I); |
| 202 | } |
| 203 | |
| 204 | static void (* r4k_blast_icache_page)(unsigned long addr); |
| 205 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 206 | static void __init r4k_blast_icache_page_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | unsigned long ic_lsize = cpu_icache_line_size(); |
| 209 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 210 | if (ic_lsize == 0) |
| 211 | r4k_blast_icache_page = (void *)cache_noop; |
| 212 | else if (ic_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | r4k_blast_icache_page = blast_icache16_page; |
| 214 | else if (ic_lsize == 32) |
| 215 | r4k_blast_icache_page = blast_icache32_page; |
| 216 | else if (ic_lsize == 64) |
| 217 | r4k_blast_icache_page = blast_icache64_page; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | static void (* r4k_blast_icache_page_indexed)(unsigned long addr); |
| 222 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 223 | static void __init r4k_blast_icache_page_indexed_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | unsigned long ic_lsize = cpu_icache_line_size(); |
| 226 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 227 | if (ic_lsize == 0) |
| 228 | r4k_blast_icache_page_indexed = (void *)cache_noop; |
| 229 | else if (ic_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | r4k_blast_icache_page_indexed = blast_icache16_page_indexed; |
| 231 | else if (ic_lsize == 32) { |
Thiemo Seufer | 02fe2c9 | 2005-09-09 19:45:41 +0000 | [diff] [blame] | 232 | if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | r4k_blast_icache_page_indexed = |
| 234 | blast_icache32_r4600_v1_page_indexed; |
Thiemo Seufer | 02fe2c9 | 2005-09-09 19:45:41 +0000 | [diff] [blame] | 235 | else if (TX49XX_ICACHE_INDEX_INV_WAR) |
| 236 | r4k_blast_icache_page_indexed = |
| 237 | tx49_blast_icache32_page_indexed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | else |
| 239 | r4k_blast_icache_page_indexed = |
| 240 | blast_icache32_page_indexed; |
| 241 | } else if (ic_lsize == 64) |
| 242 | r4k_blast_icache_page_indexed = blast_icache64_page_indexed; |
| 243 | } |
| 244 | |
| 245 | static void (* r4k_blast_icache)(void); |
| 246 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 247 | static void __init r4k_blast_icache_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | unsigned long ic_lsize = cpu_icache_line_size(); |
| 250 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 251 | if (ic_lsize == 0) |
| 252 | r4k_blast_icache = (void *)cache_noop; |
| 253 | else if (ic_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | r4k_blast_icache = blast_icache16; |
| 255 | else if (ic_lsize == 32) { |
| 256 | if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x()) |
| 257 | r4k_blast_icache = blast_r4600_v1_icache32; |
| 258 | else if (TX49XX_ICACHE_INDEX_INV_WAR) |
| 259 | r4k_blast_icache = tx49_blast_icache32; |
| 260 | else |
| 261 | r4k_blast_icache = blast_icache32; |
| 262 | } else if (ic_lsize == 64) |
| 263 | r4k_blast_icache = blast_icache64; |
| 264 | } |
| 265 | |
| 266 | static void (* r4k_blast_scache_page)(unsigned long addr); |
| 267 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 268 | static void __init r4k_blast_scache_page_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | unsigned long sc_lsize = cpu_scache_line_size(); |
| 271 | |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 272 | if (scache_size == 0) |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 273 | r4k_blast_scache_page = (void *)cache_noop; |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 274 | else if (sc_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | r4k_blast_scache_page = blast_scache16_page; |
| 276 | else if (sc_lsize == 32) |
| 277 | r4k_blast_scache_page = blast_scache32_page; |
| 278 | else if (sc_lsize == 64) |
| 279 | r4k_blast_scache_page = blast_scache64_page; |
| 280 | else if (sc_lsize == 128) |
| 281 | r4k_blast_scache_page = blast_scache128_page; |
| 282 | } |
| 283 | |
| 284 | static void (* r4k_blast_scache_page_indexed)(unsigned long addr); |
| 285 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 286 | static void __init r4k_blast_scache_page_indexed_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
| 288 | unsigned long sc_lsize = cpu_scache_line_size(); |
| 289 | |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 290 | if (scache_size == 0) |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 291 | r4k_blast_scache_page_indexed = (void *)cache_noop; |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 292 | else if (sc_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | r4k_blast_scache_page_indexed = blast_scache16_page_indexed; |
| 294 | else if (sc_lsize == 32) |
| 295 | r4k_blast_scache_page_indexed = blast_scache32_page_indexed; |
| 296 | else if (sc_lsize == 64) |
| 297 | r4k_blast_scache_page_indexed = blast_scache64_page_indexed; |
| 298 | else if (sc_lsize == 128) |
| 299 | r4k_blast_scache_page_indexed = blast_scache128_page_indexed; |
| 300 | } |
| 301 | |
| 302 | static void (* r4k_blast_scache)(void); |
| 303 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 304 | static void __init r4k_blast_scache_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | unsigned long sc_lsize = cpu_scache_line_size(); |
| 307 | |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 308 | if (scache_size == 0) |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 309 | r4k_blast_scache = (void *)cache_noop; |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 310 | else if (sc_lsize == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | r4k_blast_scache = blast_scache16; |
| 312 | else if (sc_lsize == 32) |
| 313 | r4k_blast_scache = blast_scache32; |
| 314 | else if (sc_lsize == 64) |
| 315 | r4k_blast_scache = blast_scache64; |
| 316 | else if (sc_lsize == 128) |
| 317 | r4k_blast_scache = blast_scache128; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * This is former mm's flush_cache_all() which really should be |
| 322 | * flush_cache_vunmap these days ... |
| 323 | */ |
| 324 | static inline void local_r4k_flush_cache_all(void * args) |
| 325 | { |
| 326 | r4k_blast_dcache(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static void r4k_flush_cache_all(void) |
| 330 | { |
| 331 | if (!cpu_has_dc_aliases) |
| 332 | return; |
| 333 | |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 334 | r4k_on_each_cpu(local_r4k_flush_cache_all, NULL, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static inline void local_r4k___flush_cache_all(void * args) |
| 338 | { |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 339 | #if defined(CONFIG_CPU_LOONGSON2) |
| 340 | r4k_blast_scache(); |
| 341 | return; |
| 342 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | r4k_blast_dcache(); |
| 344 | r4k_blast_icache(); |
| 345 | |
| 346 | switch (current_cpu_data.cputype) { |
| 347 | case CPU_R4000SC: |
| 348 | case CPU_R4000MC: |
| 349 | case CPU_R4400SC: |
| 350 | case CPU_R4400MC: |
| 351 | case CPU_R10000: |
| 352 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 353 | case CPU_R14000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | r4k_blast_scache(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | static void r4k___flush_cache_all(void) |
| 359 | { |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 360 | r4k_on_each_cpu(local_r4k___flush_cache_all, NULL, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static inline void local_r4k_flush_cache_range(void * args) |
| 364 | { |
| 365 | struct vm_area_struct *vma = args; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | if (!(cpu_context(smp_processor_id(), vma->vm_mm))) |
| 368 | return; |
| 369 | |
Atsushi Nemoto | 0550d9d | 2006-08-22 21:15:47 +0900 | [diff] [blame] | 370 | r4k_blast_dcache(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void r4k_flush_cache_range(struct vm_area_struct *vma, |
| 374 | unsigned long start, unsigned long end) |
| 375 | { |
Atsushi Nemoto | 0550d9d | 2006-08-22 21:15:47 +0900 | [diff] [blame] | 376 | if (!cpu_has_dc_aliases) |
| 377 | return; |
| 378 | |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 379 | r4k_on_each_cpu(local_r4k_flush_cache_range, vma, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static inline void local_r4k_flush_cache_mm(void * args) |
| 383 | { |
| 384 | struct mm_struct *mm = args; |
| 385 | |
| 386 | if (!cpu_context(smp_processor_id(), mm)) |
| 387 | return; |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* |
| 390 | * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we |
| 391 | * only flush the primary caches but R10000 and R12000 behave sane ... |
Ralf Baechle | 617667b | 2006-11-30 01:14:48 +0000 | [diff] [blame] | 392 | * R4000SC and R4400SC indexed S-cache ops also invalidate primary |
| 393 | * caches, so we can bail out early. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | */ |
| 395 | if (current_cpu_data.cputype == CPU_R4000SC || |
| 396 | current_cpu_data.cputype == CPU_R4000MC || |
| 397 | current_cpu_data.cputype == CPU_R4400SC || |
Ralf Baechle | 617667b | 2006-11-30 01:14:48 +0000 | [diff] [blame] | 398 | current_cpu_data.cputype == CPU_R4400MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | r4k_blast_scache(); |
Ralf Baechle | 617667b | 2006-11-30 01:14:48 +0000 | [diff] [blame] | 400 | return; |
| 401 | } |
| 402 | |
| 403 | r4k_blast_dcache(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void r4k_flush_cache_mm(struct mm_struct *mm) |
| 407 | { |
| 408 | if (!cpu_has_dc_aliases) |
| 409 | return; |
| 410 | |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 411 | r4k_on_each_cpu(local_r4k_flush_cache_mm, mm, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | struct flush_cache_page_args { |
| 415 | struct vm_area_struct *vma; |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 416 | unsigned long addr; |
Atsushi Nemoto | de62893 | 2006-03-13 18:23:03 +0900 | [diff] [blame] | 417 | unsigned long pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | static inline void local_r4k_flush_cache_page(void *args) |
| 421 | { |
| 422 | struct flush_cache_page_args *fcp_args = args; |
| 423 | struct vm_area_struct *vma = fcp_args->vma; |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 424 | unsigned long addr = fcp_args->addr; |
Atsushi Nemoto | de62893 | 2006-03-13 18:23:03 +0900 | [diff] [blame] | 425 | unsigned long paddr = fcp_args->pfn << PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | int exec = vma->vm_flags & VM_EXEC; |
| 427 | struct mm_struct *mm = vma->vm_mm; |
| 428 | pgd_t *pgdp; |
Ralf Baechle | c6e8b58 | 2005-02-10 12:19:59 +0000 | [diff] [blame] | 429 | pud_t *pudp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | pmd_t *pmdp; |
| 431 | pte_t *ptep; |
| 432 | |
Ralf Baechle | 79acf83 | 2005-02-10 13:54:37 +0000 | [diff] [blame] | 433 | /* |
| 434 | * If ownes no valid ASID yet, cannot possibly have gotten |
| 435 | * this page into the cache. |
| 436 | */ |
Thiemo Seufer | 26a51b2 | 2005-02-19 13:32:02 +0000 | [diff] [blame] | 437 | if (cpu_context(smp_processor_id(), mm) == 0) |
Ralf Baechle | 79acf83 | 2005-02-10 13:54:37 +0000 | [diff] [blame] | 438 | return; |
| 439 | |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 440 | addr &= PAGE_MASK; |
| 441 | pgdp = pgd_offset(mm, addr); |
| 442 | pudp = pud_offset(pgdp, addr); |
| 443 | pmdp = pmd_offset(pudp, addr); |
| 444 | ptep = pte_offset(pmdp, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * If the page isn't marked valid, the page cannot possibly be |
| 448 | * in the cache. |
| 449 | */ |
| 450 | if (!(pte_val(*ptep) & _PAGE_PRESENT)) |
| 451 | return; |
| 452 | |
| 453 | /* |
| 454 | * Doing flushes for another ASID than the current one is |
| 455 | * too difficult since stupid R4k caches do a TLB translation |
| 456 | * for every cache flush operation. So we do indexed flushes |
| 457 | * in that case, which doesn't overly flush the cache too much. |
| 458 | */ |
| 459 | if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) { |
| 460 | if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) { |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 461 | r4k_blast_dcache_page(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | if (exec && !cpu_icache_snoops_remote_store) |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 463 | r4k_blast_scache_page(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | if (exec) |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 466 | r4k_blast_icache_page(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | return; |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Do indexed flush, too much work to get the (possible) TLB refills |
| 473 | * to work correctly. |
| 474 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) { |
Atsushi Nemoto | de62893 | 2006-03-13 18:23:03 +0900 | [diff] [blame] | 476 | r4k_blast_dcache_page_indexed(cpu_has_pindexed_dcache ? |
| 477 | paddr : addr); |
| 478 | if (exec && !cpu_icache_snoops_remote_store) { |
| 479 | r4k_blast_scache_page_indexed(paddr); |
| 480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | if (exec) { |
Atsushi Nemoto | f650279 | 2006-08-25 17:55:31 +0900 | [diff] [blame] | 483 | if (cpu_has_vtag_icache && mm == current->active_mm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | int cpu = smp_processor_id(); |
| 485 | |
Thiemo Seufer | 26a51b2 | 2005-02-19 13:32:02 +0000 | [diff] [blame] | 486 | if (cpu_context(cpu, mm) != 0) |
| 487 | drop_mmu_context(mm, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } else |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 489 | r4k_blast_icache_page_indexed(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 493 | static void r4k_flush_cache_page(struct vm_area_struct *vma, |
| 494 | unsigned long addr, unsigned long pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
| 496 | struct flush_cache_page_args args; |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | args.vma = vma; |
Ralf Baechle | 6ec2580 | 2005-10-12 00:02:34 +0100 | [diff] [blame] | 499 | args.addr = addr; |
Atsushi Nemoto | de62893 | 2006-03-13 18:23:03 +0900 | [diff] [blame] | 500 | args.pfn = pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 502 | r4k_on_each_cpu(local_r4k_flush_cache_page, &args, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static inline void local_r4k_flush_data_cache_page(void * addr) |
| 506 | { |
| 507 | r4k_blast_dcache_page((unsigned long) addr); |
| 508 | } |
| 509 | |
| 510 | static void r4k_flush_data_cache_page(unsigned long addr) |
| 511 | { |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 512 | r4k_on_each_cpu(local_r4k_flush_data_cache_page, (void *) addr, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | struct flush_icache_range_args { |
Atsushi Nemoto | d4264f1 | 2006-01-29 02:27:51 +0900 | [diff] [blame] | 516 | unsigned long start; |
| 517 | unsigned long end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | static inline void local_r4k_flush_icache_range(void *args) |
| 521 | { |
| 522 | struct flush_icache_range_args *fir_args = args; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | unsigned long start = fir_args->start; |
| 524 | unsigned long end = fir_args->end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | if (!cpu_has_ic_fills_f_dc) { |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 527 | if (end - start >= dcache_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | r4k_blast_dcache(); |
| 529 | } else { |
Thiemo Seufer | 10a3dab | 2005-09-09 20:26:54 +0000 | [diff] [blame] | 530 | R4600_HIT_CACHEOP_WAR_IMPL; |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 531 | protected_blast_dcache_range(start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 534 | if (!cpu_icache_snoops_remote_store && scache_size) { |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 535 | if (end - start > scache_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | r4k_blast_scache(); |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 537 | else |
| 538 | protected_blast_scache_range(start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | if (end - start > icache_size) |
| 543 | r4k_blast_icache(); |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 544 | else |
| 545 | protected_blast_icache_range(start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Atsushi Nemoto | d4264f1 | 2006-01-29 02:27:51 +0900 | [diff] [blame] | 548 | static void r4k_flush_icache_range(unsigned long start, unsigned long end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
| 550 | struct flush_icache_range_args args; |
| 551 | |
| 552 | args.start = start; |
| 553 | args.end = end; |
| 554 | |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 555 | r4k_on_each_cpu(local_r4k_flush_icache_range, &args, 1, 1); |
Ralf Baechle | cc61c1f | 2005-07-12 18:35:38 +0000 | [diff] [blame] | 556 | instruction_hazard(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | #ifdef CONFIG_DMA_NONCOHERENT |
| 560 | |
| 561 | static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size) |
| 562 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* Catch bad driver code */ |
| 564 | BUG_ON(size == 0); |
| 565 | |
Ralf Baechle | fc5d2d2 | 2006-07-06 13:04:01 +0100 | [diff] [blame] | 566 | if (cpu_has_inclusive_pcaches) { |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 567 | if (size >= scache_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | r4k_blast_scache(); |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 569 | else |
| 570 | blast_scache_range(addr, addr + size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | return; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Either no secondary cache or the available caches don't have the |
| 576 | * subset property so we have to flush the primary caches |
| 577 | * explicitly |
| 578 | */ |
| 579 | if (size >= dcache_size) { |
| 580 | r4k_blast_dcache(); |
| 581 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | R4600_HIT_CACHEOP_WAR_IMPL; |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 583 | blast_dcache_range(addr, addr + size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | bc_wback_inv(addr, size); |
| 587 | } |
| 588 | |
| 589 | static void r4k_dma_cache_inv(unsigned long addr, unsigned long size) |
| 590 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | /* Catch bad driver code */ |
| 592 | BUG_ON(size == 0); |
| 593 | |
Ralf Baechle | fc5d2d2 | 2006-07-06 13:04:01 +0100 | [diff] [blame] | 594 | if (cpu_has_inclusive_pcaches) { |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 595 | if (size >= scache_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | r4k_blast_scache(); |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 597 | else |
| 598 | blast_scache_range(addr, addr + size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | return; |
| 600 | } |
| 601 | |
| 602 | if (size >= dcache_size) { |
| 603 | r4k_blast_dcache(); |
| 604 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | R4600_HIT_CACHEOP_WAR_IMPL; |
Atsushi Nemoto | 41700e7 | 2006-02-10 00:39:06 +0900 | [diff] [blame] | 606 | blast_dcache_range(addr, addr + size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | bc_inv(addr, size); |
| 610 | } |
| 611 | #endif /* CONFIG_DMA_NONCOHERENT */ |
| 612 | |
| 613 | /* |
| 614 | * While we're protected against bad userland addresses we don't care |
| 615 | * very much about what happens in that case. Usually a segmentation |
| 616 | * fault will dump the process later on anyway ... |
| 617 | */ |
| 618 | static void local_r4k_flush_cache_sigtramp(void * arg) |
| 619 | { |
Thiemo Seufer | 02fe2c9 | 2005-09-09 19:45:41 +0000 | [diff] [blame] | 620 | unsigned long ic_lsize = cpu_icache_line_size(); |
| 621 | unsigned long dc_lsize = cpu_dcache_line_size(); |
| 622 | unsigned long sc_lsize = cpu_scache_line_size(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | unsigned long addr = (unsigned long) arg; |
| 624 | |
| 625 | R4600_HIT_CACHEOP_WAR_IMPL; |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 626 | if (dc_lsize) |
| 627 | protected_writeback_dcache_line(addr & ~(dc_lsize - 1)); |
Ralf Baechle | 4debe4f | 2006-02-27 19:05:55 +0000 | [diff] [blame] | 628 | if (!cpu_icache_snoops_remote_store && scache_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | protected_writeback_scache_line(addr & ~(sc_lsize - 1)); |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 630 | if (ic_lsize) |
| 631 | protected_flush_icache_line(addr & ~(ic_lsize - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | if (MIPS4K_ICACHE_REFILL_WAR) { |
| 633 | __asm__ __volatile__ ( |
| 634 | ".set push\n\t" |
| 635 | ".set noat\n\t" |
| 636 | ".set mips3\n\t" |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 637 | #ifdef CONFIG_32BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | "la $at,1f\n\t" |
| 639 | #endif |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 640 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | "dla $at,1f\n\t" |
| 642 | #endif |
| 643 | "cache %0,($at)\n\t" |
| 644 | "nop; nop; nop\n" |
| 645 | "1:\n\t" |
| 646 | ".set pop" |
| 647 | : |
| 648 | : "i" (Hit_Invalidate_I)); |
| 649 | } |
| 650 | if (MIPS_CACHE_SYNC_WAR) |
| 651 | __asm__ __volatile__ ("sync"); |
| 652 | } |
| 653 | |
| 654 | static void r4k_flush_cache_sigtramp(unsigned long addr) |
| 655 | { |
Ralf Baechle | 7f3f1d0 | 2006-05-12 13:20:06 +0100 | [diff] [blame] | 656 | r4k_on_each_cpu(local_r4k_flush_cache_sigtramp, (void *) addr, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static void r4k_flush_icache_all(void) |
| 660 | { |
| 661 | if (cpu_has_vtag_icache) |
| 662 | r4k_blast_icache(); |
| 663 | } |
| 664 | |
| 665 | static inline void rm7k_erratum31(void) |
| 666 | { |
| 667 | const unsigned long ic_lsize = 32; |
| 668 | unsigned long addr; |
| 669 | |
| 670 | /* RM7000 erratum #31. The icache is screwed at startup. */ |
| 671 | write_c0_taglo(0); |
| 672 | write_c0_taghi(0); |
| 673 | |
| 674 | for (addr = INDEX_BASE; addr <= INDEX_BASE + 4096; addr += ic_lsize) { |
| 675 | __asm__ __volatile__ ( |
Thiemo Seufer | d8748a3 | 2005-09-02 09:56:12 +0000 | [diff] [blame] | 676 | ".set push\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | ".set noreorder\n\t" |
| 678 | ".set mips3\n\t" |
| 679 | "cache\t%1, 0(%0)\n\t" |
| 680 | "cache\t%1, 0x1000(%0)\n\t" |
| 681 | "cache\t%1, 0x2000(%0)\n\t" |
| 682 | "cache\t%1, 0x3000(%0)\n\t" |
| 683 | "cache\t%2, 0(%0)\n\t" |
| 684 | "cache\t%2, 0x1000(%0)\n\t" |
| 685 | "cache\t%2, 0x2000(%0)\n\t" |
| 686 | "cache\t%2, 0x3000(%0)\n\t" |
| 687 | "cache\t%1, 0(%0)\n\t" |
| 688 | "cache\t%1, 0x1000(%0)\n\t" |
| 689 | "cache\t%1, 0x2000(%0)\n\t" |
| 690 | "cache\t%1, 0x3000(%0)\n\t" |
Thiemo Seufer | d8748a3 | 2005-09-02 09:56:12 +0000 | [diff] [blame] | 691 | ".set pop\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | : |
| 693 | : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill)); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | static char *way_string[] __initdata = { NULL, "direct mapped", "2-way", |
| 698 | "3-way", "4-way", "5-way", "6-way", "7-way", "8-way" |
| 699 | }; |
| 700 | |
| 701 | static void __init probe_pcache(void) |
| 702 | { |
| 703 | struct cpuinfo_mips *c = ¤t_cpu_data; |
| 704 | unsigned int config = read_c0_config(); |
| 705 | unsigned int prid = read_c0_prid(); |
| 706 | unsigned long config1; |
| 707 | unsigned int lsize; |
| 708 | |
| 709 | switch (c->cputype) { |
| 710 | case CPU_R4600: /* QED style two way caches? */ |
| 711 | case CPU_R4700: |
| 712 | case CPU_R5000: |
| 713 | case CPU_NEVADA: |
| 714 | icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); |
| 715 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 716 | c->icache.ways = 2; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 717 | c->icache.waybit = __ffs(icache_size/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
| 719 | dcache_size = 1 << (12 + ((config & CONF_DC) >> 6)); |
| 720 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 721 | c->dcache.ways = 2; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 722 | c->dcache.waybit= __ffs(dcache_size/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
| 725 | break; |
| 726 | |
| 727 | case CPU_R5432: |
| 728 | case CPU_R5500: |
| 729 | icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); |
| 730 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 731 | c->icache.ways = 2; |
| 732 | c->icache.waybit= 0; |
| 733 | |
| 734 | dcache_size = 1 << (12 + ((config & CONF_DC) >> 6)); |
| 735 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 736 | c->dcache.ways = 2; |
| 737 | c->dcache.waybit = 0; |
| 738 | |
| 739 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
| 740 | break; |
| 741 | |
| 742 | case CPU_TX49XX: |
| 743 | icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); |
| 744 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 745 | c->icache.ways = 4; |
| 746 | c->icache.waybit= 0; |
| 747 | |
| 748 | dcache_size = 1 << (12 + ((config & CONF_DC) >> 6)); |
| 749 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 750 | c->dcache.ways = 4; |
| 751 | c->dcache.waybit = 0; |
| 752 | |
| 753 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
Atsushi Nemoto | de862b4 | 2006-03-17 12:59:22 +0900 | [diff] [blame] | 754 | c->options |= MIPS_CPU_PREFETCH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case CPU_R4000PC: |
| 758 | case CPU_R4000SC: |
| 759 | case CPU_R4000MC: |
| 760 | case CPU_R4400PC: |
| 761 | case CPU_R4400SC: |
| 762 | case CPU_R4400MC: |
| 763 | case CPU_R4300: |
| 764 | icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); |
| 765 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 766 | c->icache.ways = 1; |
| 767 | c->icache.waybit = 0; /* doesn't matter */ |
| 768 | |
| 769 | dcache_size = 1 << (12 + ((config & CONF_DC) >> 6)); |
| 770 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 771 | c->dcache.ways = 1; |
| 772 | c->dcache.waybit = 0; /* does not matter */ |
| 773 | |
| 774 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
| 775 | break; |
| 776 | |
| 777 | case CPU_R10000: |
| 778 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 779 | case CPU_R14000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29)); |
| 781 | c->icache.linesz = 64; |
| 782 | c->icache.ways = 2; |
| 783 | c->icache.waybit = 0; |
| 784 | |
| 785 | dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26)); |
| 786 | c->dcache.linesz = 32; |
| 787 | c->dcache.ways = 2; |
| 788 | c->dcache.waybit = 0; |
| 789 | |
| 790 | c->options |= MIPS_CPU_PREFETCH; |
| 791 | break; |
| 792 | |
| 793 | case CPU_VR4133: |
Yoichi Yuasa | 2874fe5 | 2006-07-08 00:42:12 +0900 | [diff] [blame] | 794 | write_c0_config(config & ~VR41_CONF_P4K); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | case CPU_VR4131: |
| 796 | /* Workaround for cache instruction bug of VR4131 */ |
| 797 | if (c->processor_id == 0x0c80U || c->processor_id == 0x0c81U || |
| 798 | c->processor_id == 0x0c82U) { |
Yoichi Yuasa | 4e8ab36 | 2006-07-04 22:59:41 +0900 | [diff] [blame] | 799 | config |= 0x00400000U; |
| 800 | if (c->processor_id == 0x0c80U) |
| 801 | config |= VR41_CONF_BP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | write_c0_config(config); |
Yoichi Yuasa | 1058ecd | 2006-07-08 00:42:01 +0900 | [diff] [blame] | 803 | } else |
| 804 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
| 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | icache_size = 1 << (10 + ((config & CONF_IC) >> 9)); |
| 807 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 808 | c->icache.ways = 2; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 809 | c->icache.waybit = __ffs(icache_size/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | dcache_size = 1 << (10 + ((config & CONF_DC) >> 6)); |
| 812 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 813 | c->dcache.ways = 2; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 814 | c->dcache.waybit = __ffs(dcache_size/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | break; |
| 816 | |
| 817 | case CPU_VR41XX: |
| 818 | case CPU_VR4111: |
| 819 | case CPU_VR4121: |
| 820 | case CPU_VR4122: |
| 821 | case CPU_VR4181: |
| 822 | case CPU_VR4181A: |
| 823 | icache_size = 1 << (10 + ((config & CONF_IC) >> 9)); |
| 824 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 825 | c->icache.ways = 1; |
| 826 | c->icache.waybit = 0; /* doesn't matter */ |
| 827 | |
| 828 | dcache_size = 1 << (10 + ((config & CONF_DC) >> 6)); |
| 829 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 830 | c->dcache.ways = 1; |
| 831 | c->dcache.waybit = 0; /* does not matter */ |
| 832 | |
| 833 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
| 834 | break; |
| 835 | |
| 836 | case CPU_RM7000: |
| 837 | rm7k_erratum31(); |
| 838 | |
| 839 | case CPU_RM9000: |
| 840 | icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); |
| 841 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 842 | c->icache.ways = 4; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 843 | c->icache.waybit = __ffs(icache_size / c->icache.ways); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
| 845 | dcache_size = 1 << (12 + ((config & CONF_DC) >> 6)); |
| 846 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 847 | c->dcache.ways = 4; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 848 | c->dcache.waybit = __ffs(dcache_size / c->dcache.ways); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | #if !defined(CONFIG_SMP) || !defined(RM9000_CDEX_SMP_WAR) |
| 851 | c->options |= MIPS_CPU_CACHE_CDEX_P; |
| 852 | #endif |
| 853 | c->options |= MIPS_CPU_PREFETCH; |
| 854 | break; |
| 855 | |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 856 | case CPU_LOONGSON2: |
| 857 | icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); |
| 858 | c->icache.linesz = 16 << ((config & CONF_IB) >> 5); |
| 859 | if (prid & 0x3) |
| 860 | c->icache.ways = 4; |
| 861 | else |
| 862 | c->icache.ways = 2; |
| 863 | c->icache.waybit = 0; |
| 864 | |
| 865 | dcache_size = 1 << (12 + ((config & CONF_DC) >> 6)); |
| 866 | c->dcache.linesz = 16 << ((config & CONF_DB) >> 4); |
| 867 | if (prid & 0x3) |
| 868 | c->dcache.ways = 4; |
| 869 | else |
| 870 | c->dcache.ways = 2; |
| 871 | c->dcache.waybit = 0; |
| 872 | break; |
| 873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | default: |
| 875 | if (!(config & MIPS_CONF_M)) |
| 876 | panic("Don't know how to probe P-caches on this cpu."); |
| 877 | |
| 878 | /* |
| 879 | * So we seem to be a MIPS32 or MIPS64 CPU |
| 880 | * So let's probe the I-cache ... |
| 881 | */ |
| 882 | config1 = read_c0_config1(); |
| 883 | |
| 884 | if ((lsize = ((config1 >> 19) & 7))) |
| 885 | c->icache.linesz = 2 << lsize; |
| 886 | else |
| 887 | c->icache.linesz = lsize; |
| 888 | c->icache.sets = 64 << ((config1 >> 22) & 7); |
| 889 | c->icache.ways = 1 + ((config1 >> 16) & 7); |
| 890 | |
| 891 | icache_size = c->icache.sets * |
| 892 | c->icache.ways * |
| 893 | c->icache.linesz; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 894 | c->icache.waybit = __ffs(icache_size/c->icache.ways); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | if (config & 0x8) /* VI bit */ |
| 897 | c->icache.flags |= MIPS_CACHE_VTAG; |
| 898 | |
| 899 | /* |
| 900 | * Now probe the MIPS32 / MIPS64 data cache. |
| 901 | */ |
| 902 | c->dcache.flags = 0; |
| 903 | |
| 904 | if ((lsize = ((config1 >> 10) & 7))) |
| 905 | c->dcache.linesz = 2 << lsize; |
| 906 | else |
| 907 | c->dcache.linesz= lsize; |
| 908 | c->dcache.sets = 64 << ((config1 >> 13) & 7); |
| 909 | c->dcache.ways = 1 + ((config1 >> 7) & 7); |
| 910 | |
| 911 | dcache_size = c->dcache.sets * |
| 912 | c->dcache.ways * |
| 913 | c->dcache.linesz; |
Atsushi Nemoto | 3c68da7 | 2006-04-08 01:33:31 +0900 | [diff] [blame] | 914 | c->dcache.waybit = __ffs(dcache_size/c->dcache.ways); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | c->options |= MIPS_CPU_PREFETCH; |
| 917 | break; |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * Processor configuration sanity check for the R4000SC erratum |
| 922 | * #5. With page sizes larger than 32kB there is no possibility |
| 923 | * to get a VCE exception anymore so we don't care about this |
| 924 | * misconfiguration. The case is rather theoretical anyway; |
| 925 | * presumably no vendor is shipping his hardware in the "bad" |
| 926 | * configuration. |
| 927 | */ |
| 928 | if ((prid & 0xff00) == PRID_IMP_R4000 && (prid & 0xff) < 0x40 && |
| 929 | !(config & CONF_SC) && c->icache.linesz != 16 && |
| 930 | PAGE_SIZE <= 0x8000) |
| 931 | panic("Improper R4000SC processor configuration detected"); |
| 932 | |
| 933 | /* compute a couple of other cache variables */ |
| 934 | c->icache.waysize = icache_size / c->icache.ways; |
| 935 | c->dcache.waysize = dcache_size / c->dcache.ways; |
| 936 | |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 937 | c->icache.sets = c->icache.linesz ? |
| 938 | icache_size / (c->icache.linesz * c->icache.ways) : 0; |
| 939 | c->dcache.sets = c->dcache.linesz ? |
| 940 | dcache_size / (c->dcache.linesz * c->dcache.ways) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
| 942 | /* |
| 943 | * R10000 and R12000 P-caches are odd in a positive way. They're 32kB |
| 944 | * 2-way virtually indexed so normally would suffer from aliases. So |
| 945 | * normally they'd suffer from aliases but magic in the hardware deals |
| 946 | * with that for us so we don't need to take care ourselves. |
| 947 | */ |
Ralf Baechle | d1e344e | 2005-02-04 15:51:26 +0000 | [diff] [blame] | 948 | switch (c->cputype) { |
Ralf Baechle | a95970f | 2005-02-07 21:41:32 +0000 | [diff] [blame] | 949 | case CPU_20KC: |
Ralf Baechle | 505403b | 2005-02-07 21:53:39 +0000 | [diff] [blame] | 950 | case CPU_25KF: |
Atsushi Nemoto | de62893 | 2006-03-13 18:23:03 +0900 | [diff] [blame] | 951 | c->dcache.flags |= MIPS_CACHE_PINDEX; |
Ralf Baechle | d1e344e | 2005-02-04 15:51:26 +0000 | [diff] [blame] | 952 | case CPU_R10000: |
| 953 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 954 | case CPU_R14000: |
Ralf Baechle | a95970f | 2005-02-07 21:41:32 +0000 | [diff] [blame] | 955 | case CPU_SB1: |
Ralf Baechle | d1e344e | 2005-02-04 15:51:26 +0000 | [diff] [blame] | 956 | break; |
| 957 | case CPU_24K: |
Nigel Stephens | 98a41de | 2006-04-27 15:50:32 +0100 | [diff] [blame] | 958 | case CPU_34K: |
Ralf Baechle | 2e78ae3 | 2006-06-23 18:48:21 +0100 | [diff] [blame] | 959 | case CPU_74K: |
Ralf Baechle | beab375 | 2006-06-19 21:56:25 +0100 | [diff] [blame] | 960 | if ((read_c0_config7() & (1 << 16))) { |
| 961 | /* effectively physically indexed dcache, |
| 962 | thus no virtual aliases. */ |
| 963 | c->dcache.flags |= MIPS_CACHE_PINDEX; |
| 964 | break; |
| 965 | } |
Ralf Baechle | d1e344e | 2005-02-04 15:51:26 +0000 | [diff] [blame] | 966 | default: |
Ralf Baechle | beab375 | 2006-06-19 21:56:25 +0100 | [diff] [blame] | 967 | if (c->dcache.waysize > PAGE_SIZE) |
| 968 | c->dcache.flags |= MIPS_CACHE_ALIASES; |
Ralf Baechle | d1e344e | 2005-02-04 15:51:26 +0000 | [diff] [blame] | 969 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | switch (c->cputype) { |
| 972 | case CPU_20KC: |
| 973 | /* |
| 974 | * Some older 20Kc chips doesn't have the 'VI' bit in |
| 975 | * the config register. |
| 976 | */ |
| 977 | c->icache.flags |= MIPS_CACHE_VTAG; |
| 978 | break; |
| 979 | |
Pete Popov | e3ad1c2 | 2005-03-01 06:33:16 +0000 | [diff] [blame] | 980 | case CPU_AU1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | case CPU_AU1500: |
Pete Popov | e3ad1c2 | 2005-03-01 06:33:16 +0000 | [diff] [blame] | 982 | case CPU_AU1100: |
| 983 | case CPU_AU1550: |
| 984 | case CPU_AU1200: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | c->icache.flags |= MIPS_CACHE_IC_F_DC; |
| 986 | break; |
| 987 | } |
| 988 | |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 989 | #ifdef CONFIG_CPU_LOONGSON2 |
| 990 | /* |
| 991 | * LOONGSON2 has 4 way icache, but when using indexed cache op, |
| 992 | * one op will act on all 4 ways |
| 993 | */ |
| 994 | c->icache.ways = 1; |
| 995 | #endif |
| 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n", |
| 998 | icache_size >> 10, |
| 999 | cpu_has_vtag_icache ? "virtually tagged" : "physically tagged", |
| 1000 | way_string[c->icache.ways], c->icache.linesz); |
| 1001 | |
| 1002 | printk("Primary data cache %ldkB, %s, linesize %d bytes.\n", |
| 1003 | dcache_size >> 10, way_string[c->dcache.ways], c->dcache.linesz); |
| 1004 | } |
| 1005 | |
| 1006 | /* |
| 1007 | * If you even _breathe_ on this function, look at the gcc output and make sure |
| 1008 | * it does not pop things on and off the stack for the cache sizing loop that |
| 1009 | * executes in KSEG1 space or else you will crash and burn badly. You have |
| 1010 | * been warned. |
| 1011 | */ |
| 1012 | static int __init probe_scache(void) |
| 1013 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | unsigned long flags, addr, begin, end, pow2; |
| 1015 | unsigned int config = read_c0_config(); |
| 1016 | struct cpuinfo_mips *c = ¤t_cpu_data; |
| 1017 | int tmp; |
| 1018 | |
| 1019 | if (config & CONF_SC) |
| 1020 | return 0; |
| 1021 | |
Ralf Baechle | e001e52 | 2007-07-28 12:45:47 +0100 | [diff] [blame^] | 1022 | begin = (unsigned long) &_stext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | begin &= ~((4 * 1024 * 1024) - 1); |
| 1024 | end = begin + (4 * 1024 * 1024); |
| 1025 | |
| 1026 | /* |
| 1027 | * This is such a bitch, you'd think they would make it easy to do |
| 1028 | * this. Away you daemons of stupidity! |
| 1029 | */ |
| 1030 | local_irq_save(flags); |
| 1031 | |
| 1032 | /* Fill each size-multiple cache line with a valid tag. */ |
| 1033 | pow2 = (64 * 1024); |
| 1034 | for (addr = begin; addr < end; addr = (begin + pow2)) { |
| 1035 | unsigned long *p = (unsigned long *) addr; |
| 1036 | __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */ |
| 1037 | pow2 <<= 1; |
| 1038 | } |
| 1039 | |
| 1040 | /* Load first line with zero (therefore invalid) tag. */ |
| 1041 | write_c0_taglo(0); |
| 1042 | write_c0_taghi(0); |
| 1043 | __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */ |
| 1044 | cache_op(Index_Store_Tag_I, begin); |
| 1045 | cache_op(Index_Store_Tag_D, begin); |
| 1046 | cache_op(Index_Store_Tag_SD, begin); |
| 1047 | |
| 1048 | /* Now search for the wrap around point. */ |
| 1049 | pow2 = (128 * 1024); |
| 1050 | tmp = 0; |
| 1051 | for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) { |
| 1052 | cache_op(Index_Load_Tag_SD, addr); |
| 1053 | __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */ |
| 1054 | if (!read_c0_taglo()) |
| 1055 | break; |
| 1056 | pow2 <<= 1; |
| 1057 | } |
| 1058 | local_irq_restore(flags); |
| 1059 | addr -= begin; |
| 1060 | |
| 1061 | scache_size = addr; |
| 1062 | c->scache.linesz = 16 << ((config & R4K_CONF_SB) >> 22); |
| 1063 | c->scache.ways = 1; |
| 1064 | c->dcache.waybit = 0; /* does not matter */ |
| 1065 | |
| 1066 | return 1; |
| 1067 | } |
| 1068 | |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 1069 | #if defined(CONFIG_CPU_LOONGSON2) |
| 1070 | static void __init loongson2_sc_init(void) |
| 1071 | { |
| 1072 | struct cpuinfo_mips *c = ¤t_cpu_data; |
| 1073 | |
| 1074 | scache_size = 512*1024; |
| 1075 | c->scache.linesz = 32; |
| 1076 | c->scache.ways = 4; |
| 1077 | c->scache.waybit = 0; |
| 1078 | c->scache.waysize = scache_size / (c->scache.ways); |
| 1079 | c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways); |
| 1080 | pr_info("Unified secondary cache %ldkB %s, linesize %d bytes.\n", |
| 1081 | scache_size >> 10, way_string[c->scache.ways], c->scache.linesz); |
| 1082 | |
| 1083 | c->options |= MIPS_CPU_INCLUSIVE_CACHES; |
| 1084 | } |
| 1085 | #endif |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | extern int r5k_sc_init(void); |
| 1088 | extern int rm7k_sc_init(void); |
Chris Dearman | 9318c51 | 2006-06-20 17:15:20 +0100 | [diff] [blame] | 1089 | extern int mips_sc_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
| 1091 | static void __init setup_scache(void) |
| 1092 | { |
| 1093 | struct cpuinfo_mips *c = ¤t_cpu_data; |
| 1094 | unsigned int config = read_c0_config(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | int sc_present = 0; |
| 1096 | |
| 1097 | /* |
| 1098 | * Do the probing thing on R4000SC and R4400SC processors. Other |
| 1099 | * processors don't have a S-cache that would be relevant to the |
| 1100 | * Linux memory managment. |
| 1101 | */ |
| 1102 | switch (c->cputype) { |
| 1103 | case CPU_R4000SC: |
| 1104 | case CPU_R4000MC: |
| 1105 | case CPU_R4400SC: |
| 1106 | case CPU_R4400MC: |
Thiemo Seufer | ba5187d | 2005-04-25 16:36:23 +0000 | [diff] [blame] | 1107 | sc_present = run_uncached(probe_scache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | if (sc_present) |
| 1109 | c->options |= MIPS_CPU_CACHE_CDEX_S; |
| 1110 | break; |
| 1111 | |
| 1112 | case CPU_R10000: |
| 1113 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 1114 | case CPU_R14000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16); |
| 1116 | c->scache.linesz = 64 << ((config >> 13) & 1); |
| 1117 | c->scache.ways = 2; |
| 1118 | c->scache.waybit= 0; |
| 1119 | sc_present = 1; |
| 1120 | break; |
| 1121 | |
| 1122 | case CPU_R5000: |
| 1123 | case CPU_NEVADA: |
| 1124 | #ifdef CONFIG_R5000_CPU_SCACHE |
| 1125 | r5k_sc_init(); |
| 1126 | #endif |
| 1127 | return; |
| 1128 | |
| 1129 | case CPU_RM7000: |
| 1130 | case CPU_RM9000: |
| 1131 | #ifdef CONFIG_RM7000_CPU_SCACHE |
| 1132 | rm7k_sc_init(); |
| 1133 | #endif |
| 1134 | return; |
| 1135 | |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 1136 | #if defined(CONFIG_CPU_LOONGSON2) |
| 1137 | case CPU_LOONGSON2: |
| 1138 | loongson2_sc_init(); |
| 1139 | return; |
| 1140 | #endif |
| 1141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | default: |
Chris Dearman | 9318c51 | 2006-06-20 17:15:20 +0100 | [diff] [blame] | 1143 | if (c->isa_level == MIPS_CPU_ISA_M32R1 || |
| 1144 | c->isa_level == MIPS_CPU_ISA_M32R2 || |
| 1145 | c->isa_level == MIPS_CPU_ISA_M64R1 || |
| 1146 | c->isa_level == MIPS_CPU_ISA_M64R2) { |
| 1147 | #ifdef CONFIG_MIPS_CPU_SCACHE |
| 1148 | if (mips_sc_init ()) { |
| 1149 | scache_size = c->scache.ways * c->scache.sets * c->scache.linesz; |
| 1150 | printk("MIPS secondary cache %ldkB, %s, linesize %d bytes.\n", |
| 1151 | scache_size >> 10, |
| 1152 | way_string[c->scache.ways], c->scache.linesz); |
| 1153 | } |
| 1154 | #else |
| 1155 | if (!(c->scache.flags & MIPS_CACHE_NOT_PRESENT)) |
| 1156 | panic("Dunno how to handle MIPS32 / MIPS64 second level cache"); |
| 1157 | #endif |
| 1158 | return; |
| 1159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | sc_present = 0; |
| 1161 | } |
| 1162 | |
| 1163 | if (!sc_present) |
| 1164 | return; |
| 1165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | /* compute a couple of other cache variables */ |
| 1167 | c->scache.waysize = scache_size / c->scache.ways; |
| 1168 | |
| 1169 | c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways); |
| 1170 | |
| 1171 | printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n", |
| 1172 | scache_size >> 10, way_string[c->scache.ways], c->scache.linesz); |
| 1173 | |
Ralf Baechle | fc5d2d2 | 2006-07-06 13:04:01 +0100 | [diff] [blame] | 1174 | c->options |= MIPS_CPU_INCLUSIVE_CACHES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Sergei Shtylyov | 9370b35 | 2006-05-26 19:44:54 +0400 | [diff] [blame] | 1177 | void au1x00_fixup_config_od(void) |
| 1178 | { |
| 1179 | /* |
| 1180 | * c0_config.od (bit 19) was write only (and read as 0) |
| 1181 | * on the early revisions of Alchemy SOCs. It disables the bus |
| 1182 | * transaction overlapping and needs to be set to fix various errata. |
| 1183 | */ |
| 1184 | switch (read_c0_prid()) { |
| 1185 | case 0x00030100: /* Au1000 DA */ |
| 1186 | case 0x00030201: /* Au1000 HA */ |
| 1187 | case 0x00030202: /* Au1000 HB */ |
| 1188 | case 0x01030200: /* Au1500 AB */ |
| 1189 | /* |
| 1190 | * Au1100 errata actually keeps silence about this bit, so we set it |
| 1191 | * just in case for those revisions that require it to be set according |
| 1192 | * to arch/mips/au1000/common/cputable.c |
| 1193 | */ |
| 1194 | case 0x02030200: /* Au1100 AB */ |
| 1195 | case 0x02030201: /* Au1100 BA */ |
| 1196 | case 0x02030202: /* Au1100 BC */ |
| 1197 | set_c0_config(1 << 19); |
| 1198 | break; |
| 1199 | } |
| 1200 | } |
| 1201 | |
Ralf Baechle | a00f631 | 2006-08-01 23:39:42 +0100 | [diff] [blame] | 1202 | static void __init coherency_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
| 1204 | change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT); |
| 1205 | |
| 1206 | /* |
| 1207 | * c0_status.cu=0 specifies that updates by the sc instruction use |
| 1208 | * the coherency mode specified by the TLB; 1 means cachable |
| 1209 | * coherent update on write will be used. Not all processors have |
| 1210 | * this bit and; some wire it to zero, others like Toshiba had the |
| 1211 | * silly idea of putting something else there ... |
| 1212 | */ |
| 1213 | switch (current_cpu_data.cputype) { |
| 1214 | case CPU_R4000PC: |
| 1215 | case CPU_R4000SC: |
| 1216 | case CPU_R4000MC: |
| 1217 | case CPU_R4400PC: |
| 1218 | case CPU_R4400SC: |
| 1219 | case CPU_R4400MC: |
| 1220 | clear_c0_config(CONF_CU); |
| 1221 | break; |
Sergei Shtylyov | 9370b35 | 2006-05-26 19:44:54 +0400 | [diff] [blame] | 1222 | /* |
Ralf Baechle | df586d5 | 2006-08-01 23:42:30 +0100 | [diff] [blame] | 1223 | * We need to catch the early Alchemy SOCs with |
Sergei Shtylyov | 9370b35 | 2006-05-26 19:44:54 +0400 | [diff] [blame] | 1224 | * the write-only co_config.od bit and set it back to one... |
| 1225 | */ |
| 1226 | case CPU_AU1000: /* rev. DA, HA, HB */ |
| 1227 | case CPU_AU1100: /* rev. AB, BA, BC ?? */ |
| 1228 | case CPU_AU1500: /* rev. AB */ |
| 1229 | au1x00_fixup_config_od(); |
| 1230 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | |
Ralf Baechle | 02cf211 | 2005-10-01 13:06:32 +0100 | [diff] [blame] | 1234 | void __init r4k_cache_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
| 1236 | extern void build_clear_page(void); |
| 1237 | extern void build_copy_page(void); |
| 1238 | extern char except_vec2_generic; |
| 1239 | struct cpuinfo_mips *c = ¤t_cpu_data; |
| 1240 | |
| 1241 | /* Default cache error handler for R4000 and R5000 family */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1242 | set_uncached_handler (0x100, &except_vec2_generic, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
| 1244 | probe_pcache(); |
| 1245 | setup_scache(); |
| 1246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | r4k_blast_dcache_page_setup(); |
| 1248 | r4k_blast_dcache_page_indexed_setup(); |
| 1249 | r4k_blast_dcache_setup(); |
| 1250 | r4k_blast_icache_page_setup(); |
| 1251 | r4k_blast_icache_page_indexed_setup(); |
| 1252 | r4k_blast_icache_setup(); |
| 1253 | r4k_blast_scache_page_setup(); |
| 1254 | r4k_blast_scache_page_indexed_setup(); |
| 1255 | r4k_blast_scache_setup(); |
| 1256 | |
| 1257 | /* |
| 1258 | * Some MIPS32 and MIPS64 processors have physically indexed caches. |
| 1259 | * This code supports virtually indexed processors and will be |
| 1260 | * unnecessarily inefficient on physically indexed processors. |
| 1261 | */ |
Chris Dearman | 73f4035 | 2006-06-20 18:06:52 +0100 | [diff] [blame] | 1262 | if (c->dcache.linesz) |
| 1263 | shm_align_mask = max_t( unsigned long, |
| 1264 | c->dcache.sets * c->dcache.linesz - 1, |
| 1265 | PAGE_SIZE - 1); |
| 1266 | else |
| 1267 | shm_align_mask = PAGE_SIZE-1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | flush_cache_all = r4k_flush_cache_all; |
| 1269 | __flush_cache_all = r4k___flush_cache_all; |
| 1270 | flush_cache_mm = r4k_flush_cache_mm; |
| 1271 | flush_cache_page = r4k_flush_cache_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | flush_cache_range = r4k_flush_cache_range; |
| 1273 | |
| 1274 | flush_cache_sigtramp = r4k_flush_cache_sigtramp; |
| 1275 | flush_icache_all = r4k_flush_icache_all; |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 1276 | local_flush_data_cache_page = local_r4k_flush_data_cache_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | flush_data_cache_page = r4k_flush_data_cache_page; |
| 1278 | flush_icache_range = r4k_flush_icache_range; |
| 1279 | |
| 1280 | #ifdef CONFIG_DMA_NONCOHERENT |
| 1281 | _dma_cache_wback_inv = r4k_dma_cache_wback_inv; |
| 1282 | _dma_cache_wback = r4k_dma_cache_wback_inv; |
| 1283 | _dma_cache_inv = r4k_dma_cache_inv; |
| 1284 | #endif |
| 1285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | build_clear_page(); |
| 1287 | build_copy_page(); |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1288 | local_r4k___flush_cache_all(NULL); |
| 1289 | coherency_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | } |