[PATCH v4 09/10] coresight: tmc: integrate byte-cntr's read_ops with sysfs file_ops
Jie Gan
jie.gan at oss.qualcomm.com
Fri Jul 25 03:08:05 PDT 2025
Add code logic to invoke byte-cntr's read_ops if the byte-cntr
is enabled.
Signed-off-by: Jie Gan <jie.gan at oss.qualcomm.com>
---
.../hwtracing/coresight/coresight-tmc-core.c | 48 ++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index f668047c5df4..671ae4542f6a 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -228,15 +228,41 @@ static int tmc_prepare_crashdata(struct tmc_drvdata *drvdata)
return 0;
}
+static const struct tmc_read_ops *tmc_qcom_byte_cntr_in_use(struct tmc_drvdata *drvdata,
+ bool *in_use)
+{
+ struct tmc_read_ops *byte_cntr_read_ops;
+ struct coresight_device *helper;
+
+ helper = coresight_get_helper(drvdata->csdev, CORESIGHT_DEV_SUBTYPE_HELPER_CTCU);
+ if (helper)
+ *in_use = helper_ops(helper)->qcom_byte_cntr_in_use(drvdata->csdev,
+ (void **)&byte_cntr_read_ops);
+
+ if (*in_use)
+ return byte_cntr_read_ops;
+
+ return NULL;
+}
+
static int tmc_read_prepare(struct tmc_drvdata *drvdata)
{
+ const struct tmc_read_ops *byte_cntr_read_ops;
+ bool in_use = false;
int ret = 0;
+ byte_cntr_read_ops = tmc_qcom_byte_cntr_in_use(drvdata, &in_use);
+ if (in_use) {
+ ret = byte_cntr_read_ops->read_prepare(drvdata);
+ goto out;
+ }
+
if (drvdata->read_ops)
ret = drvdata->read_ops->read_prepare(drvdata);
else
ret = -EINVAL;
+out:
if (!ret)
dev_dbg(&drvdata->csdev->dev, "TMC read start\n");
@@ -245,13 +271,22 @@ static int tmc_read_prepare(struct tmc_drvdata *drvdata)
static int tmc_read_unprepare(struct tmc_drvdata *drvdata)
{
+ const struct tmc_read_ops *byte_cntr_read_ops;
+ bool in_use = false;
int ret = 0;
+ byte_cntr_read_ops = tmc_qcom_byte_cntr_in_use(drvdata, &in_use);
+ if (in_use) {
+ ret = byte_cntr_read_ops->read_unprepare(drvdata);
+ goto out;
+ }
+
if (drvdata->read_ops)
ret = drvdata->read_ops->read_unprepare(drvdata);
else
ret = -EINVAL;
+out:
if (!ret)
dev_dbg(&drvdata->csdev->dev, "TMC read end\n");
@@ -277,6 +312,13 @@ static int tmc_open(struct inode *inode, struct file *file)
static ssize_t tmc_get_sysfs_trace(struct tmc_drvdata *drvdata, loff_t pos, size_t len,
char **bufpp)
{
+ const struct tmc_read_ops *byte_cntr_read_ops;
+ bool in_use = false;
+
+ byte_cntr_read_ops = tmc_qcom_byte_cntr_in_use(drvdata, &in_use);
+ if (in_use)
+ return byte_cntr_read_ops->get_trace_data(drvdata, pos, len, bufpp);
+
if (drvdata->read_ops)
return drvdata->read_ops->get_trace_data(drvdata, pos, len, bufpp);
@@ -300,7 +342,11 @@ static ssize_t tmc_read(struct file *file, char __user *data, size_t len,
return -EFAULT;
}
- *ppos += actual;
+ if (drvdata->reading_node)
+ drvdata->reading_node->pos += actual;
+ else
+ *ppos += actual;
+
dev_dbg(&drvdata->csdev->dev, "%zu bytes copied\n", actual);
return actual;
--
2.34.1
More information about the linux-arm-kernel
mailing list