Skip to content

Commit c367a89

Browse files
Jie GanSuzuki K Poulose
authored andcommitted
Coresight: Add trace_id function to retrieving the trace ID
Add 'trace_id' function pointer in coresight_ops. It's responsible for retrieving the device's trace ID. Co-developed-by: James Clark <[email protected]> Signed-off-by: James Clark <[email protected]> Reviewed-by: James Clark <[email protected]> Signed-off-by: Jie Gan <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dc872c5 commit c367a89

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "coresight-etm-perf.h"
2525
#include "coresight-priv.h"
2626
#include "coresight-syscfg.h"
27+
#include "coresight-trace-id.h"
2728

2829
/*
2930
* Mutex used to lock all sysfs enable and disable actions and loading and
@@ -1567,6 +1568,35 @@ void coresight_remove_driver(struct amba_driver *amba_drv,
15671568
}
15681569
EXPORT_SYMBOL_GPL(coresight_remove_driver);
15691570

1571+
int coresight_etm_get_trace_id(struct coresight_device *csdev, enum cs_mode mode,
1572+
struct coresight_device *sink)
1573+
{
1574+
int trace_id;
1575+
int cpu = source_ops(csdev)->cpu_id(csdev);
1576+
1577+
switch (mode) {
1578+
case CS_MODE_SYSFS:
1579+
trace_id = coresight_trace_id_get_cpu_id(cpu);
1580+
break;
1581+
case CS_MODE_PERF:
1582+
if (WARN_ON(!sink))
1583+
return -EINVAL;
1584+
1585+
trace_id = coresight_trace_id_get_cpu_id_map(cpu, &sink->perf_sink_id_map);
1586+
break;
1587+
default:
1588+
trace_id = -EINVAL;
1589+
break;
1590+
}
1591+
1592+
if (!IS_VALID_CS_TRACE_ID(trace_id))
1593+
dev_err(&csdev->dev,
1594+
"Failed to allocate trace ID on CPU%d\n", cpu);
1595+
1596+
return trace_id;
1597+
}
1598+
EXPORT_SYMBOL_GPL(coresight_etm_get_trace_id);
1599+
15701600
MODULE_LICENSE("GPL v2");
15711601
MODULE_AUTHOR("Pratik Patel <[email protected]>");
15721602
MODULE_AUTHOR("Mathieu Poirier <[email protected]>");

drivers/hwtracing/coresight/coresight-dummy.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ static void dummy_source_disable(struct coresight_device *csdev,
4141
dev_dbg(csdev->dev.parent, "Dummy source disabled\n");
4242
}
4343

44+
static int dummy_source_trace_id(struct coresight_device *csdev, __maybe_unused enum cs_mode mode,
45+
__maybe_unused struct coresight_device *sink)
46+
{
47+
struct dummy_drvdata *drvdata;
48+
49+
drvdata = dev_get_drvdata(csdev->dev.parent);
50+
51+
return drvdata->traceid;
52+
}
53+
4454
static int dummy_sink_enable(struct coresight_device *csdev, enum cs_mode mode,
4555
void *data)
4656
{
@@ -62,7 +72,8 @@ static const struct coresight_ops_source dummy_source_ops = {
6272
};
6373

6474
static const struct coresight_ops dummy_source_cs_ops = {
65-
.source_ops = &dummy_source_ops,
75+
.trace_id = dummy_source_trace_id,
76+
.source_ops = &dummy_source_ops,
6677
};
6778

6879
static const struct coresight_ops_sink dummy_sink_ops = {

drivers/hwtracing/coresight/coresight-etm3x-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ static const struct coresight_ops_source etm_source_ops = {
704704
};
705705

706706
static const struct coresight_ops etm_cs_ops = {
707+
.trace_id = coresight_etm_get_trace_id,
707708
.source_ops = &etm_source_ops,
708709
};
709710

drivers/hwtracing/coresight/coresight-etm4x-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ static const struct coresight_ops_source etm4_source_ops = {
11041104
};
11051105

11061106
static const struct coresight_ops etm4_cs_ops = {
1107+
.trace_id = coresight_etm_get_trace_id,
11071108
.source_ops = &etm4_source_ops,
11081109
};
11091110

drivers/hwtracing/coresight/coresight-stm.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,23 @@ static void stm_disable(struct coresight_device *csdev,
281281
}
282282
}
283283

284+
static int stm_trace_id(struct coresight_device *csdev, __maybe_unused enum cs_mode mode,
285+
__maybe_unused struct coresight_device *sink)
286+
{
287+
struct stm_drvdata *drvdata;
288+
289+
drvdata = dev_get_drvdata(csdev->dev.parent);
290+
291+
return drvdata->traceid;
292+
}
293+
284294
static const struct coresight_ops_source stm_source_ops = {
285295
.enable = stm_enable,
286296
.disable = stm_disable,
287297
};
288298

289299
static const struct coresight_ops stm_cs_ops = {
300+
.trace_id = stm_trace_id,
290301
.source_ops = &stm_source_ops,
291302
};
292303

drivers/hwtracing/coresight/coresight-tpda.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,23 @@ static void tpda_disable(struct coresight_device *csdev,
242242
dev_dbg(drvdata->dev, "TPDA inport %d disabled\n", in->dest_port);
243243
}
244244

245+
static int tpda_trace_id(struct coresight_device *csdev, __maybe_unused enum cs_mode mode,
246+
__maybe_unused struct coresight_device *sink)
247+
{
248+
struct tpda_drvdata *drvdata;
249+
250+
drvdata = dev_get_drvdata(csdev->dev.parent);
251+
252+
return drvdata->atid;
253+
}
254+
245255
static const struct coresight_ops_link tpda_link_ops = {
246256
.enable = tpda_enable,
247257
.disable = tpda_disable,
248258
};
249259

250260
static const struct coresight_ops tpda_cs_ops = {
261+
.trace_id = tpda_trace_id,
251262
.link_ops = &tpda_link_ops,
252263
};
253264

include/linux/coresight.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ enum cs_mode {
335335
CS_MODE_PERF,
336336
};
337337

338+
#define coresight_ops(csdev) csdev->ops
338339
#define source_ops(csdev) csdev->ops->source_ops
339340
#define sink_ops(csdev) csdev->ops->sink_ops
340341
#define link_ops(csdev) csdev->ops->link_ops
@@ -421,6 +422,8 @@ struct coresight_ops_panic {
421422
};
422423

423424
struct coresight_ops {
425+
int (*trace_id)(struct coresight_device *csdev, enum cs_mode mode,
426+
struct coresight_device *sink);
424427
const struct coresight_ops_sink *sink_ops;
425428
const struct coresight_ops_link *link_ops;
426429
const struct coresight_ops_source *source_ops;
@@ -713,4 +716,6 @@ int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
713716

714717
void coresight_remove_driver(struct amba_driver *amba_drv,
715718
struct platform_driver *pdev_drv);
719+
int coresight_etm_get_trace_id(struct coresight_device *csdev, enum cs_mode mode,
720+
struct coresight_device *sink);
716721
#endif /* _LINUX_COREISGHT_H */

0 commit comments

Comments
 (0)