RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / devicemem_pdump.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Shared device memory management PDump functions
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements common (client & server) PDump functions for the
6                 memory management code
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 #if defined PDUMP
46
47 #include "allocmem.h"
48 #include "img_types.h"
49 #include "pvrsrv_error.h"
50 #include "pdump.h"
51 #include "devicemem.h"
52 #include "devicemem_utils.h"
53 #include "devicemem_pdump.h"
54 #include "client_pdumpmm_bridge.h"
55 #if defined(LINUX) && !defined(__KERNEL__)
56 #include <stdio.h>
57 #if defined(SUPPORT_ANDROID_PLATFORM)
58 #include "android_utils.h"
59 #endif
60 #endif
61
62 IMG_INTERNAL void
63 DevmemPDumpLoadMem(DEVMEM_MEMDESC *psMemDesc,
64                    IMG_DEVMEM_OFFSET_T uiOffset,
65                    IMG_DEVMEM_SIZE_T uiSize,
66                    PDUMP_FLAGS_T uiPDumpFlags)
67 {
68     PVRSRV_ERROR eError;
69
70     PVR_ASSERT(uiOffset + uiSize <= psMemDesc->psImport->uiSize);
71
72     eError = BridgePMRPDumpLoadMem(psMemDesc->psImport->hDevConnection,
73                                    psMemDesc->psImport->hPMR,
74                                    psMemDesc->uiOffset + uiOffset,
75                                    uiSize,
76                                    uiPDumpFlags,
77                                    IMG_FALSE);
78
79         if (eError != PVRSRV_OK)
80         {
81                 PVR_DPF((PVR_DBG_ERROR,
82                                 "%s: failed with error %d",
83                                 __FUNCTION__, eError));
84         }
85     PVR_ASSERT(eError == PVRSRV_OK);
86 }
87
88 IMG_INTERNAL void
89 DevmemPDumpLoadZeroMem(DEVMEM_MEMDESC *psMemDesc,
90                    IMG_DEVMEM_OFFSET_T uiOffset,
91                    IMG_DEVMEM_SIZE_T uiSize,
92                    PDUMP_FLAGS_T uiPDumpFlags)
93 {
94     PVRSRV_ERROR eError;
95
96     PVR_ASSERT(uiOffset + uiSize <= psMemDesc->psImport->uiSize);
97
98     eError = BridgePMRPDumpLoadMem(psMemDesc->psImport->hDevConnection,
99                                    psMemDesc->psImport->hPMR,
100                                    psMemDesc->uiOffset + uiOffset,
101                                    uiSize,
102                                    uiPDumpFlags,
103                                    IMG_TRUE);
104
105         if (eError != PVRSRV_OK)
106         {
107                 PVR_DPF((PVR_DBG_ERROR,
108                                 "%s: failed with error %d",
109                                 __FUNCTION__, eError));
110         }
111     PVR_ASSERT(eError == PVRSRV_OK);
112 }
113
114 IMG_INTERNAL void
115 DevmemPDumpLoadMemValue32(DEVMEM_MEMDESC *psMemDesc,
116                         IMG_DEVMEM_OFFSET_T uiOffset,
117                         IMG_UINT32 ui32Value,
118                         PDUMP_FLAGS_T uiPDumpFlags)
119 {
120     PVRSRV_ERROR eError;
121
122     eError = BridgePMRPDumpLoadMemValue32(psMemDesc->psImport->hDevConnection,
123                                         psMemDesc->psImport->hPMR,
124                                         psMemDesc->uiOffset + uiOffset,
125                                         ui32Value,
126                                         uiPDumpFlags);
127
128         if (eError != PVRSRV_OK)
129         {
130                 PVR_DPF((PVR_DBG_ERROR,
131                                 "%s: failed with error %d",
132                                 __FUNCTION__, eError));
133         }
134     PVR_ASSERT(eError == PVRSRV_OK);
135 }
136
137 IMG_INTERNAL void
138 DevmemPDumpLoadMemValue64(DEVMEM_MEMDESC *psMemDesc,
139                         IMG_DEVMEM_OFFSET_T uiOffset,
140                         IMG_UINT64 ui64Value,
141                         PDUMP_FLAGS_T uiPDumpFlags)
142 {
143     PVRSRV_ERROR eError;
144
145     eError = BridgePMRPDumpLoadMemValue64(psMemDesc->psImport->hDevConnection,
146                                           psMemDesc->psImport->hPMR,
147                                           psMemDesc->uiOffset + uiOffset,
148                                           ui64Value,
149                                           uiPDumpFlags);
150         if (eError != PVRSRV_OK)
151         {
152                 PVR_DPF((PVR_DBG_ERROR,
153                                 "%s: failed with error %d",
154                                 __FUNCTION__, eError));
155         }
156     PVR_ASSERT(eError == PVRSRV_OK);
157 }
158
159 /* FIXME: This should be server side only */
160 IMG_INTERNAL PVRSRV_ERROR
161 DevmemPDumpPageCatBaseToSAddr(DEVMEM_MEMDESC            *psMemDesc,
162                                                           IMG_DEVMEM_OFFSET_T   *puiMemOffset,
163                                                           IMG_CHAR                              *pszName,
164                                                           IMG_UINT32                    ui32Size)
165 {
166     PVRSRV_ERROR                eError;
167         IMG_CHAR                        aszMemspaceName[100];
168         IMG_CHAR                        aszSymbolicName[100];
169         IMG_DEVMEM_OFFSET_T uiNextSymName;
170
171         *puiMemOffset += psMemDesc->uiOffset;
172
173     eError = BridgePMRPDumpSymbolicAddr(psMemDesc->psImport->hDevConnection,
174                                                                                 psMemDesc->psImport->hPMR,
175                                                                                 *puiMemOffset,
176                                                                                 sizeof(aszMemspaceName),
177                                                                                 &aszMemspaceName[0],
178                                                                                 sizeof(aszSymbolicName),
179                                                                                 &aszSymbolicName[0],
180                                                                                 puiMemOffset,
181                                                                                 &uiNextSymName);
182
183         if (eError != PVRSRV_OK)
184         {
185                 PVR_DPF((PVR_DBG_ERROR,
186                                 "%s: failed with error %d",
187                                 __FUNCTION__, eError));
188         }
189     PVR_ASSERT(eError == PVRSRV_OK);
190
191         OSSNPrintf(pszName, ui32Size, "%s:%s", &aszMemspaceName[0], &aszSymbolicName[0]);
192         return eError;
193 }
194
195 IMG_INTERNAL void
196 DevmemPDumpSaveToFile(DEVMEM_MEMDESC *psMemDesc,
197                       IMG_DEVMEM_OFFSET_T uiOffset,
198                       IMG_DEVMEM_SIZE_T uiSize,
199                       const IMG_CHAR *pszFilename,
200                       IMG_UINT32 uiFileOffset)
201 {
202     PVRSRV_ERROR eError;
203
204     eError = BridgePMRPDumpSaveToFile(psMemDesc->psImport->hDevConnection,
205                                                                           psMemDesc->psImport->hPMR,
206                                                                           psMemDesc->uiOffset + uiOffset,
207                                                                           uiSize,
208                                                                           OSStringLength(pszFilename) + 1,
209                                                                           pszFilename,
210                                                                           uiFileOffset);
211
212         if (eError != PVRSRV_OK)
213         {
214                 PVR_DPF((PVR_DBG_ERROR,
215                                 "%s: failed with error %d",
216                                 __FUNCTION__, eError));
217         }
218     PVR_ASSERT(eError == PVRSRV_OK);
219 }
220
221
222
223 /* FIXME: Remove? */
224 IMG_INTERNAL void
225 DevmemPDumpSaveToFileVirtual(DEVMEM_MEMDESC *psMemDesc,
226                              IMG_DEVMEM_OFFSET_T uiOffset,
227                              IMG_DEVMEM_SIZE_T uiSize,
228                              const IMG_CHAR *pszFilename,
229                                                          IMG_UINT32 ui32FileOffset,
230                                                          IMG_UINT32     ui32PdumpFlags)
231 {
232     PVRSRV_ERROR eError;
233     IMG_DEV_VIRTADDR sDevAddrStart;
234
235     sDevAddrStart = psMemDesc->psImport->sDeviceImport.sDevVAddr;
236     sDevAddrStart.uiAddr += psMemDesc->uiOffset;
237     sDevAddrStart.uiAddr += uiOffset;
238
239     eError = BridgeDevmemIntPDumpSaveToFileVirtual(psMemDesc->psImport->hDevConnection,
240                                                    psMemDesc->psImport->sDeviceImport.psHeap->psCtx->hDevMemServerContext,
241                                                    sDevAddrStart,
242                                                    uiSize,
243                                                    OSStringLength(pszFilename) + 1,
244                                                    pszFilename,
245                                                                                                    ui32FileOffset,
246                                                                                                    ui32PdumpFlags);
247
248         if (eError != PVRSRV_OK)
249         {
250                 PVR_DPF((PVR_DBG_ERROR,
251                                 "%s: failed with error %d",
252                                 __FUNCTION__, eError));
253         }
254     PVR_ASSERT(eError == PVRSRV_OK);
255 }
256
257
258 IMG_INTERNAL PVRSRV_ERROR
259 DevmemPDumpDevmemPol32(const DEVMEM_MEMDESC *psMemDesc,
260                        IMG_DEVMEM_OFFSET_T uiOffset,
261                        IMG_UINT32 ui32Value,
262                        IMG_UINT32 ui32Mask,
263                        PDUMP_POLL_OPERATOR eOperator,
264                        PDUMP_FLAGS_T ui32PDumpFlags)
265 {
266     PVRSRV_ERROR eError;
267     IMG_DEVMEM_SIZE_T uiNumBytes;
268
269     uiNumBytes = 4;
270
271     if (psMemDesc->uiOffset + uiOffset + uiNumBytes >= psMemDesc->psImport->uiSize)
272     {
273         eError = PVRSRV_ERROR_DEVICEMEM_OUT_OF_RANGE;
274         goto e0;
275     }
276
277     eError = BridgePMRPDumpPol32(psMemDesc->psImport->hDevConnection,
278                                  psMemDesc->psImport->hPMR,
279                                  psMemDesc->uiOffset + uiOffset,
280                                  ui32Value,
281                                  ui32Mask,
282                                  eOperator,
283                                  ui32PDumpFlags);
284     if (eError != PVRSRV_OK)
285     {
286         goto e0;
287     }
288
289     return PVRSRV_OK;
290
291     /*
292       error exit paths follow
293     */
294
295  e0:
296     PVR_ASSERT(eError != PVRSRV_OK);
297     return eError;
298 }
299
300 IMG_INTERNAL PVRSRV_ERROR
301 DevmemPDumpCBP(const DEVMEM_MEMDESC *psMemDesc,
302                                 IMG_DEVMEM_OFFSET_T uiReadOffset,
303                                 IMG_DEVMEM_OFFSET_T uiWriteOffset,
304                                 IMG_DEVMEM_SIZE_T uiPacketSize,
305                                 IMG_DEVMEM_SIZE_T uiBufferSize)
306 {
307         PVRSRV_ERROR eError;
308
309         if ((psMemDesc->uiOffset + uiReadOffset) > psMemDesc->psImport->uiSize)
310         {
311                 eError = PVRSRV_ERROR_DEVICEMEM_OUT_OF_RANGE;
312                 goto e0;
313         }
314
315         eError = BridgePMRPDumpCBP(psMemDesc->psImport->hDevConnection,
316                                                            psMemDesc->psImport->hPMR,
317                                                            psMemDesc->uiOffset + uiReadOffset,
318                                                            uiWriteOffset,
319                                                            uiPacketSize,
320                                                            uiBufferSize);
321         if (eError != PVRSRV_OK)
322         {
323                 goto e0;
324         }
325
326         return PVRSRV_OK;
327
328 e0:
329         PVR_ASSERT(eError != PVRSRV_OK);
330         return eError;
331 }
332
333 #endif /* PDUMP */
334