c-r4k.c 34 KB

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