18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ARM DynamIQ Shared Unit (DSU) PMU Low level register access routines. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) ARM Limited, 2017. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Suzuki K Poulose <suzuki.poulose@arm.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/bitops.h> 118c2ecf20Sopenharmony_ci#include <linux/build_bug.h> 128c2ecf20Sopenharmony_ci#include <linux/compiler.h> 138c2ecf20Sopenharmony_ci#include <linux/types.h> 148c2ecf20Sopenharmony_ci#include <asm/barrier.h> 158c2ecf20Sopenharmony_ci#include <asm/sysreg.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define CLUSTERPMCR_EL1 sys_reg(3, 0, 15, 5, 0) 198c2ecf20Sopenharmony_ci#define CLUSTERPMCNTENSET_EL1 sys_reg(3, 0, 15, 5, 1) 208c2ecf20Sopenharmony_ci#define CLUSTERPMCNTENCLR_EL1 sys_reg(3, 0, 15, 5, 2) 218c2ecf20Sopenharmony_ci#define CLUSTERPMOVSSET_EL1 sys_reg(3, 0, 15, 5, 3) 228c2ecf20Sopenharmony_ci#define CLUSTERPMOVSCLR_EL1 sys_reg(3, 0, 15, 5, 4) 238c2ecf20Sopenharmony_ci#define CLUSTERPMSELR_EL1 sys_reg(3, 0, 15, 5, 5) 248c2ecf20Sopenharmony_ci#define CLUSTERPMINTENSET_EL1 sys_reg(3, 0, 15, 5, 6) 258c2ecf20Sopenharmony_ci#define CLUSTERPMINTENCLR_EL1 sys_reg(3, 0, 15, 5, 7) 268c2ecf20Sopenharmony_ci#define CLUSTERPMCCNTR_EL1 sys_reg(3, 0, 15, 6, 0) 278c2ecf20Sopenharmony_ci#define CLUSTERPMXEVTYPER_EL1 sys_reg(3, 0, 15, 6, 1) 288c2ecf20Sopenharmony_ci#define CLUSTERPMXEVCNTR_EL1 sys_reg(3, 0, 15, 6, 2) 298c2ecf20Sopenharmony_ci#define CLUSTERPMMDCR_EL1 sys_reg(3, 0, 15, 6, 3) 308c2ecf20Sopenharmony_ci#define CLUSTERPMCEID0_EL1 sys_reg(3, 0, 15, 6, 4) 318c2ecf20Sopenharmony_ci#define CLUSTERPMCEID1_EL1 sys_reg(3, 0, 15, 6, 5) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic inline u32 __dsu_pmu_read_pmcr(void) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci return read_sysreg_s(CLUSTERPMCR_EL1); 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_write_pmcr(u32 val) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci write_sysreg_s(val, CLUSTERPMCR_EL1); 418c2ecf20Sopenharmony_ci isb(); 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic inline u32 __dsu_pmu_get_reset_overflow(void) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci u32 val = read_sysreg_s(CLUSTERPMOVSCLR_EL1); 478c2ecf20Sopenharmony_ci /* Clear the bit */ 488c2ecf20Sopenharmony_ci write_sysreg_s(val, CLUSTERPMOVSCLR_EL1); 498c2ecf20Sopenharmony_ci isb(); 508c2ecf20Sopenharmony_ci return val; 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_select_counter(int counter) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci write_sysreg_s(counter, CLUSTERPMSELR_EL1); 568c2ecf20Sopenharmony_ci isb(); 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic inline u64 __dsu_pmu_read_counter(int counter) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci __dsu_pmu_select_counter(counter); 628c2ecf20Sopenharmony_ci return read_sysreg_s(CLUSTERPMXEVCNTR_EL1); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_write_counter(int counter, u64 val) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci __dsu_pmu_select_counter(counter); 688c2ecf20Sopenharmony_ci write_sysreg_s(val, CLUSTERPMXEVCNTR_EL1); 698c2ecf20Sopenharmony_ci isb(); 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_set_event(int counter, u32 event) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci __dsu_pmu_select_counter(counter); 758c2ecf20Sopenharmony_ci write_sysreg_s(event, CLUSTERPMXEVTYPER_EL1); 768c2ecf20Sopenharmony_ci isb(); 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic inline u64 __dsu_pmu_read_pmccntr(void) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci return read_sysreg_s(CLUSTERPMCCNTR_EL1); 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_write_pmccntr(u64 val) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci write_sysreg_s(val, CLUSTERPMCCNTR_EL1); 878c2ecf20Sopenharmony_ci isb(); 888c2ecf20Sopenharmony_ci} 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_disable_counter(int counter) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci write_sysreg_s(BIT(counter), CLUSTERPMCNTENCLR_EL1); 938c2ecf20Sopenharmony_ci isb(); 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_enable_counter(int counter) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci write_sysreg_s(BIT(counter), CLUSTERPMCNTENSET_EL1); 998c2ecf20Sopenharmony_ci isb(); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_counter_interrupt_enable(int counter) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci write_sysreg_s(BIT(counter), CLUSTERPMINTENSET_EL1); 1058c2ecf20Sopenharmony_ci isb(); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline void __dsu_pmu_counter_interrupt_disable(int counter) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci write_sysreg_s(BIT(counter), CLUSTERPMINTENCLR_EL1); 1118c2ecf20Sopenharmony_ci isb(); 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic inline u32 __dsu_pmu_read_pmceid(int n) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci switch (n) { 1188c2ecf20Sopenharmony_ci case 0: 1198c2ecf20Sopenharmony_ci return read_sysreg_s(CLUSTERPMCEID0_EL1); 1208c2ecf20Sopenharmony_ci case 1: 1218c2ecf20Sopenharmony_ci return read_sysreg_s(CLUSTERPMCEID1_EL1); 1228c2ecf20Sopenharmony_ci default: 1238c2ecf20Sopenharmony_ci BUILD_BUG(); 1248c2ecf20Sopenharmony_ci return 0; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci} 127