RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / generated / rgxhwperf_bridge / server_rgxhwperf_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for rgxhwperf
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for rgxhwperf
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 #include <stddef.h>
45 #include <asm/uaccess.h>
46
47 #include "img_defs.h"
48
49 #include "rgxhwperf.h"
50
51
52 #include "common_rgxhwperf_bridge.h"
53
54 #include "allocmem.h"
55 #include "pvr_debug.h"
56 #include "connection_server.h"
57 #include "pvr_bridge.h"
58 #include "rgx_bridge.h"
59 #include "srvcore.h"
60 #include "handle.h"
61
62 #if defined (SUPPORT_AUTH)
63 #include "osauth.h"
64 #endif
65
66 #include <linux/slab.h>
67
68
69
70
71 /* ***************************************************************************
72  * Server-side bridge entry points
73  */
74  
75 static IMG_INT
76 PVRSRVBridgeRGXCtrlHWPerf(IMG_UINT32 ui32DispatchTableEntry,
77                                           PVRSRV_BRIDGE_IN_RGXCTRLHWPERF *psRGXCtrlHWPerfIN,
78                                           PVRSRV_BRIDGE_OUT_RGXCTRLHWPERF *psRGXCtrlHWPerfOUT,
79                                          CONNECTION_DATA *psConnection)
80 {
81         IMG_HANDLE hDevNodeInt = IMG_NULL;
82
83
84
85
86
87
88
89                                 {
90                                         /* Look up the address from the handle */
91                                         psRGXCtrlHWPerfOUT->eError =
92                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
93                                                                                         (IMG_VOID **) &hDevNodeInt,
94                                                                                         psRGXCtrlHWPerfIN->hDevNode,
95                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
96                                         if(psRGXCtrlHWPerfOUT->eError != PVRSRV_OK)
97                                         {
98                                                 goto RGXCtrlHWPerf_exit;
99                                         }
100                                 }
101
102
103         psRGXCtrlHWPerfOUT->eError =
104                 PVRSRVRGXCtrlHWPerfKM(
105                                         hDevNodeInt,
106                                         psRGXCtrlHWPerfIN->bToggle,
107                                         psRGXCtrlHWPerfIN->ui64Mask);
108
109
110
111
112 RGXCtrlHWPerf_exit:
113
114         return 0;
115 }
116
117 static IMG_INT
118 PVRSRVBridgeRGXConfigEnableHWPerfCounters(IMG_UINT32 ui32DispatchTableEntry,
119                                           PVRSRV_BRIDGE_IN_RGXCONFIGENABLEHWPERFCOUNTERS *psRGXConfigEnableHWPerfCountersIN,
120                                           PVRSRV_BRIDGE_OUT_RGXCONFIGENABLEHWPERFCOUNTERS *psRGXConfigEnableHWPerfCountersOUT,
121                                          CONNECTION_DATA *psConnection)
122 {
123         IMG_HANDLE hDevNodeInt = IMG_NULL;
124         RGX_HWPERF_CONFIG_CNTBLK *psBlockConfigsInt = IMG_NULL;
125
126
127
128
129         if (psRGXConfigEnableHWPerfCountersIN->ui32ArrayLen != 0)
130         {
131                 psBlockConfigsInt = OSAllocMem(psRGXConfigEnableHWPerfCountersIN->ui32ArrayLen * sizeof(RGX_HWPERF_CONFIG_CNTBLK));
132                 if (!psBlockConfigsInt)
133                 {
134                         psRGXConfigEnableHWPerfCountersOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
135         
136                         goto RGXConfigEnableHWPerfCounters_exit;
137                 }
138         }
139
140                         /* Copy the data over */
141                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXConfigEnableHWPerfCountersIN->psBlockConfigs, psRGXConfigEnableHWPerfCountersIN->ui32ArrayLen * sizeof(RGX_HWPERF_CONFIG_CNTBLK))
142                                 || (OSCopyFromUser(NULL, psBlockConfigsInt, psRGXConfigEnableHWPerfCountersIN->psBlockConfigs,
143                                 psRGXConfigEnableHWPerfCountersIN->ui32ArrayLen * sizeof(RGX_HWPERF_CONFIG_CNTBLK)) != PVRSRV_OK) )
144                         {
145                                 psRGXConfigEnableHWPerfCountersOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
146
147                                 goto RGXConfigEnableHWPerfCounters_exit;
148                         }
149
150
151
152                                 {
153                                         /* Look up the address from the handle */
154                                         psRGXConfigEnableHWPerfCountersOUT->eError =
155                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
156                                                                                         (IMG_VOID **) &hDevNodeInt,
157                                                                                         psRGXConfigEnableHWPerfCountersIN->hDevNode,
158                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
159                                         if(psRGXConfigEnableHWPerfCountersOUT->eError != PVRSRV_OK)
160                                         {
161                                                 goto RGXConfigEnableHWPerfCounters_exit;
162                                         }
163                                 }
164
165
166         psRGXConfigEnableHWPerfCountersOUT->eError =
167                 PVRSRVRGXConfigEnableHWPerfCountersKM(
168                                         hDevNodeInt,
169                                         psRGXConfigEnableHWPerfCountersIN->ui32ArrayLen,
170                                         psBlockConfigsInt);
171
172
173
174
175 RGXConfigEnableHWPerfCounters_exit:
176         if (psBlockConfigsInt)
177                 OSFreeMem(psBlockConfigsInt);
178
179         return 0;
180 }
181
182 static IMG_INT
183 PVRSRVBridgeRGXCtrlHWPerfCounters(IMG_UINT32 ui32DispatchTableEntry,
184                                           PVRSRV_BRIDGE_IN_RGXCTRLHWPERFCOUNTERS *psRGXCtrlHWPerfCountersIN,
185                                           PVRSRV_BRIDGE_OUT_RGXCTRLHWPERFCOUNTERS *psRGXCtrlHWPerfCountersOUT,
186                                          CONNECTION_DATA *psConnection)
187 {
188         IMG_HANDLE hDevNodeInt = IMG_NULL;
189         IMG_UINT16 *ui16BlockIDsInt = IMG_NULL;
190
191
192
193
194         if (psRGXCtrlHWPerfCountersIN->ui32ArrayLen != 0)
195         {
196                 ui16BlockIDsInt = OSAllocMem(psRGXCtrlHWPerfCountersIN->ui32ArrayLen * sizeof(IMG_UINT16));
197                 if (!ui16BlockIDsInt)
198                 {
199                         psRGXCtrlHWPerfCountersOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
200         
201                         goto RGXCtrlHWPerfCounters_exit;
202                 }
203         }
204
205                         /* Copy the data over */
206                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXCtrlHWPerfCountersIN->pui16BlockIDs, psRGXCtrlHWPerfCountersIN->ui32ArrayLen * sizeof(IMG_UINT16))
207                                 || (OSCopyFromUser(NULL, ui16BlockIDsInt, psRGXCtrlHWPerfCountersIN->pui16BlockIDs,
208                                 psRGXCtrlHWPerfCountersIN->ui32ArrayLen * sizeof(IMG_UINT16)) != PVRSRV_OK) )
209                         {
210                                 psRGXCtrlHWPerfCountersOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
211
212                                 goto RGXCtrlHWPerfCounters_exit;
213                         }
214
215
216
217                                 {
218                                         /* Look up the address from the handle */
219                                         psRGXCtrlHWPerfCountersOUT->eError =
220                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
221                                                                                         (IMG_VOID **) &hDevNodeInt,
222                                                                                         psRGXCtrlHWPerfCountersIN->hDevNode,
223                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
224                                         if(psRGXCtrlHWPerfCountersOUT->eError != PVRSRV_OK)
225                                         {
226                                                 goto RGXCtrlHWPerfCounters_exit;
227                                         }
228                                 }
229
230
231         psRGXCtrlHWPerfCountersOUT->eError =
232                 PVRSRVRGXCtrlHWPerfCountersKM(
233                                         hDevNodeInt,
234                                         psRGXCtrlHWPerfCountersIN->bEnable,
235                                         psRGXCtrlHWPerfCountersIN->ui32ArrayLen,
236                                         ui16BlockIDsInt);
237
238
239
240
241 RGXCtrlHWPerfCounters_exit:
242         if (ui16BlockIDsInt)
243                 OSFreeMem(ui16BlockIDsInt);
244
245         return 0;
246 }
247
248 static IMG_INT
249 PVRSRVBridgeRGXConfigCustomCounters(IMG_UINT32 ui32DispatchTableEntry,
250                                           PVRSRV_BRIDGE_IN_RGXCONFIGCUSTOMCOUNTERS *psRGXConfigCustomCountersIN,
251                                           PVRSRV_BRIDGE_OUT_RGXCONFIGCUSTOMCOUNTERS *psRGXConfigCustomCountersOUT,
252                                          CONNECTION_DATA *psConnection)
253 {
254         IMG_HANDLE hDevNodeInt = IMG_NULL;
255         IMG_UINT32 *ui32CustomCounterIDsInt = IMG_NULL;
256
257
258
259
260         if (psRGXConfigCustomCountersIN->ui16NumCustomCounters != 0)
261         {
262                 ui32CustomCounterIDsInt = OSAllocMem(psRGXConfigCustomCountersIN->ui16NumCustomCounters * sizeof(IMG_UINT32));
263                 if (!ui32CustomCounterIDsInt)
264                 {
265                         psRGXConfigCustomCountersOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
266         
267                         goto RGXConfigCustomCounters_exit;
268                 }
269         }
270
271                         /* Copy the data over */
272                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXConfigCustomCountersIN->pui32CustomCounterIDs, psRGXConfigCustomCountersIN->ui16NumCustomCounters * sizeof(IMG_UINT32))
273                                 || (OSCopyFromUser(NULL, ui32CustomCounterIDsInt, psRGXConfigCustomCountersIN->pui32CustomCounterIDs,
274                                 psRGXConfigCustomCountersIN->ui16NumCustomCounters * sizeof(IMG_UINT32)) != PVRSRV_OK) )
275                         {
276                                 psRGXConfigCustomCountersOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
277
278                                 goto RGXConfigCustomCounters_exit;
279                         }
280
281
282
283                                 {
284                                         /* Look up the address from the handle */
285                                         psRGXConfigCustomCountersOUT->eError =
286                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
287                                                                                         (IMG_VOID **) &hDevNodeInt,
288                                                                                         psRGXConfigCustomCountersIN->hDevNode,
289                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
290                                         if(psRGXConfigCustomCountersOUT->eError != PVRSRV_OK)
291                                         {
292                                                 goto RGXConfigCustomCounters_exit;
293                                         }
294                                 }
295
296
297         psRGXConfigCustomCountersOUT->eError =
298                 PVRSRVRGXConfigCustomCountersKM(
299                                         hDevNodeInt,
300                                         psRGXConfigCustomCountersIN->ui16CustomBlockID,
301                                         psRGXConfigCustomCountersIN->ui16NumCustomCounters,
302                                         ui32CustomCounterIDsInt);
303
304
305
306
307 RGXConfigCustomCounters_exit:
308         if (ui32CustomCounterIDsInt)
309                 OSFreeMem(ui32CustomCounterIDsInt);
310
311         return 0;
312 }
313
314
315
316 /* *************************************************************************** 
317  * Server bridge dispatch related glue 
318  */
319
320
321 PVRSRV_ERROR InitRGXHWPERFBridge(IMG_VOID);
322 PVRSRV_ERROR DeinitRGXHWPERFBridge(IMG_VOID);
323
324 /*
325  * Register all RGXHWPERF functions with services
326  */
327 PVRSRV_ERROR InitRGXHWPERFBridge(IMG_VOID)
328 {
329
330         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXHWPERF, PVRSRV_BRIDGE_RGXHWPERF_RGXCTRLHWPERF, PVRSRVBridgeRGXCtrlHWPerf,
331                                         IMG_NULL, IMG_NULL,
332                                         0, 0);
333
334         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXHWPERF, PVRSRV_BRIDGE_RGXHWPERF_RGXCONFIGENABLEHWPERFCOUNTERS, PVRSRVBridgeRGXConfigEnableHWPerfCounters,
335                                         IMG_NULL, IMG_NULL,
336                                         0, 0);
337
338         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXHWPERF, PVRSRV_BRIDGE_RGXHWPERF_RGXCTRLHWPERFCOUNTERS, PVRSRVBridgeRGXCtrlHWPerfCounters,
339                                         IMG_NULL, IMG_NULL,
340                                         0, 0);
341
342         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXHWPERF, PVRSRV_BRIDGE_RGXHWPERF_RGXCONFIGCUSTOMCOUNTERS, PVRSRVBridgeRGXConfigCustomCounters,
343                                         IMG_NULL, IMG_NULL,
344                                         0, 0);
345
346
347         return PVRSRV_OK;
348 }
349
350 /*
351  * Unregister all rgxhwperf functions with services
352  */
353 PVRSRV_ERROR DeinitRGXHWPERFBridge(IMG_VOID)
354 {
355         return PVRSRV_OK;
356 }
357