[PATCH v2 5/5] coresight-tnoc: add nodes to configure freq packet

Yuanfang Zhang
2025-02-26T13:25:03Z

Three nodes for freq packet config are added here:

1. freq_type: used to set the type of issued ATB FREQ packets.
0: 'FREQ' packets; 1: 'FREQ_TS' packets.

2. freq_req_val: used to set frequency values carried by 'FREQ'
and 'FREQ_TS' packets.

3. freq_ts_req: writing '1' to issue a 'FREQ' or 'FREQ_TS' packet.

Signed-off-by: Yuanfang Zhang <quic_yuanfang@quicinc.com>
---
drivers/hwtracing/coresight/coresight-tnoc.c | 97 ++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-tnoc.c b/drivers/hwtracing/coresight/coresight-tnoc.c
index ad973749250644760adc4dfd855240026d0a744c..24b1add4c921866b944d756e563d50b4172d583a 100644
--- a/drivers/hwtracing/coresight/coresight-tnoc.c
+++ b/drivers/hwtracing/coresight/coresight-tnoc.c
@@ -112,10 +112,107 @@ static ssize_t flag_type_show(struct device *dev,
}
static DEVICE_ATTR_RW(flag_type);

+static ssize_t freq_type_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct trace_noc_drvdata *drvdata = dev_get_drvdata(dev->parent);
+
+ return sysfs_emit(buf, "%u\n", drvdata->freq_type);
+}
+
+static ssize_t freq_type_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf,
+ size_t size)
+{
+ struct trace_noc_drvdata *drvdata = dev_get_drvdata(dev->parent);
+ unsigned long val;
+
+ if (kstrtoul(buf, 0, &val))
+ return -EINVAL;
+
+ if (val != 1 && val != 0)
+ return -EINVAL;
+
+ spin_lock(&drvdata->spinlock);
+ if (val)
+ drvdata->freq_type = FREQ_TS;
+ else
+ drvdata->freq_type = FREQ;
+ spin_unlock(&drvdata->spinlock);
+
+ return size;
+}
+static DEVICE_ATTR_RW(freq_type);
+
+static ssize_t freq_req_val_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct trace_noc_drvdata *drvdata = dev_get_drvdata(dev->parent);
+
+ return sysfs_emit(buf, "%u\n", drvdata->freq_req_val);
+}
+
+static ssize_t freq_req_val_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf,
+ size_t size)
+{
+ struct trace_noc_drvdata *drvdata = dev_get_drvdata(dev->parent);
+ unsigned long val;
+
+ if (kstrtoul(buf, 0, &val))
+ return -EINVAL;
+
+ if (val) {
+ spin_lock(&drvdata->spinlock);
+ drvdata->freq_req_val = val;
+ spin_unlock(&drvdata->spinlock);
+ }
+
+ return size;
+}
+static DEVICE_ATTR_RW(freq_req_val);
+
+static ssize_t freq_ts_req_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf,
+ size_t size)
+{
+ struct trace_noc_drvdata *drvdata = dev_get_drvdata(dev->parent);
+ struct coresight_device *csdev = drvdata->csdev;
+ unsigned long val;
+ u32 reg;
+
+ if (kstrtoul(buf, 0, &val))
+ return -EINVAL;
+
+ spin_lock(&drvdata->spinlock);
+ if (csdev->refcnt == 0) {
+ spin_unlock(&drvdata->spinlock);
+ return -EPERM;
+ }
+
+ if (val) {
+ reg = readl_relaxed(drvdata->base + TRACE_NOC_CTRL);
+ reg = reg | TRACE_NOC_CTRL_FREQTSREQ;
+ writel_relaxed(reg, drvdata->base + TRACE_NOC_CTRL);
+ }
+ spin_unlock(&drvdata->spinlock);
+
+ return size;
+}
+static DEVICE_ATTR_WO(freq_ts_req);
+
static struct attribute *trace_noc_attrs[] = {
&dev_attr_flush_req.attr,
&dev_attr_flush_status.attr,
&dev_attr_flag_type.attr,
+ &dev_attr_freq_type.attr,
+ &dev_attr_freq_req_val.attr,
+ &dev_attr_freq_ts_req.attr,
NULL,
};

--
2.34.1