1
2
3
4
5
6#ifndef _LINUX_CORESIGHT_H
7#define _LINUX_CORESIGHT_H
8
9#include <linux/device.h>
10#include <linux/io.h>
11#include <linux/perf_event.h>
12#include <linux/sched.h>
13
14
15#define CORESIGHT_PERIPHIDR4 0xfd0
16#define CORESIGHT_PERIPHIDR5 0xfd4
17#define CORESIGHT_PERIPHIDR6 0xfd8
18#define CORESIGHT_PERIPHIDR7 0xfdC
19#define CORESIGHT_PERIPHIDR0 0xfe0
20#define CORESIGHT_PERIPHIDR1 0xfe4
21#define CORESIGHT_PERIPHIDR2 0xfe8
22#define CORESIGHT_PERIPHIDR3 0xfeC
23
24#define CORESIGHT_COMPIDR0 0xff0
25#define CORESIGHT_COMPIDR1 0xff4
26#define CORESIGHT_COMPIDR2 0xff8
27#define CORESIGHT_COMPIDR3 0xffC
28
29#define ETM_ARCH_V3_3 0x23
30#define ETM_ARCH_V3_5 0x25
31#define PFT_ARCH_V1_0 0x30
32#define PFT_ARCH_V1_1 0x31
33
34#define CORESIGHT_UNLOCK 0xc5acce55
35
36extern struct bus_type coresight_bustype;
37
38enum coresight_dev_type {
39 CORESIGHT_DEV_TYPE_NONE,
40 CORESIGHT_DEV_TYPE_SINK,
41 CORESIGHT_DEV_TYPE_LINK,
42 CORESIGHT_DEV_TYPE_LINKSINK,
43 CORESIGHT_DEV_TYPE_SOURCE,
44 CORESIGHT_DEV_TYPE_HELPER,
45 CORESIGHT_DEV_TYPE_ECT,
46};
47
48enum coresight_dev_subtype_sink {
49 CORESIGHT_DEV_SUBTYPE_SINK_NONE,
50 CORESIGHT_DEV_SUBTYPE_SINK_PORT,
51 CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
52 CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM,
53 CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM,
54};
55
56enum coresight_dev_subtype_link {
57 CORESIGHT_DEV_SUBTYPE_LINK_NONE,
58 CORESIGHT_DEV_SUBTYPE_LINK_MERG,
59 CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
60 CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
61};
62
63enum coresight_dev_subtype_source {
64 CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
65 CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
66 CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
67 CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
68};
69
70enum coresight_dev_subtype_helper {
71 CORESIGHT_DEV_SUBTYPE_HELPER_NONE,
72 CORESIGHT_DEV_SUBTYPE_HELPER_CATU,
73};
74
75
76enum coresight_dev_subtype_ect {
77 CORESIGHT_DEV_SUBTYPE_ECT_NONE,
78 CORESIGHT_DEV_SUBTYPE_ECT_CTI,
79};
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94union coresight_dev_subtype {
95
96 struct {
97 enum coresight_dev_subtype_sink sink_subtype;
98 enum coresight_dev_subtype_link link_subtype;
99 };
100 enum coresight_dev_subtype_source source_subtype;
101 enum coresight_dev_subtype_helper helper_subtype;
102 enum coresight_dev_subtype_ect ect_subtype;
103};
104
105
106
107
108
109
110
111
112
113struct coresight_platform_data {
114 int nr_inport;
115 int nr_outport;
116 struct coresight_connection *conns;
117};
118
119
120
121
122
123
124
125
126
127struct csdev_access {
128 bool io_mem;
129 union {
130 void __iomem *base;
131 struct {
132 u64 (*read)(u32 offset, bool relaxed, bool _64bit);
133 void (*write)(u64 val, u32 offset, bool relaxed,
134 bool _64bit);
135 };
136 };
137};
138
139#define CSDEV_ACCESS_IOMEM(_addr) \
140 ((struct csdev_access) { \
141 .io_mem = true, \
142 .base = (_addr), \
143 })
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158struct coresight_desc {
159 enum coresight_dev_type type;
160 union coresight_dev_subtype subtype;
161 const struct coresight_ops *ops;
162 struct coresight_platform_data *pdata;
163 struct device *dev;
164 const struct attribute_group **groups;
165 const char *name;
166 struct csdev_access access;
167};
168
169
170
171
172
173
174
175
176
177
178struct coresight_connection {
179 int outport;
180 int child_port;
181 struct fwnode_handle *child_fwnode;
182 struct coresight_device *child_dev;
183 struct coresight_sysfs_link *link;
184};
185
186
187
188
189
190
191
192
193struct coresight_sysfs_link {
194 struct coresight_device *orig;
195 const char *orig_name;
196 struct coresight_device *target;
197 const char *target_name;
198};
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224struct coresight_device {
225 struct coresight_platform_data *pdata;
226 enum coresight_dev_type type;
227 union coresight_dev_subtype subtype;
228 const struct coresight_ops *ops;
229 struct csdev_access access;
230 struct device dev;
231 atomic_t *refcnt;
232 bool orphan;
233 bool enable;
234
235 bool activated;
236 struct dev_ext_attribute *ea;
237 struct coresight_device *def_sink;
238
239 struct coresight_device *ect_dev;
240
241 int nr_links;
242 bool has_conns_grp;
243 bool ect_enabled;
244};
245
246
247
248
249
250
251
252
253
254
255struct coresight_dev_list {
256 int nr_idx;
257 const char *pfx;
258 struct fwnode_handle **fwnode_list;
259};
260
261#define DEFINE_CORESIGHT_DEVLIST(var, dev_pfx) \
262static struct coresight_dev_list (var) = { \
263 .pfx = dev_pfx, \
264 .nr_idx = 0, \
265 .fwnode_list = NULL, \
266}
267
268#define to_coresight_device(d) container_of(d, struct coresight_device, dev)
269
270#define source_ops(csdev) csdev->ops->source_ops
271#define sink_ops(csdev) csdev->ops->sink_ops
272#define link_ops(csdev) csdev->ops->link_ops
273#define helper_ops(csdev) csdev->ops->helper_ops
274#define ect_ops(csdev) csdev->ops->ect_ops
275
276
277
278
279
280
281
282
283
284
285struct coresight_ops_sink {
286 int (*enable)(struct coresight_device *csdev, u32 mode, void *data);
287 int (*disable)(struct coresight_device *csdev);
288 void *(*alloc_buffer)(struct coresight_device *csdev,
289 struct perf_event *event, void **pages,
290 int nr_pages, bool overwrite);
291 void (*free_buffer)(void *config);
292 unsigned long (*update_buffer)(struct coresight_device *csdev,
293 struct perf_output_handle *handle,
294 void *sink_config);
295};
296
297
298
299
300
301
302
303struct coresight_ops_link {
304 int (*enable)(struct coresight_device *csdev, int iport, int oport);
305 void (*disable)(struct coresight_device *csdev, int iport, int oport);
306};
307
308
309
310
311
312
313
314
315
316
317
318struct coresight_ops_source {
319 int (*cpu_id)(struct coresight_device *csdev);
320 int (*trace_id)(struct coresight_device *csdev);
321 int (*enable)(struct coresight_device *csdev,
322 struct perf_event *event, u32 mode);
323 void (*disable)(struct coresight_device *csdev,
324 struct perf_event *event);
325};
326
327
328
329
330
331
332
333
334
335
336struct coresight_ops_helper {
337 int (*enable)(struct coresight_device *csdev, void *data);
338 int (*disable)(struct coresight_device *csdev, void *data);
339};
340
341
342
343
344
345
346
347struct coresight_ops_ect {
348 int (*enable)(struct coresight_device *csdev);
349 int (*disable)(struct coresight_device *csdev);
350};
351
352struct coresight_ops {
353 const struct coresight_ops_sink *sink_ops;
354 const struct coresight_ops_link *link_ops;
355 const struct coresight_ops_source *source_ops;
356 const struct coresight_ops_helper *helper_ops;
357 const struct coresight_ops_ect *ect_ops;
358};
359
360#if IS_ENABLED(CONFIG_CORESIGHT)
361
362static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa,
363 u32 offset)
364{
365 if (likely(csa->io_mem))
366 return readl_relaxed(csa->base + offset);
367
368 return csa->read(offset, true, false);
369}
370
371static inline u32 csdev_access_read32(struct csdev_access *csa, u32 offset)
372{
373 if (likely(csa->io_mem))
374 return readl(csa->base + offset);
375
376 return csa->read(offset, false, false);
377}
378
379static inline void csdev_access_relaxed_write32(struct csdev_access *csa,
380 u32 val, u32 offset)
381{
382 if (likely(csa->io_mem))
383 writel_relaxed(val, csa->base + offset);
384 else
385 csa->write(val, offset, true, false);
386}
387
388static inline void csdev_access_write32(struct csdev_access *csa, u32 val, u32 offset)
389{
390 if (likely(csa->io_mem))
391 writel(val, csa->base + offset);
392 else
393 csa->write(val, offset, false, false);
394}
395
396#ifdef CONFIG_64BIT
397
398static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa,
399 u32 offset)
400{
401 if (likely(csa->io_mem))
402 return readq_relaxed(csa->base + offset);
403
404 return csa->read(offset, true, true);
405}
406
407static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset)
408{
409 if (likely(csa->io_mem))
410 return readq(csa->base + offset);
411
412 return csa->read(offset, false, true);
413}
414
415static inline void csdev_access_relaxed_write64(struct csdev_access *csa,
416 u64 val, u32 offset)
417{
418 if (likely(csa->io_mem))
419 writeq_relaxed(val, csa->base + offset);
420 else
421 csa->write(val, offset, true, true);
422}
423
424static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset)
425{
426 if (likely(csa->io_mem))
427 writeq(val, csa->base + offset);
428 else
429 csa->write(val, offset, false, true);
430}
431
432#else
433
434static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa,
435 u32 offset)
436{
437 WARN_ON(1);
438 return 0;
439}
440
441static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset)
442{
443 WARN_ON(1);
444 return 0;
445}
446
447static inline void csdev_access_relaxed_write64(struct csdev_access *csa,
448 u64 val, u32 offset)
449{
450 WARN_ON(1);
451}
452
453static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset)
454{
455 WARN_ON(1);
456}
457#endif
458
459static inline bool coresight_is_percpu_source(struct coresight_device *csdev)
460{
461 return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SOURCE) &&
462 (csdev->subtype.source_subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_PROC);
463}
464
465static inline bool coresight_is_percpu_sink(struct coresight_device *csdev)
466{
467 return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SINK) &&
468 (csdev->subtype.sink_subtype == CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM);
469}
470
471extern struct coresight_device *
472coresight_register(struct coresight_desc *desc);
473extern void coresight_unregister(struct coresight_device *csdev);
474extern int coresight_enable(struct coresight_device *csdev);
475extern void coresight_disable(struct coresight_device *csdev);
476extern int coresight_timeout(struct csdev_access *csa, u32 offset,
477 int position, int value);
478
479extern int coresight_claim_device(struct coresight_device *csdev);
480extern int coresight_claim_device_unlocked(struct coresight_device *csdev);
481
482extern void coresight_disclaim_device(struct coresight_device *csdev);
483extern void coresight_disclaim_device_unlocked(struct coresight_device *csdev);
484extern char *coresight_alloc_device_name(struct coresight_dev_list *devs,
485 struct device *dev);
486
487extern bool coresight_loses_context_with_cpu(struct device *dev);
488
489u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset);
490u32 coresight_read32(struct coresight_device *csdev, u32 offset);
491void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset);
492void coresight_relaxed_write32(struct coresight_device *csdev,
493 u32 val, u32 offset);
494u64 coresight_relaxed_read64(struct coresight_device *csdev, u32 offset);
495u64 coresight_read64(struct coresight_device *csdev, u32 offset);
496void coresight_relaxed_write64(struct coresight_device *csdev,
497 u64 val, u32 offset);
498void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset);
499
500#else
501static inline struct coresight_device *
502coresight_register(struct coresight_desc *desc) { return NULL; }
503static inline void coresight_unregister(struct coresight_device *csdev) {}
504static inline int
505coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
506static inline void coresight_disable(struct coresight_device *csdev) {}
507
508static inline int coresight_timeout(struct csdev_access *csa, u32 offset,
509 int position, int value)
510{
511 return 1;
512}
513
514static inline int coresight_claim_device_unlocked(struct coresight_device *csdev)
515{
516 return -EINVAL;
517}
518
519static inline int coresight_claim_device(struct coresight_device *csdev)
520{
521 return -EINVAL;
522}
523
524static inline void coresight_disclaim_device(struct coresight_device *csdev) {}
525static inline void coresight_disclaim_device_unlocked(struct coresight_device *csdev) {}
526
527static inline bool coresight_loses_context_with_cpu(struct device *dev)
528{
529 return false;
530}
531
532static inline u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset)
533{
534 WARN_ON_ONCE(1);
535 return 0;
536}
537
538static inline u32 coresight_read32(struct coresight_device *csdev, u32 offset)
539{
540 WARN_ON_ONCE(1);
541 return 0;
542}
543
544static inline void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset)
545{
546}
547
548static inline void coresight_relaxed_write32(struct coresight_device *csdev,
549 u32 val, u32 offset)
550{
551}
552
553static inline u64 coresight_relaxed_read64(struct coresight_device *csdev,
554 u32 offset)
555{
556 WARN_ON_ONCE(1);
557 return 0;
558}
559
560static inline u64 coresight_read64(struct coresight_device *csdev, u32 offset)
561{
562 WARN_ON_ONCE(1);
563 return 0;
564}
565
566static inline void coresight_relaxed_write64(struct coresight_device *csdev,
567 u64 val, u32 offset)
568{
569}
570
571static inline void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset)
572{
573}
574
575#endif
576
577extern int coresight_get_cpu(struct device *dev);
578
579struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
580
581#endif
582