c-r4k.c 32 KB

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