amu_helpers.S 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <assert_macros.S>
  8. #include <asm_macros.S>
  9. .globl amu_group0_cnt_read_internal
  10. .globl amu_group0_cnt_write_internal
  11. .globl amu_group1_cnt_read_internal
  12. .globl amu_group1_cnt_write_internal
  13. .globl amu_group1_set_evtype_internal
  14. /*
  15. * uint64_t amu_group0_cnt_read_internal(int idx);
  16. *
  17. * Given `idx`, read the corresponding AMU counter
  18. * and return it in `r0` and `r1`.
  19. */
  20. func amu_group0_cnt_read_internal
  21. #if ENABLE_ASSERTIONS
  22. /* `idx` should be between [0, 3] */
  23. mov r1, r0
  24. lsr r1, r1, #2
  25. cmp r1, #0
  26. ASM_ASSERT(eq)
  27. #endif
  28. /*
  29. * Given `idx` calculate address of ldcopr16/bx lr instruction pair
  30. * in the table below.
  31. */
  32. adr r1, 1f
  33. lsl r0, r0, #3 /* each ldcopr16/bx lr sequence is 8 bytes */
  34. add r1, r1, r0
  35. bx r1
  36. 1:
  37. ldcopr16 r0, r1, AMEVCNTR00 /* index 0 */
  38. bx lr
  39. ldcopr16 r0, r1, AMEVCNTR01 /* index 1 */
  40. bx lr
  41. ldcopr16 r0, r1, AMEVCNTR02 /* index 2 */
  42. bx lr
  43. ldcopr16 r0, r1, AMEVCNTR03 /* index 3 */
  44. bx lr
  45. endfunc amu_group0_cnt_read_internal
  46. /*
  47. * void amu_group0_cnt_write_internal(int idx, uint64_t val);
  48. *
  49. * Given `idx`, write `val` to the corresponding AMU counter.
  50. * `idx` is passed in `r0` and `val` is passed in `r2` and `r3`.
  51. * `r1` is used as a scratch register.
  52. */
  53. func amu_group0_cnt_write_internal
  54. #if ENABLE_ASSERTIONS
  55. /* `idx` should be between [0, 3] */
  56. mov r1, r0
  57. lsr r1, r1, #2
  58. cmp r1, #0
  59. ASM_ASSERT(eq)
  60. #endif
  61. /*
  62. * Given `idx` calculate address of stcopr16/bx lr instruction pair
  63. * in the table below.
  64. */
  65. adr r1, 1f
  66. lsl r0, r0, #3 /* each stcopr16/bx lr sequence is 8 bytes */
  67. add r1, r1, r0
  68. bx r1
  69. 1:
  70. stcopr16 r2, r3, AMEVCNTR00 /* index 0 */
  71. bx lr
  72. stcopr16 r2, r3, AMEVCNTR01 /* index 1 */
  73. bx lr
  74. stcopr16 r2, r3, AMEVCNTR02 /* index 2 */
  75. bx lr
  76. stcopr16 r2, r3, AMEVCNTR03 /* index 3 */
  77. bx lr
  78. endfunc amu_group0_cnt_write_internal
  79. #if ENABLE_AMU_AUXILIARY_COUNTERS
  80. /*
  81. * uint64_t amu_group1_cnt_read_internal(int idx);
  82. *
  83. * Given `idx`, read the corresponding AMU counter
  84. * and return it in `r0` and `r1`.
  85. */
  86. func amu_group1_cnt_read_internal
  87. #if ENABLE_ASSERTIONS
  88. /* `idx` should be between [0, 15] */
  89. mov r1, r0
  90. lsr r1, r1, #4
  91. cmp r1, #0
  92. ASM_ASSERT(eq)
  93. #endif
  94. /*
  95. * Given `idx` calculate address of ldcopr16/bx lr instruction pair
  96. * in the table below.
  97. */
  98. adr r1, 1f
  99. lsl r0, r0, #3 /* each ldcopr16/bx lr sequence is 8 bytes */
  100. add r1, r1, r0
  101. bx r1
  102. 1:
  103. ldcopr16 r0, r1, AMEVCNTR10 /* index 0 */
  104. bx lr
  105. ldcopr16 r0, r1, AMEVCNTR11 /* index 1 */
  106. bx lr
  107. ldcopr16 r0, r1, AMEVCNTR12 /* index 2 */
  108. bx lr
  109. ldcopr16 r0, r1, AMEVCNTR13 /* index 3 */
  110. bx lr
  111. ldcopr16 r0, r1, AMEVCNTR14 /* index 4 */
  112. bx lr
  113. ldcopr16 r0, r1, AMEVCNTR15 /* index 5 */
  114. bx lr
  115. ldcopr16 r0, r1, AMEVCNTR16 /* index 6 */
  116. bx lr
  117. ldcopr16 r0, r1, AMEVCNTR17 /* index 7 */
  118. bx lr
  119. ldcopr16 r0, r1, AMEVCNTR18 /* index 8 */
  120. bx lr
  121. ldcopr16 r0, r1, AMEVCNTR19 /* index 9 */
  122. bx lr
  123. ldcopr16 r0, r1, AMEVCNTR1A /* index 10 */
  124. bx lr
  125. ldcopr16 r0, r1, AMEVCNTR1B /* index 11 */
  126. bx lr
  127. ldcopr16 r0, r1, AMEVCNTR1C /* index 12 */
  128. bx lr
  129. ldcopr16 r0, r1, AMEVCNTR1D /* index 13 */
  130. bx lr
  131. ldcopr16 r0, r1, AMEVCNTR1E /* index 14 */
  132. bx lr
  133. ldcopr16 r0, r1, AMEVCNTR1F /* index 15 */
  134. bx lr
  135. endfunc amu_group1_cnt_read_internal
  136. /*
  137. * void amu_group1_cnt_write_internal(int idx, uint64_t val);
  138. *
  139. * Given `idx`, write `val` to the corresponding AMU counter.
  140. * `idx` is passed in `r0` and `val` is passed in `r2` and `r3`.
  141. * `r1` is used as a scratch register.
  142. */
  143. func amu_group1_cnt_write_internal
  144. #if ENABLE_ASSERTIONS
  145. /* `idx` should be between [0, 15] */
  146. mov r1, r0
  147. lsr r1, r1, #4
  148. cmp r1, #0
  149. ASM_ASSERT(eq)
  150. #endif
  151. /*
  152. * Given `idx` calculate address of ldcopr16/bx lr instruction pair
  153. * in the table below.
  154. */
  155. adr r1, 1f
  156. lsl r0, r0, #3 /* each stcopr16/bx lr sequence is 8 bytes */
  157. add r1, r1, r0
  158. bx r1
  159. 1:
  160. stcopr16 r2, r3, AMEVCNTR10 /* index 0 */
  161. bx lr
  162. stcopr16 r2, r3, AMEVCNTR11 /* index 1 */
  163. bx lr
  164. stcopr16 r2, r3, AMEVCNTR12 /* index 2 */
  165. bx lr
  166. stcopr16 r2, r3, AMEVCNTR13 /* index 3 */
  167. bx lr
  168. stcopr16 r2, r3, AMEVCNTR14 /* index 4 */
  169. bx lr
  170. stcopr16 r2, r3, AMEVCNTR15 /* index 5 */
  171. bx lr
  172. stcopr16 r2, r3, AMEVCNTR16 /* index 6 */
  173. bx lr
  174. stcopr16 r2, r3, AMEVCNTR17 /* index 7 */
  175. bx lr
  176. stcopr16 r2, r3, AMEVCNTR18 /* index 8 */
  177. bx lr
  178. stcopr16 r2, r3, AMEVCNTR19 /* index 9 */
  179. bx lr
  180. stcopr16 r2, r3, AMEVCNTR1A /* index 10 */
  181. bx lr
  182. stcopr16 r2, r3, AMEVCNTR1B /* index 11 */
  183. bx lr
  184. stcopr16 r2, r3, AMEVCNTR1C /* index 12 */
  185. bx lr
  186. stcopr16 r2, r3, AMEVCNTR1D /* index 13 */
  187. bx lr
  188. stcopr16 r2, r3, AMEVCNTR1E /* index 14 */
  189. bx lr
  190. stcopr16 r2, r3, AMEVCNTR1F /* index 15 */
  191. bx lr
  192. endfunc amu_group1_cnt_write_internal
  193. /*
  194. * void amu_group1_set_evtype_internal(int idx, unsigned int val);
  195. *
  196. * Program the AMU event type register indexed by `idx`
  197. * with the value `val`.
  198. */
  199. func amu_group1_set_evtype_internal
  200. #if ENABLE_ASSERTIONS
  201. /* `idx` should be between [0, 15] */
  202. mov r2, r0
  203. lsr r2, r2, #4
  204. cmp r2, #0
  205. ASM_ASSERT(eq)
  206. /* val should be between [0, 65535] */
  207. mov r2, r1
  208. lsr r2, r2, #16
  209. cmp r2, #0
  210. ASM_ASSERT(eq)
  211. #endif
  212. /*
  213. * Given `idx` calculate address of stcopr/bx lr instruction pair
  214. * in the table below.
  215. */
  216. adr r2, 1f
  217. lsl r0, r0, #3 /* each stcopr/bx lr sequence is 8 bytes */
  218. add r2, r2, r0
  219. bx r2
  220. 1:
  221. stcopr r1, AMEVTYPER10 /* index 0 */
  222. bx lr
  223. stcopr r1, AMEVTYPER11 /* index 1 */
  224. bx lr
  225. stcopr r1, AMEVTYPER12 /* index 2 */
  226. bx lr
  227. stcopr r1, AMEVTYPER13 /* index 3 */
  228. bx lr
  229. stcopr r1, AMEVTYPER14 /* index 4 */
  230. bx lr
  231. stcopr r1, AMEVTYPER15 /* index 5 */
  232. bx lr
  233. stcopr r1, AMEVTYPER16 /* index 6 */
  234. bx lr
  235. stcopr r1, AMEVTYPER17 /* index 7 */
  236. bx lr
  237. stcopr r1, AMEVTYPER18 /* index 8 */
  238. bx lr
  239. stcopr r1, AMEVTYPER19 /* index 9 */
  240. bx lr
  241. stcopr r1, AMEVTYPER1A /* index 10 */
  242. bx lr
  243. stcopr r1, AMEVTYPER1B /* index 11 */
  244. bx lr
  245. stcopr r1, AMEVTYPER1C /* index 12 */
  246. bx lr
  247. stcopr r1, AMEVTYPER1D /* index 13 */
  248. bx lr
  249. stcopr r1, AMEVTYPER1E /* index 14 */
  250. bx lr
  251. stcopr r1, AMEVTYPER1F /* index 15 */
  252. bx lr
  253. endfunc amu_group1_set_evtype_internal
  254. #endif