RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / generated / sync_bridge / server_sync_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for sync
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for sync
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 "sync_server.h"
50 #include "pdump.h"
51
52
53 #include "common_sync_bridge.h"
54
55 #include "allocmem.h"
56 #include "pvr_debug.h"
57 #include "connection_server.h"
58 #include "pvr_bridge.h"
59 #include "rgx_bridge.h"
60 #include "srvcore.h"
61 #include "handle.h"
62
63 #if defined (SUPPORT_AUTH)
64 #include "osauth.h"
65 #endif
66
67 #include <linux/slab.h>
68
69
70
71
72 /* ***************************************************************************
73  * Server-side bridge entry points
74  */
75  
76 static IMG_INT
77 PVRSRVBridgeAllocSyncPrimitiveBlock(IMG_UINT32 ui32DispatchTableEntry,
78                                           PVRSRV_BRIDGE_IN_ALLOCSYNCPRIMITIVEBLOCK *psAllocSyncPrimitiveBlockIN,
79                                           PVRSRV_BRIDGE_OUT_ALLOCSYNCPRIMITIVEBLOCK *psAllocSyncPrimitiveBlockOUT,
80                                          CONNECTION_DATA *psConnection)
81 {
82         IMG_HANDLE hDevNodeInt = IMG_NULL;
83         SYNC_PRIMITIVE_BLOCK * psSyncHandleInt = IMG_NULL;
84         DEVMEM_EXPORTCOOKIE * psExportCookieInt = IMG_NULL;
85
86
87
88         psAllocSyncPrimitiveBlockOUT->hSyncHandle = IMG_NULL;
89
90
91
92
93                                 {
94                                         /* Look up the address from the handle */
95                                         psAllocSyncPrimitiveBlockOUT->eError =
96                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
97                                                                                         (IMG_VOID **) &hDevNodeInt,
98                                                                                         psAllocSyncPrimitiveBlockIN->hDevNode,
99                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
100                                         if(psAllocSyncPrimitiveBlockOUT->eError != PVRSRV_OK)
101                                         {
102                                                 goto AllocSyncPrimitiveBlock_exit;
103                                         }
104                                 }
105
106
107         psAllocSyncPrimitiveBlockOUT->eError =
108                 PVRSRVAllocSyncPrimitiveBlockKM(psConnection,
109                                         hDevNodeInt,
110                                         &psSyncHandleInt,
111                                         &psAllocSyncPrimitiveBlockOUT->ui32SyncPrimVAddr,
112                                         &psAllocSyncPrimitiveBlockOUT->ui32SyncPrimBlockSize,
113                                         &psExportCookieInt);
114         /* Exit early if bridged call fails */
115         if(psAllocSyncPrimitiveBlockOUT->eError != PVRSRV_OK)
116         {
117                 goto AllocSyncPrimitiveBlock_exit;
118         }
119
120
121         psAllocSyncPrimitiveBlockOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
122                                                         &psAllocSyncPrimitiveBlockOUT->hSyncHandle,
123                                                         (IMG_VOID *) psSyncHandleInt,
124                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK,
125                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
126                                                         ,(PFN_HANDLE_RELEASE)&PVRSRVFreeSyncPrimitiveBlockKM);
127         if (psAllocSyncPrimitiveBlockOUT->eError != PVRSRV_OK)
128         {
129                 goto AllocSyncPrimitiveBlock_exit;
130         }
131
132
133         psAllocSyncPrimitiveBlockOUT->eError = PVRSRVAllocSubHandle(psConnection->psHandleBase,
134                                                         &psAllocSyncPrimitiveBlockOUT->hExportCookie,
135                                                         (IMG_VOID *) psExportCookieInt,
136                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE,
137                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
138                                                         ,psAllocSyncPrimitiveBlockOUT->hSyncHandle);
139         if (psAllocSyncPrimitiveBlockOUT->eError != PVRSRV_OK)
140         {
141                 goto AllocSyncPrimitiveBlock_exit;
142         }
143
144
145
146
147 AllocSyncPrimitiveBlock_exit:
148         if (psAllocSyncPrimitiveBlockOUT->eError != PVRSRV_OK)
149         {
150                 if (psAllocSyncPrimitiveBlockOUT->hSyncHandle)
151                 {
152                         PVRSRV_ERROR eError = PVRSRVReleaseHandle(psConnection->psHandleBase,
153                                                 (IMG_HANDLE) psAllocSyncPrimitiveBlockOUT->hSyncHandle,
154                                                 PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
155
156                         /* Releasing the handle should free/destroy/release the resource. This should never fail... */
157                         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
158
159                         /* Avoid freeing/destroying/releasing the resource a second time below */
160                         psSyncHandleInt = IMG_NULL;
161                 }
162
163
164                 if (psSyncHandleInt)
165                 {
166                         PVRSRVFreeSyncPrimitiveBlockKM(psSyncHandleInt);
167                 }
168         }
169
170
171         return 0;
172 }
173
174 static IMG_INT
175 PVRSRVBridgeFreeSyncPrimitiveBlock(IMG_UINT32 ui32DispatchTableEntry,
176                                           PVRSRV_BRIDGE_IN_FREESYNCPRIMITIVEBLOCK *psFreeSyncPrimitiveBlockIN,
177                                           PVRSRV_BRIDGE_OUT_FREESYNCPRIMITIVEBLOCK *psFreeSyncPrimitiveBlockOUT,
178                                          CONNECTION_DATA *psConnection)
179 {
180
181
182
183
184
185
186
187
188
189         psFreeSyncPrimitiveBlockOUT->eError =
190                 PVRSRVReleaseHandle(psConnection->psHandleBase,
191                                         (IMG_HANDLE) psFreeSyncPrimitiveBlockIN->hSyncHandle,
192                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
193         if ((psFreeSyncPrimitiveBlockOUT->eError != PVRSRV_OK) && (psFreeSyncPrimitiveBlockOUT->eError != PVRSRV_ERROR_RETRY))
194         {
195                 PVR_ASSERT(0);
196                 goto FreeSyncPrimitiveBlock_exit;
197         }
198
199
200
201 FreeSyncPrimitiveBlock_exit:
202
203         return 0;
204 }
205
206 static IMG_INT
207 PVRSRVBridgeSyncPrimSet(IMG_UINT32 ui32DispatchTableEntry,
208                                           PVRSRV_BRIDGE_IN_SYNCPRIMSET *psSyncPrimSetIN,
209                                           PVRSRV_BRIDGE_OUT_SYNCPRIMSET *psSyncPrimSetOUT,
210                                          CONNECTION_DATA *psConnection)
211 {
212         SYNC_PRIMITIVE_BLOCK * psSyncHandleInt = IMG_NULL;
213
214
215
216
217
218
219
220                                 {
221                                         /* Look up the address from the handle */
222                                         psSyncPrimSetOUT->eError =
223                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
224                                                                                         (IMG_VOID **) &psSyncHandleInt,
225                                                                                         psSyncPrimSetIN->hSyncHandle,
226                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
227                                         if(psSyncPrimSetOUT->eError != PVRSRV_OK)
228                                         {
229                                                 goto SyncPrimSet_exit;
230                                         }
231                                 }
232
233
234         psSyncPrimSetOUT->eError =
235                 PVRSRVSyncPrimSetKM(
236                                         psSyncHandleInt,
237                                         psSyncPrimSetIN->ui32Index,
238                                         psSyncPrimSetIN->ui32Value);
239
240
241
242
243 SyncPrimSet_exit:
244
245         return 0;
246 }
247
248 static IMG_INT
249 PVRSRVBridgeServerSyncPrimSet(IMG_UINT32 ui32DispatchTableEntry,
250                                           PVRSRV_BRIDGE_IN_SERVERSYNCPRIMSET *psServerSyncPrimSetIN,
251                                           PVRSRV_BRIDGE_OUT_SERVERSYNCPRIMSET *psServerSyncPrimSetOUT,
252                                          CONNECTION_DATA *psConnection)
253 {
254         SERVER_SYNC_PRIMITIVE * psSyncHandleInt = IMG_NULL;
255
256
257
258
259
260
261
262                                 {
263                                         /* Look up the address from the handle */
264                                         psServerSyncPrimSetOUT->eError =
265                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
266                                                                                         (IMG_VOID **) &psSyncHandleInt,
267                                                                                         psServerSyncPrimSetIN->hSyncHandle,
268                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
269                                         if(psServerSyncPrimSetOUT->eError != PVRSRV_OK)
270                                         {
271                                                 goto ServerSyncPrimSet_exit;
272                                         }
273                                 }
274
275
276         psServerSyncPrimSetOUT->eError =
277                 PVRSRVServerSyncPrimSetKM(
278                                         psSyncHandleInt,
279                                         psServerSyncPrimSetIN->ui32Value);
280
281
282
283
284 ServerSyncPrimSet_exit:
285
286         return 0;
287 }
288
289 static IMG_INT
290 PVRSRVBridgeSyncRecordRemoveByHandle(IMG_UINT32 ui32DispatchTableEntry,
291                                           PVRSRV_BRIDGE_IN_SYNCRECORDREMOVEBYHANDLE *psSyncRecordRemoveByHandleIN,
292                                           PVRSRV_BRIDGE_OUT_SYNCRECORDREMOVEBYHANDLE *psSyncRecordRemoveByHandleOUT,
293                                          CONNECTION_DATA *psConnection)
294 {
295
296
297
298
299
300
301
302
303
304         psSyncRecordRemoveByHandleOUT->eError =
305                 PVRSRVReleaseHandle(psConnection->psHandleBase,
306                                         (IMG_HANDLE) psSyncRecordRemoveByHandleIN->hhRecord,
307                                         PVRSRV_HANDLE_TYPE_SYNC_RECORD_HANDLE);
308         if ((psSyncRecordRemoveByHandleOUT->eError != PVRSRV_OK) && (psSyncRecordRemoveByHandleOUT->eError != PVRSRV_ERROR_RETRY))
309         {
310                 PVR_ASSERT(0);
311                 goto SyncRecordRemoveByHandle_exit;
312         }
313
314
315
316 SyncRecordRemoveByHandle_exit:
317
318         return 0;
319 }
320
321 static IMG_INT
322 PVRSRVBridgeSyncRecordAdd(IMG_UINT32 ui32DispatchTableEntry,
323                                           PVRSRV_BRIDGE_IN_SYNCRECORDADD *psSyncRecordAddIN,
324                                           PVRSRV_BRIDGE_OUT_SYNCRECORDADD *psSyncRecordAddOUT,
325                                          CONNECTION_DATA *psConnection)
326 {
327         SYNC_RECORD_HANDLE pshRecordInt = IMG_NULL;
328         SYNC_PRIMITIVE_BLOCK * pshServerSyncPrimBlockInt = IMG_NULL;
329         IMG_CHAR *uiClassNameInt = IMG_NULL;
330
331
332
333
334         if (psSyncRecordAddIN->ui32ClassNameSize != 0)
335         {
336                 uiClassNameInt = OSAllocMem(psSyncRecordAddIN->ui32ClassNameSize * sizeof(IMG_CHAR));
337                 if (!uiClassNameInt)
338                 {
339                         psSyncRecordAddOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
340         
341                         goto SyncRecordAdd_exit;
342                 }
343         }
344
345                         /* Copy the data over */
346                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncRecordAddIN->puiClassName, psSyncRecordAddIN->ui32ClassNameSize * sizeof(IMG_CHAR))
347                                 || (OSCopyFromUser(NULL, uiClassNameInt, psSyncRecordAddIN->puiClassName,
348                                 psSyncRecordAddIN->ui32ClassNameSize * sizeof(IMG_CHAR)) != PVRSRV_OK) )
349                         {
350                                 psSyncRecordAddOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
351
352                                 goto SyncRecordAdd_exit;
353                         }
354
355
356
357                                 {
358                                         /* Look up the address from the handle */
359                                         psSyncRecordAddOUT->eError =
360                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
361                                                                                         (IMG_VOID **) &pshServerSyncPrimBlockInt,
362                                                                                         psSyncRecordAddIN->hhServerSyncPrimBlock,
363                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
364                                         if(psSyncRecordAddOUT->eError != PVRSRV_OK)
365                                         {
366                                                 goto SyncRecordAdd_exit;
367                                         }
368                                 }
369
370
371         psSyncRecordAddOUT->eError =
372                 PVRSRVSyncRecordAddKM(
373                                         &pshRecordInt,
374                                         pshServerSyncPrimBlockInt,
375                                         psSyncRecordAddIN->ui32ui32FwBlockAddr,
376                                         psSyncRecordAddIN->ui32ui32SyncOffset,
377                                         psSyncRecordAddIN->bbServerSync,
378                                         psSyncRecordAddIN->ui32ClassNameSize,
379                                         uiClassNameInt);
380         /* Exit early if bridged call fails */
381         if(psSyncRecordAddOUT->eError != PVRSRV_OK)
382         {
383                 goto SyncRecordAdd_exit;
384         }
385
386
387         psSyncRecordAddOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
388                                                         &psSyncRecordAddOUT->hhRecord,
389                                                         (IMG_VOID *) pshRecordInt,
390                                                         PVRSRV_HANDLE_TYPE_SYNC_RECORD_HANDLE,
391                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
392                                                         ,(PFN_HANDLE_RELEASE)&PVRSRVSyncRecordRemoveByHandleKM);
393         if (psSyncRecordAddOUT->eError != PVRSRV_OK)
394         {
395                 goto SyncRecordAdd_exit;
396         }
397
398
399
400
401 SyncRecordAdd_exit:
402         if (psSyncRecordAddOUT->eError != PVRSRV_OK)
403         {
404                 if (pshRecordInt)
405                 {
406                         PVRSRVSyncRecordRemoveByHandleKM(pshRecordInt);
407                 }
408         }
409
410         if (uiClassNameInt)
411                 OSFreeMem(uiClassNameInt);
412
413         return 0;
414 }
415
416 static IMG_INT
417 PVRSRVBridgeServerSyncAlloc(IMG_UINT32 ui32DispatchTableEntry,
418                                           PVRSRV_BRIDGE_IN_SERVERSYNCALLOC *psServerSyncAllocIN,
419                                           PVRSRV_BRIDGE_OUT_SERVERSYNCALLOC *psServerSyncAllocOUT,
420                                          CONNECTION_DATA *psConnection)
421 {
422         IMG_HANDLE hDevNodeInt = IMG_NULL;
423         SERVER_SYNC_PRIMITIVE * psSyncHandleInt = IMG_NULL;
424         IMG_CHAR *uiClassNameInt = IMG_NULL;
425
426
427
428
429         if (psServerSyncAllocIN->ui32ClassNameSize != 0)
430         {
431                 uiClassNameInt = OSAllocMem(psServerSyncAllocIN->ui32ClassNameSize * sizeof(IMG_CHAR));
432                 if (!uiClassNameInt)
433                 {
434                         psServerSyncAllocOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
435         
436                         goto ServerSyncAlloc_exit;
437                 }
438         }
439
440                         /* Copy the data over */
441                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psServerSyncAllocIN->puiClassName, psServerSyncAllocIN->ui32ClassNameSize * sizeof(IMG_CHAR))
442                                 || (OSCopyFromUser(NULL, uiClassNameInt, psServerSyncAllocIN->puiClassName,
443                                 psServerSyncAllocIN->ui32ClassNameSize * sizeof(IMG_CHAR)) != PVRSRV_OK) )
444                         {
445                                 psServerSyncAllocOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
446
447                                 goto ServerSyncAlloc_exit;
448                         }
449
450
451
452                                 {
453                                         /* Look up the address from the handle */
454                                         psServerSyncAllocOUT->eError =
455                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
456                                                                                         (IMG_VOID **) &hDevNodeInt,
457                                                                                         psServerSyncAllocIN->hDevNode,
458                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
459                                         if(psServerSyncAllocOUT->eError != PVRSRV_OK)
460                                         {
461                                                 goto ServerSyncAlloc_exit;
462                                         }
463                                 }
464
465
466         psServerSyncAllocOUT->eError =
467                 PVRSRVServerSyncAllocKM(
468                                         hDevNodeInt,
469                                         &psSyncHandleInt,
470                                         &psServerSyncAllocOUT->ui32SyncPrimVAddr,
471                                         psServerSyncAllocIN->ui32ClassNameSize,
472                                         uiClassNameInt);
473         /* Exit early if bridged call fails */
474         if(psServerSyncAllocOUT->eError != PVRSRV_OK)
475         {
476                 goto ServerSyncAlloc_exit;
477         }
478
479
480         psServerSyncAllocOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
481                                                         &psServerSyncAllocOUT->hSyncHandle,
482                                                         (IMG_VOID *) psSyncHandleInt,
483                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE,
484                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
485                                                         ,(PFN_HANDLE_RELEASE)&PVRSRVServerSyncFreeKM);
486         if (psServerSyncAllocOUT->eError != PVRSRV_OK)
487         {
488                 goto ServerSyncAlloc_exit;
489         }
490
491
492
493
494 ServerSyncAlloc_exit:
495         if (psServerSyncAllocOUT->eError != PVRSRV_OK)
496         {
497                 if (psSyncHandleInt)
498                 {
499                         PVRSRVServerSyncFreeKM(psSyncHandleInt);
500                 }
501         }
502
503         if (uiClassNameInt)
504                 OSFreeMem(uiClassNameInt);
505
506         return 0;
507 }
508
509 static IMG_INT
510 PVRSRVBridgeServerSyncFree(IMG_UINT32 ui32DispatchTableEntry,
511                                           PVRSRV_BRIDGE_IN_SERVERSYNCFREE *psServerSyncFreeIN,
512                                           PVRSRV_BRIDGE_OUT_SERVERSYNCFREE *psServerSyncFreeOUT,
513                                          CONNECTION_DATA *psConnection)
514 {
515
516
517
518
519
520
521
522
523
524         psServerSyncFreeOUT->eError =
525                 PVRSRVReleaseHandle(psConnection->psHandleBase,
526                                         (IMG_HANDLE) psServerSyncFreeIN->hSyncHandle,
527                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
528         if ((psServerSyncFreeOUT->eError != PVRSRV_OK) && (psServerSyncFreeOUT->eError != PVRSRV_ERROR_RETRY))
529         {
530                 PVR_ASSERT(0);
531                 goto ServerSyncFree_exit;
532         }
533
534
535
536 ServerSyncFree_exit:
537
538         return 0;
539 }
540
541 static IMG_INT
542 PVRSRVBridgeServerSyncQueueHWOp(IMG_UINT32 ui32DispatchTableEntry,
543                                           PVRSRV_BRIDGE_IN_SERVERSYNCQUEUEHWOP *psServerSyncQueueHWOpIN,
544                                           PVRSRV_BRIDGE_OUT_SERVERSYNCQUEUEHWOP *psServerSyncQueueHWOpOUT,
545                                          CONNECTION_DATA *psConnection)
546 {
547         SERVER_SYNC_PRIMITIVE * psSyncHandleInt = IMG_NULL;
548
549
550
551
552
553
554
555                                 {
556                                         /* Look up the address from the handle */
557                                         psServerSyncQueueHWOpOUT->eError =
558                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
559                                                                                         (IMG_VOID **) &psSyncHandleInt,
560                                                                                         psServerSyncQueueHWOpIN->hSyncHandle,
561                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
562                                         if(psServerSyncQueueHWOpOUT->eError != PVRSRV_OK)
563                                         {
564                                                 goto ServerSyncQueueHWOp_exit;
565                                         }
566                                 }
567
568
569         psServerSyncQueueHWOpOUT->eError =
570                 PVRSRVServerSyncQueueHWOpKM(
571                                         psSyncHandleInt,
572                                         psServerSyncQueueHWOpIN->bbUpdate,
573                                         &psServerSyncQueueHWOpOUT->ui32FenceValue,
574                                         &psServerSyncQueueHWOpOUT->ui32UpdateValue);
575
576
577
578
579 ServerSyncQueueHWOp_exit:
580
581         return 0;
582 }
583
584 static IMG_INT
585 PVRSRVBridgeServerSyncGetStatus(IMG_UINT32 ui32DispatchTableEntry,
586                                           PVRSRV_BRIDGE_IN_SERVERSYNCGETSTATUS *psServerSyncGetStatusIN,
587                                           PVRSRV_BRIDGE_OUT_SERVERSYNCGETSTATUS *psServerSyncGetStatusOUT,
588                                          CONNECTION_DATA *psConnection)
589 {
590         SERVER_SYNC_PRIMITIVE * *psSyncHandleInt = IMG_NULL;
591         IMG_HANDLE *hSyncHandleInt2 = IMG_NULL;
592         IMG_UINT32 *pui32UIDInt = IMG_NULL;
593         IMG_UINT32 *pui32FWAddrInt = IMG_NULL;
594         IMG_UINT32 *pui32CurrentOpInt = IMG_NULL;
595         IMG_UINT32 *pui32NextOpInt = IMG_NULL;
596
597
598         psServerSyncGetStatusOUT->pui32UID = psServerSyncGetStatusIN->pui32UID;
599         psServerSyncGetStatusOUT->pui32FWAddr = psServerSyncGetStatusIN->pui32FWAddr;
600         psServerSyncGetStatusOUT->pui32CurrentOp = psServerSyncGetStatusIN->pui32CurrentOp;
601         psServerSyncGetStatusOUT->pui32NextOp = psServerSyncGetStatusIN->pui32NextOp;
602
603
604         if (psServerSyncGetStatusIN->ui32SyncCount != 0)
605         {
606                 psSyncHandleInt = OSAllocMem(psServerSyncGetStatusIN->ui32SyncCount * sizeof(SERVER_SYNC_PRIMITIVE *));
607                 if (!psSyncHandleInt)
608                 {
609                         psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
610         
611                         goto ServerSyncGetStatus_exit;
612                 }
613                 hSyncHandleInt2 = OSAllocMem(psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_HANDLE));
614                 if (!hSyncHandleInt2)
615                 {
616                         psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
617         
618                         goto ServerSyncGetStatus_exit;
619                 }
620         }
621
622                         /* Copy the data over */
623                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psServerSyncGetStatusIN->phSyncHandle, psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_HANDLE))
624                                 || (OSCopyFromUser(NULL, hSyncHandleInt2, psServerSyncGetStatusIN->phSyncHandle,
625                                 psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_HANDLE)) != PVRSRV_OK) )
626                         {
627                                 psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
628
629                                 goto ServerSyncGetStatus_exit;
630                         }
631         if (psServerSyncGetStatusIN->ui32SyncCount != 0)
632         {
633                 pui32UIDInt = OSAllocMem(psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32));
634                 if (!pui32UIDInt)
635                 {
636                         psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
637         
638                         goto ServerSyncGetStatus_exit;
639                 }
640         }
641
642         if (psServerSyncGetStatusIN->ui32SyncCount != 0)
643         {
644                 pui32FWAddrInt = OSAllocMem(psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32));
645                 if (!pui32FWAddrInt)
646                 {
647                         psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
648         
649                         goto ServerSyncGetStatus_exit;
650                 }
651         }
652
653         if (psServerSyncGetStatusIN->ui32SyncCount != 0)
654         {
655                 pui32CurrentOpInt = OSAllocMem(psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32));
656                 if (!pui32CurrentOpInt)
657                 {
658                         psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
659         
660                         goto ServerSyncGetStatus_exit;
661                 }
662         }
663
664         if (psServerSyncGetStatusIN->ui32SyncCount != 0)
665         {
666                 pui32NextOpInt = OSAllocMem(psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32));
667                 if (!pui32NextOpInt)
668                 {
669                         psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
670         
671                         goto ServerSyncGetStatus_exit;
672                 }
673         }
674
675
676
677
678         {
679                 IMG_UINT32 i;
680
681                 for (i=0;i<psServerSyncGetStatusIN->ui32SyncCount;i++)
682                 {
683                                 {
684                                         /* Look up the address from the handle */
685                                         psServerSyncGetStatusOUT->eError =
686                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
687                                                                                         (IMG_VOID **) &psSyncHandleInt[i],
688                                                                                         hSyncHandleInt2[i],
689                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
690                                         if(psServerSyncGetStatusOUT->eError != PVRSRV_OK)
691                                         {
692                                                 goto ServerSyncGetStatus_exit;
693                                         }
694                                 }
695
696                 }
697         }
698
699         psServerSyncGetStatusOUT->eError =
700                 PVRSRVServerSyncGetStatusKM(
701                                         psServerSyncGetStatusIN->ui32SyncCount,
702                                         psSyncHandleInt,
703                                         pui32UIDInt,
704                                         pui32FWAddrInt,
705                                         pui32CurrentOpInt,
706                                         pui32NextOpInt);
707
708
709
710         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psServerSyncGetStatusOUT->pui32UID, (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) 
711                 || (OSCopyToUser(NULL, psServerSyncGetStatusOUT->pui32UID, pui32UIDInt,
712                 (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) != PVRSRV_OK) )
713         {
714                 psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
715
716                 goto ServerSyncGetStatus_exit;
717         }
718
719         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psServerSyncGetStatusOUT->pui32FWAddr, (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) 
720                 || (OSCopyToUser(NULL, psServerSyncGetStatusOUT->pui32FWAddr, pui32FWAddrInt,
721                 (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) != PVRSRV_OK) )
722         {
723                 psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
724
725                 goto ServerSyncGetStatus_exit;
726         }
727
728         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psServerSyncGetStatusOUT->pui32CurrentOp, (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) 
729                 || (OSCopyToUser(NULL, psServerSyncGetStatusOUT->pui32CurrentOp, pui32CurrentOpInt,
730                 (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) != PVRSRV_OK) )
731         {
732                 psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
733
734                 goto ServerSyncGetStatus_exit;
735         }
736
737         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psServerSyncGetStatusOUT->pui32NextOp, (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) 
738                 || (OSCopyToUser(NULL, psServerSyncGetStatusOUT->pui32NextOp, pui32NextOpInt,
739                 (psServerSyncGetStatusIN->ui32SyncCount * sizeof(IMG_UINT32))) != PVRSRV_OK) )
740         {
741                 psServerSyncGetStatusOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
742
743                 goto ServerSyncGetStatus_exit;
744         }
745
746
747 ServerSyncGetStatus_exit:
748         if (psSyncHandleInt)
749                 OSFreeMem(psSyncHandleInt);
750         if (hSyncHandleInt2)
751                 OSFreeMem(hSyncHandleInt2);
752         if (pui32UIDInt)
753                 OSFreeMem(pui32UIDInt);
754         if (pui32FWAddrInt)
755                 OSFreeMem(pui32FWAddrInt);
756         if (pui32CurrentOpInt)
757                 OSFreeMem(pui32CurrentOpInt);
758         if (pui32NextOpInt)
759                 OSFreeMem(pui32NextOpInt);
760
761         return 0;
762 }
763
764 static IMG_INT
765 PVRSRVBridgeSyncPrimOpCreate(IMG_UINT32 ui32DispatchTableEntry,
766                                           PVRSRV_BRIDGE_IN_SYNCPRIMOPCREATE *psSyncPrimOpCreateIN,
767                                           PVRSRV_BRIDGE_OUT_SYNCPRIMOPCREATE *psSyncPrimOpCreateOUT,
768                                          CONNECTION_DATA *psConnection)
769 {
770         SYNC_PRIMITIVE_BLOCK * *psBlockListInt = IMG_NULL;
771         IMG_HANDLE *hBlockListInt2 = IMG_NULL;
772         IMG_UINT32 *ui32SyncBlockIndexInt = IMG_NULL;
773         IMG_UINT32 *ui32IndexInt = IMG_NULL;
774         SERVER_SYNC_PRIMITIVE * *psServerSyncInt = IMG_NULL;
775         IMG_HANDLE *hServerSyncInt2 = IMG_NULL;
776         SERVER_OP_COOKIE * psServerCookieInt = IMG_NULL;
777
778
779
780
781         if (psSyncPrimOpCreateIN->ui32SyncBlockCount != 0)
782         {
783                 psBlockListInt = OSAllocMem(psSyncPrimOpCreateIN->ui32SyncBlockCount * sizeof(SYNC_PRIMITIVE_BLOCK *));
784                 if (!psBlockListInt)
785                 {
786                         psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
787         
788                         goto SyncPrimOpCreate_exit;
789                 }
790                 hBlockListInt2 = OSAllocMem(psSyncPrimOpCreateIN->ui32SyncBlockCount * sizeof(IMG_HANDLE));
791                 if (!hBlockListInt2)
792                 {
793                         psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
794         
795                         goto SyncPrimOpCreate_exit;
796                 }
797         }
798
799                         /* Copy the data over */
800                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpCreateIN->phBlockList, psSyncPrimOpCreateIN->ui32SyncBlockCount * sizeof(IMG_HANDLE))
801                                 || (OSCopyFromUser(NULL, hBlockListInt2, psSyncPrimOpCreateIN->phBlockList,
802                                 psSyncPrimOpCreateIN->ui32SyncBlockCount * sizeof(IMG_HANDLE)) != PVRSRV_OK) )
803                         {
804                                 psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
805
806                                 goto SyncPrimOpCreate_exit;
807                         }
808         if (psSyncPrimOpCreateIN->ui32ClientSyncCount != 0)
809         {
810                 ui32SyncBlockIndexInt = OSAllocMem(psSyncPrimOpCreateIN->ui32ClientSyncCount * sizeof(IMG_UINT32));
811                 if (!ui32SyncBlockIndexInt)
812                 {
813                         psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
814         
815                         goto SyncPrimOpCreate_exit;
816                 }
817         }
818
819                         /* Copy the data over */
820                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpCreateIN->pui32SyncBlockIndex, psSyncPrimOpCreateIN->ui32ClientSyncCount * sizeof(IMG_UINT32))
821                                 || (OSCopyFromUser(NULL, ui32SyncBlockIndexInt, psSyncPrimOpCreateIN->pui32SyncBlockIndex,
822                                 psSyncPrimOpCreateIN->ui32ClientSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK) )
823                         {
824                                 psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
825
826                                 goto SyncPrimOpCreate_exit;
827                         }
828         if (psSyncPrimOpCreateIN->ui32ClientSyncCount != 0)
829         {
830                 ui32IndexInt = OSAllocMem(psSyncPrimOpCreateIN->ui32ClientSyncCount * sizeof(IMG_UINT32));
831                 if (!ui32IndexInt)
832                 {
833                         psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
834         
835                         goto SyncPrimOpCreate_exit;
836                 }
837         }
838
839                         /* Copy the data over */
840                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpCreateIN->pui32Index, psSyncPrimOpCreateIN->ui32ClientSyncCount * sizeof(IMG_UINT32))
841                                 || (OSCopyFromUser(NULL, ui32IndexInt, psSyncPrimOpCreateIN->pui32Index,
842                                 psSyncPrimOpCreateIN->ui32ClientSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK) )
843                         {
844                                 psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
845
846                                 goto SyncPrimOpCreate_exit;
847                         }
848         if (psSyncPrimOpCreateIN->ui32ServerSyncCount != 0)
849         {
850                 psServerSyncInt = OSAllocMem(psSyncPrimOpCreateIN->ui32ServerSyncCount * sizeof(SERVER_SYNC_PRIMITIVE *));
851                 if (!psServerSyncInt)
852                 {
853                         psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
854         
855                         goto SyncPrimOpCreate_exit;
856                 }
857                 hServerSyncInt2 = OSAllocMem(psSyncPrimOpCreateIN->ui32ServerSyncCount * sizeof(IMG_HANDLE));
858                 if (!hServerSyncInt2)
859                 {
860                         psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
861         
862                         goto SyncPrimOpCreate_exit;
863                 }
864         }
865
866                         /* Copy the data over */
867                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpCreateIN->phServerSync, psSyncPrimOpCreateIN->ui32ServerSyncCount * sizeof(IMG_HANDLE))
868                                 || (OSCopyFromUser(NULL, hServerSyncInt2, psSyncPrimOpCreateIN->phServerSync,
869                                 psSyncPrimOpCreateIN->ui32ServerSyncCount * sizeof(IMG_HANDLE)) != PVRSRV_OK) )
870                         {
871                                 psSyncPrimOpCreateOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
872
873                                 goto SyncPrimOpCreate_exit;
874                         }
875
876
877
878         {
879                 IMG_UINT32 i;
880
881                 for (i=0;i<psSyncPrimOpCreateIN->ui32SyncBlockCount;i++)
882                 {
883                                 {
884                                         /* Look up the address from the handle */
885                                         psSyncPrimOpCreateOUT->eError =
886                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
887                                                                                         (IMG_VOID **) &psBlockListInt[i],
888                                                                                         hBlockListInt2[i],
889                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
890                                         if(psSyncPrimOpCreateOUT->eError != PVRSRV_OK)
891                                         {
892                                                 goto SyncPrimOpCreate_exit;
893                                         }
894                                 }
895
896                 }
897         }
898
899         {
900                 IMG_UINT32 i;
901
902                 for (i=0;i<psSyncPrimOpCreateIN->ui32ServerSyncCount;i++)
903                 {
904                                 {
905                                         /* Look up the address from the handle */
906                                         psSyncPrimOpCreateOUT->eError =
907                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
908                                                                                         (IMG_VOID **) &psServerSyncInt[i],
909                                                                                         hServerSyncInt2[i],
910                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
911                                         if(psSyncPrimOpCreateOUT->eError != PVRSRV_OK)
912                                         {
913                                                 goto SyncPrimOpCreate_exit;
914                                         }
915                                 }
916
917                 }
918         }
919
920         psSyncPrimOpCreateOUT->eError =
921                 PVRSRVSyncPrimOpCreateKM(
922                                         psSyncPrimOpCreateIN->ui32SyncBlockCount,
923                                         psBlockListInt,
924                                         psSyncPrimOpCreateIN->ui32ClientSyncCount,
925                                         ui32SyncBlockIndexInt,
926                                         ui32IndexInt,
927                                         psSyncPrimOpCreateIN->ui32ServerSyncCount,
928                                         psServerSyncInt,
929                                         &psServerCookieInt);
930         /* Exit early if bridged call fails */
931         if(psSyncPrimOpCreateOUT->eError != PVRSRV_OK)
932         {
933                 goto SyncPrimOpCreate_exit;
934         }
935
936
937         psSyncPrimOpCreateOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
938                                                         &psSyncPrimOpCreateOUT->hServerCookie,
939                                                         (IMG_VOID *) psServerCookieInt,
940                                                         PVRSRV_HANDLE_TYPE_SERVER_OP_COOKIE,
941                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
942                                                         ,(PFN_HANDLE_RELEASE)&PVRSRVSyncPrimOpDestroyKM);
943         if (psSyncPrimOpCreateOUT->eError != PVRSRV_OK)
944         {
945                 goto SyncPrimOpCreate_exit;
946         }
947
948
949
950
951 SyncPrimOpCreate_exit:
952         if (psSyncPrimOpCreateOUT->eError != PVRSRV_OK)
953         {
954                 if (psServerCookieInt)
955                 {
956                         PVRSRVSyncPrimOpDestroyKM(psServerCookieInt);
957                 }
958         }
959
960         if (psBlockListInt)
961                 OSFreeMem(psBlockListInt);
962         if (hBlockListInt2)
963                 OSFreeMem(hBlockListInt2);
964         if (ui32SyncBlockIndexInt)
965                 OSFreeMem(ui32SyncBlockIndexInt);
966         if (ui32IndexInt)
967                 OSFreeMem(ui32IndexInt);
968         if (psServerSyncInt)
969                 OSFreeMem(psServerSyncInt);
970         if (hServerSyncInt2)
971                 OSFreeMem(hServerSyncInt2);
972
973         return 0;
974 }
975
976 static IMG_INT
977 PVRSRVBridgeSyncPrimOpTake(IMG_UINT32 ui32DispatchTableEntry,
978                                           PVRSRV_BRIDGE_IN_SYNCPRIMOPTAKE *psSyncPrimOpTakeIN,
979                                           PVRSRV_BRIDGE_OUT_SYNCPRIMOPTAKE *psSyncPrimOpTakeOUT,
980                                          CONNECTION_DATA *psConnection)
981 {
982         SERVER_OP_COOKIE * psServerCookieInt = IMG_NULL;
983         IMG_UINT32 *ui32FlagsInt = IMG_NULL;
984         IMG_UINT32 *ui32FenceValueInt = IMG_NULL;
985         IMG_UINT32 *ui32UpdateValueInt = IMG_NULL;
986         IMG_UINT32 *ui32ServerFlagsInt = IMG_NULL;
987
988
989
990
991         if (psSyncPrimOpTakeIN->ui32ClientSyncCount != 0)
992         {
993                 ui32FlagsInt = OSAllocMem(psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32));
994                 if (!ui32FlagsInt)
995                 {
996                         psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
997         
998                         goto SyncPrimOpTake_exit;
999                 }
1000         }
1001
1002                         /* Copy the data over */
1003                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpTakeIN->pui32Flags, psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32))
1004                                 || (OSCopyFromUser(NULL, ui32FlagsInt, psSyncPrimOpTakeIN->pui32Flags,
1005                                 psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK) )
1006                         {
1007                                 psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
1008
1009                                 goto SyncPrimOpTake_exit;
1010                         }
1011         if (psSyncPrimOpTakeIN->ui32ClientSyncCount != 0)
1012         {
1013                 ui32FenceValueInt = OSAllocMem(psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32));
1014                 if (!ui32FenceValueInt)
1015                 {
1016                         psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1017         
1018                         goto SyncPrimOpTake_exit;
1019                 }
1020         }
1021
1022                         /* Copy the data over */
1023                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpTakeIN->pui32FenceValue, psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32))
1024                                 || (OSCopyFromUser(NULL, ui32FenceValueInt, psSyncPrimOpTakeIN->pui32FenceValue,
1025                                 psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK) )
1026                         {
1027                                 psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
1028
1029                                 goto SyncPrimOpTake_exit;
1030                         }
1031         if (psSyncPrimOpTakeIN->ui32ClientSyncCount != 0)
1032         {
1033                 ui32UpdateValueInt = OSAllocMem(psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32));
1034                 if (!ui32UpdateValueInt)
1035                 {
1036                         psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1037         
1038                         goto SyncPrimOpTake_exit;
1039                 }
1040         }
1041
1042                         /* Copy the data over */
1043                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpTakeIN->pui32UpdateValue, psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32))
1044                                 || (OSCopyFromUser(NULL, ui32UpdateValueInt, psSyncPrimOpTakeIN->pui32UpdateValue,
1045                                 psSyncPrimOpTakeIN->ui32ClientSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK) )
1046                         {
1047                                 psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
1048
1049                                 goto SyncPrimOpTake_exit;
1050                         }
1051         if (psSyncPrimOpTakeIN->ui32ServerSyncCount != 0)
1052         {
1053                 ui32ServerFlagsInt = OSAllocMem(psSyncPrimOpTakeIN->ui32ServerSyncCount * sizeof(IMG_UINT32));
1054                 if (!ui32ServerFlagsInt)
1055                 {
1056                         psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1057         
1058                         goto SyncPrimOpTake_exit;
1059                 }
1060         }
1061
1062                         /* Copy the data over */
1063                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psSyncPrimOpTakeIN->pui32ServerFlags, psSyncPrimOpTakeIN->ui32ServerSyncCount * sizeof(IMG_UINT32))
1064                                 || (OSCopyFromUser(NULL, ui32ServerFlagsInt, psSyncPrimOpTakeIN->pui32ServerFlags,
1065                                 psSyncPrimOpTakeIN->ui32ServerSyncCount * sizeof(IMG_UINT32)) != PVRSRV_OK) )
1066                         {
1067                                 psSyncPrimOpTakeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
1068
1069                                 goto SyncPrimOpTake_exit;
1070                         }
1071
1072
1073
1074                                 {
1075                                         /* Look up the address from the handle */
1076                                         psSyncPrimOpTakeOUT->eError =
1077                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1078                                                                                         (IMG_VOID **) &psServerCookieInt,
1079                                                                                         psSyncPrimOpTakeIN->hServerCookie,
1080                                                                                         PVRSRV_HANDLE_TYPE_SERVER_OP_COOKIE);
1081                                         if(psSyncPrimOpTakeOUT->eError != PVRSRV_OK)
1082                                         {
1083                                                 goto SyncPrimOpTake_exit;
1084                                         }
1085                                 }
1086
1087
1088         psSyncPrimOpTakeOUT->eError =
1089                 PVRSRVSyncPrimOpTakeKM(
1090                                         psServerCookieInt,
1091                                         psSyncPrimOpTakeIN->ui32ClientSyncCount,
1092                                         ui32FlagsInt,
1093                                         ui32FenceValueInt,
1094                                         ui32UpdateValueInt,
1095                                         psSyncPrimOpTakeIN->ui32ServerSyncCount,
1096                                         ui32ServerFlagsInt);
1097
1098
1099
1100
1101 SyncPrimOpTake_exit:
1102         if (ui32FlagsInt)
1103                 OSFreeMem(ui32FlagsInt);
1104         if (ui32FenceValueInt)
1105                 OSFreeMem(ui32FenceValueInt);
1106         if (ui32UpdateValueInt)
1107                 OSFreeMem(ui32UpdateValueInt);
1108         if (ui32ServerFlagsInt)
1109                 OSFreeMem(ui32ServerFlagsInt);
1110
1111         return 0;
1112 }
1113
1114 static IMG_INT
1115 PVRSRVBridgeSyncPrimOpReady(IMG_UINT32 ui32DispatchTableEntry,
1116                                           PVRSRV_BRIDGE_IN_SYNCPRIMOPREADY *psSyncPrimOpReadyIN,
1117                                           PVRSRV_BRIDGE_OUT_SYNCPRIMOPREADY *psSyncPrimOpReadyOUT,
1118                                          CONNECTION_DATA *psConnection)
1119 {
1120         SERVER_OP_COOKIE * psServerCookieInt = IMG_NULL;
1121
1122
1123
1124
1125
1126
1127
1128                                 {
1129                                         /* Look up the address from the handle */
1130                                         psSyncPrimOpReadyOUT->eError =
1131                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1132                                                                                         (IMG_VOID **) &psServerCookieInt,
1133                                                                                         psSyncPrimOpReadyIN->hServerCookie,
1134                                                                                         PVRSRV_HANDLE_TYPE_SERVER_OP_COOKIE);
1135                                         if(psSyncPrimOpReadyOUT->eError != PVRSRV_OK)
1136                                         {
1137                                                 goto SyncPrimOpReady_exit;
1138                                         }
1139                                 }
1140
1141
1142         psSyncPrimOpReadyOUT->eError =
1143                 PVRSRVSyncPrimOpReadyKM(
1144                                         psServerCookieInt,
1145                                         &psSyncPrimOpReadyOUT->bReady);
1146
1147
1148
1149
1150 SyncPrimOpReady_exit:
1151
1152         return 0;
1153 }
1154
1155 static IMG_INT
1156 PVRSRVBridgeSyncPrimOpComplete(IMG_UINT32 ui32DispatchTableEntry,
1157                                           PVRSRV_BRIDGE_IN_SYNCPRIMOPCOMPLETE *psSyncPrimOpCompleteIN,
1158                                           PVRSRV_BRIDGE_OUT_SYNCPRIMOPCOMPLETE *psSyncPrimOpCompleteOUT,
1159                                          CONNECTION_DATA *psConnection)
1160 {
1161         SERVER_OP_COOKIE * psServerCookieInt = IMG_NULL;
1162
1163
1164
1165
1166
1167
1168
1169                                 {
1170                                         /* Look up the address from the handle */
1171                                         psSyncPrimOpCompleteOUT->eError =
1172                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1173                                                                                         (IMG_VOID **) &psServerCookieInt,
1174                                                                                         psSyncPrimOpCompleteIN->hServerCookie,
1175                                                                                         PVRSRV_HANDLE_TYPE_SERVER_OP_COOKIE);
1176                                         if(psSyncPrimOpCompleteOUT->eError != PVRSRV_OK)
1177                                         {
1178                                                 goto SyncPrimOpComplete_exit;
1179                                         }
1180                                 }
1181
1182
1183         psSyncPrimOpCompleteOUT->eError =
1184                 PVRSRVSyncPrimOpCompleteKM(
1185                                         psServerCookieInt);
1186
1187
1188
1189
1190 SyncPrimOpComplete_exit:
1191
1192         return 0;
1193 }
1194
1195 static IMG_INT
1196 PVRSRVBridgeSyncPrimOpDestroy(IMG_UINT32 ui32DispatchTableEntry,
1197                                           PVRSRV_BRIDGE_IN_SYNCPRIMOPDESTROY *psSyncPrimOpDestroyIN,
1198                                           PVRSRV_BRIDGE_OUT_SYNCPRIMOPDESTROY *psSyncPrimOpDestroyOUT,
1199                                          CONNECTION_DATA *psConnection)
1200 {
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210         psSyncPrimOpDestroyOUT->eError =
1211                 PVRSRVReleaseHandle(psConnection->psHandleBase,
1212                                         (IMG_HANDLE) psSyncPrimOpDestroyIN->hServerCookie,
1213                                         PVRSRV_HANDLE_TYPE_SERVER_OP_COOKIE);
1214         if ((psSyncPrimOpDestroyOUT->eError != PVRSRV_OK) && (psSyncPrimOpDestroyOUT->eError != PVRSRV_ERROR_RETRY))
1215         {
1216                 PVR_ASSERT(0);
1217                 goto SyncPrimOpDestroy_exit;
1218         }
1219
1220
1221
1222 SyncPrimOpDestroy_exit:
1223
1224         return 0;
1225 }
1226
1227 static IMG_INT
1228 PVRSRVBridgeSyncPrimPDump(IMG_UINT32 ui32DispatchTableEntry,
1229                                           PVRSRV_BRIDGE_IN_SYNCPRIMPDUMP *psSyncPrimPDumpIN,
1230                                           PVRSRV_BRIDGE_OUT_SYNCPRIMPDUMP *psSyncPrimPDumpOUT,
1231                                          CONNECTION_DATA *psConnection)
1232 {
1233         SYNC_PRIMITIVE_BLOCK * psSyncHandleInt = IMG_NULL;
1234
1235
1236
1237
1238
1239
1240
1241                                 {
1242                                         /* Look up the address from the handle */
1243                                         psSyncPrimPDumpOUT->eError =
1244                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1245                                                                                         (IMG_VOID **) &psSyncHandleInt,
1246                                                                                         psSyncPrimPDumpIN->hSyncHandle,
1247                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
1248                                         if(psSyncPrimPDumpOUT->eError != PVRSRV_OK)
1249                                         {
1250                                                 goto SyncPrimPDump_exit;
1251                                         }
1252                                 }
1253
1254
1255         psSyncPrimPDumpOUT->eError =
1256                 PVRSRVSyncPrimPDumpKM(
1257                                         psSyncHandleInt,
1258                                         psSyncPrimPDumpIN->ui32Offset);
1259
1260
1261
1262
1263 SyncPrimPDump_exit:
1264
1265         return 0;
1266 }
1267
1268 static IMG_INT
1269 PVRSRVBridgeSyncPrimPDumpValue(IMG_UINT32 ui32DispatchTableEntry,
1270                                           PVRSRV_BRIDGE_IN_SYNCPRIMPDUMPVALUE *psSyncPrimPDumpValueIN,
1271                                           PVRSRV_BRIDGE_OUT_SYNCPRIMPDUMPVALUE *psSyncPrimPDumpValueOUT,
1272                                          CONNECTION_DATA *psConnection)
1273 {
1274         SYNC_PRIMITIVE_BLOCK * psSyncHandleInt = IMG_NULL;
1275
1276
1277
1278
1279
1280
1281
1282                                 {
1283                                         /* Look up the address from the handle */
1284                                         psSyncPrimPDumpValueOUT->eError =
1285                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1286                                                                                         (IMG_VOID **) &psSyncHandleInt,
1287                                                                                         psSyncPrimPDumpValueIN->hSyncHandle,
1288                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
1289                                         if(psSyncPrimPDumpValueOUT->eError != PVRSRV_OK)
1290                                         {
1291                                                 goto SyncPrimPDumpValue_exit;
1292                                         }
1293                                 }
1294
1295
1296         psSyncPrimPDumpValueOUT->eError =
1297                 PVRSRVSyncPrimPDumpValueKM(
1298                                         psSyncHandleInt,
1299                                         psSyncPrimPDumpValueIN->ui32Offset,
1300                                         psSyncPrimPDumpValueIN->ui32Value);
1301
1302
1303
1304
1305 SyncPrimPDumpValue_exit:
1306
1307         return 0;
1308 }
1309
1310 static IMG_INT
1311 PVRSRVBridgeSyncPrimPDumpPol(IMG_UINT32 ui32DispatchTableEntry,
1312                                           PVRSRV_BRIDGE_IN_SYNCPRIMPDUMPPOL *psSyncPrimPDumpPolIN,
1313                                           PVRSRV_BRIDGE_OUT_SYNCPRIMPDUMPPOL *psSyncPrimPDumpPolOUT,
1314                                          CONNECTION_DATA *psConnection)
1315 {
1316         SYNC_PRIMITIVE_BLOCK * psSyncHandleInt = IMG_NULL;
1317
1318
1319
1320
1321
1322
1323
1324                                 {
1325                                         /* Look up the address from the handle */
1326                                         psSyncPrimPDumpPolOUT->eError =
1327                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1328                                                                                         (IMG_VOID **) &psSyncHandleInt,
1329                                                                                         psSyncPrimPDumpPolIN->hSyncHandle,
1330                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
1331                                         if(psSyncPrimPDumpPolOUT->eError != PVRSRV_OK)
1332                                         {
1333                                                 goto SyncPrimPDumpPol_exit;
1334                                         }
1335                                 }
1336
1337
1338         psSyncPrimPDumpPolOUT->eError =
1339                 PVRSRVSyncPrimPDumpPolKM(
1340                                         psSyncHandleInt,
1341                                         psSyncPrimPDumpPolIN->ui32Offset,
1342                                         psSyncPrimPDumpPolIN->ui32Value,
1343                                         psSyncPrimPDumpPolIN->ui32Mask,
1344                                         psSyncPrimPDumpPolIN->eOperator,
1345                                         psSyncPrimPDumpPolIN->uiPDumpFlags);
1346
1347
1348
1349
1350 SyncPrimPDumpPol_exit:
1351
1352         return 0;
1353 }
1354
1355 static IMG_INT
1356 PVRSRVBridgeSyncPrimOpPDumpPol(IMG_UINT32 ui32DispatchTableEntry,
1357                                           PVRSRV_BRIDGE_IN_SYNCPRIMOPPDUMPPOL *psSyncPrimOpPDumpPolIN,
1358                                           PVRSRV_BRIDGE_OUT_SYNCPRIMOPPDUMPPOL *psSyncPrimOpPDumpPolOUT,
1359                                          CONNECTION_DATA *psConnection)
1360 {
1361         SERVER_OP_COOKIE * psServerCookieInt = IMG_NULL;
1362
1363
1364
1365
1366
1367
1368
1369                                 {
1370                                         /* Look up the address from the handle */
1371                                         psSyncPrimOpPDumpPolOUT->eError =
1372                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1373                                                                                         (IMG_VOID **) &psServerCookieInt,
1374                                                                                         psSyncPrimOpPDumpPolIN->hServerCookie,
1375                                                                                         PVRSRV_HANDLE_TYPE_SERVER_OP_COOKIE);
1376                                         if(psSyncPrimOpPDumpPolOUT->eError != PVRSRV_OK)
1377                                         {
1378                                                 goto SyncPrimOpPDumpPol_exit;
1379                                         }
1380                                 }
1381
1382
1383         psSyncPrimOpPDumpPolOUT->eError =
1384                 PVRSRVSyncPrimOpPDumpPolKM(
1385                                         psServerCookieInt,
1386                                         psSyncPrimOpPDumpPolIN->eOperator,
1387                                         psSyncPrimOpPDumpPolIN->uiPDumpFlags);
1388
1389
1390
1391
1392 SyncPrimOpPDumpPol_exit:
1393
1394         return 0;
1395 }
1396
1397 static IMG_INT
1398 PVRSRVBridgeSyncPrimPDumpCBP(IMG_UINT32 ui32DispatchTableEntry,
1399                                           PVRSRV_BRIDGE_IN_SYNCPRIMPDUMPCBP *psSyncPrimPDumpCBPIN,
1400                                           PVRSRV_BRIDGE_OUT_SYNCPRIMPDUMPCBP *psSyncPrimPDumpCBPOUT,
1401                                          CONNECTION_DATA *psConnection)
1402 {
1403         SYNC_PRIMITIVE_BLOCK * psSyncHandleInt = IMG_NULL;
1404
1405
1406
1407
1408
1409
1410
1411                                 {
1412                                         /* Look up the address from the handle */
1413                                         psSyncPrimPDumpCBPOUT->eError =
1414                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
1415                                                                                         (IMG_VOID **) &psSyncHandleInt,
1416                                                                                         psSyncPrimPDumpCBPIN->hSyncHandle,
1417                                                                                         PVRSRV_HANDLE_TYPE_SYNC_PRIMITIVE_BLOCK);
1418                                         if(psSyncPrimPDumpCBPOUT->eError != PVRSRV_OK)
1419                                         {
1420                                                 goto SyncPrimPDumpCBP_exit;
1421                                         }
1422                                 }
1423
1424
1425         psSyncPrimPDumpCBPOUT->eError =
1426                 PVRSRVSyncPrimPDumpCBPKM(
1427                                         psSyncHandleInt,
1428                                         psSyncPrimPDumpCBPIN->ui32Offset,
1429                                         psSyncPrimPDumpCBPIN->uiWriteOffset,
1430                                         psSyncPrimPDumpCBPIN->uiPacketSize,
1431                                         psSyncPrimPDumpCBPIN->uiBufferSize);
1432
1433
1434
1435
1436 SyncPrimPDumpCBP_exit:
1437
1438         return 0;
1439 }
1440
1441
1442
1443 /* *************************************************************************** 
1444  * Server bridge dispatch related glue 
1445  */
1446
1447
1448 PVRSRV_ERROR InitSYNCBridge(IMG_VOID);
1449 PVRSRV_ERROR DeinitSYNCBridge(IMG_VOID);
1450
1451 /*
1452  * Register all SYNC functions with services
1453  */
1454 PVRSRV_ERROR InitSYNCBridge(IMG_VOID)
1455 {
1456
1457         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_ALLOCSYNCPRIMITIVEBLOCK, PVRSRVBridgeAllocSyncPrimitiveBlock,
1458                                         IMG_NULL, IMG_NULL,
1459                                         0, 0);
1460
1461         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_FREESYNCPRIMITIVEBLOCK, PVRSRVBridgeFreeSyncPrimitiveBlock,
1462                                         IMG_NULL, IMG_NULL,
1463                                         0, 0);
1464
1465         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMSET, PVRSRVBridgeSyncPrimSet,
1466                                         IMG_NULL, IMG_NULL,
1467                                         0, 0);
1468
1469         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SERVERSYNCPRIMSET, PVRSRVBridgeServerSyncPrimSet,
1470                                         IMG_NULL, IMG_NULL,
1471                                         0, 0);
1472
1473         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCRECORDREMOVEBYHANDLE, PVRSRVBridgeSyncRecordRemoveByHandle,
1474                                         IMG_NULL, IMG_NULL,
1475                                         0, 0);
1476
1477         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCRECORDADD, PVRSRVBridgeSyncRecordAdd,
1478                                         IMG_NULL, IMG_NULL,
1479                                         0, 0);
1480
1481         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SERVERSYNCALLOC, PVRSRVBridgeServerSyncAlloc,
1482                                         IMG_NULL, IMG_NULL,
1483                                         0, 0);
1484
1485         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SERVERSYNCFREE, PVRSRVBridgeServerSyncFree,
1486                                         IMG_NULL, IMG_NULL,
1487                                         0, 0);
1488
1489         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SERVERSYNCQUEUEHWOP, PVRSRVBridgeServerSyncQueueHWOp,
1490                                         IMG_NULL, IMG_NULL,
1491                                         0, 0);
1492
1493         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SERVERSYNCGETSTATUS, PVRSRVBridgeServerSyncGetStatus,
1494                                         IMG_NULL, IMG_NULL,
1495                                         0, 0);
1496
1497         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMOPCREATE, PVRSRVBridgeSyncPrimOpCreate,
1498                                         IMG_NULL, IMG_NULL,
1499                                         0, 0);
1500
1501         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMOPTAKE, PVRSRVBridgeSyncPrimOpTake,
1502                                         IMG_NULL, IMG_NULL,
1503                                         0, 0);
1504
1505         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMOPREADY, PVRSRVBridgeSyncPrimOpReady,
1506                                         IMG_NULL, IMG_NULL,
1507                                         0, 0);
1508
1509         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMOPCOMPLETE, PVRSRVBridgeSyncPrimOpComplete,
1510                                         IMG_NULL, IMG_NULL,
1511                                         0, 0);
1512
1513         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMOPDESTROY, PVRSRVBridgeSyncPrimOpDestroy,
1514                                         IMG_NULL, IMG_NULL,
1515                                         0, 0);
1516
1517         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMPDUMP, PVRSRVBridgeSyncPrimPDump,
1518                                         IMG_NULL, IMG_NULL,
1519                                         0, 0);
1520
1521         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMPDUMPVALUE, PVRSRVBridgeSyncPrimPDumpValue,
1522                                         IMG_NULL, IMG_NULL,
1523                                         0, 0);
1524
1525         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMPDUMPPOL, PVRSRVBridgeSyncPrimPDumpPol,
1526                                         IMG_NULL, IMG_NULL,
1527                                         0, 0);
1528
1529         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMOPPDUMPPOL, PVRSRVBridgeSyncPrimOpPDumpPol,
1530                                         IMG_NULL, IMG_NULL,
1531                                         0, 0);
1532
1533         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNC, PVRSRV_BRIDGE_SYNC_SYNCPRIMPDUMPCBP, PVRSRVBridgeSyncPrimPDumpCBP,
1534                                         IMG_NULL, IMG_NULL,
1535                                         0, 0);
1536
1537
1538         return PVRSRV_OK;
1539 }
1540
1541 /*
1542  * Unregister all sync functions with services
1543  */
1544 PVRSRV_ERROR DeinitSYNCBridge(IMG_VOID)
1545 {
1546         return PVRSRV_OK;
1547 }
1548