RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / generated / pvrtl_bridge / server_pvrtl_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for pvrtl
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for pvrtl
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 "tlserver.h"
50
51
52 #include "common_pvrtl_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
70
71 /* ***************************************************************************
72  * Server-side bridge entry points
73  */
74  
75 static IMG_INT
76 PVRSRVBridgeTLConnect(IMG_UINT32 ui32DispatchTableEntry,
77                                           PVRSRV_BRIDGE_IN_TLCONNECT *psTLConnectIN,
78                                           PVRSRV_BRIDGE_OUT_TLCONNECT *psTLConnectOUT,
79                                          CONNECTION_DATA *psConnection)
80 {
81
82         PVR_UNREFERENCED_PARAMETER(psTLConnectIN);
83
84
85
86
87
88
89         psTLConnectOUT->eError =
90                 TLServerConnectKM(psConnection
91                                         );
92
93
94
95
96
97         return 0;
98 }
99
100 static IMG_INT
101 PVRSRVBridgeTLDisconnect(IMG_UINT32 ui32DispatchTableEntry,
102                                           PVRSRV_BRIDGE_IN_TLDISCONNECT *psTLDisconnectIN,
103                                           PVRSRV_BRIDGE_OUT_TLDISCONNECT *psTLDisconnectOUT,
104                                          CONNECTION_DATA *psConnection)
105 {
106
107         PVR_UNREFERENCED_PARAMETER(psTLDisconnectIN);
108
109
110
111
112
113
114         psTLDisconnectOUT->eError =
115                 TLServerDisconnectKM(psConnection
116                                         );
117
118
119
120
121
122         return 0;
123 }
124
125 static IMG_INT
126 PVRSRVBridgeTLOpenStream(IMG_UINT32 ui32DispatchTableEntry,
127                                           PVRSRV_BRIDGE_IN_TLOPENSTREAM *psTLOpenStreamIN,
128                                           PVRSRV_BRIDGE_OUT_TLOPENSTREAM *psTLOpenStreamOUT,
129                                          CONNECTION_DATA *psConnection)
130 {
131         IMG_CHAR *uiNameInt = IMG_NULL;
132         TL_STREAM_DESC * psSDInt = IMG_NULL;
133         DEVMEM_EXPORTCOOKIE * psClientBUFExportCookieInt = IMG_NULL;
134
135
136
137         psTLOpenStreamOUT->hSD = IMG_NULL;
138
139         
140         {
141                 uiNameInt = OSAllocMem(PRVSRVTL_MAX_STREAM_NAME_SIZE * sizeof(IMG_CHAR));
142                 if (!uiNameInt)
143                 {
144                         psTLOpenStreamOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
145         
146                         goto TLOpenStream_exit;
147                 }
148         }
149
150                         /* Copy the data over */
151                         if ( !OSAccessOK(PVR_VERIFY_READ, (IMG_VOID*) psTLOpenStreamIN->puiName, PRVSRVTL_MAX_STREAM_NAME_SIZE * sizeof(IMG_CHAR))
152                                 || (OSCopyFromUser(NULL, uiNameInt, psTLOpenStreamIN->puiName,
153                                 PRVSRVTL_MAX_STREAM_NAME_SIZE * sizeof(IMG_CHAR)) != PVRSRV_OK) )
154                         {
155                                 psTLOpenStreamOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
156
157                                 goto TLOpenStream_exit;
158                         }
159
160
161
162         psTLOpenStreamOUT->eError =
163                 TLServerOpenStreamKM(
164                                         uiNameInt,
165                                         psTLOpenStreamIN->ui32Mode,
166                                         &psSDInt,
167                                         &psClientBUFExportCookieInt);
168         /* Exit early if bridged call fails */
169         if(psTLOpenStreamOUT->eError != PVRSRV_OK)
170         {
171                 goto TLOpenStream_exit;
172         }
173
174
175         psTLOpenStreamOUT->eError = PVRSRVAllocHandle(psConnection->psHandleBase,
176                                                         &psTLOpenStreamOUT->hSD,
177                                                         (IMG_VOID *) psSDInt,
178                                                         PVRSRV_HANDLE_TYPE_PVR_TL_SD,
179                                                         PVRSRV_HANDLE_ALLOC_FLAG_MULTI
180                                                         ,(PFN_HANDLE_RELEASE)&TLServerCloseStreamKM);
181         if (psTLOpenStreamOUT->eError != PVRSRV_OK)
182         {
183                 goto TLOpenStream_exit;
184         }
185
186
187         psTLOpenStreamOUT->eError = PVRSRVAllocSubHandle(psConnection->psHandleBase,
188                                                         &psTLOpenStreamOUT->hClientBUFExportCookie,
189                                                         (IMG_VOID *) psClientBUFExportCookieInt,
190                                                         PVRSRV_HANDLE_TYPE_SERVER_EXPORTCOOKIE,
191                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE
192                                                         ,psTLOpenStreamOUT->hSD);
193         if (psTLOpenStreamOUT->eError != PVRSRV_OK)
194         {
195                 goto TLOpenStream_exit;
196         }
197
198
199
200
201 TLOpenStream_exit:
202         if (psTLOpenStreamOUT->eError != PVRSRV_OK)
203         {
204                 if (psTLOpenStreamOUT->hSD)
205                 {
206                         PVRSRV_ERROR eError = PVRSRVReleaseHandle(psConnection->psHandleBase,
207                                                 (IMG_HANDLE) psTLOpenStreamOUT->hSD,
208                                                 PVRSRV_HANDLE_TYPE_PVR_TL_SD);
209
210                         /* Releasing the handle should free/destroy/release the resource. This should never fail... */
211                         PVR_ASSERT((eError == PVRSRV_OK) || (eError == PVRSRV_ERROR_RETRY));
212
213                         /* Avoid freeing/destroying/releasing the resource a second time below */
214                         psSDInt = IMG_NULL;
215                 }
216
217
218                 if (psSDInt)
219                 {
220                         TLServerCloseStreamKM(psSDInt);
221                 }
222         }
223
224         if (uiNameInt)
225                 OSFreeMem(uiNameInt);
226
227         return 0;
228 }
229
230 static IMG_INT
231 PVRSRVBridgeTLCloseStream(IMG_UINT32 ui32DispatchTableEntry,
232                                           PVRSRV_BRIDGE_IN_TLCLOSESTREAM *psTLCloseStreamIN,
233                                           PVRSRV_BRIDGE_OUT_TLCLOSESTREAM *psTLCloseStreamOUT,
234                                          CONNECTION_DATA *psConnection)
235 {
236
237
238
239
240
241
242
243
244
245         psTLCloseStreamOUT->eError =
246                 PVRSRVReleaseHandle(psConnection->psHandleBase,
247                                         (IMG_HANDLE) psTLCloseStreamIN->hSD,
248                                         PVRSRV_HANDLE_TYPE_PVR_TL_SD);
249         if ((psTLCloseStreamOUT->eError != PVRSRV_OK) && (psTLCloseStreamOUT->eError != PVRSRV_ERROR_RETRY))
250         {
251                 PVR_ASSERT(0);
252                 goto TLCloseStream_exit;
253         }
254
255
256
257 TLCloseStream_exit:
258
259         return 0;
260 }
261
262 static IMG_INT
263 PVRSRVBridgeTLAcquireData(IMG_UINT32 ui32DispatchTableEntry,
264                                           PVRSRV_BRIDGE_IN_TLACQUIREDATA *psTLAcquireDataIN,
265                                           PVRSRV_BRIDGE_OUT_TLACQUIREDATA *psTLAcquireDataOUT,
266                                          CONNECTION_DATA *psConnection)
267 {
268         TL_STREAM_DESC * psSDInt = IMG_NULL;
269
270
271
272
273
274
275
276                                 {
277                                         /* Look up the address from the handle */
278                                         psTLAcquireDataOUT->eError =
279                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
280                                                                                         (IMG_VOID **) &psSDInt,
281                                                                                         psTLAcquireDataIN->hSD,
282                                                                                         PVRSRV_HANDLE_TYPE_PVR_TL_SD);
283                                         if(psTLAcquireDataOUT->eError != PVRSRV_OK)
284                                         {
285                                                 goto TLAcquireData_exit;
286                                         }
287                                 }
288
289
290         psTLAcquireDataOUT->eError =
291                 TLServerAcquireDataKM(
292                                         psSDInt,
293                                         &psTLAcquireDataOUT->ui32ReadOffset,
294                                         &psTLAcquireDataOUT->ui32ReadLen);
295
296
297
298
299 TLAcquireData_exit:
300
301         return 0;
302 }
303
304 static IMG_INT
305 PVRSRVBridgeTLReleaseData(IMG_UINT32 ui32DispatchTableEntry,
306                                           PVRSRV_BRIDGE_IN_TLRELEASEDATA *psTLReleaseDataIN,
307                                           PVRSRV_BRIDGE_OUT_TLRELEASEDATA *psTLReleaseDataOUT,
308                                          CONNECTION_DATA *psConnection)
309 {
310         TL_STREAM_DESC * psSDInt = IMG_NULL;
311
312
313
314
315
316
317
318                                 {
319                                         /* Look up the address from the handle */
320                                         psTLReleaseDataOUT->eError =
321                                                 PVRSRVLookupHandle(psConnection->psHandleBase,
322                                                                                         (IMG_VOID **) &psSDInt,
323                                                                                         psTLReleaseDataIN->hSD,
324                                                                                         PVRSRV_HANDLE_TYPE_PVR_TL_SD);
325                                         if(psTLReleaseDataOUT->eError != PVRSRV_OK)
326                                         {
327                                                 goto TLReleaseData_exit;
328                                         }
329                                 }
330
331
332         psTLReleaseDataOUT->eError =
333                 TLServerReleaseDataKM(
334                                         psSDInt,
335                                         psTLReleaseDataIN->ui32ReadOffset,
336                                         psTLReleaseDataIN->ui32ReadLen);
337
338
339
340
341 TLReleaseData_exit:
342
343         return 0;
344 }
345
346
347
348 /* *************************************************************************** 
349  * Server bridge dispatch related glue 
350  */
351
352
353 PVRSRV_ERROR InitPVRTLBridge(IMG_VOID);
354 PVRSRV_ERROR DeinitPVRTLBridge(IMG_VOID);
355
356 /*
357  * Register all PVRTL functions with services
358  */
359 PVRSRV_ERROR InitPVRTLBridge(IMG_VOID)
360 {
361
362         SetDispatchTableEntry(PVRSRV_BRIDGE_PVRTL, PVRSRV_BRIDGE_PVRTL_TLCONNECT, PVRSRVBridgeTLConnect,
363                                         IMG_NULL, IMG_NULL,
364                                         0, 0);
365
366         SetDispatchTableEntry(PVRSRV_BRIDGE_PVRTL, PVRSRV_BRIDGE_PVRTL_TLDISCONNECT, PVRSRVBridgeTLDisconnect,
367                                         IMG_NULL, IMG_NULL,
368                                         0, 0);
369
370         SetDispatchTableEntry(PVRSRV_BRIDGE_PVRTL, PVRSRV_BRIDGE_PVRTL_TLOPENSTREAM, PVRSRVBridgeTLOpenStream,
371                                         IMG_NULL, IMG_NULL,
372                                         0, 0);
373
374         SetDispatchTableEntry(PVRSRV_BRIDGE_PVRTL, PVRSRV_BRIDGE_PVRTL_TLCLOSESTREAM, PVRSRVBridgeTLCloseStream,
375                                         IMG_NULL, IMG_NULL,
376                                         0, 0);
377
378         SetDispatchTableEntry(PVRSRV_BRIDGE_PVRTL, PVRSRV_BRIDGE_PVRTL_TLACQUIREDATA, PVRSRVBridgeTLAcquireData,
379                                         IMG_NULL, IMG_NULL,
380                                         0, 0);
381
382         SetDispatchTableEntry(PVRSRV_BRIDGE_PVRTL, PVRSRV_BRIDGE_PVRTL_TLRELEASEDATA, PVRSRVBridgeTLReleaseData,
383                                         IMG_NULL, IMG_NULL,
384                                         0, 0);
385
386
387         return PVRSRV_OK;
388 }
389
390 /*
391  * Unregister all pvrtl functions with services
392  */
393 PVRSRV_ERROR DeinitPVRTLBridge(IMG_VOID)
394 {
395         return PVRSRV_OK;
396 }
397