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 911fba29aSZaid Al-Bassam #include <linux/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) 16*3bc879e3SGeert 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) 24*3bc879e3SGeert 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) 31*3bc879e3SGeert Uytterhoeven static inline void write_pmevtypern(int n, unsigned long val) 32df29ddf4SMarc Zyngier { 33df29ddf4SMarc Zyngier PMEVN_SWITCH(n, WRITE_PMEVTYPERN); 34df29ddf4SMarc Zyngier } 35df29ddf4SMarc Zyngier 36df29ddf4SMarc Zyngier static inline unsigned long read_pmmir(void) 37df29ddf4SMarc Zyngier { 38df29ddf4SMarc Zyngier return read_cpuid(PMMIR_EL1); 39df29ddf4SMarc Zyngier } 40df29ddf4SMarc Zyngier 41df29ddf4SMarc Zyngier static inline u32 read_pmuver(void) 42df29ddf4SMarc Zyngier { 43df29ddf4SMarc Zyngier u64 dfr0 = read_sysreg(id_aa64dfr0_el1); 44df29ddf4SMarc Zyngier 45df29ddf4SMarc Zyngier return cpuid_feature_extract_unsigned_field(dfr0, 46df29ddf4SMarc Zyngier ID_AA64DFR0_EL1_PMUVer_SHIFT); 47df29ddf4SMarc Zyngier } 48df29ddf4SMarc Zyngier 49df29ddf4SMarc Zyngier static inline void write_pmcr(u32 val) 50df29ddf4SMarc Zyngier { 51df29ddf4SMarc Zyngier write_sysreg(val, pmcr_el0); 52df29ddf4SMarc Zyngier } 53df29ddf4SMarc Zyngier 54df29ddf4SMarc Zyngier static inline u32 read_pmcr(void) 55df29ddf4SMarc Zyngier { 56df29ddf4SMarc Zyngier return read_sysreg(pmcr_el0); 57df29ddf4SMarc Zyngier } 58df29ddf4SMarc Zyngier 59df29ddf4SMarc Zyngier static inline void write_pmselr(u32 val) 60df29ddf4SMarc Zyngier { 61df29ddf4SMarc Zyngier write_sysreg(val, pmselr_el0); 62df29ddf4SMarc Zyngier } 63df29ddf4SMarc Zyngier 64df29ddf4SMarc Zyngier static inline void write_pmccntr(u64 val) 65df29ddf4SMarc Zyngier { 66df29ddf4SMarc Zyngier write_sysreg(val, pmccntr_el0); 67df29ddf4SMarc Zyngier } 68df29ddf4SMarc Zyngier 69df29ddf4SMarc Zyngier static inline u64 read_pmccntr(void) 70df29ddf4SMarc Zyngier { 71df29ddf4SMarc Zyngier return read_sysreg(pmccntr_el0); 72df29ddf4SMarc Zyngier } 73df29ddf4SMarc Zyngier 74df29ddf4SMarc Zyngier static inline void write_pmxevcntr(u32 val) 75df29ddf4SMarc Zyngier { 76df29ddf4SMarc Zyngier write_sysreg(val, pmxevcntr_el0); 77df29ddf4SMarc Zyngier } 78df29ddf4SMarc Zyngier 79df29ddf4SMarc Zyngier static inline u32 read_pmxevcntr(void) 80df29ddf4SMarc Zyngier { 81df29ddf4SMarc Zyngier return read_sysreg(pmxevcntr_el0); 82df29ddf4SMarc Zyngier } 83df29ddf4SMarc Zyngier 84df29ddf4SMarc Zyngier static inline void write_pmxevtyper(u32 val) 85df29ddf4SMarc Zyngier { 86df29ddf4SMarc Zyngier write_sysreg(val, pmxevtyper_el0); 87df29ddf4SMarc Zyngier } 88df29ddf4SMarc Zyngier 89df29ddf4SMarc Zyngier static inline void write_pmcntenset(u32 val) 90df29ddf4SMarc Zyngier { 91df29ddf4SMarc Zyngier write_sysreg(val, pmcntenset_el0); 92df29ddf4SMarc Zyngier } 93df29ddf4SMarc Zyngier 94df29ddf4SMarc Zyngier static inline void write_pmcntenclr(u32 val) 95df29ddf4SMarc Zyngier { 96df29ddf4SMarc Zyngier write_sysreg(val, pmcntenclr_el0); 97df29ddf4SMarc Zyngier } 98df29ddf4SMarc Zyngier 99df29ddf4SMarc Zyngier static inline void write_pmintenset(u32 val) 100df29ddf4SMarc Zyngier { 101df29ddf4SMarc Zyngier write_sysreg(val, pmintenset_el1); 102df29ddf4SMarc Zyngier } 103df29ddf4SMarc Zyngier 104df29ddf4SMarc Zyngier static inline void write_pmintenclr(u32 val) 105df29ddf4SMarc Zyngier { 106df29ddf4SMarc Zyngier write_sysreg(val, pmintenclr_el1); 107df29ddf4SMarc Zyngier } 108df29ddf4SMarc Zyngier 109df29ddf4SMarc Zyngier static inline void write_pmccfiltr(u32 val) 110df29ddf4SMarc Zyngier { 111df29ddf4SMarc Zyngier write_sysreg(val, pmccfiltr_el0); 112df29ddf4SMarc Zyngier } 113df29ddf4SMarc Zyngier 114df29ddf4SMarc Zyngier static inline void write_pmovsclr(u32 val) 115df29ddf4SMarc Zyngier { 116df29ddf4SMarc Zyngier write_sysreg(val, pmovsclr_el0); 117df29ddf4SMarc Zyngier } 118df29ddf4SMarc Zyngier 119df29ddf4SMarc Zyngier static inline u32 read_pmovsclr(void) 120df29ddf4SMarc Zyngier { 121df29ddf4SMarc Zyngier return read_sysreg(pmovsclr_el0); 122df29ddf4SMarc Zyngier } 123df29ddf4SMarc Zyngier 124df29ddf4SMarc Zyngier static inline void write_pmuserenr(u32 val) 125df29ddf4SMarc Zyngier { 126df29ddf4SMarc Zyngier write_sysreg(val, pmuserenr_el0); 127df29ddf4SMarc Zyngier } 128df29ddf4SMarc Zyngier 129df29ddf4SMarc Zyngier static inline u32 read_pmceid0(void) 130df29ddf4SMarc Zyngier { 131df29ddf4SMarc Zyngier return read_sysreg(pmceid0_el0); 132df29ddf4SMarc Zyngier } 133df29ddf4SMarc Zyngier 134df29ddf4SMarc Zyngier static inline u32 read_pmceid1(void) 135df29ddf4SMarc Zyngier { 136df29ddf4SMarc Zyngier return read_sysreg(pmceid1_el0); 137df29ddf4SMarc Zyngier } 138df29ddf4SMarc Zyngier 13971143277SZaid Al-Bassam static inline bool pmuv3_implemented(int pmuver) 14071143277SZaid Al-Bassam { 14171143277SZaid Al-Bassam return !(pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF || 14271143277SZaid Al-Bassam pmuver == ID_AA64DFR0_EL1_PMUVer_NI); 14371143277SZaid Al-Bassam } 14471143277SZaid Al-Bassam 14571143277SZaid Al-Bassam static inline bool is_pmuv3p4(int pmuver) 14671143277SZaid Al-Bassam { 14771143277SZaid Al-Bassam return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P4; 14871143277SZaid Al-Bassam } 14971143277SZaid Al-Bassam 15071143277SZaid Al-Bassam static inline bool is_pmuv3p5(int pmuver) 15171143277SZaid Al-Bassam { 15271143277SZaid Al-Bassam return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P5; 15371143277SZaid Al-Bassam } 15471143277SZaid Al-Bassam 155df29ddf4SMarc Zyngier #endif 156