c-r4k.c 35 KB

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