Upgrade to 4.4.50-rt62
[kvmfornfv.git] / kernel / drivers / hwtracing / intel_th / intel_th.h
1 /*
2  * Intel(R) Trace Hub data structures
3  *
4  * Copyright (C) 2014-2015 Intel Corporation.
5  *
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.
9  *
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
13  * more details.
14  */
15
16 #ifndef __INTEL_TH_H__
17 #define __INTEL_TH_H__
18
19 /* intel_th_device device types */
20 enum {
21         /* Devices that generate trace data */
22         INTEL_TH_SOURCE = 0,
23         /* Output ports (MSC, PTI) */
24         INTEL_TH_OUTPUT,
25         /* Switch, the Global Trace Hub (GTH) */
26         INTEL_TH_SWITCH,
27 };
28
29 /**
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  * @multiblock: true for multiblock output configuration
34  * @active:     true when this output is enabled
35  *
36  * Output port descriptor, used by switch driver to tell which output
37  * port this output device corresponds to. Filled in at output device's
38  * probe time by switch::assign(). Passed from output device driver to
39  * switch related code to enable/disable its port.
40  */
41 struct intel_th_output {
42         int             port;
43         unsigned int    type;
44         bool            multiblock;
45         bool            active;
46 };
47
48 /**
49  * struct intel_th_device - device on the intel_th bus
50  * @dev:                device
51  * @resource:           array of resources available to this device
52  * @num_resources:      number of resources in @resource array
53  * @type:               INTEL_TH_{SOURCE,OUTPUT,SWITCH}
54  * @id:                 device instance or -1
55  * @output:             output descriptor for INTEL_TH_OUTPUT devices
56  * @name:               device name to match the driver
57  */
58 struct intel_th_device {
59         struct device   dev;
60         struct resource *resource;
61         unsigned int    num_resources;
62         unsigned int    type;
63         int             id;
64
65         /* INTEL_TH_OUTPUT specific */
66         struct intel_th_output  output;
67
68         char            name[];
69 };
70
71 #define to_intel_th_device(_d)                          \
72         container_of((_d), struct intel_th_device, dev)
73
74 /**
75  * intel_th_device_get_resource() - obtain @num'th resource of type @type
76  * @thdev:      the device to search the resource for
77  * @type:       resource type
78  * @num:        number of the resource
79  */
80 static inline struct resource *
81 intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
82                              unsigned int num)
83 {
84         int i;
85
86         for (i = 0; i < thdev->num_resources; i++)
87                 if (resource_type(&thdev->resource[i]) == type && !num--)
88                         return &thdev->resource[i];
89
90         return NULL;
91 }
92
93 /**
94  * intel_th_output_assigned() - if an output device is assigned to a switch port
95  * @thdev:      the output device
96  *
97  * Return:      true if the device is INTEL_TH_OUTPUT *and* is assigned a port
98  */
99 static inline bool
100 intel_th_output_assigned(struct intel_th_device *thdev)
101 {
102         return thdev->type == INTEL_TH_OUTPUT &&
103                 thdev->output.port >= 0;
104 }
105
106 /**
107  * struct intel_th_driver - driver for an intel_th_device device
108  * @driver:     generic driver
109  * @probe:      probe method
110  * @remove:     remove method
111  * @assign:     match a given output type device against available outputs
112  * @unassign:   deassociate an output type device from an output port
113  * @enable:     enable tracing for a given output device
114  * @disable:    disable tracing for a given output device
115  * @fops:       file operations for device nodes
116  *
117  * Callbacks @probe and @remove are required for all device types.
118  * Switch device driver needs to fill in @assign, @enable and @disable
119  * callbacks.
120  */
121 struct intel_th_driver {
122         struct device_driver    driver;
123         int                     (*probe)(struct intel_th_device *thdev);
124         void                    (*remove)(struct intel_th_device *thdev);
125         /* switch (GTH) ops */
126         int                     (*assign)(struct intel_th_device *thdev,
127                                           struct intel_th_device *othdev);
128         void                    (*unassign)(struct intel_th_device *thdev,
129                                             struct intel_th_device *othdev);
130         void                    (*enable)(struct intel_th_device *thdev,
131                                           struct intel_th_output *output);
132         void                    (*disable)(struct intel_th_device *thdev,
133                                            struct intel_th_output *output);
134         /* output ops */
135         void                    (*irq)(struct intel_th_device *thdev);
136         int                     (*activate)(struct intel_th_device *thdev);
137         void                    (*deactivate)(struct intel_th_device *thdev);
138         /* file_operations for those who want a device node */
139         const struct file_operations *fops;
140
141         /* source ops */
142         int                     (*set_output)(struct intel_th_device *thdev,
143                                               unsigned int master);
144 };
145
146 #define to_intel_th_driver(_d)                                  \
147         container_of((_d), struct intel_th_driver, driver)
148
149 static inline struct intel_th_device *
150 to_intel_th_hub(struct intel_th_device *thdev)
151 {
152         struct device *parent = thdev->dev.parent;
153
154         if (!parent)
155                 return NULL;
156
157         return to_intel_th_device(parent);
158 }
159
160 struct intel_th *
161 intel_th_alloc(struct device *dev, struct resource *devres,
162                unsigned int ndevres, int irq);
163 void intel_th_free(struct intel_th *th);
164
165 int intel_th_driver_register(struct intel_th_driver *thdrv);
166 void intel_th_driver_unregister(struct intel_th_driver *thdrv);
167
168 int intel_th_trace_enable(struct intel_th_device *thdev);
169 int intel_th_trace_disable(struct intel_th_device *thdev);
170 int intel_th_set_output(struct intel_th_device *thdev,
171                         unsigned int master);
172
173 enum {
174         TH_MMIO_CONFIG = 0,
175         TH_MMIO_SW = 2,
176         TH_MMIO_END,
177 };
178
179 #define TH_SUBDEVICE_MAX        6
180 #define TH_POSSIBLE_OUTPUTS     8
181 #define TH_CONFIGURABLE_MASTERS 256
182 #define TH_MSC_MAX              2
183
184 /**
185  * struct intel_th - Intel TH controller
186  * @dev:        driver core's device
187  * @thdev:      subdevices
188  * @hub:        "switch" subdevice (GTH)
189  * @id:         this Intel TH controller's device ID in the system
190  * @major:      device node major for output devices
191  */
192 struct intel_th {
193         struct device           *dev;
194
195         struct intel_th_device  *thdev[TH_SUBDEVICE_MAX];
196         struct intel_th_device  *hub;
197
198         int                     id;
199         int                     major;
200 #ifdef CONFIG_MODULES
201         struct work_struct      request_module_work;
202 #endif /* CONFIG_MODULES */
203 #ifdef CONFIG_INTEL_TH_DEBUG
204         struct dentry           *dbg;
205 #endif
206 };
207
208 /*
209  * Register windows
210  */
211 enum {
212         /* Global Trace Hub (GTH) */
213         REG_GTH_OFFSET          = 0x0000,
214         REG_GTH_LENGTH          = 0x2000,
215
216         /* Software Trace Hub (STH) [0x4000..0x4fff] */
217         REG_STH_OFFSET          = 0x4000,
218         REG_STH_LENGTH          = 0x2000,
219
220         /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
221         REG_MSU_OFFSET          = 0xa0000,
222         REG_MSU_LENGTH          = 0x02000,
223
224         /* Internal MSU trace buffer [0x80000..0x9ffff] */
225         BUF_MSU_OFFSET          = 0x80000,
226         BUF_MSU_LENGTH          = 0x20000,
227
228         /* PTI output == same window as GTH */
229         REG_PTI_OFFSET          = REG_GTH_OFFSET,
230         REG_PTI_LENGTH          = REG_GTH_LENGTH,
231
232         /* DCI Handler (DCIH) == some window as MSU */
233         REG_DCIH_OFFSET         = REG_MSU_OFFSET,
234         REG_DCIH_LENGTH         = REG_MSU_LENGTH,
235 };
236
237 /*
238  * GTH, output ports configuration
239  */
240 enum {
241         GTH_NONE = 0,
242         GTH_MSU,        /* memory/usb */
243         GTH_CTP,        /* Common Trace Port */
244         GTH_PTI = 4,    /* MIPI-PTI */
245 };
246
247 #endif