r4kcache.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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 <linux/uaccess.h> /* for uaccess_kernel() */
  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. ({ \
  127. int __err = 0; \
  128. __asm__ __volatile__( \
  129. " .set push \n" \
  130. " .set noreorder \n" \
  131. " .set "MIPS_ISA_ARCH_LEVEL" \n" \
  132. "1: cache %1, (%2) \n" \
  133. "2: .insn \n" \
  134. " .set pop \n" \
  135. " .section .fixup,\"ax\" \n" \
  136. "3: li %0, %3 \n" \
  137. " j 2b \n" \
  138. " .previous \n" \
  139. " .section __ex_table,\"a\" \n" \
  140. " "STR(PTR)" 1b, 3b \n" \
  141. " .previous" \
  142. : "+r" (__err) \
  143. : "i" (op), "r" (addr), "i" (-EFAULT)); \
  144. __err; \
  145. })
  146. #define protected_cachee_op(op,addr) \
  147. ({ \
  148. int __err = 0; \
  149. __asm__ __volatile__( \
  150. " .set push \n" \
  151. " .set noreorder \n" \
  152. " .set mips0 \n" \
  153. " .set eva \n" \
  154. "1: cachee %1, (%2) \n" \
  155. "2: .insn \n" \
  156. " .set pop \n" \
  157. " .section .fixup,\"ax\" \n" \
  158. "3: li %0, %3 \n" \
  159. " j 2b \n" \
  160. " .previous \n" \
  161. " .section __ex_table,\"a\" \n" \
  162. " "STR(PTR)" 1b, 3b \n" \
  163. " .previous" \
  164. : "+r" (__err) \
  165. : "i" (op), "r" (addr), "i" (-EFAULT)); \
  166. __err; \
  167. })
  168. /*
  169. * The next two are for badland addresses like signal trampolines.
  170. */
  171. static inline int protected_flush_icache_line(unsigned long addr)
  172. {
  173. switch (boot_cpu_type()) {
  174. case CPU_LOONGSON2:
  175. return protected_cache_op(Hit_Invalidate_I_Loongson2, addr);
  176. default:
  177. #ifdef CONFIG_EVA
  178. return protected_cachee_op(Hit_Invalidate_I, addr);
  179. #else
  180. return protected_cache_op(Hit_Invalidate_I, addr);
  181. #endif
  182. }
  183. }
  184. /*
  185. * R10000 / R12000 hazard - these processors don't support the Hit_Writeback_D
  186. * cacheop so we use Hit_Writeback_Inv_D which is supported by all R4000-style
  187. * caches. We're talking about one cacheline unnecessarily getting invalidated
  188. * here so the penalty isn't overly hard.
  189. */
  190. static inline int protected_writeback_dcache_line(unsigned long addr)
  191. {
  192. #ifdef CONFIG_EVA
  193. return protected_cachee_op(Hit_Writeback_Inv_D, addr);
  194. #else
  195. return protected_cache_op(Hit_Writeback_Inv_D, addr);
  196. #endif
  197. }
  198. static inline int protected_writeback_scache_line(unsigned long addr)
  199. {
  200. #ifdef CONFIG_EVA
  201. return protected_cachee_op(Hit_Writeback_Inv_SD, addr);
  202. #else
  203. return protected_cache_op(Hit_Writeback_Inv_SD, addr);
  204. #endif
  205. }
  206. /*
  207. * This one is RM7000-specific
  208. */
  209. static inline void invalidate_tcache_page(unsigned long addr)
  210. {
  211. cache_op(Page_Invalidate_T, addr);
  212. }
  213. #ifndef CONFIG_CPU_MIPSR6
  214. #define cache16_unroll32(base,op) \
  215. __asm__ __volatile__( \
  216. " .set push \n" \
  217. " .set noreorder \n" \
  218. " .set mips3 \n" \
  219. " cache %1, 0x000(%0); cache %1, 0x010(%0) \n" \
  220. " cache %1, 0x020(%0); cache %1, 0x030(%0) \n" \
  221. " cache %1, 0x040(%0); cache %1, 0x050(%0) \n" \
  222. " cache %1, 0x060(%0); cache %1, 0x070(%0) \n" \
  223. " cache %1, 0x080(%0); cache %1, 0x090(%0) \n" \
  224. " cache %1, 0x0a0(%0); cache %1, 0x0b0(%0) \n" \
  225. " cache %1, 0x0c0(%0); cache %1, 0x0d0(%0) \n" \
  226. " cache %1, 0x0e0(%0); cache %1, 0x0f0(%0) \n" \
  227. " cache %1, 0x100(%0); cache %1, 0x110(%0) \n" \
  228. " cache %1, 0x120(%0); cache %1, 0x130(%0) \n" \
  229. " cache %1, 0x140(%0); cache %1, 0x150(%0) \n" \
  230. " cache %1, 0x160(%0); cache %1, 0x170(%0) \n" \
  231. " cache %1, 0x180(%0); cache %1, 0x190(%0) \n" \
  232. " cache %1, 0x1a0(%0); cache %1, 0x1b0(%0) \n" \
  233. " cache %1, 0x1c0(%0); cache %1, 0x1d0(%0) \n" \
  234. " cache %1, 0x1e0(%0); cache %1, 0x1f0(%0) \n" \
  235. " .set pop \n" \
  236. : \
  237. : "r" (base), \
  238. "i" (op));
  239. #define cache32_unroll32(base,op) \
  240. __asm__ __volatile__( \
  241. " .set push \n" \
  242. " .set noreorder \n" \
  243. " .set mips3 \n" \
  244. " cache %1, 0x000(%0); cache %1, 0x020(%0) \n" \
  245. " cache %1, 0x040(%0); cache %1, 0x060(%0) \n" \
  246. " cache %1, 0x080(%0); cache %1, 0x0a0(%0) \n" \
  247. " cache %1, 0x0c0(%0); cache %1, 0x0e0(%0) \n" \
  248. " cache %1, 0x100(%0); cache %1, 0x120(%0) \n" \
  249. " cache %1, 0x140(%0); cache %1, 0x160(%0) \n" \
  250. " cache %1, 0x180(%0); cache %1, 0x1a0(%0) \n" \
  251. " cache %1, 0x1c0(%0); cache %1, 0x1e0(%0) \n" \
  252. " cache %1, 0x200(%0); cache %1, 0x220(%0) \n" \
  253. " cache %1, 0x240(%0); cache %1, 0x260(%0) \n" \
  254. " cache %1, 0x280(%0); cache %1, 0x2a0(%0) \n" \
  255. " cache %1, 0x2c0(%0); cache %1, 0x2e0(%0) \n" \
  256. " cache %1, 0x300(%0); cache %1, 0x320(%0) \n" \
  257. " cache %1, 0x340(%0); cache %1, 0x360(%0) \n" \
  258. " cache %1, 0x380(%0); cache %1, 0x3a0(%0) \n" \
  259. " cache %1, 0x3c0(%0); cache %1, 0x3e0(%0) \n" \
  260. " .set pop \n" \
  261. : \
  262. : "r" (base), \
  263. "i" (op));
  264. #define cache64_unroll32(base,op) \
  265. __asm__ __volatile__( \
  266. " .set push \n" \
  267. " .set noreorder \n" \
  268. " .set mips3 \n" \
  269. " cache %1, 0x000(%0); cache %1, 0x040(%0) \n" \
  270. " cache %1, 0x080(%0); cache %1, 0x0c0(%0) \n" \
  271. " cache %1, 0x100(%0); cache %1, 0x140(%0) \n" \
  272. " cache %1, 0x180(%0); cache %1, 0x1c0(%0) \n" \
  273. " cache %1, 0x200(%0); cache %1, 0x240(%0) \n" \
  274. " cache %1, 0x280(%0); cache %1, 0x2c0(%0) \n" \
  275. " cache %1, 0x300(%0); cache %1, 0x340(%0) \n" \
  276. " cache %1, 0x380(%0); cache %1, 0x3c0(%0) \n" \
  277. " cache %1, 0x400(%0); cache %1, 0x440(%0) \n" \
  278. " cache %1, 0x480(%0); cache %1, 0x4c0(%0) \n" \
  279. " cache %1, 0x500(%0); cache %1, 0x540(%0) \n" \
  280. " cache %1, 0x580(%0); cache %1, 0x5c0(%0) \n" \
  281. " cache %1, 0x600(%0); cache %1, 0x640(%0) \n" \
  282. " cache %1, 0x680(%0); cache %1, 0x6c0(%0) \n" \
  283. " cache %1, 0x700(%0); cache %1, 0x740(%0) \n" \
  284. " cache %1, 0x780(%0); cache %1, 0x7c0(%0) \n" \
  285. " .set pop \n" \
  286. : \
  287. : "r" (base), \
  288. "i" (op));
  289. #define cache128_unroll32(base,op) \
  290. __asm__ __volatile__( \
  291. " .set push \n" \
  292. " .set noreorder \n" \
  293. " .set mips3 \n" \
  294. " cache %1, 0x000(%0); cache %1, 0x080(%0) \n" \
  295. " cache %1, 0x100(%0); cache %1, 0x180(%0) \n" \
  296. " cache %1, 0x200(%0); cache %1, 0x280(%0) \n" \
  297. " cache %1, 0x300(%0); cache %1, 0x380(%0) \n" \
  298. " cache %1, 0x400(%0); cache %1, 0x480(%0) \n" \
  299. " cache %1, 0x500(%0); cache %1, 0x580(%0) \n" \
  300. " cache %1, 0x600(%0); cache %1, 0x680(%0) \n" \
  301. " cache %1, 0x700(%0); cache %1, 0x780(%0) \n" \
  302. " cache %1, 0x800(%0); cache %1, 0x880(%0) \n" \
  303. " cache %1, 0x900(%0); cache %1, 0x980(%0) \n" \
  304. " cache %1, 0xa00(%0); cache %1, 0xa80(%0) \n" \
  305. " cache %1, 0xb00(%0); cache %1, 0xb80(%0) \n" \
  306. " cache %1, 0xc00(%0); cache %1, 0xc80(%0) \n" \
  307. " cache %1, 0xd00(%0); cache %1, 0xd80(%0) \n" \
  308. " cache %1, 0xe00(%0); cache %1, 0xe80(%0) \n" \
  309. " cache %1, 0xf00(%0); cache %1, 0xf80(%0) \n" \
  310. " .set pop \n" \
  311. : \
  312. : "r" (base), \
  313. "i" (op));
  314. #else
  315. /*
  316. * MIPS R6 changed the cache opcode and moved to a 8-bit offset field.
  317. * This means we now need to increment the base register before we flush
  318. * more cache lines
  319. */
  320. #define cache16_unroll32(base,op) \
  321. __asm__ __volatile__( \
  322. " .set push\n" \
  323. " .set noreorder\n" \
  324. " .set mips64r6\n" \
  325. " .set noat\n" \
  326. " cache %1, 0x000(%0); cache %1, 0x010(%0)\n" \
  327. " cache %1, 0x020(%0); cache %1, 0x030(%0)\n" \
  328. " cache %1, 0x040(%0); cache %1, 0x050(%0)\n" \
  329. " cache %1, 0x060(%0); cache %1, 0x070(%0)\n" \
  330. " cache %1, 0x080(%0); cache %1, 0x090(%0)\n" \
  331. " cache %1, 0x0a0(%0); cache %1, 0x0b0(%0)\n" \
  332. " cache %1, 0x0c0(%0); cache %1, 0x0d0(%0)\n" \
  333. " cache %1, 0x0e0(%0); cache %1, 0x0f0(%0)\n" \
  334. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  335. " cache %1, 0x000($1); cache %1, 0x010($1)\n" \
  336. " cache %1, 0x020($1); cache %1, 0x030($1)\n" \
  337. " cache %1, 0x040($1); cache %1, 0x050($1)\n" \
  338. " cache %1, 0x060($1); cache %1, 0x070($1)\n" \
  339. " cache %1, 0x080($1); cache %1, 0x090($1)\n" \
  340. " cache %1, 0x0a0($1); cache %1, 0x0b0($1)\n" \
  341. " cache %1, 0x0c0($1); cache %1, 0x0d0($1)\n" \
  342. " cache %1, 0x0e0($1); cache %1, 0x0f0($1)\n" \
  343. " .set pop\n" \
  344. : \
  345. : "r" (base), \
  346. "i" (op));
  347. #define cache32_unroll32(base,op) \
  348. __asm__ __volatile__( \
  349. " .set push\n" \
  350. " .set noreorder\n" \
  351. " .set mips64r6\n" \
  352. " .set noat\n" \
  353. " cache %1, 0x000(%0); cache %1, 0x020(%0)\n" \
  354. " cache %1, 0x040(%0); cache %1, 0x060(%0)\n" \
  355. " cache %1, 0x080(%0); cache %1, 0x0a0(%0)\n" \
  356. " cache %1, 0x0c0(%0); cache %1, 0x0e0(%0)\n" \
  357. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  358. " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
  359. " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
  360. " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
  361. " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
  362. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  363. " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
  364. " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
  365. " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
  366. " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
  367. " "__stringify(LONG_ADDIU)" $1, $1, 0x100\n" \
  368. " cache %1, 0x000($1); cache %1, 0x020($1)\n" \
  369. " cache %1, 0x040($1); cache %1, 0x060($1)\n" \
  370. " cache %1, 0x080($1); cache %1, 0x0a0($1)\n" \
  371. " cache %1, 0x0c0($1); cache %1, 0x0e0($1)\n" \
  372. " .set pop\n" \
  373. : \
  374. : "r" (base), \
  375. "i" (op));
  376. #define cache64_unroll32(base,op) \
  377. __asm__ __volatile__( \
  378. " .set push\n" \
  379. " .set noreorder\n" \
  380. " .set mips64r6\n" \
  381. " .set noat\n" \
  382. " cache %1, 0x000(%0); cache %1, 0x040(%0)\n" \
  383. " cache %1, 0x080(%0); cache %1, 0x0c0(%0)\n" \
  384. " "__stringify(LONG_ADDIU)" $1, %0, 0x100 \n" \
  385. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  386. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  387. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  388. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  389. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  390. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  391. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  392. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  393. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  394. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  395. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  396. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  397. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  398. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  399. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  400. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  401. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  402. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  403. " cache %1, 0x000($1); cache %1, 0x040($1)\n" \
  404. " cache %1, 0x080($1); cache %1, 0x0c0($1)\n" \
  405. " .set pop\n" \
  406. : \
  407. : "r" (base), \
  408. "i" (op));
  409. #define cache128_unroll32(base,op) \
  410. __asm__ __volatile__( \
  411. " .set push\n" \
  412. " .set noreorder\n" \
  413. " .set mips64r6\n" \
  414. " .set noat\n" \
  415. " cache %1, 0x000(%0); cache %1, 0x080(%0)\n" \
  416. " "__stringify(LONG_ADDIU)" $1, %0, 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. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  433. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  434. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  435. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  436. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  437. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  438. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  439. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  440. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  441. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  442. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  443. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  444. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  445. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  446. " "__stringify(LONG_ADDIU)" $1, $1, 0x100 \n" \
  447. " cache %1, 0x000($1); cache %1, 0x080($1)\n" \
  448. " .set pop\n" \
  449. : \
  450. : "r" (base), \
  451. "i" (op));
  452. #endif /* CONFIG_CPU_MIPSR6 */
  453. /*
  454. * Perform the cache operation specified by op using a user mode virtual
  455. * address while in kernel mode.
  456. */
  457. #define cache16_unroll32_user(base,op) \
  458. __asm__ __volatile__( \
  459. " .set push \n" \
  460. " .set noreorder \n" \
  461. " .set mips0 \n" \
  462. " .set eva \n" \
  463. " cachee %1, 0x000(%0); cachee %1, 0x010(%0) \n" \
  464. " cachee %1, 0x020(%0); cachee %1, 0x030(%0) \n" \
  465. " cachee %1, 0x040(%0); cachee %1, 0x050(%0) \n" \
  466. " cachee %1, 0x060(%0); cachee %1, 0x070(%0) \n" \
  467. " cachee %1, 0x080(%0); cachee %1, 0x090(%0) \n" \
  468. " cachee %1, 0x0a0(%0); cachee %1, 0x0b0(%0) \n" \
  469. " cachee %1, 0x0c0(%0); cachee %1, 0x0d0(%0) \n" \
  470. " cachee %1, 0x0e0(%0); cachee %1, 0x0f0(%0) \n" \
  471. " cachee %1, 0x100(%0); cachee %1, 0x110(%0) \n" \
  472. " cachee %1, 0x120(%0); cachee %1, 0x130(%0) \n" \
  473. " cachee %1, 0x140(%0); cachee %1, 0x150(%0) \n" \
  474. " cachee %1, 0x160(%0); cachee %1, 0x170(%0) \n" \
  475. " cachee %1, 0x180(%0); cachee %1, 0x190(%0) \n" \
  476. " cachee %1, 0x1a0(%0); cachee %1, 0x1b0(%0) \n" \
  477. " cachee %1, 0x1c0(%0); cachee %1, 0x1d0(%0) \n" \
  478. " cachee %1, 0x1e0(%0); cachee %1, 0x1f0(%0) \n" \
  479. " .set pop \n" \
  480. : \
  481. : "r" (base), \
  482. "i" (op));
  483. #define cache32_unroll32_user(base, op) \
  484. __asm__ __volatile__( \
  485. " .set push \n" \
  486. " .set noreorder \n" \
  487. " .set mips0 \n" \
  488. " .set eva \n" \
  489. " cachee %1, 0x000(%0); cachee %1, 0x020(%0) \n" \
  490. " cachee %1, 0x040(%0); cachee %1, 0x060(%0) \n" \
  491. " cachee %1, 0x080(%0); cachee %1, 0x0a0(%0) \n" \
  492. " cachee %1, 0x0c0(%0); cachee %1, 0x0e0(%0) \n" \
  493. " cachee %1, 0x100(%0); cachee %1, 0x120(%0) \n" \
  494. " cachee %1, 0x140(%0); cachee %1, 0x160(%0) \n" \
  495. " cachee %1, 0x180(%0); cachee %1, 0x1a0(%0) \n" \
  496. " cachee %1, 0x1c0(%0); cachee %1, 0x1e0(%0) \n" \
  497. " cachee %1, 0x200(%0); cachee %1, 0x220(%0) \n" \
  498. " cachee %1, 0x240(%0); cachee %1, 0x260(%0) \n" \
  499. " cachee %1, 0x280(%0); cachee %1, 0x2a0(%0) \n" \
  500. " cachee %1, 0x2c0(%0); cachee %1, 0x2e0(%0) \n" \
  501. " cachee %1, 0x300(%0); cachee %1, 0x320(%0) \n" \
  502. " cachee %1, 0x340(%0); cachee %1, 0x360(%0) \n" \
  503. " cachee %1, 0x380(%0); cachee %1, 0x3a0(%0) \n" \
  504. " cachee %1, 0x3c0(%0); cachee %1, 0x3e0(%0) \n" \
  505. " .set pop \n" \
  506. : \
  507. : "r" (base), \
  508. "i" (op));
  509. #define cache64_unroll32_user(base, op) \
  510. __asm__ __volatile__( \
  511. " .set push \n" \
  512. " .set noreorder \n" \
  513. " .set mips0 \n" \
  514. " .set eva \n" \
  515. " cachee %1, 0x000(%0); cachee %1, 0x040(%0) \n" \
  516. " cachee %1, 0x080(%0); cachee %1, 0x0c0(%0) \n" \
  517. " cachee %1, 0x100(%0); cachee %1, 0x140(%0) \n" \
  518. " cachee %1, 0x180(%0); cachee %1, 0x1c0(%0) \n" \
  519. " cachee %1, 0x200(%0); cachee %1, 0x240(%0) \n" \
  520. " cachee %1, 0x280(%0); cachee %1, 0x2c0(%0) \n" \
  521. " cachee %1, 0x300(%0); cachee %1, 0x340(%0) \n" \
  522. " cachee %1, 0x380(%0); cachee %1, 0x3c0(%0) \n" \
  523. " cachee %1, 0x400(%0); cachee %1, 0x440(%0) \n" \
  524. " cachee %1, 0x480(%0); cachee %1, 0x4c0(%0) \n" \
  525. " cachee %1, 0x500(%0); cachee %1, 0x540(%0) \n" \
  526. " cachee %1, 0x580(%0); cachee %1, 0x5c0(%0) \n" \
  527. " cachee %1, 0x600(%0); cachee %1, 0x640(%0) \n" \
  528. " cachee %1, 0x680(%0); cachee %1, 0x6c0(%0) \n" \
  529. " cachee %1, 0x700(%0); cachee %1, 0x740(%0) \n" \
  530. " cachee %1, 0x780(%0); cachee %1, 0x7c0(%0) \n" \
  531. " .set pop \n" \
  532. : \
  533. : "r" (base), \
  534. "i" (op));
  535. /* build blast_xxx, blast_xxx_page, blast_xxx_page_indexed */
  536. #define __BUILD_BLAST_CACHE(pfx, desc, indexop, hitop, lsize, extra) \
  537. static inline void extra##blast_##pfx##cache##lsize(void) \
  538. { \
  539. unsigned long start = INDEX_BASE; \
  540. unsigned long end = start + current_cpu_data.desc.waysize; \
  541. unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \
  542. unsigned long ws_end = current_cpu_data.desc.ways << \
  543. current_cpu_data.desc.waybit; \
  544. unsigned long ws, addr; \
  545. \
  546. __##pfx##flush_prologue \
  547. \
  548. for (ws = 0; ws < ws_end; ws += ws_inc) \
  549. for (addr = start; addr < end; addr += lsize * 32) \
  550. cache##lsize##_unroll32(addr|ws, indexop); \
  551. \
  552. __##pfx##flush_epilogue \
  553. } \
  554. \
  555. static inline void extra##blast_##pfx##cache##lsize##_page(unsigned long page) \
  556. { \
  557. unsigned long start = page; \
  558. unsigned long end = page + PAGE_SIZE; \
  559. \
  560. __##pfx##flush_prologue \
  561. \
  562. do { \
  563. cache##lsize##_unroll32(start, hitop); \
  564. start += lsize * 32; \
  565. } while (start < end); \
  566. \
  567. __##pfx##flush_epilogue \
  568. } \
  569. \
  570. static inline void extra##blast_##pfx##cache##lsize##_page_indexed(unsigned long page) \
  571. { \
  572. unsigned long indexmask = current_cpu_data.desc.waysize - 1; \
  573. unsigned long start = INDEX_BASE + (page & indexmask); \
  574. unsigned long end = start + PAGE_SIZE; \
  575. unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \
  576. unsigned long ws_end = current_cpu_data.desc.ways << \
  577. current_cpu_data.desc.waybit; \
  578. unsigned long ws, addr; \
  579. \
  580. __##pfx##flush_prologue \
  581. \
  582. for (ws = 0; ws < ws_end; ws += ws_inc) \
  583. for (addr = start; addr < end; addr += lsize * 32) \
  584. cache##lsize##_unroll32(addr|ws, indexop); \
  585. \
  586. __##pfx##flush_epilogue \
  587. }
  588. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 16, )
  589. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16, )
  590. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16, )
  591. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 32, )
  592. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32, )
  593. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I_Loongson2, 32, loongson2_)
  594. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32, )
  595. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 64, )
  596. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64, )
  597. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 64, )
  598. __BUILD_BLAST_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D, 128, )
  599. __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 128, )
  600. __BUILD_BLAST_CACHE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128, )
  601. __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 16, )
  602. __BUILD_BLAST_CACHE(inv_d, dcache, Index_Writeback_Inv_D, Hit_Invalidate_D, 32, )
  603. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 16, )
  604. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 32, )
  605. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 64, )
  606. __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 128, )
  607. #define __BUILD_BLAST_USER_CACHE(pfx, desc, indexop, hitop, lsize) \
  608. static inline void blast_##pfx##cache##lsize##_user_page(unsigned long page) \
  609. { \
  610. unsigned long start = page; \
  611. unsigned long end = page + PAGE_SIZE; \
  612. \
  613. __##pfx##flush_prologue \
  614. \
  615. do { \
  616. cache##lsize##_unroll32_user(start, hitop); \
  617. start += lsize * 32; \
  618. } while (start < end); \
  619. \
  620. __##pfx##flush_epilogue \
  621. }
  622. __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
  623. 16)
  624. __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 16)
  625. __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
  626. 32)
  627. __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32)
  628. __BUILD_BLAST_USER_CACHE(d, dcache, Index_Writeback_Inv_D, Hit_Writeback_Inv_D,
  629. 64)
  630. __BUILD_BLAST_USER_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 64)
  631. /* build blast_xxx_range, protected_blast_xxx_range */
  632. #define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot, extra) \
  633. static inline void prot##extra##blast_##pfx##cache##_range(unsigned long start, \
  634. unsigned long end) \
  635. { \
  636. unsigned long lsize = cpu_##desc##_line_size(); \
  637. unsigned long addr = start & ~(lsize - 1); \
  638. unsigned long aend = (end - 1) & ~(lsize - 1); \
  639. \
  640. __##pfx##flush_prologue \
  641. \
  642. while (1) { \
  643. prot##cache_op(hitop, addr); \
  644. if (addr == aend) \
  645. break; \
  646. addr += lsize; \
  647. } \
  648. \
  649. __##pfx##flush_epilogue \
  650. }
  651. #ifndef CONFIG_EVA
  652. __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_, )
  653. __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_, )
  654. #else
  655. #define __BUILD_PROT_BLAST_CACHE_RANGE(pfx, desc, hitop) \
  656. static inline void protected_blast_##pfx##cache##_range(unsigned long start,\
  657. unsigned long end) \
  658. { \
  659. unsigned long lsize = cpu_##desc##_line_size(); \
  660. unsigned long addr = start & ~(lsize - 1); \
  661. unsigned long aend = (end - 1) & ~(lsize - 1); \
  662. \
  663. __##pfx##flush_prologue \
  664. \
  665. if (!uaccess_kernel()) { \
  666. while (1) { \
  667. protected_cachee_op(hitop, addr); \
  668. if (addr == aend) \
  669. break; \
  670. addr += lsize; \
  671. } \
  672. } else { \
  673. while (1) { \
  674. protected_cache_op(hitop, addr); \
  675. if (addr == aend) \
  676. break; \
  677. addr += lsize; \
  678. } \
  679. \
  680. } \
  681. __##pfx##flush_epilogue \
  682. }
  683. __BUILD_PROT_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D)
  684. __BUILD_PROT_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I)
  685. #endif
  686. __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_, )
  687. __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I_Loongson2, \
  688. protected_, loongson2_)
  689. __BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, , )
  690. __BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, , )
  691. __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, , )
  692. /* blast_inv_dcache_range */
  693. __BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, , )
  694. __BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, , )
  695. #endif /* _ASM_R4KCACHE_H */