RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / generated / ri_bridge / server_ri_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for ri
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for ri
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 "ri_server.h"
50
51
52 #include "common_ri_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 PVRSRVBridgeRIWritePMREntry(IMG_UINT32 ui32DispatchTableEntry,
75                                           PVRSRV_BRIDGE_IN_RIWRITEPMRENTRY *psRIWritePMREntryIN,
76                                           PVRSRV_BRIDGE_OUT_RIWRITEPMRENTRY *psRIWritePMREntryOUT,
77                                          CONNECTION_DATA *psConnection)
78 {
79         IMG_HANDLE hPMRHandle = psRIWritePMREntryIN->hPMRHandle;
80         PMR * psPMRHandleInt = NULL;
81         IMG_CHAR *uiTextAInt = NULL;
82
83         IMG_UINT32 ui32NextOffset = 0;
84         IMG_BYTE   *pArrayArgsBuffer = NULL;
85 #if !defined(INTEGRITY_OS)
86         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
87 #endif
88
89         IMG_UINT32 ui32BufferSize = 
90                         (psRIWritePMREntryIN->ui32TextASize * sizeof(IMG_CHAR)) +
91                         0;
92
93
94
95
96
97         if (ui32BufferSize != 0)
98         {
99 #if !defined(INTEGRITY_OS)
100                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
101                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psRIWritePMREntryIN), sizeof(unsigned long));
102                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
103                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
104
105                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
106                 if (bHaveEnoughSpace)
107                 {
108                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psRIWritePMREntryIN;
109
110                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
111                 else
112 #endif
113                 {
114                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
115
116                         if(!pArrayArgsBuffer)
117                         {
118                                 psRIWritePMREntryOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
119                                 goto RIWritePMREntry_exit;
120                         }
121                 }
122         }
123
124         if (psRIWritePMREntryIN->ui32TextASize != 0)
125         {
126                 uiTextAInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
127                 ui32NextOffset += psRIWritePMREntryIN->ui32TextASize * sizeof(IMG_CHAR);
128         }
129
130                         /* Copy the data over */
131                         if (psRIWritePMREntryIN->ui32TextASize * sizeof(IMG_CHAR) > 0)
132                         {
133                                 if ( OSCopyFromUser(NULL, uiTextAInt, psRIWritePMREntryIN->puiTextA, psRIWritePMREntryIN->ui32TextASize * sizeof(IMG_CHAR)) != PVRSRV_OK )
134                                 {
135                                         psRIWritePMREntryOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
136
137                                         goto RIWritePMREntry_exit;
138                                 }
139                         }
140
141         /* Lock over handle lookup. */
142         LockHandle();
143
144
145
146
147
148                                 {
149                                         /* Look up the address from the handle */
150                                         psRIWritePMREntryOUT->eError =
151                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
152                                                                                         (void **) &psPMRHandleInt,
153                                                                                         hPMRHandle,
154                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR,
155                                                                                         IMG_TRUE);
156                                         if(psRIWritePMREntryOUT->eError != PVRSRV_OK)
157                                         {
158                                                 UnlockHandle();
159                                                 goto RIWritePMREntry_exit;
160                                         }
161                                 }
162         /* Release now we have looked up handles. */
163         UnlockHandle();
164
165         psRIWritePMREntryOUT->eError =
166                 RIWritePMREntryKM(
167                                         psPMRHandleInt,
168                                         psRIWritePMREntryIN->ui32TextASize,
169                                         uiTextAInt,
170                                         psRIWritePMREntryIN->ui64LogicalSize);
171
172
173
174
175 RIWritePMREntry_exit:
176
177         /* Lock over handle lookup cleanup. */
178         LockHandle();
179
180
181
182
183
184
185                                 {
186                                         /* Unreference the previously looked up handle */
187                                                 if(psPMRHandleInt)
188                                                 {
189                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
190                                                                                         hPMRHandle,
191                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
192                                                 }
193                                 }
194         /* Release now we have cleaned up look up handles. */
195         UnlockHandle();
196
197         /* Allocated space should be equal to the last updated offset */
198         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
199
200 #if defined(INTEGRITY_OS)
201         if(pArrayArgsBuffer)
202 #else
203         if(!bHaveEnoughSpace && pArrayArgsBuffer)
204 #endif
205                 OSFreeMemNoStats(pArrayArgsBuffer);
206
207
208         return 0;
209 }
210
211
212 static IMG_INT
213 PVRSRVBridgeRIWriteMEMDESCEntry(IMG_UINT32 ui32DispatchTableEntry,
214                                           PVRSRV_BRIDGE_IN_RIWRITEMEMDESCENTRY *psRIWriteMEMDESCEntryIN,
215                                           PVRSRV_BRIDGE_OUT_RIWRITEMEMDESCENTRY *psRIWriteMEMDESCEntryOUT,
216                                          CONNECTION_DATA *psConnection)
217 {
218         IMG_HANDLE hPMRHandle = psRIWriteMEMDESCEntryIN->hPMRHandle;
219         PMR * psPMRHandleInt = NULL;
220         IMG_CHAR *uiTextBInt = NULL;
221         RI_HANDLE psRIHandleInt = NULL;
222
223         IMG_UINT32 ui32NextOffset = 0;
224         IMG_BYTE   *pArrayArgsBuffer = NULL;
225 #if !defined(INTEGRITY_OS)
226         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
227 #endif
228
229         IMG_UINT32 ui32BufferSize = 
230                         (psRIWriteMEMDESCEntryIN->ui32TextBSize * sizeof(IMG_CHAR)) +
231                         0;
232
233
234
235
236
237         if (ui32BufferSize != 0)
238         {
239 #if !defined(INTEGRITY_OS)
240                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
241                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psRIWriteMEMDESCEntryIN), sizeof(unsigned long));
242                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
243                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
244
245                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
246                 if (bHaveEnoughSpace)
247                 {
248                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psRIWriteMEMDESCEntryIN;
249
250                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
251                 else
252 #endif
253                 {
254                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
255
256                         if(!pArrayArgsBuffer)
257                         {
258                                 psRIWriteMEMDESCEntryOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
259                                 goto RIWriteMEMDESCEntry_exit;
260                         }
261                 }
262         }
263
264         if (psRIWriteMEMDESCEntryIN->ui32TextBSize != 0)
265         {
266                 uiTextBInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
267                 ui32NextOffset += psRIWriteMEMDESCEntryIN->ui32TextBSize * sizeof(IMG_CHAR);
268         }
269
270                         /* Copy the data over */
271                         if (psRIWriteMEMDESCEntryIN->ui32TextBSize * sizeof(IMG_CHAR) > 0)
272                         {
273                                 if ( OSCopyFromUser(NULL, uiTextBInt, psRIWriteMEMDESCEntryIN->puiTextB, psRIWriteMEMDESCEntryIN->ui32TextBSize * sizeof(IMG_CHAR)) != PVRSRV_OK )
274                                 {
275                                         psRIWriteMEMDESCEntryOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
276
277                                         goto RIWriteMEMDESCEntry_exit;
278                                 }
279                         }
280
281         /* Lock over handle lookup. */
282         LockHandle();
283
284
285
286
287
288                                 {
289                                         /* Look up the address from the handle */
290                                         psRIWriteMEMDESCEntryOUT->eError =
291                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
292                                                                                         (void **) &psPMRHandleInt,
293                                                                                         hPMRHandle,
294                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR,
295                                                                                         IMG_TRUE);
296                                         if(psRIWriteMEMDESCEntryOUT->eError != PVRSRV_OK)
297                                         {
298                                                 UnlockHandle();
299                                                 goto RIWriteMEMDESCEntry_exit;
300                                         }
301                                 }
302         /* Release now we have looked up handles. */
303         UnlockHandle();
304
305         psRIWriteMEMDESCEntryOUT->eError =
306                 RIWriteMEMDESCEntryKM(
307                                         psPMRHandleInt,
308                                         psRIWriteMEMDESCEntryIN->ui32TextBSize,
309                                         uiTextBInt,
310                                         psRIWriteMEMDESCEntryIN->ui64Offset,
311                                         psRIWriteMEMDESCEntryIN->ui64Size,
312                                         psRIWriteMEMDESCEntryIN->ui64BackedSize,
313                                         psRIWriteMEMDESCEntryIN->bIsImport,
314                                         psRIWriteMEMDESCEntryIN->bIsExportable,
315                                         &psRIHandleInt);
316         /* Exit early if bridged call fails */
317         if(psRIWriteMEMDESCEntryOUT->eError != PVRSRV_OK)
318         {
319                 goto RIWriteMEMDESCEntry_exit;
320         }
321
322         /* Lock over handle creation. */
323         LockHandle();
324
325
326
327
328
329         psRIWriteMEMDESCEntryOUT->eError = PVRSRVAllocHandleUnlocked(psConnection->psHandleBase,
330
331                                                         &psRIWriteMEMDESCEntryOUT->hRIHandle,
332                                                         (void *) psRIHandleInt,
333                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE,
334                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
335                                                         ,(PFN_HANDLE_RELEASE)&RIDeleteMEMDESCEntryKM);
336         if (psRIWriteMEMDESCEntryOUT->eError != PVRSRV_OK)
337         {
338                 UnlockHandle();
339                 goto RIWriteMEMDESCEntry_exit;
340         }
341
342         /* Release now we have created handles. */
343         UnlockHandle();
344
345
346
347 RIWriteMEMDESCEntry_exit:
348
349         /* Lock over handle lookup cleanup. */
350         LockHandle();
351
352
353
354
355
356
357                                 {
358                                         /* Unreference the previously looked up handle */
359                                                 if(psPMRHandleInt)
360                                                 {
361                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
362                                                                                         hPMRHandle,
363                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
364                                                 }
365                                 }
366         /* Release now we have cleaned up look up handles. */
367         UnlockHandle();
368
369         if (psRIWriteMEMDESCEntryOUT->eError != PVRSRV_OK)
370         {
371                 if (psRIHandleInt)
372                 {
373                         RIDeleteMEMDESCEntryKM(psRIHandleInt);
374                 }
375         }
376
377         /* Allocated space should be equal to the last updated offset */
378         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
379
380 #if defined(INTEGRITY_OS)
381         if(pArrayArgsBuffer)
382 #else
383         if(!bHaveEnoughSpace && pArrayArgsBuffer)
384 #endif
385                 OSFreeMemNoStats(pArrayArgsBuffer);
386
387
388         return 0;
389 }
390
391
392 static IMG_INT
393 PVRSRVBridgeRIWriteProcListEntry(IMG_UINT32 ui32DispatchTableEntry,
394                                           PVRSRV_BRIDGE_IN_RIWRITEPROCLISTENTRY *psRIWriteProcListEntryIN,
395                                           PVRSRV_BRIDGE_OUT_RIWRITEPROCLISTENTRY *psRIWriteProcListEntryOUT,
396                                          CONNECTION_DATA *psConnection)
397 {
398         IMG_CHAR *uiTextBInt = NULL;
399         RI_HANDLE psRIHandleInt = NULL;
400
401         IMG_UINT32 ui32NextOffset = 0;
402         IMG_BYTE   *pArrayArgsBuffer = NULL;
403 #if !defined(INTEGRITY_OS)
404         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
405 #endif
406
407         IMG_UINT32 ui32BufferSize = 
408                         (psRIWriteProcListEntryIN->ui32TextBSize * sizeof(IMG_CHAR)) +
409                         0;
410
411
412
413
414
415         if (ui32BufferSize != 0)
416         {
417 #if !defined(INTEGRITY_OS)
418                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
419                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psRIWriteProcListEntryIN), sizeof(unsigned long));
420                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
421                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
422
423                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
424                 if (bHaveEnoughSpace)
425                 {
426                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psRIWriteProcListEntryIN;
427
428                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
429                 else
430 #endif
431                 {
432                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
433
434                         if(!pArrayArgsBuffer)
435                         {
436                                 psRIWriteProcListEntryOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
437                                 goto RIWriteProcListEntry_exit;
438                         }
439                 }
440         }
441
442         if (psRIWriteProcListEntryIN->ui32TextBSize != 0)
443         {
444                 uiTextBInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
445                 ui32NextOffset += psRIWriteProcListEntryIN->ui32TextBSize * sizeof(IMG_CHAR);
446         }
447
448                         /* Copy the data over */
449                         if (psRIWriteProcListEntryIN->ui32TextBSize * sizeof(IMG_CHAR) > 0)
450                         {
451                                 if ( OSCopyFromUser(NULL, uiTextBInt, psRIWriteProcListEntryIN->puiTextB, psRIWriteProcListEntryIN->ui32TextBSize * sizeof(IMG_CHAR)) != PVRSRV_OK )
452                                 {
453                                         psRIWriteProcListEntryOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
454
455                                         goto RIWriteProcListEntry_exit;
456                                 }
457                         }
458
459
460         psRIWriteProcListEntryOUT->eError =
461                 RIWriteProcListEntryKM(
462                                         psRIWriteProcListEntryIN->ui32TextBSize,
463                                         uiTextBInt,
464                                         psRIWriteProcListEntryIN->ui64Size,
465                                         psRIWriteProcListEntryIN->ui64BackedSize,
466                                         psRIWriteProcListEntryIN->ui64DevVAddr,
467                                         &psRIHandleInt);
468         /* Exit early if bridged call fails */
469         if(psRIWriteProcListEntryOUT->eError != PVRSRV_OK)
470         {
471                 goto RIWriteProcListEntry_exit;
472         }
473
474         /* Lock over handle creation. */
475         LockHandle();
476
477
478
479
480
481         psRIWriteProcListEntryOUT->eError = PVRSRVAllocHandleUnlocked(psConnection->psHandleBase,
482
483                                                         &psRIWriteProcListEntryOUT->hRIHandle,
484                                                         (void *) psRIHandleInt,
485                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE,
486                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
487                                                         ,(PFN_HANDLE_RELEASE)&RIDeleteMEMDESCEntryKM);
488         if (psRIWriteProcListEntryOUT->eError != PVRSRV_OK)
489         {
490                 UnlockHandle();
491                 goto RIWriteProcListEntry_exit;
492         }
493
494         /* Release now we have created handles. */
495         UnlockHandle();
496
497
498
499 RIWriteProcListEntry_exit:
500
501
502
503         if (psRIWriteProcListEntryOUT->eError != PVRSRV_OK)
504         {
505                 if (psRIHandleInt)
506                 {
507                         RIDeleteMEMDESCEntryKM(psRIHandleInt);
508                 }
509         }
510
511         /* Allocated space should be equal to the last updated offset */
512         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
513
514 #if defined(INTEGRITY_OS)
515         if(pArrayArgsBuffer)
516 #else
517         if(!bHaveEnoughSpace && pArrayArgsBuffer)
518 #endif
519                 OSFreeMemNoStats(pArrayArgsBuffer);
520
521
522         return 0;
523 }
524
525
526 static IMG_INT
527 PVRSRVBridgeRIUpdateMEMDESCAddr(IMG_UINT32 ui32DispatchTableEntry,
528                                           PVRSRV_BRIDGE_IN_RIUPDATEMEMDESCADDR *psRIUpdateMEMDESCAddrIN,
529                                           PVRSRV_BRIDGE_OUT_RIUPDATEMEMDESCADDR *psRIUpdateMEMDESCAddrOUT,
530                                          CONNECTION_DATA *psConnection)
531 {
532         IMG_HANDLE hRIHandle = psRIUpdateMEMDESCAddrIN->hRIHandle;
533         RI_HANDLE psRIHandleInt = NULL;
534
535
536
537
538
539
540
541         /* Lock over handle lookup. */
542         LockHandle();
543
544
545
546
547
548                                 {
549                                         /* Look up the address from the handle */
550                                         psRIUpdateMEMDESCAddrOUT->eError =
551                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
552                                                                                         (void **) &psRIHandleInt,
553                                                                                         hRIHandle,
554                                                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE,
555                                                                                         IMG_TRUE);
556                                         if(psRIUpdateMEMDESCAddrOUT->eError != PVRSRV_OK)
557                                         {
558                                                 UnlockHandle();
559                                                 goto RIUpdateMEMDESCAddr_exit;
560                                         }
561                                 }
562         /* Release now we have looked up handles. */
563         UnlockHandle();
564
565         psRIUpdateMEMDESCAddrOUT->eError =
566                 RIUpdateMEMDESCAddrKM(
567                                         psRIHandleInt,
568                                         psRIUpdateMEMDESCAddrIN->sAddr);
569
570
571
572
573 RIUpdateMEMDESCAddr_exit:
574
575         /* Lock over handle lookup cleanup. */
576         LockHandle();
577
578
579
580
581
582
583                                 {
584                                         /* Unreference the previously looked up handle */
585                                                 if(psRIHandleInt)
586                                                 {
587                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
588                                                                                         hRIHandle,
589                                                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE);
590                                                 }
591                                 }
592         /* Release now we have cleaned up look up handles. */
593         UnlockHandle();
594
595
596         return 0;
597 }
598
599
600 static IMG_INT
601 PVRSRVBridgeRIUpdateMEMDESCPinning(IMG_UINT32 ui32DispatchTableEntry,
602                                           PVRSRV_BRIDGE_IN_RIUPDATEMEMDESCPINNING *psRIUpdateMEMDESCPinningIN,
603                                           PVRSRV_BRIDGE_OUT_RIUPDATEMEMDESCPINNING *psRIUpdateMEMDESCPinningOUT,
604                                          CONNECTION_DATA *psConnection)
605 {
606         IMG_HANDLE hRIHandle = psRIUpdateMEMDESCPinningIN->hRIHandle;
607         RI_HANDLE psRIHandleInt = NULL;
608
609
610
611
612
613
614
615         /* Lock over handle lookup. */
616         LockHandle();
617
618
619
620
621
622                                 {
623                                         /* Look up the address from the handle */
624                                         psRIUpdateMEMDESCPinningOUT->eError =
625                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
626                                                                                         (void **) &psRIHandleInt,
627                                                                                         hRIHandle,
628                                                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE,
629                                                                                         IMG_TRUE);
630                                         if(psRIUpdateMEMDESCPinningOUT->eError != PVRSRV_OK)
631                                         {
632                                                 UnlockHandle();
633                                                 goto RIUpdateMEMDESCPinning_exit;
634                                         }
635                                 }
636         /* Release now we have looked up handles. */
637         UnlockHandle();
638
639         psRIUpdateMEMDESCPinningOUT->eError =
640                 RIUpdateMEMDESCPinningKM(
641                                         psRIHandleInt,
642                                         psRIUpdateMEMDESCPinningIN->bIsPinned);
643
644
645
646
647 RIUpdateMEMDESCPinning_exit:
648
649         /* Lock over handle lookup cleanup. */
650         LockHandle();
651
652
653
654
655
656
657                                 {
658                                         /* Unreference the previously looked up handle */
659                                                 if(psRIHandleInt)
660                                                 {
661                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
662                                                                                         hRIHandle,
663                                                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE);
664                                                 }
665                                 }
666         /* Release now we have cleaned up look up handles. */
667         UnlockHandle();
668
669
670         return 0;
671 }
672
673
674 static IMG_INT
675 PVRSRVBridgeRIUpdateMEMDESCBacking(IMG_UINT32 ui32DispatchTableEntry,
676                                           PVRSRV_BRIDGE_IN_RIUPDATEMEMDESCBACKING *psRIUpdateMEMDESCBackingIN,
677                                           PVRSRV_BRIDGE_OUT_RIUPDATEMEMDESCBACKING *psRIUpdateMEMDESCBackingOUT,
678                                          CONNECTION_DATA *psConnection)
679 {
680         IMG_HANDLE hRIHandle = psRIUpdateMEMDESCBackingIN->hRIHandle;
681         RI_HANDLE psRIHandleInt = NULL;
682
683
684
685
686
687
688
689         /* Lock over handle lookup. */
690         LockHandle();
691
692
693
694
695
696                                 {
697                                         /* Look up the address from the handle */
698                                         psRIUpdateMEMDESCBackingOUT->eError =
699                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
700                                                                                         (void **) &psRIHandleInt,
701                                                                                         hRIHandle,
702                                                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE,
703                                                                                         IMG_TRUE);
704                                         if(psRIUpdateMEMDESCBackingOUT->eError != PVRSRV_OK)
705                                         {
706                                                 UnlockHandle();
707                                                 goto RIUpdateMEMDESCBacking_exit;
708                                         }
709                                 }
710         /* Release now we have looked up handles. */
711         UnlockHandle();
712
713         psRIUpdateMEMDESCBackingOUT->eError =
714                 RIUpdateMEMDESCBackingKM(
715                                         psRIHandleInt,
716                                         psRIUpdateMEMDESCBackingIN->i32NumModified);
717
718
719
720
721 RIUpdateMEMDESCBacking_exit:
722
723         /* Lock over handle lookup cleanup. */
724         LockHandle();
725
726
727
728
729
730
731                                 {
732                                         /* Unreference the previously looked up handle */
733                                                 if(psRIHandleInt)
734                                                 {
735                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
736                                                                                         hRIHandle,
737                                                                                         PVRSRV_HANDLE_TYPE_RI_HANDLE);
738                                                 }
739                                 }
740         /* Release now we have cleaned up look up handles. */
741         UnlockHandle();
742
743
744         return 0;
745 }
746
747
748 static IMG_INT
749 PVRSRVBridgeRIDeleteMEMDESCEntry(IMG_UINT32 ui32DispatchTableEntry,
750                                           PVRSRV_BRIDGE_IN_RIDELETEMEMDESCENTRY *psRIDeleteMEMDESCEntryIN,
751                                           PVRSRV_BRIDGE_OUT_RIDELETEMEMDESCENTRY *psRIDeleteMEMDESCEntryOUT,
752                                          CONNECTION_DATA *psConnection)
753 {
754
755
756
757
758
759
760
761
762
763         /* Lock over handle destruction. */
764         LockHandle();
765
766
767
768
769
770         psRIDeleteMEMDESCEntryOUT->eError =
771                 PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
772                                         (IMG_HANDLE) psRIDeleteMEMDESCEntryIN->hRIHandle,
773                                         PVRSRV_HANDLE_TYPE_RI_HANDLE);
774         if ((psRIDeleteMEMDESCEntryOUT->eError != PVRSRV_OK) &&
775             (psRIDeleteMEMDESCEntryOUT->eError != PVRSRV_ERROR_RETRY))
776         {
777                 PVR_DPF((PVR_DBG_ERROR,
778                         "PVRSRVBridgeRIDeleteMEMDESCEntry: %s",
779                         PVRSRVGetErrorStringKM(psRIDeleteMEMDESCEntryOUT->eError)));
780                 PVR_ASSERT(0);
781                 UnlockHandle();
782                 goto RIDeleteMEMDESCEntry_exit;
783         }
784
785         /* Release now we have destroyed handles. */
786         UnlockHandle();
787
788
789
790 RIDeleteMEMDESCEntry_exit:
791
792
793
794
795         return 0;
796 }
797
798
799 static IMG_INT
800 PVRSRVBridgeRIDumpList(IMG_UINT32 ui32DispatchTableEntry,
801                                           PVRSRV_BRIDGE_IN_RIDUMPLIST *psRIDumpListIN,
802                                           PVRSRV_BRIDGE_OUT_RIDUMPLIST *psRIDumpListOUT,
803                                          CONNECTION_DATA *psConnection)
804 {
805         IMG_HANDLE hPMRHandle = psRIDumpListIN->hPMRHandle;
806         PMR * psPMRHandleInt = NULL;
807
808
809
810
811
812
813
814         /* Lock over handle lookup. */
815         LockHandle();
816
817
818
819
820
821                                 {
822                                         /* Look up the address from the handle */
823                                         psRIDumpListOUT->eError =
824                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
825                                                                                         (void **) &psPMRHandleInt,
826                                                                                         hPMRHandle,
827                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR,
828                                                                                         IMG_TRUE);
829                                         if(psRIDumpListOUT->eError != PVRSRV_OK)
830                                         {
831                                                 UnlockHandle();
832                                                 goto RIDumpList_exit;
833                                         }
834                                 }
835         /* Release now we have looked up handles. */
836         UnlockHandle();
837
838         psRIDumpListOUT->eError =
839                 RIDumpListKM(
840                                         psPMRHandleInt);
841
842
843
844
845 RIDumpList_exit:
846
847         /* Lock over handle lookup cleanup. */
848         LockHandle();
849
850
851
852
853
854
855                                 {
856                                         /* Unreference the previously looked up handle */
857                                                 if(psPMRHandleInt)
858                                                 {
859                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
860                                                                                         hPMRHandle,
861                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
862                                                 }
863                                 }
864         /* Release now we have cleaned up look up handles. */
865         UnlockHandle();
866
867
868         return 0;
869 }
870
871
872 static IMG_INT
873 PVRSRVBridgeRIDumpAll(IMG_UINT32 ui32DispatchTableEntry,
874                                           PVRSRV_BRIDGE_IN_RIDUMPALL *psRIDumpAllIN,
875                                           PVRSRV_BRIDGE_OUT_RIDUMPALL *psRIDumpAllOUT,
876                                          CONNECTION_DATA *psConnection)
877 {
878
879
880
881         PVR_UNREFERENCED_PARAMETER(psConnection);
882         PVR_UNREFERENCED_PARAMETER(psRIDumpAllIN);
883
884
885
886
887
888         psRIDumpAllOUT->eError =
889                 RIDumpAllKM(
890                                         );
891
892
893
894
895
896
897
898
899         return 0;
900 }
901
902
903 static IMG_INT
904 PVRSRVBridgeRIDumpProcess(IMG_UINT32 ui32DispatchTableEntry,
905                                           PVRSRV_BRIDGE_IN_RIDUMPPROCESS *psRIDumpProcessIN,
906                                           PVRSRV_BRIDGE_OUT_RIDUMPPROCESS *psRIDumpProcessOUT,
907                                          CONNECTION_DATA *psConnection)
908 {
909
910
911
912         PVR_UNREFERENCED_PARAMETER(psConnection);
913
914
915
916
917
918         psRIDumpProcessOUT->eError =
919                 RIDumpProcessKM(
920                                         psRIDumpProcessIN->ui32Pid);
921
922
923
924
925
926
927
928
929         return 0;
930 }
931
932
933
934
935 /* *************************************************************************** 
936  * Server bridge dispatch related glue 
937  */
938
939 static IMG_BOOL bUseLock = IMG_TRUE;
940
941 PVRSRV_ERROR InitRIBridge(void);
942 PVRSRV_ERROR DeinitRIBridge(void);
943
944 /*
945  * Register all RI functions with services
946  */
947 PVRSRV_ERROR InitRIBridge(void)
948 {
949
950         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIWRITEPMRENTRY, PVRSRVBridgeRIWritePMREntry,
951                                         NULL, bUseLock);
952
953         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIWRITEMEMDESCENTRY, PVRSRVBridgeRIWriteMEMDESCEntry,
954                                         NULL, bUseLock);
955
956         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIWRITEPROCLISTENTRY, PVRSRVBridgeRIWriteProcListEntry,
957                                         NULL, bUseLock);
958
959         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIUPDATEMEMDESCADDR, PVRSRVBridgeRIUpdateMEMDESCAddr,
960                                         NULL, bUseLock);
961
962         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIUPDATEMEMDESCPINNING, PVRSRVBridgeRIUpdateMEMDESCPinning,
963                                         NULL, bUseLock);
964
965         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIUPDATEMEMDESCBACKING, PVRSRVBridgeRIUpdateMEMDESCBacking,
966                                         NULL, bUseLock);
967
968         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIDELETEMEMDESCENTRY, PVRSRVBridgeRIDeleteMEMDESCEntry,
969                                         NULL, bUseLock);
970
971         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIDUMPLIST, PVRSRVBridgeRIDumpList,
972                                         NULL, bUseLock);
973
974         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIDUMPALL, PVRSRVBridgeRIDumpAll,
975                                         NULL, bUseLock);
976
977         SetDispatchTableEntry(PVRSRV_BRIDGE_RI, PVRSRV_BRIDGE_RI_RIDUMPPROCESS, PVRSRVBridgeRIDumpProcess,
978                                         NULL, bUseLock);
979
980
981         return PVRSRV_OK;
982 }
983
984 /*
985  * Unregister all ri functions with services
986  */
987 PVRSRV_ERROR DeinitRIBridge(void)
988 {
989         return PVRSRV_OK;
990 }