Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <quic_jinlmao@quicinc.com>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20241121062829.11571-3-quic_jinlmao@quicinc.com

authored by

Mao Jinlong and committed by
Suzuki K Poulose
fd9b7e8e d0a10da7

+47 -12
+6
drivers/hwtracing/coresight/coresight-platform.c
··· 796 796 } 797 797 EXPORT_SYMBOL_GPL(coresight_get_cpu); 798 798 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 + 799 805 struct coresight_platform_data * 800 806 coresight_get_platform_data(struct device *dev) 801 807 {
+31 -12
drivers/hwtracing/coresight/coresight-trace-id.c
··· 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 = { ··· 80 74 * Otherwise allocate next available ID. 81 75 */ 82 76 static int coresight_trace_id_alloc_new_id(struct coresight_trace_id_map *id_map, 83 - int preferred_id, bool prefer_odd_id) 77 + int preferred_id, unsigned int flags) 84 78 { 85 79 int id = 0; 86 80 87 81 /* for backwards compatibility, cpu IDs may use preferred value */ 88 - if (IS_VALID_CS_TRACE_ID(preferred_id) && 89 - !test_bit(preferred_id, id_map->used_ids)) { 90 - id = preferred_id; 91 - goto trace_id_allocated; 92 - } else if (prefer_odd_id) { 82 + if (IS_VALID_CS_TRACE_ID(preferred_id)) { 83 + if (!test_bit(preferred_id, id_map->used_ids)) { 84 + id = preferred_id; 85 + goto trace_id_allocated; 86 + } else if (flags & TRACE_ID_REQ_STATIC) 87 + return -EBUSY; 88 + } else if (flags & TRACE_ID_PREFER_ODD) { 93 89 /* may use odd ids to avoid preferred legacy cpu IDs */ 94 90 id = coresight_trace_id_find_odd_id(id_map); 95 91 if (id) 96 92 goto trace_id_allocated; 97 - } 93 + } else if (!IS_VALID_CS_TRACE_ID(preferred_id) && 94 + (flags & TRACE_ID_REQ_STATIC)) 95 + return -EINVAL; 98 96 99 97 /* 100 98 * skip reserved bit 0, look at bitmap length of ··· 163 153 */ 164 154 id = coresight_trace_id_alloc_new_id(id_map, 165 155 CORESIGHT_LEGACY_CPU_TRACE_ID(cpu), 166 - false); 156 + TRACE_ID_ANY); 167 157 if (!IS_VALID_CS_TRACE_ID(id)) 168 158 goto get_cpu_id_out_unlock; 169 159 ··· 198 188 DUMP_ID_MAP(id_map); 199 189 } 200 190 201 - static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_map *id_map) 191 + static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_map *id_map, 192 + int preferred_id, unsigned int traceid_flags) 202 193 { 203 194 unsigned long flags; 204 195 int id; 205 196 206 197 spin_lock_irqsave(&id_map->lock, flags); 207 - /* prefer odd IDs for system components to avoid legacy CPU IDS */ 208 - id = coresight_trace_id_alloc_new_id(id_map, 0, true); 198 + id = coresight_trace_id_alloc_new_id(id_map, preferred_id, traceid_flags); 209 199 spin_unlock_irqrestore(&id_map->lock, flags); 210 200 211 201 DUMP_ID(id); ··· 265 255 266 256 int coresight_trace_id_get_system_id(void) 267 257 { 268 - return coresight_trace_id_map_get_system_id(&id_map_default); 258 + /* prefer odd IDs for system components to avoid legacy CPU IDS */ 259 + return coresight_trace_id_map_get_system_id(&id_map_default, 0, 260 + TRACE_ID_PREFER_ODD); 269 261 } 270 262 EXPORT_SYMBOL_GPL(coresight_trace_id_get_system_id); 263 + 264 + int coresight_trace_id_get_static_system_id(int trace_id) 265 + { 266 + return coresight_trace_id_map_get_system_id(&id_map_default, 267 + trace_id, TRACE_ID_REQ_STATIC); 268 + } 269 + EXPORT_SYMBOL_GPL(coresight_trace_id_get_static_system_id); 271 270 272 271 void coresight_trace_id_put_system_id(int id) 273 272 {
+9
drivers/hwtracing/coresight/coresight-trace-id.h
··· 117 117 int coresight_trace_id_get_system_id(void); 118 118 119 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 + 128 + /** 120 129 * Release an allocated system trace ID. 121 130 * 122 131 * Unconditionally release a trace ID allocated to a system component.
+1
include/linux/coresight.h
··· 662 662 void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset); 663 663 664 664 extern int coresight_get_cpu(struct device *dev); 665 + extern int coresight_get_static_trace_id(struct device *dev, u32 *id); 665 666 666 667 struct coresight_platform_data *coresight_get_platform_data(struct device *dev); 667 668 struct coresight_connection *