1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _LINUX_CORESIGHT_H
14#define _LINUX_CORESIGHT_H
15
16#include <linux/device.h>
17#include <linux/perf_event.h>
18#include <linux/sched.h>
19
20
21#define CORESIGHT_PERIPHIDR4 0xfd0
22#define CORESIGHT_PERIPHIDR5 0xfd4
23#define CORESIGHT_PERIPHIDR6 0xfd8
24#define CORESIGHT_PERIPHIDR7 0xfdC
25#define CORESIGHT_PERIPHIDR0 0xfe0
26#define CORESIGHT_PERIPHIDR1 0xfe4
27#define CORESIGHT_PERIPHIDR2 0xfe8
28#define CORESIGHT_PERIPHIDR3 0xfeC
29
30#define CORESIGHT_COMPIDR0 0xff0
31#define CORESIGHT_COMPIDR1 0xff4
32#define CORESIGHT_COMPIDR2 0xff8
33#define CORESIGHT_COMPIDR3 0xffC
34
35#define ETM_ARCH_V3_3 0x23
36#define ETM_ARCH_V3_5 0x25
37#define PFT_ARCH_V1_0 0x30
38#define PFT_ARCH_V1_1 0x31
39
40#define CORESIGHT_UNLOCK 0xc5acce55
41
42extern struct bus_type coresight_bustype;
43
44enum coresight_dev_type {
45 CORESIGHT_DEV_TYPE_NONE,
46 CORESIGHT_DEV_TYPE_SINK,
47 CORESIGHT_DEV_TYPE_LINK,
48 CORESIGHT_DEV_TYPE_LINKSINK,
49 CORESIGHT_DEV_TYPE_SOURCE,
50};
51
52enum coresight_dev_subtype_sink {
53 CORESIGHT_DEV_SUBTYPE_SINK_NONE,
54 CORESIGHT_DEV_SUBTYPE_SINK_PORT,
55 CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
56};
57
58enum coresight_dev_subtype_link {
59 CORESIGHT_DEV_SUBTYPE_LINK_NONE,
60 CORESIGHT_DEV_SUBTYPE_LINK_MERG,
61 CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
62 CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
63};
64
65enum coresight_dev_subtype_source {
66 CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
67 CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
68 CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
69 CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
70};
71
72
73
74
75
76
77
78
79
80
81struct coresight_dev_subtype {
82 enum coresight_dev_subtype_sink sink_subtype;
83 enum coresight_dev_subtype_link link_subtype;
84 enum coresight_dev_subtype_source source_subtype;
85};
86
87
88
89
90
91
92
93
94
95
96
97
98
99struct coresight_platform_data {
100 int cpu;
101 const char *name;
102 int nr_inport;
103 int *outports;
104 const char **child_names;
105 int *child_ports;
106 int nr_outport;
107 struct clk *clk;
108};
109
110
111
112
113
114
115
116
117
118
119
120
121struct coresight_desc {
122 enum coresight_dev_type type;
123 struct coresight_dev_subtype subtype;
124 const struct coresight_ops *ops;
125 struct coresight_platform_data *pdata;
126 struct device *dev;
127 const struct attribute_group **groups;
128};
129
130
131
132
133
134
135
136
137
138struct coresight_connection {
139 int outport;
140 const char *child_name;
141 int child_port;
142 struct coresight_device *child_dev;
143};
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162struct coresight_device {
163 struct coresight_connection *conns;
164 int nr_inport;
165 int nr_outport;
166 enum coresight_dev_type type;
167 struct coresight_dev_subtype subtype;
168 const struct coresight_ops *ops;
169 struct device dev;
170 atomic_t *refcnt;
171 bool orphan;
172 bool enable;
173 bool activated;
174};
175
176#define to_coresight_device(d) container_of(d, struct coresight_device, dev)
177
178#define source_ops(csdev) csdev->ops->source_ops
179#define sink_ops(csdev) csdev->ops->sink_ops
180#define link_ops(csdev) csdev->ops->link_ops
181
182
183
184
185
186
187
188
189
190
191
192
193struct coresight_ops_sink {
194 int (*enable)(struct coresight_device *csdev, u32 mode);
195 void (*disable)(struct coresight_device *csdev);
196 void *(*alloc_buffer)(struct coresight_device *csdev, int cpu,
197 void **pages, int nr_pages, bool overwrite);
198 void (*free_buffer)(void *config);
199 int (*set_buffer)(struct coresight_device *csdev,
200 struct perf_output_handle *handle,
201 void *sink_config);
202 unsigned long (*reset_buffer)(struct coresight_device *csdev,
203 struct perf_output_handle *handle,
204 void *sink_config, bool *lost);
205 void (*update_buffer)(struct coresight_device *csdev,
206 struct perf_output_handle *handle,
207 void *sink_config);
208};
209
210
211
212
213
214
215
216struct coresight_ops_link {
217 int (*enable)(struct coresight_device *csdev, int iport, int oport);
218 void (*disable)(struct coresight_device *csdev, int iport, int oport);
219};
220
221
222
223
224
225
226
227
228
229
230
231struct coresight_ops_source {
232 int (*cpu_id)(struct coresight_device *csdev);
233 int (*trace_id)(struct coresight_device *csdev);
234 int (*enable)(struct coresight_device *csdev,
235 struct perf_event *event, u32 mode);
236 void (*disable)(struct coresight_device *csdev,
237 struct perf_event *event);
238};
239
240struct coresight_ops {
241 const struct coresight_ops_sink *sink_ops;
242 const struct coresight_ops_link *link_ops;
243 const struct coresight_ops_source *source_ops;
244};
245
246#ifdef CONFIG_CORESIGHT
247extern struct coresight_device *
248coresight_register(struct coresight_desc *desc);
249extern void coresight_unregister(struct coresight_device *csdev);
250extern int coresight_enable(struct coresight_device *csdev);
251extern void coresight_disable(struct coresight_device *csdev);
252extern int coresight_timeout(void __iomem *addr, u32 offset,
253 int position, int value);
254#else
255static inline struct coresight_device *
256coresight_register(struct coresight_desc *desc) { return NULL; }
257static inline void coresight_unregister(struct coresight_device *csdev) {}
258static inline int
259coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
260static inline void coresight_disable(struct coresight_device *csdev) {}
261static inline int coresight_timeout(void __iomem *addr, u32 offset,
262 int position, int value) { return 1; }
263#endif
264
265#ifdef CONFIG_OF
266extern struct coresight_platform_data *of_get_coresight_platform_data(
267 struct device *dev, struct device_node *node);
268#else
269static inline struct coresight_platform_data *of_get_coresight_platform_data(
270 struct device *dev, struct device_node *node) { return NULL; }
271#endif
272
273#ifdef CONFIG_PID_NS
274static inline unsigned long
275coresight_vpid_to_pid(unsigned long vpid)
276{
277 struct task_struct *task = NULL;
278 unsigned long pid = 0;
279
280 rcu_read_lock();
281 task = find_task_by_vpid(vpid);
282 if (task)
283 pid = task_pid_nr(task);
284 rcu_read_unlock();
285
286 return pid;
287}
288#else
289static inline unsigned long
290coresight_vpid_to_pid(unsigned long vpid) { return vpid; }
291#endif
292
293#endif
294