c-r4k.c 33 KB

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