RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / generated / dmm_bridge / client_mm_bridge.c
1 /*************************************************************************/ /*!
2 @Title          Direct client bridge for mm
3 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License        Dual MIT/GPLv2
5
6 The contents of this file are subject to the MIT license as set out below.
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
21
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
29
30 This License is also included in this distribution in the file called
31 "MIT-COPYING".
32
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */ /**************************************************************************/
41
42 #include "client_mm_bridge.h"
43 #include "img_defs.h"
44 #include "pvr_debug.h"
45
46 /* Module specific includes */
47 #include "pvrsrv_memallocflags.h"
48 #include "devicemem_typedefs.h"
49
50 #include "devicemem_server.h"
51 #include "pmr.h"
52 #include "devicemem_heapcfg.h"
53 #include "physmem.h"
54
55
56 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRExportPMR(IMG_HANDLE hBridge,
57                                                           IMG_HANDLE hPMR,
58                                                           IMG_HANDLE *phPMRExport,
59                                                           IMG_UINT64 *pui64Size,
60                                                           IMG_UINT32 *pui32Log2Contig,
61                                                           IMG_UINT64 *pui64Password)
62 {
63         PVRSRV_ERROR eError;
64         PMR * psPMRInt;
65         PMR_EXPORT * psPMRExportInt;
66         PVR_UNREFERENCED_PARAMETER(hBridge);
67
68         psPMRInt = (PMR *) hPMR;
69
70         eError =
71                 PMRExportPMR(
72                                         psPMRInt,
73                                         &psPMRExportInt,
74                                         pui64Size,
75                                         pui32Log2Contig,
76                                         pui64Password);
77
78         *phPMRExport = psPMRExportInt;
79         return eError;
80 }
81
82 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRUnexportPMR(IMG_HANDLE hBridge,
83                                                             IMG_HANDLE hPMRExport)
84 {
85         PVRSRV_ERROR eError;
86         PMR_EXPORT * psPMRExportInt;
87         PVR_UNREFERENCED_PARAMETER(hBridge);
88
89         psPMRExportInt = (PMR_EXPORT *) hPMRExport;
90
91         eError =
92                 PMRUnexportPMR(
93                                         psPMRExportInt);
94
95         return eError;
96 }
97
98 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRGetUID(IMG_HANDLE hBridge,
99                                                        IMG_HANDLE hPMR,
100                                                        IMG_UINT64 *pui64UID)
101 {
102         PVRSRV_ERROR eError;
103         PMR * psPMRInt;
104         PVR_UNREFERENCED_PARAMETER(hBridge);
105
106         psPMRInt = (PMR *) hPMR;
107
108         eError =
109                 PMRGetUID(
110                                         psPMRInt,
111                                         pui64UID);
112
113         return eError;
114 }
115
116 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRMakeServerExportClientExport(IMG_HANDLE hBridge,
117                                                                              DEVMEM_SERVER_EXPORTCOOKIE hPMRServerExport,
118                                                                              IMG_HANDLE *phPMRExportOut,
119                                                                              IMG_UINT64 *pui64Size,
120                                                                              IMG_UINT32 *pui32Log2Contig,
121                                                                              IMG_UINT64 *pui64Password)
122 {
123         PVRSRV_ERROR eError;
124         DEVMEM_EXPORTCOOKIE * psPMRServerExportInt;
125         PMR_EXPORT * psPMRExportOutInt;
126         PVR_UNREFERENCED_PARAMETER(hBridge);
127
128         psPMRServerExportInt = (DEVMEM_EXPORTCOOKIE *) hPMRServerExport;
129
130         eError =
131                 PMRMakeServerExportClientExport(
132                                         psPMRServerExportInt,
133                                         &psPMRExportOutInt,
134                                         pui64Size,
135                                         pui32Log2Contig,
136                                         pui64Password);
137
138         *phPMRExportOut = psPMRExportOutInt;
139         return eError;
140 }
141
142 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRUnmakeServerExportClientExport(IMG_HANDLE hBridge,
143                                                                                IMG_HANDLE hPMRExport)
144 {
145         PVRSRV_ERROR eError;
146         PMR_EXPORT * psPMRExportInt;
147         PVR_UNREFERENCED_PARAMETER(hBridge);
148
149         psPMRExportInt = (PMR_EXPORT *) hPMRExport;
150
151         eError =
152                 PMRUnmakeServerExportClientExport(
153                                         psPMRExportInt);
154
155         return eError;
156 }
157
158 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRImportPMR(IMG_HANDLE hBridge,
159                                                           IMG_HANDLE hPMRExport,
160                                                           IMG_UINT64 ui64uiPassword,
161                                                           IMG_UINT64 ui64uiSize,
162                                                           IMG_UINT32 ui32uiLog2Contig,
163                                                           IMG_HANDLE *phPMR)
164 {
165         PVRSRV_ERROR eError;
166         PMR_EXPORT * psPMRExportInt;
167         PMR * psPMRInt;
168         PVR_UNREFERENCED_PARAMETER(hBridge);
169
170         psPMRExportInt = (PMR_EXPORT *) hPMRExport;
171
172         eError =
173                 PMRImportPMR(
174                                         psPMRExportInt,
175                                         ui64uiPassword,
176                                         ui64uiSize,
177                                         ui32uiLog2Contig,
178                                         &psPMRInt);
179
180         *phPMR = psPMRInt;
181         return eError;
182 }
183
184 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntCtxCreate(IMG_HANDLE hBridge,
185                                                                 IMG_HANDLE hDeviceNode,
186                                                                 IMG_HANDLE *phDevMemServerContext,
187                                                                 IMG_HANDLE *phPrivData)
188 {
189         PVRSRV_ERROR eError;
190         IMG_HANDLE hDeviceNodeInt;
191         DEVMEMINT_CTX * psDevMemServerContextInt;
192         IMG_HANDLE hPrivDataInt;
193         PVR_UNREFERENCED_PARAMETER(hBridge);
194
195         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
196
197         eError =
198                 DevmemIntCtxCreate(
199                                         hDeviceNodeInt,
200                                         &psDevMemServerContextInt,
201                                         &hPrivDataInt);
202
203         *phDevMemServerContext = psDevMemServerContextInt;
204         *phPrivData = hPrivDataInt;
205         return eError;
206 }
207
208 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntCtxDestroy(IMG_HANDLE hBridge,
209                                                                  IMG_HANDLE hDevmemServerContext)
210 {
211         PVRSRV_ERROR eError;
212         DEVMEMINT_CTX * psDevmemServerContextInt;
213         PVR_UNREFERENCED_PARAMETER(hBridge);
214
215         psDevmemServerContextInt = (DEVMEMINT_CTX *) hDevmemServerContext;
216
217         eError =
218                 DevmemIntCtxDestroy(
219                                         psDevmemServerContextInt);
220
221         return eError;
222 }
223
224 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntHeapCreate(IMG_HANDLE hBridge,
225                                                                  IMG_HANDLE hDevmemCtx,
226                                                                  IMG_DEV_VIRTADDR sHeapBaseAddr,
227                                                                  IMG_DEVMEM_SIZE_T uiHeapLength,
228                                                                  IMG_UINT32 ui32Log2DataPageSize,
229                                                                  IMG_HANDLE *phDevmemHeapPtr)
230 {
231         PVRSRV_ERROR eError;
232         DEVMEMINT_CTX * psDevmemCtxInt;
233         DEVMEMINT_HEAP * psDevmemHeapPtrInt;
234         PVR_UNREFERENCED_PARAMETER(hBridge);
235
236         psDevmemCtxInt = (DEVMEMINT_CTX *) hDevmemCtx;
237
238         eError =
239                 DevmemIntHeapCreate(
240                                         psDevmemCtxInt,
241                                         sHeapBaseAddr,
242                                         uiHeapLength,
243                                         ui32Log2DataPageSize,
244                                         &psDevmemHeapPtrInt);
245
246         *phDevmemHeapPtr = psDevmemHeapPtrInt;
247         return eError;
248 }
249
250 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntHeapDestroy(IMG_HANDLE hBridge,
251                                                                   IMG_HANDLE hDevmemHeap)
252 {
253         PVRSRV_ERROR eError;
254         DEVMEMINT_HEAP * psDevmemHeapInt;
255         PVR_UNREFERENCED_PARAMETER(hBridge);
256
257         psDevmemHeapInt = (DEVMEMINT_HEAP *) hDevmemHeap;
258
259         eError =
260                 DevmemIntHeapDestroy(
261                                         psDevmemHeapInt);
262
263         return eError;
264 }
265
266 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntMapPMR(IMG_HANDLE hBridge,
267                                                              IMG_HANDLE hDevmemServerHeap,
268                                                              IMG_HANDLE hReservation,
269                                                              IMG_HANDLE hPMR,
270                                                              PVRSRV_MEMALLOCFLAGS_T uiMapFlags,
271                                                              IMG_HANDLE *phMapping)
272 {
273         PVRSRV_ERROR eError;
274         DEVMEMINT_HEAP * psDevmemServerHeapInt;
275         DEVMEMINT_RESERVATION * psReservationInt;
276         PMR * psPMRInt;
277         DEVMEMINT_MAPPING * psMappingInt;
278         PVR_UNREFERENCED_PARAMETER(hBridge);
279
280         psDevmemServerHeapInt = (DEVMEMINT_HEAP *) hDevmemServerHeap;
281         psReservationInt = (DEVMEMINT_RESERVATION *) hReservation;
282         psPMRInt = (PMR *) hPMR;
283
284         eError =
285                 DevmemIntMapPMR(
286                                         psDevmemServerHeapInt,
287                                         psReservationInt,
288                                         psPMRInt,
289                                         uiMapFlags,
290                                         &psMappingInt);
291
292         *phMapping = psMappingInt;
293         return eError;
294 }
295
296 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntUnmapPMR(IMG_HANDLE hBridge,
297                                                                IMG_HANDLE hMapping)
298 {
299         PVRSRV_ERROR eError;
300         DEVMEMINT_MAPPING * psMappingInt;
301         PVR_UNREFERENCED_PARAMETER(hBridge);
302
303         psMappingInt = (DEVMEMINT_MAPPING *) hMapping;
304
305         eError =
306                 DevmemIntUnmapPMR(
307                                         psMappingInt);
308
309         return eError;
310 }
311
312 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntReserveRange(IMG_HANDLE hBridge,
313                                                                    IMG_HANDLE hDevmemServerHeap,
314                                                                    IMG_DEV_VIRTADDR sAddress,
315                                                                    IMG_DEVMEM_SIZE_T uiLength,
316                                                                    IMG_HANDLE *phReservation)
317 {
318         PVRSRV_ERROR eError;
319         DEVMEMINT_HEAP * psDevmemServerHeapInt;
320         DEVMEMINT_RESERVATION * psReservationInt;
321         PVR_UNREFERENCED_PARAMETER(hBridge);
322
323         psDevmemServerHeapInt = (DEVMEMINT_HEAP *) hDevmemServerHeap;
324
325         eError =
326                 DevmemIntReserveRange(
327                                         psDevmemServerHeapInt,
328                                         sAddress,
329                                         uiLength,
330                                         &psReservationInt);
331
332         *phReservation = psReservationInt;
333         return eError;
334 }
335
336 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIntUnreserveRange(IMG_HANDLE hBridge,
337                                                                      IMG_HANDLE hReservation)
338 {
339         PVRSRV_ERROR eError;
340         DEVMEMINT_RESERVATION * psReservationInt;
341         PVR_UNREFERENCED_PARAMETER(hBridge);
342
343         psReservationInt = (DEVMEMINT_RESERVATION *) hReservation;
344
345         eError =
346                 DevmemIntUnreserveRange(
347                                         psReservationInt);
348
349         return eError;
350 }
351
352 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePhysmemNewRamBackedPMR(IMG_HANDLE hBridge,
353                                                                     IMG_HANDLE hDeviceNode,
354                                                                     IMG_DEVMEM_SIZE_T uiSize,
355                                                                     IMG_DEVMEM_SIZE_T uiChunkSize,
356                                                                     IMG_UINT32 ui32NumPhysChunks,
357                                                                     IMG_UINT32 ui32NumVirtChunks,
358                                                                     IMG_BOOL *pbMappingTable,
359                                                                     IMG_UINT32 ui32Log2PageSize,
360                                                                     PVRSRV_MEMALLOCFLAGS_T uiFlags,
361                                                                     IMG_HANDLE *phPMRPtr)
362 {
363         PVRSRV_ERROR eError;
364         IMG_HANDLE hDeviceNodeInt;
365         PMR * psPMRPtrInt;
366         PVR_UNREFERENCED_PARAMETER(hBridge);
367
368         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
369
370         eError =
371                 PhysmemNewRamBackedPMR(
372                                         hDeviceNodeInt,
373                                         uiSize,
374                                         uiChunkSize,
375                                         ui32NumPhysChunks,
376                                         ui32NumVirtChunks,
377                                         pbMappingTable,
378                                         ui32Log2PageSize,
379                                         uiFlags,
380                                         &psPMRPtrInt);
381
382         *phPMRPtr = psPMRPtrInt;
383         return eError;
384 }
385
386 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRLocalImportPMR(IMG_HANDLE hBridge,
387                                                                IMG_HANDLE hExtHandle,
388                                                                IMG_HANDLE *phPMR,
389                                                                IMG_DEVMEM_SIZE_T *puiSize,
390                                                                IMG_DEVMEM_ALIGN_T *psAlign)
391 {
392         PVRSRV_ERROR eError;
393         PMR * psExtHandleInt;
394         PMR * psPMRInt;
395         PVR_UNREFERENCED_PARAMETER(hBridge);
396
397         psExtHandleInt = (PMR *) hExtHandle;
398
399         eError =
400                 PMRLocalImportPMR(
401                                         psExtHandleInt,
402                                         &psPMRInt,
403                                         puiSize,
404                                         psAlign);
405
406         *phPMR = psPMRInt;
407         return eError;
408 }
409
410 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgePMRUnrefPMR(IMG_HANDLE hBridge,
411                                                          IMG_HANDLE hPMR)
412 {
413         PVRSRV_ERROR eError;
414         PMR * psPMRInt;
415         PVR_UNREFERENCED_PARAMETER(hBridge);
416
417         psPMRInt = (PMR *) hPMR;
418
419         eError =
420                 PMRUnrefPMR(
421                                         psPMRInt);
422
423         return eError;
424 }
425
426 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemSLCFlushInvalRequest(IMG_HANDLE hBridge,
427                                                                         IMG_HANDLE hDeviceNode,
428                                                                         IMG_HANDLE hPmr)
429 {
430         PVRSRV_ERROR eError;
431         IMG_HANDLE hDeviceNodeInt;
432         PMR * psPmrInt;
433         PVR_UNREFERENCED_PARAMETER(hBridge);
434
435         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
436         psPmrInt = (PMR *) hPmr;
437
438         eError =
439                 DevmemSLCFlushInvalRequest(
440                                         hDeviceNodeInt,
441                                         psPmrInt);
442
443         return eError;
444 }
445
446 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeDevmemIsVDevAddrValid(IMG_HANDLE hBridge,
447                                                                    IMG_HANDLE hDevmemCtx,
448                                                                    IMG_DEV_VIRTADDR sAddress)
449 {
450         PVRSRV_ERROR eError;
451         DEVMEMINT_CTX * psDevmemCtxInt;
452         PVR_UNREFERENCED_PARAMETER(hBridge);
453
454         psDevmemCtxInt = (DEVMEMINT_CTX *) hDevmemCtx;
455
456         eError =
457                 DevmemIntIsVDevAddrValid(
458                                         psDevmemCtxInt,
459                                         sAddress);
460
461         return eError;
462 }
463
464 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeHeapCfgHeapConfigCount(IMG_HANDLE hBridge,
465                                                                     IMG_HANDLE hDeviceNode,
466                                                                     IMG_UINT32 *pui32NumHeapConfigs)
467 {
468         PVRSRV_ERROR eError;
469         IMG_HANDLE hDeviceNodeInt;
470         PVR_UNREFERENCED_PARAMETER(hBridge);
471
472         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
473
474         eError =
475                 HeapCfgHeapConfigCount(
476                                         hDeviceNodeInt,
477                                         pui32NumHeapConfigs);
478
479         return eError;
480 }
481
482 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeHeapCfgHeapCount(IMG_HANDLE hBridge,
483                                                               IMG_HANDLE hDeviceNode,
484                                                               IMG_UINT32 ui32HeapConfigIndex,
485                                                               IMG_UINT32 *pui32NumHeaps)
486 {
487         PVRSRV_ERROR eError;
488         IMG_HANDLE hDeviceNodeInt;
489         PVR_UNREFERENCED_PARAMETER(hBridge);
490
491         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
492
493         eError =
494                 HeapCfgHeapCount(
495                                         hDeviceNodeInt,
496                                         ui32HeapConfigIndex,
497                                         pui32NumHeaps);
498
499         return eError;
500 }
501
502 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeHeapCfgHeapConfigName(IMG_HANDLE hBridge,
503                                                                    IMG_HANDLE hDeviceNode,
504                                                                    IMG_UINT32 ui32HeapConfigIndex,
505                                                                    IMG_UINT32 ui32HeapConfigNameBufSz,
506                                                                    IMG_CHAR *puiHeapConfigName)
507 {
508         PVRSRV_ERROR eError;
509         IMG_HANDLE hDeviceNodeInt;
510         PVR_UNREFERENCED_PARAMETER(hBridge);
511
512         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
513
514         eError =
515                 HeapCfgHeapConfigName(
516                                         hDeviceNodeInt,
517                                         ui32HeapConfigIndex,
518                                         ui32HeapConfigNameBufSz,
519                                         puiHeapConfigName);
520
521         return eError;
522 }
523
524 IMG_INTERNAL PVRSRV_ERROR IMG_CALLCONV BridgeHeapCfgHeapDetails(IMG_HANDLE hBridge,
525                                                                 IMG_HANDLE hDeviceNode,
526                                                                 IMG_UINT32 ui32HeapConfigIndex,
527                                                                 IMG_UINT32 ui32HeapIndex,
528                                                                 IMG_UINT32 ui32HeapNameBufSz,
529                                                                 IMG_CHAR *puiHeapNameOut,
530                                                                 IMG_DEV_VIRTADDR *psDevVAddrBase,
531                                                                 IMG_DEVMEM_SIZE_T *puiHeapLength,
532                                                                 IMG_UINT32 *pui32Log2DataPageSizeOut,
533                                                                 IMG_UINT32 *pui32Log2ImportAlignmentOut)
534 {
535         PVRSRV_ERROR eError;
536         IMG_HANDLE hDeviceNodeInt;
537         PVR_UNREFERENCED_PARAMETER(hBridge);
538
539         hDeviceNodeInt = (IMG_HANDLE) hDeviceNode;
540
541         eError =
542                 HeapCfgHeapDetails(
543                                         hDeviceNodeInt,
544                                         ui32HeapConfigIndex,
545                                         ui32HeapIndex,
546                                         ui32HeapNameBufSz,
547                                         puiHeapNameOut,
548                                         psDevVAddrBase,
549                                         puiHeapLength,
550                                         pui32Log2DataPageSizeOut,
551                                         pui32Log2ImportAlignmentOut);
552
553         return eError;
554 }
555