c-r4k.c 34 KB

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