c-r4k.c 34 KB

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