arm_pmuv3.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_PMUV3_H
  6. #define __ASM_PMUV3_H
  7. #include <asm/kvm_host.h>
  8. #include <asm/cpufeature.h>
  9. #include <asm/sysreg.h>
  10. #define RETURN_READ_PMEVCNTRN(n) \
  11. return read_sysreg(pmevcntr##n##_el0)
  12. static inline unsigned long read_pmevcntrn(int n)
  13. {
  14. PMEVN_SWITCH(n, RETURN_READ_PMEVCNTRN);
  15. return 0;
  16. }
  17. #define WRITE_PMEVCNTRN(n) \
  18. write_sysreg(val, pmevcntr##n##_el0)
  19. static inline void write_pmevcntrn(int n, unsigned long val)
  20. {
  21. PMEVN_SWITCH(n, WRITE_PMEVCNTRN);
  22. }
  23. #define WRITE_PMEVTYPERN(n) \
  24. write_sysreg(val, pmevtyper##n##_el0)
  25. static inline void write_pmevtypern(int n, unsigned long val)
  26. {
  27. PMEVN_SWITCH(n, WRITE_PMEVTYPERN);
  28. }
  29. #define RETURN_READ_PMEVTYPERN(n) \
  30. return read_sysreg(pmevtyper##n##_el0)
  31. static inline unsigned long read_pmevtypern(int n)
  32. {
  33. PMEVN_SWITCH(n, RETURN_READ_PMEVTYPERN);
  34. return 0;
  35. }
  36. static inline unsigned long read_pmmir(void)
  37. {
  38. return read_cpuid(PMMIR_EL1);
  39. }
  40. static inline u32 read_pmuver(void)
  41. {
  42. u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
  43. return cpuid_feature_extract_unsigned_field(dfr0,
  44. ID_AA64DFR0_EL1_PMUVer_SHIFT);
  45. }
  46. static inline bool pmuv3_has_icntr(void)
  47. {
  48. u64 dfr1 = read_sysreg(id_aa64dfr1_el1);
  49. return !!cpuid_feature_extract_unsigned_field(dfr1,
  50. ID_AA64DFR1_EL1_PMICNTR_SHIFT);
  51. }
  52. static inline void write_pmcr(u64 val)
  53. {
  54. write_sysreg(val, pmcr_el0);
  55. }
  56. static inline u64 read_pmcr(void)
  57. {
  58. return read_sysreg(pmcr_el0);
  59. }
  60. static inline void write_pmselr(u32 val)
  61. {
  62. write_sysreg(val, pmselr_el0);
  63. }
  64. static inline void write_pmccntr(u64 val)
  65. {
  66. write_sysreg(val, pmccntr_el0);
  67. }
  68. static inline u64 read_pmccntr(void)
  69. {
  70. return read_sysreg(pmccntr_el0);
  71. }
  72. static inline void write_pmicntr(u64 val)
  73. {
  74. write_sysreg_s(val, SYS_PMICNTR_EL0);
  75. }
  76. static inline u64 read_pmicntr(void)
  77. {
  78. return read_sysreg_s(SYS_PMICNTR_EL0);
  79. }
  80. static inline void write_pmcntenset(u64 val)
  81. {
  82. write_sysreg(val, pmcntenset_el0);
  83. }
  84. static inline void write_pmcntenclr(u64 val)
  85. {
  86. write_sysreg(val, pmcntenclr_el0);
  87. }
  88. static inline void write_pmintenset(u64 val)
  89. {
  90. write_sysreg(val, pmintenset_el1);
  91. }
  92. static inline void write_pmintenclr(u64 val)
  93. {
  94. write_sysreg(val, pmintenclr_el1);
  95. }
  96. static inline void write_pmccfiltr(u64 val)
  97. {
  98. write_sysreg(val, pmccfiltr_el0);
  99. }
  100. static inline u64 read_pmccfiltr(void)
  101. {
  102. return read_sysreg(pmccfiltr_el0);
  103. }
  104. static inline void write_pmicfiltr(u64 val)
  105. {
  106. write_sysreg_s(val, SYS_PMICFILTR_EL0);
  107. }
  108. static inline u64 read_pmicfiltr(void)
  109. {
  110. return read_sysreg_s(SYS_PMICFILTR_EL0);
  111. }
  112. static inline void write_pmovsclr(u64 val)
  113. {
  114. write_sysreg(val, pmovsclr_el0);
  115. }
  116. static inline u64 read_pmovsclr(void)
  117. {
  118. return read_sysreg(pmovsclr_el0);
  119. }
  120. static inline void write_pmuserenr(u32 val)
  121. {
  122. write_sysreg(val, pmuserenr_el0);
  123. }
  124. static inline u64 read_pmceid0(void)
  125. {
  126. return read_sysreg(pmceid0_el0);
  127. }
  128. static inline u64 read_pmceid1(void)
  129. {
  130. return read_sysreg(pmceid1_el0);
  131. }
  132. static inline bool pmuv3_implemented(int pmuver)
  133. {
  134. return !(pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF ||
  135. pmuver == ID_AA64DFR0_EL1_PMUVer_NI);
  136. }
  137. static inline bool is_pmuv3p4(int pmuver)
  138. {
  139. return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P4;
  140. }
  141. static inline bool is_pmuv3p5(int pmuver)
  142. {
  143. return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P5;
  144. }
  145. #endif