arm_dsu_pmu.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * ARM DynamIQ Shared Unit (DSU) PMU Low level register access routines.
  4. *
  5. * Copyright (C) ARM Limited, 2017.
  6. *
  7. * Author: Suzuki K Poulose <suzuki.poulose@arm.com>
  8. */
  9. #include <linux/bitops.h>
  10. #include <linux/build_bug.h>
  11. #include <linux/compiler.h>
  12. #include <linux/types.h>
  13. #include <asm/barrier.h>
  14. #include <asm/sysreg.h>
  15. #define CLUSTERPMCR_EL1 sys_reg(3, 0, 15, 5, 0)
  16. #define CLUSTERPMCNTENSET_EL1 sys_reg(3, 0, 15, 5, 1)
  17. #define CLUSTERPMCNTENCLR_EL1 sys_reg(3, 0, 15, 5, 2)
  18. #define CLUSTERPMOVSSET_EL1 sys_reg(3, 0, 15, 5, 3)
  19. #define CLUSTERPMOVSCLR_EL1 sys_reg(3, 0, 15, 5, 4)
  20. #define CLUSTERPMSELR_EL1 sys_reg(3, 0, 15, 5, 5)
  21. #define CLUSTERPMINTENSET_EL1 sys_reg(3, 0, 15, 5, 6)
  22. #define CLUSTERPMINTENCLR_EL1 sys_reg(3, 0, 15, 5, 7)
  23. #define CLUSTERPMCCNTR_EL1 sys_reg(3, 0, 15, 6, 0)
  24. #define CLUSTERPMXEVTYPER_EL1 sys_reg(3, 0, 15, 6, 1)
  25. #define CLUSTERPMXEVCNTR_EL1 sys_reg(3, 0, 15, 6, 2)
  26. #define CLUSTERPMMDCR_EL1 sys_reg(3, 0, 15, 6, 3)
  27. #define CLUSTERPMCEID0_EL1 sys_reg(3, 0, 15, 6, 4)
  28. #define CLUSTERPMCEID1_EL1 sys_reg(3, 0, 15, 6, 5)
  29. static inline u32 __dsu_pmu_read_pmcr(void)
  30. {
  31. return read_sysreg_s(CLUSTERPMCR_EL1);
  32. }
  33. static inline void __dsu_pmu_write_pmcr(u32 val)
  34. {
  35. write_sysreg_s(val, CLUSTERPMCR_EL1);
  36. isb();
  37. }
  38. static inline u32 __dsu_pmu_get_reset_overflow(void)
  39. {
  40. u32 val = read_sysreg_s(CLUSTERPMOVSCLR_EL1);
  41. /* Clear the bit */
  42. write_sysreg_s(val, CLUSTERPMOVSCLR_EL1);
  43. isb();
  44. return val;
  45. }
  46. static inline void __dsu_pmu_select_counter(int counter)
  47. {
  48. write_sysreg_s(counter, CLUSTERPMSELR_EL1);
  49. isb();
  50. }
  51. static inline u64 __dsu_pmu_read_counter(int counter)
  52. {
  53. __dsu_pmu_select_counter(counter);
  54. return read_sysreg_s(CLUSTERPMXEVCNTR_EL1);
  55. }
  56. static inline void __dsu_pmu_write_counter(int counter, u64 val)
  57. {
  58. __dsu_pmu_select_counter(counter);
  59. write_sysreg_s(val, CLUSTERPMXEVCNTR_EL1);
  60. isb();
  61. }
  62. static inline void __dsu_pmu_set_event(int counter, u32 event)
  63. {
  64. __dsu_pmu_select_counter(counter);
  65. write_sysreg_s(event, CLUSTERPMXEVTYPER_EL1);
  66. isb();
  67. }
  68. static inline u64 __dsu_pmu_read_pmccntr(void)
  69. {
  70. return read_sysreg_s(CLUSTERPMCCNTR_EL1);
  71. }
  72. static inline void __dsu_pmu_write_pmccntr(u64 val)
  73. {
  74. write_sysreg_s(val, CLUSTERPMCCNTR_EL1);
  75. isb();
  76. }
  77. static inline void __dsu_pmu_disable_counter(int counter)
  78. {
  79. write_sysreg_s(BIT(counter), CLUSTERPMCNTENCLR_EL1);
  80. isb();
  81. }
  82. static inline void __dsu_pmu_enable_counter(int counter)
  83. {
  84. write_sysreg_s(BIT(counter), CLUSTERPMCNTENSET_EL1);
  85. isb();
  86. }
  87. static inline void __dsu_pmu_counter_interrupt_enable(int counter)
  88. {
  89. write_sysreg_s(BIT(counter), CLUSTERPMINTENSET_EL1);
  90. isb();
  91. }
  92. static inline void __dsu_pmu_counter_interrupt_disable(int counter)
  93. {
  94. write_sysreg_s(BIT(counter), CLUSTERPMINTENCLR_EL1);
  95. isb();
  96. }
  97. static inline u32 __dsu_pmu_read_pmceid(int n)
  98. {
  99. switch (n) {
  100. case 0:
  101. return read_sysreg_s(CLUSTERPMCEID0_EL1);
  102. case 1:
  103. return read_sysreg_s(CLUSTERPMCEID1_EL1);
  104. default:
  105. BUILD_BUG();
  106. return 0;
  107. }
  108. }