1
2
3
4
5
6#ifndef _LINUX_CORESIGHT_H
7#define _LINUX_CORESIGHT_H
8
9#include <linux/device.h>
10#include <linux/perf_event.h>
11#include <linux/sched.h>
12
13
14#define CORESIGHT_PERIPHIDR4 0xfd0
15#define CORESIGHT_PERIPHIDR5 0xfd4
16#define CORESIGHT_PERIPHIDR6 0xfd8
17#define CORESIGHT_PERIPHIDR7 0xfdC
18#define CORESIGHT_PERIPHIDR0 0xfe0
19#define CORESIGHT_PERIPHIDR1 0xfe4
20#define CORESIGHT_PERIPHIDR2 0xfe8
21#define CORESIGHT_PERIPHIDR3 0xfeC
22
23#define CORESIGHT_COMPIDR0 0xff0
24#define CORESIGHT_COMPIDR1 0xff4
25#define CORESIGHT_COMPIDR2 0xff8
26#define CORESIGHT_COMPIDR3 0xffC
27
28#define ETM_ARCH_V3_3 0x23
29#define ETM_ARCH_V3_5 0x25
30#define PFT_ARCH_V1_0 0x30
31#define PFT_ARCH_V1_1 0x31
32
33#define CORESIGHT_UNLOCK 0xc5acce55
34
35extern struct bus_type coresight_bustype;
36
37enum coresight_dev_type {
38 CORESIGHT_DEV_TYPE_NONE,
39 CORESIGHT_DEV_TYPE_SINK,
40 CORESIGHT_DEV_TYPE_LINK,
41 CORESIGHT_DEV_TYPE_LINKSINK,
42 CORESIGHT_DEV_TYPE_SOURCE,
43 CORESIGHT_DEV_TYPE_HELPER,
44 CORESIGHT_DEV_TYPE_ECT,
45};
46
47enum coresight_dev_subtype_sink {
48 CORESIGHT_DEV_SUBTYPE_SINK_NONE,
49 CORESIGHT_DEV_SUBTYPE_SINK_PORT,
50 CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
51};
52
53enum coresight_dev_subtype_link {
54 CORESIGHT_DEV_SUBTYPE_LINK_NONE,
55 CORESIGHT_DEV_SUBTYPE_LINK_MERG,
56 CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
57 CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
58};
59
60enum coresight_dev_subtype_source {
61 CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
62 CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
63 CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
64 CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
65};
66
67enum coresight_dev_subtype_helper {
68 CORESIGHT_DEV_SUBTYPE_HELPER_NONE,
69 CORESIGHT_DEV_SUBTYPE_HELPER_CATU,
70};
71
72
73enum coresight_dev_subtype_ect {
74 CORESIGHT_DEV_SUBTYPE_ECT_NONE,
75 CORESIGHT_DEV_SUBTYPE_ECT_CTI,
76};
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91union coresight_dev_subtype {
92
93 struct {
94 enum coresight_dev_subtype_sink sink_subtype;
95 enum coresight_dev_subtype_link link_subtype;
96 };
97 enum coresight_dev_subtype_source source_subtype;
98 enum coresight_dev_subtype_helper helper_subtype;
99 enum coresight_dev_subtype_ect ect_subtype;
100};
101
102
103
104
105
106
107
108
109
110struct coresight_platform_data {
111 int nr_inport;
112 int nr_outport;
113 struct coresight_connection *conns;
114};
115
116
117
118
119
120
121
122
123
124
125
126
127
128struct coresight_desc {
129 enum coresight_dev_type type;
130 union coresight_dev_subtype subtype;
131 const struct coresight_ops *ops;
132 struct coresight_platform_data *pdata;
133 struct device *dev;
134 const struct attribute_group **groups;
135 const char *name;
136};
137
138
139
140
141
142
143
144
145
146
147struct coresight_connection {
148 int outport;
149 int child_port;
150 struct fwnode_handle *child_fwnode;
151 struct coresight_device *child_dev;
152 struct coresight_sysfs_link *link;
153};
154
155
156
157
158
159
160
161
162struct coresight_sysfs_link {
163 struct coresight_device *orig;
164 const char *orig_name;
165 struct coresight_device *target;
166 const char *target_name;
167};
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190struct coresight_device {
191 struct coresight_platform_data *pdata;
192 enum coresight_dev_type type;
193 union coresight_dev_subtype subtype;
194 const struct coresight_ops *ops;
195 struct device dev;
196 atomic_t *refcnt;
197 bool orphan;
198 bool enable;
199
200 bool activated;
201 struct dev_ext_attribute *ea;
202
203 struct coresight_device *ect_dev;
204
205 int nr_links;
206 bool has_conns_grp;
207};
208
209
210
211
212
213
214
215
216
217
218struct coresight_dev_list {
219 int nr_idx;
220 const char *pfx;
221 struct fwnode_handle **fwnode_list;
222};
223
224#define DEFINE_CORESIGHT_DEVLIST(var, dev_pfx) \
225static struct coresight_dev_list (var) = { \
226 .pfx = dev_pfx, \
227 .nr_idx = 0, \
228 .fwnode_list = NULL, \
229}
230
231#define to_coresight_device(d) container_of(d, struct coresight_device, dev)
232
233#define source_ops(csdev) csdev->ops->source_ops
234#define sink_ops(csdev) csdev->ops->sink_ops
235#define link_ops(csdev) csdev->ops->link_ops
236#define helper_ops(csdev) csdev->ops->helper_ops
237#define ect_ops(csdev) csdev->ops->ect_ops
238
239
240
241
242
243
244
245
246
247
248struct coresight_ops_sink {
249 int (*enable)(struct coresight_device *csdev, u32 mode, void *data);
250 int (*disable)(struct coresight_device *csdev);
251 void *(*alloc_buffer)(struct coresight_device *csdev,
252 struct perf_event *event, void **pages,
253 int nr_pages, bool overwrite);
254 void (*free_buffer)(void *config);
255 unsigned long (*update_buffer)(struct coresight_device *csdev,
256 struct perf_output_handle *handle,
257 void *sink_config);
258};
259
260
261
262
263
264
265
266struct coresight_ops_link {
267 int (*enable)(struct coresight_device *csdev, int iport, int oport);
268 void (*disable)(struct coresight_device *csdev, int iport, int oport);
269};
270
271
272
273
274
275
276
277
278
279
280
281struct coresight_ops_source {
282 int (*cpu_id)(struct coresight_device *csdev);
283 int (*trace_id)(struct coresight_device *csdev);
284 int (*enable)(struct coresight_device *csdev,
285 struct perf_event *event, u32 mode);
286 void (*disable)(struct coresight_device *csdev,
287 struct perf_event *event);
288};
289
290
291
292
293
294
295
296
297
298
299struct coresight_ops_helper {
300 int (*enable)(struct coresight_device *csdev, void *data);
301 int (*disable)(struct coresight_device *csdev, void *data);
302};
303
304
305
306
307
308
309
310struct coresight_ops_ect {
311 int (*enable)(struct coresight_device *csdev);
312 int (*disable)(struct coresight_device *csdev);
313};
314
315struct coresight_ops {
316 const struct coresight_ops_sink *sink_ops;
317 const struct coresight_ops_link *link_ops;
318 const struct coresight_ops_source *source_ops;
319 const struct coresight_ops_helper *helper_ops;
320 const struct coresight_ops_ect *ect_ops;
321};
322
323#ifdef CONFIG_CORESIGHT
324extern struct coresight_device *
325coresight_register(struct coresight_desc *desc);
326extern void coresight_unregister(struct coresight_device *csdev);
327extern int coresight_enable(struct coresight_device *csdev);
328extern void coresight_disable(struct coresight_device *csdev);
329extern int coresight_timeout(void __iomem *addr, u32 offset,
330 int position, int value);
331
332extern int coresight_claim_device(void __iomem *base);
333extern int coresight_claim_device_unlocked(void __iomem *base);
334
335extern void coresight_disclaim_device(void __iomem *base);
336extern void coresight_disclaim_device_unlocked(void __iomem *base);
337extern char *coresight_alloc_device_name(struct coresight_dev_list *devs,
338 struct device *dev);
339
340extern bool coresight_loses_context_with_cpu(struct device *dev);
341#else
342static inline struct coresight_device *
343coresight_register(struct coresight_desc *desc) { return NULL; }
344static inline void coresight_unregister(struct coresight_device *csdev) {}
345static inline int
346coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
347static inline void coresight_disable(struct coresight_device *csdev) {}
348static inline int coresight_timeout(void __iomem *addr, u32 offset,
349 int position, int value) { return 1; }
350static inline int coresight_claim_device_unlocked(void __iomem *base)
351{
352 return -EINVAL;
353}
354
355static inline int coresight_claim_device(void __iomem *base)
356{
357 return -EINVAL;
358}
359
360static inline void coresight_disclaim_device(void __iomem *base) {}
361static inline void coresight_disclaim_device_unlocked(void __iomem *base) {}
362
363static inline bool coresight_loses_context_with_cpu(struct device *dev)
364{
365 return false;
366}
367#endif
368
369extern int coresight_get_cpu(struct device *dev);
370
371struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
372
373#endif
374