Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

coresight: Interpret ETMv4 config with ATTR_CFG_GET_FLD()

Remove hard coded bitfield extractions and shifts and replace with
ATTR_CFG_GET_FLD().

ETM4_CFG_BIT_BB was defined to give the register bit positions to
userspace, TRCCONFIGR_BB should be used in the kernel so replace it.

Reviewed-by: Leo Yan <leo.yan@arm.com>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Tested-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20251128-james-cs-syncfreq-v8-9-4d319764cc58@linaro.org

authored by

James Clark and committed by
Suzuki K Poulose
afed86e6 b945d367

+19 -25
+19 -25
drivers/hwtracing/coresight/coresight-etm4x-core.c
··· 29 29 #include <linux/seq_file.h> 30 30 #include <linux/uaccess.h> 31 31 #include <linux/perf_event.h> 32 + #include <linux/perf/arm_pmu.h> 32 33 #include <linux/platform_device.h> 33 34 #include <linux/pm_runtime.h> 34 35 #include <linux/property.h> ··· 781 780 goto out; 782 781 783 782 /* Go from generic option to ETMv4 specifics */ 784 - if (attr->config & BIT(ETM_OPT_CYCACC)) { 783 + if (ATTR_CFG_GET_FLD(attr, cycacc)) { 785 784 config->cfg |= TRCCONFIGR_CCI; 786 785 /* TRM: Must program this for cycacc to work */ 787 - cc_threshold = attr->config3 & ETM_CYC_THRESHOLD_MASK; 786 + cc_threshold = ATTR_CFG_GET_FLD(attr, cc_threshold); 788 787 if (!cc_threshold) 789 788 cc_threshold = ETM_CYC_THRESHOLD_DEFAULT; 790 789 if (cc_threshold < drvdata->ccitmin) 791 790 cc_threshold = drvdata->ccitmin; 792 791 config->ccctlr = cc_threshold; 793 792 } 794 - if (attr->config & BIT(ETM_OPT_TS)) { 793 + if (ATTR_CFG_GET_FLD(attr, timestamp)) { 795 794 /* 796 795 * Configure timestamps to be emitted at regular intervals in 797 796 * order to correlate instructions executed on different CPUs ··· 811 810 } 812 811 813 812 /* Only trace contextID when runs in root PID namespace */ 814 - if ((attr->config & BIT(ETM_OPT_CTXTID)) && 813 + if (ATTR_CFG_GET_FLD(attr, contextid1) && 815 814 task_is_in_init_pid_ns(current)) 816 815 /* bit[6], Context ID tracing bit */ 817 816 config->cfg |= TRCCONFIGR_CID; 818 817 819 818 /* 820 - * If set bit ETM_OPT_CTXTID2 in perf config, this asks to trace VMID 821 - * for recording CONTEXTIDR_EL2. Do not enable VMID tracing if the 822 - * kernel is not running in EL2. 819 + * If set bit contextid2 in perf config, this asks to trace VMID for 820 + * recording CONTEXTIDR_EL2. Do not enable VMID tracing if the kernel 821 + * is not running in EL2. 823 822 */ 824 - if (attr->config & BIT(ETM_OPT_CTXTID2)) { 823 + if (ATTR_CFG_GET_FLD(attr, contextid2)) { 825 824 if (!is_kernel_in_hyp_mode()) { 826 825 ret = -EINVAL; 827 826 goto out; ··· 832 831 } 833 832 834 833 /* return stack - enable if selected and supported */ 835 - if ((attr->config & BIT(ETM_OPT_RETSTK)) && drvdata->retstack) 834 + if (ATTR_CFG_GET_FLD(attr, retstack) && drvdata->retstack) 836 835 /* bit[12], Return stack enable bit */ 837 836 config->cfg |= TRCCONFIGR_RS; 838 837 839 838 /* 840 - * Set any selected configuration and preset. 841 - * 842 - * This extracts the values of PMU_FORMAT_ATTR(configid) and PMU_FORMAT_ATTR(preset) 843 - * in the perf attributes defined in coresight-etm-perf.c. 844 - * configid uses bits 63:32 of attr->config2, preset uses bits 3:0 of attr->config. 845 - * A zero configid means no configuration active, preset = 0 means no preset selected. 839 + * Set any selected configuration and preset. A zero configid means no 840 + * configuration active, preset = 0 means no preset selected. 846 841 */ 847 - if (attr->config2 & GENMASK_ULL(63, 32)) { 848 - cfg_hash = (u32)(attr->config2 >> 32); 849 - preset = attr->config & 0xF; 842 + cfg_hash = ATTR_CFG_GET_FLD(attr, configid); 843 + if (cfg_hash) { 844 + preset = ATTR_CFG_GET_FLD(attr, preset); 850 845 ret = cscfg_csdev_enable_active_config(csdev, cfg_hash, preset); 851 846 } 852 847 853 848 /* branch broadcast - enable if selected and supported */ 854 - if (attr->config & BIT(ETM_OPT_BRANCH_BROADCAST)) { 849 + if (ATTR_CFG_GET_FLD(attr, branch_broadcast)) { 855 850 if (!drvdata->trcbb) { 856 851 /* 857 852 * Missing BB support could cause silent decode errors ··· 856 859 ret = -EINVAL; 857 860 goto out; 858 861 } else { 859 - config->cfg |= BIT(ETM4_CFG_BIT_BB); 862 + config->cfg |= TRCCONFIGR_BB; 860 863 } 861 864 } 862 865 ··· 1080 1083 return -EINVAL; 1081 1084 1082 1085 etm4_disable_hw(drvdata); 1083 - /* 1084 - * The config_id occupies bits 63:32 of the config2 perf event attr 1085 - * field. If this is non-zero then we will have enabled a config. 1086 - */ 1087 - if (attr->config2 & GENMASK_ULL(63, 32)) 1086 + /* If configid is non-zero then we will have enabled a config. */ 1087 + if (ATTR_CFG_GET_FLD(attr, configid)) 1088 1088 cscfg_csdev_disable_active_config(csdev); 1089 1089 1090 1090 /*