c-r4k.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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/kernel.h>
  12. #include <linux/linkage.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/bitops.h>
  16. #include <asm/bcache.h>
  17. #include <asm/bootinfo.h>
  18. #include <asm/cache.h>
  19. #include <asm/cacheops.h>
  20. #include <asm/cpu.h>
  21. #include <asm/cpu-features.h>
  22. #include <asm/io.h>
  23. #include <asm/page.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/r4kcache.h>
  26. #include <asm/sections.h>
  27. #include <asm/system.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/war.h>
  30. #include <asm/cacheflush.h> /* for run_uncached() */
  31. /*
  32. * Special Variant of smp_call_function for use by cache functions:
  33. *
  34. * o No return value
  35. * o collapses to normal function call on UP kernels
  36. * o collapses to normal function call on systems with a single shared
  37. * primary cache.
  38. */
  39. static inline void r4k_on_each_cpu(void (*func) (void *info), void *info,
  40. int retry, int wait)
  41. {
  42. preempt_disable();
  43. #if !defined(CONFIG_MIPS_MT_SMP) && !defined(CONFIG_MIPS_MT_SMTC)
  44. smp_call_function(func, info, retry, wait);
  45. #endif
  46. func(info);
  47. preempt_enable();
  48. }
  49. /*
  50. * Must die.
  51. */
  52. static unsigned long icache_size __read_mostly;
  53. static unsigned long dcache_size __read_mostly;
  54. static unsigned long scache_size __read_mostly;
  55. /*
  56. * Dummy cache handling routines for machines without boardcaches
  57. */
  58. static void cache_noop(void) {}
  59. static struct bcache_ops no_sc_ops = {
  60. .bc_enable = (void *)cache_noop,
  61. .bc_disable = (void *)cache_noop,
  62. .bc_wback_inv = (void *)cache_noop,
  63. .bc_inv = (void *)cache_noop
  64. };
  65. struct bcache_ops *bcops = &no_sc_ops;
  66. #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
  67. #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
  68. #define R4600_HIT_CACHEOP_WAR_IMPL \
  69. do { \
  70. if (R4600_V2_HIT_CACHEOP_WAR && cpu_is_r4600_v2_x()) \
  71. *(volatile unsigned long *)CKSEG1; \
  72. if (R4600_V1_HIT_CACHEOP_WAR) \
  73. __asm__ __volatile__("nop;nop;nop;nop"); \
  74. } while (0)
  75. static void (*r4k_blast_dcache_page)(unsigned long addr);
  76. static inline void r4k_blast_dcache_page_dc32(unsigned long addr)
  77. {
  78. R4600_HIT_CACHEOP_WAR_IMPL;
  79. blast_dcache32_page(addr);
  80. }
  81. static void __init r4k_blast_dcache_page_setup(void)
  82. {
  83. unsigned long dc_lsize = cpu_dcache_line_size();
  84. if (dc_lsize == 0)
  85. r4k_blast_dcache_page = (void *)cache_noop;
  86. else if (dc_lsize == 16)
  87. r4k_blast_dcache_page = blast_dcache16_page;
  88. else if (dc_lsize == 32)
  89. r4k_blast_dcache_page = r4k_blast_dcache_page_dc32;
  90. }
  91. static void (* r4k_blast_dcache_page_indexed)(unsigned long addr);
  92. static void __init r4k_blast_dcache_page_indexed_setup(void)
  93. {
  94. unsigned long dc_lsize = cpu_dcache_line_size();
  95. if (dc_lsize == 0)
  96. r4k_blast_dcache_page_indexed = (void *)cache_noop;
  97. else if (dc_lsize == 16)
  98. r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed;
  99. else if (dc_lsize == 32)
  100. r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed;
  101. }
  102. static void (* r4k_blast_dcache)(void);
  103. static void __init r4k_blast_dcache_setup(void)
  104. {
  105. unsigned long dc_lsize = cpu_dcache_line_size();
  106. if (dc_lsize == 0)
  107. r4k_blast_dcache = (void *)cache_noop;
  108. else if (dc_lsize == 16)
  109. r4k_blast_dcache = blast_dcache16;
  110. else if (dc_lsize == 32)
  111. r4k_blast_dcache = blast_dcache32;
  112. }
  113. /* force code alignment (used for TX49XX_ICACHE_INDEX_INV_WAR) */
  114. #define JUMP_TO_ALIGN(order) \
  115. __asm__ __volatile__( \
  116. "b\t1f\n\t" \
  117. ".align\t" #order "\n\t" \
  118. "1:\n\t" \
  119. )
  120. #define CACHE32_UNROLL32_ALIGN JUMP_TO_ALIGN(10) /* 32 * 32 = 1024 */
  121. #define CACHE32_UNROLL32_ALIGN2 JUMP_TO_ALIGN(11)
  122. static inline void blast_r4600_v1_icache32(void)
  123. {
  124. unsigned long flags;
  125. local_irq_save(flags);
  126. blast_icache32();
  127. local_irq_restore(flags);
  128. }
  129. static inline void tx49_blast_icache32(void)
  130. {
  131. unsigned long start = INDEX_BASE;
  132. unsigned long end = start + current_cpu_data.icache.waysize;
  133. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  134. unsigned long ws_end = current_cpu_data.icache.ways <<
  135. current_cpu_data.icache.waybit;
  136. unsigned long ws, addr;
  137. CACHE32_UNROLL32_ALIGN2;
  138. /* I'm in even chunk. blast odd chunks */
  139. for (ws = 0; ws < ws_end; ws += ws_inc)
  140. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  141. cache32_unroll32(addr|ws,Index_Invalidate_I);
  142. CACHE32_UNROLL32_ALIGN;
  143. /* I'm in odd chunk. blast even chunks */
  144. for (ws = 0; ws < ws_end; ws += ws_inc)
  145. for (addr = start; addr < end; addr += 0x400 * 2)
  146. cache32_unroll32(addr|ws,Index_Invalidate_I);
  147. }
  148. static inline void blast_icache32_r4600_v1_page_indexed(unsigned long page)
  149. {
  150. unsigned long flags;
  151. local_irq_save(flags);
  152. blast_icache32_page_indexed(page);
  153. local_irq_restore(flags);
  154. }
  155. static inline void tx49_blast_icache32_page_indexed(unsigned long page)
  156. {
  157. unsigned long indexmask = current_cpu_data.icache.waysize - 1;
  158. unsigned long start = INDEX_BASE + (page & indexmask);
  159. unsigned long end = start + PAGE_SIZE;
  160. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  161. unsigned long ws_end = current_cpu_data.icache.ways <<
  162. current_cpu_data.icache.waybit;
  163. unsigned long ws, addr;
  164. CACHE32_UNROLL32_ALIGN2;
  165. /* I'm in even chunk. blast odd chunks */
  166. for (ws = 0; ws < ws_end; ws += ws_inc)
  167. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  168. cache32_unroll32(addr|ws,Index_Invalidate_I);
  169. CACHE32_UNROLL32_ALIGN;
  170. /* I'm in odd chunk. blast even chunks */
  171. for (ws = 0; ws < ws_end; ws += ws_inc)
  172. for (addr = start; addr < end; addr += 0x400 * 2)
  173. cache32_unroll32(addr|ws,Index_Invalidate_I);
  174. }
  175. static void (* r4k_blast_icache_page)(unsigned long addr);
  176. static void __init r4k_blast_icache_page_setup(void)
  177. {
  178. unsigned long ic_lsize = cpu_icache_line_size();
  179. if (ic_lsize == 0)
  180. r4k_blast_icache_page = (void *)cache_noop;
  181. else if (ic_lsize == 16)
  182. r4k_blast_icache_page = blast_icache16_page;
  183. else if (ic_lsize == 32)
  184. r4k_blast_icache_page = blast_icache32_page;
  185. else if (ic_lsize == 64)
  186. r4k_blast_icache_page = blast_icache64_page;
  187. }
  188. static void (* r4k_blast_icache_page_indexed)(unsigned long addr);
  189. static void __init r4k_blast_icache_page_indexed_setup(void)
  190. {
  191. unsigned long ic_lsize = cpu_icache_line_size();
  192. if (ic_lsize == 0)
  193. r4k_blast_icache_page_indexed = (void *)cache_noop;
  194. else if (ic_lsize == 16)
  195. r4k_blast_icache_page_indexed = blast_icache16_page_indexed;
  196. else if (ic_lsize == 32) {
  197. if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x())
  198. r4k_blast_icache_page_indexed =
  199. blast_icache32_r4600_v1_page_indexed;
  200. else if (TX49XX_ICACHE_INDEX_INV_WAR)
  201. r4k_blast_icache_page_indexed =
  202. tx49_blast_icache32_page_indexed;
  203. else
  204. r4k_blast_icache_page_indexed =
  205. blast_icache32_page_indexed;
  206. } else if (ic_lsize == 64)
  207. r4k_blast_icache_page_indexed = blast_icache64_page_indexed;
  208. }
  209. static void (* r4k_blast_icache)(void);
  210. static void __init r4k_blast_icache_setup(void)
  211. {
  212. unsigned long ic_lsize = cpu_icache_line_size();
  213. if (ic_lsize == 0)
  214. r4k_blast_icache = (void *)cache_noop;
  215. else if (ic_lsize == 16)
  216. r4k_blast_icache = blast_icache16;
  217. else if (ic_lsize == 32) {
  218. if (R4600_V1_INDEX_ICACHEOP_WAR && cpu_is_r4600_v1_x())
  219. r4k_blast_icache = blast_r4600_v1_icache32;
  220. else if (TX49XX_ICACHE_INDEX_INV_WAR)
  221. r4k_blast_icache = tx49_blast_icache32;
  222. else
  223. r4k_blast_icache = blast_icache32;
  224. } else if (ic_lsize == 64)
  225. r4k_blast_icache = blast_icache64;
  226. }
  227. static void (* r4k_blast_scache_page)(unsigned long addr);
  228. static void __init r4k_blast_scache_page_setup(void)
  229. {
  230. unsigned long sc_lsize = cpu_scache_line_size();
  231. if (scache_size == 0)
  232. r4k_blast_scache_page = (void *)cache_noop;
  233. else if (sc_lsize == 16)
  234. r4k_blast_scache_page = blast_scache16_page;
  235. else if (sc_lsize == 32)
  236. r4k_blast_scache_page = blast_scache32_page;
  237. else if (sc_lsize == 64)
  238. r4k_blast_scache_page = blast_scache64_page;
  239. else if (sc_lsize == 128)
  240. r4k_blast_scache_page = blast_scache128_page;
  241. }
  242. static void (* r4k_blast_scache_page_indexed)(unsigned long addr);
  243. static void __init r4k_blast_scache_page_indexed_setup(void)
  244. {
  245. unsigned long sc_lsize = cpu_scache_line_size();
  246. if (scache_size == 0)
  247. r4k_blast_scache_page_indexed = (void *)cache_noop;
  248. else if (sc_lsize == 16)
  249. r4k_blast_scache_page_indexed = blast_scache16_page_indexed;
  250. else if (sc_lsize == 32)
  251. r4k_blast_scache_page_indexed = blast_scache32_page_indexed;
  252. else if (sc_lsize == 64)
  253. r4k_blast_scache_page_indexed = blast_scache64_page_indexed;
  254. else if (sc_lsize == 128)
  255. r4k_blast_scache_page_indexed = blast_scache128_page_indexed;
  256. }
  257. static void (* r4k_blast_scache)(void);
  258. static void __init r4k_blast_scache_setup(void)
  259. {
  260. unsigned long sc_lsize = cpu_scache_line_size();
  261. if (scache_size == 0)
  262. r4k_blast_scache = (void *)cache_noop;
  263. else if (sc_lsize == 16)
  264. r4k_blast_scache = blast_scache16;
  265. else if (sc_lsize == 32)
  266. r4k_blast_scache = blast_scache32;
  267. else if (sc_lsize == 64)
  268. r4k_blast_scache = blast_scache64;
  269. else if (sc_lsize == 128)
  270. r4k_blast_scache = blast_scache128;
  271. }
  272. /*
  273. * This is former mm's flush_cache_all() which really should be
  274. * flush_cache_vunmap these days ...
  275. */
  276. static inline void local_r4k_flush_cache_all(void * args)
  277. {
  278. r4k_blast_dcache();
  279. }
  280. static void r4k_flush_cache_all(void)
  281. {
  282. if (!cpu_has_dc_aliases)
  283. return;
  284. r4k_on_each_cpu(local_r4k_flush_cache_all, NULL, 1, 1);
  285. }
  286. static inline void local_r4k___flush_cache_all(void * args)
  287. {
  288. #if defined(CONFIG_CPU_LOONGSON2)
  289. r4k_blast_scache();
  290. return;
  291. #endif
  292. r4k_blast_dcache();
  293. r4k_blast_icache();
  294. switch (current_cpu_data.cputype) {
  295. case CPU_R4000SC:
  296. case CPU_R4000MC:
  297. case CPU_R4400SC:
  298. case CPU_R4400MC:
  299. case CPU_R10000:
  300. case CPU_R12000:
  301. case CPU_R14000:
  302. r4k_blast_scache();
  303. }
  304. }
  305. static void r4k___flush_cache_all(void)
  306. {
  307. r4k_on_each_cpu(local_r4k___flush_cache_all, NULL, 1, 1);
  308. }
  309. static inline void local_r4k_flush_cache_range(void * args)
  310. {
  311. struct vm_area_struct *vma = args;
  312. if (!(cpu_context(smp_processor_id(), 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 (!cpu_context(smp_processor_id(), 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_data.cputype == CPU_R4000SC ||
  335. current_cpu_data.cputype == CPU_R4000MC ||
  336. current_cpu_data.cputype == CPU_R4400SC ||
  337. current_cpu_data.cputype == 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. unsigned long paddr = fcp_args->pfn << PAGE_SHIFT;
  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. /*
  367. * If ownes no valid ASID yet, cannot possibly have gotten
  368. * this page into the cache.
  369. */
  370. if (cpu_context(smp_processor_id(), mm) == 0)
  371. return;
  372. addr &= PAGE_MASK;
  373. pgdp = pgd_offset(mm, addr);
  374. pudp = pud_offset(pgdp, addr);
  375. pmdp = pmd_offset(pudp, addr);
  376. ptep = pte_offset(pmdp, addr);
  377. /*
  378. * If the page isn't marked valid, the page cannot possibly be
  379. * in the cache.
  380. */
  381. if (!(pte_val(*ptep) & _PAGE_PRESENT))
  382. return;
  383. /*
  384. * Doing flushes for another ASID than the current one is
  385. * too difficult since stupid R4k caches do a TLB translation
  386. * for every cache flush operation. So we do indexed flushes
  387. * in that case, which doesn't overly flush the cache too much.
  388. */
  389. if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) {
  390. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  391. r4k_blast_dcache_page(addr);
  392. if (exec && !cpu_icache_snoops_remote_store)
  393. r4k_blast_scache_page(addr);
  394. }
  395. if (exec)
  396. r4k_blast_icache_page(addr);
  397. return;
  398. }
  399. /*
  400. * Do indexed flush, too much work to get the (possible) TLB refills
  401. * to work correctly.
  402. */
  403. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  404. r4k_blast_dcache_page_indexed(cpu_has_pindexed_dcache ?
  405. paddr : addr);
  406. if (exec && !cpu_icache_snoops_remote_store) {
  407. r4k_blast_scache_page_indexed(paddr);
  408. }
  409. }
  410. if (exec) {
  411. if (cpu_has_vtag_icache && mm == current->active_mm) {
  412. int cpu = smp_processor_id();
  413. if (cpu_context(cpu, mm) != 0)
  414. drop_mmu_context(mm, cpu);
  415. } else
  416. r4k_blast_icache_page_indexed(addr);
  417. }
  418. }
  419. static void r4k_flush_cache_page(struct vm_area_struct *vma,
  420. unsigned long addr, unsigned long pfn)
  421. {
  422. struct flush_cache_page_args args;
  423. args.vma = vma;
  424. args.addr = addr;
  425. args.pfn = pfn;
  426. r4k_on_each_cpu(local_r4k_flush_cache_page, &args, 1, 1);
  427. }
  428. static inline void local_r4k_flush_data_cache_page(void * addr)
  429. {
  430. r4k_blast_dcache_page((unsigned long) addr);
  431. }
  432. static void r4k_flush_data_cache_page(unsigned long addr)
  433. {
  434. r4k_on_each_cpu(local_r4k_flush_data_cache_page, (void *) addr, 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. if (!cpu_icache_snoops_remote_store && scache_size) {
  453. if (end - start > scache_size)
  454. r4k_blast_scache();
  455. else
  456. protected_blast_scache_range(start, end);
  457. }
  458. }
  459. if (end - start > icache_size)
  460. r4k_blast_icache();
  461. else
  462. protected_blast_icache_range(start, end);
  463. }
  464. static void r4k_flush_icache_range(unsigned long start, unsigned long end)
  465. {
  466. struct flush_icache_range_args args;
  467. args.start = start;
  468. args.end = end;
  469. r4k_on_each_cpu(local_r4k_flush_icache_range, &args, 1, 1);
  470. instruction_hazard();
  471. }
  472. #ifdef CONFIG_DMA_NONCOHERENT
  473. static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
  474. {
  475. /* Catch bad driver code */
  476. BUG_ON(size == 0);
  477. if (cpu_has_inclusive_pcaches) {
  478. if (size >= scache_size)
  479. r4k_blast_scache();
  480. else
  481. blast_scache_range(addr, addr + size);
  482. return;
  483. }
  484. /*
  485. * Either no secondary cache or the available caches don't have the
  486. * subset property so we have to flush the primary caches
  487. * explicitly
  488. */
  489. if (size >= dcache_size) {
  490. r4k_blast_dcache();
  491. } else {
  492. R4600_HIT_CACHEOP_WAR_IMPL;
  493. blast_dcache_range(addr, addr + size);
  494. }
  495. bc_wback_inv(addr, size);
  496. }
  497. static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
  498. {
  499. /* Catch bad driver code */
  500. BUG_ON(size == 0);
  501. if (cpu_has_inclusive_pcaches) {
  502. if (size >= scache_size)
  503. r4k_blast_scache();
  504. else
  505. blast_scache_range(addr, addr + size);
  506. return;
  507. }
  508. if (size >= dcache_size) {
  509. r4k_blast_dcache();
  510. } else {
  511. R4600_HIT_CACHEOP_WAR_IMPL;
  512. blast_dcache_range(addr, addr + size);
  513. }
  514. bc_inv(addr, size);
  515. }
  516. #endif /* CONFIG_DMA_NONCOHERENT */
  517. /*
  518. * While we're protected against bad userland addresses we don't care
  519. * very much about what happens in that case. Usually a segmentation
  520. * fault will dump the process later on anyway ...
  521. */
  522. static void local_r4k_flush_cache_sigtramp(void * arg)
  523. {
  524. unsigned long ic_lsize = cpu_icache_line_size();
  525. unsigned long dc_lsize = cpu_dcache_line_size();
  526. unsigned long sc_lsize = cpu_scache_line_size();
  527. unsigned long addr = (unsigned long) arg;
  528. R4600_HIT_CACHEOP_WAR_IMPL;
  529. if (dc_lsize)
  530. protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
  531. if (!cpu_icache_snoops_remote_store && scache_size)
  532. protected_writeback_scache_line(addr & ~(sc_lsize - 1));
  533. if (ic_lsize)
  534. protected_flush_icache_line(addr & ~(ic_lsize - 1));
  535. if (MIPS4K_ICACHE_REFILL_WAR) {
  536. __asm__ __volatile__ (
  537. ".set push\n\t"
  538. ".set noat\n\t"
  539. ".set mips3\n\t"
  540. #ifdef CONFIG_32BIT
  541. "la $at,1f\n\t"
  542. #endif
  543. #ifdef CONFIG_64BIT
  544. "dla $at,1f\n\t"
  545. #endif
  546. "cache %0,($at)\n\t"
  547. "nop; nop; nop\n"
  548. "1:\n\t"
  549. ".set pop"
  550. :
  551. : "i" (Hit_Invalidate_I));
  552. }
  553. if (MIPS_CACHE_SYNC_WAR)
  554. __asm__ __volatile__ ("sync");
  555. }
  556. static void r4k_flush_cache_sigtramp(unsigned long addr)
  557. {
  558. r4k_on_each_cpu(local_r4k_flush_cache_sigtramp, (void *) addr, 1, 1);
  559. }
  560. static void r4k_flush_icache_all(void)
  561. {
  562. if (cpu_has_vtag_icache)
  563. r4k_blast_icache();
  564. }
  565. static inline void rm7k_erratum31(void)
  566. {
  567. const unsigned long ic_lsize = 32;
  568. unsigned long addr;
  569. /* RM7000 erratum #31. The icache is screwed at startup. */
  570. write_c0_taglo(0);
  571. write_c0_taghi(0);
  572. for (addr = INDEX_BASE; addr <= INDEX_BASE + 4096; addr += ic_lsize) {
  573. __asm__ __volatile__ (
  574. ".set push\n\t"
  575. ".set noreorder\n\t"
  576. ".set mips3\n\t"
  577. "cache\t%1, 0(%0)\n\t"
  578. "cache\t%1, 0x1000(%0)\n\t"
  579. "cache\t%1, 0x2000(%0)\n\t"
  580. "cache\t%1, 0x3000(%0)\n\t"
  581. "cache\t%2, 0(%0)\n\t"
  582. "cache\t%2, 0x1000(%0)\n\t"
  583. "cache\t%2, 0x2000(%0)\n\t"
  584. "cache\t%2, 0x3000(%0)\n\t"
  585. "cache\t%1, 0(%0)\n\t"
  586. "cache\t%1, 0x1000(%0)\n\t"
  587. "cache\t%1, 0x2000(%0)\n\t"
  588. "cache\t%1, 0x3000(%0)\n\t"
  589. ".set pop\n"
  590. :
  591. : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill));
  592. }
  593. }
  594. static char *way_string[] __initdata = { NULL, "direct mapped", "2-way",
  595. "3-way", "4-way", "5-way", "6-way", "7-way", "8-way"
  596. };
  597. static void __init probe_pcache(void)
  598. {
  599. struct cpuinfo_mips *c = &current_cpu_data;
  600. unsigned int config = read_c0_config();
  601. unsigned int prid = read_c0_prid();
  602. unsigned long config1;
  603. unsigned int lsize;
  604. switch (c->cputype) {
  605. case CPU_R4600: /* QED style two way caches? */
  606. case CPU_R4700:
  607. case CPU_R5000:
  608. case CPU_NEVADA:
  609. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  610. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  611. c->icache.ways = 2;
  612. c->icache.waybit = __ffs(icache_size/2);
  613. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  614. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  615. c->dcache.ways = 2;
  616. c->dcache.waybit= __ffs(dcache_size/2);
  617. c->options |= MIPS_CPU_CACHE_CDEX_P;
  618. break;
  619. case CPU_R5432:
  620. case CPU_R5500:
  621. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  622. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  623. c->icache.ways = 2;
  624. c->icache.waybit= 0;
  625. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  626. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  627. c->dcache.ways = 2;
  628. c->dcache.waybit = 0;
  629. c->options |= MIPS_CPU_CACHE_CDEX_P;
  630. break;
  631. case CPU_TX49XX:
  632. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  633. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  634. c->icache.ways = 4;
  635. c->icache.waybit= 0;
  636. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  637. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  638. c->dcache.ways = 4;
  639. c->dcache.waybit = 0;
  640. c->options |= MIPS_CPU_CACHE_CDEX_P;
  641. c->options |= MIPS_CPU_PREFETCH;
  642. break;
  643. case CPU_R4000PC:
  644. case CPU_R4000SC:
  645. case CPU_R4000MC:
  646. case CPU_R4400PC:
  647. case CPU_R4400SC:
  648. case CPU_R4400MC:
  649. case CPU_R4300:
  650. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  651. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  652. c->icache.ways = 1;
  653. c->icache.waybit = 0; /* doesn't matter */
  654. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  655. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  656. c->dcache.ways = 1;
  657. c->dcache.waybit = 0; /* does not matter */
  658. c->options |= MIPS_CPU_CACHE_CDEX_P;
  659. break;
  660. case CPU_R10000:
  661. case CPU_R12000:
  662. case CPU_R14000:
  663. icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
  664. c->icache.linesz = 64;
  665. c->icache.ways = 2;
  666. c->icache.waybit = 0;
  667. dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26));
  668. c->dcache.linesz = 32;
  669. c->dcache.ways = 2;
  670. c->dcache.waybit = 0;
  671. c->options |= MIPS_CPU_PREFETCH;
  672. break;
  673. case CPU_VR4133:
  674. write_c0_config(config & ~VR41_CONF_P4K);
  675. case CPU_VR4131:
  676. /* Workaround for cache instruction bug of VR4131 */
  677. if (c->processor_id == 0x0c80U || c->processor_id == 0x0c81U ||
  678. c->processor_id == 0x0c82U) {
  679. config |= 0x00400000U;
  680. if (c->processor_id == 0x0c80U)
  681. config |= VR41_CONF_BP;
  682. write_c0_config(config);
  683. } else
  684. c->options |= MIPS_CPU_CACHE_CDEX_P;
  685. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  686. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  687. c->icache.ways = 2;
  688. c->icache.waybit = __ffs(icache_size/2);
  689. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  690. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  691. c->dcache.ways = 2;
  692. c->dcache.waybit = __ffs(dcache_size/2);
  693. break;
  694. case CPU_VR41XX:
  695. case CPU_VR4111:
  696. case CPU_VR4121:
  697. case CPU_VR4122:
  698. case CPU_VR4181:
  699. case CPU_VR4181A:
  700. icache_size = 1 << (10 + ((config & CONF_IC) >> 9));
  701. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  702. c->icache.ways = 1;
  703. c->icache.waybit = 0; /* doesn't matter */
  704. dcache_size = 1 << (10 + ((config & CONF_DC) >> 6));
  705. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  706. c->dcache.ways = 1;
  707. c->dcache.waybit = 0; /* does not matter */
  708. c->options |= MIPS_CPU_CACHE_CDEX_P;
  709. break;
  710. case CPU_RM7000:
  711. rm7k_erratum31();
  712. case CPU_RM9000:
  713. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  714. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  715. c->icache.ways = 4;
  716. c->icache.waybit = __ffs(icache_size / c->icache.ways);
  717. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  718. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  719. c->dcache.ways = 4;
  720. c->dcache.waybit = __ffs(dcache_size / c->dcache.ways);
  721. #if !defined(CONFIG_SMP) || !defined(RM9000_CDEX_SMP_WAR)
  722. c->options |= MIPS_CPU_CACHE_CDEX_P;
  723. #endif
  724. c->options |= MIPS_CPU_PREFETCH;
  725. break;
  726. case CPU_LOONGSON2:
  727. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  728. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  729. if (prid & 0x3)
  730. c->icache.ways = 4;
  731. else
  732. c->icache.ways = 2;
  733. c->icache.waybit = 0;
  734. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  735. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  736. if (prid & 0x3)
  737. c->dcache.ways = 4;
  738. else
  739. c->dcache.ways = 2;
  740. c->dcache.waybit = 0;
  741. break;
  742. default:
  743. if (!(config & MIPS_CONF_M))
  744. panic("Don't know how to probe P-caches on this cpu.");
  745. /*
  746. * So we seem to be a MIPS32 or MIPS64 CPU
  747. * So let's probe the I-cache ...
  748. */
  749. config1 = read_c0_config1();
  750. if ((lsize = ((config1 >> 19) & 7)))
  751. c->icache.linesz = 2 << lsize;
  752. else
  753. c->icache.linesz = lsize;
  754. c->icache.sets = 64 << ((config1 >> 22) & 7);
  755. c->icache.ways = 1 + ((config1 >> 16) & 7);
  756. icache_size = c->icache.sets *
  757. c->icache.ways *
  758. c->icache.linesz;
  759. c->icache.waybit = __ffs(icache_size/c->icache.ways);
  760. if (config & 0x8) /* VI bit */
  761. c->icache.flags |= MIPS_CACHE_VTAG;
  762. /*
  763. * Now probe the MIPS32 / MIPS64 data cache.
  764. */
  765. c->dcache.flags = 0;
  766. if ((lsize = ((config1 >> 10) & 7)))
  767. c->dcache.linesz = 2 << lsize;
  768. else
  769. c->dcache.linesz= lsize;
  770. c->dcache.sets = 64 << ((config1 >> 13) & 7);
  771. c->dcache.ways = 1 + ((config1 >> 7) & 7);
  772. dcache_size = c->dcache.sets *
  773. c->dcache.ways *
  774. c->dcache.linesz;
  775. c->dcache.waybit = __ffs(dcache_size/c->dcache.ways);
  776. c->options |= MIPS_CPU_PREFETCH;
  777. break;
  778. }
  779. /*
  780. * Processor configuration sanity check for the R4000SC erratum
  781. * #5. With page sizes larger than 32kB there is no possibility
  782. * to get a VCE exception anymore so we don't care about this
  783. * misconfiguration. The case is rather theoretical anyway;
  784. * presumably no vendor is shipping his hardware in the "bad"
  785. * configuration.
  786. */
  787. if ((prid & 0xff00) == PRID_IMP_R4000 && (prid & 0xff) < 0x40 &&
  788. !(config & CONF_SC) && c->icache.linesz != 16 &&
  789. PAGE_SIZE <= 0x8000)
  790. panic("Improper R4000SC processor configuration detected");
  791. /* compute a couple of other cache variables */
  792. c->icache.waysize = icache_size / c->icache.ways;
  793. c->dcache.waysize = dcache_size / c->dcache.ways;
  794. c->icache.sets = c->icache.linesz ?
  795. icache_size / (c->icache.linesz * c->icache.ways) : 0;
  796. c->dcache.sets = c->dcache.linesz ?
  797. dcache_size / (c->dcache.linesz * c->dcache.ways) : 0;
  798. /*
  799. * R10000 and R12000 P-caches are odd in a positive way. They're 32kB
  800. * 2-way virtually indexed so normally would suffer from aliases. So
  801. * normally they'd suffer from aliases but magic in the hardware deals
  802. * with that for us so we don't need to take care ourselves.
  803. */
  804. switch (c->cputype) {
  805. case CPU_20KC:
  806. case CPU_25KF:
  807. case CPU_SB1:
  808. case CPU_SB1A:
  809. c->dcache.flags |= MIPS_CACHE_PINDEX;
  810. break;
  811. case CPU_R10000:
  812. case CPU_R12000:
  813. case CPU_R14000:
  814. break;
  815. case CPU_24K:
  816. case CPU_34K:
  817. case CPU_74K:
  818. if ((read_c0_config7() & (1 << 16))) {
  819. /* effectively physically indexed dcache,
  820. thus no virtual aliases. */
  821. c->dcache.flags |= MIPS_CACHE_PINDEX;
  822. break;
  823. }
  824. default:
  825. if (c->dcache.waysize > PAGE_SIZE)
  826. c->dcache.flags |= MIPS_CACHE_ALIASES;
  827. }
  828. switch (c->cputype) {
  829. case CPU_20KC:
  830. /*
  831. * Some older 20Kc chips doesn't have the 'VI' bit in
  832. * the config register.
  833. */
  834. c->icache.flags |= MIPS_CACHE_VTAG;
  835. break;
  836. case CPU_AU1000:
  837. case CPU_AU1500:
  838. case CPU_AU1100:
  839. case CPU_AU1550:
  840. case CPU_AU1200:
  841. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  842. break;
  843. }
  844. #ifdef CONFIG_CPU_LOONGSON2
  845. /*
  846. * LOONGSON2 has 4 way icache, but when using indexed cache op,
  847. * one op will act on all 4 ways
  848. */
  849. c->icache.ways = 1;
  850. #endif
  851. printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
  852. icache_size >> 10,
  853. cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
  854. way_string[c->icache.ways], c->icache.linesz);
  855. printk("Primary data cache %ldkB, %s, linesize %d bytes.\n",
  856. dcache_size >> 10, way_string[c->dcache.ways], 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 managment.
  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_data.cputype) {
  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 = r4k_flush_cache_all;
  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. }