drm/rockchip: Don't change hdmi reference clock rate
[drm/drm-misc.git] / drivers / hwtracing / coresight / coresight-trace-id.h
blob9aae50a553caa3367b8fef4652ef937415bf6dcf
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright(C) 2022 Linaro Limited. All rights reserved.
4 * Author: Mike Leach <mike.leach@linaro.org>
5 */
7 #ifndef _CORESIGHT_TRACE_ID_H
8 #define _CORESIGHT_TRACE_ID_H
11 * Coresight trace ID allocation API
13 * With multi cpu systems, and more additional trace sources a scalable
14 * trace ID reservation system is required.
16 * The system will allocate Ids on a demand basis, and allow them to be
17 * released when done.
19 * In order to ensure that a consistent cpu / ID matching is maintained
20 * throughout a perf cs_etm event session - a session in progress flag will be
21 * maintained for each sink, and IDs are cleared when all the perf sessions
22 * complete. This allows the same CPU to be re-allocated its prior ID when
23 * events are scheduled in and out.
26 * Trace ID maps will be created and initialised to prevent architecturally
27 * reserved IDs from being allocated.
29 * API permits multiple maps to be maintained - for large systems where
30 * different sets of cpus trace into different independent sinks.
33 #include <linux/bitops.h>
34 #include <linux/types.h>
36 /* ID 0 is reserved */
37 #define CORESIGHT_TRACE_ID_RES_0 0
39 /* ID 0x70 onwards are reserved */
40 #define CORESIGHT_TRACE_ID_RES_TOP 0x70
42 /* check an ID is in the valid range */
43 #define IS_VALID_CS_TRACE_ID(id) \
44 ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP))
46 /**
47 * Read and optionally allocate a CoreSight trace ID and associate with a CPU.
49 * Function will read the current trace ID for the associated CPU,
50 * allocating an new ID if one is not currently allocated.
52 * Numeric ID values allocated use legacy allocation algorithm if possible,
53 * otherwise any available ID is used.
55 * @cpu: The CPU index to allocate for.
57 * return: CoreSight trace ID or -EINVAL if allocation impossible.
59 int coresight_trace_id_get_cpu_id(int cpu);
61 /**
62 * Version of coresight_trace_id_get_cpu_id() that allows the ID map to operate
63 * on to be provided.
65 int coresight_trace_id_get_cpu_id_map(int cpu, struct coresight_trace_id_map *id_map);
67 /**
68 * Release an allocated trace ID associated with the CPU.
70 * This will release the CoreSight trace ID associated with the CPU.
72 * @cpu: The CPU index to release the associated trace ID.
74 void coresight_trace_id_put_cpu_id(int cpu);
76 /**
77 * Version of coresight_trace_id_put_cpu_id() that allows the ID map to operate
78 * on to be provided.
80 void coresight_trace_id_put_cpu_id_map(int cpu, struct coresight_trace_id_map *id_map);
82 /**
83 * Read the current allocated CoreSight Trace ID value for the CPU.
85 * Fast read of the current value that does not allocate if no ID allocated
86 * for the CPU.
88 * Used in perf context where it is known that the value for the CPU will not
89 * be changing, when perf starts and event on a core and outputs the Trace ID
90 * for the CPU as a packet in the data file. IDs cannot change during a perf
91 * session.
93 * This function does not take the lock protecting the ID lists, avoiding
94 * locking dependency issues with perf locks.
96 * @cpu: The CPU index to read.
98 * return: current value, will be 0 if unallocated.
100 int coresight_trace_id_read_cpu_id(int cpu);
103 * Version of coresight_trace_id_read_cpu_id() that allows the ID map to operate
104 * on to be provided.
106 int coresight_trace_id_read_cpu_id_map(int cpu, struct coresight_trace_id_map *id_map);
109 * Allocate a CoreSight trace ID for a system component.
111 * Unconditionally allocates a Trace ID, without associating the ID with a CPU.
113 * Used to allocate IDs for system trace sources such as STM.
115 * return: Trace ID or -EINVAL if allocation is impossible.
117 int coresight_trace_id_get_system_id(void);
120 * Release an allocated system trace ID.
122 * Unconditionally release a trace ID allocated to a system component.
124 * @id: value of trace ID allocated.
126 void coresight_trace_id_put_system_id(int id);
128 /* notifiers for perf session start and stop */
131 * Notify the Trace ID allocator that a perf session is starting.
133 * Increase the perf session reference count - called by perf when setting up a
134 * trace event.
136 * Perf sessions never free trace IDs to ensure that the ID associated with a
137 * CPU cannot change during their and other's concurrent sessions. Instead,
138 * this refcount is used so that the last event to finish always frees all IDs.
140 void coresight_trace_id_perf_start(struct coresight_trace_id_map *id_map);
143 * Notify the ID allocator that a perf session is stopping.
145 * Decrease the perf session reference count. If this causes the count to go to
146 * zero, then all Trace IDs will be released.
148 void coresight_trace_id_perf_stop(struct coresight_trace_id_map *id_map);
150 #endif /* _CORESIGHT_TRACE_ID_H */