1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2012 ARM Ltd.
9 #include <linux/kvm_host.h>
11 #include <asm/cpufeature.h>
12 #include <asm/sysreg.h>
14 #define RETURN_READ_PMEVCNTRN(n) \
15 return read_sysreg(pmevcntr##n##_el0)
16 static inline unsigned long read_pmevcntrn(int n)
18 PMEVN_SWITCH(n, RETURN_READ_PMEVCNTRN);
22 #define WRITE_PMEVCNTRN(n) \
23 write_sysreg(val, pmevcntr##n##_el0)
24 static inline void write_pmevcntrn(int n, unsigned long val)
26 PMEVN_SWITCH(n, WRITE_PMEVCNTRN);
29 #define WRITE_PMEVTYPERN(n) \
30 write_sysreg(val, pmevtyper##n##_el0)
31 static inline void write_pmevtypern(int n, unsigned long val)
33 PMEVN_SWITCH(n, WRITE_PMEVTYPERN);
36 static inline unsigned long read_pmmir(void)
38 return read_cpuid(PMMIR_EL1);
41 static inline u32 read_pmuver(void)
43 u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
45 return cpuid_feature_extract_unsigned_field(dfr0,
46 ID_AA64DFR0_EL1_PMUVer_SHIFT);
49 static inline void write_pmcr(u64 val)
51 write_sysreg(val, pmcr_el0);
54 static inline u64 read_pmcr(void)
56 return read_sysreg(pmcr_el0);
59 static inline void write_pmselr(u32 val)
61 write_sysreg(val, pmselr_el0);
64 static inline void write_pmccntr(u64 val)
66 write_sysreg(val, pmccntr_el0);
69 static inline u64 read_pmccntr(void)
71 return read_sysreg(pmccntr_el0);
74 static inline void write_pmcntenset(u32 val)
76 write_sysreg(val, pmcntenset_el0);
79 static inline void write_pmcntenclr(u32 val)
81 write_sysreg(val, pmcntenclr_el0);
84 static inline void write_pmintenset(u32 val)
86 write_sysreg(val, pmintenset_el1);
89 static inline void write_pmintenclr(u32 val)
91 write_sysreg(val, pmintenclr_el1);
94 static inline void write_pmccfiltr(u64 val)
96 write_sysreg(val, pmccfiltr_el0);
99 static inline void write_pmovsclr(u32 val)
101 write_sysreg(val, pmovsclr_el0);
104 static inline u32 read_pmovsclr(void)
106 return read_sysreg(pmovsclr_el0);
109 static inline void write_pmuserenr(u32 val)
111 write_sysreg(val, pmuserenr_el0);
114 static inline u64 read_pmceid0(void)
116 return read_sysreg(pmceid0_el0);
119 static inline u64 read_pmceid1(void)
121 return read_sysreg(pmceid1_el0);
124 static inline bool pmuv3_implemented(int pmuver)
126 return !(pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF ||
127 pmuver == ID_AA64DFR0_EL1_PMUVer_NI);
130 static inline bool is_pmuv3p4(int pmuver)
132 return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P4;
135 static inline bool is_pmuv3p5(int pmuver)
137 return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P5;