Introduce a new helper, has_feat_trf(), to detect whether FEAT_TRF is implemented.
To avoid a SMP call for checking the system register, the function directly reads the configured value. If the value is non-zero, it indicates that the feature is present.
Signed-off-by: Leo Yan leo.yan@arm.com --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 ++++---- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 2 +- drivers/hwtracing/coresight/coresight-etm4x.h | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 42e5d37403ad..08deb67fe0ef 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -252,7 +252,7 @@ static void etm4x_prohibit_trace(struct etmv4_drvdata *drvdata) u64 trfcr;
/* If the CPU doesn't support FEAT_TRF, nothing to do */ - if (!drvdata->trfcr) + if (!has_feat_trf(drvdata)) return;
trfcr = drvdata->trfcr & ~(TRFCR_EL1_ExTRE | TRFCR_EL1_E0TRE); @@ -288,7 +288,7 @@ static void etm4x_allow_trace(struct etmv4_drvdata *drvdata) u64 trfcr, guest_trfcr;
/* If the CPU doesn't support FEAT_TRF, nothing to do */ - if (!drvdata->trfcr) + if (!has_feat_trf(drvdata)) return;
if (drvdata->config.mode & ETM_MODE_EXCL_HOST) @@ -1931,7 +1931,7 @@ static int etm4_cpu_save(struct etmv4_drvdata *drvdata) int ret = 0;
/* Save the TRFCR irrespective of whether the ETM is ON */ - if (drvdata->trfcr) + if (has_feat_trf(drvdata)) drvdata->save_trfcr = read_trfcr(); /* * Save and restore the ETM Trace registers only if @@ -2043,7 +2043,7 @@ static void __etm4_cpu_restore(struct etmv4_drvdata *drvdata)
static void etm4_cpu_restore(struct etmv4_drvdata *drvdata) { - if (drvdata->trfcr) + if (has_feat_trf(drvdata)) write_trfcr(drvdata->save_trfcr); if (drvdata->state_needs_restore) __etm4_cpu_restore(drvdata); diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index ab251865b893..8afcc553bb97 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -2315,7 +2315,7 @@ static ssize_t ts_source_show(struct device *dev, int val; struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent);
- if (!drvdata->trfcr) { + if (!has_feat_trf(drvdata)) { val = -1; goto out; } diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtracing/coresight/coresight-etm4x.h index ac649515054d..1840e658eda2 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -1068,5 +1068,14 @@ static inline bool etm4x_is_ete(struct etmv4_drvdata *drvdata) return drvdata->arch >= ETM_ARCH_ETE; }
+static inline bool has_feat_trf(struct etmv4_drvdata *drvdata) +{ + /* + * drvdata->trfcr is initialized to a non-zero value if trace + * filtering is supported. + */ + return !!drvdata->trfcr; +} + void etm4_release_trace_id(struct etmv4_drvdata *drvdata); #endif