c-r4k.c 47 KB

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