c-r4k.c 32 KB

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