c-r4k.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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 ([email protected])
  7. * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Ralf Baechle ([email protected])
  8. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  9. */
  10. #include <linux/cpu_pm.h>
  11. #include <linux/hardirq.h>
  12. #include <linux/init.h>
  13. #include <linux/highmem.h>
  14. #include <linux/kernel.h>
  15. #include <linux/linkage.h>
  16. #include <linux/preempt.h>
  17. #include <linux/sched.h>
  18. #include <linux/smp.h>
  19. #include <linux/mm.h>
  20. #include <linux/export.h>
  21. #include <linux/bitops.h>
  22. #include <linux/dma-map-ops.h> /* for dma_default_coherent */
  23. #include <asm/bcache.h>
  24. #include <asm/bootinfo.h>
  25. #include <asm/cache.h>
  26. #include <asm/cacheops.h>
  27. #include <asm/cpu.h>
  28. #include <asm/cpu-features.h>
  29. #include <asm/cpu-type.h>
  30. #include <asm/io.h>
  31. #include <asm/page.h>
  32. #include <asm/r4kcache.h>
  33. #include <asm/sections.h>
  34. #include <asm/mmu_context.h>
  35. #include <asm/cacheflush.h> /* for run_uncached() */
  36. #include <asm/traps.h>
  37. #include <asm/mips-cps.h>
  38. /*
  39. * Bits describing what cache ops an SMP callback function may perform.
  40. *
  41. * R4K_HIT - Virtual user or kernel address based cache operations. The
  42. * active_mm must be checked before using user addresses, falling
  43. * back to kmap.
  44. * R4K_INDEX - Index based cache operations.
  45. */
  46. #define R4K_HIT BIT(0)
  47. #define R4K_INDEX BIT(1)
  48. /**
  49. * r4k_op_needs_ipi() - Decide if a cache op needs to be done on every core.
  50. * @type: Type of cache operations (R4K_HIT or R4K_INDEX).
  51. *
  52. * Decides whether a cache op needs to be performed on every core in the system.
  53. * This may change depending on the @type of cache operation, as well as the set
  54. * of online CPUs, so preemption should be disabled by the caller to prevent CPU
  55. * hotplug from changing the result.
  56. *
  57. * Returns: 1 if the cache operation @type should be done on every core in
  58. * the system.
  59. * 0 if the cache operation @type is globalized and only needs to
  60. * be performed on a simple CPU.
  61. */
  62. static inline bool r4k_op_needs_ipi(unsigned int type)
  63. {
  64. /* The MIPS Coherence Manager (CM) globalizes address-based cache ops */
  65. if (type == R4K_HIT && mips_cm_present())
  66. return false;
  67. /*
  68. * Hardware doesn't globalize the required cache ops, so SMP calls may
  69. * be needed, but only if there are foreign CPUs (non-siblings with
  70. * separate caches).
  71. */
  72. /* cpu_foreign_map[] undeclared when !CONFIG_SMP */
  73. #ifdef CONFIG_SMP
  74. return !cpumask_empty(&cpu_foreign_map[0]);
  75. #else
  76. return false;
  77. #endif
  78. }
  79. /*
  80. * Special Variant of smp_call_function for use by cache functions:
  81. *
  82. * o No return value
  83. * o collapses to normal function call on UP kernels
  84. * o collapses to normal function call on systems with a single shared
  85. * primary cache.
  86. * o doesn't disable interrupts on the local CPU
  87. */
  88. static inline void r4k_on_each_cpu(unsigned int type,
  89. void (*func)(void *info), void *info)
  90. {
  91. preempt_disable();
  92. if (r4k_op_needs_ipi(type))
  93. smp_call_function_many(&cpu_foreign_map[smp_processor_id()],
  94. func, info, 1);
  95. func(info);
  96. preempt_enable();
  97. }
  98. /*
  99. * Must die.
  100. */
  101. static unsigned long icache_size __read_mostly;
  102. static unsigned long dcache_size __read_mostly;
  103. static unsigned long vcache_size __read_mostly;
  104. static unsigned long scache_size __read_mostly;
  105. /*
  106. * Dummy cache handling routines for machines without boardcaches
  107. */
  108. static void cache_noop(void) {}
  109. static struct bcache_ops no_sc_ops = {
  110. .bc_enable = (void *)cache_noop,
  111. .bc_disable = (void *)cache_noop,
  112. .bc_wback_inv = (void *)cache_noop,
  113. .bc_inv = (void *)cache_noop
  114. };
  115. struct bcache_ops *bcops = &no_sc_ops;
  116. #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
  117. #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
  118. #define R4600_HIT_CACHEOP_WAR_IMPL \
  119. do { \
  120. if (IS_ENABLED(CONFIG_WAR_R4600_V2_HIT_CACHEOP) && \
  121. cpu_is_r4600_v2_x()) \
  122. *(volatile unsigned long *)CKSEG1; \
  123. if (IS_ENABLED(CONFIG_WAR_R4600_V1_HIT_CACHEOP)) \
  124. __asm__ __volatile__("nop;nop;nop;nop"); \
  125. } while (0)
  126. static void (*r4k_blast_dcache_page)(unsigned long addr);
  127. static inline void r4k_blast_dcache_page_dc32(unsigned long addr)
  128. {
  129. R4600_HIT_CACHEOP_WAR_IMPL;
  130. blast_dcache32_page(addr);
  131. }
  132. static inline void r4k_blast_dcache_page_dc64(unsigned long addr)
  133. {
  134. blast_dcache64_page(addr);
  135. }
  136. static inline void r4k_blast_dcache_page_dc128(unsigned long addr)
  137. {
  138. blast_dcache128_page(addr);
  139. }
  140. static void r4k_blast_dcache_page_setup(void)
  141. {
  142. unsigned long dc_lsize = cpu_dcache_line_size();
  143. switch (dc_lsize) {
  144. case 0:
  145. r4k_blast_dcache_page = (void *)cache_noop;
  146. break;
  147. case 16:
  148. r4k_blast_dcache_page = blast_dcache16_page;
  149. break;
  150. case 32:
  151. r4k_blast_dcache_page = r4k_blast_dcache_page_dc32;
  152. break;
  153. case 64:
  154. r4k_blast_dcache_page = r4k_blast_dcache_page_dc64;
  155. break;
  156. case 128:
  157. r4k_blast_dcache_page = r4k_blast_dcache_page_dc128;
  158. break;
  159. default:
  160. break;
  161. }
  162. }
  163. #ifndef CONFIG_EVA
  164. #define r4k_blast_dcache_user_page r4k_blast_dcache_page
  165. #else
  166. static void (*r4k_blast_dcache_user_page)(unsigned long addr);
  167. static void r4k_blast_dcache_user_page_setup(void)
  168. {
  169. unsigned long dc_lsize = cpu_dcache_line_size();
  170. if (dc_lsize == 0)
  171. r4k_blast_dcache_user_page = (void *)cache_noop;
  172. else if (dc_lsize == 16)
  173. r4k_blast_dcache_user_page = blast_dcache16_user_page;
  174. else if (dc_lsize == 32)
  175. r4k_blast_dcache_user_page = blast_dcache32_user_page;
  176. else if (dc_lsize == 64)
  177. r4k_blast_dcache_user_page = blast_dcache64_user_page;
  178. }
  179. #endif
  180. static void (* r4k_blast_dcache_page_indexed)(unsigned long addr);
  181. static void r4k_blast_dcache_page_indexed_setup(void)
  182. {
  183. unsigned long dc_lsize = cpu_dcache_line_size();
  184. if (dc_lsize == 0)
  185. r4k_blast_dcache_page_indexed = (void *)cache_noop;
  186. else if (dc_lsize == 16)
  187. r4k_blast_dcache_page_indexed = blast_dcache16_page_indexed;
  188. else if (dc_lsize == 32)
  189. r4k_blast_dcache_page_indexed = blast_dcache32_page_indexed;
  190. else if (dc_lsize == 64)
  191. r4k_blast_dcache_page_indexed = blast_dcache64_page_indexed;
  192. else if (dc_lsize == 128)
  193. r4k_blast_dcache_page_indexed = blast_dcache128_page_indexed;
  194. }
  195. void (* r4k_blast_dcache)(void);
  196. EXPORT_SYMBOL(r4k_blast_dcache);
  197. static void r4k_blast_dcache_setup(void)
  198. {
  199. unsigned long dc_lsize = cpu_dcache_line_size();
  200. if (dc_lsize == 0)
  201. r4k_blast_dcache = (void *)cache_noop;
  202. else if (dc_lsize == 16)
  203. r4k_blast_dcache = blast_dcache16;
  204. else if (dc_lsize == 32)
  205. r4k_blast_dcache = blast_dcache32;
  206. else if (dc_lsize == 64)
  207. r4k_blast_dcache = blast_dcache64;
  208. else if (dc_lsize == 128)
  209. r4k_blast_dcache = blast_dcache128;
  210. }
  211. /* force code alignment (used for CONFIG_WAR_TX49XX_ICACHE_INDEX_INV) */
  212. #define JUMP_TO_ALIGN(order) \
  213. __asm__ __volatile__( \
  214. "b\t1f\n\t" \
  215. ".align\t" #order "\n\t" \
  216. "1:\n\t" \
  217. )
  218. #define CACHE32_UNROLL32_ALIGN JUMP_TO_ALIGN(10) /* 32 * 32 = 1024 */
  219. #define CACHE32_UNROLL32_ALIGN2 JUMP_TO_ALIGN(11)
  220. static inline void blast_r4600_v1_icache32(void)
  221. {
  222. unsigned long flags;
  223. local_irq_save(flags);
  224. blast_icache32();
  225. local_irq_restore(flags);
  226. }
  227. static inline void tx49_blast_icache32(void)
  228. {
  229. unsigned long start = INDEX_BASE;
  230. unsigned long end = start + current_cpu_data.icache.waysize;
  231. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  232. unsigned long ws_end = current_cpu_data.icache.ways <<
  233. current_cpu_data.icache.waybit;
  234. unsigned long ws, addr;
  235. CACHE32_UNROLL32_ALIGN2;
  236. /* I'm in even chunk. blast odd chunks */
  237. for (ws = 0; ws < ws_end; ws += ws_inc)
  238. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  239. cache_unroll(32, kernel_cache, Index_Invalidate_I,
  240. addr | ws, 32);
  241. CACHE32_UNROLL32_ALIGN;
  242. /* I'm in odd chunk. blast even chunks */
  243. for (ws = 0; ws < ws_end; ws += ws_inc)
  244. for (addr = start; addr < end; addr += 0x400 * 2)
  245. cache_unroll(32, kernel_cache, Index_Invalidate_I,
  246. addr | ws, 32);
  247. }
  248. static inline void blast_icache32_r4600_v1_page_indexed(unsigned long page)
  249. {
  250. unsigned long flags;
  251. local_irq_save(flags);
  252. blast_icache32_page_indexed(page);
  253. local_irq_restore(flags);
  254. }
  255. static inline void tx49_blast_icache32_page_indexed(unsigned long page)
  256. {
  257. unsigned long indexmask = current_cpu_data.icache.waysize - 1;
  258. unsigned long start = INDEX_BASE + (page & indexmask);
  259. unsigned long end = start + PAGE_SIZE;
  260. unsigned long ws_inc = 1UL << current_cpu_data.icache.waybit;
  261. unsigned long ws_end = current_cpu_data.icache.ways <<
  262. current_cpu_data.icache.waybit;
  263. unsigned long ws, addr;
  264. CACHE32_UNROLL32_ALIGN2;
  265. /* I'm in even chunk. blast odd chunks */
  266. for (ws = 0; ws < ws_end; ws += ws_inc)
  267. for (addr = start + 0x400; addr < end; addr += 0x400 * 2)
  268. cache_unroll(32, kernel_cache, Index_Invalidate_I,
  269. addr | ws, 32);
  270. CACHE32_UNROLL32_ALIGN;
  271. /* I'm in odd chunk. blast even chunks */
  272. for (ws = 0; ws < ws_end; ws += ws_inc)
  273. for (addr = start; addr < end; addr += 0x400 * 2)
  274. cache_unroll(32, kernel_cache, Index_Invalidate_I,
  275. addr | ws, 32);
  276. }
  277. static void (* r4k_blast_icache_page)(unsigned long addr);
  278. static void r4k_blast_icache_page_setup(void)
  279. {
  280. unsigned long ic_lsize = cpu_icache_line_size();
  281. if (ic_lsize == 0)
  282. r4k_blast_icache_page = (void *)cache_noop;
  283. else if (ic_lsize == 16)
  284. r4k_blast_icache_page = blast_icache16_page;
  285. else if (ic_lsize == 32 && current_cpu_type() == CPU_LOONGSON2EF)
  286. r4k_blast_icache_page = loongson2_blast_icache32_page;
  287. else if (ic_lsize == 32)
  288. r4k_blast_icache_page = blast_icache32_page;
  289. else if (ic_lsize == 64)
  290. r4k_blast_icache_page = blast_icache64_page;
  291. else if (ic_lsize == 128)
  292. r4k_blast_icache_page = blast_icache128_page;
  293. }
  294. #ifndef CONFIG_EVA
  295. #define r4k_blast_icache_user_page r4k_blast_icache_page
  296. #else
  297. static void (*r4k_blast_icache_user_page)(unsigned long addr);
  298. static void r4k_blast_icache_user_page_setup(void)
  299. {
  300. unsigned long ic_lsize = cpu_icache_line_size();
  301. if (ic_lsize == 0)
  302. r4k_blast_icache_user_page = (void *)cache_noop;
  303. else if (ic_lsize == 16)
  304. r4k_blast_icache_user_page = blast_icache16_user_page;
  305. else if (ic_lsize == 32)
  306. r4k_blast_icache_user_page = blast_icache32_user_page;
  307. else if (ic_lsize == 64)
  308. r4k_blast_icache_user_page = blast_icache64_user_page;
  309. }
  310. #endif
  311. static void (* r4k_blast_icache_page_indexed)(unsigned long addr);
  312. static void r4k_blast_icache_page_indexed_setup(void)
  313. {
  314. unsigned long ic_lsize = cpu_icache_line_size();
  315. if (ic_lsize == 0)
  316. r4k_blast_icache_page_indexed = (void *)cache_noop;
  317. else if (ic_lsize == 16)
  318. r4k_blast_icache_page_indexed = blast_icache16_page_indexed;
  319. else if (ic_lsize == 32) {
  320. if (IS_ENABLED(CONFIG_WAR_R4600_V1_INDEX_ICACHEOP) &&
  321. cpu_is_r4600_v1_x())
  322. r4k_blast_icache_page_indexed =
  323. blast_icache32_r4600_v1_page_indexed;
  324. else if (IS_ENABLED(CONFIG_WAR_TX49XX_ICACHE_INDEX_INV))
  325. r4k_blast_icache_page_indexed =
  326. tx49_blast_icache32_page_indexed;
  327. else if (current_cpu_type() == CPU_LOONGSON2EF)
  328. r4k_blast_icache_page_indexed =
  329. loongson2_blast_icache32_page_indexed;
  330. else
  331. r4k_blast_icache_page_indexed =
  332. blast_icache32_page_indexed;
  333. } else if (ic_lsize == 64)
  334. r4k_blast_icache_page_indexed = blast_icache64_page_indexed;
  335. }
  336. void (* r4k_blast_icache)(void);
  337. EXPORT_SYMBOL(r4k_blast_icache);
  338. static void r4k_blast_icache_setup(void)
  339. {
  340. unsigned long ic_lsize = cpu_icache_line_size();
  341. if (ic_lsize == 0)
  342. r4k_blast_icache = (void *)cache_noop;
  343. else if (ic_lsize == 16)
  344. r4k_blast_icache = blast_icache16;
  345. else if (ic_lsize == 32) {
  346. if (IS_ENABLED(CONFIG_WAR_R4600_V1_INDEX_ICACHEOP) &&
  347. cpu_is_r4600_v1_x())
  348. r4k_blast_icache = blast_r4600_v1_icache32;
  349. else if (IS_ENABLED(CONFIG_WAR_TX49XX_ICACHE_INDEX_INV))
  350. r4k_blast_icache = tx49_blast_icache32;
  351. else if (current_cpu_type() == CPU_LOONGSON2EF)
  352. r4k_blast_icache = loongson2_blast_icache32;
  353. else
  354. r4k_blast_icache = blast_icache32;
  355. } else if (ic_lsize == 64)
  356. r4k_blast_icache = blast_icache64;
  357. else if (ic_lsize == 128)
  358. r4k_blast_icache = blast_icache128;
  359. }
  360. static void (* r4k_blast_scache_page)(unsigned long addr);
  361. static void r4k_blast_scache_page_setup(void)
  362. {
  363. unsigned long sc_lsize = cpu_scache_line_size();
  364. if (scache_size == 0)
  365. r4k_blast_scache_page = (void *)cache_noop;
  366. else if (sc_lsize == 16)
  367. r4k_blast_scache_page = blast_scache16_page;
  368. else if (sc_lsize == 32)
  369. r4k_blast_scache_page = blast_scache32_page;
  370. else if (sc_lsize == 64)
  371. r4k_blast_scache_page = blast_scache64_page;
  372. else if (sc_lsize == 128)
  373. r4k_blast_scache_page = blast_scache128_page;
  374. }
  375. static void (* r4k_blast_scache_page_indexed)(unsigned long addr);
  376. static void r4k_blast_scache_page_indexed_setup(void)
  377. {
  378. unsigned long sc_lsize = cpu_scache_line_size();
  379. if (scache_size == 0)
  380. r4k_blast_scache_page_indexed = (void *)cache_noop;
  381. else if (sc_lsize == 16)
  382. r4k_blast_scache_page_indexed = blast_scache16_page_indexed;
  383. else if (sc_lsize == 32)
  384. r4k_blast_scache_page_indexed = blast_scache32_page_indexed;
  385. else if (sc_lsize == 64)
  386. r4k_blast_scache_page_indexed = blast_scache64_page_indexed;
  387. else if (sc_lsize == 128)
  388. r4k_blast_scache_page_indexed = blast_scache128_page_indexed;
  389. }
  390. static void (* r4k_blast_scache)(void);
  391. static void r4k_blast_scache_setup(void)
  392. {
  393. unsigned long sc_lsize = cpu_scache_line_size();
  394. if (scache_size == 0)
  395. r4k_blast_scache = (void *)cache_noop;
  396. else if (sc_lsize == 16)
  397. r4k_blast_scache = blast_scache16;
  398. else if (sc_lsize == 32)
  399. r4k_blast_scache = blast_scache32;
  400. else if (sc_lsize == 64)
  401. r4k_blast_scache = blast_scache64;
  402. else if (sc_lsize == 128)
  403. r4k_blast_scache = blast_scache128;
  404. }
  405. static void (*r4k_blast_scache_node)(long node);
  406. static void r4k_blast_scache_node_setup(void)
  407. {
  408. unsigned long sc_lsize = cpu_scache_line_size();
  409. if (current_cpu_type() != CPU_LOONGSON64)
  410. r4k_blast_scache_node = (void *)cache_noop;
  411. else if (sc_lsize == 16)
  412. r4k_blast_scache_node = blast_scache16_node;
  413. else if (sc_lsize == 32)
  414. r4k_blast_scache_node = blast_scache32_node;
  415. else if (sc_lsize == 64)
  416. r4k_blast_scache_node = blast_scache64_node;
  417. else if (sc_lsize == 128)
  418. r4k_blast_scache_node = blast_scache128_node;
  419. }
  420. static inline void local_r4k___flush_cache_all(void * args)
  421. {
  422. switch (current_cpu_type()) {
  423. case CPU_LOONGSON2EF:
  424. case CPU_R4000SC:
  425. case CPU_R4000MC:
  426. case CPU_R4400SC:
  427. case CPU_R4400MC:
  428. case CPU_R10000:
  429. case CPU_R12000:
  430. case CPU_R14000:
  431. case CPU_R16000:
  432. /*
  433. * These caches are inclusive caches, that is, if something
  434. * is not cached in the S-cache, we know it also won't be
  435. * in one of the primary caches.
  436. */
  437. r4k_blast_scache();
  438. break;
  439. case CPU_LOONGSON64:
  440. /* Use get_ebase_cpunum() for both NUMA=y/n */
  441. r4k_blast_scache_node(get_ebase_cpunum() >> 2);
  442. break;
  443. case CPU_BMIPS5000:
  444. r4k_blast_scache();
  445. __sync();
  446. break;
  447. default:
  448. r4k_blast_dcache();
  449. r4k_blast_icache();
  450. break;
  451. }
  452. }
  453. static void r4k___flush_cache_all(void)
  454. {
  455. r4k_on_each_cpu(R4K_INDEX, local_r4k___flush_cache_all, NULL);
  456. }
  457. /**
  458. * has_valid_asid() - Determine if an mm already has an ASID.
  459. * @mm: Memory map.
  460. * @type: R4K_HIT or R4K_INDEX, type of cache op.
  461. *
  462. * Determines whether @mm already has an ASID on any of the CPUs which cache ops
  463. * of type @type within an r4k_on_each_cpu() call will affect. If
  464. * r4k_on_each_cpu() does an SMP call to a single VPE in each core, then the
  465. * scope of the operation is confined to sibling CPUs, otherwise all online CPUs
  466. * will need to be checked.
  467. *
  468. * Must be called in non-preemptive context.
  469. *
  470. * Returns: 1 if the CPUs affected by @type cache ops have an ASID for @mm.
  471. * 0 otherwise.
  472. */
  473. static inline int has_valid_asid(const struct mm_struct *mm, unsigned int type)
  474. {
  475. unsigned int i;
  476. const cpumask_t *mask = cpu_present_mask;
  477. if (cpu_has_mmid)
  478. return cpu_context(0, mm) != 0;
  479. /* cpu_sibling_map[] undeclared when !CONFIG_SMP */
  480. #ifdef CONFIG_SMP
  481. /*
  482. * If r4k_on_each_cpu does SMP calls, it does them to a single VPE in
  483. * each foreign core, so we only need to worry about siblings.
  484. * Otherwise we need to worry about all present CPUs.
  485. */
  486. if (r4k_op_needs_ipi(type))
  487. mask = &cpu_sibling_map[smp_processor_id()];
  488. #endif
  489. for_each_cpu(i, mask)
  490. if (cpu_context(i, mm))
  491. return 1;
  492. return 0;
  493. }
  494. static void r4k__flush_cache_vmap(void)
  495. {
  496. r4k_blast_dcache();
  497. }
  498. static void r4k__flush_cache_vunmap(void)
  499. {
  500. r4k_blast_dcache();
  501. }
  502. /*
  503. * Note: flush_tlb_range() assumes flush_cache_range() sufficiently flushes
  504. * whole caches when vma is executable.
  505. */
  506. static inline void local_r4k_flush_cache_range(void * args)
  507. {
  508. struct vm_area_struct *vma = args;
  509. int exec = vma->vm_flags & VM_EXEC;
  510. if (!has_valid_asid(vma->vm_mm, R4K_INDEX))
  511. return;
  512. /*
  513. * If dcache can alias, we must blast it since mapping is changing.
  514. * If executable, we must ensure any dirty lines are written back far
  515. * enough to be visible to icache.
  516. */
  517. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc))
  518. r4k_blast_dcache();
  519. /* If executable, blast stale lines from icache */
  520. if (exec)
  521. r4k_blast_icache();
  522. }
  523. static void r4k_flush_cache_range(struct vm_area_struct *vma,
  524. unsigned long start, unsigned long end)
  525. {
  526. int exec = vma->vm_flags & VM_EXEC;
  527. if (cpu_has_dc_aliases || exec)
  528. r4k_on_each_cpu(R4K_INDEX, local_r4k_flush_cache_range, vma);
  529. }
  530. static inline void local_r4k_flush_cache_mm(void * args)
  531. {
  532. struct mm_struct *mm = args;
  533. if (!has_valid_asid(mm, R4K_INDEX))
  534. return;
  535. /*
  536. * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we
  537. * only flush the primary caches but R1x000 behave sane ...
  538. * R4000SC and R4400SC indexed S-cache ops also invalidate primary
  539. * caches, so we can bail out early.
  540. */
  541. if (current_cpu_type() == CPU_R4000SC ||
  542. current_cpu_type() == CPU_R4000MC ||
  543. current_cpu_type() == CPU_R4400SC ||
  544. current_cpu_type() == CPU_R4400MC) {
  545. r4k_blast_scache();
  546. return;
  547. }
  548. r4k_blast_dcache();
  549. }
  550. static void r4k_flush_cache_mm(struct mm_struct *mm)
  551. {
  552. if (!cpu_has_dc_aliases)
  553. return;
  554. r4k_on_each_cpu(R4K_INDEX, local_r4k_flush_cache_mm, mm);
  555. }
  556. struct flush_cache_page_args {
  557. struct vm_area_struct *vma;
  558. unsigned long addr;
  559. unsigned long pfn;
  560. };
  561. static inline void local_r4k_flush_cache_page(void *args)
  562. {
  563. struct flush_cache_page_args *fcp_args = args;
  564. struct vm_area_struct *vma = fcp_args->vma;
  565. unsigned long addr = fcp_args->addr;
  566. struct page *page = pfn_to_page(fcp_args->pfn);
  567. int exec = vma->vm_flags & VM_EXEC;
  568. struct mm_struct *mm = vma->vm_mm;
  569. int map_coherent = 0;
  570. pmd_t *pmdp;
  571. pte_t *ptep;
  572. void *vaddr;
  573. /*
  574. * If owns no valid ASID yet, cannot possibly have gotten
  575. * this page into the cache.
  576. */
  577. if (!has_valid_asid(mm, R4K_HIT))
  578. return;
  579. addr &= PAGE_MASK;
  580. pmdp = pmd_off(mm, addr);
  581. ptep = pte_offset_kernel(pmdp, addr);
  582. /*
  583. * If the page isn't marked valid, the page cannot possibly be
  584. * in the cache.
  585. */
  586. if (!(pte_present(*ptep)))
  587. return;
  588. if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID))
  589. vaddr = NULL;
  590. else {
  591. /*
  592. * Use kmap_coherent or kmap_atomic to do flushes for
  593. * another ASID than the current one.
  594. */
  595. map_coherent = (cpu_has_dc_aliases &&
  596. page_mapcount(page) &&
  597. !Page_dcache_dirty(page));
  598. if (map_coherent)
  599. vaddr = kmap_coherent(page, addr);
  600. else
  601. vaddr = kmap_atomic(page);
  602. addr = (unsigned long)vaddr;
  603. }
  604. if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc)) {
  605. vaddr ? r4k_blast_dcache_page(addr) :
  606. r4k_blast_dcache_user_page(addr);
  607. if (exec && !cpu_icache_snoops_remote_store)
  608. r4k_blast_scache_page(addr);
  609. }
  610. if (exec) {
  611. if (vaddr && cpu_has_vtag_icache && mm == current->active_mm) {
  612. drop_mmu_context(mm);
  613. } else
  614. vaddr ? r4k_blast_icache_page(addr) :
  615. r4k_blast_icache_user_page(addr);
  616. }
  617. if (vaddr) {
  618. if (map_coherent)
  619. kunmap_coherent();
  620. else
  621. kunmap_atomic(vaddr);
  622. }
  623. }
  624. static void r4k_flush_cache_page(struct vm_area_struct *vma,
  625. unsigned long addr, unsigned long pfn)
  626. {
  627. struct flush_cache_page_args args;
  628. args.vma = vma;
  629. args.addr = addr;
  630. args.pfn = pfn;
  631. r4k_on_each_cpu(R4K_HIT, local_r4k_flush_cache_page, &args);
  632. }
  633. static inline void local_r4k_flush_data_cache_page(void * addr)
  634. {
  635. r4k_blast_dcache_page((unsigned long) addr);
  636. }
  637. static void r4k_flush_data_cache_page(unsigned long addr)
  638. {
  639. if (in_atomic())
  640. local_r4k_flush_data_cache_page((void *)addr);
  641. else
  642. r4k_on_each_cpu(R4K_HIT, local_r4k_flush_data_cache_page,
  643. (void *) addr);
  644. }
  645. struct flush_icache_range_args {
  646. unsigned long start;
  647. unsigned long end;
  648. unsigned int type;
  649. bool user;
  650. };
  651. static inline void __local_r4k_flush_icache_range(unsigned long start,
  652. unsigned long end,
  653. unsigned int type,
  654. bool user)
  655. {
  656. if (!cpu_has_ic_fills_f_dc) {
  657. if (type == R4K_INDEX ||
  658. (type & R4K_INDEX && end - start >= dcache_size)) {
  659. r4k_blast_dcache();
  660. } else {
  661. R4600_HIT_CACHEOP_WAR_IMPL;
  662. if (user)
  663. protected_blast_dcache_range(start, end);
  664. else
  665. blast_dcache_range(start, end);
  666. }
  667. }
  668. if (type == R4K_INDEX ||
  669. (type & R4K_INDEX && end - start > icache_size))
  670. r4k_blast_icache();
  671. else {
  672. switch (boot_cpu_type()) {
  673. case CPU_LOONGSON2EF:
  674. protected_loongson2_blast_icache_range(start, end);
  675. break;
  676. default:
  677. if (user)
  678. protected_blast_icache_range(start, end);
  679. else
  680. blast_icache_range(start, end);
  681. break;
  682. }
  683. }
  684. }
  685. static inline void local_r4k_flush_icache_range(unsigned long start,
  686. unsigned long end)
  687. {
  688. __local_r4k_flush_icache_range(start, end, R4K_HIT | R4K_INDEX, false);
  689. }
  690. static inline void local_r4k_flush_icache_user_range(unsigned long start,
  691. unsigned long end)
  692. {
  693. __local_r4k_flush_icache_range(start, end, R4K_HIT | R4K_INDEX, true);
  694. }
  695. static inline void local_r4k_flush_icache_range_ipi(void *args)
  696. {
  697. struct flush_icache_range_args *fir_args = args;
  698. unsigned long start = fir_args->start;
  699. unsigned long end = fir_args->end;
  700. unsigned int type = fir_args->type;
  701. bool user = fir_args->user;
  702. __local_r4k_flush_icache_range(start, end, type, user);
  703. }
  704. static void __r4k_flush_icache_range(unsigned long start, unsigned long end,
  705. bool user)
  706. {
  707. struct flush_icache_range_args args;
  708. unsigned long size, cache_size;
  709. args.start = start;
  710. args.end = end;
  711. args.type = R4K_HIT | R4K_INDEX;
  712. args.user = user;
  713. /*
  714. * Indexed cache ops require an SMP call.
  715. * Consider if that can or should be avoided.
  716. */
  717. preempt_disable();
  718. if (r4k_op_needs_ipi(R4K_INDEX) && !r4k_op_needs_ipi(R4K_HIT)) {
  719. /*
  720. * If address-based cache ops don't require an SMP call, then
  721. * use them exclusively for small flushes.
  722. */
  723. size = end - start;
  724. cache_size = icache_size;
  725. if (!cpu_has_ic_fills_f_dc) {
  726. size *= 2;
  727. cache_size += dcache_size;
  728. }
  729. if (size <= cache_size)
  730. args.type &= ~R4K_INDEX;
  731. }
  732. r4k_on_each_cpu(args.type, local_r4k_flush_icache_range_ipi, &args);
  733. preempt_enable();
  734. instruction_hazard();
  735. }
  736. static void r4k_flush_icache_range(unsigned long start, unsigned long end)
  737. {
  738. return __r4k_flush_icache_range(start, end, false);
  739. }
  740. static void r4k_flush_icache_user_range(unsigned long start, unsigned long end)
  741. {
  742. return __r4k_flush_icache_range(start, end, true);
  743. }
  744. #ifdef CONFIG_DMA_NONCOHERENT
  745. static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
  746. {
  747. /* Catch bad driver code */
  748. if (WARN_ON(size == 0))
  749. return;
  750. preempt_disable();
  751. if (cpu_has_inclusive_pcaches) {
  752. if (size >= scache_size) {
  753. if (current_cpu_type() != CPU_LOONGSON64)
  754. r4k_blast_scache();
  755. else
  756. r4k_blast_scache_node(pa_to_nid(addr));
  757. } else {
  758. blast_scache_range(addr, addr + size);
  759. }
  760. preempt_enable();
  761. __sync();
  762. return;
  763. }
  764. /*
  765. * Either no secondary cache or the available caches don't have the
  766. * subset property so we have to flush the primary caches
  767. * explicitly.
  768. * If we would need IPI to perform an INDEX-type operation, then
  769. * we have to use the HIT-type alternative as IPI cannot be used
  770. * here due to interrupts possibly being disabled.
  771. */
  772. if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {
  773. r4k_blast_dcache();
  774. } else {
  775. R4600_HIT_CACHEOP_WAR_IMPL;
  776. blast_dcache_range(addr, addr + size);
  777. }
  778. preempt_enable();
  779. bc_wback_inv(addr, size);
  780. __sync();
  781. }
  782. static void prefetch_cache_inv(unsigned long addr, unsigned long size)
  783. {
  784. unsigned int linesz = cpu_scache_line_size();
  785. unsigned long addr0 = addr, addr1;
  786. addr0 &= ~(linesz - 1);
  787. addr1 = (addr0 + size - 1) & ~(linesz - 1);
  788. protected_writeback_scache_line(addr0);
  789. if (likely(addr1 != addr0))
  790. protected_writeback_scache_line(addr1);
  791. else
  792. return;
  793. addr0 += linesz;
  794. if (likely(addr1 != addr0))
  795. protected_writeback_scache_line(addr0);
  796. else
  797. return;
  798. addr1 -= linesz;
  799. if (likely(addr1 > addr0))
  800. protected_writeback_scache_line(addr0);
  801. }
  802. static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
  803. {
  804. /* Catch bad driver code */
  805. if (WARN_ON(size == 0))
  806. return;
  807. preempt_disable();
  808. if (current_cpu_type() == CPU_BMIPS5000)
  809. prefetch_cache_inv(addr, size);
  810. if (cpu_has_inclusive_pcaches) {
  811. if (size >= scache_size) {
  812. if (current_cpu_type() != CPU_LOONGSON64)
  813. r4k_blast_scache();
  814. else
  815. r4k_blast_scache_node(pa_to_nid(addr));
  816. } else {
  817. /*
  818. * There is no clearly documented alignment requirement
  819. * for the cache instruction on MIPS processors and
  820. * some processors, among them the RM5200 and RM7000
  821. * QED processors will throw an address error for cache
  822. * hit ops with insufficient alignment. Solved by
  823. * aligning the address to cache line size.
  824. */
  825. blast_inv_scache_range(addr, addr + size);
  826. }
  827. preempt_enable();
  828. __sync();
  829. return;
  830. }
  831. if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {
  832. r4k_blast_dcache();
  833. } else {
  834. R4600_HIT_CACHEOP_WAR_IMPL;
  835. blast_inv_dcache_range(addr, addr + size);
  836. }
  837. preempt_enable();
  838. bc_inv(addr, size);
  839. __sync();
  840. }
  841. #endif /* CONFIG_DMA_NONCOHERENT */
  842. static void r4k_flush_icache_all(void)
  843. {
  844. if (cpu_has_vtag_icache)
  845. r4k_blast_icache();
  846. }
  847. struct flush_kernel_vmap_range_args {
  848. unsigned long vaddr;
  849. int size;
  850. };
  851. static inline void local_r4k_flush_kernel_vmap_range_index(void *args)
  852. {
  853. /*
  854. * Aliases only affect the primary caches so don't bother with
  855. * S-caches or T-caches.
  856. */
  857. r4k_blast_dcache();
  858. }
  859. static inline void local_r4k_flush_kernel_vmap_range(void *args)
  860. {
  861. struct flush_kernel_vmap_range_args *vmra = args;
  862. unsigned long vaddr = vmra->vaddr;
  863. int size = vmra->size;
  864. /*
  865. * Aliases only affect the primary caches so don't bother with
  866. * S-caches or T-caches.
  867. */
  868. R4600_HIT_CACHEOP_WAR_IMPL;
  869. blast_dcache_range(vaddr, vaddr + size);
  870. }
  871. static void r4k_flush_kernel_vmap_range(unsigned long vaddr, int size)
  872. {
  873. struct flush_kernel_vmap_range_args args;
  874. args.vaddr = (unsigned long) vaddr;
  875. args.size = size;
  876. if (size >= dcache_size)
  877. r4k_on_each_cpu(R4K_INDEX,
  878. local_r4k_flush_kernel_vmap_range_index, NULL);
  879. else
  880. r4k_on_each_cpu(R4K_HIT, local_r4k_flush_kernel_vmap_range,
  881. &args);
  882. }
  883. static inline void rm7k_erratum31(void)
  884. {
  885. const unsigned long ic_lsize = 32;
  886. unsigned long addr;
  887. /* RM7000 erratum #31. The icache is screwed at startup. */
  888. write_c0_taglo(0);
  889. write_c0_taghi(0);
  890. for (addr = INDEX_BASE; addr <= INDEX_BASE + 4096; addr += ic_lsize) {
  891. __asm__ __volatile__ (
  892. ".set push\n\t"
  893. ".set noreorder\n\t"
  894. ".set mips3\n\t"
  895. "cache\t%1, 0(%0)\n\t"
  896. "cache\t%1, 0x1000(%0)\n\t"
  897. "cache\t%1, 0x2000(%0)\n\t"
  898. "cache\t%1, 0x3000(%0)\n\t"
  899. "cache\t%2, 0(%0)\n\t"
  900. "cache\t%2, 0x1000(%0)\n\t"
  901. "cache\t%2, 0x2000(%0)\n\t"
  902. "cache\t%2, 0x3000(%0)\n\t"
  903. "cache\t%1, 0(%0)\n\t"
  904. "cache\t%1, 0x1000(%0)\n\t"
  905. "cache\t%1, 0x2000(%0)\n\t"
  906. "cache\t%1, 0x3000(%0)\n\t"
  907. ".set pop\n"
  908. :
  909. : "r" (addr), "i" (Index_Store_Tag_I), "i" (Fill_I));
  910. }
  911. }
  912. static inline int alias_74k_erratum(struct cpuinfo_mips *c)
  913. {
  914. unsigned int imp = c->processor_id & PRID_IMP_MASK;
  915. unsigned int rev = c->processor_id & PRID_REV_MASK;
  916. int present = 0;
  917. /*
  918. * Early versions of the 74K do not update the cache tags on a
  919. * vtag miss/ptag hit which can occur in the case of KSEG0/KUSEG
  920. * aliases. In this case it is better to treat the cache as always
  921. * having aliases. Also disable the synonym tag update feature
  922. * where available. In this case no opportunistic tag update will
  923. * happen where a load causes a virtual address miss but a physical
  924. * address hit during a D-cache look-up.
  925. */
  926. switch (imp) {
  927. case PRID_IMP_74K:
  928. if (rev <= PRID_REV_ENCODE_332(2, 4, 0))
  929. present = 1;
  930. if (rev == PRID_REV_ENCODE_332(2, 4, 0))
  931. write_c0_config6(read_c0_config6() | MTI_CONF6_SYND);
  932. break;
  933. case PRID_IMP_1074K:
  934. if (rev <= PRID_REV_ENCODE_332(1, 1, 0)) {
  935. present = 1;
  936. write_c0_config6(read_c0_config6() | MTI_CONF6_SYND);
  937. }
  938. break;
  939. default:
  940. BUG();
  941. }
  942. return present;
  943. }
  944. static void b5k_instruction_hazard(void)
  945. {
  946. __sync();
  947. __sync();
  948. __asm__ __volatile__(
  949. " nop; nop; nop; nop; nop; nop; nop; nop\n"
  950. " nop; nop; nop; nop; nop; nop; nop; nop\n"
  951. " nop; nop; nop; nop; nop; nop; nop; nop\n"
  952. " nop; nop; nop; nop; nop; nop; nop; nop\n"
  953. : : : "memory");
  954. }
  955. static char *way_string[] = { NULL, "direct mapped", "2-way",
  956. "3-way", "4-way", "5-way", "6-way", "7-way", "8-way",
  957. "9-way", "10-way", "11-way", "12-way",
  958. "13-way", "14-way", "15-way", "16-way",
  959. };
  960. static void probe_pcache(void)
  961. {
  962. struct cpuinfo_mips *c = &current_cpu_data;
  963. unsigned int config = read_c0_config();
  964. unsigned int prid = read_c0_prid();
  965. int has_74k_erratum = 0;
  966. unsigned long config1;
  967. unsigned int lsize;
  968. switch (current_cpu_type()) {
  969. case CPU_R4600: /* QED style two way caches? */
  970. case CPU_R4700:
  971. case CPU_R5000:
  972. case CPU_NEVADA:
  973. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  974. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  975. c->icache.ways = 2;
  976. c->icache.waybit = __ffs(icache_size/2);
  977. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  978. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  979. c->dcache.ways = 2;
  980. c->dcache.waybit= __ffs(dcache_size/2);
  981. c->options |= MIPS_CPU_CACHE_CDEX_P;
  982. break;
  983. case CPU_R5500:
  984. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  985. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  986. c->icache.ways = 2;
  987. c->icache.waybit= 0;
  988. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  989. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  990. c->dcache.ways = 2;
  991. c->dcache.waybit = 0;
  992. c->options |= MIPS_CPU_CACHE_CDEX_P | MIPS_CPU_PREFETCH;
  993. break;
  994. case CPU_TX49XX:
  995. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  996. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  997. c->icache.ways = 4;
  998. c->icache.waybit= 0;
  999. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  1000. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  1001. c->dcache.ways = 4;
  1002. c->dcache.waybit = 0;
  1003. c->options |= MIPS_CPU_CACHE_CDEX_P;
  1004. c->options |= MIPS_CPU_PREFETCH;
  1005. break;
  1006. case CPU_R4000PC:
  1007. case CPU_R4000SC:
  1008. case CPU_R4000MC:
  1009. case CPU_R4400PC:
  1010. case CPU_R4400SC:
  1011. case CPU_R4400MC:
  1012. case CPU_R4300:
  1013. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  1014. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  1015. c->icache.ways = 1;
  1016. c->icache.waybit = 0; /* doesn't matter */
  1017. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  1018. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  1019. c->dcache.ways = 1;
  1020. c->dcache.waybit = 0; /* does not matter */
  1021. c->options |= MIPS_CPU_CACHE_CDEX_P;
  1022. break;
  1023. case CPU_R10000:
  1024. case CPU_R12000:
  1025. case CPU_R14000:
  1026. case CPU_R16000:
  1027. icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
  1028. c->icache.linesz = 64;
  1029. c->icache.ways = 2;
  1030. c->icache.waybit = 0;
  1031. dcache_size = 1 << (12 + ((config & R10K_CONF_DC) >> 26));
  1032. c->dcache.linesz = 32;
  1033. c->dcache.ways = 2;
  1034. c->dcache.waybit = 0;
  1035. c->options |= MIPS_CPU_PREFETCH;
  1036. break;
  1037. case CPU_RM7000:
  1038. rm7k_erratum31();
  1039. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  1040. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  1041. c->icache.ways = 4;
  1042. c->icache.waybit = __ffs(icache_size / c->icache.ways);
  1043. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  1044. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  1045. c->dcache.ways = 4;
  1046. c->dcache.waybit = __ffs(dcache_size / c->dcache.ways);
  1047. c->options |= MIPS_CPU_CACHE_CDEX_P;
  1048. c->options |= MIPS_CPU_PREFETCH;
  1049. break;
  1050. case CPU_LOONGSON2EF:
  1051. icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
  1052. c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
  1053. if (prid & 0x3)
  1054. c->icache.ways = 4;
  1055. else
  1056. c->icache.ways = 2;
  1057. c->icache.waybit = 0;
  1058. dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
  1059. c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
  1060. if (prid & 0x3)
  1061. c->dcache.ways = 4;
  1062. else
  1063. c->dcache.ways = 2;
  1064. c->dcache.waybit = 0;
  1065. break;
  1066. case CPU_LOONGSON64:
  1067. config1 = read_c0_config1();
  1068. lsize = (config1 >> 19) & 7;
  1069. if (lsize)
  1070. c->icache.linesz = 2 << lsize;
  1071. else
  1072. c->icache.linesz = 0;
  1073. c->icache.sets = 64 << ((config1 >> 22) & 7);
  1074. c->icache.ways = 1 + ((config1 >> 16) & 7);
  1075. icache_size = c->icache.sets *
  1076. c->icache.ways *
  1077. c->icache.linesz;
  1078. c->icache.waybit = 0;
  1079. lsize = (config1 >> 10) & 7;
  1080. if (lsize)
  1081. c->dcache.linesz = 2 << lsize;
  1082. else
  1083. c->dcache.linesz = 0;
  1084. c->dcache.sets = 64 << ((config1 >> 13) & 7);
  1085. c->dcache.ways = 1 + ((config1 >> 7) & 7);
  1086. dcache_size = c->dcache.sets *
  1087. c->dcache.ways *
  1088. c->dcache.linesz;
  1089. c->dcache.waybit = 0;
  1090. if ((c->processor_id & (PRID_IMP_MASK | PRID_REV_MASK)) >=
  1091. (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0) ||
  1092. (c->processor_id & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R)
  1093. c->options |= MIPS_CPU_PREFETCH;
  1094. break;
  1095. case CPU_CAVIUM_OCTEON3:
  1096. /* For now lie about the number of ways. */
  1097. c->icache.linesz = 128;
  1098. c->icache.sets = 16;
  1099. c->icache.ways = 8;
  1100. c->icache.flags |= MIPS_CACHE_VTAG;
  1101. icache_size = c->icache.sets * c->icache.ways * c->icache.linesz;
  1102. c->dcache.linesz = 128;
  1103. c->dcache.ways = 8;
  1104. c->dcache.sets = 8;
  1105. dcache_size = c->dcache.sets * c->dcache.ways * c->dcache.linesz;
  1106. c->options |= MIPS_CPU_PREFETCH;
  1107. break;
  1108. default:
  1109. if (!(config & MIPS_CONF_M))
  1110. panic("Don't know how to probe P-caches on this cpu.");
  1111. /*
  1112. * So we seem to be a MIPS32 or MIPS64 CPU
  1113. * So let's probe the I-cache ...
  1114. */
  1115. config1 = read_c0_config1();
  1116. lsize = (config1 >> 19) & 7;
  1117. /* IL == 7 is reserved */
  1118. if (lsize == 7)
  1119. panic("Invalid icache line size");
  1120. c->icache.linesz = lsize ? 2 << lsize : 0;
  1121. c->icache.sets = 32 << (((config1 >> 22) + 1) & 7);
  1122. c->icache.ways = 1 + ((config1 >> 16) & 7);
  1123. icache_size = c->icache.sets *
  1124. c->icache.ways *
  1125. c->icache.linesz;
  1126. c->icache.waybit = __ffs(icache_size/c->icache.ways);
  1127. if (config & MIPS_CONF_VI)
  1128. c->icache.flags |= MIPS_CACHE_VTAG;
  1129. /*
  1130. * Now probe the MIPS32 / MIPS64 data cache.
  1131. */
  1132. c->dcache.flags = 0;
  1133. lsize = (config1 >> 10) & 7;
  1134. /* DL == 7 is reserved */
  1135. if (lsize == 7)
  1136. panic("Invalid dcache line size");
  1137. c->dcache.linesz = lsize ? 2 << lsize : 0;
  1138. c->dcache.sets = 32 << (((config1 >> 13) + 1) & 7);
  1139. c->dcache.ways = 1 + ((config1 >> 7) & 7);
  1140. dcache_size = c->dcache.sets *
  1141. c->dcache.ways *
  1142. c->dcache.linesz;
  1143. c->dcache.waybit = __ffs(dcache_size/c->dcache.ways);
  1144. c->options |= MIPS_CPU_PREFETCH;
  1145. break;
  1146. }
  1147. /*
  1148. * Processor configuration sanity check for the R4000SC erratum
  1149. * #5. With page sizes larger than 32kB there is no possibility
  1150. * to get a VCE exception anymore so we don't care about this
  1151. * misconfiguration. The case is rather theoretical anyway;
  1152. * presumably no vendor is shipping his hardware in the "bad"
  1153. * configuration.
  1154. */
  1155. if ((prid & PRID_IMP_MASK) == PRID_IMP_R4000 &&
  1156. (prid & PRID_REV_MASK) < PRID_REV_R4400 &&
  1157. !(config & CONF_SC) && c->icache.linesz != 16 &&
  1158. PAGE_SIZE <= 0x8000)
  1159. panic("Improper R4000SC processor configuration detected");
  1160. /* compute a couple of other cache variables */
  1161. c->icache.waysize = icache_size / c->icache.ways;
  1162. c->dcache.waysize = dcache_size / c->dcache.ways;
  1163. c->icache.sets = c->icache.linesz ?
  1164. icache_size / (c->icache.linesz * c->icache.ways) : 0;
  1165. c->dcache.sets = c->dcache.linesz ?
  1166. dcache_size / (c->dcache.linesz * c->dcache.ways) : 0;
  1167. /*
  1168. * R1x000 P-caches are odd in a positive way. They're 32kB 2-way
  1169. * virtually indexed so normally would suffer from aliases. So
  1170. * normally they'd suffer from aliases but magic in the hardware deals
  1171. * with that for us so we don't need to take care ourselves.
  1172. */
  1173. switch (current_cpu_type()) {
  1174. case CPU_20KC:
  1175. case CPU_25KF:
  1176. case CPU_I6400:
  1177. case CPU_I6500:
  1178. case CPU_SB1:
  1179. case CPU_SB1A:
  1180. c->dcache.flags |= MIPS_CACHE_PINDEX;
  1181. break;
  1182. case CPU_R10000:
  1183. case CPU_R12000:
  1184. case CPU_R14000:
  1185. case CPU_R16000:
  1186. break;
  1187. case CPU_74K:
  1188. case CPU_1074K:
  1189. has_74k_erratum = alias_74k_erratum(c);
  1190. fallthrough;
  1191. case CPU_M14KC:
  1192. case CPU_M14KEC:
  1193. case CPU_24K:
  1194. case CPU_34K:
  1195. case CPU_1004K:
  1196. case CPU_INTERAPTIV:
  1197. case CPU_P5600:
  1198. case CPU_PROAPTIV:
  1199. case CPU_M5150:
  1200. case CPU_QEMU_GENERIC:
  1201. case CPU_P6600:
  1202. case CPU_M6250:
  1203. if (!(read_c0_config7() & MIPS_CONF7_IAR) &&
  1204. (c->icache.waysize > PAGE_SIZE))
  1205. c->icache.flags |= MIPS_CACHE_ALIASES;
  1206. if (!has_74k_erratum && (read_c0_config7() & MIPS_CONF7_AR)) {
  1207. /*
  1208. * Effectively physically indexed dcache,
  1209. * thus no virtual aliases.
  1210. */
  1211. c->dcache.flags |= MIPS_CACHE_PINDEX;
  1212. break;
  1213. }
  1214. fallthrough;
  1215. default:
  1216. if (has_74k_erratum || c->dcache.waysize > PAGE_SIZE)
  1217. c->dcache.flags |= MIPS_CACHE_ALIASES;
  1218. }
  1219. /* Physically indexed caches don't suffer from virtual aliasing */
  1220. if (c->dcache.flags & MIPS_CACHE_PINDEX)
  1221. c->dcache.flags &= ~MIPS_CACHE_ALIASES;
  1222. /*
  1223. * In systems with CM the icache fills from L2 or closer caches, and
  1224. * thus sees remote stores without needing to write them back any
  1225. * further than that.
  1226. */
  1227. if (mips_cm_present())
  1228. c->icache.flags |= MIPS_IC_SNOOPS_REMOTE;
  1229. switch (current_cpu_type()) {
  1230. case CPU_20KC:
  1231. /*
  1232. * Some older 20Kc chips doesn't have the 'VI' bit in
  1233. * the config register.
  1234. */
  1235. c->icache.flags |= MIPS_CACHE_VTAG;
  1236. break;
  1237. case CPU_ALCHEMY:
  1238. case CPU_I6400:
  1239. case CPU_I6500:
  1240. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  1241. break;
  1242. case CPU_BMIPS5000:
  1243. c->icache.flags |= MIPS_CACHE_IC_F_DC;
  1244. /* Cache aliases are handled in hardware; allow HIGHMEM */
  1245. c->dcache.flags &= ~MIPS_CACHE_ALIASES;
  1246. break;
  1247. case CPU_LOONGSON2EF:
  1248. /*
  1249. * LOONGSON2 has 4 way icache, but when using indexed cache op,
  1250. * one op will act on all 4 ways
  1251. */
  1252. c->icache.ways = 1;
  1253. }
  1254. pr_info("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
  1255. icache_size >> 10,
  1256. c->icache.flags & MIPS_CACHE_VTAG ? "VIVT" : "VIPT",
  1257. way_string[c->icache.ways], c->icache.linesz);
  1258. pr_info("Primary data cache %ldkB, %s, %s, %s, linesize %d bytes\n",
  1259. dcache_size >> 10, way_string[c->dcache.ways],
  1260. (c->dcache.flags & MIPS_CACHE_PINDEX) ? "PIPT" : "VIPT",
  1261. (c->dcache.flags & MIPS_CACHE_ALIASES) ?
  1262. "cache aliases" : "no aliases",
  1263. c->dcache.linesz);
  1264. }
  1265. static void probe_vcache(void)
  1266. {
  1267. struct cpuinfo_mips *c = &current_cpu_data;
  1268. unsigned int config2, lsize;
  1269. if (current_cpu_type() != CPU_LOONGSON64)
  1270. return;
  1271. config2 = read_c0_config2();
  1272. if ((lsize = ((config2 >> 20) & 15)))
  1273. c->vcache.linesz = 2 << lsize;
  1274. else
  1275. c->vcache.linesz = lsize;
  1276. c->vcache.sets = 64 << ((config2 >> 24) & 15);
  1277. c->vcache.ways = 1 + ((config2 >> 16) & 15);
  1278. vcache_size = c->vcache.sets * c->vcache.ways * c->vcache.linesz;
  1279. c->vcache.waybit = 0;
  1280. c->vcache.waysize = vcache_size / c->vcache.ways;
  1281. pr_info("Unified victim cache %ldkB %s, linesize %d bytes.\n",
  1282. vcache_size >> 10, way_string[c->vcache.ways], c->vcache.linesz);
  1283. }
  1284. /*
  1285. * If you even _breathe_ on this function, look at the gcc output and make sure
  1286. * it does not pop things on and off the stack for the cache sizing loop that
  1287. * executes in KSEG1 space or else you will crash and burn badly. You have
  1288. * been warned.
  1289. */
  1290. static int probe_scache(void)
  1291. {
  1292. unsigned long flags, addr, begin, end, pow2;
  1293. unsigned int config = read_c0_config();
  1294. struct cpuinfo_mips *c = &current_cpu_data;
  1295. if (config & CONF_SC)
  1296. return 0;
  1297. begin = (unsigned long) &_stext;
  1298. begin &= ~((4 * 1024 * 1024) - 1);
  1299. end = begin + (4 * 1024 * 1024);
  1300. /*
  1301. * This is such a bitch, you'd think they would make it easy to do
  1302. * this. Away you daemons of stupidity!
  1303. */
  1304. local_irq_save(flags);
  1305. /* Fill each size-multiple cache line with a valid tag. */
  1306. pow2 = (64 * 1024);
  1307. for (addr = begin; addr < end; addr = (begin + pow2)) {
  1308. unsigned long *p = (unsigned long *) addr;
  1309. __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */
  1310. pow2 <<= 1;
  1311. }
  1312. /* Load first line with zero (therefore invalid) tag. */
  1313. write_c0_taglo(0);
  1314. write_c0_taghi(0);
  1315. __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
  1316. cache_op(Index_Store_Tag_I, begin);
  1317. cache_op(Index_Store_Tag_D, begin);
  1318. cache_op(Index_Store_Tag_SD, begin);
  1319. /* Now search for the wrap around point. */
  1320. pow2 = (128 * 1024);
  1321. for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) {
  1322. cache_op(Index_Load_Tag_SD, addr);
  1323. __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */
  1324. if (!read_c0_taglo())
  1325. break;
  1326. pow2 <<= 1;
  1327. }
  1328. local_irq_restore(flags);
  1329. addr -= begin;
  1330. scache_size = addr;
  1331. c->scache.linesz = 16 << ((config & R4K_CONF_SB) >> 22);
  1332. c->scache.ways = 1;
  1333. c->scache.waybit = 0; /* does not matter */
  1334. return 1;
  1335. }
  1336. static void loongson2_sc_init(void)
  1337. {
  1338. struct cpuinfo_mips *c = &current_cpu_data;
  1339. scache_size = 512*1024;
  1340. c->scache.linesz = 32;
  1341. c->scache.ways = 4;
  1342. c->scache.waybit = 0;
  1343. c->scache.waysize = scache_size / (c->scache.ways);
  1344. c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
  1345. pr_info("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
  1346. scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
  1347. c->options |= MIPS_CPU_INCLUSIVE_CACHES;
  1348. }
  1349. static void loongson3_sc_init(void)
  1350. {
  1351. struct cpuinfo_mips *c = &current_cpu_data;
  1352. unsigned int config2, lsize;
  1353. config2 = read_c0_config2();
  1354. lsize = (config2 >> 4) & 15;
  1355. if (lsize)
  1356. c->scache.linesz = 2 << lsize;
  1357. else
  1358. c->scache.linesz = 0;
  1359. c->scache.sets = 64 << ((config2 >> 8) & 15);
  1360. c->scache.ways = 1 + (config2 & 15);
  1361. /* Loongson-3 has 4-Scache banks, while Loongson-2K have only 2 banks */
  1362. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R)
  1363. c->scache.sets *= 2;
  1364. else
  1365. c->scache.sets *= 4;
  1366. scache_size = c->scache.sets * c->scache.ways * c->scache.linesz;
  1367. c->scache.waybit = 0;
  1368. c->scache.waysize = scache_size / c->scache.ways;
  1369. pr_info("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
  1370. scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
  1371. if (scache_size)
  1372. c->options |= MIPS_CPU_INCLUSIVE_CACHES;
  1373. return;
  1374. }
  1375. extern int r5k_sc_init(void);
  1376. extern int rm7k_sc_init(void);
  1377. extern int mips_sc_init(void);
  1378. static void setup_scache(void)
  1379. {
  1380. struct cpuinfo_mips *c = &current_cpu_data;
  1381. unsigned int config = read_c0_config();
  1382. int sc_present = 0;
  1383. /*
  1384. * Do the probing thing on R4000SC and R4400SC processors. Other
  1385. * processors don't have a S-cache that would be relevant to the
  1386. * Linux memory management.
  1387. */
  1388. switch (current_cpu_type()) {
  1389. case CPU_R4000SC:
  1390. case CPU_R4000MC:
  1391. case CPU_R4400SC:
  1392. case CPU_R4400MC:
  1393. sc_present = run_uncached(probe_scache);
  1394. if (sc_present)
  1395. c->options |= MIPS_CPU_CACHE_CDEX_S;
  1396. break;
  1397. case CPU_R10000:
  1398. case CPU_R12000:
  1399. case CPU_R14000:
  1400. case CPU_R16000:
  1401. scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
  1402. c->scache.linesz = 64 << ((config >> 13) & 1);
  1403. c->scache.ways = 2;
  1404. c->scache.waybit= 0;
  1405. sc_present = 1;
  1406. break;
  1407. case CPU_R5000:
  1408. case CPU_NEVADA:
  1409. #ifdef CONFIG_R5000_CPU_SCACHE
  1410. r5k_sc_init();
  1411. #endif
  1412. return;
  1413. case CPU_RM7000:
  1414. #ifdef CONFIG_RM7000_CPU_SCACHE
  1415. rm7k_sc_init();
  1416. #endif
  1417. return;
  1418. case CPU_LOONGSON2EF:
  1419. loongson2_sc_init();
  1420. return;
  1421. case CPU_LOONGSON64:
  1422. loongson3_sc_init();
  1423. return;
  1424. case CPU_CAVIUM_OCTEON3:
  1425. /* don't need to worry about L2, fully coherent */
  1426. return;
  1427. default:
  1428. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  1429. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  1430. MIPS_CPU_ISA_M32R5 | MIPS_CPU_ISA_M64R5 |
  1431. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
  1432. #ifdef CONFIG_MIPS_CPU_SCACHE
  1433. if (mips_sc_init ()) {
  1434. scache_size = c->scache.ways * c->scache.sets * c->scache.linesz;
  1435. printk("MIPS secondary cache %ldkB, %s, linesize %d bytes.\n",
  1436. scache_size >> 10,
  1437. way_string[c->scache.ways], c->scache.linesz);
  1438. if (current_cpu_type() == CPU_BMIPS5000)
  1439. c->options |= MIPS_CPU_INCLUSIVE_CACHES;
  1440. }
  1441. #else
  1442. if (!(c->scache.flags & MIPS_CACHE_NOT_PRESENT))
  1443. panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
  1444. #endif
  1445. return;
  1446. }
  1447. sc_present = 0;
  1448. }
  1449. if (!sc_present)
  1450. return;
  1451. /* compute a couple of other cache variables */
  1452. c->scache.waysize = scache_size / c->scache.ways;
  1453. c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
  1454. printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
  1455. scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
  1456. c->options |= MIPS_CPU_INCLUSIVE_CACHES;
  1457. }
  1458. void au1x00_fixup_config_od(void)
  1459. {
  1460. /*
  1461. * c0_config.od (bit 19) was write only (and read as 0)
  1462. * on the early revisions of Alchemy SOCs. It disables the bus
  1463. * transaction overlapping and needs to be set to fix various errata.
  1464. */
  1465. switch (read_c0_prid()) {
  1466. case 0x00030100: /* Au1000 DA */
  1467. case 0x00030201: /* Au1000 HA */
  1468. case 0x00030202: /* Au1000 HB */
  1469. case 0x01030200: /* Au1500 AB */
  1470. /*
  1471. * Au1100 errata actually keeps silence about this bit, so we set it
  1472. * just in case for those revisions that require it to be set according
  1473. * to the (now gone) cpu table.
  1474. */
  1475. case 0x02030200: /* Au1100 AB */
  1476. case 0x02030201: /* Au1100 BA */
  1477. case 0x02030202: /* Au1100 BC */
  1478. set_c0_config(1 << 19);
  1479. break;
  1480. }
  1481. }
  1482. /* CP0 hazard avoidance. */
  1483. #define NXP_BARRIER() \
  1484. __asm__ __volatile__( \
  1485. ".set noreorder\n\t" \
  1486. "nop; nop; nop; nop; nop; nop;\n\t" \
  1487. ".set reorder\n\t")
  1488. static void nxp_pr4450_fixup_config(void)
  1489. {
  1490. unsigned long config0;
  1491. config0 = read_c0_config();
  1492. /* clear all three cache coherency fields */
  1493. config0 &= ~(0x7 | (7 << 25) | (7 << 28));
  1494. config0 |= (((_page_cachable_default >> _CACHE_SHIFT) << 0) |
  1495. ((_page_cachable_default >> _CACHE_SHIFT) << 25) |
  1496. ((_page_cachable_default >> _CACHE_SHIFT) << 28));
  1497. write_c0_config(config0);
  1498. NXP_BARRIER();
  1499. }
  1500. static int cca = -1;
  1501. static int __init cca_setup(char *str)
  1502. {
  1503. get_option(&str, &cca);
  1504. return 0;
  1505. }
  1506. early_param("cca", cca_setup);
  1507. static void coherency_setup(void)
  1508. {
  1509. if (cca < 0 || cca > 7)
  1510. cca = read_c0_config() & CONF_CM_CMASK;
  1511. _page_cachable_default = cca << _CACHE_SHIFT;
  1512. pr_debug("Using cache attribute %d\n", cca);
  1513. change_c0_config(CONF_CM_CMASK, cca);
  1514. /*
  1515. * c0_status.cu=0 specifies that updates by the sc instruction use
  1516. * the coherency mode specified by the TLB; 1 means cachable
  1517. * coherent update on write will be used. Not all processors have
  1518. * this bit and; some wire it to zero, others like Toshiba had the
  1519. * silly idea of putting something else there ...
  1520. */
  1521. switch (current_cpu_type()) {
  1522. case CPU_R4000PC:
  1523. case CPU_R4000SC:
  1524. case CPU_R4000MC:
  1525. case CPU_R4400PC:
  1526. case CPU_R4400SC:
  1527. case CPU_R4400MC:
  1528. clear_c0_config(CONF_CU);
  1529. break;
  1530. /*
  1531. * We need to catch the early Alchemy SOCs with
  1532. * the write-only co_config.od bit and set it back to one on:
  1533. * Au1000 rev DA, HA, HB; Au1100 AB, BA, BC, Au1500 AB
  1534. */
  1535. case CPU_ALCHEMY:
  1536. au1x00_fixup_config_od();
  1537. break;
  1538. case PRID_IMP_PR4450:
  1539. nxp_pr4450_fixup_config();
  1540. break;
  1541. }
  1542. }
  1543. static void r4k_cache_error_setup(void)
  1544. {
  1545. extern char __weak except_vec2_generic;
  1546. extern char __weak except_vec2_sb1;
  1547. switch (current_cpu_type()) {
  1548. case CPU_SB1:
  1549. case CPU_SB1A:
  1550. set_uncached_handler(0x100, &except_vec2_sb1, 0x80);
  1551. break;
  1552. default:
  1553. set_uncached_handler(0x100, &except_vec2_generic, 0x80);
  1554. break;
  1555. }
  1556. }
  1557. void r4k_cache_init(void)
  1558. {
  1559. extern void build_clear_page(void);
  1560. extern void build_copy_page(void);
  1561. struct cpuinfo_mips *c = &current_cpu_data;
  1562. probe_pcache();
  1563. probe_vcache();
  1564. setup_scache();
  1565. r4k_blast_dcache_page_setup();
  1566. r4k_blast_dcache_page_indexed_setup();
  1567. r4k_blast_dcache_setup();
  1568. r4k_blast_icache_page_setup();
  1569. r4k_blast_icache_page_indexed_setup();
  1570. r4k_blast_icache_setup();
  1571. r4k_blast_scache_page_setup();
  1572. r4k_blast_scache_page_indexed_setup();
  1573. r4k_blast_scache_setup();
  1574. r4k_blast_scache_node_setup();
  1575. #ifdef CONFIG_EVA
  1576. r4k_blast_dcache_user_page_setup();
  1577. r4k_blast_icache_user_page_setup();
  1578. #endif
  1579. /*
  1580. * Some MIPS32 and MIPS64 processors have physically indexed caches.
  1581. * This code supports virtually indexed processors and will be
  1582. * unnecessarily inefficient on physically indexed processors.
  1583. */
  1584. if (c->dcache.linesz && cpu_has_dc_aliases)
  1585. shm_align_mask = max_t( unsigned long,
  1586. c->dcache.sets * c->dcache.linesz - 1,
  1587. PAGE_SIZE - 1);
  1588. else
  1589. shm_align_mask = PAGE_SIZE-1;
  1590. __flush_cache_vmap = r4k__flush_cache_vmap;
  1591. __flush_cache_vunmap = r4k__flush_cache_vunmap;
  1592. flush_cache_all = cache_noop;
  1593. __flush_cache_all = r4k___flush_cache_all;
  1594. flush_cache_mm = r4k_flush_cache_mm;
  1595. flush_cache_page = r4k_flush_cache_page;
  1596. flush_cache_range = r4k_flush_cache_range;
  1597. __flush_kernel_vmap_range = r4k_flush_kernel_vmap_range;
  1598. flush_icache_all = r4k_flush_icache_all;
  1599. local_flush_data_cache_page = local_r4k_flush_data_cache_page;
  1600. flush_data_cache_page = r4k_flush_data_cache_page;
  1601. flush_icache_range = r4k_flush_icache_range;
  1602. local_flush_icache_range = local_r4k_flush_icache_range;
  1603. __flush_icache_user_range = r4k_flush_icache_user_range;
  1604. __local_flush_icache_user_range = local_r4k_flush_icache_user_range;
  1605. #ifdef CONFIG_DMA_NONCOHERENT
  1606. if (dma_default_coherent) {
  1607. _dma_cache_wback_inv = (void *)cache_noop;
  1608. _dma_cache_wback = (void *)cache_noop;
  1609. _dma_cache_inv = (void *)cache_noop;
  1610. } else {
  1611. _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
  1612. _dma_cache_wback = r4k_dma_cache_wback_inv;
  1613. _dma_cache_inv = r4k_dma_cache_inv;
  1614. }
  1615. #endif /* CONFIG_DMA_NONCOHERENT */
  1616. build_clear_page();
  1617. build_copy_page();
  1618. /*
  1619. * We want to run CMP kernels on core with and without coherent
  1620. * caches. Therefore, do not use CONFIG_MIPS_CMP to decide whether
  1621. * or not to flush caches.
  1622. */
  1623. local_r4k___flush_cache_all(NULL);
  1624. coherency_setup();
  1625. board_cache_error_setup = r4k_cache_error_setup;
  1626. /*
  1627. * Per-CPU overrides
  1628. */
  1629. switch (current_cpu_type()) {
  1630. case CPU_BMIPS4350:
  1631. case CPU_BMIPS4380:
  1632. /* No IPI is needed because all CPUs share the same D$ */
  1633. flush_data_cache_page = r4k_blast_dcache_page;
  1634. break;
  1635. case CPU_BMIPS5000:
  1636. /* We lose our superpowers if L2 is disabled */
  1637. if (c->scache.flags & MIPS_CACHE_NOT_PRESENT)
  1638. break;
  1639. /* I$ fills from D$ just by emptying the write buffers */
  1640. flush_cache_page = (void *)b5k_instruction_hazard;
  1641. flush_cache_range = (void *)b5k_instruction_hazard;
  1642. local_flush_data_cache_page = (void *)b5k_instruction_hazard;
  1643. flush_data_cache_page = (void *)b5k_instruction_hazard;
  1644. flush_icache_range = (void *)b5k_instruction_hazard;
  1645. local_flush_icache_range = (void *)b5k_instruction_hazard;
  1646. /* Optimization: an L2 flush implicitly flushes the L1 */
  1647. current_cpu_data.options |= MIPS_CPU_INCLUSIVE_CACHES;
  1648. break;
  1649. case CPU_LOONGSON64:
  1650. /* Loongson-3 maintains cache coherency by hardware */
  1651. __flush_cache_all = cache_noop;
  1652. __flush_cache_vmap = cache_noop;
  1653. __flush_cache_vunmap = cache_noop;
  1654. __flush_kernel_vmap_range = (void *)cache_noop;
  1655. flush_cache_mm = (void *)cache_noop;
  1656. flush_cache_page = (void *)cache_noop;
  1657. flush_cache_range = (void *)cache_noop;
  1658. flush_icache_all = (void *)cache_noop;
  1659. flush_data_cache_page = (void *)cache_noop;
  1660. local_flush_data_cache_page = (void *)cache_noop;
  1661. break;
  1662. }
  1663. }
  1664. static int r4k_cache_pm_notifier(struct notifier_block *self, unsigned long cmd,
  1665. void *v)
  1666. {
  1667. switch (cmd) {
  1668. case CPU_PM_ENTER_FAILED:
  1669. case CPU_PM_EXIT:
  1670. coherency_setup();
  1671. break;
  1672. }
  1673. return NOTIFY_OK;
  1674. }
  1675. static struct notifier_block r4k_cache_pm_notifier_block = {
  1676. .notifier_call = r4k_cache_pm_notifier,
  1677. };
  1678. int __init r4k_cache_init_pm(void)
  1679. {
  1680. return cpu_pm_register_notifier(&r4k_cache_pm_notifier_block);
  1681. }
  1682. arch_initcall(r4k_cache_init_pm);