c-r4k.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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. pud_t *pudp;
  313. pmd_t *pmdp;
  314. pte_t *ptep;
  315. /*
  316. * If ownes no valid ASID yet, cannot possibly have gotten
  317. * this page into the cache.
  318. */
  319. if (cpu_context(smp_processor_id(), mm) == 0)
  320. return;
  321. page &= PAGE_MASK;
  322. pgdp = pgd_offset(mm, page);
  323. pudp = pud_offset(pgdp, page);
  324. pmdp = pmd_offset(pudp, page);
  325. ptep = pte_offset(pmdp, page);
  326. /*
  327. * If the page isn't marked valid, the page cannot possibly be
  328. * in the cache.
  329. */
  330. if (!(pte_val(*ptep) & _PAGE_PRESENT))
  331. return;
  332. /*
  333. * Doing flushes for another ASID than the current one is
  334. * too difficult since stupid R4k caches do a TLB translation
  335. * for every cache flush operation. So we do indexed flushes
  336. * in that case, which doesn't overly flush the cache too much.
  337. */
  338. if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) {
  339. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  340. r4k_blast_dcache_page(page);
  341. if (exec && !cpu_icache_snoops_remote_store)
  342. r4k_blast_scache_page(page);
  343. }
  344. if (exec)
  345. r4k_blast_icache_page(page);
  346. return;
  347. }
  348. /*
  349. * Do indexed flush, too much work to get the (possible) TLB refills
  350. * to work correctly.
  351. */
  352. page = INDEX_BASE + (page & (dcache_size - 1));
  353. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  354. r4k_blast_dcache_page_indexed(page);
  355. if (exec && !cpu_icache_snoops_remote_store)
  356. r4k_blast_scache_page_indexed(page);
  357. }
  358. if (exec) {
  359. if (cpu_has_vtag_icache) {
  360. int cpu = smp_processor_id();
  361. if (cpu_context(cpu, mm) != 0)
  362. drop_mmu_context(mm, cpu);
  363. } else
  364. r4k_blast_icache_page_indexed(page);
  365. }
  366. }
  367. static void r4k_flush_cache_page(struct vm_area_struct *vma, unsigned long page, unsigned long pfn)
  368. {
  369. struct flush_cache_page_args args;
  370. args.vma = vma;
  371. args.page = page;
  372. on_each_cpu(local_r4k_flush_cache_page, &args, 1, 1);
  373. }
  374. static inline void local_r4k_flush_data_cache_page(void * addr)
  375. {
  376. r4k_blast_dcache_page((unsigned long) addr);
  377. }
  378. static void r4k_flush_data_cache_page(unsigned long addr)
  379. {
  380. on_each_cpu(local_r4k_flush_data_cache_page, (void *) addr, 1, 1);
  381. }
  382. struct flush_icache_range_args {
  383. unsigned long start;
  384. unsigned long end;
  385. };
  386. static inline void local_r4k_flush_icache_range(void *args)
  387. {
  388. struct flush_icache_range_args *fir_args = args;
  389. unsigned long dc_lsize = current_cpu_data.dcache.linesz;
  390. unsigned long ic_lsize = current_cpu_data.icache.linesz;
  391. unsigned long sc_lsize = current_cpu_data.scache.linesz;
  392. unsigned long start = fir_args->start;
  393. unsigned long end = fir_args->end;
  394. unsigned long addr, aend;
  395. if (!cpu_has_ic_fills_f_dc) {
  396. if (end - start > dcache_size) {
  397. r4k_blast_dcache();
  398. } else {
  399. addr = start & ~(dc_lsize - 1);
  400. aend = (end - 1) & ~(dc_lsize - 1);
  401. while (1) {
  402. /* Hit_Writeback_Inv_D */
  403. protected_writeback_dcache_line(addr);
  404. if (addr == aend)
  405. break;
  406. addr += dc_lsize;
  407. }
  408. }
  409. if (!cpu_icache_snoops_remote_store) {
  410. if (end - start > scache_size) {
  411. r4k_blast_scache();
  412. } else {
  413. addr = start & ~(sc_lsize - 1);
  414. aend = (end - 1) & ~(sc_lsize - 1);
  415. while (1) {
  416. /* Hit_Writeback_Inv_D */
  417. protected_writeback_scache_line(addr);
  418. if (addr == aend)
  419. break;
  420. addr += sc_lsize;
  421. }
  422. }
  423. }
  424. }
  425. if (end - start > icache_size)
  426. r4k_blast_icache();
  427. else {
  428. addr = start & ~(ic_lsize - 1);
  429. aend = (end - 1) & ~(ic_lsize - 1);
  430. while (1) {
  431. /* Hit_Invalidate_I */
  432. protected_flush_icache_line(addr);
  433. if (addr == aend)
  434. break;
  435. addr += ic_lsize;
  436. }
  437. }
  438. }
  439. static void r4k_flush_icache_range(unsigned long start, unsigned long end)
  440. {
  441. struct flush_icache_range_args args;
  442. args.start = start;
  443. args.end = end;
  444. on_each_cpu(local_r4k_flush_icache_range, &args, 1, 1);
  445. }
  446. /*
  447. * Ok, this seriously sucks. We use them to flush a user page but don't
  448. * know the virtual address, so we have to blast away the whole icache
  449. * which is significantly more expensive than the real thing. Otoh we at
  450. * least know the kernel address of the page so we can flush it
  451. * selectivly.
  452. */
  453. struct flush_icache_page_args {
  454. struct vm_area_struct *vma;
  455. struct page *page;
  456. };
  457. static inline void local_r4k_flush_icache_page(void *args)
  458. {
  459. struct flush_icache_page_args *fip_args = args;
  460. struct vm_area_struct *vma = fip_args->vma;
  461. struct page *page = fip_args->page;
  462. /*
  463. * Tricky ... Because we don't know the virtual address we've got the
  464. * choice of either invalidating the entire primary and secondary
  465. * caches or invalidating the secondary caches also. With the subset
  466. * enforcment on R4000SC, R4400SC, R10000 and R12000 invalidating the
  467. * secondary cache will result in any entries in the primary caches
  468. * also getting invalidated which hopefully is a bit more economical.
  469. */
  470. if (cpu_has_subset_pcaches) {
  471. unsigned long addr = (unsigned long) page_address(page);
  472. r4k_blast_scache_page(addr);
  473. ClearPageDcacheDirty(page);
  474. return;
  475. }
  476. if (!cpu_has_ic_fills_f_dc) {
  477. unsigned long addr = (unsigned long) page_address(page);
  478. r4k_blast_dcache_page(addr);
  479. if (!cpu_icache_snoops_remote_store)
  480. r4k_blast_scache_page(addr);
  481. ClearPageDcacheDirty(page);
  482. }
  483. /*
  484. * We're not sure of the virtual address(es) involved here, so
  485. * we have to flush the entire I-cache.
  486. */
  487. if (cpu_has_vtag_icache) {
  488. int cpu = smp_processor_id();
  489. if (cpu_context(cpu, vma->vm_mm) != 0)
  490. drop_mmu_context(vma->vm_mm, cpu);
  491. } else
  492. r4k_blast_icache();
  493. }
  494. static void r4k_flush_icache_page(struct vm_area_struct *vma,
  495. struct page *page)
  496. {
  497. struct flush_icache_page_args args;
  498. /*
  499. * If there's no context yet, or the page isn't executable, no I-cache
  500. * flush is needed.
  501. */
  502. if (!(vma->vm_flags & VM_EXEC))
  503. return;
  504. args.vma = vma;
  505. args.page = page;
  506. on_each_cpu(local_r4k_flush_icache_page, &args, 1, 1);
  507. }
  508. #ifdef CONFIG_DMA_NONCOHERENT
  509. static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
  510. {
  511. unsigned long end, a;
  512. /* Catch bad driver code */
  513. BUG_ON(size == 0);
  514. if (cpu_has_subset_pcaches) {
  515. unsigned long sc_lsize = current_cpu_data.scache.linesz;
  516. if (size >= scache_size) {
  517. r4k_blast_scache();
  518. return;
  519. }
  520. a = addr & ~(sc_lsize - 1);
  521. end = (addr + size - 1) & ~(sc_lsize - 1);
  522. while (1) {
  523. flush_scache_line(a); /* Hit_Writeback_Inv_SD */
  524. if (a == end)
  525. break;
  526. a += sc_lsize;
  527. }
  528. return;
  529. }
  530. /*
  531. * Either no secondary cache or the available caches don't have the
  532. * subset property so we have to flush the primary caches
  533. * explicitly
  534. */
  535. if (size >= dcache_size) {
  536. r4k_blast_dcache();
  537. } else {
  538. unsigned long dc_lsize = current_cpu_data.dcache.linesz;
  539. R4600_HIT_CACHEOP_WAR_IMPL;
  540. a = addr & ~(dc_lsize - 1);
  541. end = (addr + size - 1) & ~(dc_lsize - 1);
  542. while (1) {
  543. flush_dcache_line(a); /* Hit_Writeback_Inv_D */
  544. if (a == end)
  545. break;
  546. a += dc_lsize;
  547. }
  548. }
  549. bc_wback_inv(addr, size);
  550. }
  551. static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
  552. {
  553. unsigned long end, a;
  554. /* Catch bad driver code */
  555. BUG_ON(size == 0);
  556. if (cpu_has_subset_pcaches) {
  557. unsigned long sc_lsize = current_cpu_data.scache.linesz;
  558. if (size >= scache_size) {
  559. r4k_blast_scache();
  560. return;
  561. }
  562. a = addr & ~(sc_lsize - 1);
  563. end = (addr + size - 1) & ~(sc_lsize - 1);
  564. while (1) {
  565. flush_scache_line(a); /* Hit_Writeback_Inv_SD */
  566. if (a == end)
  567. break;
  568. a += sc_lsize;
  569. }
  570. return;
  571. }
  572. if (size >= dcache_size) {
  573. r4k_blast_dcache();
  574. } else {
  575. unsigned long dc_lsize = current_cpu_data.dcache.linesz;
  576. R4600_HIT_CACHEOP_WAR_IMPL;
  577. a = addr & ~(dc_lsize - 1);
  578. end = (addr + size - 1) & ~(dc_lsize - 1);
  579. while (1) {
  580. flush_dcache_line(a); /* Hit_Writeback_Inv_D */
  581. if (a == end)
  582. break;
  583. a += dc_lsize;
  584. }
  585. }
  586. bc_inv(addr, size);
  587. }
  588. #endif /* CONFIG_DMA_NONCOHERENT */
  589. /*
  590. * While we're protected against bad userland addresses we don't care
  591. * very much about what happens in that case. Usually a segmentation
  592. * fault will dump the process later on anyway ...
  593. */
  594. static void local_r4k_flush_cache_sigtramp(void * arg)
  595. {
  596. unsigned long ic_lsize = current_cpu_data.icache.linesz;
  597. unsigned long dc_lsize = current_cpu_data.dcache.linesz;
  598. unsigned long sc_lsize = current_cpu_data.scache.linesz;
  599. unsigned long addr = (unsigned long) arg;
  600. R4600_HIT_CACHEOP_WAR_IMPL;
  601. protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
  602. if (!cpu_icache_snoops_remote_store)
  603. protected_writeback_scache_line(addr & ~(sc_lsize - 1));
  604. protected_flush_icache_line(addr & ~(ic_lsize - 1));
  605. if (MIPS4K_ICACHE_REFILL_WAR) {
  606. __asm__ __volatile__ (
  607. ".set push\n\t"
  608. ".set noat\n\t"
  609. ".set mips3\n\t"
  610. #ifdef CONFIG_32BIT
  611. "la $at,1f\n\t"
  612. #endif
  613. #ifdef CONFIG_64BIT
  614. "dla $at,1f\n\t"
  615. #endif
  616. "cache %0,($at)\n\t"
  617. "nop; nop; nop\n"
  618. "1:\n\t"
  619. ".set pop"
  620. :
  621. : "i" (Hit_Invalidate_I));
  622. }
  623. if (MIPS_CACHE_SYNC_WAR)
  624. __asm__ __volatile__ ("sync");
  625. }
  626. static void r4k_flush_cache_sigtramp(unsigned long addr)
  627. {
  628. on_each_cpu(local_r4k_flush_cache_sigtramp, (void *) addr, 1, 1);
  629. }
  630. static void r4k_flush_icache_all(void)
  631. {
  632. if (cpu_has_vtag_icache)
  633. r4k_blast_icache();
  634. }
  635. static inline void rm7k_erratum31(void)
  636. {
  637. const unsigned long ic_lsize = 32;
  638. unsigned long addr;
  639. /* RM7000 erratum #31. The icache is screwed at startup. */
  640. write_c0_taglo(0);
  641. write_c0_taghi(0);
  642. for (addr = INDEX_BASE; addr <= INDEX_BASE + 4096; addr += ic_lsize) {
  643. __asm__ __volatile__ (
  644. ".set noreorder\n\t"
  645. ".set mips3\n\t"
  646. "cache\t%1, 0(%0)\n\t"
  647. "cache\t%1, 0x1000(%0)\n\t"
  648. "cache\t%1, 0x2000(%0)\n\t"
  649. "cache\t%1, 0x3000(%0)\n\t"
  650. "cache\t%2, 0(%0)\n\t"
  651. "cache\t%2, 0x1000(%0)\n\t"
  652. "cache\t%2, 0x2000(%0)\n\t"
  653. "cache\t%2, 0x3000(%0)\n\t"
  654. "cache\t%1, 0(%0)\n\t"
  655. "cache\t%1, 0x1000(%0)\n\t"
  656. "cache\t%1, 0x2000(%0)\n\t"
  657. "cache\t%1, 0x3000(%0)\n\t"
  658. ".set\tmips0\n\t"
  659. ".set\treorder\n\t"
  660. :
  661. : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill));
  662. }
  663. }
  664. static char *way_string[] __initdata = { NULL, "direct mapped", "2-way",
  665. "3-way", "4-way", "5-way", "6-way", "7-way", "8-way"
  666. };
  667. static void __init probe_pcache(void)
  668. {
  669. struct cpuinfo_mips *c = &current_cpu_data;
  670. unsigned int config = read_c0_config();
  671. unsigned int prid = read_c0_prid();
  672. unsigned long config1;
  673. unsigned int lsize;
  674. switch (c->cputype) {
  675. case CPU_R4600: /* QED style two way caches? */
  676. case CPU_R4700:
  677. case CPU_R5000:
  678. case CPU_NEVADA:
  679. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  680. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  681. c->icache.ways = 2;
  682. c->icache.waybit = ffs(icache_size/2) - 1;
  683. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  684. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  685. c->dcache.ways = 2;
  686. c->dcache.waybit= ffs(dcache_size/2) - 1;
  687. c->options |= MIPS_CPU_CACHE_CDEX_P;
  688. break;
  689. case CPU_R5432:
  690. case CPU_R5500:
  691. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  692. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  693. c->icache.ways = 2;
  694. c->icache.waybit= 0;
  695. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  696. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  697. c->dcache.ways = 2;
  698. c->dcache.waybit = 0;
  699. c->options |= MIPS_CPU_CACHE_CDEX_P;
  700. break;
  701. case CPU_TX49XX:
  702. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  703. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  704. c->icache.ways = 4;
  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 = 4;
  709. c->dcache.waybit = 0;
  710. c->options |= MIPS_CPU_CACHE_CDEX_P;
  711. break;
  712. case CPU_R4000PC:
  713. case CPU_R4000SC:
  714. case CPU_R4000MC:
  715. case CPU_R4400PC:
  716. case CPU_R4400SC:
  717. case CPU_R4400MC:
  718. case CPU_R4300:
  719. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  720. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  721. c->icache.ways = 1;
  722. c->icache.waybit = 0; /* doesn't matter */
  723. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  724. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  725. c->dcache.ways = 1;
  726. c->dcache.waybit = 0; /* does not matter */
  727. c->options |= MIPS_CPU_CACHE_CDEX_P;
  728. break;
  729. case CPU_R10000:
  730. case CPU_R12000:
  731. icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
  732. c->icache.linesz = 64;
  733. c->icache.ways = 2;
  734. c->icache.waybit = 0;
  735. dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26));
  736. c->dcache.linesz = 32;
  737. c->dcache.ways = 2;
  738. c->dcache.waybit = 0;
  739. c->options |= MIPS_CPU_PREFETCH;
  740. break;
  741. case CPU_VR4133:
  742. write_c0_config(config & ~CONF_EB);
  743. case CPU_VR4131:
  744. /* Workaround for cache instruction bug of VR4131 */
  745. if (c->processor_id == 0x0c80U || c->processor_id == 0x0c81U ||
  746. c->processor_id == 0x0c82U) {
  747. config &= ~0x00000030U;
  748. config |= 0x00410000U;
  749. write_c0_config(config);
  750. }
  751. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  752. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  753. c->icache.ways = 2;
  754. c->icache.waybit = ffs(icache_size/2) - 1;
  755. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  756. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  757. c->dcache.ways = 2;
  758. c->dcache.waybit = ffs(dcache_size/2) - 1;
  759. c->options |= MIPS_CPU_CACHE_CDEX_P;
  760. break;
  761. case CPU_VR41XX:
  762. case CPU_VR4111:
  763. case CPU_VR4121:
  764. case CPU_VR4122:
  765. case CPU_VR4181:
  766. case CPU_VR4181A:
  767. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  768. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  769. c->icache.ways = 1;
  770. c->icache.waybit = 0; /* doesn't matter */
  771. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  772. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  773. c->dcache.ways = 1;
  774. c->dcache.waybit = 0; /* does not matter */
  775. c->options |= MIPS_CPU_CACHE_CDEX_P;
  776. break;
  777. case CPU_RM7000:
  778. rm7k_erratum31();
  779. case CPU_RM9000:
  780. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  781. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  782. c->icache.ways = 4;
  783. c->icache.waybit = ffs(icache_size / c->icache.ways) - 1;
  784. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  785. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  786. c->dcache.ways = 4;
  787. c->dcache.waybit = ffs(dcache_size / c->dcache.ways) - 1;
  788. #if !defined(CONFIG_SMP) || !defined(RM9000_CDEX_SMP_WAR)
  789. c->options |= MIPS_CPU_CACHE_CDEX_P;
  790. #endif
  791. c->options |= MIPS_CPU_PREFETCH;
  792. break;
  793. default:
  794. if (!(config & MIPS_CONF_M))
  795. panic("Don't know how to probe P-caches on this cpu.");
  796. /*
  797. * So we seem to be a MIPS32 or MIPS64 CPU
  798. * So let's probe the I-cache ...
  799. */
  800. config1 = read_c0_config1();
  801. if ((lsize = ((config1 >> 19) & 7)))
  802. c->icache.linesz = 2 << lsize;
  803. else
  804. c->icache.linesz = lsize;
  805. c->icache.sets = 64 << ((config1 >> 22) & 7);
  806. c->icache.ways = 1 + ((config1 >> 16) & 7);
  807. icache_size = c->icache.sets *
  808. c->icache.ways *
  809. c->icache.linesz;
  810. c->icache.waybit = ffs(icache_size/c->icache.ways) - 1;
  811. if (config & 0x8) /* VI bit */
  812. c->icache.flags |= MIPS_CACHE_VTAG;
  813. /*
  814. * Now probe the MIPS32 / MIPS64 data cache.
  815. */
  816. c->dcache.flags = 0;
  817. if ((lsize = ((config1 >> 10) & 7)))
  818. c->dcache.linesz = 2 << lsize;
  819. else
  820. c->dcache.linesz= lsize;
  821. c->dcache.sets = 64 << ((config1 >> 13) & 7);
  822. c->dcache.ways = 1 + ((config1 >> 7) & 7);
  823. dcache_size = c->dcache.sets *
  824. c->dcache.ways *
  825. c->dcache.linesz;
  826. c->dcache.waybit = ffs(dcache_size/c->dcache.ways) - 1;
  827. c->options |= MIPS_CPU_PREFETCH;
  828. break;
  829. }
  830. /*
  831. * Processor configuration sanity check for the R4000SC erratum
  832. * #5. With page sizes larger than 32kB there is no possibility
  833. * to get a VCE exception anymore so we don't care about this
  834. * misconfiguration. The case is rather theoretical anyway;
  835. * presumably no vendor is shipping his hardware in the "bad"
  836. * configuration.
  837. */
  838. if ((prid & 0xff00) == PRID_IMP_R4000 && (prid & 0xff) < 0x40 &&
  839. !(config & CONF_SC) && c->icache.linesz != 16 &&
  840. PAGE_SIZE <= 0x8000)
  841. panic("Improper R4000SC processor configuration detected");
  842. /* compute a couple of other cache variables */
  843. c->icache.waysize = icache_size / c->icache.ways;
  844. c->dcache.waysize = dcache_size / c->dcache.ways;
  845. c->icache.sets = icache_size / (c->icache.linesz * c->icache.ways);
  846. c->dcache.sets = dcache_size / (c->dcache.linesz * c->dcache.ways);
  847. /*
  848. * R10000 and R12000 P-caches are odd in a positive way. They're 32kB
  849. * 2-way virtually indexed so normally would suffer from aliases. So
  850. * normally they'd suffer from aliases but magic in the hardware deals
  851. * with that for us so we don't need to take care ourselves.
  852. */
  853. switch (c->cputype) {
  854. case CPU_20KC:
  855. case CPU_25KF:
  856. case CPU_R10000:
  857. case CPU_R12000:
  858. case CPU_SB1:
  859. break;
  860. case CPU_24K:
  861. if (!(read_c0_config7() & (1 << 16)))
  862. default:
  863. if (c->dcache.waysize > PAGE_SIZE)
  864. c->dcache.flags |= MIPS_CACHE_ALIASES;
  865. }
  866. switch (c->cputype) {
  867. case CPU_20KC:
  868. /*
  869. * Some older 20Kc chips doesn't have the 'VI' bit in
  870. * the config register.
  871. */
  872. c->icache.flags |= MIPS_CACHE_VTAG;
  873. break;
  874. case CPU_AU1000:
  875. case CPU_AU1500:
  876. case CPU_AU1100:
  877. case CPU_AU1550:
  878. case CPU_AU1200:
  879. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  880. break;
  881. }
  882. printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
  883. icache_size >> 10,
  884. cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
  885. way_string[c->icache.ways], c->icache.linesz);
  886. printk("Primary data cache %ldkB, %s, linesize %d bytes.\n",
  887. dcache_size >> 10, way_string[c->dcache.ways], c->dcache.linesz);
  888. }
  889. /*
  890. * If you even _breathe_ on this function, look at the gcc output and make sure
  891. * it does not pop things on and off the stack for the cache sizing loop that
  892. * executes in KSEG1 space or else you will crash and burn badly. You have
  893. * been warned.
  894. */
  895. static int __init probe_scache(void)
  896. {
  897. extern unsigned long stext;
  898. unsigned long flags, addr, begin, end, pow2;
  899. unsigned int config = read_c0_config();
  900. struct cpuinfo_mips *c = &current_cpu_data;
  901. int tmp;
  902. if (config & CONF_SC)
  903. return 0;
  904. begin = (unsigned long) &stext;
  905. begin &= ~((4 * 1024 * 1024) - 1);
  906. end = begin + (4 * 1024 * 1024);
  907. /*
  908. * This is such a bitch, you'd think they would make it easy to do
  909. * this. Away you daemons of stupidity!
  910. */
  911. local_irq_save(flags);
  912. /* Fill each size-multiple cache line with a valid tag. */
  913. pow2 = (64 * 1024);
  914. for (addr = begin; addr < end; addr = (begin + pow2)) {
  915. unsigned long *p = (unsigned long *) addr;
  916. __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */
  917. pow2 <<= 1;
  918. }
  919. /* Load first line with zero (therefore invalid) tag. */
  920. write_c0_taglo(0);
  921. write_c0_taghi(0);
  922. __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
  923. cache_op(Index_Store_Tag_I, begin);
  924. cache_op(Index_Store_Tag_D, begin);
  925. cache_op(Index_Store_Tag_SD, begin);
  926. /* Now search for the wrap around point. */
  927. pow2 = (128 * 1024);
  928. tmp = 0;
  929. for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) {
  930. cache_op(Index_Load_Tag_SD, addr);
  931. __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */
  932. if (!read_c0_taglo())
  933. break;
  934. pow2 <<= 1;
  935. }
  936. local_irq_restore(flags);
  937. addr -= begin;
  938. scache_size = addr;
  939. c->scache.linesz = 16 << ((config & R4K_CONF_SB) >> 22);
  940. c->scache.ways = 1;
  941. c->dcache.waybit = 0; /* does not matter */
  942. return 1;
  943. }
  944. typedef int (*probe_func_t)(unsigned long);
  945. extern int r5k_sc_init(void);
  946. extern int rm7k_sc_init(void);
  947. static void __init setup_scache(void)
  948. {
  949. struct cpuinfo_mips *c = &current_cpu_data;
  950. unsigned int config = read_c0_config();
  951. probe_func_t probe_scache_kseg1;
  952. int sc_present = 0;
  953. /*
  954. * Do the probing thing on R4000SC and R4400SC processors. Other
  955. * processors don't have a S-cache that would be relevant to the
  956. * Linux memory managment.
  957. */
  958. switch (c->cputype) {
  959. case CPU_R4000SC:
  960. case CPU_R4000MC:
  961. case CPU_R4400SC:
  962. case CPU_R4400MC:
  963. probe_scache_kseg1 = (probe_func_t) (CKSEG1ADDR(&probe_scache));
  964. sc_present = probe_scache_kseg1(config);
  965. if (sc_present)
  966. c->options |= MIPS_CPU_CACHE_CDEX_S;
  967. break;
  968. case CPU_R10000:
  969. case CPU_R12000:
  970. scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
  971. c->scache.linesz = 64 << ((config >> 13) & 1);
  972. c->scache.ways = 2;
  973. c->scache.waybit= 0;
  974. sc_present = 1;
  975. break;
  976. case CPU_R5000:
  977. case CPU_NEVADA:
  978. #ifdef CONFIG_R5000_CPU_SCACHE
  979. r5k_sc_init();
  980. #endif
  981. return;
  982. case CPU_RM7000:
  983. case CPU_RM9000:
  984. #ifdef CONFIG_RM7000_CPU_SCACHE
  985. rm7k_sc_init();
  986. #endif
  987. return;
  988. default:
  989. sc_present = 0;
  990. }
  991. if (!sc_present)
  992. return;
  993. if ((c->isa_level == MIPS_CPU_ISA_M32 ||
  994. c->isa_level == MIPS_CPU_ISA_M64) &&
  995. !(c->scache.flags & MIPS_CACHE_NOT_PRESENT))
  996. panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
  997. /* compute a couple of other cache variables */
  998. c->scache.waysize = scache_size / c->scache.ways;
  999. c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
  1000. printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
  1001. scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
  1002. c->options |= MIPS_CPU_SUBSET_CACHES;
  1003. }
  1004. static inline void coherency_setup(void)
  1005. {
  1006. change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
  1007. /*
  1008. * c0_status.cu=0 specifies that updates by the sc instruction use
  1009. * the coherency mode specified by the TLB; 1 means cachable
  1010. * coherent update on write will be used. Not all processors have
  1011. * this bit and; some wire it to zero, others like Toshiba had the
  1012. * silly idea of putting something else there ...
  1013. */
  1014. switch (current_cpu_data.cputype) {
  1015. case CPU_R4000PC:
  1016. case CPU_R4000SC:
  1017. case CPU_R4000MC:
  1018. case CPU_R4400PC:
  1019. case CPU_R4400SC:
  1020. case CPU_R4400MC:
  1021. clear_c0_config(CONF_CU);
  1022. break;
  1023. }
  1024. }
  1025. void __init ld_mmu_r4xx0(void)
  1026. {
  1027. extern void build_clear_page(void);
  1028. extern void build_copy_page(void);
  1029. extern char except_vec2_generic;
  1030. struct cpuinfo_mips *c = &current_cpu_data;
  1031. /* Default cache error handler for R4000 and R5000 family */
  1032. memcpy((void *)(CAC_BASE + 0x100), &except_vec2_generic, 0x80);
  1033. memcpy((void *)(UNCAC_BASE + 0x100), &except_vec2_generic, 0x80);
  1034. probe_pcache();
  1035. setup_scache();
  1036. r4k_blast_dcache_page_setup();
  1037. r4k_blast_dcache_page_indexed_setup();
  1038. r4k_blast_dcache_setup();
  1039. r4k_blast_icache_page_setup();
  1040. r4k_blast_icache_page_indexed_setup();
  1041. r4k_blast_icache_setup();
  1042. r4k_blast_scache_page_setup();
  1043. r4k_blast_scache_page_indexed_setup();
  1044. r4k_blast_scache_setup();
  1045. /*
  1046. * Some MIPS32 and MIPS64 processors have physically indexed caches.
  1047. * This code supports virtually indexed processors and will be
  1048. * unnecessarily inefficient on physically indexed processors.
  1049. */
  1050. shm_align_mask = max_t( unsigned long,
  1051. c->dcache.sets * c->dcache.linesz - 1,
  1052. PAGE_SIZE - 1);
  1053. flush_cache_all = r4k_flush_cache_all;
  1054. __flush_cache_all = r4k___flush_cache_all;
  1055. flush_cache_mm = r4k_flush_cache_mm;
  1056. flush_cache_page = r4k_flush_cache_page;
  1057. flush_icache_page = r4k_flush_icache_page;
  1058. flush_cache_range = r4k_flush_cache_range;
  1059. flush_cache_sigtramp = r4k_flush_cache_sigtramp;
  1060. flush_icache_all = r4k_flush_icache_all;
  1061. flush_data_cache_page = r4k_flush_data_cache_page;
  1062. flush_icache_range = r4k_flush_icache_range;
  1063. #ifdef CONFIG_DMA_NONCOHERENT
  1064. _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
  1065. _dma_cache_wback = r4k_dma_cache_wback_inv;
  1066. _dma_cache_inv = r4k_dma_cache_inv;
  1067. #endif
  1068. __flush_cache_all();
  1069. coherency_setup();
  1070. build_clear_page();
  1071. build_copy_page();
  1072. }