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