1
2
3
4
5
6
7
8#ifndef __INTEL_TH_H__
9#define __INTEL_TH_H__
10
11#include <linux/irqreturn.h>
12
13
14enum {
15
16 INTEL_TH_SOURCE = 0,
17
18 INTEL_TH_OUTPUT,
19
20 INTEL_TH_SWITCH,
21};
22
23struct intel_th_device;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39struct intel_th_output {
40 int port;
41 unsigned int type;
42 unsigned int scratchpad;
43 bool multiblock;
44 bool active;
45};
46
47
48
49
50
51
52
53
54struct intel_th_drvdata {
55 unsigned int tscu_enable : 1,
56 multi_is_broken : 1,
57 has_mintctl : 1,
58 host_mode_only : 1;
59};
60
61#define INTEL_TH_CAP(_th, _cap) ((_th)->drvdata ? (_th)->drvdata->_cap : 0)
62
63
64
65
66
67
68
69
70
71
72
73
74
75struct intel_th_device {
76 struct device dev;
77 const struct intel_th_drvdata *drvdata;
78 struct resource *resource;
79 unsigned int num_resources;
80 unsigned int type;
81 int id;
82
83
84 bool host_mode;
85
86
87 struct intel_th_output output;
88
89 char name[];
90};
91
92#define to_intel_th_device(_d) \
93 container_of((_d), struct intel_th_device, dev)
94
95
96
97
98
99
100
101static inline struct resource *
102intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
103 unsigned int num)
104{
105 int i;
106
107 for (i = 0; i < thdev->num_resources; i++)
108 if (resource_type(&thdev->resource[i]) == type && !num--)
109 return &thdev->resource[i];
110
111 return NULL;
112}
113
114
115
116
117enum {
118 GTH_NONE = 0,
119 GTH_MSU,
120 GTH_CTP,
121 GTH_LPP,
122 GTH_PTI,
123};
124
125
126
127
128
129
130
131static inline bool
132intel_th_output_assigned(struct intel_th_device *thdev)
133{
134 return thdev->type == INTEL_TH_OUTPUT &&
135 (thdev->output.port >= 0 ||
136 thdev->output.type == GTH_NONE);
137}
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159struct intel_th_driver {
160 struct device_driver driver;
161 int (*probe)(struct intel_th_device *thdev);
162 void (*remove)(struct intel_th_device *thdev);
163
164 int (*assign)(struct intel_th_device *thdev,
165 struct intel_th_device *othdev);
166 void (*unassign)(struct intel_th_device *thdev,
167 struct intel_th_device *othdev);
168 void (*prepare)(struct intel_th_device *thdev,
169 struct intel_th_output *output);
170 void (*enable)(struct intel_th_device *thdev,
171 struct intel_th_output *output);
172 void (*trig_switch)(struct intel_th_device *thdev,
173 struct intel_th_output *output);
174 void (*disable)(struct intel_th_device *thdev,
175 struct intel_th_output *output);
176
177 irqreturn_t (*irq)(struct intel_th_device *thdev);
178 void (*wait_empty)(struct intel_th_device *thdev);
179 int (*activate)(struct intel_th_device *thdev);
180 void (*deactivate)(struct intel_th_device *thdev);
181
182 const struct file_operations *fops;
183
184 const struct attribute_group *attr_group;
185
186
187 int (*set_output)(struct intel_th_device *thdev,
188 unsigned int master);
189};
190
191#define to_intel_th_driver(_d) \
192 container_of((_d), struct intel_th_driver, driver)
193
194#define to_intel_th_driver_or_null(_d) \
195 ((_d) ? to_intel_th_driver(_d) : NULL)
196
197
198
199
200
201
202
203
204
205
206
207static inline struct intel_th_device *
208to_intel_th_parent(struct intel_th_device *thdev)
209{
210 struct device *parent = thdev->dev.parent;
211
212 if (!parent)
213 return NULL;
214
215 return to_intel_th_device(parent);
216}
217
218static inline struct intel_th *to_intel_th(struct intel_th_device *thdev)
219{
220 if (thdev->type == INTEL_TH_OUTPUT)
221 thdev = to_intel_th_parent(thdev);
222
223 if (WARN_ON_ONCE(!thdev || thdev->type == INTEL_TH_OUTPUT))
224 return NULL;
225
226 return dev_get_drvdata(thdev->dev.parent);
227}
228
229struct intel_th *
230intel_th_alloc(struct device *dev, const struct intel_th_drvdata *drvdata,
231 struct resource *devres, unsigned int ndevres);
232void intel_th_free(struct intel_th *th);
233
234int intel_th_driver_register(struct intel_th_driver *thdrv);
235void intel_th_driver_unregister(struct intel_th_driver *thdrv);
236
237int intel_th_trace_enable(struct intel_th_device *thdev);
238int intel_th_trace_switch(struct intel_th_device *thdev);
239int intel_th_trace_disable(struct intel_th_device *thdev);
240int intel_th_set_output(struct intel_th_device *thdev,
241 unsigned int master);
242int intel_th_output_enable(struct intel_th *th, unsigned int otype);
243
244enum th_mmio_idx {
245 TH_MMIO_CONFIG = 0,
246 TH_MMIO_SW = 1,
247 TH_MMIO_RTIT = 2,
248 TH_MMIO_END,
249};
250
251#define TH_POSSIBLE_OUTPUTS 8
252
253#define TH_SUBDEVICE_MAX (TH_POSSIBLE_OUTPUTS + 2)
254#define TH_CONFIGURABLE_MASTERS 256
255#define TH_MSC_MAX 2
256
257
258#define TH_NVEC_MAX 8
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273struct intel_th {
274 struct device *dev;
275
276 struct intel_th_device *thdev[TH_SUBDEVICE_MAX];
277 struct intel_th_device *hub;
278 const struct intel_th_drvdata *drvdata;
279
280 struct resource resource[TH_MMIO_END];
281 int (*activate)(struct intel_th *);
282 void (*deactivate)(struct intel_th *);
283 unsigned int num_thdevs;
284 unsigned int num_resources;
285 int irq;
286 int num_irqs;
287
288 int id;
289 int major;
290#ifdef CONFIG_MODULES
291 struct work_struct request_module_work;
292#endif
293#ifdef CONFIG_INTEL_TH_DEBUG
294 struct dentry *dbg;
295#endif
296};
297
298static inline struct intel_th_device *
299to_intel_th_hub(struct intel_th_device *thdev)
300{
301 if (thdev->type == INTEL_TH_SWITCH)
302 return thdev;
303 else if (thdev->type == INTEL_TH_OUTPUT)
304 return to_intel_th_parent(thdev);
305
306 return to_intel_th(thdev)->hub;
307}
308
309
310
311
312enum {
313
314 REG_GTH_OFFSET = 0x0000,
315 REG_GTH_LENGTH = 0x2000,
316
317
318 REG_TSCU_OFFSET = 0x2000,
319 REG_TSCU_LENGTH = 0x1000,
320
321 REG_CTS_OFFSET = 0x3000,
322 REG_CTS_LENGTH = 0x1000,
323
324
325 REG_STH_OFFSET = 0x4000,
326 REG_STH_LENGTH = 0x2000,
327
328
329 REG_MSU_OFFSET = 0xa0000,
330 REG_MSU_LENGTH = 0x02000,
331
332
333 BUF_MSU_OFFSET = 0x80000,
334 BUF_MSU_LENGTH = 0x20000,
335
336
337 REG_PTI_OFFSET = REG_GTH_OFFSET,
338 REG_PTI_LENGTH = REG_GTH_LENGTH,
339
340
341 REG_DCIH_OFFSET = REG_MSU_OFFSET,
342 REG_DCIH_LENGTH = REG_MSU_LENGTH,
343};
344
345
346
347
348
349enum {
350
351 SCRPD_MEM_IS_PRIM_DEST = BIT(0),
352
353 SCRPD_DBC_IS_PRIM_DEST = BIT(1),
354
355 SCRPD_PTI_IS_PRIM_DEST = BIT(2),
356
357 SCRPD_BSSB_IS_PRIM_DEST = BIT(3),
358
359 SCRPD_PTI_IS_ALT_DEST = BIT(4),
360
361 SCRPD_BSSB_IS_ALT_DEST = BIT(5),
362
363 SCRPD_DEEPSX_EXIT = BIT(6),
364
365 SCRPD_S4_EXIT = BIT(7),
366
367 SCRPD_S5_EXIT = BIT(8),
368
369 SCRPD_MSC0_IS_ENABLED = BIT(9),
370 SCRPD_MSC1_IS_ENABLED = BIT(10),
371
372 SCRPD_SX_EXIT = BIT(11),
373
374 SCRPD_TRIGGER_IS_ENABLED = BIT(12),
375 SCRPD_ODLA_IS_ENABLED = BIT(13),
376 SCRPD_SOCHAP_IS_ENABLED = BIT(14),
377 SCRPD_STH_IS_ENABLED = BIT(15),
378 SCRPD_DCIH_IS_ENABLED = BIT(16),
379 SCRPD_VER_IS_ENABLED = BIT(17),
380
381 SCRPD_DEBUGGER_IN_USE = BIT(24),
382};
383
384#endif
385