2 * Intel(R) Trace Hub data structures
4 * Copyright (C) 2014-2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #ifndef __INTEL_TH_H__
17 #define __INTEL_TH_H__
19 /* intel_th_device device types */
21 /* Devices that generate trace data */
23 /* Output ports (MSC, PTI) */
25 /* Switch, the Global Trace Hub (GTH) */
30 * struct intel_th_output - descriptor INTEL_TH_OUTPUT type devices
31 * @port: output port number, assigned by the switch
32 * @type: GTH_{MSU,CTP,PTI}
33 * @scratchpad: scratchpad bits to flag when this output is enabled
34 * @multiblock: true for multiblock output configuration
35 * @active: true when this output is enabled
37 * Output port descriptor, used by switch driver to tell which output
38 * port this output device corresponds to. Filled in at output device's
39 * probe time by switch::assign(). Passed from output device driver to
40 * switch related code to enable/disable its port.
42 struct intel_th_output {
45 unsigned int scratchpad;
51 * struct intel_th_device - device on the intel_th bus
53 * @resource: array of resources available to this device
54 * @num_resources: number of resources in @resource array
55 * @type: INTEL_TH_{SOURCE,OUTPUT,SWITCH}
56 * @id: device instance or -1
57 * @output: output descriptor for INTEL_TH_OUTPUT devices
58 * @name: device name to match the driver
60 struct intel_th_device {
62 struct resource *resource;
63 unsigned int num_resources;
67 /* INTEL_TH_OUTPUT specific */
68 struct intel_th_output output;
73 #define to_intel_th_device(_d) \
74 container_of((_d), struct intel_th_device, dev)
77 * intel_th_device_get_resource() - obtain @num'th resource of type @type
78 * @thdev: the device to search the resource for
79 * @type: resource type
80 * @num: number of the resource
82 static inline struct resource *
83 intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
88 for (i = 0; i < thdev->num_resources; i++)
89 if (resource_type(&thdev->resource[i]) == type && !num--)
90 return &thdev->resource[i];
96 * intel_th_output_assigned() - if an output device is assigned to a switch port
97 * @thdev: the output device
99 * Return: true if the device is INTEL_TH_OUTPUT *and* is assigned a port
102 intel_th_output_assigned(struct intel_th_device *thdev)
104 return thdev->type == INTEL_TH_OUTPUT &&
105 thdev->output.port >= 0;
109 * struct intel_th_driver - driver for an intel_th_device device
110 * @driver: generic driver
111 * @probe: probe method
112 * @remove: remove method
113 * @assign: match a given output type device against available outputs
114 * @unassign: deassociate an output type device from an output port
115 * @enable: enable tracing for a given output device
116 * @disable: disable tracing for a given output device
117 * @irq: interrupt callback
118 * @activate: enable tracing on the output's side
119 * @deactivate: disable tracing on the output's side
120 * @fops: file operations for device nodes
121 * @attr_group: attributes provided by the driver
123 * Callbacks @probe and @remove are required for all device types.
124 * Switch device driver needs to fill in @assign, @enable and @disable
127 struct intel_th_driver {
128 struct device_driver driver;
129 int (*probe)(struct intel_th_device *thdev);
130 void (*remove)(struct intel_th_device *thdev);
131 /* switch (GTH) ops */
132 int (*assign)(struct intel_th_device *thdev,
133 struct intel_th_device *othdev);
134 void (*unassign)(struct intel_th_device *thdev,
135 struct intel_th_device *othdev);
136 void (*enable)(struct intel_th_device *thdev,
137 struct intel_th_output *output);
138 void (*disable)(struct intel_th_device *thdev,
139 struct intel_th_output *output);
141 void (*irq)(struct intel_th_device *thdev);
142 int (*activate)(struct intel_th_device *thdev);
143 void (*deactivate)(struct intel_th_device *thdev);
144 /* file_operations for those who want a device node */
145 const struct file_operations *fops;
146 /* optional attributes */
147 struct attribute_group *attr_group;
150 int (*set_output)(struct intel_th_device *thdev,
151 unsigned int master);
154 #define to_intel_th_driver(_d) \
155 container_of((_d), struct intel_th_driver, driver)
157 #define to_intel_th_driver_or_null(_d) \
158 ((_d) ? to_intel_th_driver(_d) : NULL)
160 static inline struct intel_th_device *
161 to_intel_th_hub(struct intel_th_device *thdev)
163 struct device *parent = thdev->dev.parent;
168 return to_intel_th_device(parent);
172 intel_th_alloc(struct device *dev, struct resource *devres,
173 unsigned int ndevres, int irq);
174 void intel_th_free(struct intel_th *th);
176 int intel_th_driver_register(struct intel_th_driver *thdrv);
177 void intel_th_driver_unregister(struct intel_th_driver *thdrv);
179 int intel_th_trace_enable(struct intel_th_device *thdev);
180 int intel_th_trace_disable(struct intel_th_device *thdev);
181 int intel_th_set_output(struct intel_th_device *thdev,
182 unsigned int master);
190 #define TH_SUBDEVICE_MAX 6
191 #define TH_POSSIBLE_OUTPUTS 8
192 #define TH_CONFIGURABLE_MASTERS 256
196 * struct intel_th - Intel TH controller
197 * @dev: driver core's device
199 * @hub: "switch" subdevice (GTH)
200 * @id: this Intel TH controller's device ID in the system
201 * @major: device node major for output devices
206 struct intel_th_device *thdev[TH_SUBDEVICE_MAX];
207 struct intel_th_device *hub;
211 #ifdef CONFIG_MODULES
212 struct work_struct request_module_work;
213 #endif /* CONFIG_MODULES */
214 #ifdef CONFIG_INTEL_TH_DEBUG
223 /* Global Trace Hub (GTH) */
224 REG_GTH_OFFSET = 0x0000,
225 REG_GTH_LENGTH = 0x2000,
227 /* Software Trace Hub (STH) [0x4000..0x4fff] */
228 REG_STH_OFFSET = 0x4000,
229 REG_STH_LENGTH = 0x2000,
231 /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
232 REG_MSU_OFFSET = 0xa0000,
233 REG_MSU_LENGTH = 0x02000,
235 /* Internal MSU trace buffer [0x80000..0x9ffff] */
236 BUF_MSU_OFFSET = 0x80000,
237 BUF_MSU_LENGTH = 0x20000,
239 /* PTI output == same window as GTH */
240 REG_PTI_OFFSET = REG_GTH_OFFSET,
241 REG_PTI_LENGTH = REG_GTH_LENGTH,
243 /* DCI Handler (DCIH) == some window as MSU */
244 REG_DCIH_OFFSET = REG_MSU_OFFSET,
245 REG_DCIH_LENGTH = REG_MSU_LENGTH,
249 * GTH, output ports configuration
253 GTH_MSU, /* memory/usb */
254 GTH_CTP, /* Common Trace Port */
255 GTH_PTI = 4, /* MIPI-PTI */
259 * Scratchpad bits: tell firmware and external debuggers
263 /* Memory is the primary destination */
264 SCRPD_MEM_IS_PRIM_DEST = BIT(0),
265 /* XHCI DbC is the primary destination */
266 SCRPD_DBC_IS_PRIM_DEST = BIT(1),
267 /* PTI is the primary destination */
268 SCRPD_PTI_IS_PRIM_DEST = BIT(2),
269 /* BSSB is the primary destination */
270 SCRPD_BSSB_IS_PRIM_DEST = BIT(3),
271 /* PTI is the alternate destination */
272 SCRPD_PTI_IS_ALT_DEST = BIT(4),
273 /* BSSB is the alternate destination */
274 SCRPD_BSSB_IS_ALT_DEST = BIT(5),
275 /* DeepSx exit occurred */
276 SCRPD_DEEPSX_EXIT = BIT(6),
277 /* S4 exit occurred */
278 SCRPD_S4_EXIT = BIT(7),
279 /* S5 exit occurred */
280 SCRPD_S5_EXIT = BIT(8),
281 /* MSU controller 0/1 is enabled */
282 SCRPD_MSC0_IS_ENABLED = BIT(9),
283 SCRPD_MSC1_IS_ENABLED = BIT(10),
284 /* Sx exit occurred */
285 SCRPD_SX_EXIT = BIT(11),
286 /* Trigger Unit is enabled */
287 SCRPD_TRIGGER_IS_ENABLED = BIT(12),
288 SCRPD_ODLA_IS_ENABLED = BIT(13),
289 SCRPD_SOCHAP_IS_ENABLED = BIT(14),
290 SCRPD_STH_IS_ENABLED = BIT(15),
291 SCRPD_DCIH_IS_ENABLED = BIT(16),
292 SCRPD_VER_IS_ENABLED = BIT(17),
293 /* External debugger is using Intel TH */
294 SCRPD_DEBUGGER_IN_USE = BIT(24),