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