xref: /linux/arch/arm64/include/asm/arm_pmuv3.h (revision d8226d8cfbaf5eb9771af8ad8b4e58697e2ffb74)
1df29ddf4SMarc Zyngier /* SPDX-License-Identifier: GPL-2.0 */
2df29ddf4SMarc Zyngier /*
3df29ddf4SMarc Zyngier  * Copyright (C) 2012 ARM Ltd.
4df29ddf4SMarc Zyngier  */
5df29ddf4SMarc Zyngier 
6df29ddf4SMarc Zyngier #ifndef __ASM_PMUV3_H
7df29ddf4SMarc Zyngier #define __ASM_PMUV3_H
8df29ddf4SMarc Zyngier 
9d688ffa2SRob Herring (Arm) #include <asm/kvm_host.h>
1011fba29aSZaid Al-Bassam 
11df29ddf4SMarc Zyngier #include <asm/cpufeature.h>
12df29ddf4SMarc Zyngier #include <asm/sysreg.h>
13df29ddf4SMarc Zyngier 
14df29ddf4SMarc Zyngier #define RETURN_READ_PMEVCNTRN(n) \
15df29ddf4SMarc Zyngier 	return read_sysreg(pmevcntr##n##_el0)
163bc879e3SGeert Uytterhoeven static inline unsigned long read_pmevcntrn(int n)
17df29ddf4SMarc Zyngier {
18df29ddf4SMarc Zyngier 	PMEVN_SWITCH(n, RETURN_READ_PMEVCNTRN);
19df29ddf4SMarc Zyngier 	return 0;
20df29ddf4SMarc Zyngier }
21df29ddf4SMarc Zyngier 
22df29ddf4SMarc Zyngier #define WRITE_PMEVCNTRN(n) \
23df29ddf4SMarc Zyngier 	write_sysreg(val, pmevcntr##n##_el0)
243bc879e3SGeert Uytterhoeven static inline void write_pmevcntrn(int n, unsigned long val)
25df29ddf4SMarc Zyngier {
26df29ddf4SMarc Zyngier 	PMEVN_SWITCH(n, WRITE_PMEVCNTRN);
27df29ddf4SMarc Zyngier }
28df29ddf4SMarc Zyngier 
29df29ddf4SMarc Zyngier #define WRITE_PMEVTYPERN(n) \
30df29ddf4SMarc Zyngier 	write_sysreg(val, pmevtyper##n##_el0)
313bc879e3SGeert Uytterhoeven static inline void write_pmevtypern(int n, unsigned long val)
32df29ddf4SMarc Zyngier {
33df29ddf4SMarc Zyngier 	PMEVN_SWITCH(n, WRITE_PMEVTYPERN);
34df29ddf4SMarc Zyngier }
35df29ddf4SMarc Zyngier 
36741ee528SRob Herring (Arm) #define RETURN_READ_PMEVTYPERN(n) \
37741ee528SRob Herring (Arm) 	return read_sysreg(pmevtyper##n##_el0)
38741ee528SRob Herring (Arm) static inline unsigned long read_pmevtypern(int n)
39741ee528SRob Herring (Arm) {
40741ee528SRob Herring (Arm) 	PMEVN_SWITCH(n, RETURN_READ_PMEVTYPERN);
41741ee528SRob Herring (Arm) 	return 0;
42741ee528SRob Herring (Arm) }
43741ee528SRob Herring (Arm) 
44df29ddf4SMarc Zyngier static inline unsigned long read_pmmir(void)
45df29ddf4SMarc Zyngier {
46df29ddf4SMarc Zyngier 	return read_cpuid(PMMIR_EL1);
47df29ddf4SMarc Zyngier }
48df29ddf4SMarc Zyngier 
49df29ddf4SMarc Zyngier static inline u32 read_pmuver(void)
50df29ddf4SMarc Zyngier {
51df29ddf4SMarc Zyngier 	u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
52df29ddf4SMarc Zyngier 
53df29ddf4SMarc Zyngier 	return cpuid_feature_extract_unsigned_field(dfr0,
54df29ddf4SMarc Zyngier 			ID_AA64DFR0_EL1_PMUVer_SHIFT);
55df29ddf4SMarc Zyngier }
56df29ddf4SMarc Zyngier 
57*d8226d8cSRob Herring (Arm) static inline bool pmuv3_has_icntr(void)
58*d8226d8cSRob Herring (Arm) {
59*d8226d8cSRob Herring (Arm) 	u64 dfr1 = read_sysreg(id_aa64dfr1_el1);
60*d8226d8cSRob Herring (Arm) 
61*d8226d8cSRob Herring (Arm) 	return !!cpuid_feature_extract_unsigned_field(dfr1,
62*d8226d8cSRob Herring (Arm) 			ID_AA64DFR1_EL1_PMICNTR_SHIFT);
63*d8226d8cSRob Herring (Arm) }
64*d8226d8cSRob Herring (Arm) 
65403edfa4SIlkka Koskinen static inline void write_pmcr(u64 val)
66df29ddf4SMarc Zyngier {
67df29ddf4SMarc Zyngier 	write_sysreg(val, pmcr_el0);
68df29ddf4SMarc Zyngier }
69df29ddf4SMarc Zyngier 
70403edfa4SIlkka Koskinen static inline u64 read_pmcr(void)
71df29ddf4SMarc Zyngier {
72df29ddf4SMarc Zyngier 	return read_sysreg(pmcr_el0);
73df29ddf4SMarc Zyngier }
74df29ddf4SMarc Zyngier 
75df29ddf4SMarc Zyngier static inline void write_pmselr(u32 val)
76df29ddf4SMarc Zyngier {
77df29ddf4SMarc Zyngier 	write_sysreg(val, pmselr_el0);
78df29ddf4SMarc Zyngier }
79df29ddf4SMarc Zyngier 
80df29ddf4SMarc Zyngier static inline void write_pmccntr(u64 val)
81df29ddf4SMarc Zyngier {
82df29ddf4SMarc Zyngier 	write_sysreg(val, pmccntr_el0);
83df29ddf4SMarc Zyngier }
84df29ddf4SMarc Zyngier 
85df29ddf4SMarc Zyngier static inline u64 read_pmccntr(void)
86df29ddf4SMarc Zyngier {
87df29ddf4SMarc Zyngier 	return read_sysreg(pmccntr_el0);
88df29ddf4SMarc Zyngier }
89df29ddf4SMarc Zyngier 
90*d8226d8cSRob Herring (Arm) static inline void write_pmicntr(u64 val)
91*d8226d8cSRob Herring (Arm) {
92*d8226d8cSRob Herring (Arm) 	write_sysreg_s(val, SYS_PMICNTR_EL0);
93*d8226d8cSRob Herring (Arm) }
94*d8226d8cSRob Herring (Arm) 
95*d8226d8cSRob Herring (Arm) static inline u64 read_pmicntr(void)
96*d8226d8cSRob Herring (Arm) {
97*d8226d8cSRob Herring (Arm) 	return read_sysreg_s(SYS_PMICNTR_EL0);
98*d8226d8cSRob Herring (Arm) }
99*d8226d8cSRob Herring (Arm) 
100a4a6e207SRob Herring (Arm) static inline void write_pmcntenset(u64 val)
101df29ddf4SMarc Zyngier {
102df29ddf4SMarc Zyngier 	write_sysreg(val, pmcntenset_el0);
103df29ddf4SMarc Zyngier }
104df29ddf4SMarc Zyngier 
105a4a6e207SRob Herring (Arm) static inline void write_pmcntenclr(u64 val)
106df29ddf4SMarc Zyngier {
107df29ddf4SMarc Zyngier 	write_sysreg(val, pmcntenclr_el0);
108df29ddf4SMarc Zyngier }
109df29ddf4SMarc Zyngier 
110a4a6e207SRob Herring (Arm) static inline void write_pmintenset(u64 val)
111df29ddf4SMarc Zyngier {
112df29ddf4SMarc Zyngier 	write_sysreg(val, pmintenset_el1);
113df29ddf4SMarc Zyngier }
114df29ddf4SMarc Zyngier 
115a4a6e207SRob Herring (Arm) static inline void write_pmintenclr(u64 val)
116df29ddf4SMarc Zyngier {
117df29ddf4SMarc Zyngier 	write_sysreg(val, pmintenclr_el1);
118df29ddf4SMarc Zyngier }
119df29ddf4SMarc Zyngier 
120403edfa4SIlkka Koskinen static inline void write_pmccfiltr(u64 val)
121df29ddf4SMarc Zyngier {
122df29ddf4SMarc Zyngier 	write_sysreg(val, pmccfiltr_el0);
123df29ddf4SMarc Zyngier }
124df29ddf4SMarc Zyngier 
125741ee528SRob Herring (Arm) static inline u64 read_pmccfiltr(void)
126741ee528SRob Herring (Arm) {
127741ee528SRob Herring (Arm) 	return read_sysreg(pmccfiltr_el0);
128741ee528SRob Herring (Arm) }
129741ee528SRob Herring (Arm) 
130*d8226d8cSRob Herring (Arm) static inline void write_pmicfiltr(u64 val)
131*d8226d8cSRob Herring (Arm) {
132*d8226d8cSRob Herring (Arm) 	write_sysreg_s(val, SYS_PMICFILTR_EL0);
133*d8226d8cSRob Herring (Arm) }
134*d8226d8cSRob Herring (Arm) 
135*d8226d8cSRob Herring (Arm) static inline u64 read_pmicfiltr(void)
136*d8226d8cSRob Herring (Arm) {
137*d8226d8cSRob Herring (Arm) 	return read_sysreg_s(SYS_PMICFILTR_EL0);
138*d8226d8cSRob Herring (Arm) }
139*d8226d8cSRob Herring (Arm) 
140a4a6e207SRob Herring (Arm) static inline void write_pmovsclr(u64 val)
141df29ddf4SMarc Zyngier {
142df29ddf4SMarc Zyngier 	write_sysreg(val, pmovsclr_el0);
143df29ddf4SMarc Zyngier }
144df29ddf4SMarc Zyngier 
145a4a6e207SRob Herring (Arm) static inline u64 read_pmovsclr(void)
146df29ddf4SMarc Zyngier {
147df29ddf4SMarc Zyngier 	return read_sysreg(pmovsclr_el0);
148df29ddf4SMarc Zyngier }
149df29ddf4SMarc Zyngier 
150df29ddf4SMarc Zyngier static inline void write_pmuserenr(u32 val)
151df29ddf4SMarc Zyngier {
152df29ddf4SMarc Zyngier 	write_sysreg(val, pmuserenr_el0);
153df29ddf4SMarc Zyngier }
154df29ddf4SMarc Zyngier 
155403edfa4SIlkka Koskinen static inline u64 read_pmceid0(void)
156df29ddf4SMarc Zyngier {
157df29ddf4SMarc Zyngier 	return read_sysreg(pmceid0_el0);
158df29ddf4SMarc Zyngier }
159df29ddf4SMarc Zyngier 
160403edfa4SIlkka Koskinen static inline u64 read_pmceid1(void)
161df29ddf4SMarc Zyngier {
162df29ddf4SMarc Zyngier 	return read_sysreg(pmceid1_el0);
163df29ddf4SMarc Zyngier }
164df29ddf4SMarc Zyngier 
16571143277SZaid Al-Bassam static inline bool pmuv3_implemented(int pmuver)
16671143277SZaid Al-Bassam {
16771143277SZaid Al-Bassam 	return !(pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF ||
16871143277SZaid Al-Bassam 		 pmuver == ID_AA64DFR0_EL1_PMUVer_NI);
16971143277SZaid Al-Bassam }
17071143277SZaid Al-Bassam 
17171143277SZaid Al-Bassam static inline bool is_pmuv3p4(int pmuver)
17271143277SZaid Al-Bassam {
17371143277SZaid Al-Bassam 	return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P4;
17471143277SZaid Al-Bassam }
17571143277SZaid Al-Bassam 
17671143277SZaid Al-Bassam static inline bool is_pmuv3p5(int pmuver)
17771143277SZaid Al-Bassam {
17871143277SZaid Al-Bassam 	return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P5;
17971143277SZaid Al-Bassam }
18071143277SZaid Al-Bassam 
181df29ddf4SMarc Zyngier #endif
182