c-r4k.c 35 KB

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