RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / generated / breakpoint_bridge / server_breakpoint_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for breakpoint
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for breakpoint
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 "rgxbreakpoint.h"
50
51
52 #include "common_breakpoint_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 #include <linux/slab.h>
63
64
65
66 #if !defined(EXCLUDE_BREAKPOINT_BRIDGE)
67
68
69
70 /* ***************************************************************************
71  * Server-side bridge entry points
72  */
73  
74 static IMG_INT
75 PVRSRVBridgeRGXSetBreakpoint(IMG_UINT32 ui32DispatchTableEntry,
76                                           PVRSRV_BRIDGE_IN_RGXSETBREAKPOINT *psRGXSetBreakpointIN,
77                                           PVRSRV_BRIDGE_OUT_RGXSETBREAKPOINT *psRGXSetBreakpointOUT,
78                                          CONNECTION_DATA *psConnection)
79 {
80         IMG_HANDLE hPrivData = psRGXSetBreakpointIN->hPrivData;
81         IMG_HANDLE hPrivDataInt = NULL;
82
83
84
85
86
87
88
89         /* Lock over handle lookup. */
90         LockHandle();
91
92
93
94
95
96                                 {
97                                         /* Look up the address from the handle */
98                                         psRGXSetBreakpointOUT->eError =
99                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
100                                                                                         (void **) &hPrivDataInt,
101                                                                                         hPrivData,
102                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA,
103                                                                                         IMG_TRUE);
104                                         if(psRGXSetBreakpointOUT->eError != PVRSRV_OK)
105                                         {
106                                                 UnlockHandle();
107                                                 goto RGXSetBreakpoint_exit;
108                                         }
109                                 }
110         /* Release now we have looked up handles. */
111         UnlockHandle();
112
113         psRGXSetBreakpointOUT->eError =
114                 PVRSRVRGXSetBreakpointKM(psConnection, OSGetDevData(psConnection),
115                                         hPrivDataInt,
116                                         psRGXSetBreakpointIN->eFWDataMaster,
117                                         psRGXSetBreakpointIN->ui32BreakpointAddr,
118                                         psRGXSetBreakpointIN->ui32HandlerAddr,
119                                         psRGXSetBreakpointIN->ui32DM);
120
121
122
123
124 RGXSetBreakpoint_exit:
125
126         /* Lock over handle lookup cleanup. */
127         LockHandle();
128
129
130
131
132
133
134                                 {
135                                         /* Unreference the previously looked up handle */
136                                                 if(hPrivDataInt)
137                                                 {
138                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
139                                                                                         hPrivData,
140                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA);
141                                                 }
142                                 }
143         /* Release now we have cleaned up look up handles. */
144         UnlockHandle();
145
146
147         return 0;
148 }
149
150
151 static IMG_INT
152 PVRSRVBridgeRGXClearBreakpoint(IMG_UINT32 ui32DispatchTableEntry,
153                                           PVRSRV_BRIDGE_IN_RGXCLEARBREAKPOINT *psRGXClearBreakpointIN,
154                                           PVRSRV_BRIDGE_OUT_RGXCLEARBREAKPOINT *psRGXClearBreakpointOUT,
155                                          CONNECTION_DATA *psConnection)
156 {
157         IMG_HANDLE hPrivData = psRGXClearBreakpointIN->hPrivData;
158         IMG_HANDLE hPrivDataInt = NULL;
159
160
161
162
163
164
165
166         /* Lock over handle lookup. */
167         LockHandle();
168
169
170
171
172
173                                 {
174                                         /* Look up the address from the handle */
175                                         psRGXClearBreakpointOUT->eError =
176                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
177                                                                                         (void **) &hPrivDataInt,
178                                                                                         hPrivData,
179                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA,
180                                                                                         IMG_TRUE);
181                                         if(psRGXClearBreakpointOUT->eError != PVRSRV_OK)
182                                         {
183                                                 UnlockHandle();
184                                                 goto RGXClearBreakpoint_exit;
185                                         }
186                                 }
187         /* Release now we have looked up handles. */
188         UnlockHandle();
189
190         psRGXClearBreakpointOUT->eError =
191                 PVRSRVRGXClearBreakpointKM(psConnection, OSGetDevData(psConnection),
192                                         hPrivDataInt);
193
194
195
196
197 RGXClearBreakpoint_exit:
198
199         /* Lock over handle lookup cleanup. */
200         LockHandle();
201
202
203
204
205
206
207                                 {
208                                         /* Unreference the previously looked up handle */
209                                                 if(hPrivDataInt)
210                                                 {
211                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
212                                                                                         hPrivData,
213                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA);
214                                                 }
215                                 }
216         /* Release now we have cleaned up look up handles. */
217         UnlockHandle();
218
219
220         return 0;
221 }
222
223
224 static IMG_INT
225 PVRSRVBridgeRGXEnableBreakpoint(IMG_UINT32 ui32DispatchTableEntry,
226                                           PVRSRV_BRIDGE_IN_RGXENABLEBREAKPOINT *psRGXEnableBreakpointIN,
227                                           PVRSRV_BRIDGE_OUT_RGXENABLEBREAKPOINT *psRGXEnableBreakpointOUT,
228                                          CONNECTION_DATA *psConnection)
229 {
230         IMG_HANDLE hPrivData = psRGXEnableBreakpointIN->hPrivData;
231         IMG_HANDLE hPrivDataInt = NULL;
232
233
234
235
236
237
238
239         /* Lock over handle lookup. */
240         LockHandle();
241
242
243
244
245
246                                 {
247                                         /* Look up the address from the handle */
248                                         psRGXEnableBreakpointOUT->eError =
249                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
250                                                                                         (void **) &hPrivDataInt,
251                                                                                         hPrivData,
252                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA,
253                                                                                         IMG_TRUE);
254                                         if(psRGXEnableBreakpointOUT->eError != PVRSRV_OK)
255                                         {
256                                                 UnlockHandle();
257                                                 goto RGXEnableBreakpoint_exit;
258                                         }
259                                 }
260         /* Release now we have looked up handles. */
261         UnlockHandle();
262
263         psRGXEnableBreakpointOUT->eError =
264                 PVRSRVRGXEnableBreakpointKM(psConnection, OSGetDevData(psConnection),
265                                         hPrivDataInt);
266
267
268
269
270 RGXEnableBreakpoint_exit:
271
272         /* Lock over handle lookup cleanup. */
273         LockHandle();
274
275
276
277
278
279
280                                 {
281                                         /* Unreference the previously looked up handle */
282                                                 if(hPrivDataInt)
283                                                 {
284                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
285                                                                                         hPrivData,
286                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA);
287                                                 }
288                                 }
289         /* Release now we have cleaned up look up handles. */
290         UnlockHandle();
291
292
293         return 0;
294 }
295
296
297 static IMG_INT
298 PVRSRVBridgeRGXDisableBreakpoint(IMG_UINT32 ui32DispatchTableEntry,
299                                           PVRSRV_BRIDGE_IN_RGXDISABLEBREAKPOINT *psRGXDisableBreakpointIN,
300                                           PVRSRV_BRIDGE_OUT_RGXDISABLEBREAKPOINT *psRGXDisableBreakpointOUT,
301                                          CONNECTION_DATA *psConnection)
302 {
303         IMG_HANDLE hPrivData = psRGXDisableBreakpointIN->hPrivData;
304         IMG_HANDLE hPrivDataInt = NULL;
305
306
307
308
309
310
311
312         /* Lock over handle lookup. */
313         LockHandle();
314
315
316
317
318
319                                 {
320                                         /* Look up the address from the handle */
321                                         psRGXDisableBreakpointOUT->eError =
322                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
323                                                                                         (void **) &hPrivDataInt,
324                                                                                         hPrivData,
325                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA,
326                                                                                         IMG_TRUE);
327                                         if(psRGXDisableBreakpointOUT->eError != PVRSRV_OK)
328                                         {
329                                                 UnlockHandle();
330                                                 goto RGXDisableBreakpoint_exit;
331                                         }
332                                 }
333         /* Release now we have looked up handles. */
334         UnlockHandle();
335
336         psRGXDisableBreakpointOUT->eError =
337                 PVRSRVRGXDisableBreakpointKM(psConnection, OSGetDevData(psConnection),
338                                         hPrivDataInt);
339
340
341
342
343 RGXDisableBreakpoint_exit:
344
345         /* Lock over handle lookup cleanup. */
346         LockHandle();
347
348
349
350
351
352
353                                 {
354                                         /* Unreference the previously looked up handle */
355                                                 if(hPrivDataInt)
356                                                 {
357                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
358                                                                                         hPrivData,
359                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA);
360                                                 }
361                                 }
362         /* Release now we have cleaned up look up handles. */
363         UnlockHandle();
364
365
366         return 0;
367 }
368
369
370 static IMG_INT
371 PVRSRVBridgeRGXOverallocateBPRegisters(IMG_UINT32 ui32DispatchTableEntry,
372                                           PVRSRV_BRIDGE_IN_RGXOVERALLOCATEBPREGISTERS *psRGXOverallocateBPRegistersIN,
373                                           PVRSRV_BRIDGE_OUT_RGXOVERALLOCATEBPREGISTERS *psRGXOverallocateBPRegistersOUT,
374                                          CONNECTION_DATA *psConnection)
375 {
376
377
378
379
380
381
382
383
384         psRGXOverallocateBPRegistersOUT->eError =
385                 PVRSRVRGXOverallocateBPRegistersKM(psConnection, OSGetDevData(psConnection),
386                                         psRGXOverallocateBPRegistersIN->ui32TempRegs,
387                                         psRGXOverallocateBPRegistersIN->ui32SharedRegs);
388
389
390
391
392
393
394
395
396         return 0;
397 }
398
399
400
401
402 /* *************************************************************************** 
403  * Server bridge dispatch related glue 
404  */
405
406 static IMG_BOOL bUseLock = IMG_TRUE;
407 #endif /* EXCLUDE_BREAKPOINT_BRIDGE */
408
409 #if !defined(EXCLUDE_BREAKPOINT_BRIDGE)
410 PVRSRV_ERROR InitBREAKPOINTBridge(void);
411 PVRSRV_ERROR DeinitBREAKPOINTBridge(void);
412
413 /*
414  * Register all BREAKPOINT functions with services
415  */
416 PVRSRV_ERROR InitBREAKPOINTBridge(void)
417 {
418
419         SetDispatchTableEntry(PVRSRV_BRIDGE_BREAKPOINT, PVRSRV_BRIDGE_BREAKPOINT_RGXSETBREAKPOINT, PVRSRVBridgeRGXSetBreakpoint,
420                                         NULL, bUseLock);
421
422         SetDispatchTableEntry(PVRSRV_BRIDGE_BREAKPOINT, PVRSRV_BRIDGE_BREAKPOINT_RGXCLEARBREAKPOINT, PVRSRVBridgeRGXClearBreakpoint,
423                                         NULL, bUseLock);
424
425         SetDispatchTableEntry(PVRSRV_BRIDGE_BREAKPOINT, PVRSRV_BRIDGE_BREAKPOINT_RGXENABLEBREAKPOINT, PVRSRVBridgeRGXEnableBreakpoint,
426                                         NULL, bUseLock);
427
428         SetDispatchTableEntry(PVRSRV_BRIDGE_BREAKPOINT, PVRSRV_BRIDGE_BREAKPOINT_RGXDISABLEBREAKPOINT, PVRSRVBridgeRGXDisableBreakpoint,
429                                         NULL, bUseLock);
430
431         SetDispatchTableEntry(PVRSRV_BRIDGE_BREAKPOINT, PVRSRV_BRIDGE_BREAKPOINT_RGXOVERALLOCATEBPREGISTERS, PVRSRVBridgeRGXOverallocateBPRegisters,
432                                         NULL, bUseLock);
433
434
435         return PVRSRV_OK;
436 }
437
438 /*
439  * Unregister all breakpoint functions with services
440  */
441 PVRSRV_ERROR DeinitBREAKPOINTBridge(void)
442 {
443         return PVRSRV_OK;
444 }
445 #else /* EXCLUDE_BREAKPOINT_BRIDGE */
446 /* This bridge is conditional on EXCLUDE_BREAKPOINT_BRIDGE - when defined,
447  * do not populate the dispatch table with its functions
448  */
449 #define InitBREAKPOINTBridge() \
450         PVRSRV_OK
451
452 #define DeinitBREAKPOINTBridge() \
453         PVRSRV_OK
454
455 #endif /* EXCLUDE_BREAKPOINT_BRIDGE */