c-r4k.c 33 KB

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