c-r4k.c 34 KB

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