RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / ioctl.c
1 /*************************************************************************/ /*!
2 @File
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 #if defined(_WIN32)
43 #pragma  warning(disable:4201)
44 #pragma  warning(disable:4214)
45 #pragma  warning(disable:4115)
46 #pragma  warning(disable:4514)
47
48 #include <ntddk.h>
49 #include <windef.h>
50
51 #endif /* _WIN32 */
52
53 #ifdef LINUX
54 #include <asm/uaccess.h>
55 #include "pvr_uaccess.h"
56 #endif /* LINUX */
57
58 #include "img_types.h"
59 #include "dbgdrvif_srv5.h"
60 #include "dbgdriv.h"
61 #include "dbgdriv_ioctl.h"
62 #include "hostfunc.h"
63
64 #ifdef _WIN32
65 #pragma  warning(default:4214)
66 #pragma  warning(default:4115)
67 #endif /* _WIN32 */
68
69 /*****************************************************************************
70  Code
71 *****************************************************************************/
72
73 /*****************************************************************************
74  FUNCTION       :       DBGDIOCDrivGetServiceTable
75
76  PURPOSE        :
77
78  PARAMETERS     :
79
80  RETURNS        :
81 *****************************************************************************/
82 static IMG_UINT32 DBGDIOCDrivGetServiceTable(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
83 {
84         void **ppvOut;
85
86         PVR_UNREFERENCED_PARAMETER(pvInBuffer);
87         PVR_UNREFERENCED_PARAMETER(bCompat);
88         ppvOut = (void **) pvOutBuffer;
89
90         *ppvOut = DBGDrivGetServiceTable();
91
92     return(IMG_TRUE);
93 }
94
95 #if defined(__QNXNTO__)
96 /*****************************************************************************
97  FUNCTION       :       DBGIODrivCreateStream
98
99  PURPOSE        :
100
101  PARAMETERS     :
102
103  RETURNS        :
104 *****************************************************************************/
105 static IMG_UINT32 DBGDIOCDrivCreateStream(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
106 {
107         PDBG_IN_CREATESTREAM psIn;
108         PDBG_OUT_CREATESTREAM psOut;
109
110         PVR_UNREFERENCED_PARAMETER(bCompat);
111
112         psIn = (PDBG_IN_CREATESTREAM) pvInBuffer;
113         psOut = (PDBG_OUT_CREATESTREAM) pvOutBuffer;
114
115         return (ExtDBGDrivCreateStream(psIn->u.pszName, DEBUG_FLAGS_NO_BUF_EXPANDSION, psIn->ui32Pages, &psOut->phInit, &psOut->phMain, &psOut->phDeinit));
116 }
117 #endif
118
119 /*****************************************************************************
120  FUNCTION       :       DBGDIOCDrivGetStream
121
122  PURPOSE        :
123
124  PARAMETERS     :
125
126  RETURNS        :
127 *****************************************************************************/
128 static IMG_UINT32 DBGDIOCDrivGetStream(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
129 {
130         PDBG_IN_FINDSTREAM psParams;
131         IMG_SID *       phStream;
132
133         psParams        = (PDBG_IN_FINDSTREAM)pvInBuffer;
134         phStream        = (IMG_SID *)pvOutBuffer;
135
136         /* Ensure that the name will be NULL terminated */
137         psParams->pszName[DEBUG_STREAM_NAME_MAX-1] = '\0';
138
139         *phStream = PStream2SID(ExtDBGDrivFindStream(psParams->pszName, psParams->bResetStream));
140
141         return(IMG_TRUE);
142 }
143
144 /*****************************************************************************
145  FUNCTION       :       DBGDIOCDrivRead
146
147  PURPOSE        :
148
149  PARAMETERS     :
150
151  RETURNS        :
152 *****************************************************************************/
153 static IMG_UINT32 DBGDIOCDrivRead(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
154 {
155         IMG_UINT32 *    pui32BytesCopied;
156         PDBG_IN_READ    psInParams;
157         PDBG_STREAM             psStream;
158         IMG_UINT8       *pui8ReadBuffer;
159
160         psInParams = (PDBG_IN_READ) pvInBuffer;
161         pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer;
162         pui8ReadBuffer = WIDEPTR_GET_PTR(psInParams->pui8OutBuffer, bCompat);
163
164         psStream = SID2PStream(psInParams->hStream);
165
166         if (psStream != (PDBG_STREAM)NULL)
167         {
168                 *pui32BytesCopied = ExtDBGDrivRead(psStream,
169                                                                            psInParams->ui32BufID,
170                                                                            psInParams->ui32OutBufferSize,
171                                                                            pui8ReadBuffer);
172                 return(IMG_TRUE);
173         }
174         else
175         {
176                 /* invalid SID */
177                 *pui32BytesCopied = 0;
178                 return(IMG_FALSE);
179         }
180 }
181
182 /*****************************************************************************
183  FUNCTION       : DBGDIOCDrivSetMarker
184
185  PURPOSE        : Sets the marker in the stream to split output files
186
187  PARAMETERS     : pvInBuffer, pvOutBuffer
188
189  RETURNS        : success
190 *****************************************************************************/
191 static IMG_UINT32 DBGDIOCDrivSetMarker(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
192 {
193         PDBG_IN_SETMARKER       psParams;
194         PDBG_STREAM                     psStream;
195
196         psParams = (PDBG_IN_SETMARKER) pvInBuffer;
197         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
198         PVR_UNREFERENCED_PARAMETER(bCompat);
199
200         psStream = SID2PStream(psParams->hStream);
201         if (psStream != (PDBG_STREAM)NULL)
202         {
203                 ExtDBGDrivSetMarker(psStream, psParams->ui32Marker);
204                 return(IMG_TRUE);
205         }
206         else
207         {
208                 /* invalid SID */
209                 return(IMG_FALSE);
210         }
211 }
212
213 /*****************************************************************************
214  FUNCTION       : DBGDIOCDrivGetMarker
215
216  PURPOSE        : Gets the marker in the stream to split output files
217
218  PARAMETERS     : pvInBuffer, pvOutBuffer
219
220  RETURNS        : success
221 *****************************************************************************/
222 static IMG_UINT32 DBGDIOCDrivGetMarker(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
223 {
224         PDBG_STREAM  psStream;
225         IMG_UINT32  *pui32Current;
226
227         PVR_UNREFERENCED_PARAMETER(bCompat);
228
229         pui32Current = (IMG_UINT32 *) pvOutBuffer;
230
231         psStream = SID2PStream(*(IMG_SID *)pvInBuffer);
232         if (psStream != (PDBG_STREAM)NULL)
233         {
234                 *pui32Current = ExtDBGDrivGetMarker(psStream);
235                 return(IMG_TRUE);
236         }
237         else
238         {
239                 /* invalid SID */
240                 *pui32Current = 0;
241                 return(IMG_FALSE);
242         }
243 }
244
245
246 /*****************************************************************************
247  FUNCTION       :       DBGDIOCDrivWaitForEvent
248
249  PURPOSE        :
250
251  PARAMETERS     :
252
253  RETURNS        :
254 *****************************************************************************/
255 static IMG_UINT32 DBGDIOCDrivWaitForEvent(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
256 {
257         DBG_EVENT eEvent = (DBG_EVENT)(*(IMG_UINT32 *)pvInBuffer);
258
259         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
260         PVR_UNREFERENCED_PARAMETER(bCompat);
261
262         ExtDBGDrivWaitForEvent(eEvent);
263
264         return(IMG_TRUE);
265 }
266
267
268 /*****************************************************************************
269  FUNCTION       : DBGDIOCDrivGetFrame
270
271  PURPOSE        : Gets the marker in the stream to split output files
272
273  PARAMETERS     : pvInBuffer, pvOutBuffer
274
275  RETURNS        : success
276 *****************************************************************************/
277 static IMG_UINT32 DBGDIOCDrivGetFrame(void * pvInBuffer, void * pvOutBuffer, IMG_BOOL bCompat)
278 {
279         IMG_UINT32  *pui32Current;
280
281         PVR_UNREFERENCED_PARAMETER(pvInBuffer);
282         PVR_UNREFERENCED_PARAMETER(bCompat);
283
284         pui32Current = (IMG_UINT32 *) pvOutBuffer;
285
286         *pui32Current = ExtDBGDrivGetFrame();
287
288         return(IMG_TRUE);
289 }
290
291 /*
292         ioctl interface jump table.
293         Accessed from the UM debug driver client
294 */
295 IMG_UINT32 (*g_DBGDrivProc[DEBUG_SERVICE_MAX_API])(void *, void *, IMG_BOOL) =
296 {
297         DBGDIOCDrivGetServiceTable, /* WDDM only for KMD to retrieve address from DBGDRV, Not used by umdbgdrvlnx */
298         DBGDIOCDrivGetStream,
299         DBGDIOCDrivRead,
300         DBGDIOCDrivSetMarker,
301         DBGDIOCDrivGetMarker,
302         DBGDIOCDrivWaitForEvent,
303         DBGDIOCDrivGetFrame,
304 #if defined(__QNXNTO__)
305         DBGDIOCDrivCreateStream
306 #endif
307 };
308
309 /*****************************************************************************
310  End of file (IOCTL.C)
311 *****************************************************************************/