r4kcache.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. * Inline assembly cache operations.
  7. *
  8. * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
  9. * Copyright (C) 1997 - 2002 Ralf Baechle (ralf@gnu.org)
  10. * Copyright (C) 2004 Ralf Baechle (ralf@linux-mips.org)
  11. */
  12. #ifndef _ASM_R4KCACHE_H
  13. #define _ASM_R4KCACHE_H
  14. #include <linux/stringify.h>
  15. #include <asm/asm.h>
  16. #include <asm/cacheops.h>
  17. #include <asm/compiler.h>
  18. #include <asm/cpu-features.h>
  19. #include <asm/cpu-type.h>
  20. #include <asm/mipsmtregs.h>
  21. #include <asm/uaccess.h> /* for segment_eq() */
  22. extern void (*r4k_blast_dcache)(void);
  23. extern void (*r4k_blast_icache)(void);
  24. /*
  25. * This macro return a properly sign-extended address suitable as base address
  26. * for indexed cache operations. Two issues here:
  27. *
  28. * - The MIPS32 and MIPS64 specs permit an implementation to directly derive
  29. * the index bits from the virtual address. This breaks with tradition
  30. * set by the R4000. To keep unpleasant surprises from happening we pick
  31. * an address in KSEG0 / CKSEG0.
  32. * - We need a properly sign extended address for 64-bit code. To get away
  33. * without ifdefs we let the compiler do it by a type cast.
  34. */
  35. #define INDEX_BASE CKSEG0
  36. #define cache_op(op,addr) \
  37. __asm__ __volatile__( \
  38. " .set push \n" \
  39. " .set noreorder \n" \
  40. " .set "MIPS_ISA_ARCH_LEVEL" \n" \
  41. " cache %0, %1 \n" \
  42. " .set pop \n" \
  43. : \
  44. : "i" (op), "R" (*(unsigned char *)(addr)))
  45. #ifdef CONFIG_MIPS_MT
  46. #define __iflush_prologue \
  47. unsigned long redundance; \
  48. extern int mt_n_iflushes; \
  49. for (redundance = 0; redundance < mt_n_iflushes; redundance++) {
  50. #define __iflush_epilogue \
  51. }
  52. #define __dflush_prologue \
  53. unsigned long redundance; \
  54. extern int mt_n_dflushes; \
  55. for (redundance = 0; redundance < mt_n_dflushes; redundance++) {
  56. #define __dflush_epilogue \
  57. }
  58. #define __inv_dflush_prologue __dflush_prologue
  59. #define __inv_dflush_epilogue __dflush_epilogue
  60. #define __sflush_prologue {
  61. #define __sflush_epilogue }
  62. #define __inv_sflush_prologue __sflush_prologue
  63. #define __inv_sflush_epilogue __sflush_epilogue
  64. #else /* CONFIG_MIPS_MT */
  65. #define __iflush_prologue {
  66. #define __iflush_epilogue }
  67. #define __dflush_prologue {
  68. #define __dflush_epilogue }
  69. #define __inv_dflush_prologue {
  70. #define __inv_dflush_epilogue }
  71. #define __sflush_prologue {
  72. #define __sflush_epilogue }
  73. #define __inv_sflush_prologue {
  74. #define __inv_sflush_epilogue }
  75. #endif /* CONFIG_MIPS_MT */
  76. static inline void flush_icache_line_indexed(unsigned long addr)
  77. {
  78. __iflush_prologue
  79. cache_op(Index_Invalidate_I, addr);
  80. __iflush_epilogue
  81. }
  82. static inline void flush_dcache_line_indexed(unsigned long addr)
  83. {
  84. __dflush_prologue
  85. cache_op(Index_Writeback_Inv_D, addr);
  86. __dflush_epilogue
  87. }
  88. static inline void flush_scache_line_indexed(unsigned long addr)
  89. {
  90. cache_op(Index_Writeback_Inv_SD, addr);
  91. }
  92. static inline void flush_icache_line(unsigned long addr)
  93. {
  94. __iflush_prologue
  95. switch (boot_cpu_type()) {
  96. case CPU_LOONGSON2:
  97. cache_op(Hit_Invalidate_I_Loongson2, addr);
  98. break;
  99. default:
  100. cache_op(Hit_Invalidate_I, addr);
  101. break;
  102. }
  103. __iflush_epilogue
  104. }
  105. static inline void flush_dcache_line(unsigned long addr)
  106. {
  107. __dflush_prologue
  108. cache_op(Hit_Writeback_Inv_D, addr);
  109. __dflush_epilogue
  110. }
  111. static inline void invalidate_dcache_line(unsigned long addr)
  112. {
  113. __dflush_prologue
  114. cache_op(Hit_Invalidate_D, addr);
  115. __dflush_epilogue
  116. }
  117. static inline void invalidate_scache_line(unsigned long addr)
  118. {
  119. cache_op(Hit_Invalidate_SD, addr);
  120. }
  121. static inline void flush_scache_line(unsigned long addr)
  122. {
  123. cache_op(Hit_Writeback_Inv_SD, addr);
  124. }
  125. #define protected_cache_op(op,addr) \
  126. __asm__ __volatile__( \
  127. " .set push \n" \
  128. " .set noreorder \n" \
  129. " .set "MIPS_ISA_ARCH_LEVEL" \n" \
  130. "1: cache %0, (%1) \n" \
  131. "2: .set pop \n" \
  132. " .section __ex_table,\"a\" \n" \
  133. " "STR(PTR)" 1b, 2b \n" \
  134. " .previous" \
  135. : \
  136. : "i" (op), "r" (addr))
  137. #define protected_cachee_op(op,addr) \
  138. __asm__ __volatile__( \
  139. " .set push \n" \
  140. " .set noreorder \n" \
  141. " .set mips0 \n" \
  142. " .set eva \n" \
  143. "1: cachee %0, (%1) \n" \
  144. "2: .set pop \n" \
  145. " .section __ex_table,\"a\" \n" \
  146. " "STR(PTR)" 1b, 2b \n" \
  147. " .previous" \
  148. : \
  149. : "i" (op), "r" (addr))
  150. /*
  151. * The next two are for badland addresses like signal trampolines.
  152. */
  153. static inline void protected_flush_icache_line(unsigned long addr)
  154. {
  155. switch (boot_cpu_type()) {
  156. case CPU_LOONGSON2:
  157. protected_cache_op(Hit_Invalidate_I_Loongson2, addr);
  158. break;
  159. default:
  160. #ifdef CONFIG_EVA
  161. protected_cachee_op(Hit_Invalidate_I, addr);
  162. #else
  163. protected_cache_op(Hit_Invalidate_I, addr);
  164. #endif
  165. break;
  166. }
  167. }
  168. /*
  169. * R10000 / R12000 hazard - these processors don't support the Hit_Writeback_D
  170. * cacheop so we use Hit_Writeback_Inv_D which is supported by all R4000-style
  171. * caches. We're talking about one cacheline unnecessarily getting invalidated
  172. * here so the penalty isn't overly hard.
  173. */
  174. static inline void protected_writeback_dcache_line(unsigned long addr)
  175. {
  176. #ifdef CONFIG_EVA
  177. protected_cachee_op(Hit_Writeback_Inv_D, addr);
  178. #else
  179. protected_cache_op(Hit_Writeback_Inv_D, addr);
  180. #endif
  181. }
  182. static inline void protected_writeback_scache_line(unsigned long addr)
  183. {
  184. #ifdef CONFIG_EVA
  185. protected_cachee_op(Hit_Writeback_Inv_SD, addr);
  186. #else
  187. protected_cache_op(Hit_Writeback_Inv_SD, addr);
  188. #endif
  189. }
  190. /*
  191. * This one is RM7000-specific
  192. */
  193. static inline void invalidate_tcache_page(unsigned long addr)
  194. {
  195. cache_op(Page_Invalidate_T, addr);
  196. }
  197. #ifndef CONFIG_CPU_MIPSR6
  198. #define cache16_unroll32(base,op) \
  199. __asm__ __volatile__( \
  200. " .set push \n" \
  201. " .set noreorder \n" \
  202. " .set mips3 \n" \
  203. " cache %1, 0x000(%0); cache %1, 0x010(%0) \n" \
  204. " cache %1, 0x020(%0); cache %1, 0x030(%0) \n" \
  205. " cache %1, 0x040(%0); cache %1, 0x050(%0) \n" \
  206. " cache %1, 0x060(%0); cache %1, 0x070(%0) \n" \
  207. " cache %1, 0x080(%0); cache %1, 0x090(%0) \n" \
  208. " cache %1, 0x0a0(%0); cache %1, 0x0b0(%0) \n" \
  209. " cache %1, 0x0c0(%0); cache %1, 0x0d0(%0) \n" \
  210. " cache %1, 0x0e0(%0); cache %1, 0x0f0(%0) \n" \
  211. " cache %1, 0x100(%0); cache %1, 0x110(%0) \n" \
  212. " cache %1, 0x120(%0); cache %1, 0x130(%0) \n" \
  213. " cache %1, 0x140(%0); cache %1, 0x150(%0) \n" \
  214. " cache %1, 0x160(%0); cache %1, 0x170(%0) \n" \
  215. " cache %1, 0x180(%0); cache %1, 0x190(%0) \n" \
  216. " cache %1, 0x1a0(%0); cache %1, 0x1b0(%0) \n" \
  217. " cache %1, 0x1c0(%0); cache %1, 0x1d0(%0) \n" \
  218. " cache %1, 0x1e0(%0); cache %1, 0x1f0(%0) \n" \
  219. " .set pop \n" \
  220. : \
  221. : "r" (base), \
  222. "i" (op));
  223. #define cache32_unroll32(base,op) \
  224. __asm__ __volatile__( \
  225. " .set push \n" \
  226. " .set noreorder \n" \
  227. " .set mips3 \n" \
  228. " cache %1, 0x000(%0); cache %1, 0x020(%0) \n" \
  229. " cache %1, 0x040(%0); cache %1, 0x060(%0) \n" \
  230. " cache %1, 0x080(%0); cache %1, 0x0a0(%0) \n" \
  231. " cache %1, 0x0c0(%0); cache %1, 0x0e0(%0) \n" \
  232. " cache %1, 0x100(%0); cache %1, 0x120(%0) \n" \
  233. " cache %1, 0x140(%0); cache %1, 0x160(%0) \n" \
  234. " cache %1, 0x180(%0); cache %1, 0x1a0(%0) \n" \
  235. " cache %1, 0x1c0(%0); cache %1, 0x1e0(%0) \n" \
  236. " cache %1, 0x200(%0); cache %1, 0x220(%0) \n" \
  237. " cache %1, 0x240(%0); cache %1, 0x260(%0) \n" \
  238. " cache %1, 0x280(%0); cache %1, 0x2a0(%0) \n" \
  239. " cache %1, 0x2c0(%0); cache %1, 0x2e0(%0) \n" \
  240. " cache %1, 0x300(%0); cache %1, 0x320(%0) \n" \
  241. " cache %1, 0x340(%0); cache %1, 0x360(%0) \n" \
  242. " cache %1, 0x380(%0); cache %1, 0x3a0(%0) \n" \
  243. " cache %1, 0x3c0(%0); cache %1, 0x3e0(%0) \n" \
  244. " .set pop \n" \
  245. : \
  246. : "r" (base), \
  247. "i" (op));
  248. #define cache64_unroll32(base,op) \
  249. __asm__ __volatile__( \
  250. " .set push \n" \
  251. " .set noreorder \n" \
  252. " .set mips3 \n" \
  253. " cache %1, 0x000(%0); cache %1, 0x040(%0) \n" \
  254. " cache %1, 0x080(%0); cache %1, 0x0c0(%0) \n" \
  255. " cache %1, 0x100(%0); cache %1, 0x140(%0) \n" \
  256. " cache %1, 0x180(%0); cache %1, 0x1c0(%0) \n" \
  257. " cache %1, 0x200(%0); cache %1, 0x240(%0) \n" \
  258. " cache %1, 0x280(%0); cache %1, 0x2c0(%0) \n" \
  259. " cache %1, 0x300(%0); cache %1, 0x340(%0) \n" \
  260. " cache %1, 0x380(%0); cache %1, 0x3c0(%0) \n" \
  261. " cache %1, 0x400(%0); cache %1, 0x440(%0) \n" \
  262. " cache %1, 0x480(%0); cache %1, 0x4c0(%0) \n" \
  263. " cache %1, 0x500(%0); cache %1, 0x540(%0) \n" \
  264. " cache %1, 0x580(%0); cache %1, 0x5c0(%0) \n" \
  265. " cache %1, 0x600(%0); cache %1, 0x640(%0) \n" \
  266. " cache %1, 0x680(%0); cache %1, 0x6c0(%0) \n" \
  267. " cache %1, 0x700(%0); cache %1, 0x740(%0) \n" \
  268. " cache %1, 0x780(%0); cache %1, 0x7c0(%0) \n" \
  269. " .set pop \n" \
  270. : \
  271. : "r" (base), \
  272. "i" (op));
  273. #define cache128_unroll32(base,op) \
  274. __asm__ __volatile__( \
  275. " .set push \n" \
  276. " .set noreorder \n" \
  277. " .set mips3 \n" \
  278. " cache %1, 0x000(%0); cache %1, 0x080(%0) \n" \
  279. " cache %1, 0x100(%0); cache %1, 0x180(%0) \n" \
  280. " cache %1, 0x200(%0); cache %1, 0x280(%0) \n" \
  281. " cache %1, 0x300(%0); cache %1, 0x380(%0) \n" \
  282. " cache %1, 0x400(%0); cache %1, 0x480(%0) \n" \
  283. " cache %1, 0x500(%0); cache %1, 0x580(%0) \n" \
  284. " cache %1, 0x600(%0); cache %1, 0x680(%0) \n" \
  285. " cache %1, 0x700(%0); cache %1, 0x780(%0) \n" \
  286. " cache %1, 0x800(%0); cache %1, 0x880(%0) \n" \
  287. " cache %1, 0x900(%0); cache %1, 0x980(%0) \n" \
  288. " cache %1, 0xa00(%0); cache %1, 0xa80(%0) \n" \
  289. " cache %1, 0xb00(%0); cache %1, 0xb80(%0) \n" \
  290. " cache %1, 0xc00(%0); cache %1, 0xc80(%0) \n" \
  291. " cache %1, 0xd00(%0); cache %1, 0xd80(%0) \n" \
  292. " cache %1, 0xe00(%0); cache %1, 0xe80(%0) \n" \
  293. " cache %1, 0xf00(%0); cache %1, 0xf80(%0) \n" \
  294. " .set pop \n" \
  295. : \
  296. : "r" (base), \
  297. "i" (op));
  298. #else
  299. /*
  300. * MIPS R6 changed the cache opcode and moved to a 8-bit offset field.
  301. * This means we now need to increment the base register before we flush
  302. * more cache lines
  303. */
  304. #define cache16_unroll32(base,op) \
  305. __asm__ __volatile__( \
  306. " .set push\n" \
  307. " .set noreorder\n" \
  308. " .set mips64r6\n" \
  309. " .set noat\n" \
  310. " cache %1, 0x000(%0); cache %1, 0x010(%0)\n" \
  311. " cache %1, 0x020(%0); cache %1, 0x030(%0)\n" \
  312. " cache %1, 0x040(%0); cache %1, 0x050(%0)\n" \
  313. " cache %1, 0x060(%0); cache %1, 0x070(%0)\n" \
  314. " cache %1, 0x080(%0); cache %1, 0x090(%0)\n" \
  315. " cache %1, 0x0a0(%0); cache %1, 0x0b0(%0)\n" \
  316. " cache %1, 0x0c0(%0); cache %1, 0x0d0(%0)\n" \
  317. " cache %1, 0x0e0(%0); cache %1, 0x0f0(%0)\n" \
  318. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  319. " cache %1, 0x000($1); cache %1, 0x010($1)\n" \
  320. " cache %1, 0x020($1); cache %1, 0x030($1)\n" \
  321. " cache %1, 0x040($1); cache %1, 0x050($1)\n" \
  322. " cache %1, 0x060($1); cache %1, 0x070($1)\n" \
  323. " cache %1, 0x080($1); cache %1, 0x090($1)\n" \
  324. " cache %1, 0x0a0($1); cache %1, 0x0b0($1)\n" \
  325. " cache %1, 0x0c0($1); cache %1, 0x0d0($1)\n" \
  326. " cache %1, 0x0e0($1); cache %1, 0x0f0($1)\n" \
  327. " .set pop\n" \
  328. : \
  329. : "r" (base), \
  330. "i" (op));
  331. #define cache32_unroll32(base,op) \
  332. __asm__ __volatile__( \
  333. " .set push\n" \
  334. " .set noreorder\n" \
  335. " .set mips64r6\n" \
  336. " .set noat\n" \
  337. " cache %1, 0x000(%0); cache %1, 0x020(%0)\n" \
  338. " cache %1, 0x040(%0); cache %1, 0x060(%0)\n" \
  339. " cache %1, 0x080(%0); cache %1, 0x0a0(%0)\n" \
  340. " cache %1, 0x0c0(%0); cache %1, 0x0e0(%0)\n" \
  341. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  342. " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
  343. " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
  344. " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
  345. " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
  346. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  347. " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
  348. " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
  349. " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
  350. " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
  351. " "__stringify(LONG_ADDIU)" $1, $1, 0x100\n" \
  352. " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
  353. " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
  354. " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
  355. " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
  356. " .set pop\n" \
  357. : \
  358. : "r" (base), \
  359. "i" (op));
  360. #define cache64_unroll32(base,op) \
  361. __asm__ __volatile__( \
  362. " .set push\n" \
  363. " .set noreorder\n" \
  364. " .set mips64r6\n" \
  365. " .set noat\n" \
  366. " cache %1, 0x000(%0); cache %1, 0x040(%0)\n" \
  367. " cache %1, 0x080(%0); cache %1, 0x0c0(%0)\n" \
  368. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  369. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  370. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  371. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  372. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  373. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  374. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  375. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  376. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  377. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  378. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  379. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  380. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  381. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  382. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  383. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  384. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  385. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  386. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  387. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  388. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  389. " .set pop\n" \
  390. : \
  391. : "r" (base), \
  392. "i" (op));
  393. #define cache128_unroll32(base,op) \
  394. __asm__ __volatile__( \
  395. " .set push\n" \
  396. " .set noreorder\n" \
  397. " .set mips64r6\n" \
  398. " .set noat\n" \
  399. " cache %1, 0x000(%0); cache %1, 0x080(%0)\n" \
  400. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  401. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  402. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  403. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  404. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  405. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  406. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  407. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  408. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  409. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  410. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  411. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  412. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  413. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  414. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  415. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  416. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  417. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  418. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  419. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  420. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  421. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  422. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  423. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  424. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  425. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  426. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  427. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  428. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  429. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  430. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  431. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  432. " .set pop\n" \
  433. : \
  434. : "r" (base), \
  435. "i" (op));
  436. #endif /* CONFIG_CPU_MIPSR6 */
  437. /*
  438. * Perform the cache operation specified by op using a user mode virtual
  439. * address while in kernel mode.
  440. */
  441. #define cache16_unroll32_user(base,op) \
  442. __asm__ __volatile__( \
  443. " .set push \n" \
  444. " .set noreorder \n" \
  445. " .set mips0 \n" \
  446. " .set eva \n" \
  447. " cachee %1, 0x000(%0); cachee %1, 0x010(%0) \n" \
  448. " cachee %1, 0x020(%0); cachee %1, 0x030(%0) \n" \
  449. " cachee %1, 0x040(%0); cachee %1, 0x050(%0) \n" \
  450. " cachee %1, 0x060(%0); cachee %1, 0x070(%0) \n" \
  451. " cachee %1, 0x080(%0); cachee %1, 0x090(%0) \n" \
  452. " cachee %1, 0x0a0(%0); cachee %1, 0x0b0(%0) \n" \
  453. " cachee %1, 0x0c0(%0); cachee %1, 0x0d0(%0) \n" \
  454. " cachee %1, 0x0e0(%0); cachee %1, 0x0f0(%0) \n" \
  455. " cachee %1, 0x100(%0); cachee %1, 0x110(%0) \n" \
  456. " cachee %1, 0x120(%0); cachee %1, 0x130(%0) \n" \
  457. " cachee %1, 0x140(%0); cachee %1, 0x150(%0) \n" \
  458. " cachee %1, 0x160(%0); cachee %1, 0x170(%0) \n" \
  459. " cachee %1, 0x180(%0); cachee %1, 0x190(%0) \n" \
  460. " cachee %1, 0x1a0(%0); cachee %1, 0x1b0(%0) \n" \
  461. " cachee %1, 0x1c0(%0); cachee %1, 0x1d0(%0) \n" \
  462. " cachee %1, 0x1e0(%0); cachee %1, 0x1f0(%0) \n" \
  463. " .set pop \n" \
  464. : \
  465. : "r" (base), \
  466. "i" (op));
  467. #define cache32_unroll32_user(base, op) \
  468. __asm__ __volatile__( \
  469. " .set push \n" \
  470. " .set noreorder \n" \
  471. " .set mips0 \n" \
  472. " .set eva \n" \
  473. " cachee %1, 0x000(%0); cachee %1, 0x020(%0) \n" \
  474. " cachee %1, 0x040(%0); cachee %1, 0x060(%0) \n" \
  475. " cachee %1, 0x080(%0); cachee %1, 0x0a0(%0) \n" \
  476. " cachee %1, 0x0c0(%0); cachee %1, 0x0e0(%0) \n" \
  477. " cachee %1, 0x100(%0); cachee %1, 0x120(%0) \n" \
  478. " cachee %1, 0x140(%0); cachee %1, 0x160(%0) \n" \
  479. " cachee %1, 0x180(%0); cachee %1, 0x1a0(%0) \n" \
  480. " cachee %1, 0x1c0(%0); cachee %1, 0x1e0(%0) \n" \
  481. " cachee %1, 0x200(%0); cachee %1, 0x220(%0) \n" \
  482. " cachee %1, 0x240(%0); cachee %1, 0x260(%0) \n" \
  483. " cachee %1, 0x280(%0); cachee %1, 0x2a0(%0) \n" \
  484. " cachee %1, 0x2c0(%0); cachee %1, 0x2e0(%0) \n" \
  485. " cachee %1, 0x300(%0); cachee %1, 0x320(%0) \n" \
  486. " cachee %1, 0x340(%0); cachee %1, 0x360(%0) \n" \
  487. " cachee %1, 0x380(%0); cachee %1, 0x3a0(%0) \n" \
  488. " cachee %1, 0x3c0(%0); cachee %1, 0x3e0(%0) \n" \
  489. " .set pop \n" \
  490. : \
  491. : "r" (base), \
  492. "i" (op));
  493. #define cache64_unroll32_user(base, op) \
  494. __asm__ __volatile__( \
  495. " .set push \n" \
  496. " .set noreorder \n" \
  497. " .set mips0 \n" \
  498. " .set eva \n" \
  499. " cachee %1, 0x000(%0); cachee %1, 0x040(%0) \n" \
  500. " cachee %1, 0x080(%0); cachee %1, 0x0c0(%0) \n" \
  501. " cachee %1, 0x100(%0); cachee %1, 0x140(%0) \n" \
  502. " cachee %1, 0x180(%0); cachee %1, 0x1c0(%0) \n" \
  503. " cachee %1, 0x200(%0); cachee %1, 0x240(%0) \n" \
  504. " cachee %1, 0x280(%0); cachee %1, 0x2c0(%0) \n" \
  505. " cachee %1, 0x300(%0); cachee %1, 0x340(%0) \n" \
  506. " cachee %1, 0x380(%0); cachee %1, 0x3c0(%0) \n" \
  507. " cachee %1, 0x400(%0); cachee %1, 0x440(%0) \n" \
  508. " cachee %1, 0x480(%0); cachee %1, 0x4c0(%0) \n" \
  509. " cachee %1, 0x500(%0); cachee %1, 0x540(%0) \n" \
  510. " cachee %1, 0x580(%0); cachee %1, 0x5c0(%0) \n" \
  511. " cachee %1, 0x600(%0); cachee %1, 0x640(%0) \n" \
  512. " cachee %1, 0x680(%0); cachee %1, 0x6c0(%0) \n" \
  513. " cachee %1, 0x700(%0); cachee %1, 0x740(%0) \n" \
  514. " cachee %1, 0x780(%0); cachee %1, 0x7c0(%0) \n" \
  515. " .set pop \n" \
  516. : \
  517. : "r" (base), \
  518. "i" (op));
  519. /* build blast_xxx, blast_xxx_page, blast_xxx_page_indexed */
  520. #define __BUILD_BLAST_CACHE(pfx, desc, indexop, hitop, lsize, extra) \
  521. static inline void extra##blast_##pfx##cache##lsize(void) \
  522. { \
  523. unsigned long start = INDEX_BASE; \
  524. unsigned long end = start + current_cpu_data.desc.waysize; \
  525. unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \
  526. unsigned long ws_end = current_cpu_data.desc.ways << \
  527. current_cpu_data.desc.waybit; \
  528. unsigned long ws, addr; \
  529. \
  530. __##pfx##flush_prologue \
  531. \
  532. for (ws = 0; ws < ws_end; ws += ws_inc) \
  533. for (addr = start; addr < end; addr += lsize * 32) \
  534. cache##lsize##_unroll32(addr|ws, indexop); \
  535. \
  536. __##pfx##flush_epilogue \
  537. } \
  538. \
  539. static inline void extra##blast_##pfx##cache##lsize##_page(unsigned long page) \
  540. { \
  541. unsigned long start = page; \
  542. unsigned long end = page + PAGE_SIZE; \
  543. \
  544. __##pfx##flush_prologue \
  545. \
  546. do { \
  547. cache##lsize##_unroll32(start, hitop); \
  548. start += lsize * 32; \
  549. } while (start < end); \
  550. \
  551. __##pfx##flush_epilogue \
  552. } \
  553. \
  554. static inline void extra##blast_##pfx##cache##lsize##_page_indexed(unsigned long page) \
  555. { \
  556. unsigned long indexmask = current_cpu_data.desc.waysize - 1; \
  557. unsigned long start = INDEX_BASE + (page & indexmask); \
  558. unsigned long end = start + PAGE_SIZE; \
  559. unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \
  560. unsigned long ws_end = current_cpu_data.desc.ways << \
  561. current_cpu_data.desc.waybit; \
  562. unsigned long ws, addr; \
  563. \
  564. __##pfx##flush_prologue \
  565. \
  566. for (ws = 0; ws < ws_end; ws += ws_inc) \
  567. for (addr = start; addr < end; addr += lsize * 32) \
  568. cache##lsize##_unroll32(addr|ws, indexop); \
  569. \
  570. __##pfx##flush_epilogue \
  571. }
  572. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 16, )
  573. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16, )
  574. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16, )
  575. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 32, )
  576. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32, )
  577. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I_Loongson2, 32, loongson2_)
  578. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32, )
  579. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 64, )
  580. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64, )
  581. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 64, )
  582. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 128, )
  583. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 128, )
  584. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128, )
  585. __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 16, )
  586. __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 32, )
  587. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 16, )
  588. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 32, )
  589. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 64, )
  590. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 128, )
  591. #define __BUILD_BLAST_USER_CACHE(pfx, desc, indexop, hitop, lsize) \
  592. static inline void blast_##pfx##cache##lsize##_user_page(unsigned long page) \
  593. { \
  594. unsigned long start = page; \
  595. unsigned long end = page + PAGE_SIZE; \
  596. \
  597. __##pfx##flush_prologue \
  598. \
  599. do { \
  600. cache##lsize##_unroll32_user(start, hitop); \
  601. start += lsize * 32; \
  602. } while (start < end); \
  603. \
  604. __##pfx##flush_epilogue \
  605. }
  606. __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
  607. 16)
  608. __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16)
  609. __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
  610. 32)
  611. __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32)
  612. __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
  613. 64)
  614. __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64)
  615. /* build blast_xxx_range, protected_blast_xxx_range */
  616. #define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot, extra) \
  617. static inline void prot##extra##blast_##pfx##cache##_range(unsigned long start, \
  618. unsigned long end) \
  619. { \
  620. unsigned long lsize = cpu_##desc##_line_size(); \
  621. unsigned long addr = start & ~(lsize - 1); \
  622. unsigned long aend = (end - 1) & ~(lsize - 1); \
  623. \
  624. __##pfx##flush_prologue \
  625. \
  626. while (1) { \
  627. prot##cache_op(hitop, addr); \
  628. if (addr == aend) \
  629. break; \
  630. addr += lsize; \
  631. } \
  632. \
  633. __##pfx##flush_epilogue \
  634. }
  635. #ifndef CONFIG_EVA
  636. __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_, )
  637. __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_, )
  638. #else
  639. #define __BUILD_PROT_BLAST_CACHE_RANGE(pfx, desc, hitop) \
  640. static inline void protected_blast_##pfx##cache##_range(unsigned long start,\
  641. unsigned long end) \
  642. { \
  643. unsigned long lsize = cpu_##desc##_line_size(); \
  644. unsigned long addr = start & ~(lsize - 1); \
  645. unsigned long aend = (end - 1) & ~(lsize - 1); \
  646. \
  647. __##pfx##flush_prologue \
  648. \
  649. if (segment_eq(get_fs(), USER_DS)) { \
  650. while (1) { \
  651. protected_cachee_op(hitop, addr); \
  652. if (addr == aend) \
  653. break; \
  654. addr += lsize; \
  655. } \
  656. } else { \
  657. while (1) { \
  658. protected_cache_op(hitop, addr); \
  659. if (addr == aend) \
  660. break; \
  661. addr += lsize; \
  662. } \
  663. \
  664. } \
  665. __##pfx##flush_epilogue \
  666. }
  667. __BUILD_PROT_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D)
  668. __BUILD_PROT_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I)
  669. #endif
  670. __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_, )
  671. __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I_Loongson2, \
  672. protected_, loongson2_)
  673. __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, , )
  674. __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, , )
  675. __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, , )
  676. /* blast_inv_dcache_range */
  677. __BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, , )
  678. __BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, , )
  679. #endif /* _ASM_R4KCACHE_H */