RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / generated / rgxinit_bridge / server_rgxinit_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for rgxinit
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for rgxinit
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 "rgxinit.h"
50
51
52 #include "common_rgxinit_bridge.h"
53
54 #include "allocmem.h"
55 #include "pvr_debug.h"
56 #include "connection_server.h"
57 #include "pvr_bridge.h"
58 #include "rgx_bridge.h"
59 #include "srvcore.h"
60 #include "handle.h"
61
62 #if defined (SUPPORT_AUTH)
63 #include "osauth.h"
64 #endif
65
66 #include <linux/slab.h>
67
68
69 static PVRSRV_ERROR ReleaseFWCodeAllocServerExportCookie(IMG_VOID *pvData)
70 {
71         PVR_UNREFERENCED_PARAMETER(pvData);
72
73         return PVRSRV_OK;
74 }
75 static PVRSRV_ERROR ReleaseFWDataAllocServerExportCookie(IMG_VOID *pvData)
76 {
77         PVR_UNREFERENCED_PARAMETER(pvData);
78
79         return PVRSRV_OK;
80 }
81 static PVRSRV_ERROR ReleaseFWCorememAllocServerExportCookie(IMG_VOID *pvData)
82 {
83         PVR_UNREFERENCED_PARAMETER(pvData);
84
85         return PVRSRV_OK;
86 }
87 static PVRSRV_ERROR ReleaseHWPerfDataAllocServerExportCookie(IMG_VOID *pvData)
88 {
89         PVR_UNREFERENCED_PARAMETER(pvData);
90
91         return PVRSRV_OK;
92 }
93
94
95 /* ***************************************************************************
96  * Server-side bridge entry points
97  */
98  
99 static IMG_INT
100 PVRSRVBridgeRGXInitAllocFWImgMem(IMG_UINT32 ui32DispatchTableEntry,
101                                           PVRSRV_BRIDGE_IN_RGXINITALLOCFWIMGMEM *psRGXInitAllocFWImgMemIN,
102                                           PVRSRV_BRIDGE_OUT_RGXINITALLOCFWIMGMEM *psRGXInitAllocFWImgMemOUT,
103                                          CONNECTION_DATA *psConnection)
104 {
105         IMG_HANDLE hDevNodeInt = IMG_NULL;
106         DEVMEM_EXPORTCOOKIE * psFWCodeAllocServerExportCookieInt = IMG_NULL;
107         DEVMEM_EXPORTCOOKIE * psFWDataAllocServerExportCookieInt = IMG_NULL;
108         DEVMEM_EXPORTCOOKIE * psFWCorememAllocServerExportCookieInt = IMG_NULL;
109
110
111
112
113
114
115
116                                 {
117                                         /* Look up the address from the handle */
118                                         psRGXInitAllocFWImgMemOUT->eError =
119                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
120                                                                                         (IMG_VOID **) &hDevNodeInt,
121                                                                                         psRGXInitAllocFWImgMemIN->hDevNode,
122                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
123                                         if(psRGXInitAllocFWImgMemOUT->eError != PVRSRV_OK)
124                                         {
125                                                 goto RGXInitAllocFWImgMem_exit;
126                                         }
127                                 }
128
129
130         psRGXInitAllocFWImgMemOUT->eError =
131                 PVRSRVRGXInitAllocFWImgMemKM(
132                                         hDevNodeInt,
133                                         psRGXInitAllocFWImgMemIN->uiFWCodeLen,
134                                         psRGXInitAllocFWImgMemIN->uiFWDataLen,
135                                         psRGXInitAllocFWImgMemIN->uiFWCoremem,
136                                         &psFWCodeAllocServerExportCookieInt,
137                                         &psRGXInitAllocFWImgMemOUT->sFWCodeDevVAddrBase,
138                                         &psFWDataAllocServerExportCookieInt,
139                                         &psRGXInitAllocFWImgMemOUT->sFWDataDevVAddrBase,
140                                         &psFWCorememAllocServerExportCookieInt,
141                                         &psRGXInitAllocFWImgMemOUT->sFWCorememDevVAddrBase,
142                                         &psRGXInitAllocFWImgMemOUT->sFWCorememMetaVAddrBase);
143         /* Exit early if bridged call fails */
144         if(psRGXInitAllocFWImgMemOUT->eError != PVRSRV_OK)
145         {
146                 goto RGXInitAllocFWImgMem_exit;
147         }
148
149
150         psRGXInitAllocFWImgMemOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
151                                                         &psRGXInitAllocFWImgMemOUT->hFWCodeAllocServerExportCookie,
152                                                         (IMG_VOID *) psFWCodeAllocServerExportCookieInt,
153                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE,
154                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
155                                                         ,(PFN_HANDLE_RELEASE)&ReleaseFWCodeAllocServerExportCookie);
156         if (psRGXInitAllocFWImgMemOUT->eError != PVRSRV_OK)
157         {
158                 goto RGXInitAllocFWImgMem_exit;
159         }
160
161
162         psRGXInitAllocFWImgMemOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
163                                                         &psRGXInitAllocFWImgMemOUT->hFWDataAllocServerExportCookie,
164                                                         (IMG_VOID *) psFWDataAllocServerExportCookieInt,
165                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE,
166                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
167                                                         ,(PFN_HANDLE_RELEASE)&ReleaseFWDataAllocServerExportCookie);
168         if (psRGXInitAllocFWImgMemOUT->eError != PVRSRV_OK)
169         {
170                 goto RGXInitAllocFWImgMem_exit;
171         }
172
173
174         psRGXInitAllocFWImgMemOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
175                                                         &psRGXInitAllocFWImgMemOUT->hFWCorememAllocServerExportCookie,
176                                                         (IMG_VOID *) psFWCorememAllocServerExportCookieInt,
177                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE,
178                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
179                                                         ,(PFN_HANDLE_RELEASE)&ReleaseFWCorememAllocServerExportCookie);
180         if (psRGXInitAllocFWImgMemOUT->eError != PVRSRV_OK)
181         {
182                 goto RGXInitAllocFWImgMem_exit;
183         }
184
185
186
187
188 RGXInitAllocFWImgMem_exit:
189         if (psRGXInitAllocFWImgMemOUT->eError != PVRSRV_OK)
190         {
191         }
192
193
194         return 0;
195 }
196
197 static IMG_INT
198 PVRSRVBridgeRGXInitFirmware(IMG_UINT32 ui32DispatchTableEntry,
199                                           PVRSRV_BRIDGE_IN_RGXINITFIRMWARE *psRGXInitFirmwareIN,
200                                           PVRSRV_BRIDGE_OUT_RGXINITFIRMWARE *psRGXInitFirmwareOUT,
201                                          CONNECTION_DATA *psConnection)
202 {
203         IMG_HANDLE hDevNodeInt = IMG_NULL;
204         IMG_UINT32 *ui32RGXFWAlignChecksInt = IMG_NULL;
205         DEVMEM_EXPORTCOOKIE * psHWPerfDataAllocServerExportCookieInt = IMG_NULL;
206
207
208
209
210         if (psRGXInitFirmwareIN->ui32RGXFWAlignChecksSize != 0)
211         {
212                 ui32RGXFWAlignChecksInt = OSAllocMem(psRGXInitFirmwareIN->ui32RGXFWAlignChecksSize * sizeof(IMG_UINT32));
213                 if (!ui32RGXFWAlignChecksInt)
214                 {
215                         psRGXInitFirmwareOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
216         
217                         goto RGXInitFirmware_exit;
218                 }
219         }
220
221                         /* Copy the data over */
222                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXInitFirmwareIN->pui32RGXFWAlignChecks, psRGXInitFirmwareIN->ui32RGXFWAlignChecksSize * sizeof(IMG_UINT32))
223                                 || (OSCopyFromUser(NULL, ui32RGXFWAlignChecksInt, psRGXInitFirmwareIN->pui32RGXFWAlignChecks,
224                                 psRGXInitFirmwareIN->ui32RGXFWAlignChecksSize * sizeof(IMG_UINT32)) != PVRSRV_OK) )
225                         {
226                                 psRGXInitFirmwareOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
227
228                                 goto RGXInitFirmware_exit;
229                         }
230
231
232
233                                 {
234                                         /* Look up the address from the handle */
235                                         psRGXInitFirmwareOUT->eError =
236                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
237                                                                                         (IMG_VOID **) &hDevNodeInt,
238                                                                                         psRGXInitFirmwareIN->hDevNode,
239                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
240                                         if(psRGXInitFirmwareOUT->eError != PVRSRV_OK)
241                                         {
242                                                 goto RGXInitFirmware_exit;
243                                         }
244                                 }
245
246
247         psRGXInitFirmwareOUT->eError =
248                 PVRSRVRGXInitFirmwareKM(
249                                         hDevNodeInt,
250                                         &psRGXInitFirmwareOUT->spsRGXFwInit,
251                                         psRGXInitFirmwareIN->bEnableSignatureChecks,
252                                         psRGXInitFirmwareIN->ui32SignatureChecksBufSize,
253                                         psRGXInitFirmwareIN->ui32HWPerfFWBufSizeKB,
254                                         psRGXInitFirmwareIN->ui64HWPerfFilter,
255                                         psRGXInitFirmwareIN->ui32RGXFWAlignChecksSize,
256                                         ui32RGXFWAlignChecksInt,
257                                         psRGXInitFirmwareIN->ui32ConfigFlags,
258                                         psRGXInitFirmwareIN->ui32LogType,
259                                         psRGXInitFirmwareIN->ui32FilterFlags,
260                                         psRGXInitFirmwareIN->ui32JonesDisableMask,
261                                         psRGXInitFirmwareIN->ui32ui32HWRDebugDumpLimit,
262                                         &psRGXInitFirmwareIN->sClientBVNC,
263                                         psRGXInitFirmwareIN->ui32HWPerfCountersDataSize,
264                                         &psHWPerfDataAllocServerExportCookieInt,
265                                         psRGXInitFirmwareIN->eRGXRDPowerIslandConf);
266         /* Exit early if bridged call fails */
267         if(psRGXInitFirmwareOUT->eError != PVRSRV_OK)
268         {
269                 goto RGXInitFirmware_exit;
270         }
271
272
273         psRGXInitFirmwareOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
274                                                         &psRGXInitFirmwareOUT->hHWPerfDataAllocServerExportCookie,
275                                                         (IMG_VOID *) psHWPerfDataAllocServerExportCookieInt,
276                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE,
277                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
278                                                         ,(PFN_HANDLE_RELEASE)&ReleaseHWPerfDataAllocServerExportCookie);
279         if (psRGXInitFirmwareOUT->eError != PVRSRV_OK)
280         {
281                 goto RGXInitFirmware_exit;
282         }
283
284
285
286
287 RGXInitFirmware_exit:
288         if (psRGXInitFirmwareOUT->eError != PVRSRV_OK)
289         {
290         }
291
292         if (ui32RGXFWAlignChecksInt)
293                 OSFreeMem(ui32RGXFWAlignChecksInt);
294
295         return 0;
296 }
297
298 static IMG_INT
299 PVRSRVBridgeRGXInitLoadFWImage(IMG_UINT32 ui32DispatchTableEntry,
300                                           PVRSRV_BRIDGE_IN_RGXINITLOADFWIMAGE *psRGXInitLoadFWImageIN,
301                                           PVRSRV_BRIDGE_OUT_RGXINITLOADFWIMAGE *psRGXInitLoadFWImageOUT,
302                                          CONNECTION_DATA *psConnection)
303 {
304         PMR * psImgDestImportInt = IMG_NULL;
305         PMR * psImgSrcImportInt = IMG_NULL;
306         PMR * psSigImportInt = IMG_NULL;
307
308
309
310
311
312
313
314                                 {
315                                         /* Look up the address from the handle */
316                                         psRGXInitLoadFWImageOUT->eError =
317                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
318                                                                                         (IMG_VOID **) &psImgDestImportInt,
319                                                                                         psRGXInitLoadFWImageIN->hImgDestImport,
320                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
321                                         if(psRGXInitLoadFWImageOUT->eError != PVRSRV_OK)
322                                         {
323                                                 goto RGXInitLoadFWImage_exit;
324                                         }
325                                 }
326
327
328                                 {
329                                         /* Look up the address from the handle */
330                                         psRGXInitLoadFWImageOUT->eError =
331                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
332                                                                                         (IMG_VOID **) &psImgSrcImportInt,
333                                                                                         psRGXInitLoadFWImageIN->hImgSrcImport,
334                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
335                                         if(psRGXInitLoadFWImageOUT->eError != PVRSRV_OK)
336                                         {
337                                                 goto RGXInitLoadFWImage_exit;
338                                         }
339                                 }
340
341
342                                 {
343                                         /* Look up the address from the handle */
344                                         psRGXInitLoadFWImageOUT->eError =
345                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
346                                                                                         (IMG_VOID **) &psSigImportInt,
347                                                                                         psRGXInitLoadFWImageIN->hSigImport,
348                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
349                                         if(psRGXInitLoadFWImageOUT->eError != PVRSRV_OK)
350                                         {
351                                                 goto RGXInitLoadFWImage_exit;
352                                         }
353                                 }
354
355
356         psRGXInitLoadFWImageOUT->eError =
357                 PVRSRVRGXInitLoadFWImageKM(
358                                         psImgDestImportInt,
359                                         psImgSrcImportInt,
360                                         psRGXInitLoadFWImageIN->ui64ImgLen,
361                                         psSigImportInt,
362                                         psRGXInitLoadFWImageIN->ui64SigLen);
363
364
365
366
367 RGXInitLoadFWImage_exit:
368
369         return 0;
370 }
371
372 static IMG_INT
373 PVRSRVBridgeRGXInitDevPart2(IMG_UINT32 ui32DispatchTableEntry,
374                                           PVRSRV_BRIDGE_IN_RGXINITDEVPART2 *psRGXInitDevPart2IN,
375                                           PVRSRV_BRIDGE_OUT_RGXINITDEVPART2 *psRGXInitDevPart2OUT,
376                                          CONNECTION_DATA *psConnection)
377 {
378         IMG_HANDLE hDevNodeInt = IMG_NULL;
379         RGX_INIT_COMMAND *psInitScriptInt = IMG_NULL;
380         RGX_INIT_COMMAND *psDbgScriptInt = IMG_NULL;
381         RGX_INIT_COMMAND *psDbgBusScriptInt = IMG_NULL;
382         RGX_INIT_COMMAND *psDeinitScriptInt = IMG_NULL;
383         DEVMEM_EXPORTCOOKIE * psFWCodeAllocServerExportCookieInt = IMG_NULL;
384         DEVMEM_EXPORTCOOKIE * psFWDataAllocServerExportCookieInt = IMG_NULL;
385         DEVMEM_EXPORTCOOKIE * psFWCorememAllocServerExportCookieInt = IMG_NULL;
386         DEVMEM_EXPORTCOOKIE * psHWPerfDataAllocServerExportCookieInt = IMG_NULL;
387
388
389
390
391         
392         {
393                 psInitScriptInt = OSAllocMem(RGX_MAX_INIT_COMMANDS * sizeof(RGX_INIT_COMMAND));
394                 if (!psInitScriptInt)
395                 {
396                         psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
397         
398                         goto RGXInitDevPart2_exit;
399                 }
400         }
401
402                         /* Copy the data over */
403                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXInitDevPart2IN->psInitScript, RGX_MAX_INIT_COMMANDS * sizeof(RGX_INIT_COMMAND))
404                                 || (OSCopyFromUser(NULL, psInitScriptInt, psRGXInitDevPart2IN->psInitScript,
405                                 RGX_MAX_INIT_COMMANDS * sizeof(RGX_INIT_COMMAND)) != PVRSRV_OK) )
406                         {
407                                 psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
408
409                                 goto RGXInitDevPart2_exit;
410                         }
411         
412         {
413                 psDbgScriptInt = OSAllocMem(RGX_MAX_DEBUG_COMMANDS * sizeof(RGX_INIT_COMMAND));
414                 if (!psDbgScriptInt)
415                 {
416                         psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
417         
418                         goto RGXInitDevPart2_exit;
419                 }
420         }
421
422                         /* Copy the data over */
423                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXInitDevPart2IN->psDbgScript, RGX_MAX_DEBUG_COMMANDS * sizeof(RGX_INIT_COMMAND))
424                                 || (OSCopyFromUser(NULL, psDbgScriptInt, psRGXInitDevPart2IN->psDbgScript,
425                                 RGX_MAX_DEBUG_COMMANDS * sizeof(RGX_INIT_COMMAND)) != PVRSRV_OK) )
426                         {
427                                 psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
428
429                                 goto RGXInitDevPart2_exit;
430                         }
431         
432         {
433                 psDbgBusScriptInt = OSAllocMem(RGX_MAX_DBGBUS_COMMANDS * sizeof(RGX_INIT_COMMAND));
434                 if (!psDbgBusScriptInt)
435                 {
436                         psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
437         
438                         goto RGXInitDevPart2_exit;
439                 }
440         }
441
442                         /* Copy the data over */
443                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXInitDevPart2IN->psDbgBusScript, RGX_MAX_DBGBUS_COMMANDS * sizeof(RGX_INIT_COMMAND))
444                                 || (OSCopyFromUser(NULL, psDbgBusScriptInt, psRGXInitDevPart2IN->psDbgBusScript,
445                                 RGX_MAX_DBGBUS_COMMANDS * sizeof(RGX_INIT_COMMAND)) != PVRSRV_OK) )
446                         {
447                                 psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
448
449                                 goto RGXInitDevPart2_exit;
450                         }
451         
452         {
453                 psDeinitScriptInt = OSAllocMem(RGX_MAX_DEINIT_COMMANDS * sizeof(RGX_INIT_COMMAND));
454                 if (!psDeinitScriptInt)
455                 {
456                         psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
457         
458                         goto RGXInitDevPart2_exit;
459                 }
460         }
461
462                         /* Copy the data over */
463                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psRGXInitDevPart2IN->psDeinitScript, RGX_MAX_DEINIT_COMMANDS * sizeof(RGX_INIT_COMMAND))
464                                 || (OSCopyFromUser(NULL, psDeinitScriptInt, psRGXInitDevPart2IN->psDeinitScript,
465                                 RGX_MAX_DEINIT_COMMANDS * sizeof(RGX_INIT_COMMAND)) != PVRSRV_OK) )
466                         {
467                                 psRGXInitDevPart2OUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
468
469                                 goto RGXInitDevPart2_exit;
470                         }
471
472
473
474                                 {
475                                         /* Look up the address from the handle */
476                                         psRGXInitDevPart2OUT->eError =
477                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
478                                                                                         (IMG_VOID **) &hDevNodeInt,
479                                                                                         psRGXInitDevPart2IN->hDevNode,
480                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
481                                         if(psRGXInitDevPart2OUT->eError != PVRSRV_OK)
482                                         {
483                                                 goto RGXInitDevPart2_exit;
484                                         }
485                                 }
486
487
488                                 {
489                                         /* Look up the address from the handle */
490                                         psRGXInitDevPart2OUT->eError =
491                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
492                                                                                         (IMG_VOID **) &psFWCodeAllocServerExportCookieInt,
493                                                                                         psRGXInitDevPart2IN->hFWCodeAllocServerExportCookie,
494                                                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
495                                         if(psRGXInitDevPart2OUT->eError != PVRSRV_OK)
496                                         {
497                                                 goto RGXInitDevPart2_exit;
498                                         }
499                                 }
500
501
502                                 {
503                                         /* Look up the address from the handle */
504                                         psRGXInitDevPart2OUT->eError =
505                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
506                                                                                         (IMG_VOID **) &psFWDataAllocServerExportCookieInt,
507                                                                                         psRGXInitDevPart2IN->hFWDataAllocServerExportCookie,
508                                                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
509                                         if(psRGXInitDevPart2OUT->eError != PVRSRV_OK)
510                                         {
511                                                 goto RGXInitDevPart2_exit;
512                                         }
513                                 }
514
515
516                                 {
517                                         /* Look up the address from the handle */
518                                         psRGXInitDevPart2OUT->eError =
519                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
520                                                                                         (IMG_VOID **) &psFWCorememAllocServerExportCookieInt,
521                                                                                         psRGXInitDevPart2IN->hFWCorememAllocServerExportCookie,
522                                                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
523                                         if(psRGXInitDevPart2OUT->eError != PVRSRV_OK)
524                                         {
525                                                 goto RGXInitDevPart2_exit;
526                                         }
527                                 }
528
529
530                                 {
531                                         /* Look up the address from the handle */
532                                         psRGXInitDevPart2OUT->eError =
533                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
534                                                                                         (IMG_VOID **) &psHWPerfDataAllocServerExportCookieInt,
535                                                                                         psRGXInitDevPart2IN->hHWPerfDataAllocServerExportCookie,
536                                                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
537                                         if(psRGXInitDevPart2OUT->eError != PVRSRV_OK)
538                                         {
539                                                 goto RGXInitDevPart2_exit;
540                                         }
541                                 }
542
543
544         psRGXInitDevPart2OUT->eError =
545                 PVRSRVRGXInitDevPart2KM(
546                                         hDevNodeInt,
547                                         psInitScriptInt,
548                                         psDbgScriptInt,
549                                         psDbgBusScriptInt,
550                                         psDeinitScriptInt,
551                                         psRGXInitDevPart2IN->ui32ui32KernelCatBaseIdReg,
552                                         psRGXInitDevPart2IN->ui32KernelCatBaseId,
553                                         psRGXInitDevPart2IN->ui32KernelCatBaseReg,
554                                         psRGXInitDevPart2IN->ui32KernelCatBaseWordSize,
555                                         psRGXInitDevPart2IN->ui32KernelCatBaseAlignShift,
556                                         psRGXInitDevPart2IN->ui32KernelCatBaseShift,
557                                         psRGXInitDevPart2IN->ui64KernelCatBaseMask,
558                                         psRGXInitDevPart2IN->ui32DeviceFlags,
559                                         psRGXInitDevPart2IN->ui32RGXActivePMConf,
560                                         psFWCodeAllocServerExportCookieInt,
561                                         psFWDataAllocServerExportCookieInt,
562                                         psFWCorememAllocServerExportCookieInt,
563                                         psHWPerfDataAllocServerExportCookieInt);
564
565
566         psRGXInitDevPart2OUT->eError =
567                 PVRSRVReleaseHandle(psConnection->psHandleBase,
568                                         (IMG_HANDLE) psRGXInitDevPart2IN->hFWCodeAllocServerExportCookie,
569                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
570         if ((psRGXInitDevPart2OUT->eError != PVRSRV_OK) && (psRGXInitDevPart2OUT->eError != PVRSRV_ERROR_RETRY))
571         {
572                 PVR_ASSERT(0);
573                 goto RGXInitDevPart2_exit;
574         }
575
576         psRGXInitDevPart2OUT->eError =
577                 PVRSRVReleaseHandle(psConnection->psHandleBase,
578                                         (IMG_HANDLE) psRGXInitDevPart2IN->hFWDataAllocServerExportCookie,
579                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
580         if ((psRGXInitDevPart2OUT->eError != PVRSRV_OK) && (psRGXInitDevPart2OUT->eError != PVRSRV_ERROR_RETRY))
581         {
582                 PVR_ASSERT(0);
583                 goto RGXInitDevPart2_exit;
584         }
585
586         psRGXInitDevPart2OUT->eError =
587                 PVRSRVReleaseHandle(psConnection->psHandleBase,
588                                         (IMG_HANDLE) psRGXInitDevPart2IN->hFWCorememAllocServerExportCookie,
589                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
590         if ((psRGXInitDevPart2OUT->eError != PVRSRV_OK) && (psRGXInitDevPart2OUT->eError != PVRSRV_ERROR_RETRY))
591         {
592                 PVR_ASSERT(0);
593                 goto RGXInitDevPart2_exit;
594         }
595
596         psRGXInitDevPart2OUT->eError =
597                 PVRSRVReleaseHandle(psConnection->psHandleBase,
598                                         (IMG_HANDLE) psRGXInitDevPart2IN->hHWPerfDataAllocServerExportCookie,
599                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE);
600         if ((psRGXInitDevPart2OUT->eError != PVRSRV_OK) && (psRGXInitDevPart2OUT->eError != PVRSRV_ERROR_RETRY))
601         {
602                 PVR_ASSERT(0);
603                 goto RGXInitDevPart2_exit;
604         }
605
606
607
608 RGXInitDevPart2_exit:
609         if (psInitScriptInt)
610                 OSFreeMem(psInitScriptInt);
611         if (psDbgScriptInt)
612                 OSFreeMem(psDbgScriptInt);
613         if (psDbgBusScriptInt)
614                 OSFreeMem(psDbgBusScriptInt);
615         if (psDeinitScriptInt)
616                 OSFreeMem(psDeinitScriptInt);
617
618         return 0;
619 }
620
621 static IMG_INT
622 PVRSRVBridgeGPUVIRTPopulateLMASubArenas(IMG_UINT32 ui32DispatchTableEntry,
623                                           PVRSRV_BRIDGE_IN_GPUVIRTPOPULATELMASUBARENAS *psGPUVIRTPopulateLMASubArenasIN,
624                                           PVRSRV_BRIDGE_OUT_GPUVIRTPOPULATELMASUBARENAS *psGPUVIRTPopulateLMASubArenasOUT,
625                                          CONNECTION_DATA *psConnection)
626 {
627         IMG_HANDLE hDevNodeInt = IMG_NULL;
628         IMG_UINT32 *ui32ElementsInt = IMG_NULL;
629
630
631
632
633         if (psGPUVIRTPopulateLMASubArenasIN->ui32NumElements != 0)
634         {
635                 ui32ElementsInt = OSAllocMem(psGPUVIRTPopulateLMASubArenasIN->ui32NumElements * sizeof(IMG_UINT32));
636                 if (!ui32ElementsInt)
637                 {
638                         psGPUVIRTPopulateLMASubArenasOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
639         
640                         goto GPUVIRTPopulateLMASubArenas_exit;
641                 }
642         }
643
644                         /* Copy the data over */
645                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psGPUVIRTPopulateLMASubArenasIN->pui32Elements, psGPUVIRTPopulateLMASubArenasIN->ui32NumElements * sizeof(IMG_UINT32))
646                                 || (OSCopyFromUser(NULL, ui32ElementsInt, psGPUVIRTPopulateLMASubArenasIN->pui32Elements,
647                                 psGPUVIRTPopulateLMASubArenasIN->ui32NumElements * sizeof(IMG_UINT32)) != PVRSRV_OK) )
648                         {
649                                 psGPUVIRTPopulateLMASubArenasOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
650
651                                 goto GPUVIRTPopulateLMASubArenas_exit;
652                         }
653
654
655
656                                 {
657                                         /* Look up the address from the handle */
658                                         psGPUVIRTPopulateLMASubArenasOUT->eError =
659                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
660                                                                                         (IMG_VOID **) &hDevNodeInt,
661                                                                                         psGPUVIRTPopulateLMASubArenasIN->hDevNode,
662                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
663                                         if(psGPUVIRTPopulateLMASubArenasOUT->eError != PVRSRV_OK)
664                                         {
665                                                 goto GPUVIRTPopulateLMASubArenas_exit;
666                                         }
667                                 }
668
669
670         psGPUVIRTPopulateLMASubArenasOUT->eError =
671                 PVRSRVGPUVIRTPopulateLMASubArenasKM(
672                                         hDevNodeInt,
673                                         psGPUVIRTPopulateLMASubArenasIN->ui32NumElements,
674                                         ui32ElementsInt);
675
676
677
678
679 GPUVIRTPopulateLMASubArenas_exit:
680         if (ui32ElementsInt)
681                 OSFreeMem(ui32ElementsInt);
682
683         return 0;
684 }
685
686
687
688 /* *************************************************************************** 
689  * Server bridge dispatch related glue 
690  */
691
692
693 PVRSRV_ERROR InitRGXINITBridge(IMG_VOID);
694 PVRSRV_ERROR DeinitRGXINITBridge(IMG_VOID);
695
696 /*
697  * Register all RGXINIT functions with services
698  */
699 PVRSRV_ERROR InitRGXINITBridge(IMG_VOID)
700 {
701
702         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXINIT, PVRSRV_BRIDGE_RGXINIT_RGXINITALLOCFWIMGMEM, PVRSRVBridgeRGXInitAllocFWImgMem,
703                                         IMG_NULL, IMG_NULL,
704                                         0, 0);
705
706         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXINIT, PVRSRV_BRIDGE_RGXINIT_RGXINITFIRMWARE, PVRSRVBridgeRGXInitFirmware,
707                                         IMG_NULL, IMG_NULL,
708                                         0, 0);
709
710         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXINIT, PVRSRV_BRIDGE_RGXINIT_RGXINITLOADFWIMAGE, PVRSRVBridgeRGXInitLoadFWImage,
711                                         IMG_NULL, IMG_NULL,
712                                         0, 0);
713
714         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXINIT, PVRSRV_BRIDGE_RGXINIT_RGXINITDEVPART2, PVRSRVBridgeRGXInitDevPart2,
715                                         IMG_NULL, IMG_NULL,
716                                         0, 0);
717
718         SetDispatchTableEntry(PVRSRV_BRIDGE_RGXINIT, PVRSRV_BRIDGE_RGXINIT_GPUVIRTPOPULATELMASUBARENAS, PVRSRVBridgeGPUVIRTPopulateLMASubArenas,
719                                         IMG_NULL, IMG_NULL,
720                                         0, 0);
721
722
723         return PVRSRV_OK;
724 }
725
726 /*
727  * Unregister all rgxinit functions with services
728  */
729 PVRSRV_ERROR DeinitRGXINITBridge(IMG_VOID)
730 {
731         return PVRSRV_OK;
732 }
733