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 / syncsexport_bridge / server_syncsexport_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for syncsexport
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for syncsexport
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #include <stddef.h>
45 #include <asm/uaccess.h>
46
47 #include "img_defs.h"
48
49 #include "sync_server.h"
50
51
52 #include "common_syncsexport_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  * Bridge proxy functions
70  */
71
72 static PVRSRV_ERROR
73 SyncPrimServerSecureUnexportResManProxy(IMG_HANDLE hResmanItem)
74 {
75         PVRSRV_ERROR eError;
76
77         eError = ResManFreeResByPtr(hResmanItem);
78
79         /* Freeing a resource should never fail... */
80         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
81
82         return eError;
83 }
84
85
86
87 /* ***************************************************************************
88  * Server-side bridge entry points
89  */
90  
91 static IMG_INT
92 PVRSRVBridgeSyncPrimServerSecureExport(IMG_UINT32 ui32BridgeID,
93                                          PVRSRV_BRIDGE_IN_SYNCPRIMSERVERSECUREEXPORT *psSyncPrimServerSecureExportIN,
94                                          PVRSRV_BRIDGE_OUT_SYNCPRIMSERVERSECUREEXPORT *psSyncPrimServerSecureExportOUT,
95                                          CONNECTION_DATA *psConnection)
96 {
97         SERVER_SYNC_PRIMITIVE * psSyncHandleInt = IMG_NULL;
98         IMG_HANDLE hSyncHandleInt2 = IMG_NULL;
99         SERVER_SYNC_EXPORT * psExportInt = IMG_NULL;
100         IMG_HANDLE hExportInt2 = IMG_NULL;
101         CONNECTION_DATA *psSecureConnection;
102
103         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SYNCSEXPORT_SYNCPRIMSERVERSECUREEXPORT);
104
105
106
107
108
109                                 {
110                                         /* Look up the address from the handle */
111                                         psSyncPrimServerSecureExportOUT->eError =
112                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
113                                                                                         (IMG_HANDLE *) &hSyncHandleInt2,
114                                                                                         psSyncPrimServerSecureExportIN->hSyncHandle,
115                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE);
116                                         if(psSyncPrimServerSecureExportOUT->eError != PVRSRV_OK)
117                                         {
118                                                 goto SyncPrimServerSecureExport_exit;
119                                         }
120
121                                         /* Look up the data from the resman address */
122                                         psSyncPrimServerSecureExportOUT->eError = ResManFindPrivateDataByPtr(hSyncHandleInt2, (IMG_VOID **) &psSyncHandleInt);
123
124                                         if(psSyncPrimServerSecureExportOUT->eError != PVRSRV_OK)
125                                         {
126                                                 goto SyncPrimServerSecureExport_exit;
127                                         }
128                                 }
129
130         psSyncPrimServerSecureExportOUT->eError =
131                 PVRSRVSyncPrimServerSecureExportKM(psConnection,
132                                         psSyncHandleInt,
133                                         &psSyncPrimServerSecureExportOUT->Export,
134                                         &psExportInt, &psSecureConnection);
135         /* Exit early if bridged call fails */
136         if(psSyncPrimServerSecureExportOUT->eError != PVRSRV_OK)
137         {
138                 goto SyncPrimServerSecureExport_exit;
139         }
140
141         /* Create a resman item and overwrite the handle with it */
142         hExportInt2 = ResManRegisterRes(psSecureConnection->hResManContext,
143                                                                                                 RESMAN_TYPE_SERVER_SYNC_EXPORT,
144                                                                                                 psExportInt,
145                                                                                                 (RESMAN_FREE_FN)&PVRSRVSyncPrimServerSecureUnexportKM);
146         if (hExportInt2 == IMG_NULL)
147         {
148                 psSyncPrimServerSecureExportOUT->eError = PVRSRV_ERROR_UNABLE_TO_REGISTER_RESOURCE;
149                 goto SyncPrimServerSecureExport_exit;
150         }
151
152
153 SyncPrimServerSecureExport_exit:
154         if (psSyncPrimServerSecureExportOUT->eError != PVRSRV_OK)
155         {
156                 /* If we have a valid resman item we should undo the bridge function by freeing the resman item */
157                 if (hExportInt2)
158                 {
159                         PVRSRV_ERROR eError = ResManFreeResByPtr(hExportInt2);
160
161                         /* Freeing a resource should never fail... */
162                         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
163                 }
164                 else if (psExportInt)
165                 {
166                         PVRSRVSyncPrimServerSecureUnexportKM(psExportInt);
167                 }
168         }
169
170
171         return 0;
172 }
173
174 static IMG_INT
175 PVRSRVBridgeSyncPrimServerSecureUnexport(IMG_UINT32 ui32BridgeID,
176                                          PVRSRV_BRIDGE_IN_SYNCPRIMSERVERSECUREUNEXPORT *psSyncPrimServerSecureUnexportIN,
177                                          PVRSRV_BRIDGE_OUT_SYNCPRIMSERVERSECUREUNEXPORT *psSyncPrimServerSecureUnexportOUT,
178                                          CONNECTION_DATA *psConnection)
179 {
180         IMG_HANDLE hExportInt2 = IMG_NULL;
181
182         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SYNCSEXPORT_SYNCPRIMSERVERSECUREUNEXPORT);
183
184
185
186
187
188                                 {
189                                         /* Look up the address from the handle */
190                                         psSyncPrimServerSecureUnexportOUT->eError =
191                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
192                                                                                         (IMG_HANDLE *) &hExportInt2,
193                                                                                         psSyncPrimServerSecureUnexportIN->hExport,
194                                                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_EXPORT);
195                                         if(psSyncPrimServerSecureUnexportOUT->eError != PVRSRV_OK)
196                                         {
197                                                 goto SyncPrimServerSecureUnexport_exit;
198                                         }
199
200                                 }
201
202         psSyncPrimServerSecureUnexportOUT->eError = SyncPrimServerSecureUnexportResManProxy(hExportInt2);
203         /* Exit early if bridged call fails */
204         if(psSyncPrimServerSecureUnexportOUT->eError != PVRSRV_OK)
205         {
206                 goto SyncPrimServerSecureUnexport_exit;
207         }
208
209         psSyncPrimServerSecureUnexportOUT->eError =
210                 PVRSRVReleaseHandle(psConnection->psHandleBase,
211                                         (IMG_HANDLE) psSyncPrimServerSecureUnexportIN->hExport,
212                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_EXPORT);
213
214
215 SyncPrimServerSecureUnexport_exit:
216
217         return 0;
218 }
219
220 static IMG_INT
221 PVRSRVBridgeSyncPrimServerSecureImport(IMG_UINT32 ui32BridgeID,
222                                          PVRSRV_BRIDGE_IN_SYNCPRIMSERVERSECUREIMPORT *psSyncPrimServerSecureImportIN,
223                                          PVRSRV_BRIDGE_OUT_SYNCPRIMSERVERSECUREIMPORT *psSyncPrimServerSecureImportOUT,
224                                          CONNECTION_DATA *psConnection)
225 {
226         SERVER_SYNC_PRIMITIVE * psSyncHandleInt = IMG_NULL;
227         IMG_HANDLE hSyncHandleInt2 = IMG_NULL;
228
229         PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SYNCSEXPORT_SYNCPRIMSERVERSECUREIMPORT);
230
231
232
233
234
235         psSyncPrimServerSecureImportOUT->eError =
236                 PVRSRVSyncPrimServerSecureImportKM(
237                                         psSyncPrimServerSecureImportIN->Export,
238                                         &psSyncHandleInt,
239                                         &psSyncPrimServerSecureImportOUT->ui32SyncPrimVAddr);
240         /* Exit early if bridged call fails */
241         if(psSyncPrimServerSecureImportOUT->eError != PVRSRV_OK)
242         {
243                 goto SyncPrimServerSecureImport_exit;
244         }
245
246         /* Create a resman item and overwrite the handle with it */
247         hSyncHandleInt2 = ResManRegisterRes(psConnection->hResManContext,
248                                                                                                 RESMAN_TYPE_SERVER_SYNC_PRIMITIVE,
249                                                                                                 psSyncHandleInt,
250                                                                                                 (RESMAN_FREE_FN)&PVRSRVServerSyncFreeKM);
251         if (hSyncHandleInt2 == IMG_NULL)
252         {
253                 psSyncPrimServerSecureImportOUT->eError = PVRSRV_ERROR_UNABLE_TO_REGISTER_RESOURCE;
254                 goto SyncPrimServerSecureImport_exit;
255         }
256         psSyncPrimServerSecureImportOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
257                                                         &psSyncPrimServerSecureImportOUT->hSyncHandle,
258                                                         (IMG_HANDLE) hSyncHandleInt2,
259                                                         PVRSRV_HANDLE_TYPE_SERVER_SYNC_PRIMITIVE,
260                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
261                                                         );
262         if (psSyncPrimServerSecureImportOUT->eError != PVRSRV_OK)
263         {
264                 goto SyncPrimServerSecureImport_exit;
265         }
266
267
268 SyncPrimServerSecureImport_exit:
269         if (psSyncPrimServerSecureImportOUT->eError != PVRSRV_OK)
270         {
271                 /* If we have a valid resman item we should undo the bridge function by freeing the resman item */
272                 if (hSyncHandleInt2)
273                 {
274                         PVRSRV_ERROR eError = ResManFreeResByPtr(hSyncHandleInt2);
275
276                         /* Freeing a resource should never fail... */
277                         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
278                 }
279                 else if (psSyncHandleInt)
280                 {
281                         PVRSRVServerSyncFreeKM(psSyncHandleInt);
282                 }
283         }
284
285
286         return 0;
287 }
288
289
290
291 /* *************************************************************************** 
292  * Server bridge dispatch related glue 
293  */
294  
295 PVRSRV_ERROR RegisterSYNCSEXPORTFunctions(IMG_VOID);
296 IMG_VOID UnregisterSYNCSEXPORTFunctions(IMG_VOID);
297
298 /*
299  * Register all SYNCSEXPORT functions with services
300  */
301 PVRSRV_ERROR RegisterSYNCSEXPORTFunctions(IMG_VOID)
302 {
303         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNCSEXPORT_SYNCPRIMSERVERSECUREEXPORT, PVRSRVBridgeSyncPrimServerSecureExport);
304         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNCSEXPORT_SYNCPRIMSERVERSECUREUNEXPORT, PVRSRVBridgeSyncPrimServerSecureUnexport);
305         SetDispatchTableEntry(PVRSRV_BRIDGE_SYNCSEXPORT_SYNCPRIMSERVERSECUREIMPORT, PVRSRVBridgeSyncPrimServerSecureImport);
306
307         return PVRSRV_OK;
308 }
309
310 /*
311  * Unregister all syncsexport functions with services
312  */
313 IMG_VOID UnregisterSYNCSEXPORTFunctions(IMG_VOID)
314 {
315 }