Skip to content

Commit f7d7454

Browse files
Mao JinlongSuzuki K Poulose
authored andcommitted
coresight: dummy: Add static trace id support for dummy source
Some dummy source has static trace id configured in HW and it cannot be changed via software programming. Configure the trace id in device tree and reserve the id when device probe. Signed-off-by: Mao Jinlong <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Fix Date and Version to December 2024, v6.14 ] Signed-off-by: Suzuki K Poulose <[email protected]>
1 parent fd9b7e8 commit f7d7454

File tree

2 files changed

+87
-9
lines changed

2 files changed

+87
-9
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
What: /sys/bus/coresight/devices/dummy_source<N>/enable_source
2+
Date: Dec 2024
3+
KernelVersion: 6.14
4+
Contact: Mao Jinlong <[email protected]>
5+
Description: (RW) Enable/disable tracing of dummy source. A sink should be activated
6+
before enabling the source. The path of coresight components linking
7+
the source to the sink is configured and managed automatically by the
8+
coresight framework.
9+
10+
What: /sys/bus/coresight/devices/dummy_source<N>/traceid
11+
Date: Dec 2024
12+
KernelVersion: 6.14
13+
Contact: Mao Jinlong <[email protected]>
14+
Description: (R) Show the trace ID that will appear in the trace stream
15+
coming from this trace entity.

drivers/hwtracing/coresight/coresight-dummy.c

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
#include <linux/pm_runtime.h>
1212

1313
#include "coresight-priv.h"
14+
#include "coresight-trace-id.h"
1415

1516
struct dummy_drvdata {
1617
struct device *dev;
1718
struct coresight_device *csdev;
19+
u8 traceid;
1820
};
1921

2022
DEFINE_CORESIGHT_DEVLIST(source_devs, "dummy_source");
@@ -72,13 +74,44 @@ static const struct coresight_ops dummy_sink_cs_ops = {
7274
.sink_ops = &dummy_sink_ops,
7375
};
7476

77+
/* User can get the trace id of dummy source from this node. */
78+
static ssize_t traceid_show(struct device *dev,
79+
struct device_attribute *attr, char *buf)
80+
{
81+
unsigned long val;
82+
struct dummy_drvdata *drvdata = dev_get_drvdata(dev->parent);
83+
84+
val = drvdata->traceid;
85+
return sysfs_emit(buf, "%#lx\n", val);
86+
}
87+
static DEVICE_ATTR_RO(traceid);
88+
89+
static struct attribute *coresight_dummy_attrs[] = {
90+
&dev_attr_traceid.attr,
91+
NULL,
92+
};
93+
94+
static const struct attribute_group coresight_dummy_group = {
95+
.attrs = coresight_dummy_attrs,
96+
};
97+
98+
static const struct attribute_group *coresight_dummy_groups[] = {
99+
&coresight_dummy_group,
100+
NULL,
101+
};
102+
75103
static int dummy_probe(struct platform_device *pdev)
76104
{
77105
struct device *dev = &pdev->dev;
78106
struct device_node *node = dev->of_node;
79107
struct coresight_platform_data *pdata;
80108
struct dummy_drvdata *drvdata;
81109
struct coresight_desc desc = { 0 };
110+
int ret = 0, trace_id = 0;
111+
112+
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
113+
if (!drvdata)
114+
return -ENOMEM;
82115

83116
if (of_device_is_compatible(node, "arm,coresight-dummy-source")) {
84117

@@ -90,6 +123,26 @@ static int dummy_probe(struct platform_device *pdev)
90123
desc.subtype.source_subtype =
91124
CORESIGHT_DEV_SUBTYPE_SOURCE_OTHERS;
92125
desc.ops = &dummy_source_cs_ops;
126+
desc.groups = coresight_dummy_groups;
127+
128+
ret = coresight_get_static_trace_id(dev, &trace_id);
129+
if (!ret) {
130+
/* Get the static id if id is set in device tree. */
131+
ret = coresight_trace_id_get_static_system_id(trace_id);
132+
if (ret < 0) {
133+
dev_err(dev, "Fail to get static id.\n");
134+
return ret;
135+
}
136+
} else {
137+
/* Get next available id if id is not set in device tree. */
138+
trace_id = coresight_trace_id_get_system_id();
139+
if (trace_id < 0) {
140+
ret = trace_id;
141+
return ret;
142+
}
143+
}
144+
drvdata->traceid = (u8)trace_id;
145+
93146
} else if (of_device_is_compatible(node, "arm,coresight-dummy-sink")) {
94147
desc.name = coresight_alloc_device_name(&sink_devs, dev);
95148
if (!desc.name)
@@ -104,34 +157,44 @@ static int dummy_probe(struct platform_device *pdev)
104157
}
105158

106159
pdata = coresight_get_platform_data(dev);
107-
if (IS_ERR(pdata))
108-
return PTR_ERR(pdata);
160+
if (IS_ERR(pdata)) {
161+
ret = PTR_ERR(pdata);
162+
goto free_id;
163+
}
109164
pdev->dev.platform_data = pdata;
110165

111-
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
112-
if (!drvdata)
113-
return -ENOMEM;
114-
115166
drvdata->dev = &pdev->dev;
116167
platform_set_drvdata(pdev, drvdata);
117168

118169
desc.pdata = pdev->dev.platform_data;
119170
desc.dev = &pdev->dev;
120171
drvdata->csdev = coresight_register(&desc);
121-
if (IS_ERR(drvdata->csdev))
122-
return PTR_ERR(drvdata->csdev);
172+
if (IS_ERR(drvdata->csdev)) {
173+
ret = PTR_ERR(drvdata->csdev);
174+
goto free_id;
175+
}
123176

124177
pm_runtime_enable(dev);
125178
dev_dbg(dev, "Dummy device initialized\n");
126179

127-
return 0;
180+
ret = 0;
181+
goto out;
182+
183+
free_id:
184+
if (IS_VALID_CS_TRACE_ID(drvdata->traceid))
185+
coresight_trace_id_put_system_id(drvdata->traceid);
186+
187+
out:
188+
return ret;
128189
}
129190

130191
static void dummy_remove(struct platform_device *pdev)
131192
{
132193
struct dummy_drvdata *drvdata = platform_get_drvdata(pdev);
133194
struct device *dev = &pdev->dev;
134195

196+
if (IS_VALID_CS_TRACE_ID(drvdata->traceid))
197+
coresight_trace_id_put_system_id(drvdata->traceid);
135198
pm_runtime_disable(dev);
136199
coresight_unregister(drvdata->csdev);
137200
}

0 commit comments

Comments
 (0)