RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / rgxhwperf.h
1 /*************************************************************************/ /*!
2 @File
3 @Title          RGX HW Performance header file
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Header for the RGX HWPerf functions
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #ifndef RGXHWPERF_H_
45 #define RGXHWPERF_H_
46
47 #include "img_types.h"
48 #include "img_defs.h"
49 #include "pvrsrv_error.h"
50
51 #include "device.h"
52 #include "connection_server.h"
53 #include "rgxdevice.h"
54 #include "rgx_hwperf_km.h"
55
56
57 /******************************************************************************
58  * RGX HW Performance Data Transport Routines
59  *****************************************************************************/
60
61 PVRSRV_ERROR RGXHWPerfDataStoreCB(PVRSRV_DEVICE_NODE* psDevInfo);
62
63 PVRSRV_ERROR RGXHWPerfInit(PVRSRV_DEVICE_NODE *psRgxDevInfo);
64 PVRSRV_ERROR RGXHWPerfInitOnDemandResources(void);
65 void RGXHWPerfDeinit(void);
66 void RGXHWPerfInitAppHintCallbacks(const PVRSRV_DEVICE_NODE *psDeviceNode);
67
68 /******************************************************************************
69  * RGX HW Performance Profiling API(s)
70  *****************************************************************************/
71
72 PVRSRV_ERROR PVRSRVRGXCtrlHWPerfKM(
73         CONNECTION_DATA      * psConnection,
74         PVRSRV_DEVICE_NODE   * psDeviceNode,
75          RGX_HWPERF_STREAM_ID  eStreamId,
76         IMG_BOOL               bToggle,
77         IMG_UINT64             ui64Mask);
78
79
80 PVRSRV_ERROR PVRSRVRGXConfigEnableHWPerfCountersKM(
81         CONNECTION_DATA    * psConnection,
82         PVRSRV_DEVICE_NODE * psDeviceNode,
83         IMG_UINT32         ui32ArrayLen,
84         RGX_HWPERF_CONFIG_CNTBLK * psBlockConfigs);
85
86 PVRSRV_ERROR PVRSRVRGXCtrlHWPerfCountersKM(
87         CONNECTION_DATA    * psConnection,
88         PVRSRV_DEVICE_NODE * psDeviceNode,
89         IMG_BOOL           bEnable,
90         IMG_UINT32         ui32ArrayLen,
91         IMG_UINT16         * psBlockIDs);
92
93 PVRSRV_ERROR PVRSRVRGXConfigCustomCountersKM(
94         CONNECTION_DATA    * psConnection,
95         PVRSRV_DEVICE_NODE * psDeviceNode,
96         IMG_UINT16           ui16CustomBlockID,
97         IMG_UINT16           ui16NumCustomCounters,
98         IMG_UINT32         * pui32CustomCounterIDs);
99
100 /******************************************************************************
101  * RGX HW Performance Host Stream API
102  *****************************************************************************/
103
104 PVRSRV_ERROR RGXHWPerfHostInit(IMG_UINT32 ui32BufSizeKB);
105 PVRSRV_ERROR RGXHWPerfHostInitOnDemandResources(void);
106 void RGXHWPerfHostDeInit(void);
107
108 void RGXHWPerfHostSetEventFilter(IMG_UINT32 ui32Filter);
109
110 void RGXHWPerfHostPostCtrlEvent(RGX_HWPERF_HOST_CTRL_TYPE eEvType,
111                                 IMG_UINT32 ui32Pid);
112
113 void RGXHWPerfHostPostEnqEvent(RGX_HWPERF_KICK_TYPE eEnqType,
114                                IMG_UINT32 ui32Pid,
115                                IMG_UINT32 ui32FWDMContext,
116                                IMG_UINT32 ui32ExtJobRef,
117                                IMG_UINT32 ui32IntJobRef);
118
119 void RGXHWPerfHostPostAllocEvent(RGX_HWPERF_HOST_RESOURCE_TYPE eAllocType,
120                                  IMG_UINT32 ui32FWAddr,
121                                  const IMG_CHAR *psName,
122                                  IMG_UINT32 ui32NameSize);
123
124 void RGXHWPerfHostPostFreeEvent(RGX_HWPERF_HOST_RESOURCE_TYPE eFreeType,
125                                 IMG_UINT32 ui32FWAddr);
126
127 void RGXHWPerfHostPostUfoEvent(RGX_HWPERF_UFO_EV eUfoType,
128                                RGX_HWPERF_UFO_DATA_ELEMENT psUFOData[],
129                                IMG_UINT uiNoOfUFOs);
130
131 void RGXHWPerfHostPostClkSyncEvent(void);
132
133 IMG_BOOL RGXHWPerfHostIsEventEnabled(RGX_HWPERF_HOST_EVENT_TYPE eEvent);
134
135 #define _RGX_HWPERF_HOST_FILTER(CTX, EV) \
136                 (((PVRSRV_RGXDEV_INFO *)CTX->psDeviceNode->pvDevice)->ui32HWPerfHostFilter \
137                 & RGX_HWPERF_EVENT_MASK_VALUE(EV))
138
139 /**
140  * This macro checks if HWPerfHost and the event are enabled and if they are
141  * it posts event to the HWPerfHost stream.
142  *
143  * @param C context
144  * @param P process id (PID)
145  * @param X firmware context
146  * @param E ExtJobRef
147  * @param I IntJobRef
148  * @param K kick type
149  */
150 #if defined(PVRSRV_GPUVIRT_GUESTDRV)
151 #define RGX_HWPERF_HOST_CTRL(E, P) \
152                 do { \
153                         PVR_UNREFERENCED_PARAMETER(P); \
154                 } while (0)
155
156 #define RGX_HWPERF_HOST_ENQ(C, P, X, E, I, K) \
157                 do { \
158                         PVR_UNREFERENCED_PARAMETER(X); \
159                         PVR_UNREFERENCED_PARAMETER(E); \
160                         PVR_UNREFERENCED_PARAMETER(I); \
161                 } while (0)
162
163 #define RGX_HWPERF_HOST_UFO(T, D, N) \
164                 do { \
165                         PVR_UNREFERENCED_PARAMETER(T); \
166                         PVR_UNREFERENCED_PARAMETER(D); \
167                         PVR_UNREFERENCED_PARAMETER(N); \
168                 } while (0)
169
170 #define RGX_HWPERF_HOST_ALLOC(T, F, N, Z) \
171                 do { \
172                         PVR_UNREFERENCED_PARAMETER(RGX_HWPERF_HOST_RESOURCE_TYPE_##T); \
173                         PVR_UNREFERENCED_PARAMETER(F); \
174                         PVR_UNREFERENCED_PARAMETER(N); \
175                         PVR_UNREFERENCED_PARAMETER(Z); \
176                 } while (0)
177
178 #define RGX_HWPERF_HOST_FREE(T, F) \
179                 do { \
180                         PVR_UNREFERENCED_PARAMETER(RGX_HWPERF_HOST_RESOURCE_TYPE_##T); \
181                         PVR_UNREFERENCED_PARAMETER(F); \
182                 } while (0)
183
184 #define RGX_HWPERF_HOST_CLK_SYNC()
185 #else
186 /**
187  * @param E event type
188  * @param P PID
189  */
190 #define RGX_HWPERF_HOST_CTRL(E, P) \
191                 do { \
192                         if (RGXHWPerfHostIsEventEnabled(RGX_HWPERF_HOST_CTRL)) \
193                         { \
194                                 RGXHWPerfHostPostCtrlEvent(RGX_HWPERF_CTRL_TYPE_##E, (P)); \
195                         } \
196                 } while (0)
197
198 #define RGX_HWPERF_HOST_ENQ(C, P, X, E, I, K) \
199                 do { \
200                         if (_RGX_HWPERF_HOST_FILTER(C, RGX_HWPERF_HOST_ENQ)) \
201                         { \
202                                 RGXHWPerfHostPostEnqEvent((K), (P), (X), (E), (I)); \
203                         } \
204                 } while (0)
205
206 /**
207  * This macro checks if HWPerfHost and the event are enabled and if they are
208  * it posts event to the HWPerfHost stream.
209  *
210  * @param T Host UFO event type
211  * @param D UFO data array
212  * @param N number of syncs in data array
213  */
214 #define RGX_HWPERF_HOST_UFO(T, D, N) \
215                 do { \
216                         if (RGXHWPerfHostIsEventEnabled(RGX_HWPERF_HOST_UFO)) \
217                         { \
218                                 RGXHWPerfHostPostUfoEvent((T), (D), (N)); \
219                         } \
220                 } while (0)
221
222 /**
223  * This macro checks if HWPerfHost and the event are enabled and if they are
224  * it posts event to the HWPerfHost stream.
225  *
226  * @param F sync firmware address
227  * @param S boolean value telling if this is a server sync
228  * @param N string containing sync name
229  * @param Z string size including null terminating character
230  */
231 #define RGX_HWPERF_HOST_ALLOC(T, F, N, Z) \
232                 do { \
233                         if (RGXHWPerfHostIsEventEnabled(RGX_HWPERF_HOST_ALLOC)) \
234                         { \
235                                 RGXHWPerfHostPostAllocEvent(RGX_HWPERF_HOST_RESOURCE_TYPE_##T, \
236                                                             (F), (N), (Z)); \
237                         } \
238                 } while (0)
239
240 /**
241  * This macro checks if HWPerfHost and the event are enabled and if they are
242  * it posts event to the HWPerfHost stream.
243  *
244  * @param F sync firmware address
245  */
246 #define RGX_HWPERF_HOST_FREE(T, F) \
247                 do { \
248                         if (RGXHWPerfHostIsEventEnabled(RGX_HWPERF_HOST_FREE)) \
249                         { \
250                                 RGXHWPerfHostPostFreeEvent(RGX_HWPERF_HOST_RESOURCE_TYPE_##T, \
251                                                            (F)); \
252                         } \
253                 } while (0)
254
255 /**
256  * This macro checks if HWPerfHost and the event are enabled and if they are
257  * it posts event to the HWPerfHost stream.
258  */
259 #define RGX_HWPERF_HOST_CLK_SYNC() \
260                 do { \
261                         if (RGXHWPerfHostIsEventEnabled(RGX_HWPERF_HOST_CLK_SYNC)) \
262                         { \
263                                 RGXHWPerfHostPostClkSyncEvent(); \
264                         } \
265                 } while (0)
266 #endif
267
268 /******************************************************************************
269  * RGX HW Performance To FTrace Profiling API(s)
270  *****************************************************************************/
271
272 #if defined(SUPPORT_GPUTRACE_EVENTS)
273
274 PVRSRV_ERROR RGXHWPerfFTraceGPUInit(PVRSRV_DEVICE_NODE *psDeviceNode);
275 void RGXHWPerfFTraceGPUDeInit(PVRSRV_DEVICE_NODE *psDeviceNode);
276
277 void RGXHWPerfFTraceGPUEnqueueEvent(PVRSRV_RGXDEV_INFO *psDevInfo,
278                 IMG_UINT32 ui32ExternalJobRef, IMG_UINT32 ui32InternalJobRef,
279                 RGX_HWPERF_KICK_TYPE eKickType);
280
281 PVRSRV_ERROR RGXHWPerfFTraceGPUEventsEnabledSet(IMG_BOOL bNewValue);
282
283 void RGXHWPerfFTraceGPUThread(void *pvData);
284
285 #endif
286
287 /******************************************************************************
288  * RGX HW utils functions
289  *****************************************************************************/
290
291 const IMG_CHAR *RGXHWPerfKickTypeToStr(RGX_HWPERF_KICK_TYPE eKickType);
292
293 #endif /* RGXHWPERF_H_ */