cpuamu_helpers.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <cpuamu.h>
  9. .globl cpuamu_cnt_read
  10. .globl cpuamu_cnt_write
  11. .globl cpuamu_read_cpuamcntenset_el0
  12. .globl cpuamu_read_cpuamcntenclr_el0
  13. .globl cpuamu_write_cpuamcntenset_el0
  14. .globl cpuamu_write_cpuamcntenclr_el0
  15. /*
  16. * uint64_t cpuamu_cnt_read(unsigned int idx);
  17. *
  18. * Given `idx`, read the corresponding AMU counter
  19. * and return it in `x0`.
  20. */
  21. func cpuamu_cnt_read
  22. adr x1, 1f
  23. add x1, x1, x0, lsl #3 /* each mrs/ret sequence is 8 bytes */
  24. #if ENABLE_BTI
  25. add x1, x1, x0, lsl #2 /* + "bti j" instruction */
  26. #endif
  27. br x1
  28. 1: read CPUAMEVCNTR0_EL0
  29. read CPUAMEVCNTR1_EL0
  30. read CPUAMEVCNTR2_EL0
  31. read CPUAMEVCNTR3_EL0
  32. read CPUAMEVCNTR4_EL0
  33. endfunc cpuamu_cnt_read
  34. /*
  35. * void cpuamu_cnt_write(unsigned int idx, uint64_t val);
  36. *
  37. * Given `idx`, write `val` to the corresponding AMU counter.
  38. */
  39. func cpuamu_cnt_write
  40. adr x2, 1f
  41. add x2, x2, x0, lsl #3 /* each msr/ret sequence is 8 bytes */
  42. #if ENABLE_BTI
  43. add x2, x2, x0, lsl #2 /* + "bti j" instruction */
  44. #endif
  45. br x2
  46. 1: write CPUAMEVCNTR0_EL0
  47. write CPUAMEVCNTR1_EL0
  48. write CPUAMEVCNTR2_EL0
  49. write CPUAMEVCNTR3_EL0
  50. write CPUAMEVCNTR4_EL0
  51. endfunc cpuamu_cnt_write
  52. /*
  53. * unsigned int cpuamu_read_cpuamcntenset_el0(void);
  54. *
  55. * Read the `CPUAMCNTENSET_EL0` CPU register and return
  56. * it in `x0`.
  57. */
  58. func cpuamu_read_cpuamcntenset_el0
  59. mrs x0, CPUAMCNTENSET_EL0
  60. ret
  61. endfunc cpuamu_read_cpuamcntenset_el0
  62. /*
  63. * unsigned int cpuamu_read_cpuamcntenclr_el0(void);
  64. *
  65. * Read the `CPUAMCNTENCLR_EL0` CPU register and return
  66. * it in `x0`.
  67. */
  68. func cpuamu_read_cpuamcntenclr_el0
  69. mrs x0, CPUAMCNTENCLR_EL0
  70. ret
  71. endfunc cpuamu_read_cpuamcntenclr_el0
  72. /*
  73. * void cpuamu_write_cpuamcntenset_el0(unsigned int mask);
  74. *
  75. * Write `mask` to the `CPUAMCNTENSET_EL0` CPU register.
  76. */
  77. func cpuamu_write_cpuamcntenset_el0
  78. msr CPUAMCNTENSET_EL0, x0
  79. ret
  80. endfunc cpuamu_write_cpuamcntenset_el0
  81. /*
  82. * void cpuamu_write_cpuamcntenclr_el0(unsigned int mask);
  83. *
  84. * Write `mask` to the `CPUAMCNTENCLR_EL0` CPU register.
  85. */
  86. func cpuamu_write_cpuamcntenclr_el0
  87. msr CPUAMCNTENCLR_EL0, x0
  88. ret
  89. endfunc cpuamu_write_cpuamcntenclr_el0