c-r4k.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  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. */
  10. #include <linux/config.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/bitops.h>
  16. #include <asm/bcache.h>
  17. #include <asm/bootinfo.h>
  18. #include <asm/cache.h>
  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>
  26. #include <asm/system.h>
  27. #include <asm/mmu_context.h>
  28. #include <asm/war.h>
  29. #include <asm/cacheflush.h> /* for run_uncached() */
  30. /*
  31. * Must die.
  32. */
  33. static unsigned long icache_size __read_mostly;
  34. static unsigned long dcache_size __read_mostly;
  35. static unsigned long scache_size __read_mostly;
  36. /*
  37. * Dummy cache handling routines for machines without boardcaches
  38. */
  39. static void no_sc_noop(void) {}
  40. static struct bcache_ops no_sc_ops = {
  41. .bc_enable = (void *)no_sc_noop,
  42. .bc_disable = (void *)no_sc_noop,
  43. .bc_wback_inv = (void *)no_sc_noop,
  44. .bc_inv = (void *)no_sc_noop
  45. };
  46. struct bcache_ops *bcops = &no_sc_ops;
  47. #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
  48. #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
  49. #define R4600_HIT_CACHEOP_WAR_IMPL \
  50. do { \
  51. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x()) \
  52. *(volatile unsigned long *)CKSEG1; \
  53. if (R4600_V1_HIT_CACHEOP_WAR) \
  54. __asm__ __volatile__("nop;nop;nop;nop"); \
  55. } while (0)
  56. static void (*r4k_blast_dcache_page)(unsigned long addr);
  57. static inline void r4k_blast_dcache_page_dc32(unsigned long addr)
  58. {
  59. R4600_HIT_CACHEOP_WAR_IMPL;
  60. blast_dcache32_page(addr);
  61. }
  62. static inline void r4k_blast_dcache_page_setup(void)
  63. {
  64. unsigned long dc_lsize = cpu_dcache_line_size();
  65. if (dc_lsize == 16)
  66. r4k_blast_dcache_page = blast_dcache16_page;
  67. else if (dc_lsize == 32)
  68. r4k_blast_dcache_page = r4k_blast_dcache_page_dc32;
  69. }
  70. static void (* r4k_blast_dcache_page_indexed)(unsigned long addr);
  71. static inline void r4k_blast_dcache_page_indexed_setup(void)
  72. {
  73. unsigned long dc_lsize = cpu_dcache_line_size();
  74. if (dc_lsize == 16)
  75. r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed;
  76. else if (dc_lsize == 32)
  77. r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed;
  78. }
  79. static void (* r4k_blast_dcache)(void);
  80. static inline void r4k_blast_dcache_setup(void)
  81. {
  82. unsigned long dc_lsize = cpu_dcache_line_size();
  83. if (dc_lsize == 16)
  84. r4k_blast_dcache = blast_dcache16;
  85. else if (dc_lsize == 32)
  86. r4k_blast_dcache = blast_dcache32;
  87. }
  88. /* force code alignment (used for TX49XX_ICACHE_INDEX_INV_WAR) */
  89. #define JUMP_TO_ALIGN(order) \
  90. __asm__ __volatile__( \
  91. "b\t1f\n\t" \
  92. ".align\t" #order "\n\t" \
  93. "1:\n\t" \
  94. )
  95. #define CACHE32_UNROLL32_ALIGN JUMP_TO_ALIGN(10) /* 32 * 32 = 1024 */
  96. #define CACHE32_UNROLL32_ALIGN2 JUMP_TO_ALIGN(11)
  97. static inline void blast_r4600_v1_icache32(void)
  98. {
  99. unsigned long flags;
  100. local_irq_save(flags);
  101. blast_icache32();
  102. local_irq_restore(flags);
  103. }
  104. static inline void tx49_blast_icache32(void)
  105. {
  106. unsigned long start = INDEX_BASE;
  107. unsigned long end = start + current_cpu_data.icache.waysize;
  108. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  109. unsigned long ws_end = current_cpu_data.icache.ways <<
  110. current_cpu_data.icache.waybit;
  111. unsigned long ws, addr;
  112. CACHE32_UNROLL32_ALIGN2;
  113. /* I'm in even chunk. blast odd chunks */
  114. for (ws = 0; ws < ws_end; ws += ws_inc)
  115. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  116. cache32_unroll32(addr|ws,Index_Invalidate_I);
  117. CACHE32_UNROLL32_ALIGN;
  118. /* I'm in odd chunk. blast even chunks */
  119. for (ws = 0; ws < ws_end; ws += ws_inc)
  120. for (addr = start; addr < end; addr += 0x400 * 2)
  121. cache32_unroll32(addr|ws,Index_Invalidate_I);
  122. }
  123. static inline void blast_icache32_r4600_v1_page_indexed(unsigned long page)
  124. {
  125. unsigned long flags;
  126. local_irq_save(flags);
  127. blast_icache32_page_indexed(page);
  128. local_irq_restore(flags);
  129. }
  130. static inline void tx49_blast_icache32_page_indexed(unsigned long page)
  131. {
  132. unsigned long start = page;
  133. unsigned long end = start + PAGE_SIZE;
  134. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  135. unsigned long ws_end = current_cpu_data.icache.ways <<
  136. current_cpu_data.icache.waybit;
  137. unsigned long ws, addr;
  138. CACHE32_UNROLL32_ALIGN2;
  139. /* I'm in even chunk. blast odd chunks */
  140. for (ws = 0; ws < ws_end; ws += ws_inc)
  141. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  142. cache32_unroll32(addr|ws,Index_Invalidate_I);
  143. CACHE32_UNROLL32_ALIGN;
  144. /* I'm in odd chunk. blast even chunks */
  145. for (ws = 0; ws < ws_end; ws += ws_inc)
  146. for (addr = start; addr < end; addr += 0x400 * 2)
  147. cache32_unroll32(addr|ws,Index_Invalidate_I);
  148. }
  149. static void (* r4k_blast_icache_page)(unsigned long addr);
  150. static inline void r4k_blast_icache_page_setup(void)
  151. {
  152. unsigned long ic_lsize = cpu_icache_line_size();
  153. if (ic_lsize == 16)
  154. r4k_blast_icache_page = blast_icache16_page;
  155. else if (ic_lsize == 32)
  156. r4k_blast_icache_page = blast_icache32_page;
  157. else if (ic_lsize == 64)
  158. r4k_blast_icache_page = blast_icache64_page;
  159. }
  160. static void (* r4k_blast_icache_page_indexed)(unsigned long addr);
  161. static inline void r4k_blast_icache_page_indexed_setup(void)
  162. {
  163. unsigned long ic_lsize = cpu_icache_line_size();
  164. if (ic_lsize == 16)
  165. r4k_blast_icache_page_indexed = blast_icache16_page_indexed;
  166. else if (ic_lsize == 32) {
  167. if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x())
  168. r4k_blast_icache_page_indexed =
  169. blast_icache32_r4600_v1_page_indexed;
  170. else if (TX49XX_ICACHE_INDEX_INV_WAR)
  171. r4k_blast_icache_page_indexed =
  172. tx49_blast_icache32_page_indexed;
  173. else
  174. r4k_blast_icache_page_indexed =
  175. blast_icache32_page_indexed;
  176. } else if (ic_lsize == 64)
  177. r4k_blast_icache_page_indexed = blast_icache64_page_indexed;
  178. }
  179. static void (* r4k_blast_icache)(void);
  180. static inline void r4k_blast_icache_setup(void)
  181. {
  182. unsigned long ic_lsize = cpu_icache_line_size();
  183. if (ic_lsize == 16)
  184. r4k_blast_icache = blast_icache16;
  185. else if (ic_lsize == 32) {
  186. if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x())
  187. r4k_blast_icache = blast_r4600_v1_icache32;
  188. else if (TX49XX_ICACHE_INDEX_INV_WAR)
  189. r4k_blast_icache = tx49_blast_icache32;
  190. else
  191. r4k_blast_icache = blast_icache32;
  192. } else if (ic_lsize == 64)
  193. r4k_blast_icache = blast_icache64;
  194. }
  195. static void (* r4k_blast_scache_page)(unsigned long addr);
  196. static inline void r4k_blast_scache_page_setup(void)
  197. {
  198. unsigned long sc_lsize = cpu_scache_line_size();
  199. if (sc_lsize == 16)
  200. r4k_blast_scache_page = blast_scache16_page;
  201. else if (sc_lsize == 32)
  202. r4k_blast_scache_page = blast_scache32_page;
  203. else if (sc_lsize == 64)
  204. r4k_blast_scache_page = blast_scache64_page;
  205. else if (sc_lsize == 128)
  206. r4k_blast_scache_page = blast_scache128_page;
  207. }
  208. static void (* r4k_blast_scache_page_indexed)(unsigned long addr);
  209. static inline void r4k_blast_scache_page_indexed_setup(void)
  210. {
  211. unsigned long sc_lsize = cpu_scache_line_size();
  212. if (sc_lsize == 16)
  213. r4k_blast_scache_page_indexed = blast_scache16_page_indexed;
  214. else if (sc_lsize == 32)
  215. r4k_blast_scache_page_indexed = blast_scache32_page_indexed;
  216. else if (sc_lsize == 64)
  217. r4k_blast_scache_page_indexed = blast_scache64_page_indexed;
  218. else if (sc_lsize == 128)
  219. r4k_blast_scache_page_indexed = blast_scache128_page_indexed;
  220. }
  221. static void (* r4k_blast_scache)(void);
  222. static inline void r4k_blast_scache_setup(void)
  223. {
  224. unsigned long sc_lsize = cpu_scache_line_size();
  225. if (sc_lsize == 16)
  226. r4k_blast_scache = blast_scache16;
  227. else if (sc_lsize == 32)
  228. r4k_blast_scache = blast_scache32;
  229. else if (sc_lsize == 64)
  230. r4k_blast_scache = blast_scache64;
  231. else if (sc_lsize == 128)
  232. r4k_blast_scache = blast_scache128;
  233. }
  234. /*
  235. * This is former mm's flush_cache_all() which really should be
  236. * flush_cache_vunmap these days ...
  237. */
  238. static inline void local_r4k_flush_cache_all(void * args)
  239. {
  240. r4k_blast_dcache();
  241. r4k_blast_icache();
  242. }
  243. static void r4k_flush_cache_all(void)
  244. {
  245. if (!cpu_has_dc_aliases)
  246. return;
  247. on_each_cpu(local_r4k_flush_cache_all, NULL, 1, 1);
  248. }
  249. static inline void local_r4k___flush_cache_all(void * args)
  250. {
  251. r4k_blast_dcache();
  252. r4k_blast_icache();
  253. switch (current_cpu_data.cputype) {
  254. case CPU_R4000SC:
  255. case CPU_R4000MC:
  256. case CPU_R4400SC:
  257. case CPU_R4400MC:
  258. case CPU_R10000:
  259. case CPU_R12000:
  260. r4k_blast_scache();
  261. }
  262. }
  263. static void r4k___flush_cache_all(void)
  264. {
  265. on_each_cpu(local_r4k___flush_cache_all, NULL, 1, 1);
  266. }
  267. static inline void local_r4k_flush_cache_range(void * args)
  268. {
  269. struct vm_area_struct *vma = args;
  270. int exec;
  271. if (!(cpu_context(smp_processor_id(), vma->vm_mm)))
  272. return;
  273. exec = vma->vm_flags & VM_EXEC;
  274. if (cpu_has_dc_aliases || exec)
  275. r4k_blast_dcache();
  276. if (exec)
  277. r4k_blast_icache();
  278. }
  279. static void r4k_flush_cache_range(struct vm_area_struct *vma,
  280. unsigned long start, unsigned long end)
  281. {
  282. on_each_cpu(local_r4k_flush_cache_range, vma, 1, 1);
  283. }
  284. static inline void local_r4k_flush_cache_mm(void * args)
  285. {
  286. struct mm_struct *mm = args;
  287. if (!cpu_context(smp_processor_id(), mm))
  288. return;
  289. r4k_blast_dcache();
  290. r4k_blast_icache();
  291. /*
  292. * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we
  293. * only flush the primary caches but R10000 and R12000 behave sane ...
  294. */
  295. if (current_cpu_data.cputype == CPU_R4000SC ||
  296. current_cpu_data.cputype == CPU_R4000MC ||
  297. current_cpu_data.cputype == CPU_R4400SC ||
  298. current_cpu_data.cputype == CPU_R4400MC)
  299. r4k_blast_scache();
  300. }
  301. static void r4k_flush_cache_mm(struct mm_struct *mm)
  302. {
  303. if (!cpu_has_dc_aliases)
  304. return;
  305. on_each_cpu(local_r4k_flush_cache_mm, mm, 1, 1);
  306. }
  307. struct flush_cache_page_args {
  308. struct vm_area_struct *vma;
  309. unsigned long addr;
  310. };
  311. static inline void local_r4k_flush_cache_page(void *args)
  312. {
  313. struct flush_cache_page_args *fcp_args = args;
  314. struct vm_area_struct *vma = fcp_args->vma;
  315. unsigned long addr = fcp_args->addr;
  316. int exec = vma->vm_flags & VM_EXEC;
  317. struct mm_struct *mm = vma->vm_mm;
  318. pgd_t *pgdp;
  319. pud_t *pudp;
  320. pmd_t *pmdp;
  321. pte_t *ptep;
  322. /*
  323. * If ownes no valid ASID yet, cannot possibly have gotten
  324. * this page into the cache.
  325. */
  326. if (cpu_context(smp_processor_id(), mm) == 0)
  327. return;
  328. addr &= PAGE_MASK;
  329. pgdp = pgd_offset(mm, addr);
  330. pudp = pud_offset(pgdp, addr);
  331. pmdp = pmd_offset(pudp, addr);
  332. ptep = pte_offset(pmdp, addr);
  333. /*
  334. * If the page isn't marked valid, the page cannot possibly be
  335. * in the cache.
  336. */
  337. if (!(pte_val(*ptep) & _PAGE_PRESENT))
  338. return;
  339. /*
  340. * Doing flushes for another ASID than the current one is
  341. * too difficult since stupid R4k caches do a TLB translation
  342. * for every cache flush operation. So we do indexed flushes
  343. * in that case, which doesn't overly flush the cache too much.
  344. */
  345. if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) {
  346. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  347. r4k_blast_dcache_page(addr);
  348. if (exec && !cpu_icache_snoops_remote_store)
  349. r4k_blast_scache_page(addr);
  350. }
  351. if (exec)
  352. r4k_blast_icache_page(addr);
  353. return;
  354. }
  355. /*
  356. * Do indexed flush, too much work to get the (possible) TLB refills
  357. * to work correctly.
  358. */
  359. addr = INDEX_BASE + (addr & (dcache_size - 1));
  360. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  361. r4k_blast_dcache_page_indexed(addr);
  362. if (exec && !cpu_icache_snoops_remote_store)
  363. r4k_blast_scache_page_indexed(addr);
  364. }
  365. if (exec) {
  366. if (cpu_has_vtag_icache) {
  367. int cpu = smp_processor_id();
  368. if (cpu_context(cpu, mm) != 0)
  369. drop_mmu_context(mm, cpu);
  370. } else
  371. r4k_blast_icache_page_indexed(addr);
  372. }
  373. }
  374. static void r4k_flush_cache_page(struct vm_area_struct *vma,
  375. unsigned long addr, unsigned long pfn)
  376. {
  377. struct flush_cache_page_args args;
  378. args.vma = vma;
  379. args.addr = addr;
  380. on_each_cpu(local_r4k_flush_cache_page, &args, 1, 1);
  381. }
  382. static inline void local_r4k_flush_data_cache_page(void * addr)
  383. {
  384. r4k_blast_dcache_page((unsigned long) addr);
  385. }
  386. static void r4k_flush_data_cache_page(unsigned long addr)
  387. {
  388. on_each_cpu(local_r4k_flush_data_cache_page, (void *) addr, 1, 1);
  389. }
  390. struct flush_icache_range_args {
  391. unsigned long __user start;
  392. unsigned long __user end;
  393. };
  394. static inline void local_r4k_flush_icache_range(void *args)
  395. {
  396. struct flush_icache_range_args *fir_args = args;
  397. unsigned long dc_lsize = cpu_dcache_line_size();
  398. unsigned long ic_lsize = cpu_icache_line_size();
  399. unsigned long sc_lsize = cpu_scache_line_size();
  400. unsigned long start = fir_args->start;
  401. unsigned long end = fir_args->end;
  402. unsigned long addr, aend;
  403. if (!cpu_has_ic_fills_f_dc) {
  404. if (end - start > dcache_size) {
  405. r4k_blast_dcache();
  406. } else {
  407. R4600_HIT_CACHEOP_WAR_IMPL;
  408. addr = start & ~(dc_lsize - 1);
  409. aend = (end - 1) & ~(dc_lsize - 1);
  410. while (1) {
  411. /* Hit_Writeback_Inv_D */
  412. protected_writeback_dcache_line(addr);
  413. if (addr == aend)
  414. break;
  415. addr += dc_lsize;
  416. }
  417. }
  418. if (!cpu_icache_snoops_remote_store) {
  419. if (end - start > scache_size) {
  420. r4k_blast_scache();
  421. } else {
  422. addr = start & ~(sc_lsize - 1);
  423. aend = (end - 1) & ~(sc_lsize - 1);
  424. while (1) {
  425. /* Hit_Writeback_Inv_SD */
  426. protected_writeback_scache_line(addr);
  427. if (addr == aend)
  428. break;
  429. addr += sc_lsize;
  430. }
  431. }
  432. }
  433. }
  434. if (end - start > icache_size)
  435. r4k_blast_icache();
  436. else {
  437. addr = start & ~(ic_lsize - 1);
  438. aend = (end - 1) & ~(ic_lsize - 1);
  439. while (1) {
  440. /* Hit_Invalidate_I */
  441. protected_flush_icache_line(addr);
  442. if (addr == aend)
  443. break;
  444. addr += ic_lsize;
  445. }
  446. }
  447. }
  448. static void r4k_flush_icache_range(unsigned long __user start,
  449. unsigned long __user end)
  450. {
  451. struct flush_icache_range_args args;
  452. args.start = start;
  453. args.end = end;
  454. on_each_cpu(local_r4k_flush_icache_range, &args, 1, 1);
  455. instruction_hazard();
  456. }
  457. /*
  458. * Ok, this seriously sucks. We use them to flush a user page but don't
  459. * know the virtual address, so we have to blast away the whole icache
  460. * which is significantly more expensive than the real thing. Otoh we at
  461. * least know the kernel address of the page so we can flush it
  462. * selectivly.
  463. */
  464. struct flush_icache_page_args {
  465. struct vm_area_struct *vma;
  466. struct page *page;
  467. };
  468. static inline void local_r4k_flush_icache_page(void *args)
  469. {
  470. struct flush_icache_page_args *fip_args = args;
  471. struct vm_area_struct *vma = fip_args->vma;
  472. struct page *page = fip_args->page;
  473. /*
  474. * Tricky ... Because we don't know the virtual address we've got the
  475. * choice of either invalidating the entire primary and secondary
  476. * caches or invalidating the secondary caches also. With the subset
  477. * enforcment on R4000SC, R4400SC, R10000 and R12000 invalidating the
  478. * secondary cache will result in any entries in the primary caches
  479. * also getting invalidated which hopefully is a bit more economical.
  480. */
  481. if (cpu_has_subset_pcaches) {
  482. unsigned long addr = (unsigned long) page_address(page);
  483. r4k_blast_scache_page(addr);
  484. ClearPageDcacheDirty(page);
  485. return;
  486. }
  487. if (!cpu_has_ic_fills_f_dc) {
  488. unsigned long addr = (unsigned long) page_address(page);
  489. r4k_blast_dcache_page(addr);
  490. if (!cpu_icache_snoops_remote_store)
  491. r4k_blast_scache_page(addr);
  492. ClearPageDcacheDirty(page);
  493. }
  494. /*
  495. * We're not sure of the virtual address(es) involved here, so
  496. * we have to flush the entire I-cache.
  497. */
  498. if (cpu_has_vtag_icache) {
  499. int cpu = smp_processor_id();
  500. if (cpu_context(cpu, vma->vm_mm) != 0)
  501. drop_mmu_context(vma->vm_mm, cpu);
  502. } else
  503. r4k_blast_icache();
  504. }
  505. static void r4k_flush_icache_page(struct vm_area_struct *vma,
  506. struct page *page)
  507. {
  508. struct flush_icache_page_args args;
  509. /*
  510. * If there's no context yet, or the page isn't executable, no I-cache
  511. * flush is needed.
  512. */
  513. if (!(vma->vm_flags & VM_EXEC))
  514. return;
  515. args.vma = vma;
  516. args.page = page;
  517. on_each_cpu(local_r4k_flush_icache_page, &args, 1, 1);
  518. }
  519. #ifdef CONFIG_DMA_NONCOHERENT
  520. static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
  521. {
  522. unsigned long end, a;
  523. /* Catch bad driver code */
  524. BUG_ON(size == 0);
  525. if (cpu_has_subset_pcaches) {
  526. unsigned long sc_lsize = cpu_scache_line_size();
  527. if (size >= scache_size) {
  528. r4k_blast_scache();
  529. return;
  530. }
  531. a = addr & ~(sc_lsize - 1);
  532. end = (addr + size - 1) & ~(sc_lsize - 1);
  533. while (1) {
  534. flush_scache_line(a); /* Hit_Writeback_Inv_SD */
  535. if (a == end)
  536. break;
  537. a += sc_lsize;
  538. }
  539. return;
  540. }
  541. /*
  542. * Either no secondary cache or the available caches don't have the
  543. * subset property so we have to flush the primary caches
  544. * explicitly
  545. */
  546. if (size >= dcache_size) {
  547. r4k_blast_dcache();
  548. } else {
  549. unsigned long dc_lsize = cpu_dcache_line_size();
  550. R4600_HIT_CACHEOP_WAR_IMPL;
  551. a = addr & ~(dc_lsize - 1);
  552. end = (addr + size - 1) & ~(dc_lsize - 1);
  553. while (1) {
  554. flush_dcache_line(a); /* Hit_Writeback_Inv_D */
  555. if (a == end)
  556. break;
  557. a += dc_lsize;
  558. }
  559. }
  560. bc_wback_inv(addr, size);
  561. }
  562. static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
  563. {
  564. unsigned long end, a;
  565. /* Catch bad driver code */
  566. BUG_ON(size == 0);
  567. if (cpu_has_subset_pcaches) {
  568. unsigned long sc_lsize = cpu_scache_line_size();
  569. if (size >= scache_size) {
  570. r4k_blast_scache();
  571. return;
  572. }
  573. a = addr & ~(sc_lsize - 1);
  574. end = (addr + size - 1) & ~(sc_lsize - 1);
  575. while (1) {
  576. flush_scache_line(a); /* Hit_Writeback_Inv_SD */
  577. if (a == end)
  578. break;
  579. a += sc_lsize;
  580. }
  581. return;
  582. }
  583. if (size >= dcache_size) {
  584. r4k_blast_dcache();
  585. } else {
  586. unsigned long dc_lsize = cpu_dcache_line_size();
  587. R4600_HIT_CACHEOP_WAR_IMPL;
  588. a = addr & ~(dc_lsize - 1);
  589. end = (addr + size - 1) & ~(dc_lsize - 1);
  590. while (1) {
  591. flush_dcache_line(a); /* Hit_Writeback_Inv_D */
  592. if (a == end)
  593. break;
  594. a += dc_lsize;
  595. }
  596. }
  597. bc_inv(addr, size);
  598. }
  599. #endif /* CONFIG_DMA_NONCOHERENT */
  600. /*
  601. * While we're protected against bad userland addresses we don't care
  602. * very much about what happens in that case. Usually a segmentation
  603. * fault will dump the process later on anyway ...
  604. */
  605. static void local_r4k_flush_cache_sigtramp(void * arg)
  606. {
  607. unsigned long ic_lsize = cpu_icache_line_size();
  608. unsigned long dc_lsize = cpu_dcache_line_size();
  609. unsigned long sc_lsize = cpu_scache_line_size();
  610. unsigned long addr = (unsigned long) arg;
  611. R4600_HIT_CACHEOP_WAR_IMPL;
  612. protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
  613. if (!cpu_icache_snoops_remote_store)
  614. protected_writeback_scache_line(addr & ~(sc_lsize - 1));
  615. protected_flush_icache_line(addr & ~(ic_lsize - 1));
  616. if (MIPS4K_ICACHE_REFILL_WAR) {
  617. __asm__ __volatile__ (
  618. ".set push\n\t"
  619. ".set noat\n\t"
  620. ".set mips3\n\t"
  621. #ifdef CONFIG_32BIT
  622. "la $at,1f\n\t"
  623. #endif
  624. #ifdef CONFIG_64BIT
  625. "dla $at,1f\n\t"
  626. #endif
  627. "cache %0,($at)\n\t"
  628. "nop; nop; nop\n"
  629. "1:\n\t"
  630. ".set pop"
  631. :
  632. : "i" (Hit_Invalidate_I));
  633. }
  634. if (MIPS_CACHE_SYNC_WAR)
  635. __asm__ __volatile__ ("sync");
  636. }
  637. static void r4k_flush_cache_sigtramp(unsigned long addr)
  638. {
  639. on_each_cpu(local_r4k_flush_cache_sigtramp, (void *) addr, 1, 1);
  640. }
  641. static void r4k_flush_icache_all(void)
  642. {
  643. if (cpu_has_vtag_icache)
  644. r4k_blast_icache();
  645. }
  646. static inline void rm7k_erratum31(void)
  647. {
  648. const unsigned long ic_lsize = 32;
  649. unsigned long addr;
  650. /* RM7000 erratum #31. The icache is screwed at startup. */
  651. write_c0_taglo(0);
  652. write_c0_taghi(0);
  653. for (addr = INDEX_BASE; addr <= INDEX_BASE + 4096; addr += ic_lsize) {
  654. __asm__ __volatile__ (
  655. ".set push\n\t"
  656. ".set noreorder\n\t"
  657. ".set mips3\n\t"
  658. "cache\t%1, 0(%0)\n\t"
  659. "cache\t%1, 0x1000(%0)\n\t"
  660. "cache\t%1, 0x2000(%0)\n\t"
  661. "cache\t%1, 0x3000(%0)\n\t"
  662. "cache\t%2, 0(%0)\n\t"
  663. "cache\t%2, 0x1000(%0)\n\t"
  664. "cache\t%2, 0x2000(%0)\n\t"
  665. "cache\t%2, 0x3000(%0)\n\t"
  666. "cache\t%1, 0(%0)\n\t"
  667. "cache\t%1, 0x1000(%0)\n\t"
  668. "cache\t%1, 0x2000(%0)\n\t"
  669. "cache\t%1, 0x3000(%0)\n\t"
  670. ".set pop\n"
  671. :
  672. : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill));
  673. }
  674. }
  675. static char *way_string[] __initdata = { NULL, "direct mapped", "2-way",
  676. "3-way", "4-way", "5-way", "6-way", "7-way", "8-way"
  677. };
  678. static void __init probe_pcache(void)
  679. {
  680. struct cpuinfo_mips *c = &current_cpu_data;
  681. unsigned int config = read_c0_config();
  682. unsigned int prid = read_c0_prid();
  683. unsigned long config1;
  684. unsigned int lsize;
  685. switch (c->cputype) {
  686. case CPU_R4600: /* QED style two way caches? */
  687. case CPU_R4700:
  688. case CPU_R5000:
  689. case CPU_NEVADA:
  690. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  691. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  692. c->icache.ways = 2;
  693. c->icache.waybit = ffs(icache_size/2) - 1;
  694. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  695. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  696. c->dcache.ways = 2;
  697. c->dcache.waybit= ffs(dcache_size/2) - 1;
  698. c->options |= MIPS_CPU_CACHE_CDEX_P;
  699. break;
  700. case CPU_R5432:
  701. case CPU_R5500:
  702. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  703. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  704. c->icache.ways = 2;
  705. c->icache.waybit= 0;
  706. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  707. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  708. c->dcache.ways = 2;
  709. c->dcache.waybit = 0;
  710. c->options |= MIPS_CPU_CACHE_CDEX_P;
  711. break;
  712. case CPU_TX49XX:
  713. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  714. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  715. c->icache.ways = 4;
  716. c->icache.waybit= 0;
  717. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  718. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  719. c->dcache.ways = 4;
  720. c->dcache.waybit = 0;
  721. c->options |= MIPS_CPU_CACHE_CDEX_P;
  722. break;
  723. case CPU_R4000PC:
  724. case CPU_R4000SC:
  725. case CPU_R4000MC:
  726. case CPU_R4400PC:
  727. case CPU_R4400SC:
  728. case CPU_R4400MC:
  729. case CPU_R4300:
  730. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  731. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  732. c->icache.ways = 1;
  733. c->icache.waybit = 0; /* doesn't matter */
  734. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  735. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  736. c->dcache.ways = 1;
  737. c->dcache.waybit = 0; /* does not matter */
  738. c->options |= MIPS_CPU_CACHE_CDEX_P;
  739. break;
  740. case CPU_R10000:
  741. case CPU_R12000:
  742. icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
  743. c->icache.linesz = 64;
  744. c->icache.ways = 2;
  745. c->icache.waybit = 0;
  746. dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26));
  747. c->dcache.linesz = 32;
  748. c->dcache.ways = 2;
  749. c->dcache.waybit = 0;
  750. c->options |= MIPS_CPU_PREFETCH;
  751. break;
  752. case CPU_VR4133:
  753. write_c0_config(config & ~CONF_EB);
  754. case CPU_VR4131:
  755. /* Workaround for cache instruction bug of VR4131 */
  756. if (c->processor_id == 0x0c80U || c->processor_id == 0x0c81U ||
  757. c->processor_id == 0x0c82U) {
  758. config &= ~0x00000030U;
  759. config |= 0x00410000U;
  760. write_c0_config(config);
  761. }
  762. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  763. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  764. c->icache.ways = 2;
  765. c->icache.waybit = ffs(icache_size/2) - 1;
  766. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  767. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  768. c->dcache.ways = 2;
  769. c->dcache.waybit = ffs(dcache_size/2) - 1;
  770. c->options |= MIPS_CPU_CACHE_CDEX_P;
  771. break;
  772. case CPU_VR41XX:
  773. case CPU_VR4111:
  774. case CPU_VR4121:
  775. case CPU_VR4122:
  776. case CPU_VR4181:
  777. case CPU_VR4181A:
  778. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  779. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  780. c->icache.ways = 1;
  781. c->icache.waybit = 0; /* doesn't matter */
  782. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  783. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  784. c->dcache.ways = 1;
  785. c->dcache.waybit = 0; /* does not matter */
  786. c->options |= MIPS_CPU_CACHE_CDEX_P;
  787. break;
  788. case CPU_RM7000:
  789. rm7k_erratum31();
  790. case CPU_RM9000:
  791. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  792. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  793. c->icache.ways = 4;
  794. c->icache.waybit = ffs(icache_size / c->icache.ways) - 1;
  795. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  796. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  797. c->dcache.ways = 4;
  798. c->dcache.waybit = ffs(dcache_size / c->dcache.ways) - 1;
  799. #if !defined(CONFIG_SMP) || !defined(RM9000_CDEX_SMP_WAR)
  800. c->options |= MIPS_CPU_CACHE_CDEX_P;
  801. #endif
  802. c->options |= MIPS_CPU_PREFETCH;
  803. break;
  804. default:
  805. if (!(config & MIPS_CONF_M))
  806. panic("Don't know how to probe P-caches on this cpu.");
  807. /*
  808. * So we seem to be a MIPS32 or MIPS64 CPU
  809. * So let's probe the I-cache ...
  810. */
  811. config1 = read_c0_config1();
  812. if ((lsize = ((config1 >> 19) & 7)))
  813. c->icache.linesz = 2 << lsize;
  814. else
  815. c->icache.linesz = lsize;
  816. c->icache.sets = 64 << ((config1 >> 22) & 7);
  817. c->icache.ways = 1 + ((config1 >> 16) & 7);
  818. icache_size = c->icache.sets *
  819. c->icache.ways *
  820. c->icache.linesz;
  821. c->icache.waybit = ffs(icache_size/c->icache.ways) - 1;
  822. if (config & 0x8) /* VI bit */
  823. c->icache.flags |= MIPS_CACHE_VTAG;
  824. /*
  825. * Now probe the MIPS32 / MIPS64 data cache.
  826. */
  827. c->dcache.flags = 0;
  828. if ((lsize = ((config1 >> 10) & 7)))
  829. c->dcache.linesz = 2 << lsize;
  830. else
  831. c->dcache.linesz= lsize;
  832. c->dcache.sets = 64 << ((config1 >> 13) & 7);
  833. c->dcache.ways = 1 + ((config1 >> 7) & 7);
  834. dcache_size = c->dcache.sets *
  835. c->dcache.ways *
  836. c->dcache.linesz;
  837. c->dcache.waybit = ffs(dcache_size/c->dcache.ways) - 1;
  838. c->options |= MIPS_CPU_PREFETCH;
  839. break;
  840. }
  841. /*
  842. * Processor configuration sanity check for the R4000SC erratum
  843. * #5. With page sizes larger than 32kB there is no possibility
  844. * to get a VCE exception anymore so we don't care about this
  845. * misconfiguration. The case is rather theoretical anyway;
  846. * presumably no vendor is shipping his hardware in the "bad"
  847. * configuration.
  848. */
  849. if ((prid & 0xff00) == PRID_IMP_R4000 && (prid & 0xff) < 0x40 &&
  850. !(config & CONF_SC) && c->icache.linesz != 16 &&
  851. PAGE_SIZE <= 0x8000)
  852. panic("Improper R4000SC processor configuration detected");
  853. /* compute a couple of other cache variables */
  854. c->icache.waysize = icache_size / c->icache.ways;
  855. c->dcache.waysize = dcache_size / c->dcache.ways;
  856. c->icache.sets = icache_size / (c->icache.linesz * c->icache.ways);
  857. c->dcache.sets = dcache_size / (c->dcache.linesz * c->dcache.ways);
  858. /*
  859. * R10000 and R12000 P-caches are odd in a positive way. They're 32kB
  860. * 2-way virtually indexed so normally would suffer from aliases. So
  861. * normally they'd suffer from aliases but magic in the hardware deals
  862. * with that for us so we don't need to take care ourselves.
  863. */
  864. switch (c->cputype) {
  865. case CPU_20KC:
  866. case CPU_25KF:
  867. case CPU_R10000:
  868. case CPU_R12000:
  869. case CPU_SB1:
  870. break;
  871. case CPU_24K:
  872. if (!(read_c0_config7() & (1 << 16)))
  873. default:
  874. if (c->dcache.waysize > PAGE_SIZE)
  875. c->dcache.flags |= MIPS_CACHE_ALIASES;
  876. }
  877. switch (c->cputype) {
  878. case CPU_20KC:
  879. /*
  880. * Some older 20Kc chips doesn't have the 'VI' bit in
  881. * the config register.
  882. */
  883. c->icache.flags |= MIPS_CACHE_VTAG;
  884. break;
  885. case CPU_AU1000:
  886. case CPU_AU1500:
  887. case CPU_AU1100:
  888. case CPU_AU1550:
  889. case CPU_AU1200:
  890. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  891. break;
  892. }
  893. printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
  894. icache_size >> 10,
  895. cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
  896. way_string[c->icache.ways], c->icache.linesz);
  897. printk("Primary data cache %ldkB, %s, linesize %d bytes.\n",
  898. dcache_size >> 10, way_string[c->dcache.ways], c->dcache.linesz);
  899. }
  900. /*
  901. * If you even _breathe_ on this function, look at the gcc output and make sure
  902. * it does not pop things on and off the stack for the cache sizing loop that
  903. * executes in KSEG1 space or else you will crash and burn badly. You have
  904. * been warned.
  905. */
  906. static int __init probe_scache(void)
  907. {
  908. extern unsigned long stext;
  909. unsigned long flags, addr, begin, end, pow2;
  910. unsigned int config = read_c0_config();
  911. struct cpuinfo_mips *c = &current_cpu_data;
  912. int tmp;
  913. if (config & CONF_SC)
  914. return 0;
  915. begin = (unsigned long) &stext;
  916. begin &= ~((4 * 1024 * 1024) - 1);
  917. end = begin + (4 * 1024 * 1024);
  918. /*
  919. * This is such a bitch, you'd think they would make it easy to do
  920. * this. Away you daemons of stupidity!
  921. */
  922. local_irq_save(flags);
  923. /* Fill each size-multiple cache line with a valid tag. */
  924. pow2 = (64 * 1024);
  925. for (addr = begin; addr < end; addr = (begin + pow2)) {
  926. unsigned long *p = (unsigned long *) addr;
  927. __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */
  928. pow2 <<= 1;
  929. }
  930. /* Load first line with zero (therefore invalid) tag. */
  931. write_c0_taglo(0);
  932. write_c0_taghi(0);
  933. __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
  934. cache_op(Index_Store_Tag_I, begin);
  935. cache_op(Index_Store_Tag_D, begin);
  936. cache_op(Index_Store_Tag_SD, begin);
  937. /* Now search for the wrap around point. */
  938. pow2 = (128 * 1024);
  939. tmp = 0;
  940. for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) {
  941. cache_op(Index_Load_Tag_SD, addr);
  942. __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */
  943. if (!read_c0_taglo())
  944. break;
  945. pow2 <<= 1;
  946. }
  947. local_irq_restore(flags);
  948. addr -= begin;
  949. scache_size = addr;
  950. c->scache.linesz = 16 << ((config & R4K_CONF_SB) >> 22);
  951. c->scache.ways = 1;
  952. c->dcache.waybit = 0; /* does not matter */
  953. return 1;
  954. }
  955. extern int r5k_sc_init(void);
  956. extern int rm7k_sc_init(void);
  957. static void __init setup_scache(void)
  958. {
  959. struct cpuinfo_mips *c = &current_cpu_data;
  960. unsigned int config = read_c0_config();
  961. int sc_present = 0;
  962. /*
  963. * Do the probing thing on R4000SC and R4400SC processors. Other
  964. * processors don't have a S-cache that would be relevant to the
  965. * Linux memory managment.
  966. */
  967. switch (c->cputype) {
  968. case CPU_R4000SC:
  969. case CPU_R4000MC:
  970. case CPU_R4400SC:
  971. case CPU_R4400MC:
  972. sc_present = run_uncached(probe_scache);
  973. if (sc_present)
  974. c->options |= MIPS_CPU_CACHE_CDEX_S;
  975. break;
  976. case CPU_R10000:
  977. case CPU_R12000:
  978. scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
  979. c->scache.linesz = 64 << ((config >> 13) & 1);
  980. c->scache.ways = 2;
  981. c->scache.waybit= 0;
  982. sc_present = 1;
  983. break;
  984. case CPU_R5000:
  985. case CPU_NEVADA:
  986. #ifdef CONFIG_R5000_CPU_SCACHE
  987. r5k_sc_init();
  988. #endif
  989. return;
  990. case CPU_RM7000:
  991. case CPU_RM9000:
  992. #ifdef CONFIG_RM7000_CPU_SCACHE
  993. rm7k_sc_init();
  994. #endif
  995. return;
  996. default:
  997. sc_present = 0;
  998. }
  999. if (!sc_present)
  1000. return;
  1001. if ((c->isa_level == MIPS_CPU_ISA_M32R1 ||
  1002. c->isa_level == MIPS_CPU_ISA_M64R1) &&
  1003. !(c->scache.flags & MIPS_CACHE_NOT_PRESENT))
  1004. panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
  1005. /* compute a couple of other cache variables */
  1006. c->scache.waysize = scache_size / c->scache.ways;
  1007. c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
  1008. printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
  1009. scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
  1010. c->options |= MIPS_CPU_SUBSET_CACHES;
  1011. }
  1012. static inline void coherency_setup(void)
  1013. {
  1014. change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
  1015. /*
  1016. * c0_status.cu=0 specifies that updates by the sc instruction use
  1017. * the coherency mode specified by the TLB; 1 means cachable
  1018. * coherent update on write will be used. Not all processors have
  1019. * this bit and; some wire it to zero, others like Toshiba had the
  1020. * silly idea of putting something else there ...
  1021. */
  1022. switch (current_cpu_data.cputype) {
  1023. case CPU_R4000PC:
  1024. case CPU_R4000SC:
  1025. case CPU_R4000MC:
  1026. case CPU_R4400PC:
  1027. case CPU_R4400SC:
  1028. case CPU_R4400MC:
  1029. clear_c0_config(CONF_CU);
  1030. break;
  1031. }
  1032. }
  1033. void __init r4k_cache_init(void)
  1034. {
  1035. extern void build_clear_page(void);
  1036. extern void build_copy_page(void);
  1037. extern char except_vec2_generic;
  1038. struct cpuinfo_mips *c = &current_cpu_data;
  1039. /* Default cache error handler for R4000 and R5000 family */
  1040. set_uncached_handler (0x100, &except_vec2_generic, 0x80);
  1041. probe_pcache();
  1042. setup_scache();
  1043. r4k_blast_dcache_page_setup();
  1044. r4k_blast_dcache_page_indexed_setup();
  1045. r4k_blast_dcache_setup();
  1046. r4k_blast_icache_page_setup();
  1047. r4k_blast_icache_page_indexed_setup();
  1048. r4k_blast_icache_setup();
  1049. r4k_blast_scache_page_setup();
  1050. r4k_blast_scache_page_indexed_setup();
  1051. r4k_blast_scache_setup();
  1052. /*
  1053. * Some MIPS32 and MIPS64 processors have physically indexed caches.
  1054. * This code supports virtually indexed processors and will be
  1055. * unnecessarily inefficient on physically indexed processors.
  1056. */
  1057. shm_align_mask = max_t( unsigned long,
  1058. c->dcache.sets * c->dcache.linesz - 1,
  1059. PAGE_SIZE - 1);
  1060. flush_cache_all = r4k_flush_cache_all;
  1061. __flush_cache_all = r4k___flush_cache_all;
  1062. flush_cache_mm = r4k_flush_cache_mm;
  1063. flush_cache_page = r4k_flush_cache_page;
  1064. flush_icache_page = r4k_flush_icache_page;
  1065. flush_cache_range = r4k_flush_cache_range;
  1066. flush_cache_sigtramp = r4k_flush_cache_sigtramp;
  1067. flush_icache_all = r4k_flush_icache_all;
  1068. flush_data_cache_page = r4k_flush_data_cache_page;
  1069. flush_icache_range = r4k_flush_icache_range;
  1070. #ifdef CONFIG_DMA_NONCOHERENT
  1071. _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
  1072. _dma_cache_wback = r4k_dma_cache_wback_inv;
  1073. _dma_cache_inv = r4k_dma_cache_inv;
  1074. #endif
  1075. build_clear_page();
  1076. build_copy_page();
  1077. local_r4k___flush_cache_all(NULL);
  1078. coherency_setup();
  1079. }