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/sections.h>
  26. #include <asm/system.h>
  27. #include <asm/mmu_context.h>
  28. #include <asm/war.h>
  29. #include <asm/cacheflush.h> /* for run_uncached() */
  30. /*
  31. * Special Variant of smp_call_function for use by cache functions:
  32. *
  33. * o No return value
  34. * o collapses to normal function call on UP kernels
  35. * o collapses to normal function call on systems with a single shared
  36. * primary cache.
  37. */
  38. static inline void r4k_on_each_cpu(void (*func) (void *info), void *info,
  39. int retry, int wait)
  40. {
  41. preempt_disable();
  42. #if !defined(CONFIG_MIPS_MT_SMP) && !defined(CONFIG_MIPS_MT_SMTC)
  43. smp_call_function(func, info, retry, wait);
  44. #endif
  45. func(info);
  46. preempt_enable();
  47. }
  48. /*
  49. * Must die.
  50. */
  51. static unsigned long icache_size __read_mostly;
  52. static unsigned long dcache_size __read_mostly;
  53. static unsigned long scache_size __read_mostly;
  54. /*
  55. * Dummy cache handling routines for machines without boardcaches
  56. */
  57. static void cache_noop(void) {}
  58. static struct bcache_ops no_sc_ops = {
  59. .bc_enable = (void *)cache_noop,
  60. .bc_disable = (void *)cache_noop,
  61. .bc_wback_inv = (void *)cache_noop,
  62. .bc_inv = (void *)cache_noop
  63. };
  64. struct bcache_ops *bcops = &no_sc_ops;
  65. #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
  66. #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
  67. #define R4600_HIT_CACHEOP_WAR_IMPL \
  68. do { \
  69. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x()) \
  70. *(volatile unsigned long *)CKSEG1; \
  71. if (R4600_V1_HIT_CACHEOP_WAR) \
  72. __asm__ __volatile__("nop;nop;nop;nop"); \
  73. } while (0)
  74. static void (*r4k_blast_dcache_page)(unsigned long addr);
  75. static inline void r4k_blast_dcache_page_dc32(unsigned long addr)
  76. {
  77. R4600_HIT_CACHEOP_WAR_IMPL;
  78. blast_dcache32_page(addr);
  79. }
  80. static void __init r4k_blast_dcache_page_setup(void)
  81. {
  82. unsigned long dc_lsize = cpu_dcache_line_size();
  83. if (dc_lsize == 0)
  84. r4k_blast_dcache_page = (void *)cache_noop;
  85. else if (dc_lsize == 16)
  86. r4k_blast_dcache_page = blast_dcache16_page;
  87. else if (dc_lsize == 32)
  88. r4k_blast_dcache_page = r4k_blast_dcache_page_dc32;
  89. }
  90. static void (* r4k_blast_dcache_page_indexed)(unsigned long addr);
  91. static void __init r4k_blast_dcache_page_indexed_setup(void)
  92. {
  93. unsigned long dc_lsize = cpu_dcache_line_size();
  94. if (dc_lsize == 0)
  95. r4k_blast_dcache_page_indexed = (void *)cache_noop;
  96. else if (dc_lsize == 16)
  97. r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed;
  98. else if (dc_lsize == 32)
  99. r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed;
  100. }
  101. static void (* r4k_blast_dcache)(void);
  102. static void __init r4k_blast_dcache_setup(void)
  103. {
  104. unsigned long dc_lsize = cpu_dcache_line_size();
  105. if (dc_lsize == 0)
  106. r4k_blast_dcache = (void *)cache_noop;
  107. else if (dc_lsize == 16)
  108. r4k_blast_dcache = blast_dcache16;
  109. else if (dc_lsize == 32)
  110. r4k_blast_dcache = blast_dcache32;
  111. }
  112. /* force code alignment (used for TX49XX_ICACHE_INDEX_INV_WAR) */
  113. #define JUMP_TO_ALIGN(order) \
  114. __asm__ __volatile__( \
  115. "b\t1f\n\t" \
  116. ".align\t" #order "\n\t" \
  117. "1:\n\t" \
  118. )
  119. #define CACHE32_UNROLL32_ALIGN JUMP_TO_ALIGN(10) /* 32 * 32 = 1024 */
  120. #define CACHE32_UNROLL32_ALIGN2 JUMP_TO_ALIGN(11)
  121. static inline void blast_r4600_v1_icache32(void)
  122. {
  123. unsigned long flags;
  124. local_irq_save(flags);
  125. blast_icache32();
  126. local_irq_restore(flags);
  127. }
  128. static inline void tx49_blast_icache32(void)
  129. {
  130. unsigned long start = INDEX_BASE;
  131. unsigned long end = start + current_cpu_data.icache.waysize;
  132. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  133. unsigned long ws_end = current_cpu_data.icache.ways <<
  134. current_cpu_data.icache.waybit;
  135. unsigned long ws, addr;
  136. CACHE32_UNROLL32_ALIGN2;
  137. /* I'm in even chunk. blast odd chunks */
  138. for (ws = 0; ws < ws_end; ws += ws_inc)
  139. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  140. cache32_unroll32(addr|ws,Index_Invalidate_I);
  141. CACHE32_UNROLL32_ALIGN;
  142. /* I'm in odd chunk. blast even chunks */
  143. for (ws = 0; ws < ws_end; ws += ws_inc)
  144. for (addr = start; addr < end; addr += 0x400 * 2)
  145. cache32_unroll32(addr|ws,Index_Invalidate_I);
  146. }
  147. static inline void blast_icache32_r4600_v1_page_indexed(unsigned long page)
  148. {
  149. unsigned long flags;
  150. local_irq_save(flags);
  151. blast_icache32_page_indexed(page);
  152. local_irq_restore(flags);
  153. }
  154. static inline void tx49_blast_icache32_page_indexed(unsigned long page)
  155. {
  156. unsigned long indexmask = current_cpu_data.icache.waysize - 1;
  157. unsigned long start = INDEX_BASE + (page & indexmask);
  158. unsigned long end = start + PAGE_SIZE;
  159. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  160. unsigned long ws_end = current_cpu_data.icache.ways <<
  161. current_cpu_data.icache.waybit;
  162. unsigned long ws, addr;
  163. CACHE32_UNROLL32_ALIGN2;
  164. /* I'm in even chunk. blast odd chunks */
  165. for (ws = 0; ws < ws_end; ws += ws_inc)
  166. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  167. cache32_unroll32(addr|ws,Index_Invalidate_I);
  168. CACHE32_UNROLL32_ALIGN;
  169. /* I'm in odd chunk. blast even chunks */
  170. for (ws = 0; ws < ws_end; ws += ws_inc)
  171. for (addr = start; addr < end; addr += 0x400 * 2)
  172. cache32_unroll32(addr|ws,Index_Invalidate_I);
  173. }
  174. static void (* r4k_blast_icache_page)(unsigned long addr);
  175. static void __init r4k_blast_icache_page_setup(void)
  176. {
  177. unsigned long ic_lsize = cpu_icache_line_size();
  178. if (ic_lsize == 0)
  179. r4k_blast_icache_page = (void *)cache_noop;
  180. else if (ic_lsize == 16)
  181. r4k_blast_icache_page = blast_icache16_page;
  182. else if (ic_lsize == 32)
  183. r4k_blast_icache_page = blast_icache32_page;
  184. else if (ic_lsize == 64)
  185. r4k_blast_icache_page = blast_icache64_page;
  186. }
  187. static void (* r4k_blast_icache_page_indexed)(unsigned long addr);
  188. static void __init r4k_blast_icache_page_indexed_setup(void)
  189. {
  190. unsigned long ic_lsize = cpu_icache_line_size();
  191. if (ic_lsize == 0)
  192. r4k_blast_icache_page_indexed = (void *)cache_noop;
  193. else if (ic_lsize == 16)
  194. r4k_blast_icache_page_indexed = blast_icache16_page_indexed;
  195. else if (ic_lsize == 32) {
  196. if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x())
  197. r4k_blast_icache_page_indexed =
  198. blast_icache32_r4600_v1_page_indexed;
  199. else if (TX49XX_ICACHE_INDEX_INV_WAR)
  200. r4k_blast_icache_page_indexed =
  201. tx49_blast_icache32_page_indexed;
  202. else
  203. r4k_blast_icache_page_indexed =
  204. blast_icache32_page_indexed;
  205. } else if (ic_lsize == 64)
  206. r4k_blast_icache_page_indexed = blast_icache64_page_indexed;
  207. }
  208. static void (* r4k_blast_icache)(void);
  209. static void __init r4k_blast_icache_setup(void)
  210. {
  211. unsigned long ic_lsize = cpu_icache_line_size();
  212. if (ic_lsize == 0)
  213. r4k_blast_icache = (void *)cache_noop;
  214. else if (ic_lsize == 16)
  215. r4k_blast_icache = blast_icache16;
  216. else if (ic_lsize == 32) {
  217. if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x())
  218. r4k_blast_icache = blast_r4600_v1_icache32;
  219. else if (TX49XX_ICACHE_INDEX_INV_WAR)
  220. r4k_blast_icache = tx49_blast_icache32;
  221. else
  222. r4k_blast_icache = blast_icache32;
  223. } else if (ic_lsize == 64)
  224. r4k_blast_icache = blast_icache64;
  225. }
  226. static void (* r4k_blast_scache_page)(unsigned long addr);
  227. static void __init r4k_blast_scache_page_setup(void)
  228. {
  229. unsigned long sc_lsize = cpu_scache_line_size();
  230. if (scache_size == 0)
  231. r4k_blast_scache_page = (void *)cache_noop;
  232. else if (sc_lsize == 16)
  233. r4k_blast_scache_page = blast_scache16_page;
  234. else if (sc_lsize == 32)
  235. r4k_blast_scache_page = blast_scache32_page;
  236. else if (sc_lsize == 64)
  237. r4k_blast_scache_page = blast_scache64_page;
  238. else if (sc_lsize == 128)
  239. r4k_blast_scache_page = blast_scache128_page;
  240. }
  241. static void (* r4k_blast_scache_page_indexed)(unsigned long addr);
  242. static void __init r4k_blast_scache_page_indexed_setup(void)
  243. {
  244. unsigned long sc_lsize = cpu_scache_line_size();
  245. if (scache_size == 0)
  246. r4k_blast_scache_page_indexed = (void *)cache_noop;
  247. else if (sc_lsize == 16)
  248. r4k_blast_scache_page_indexed = blast_scache16_page_indexed;
  249. else if (sc_lsize == 32)
  250. r4k_blast_scache_page_indexed = blast_scache32_page_indexed;
  251. else if (sc_lsize == 64)
  252. r4k_blast_scache_page_indexed = blast_scache64_page_indexed;
  253. else if (sc_lsize == 128)
  254. r4k_blast_scache_page_indexed = blast_scache128_page_indexed;
  255. }
  256. static void (* r4k_blast_scache)(void);
  257. static void __init r4k_blast_scache_setup(void)
  258. {
  259. unsigned long sc_lsize = cpu_scache_line_size();
  260. if (scache_size == 0)
  261. r4k_blast_scache = (void *)cache_noop;
  262. else if (sc_lsize == 16)
  263. r4k_blast_scache = blast_scache16;
  264. else if (sc_lsize == 32)
  265. r4k_blast_scache = blast_scache32;
  266. else if (sc_lsize == 64)
  267. r4k_blast_scache = blast_scache64;
  268. else if (sc_lsize == 128)
  269. r4k_blast_scache = blast_scache128;
  270. }
  271. /*
  272. * This is former mm's flush_cache_all() which really should be
  273. * flush_cache_vunmap these days ...
  274. */
  275. static inline void local_r4k_flush_cache_all(void * args)
  276. {
  277. r4k_blast_dcache();
  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. #if defined(CONFIG_CPU_LOONGSON2)
  288. r4k_blast_scache();
  289. return;
  290. #endif
  291. r4k_blast_dcache();
  292. r4k_blast_icache();
  293. switch (current_cpu_data.cputype) {
  294. case CPU_R4000SC:
  295. case CPU_R4000MC:
  296. case CPU_R4400SC:
  297. case CPU_R4400MC:
  298. case CPU_R10000:
  299. case CPU_R12000:
  300. case CPU_R14000:
  301. r4k_blast_scache();
  302. }
  303. }
  304. static void r4k___flush_cache_all(void)
  305. {
  306. r4k_on_each_cpu(local_r4k___flush_cache_all, NULL, 1, 1);
  307. }
  308. static inline void local_r4k_flush_cache_range(void * args)
  309. {
  310. struct vm_area_struct *vma = args;
  311. if (!(cpu_context(smp_processor_id(), vma->vm_mm)))
  312. return;
  313. r4k_blast_dcache();
  314. }
  315. static void r4k_flush_cache_range(struct vm_area_struct *vma,
  316. unsigned long start, unsigned long end)
  317. {
  318. if (!cpu_has_dc_aliases)
  319. return;
  320. r4k_on_each_cpu(local_r4k_flush_cache_range, vma, 1, 1);
  321. }
  322. static inline void local_r4k_flush_cache_mm(void * args)
  323. {
  324. struct mm_struct *mm = args;
  325. if (!cpu_context(smp_processor_id(), mm))
  326. return;
  327. /*
  328. * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we
  329. * only flush the primary caches but R10000 and R12000 behave sane ...
  330. * R4000SC and R4400SC indexed S-cache ops also invalidate primary
  331. * caches, so we can bail out early.
  332. */
  333. if (current_cpu_data.cputype == CPU_R4000SC ||
  334. current_cpu_data.cputype == CPU_R4000MC ||
  335. current_cpu_data.cputype == CPU_R4400SC ||
  336. current_cpu_data.cputype == CPU_R4400MC) {
  337. r4k_blast_scache();
  338. return;
  339. }
  340. r4k_blast_dcache();
  341. }
  342. static void r4k_flush_cache_mm(struct mm_struct *mm)
  343. {
  344. if (!cpu_has_dc_aliases)
  345. return;
  346. r4k_on_each_cpu(local_r4k_flush_cache_mm, mm, 1, 1);
  347. }
  348. struct flush_cache_page_args {
  349. struct vm_area_struct *vma;
  350. unsigned long addr;
  351. unsigned long pfn;
  352. };
  353. static inline void local_r4k_flush_cache_page(void *args)
  354. {
  355. struct flush_cache_page_args *fcp_args = args;
  356. struct vm_area_struct *vma = fcp_args->vma;
  357. unsigned long addr = fcp_args->addr;
  358. unsigned long paddr = fcp_args->pfn << PAGE_SHIFT;
  359. int exec = vma->vm_flags & VM_EXEC;
  360. struct mm_struct *mm = vma->vm_mm;
  361. pgd_t *pgdp;
  362. pud_t *pudp;
  363. pmd_t *pmdp;
  364. pte_t *ptep;
  365. /*
  366. * If ownes no valid ASID yet, cannot possibly have gotten
  367. * this page into the cache.
  368. */
  369. if (cpu_context(smp_processor_id(), mm) == 0)
  370. return;
  371. addr &= PAGE_MASK;
  372. pgdp = pgd_offset(mm, addr);
  373. pudp = pud_offset(pgdp, addr);
  374. pmdp = pmd_offset(pudp, addr);
  375. ptep = pte_offset(pmdp, addr);
  376. /*
  377. * If the page isn't marked valid, the page cannot possibly be
  378. * in the cache.
  379. */
  380. if (!(pte_val(*ptep) & _PAGE_PRESENT))
  381. return;
  382. /*
  383. * Doing flushes for another ASID than the current one is
  384. * too difficult since stupid R4k caches do a TLB translation
  385. * for every cache flush operation. So we do indexed flushes
  386. * in that case, which doesn't overly flush the cache too much.
  387. */
  388. if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) {
  389. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  390. r4k_blast_dcache_page(addr);
  391. if (exec && !cpu_icache_snoops_remote_store)
  392. r4k_blast_scache_page(addr);
  393. }
  394. if (exec)
  395. r4k_blast_icache_page(addr);
  396. return;
  397. }
  398. /*
  399. * Do indexed flush, too much work to get the (possible) TLB refills
  400. * to work correctly.
  401. */
  402. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  403. r4k_blast_dcache_page_indexed(cpu_has_pindexed_dcache ?
  404. paddr : addr);
  405. if (exec && !cpu_icache_snoops_remote_store) {
  406. r4k_blast_scache_page_indexed(paddr);
  407. }
  408. }
  409. if (exec) {
  410. if (cpu_has_vtag_icache && mm == current->active_mm) {
  411. int cpu = smp_processor_id();
  412. if (cpu_context(cpu, mm) != 0)
  413. drop_mmu_context(mm, cpu);
  414. } else
  415. r4k_blast_icache_page_indexed(addr);
  416. }
  417. }
  418. static void r4k_flush_cache_page(struct vm_area_struct *vma,
  419. unsigned long addr, unsigned long pfn)
  420. {
  421. struct flush_cache_page_args args;
  422. args.vma = vma;
  423. args.addr = addr;
  424. args.pfn = pfn;
  425. r4k_on_each_cpu(local_r4k_flush_cache_page, &args, 1, 1);
  426. }
  427. static inline void local_r4k_flush_data_cache_page(void * addr)
  428. {
  429. r4k_blast_dcache_page((unsigned long) addr);
  430. }
  431. static void r4k_flush_data_cache_page(unsigned long addr)
  432. {
  433. r4k_on_each_cpu(local_r4k_flush_data_cache_page, (void *) addr, 1, 1);
  434. }
  435. struct flush_icache_range_args {
  436. unsigned long start;
  437. unsigned long end;
  438. };
  439. static inline void local_r4k_flush_icache_range(void *args)
  440. {
  441. struct flush_icache_range_args *fir_args = args;
  442. unsigned long start = fir_args->start;
  443. unsigned long end = fir_args->end;
  444. if (!cpu_has_ic_fills_f_dc) {
  445. if (end - start >= dcache_size) {
  446. r4k_blast_dcache();
  447. } else {
  448. R4600_HIT_CACHEOP_WAR_IMPL;
  449. protected_blast_dcache_range(start, end);
  450. }
  451. if (!cpu_icache_snoops_remote_store && scache_size) {
  452. if (end - start > scache_size)
  453. r4k_blast_scache();
  454. else
  455. protected_blast_scache_range(start, end);
  456. }
  457. }
  458. if (end - start > icache_size)
  459. r4k_blast_icache();
  460. else
  461. protected_blast_icache_range(start, end);
  462. }
  463. static void r4k_flush_icache_range(unsigned long start, unsigned long end)
  464. {
  465. struct flush_icache_range_args args;
  466. args.start = start;
  467. args.end = end;
  468. r4k_on_each_cpu(local_r4k_flush_icache_range, &args, 1, 1);
  469. instruction_hazard();
  470. }
  471. #ifdef CONFIG_DMA_NONCOHERENT
  472. static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
  473. {
  474. /* Catch bad driver code */
  475. BUG_ON(size == 0);
  476. if (cpu_has_inclusive_pcaches) {
  477. if (size >= scache_size)
  478. r4k_blast_scache();
  479. else
  480. blast_scache_range(addr, addr + size);
  481. return;
  482. }
  483. /*
  484. * Either no secondary cache or the available caches don't have the
  485. * subset property so we have to flush the primary caches
  486. * explicitly
  487. */
  488. if (size >= dcache_size) {
  489. r4k_blast_dcache();
  490. } else {
  491. R4600_HIT_CACHEOP_WAR_IMPL;
  492. blast_dcache_range(addr, addr + size);
  493. }
  494. bc_wback_inv(addr, size);
  495. }
  496. static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
  497. {
  498. /* Catch bad driver code */
  499. BUG_ON(size == 0);
  500. if (cpu_has_inclusive_pcaches) {
  501. if (size >= scache_size)
  502. r4k_blast_scache();
  503. else
  504. blast_scache_range(addr, addr + size);
  505. return;
  506. }
  507. if (size >= dcache_size) {
  508. r4k_blast_dcache();
  509. } else {
  510. R4600_HIT_CACHEOP_WAR_IMPL;
  511. blast_dcache_range(addr, addr + size);
  512. }
  513. bc_inv(addr, size);
  514. }
  515. #endif /* CONFIG_DMA_NONCOHERENT */
  516. /*
  517. * While we're protected against bad userland addresses we don't care
  518. * very much about what happens in that case. Usually a segmentation
  519. * fault will dump the process later on anyway ...
  520. */
  521. static void local_r4k_flush_cache_sigtramp(void * arg)
  522. {
  523. unsigned long ic_lsize = cpu_icache_line_size();
  524. unsigned long dc_lsize = cpu_dcache_line_size();
  525. unsigned long sc_lsize = cpu_scache_line_size();
  526. unsigned long addr = (unsigned long) arg;
  527. R4600_HIT_CACHEOP_WAR_IMPL;
  528. if (dc_lsize)
  529. protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
  530. if (!cpu_icache_snoops_remote_store && scache_size)
  531. protected_writeback_scache_line(addr & ~(sc_lsize - 1));
  532. if (ic_lsize)
  533. protected_flush_icache_line(addr & ~(ic_lsize - 1));
  534. if (MIPS4K_ICACHE_REFILL_WAR) {
  535. __asm__ __volatile__ (
  536. ".set push\n\t"
  537. ".set noat\n\t"
  538. ".set mips3\n\t"
  539. #ifdef CONFIG_32BIT
  540. "la $at,1f\n\t"
  541. #endif
  542. #ifdef CONFIG_64BIT
  543. "dla $at,1f\n\t"
  544. #endif
  545. "cache %0,($at)\n\t"
  546. "nop; nop; nop\n"
  547. "1:\n\t"
  548. ".set pop"
  549. :
  550. : "i" (Hit_Invalidate_I));
  551. }
  552. if (MIPS_CACHE_SYNC_WAR)
  553. __asm__ __volatile__ ("sync");
  554. }
  555. static void r4k_flush_cache_sigtramp(unsigned long addr)
  556. {
  557. r4k_on_each_cpu(local_r4k_flush_cache_sigtramp, (void *) addr, 1, 1);
  558. }
  559. static void r4k_flush_icache_all(void)
  560. {
  561. if (cpu_has_vtag_icache)
  562. r4k_blast_icache();
  563. }
  564. static inline void rm7k_erratum31(void)
  565. {
  566. const unsigned long ic_lsize = 32;
  567. unsigned long addr;
  568. /* RM7000 erratum #31. The icache is screwed at startup. */
  569. write_c0_taglo(0);
  570. write_c0_taghi(0);
  571. for (addr = INDEX_BASE; addr <= INDEX_BASE + 4096; addr += ic_lsize) {
  572. __asm__ __volatile__ (
  573. ".set push\n\t"
  574. ".set noreorder\n\t"
  575. ".set mips3\n\t"
  576. "cache\t%1, 0(%0)\n\t"
  577. "cache\t%1, 0x1000(%0)\n\t"
  578. "cache\t%1, 0x2000(%0)\n\t"
  579. "cache\t%1, 0x3000(%0)\n\t"
  580. "cache\t%2, 0(%0)\n\t"
  581. "cache\t%2, 0x1000(%0)\n\t"
  582. "cache\t%2, 0x2000(%0)\n\t"
  583. "cache\t%2, 0x3000(%0)\n\t"
  584. "cache\t%1, 0(%0)\n\t"
  585. "cache\t%1, 0x1000(%0)\n\t"
  586. "cache\t%1, 0x2000(%0)\n\t"
  587. "cache\t%1, 0x3000(%0)\n\t"
  588. ".set pop\n"
  589. :
  590. : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill));
  591. }
  592. }
  593. static char *way_string[] __initdata = { NULL, "direct mapped", "2-way",
  594. "3-way", "4-way", "5-way", "6-way", "7-way", "8-way"
  595. };
  596. static void __init probe_pcache(void)
  597. {
  598. struct cpuinfo_mips *c = &current_cpu_data;
  599. unsigned int config = read_c0_config();
  600. unsigned int prid = read_c0_prid();
  601. unsigned long config1;
  602. unsigned int lsize;
  603. switch (c->cputype) {
  604. case CPU_R4600: /* QED style two way caches? */
  605. case CPU_R4700:
  606. case CPU_R5000:
  607. case CPU_NEVADA:
  608. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  609. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  610. c->icache.ways = 2;
  611. c->icache.waybit = __ffs(icache_size/2);
  612. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  613. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  614. c->dcache.ways = 2;
  615. c->dcache.waybit= __ffs(dcache_size/2);
  616. c->options |= MIPS_CPU_CACHE_CDEX_P;
  617. break;
  618. case CPU_R5432:
  619. case CPU_R5500:
  620. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  621. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  622. c->icache.ways = 2;
  623. c->icache.waybit= 0;
  624. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  625. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  626. c->dcache.ways = 2;
  627. c->dcache.waybit = 0;
  628. c->options |= MIPS_CPU_CACHE_CDEX_P;
  629. break;
  630. case CPU_TX49XX:
  631. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  632. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  633. c->icache.ways = 4;
  634. c->icache.waybit= 0;
  635. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  636. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  637. c->dcache.ways = 4;
  638. c->dcache.waybit = 0;
  639. c->options |= MIPS_CPU_CACHE_CDEX_P;
  640. c->options |= MIPS_CPU_PREFETCH;
  641. break;
  642. case CPU_R4000PC:
  643. case CPU_R4000SC:
  644. case CPU_R4000MC:
  645. case CPU_R4400PC:
  646. case CPU_R4400SC:
  647. case CPU_R4400MC:
  648. case CPU_R4300:
  649. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  650. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  651. c->icache.ways = 1;
  652. c->icache.waybit = 0; /* doesn't matter */
  653. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  654. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  655. c->dcache.ways = 1;
  656. c->dcache.waybit = 0; /* does not matter */
  657. c->options |= MIPS_CPU_CACHE_CDEX_P;
  658. break;
  659. case CPU_R10000:
  660. case CPU_R12000:
  661. case CPU_R14000:
  662. icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
  663. c->icache.linesz = 64;
  664. c->icache.ways = 2;
  665. c->icache.waybit = 0;
  666. dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26));
  667. c->dcache.linesz = 32;
  668. c->dcache.ways = 2;
  669. c->dcache.waybit = 0;
  670. c->options |= MIPS_CPU_PREFETCH;
  671. break;
  672. case CPU_VR4133:
  673. write_c0_config(config & ~VR41_CONF_P4K);
  674. case CPU_VR4131:
  675. /* Workaround for cache instruction bug of VR4131 */
  676. if (c->processor_id == 0x0c80U || c->processor_id == 0x0c81U ||
  677. c->processor_id == 0x0c82U) {
  678. config |= 0x00400000U;
  679. if (c->processor_id == 0x0c80U)
  680. config |= VR41_CONF_BP;
  681. write_c0_config(config);
  682. } else
  683. c->options |= MIPS_CPU_CACHE_CDEX_P;
  684. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  685. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  686. c->icache.ways = 2;
  687. c->icache.waybit = __ffs(icache_size/2);
  688. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  689. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  690. c->dcache.ways = 2;
  691. c->dcache.waybit = __ffs(dcache_size/2);
  692. break;
  693. case CPU_VR41XX:
  694. case CPU_VR4111:
  695. case CPU_VR4121:
  696. case CPU_VR4122:
  697. case CPU_VR4181:
  698. case CPU_VR4181A:
  699. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  700. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  701. c->icache.ways = 1;
  702. c->icache.waybit = 0; /* doesn't matter */
  703. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  704. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  705. c->dcache.ways = 1;
  706. c->dcache.waybit = 0; /* does not matter */
  707. c->options |= MIPS_CPU_CACHE_CDEX_P;
  708. break;
  709. case CPU_RM7000:
  710. rm7k_erratum31();
  711. case CPU_RM9000:
  712. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  713. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  714. c->icache.ways = 4;
  715. c->icache.waybit = __ffs(icache_size / c->icache.ways);
  716. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  717. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  718. c->dcache.ways = 4;
  719. c->dcache.waybit = __ffs(dcache_size / c->dcache.ways);
  720. #if !defined(CONFIG_SMP) || !defined(RM9000_CDEX_SMP_WAR)
  721. c->options |= MIPS_CPU_CACHE_CDEX_P;
  722. #endif
  723. c->options |= MIPS_CPU_PREFETCH;
  724. break;
  725. case CPU_LOONGSON2:
  726. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  727. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  728. if (prid & 0x3)
  729. c->icache.ways = 4;
  730. else
  731. c->icache.ways = 2;
  732. c->icache.waybit = 0;
  733. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  734. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  735. if (prid & 0x3)
  736. c->dcache.ways = 4;
  737. else
  738. c->dcache.ways = 2;
  739. c->dcache.waybit = 0;
  740. break;
  741. default:
  742. if (!(config & MIPS_CONF_M))
  743. panic("Don't know how to probe P-caches on this cpu.");
  744. /*
  745. * So we seem to be a MIPS32 or MIPS64 CPU
  746. * So let's probe the I-cache ...
  747. */
  748. config1 = read_c0_config1();
  749. if ((lsize = ((config1 >> 19) & 7)))
  750. c->icache.linesz = 2 << lsize;
  751. else
  752. c->icache.linesz = lsize;
  753. c->icache.sets = 64 << ((config1 >> 22) & 7);
  754. c->icache.ways = 1 + ((config1 >> 16) & 7);
  755. icache_size = c->icache.sets *
  756. c->icache.ways *
  757. c->icache.linesz;
  758. c->icache.waybit = __ffs(icache_size/c->icache.ways);
  759. if (config & 0x8) /* VI bit */
  760. c->icache.flags |= MIPS_CACHE_VTAG;
  761. /*
  762. * Now probe the MIPS32 / MIPS64 data cache.
  763. */
  764. c->dcache.flags = 0;
  765. if ((lsize = ((config1 >> 10) & 7)))
  766. c->dcache.linesz = 2 << lsize;
  767. else
  768. c->dcache.linesz= lsize;
  769. c->dcache.sets = 64 << ((config1 >> 13) & 7);
  770. c->dcache.ways = 1 + ((config1 >> 7) & 7);
  771. dcache_size = c->dcache.sets *
  772. c->dcache.ways *
  773. c->dcache.linesz;
  774. c->dcache.waybit = __ffs(dcache_size/c->dcache.ways);
  775. c->options |= MIPS_CPU_PREFETCH;
  776. break;
  777. }
  778. /*
  779. * Processor configuration sanity check for the R4000SC erratum
  780. * #5. With page sizes larger than 32kB there is no possibility
  781. * to get a VCE exception anymore so we don't care about this
  782. * misconfiguration. The case is rather theoretical anyway;
  783. * presumably no vendor is shipping his hardware in the "bad"
  784. * configuration.
  785. */
  786. if ((prid & 0xff00) == PRID_IMP_R4000 && (prid & 0xff) < 0x40 &&
  787. !(config & CONF_SC) && c->icache.linesz != 16 &&
  788. PAGE_SIZE <= 0x8000)
  789. panic("Improper R4000SC processor configuration detected");
  790. /* compute a couple of other cache variables */
  791. c->icache.waysize = icache_size / c->icache.ways;
  792. c->dcache.waysize = dcache_size / c->dcache.ways;
  793. c->icache.sets = c->icache.linesz ?
  794. icache_size / (c->icache.linesz * c->icache.ways) : 0;
  795. c->dcache.sets = c->dcache.linesz ?
  796. dcache_size / (c->dcache.linesz * c->dcache.ways) : 0;
  797. /*
  798. * R10000 and R12000 P-caches are odd in a positive way. They're 32kB
  799. * 2-way virtually indexed so normally would suffer from aliases. So
  800. * normally they'd suffer from aliases but magic in the hardware deals
  801. * with that for us so we don't need to take care ourselves.
  802. */
  803. switch (c->cputype) {
  804. case CPU_20KC:
  805. case CPU_25KF:
  806. c->dcache.flags |= MIPS_CACHE_PINDEX;
  807. case CPU_R10000:
  808. case CPU_R12000:
  809. case CPU_R14000:
  810. case CPU_SB1:
  811. break;
  812. case CPU_24K:
  813. case CPU_34K:
  814. case CPU_74K:
  815. if ((read_c0_config7() & (1 << 16))) {
  816. /* effectively physically indexed dcache,
  817. thus no virtual aliases. */
  818. c->dcache.flags |= MIPS_CACHE_PINDEX;
  819. break;
  820. }
  821. default:
  822. if (c->dcache.waysize > PAGE_SIZE)
  823. c->dcache.flags |= MIPS_CACHE_ALIASES;
  824. }
  825. switch (c->cputype) {
  826. case CPU_20KC:
  827. /*
  828. * Some older 20Kc chips doesn't have the 'VI' bit in
  829. * the config register.
  830. */
  831. c->icache.flags |= MIPS_CACHE_VTAG;
  832. break;
  833. case CPU_AU1000:
  834. case CPU_AU1500:
  835. case CPU_AU1100:
  836. case CPU_AU1550:
  837. case CPU_AU1200:
  838. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  839. break;
  840. }
  841. #ifdef CONFIG_CPU_LOONGSON2
  842. /*
  843. * LOONGSON2 has 4 way icache, but when using indexed cache op,
  844. * one op will act on all 4 ways
  845. */
  846. c->icache.ways = 1;
  847. #endif
  848. printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
  849. icache_size >> 10,
  850. cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
  851. way_string[c->icache.ways], c->icache.linesz);
  852. printk("Primary data cache %ldkB, %s, linesize %d bytes.\n",
  853. dcache_size >> 10, way_string[c->dcache.ways], c->dcache.linesz);
  854. }
  855. /*
  856. * If you even _breathe_ on this function, look at the gcc output and make sure
  857. * it does not pop things on and off the stack for the cache sizing loop that
  858. * executes in KSEG1 space or else you will crash and burn badly. You have
  859. * been warned.
  860. */
  861. static int __init probe_scache(void)
  862. {
  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. }