1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * ARM DynamIQ Shared Unit (DSU) PMU Low level register access routines.
5 * Copyright (C) ARM Limited, 2017.
7 * Author: Suzuki K Poulose <suzuki.poulose@arm.com>
10 #include <linux/bitops.h>
11 #include <linux/build_bug.h>
12 #include <linux/compiler.h>
13 #include <linux/types.h>
14 #include <asm/barrier.h>
15 #include <asm/sysreg.h>
18 #define CLUSTERPMCR_EL1 sys_reg(3, 0, 15, 5, 0)
19 #define CLUSTERPMCNTENSET_EL1 sys_reg(3, 0, 15, 5, 1)
20 #define CLUSTERPMCNTENCLR_EL1 sys_reg(3, 0, 15, 5, 2)
21 #define CLUSTERPMOVSSET_EL1 sys_reg(3, 0, 15, 5, 3)
22 #define CLUSTERPMOVSCLR_EL1 sys_reg(3, 0, 15, 5, 4)
23 #define CLUSTERPMSELR_EL1 sys_reg(3, 0, 15, 5, 5)
24 #define CLUSTERPMINTENSET_EL1 sys_reg(3, 0, 15, 5, 6)
25 #define CLUSTERPMINTENCLR_EL1 sys_reg(3, 0, 15, 5, 7)
26 #define CLUSTERPMCCNTR_EL1 sys_reg(3, 0, 15, 6, 0)
27 #define CLUSTERPMXEVTYPER_EL1 sys_reg(3, 0, 15, 6, 1)
28 #define CLUSTERPMXEVCNTR_EL1 sys_reg(3, 0, 15, 6, 2)
29 #define CLUSTERPMMDCR_EL1 sys_reg(3, 0, 15, 6, 3)
30 #define CLUSTERPMCEID0_EL1 sys_reg(3, 0, 15, 6, 4)
31 #define CLUSTERPMCEID1_EL1 sys_reg(3, 0, 15, 6, 5)
33 static inline u32
__dsu_pmu_read_pmcr(void)
35 return read_sysreg_s(CLUSTERPMCR_EL1
);
38 static inline void __dsu_pmu_write_pmcr(u32 val
)
40 write_sysreg_s(val
, CLUSTERPMCR_EL1
);
44 static inline u32
__dsu_pmu_get_reset_overflow(void)
46 u32 val
= read_sysreg_s(CLUSTERPMOVSCLR_EL1
);
48 write_sysreg_s(val
, CLUSTERPMOVSCLR_EL1
);
53 static inline void __dsu_pmu_select_counter(int counter
)
55 write_sysreg_s(counter
, CLUSTERPMSELR_EL1
);
59 static inline u64
__dsu_pmu_read_counter(int counter
)
61 __dsu_pmu_select_counter(counter
);
62 return read_sysreg_s(CLUSTERPMXEVCNTR_EL1
);
65 static inline void __dsu_pmu_write_counter(int counter
, u64 val
)
67 __dsu_pmu_select_counter(counter
);
68 write_sysreg_s(val
, CLUSTERPMXEVCNTR_EL1
);
72 static inline void __dsu_pmu_set_event(int counter
, u32 event
)
74 __dsu_pmu_select_counter(counter
);
75 write_sysreg_s(event
, CLUSTERPMXEVTYPER_EL1
);
79 static inline u64
__dsu_pmu_read_pmccntr(void)
81 return read_sysreg_s(CLUSTERPMCCNTR_EL1
);
84 static inline void __dsu_pmu_write_pmccntr(u64 val
)
86 write_sysreg_s(val
, CLUSTERPMCCNTR_EL1
);
90 static inline void __dsu_pmu_disable_counter(int counter
)
92 write_sysreg_s(BIT(counter
), CLUSTERPMCNTENCLR_EL1
);
96 static inline void __dsu_pmu_enable_counter(int counter
)
98 write_sysreg_s(BIT(counter
), CLUSTERPMCNTENSET_EL1
);
102 static inline void __dsu_pmu_counter_interrupt_enable(int counter
)
104 write_sysreg_s(BIT(counter
), CLUSTERPMINTENSET_EL1
);
108 static inline void __dsu_pmu_counter_interrupt_disable(int counter
)
110 write_sysreg_s(BIT(counter
), CLUSTERPMINTENCLR_EL1
);
115 static inline u32
__dsu_pmu_read_pmceid(int n
)
119 return read_sysreg_s(CLUSTERPMCEID0_EL1
);
121 return read_sysreg_s(CLUSTERPMCEID1_EL1
);