RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / services / server / env / linux / devicemem_mmap_stub.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Device Memory Management
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    OS abstraction for the mmap2 interface for mapping PMRs into
6                 User Mode memory
7 @License        Dual MIT/GPLv2
8
9 The contents of this file are subject to the MIT license as set out below.
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 Alternatively, the contents of this file may be used under the terms of
22 the GNU General Public License Version 2 ("GPL") in which case the provisions
23 of GPL are applicable instead of those above.
24
25 If you wish to allow use of your version of this file only under the terms of
26 GPL, and not to allow others to use your version of this file under the terms
27 of the MIT license, indicate your decision by deleting the provisions above
28 and replace them with the notice and other provisions required by GPL as set
29 out in the file called "GPL-COPYING" included in this distribution. If you do
30 not delete the provisions above, a recipient may use your version of this file
31 under the terms of either the MIT license or GPL.
32
33 This License is also included in this distribution in the file called
34 "MIT-COPYING".
35
36 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
37 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
40 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
41 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
42 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 */ /**************************************************************************/
44
45 /* our exported API */
46 #include "devicemem_mmap.h"
47
48 /* include/ */
49 #include "img_types.h"
50 #include "pvr_debug.h"
51 #include "pvrsrv_error.h"
52
53 /* services/include/ */
54
55 /* services/include/srvhelper/ */
56 #include "ra.h"
57
58 /* autogenerated bridge */
59 #include <client_mm_bridge.h>
60
61 #include "pmr.h"
62
63 IMG_INTERNAL PVRSRV_ERROR
64 OSMMapPMR(IMG_HANDLE hBridge,
65           IMG_HANDLE hPMR,
66           IMG_DEVMEM_SIZE_T uiPMRSize,
67           IMG_UINT32 uiFlags,
68           IMG_HANDLE *phOSMMapPrivDataOut,
69           void **ppvMappingAddressOut,
70           IMG_SIZE_T *puiMappingLengthOut)
71 {
72     PVRSRV_ERROR eError;
73     PMR *psPMR;
74     void *pvKernelAddress;
75     IMG_SIZE_T uiLength;
76     IMG_HANDLE hPriv;
77
78     PVR_UNREFERENCED_PARAMETER(hBridge);
79     PVR_UNREFERENCED_PARAMETER(uiFlags);
80
81     /*
82       Normally this function would mmap a PMR into the memory space of
83       user process, but in this case we're taking a PMR and mapping it
84       into kernel virtual space.  We keep the same function name for
85       symmetry as this allows the higher layers of the software stack
86       to not care whether they are user mode or kernel
87     */
88
89     psPMR = hPMR;
90
91     eError = PMRAcquireKernelMappingData(psPMR,
92                                          0,
93                                          0,
94                                          &pvKernelAddress,
95                                          &uiLength,
96                                          &hPriv);
97     if (eError != PVRSRV_OK)
98     {
99         goto e0;
100     }
101     
102     *phOSMMapPrivDataOut = hPriv;
103     *ppvMappingAddressOut = pvKernelAddress;
104     *puiMappingLengthOut = uiLength;
105
106     PVR_ASSERT(*puiMappingLengthOut == uiPMRSize);
107
108     return PVRSRV_OK;
109
110     /*
111       error exit paths follow
112     */
113
114  e0:
115     PVR_ASSERT(eError != PVRSRV_OK);
116     return eError;
117 }
118
119 IMG_INTERNAL void
120 OSMUnmapPMR(IMG_HANDLE hBridge,
121             IMG_HANDLE hPMR,
122             IMG_HANDLE hOSMMapPrivData,
123             void *pvMappingAddress,
124             IMG_SIZE_T uiMappingLength)
125 {
126     PMR *psPMR;
127
128     PVR_UNREFERENCED_PARAMETER(hBridge);
129     PVR_UNREFERENCED_PARAMETER(pvMappingAddress);
130     PVR_UNREFERENCED_PARAMETER(uiMappingLength);
131
132     psPMR = hPMR;
133     PMRReleaseKernelMappingData(psPMR,
134                                 hOSMMapPrivData);
135 }