Commit | Line | Data |
---|---|---|
ad0dfdfd MP |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
3 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. | |
a06ae860 PP |
4 | */ |
5 | ||
6 | #ifndef _LINUX_CORESIGHT_H | |
7 | #define _LINUX_CORESIGHT_H | |
8 | ||
73d779a0 AK |
9 | #include <linux/amba/bus.h> |
10 | #include <linux/clk.h> | |
a06ae860 | 11 | #include <linux/device.h> |
6e736c60 | 12 | #include <linux/io.h> |
882d5e11 | 13 | #include <linux/perf_event.h> |
ff63ec13 | 14 | #include <linux/sched.h> |
075b7cd7 | 15 | #include <linux/platform_device.h> |
a06ae860 PP |
16 | |
17 | /* Peripheral id registers (0xFD0-0xFEC) */ | |
18 | #define CORESIGHT_PERIPHIDR4 0xfd0 | |
19 | #define CORESIGHT_PERIPHIDR5 0xfd4 | |
20 | #define CORESIGHT_PERIPHIDR6 0xfd8 | |
21 | #define CORESIGHT_PERIPHIDR7 0xfdC | |
22 | #define CORESIGHT_PERIPHIDR0 0xfe0 | |
23 | #define CORESIGHT_PERIPHIDR1 0xfe4 | |
24 | #define CORESIGHT_PERIPHIDR2 0xfe8 | |
25 | #define CORESIGHT_PERIPHIDR3 0xfeC | |
26 | /* Component id registers (0xFF0-0xFFC) */ | |
27 | #define CORESIGHT_COMPIDR0 0xff0 | |
28 | #define CORESIGHT_COMPIDR1 0xff4 | |
29 | #define CORESIGHT_COMPIDR2 0xff8 | |
30 | #define CORESIGHT_COMPIDR3 0xffC | |
31 | ||
32 | #define ETM_ARCH_V3_3 0x23 | |
33 | #define ETM_ARCH_V3_5 0x25 | |
34 | #define PFT_ARCH_V1_0 0x30 | |
35 | #define PFT_ARCH_V1_1 0x31 | |
36 | ||
37 | #define CORESIGHT_UNLOCK 0xc5acce55 | |
38 | ||
dd95255d | 39 | extern const struct bus_type coresight_bustype; |
a06ae860 PP |
40 | |
41 | enum coresight_dev_type { | |
a06ae860 PP |
42 | CORESIGHT_DEV_TYPE_SINK, |
43 | CORESIGHT_DEV_TYPE_LINK, | |
44 | CORESIGHT_DEV_TYPE_LINKSINK, | |
45 | CORESIGHT_DEV_TYPE_SOURCE, | |
8a091d84 | 46 | CORESIGHT_DEV_TYPE_HELPER, |
1b5b1646 | 47 | CORESIGHT_DEV_TYPE_MAX |
a06ae860 PP |
48 | }; |
49 | ||
50 | enum coresight_dev_subtype_sink { | |
9d3ba0b6 | 51 | CORESIGHT_DEV_SUBTYPE_SINK_DUMMY, |
a06ae860 PP |
52 | CORESIGHT_DEV_SUBTYPE_SINK_PORT, |
53 | CORESIGHT_DEV_SUBTYPE_SINK_BUFFER, | |
0336bdfd | 54 | CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM, |
2cd87a7b | 55 | CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM, |
a06ae860 PP |
56 | }; |
57 | ||
58 | enum coresight_dev_subtype_link { | |
a06ae860 PP |
59 | CORESIGHT_DEV_SUBTYPE_LINK_MERG, |
60 | CORESIGHT_DEV_SUBTYPE_LINK_SPLIT, | |
61 | CORESIGHT_DEV_SUBTYPE_LINK_FIFO, | |
62 | }; | |
63 | ||
64 | enum coresight_dev_subtype_source { | |
a06ae860 PP |
65 | CORESIGHT_DEV_SUBTYPE_SOURCE_PROC, |
66 | CORESIGHT_DEV_SUBTYPE_SOURCE_BUS, | |
67 | CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE, | |
f7f965c9 | 68 | CORESIGHT_DEV_SUBTYPE_SOURCE_TPDM, |
b3c71626 | 69 | CORESIGHT_DEV_SUBTYPE_SOURCE_OTHERS, |
a06ae860 PP |
70 | }; |
71 | ||
8a091d84 | 72 | enum coresight_dev_subtype_helper { |
fcacb5c1 | 73 | CORESIGHT_DEV_SUBTYPE_HELPER_CATU, |
f78d206f JG |
74 | CORESIGHT_DEV_SUBTYPE_HELPER_ECT_CTI, |
75 | CORESIGHT_DEV_SUBTYPE_HELPER_CTCU, | |
835d722b ML |
76 | }; |
77 | ||
a06ae860 | 78 | /** |
00b78e8b | 79 | * union coresight_dev_subtype - further characterisation of a type |
a06ae860 | 80 | * @sink_subtype: type of sink this component is, as defined |
00b78e8b | 81 | * by @coresight_dev_subtype_sink. |
a06ae860 | 82 | * @link_subtype: type of link this component is, as defined |
00b78e8b | 83 | * by @coresight_dev_subtype_link. |
a06ae860 | 84 | * @source_subtype: type of source this component is, as defined |
00b78e8b | 85 | * by @coresight_dev_subtype_source. |
8a091d84 SP |
86 | * @helper_subtype: type of helper this component is, as defined |
87 | * by @coresight_dev_subtype_helper. | |
a06ae860 | 88 | */ |
00b78e8b SP |
89 | union coresight_dev_subtype { |
90 | /* We have some devices which acts as LINK and SINK */ | |
91 | struct { | |
92 | enum coresight_dev_subtype_sink sink_subtype; | |
93 | enum coresight_dev_subtype_link link_subtype; | |
94 | }; | |
a06ae860 | 95 | enum coresight_dev_subtype_source source_subtype; |
8a091d84 | 96 | enum coresight_dev_subtype_helper helper_subtype; |
a06ae860 PP |
97 | }; |
98 | ||
99 | /** | |
d375b356 SP |
100 | * struct coresight_platform_data - data harvested from the firmware |
101 | * specification. | |
102 | * | |
81d0ea76 JC |
103 | * @nr_inconns: Number of elements for the input connections. |
104 | * @nr_outconns: Number of elements for the output connections. | |
4e8fe7e5 JC |
105 | * @out_conns: Array of nr_outconns pointers to connections from this |
106 | * component. | |
e3f4e687 JC |
107 | * @in_conns: Sparse array of pointers to input connections. Sparse |
108 | * because the source device owns the connection so when it's | |
109 | * unloaded the connection leaves an empty slot. | |
a06ae860 PP |
110 | */ |
111 | struct coresight_platform_data { | |
81d0ea76 JC |
112 | int nr_inconns; |
113 | int nr_outconns; | |
4e8fe7e5 | 114 | struct coresight_connection **out_conns; |
e3f4e687 | 115 | struct coresight_connection **in_conns; |
a06ae860 PP |
116 | }; |
117 | ||
6e736c60 SP |
118 | /** |
119 | * struct csdev_access - Abstraction of a CoreSight device access. | |
120 | * | |
121 | * @io_mem : True if the device has memory mapped I/O | |
122 | * @base : When io_mem == true, base address of the component | |
123 | * @read : Read from the given "offset" of the given instance. | |
124 | * @write : Write "val" to the given "offset". | |
125 | */ | |
126 | struct csdev_access { | |
127 | bool io_mem; | |
128 | union { | |
129 | void __iomem *base; | |
130 | struct { | |
131 | u64 (*read)(u32 offset, bool relaxed, bool _64bit); | |
132 | void (*write)(u64 val, u32 offset, bool relaxed, | |
133 | bool _64bit); | |
134 | }; | |
135 | }; | |
136 | }; | |
137 | ||
138 | #define CSDEV_ACCESS_IOMEM(_addr) \ | |
139 | ((struct csdev_access) { \ | |
140 | .io_mem = true, \ | |
141 | .base = (_addr), \ | |
142 | }) | |
143 | ||
a06ae860 PP |
144 | /** |
145 | * struct coresight_desc - description of a component required from drivers | |
146 | * @type: as defined by @coresight_dev_type. | |
147 | * @subtype: as defined by @coresight_dev_subtype. | |
148 | * @ops: generic operations for this component, as defined | |
2ede79a6 | 149 | * by @coresight_ops. |
a06ae860 PP |
150 | * @pdata: platform data collected from DT. |
151 | * @dev: The device entity associated to this component. | |
8ee885a9 | 152 | * @groups: operations specific to this component. These will end up |
2ede79a6 SP |
153 | * in the component's sysfs sub-directory. |
154 | * @name: name for the coresight device, also shown under sysfs. | |
6e736c60 | 155 | * @access: Describe access to the device |
a06ae860 PP |
156 | */ |
157 | struct coresight_desc { | |
158 | enum coresight_dev_type type; | |
00b78e8b | 159 | union coresight_dev_subtype subtype; |
a06ae860 PP |
160 | const struct coresight_ops *ops; |
161 | struct coresight_platform_data *pdata; | |
162 | struct device *dev; | |
163 | const struct attribute_group **groups; | |
2ede79a6 | 164 | const char *name; |
6e736c60 | 165 | struct csdev_access access; |
a06ae860 PP |
166 | }; |
167 | ||
168 | /** | |
169 | * struct coresight_connection - representation of a single connection | |
d49c9cf1 JC |
170 | * @src_port: a connection's output port number. |
171 | * @dest_port: destination's input port number @src_port is connected to. | |
172 | * @dest_fwnode: destination component's fwnode handle. | |
173 | * @dest_dev: a @coresight_device representation of the component | |
174 | connected to @src_port. NULL until the device is created | |
8a7365c2 | 175 | * @link: Representation of the connection as a sysfs link. |
ec9903d6 TZ |
176 | * @filter_src_fwnode: filter source component's fwnode handle. |
177 | * @filter_src_dev: a @coresight_device representation of the component that | |
178 | needs to be filtered. | |
e3f4e687 JC |
179 | * |
180 | * The full connection structure looks like this, where in_conns store | |
181 | * references to same connection as the source device's out_conns. | |
182 | * | |
183 | * +-----------------------------+ +-----------------------------+ | |
184 | * |coresight_device | |coresight_connection | | |
185 | * |-----------------------------| |-----------------------------| | |
186 | * | | | | | |
187 | * | | | dest_dev*|<-- | |
188 | * |pdata->out_conns[nr_outconns]|<->|src_dev* | | | |
189 | * | | | | | | |
190 | * +-----------------------------+ +-----------------------------+ | | |
191 | * | | |
192 | * +-----------------------------+ | | |
193 | * |coresight_device | | | |
194 | * |------------------------------ | | |
195 | * | | | | |
196 | * | pdata->in_conns[nr_inconns]|<-- | |
197 | * | | | |
198 | * +-----------------------------+ | |
a06ae860 PP |
199 | */ |
200 | struct coresight_connection { | |
d49c9cf1 JC |
201 | int src_port; |
202 | int dest_port; | |
203 | struct fwnode_handle *dest_fwnode; | |
204 | struct coresight_device *dest_dev; | |
8a7365c2 | 205 | struct coresight_sysfs_link *link; |
e3f4e687 | 206 | struct coresight_device *src_dev; |
ec9903d6 TZ |
207 | struct fwnode_handle *filter_src_fwnode; |
208 | struct coresight_device *filter_src_dev; | |
5aec7c06 JC |
209 | int src_refcnt; |
210 | int dest_refcnt; | |
a06ae860 PP |
211 | }; |
212 | ||
80961525 ML |
213 | /** |
214 | * struct coresight_sysfs_link - representation of a connection in sysfs. | |
215 | * @orig: Originating (master) coresight device for the link. | |
216 | * @orig_name: Name to use for the link orig->target. | |
217 | * @target: Target (slave) coresight device for the link. | |
218 | * @target_name: Name to use for the link target->orig. | |
219 | */ | |
220 | struct coresight_sysfs_link { | |
221 | struct coresight_device *orig; | |
222 | const char *orig_name; | |
223 | struct coresight_device *target; | |
224 | const char *target_name; | |
225 | }; | |
226 | ||
acb0184f JC |
227 | /* architecturally we have 128 IDs some of which are reserved */ |
228 | #define CORESIGHT_TRACE_IDS_MAX 128 | |
229 | ||
230 | /** | |
231 | * Trace ID map. | |
232 | * | |
233 | * @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. | |
234 | * Initialised so that the reserved IDs are permanently marked as | |
235 | * in use. | |
de0029fd | 236 | * @perf_cs_etm_session_active: Number of Perf sessions using this ID map. |
acb0184f JC |
237 | */ |
238 | struct coresight_trace_id_map { | |
239 | DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); | |
d53c8253 | 240 | atomic_t __percpu *cpu_map; |
de0029fd | 241 | atomic_t perf_cs_etm_session_active; |
4cf364ca | 242 | raw_spinlock_t lock; |
acb0184f JC |
243 | }; |
244 | ||
a06ae860 PP |
245 | /** |
246 | * struct coresight_device - representation of a device as used by the framework | |
b77e3ed0 | 247 | * @pdata: Platform data with device connections associated to this device. |
a06ae860 PP |
248 | * @type: as defined by @coresight_dev_type. |
249 | * @subtype: as defined by @coresight_dev_subtype. | |
250 | * @ops: generic operations for this component, as defined | |
6e736c60 SP |
251 | * by @coresight_ops. |
252 | * @access: Device i/o access abstraction for this device. | |
a06ae860 | 253 | * @dev: The device entity associated to this component. |
9cae77cf JC |
254 | * @mode: This tracer's mode, i.e sysFS, Perf or disabled. This is |
255 | * actually an 'enum cs_mode', but is stored in an atomic type. | |
256 | * This is always accessed through local_read() and local_set(), | |
257 | * but wherever it's done from within the Coresight device's lock, | |
4545b38e JC |
258 | * a non-atomic read would also work. This is the main point of |
259 | * synchronisation between code happening inside the sysfs mode's | |
260 | * coresight_mutex and outside when running in Perf mode. A compare | |
261 | * and exchange swap is done to atomically claim one mode or the | |
262 | * other. | |
263 | * @refcnt: keep track of what is in use. Only access this outside of the | |
264 | * device's spinlock when the coresight_mutex held and mode == | |
265 | * CS_MODE_SYSFS. Otherwise it must be accessed from inside the | |
266 | * spinlock. | |
a06ae860 | 267 | * @orphan: true if the component has connections that haven't been linked. |
a0fef3f0 JC |
268 | * @sysfs_sink_activated: 'true' when a sink has been selected for use via sysfs |
269 | * by writing a 1 to the 'enable_sink' file. A sink can be | |
270 | * activated but not yet enabled. Enabling for a _sink_ happens | |
271 | * when a source has been selected and a path is enabled from | |
272 | * source to that sink. A sink can also become enabled but not | |
273 | * activated if it's used via Perf. | |
bb8e370b | 274 | * @ea: Device attribute for sink representation under PMU directory. |
0336bdfd | 275 | * @def_sink: cached reference to default sink found for this device. |
80961525 ML |
276 | * @nr_links: number of sysfs links created to other components from this |
277 | * device. These will appear in the "connections" group. | |
278 | * @has_conns_grp: Have added a "connections" group for sysfs links. | |
42ff700f ML |
279 | * @feature_csdev_list: List of complex feature programming added to the device. |
280 | * @config_csdev_list: List of system configurations added to the device. | |
281 | * @cscfg_csdev_lock: Protect the lists of configurations and features. | |
f8cce2ff | 282 | * @active_cscfg_ctxt: Context information for current active system configuration. |
a06ae860 PP |
283 | */ |
284 | struct coresight_device { | |
b77e3ed0 | 285 | struct coresight_platform_data *pdata; |
a06ae860 | 286 | enum coresight_dev_type type; |
00b78e8b | 287 | union coresight_dev_subtype subtype; |
a06ae860 | 288 | const struct coresight_ops *ops; |
6e736c60 | 289 | struct csdev_access access; |
a06ae860 | 290 | struct device dev; |
9cae77cf | 291 | local_t mode; |
4545b38e | 292 | int refcnt; |
a06ae860 | 293 | bool orphan; |
bb8e370b | 294 | /* sink specific fields */ |
a0fef3f0 | 295 | bool sysfs_sink_activated; |
bb8e370b | 296 | struct dev_ext_attribute *ea; |
0336bdfd | 297 | struct coresight_device *def_sink; |
5ad628a7 | 298 | struct coresight_trace_id_map perf_sink_id_map; |
80961525 ML |
299 | /* sysfs links between components */ |
300 | int nr_links; | |
301 | bool has_conns_grp; | |
42ff700f ML |
302 | /* system configuration and feature lists */ |
303 | struct list_head feature_csdev_list; | |
304 | struct list_head config_csdev_list; | |
26f060c1 | 305 | raw_spinlock_t cscfg_csdev_lock; |
f8cce2ff | 306 | void *active_cscfg_ctxt; |
a06ae860 PP |
307 | }; |
308 | ||
0f5f9b6b SP |
309 | /* |
310 | * coresight_dev_list - Mapping for devices to "name" index for device | |
311 | * names. | |
312 | * | |
313 | * @nr_idx: Number of entries already allocated. | |
314 | * @pfx: Prefix pattern for device name. | |
315 | * @fwnode_list: Array of fwnode_handles associated with each allocated | |
316 | * index, upto nr_idx entries. | |
317 | */ | |
318 | struct coresight_dev_list { | |
319 | int nr_idx; | |
320 | const char *pfx; | |
321 | struct fwnode_handle **fwnode_list; | |
322 | }; | |
323 | ||
324 | #define DEFINE_CORESIGHT_DEVLIST(var, dev_pfx) \ | |
325 | static struct coresight_dev_list (var) = { \ | |
326 | .pfx = dev_pfx, \ | |
327 | .nr_idx = 0, \ | |
328 | .fwnode_list = NULL, \ | |
329 | } | |
330 | ||
a06ae860 PP |
331 | #define to_coresight_device(d) container_of(d, struct coresight_device, dev) |
332 | ||
3c03c49b JG |
333 | /** |
334 | * struct coresight_path - data needed by enable/disable path | |
335 | * @path_list: path from source to sink. | |
336 | * @trace_id: trace_id of the whole path. | |
337 | */ | |
338 | struct coresight_path { | |
339 | struct list_head path_list; | |
340 | u8 trace_id; | |
341 | }; | |
342 | ||
9fa36828 JC |
343 | enum cs_mode { |
344 | CS_MODE_DISABLED, | |
345 | CS_MODE_SYSFS, | |
346 | CS_MODE_PERF, | |
347 | }; | |
348 | ||
c367a89d | 349 | #define coresight_ops(csdev) csdev->ops |
a06ae860 PP |
350 | #define source_ops(csdev) csdev->ops->source_ops |
351 | #define sink_ops(csdev) csdev->ops->sink_ops | |
352 | #define link_ops(csdev) csdev->ops->link_ops | |
8a091d84 | 353 | #define helper_ops(csdev) csdev->ops->helper_ops |
835d722b | 354 | #define ect_ops(csdev) csdev->ops->ect_ops |
46006ceb | 355 | #define panic_ops(csdev) csdev->ops->panic_ops |
a06ae860 | 356 | |
a06ae860 PP |
357 | /** |
358 | * struct coresight_ops_sink - basic operations for a sink | |
359 | * Operations available for sinks | |
2997aa40 MP |
360 | * @enable: enables the sink. |
361 | * @disable: disables the sink. | |
362 | * @alloc_buffer: initialises perf's ring buffer for trace collection. | |
363 | * @free_buffer: release memory allocated in @get_config. | |
2997aa40 | 364 | * @update_buffer: update buffer pointers after a trace session. |
a06ae860 PP |
365 | */ |
366 | struct coresight_ops_sink { | |
9fa36828 JC |
367 | int (*enable)(struct coresight_device *csdev, enum cs_mode mode, |
368 | void *data); | |
6c817a95 | 369 | int (*disable)(struct coresight_device *csdev); |
a0f08a6a MP |
370 | void *(*alloc_buffer)(struct coresight_device *csdev, |
371 | struct perf_event *event, void **pages, | |
372 | int nr_pages, bool overwrite); | |
2997aa40 | 373 | void (*free_buffer)(void *config); |
7ec786ad | 374 | unsigned long (*update_buffer)(struct coresight_device *csdev, |
2997aa40 MP |
375 | struct perf_output_handle *handle, |
376 | void *sink_config); | |
a06ae860 PP |
377 | }; |
378 | ||
379 | /** | |
380 | * struct coresight_ops_link - basic operations for a link | |
381 | * Operations available for links. | |
382 | * @enable: enables flow between iport and oport. | |
383 | * @disable: disables flow between iport and oport. | |
384 | */ | |
385 | struct coresight_ops_link { | |
ae7f2b5a JC |
386 | int (*enable)(struct coresight_device *csdev, |
387 | struct coresight_connection *in, | |
388 | struct coresight_connection *out); | |
389 | void (*disable)(struct coresight_device *csdev, | |
390 | struct coresight_connection *in, | |
391 | struct coresight_connection *out); | |
a06ae860 PP |
392 | }; |
393 | ||
394 | /** | |
395 | * struct coresight_ops_source - basic operations for a source | |
396 | * Operations available for sources. | |
52210c87 MP |
397 | * @cpu_id: returns the value of the CPU number this component |
398 | * is associated to. | |
1d27ff5a | 399 | * @enable: enables tracing for a source. |
a06ae860 | 400 | * @disable: disables tracing for a source. |
5fa96c83 LY |
401 | * @resume_perf: resumes tracing for a source in perf session. |
402 | * @pause_perf: pauses tracing for a source in perf session. | |
a06ae860 PP |
403 | */ |
404 | struct coresight_ops_source { | |
52210c87 | 405 | int (*cpu_id)(struct coresight_device *csdev); |
9fa36828 | 406 | int (*enable)(struct coresight_device *csdev, struct perf_event *event, |
7b365f05 | 407 | enum cs_mode mode, struct coresight_path *path); |
68905d73 MP |
408 | void (*disable)(struct coresight_device *csdev, |
409 | struct perf_event *event); | |
5fa96c83 LY |
410 | int (*resume_perf)(struct coresight_device *csdev); |
411 | void (*pause_perf)(struct coresight_device *csdev); | |
a06ae860 PP |
412 | }; |
413 | ||
8a091d84 SP |
414 | /** |
415 | * struct coresight_ops_helper - Operations for a helper device. | |
416 | * | |
417 | * All operations could pass in a device specific data, which could | |
418 | * help the helper device to determine what to do. | |
419 | * | |
420 | * @enable : Enable the device | |
421 | * @disable : Disable the device | |
422 | */ | |
423 | struct coresight_ops_helper { | |
61486528 JC |
424 | int (*enable)(struct coresight_device *csdev, enum cs_mode mode, |
425 | void *data); | |
8a091d84 SP |
426 | int (*disable)(struct coresight_device *csdev, void *data); |
427 | }; | |
428 | ||
46006ceb LC |
429 | |
430 | /** | |
431 | * struct coresight_ops_panic - Generic device ops for panic handing | |
432 | * | |
433 | * @sync : Sync the device register state/trace data | |
434 | */ | |
435 | struct coresight_ops_panic { | |
436 | int (*sync)(struct coresight_device *csdev); | |
437 | }; | |
438 | ||
a06ae860 | 439 | struct coresight_ops { |
c367a89d JG |
440 | int (*trace_id)(struct coresight_device *csdev, enum cs_mode mode, |
441 | struct coresight_device *sink); | |
a06ae860 PP |
442 | const struct coresight_ops_sink *sink_ops; |
443 | const struct coresight_ops_link *link_ops; | |
444 | const struct coresight_ops_source *source_ops; | |
8a091d84 | 445 | const struct coresight_ops_helper *helper_ops; |
46006ceb | 446 | const struct coresight_ops_panic *panic_ops; |
a06ae860 PP |
447 | }; |
448 | ||
6e736c60 SP |
449 | static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa, |
450 | u32 offset) | |
451 | { | |
452 | if (likely(csa->io_mem)) | |
453 | return readl_relaxed(csa->base + offset); | |
454 | ||
455 | return csa->read(offset, true, false); | |
456 | } | |
457 | ||
73d779a0 AK |
458 | #define CORESIGHT_CIDRn(i) (0xFF0 + ((i) * 4)) |
459 | ||
460 | static inline u32 coresight_get_cid(void __iomem *base) | |
461 | { | |
462 | u32 i, cid = 0; | |
463 | ||
464 | for (i = 0; i < 4; i++) | |
465 | cid |= readl(base + CORESIGHT_CIDRn(i)) << (i * 8); | |
466 | ||
467 | return cid; | |
468 | } | |
469 | ||
470 | static inline bool is_coresight_device(void __iomem *base) | |
471 | { | |
472 | u32 cid = coresight_get_cid(base); | |
473 | ||
474 | return cid == CORESIGHT_CID; | |
475 | } | |
476 | ||
477 | /* | |
478 | * Attempt to find and enable "APB clock" for the given device | |
479 | * | |
480 | * Returns: | |
481 | * | |
482 | * clk - Clock is found and enabled | |
483 | * NULL - clock is not found | |
484 | * ERROR - Clock is found but failed to enable | |
485 | */ | |
486 | static inline struct clk *coresight_get_enable_apb_pclk(struct device *dev) | |
487 | { | |
488 | struct clk *pclk; | |
489 | int ret; | |
490 | ||
491 | pclk = clk_get(dev, "apb_pclk"); | |
dc872c5f JG |
492 | if (IS_ERR(pclk)) { |
493 | pclk = clk_get(dev, "apb"); | |
494 | if (IS_ERR(pclk)) | |
495 | return NULL; | |
496 | } | |
73d779a0 AK |
497 | |
498 | ret = clk_prepare_enable(pclk); | |
499 | if (ret) { | |
500 | clk_put(pclk); | |
501 | return ERR_PTR(ret); | |
502 | } | |
503 | return pclk; | |
504 | } | |
505 | ||
5a1c7097 AK |
506 | #define CORESIGHT_PIDRn(i) (0xFE0 + ((i) * 4)) |
507 | ||
508 | static inline u32 coresight_get_pid(struct csdev_access *csa) | |
509 | { | |
510 | u32 i, pid = 0; | |
511 | ||
512 | for (i = 0; i < 4; i++) | |
513 | pid |= csdev_access_relaxed_read32(csa, CORESIGHT_PIDRn(i)) << (i * 8); | |
514 | ||
515 | return pid; | |
516 | } | |
517 | ||
b6df1cbb | 518 | static inline u64 csdev_access_relaxed_read_pair(struct csdev_access *csa, |
0a98181f | 519 | u32 lo_offset, u32 hi_offset) |
b6df1cbb | 520 | { |
b6df1cbb | 521 | if (likely(csa->io_mem)) { |
0a98181f JC |
522 | return readl_relaxed(csa->base + lo_offset) | |
523 | ((u64)readl_relaxed(csa->base + hi_offset) << 32); | |
b6df1cbb JC |
524 | } |
525 | ||
0a98181f JC |
526 | return csa->read(lo_offset, true, false) | (csa->read(hi_offset, true, false) << 32); |
527 | } | |
528 | ||
529 | static inline void csdev_access_relaxed_write_pair(struct csdev_access *csa, u64 val, | |
530 | u32 lo_offset, u32 hi_offset) | |
531 | { | |
532 | if (likely(csa->io_mem)) { | |
533 | writel_relaxed((u32)val, csa->base + lo_offset); | |
534 | writel_relaxed((u32)(val >> 32), csa->base + hi_offset); | |
535 | } else { | |
536 | csa->write((u32)val, lo_offset, true, false); | |
537 | csa->write((u32)(val >> 32), hi_offset, true, false); | |
538 | } | |
b6df1cbb JC |
539 | } |
540 | ||
6e736c60 SP |
541 | static inline u32 csdev_access_read32(struct csdev_access *csa, u32 offset) |
542 | { | |
543 | if (likely(csa->io_mem)) | |
544 | return readl(csa->base + offset); | |
545 | ||
546 | return csa->read(offset, false, false); | |
547 | } | |
548 | ||
549 | static inline void csdev_access_relaxed_write32(struct csdev_access *csa, | |
550 | u32 val, u32 offset) | |
551 | { | |
552 | if (likely(csa->io_mem)) | |
553 | writel_relaxed(val, csa->base + offset); | |
554 | else | |
555 | csa->write(val, offset, true, false); | |
556 | } | |
557 | ||
558 | static inline void csdev_access_write32(struct csdev_access *csa, u32 val, u32 offset) | |
559 | { | |
560 | if (likely(csa->io_mem)) | |
561 | writel(val, csa->base + offset); | |
562 | else | |
563 | csa->write(val, offset, false, false); | |
564 | } | |
565 | ||
566 | #ifdef CONFIG_64BIT | |
567 | ||
568 | static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa, | |
569 | u32 offset) | |
570 | { | |
571 | if (likely(csa->io_mem)) | |
572 | return readq_relaxed(csa->base + offset); | |
573 | ||
574 | return csa->read(offset, true, true); | |
575 | } | |
576 | ||
577 | static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset) | |
578 | { | |
579 | if (likely(csa->io_mem)) | |
580 | return readq(csa->base + offset); | |
581 | ||
582 | return csa->read(offset, false, true); | |
583 | } | |
584 | ||
585 | static inline void csdev_access_relaxed_write64(struct csdev_access *csa, | |
586 | u64 val, u32 offset) | |
587 | { | |
588 | if (likely(csa->io_mem)) | |
589 | writeq_relaxed(val, csa->base + offset); | |
590 | else | |
591 | csa->write(val, offset, true, true); | |
592 | } | |
593 | ||
594 | static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset) | |
595 | { | |
596 | if (likely(csa->io_mem)) | |
597 | writeq(val, csa->base + offset); | |
598 | else | |
599 | csa->write(val, offset, false, true); | |
600 | } | |
601 | ||
602 | #else /* !CONFIG_64BIT */ | |
603 | ||
604 | static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa, | |
605 | u32 offset) | |
606 | { | |
607 | WARN_ON(1); | |
608 | return 0; | |
609 | } | |
610 | ||
611 | static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset) | |
612 | { | |
613 | WARN_ON(1); | |
614 | return 0; | |
615 | } | |
616 | ||
617 | static inline void csdev_access_relaxed_write64(struct csdev_access *csa, | |
618 | u64 val, u32 offset) | |
619 | { | |
620 | WARN_ON(1); | |
621 | } | |
622 | ||
623 | static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset) | |
624 | { | |
625 | WARN_ON(1); | |
626 | } | |
627 | #endif /* CONFIG_64BIT */ | |
628 | ||
62374ce1 TZ |
629 | static inline bool coresight_is_device_source(struct coresight_device *csdev) |
630 | { | |
631 | return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SOURCE); | |
632 | } | |
633 | ||
2cd87a7b AK |
634 | static inline bool coresight_is_percpu_source(struct coresight_device *csdev) |
635 | { | |
62374ce1 | 636 | return csdev && coresight_is_device_source(csdev) && |
2cd87a7b AK |
637 | (csdev->subtype.source_subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_PROC); |
638 | } | |
639 | ||
640 | static inline bool coresight_is_percpu_sink(struct coresight_device *csdev) | |
641 | { | |
642 | return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SINK) && | |
643 | (csdev->subtype.sink_subtype == CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM); | |
644 | } | |
645 | ||
d724f652 JC |
646 | /* |
647 | * Atomically try to take the device and set a new mode. Returns true on | |
648 | * success, false if the device is already taken by someone else. | |
649 | */ | |
650 | static inline bool coresight_take_mode(struct coresight_device *csdev, | |
651 | enum cs_mode new_mode) | |
652 | { | |
653 | return local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, new_mode) == | |
654 | CS_MODE_DISABLED; | |
655 | } | |
656 | ||
c95c2733 JC |
657 | static inline enum cs_mode coresight_get_mode(struct coresight_device *csdev) |
658 | { | |
659 | return local_read(&csdev->mode); | |
660 | } | |
661 | ||
bcaabb95 JC |
662 | static inline void coresight_set_mode(struct coresight_device *csdev, |
663 | enum cs_mode new_mode) | |
664 | { | |
665 | enum cs_mode current_mode = coresight_get_mode(csdev); | |
666 | ||
667 | /* | |
668 | * Changing to a new mode must be done from an already disabled state | |
669 | * unless it's synchronized with coresight_take_mode(). Otherwise the | |
670 | * device is already in use and signifies a locking issue. | |
671 | */ | |
672 | WARN(new_mode != CS_MODE_DISABLED && current_mode != CS_MODE_DISABLED && | |
673 | current_mode != new_mode, "Device already in use\n"); | |
674 | ||
675 | local_set(&csdev->mode, new_mode); | |
676 | } | |
677 | ||
e6e6b692 JC |
678 | struct coresight_device *coresight_register(struct coresight_desc *desc); |
679 | void coresight_unregister(struct coresight_device *csdev); | |
680 | int coresight_enable_sysfs(struct coresight_device *csdev); | |
681 | void coresight_disable_sysfs(struct coresight_device *csdev); | |
682 | int coresight_timeout(struct csdev_access *csa, u32 offset, int position, int value); | |
4ff6039f | 683 | typedef void (*coresight_timeout_cb_t) (struct csdev_access *, u32, int, int); |
e6e6b692 JC |
684 | int coresight_timeout_action(struct csdev_access *csa, u32 offset, int position, int value, |
685 | coresight_timeout_cb_t cb); | |
686 | int coresight_claim_device(struct coresight_device *csdev); | |
687 | int coresight_claim_device_unlocked(struct coresight_device *csdev); | |
2478a6ae | 688 | |
e6e6b692 JC |
689 | int coresight_claim_device(struct coresight_device *csdev); |
690 | int coresight_claim_device_unlocked(struct coresight_device *csdev); | |
fc7fed6f JC |
691 | void coresight_clear_self_claim_tag(struct csdev_access *csa); |
692 | void coresight_clear_self_claim_tag_unlocked(struct csdev_access *csa); | |
e6e6b692 JC |
693 | void coresight_disclaim_device(struct coresight_device *csdev); |
694 | void coresight_disclaim_device_unlocked(struct coresight_device *csdev); | |
695 | char *coresight_alloc_device_name(struct coresight_dev_list *devs, | |
0f5f9b6b | 696 | struct device *dev); |
f188b5e7 | 697 | |
e6e6b692 | 698 | bool coresight_loses_context_with_cpu(struct device *dev); |
6e736c60 SP |
699 | |
700 | u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset); | |
701 | u32 coresight_read32(struct coresight_device *csdev, u32 offset); | |
702 | void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset); | |
703 | void coresight_relaxed_write32(struct coresight_device *csdev, | |
704 | u32 val, u32 offset); | |
705 | u64 coresight_relaxed_read64(struct coresight_device *csdev, u32 offset); | |
706 | u64 coresight_read64(struct coresight_device *csdev, u32 offset); | |
707 | void coresight_relaxed_write64(struct coresight_device *csdev, | |
708 | u64 val, u32 offset); | |
709 | void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset); | |
710 | ||
e6e6b692 JC |
711 | int coresight_get_cpu(struct device *dev); |
712 | int coresight_get_static_trace_id(struct device *dev, u32 *id); | |
a06ae860 | 713 | |
f03631da | 714 | struct coresight_platform_data *coresight_get_platform_data(struct device *dev); |
3d4ff657 JC |
715 | struct coresight_connection * |
716 | coresight_add_out_conn(struct device *dev, | |
717 | struct coresight_platform_data *pdata, | |
718 | const struct coresight_connection *new_conn); | |
e3f4e687 | 719 | int coresight_add_in_conn(struct coresight_connection *conn); |
61486528 JC |
720 | struct coresight_device * |
721 | coresight_find_input_type(struct coresight_platform_data *pdata, | |
722 | enum coresight_dev_type type, | |
723 | union coresight_dev_subtype subtype); | |
724 | struct coresight_device * | |
725 | coresight_find_output_type(struct coresight_platform_data *pdata, | |
726 | enum coresight_dev_type type, | |
727 | union coresight_dev_subtype subtype); | |
f03631da | 728 | |
075b7cd7 | 729 | int coresight_init_driver(const char *drv, struct amba_driver *amba_drv, |
9f52aecc | 730 | struct platform_driver *pdev_drv, struct module *owner); |
075b7cd7 AK |
731 | |
732 | void coresight_remove_driver(struct amba_driver *amba_drv, | |
733 | struct platform_driver *pdev_drv); | |
c367a89d JG |
734 | int coresight_etm_get_trace_id(struct coresight_device *csdev, enum cs_mode mode, |
735 | struct coresight_device *sink); | |
6e736c60 | 736 | #endif /* _LINUX_COREISGHT_H */ |