c-r4k.c 53 KB

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