c-r4k.c 33 KB

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