c-r4k.c 33 KB

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