Skip to content

Commit fd9b7e8

Browse files
Mao JinlongSuzuki K Poulose
authored andcommitted
coresight: Add support to get static id for system trace sources
Dynamic trace id was introduced in coresight subsystem, so trace id is allocated dynamically. However, some hardware ATB source has static trace id and it cannot be changed via software programming. For such source, it can call coresight_get_static_trace_id to get the fixed trace id from device node and pass id to coresight_trace_id_get_static_system_id to reserve the id. Signed-off-by: Mao Jinlong <[email protected]> Reviewed-by: Mike Leach <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d0a10da commit fd9b7e8

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

drivers/hwtracing/coresight/coresight-platform.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,12 @@ int coresight_get_cpu(struct device *dev)
796796
}
797797
EXPORT_SYMBOL_GPL(coresight_get_cpu);
798798

799+
int coresight_get_static_trace_id(struct device *dev, u32 *id)
800+
{
801+
return fwnode_property_read_u32(dev_fwnode(dev), "arm,static-trace-id", id);
802+
}
803+
EXPORT_SYMBOL_GPL(coresight_get_static_trace_id);
804+
799805
struct coresight_platform_data *
800806
coresight_get_platform_data(struct device *dev)
801807
{

drivers/hwtracing/coresight/coresight-trace-id.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
#include "coresight-trace-id.h"
1414

15+
enum trace_id_flags {
16+
TRACE_ID_ANY = 0x0,
17+
TRACE_ID_PREFER_ODD = 0x1,
18+
TRACE_ID_REQ_STATIC = 0x2,
19+
};
20+
1521
/* Default trace ID map. Used in sysfs mode and for system sources */
1622
static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0);
1723
static struct coresight_trace_id_map id_map_default = {
@@ -74,21 +80,25 @@ static int coresight_trace_id_find_odd_id(struct coresight_trace_id_map *id_map)
7480
* Otherwise allocate next available ID.
7581
*/
7682
static int coresight_trace_id_alloc_new_id(struct coresight_trace_id_map *id_map,
77-
int preferred_id, bool prefer_odd_id)
83+
int preferred_id, unsigned int flags)
7884
{
7985
int id = 0;
8086

8187
/* for backwards compatibility, cpu IDs may use preferred value */
82-
if (IS_VALID_CS_TRACE_ID(preferred_id) &&
83-
!test_bit(preferred_id, id_map->used_ids)) {
84-
id = preferred_id;
85-
goto trace_id_allocated;
86-
} else if (prefer_odd_id) {
88+
if (IS_VALID_CS_TRACE_ID(preferred_id)) {
89+
if (!test_bit(preferred_id, id_map->used_ids)) {
90+
id = preferred_id;
91+
goto trace_id_allocated;
92+
} else if (flags & TRACE_ID_REQ_STATIC)
93+
return -EBUSY;
94+
} else if (flags & TRACE_ID_PREFER_ODD) {
8795
/* may use odd ids to avoid preferred legacy cpu IDs */
8896
id = coresight_trace_id_find_odd_id(id_map);
8997
if (id)
9098
goto trace_id_allocated;
91-
}
99+
} else if (!IS_VALID_CS_TRACE_ID(preferred_id) &&
100+
(flags & TRACE_ID_REQ_STATIC))
101+
return -EINVAL;
92102

93103
/*
94104
* skip reserved bit 0, look at bitmap length of
@@ -153,7 +163,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map
153163
*/
154164
id = coresight_trace_id_alloc_new_id(id_map,
155165
CORESIGHT_LEGACY_CPU_TRACE_ID(cpu),
156-
false);
166+
TRACE_ID_ANY);
157167
if (!IS_VALID_CS_TRACE_ID(id))
158168
goto get_cpu_id_out_unlock;
159169

@@ -188,14 +198,14 @@ static void _coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_ma
188198
DUMP_ID_MAP(id_map);
189199
}
190200

191-
static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_map *id_map)
201+
static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_map *id_map,
202+
int preferred_id, unsigned int traceid_flags)
192203
{
193204
unsigned long flags;
194205
int id;
195206

196207
spin_lock_irqsave(&id_map->lock, flags);
197-
/* prefer odd IDs for system components to avoid legacy CPU IDS */
198-
id = coresight_trace_id_alloc_new_id(id_map, 0, true);
208+
id = coresight_trace_id_alloc_new_id(id_map, preferred_id, traceid_flags);
199209
spin_unlock_irqrestore(&id_map->lock, flags);
200210

201211
DUMP_ID(id);
@@ -255,10 +265,19 @@ EXPORT_SYMBOL_GPL(coresight_trace_id_read_cpu_id_map);
255265

256266
int coresight_trace_id_get_system_id(void)
257267
{
258-
return coresight_trace_id_map_get_system_id(&id_map_default);
268+
/* prefer odd IDs for system components to avoid legacy CPU IDS */
269+
return coresight_trace_id_map_get_system_id(&id_map_default, 0,
270+
TRACE_ID_PREFER_ODD);
259271
}
260272
EXPORT_SYMBOL_GPL(coresight_trace_id_get_system_id);
261273

274+
int coresight_trace_id_get_static_system_id(int trace_id)
275+
{
276+
return coresight_trace_id_map_get_system_id(&id_map_default,
277+
trace_id, TRACE_ID_REQ_STATIC);
278+
}
279+
EXPORT_SYMBOL_GPL(coresight_trace_id_get_static_system_id);
280+
262281
void coresight_trace_id_put_system_id(int id)
263282
{
264283
coresight_trace_id_map_put_system_id(&id_map_default, id);

drivers/hwtracing/coresight/coresight-trace-id.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ int coresight_trace_id_read_cpu_id_map(int cpu, struct coresight_trace_id_map *i
116116
*/
117117
int coresight_trace_id_get_system_id(void);
118118

119+
/**
120+
* Allocate a CoreSight static trace ID for a system component.
121+
*
122+
* Used to allocate static IDs for system trace sources such as dummy source.
123+
*
124+
* return: Trace ID or -EINVAL if allocation is impossible.
125+
*/
126+
int coresight_trace_id_get_static_system_id(int id);
127+
119128
/**
120129
* Release an allocated system trace ID.
121130
*

include/linux/coresight.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ void coresight_relaxed_write64(struct coresight_device *csdev,
662662
void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset);
663663

664664
extern int coresight_get_cpu(struct device *dev);
665+
extern int coresight_get_static_trace_id(struct device *dev, u32 *id);
665666

666667
struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
667668
struct coresight_connection *

0 commit comments

Comments
 (0)