c-r4k.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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. if (c->dcache.waysize > PAGE_SIZE)
  853. case CPU_R10000:
  854. case CPU_R12000:
  855. break;
  856. case CPU_24K:
  857. if (!(read_c0_config7() & (1 << 16)))
  858. default:
  859. c->dcache.flags |= MIPS_CACHE_ALIASES;
  860. }
  861. switch (c->cputype) {
  862. case CPU_20KC:
  863. /*
  864. * Some older 20Kc chips doesn't have the 'VI' bit in
  865. * the config register.
  866. */
  867. c->icache.flags |= MIPS_CACHE_VTAG;
  868. break;
  869. case CPU_AU1500:
  870. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  871. break;
  872. }
  873. printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
  874. icache_size >> 10,
  875. cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
  876. way_string[c->icache.ways], c->icache.linesz);
  877. printk("Primary data cache %ldkB, %s, linesize %d bytes.\n",
  878. dcache_size >> 10, way_string[c->dcache.ways], c->dcache.linesz);
  879. }
  880. /*
  881. * If you even _breathe_ on this function, look at the gcc output and make sure
  882. * it does not pop things on and off the stack for the cache sizing loop that
  883. * executes in KSEG1 space or else you will crash and burn badly. You have
  884. * been warned.
  885. */
  886. static int __init probe_scache(void)
  887. {
  888. extern unsigned long stext;
  889. unsigned long flags, addr, begin, end, pow2;
  890. unsigned int config = read_c0_config();
  891. struct cpuinfo_mips *c = &current_cpu_data;
  892. int tmp;
  893. if (config & CONF_SC)
  894. return 0;
  895. begin = (unsigned long) &stext;
  896. begin &= ~((4 * 1024 * 1024) - 1);
  897. end = begin + (4 * 1024 * 1024);
  898. /*
  899. * This is such a bitch, you'd think they would make it easy to do
  900. * this. Away you daemons of stupidity!
  901. */
  902. local_irq_save(flags);
  903. /* Fill each size-multiple cache line with a valid tag. */
  904. pow2 = (64 * 1024);
  905. for (addr = begin; addr < end; addr = (begin + pow2)) {
  906. unsigned long *p = (unsigned long *) addr;
  907. __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */
  908. pow2 <<= 1;
  909. }
  910. /* Load first line with zero (therefore invalid) tag. */
  911. write_c0_taglo(0);
  912. write_c0_taghi(0);
  913. __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
  914. cache_op(Index_Store_Tag_I, begin);
  915. cache_op(Index_Store_Tag_D, begin);
  916. cache_op(Index_Store_Tag_SD, begin);
  917. /* Now search for the wrap around point. */
  918. pow2 = (128 * 1024);
  919. tmp = 0;
  920. for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) {
  921. cache_op(Index_Load_Tag_SD, addr);
  922. __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */
  923. if (!read_c0_taglo())
  924. break;
  925. pow2 <<= 1;
  926. }
  927. local_irq_restore(flags);
  928. addr -= begin;
  929. scache_size = addr;
  930. c->scache.linesz = 16 << ((config & R4K_CONF_SB) >> 22);
  931. c->scache.ways = 1;
  932. c->dcache.waybit = 0; /* does not matter */
  933. return 1;
  934. }
  935. typedef int (*probe_func_t)(unsigned long);
  936. extern int r5k_sc_init(void);
  937. extern int rm7k_sc_init(void);
  938. static void __init setup_scache(void)
  939. {
  940. struct cpuinfo_mips *c = &current_cpu_data;
  941. unsigned int config = read_c0_config();
  942. probe_func_t probe_scache_kseg1;
  943. int sc_present = 0;
  944. /*
  945. * Do the probing thing on R4000SC and R4400SC processors. Other
  946. * processors don't have a S-cache that would be relevant to the
  947. * Linux memory managment.
  948. */
  949. switch (c->cputype) {
  950. case CPU_R4000SC:
  951. case CPU_R4000MC:
  952. case CPU_R4400SC:
  953. case CPU_R4400MC:
  954. probe_scache_kseg1 = (probe_func_t) (CKSEG1ADDR(&probe_scache));
  955. sc_present = probe_scache_kseg1(config);
  956. if (sc_present)
  957. c->options |= MIPS_CPU_CACHE_CDEX_S;
  958. break;
  959. case CPU_R10000:
  960. case CPU_R12000:
  961. scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
  962. c->scache.linesz = 64 << ((config >> 13) & 1);
  963. c->scache.ways = 2;
  964. c->scache.waybit= 0;
  965. sc_present = 1;
  966. break;
  967. case CPU_R5000:
  968. case CPU_NEVADA:
  969. #ifdef CONFIG_R5000_CPU_SCACHE
  970. r5k_sc_init();
  971. #endif
  972. return;
  973. case CPU_RM7000:
  974. case CPU_RM9000:
  975. #ifdef CONFIG_RM7000_CPU_SCACHE
  976. rm7k_sc_init();
  977. #endif
  978. return;
  979. default:
  980. sc_present = 0;
  981. }
  982. if (!sc_present)
  983. return;
  984. if ((c->isa_level == MIPS_CPU_ISA_M32 ||
  985. c->isa_level == MIPS_CPU_ISA_M64) &&
  986. !(c->scache.flags & MIPS_CACHE_NOT_PRESENT))
  987. panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
  988. /* compute a couple of other cache variables */
  989. c->scache.waysize = scache_size / c->scache.ways;
  990. c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
  991. printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
  992. scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
  993. c->options |= MIPS_CPU_SUBSET_CACHES;
  994. }
  995. static inline void coherency_setup(void)
  996. {
  997. change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
  998. /*
  999. * c0_status.cu=0 specifies that updates by the sc instruction use
  1000. * the coherency mode specified by the TLB; 1 means cachable
  1001. * coherent update on write will be used. Not all processors have
  1002. * this bit and; some wire it to zero, others like Toshiba had the
  1003. * silly idea of putting something else there ...
  1004. */
  1005. switch (current_cpu_data.cputype) {
  1006. case CPU_R4000PC:
  1007. case CPU_R4000SC:
  1008. case CPU_R4000MC:
  1009. case CPU_R4400PC:
  1010. case CPU_R4400SC:
  1011. case CPU_R4400MC:
  1012. clear_c0_config(CONF_CU);
  1013. break;
  1014. }
  1015. }
  1016. void __init ld_mmu_r4xx0(void)
  1017. {
  1018. extern void build_clear_page(void);
  1019. extern void build_copy_page(void);
  1020. extern char except_vec2_generic;
  1021. struct cpuinfo_mips *c = &current_cpu_data;
  1022. /* Default cache error handler for R4000 and R5000 family */
  1023. memcpy((void *)(CAC_BASE + 0x100), &except_vec2_generic, 0x80);
  1024. memcpy((void *)(UNCAC_BASE + 0x100), &except_vec2_generic, 0x80);
  1025. probe_pcache();
  1026. setup_scache();
  1027. r4k_blast_dcache_page_setup();
  1028. r4k_blast_dcache_page_indexed_setup();
  1029. r4k_blast_dcache_setup();
  1030. r4k_blast_icache_page_setup();
  1031. r4k_blast_icache_page_indexed_setup();
  1032. r4k_blast_icache_setup();
  1033. r4k_blast_scache_page_setup();
  1034. r4k_blast_scache_page_indexed_setup();
  1035. r4k_blast_scache_setup();
  1036. /*
  1037. * Some MIPS32 and MIPS64 processors have physically indexed caches.
  1038. * This code supports virtually indexed processors and will be
  1039. * unnecessarily inefficient on physically indexed processors.
  1040. */
  1041. shm_align_mask = max_t( unsigned long,
  1042. c->dcache.sets * c->dcache.linesz - 1,
  1043. PAGE_SIZE - 1);
  1044. flush_cache_all = r4k_flush_cache_all;
  1045. __flush_cache_all = r4k___flush_cache_all;
  1046. flush_cache_mm = r4k_flush_cache_mm;
  1047. flush_cache_page = r4k_flush_cache_page;
  1048. flush_icache_page = r4k_flush_icache_page;
  1049. flush_cache_range = r4k_flush_cache_range;
  1050. flush_cache_sigtramp = r4k_flush_cache_sigtramp;
  1051. flush_icache_all = r4k_flush_icache_all;
  1052. flush_data_cache_page = r4k_flush_data_cache_page;
  1053. flush_icache_range = r4k_flush_icache_range;
  1054. #ifdef CONFIG_DMA_NONCOHERENT
  1055. _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
  1056. _dma_cache_wback = r4k_dma_cache_wback_inv;
  1057. _dma_cache_inv = r4k_dma_cache_inv;
  1058. #endif
  1059. __flush_cache_all();
  1060. coherency_setup();
  1061. build_clear_page();
  1062. build_copy_page();
  1063. }