c-r4k.c 34 KB

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