|
12 | 12 |
|
13 | 13 | #include "coresight-trace-id.h"
|
14 | 14 |
|
| 15 | +enum trace_id_flags { |
| 16 | + TRACE_ID_ANY = 0x0, |
| 17 | + TRACE_ID_PREFER_ODD = 0x1, |
| 18 | + TRACE_ID_REQ_STATIC = 0x2, |
| 19 | +}; |
| 20 | + |
15 | 21 | /* Default trace ID map. Used in sysfs mode and for system sources */
|
16 | 22 | static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0);
|
17 | 23 | 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)
|
74 | 80 | * Otherwise allocate next available ID.
|
75 | 81 | */
|
76 | 82 | 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) |
78 | 84 | {
|
79 | 85 | int id = 0;
|
80 | 86 |
|
81 | 87 | /* 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) { |
87 | 95 | /* may use odd ids to avoid preferred legacy cpu IDs */
|
88 | 96 | id = coresight_trace_id_find_odd_id(id_map);
|
89 | 97 | if (id)
|
90 | 98 | goto trace_id_allocated;
|
91 |
| - } |
| 99 | + } else if (!IS_VALID_CS_TRACE_ID(preferred_id) && |
| 100 | + (flags & TRACE_ID_REQ_STATIC)) |
| 101 | + return -EINVAL; |
92 | 102 |
|
93 | 103 | /*
|
94 | 104 | * 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
|
153 | 163 | */
|
154 | 164 | id = coresight_trace_id_alloc_new_id(id_map,
|
155 | 165 | CORESIGHT_LEGACY_CPU_TRACE_ID(cpu),
|
156 |
| - false); |
| 166 | + TRACE_ID_ANY); |
157 | 167 | if (!IS_VALID_CS_TRACE_ID(id))
|
158 | 168 | goto get_cpu_id_out_unlock;
|
159 | 169 |
|
@@ -188,14 +198,14 @@ static void _coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_ma
|
188 | 198 | DUMP_ID_MAP(id_map);
|
189 | 199 | }
|
190 | 200 |
|
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) |
192 | 203 | {
|
193 | 204 | unsigned long flags;
|
194 | 205 | int id;
|
195 | 206 |
|
196 | 207 | 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); |
199 | 209 | spin_unlock_irqrestore(&id_map->lock, flags);
|
200 | 210 |
|
201 | 211 | DUMP_ID(id);
|
@@ -255,10 +265,19 @@ EXPORT_SYMBOL_GPL(coresight_trace_id_read_cpu_id_map);
|
255 | 265 |
|
256 | 266 | int coresight_trace_id_get_system_id(void)
|
257 | 267 | {
|
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); |
259 | 271 | }
|
260 | 272 | EXPORT_SYMBOL_GPL(coresight_trace_id_get_system_id);
|
261 | 273 |
|
| 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 | + |
262 | 281 | void coresight_trace_id_put_system_id(int id)
|
263 | 282 | {
|
264 | 283 | coresight_trace_id_map_put_system_id(&id_map_default, id);
|
|
0 commit comments