Merge branch 'linux-linaro-lsk-v4.4-android' of git://git.linaro.org/kernel/linux...
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue / generated / srvcore_bridge / server_srvcore_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for srvcore
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for srvcore
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 "srvcore.h"
50 #include "pvrsrv.h"
51
52
53 #include "common_srvcore_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  * Bridge proxy functions
71  */
72
73 static PVRSRV_ERROR
74 ReleaseGlobalEventObjectResManProxy(IMG_HANDLE hResmanItem)
75 {
76         PVRSRV_ERROR eError;
77
78         eError = ResManFreeResByPtr(hResmanItem);
79
80         /* Freeing a resource should never fail... */
81         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
82
83         return eError;
84 }
85
86 static PVRSRV_ERROR
87 EventObjectCloseResManProxy(IMG_HANDLE hResmanItem)
88 {
89         PVRSRV_ERROR eError;
90
91         eError = ResManFreeResByPtr(hResmanItem);
92
93         /* Freeing a resource should never fail... */
94         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
95
96         return eError;
97 }
98
99
100
101 /* ***************************************************************************
102  * Server-side bridge entry points
103  */
104  
105 static IMG_INT
106 PVRSRVBridgeConnect(IMG_UINT32 ui32BridgeID,
107                                          PVRSRV_BRIDGE_IN_CONNECT *psConnectIN,
108                                          PVRSRV_BRIDGE_OUT_CONNECT *psConnectOUT,
109                                          CONNECTION_DATA *psConnection)
110 {
111
112         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_CONNECT);
113
114         PVR_UNREFERENCED_PARAMETER(psConnection);
115
116
117
118
119         psConnectOUT->eError =
120                 PVRSRVConnectKM(psConnection,
121                                         psConnectIN->ui32Flags,
122                                         psConnectIN->ui32ClientBuildOptions,
123                                         psConnectIN->ui32ClientDDKVersion,
124                                         psConnectIN->ui32ClientDDKBuild,
125                                         &psConnectOUT->ui8KernelArch,
126                                         &psConnectOUT->ui32Log2PageSize);
127
128
129
130
131         return 0;
132 }
133
134 static IMG_INT
135 PVRSRVBridgeDisconnect(IMG_UINT32 ui32BridgeID,
136                                          PVRSRV_BRIDGE_IN_DISCONNECT *psDisconnectIN,
137                                          PVRSRV_BRIDGE_OUT_DISCONNECT *psDisconnectOUT,
138                                          CONNECTION_DATA *psConnection)
139 {
140
141         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_DISCONNECT);
142
143         PVR_UNREFERENCED_PARAMETER(psConnection);
144         PVR_UNREFERENCED_PARAMETER(psDisconnectIN);
145
146
147
148
149         psDisconnectOUT->eError =
150                 PVRSRVDisconnectKM(
151                                         );
152
153
154
155
156         return 0;
157 }
158
159 static IMG_INT
160 PVRSRVBridgeEnumerateDevices(IMG_UINT32 ui32BridgeID,
161                                          PVRSRV_BRIDGE_IN_ENUMERATEDEVICES *psEnumerateDevicesIN,
162                                          PVRSRV_BRIDGE_OUT_ENUMERATEDEVICES *psEnumerateDevicesOUT,
163                                          CONNECTION_DATA *psConnection)
164 {
165         PVRSRV_DEVICE_TYPE *peDeviceTypeInt = IMG_NULL;
166         PVRSRV_DEVICE_CLASS *peDeviceClassInt = IMG_NULL;
167         IMG_UINT32 *pui32DeviceIndexInt = IMG_NULL;
168
169         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_ENUMERATEDEVICES);
170
171         PVR_UNREFERENCED_PARAMETER(psConnection);
172         PVR_UNREFERENCED_PARAMETER(psEnumerateDevicesIN);
173
174         psEnumerateDevicesOUT->peDeviceType = psEnumerateDevicesIN->peDeviceType;
175         psEnumerateDevicesOUT->peDeviceClass = psEnumerateDevicesIN->peDeviceClass;
176         psEnumerateDevicesOUT->pui32DeviceIndex = psEnumerateDevicesIN->pui32DeviceIndex;
177
178
179         
180         {
181                 peDeviceTypeInt = OSAllocMem(PVRSRV_MAX_DEVICES * sizeof(PVRSRV_DEVICE_TYPE));
182                 if (!peDeviceTypeInt)
183                 {
184                         psEnumerateDevicesOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
185         
186                         goto EnumerateDevices_exit;
187                 }
188         }
189
190         
191         {
192                 peDeviceClassInt = OSAllocMem(PVRSRV_MAX_DEVICES * sizeof(PVRSRV_DEVICE_CLASS));
193                 if (!peDeviceClassInt)
194                 {
195                         psEnumerateDevicesOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
196         
197                         goto EnumerateDevices_exit;
198                 }
199         }
200
201         
202         {
203                 pui32DeviceIndexInt = OSAllocMem(PVRSRV_MAX_DEVICES * sizeof(IMG_UINT32));
204                 if (!pui32DeviceIndexInt)
205                 {
206                         psEnumerateDevicesOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
207         
208                         goto EnumerateDevices_exit;
209                 }
210         }
211
212
213         psEnumerateDevicesOUT->eError =
214                 PVRSRVEnumerateDevicesKM(
215                                         &psEnumerateDevicesOUT->ui32NumDevices,
216                                         peDeviceTypeInt,
217                                         peDeviceClassInt,
218                                         pui32DeviceIndexInt);
219
220
221         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psEnumerateDevicesOUT->peDeviceType, (PVRSRV_MAX_DEVICES * sizeof(PVRSRV_DEVICE_TYPE))) 
222                 || (OSCopyToUser(NULL, psEnumerateDevicesOUT->peDeviceType, peDeviceTypeInt,
223                 (PVRSRV_MAX_DEVICES * sizeof(PVRSRV_DEVICE_TYPE))) != PVRSRV_OK) )
224         {
225                 psEnumerateDevicesOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
226
227                 goto EnumerateDevices_exit;
228         }
229
230         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psEnumerateDevicesOUT->peDeviceClass, (PVRSRV_MAX_DEVICES * sizeof(PVRSRV_DEVICE_CLASS))) 
231                 || (OSCopyToUser(NULL, psEnumerateDevicesOUT->peDeviceClass, peDeviceClassInt,
232                 (PVRSRV_MAX_DEVICES * sizeof(PVRSRV_DEVICE_CLASS))) != PVRSRV_OK) )
233         {
234                 psEnumerateDevicesOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
235
236                 goto EnumerateDevices_exit;
237         }
238
239         if ( !OSAccessOK(PVR_VERIFY_WRITE, (IMG_VOID*) psEnumerateDevicesOUT->pui32DeviceIndex, (PVRSRV_MAX_DEVICES * sizeof(IMG_UINT32))) 
240                 || (OSCopyToUser(NULL, psEnumerateDevicesOUT->pui32DeviceIndex, pui32DeviceIndexInt,
241                 (PVRSRV_MAX_DEVICES * sizeof(IMG_UINT32))) != PVRSRV_OK) )
242         {
243                 psEnumerateDevicesOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
244
245                 goto EnumerateDevices_exit;
246         }
247
248
249 EnumerateDevices_exit:
250         if (peDeviceTypeInt)
251                 OSFreeMem(peDeviceTypeInt);
252         if (peDeviceClassInt)
253                 OSFreeMem(peDeviceClassInt);
254         if (pui32DeviceIndexInt)
255                 OSFreeMem(pui32DeviceIndexInt);
256
257         return 0;
258 }
259
260 static IMG_INT
261 PVRSRVBridgeAcquireDeviceData(IMG_UINT32 ui32BridgeID,
262                                          PVRSRV_BRIDGE_IN_ACQUIREDEVICEDATA *psAcquireDeviceDataIN,
263                                          PVRSRV_BRIDGE_OUT_ACQUIREDEVICEDATA *psAcquireDeviceDataOUT,
264                                          CONNECTION_DATA *psConnection)
265 {
266         IMG_HANDLE hDevCookieInt = IMG_NULL;
267
268         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_ACQUIREDEVICEDATA);
269
270
271
272
273
274         psAcquireDeviceDataOUT->eError =
275                 PVRSRVAcquireDeviceDataKM(
276                                         psAcquireDeviceDataIN->ui32DevIndex,
277                                         psAcquireDeviceDataIN->eDeviceType,
278                                         &hDevCookieInt);
279         /* Exit early if bridged call fails */
280         if(psAcquireDeviceDataOUT->eError != PVRSRV_OK)
281         {
282                 goto AcquireDeviceData_exit;
283         }
284
285         psAcquireDeviceDataOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
286                                                         &psAcquireDeviceDataOUT->hDevCookie,
287                                                         (IMG_HANDLE) hDevCookieInt,
288                                                         PVRSRV_HANDLE_TYPE_DEV_NODE,
289                                                         PVRSRV_HANDLE_ALLOC_FLAG_SHARED
290                                                         );
291         if (psAcquireDeviceDataOUT->eError != PVRSRV_OK)
292         {
293                 goto AcquireDeviceData_exit;
294         }
295
296
297 AcquireDeviceData_exit:
298         if (psAcquireDeviceDataOUT->eError != PVRSRV_OK)
299         {
300         }
301
302
303         return 0;
304 }
305
306 static IMG_INT
307 PVRSRVBridgeReleaseDeviceData(IMG_UINT32 ui32BridgeID,
308                                          PVRSRV_BRIDGE_IN_RELEASEDEVICEDATA *psReleaseDeviceDataIN,
309                                          PVRSRV_BRIDGE_OUT_RELEASEDEVICEDATA *psReleaseDeviceDataOUT,
310                                          CONNECTION_DATA *psConnection)
311 {
312         IMG_HANDLE hDevCookieInt = IMG_NULL;
313
314         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_RELEASEDEVICEDATA);
315
316
317
318
319
320                                 {
321                                         /* Look up the address from the handle */
322                                         psReleaseDeviceDataOUT->eError =
323                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
324                                                                                         (IMG_HANDLE *) &hDevCookieInt,
325                                                                                         psReleaseDeviceDataIN->hDevCookie,
326                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
327                                         if(psReleaseDeviceDataOUT->eError != PVRSRV_OK)
328                                         {
329                                                 goto ReleaseDeviceData_exit;
330                                         }
331
332                                 }
333
334         psReleaseDeviceDataOUT->eError =
335                 PVRSRVReleaseDeviceDataKM(
336                                         hDevCookieInt);
337         /* Exit early if bridged call fails */
338         if(psReleaseDeviceDataOUT->eError != PVRSRV_OK)
339         {
340                 goto ReleaseDeviceData_exit;
341         }
342
343         psReleaseDeviceDataOUT->eError =
344                 PVRSRVReleaseHandle(psConnection->psHandleBase,
345                                         (IMG_HANDLE) psReleaseDeviceDataIN->hDevCookie,
346                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
347
348
349 ReleaseDeviceData_exit:
350
351         return 0;
352 }
353
354 static IMG_INT
355 PVRSRVBridgeInitSrvDisconnect(IMG_UINT32 ui32BridgeID,
356                                          PVRSRV_BRIDGE_IN_INITSRVDISCONNECT *psInitSrvDisconnectIN,
357                                          PVRSRV_BRIDGE_OUT_INITSRVDISCONNECT *psInitSrvDisconnectOUT,
358                                          CONNECTION_DATA *psConnection)
359 {
360
361         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_INITSRVDISCONNECT);
362
363
364
365
366
367         psInitSrvDisconnectOUT->eError =
368                 PVRSRVInitSrvDisconnectKM(psConnection,
369                                         psInitSrvDisconnectIN->bInitSuccesful,
370                                         psInitSrvDisconnectIN->ui32ClientBuildOptions);
371
372
373
374
375         return 0;
376 }
377
378 static IMG_INT
379 PVRSRVBridgeAcquireGlobalEventObject(IMG_UINT32 ui32BridgeID,
380                                          PVRSRV_BRIDGE_IN_ACQUIREGLOBALEVENTOBJECT *psAcquireGlobalEventObjectIN,
381                                          PVRSRV_BRIDGE_OUT_ACQUIREGLOBALEVENTOBJECT *psAcquireGlobalEventObjectOUT,
382                                          CONNECTION_DATA *psConnection)
383 {
384         IMG_HANDLE hGlobalEventObjectInt = IMG_NULL;
385         IMG_HANDLE hGlobalEventObjectInt2 = IMG_NULL;
386
387         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_ACQUIREGLOBALEVENTOBJECT);
388
389         PVR_UNREFERENCED_PARAMETER(psAcquireGlobalEventObjectIN);
390
391
392
393
394         psAcquireGlobalEventObjectOUT->eError =
395                 AcquireGlobalEventObjectServer(
396                                         &hGlobalEventObjectInt);
397         /* Exit early if bridged call fails */
398         if(psAcquireGlobalEventObjectOUT->eError != PVRSRV_OK)
399         {
400                 goto AcquireGlobalEventObject_exit;
401         }
402
403         /* Create a resman item and overwrite the handle with it */
404         hGlobalEventObjectInt2 = ResManRegisterRes(psConnection->hResManContext,
405                                                                                                 RESMAN_TYPE_SHARED_EVENT_OBJECT,
406                                                                                                 hGlobalEventObjectInt,
407                                                                                                 (RESMAN_FREE_FN)&ReleaseGlobalEventObjectServer);
408         if (hGlobalEventObjectInt2 == IMG_NULL)
409         {
410                 psAcquireGlobalEventObjectOUT->eError = PVRSRV_ERROR_UNABLE_TO_REGISTER_RESOURCE;
411                 goto AcquireGlobalEventObject_exit;
412         }
413         psAcquireGlobalEventObjectOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
414                                                         &psAcquireGlobalEventObjectOUT->hGlobalEventObject,
415                                                         (IMG_HANDLE) hGlobalEventObjectInt2,
416                                                         PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT,
417                                                         PVRSRV_HANDLE_ALLOC_FLAG_SHARED
418                                                         );
419         if (psAcquireGlobalEventObjectOUT->eError != PVRSRV_OK)
420         {
421                 goto AcquireGlobalEventObject_exit;
422         }
423
424
425 AcquireGlobalEventObject_exit:
426         if (psAcquireGlobalEventObjectOUT->eError != PVRSRV_OK)
427         {
428                 /* If we have a valid resman item we should undo the bridge function by freeing the resman item */
429                 if (hGlobalEventObjectInt2)
430                 {
431                         PVRSRV_ERROR eError = ResManFreeResByPtr(hGlobalEventObjectInt2);
432
433                         /* Freeing a resource should never fail... */
434                         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
435                 }
436                 else if (hGlobalEventObjectInt)
437                 {
438                         ReleaseGlobalEventObjectServer(hGlobalEventObjectInt);
439                 }
440         }
441
442
443         return 0;
444 }
445
446 static IMG_INT
447 PVRSRVBridgeReleaseGlobalEventObject(IMG_UINT32 ui32BridgeID,
448                                          PVRSRV_BRIDGE_IN_RELEASEGLOBALEVENTOBJECT *psReleaseGlobalEventObjectIN,
449                                          PVRSRV_BRIDGE_OUT_RELEASEGLOBALEVENTOBJECT *psReleaseGlobalEventObjectOUT,
450                                          CONNECTION_DATA *psConnection)
451 {
452         IMG_HANDLE hGlobalEventObjectInt2 = IMG_NULL;
453
454         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_RELEASEGLOBALEVENTOBJECT);
455
456
457
458
459
460                                 {
461                                         /* Look up the address from the handle */
462                                         psReleaseGlobalEventObjectOUT->eError =
463                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
464                                                                                         (IMG_HANDLE *) &hGlobalEventObjectInt2,
465                                                                                         psReleaseGlobalEventObjectIN->hGlobalEventObject,
466                                                                                         PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT);
467                                         if(psReleaseGlobalEventObjectOUT->eError != PVRSRV_OK)
468                                         {
469                                                 goto ReleaseGlobalEventObject_exit;
470                                         }
471
472                                 }
473
474         psReleaseGlobalEventObjectOUT->eError = ReleaseGlobalEventObjectResManProxy(hGlobalEventObjectInt2);
475         /* Exit early if bridged call fails */
476         if(psReleaseGlobalEventObjectOUT->eError != PVRSRV_OK)
477         {
478                 goto ReleaseGlobalEventObject_exit;
479         }
480
481         psReleaseGlobalEventObjectOUT->eError =
482                 PVRSRVReleaseHandle(psConnection->psHandleBase,
483                                         (IMG_HANDLE) psReleaseGlobalEventObjectIN->hGlobalEventObject,
484                                         PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT);
485
486
487 ReleaseGlobalEventObject_exit:
488
489         return 0;
490 }
491
492 static IMG_INT
493 PVRSRVBridgeEventObjectOpen(IMG_UINT32 ui32BridgeID,
494                                          PVRSRV_BRIDGE_IN_EVENTOBJECTOPEN *psEventObjectOpenIN,
495                                          PVRSRV_BRIDGE_OUT_EVENTOBJECTOPEN *psEventObjectOpenOUT,
496                                          CONNECTION_DATA *psConnection)
497 {
498         IMG_HANDLE hEventObjectInt = IMG_NULL;
499         IMG_HANDLE hEventObjectInt2 = IMG_NULL;
500         IMG_HANDLE hOSEventInt = IMG_NULL;
501         IMG_HANDLE hOSEventInt2 = IMG_NULL;
502
503         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_EVENTOBJECTOPEN);
504
505
506
507
508
509                                 {
510                                         /* Look up the address from the handle */
511                                         psEventObjectOpenOUT->eError =
512                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
513                                                                                         (IMG_HANDLE *) &hEventObjectInt2,
514                                                                                         psEventObjectOpenIN->hEventObject,
515                                                                                         PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT);
516                                         if(psEventObjectOpenOUT->eError != PVRSRV_OK)
517                                         {
518                                                 goto EventObjectOpen_exit;
519                                         }
520
521                                         /* Look up the data from the resman address */
522                                         psEventObjectOpenOUT->eError = ResManFindPrivateDataByPtr(hEventObjectInt2, (IMG_VOID **) &hEventObjectInt);
523
524                                         if(psEventObjectOpenOUT->eError != PVRSRV_OK)
525                                         {
526                                                 goto EventObjectOpen_exit;
527                                         }
528                                 }
529
530         psEventObjectOpenOUT->eError =
531                 OSEventObjectOpen(
532                                         hEventObjectInt,
533                                         &hOSEventInt);
534         /* Exit early if bridged call fails */
535         if(psEventObjectOpenOUT->eError != PVRSRV_OK)
536         {
537                 goto EventObjectOpen_exit;
538         }
539
540         /* Create a resman item and overwrite the handle with it */
541         hOSEventInt2 = ResManRegisterRes(psConnection->hResManContext,
542                                                                                                 RESMAN_TYPE_EVENT_OBJECT,
543                                                                                                 hOSEventInt,
544                                                                                                 (RESMAN_FREE_FN)&OSEventObjectClose);
545         if (hOSEventInt2 == IMG_NULL)
546         {
547                 psEventObjectOpenOUT->eError = PVRSRV_ERROR_UNABLE_TO_REGISTER_RESOURCE;
548                 goto EventObjectOpen_exit;
549         }
550         psEventObjectOpenOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
551                                                         &psEventObjectOpenOUT->hOSEvent,
552                                                         (IMG_HANDLE) hOSEventInt2,
553                                                         PVRSRV_HANDLE_TYPE_EVENT_OBJECT_CONNECT,
554                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
555                                                         );
556         if (psEventObjectOpenOUT->eError != PVRSRV_OK)
557         {
558                 goto EventObjectOpen_exit;
559         }
560
561
562 EventObjectOpen_exit:
563         if (psEventObjectOpenOUT->eError != PVRSRV_OK)
564         {
565                 /* If we have a valid resman item we should undo the bridge function by freeing the resman item */
566                 if (hOSEventInt2)
567                 {
568                         PVRSRV_ERROR eError = ResManFreeResByPtr(hOSEventInt2);
569
570                         /* Freeing a resource should never fail... */
571                         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
572                 }
573                 else if (hOSEventInt)
574                 {
575                         OSEventObjectClose(hOSEventInt);
576                 }
577         }
578
579
580         return 0;
581 }
582
583 static IMG_INT
584 PVRSRVBridgeEventObjectWait(IMG_UINT32 ui32BridgeID,
585                                          PVRSRV_BRIDGE_IN_EVENTOBJECTWAIT *psEventObjectWaitIN,
586                                          PVRSRV_BRIDGE_OUT_EVENTOBJECTWAIT *psEventObjectWaitOUT,
587                                          CONNECTION_DATA *psConnection)
588 {
589         IMG_HANDLE hOSEventKMInt = IMG_NULL;
590         IMG_HANDLE hOSEventKMInt2 = IMG_NULL;
591
592         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_EVENTOBJECTWAIT);
593
594
595
596
597
598                                 {
599                                         /* Look up the address from the handle */
600                                         psEventObjectWaitOUT->eError =
601                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
602                                                                                         (IMG_HANDLE *) &hOSEventKMInt2,
603                                                                                         psEventObjectWaitIN->hOSEventKM,
604                                                                                         PVRSRV_HANDLE_TYPE_EVENT_OBJECT_CONNECT);
605                                         if(psEventObjectWaitOUT->eError != PVRSRV_OK)
606                                         {
607                                                 goto EventObjectWait_exit;
608                                         }
609
610                                         /* Look up the data from the resman address */
611                                         psEventObjectWaitOUT->eError = ResManFindPrivateDataByPtr(hOSEventKMInt2, (IMG_VOID **) &hOSEventKMInt);
612
613                                         if(psEventObjectWaitOUT->eError != PVRSRV_OK)
614                                         {
615                                                 goto EventObjectWait_exit;
616                                         }
617                                 }
618
619         psEventObjectWaitOUT->eError =
620                 OSEventObjectWait(
621                                         hOSEventKMInt);
622
623
624
625 EventObjectWait_exit:
626
627         return 0;
628 }
629
630 static IMG_INT
631 PVRSRVBridgeEventObjectClose(IMG_UINT32 ui32BridgeID,
632                                          PVRSRV_BRIDGE_IN_EVENTOBJECTCLOSE *psEventObjectCloseIN,
633                                          PVRSRV_BRIDGE_OUT_EVENTOBJECTCLOSE *psEventObjectCloseOUT,
634                                          CONNECTION_DATA *psConnection)
635 {
636         IMG_HANDLE hOSEventKMInt2 = IMG_NULL;
637
638         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_EVENTOBJECTCLOSE);
639
640
641
642
643
644                                 {
645                                         /* Look up the address from the handle */
646                                         psEventObjectCloseOUT->eError =
647                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
648                                                                                         (IMG_HANDLE *) &hOSEventKMInt2,
649                                                                                         psEventObjectCloseIN->hOSEventKM,
650                                                                                         PVRSRV_HANDLE_TYPE_EVENT_OBJECT_CONNECT);
651                                         if(psEventObjectCloseOUT->eError != PVRSRV_OK)
652                                         {
653                                                 goto EventObjectClose_exit;
654                                         }
655
656                                 }
657
658         psEventObjectCloseOUT->eError = EventObjectCloseResManProxy(hOSEventKMInt2);
659         /* Exit early if bridged call fails */
660         if(psEventObjectCloseOUT->eError != PVRSRV_OK)
661         {
662                 goto EventObjectClose_exit;
663         }
664
665         psEventObjectCloseOUT->eError =
666                 PVRSRVReleaseHandle(psConnection->psHandleBase,
667                                         (IMG_HANDLE) psEventObjectCloseIN->hOSEventKM,
668                                         PVRSRV_HANDLE_TYPE_EVENT_OBJECT_CONNECT);
669
670
671 EventObjectClose_exit:
672
673         return 0;
674 }
675
676 static IMG_INT
677 PVRSRVBridgeDumpDebugInfo(IMG_UINT32 ui32BridgeID,
678                                          PVRSRV_BRIDGE_IN_DUMPDEBUGINFO *psDumpDebugInfoIN,
679                                          PVRSRV_BRIDGE_OUT_DUMPDEBUGINFO *psDumpDebugInfoOUT,
680                                          CONNECTION_DATA *psConnection)
681 {
682
683         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_DUMPDEBUGINFO);
684
685         PVR_UNREFERENCED_PARAMETER(psConnection);
686
687
688
689
690         psDumpDebugInfoOUT->eError =
691                 PVRSRVDumpDebugInfoKM(
692                                         psDumpDebugInfoIN->ui32ui32VerbLevel);
693
694
695
696
697         return 0;
698 }
699
700 static IMG_INT
701 PVRSRVBridgeGetDevClockSpeed(IMG_UINT32 ui32BridgeID,
702                                          PVRSRV_BRIDGE_IN_GETDEVCLOCKSPEED *psGetDevClockSpeedIN,
703                                          PVRSRV_BRIDGE_OUT_GETDEVCLOCKSPEED *psGetDevClockSpeedOUT,
704                                          CONNECTION_DATA *psConnection)
705 {
706         IMG_HANDLE hDevNodeInt = IMG_NULL;
707
708         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_GETDEVCLOCKSPEED);
709
710
711
712
713
714                                 {
715                                         /* Look up the address from the handle */
716                                         psGetDevClockSpeedOUT->eError =
717                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
718                                                                                         (IMG_HANDLE *) &hDevNodeInt,
719                                                                                         psGetDevClockSpeedIN->hDevNode,
720                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
721                                         if(psGetDevClockSpeedOUT->eError != PVRSRV_OK)
722                                         {
723                                                 goto GetDevClockSpeed_exit;
724                                         }
725
726                                 }
727
728         psGetDevClockSpeedOUT->eError =
729                 PVRSRVGetDevClockSpeedKM(
730                                         hDevNodeInt,
731                                         &psGetDevClockSpeedOUT->ui32ui32RGXClockSpeed);
732
733
734
735 GetDevClockSpeed_exit:
736
737         return 0;
738 }
739
740 static IMG_INT
741 PVRSRVBridgeHWOpTimeout(IMG_UINT32 ui32BridgeID,
742                                          PVRSRV_BRIDGE_IN_HWOPTIMEOUT *psHWOpTimeoutIN,
743                                          PVRSRV_BRIDGE_OUT_HWOPTIMEOUT *psHWOpTimeoutOUT,
744                                          CONNECTION_DATA *psConnection)
745 {
746
747         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_HWOPTIMEOUT);
748
749         PVR_UNREFERENCED_PARAMETER(psConnection);
750         PVR_UNREFERENCED_PARAMETER(psHWOpTimeoutIN);
751
752
753
754
755         psHWOpTimeoutOUT->eError =
756                 PVRSRVHWOpTimeoutKM(
757                                         );
758
759
760
761
762         return 0;
763 }
764
765 static IMG_INT
766 PVRSRVBridgeKickDevices(IMG_UINT32 ui32BridgeID,
767                                          PVRSRV_BRIDGE_IN_KICKDEVICES *psKickDevicesIN,
768                                          PVRSRV_BRIDGE_OUT_KICKDEVICES *psKickDevicesOUT,
769                                          CONNECTION_DATA *psConnection)
770 {
771
772         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_KICKDEVICES);
773
774         PVR_UNREFERENCED_PARAMETER(psConnection);
775         PVR_UNREFERENCED_PARAMETER(psKickDevicesIN);
776
777
778
779
780         psKickDevicesOUT->eError =
781                 PVRSRVKickDevicesKM(
782                                         );
783
784
785
786
787         return 0;
788 }
789
790 static IMG_INT
791 PVRSRVBridgeResetHWRLogs(IMG_UINT32 ui32BridgeID,
792                                          PVRSRV_BRIDGE_IN_RESETHWRLOGS *psResetHWRLogsIN,
793                                          PVRSRV_BRIDGE_OUT_RESETHWRLOGS *psResetHWRLogsOUT,
794                                          CONNECTION_DATA *psConnection)
795 {
796         IMG_HANDLE hDevNodeInt = IMG_NULL;
797
798         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_RESETHWRLOGS);
799
800
801
802
803
804                                 {
805                                         /* Look up the address from the handle */
806                                         psResetHWRLogsOUT->eError =
807                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
808                                                                                         (IMG_HANDLE *) &hDevNodeInt,
809                                                                                         psResetHWRLogsIN->hDevNode,
810                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
811                                         if(psResetHWRLogsOUT->eError != PVRSRV_OK)
812                                         {
813                                                 goto ResetHWRLogs_exit;
814                                         }
815
816                                 }
817
818         psResetHWRLogsOUT->eError =
819                 PVRSRVResetHWRLogsKM(
820                                         hDevNodeInt);
821
822
823
824 ResetHWRLogs_exit:
825
826         return 0;
827 }
828
829 static IMG_INT
830 PVRSRVBridgeSoftReset(IMG_UINT32 ui32BridgeID,
831                                          PVRSRV_BRIDGE_IN_SOFTRESET *psSoftResetIN,
832                                          PVRSRV_BRIDGE_OUT_SOFTRESET *psSoftResetOUT,
833                                          CONNECTION_DATA *psConnection)
834 {
835         IMG_HANDLE hDevNodeInt = IMG_NULL;
836
837         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SRVCORE_SOFTRESET);
838
839
840
841
842
843                                 {
844                                         /* Look up the address from the handle */
845                                         psSoftResetOUT->eError =
846                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
847                                                                                         (IMG_HANDLE *) &hDevNodeInt,
848                                                                                         psSoftResetIN->hDevNode,
849                                                                                         PVRSRV_HANDLE_TYPE_DEV_NODE);
850                                         if(psSoftResetOUT->eError != PVRSRV_OK)
851                                         {
852                                                 goto SoftReset_exit;
853                                         }
854
855                                 }
856
857         psSoftResetOUT->eError =
858                 PVRSRVSoftResetKM(
859                                         hDevNodeInt,
860                                         psSoftResetIN->ui64ResetValue);
861
862
863
864 SoftReset_exit:
865
866         return 0;
867 }
868
869
870
871 /* *************************************************************************** 
872  * Server bridge dispatch related glue 
873  */
874  
875 PVRSRV_ERROR RegisterSRVCOREFunctions(IMG_VOID);
876 IMG_VOID UnregisterSRVCOREFunctions(IMG_VOID);
877
878 /*
879  * Register all SRVCORE functions with services
880  */
881 PVRSRV_ERROR RegisterSRVCOREFunctions(IMG_VOID)
882 {
883         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_CONNECT, PVRSRVBridgeConnect);
884         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_DISCONNECT, PVRSRVBridgeDisconnect);
885         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_ENUMERATEDEVICES, PVRSRVBridgeEnumerateDevices);
886         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_ACQUIREDEVICEDATA, PVRSRVBridgeAcquireDeviceData);
887         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_RELEASEDEVICEDATA, PVRSRVBridgeReleaseDeviceData);
888         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_INITSRVDISCONNECT, PVRSRVBridgeInitSrvDisconnect);
889         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_ACQUIREGLOBALEVENTOBJECT, PVRSRVBridgeAcquireGlobalEventObject);
890         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_RELEASEGLOBALEVENTOBJECT, PVRSRVBridgeReleaseGlobalEventObject);
891         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_EVENTOBJECTOPEN, PVRSRVBridgeEventObjectOpen);
892         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_EVENTOBJECTWAIT, PVRSRVBridgeEventObjectWait);
893         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_EVENTOBJECTCLOSE, PVRSRVBridgeEventObjectClose);
894         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_DUMPDEBUGINFO, PVRSRVBridgeDumpDebugInfo);
895         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_GETDEVCLOCKSPEED, PVRSRVBridgeGetDevClockSpeed);
896         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_HWOPTIMEOUT, PVRSRVBridgeHWOpTimeout);
897         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_KICKDEVICES, PVRSRVBridgeKickDevices);
898         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_RESETHWRLOGS, PVRSRVBridgeResetHWRLogs);
899         SetDispatchTableEntry(PVRSRV_BRIDGE_SRVCORE_SOFTRESET, PVRSRVBridgeSoftReset);
900
901         return PVRSRV_OK;
902 }
903
904 /*
905  * Unregister all srvcore functions with services
906  */
907 IMG_VOID UnregisterSRVCOREFunctions(IMG_VOID)
908 {
909 }