iwmmxt.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/kernel/iwmmxt.S
  4. *
  5. * XScale iWMMXt (Concan) context switching and handling
  6. *
  7. * Initial code:
  8. * Copyright (c) 2003, Intel Corporation
  9. *
  10. * Full lazy switching support, optimizations and more, by Nicolas Pitre
  11. * Copyright (c) 2003-2004, MontaVista Software, Inc.
  12. */
  13. #include <linux/linkage.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/asm-offsets.h>
  17. #include <asm/assembler.h>
  18. #include "iwmmxt.h"
  19. #define MMX_WR0 (0x00)
  20. #define MMX_WR1 (0x08)
  21. #define MMX_WR2 (0x10)
  22. #define MMX_WR3 (0x18)
  23. #define MMX_WR4 (0x20)
  24. #define MMX_WR5 (0x28)
  25. #define MMX_WR6 (0x30)
  26. #define MMX_WR7 (0x38)
  27. #define MMX_WR8 (0x40)
  28. #define MMX_WR9 (0x48)
  29. #define MMX_WR10 (0x50)
  30. #define MMX_WR11 (0x58)
  31. #define MMX_WR12 (0x60)
  32. #define MMX_WR13 (0x68)
  33. #define MMX_WR14 (0x70)
  34. #define MMX_WR15 (0x78)
  35. #define MMX_WCSSF (0x80)
  36. #define MMX_WCASF (0x84)
  37. #define MMX_WCGR0 (0x88)
  38. #define MMX_WCGR1 (0x8C)
  39. #define MMX_WCGR2 (0x90)
  40. #define MMX_WCGR3 (0x94)
  41. #define MMX_SIZE (0x98)
  42. .text
  43. .arm
  44. ENTRY(iwmmxt_undef_handler)
  45. push {r9, r10, lr}
  46. get_thread_info r10
  47. mov r9, pc
  48. b iwmmxt_task_enable
  49. mov r0, #0
  50. pop {r9, r10, pc}
  51. ENDPROC(iwmmxt_undef_handler)
  52. /*
  53. * Lazy switching of Concan coprocessor context
  54. *
  55. * r0 = struct pt_regs pointer
  56. * r10 = struct thread_info pointer
  57. * r9 = ret_from_exception
  58. * lr = undefined instr exit
  59. *
  60. * called from prefetch exception handler with interrupts enabled
  61. */
  62. ENTRY(iwmmxt_task_enable)
  63. inc_preempt_count r10, r3
  64. mrc p15, 0, r2, c15, c1, 0
  65. @ CP0 and CP1 accessible?
  66. tst r2, #0x3
  67. bne 4f @ if so no business here
  68. @ enable access to CP0 and CP1
  69. orr r2, r2, #0x3
  70. mcr p15, 0, r2, c15, c1, 0
  71. ldr r3, =concan_owner
  72. ldr r2, [r0, #S_PC] @ current task pc value
  73. ldr r1, [r3] @ get current Concan owner
  74. sub r2, r2, #4 @ adjust pc back
  75. str r2, [r0, #S_PC]
  76. add r0, r10, #TI_IWMMXT_STATE @ get task Concan save area
  77. str r0, [r3] @ this task now owns Concan regs
  78. mrc p15, 0, r2, c2, c0, 0
  79. mov r2, r2 @ cpwait
  80. bl concan_save
  81. #ifdef CONFIG_PREEMPT_COUNT
  82. get_thread_info r10
  83. #endif
  84. 4: dec_preempt_count r10, r3
  85. ret r9 @ normal exit from exception
  86. concan_save:
  87. teq r1, #0 @ test for last ownership
  88. beq concan_load @ no owner, skip save
  89. tmrc r2, wCon
  90. @ CUP? wCx
  91. tst r2, #0x1
  92. beq 1f
  93. concan_dump:
  94. wstrw wCSSF, r1, MMX_WCSSF
  95. wstrw wCASF, r1, MMX_WCASF
  96. wstrw wCGR0, r1, MMX_WCGR0
  97. wstrw wCGR1, r1, MMX_WCGR1
  98. wstrw wCGR2, r1, MMX_WCGR2
  99. wstrw wCGR3, r1, MMX_WCGR3
  100. 1: @ MUP? wRn
  101. tst r2, #0x2
  102. beq 2f
  103. wstrd wR0, r1, MMX_WR0
  104. wstrd wR1, r1, MMX_WR1
  105. wstrd wR2, r1, MMX_WR2
  106. wstrd wR3, r1, MMX_WR3
  107. wstrd wR4, r1, MMX_WR4
  108. wstrd wR5, r1, MMX_WR5
  109. wstrd wR6, r1, MMX_WR6
  110. wstrd wR7, r1, MMX_WR7
  111. wstrd wR8, r1, MMX_WR8
  112. wstrd wR9, r1, MMX_WR9
  113. wstrd wR10, r1, MMX_WR10
  114. wstrd wR11, r1, MMX_WR11
  115. wstrd wR12, r1, MMX_WR12
  116. wstrd wR13, r1, MMX_WR13
  117. wstrd wR14, r1, MMX_WR14
  118. wstrd wR15, r1, MMX_WR15
  119. 2: teq r0, #0 @ anything to load?
  120. reteq lr @ if not, return
  121. concan_load:
  122. @ Load wRn
  123. wldrd wR0, r0, MMX_WR0
  124. wldrd wR1, r0, MMX_WR1
  125. wldrd wR2, r0, MMX_WR2
  126. wldrd wR3, r0, MMX_WR3
  127. wldrd wR4, r0, MMX_WR4
  128. wldrd wR5, r0, MMX_WR5
  129. wldrd wR6, r0, MMX_WR6
  130. wldrd wR7, r0, MMX_WR7
  131. wldrd wR8, r0, MMX_WR8
  132. wldrd wR9, r0, MMX_WR9
  133. wldrd wR10, r0, MMX_WR10
  134. wldrd wR11, r0, MMX_WR11
  135. wldrd wR12, r0, MMX_WR12
  136. wldrd wR13, r0, MMX_WR13
  137. wldrd wR14, r0, MMX_WR14
  138. wldrd wR15, r0, MMX_WR15
  139. @ Load wCx
  140. wldrw wCSSF, r0, MMX_WCSSF
  141. wldrw wCASF, r0, MMX_WCASF
  142. wldrw wCGR0, r0, MMX_WCGR0
  143. wldrw wCGR1, r0, MMX_WCGR1
  144. wldrw wCGR2, r0, MMX_WCGR2
  145. wldrw wCGR3, r0, MMX_WCGR3
  146. @ clear CUP/MUP (only if r1 != 0)
  147. teq r1, #0
  148. mov r2, #0
  149. reteq lr
  150. tmcr wCon, r2
  151. ret lr
  152. ENDPROC(iwmmxt_task_enable)
  153. /*
  154. * Back up Concan regs to save area and disable access to them
  155. * (mainly for gdb or sleep mode usage)
  156. *
  157. * r0 = struct thread_info pointer of target task or NULL for any
  158. */
  159. ENTRY(iwmmxt_task_disable)
  160. stmfd sp!, {r4, lr}
  161. mrs ip, cpsr
  162. orr r2, ip, #PSR_I_BIT @ disable interrupts
  163. msr cpsr_c, r2
  164. ldr r3, =concan_owner
  165. add r2, r0, #TI_IWMMXT_STATE @ get task Concan save area
  166. ldr r1, [r3] @ get current Concan owner
  167. teq r1, #0 @ any current owner?
  168. beq 1f @ no: quit
  169. teq r0, #0 @ any owner?
  170. teqne r1, r2 @ or specified one?
  171. bne 1f @ no: quit
  172. @ enable access to CP0 and CP1
  173. mrc p15, 0, r4, c15, c1, 0
  174. orr r4, r4, #0x3
  175. mcr p15, 0, r4, c15, c1, 0
  176. mov r0, #0 @ nothing to load
  177. str r0, [r3] @ no more current owner
  178. mrc p15, 0, r2, c2, c0, 0
  179. mov r2, r2 @ cpwait
  180. bl concan_save
  181. @ disable access to CP0 and CP1
  182. bic r4, r4, #0x3
  183. mcr p15, 0, r4, c15, c1, 0
  184. mrc p15, 0, r2, c2, c0, 0
  185. mov r2, r2 @ cpwait
  186. 1: msr cpsr_c, ip @ restore interrupt mode
  187. ldmfd sp!, {r4, pc}
  188. ENDPROC(iwmmxt_task_disable)
  189. /*
  190. * Copy Concan state to given memory address
  191. *
  192. * r0 = struct thread_info pointer of target task
  193. * r1 = memory address where to store Concan state
  194. *
  195. * this is called mainly in the creation of signal stack frames
  196. */
  197. ENTRY(iwmmxt_task_copy)
  198. mrs ip, cpsr
  199. orr r2, ip, #PSR_I_BIT @ disable interrupts
  200. msr cpsr_c, r2
  201. ldr r3, =concan_owner
  202. add r2, r0, #TI_IWMMXT_STATE @ get task Concan save area
  203. ldr r3, [r3] @ get current Concan owner
  204. teq r2, r3 @ does this task own it...
  205. beq 1f
  206. @ current Concan values are in the task save area
  207. msr cpsr_c, ip @ restore interrupt mode
  208. mov r0, r1
  209. mov r1, r2
  210. mov r2, #MMX_SIZE
  211. b memcpy
  212. 1: @ this task owns Concan regs -- grab a copy from there
  213. mov r0, #0 @ nothing to load
  214. mov r2, #3 @ save all regs
  215. mov r3, lr @ preserve return address
  216. bl concan_dump
  217. msr cpsr_c, ip @ restore interrupt mode
  218. ret r3
  219. ENDPROC(iwmmxt_task_copy)
  220. /*
  221. * Restore Concan state from given memory address
  222. *
  223. * r0 = struct thread_info pointer of target task
  224. * r1 = memory address where to get Concan state from
  225. *
  226. * this is used to restore Concan state when unwinding a signal stack frame
  227. */
  228. ENTRY(iwmmxt_task_restore)
  229. mrs ip, cpsr
  230. orr r2, ip, #PSR_I_BIT @ disable interrupts
  231. msr cpsr_c, r2
  232. ldr r3, =concan_owner
  233. add r2, r0, #TI_IWMMXT_STATE @ get task Concan save area
  234. ldr r3, [r3] @ get current Concan owner
  235. bic r2, r2, #0x7 @ 64-bit alignment
  236. teq r2, r3 @ does this task own it...
  237. beq 1f
  238. @ this task doesn't own Concan regs -- use its save area
  239. msr cpsr_c, ip @ restore interrupt mode
  240. mov r0, r2
  241. mov r2, #MMX_SIZE
  242. b memcpy
  243. 1: @ this task owns Concan regs -- load them directly
  244. mov r0, r1
  245. mov r1, #0 @ don't clear CUP/MUP
  246. mov r3, lr @ preserve return address
  247. bl concan_load
  248. msr cpsr_c, ip @ restore interrupt mode
  249. ret r3
  250. ENDPROC(iwmmxt_task_restore)
  251. /*
  252. * Concan handling on task switch
  253. *
  254. * r0 = next thread_info pointer
  255. *
  256. * Called only from the iwmmxt notifier with task preemption disabled.
  257. */
  258. ENTRY(iwmmxt_task_switch)
  259. mrc p15, 0, r1, c15, c1, 0
  260. @ CP0 and CP1 accessible?
  261. tst r1, #0x3
  262. bne 1f @ yes: block them for next task
  263. ldr r2, =concan_owner
  264. add r3, r0, #TI_IWMMXT_STATE @ get next task Concan save area
  265. ldr r2, [r2] @ get current Concan owner
  266. teq r2, r3 @ next task owns it?
  267. retne lr @ no: leave Concan disabled
  268. 1: @ flip Concan access
  269. eor r1, r1, #0x3
  270. mcr p15, 0, r1, c15, c1, 0
  271. mrc p15, 0, r1, c2, c0, 0
  272. sub pc, lr, r1, lsr #32 @ cpwait and return
  273. ENDPROC(iwmmxt_task_switch)
  274. /*
  275. * Remove Concan ownership of given task
  276. *
  277. * r0 = struct thread_info pointer
  278. */
  279. ENTRY(iwmmxt_task_release)
  280. mrs r2, cpsr
  281. orr ip, r2, #PSR_I_BIT @ disable interrupts
  282. msr cpsr_c, ip
  283. ldr r3, =concan_owner
  284. add r0, r0, #TI_IWMMXT_STATE @ get task Concan save area
  285. ldr r1, [r3] @ get current Concan owner
  286. eors r0, r0, r1 @ if equal...
  287. streq r0, [r3] @ then clear ownership
  288. msr cpsr_c, r2 @ restore interrupts
  289. ret lr
  290. ENDPROC(iwmmxt_task_release)
  291. .data
  292. .align 2
  293. concan_owner:
  294. .word 0