RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / generated / rgxkicksync_bridge / server_rgxkicksync_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for rgxkicksync
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for rgxkicksync
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 "rgxkicksync.h"
50
51
52 #include "common_rgxkicksync_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
67
68
69 /* ***************************************************************************
70  * Server-side bridge entry points
71  */
72  
73 static IMG_INT
74 PVRSRVBridgeRGXCreateKickSyncContext(IMG_UINT32 ui32DispatchTableEntry,
75                                           PVRSRV_BRIDGE_IN_RGXCREATEKICKSYNCCONTEXT *psRGXCreateKickSyncContextIN,
76                                           PVRSRV_BRIDGE_OUT_RGXCREATEKICKSYNCCONTEXT *psRGXCreateKickSyncContextOUT,
77                                          CONNECTION_DATA *psConnection)
78 {
79         IMG_HANDLE hPrivData = psRGXCreateKickSyncContextIN->hPrivData;
80         IMG_HANDLE hPrivDataInt = NULL;
81         RGX_SERVER_KICKSYNC_CONTEXT * psKickSyncContextInt = 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                                         psRGXCreateKickSyncContextOUT->eError =
99                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
100                                                                                         (void **) &hPrivDataInt,
101                                                                                         hPrivData,
102                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA,
103                                                                                         IMG_TRUE);
104                                         if(psRGXCreateKickSyncContextOUT->eError != PVRSRV_OK)
105                                         {
106                                                 UnlockHandle();
107                                                 goto RGXCreateKickSyncContext_exit;
108                                         }
109                                 }
110         /* Release now we have looked up handles. */
111         UnlockHandle();
112
113         psRGXCreateKickSyncContextOUT->eError =
114                 PVRSRVRGXCreateKickSyncContextKM(psConnection, OSGetDevData(psConnection),
115                                         hPrivDataInt,
116                                         &psKickSyncContextInt);
117         /* Exit early if bridged call fails */
118         if(psRGXCreateKickSyncContextOUT->eError != PVRSRV_OK)
119         {
120                 goto RGXCreateKickSyncContext_exit;
121         }
122
123         /* Lock over handle creation. */
124         LockHandle();
125
126
127
128
129
130         psRGXCreateKickSyncContextOUT->eError = PVRSRVAllocHandleUnlocked(psConnection->psHandleBase,
131
132                                                         &psRGXCreateKickSyncContextOUT->hKickSyncContext,
133                                                         (void *) psKickSyncContextInt,
134                                                         PVRSRV_HANDLE_TYPE_RGX_SERVER_KICKSYNC_CONTEXT,
135                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
136                                                         ,(PFN_HANDLE_RELEASE)&PVRSRVRGXDestroyKickSyncContextKM);
137         if (psRGXCreateKickSyncContextOUT->eError != PVRSRV_OK)
138         {
139                 UnlockHandle();
140                 goto RGXCreateKickSyncContext_exit;
141         }
142
143         /* Release now we have created handles. */
144         UnlockHandle();
145
146
147
148 RGXCreateKickSyncContext_exit:
149
150         /* Lock over handle lookup cleanup. */
151         LockHandle();
152
153
154
155
156
157
158                                 {
159                                         /* Unreference the previously looked up handle */
160                                                 if(hPrivDataInt)
161                                                 {
162                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
163                                                                                         hPrivData,
164                                                                                         PVRSRV_HANDLE_TYPE_DEV_PRIV_DATA);
165                                                 }
166                                 }
167         /* Release now we have cleaned up look up handles. */
168         UnlockHandle();
169
170         if (psRGXCreateKickSyncContextOUT->eError != PVRSRV_OK)
171         {
172                 if (psKickSyncContextInt)
173                 {
174                         PVRSRVRGXDestroyKickSyncContextKM(psKickSyncContextInt);
175                 }
176         }
177
178
179         return 0;
180 }
181
182
183 static IMG_INT
184 PVRSRVBridgeRGXDestroyKickSyncContext(IMG_UINT32 ui32DispatchTableEntry,
185                                           PVRSRV_BRIDGE_IN_RGXDESTROYKICKSYNCCONTEXT *psRGXDestroyKickSyncContextIN,
186                                           PVRSRV_BRIDGE_OUT_RGXDESTROYKICKSYNCCONTEXT *psRGXDestroyKickSyncContextOUT,
187                                          CONNECTION_DATA *psConnection)
188 {
189
190
191
192
193
194
195
196
197
198         /* Lock over handle destruction. */
199         LockHandle();
200
201
202
203
204
205         psRGXDestroyKickSyncContextOUT->eError =
206                 PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
207                                         (IMG_HANDLE) psRGXDestroyKickSyncContextIN->hKickSyncContext,
208                                         PVRSRV_HANDLE_TYPE_RGX_SERVER_KICKSYNC_CONTEXT);
209         if ((psRGXDestroyKickSyncContextOUT->eError != PVRSRV_OK) &&
210             (psRGXDestroyKickSyncContextOUT->eError != PVRSRV_ERROR_RETRY))
211         {
212                 PVR_DPF((PVR_DBG_ERROR,
213                         "PVRSRVBridgeRGXDestroyKickSyncContext: %s",
214                         PVRSRVGetErrorStringKM(psRGXDestroyKickSyncContextOUT->eError)));
215                 PVR_ASSERT(0);
216                 UnlockHandle();
217                 goto RGXDestroyKickSyncContext_exit;
218         }
219
220         /* Release now we have destroyed handles. */
221         UnlockHandle();
222
223
224
225 RGXDestroyKickSyncContext_exit:
226
227
228
229
230         return 0;
231 }
232
233
234 static IMG_INT
235 PVRSRVBridgeRGXKickSync(IMG_UINT32 ui32DispatchTableEntry,
236                                           PVRSRV_BRIDGE_IN_RGXKICKSYNC *psRGXKickSyncIN,
237                                           PVRSRV_BRIDGE_OUT_RGXKICKSYNC *psRGXKickSyncOUT,
238                                          CONNECTION_DATA *psConnection)
239 {
240         IMG_HANDLE hKickSyncContext = psRGXKickSyncIN->hKickSyncContext;
241         RGX_SERVER_KICKSYNC_CONTEXT * psKickSyncContextInt = NULL;
242         SYNC_PRIMITIVE_BLOCK * *psFenceUFOSyncPrimBlockInt = NULL;
243         IMG_HANDLE *hFenceUFOSyncPrimBlockInt2 = NULL;
244         IMG_UINT32 *ui32FenceSyncOffsetInt = NULL;
245         IMG_UINT32 *ui32FenceValueInt = NULL;
246         SYNC_PRIMITIVE_BLOCK * *psUpdateUFOSyncPrimBlockInt = NULL;
247         IMG_HANDLE *hUpdateUFOSyncPrimBlockInt2 = NULL;
248         IMG_UINT32 *ui32UpdateSyncOffsetInt = NULL;
249         IMG_UINT32 *ui32UpdateValueInt = NULL;
250         IMG_UINT32 *ui32ServerSyncFlagsInt = NULL;
251         SERVER_SYNC_PRIMITIVE * *psServerSyncInt = NULL;
252         IMG_HANDLE *hServerSyncInt2 = NULL;
253         IMG_CHAR *uiUpdateFenceNameInt = NULL;
254
255         IMG_UINT32 ui32NextOffset = 0;
256         IMG_BYTE   *pArrayArgsBuffer = NULL;
257 #if !defined(INTEGRITY_OS)
258         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
259 #endif
260
261         IMG_UINT32 ui32BufferSize = 
262                         (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(SYNC_PRIMITIVE_BLOCK *)) +
263                         (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_HANDLE)) +
264                         (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32)) +
265                         (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32)) +
266                         (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(SYNC_PRIMITIVE_BLOCK *)) +
267                         (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_HANDLE)) +
268                         (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32)) +
269                         (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32)) +
270                         (psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_UINT32)) +
271                         (psRGXKickSyncIN->ui32ServerSyncCount * sizeof(SERVER_SYNC_PRIMITIVE *)) +
272                         (psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_HANDLE)) +
273                         (32 * sizeof(IMG_CHAR)) +
274                         0;
275
276
277
278
279
280         if (ui32BufferSize != 0)
281         {
282 #if !defined(INTEGRITY_OS)
283                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
284                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psRGXKickSyncIN), sizeof(unsigned long));
285                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
286                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
287
288                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
289                 if (bHaveEnoughSpace)
290                 {
291                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psRGXKickSyncIN;
292
293                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
294                 else
295 #endif
296                 {
297                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
298
299                         if(!pArrayArgsBuffer)
300                         {
301                                 psRGXKickSyncOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
302                                 goto RGXKickSync_exit;
303                         }
304                 }
305         }
306
307         if (psRGXKickSyncIN->ui32ClientFenceCount != 0)
308         {
309                 psFenceUFOSyncPrimBlockInt = (SYNC_PRIMITIVE_BLOCK **)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
310                 ui32NextOffset += psRGXKickSyncIN->ui32ClientFenceCount * sizeof(SYNC_PRIMITIVE_BLOCK *);
311                 hFenceUFOSyncPrimBlockInt2 = (IMG_HANDLE *)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset); 
312                 ui32NextOffset += psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_HANDLE);
313         }
314
315                         /* Copy the data over */
316                         if (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_HANDLE) > 0)
317                         {
318                                 if ( OSCopyFromUser(NULL, hFenceUFOSyncPrimBlockInt2, psRGXKickSyncIN->phFenceUFOSyncPrimBlock, psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_HANDLE)) != PVRSRV_OK )
319                                 {
320                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
321
322                                         goto RGXKickSync_exit;
323                                 }
324                         }
325         if (psRGXKickSyncIN->ui32ClientFenceCount != 0)
326         {
327                 ui32FenceSyncOffsetInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
328                 ui32NextOffset += psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32);
329         }
330
331                         /* Copy the data over */
332                         if (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32) > 0)
333                         {
334                                 if ( OSCopyFromUser(NULL, ui32FenceSyncOffsetInt, psRGXKickSyncIN->pui32FenceSyncOffset, psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
335                                 {
336                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
337
338                                         goto RGXKickSync_exit;
339                                 }
340                         }
341         if (psRGXKickSyncIN->ui32ClientFenceCount != 0)
342         {
343                 ui32FenceValueInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
344                 ui32NextOffset += psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32);
345         }
346
347                         /* Copy the data over */
348                         if (psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32) > 0)
349                         {
350                                 if ( OSCopyFromUser(NULL, ui32FenceValueInt, psRGXKickSyncIN->pui32FenceValue, psRGXKickSyncIN->ui32ClientFenceCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
351                                 {
352                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
353
354                                         goto RGXKickSync_exit;
355                                 }
356                         }
357         if (psRGXKickSyncIN->ui32ClientUpdateCount != 0)
358         {
359                 psUpdateUFOSyncPrimBlockInt = (SYNC_PRIMITIVE_BLOCK **)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
360                 ui32NextOffset += psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(SYNC_PRIMITIVE_BLOCK *);
361                 hUpdateUFOSyncPrimBlockInt2 = (IMG_HANDLE *)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset); 
362                 ui32NextOffset += psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_HANDLE);
363         }
364
365                         /* Copy the data over */
366                         if (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_HANDLE) > 0)
367                         {
368                                 if ( OSCopyFromUser(NULL, hUpdateUFOSyncPrimBlockInt2, psRGXKickSyncIN->phUpdateUFOSyncPrimBlock, psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_HANDLE)) != PVRSRV_OK )
369                                 {
370                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
371
372                                         goto RGXKickSync_exit;
373                                 }
374                         }
375         if (psRGXKickSyncIN->ui32ClientUpdateCount != 0)
376         {
377                 ui32UpdateSyncOffsetInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
378                 ui32NextOffset += psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32);
379         }
380
381                         /* Copy the data over */
382                         if (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32) > 0)
383                         {
384                                 if ( OSCopyFromUser(NULL, ui32UpdateSyncOffsetInt, psRGXKickSyncIN->pui32UpdateSyncOffset, psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
385                                 {
386                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
387
388                                         goto RGXKickSync_exit;
389                                 }
390                         }
391         if (psRGXKickSyncIN->ui32ClientUpdateCount != 0)
392         {
393                 ui32UpdateValueInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
394                 ui32NextOffset += psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32);
395         }
396
397                         /* Copy the data over */
398                         if (psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32) > 0)
399                         {
400                                 if ( OSCopyFromUser(NULL, ui32UpdateValueInt, psRGXKickSyncIN->pui32UpdateValue, psRGXKickSyncIN->ui32ClientUpdateCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
401                                 {
402                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
403
404                                         goto RGXKickSync_exit;
405                                 }
406                         }
407         if (psRGXKickSyncIN->ui32ServerSyncCount != 0)
408         {
409                 ui32ServerSyncFlagsInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
410                 ui32NextOffset += psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_UINT32);
411         }
412
413                         /* Copy the data over */
414                         if (psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_UINT32) > 0)
415                         {
416                                 if ( OSCopyFromUser(NULL, ui32ServerSyncFlagsInt, psRGXKickSyncIN->pui32ServerSyncFlags, psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
417                                 {
418                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
419
420                                         goto RGXKickSync_exit;
421                                 }
422                         }
423         if (psRGXKickSyncIN->ui32ServerSyncCount != 0)
424         {
425                 psServerSyncInt = (SERVER_SYNC_PRIMITIVE **)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
426                 ui32NextOffset += psRGXKickSyncIN->ui32ServerSyncCount * sizeof(SERVER_SYNC_PRIMITIVE *);
427                 hServerSyncInt2 = (IMG_HANDLE *)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset); 
428                 ui32NextOffset += psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_HANDLE);
429         }
430
431                         /* Copy the data over */
432                         if (psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_HANDLE) > 0)
433                         {
434                                 if ( OSCopyFromUser(NULL, hServerSyncInt2, psRGXKickSyncIN->phServerSync, psRGXKickSyncIN->ui32ServerSyncCount * sizeof(IMG_HANDLE)) != PVRSRV_OK )
435                                 {
436                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
437
438                                         goto RGXKickSync_exit;
439                                 }
440                         }
441         
442         {
443                 uiUpdateFenceNameInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
444                 ui32NextOffset += 32 * sizeof(IMG_CHAR);
445         }
446
447                         /* Copy the data over */
448                         if (32 * sizeof(IMG_CHAR) > 0)
449                         {
450                                 if ( OSCopyFromUser(NULL, uiUpdateFenceNameInt, psRGXKickSyncIN->puiUpdateFenceName, 32 * sizeof(IMG_CHAR)) != PVRSRV_OK )
451                                 {
452                                         psRGXKickSyncOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
453
454                                         goto RGXKickSync_exit;
455                                 }
456                         }
457
458         /* Lock over handle lookup. */
459         LockHandle();
460
461
462
463
464
465                                 {
466                                         /* Look up the address from the handle */
467                                         psRGXKickSyncOUT->eError =
468                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
469                                                                                         (void **) &psKickSyncContextInt,
470                                                                                         hKickSyncContext,
471                                                                                         PVRSRV_HANDLE_TYPE_RGX_SERVER_KICKSYNC_CONTEXT,
472                                                                                         IMG_TRUE);
473                                         if(psRGXKickSyncOUT->eError != PVRSRV_OK)
474                                         {
475                                                 UnlockHandle();
476                                                 goto RGXKickSync_exit;
477                                         }
478                                 }
479
480
481
482
483
484         {
485                 IMG_UINT32 i;
486
487                 for (i=0;i<psRGXKickSyncIN->ui32ClientFenceCount;i++)
488                 {
489                                 {
490                                         /* Look up the address from the handle */
491                                         psRGXKickSyncOUT->eError =
492                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
493                                                                                         (void **) &psFenceUFOSyncPrimBlockInt[i],
494                                                                                         hFenceUFOSyncPrimBlockInt2[i],
495                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK,
496                                                                                         IMG_TRUE);
497                                         if(psRGXKickSyncOUT->eError != PVRSRV_OK)
498                                         {
499                                                 UnlockHandle();
500                                                 goto RGXKickSync_exit;
501                                         }
502                                 }
503                 }
504         }
505
506
507
508
509
510         {
511                 IMG_UINT32 i;
512
513                 for (i=0;i<psRGXKickSyncIN->ui32ClientUpdateCount;i++)
514                 {
515                                 {
516                                         /* Look up the address from the handle */
517                                         psRGXKickSyncOUT->eError =
518                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
519                                                                                         (void **) &psUpdateUFOSyncPrimBlockInt[i],
520                                                                                         hUpdateUFOSyncPrimBlockInt2[i],
521                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK,
522                                                                                         IMG_TRUE);
523                                         if(psRGXKickSyncOUT->eError != PVRSRV_OK)
524                                         {
525                                                 UnlockHandle();
526                                                 goto RGXKickSync_exit;
527                                         }
528                                 }
529                 }
530         }
531
532
533
534
535
536         {
537                 IMG_UINT32 i;
538
539                 for (i=0;i<psRGXKickSyncIN->ui32ServerSyncCount;i++)
540                 {
541                                 {
542                                         /* Look up the address from the handle */
543                                         psRGXKickSyncOUT->eError =
544                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
545                                                                                         (void **) &psServerSyncInt[i],
546                                                                                         hServerSyncInt2[i],
547                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE,
548                                                                                         IMG_TRUE);
549                                         if(psRGXKickSyncOUT->eError != PVRSRV_OK)
550                                         {
551                                                 UnlockHandle();
552                                                 goto RGXKickSync_exit;
553                                         }
554                                 }
555                 }
556         }
557         /* Release now we have looked up handles. */
558         UnlockHandle();
559
560         psRGXKickSyncOUT->eError =
561                 PVRSRVRGXKickSyncKM(
562                                         psKickSyncContextInt,
563                                         psRGXKickSyncIN->ui32ClientCacheOpSeqNum,
564                                         psRGXKickSyncIN->ui32ClientFenceCount,
565                                         psFenceUFOSyncPrimBlockInt,
566                                         ui32FenceSyncOffsetInt,
567                                         ui32FenceValueInt,
568                                         psRGXKickSyncIN->ui32ClientUpdateCount,
569                                         psUpdateUFOSyncPrimBlockInt,
570                                         ui32UpdateSyncOffsetInt,
571                                         ui32UpdateValueInt,
572                                         psRGXKickSyncIN->ui32ServerSyncCount,
573                                         ui32ServerSyncFlagsInt,
574                                         psServerSyncInt,
575                                         psRGXKickSyncIN->i32CheckFenceFD,
576                                         psRGXKickSyncIN->i32TimelineFenceFD,
577                                         &psRGXKickSyncOUT->i32UpdateFenceFD,
578                                         uiUpdateFenceNameInt,
579                                         psRGXKickSyncIN->ui32ExtJobRef);
580
581
582
583
584 RGXKickSync_exit:
585
586         /* Lock over handle lookup cleanup. */
587         LockHandle();
588
589
590
591
592
593
594                                 {
595                                         /* Unreference the previously looked up handle */
596                                                 if(psKickSyncContextInt)
597                                                 {
598                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
599                                                                                         hKickSyncContext,
600                                                                                         PVRSRV_HANDLE_TYPE_RGX_SERVER_KICKSYNC_CONTEXT);
601                                                 }
602                                 }
603
604
605
606
607
608         {
609                 IMG_UINT32 i;
610
611                 for (i=0;i<psRGXKickSyncIN->ui32ClientFenceCount;i++)
612                 {
613                                 {
614                                         /* Unreference the previously looked up handle */
615                                                 if(psFenceUFOSyncPrimBlockInt[i])
616                                                 {
617                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
618                                                                                         hFenceUFOSyncPrimBlockInt2[i],
619                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
620                                                 }
621                                 }
622                 }
623         }
624
625
626
627
628
629         {
630                 IMG_UINT32 i;
631
632                 for (i=0;i<psRGXKickSyncIN->ui32ClientUpdateCount;i++)
633                 {
634                                 {
635                                         /* Unreference the previously looked up handle */
636                                                 if(psUpdateUFOSyncPrimBlockInt[i])
637                                                 {
638                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
639                                                                                         hUpdateUFOSyncPrimBlockInt2[i],
640                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
641                                                 }
642                                 }
643                 }
644         }
645
646
647
648
649
650         {
651                 IMG_UINT32 i;
652
653                 for (i=0;i<psRGXKickSyncIN->ui32ServerSyncCount;i++)
654                 {
655                                 {
656                                         /* Unreference the previously looked up handle */
657                                                 if(psServerSyncInt[i])
658                                                 {
659                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
660                                                                                         hServerSyncInt2[i],
661                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
662                                                 }
663                                 }
664                 }
665         }
666         /* Release now we have cleaned up look up handles. */
667         UnlockHandle();
668
669         /* Allocated space should be equal to the last updated offset */
670         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
671
672 #if defined(INTEGRITY_OS)
673         if(pArrayArgsBuffer)
674 #else
675         if(!bHaveEnoughSpace && pArrayArgsBuffer)
676 #endif
677                 OSFreeMemNoStats(pArrayArgsBuffer);
678
679
680         return 0;
681 }
682
683
684
685
686 /* *************************************************************************** 
687  * Server bridge dispatch related glue 
688  */
689
690 static IMG_BOOL bUseLock = IMG_TRUE;
691
692 PVRSRV_ERROR InitRGXKICKSYNCBridge(void);
693 PVRSRV_ERROR DeinitRGXKICKSYNCBridge(void);
694
695 /*
696  * Register all RGXKICKSYNC functions with services
697  */
698 PVRSRV_ERROR InitRGXKICKSYNCBridge(void)
699 {
700
701         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXKICKSYNC, PVRSRV_BRIDGE_RGXKICKSYNC_RGXCREATEKICKSYNCCONTEXT, PVRSRVBridgeRGXCreateKickSyncContext,
702                                         NULL, bUseLock);
703
704         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXKICKSYNC, PVRSRV_BRIDGE_RGXKICKSYNC_RGXDESTROYKICKSYNCCONTEXT, PVRSRVBridgeRGXDestroyKickSyncContext,
705                                         NULL, bUseLock);
706
707         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXKICKSYNC, PVRSRV_BRIDGE_RGXKICKSYNC_RGXKICKSYNC, PVRSRVBridgeRGXKickSync,
708                                         NULL, bUseLock);
709
710
711         return PVRSRV_OK;
712 }
713
714 /*
715  * Unregister all rgxkicksync functions with services
716  */
717 PVRSRV_ERROR DeinitRGXKICKSYNCBridge(void)
718 {
719         return PVRSRV_OK;
720 }