gpu: pvr: move debugfs infrastructure to its own files
[sgx.git] / pvr / tools / ioctl.c
1 /**********************************************************************
2  *
3  * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful but, except
10  * as otherwise stated in writing, without any warranty; without even the
11  * implied warranty of merchantability or fitness for a particular purpose.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * The full GNU General Public License is included in this distribution in
19  * the file called "COPYING".
20  *
21  * Contact Information:
22  * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23  * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
24  *
25  ******************************************************************************/
26
27 #include <linux/uaccess.h>
28
29 #include "img_types.h"
30 #include "dbgdrvif.h"
31 #include "dbgdriv.h"
32 #include "hotkey.h"
33
34 u32 DBGDIOCDrivCreateStream(void *pvInBuffer,
35                                    void *pvOutBuffer)
36 {
37         struct DBG_IN_CREATESTREAM *psIn;
38         void **ppvOut;
39         static char name[32];
40
41         psIn = (struct DBG_IN_CREATESTREAM *)pvInBuffer;
42         ppvOut = (void **)pvOutBuffer;
43
44
45         if (copy_from_user(name, psIn->pszName, 32) != 0)
46                 return IMG_FALSE;
47         *ppvOut =
48             ExtDBGDrivCreateStream(name, psIn->ui32CapMode, psIn->ui32OutMode,
49                                    0, psIn->ui32Pages);
50
51
52         return IMG_TRUE;
53 }
54
55 u32 DBGDIOCDrivDestroyStream(void *pvInBuffer,
56                                     void *pvOutBuffer)
57 {
58         u32 *pStream;
59         struct DBG_STREAM *psStream;
60
61         pStream = (u32 *) pvInBuffer;
62         psStream = (struct DBG_STREAM *)*pStream;
63
64         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
65
66         ExtDBGDrivDestroyStream(psStream);
67
68         return IMG_TRUE;
69 }
70
71 u32 DBGDIOCDrivGetStream(void *pvInBuffer, void *pvOutBuffer)
72 {
73         struct DBG_IN_FINDSTREAM *psParams;
74         u32 *pui32Stream;
75
76         psParams = (struct DBG_IN_FINDSTREAM *)pvInBuffer;
77         pui32Stream = (u32 *) pvOutBuffer;
78
79         *pui32Stream =
80             (u32) ExtDBGDrivFindStream(psParams->pszName,
81                                               psParams->bResetStream);
82
83         return IMG_TRUE;
84 }
85
86 u32 DBGDIOCDrivWriteString(void *pvInBuffer, void *pvOutBuffer)
87 {
88         struct DBG_IN_WRITESTRING *psParams;
89         u32 *pui32OutLen;
90
91         psParams = (struct DBG_IN_WRITESTRING *)pvInBuffer;
92         pui32OutLen = (u32 *) pvOutBuffer;
93
94         *pui32OutLen =
95             ExtDBGDrivWriteString((struct DBG_STREAM *)psParams->pvStream,
96                                   psParams->pszString, psParams->ui32Level);
97
98         return IMG_TRUE;
99 }
100
101 u32 DBGDIOCDrivWriteStringCM(void *pvInBuffer,
102                                     void *pvOutBuffer)
103 {
104         struct DBG_IN_WRITESTRING *psParams;
105         u32 *pui32OutLen;
106
107         psParams = (struct DBG_IN_WRITESTRING *)pvInBuffer;
108         pui32OutLen = (u32 *) pvOutBuffer;
109
110         *pui32OutLen =
111             ExtDBGDrivWriteStringCM((struct DBG_STREAM *)psParams->pvStream,
112                                     psParams->pszString, psParams->ui32Level);
113
114         return IMG_TRUE;
115 }
116
117 u32 DBGDIOCDrivReadString(void *pvInBuffer, void *pvOutBuffer)
118 {
119         u32 *pui32OutLen;
120         struct DBG_IN_READSTRING *psParams;
121
122         psParams = (struct DBG_IN_READSTRING *)pvInBuffer;
123         pui32OutLen = (u32 *) pvOutBuffer;
124
125         *pui32OutLen =
126             ExtDBGDrivReadString(psParams->pvStream, psParams->pszString,
127                                  psParams->ui32StringLen);
128
129         return IMG_TRUE;
130 }
131
132 u32 DBGDIOCDrivWrite(void *pvInBuffer, void *pvOutBuffer)
133 {
134         u32 *pui32BytesCopied;
135         struct DBG_IN_WRITE *psInParams;
136
137         psInParams = (struct DBG_IN_WRITE *)pvInBuffer;
138         pui32BytesCopied = (u32 *) pvOutBuffer;
139
140         *pui32BytesCopied =
141             ExtDBGDrivWrite((struct DBG_STREAM *)psInParams->pvStream,
142                             psInParams->pui8InBuffer,
143                             psInParams->ui32TransferSize,
144                             psInParams->ui32Level);
145
146         return IMG_TRUE;
147 }
148
149 u32 DBGDIOCDrivWrite2(void *pvInBuffer, void *pvOutBuffer)
150 {
151         u32 *pui32BytesCopied;
152         struct DBG_IN_WRITE *psInParams;
153
154         psInParams = (struct DBG_IN_WRITE *)pvInBuffer;
155         pui32BytesCopied = (u32 *) pvOutBuffer;
156
157         *pui32BytesCopied =
158             ExtDBGDrivWrite2((struct DBG_STREAM *)psInParams->pvStream,
159                              psInParams->pui8InBuffer,
160                              psInParams->ui32TransferSize,
161                              psInParams->ui32Level);
162
163         return IMG_TRUE;
164 }
165
166 u32 DBGDIOCDrivWriteCM(void *pvInBuffer, void *pvOutBuffer)
167 {
168         u32 *pui32BytesCopied;
169         struct DBG_IN_WRITE *psInParams;
170
171         psInParams = (struct DBG_IN_WRITE *)pvInBuffer;
172         pui32BytesCopied = (u32 *) pvOutBuffer;
173
174         *pui32BytesCopied =
175             ExtDBGDrivWriteCM((struct DBG_STREAM *)psInParams->pvStream,
176                               psInParams->pui8InBuffer,
177                               psInParams->ui32TransferSize,
178                               psInParams->ui32Level);
179
180         return IMG_TRUE;
181 }
182
183 u32 DBGDIOCDrivRead(void *pvInBuffer, void *pvOutBuffer)
184 {
185         u32 *pui32BytesCopied;
186         struct DBG_IN_READ *psInParams;
187
188         psInParams = (struct DBG_IN_READ *)pvInBuffer;
189         pui32BytesCopied = (u32 *) pvOutBuffer;
190
191         *pui32BytesCopied =
192             ExtDBGDrivRead((struct DBG_STREAM *)psInParams->pvStream,
193                            psInParams->bReadInitBuffer,
194                            psInParams->ui32OutBufferSize,
195                            psInParams->pui8OutBuffer);
196
197         return IMG_TRUE;
198 }
199
200 u32 DBGDIOCDrivSetCaptureMode(void *pvInBuffer,
201                                      void *pvOutBuffer)
202 {
203         struct DBG_IN_SETDEBUGMODE *psParams;
204
205         psParams = (struct DBG_IN_SETDEBUGMODE *)pvInBuffer;
206         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
207
208         ExtDBGDrivSetCaptureMode((struct DBG_STREAM *)psParams->pvStream,
209                                  psParams->ui32Mode,
210                                  psParams->ui32Start,
211                                  psParams->ui32End, psParams->ui32SampleRate);
212
213         return IMG_TRUE;
214 }
215
216 u32 DBGDIOCDrivSetOutMode(void *pvInBuffer, void *pvOutBuffer)
217 {
218         struct DBG_IN_SETDEBUGOUTMODE *psParams;
219
220         psParams = (struct DBG_IN_SETDEBUGOUTMODE *)pvInBuffer;
221         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
222
223         ExtDBGDrivSetOutputMode((struct DBG_STREAM *)psParams->pvStream,
224                                 psParams->ui32Mode);
225
226         return IMG_TRUE;
227 }
228
229 u32 DBGDIOCDrivSetDebugLevel(void *pvInBuffer,
230                                     void *pvOutBuffer)
231 {
232         struct DBG_IN_SETDEBUGLEVEL *psParams;
233
234         psParams = (struct DBG_IN_SETDEBUGLEVEL *)pvInBuffer;
235         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
236
237         ExtDBGDrivSetDebugLevel((struct DBG_STREAM *)psParams->pvStream,
238                                 psParams->ui32Level);
239
240         return IMG_TRUE;
241 }
242
243 u32 DBGDIOCDrivSetFrame(void *pvInBuffer, void *pvOutBuffer)
244 {
245         struct DBG_IN_SETFRAME *psParams;
246
247         psParams = (struct DBG_IN_SETFRAME *)pvInBuffer;
248         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
249
250         ExtDBGDrivSetFrame((struct DBG_STREAM *)psParams->pvStream,
251                            psParams->ui32Frame);
252
253         return IMG_TRUE;
254 }
255
256 u32 DBGDIOCDrivGetFrame(void *pvInBuffer, void *pvOutBuffer)
257 {
258         u32 *pStream;
259         struct DBG_STREAM *psStream;
260         u32 *pui32Current;
261
262         pStream = (u32 *) pvInBuffer;
263         psStream = (struct DBG_STREAM *)*pStream;
264         pui32Current = (u32 *) pvOutBuffer;
265
266         *pui32Current = ExtDBGDrivGetFrame(psStream);
267
268         return IMG_TRUE;
269 }
270
271 u32 DBGDIOCDrivIsCaptureFrame(void *pvInBuffer,
272                                      void *pvOutBuffer)
273 {
274         struct DBG_IN_ISCAPTUREFRAME *psParams;
275         u32 *pui32Current;
276
277         psParams = (struct DBG_IN_ISCAPTUREFRAME *)pvInBuffer;
278         pui32Current = (u32 *) pvOutBuffer;
279
280         *pui32Current =
281             ExtDBGDrivIsCaptureFrame((struct DBG_STREAM *)psParams->pvStream,
282                                      psParams->bCheckPreviousFrame);
283
284         return IMG_TRUE;
285 }
286
287 u32 DBGDIOCDrivOverrideMode(void *pvInBuffer,
288                                    void *pvOutBuffer)
289 {
290         struct DBG_IN_OVERRIDEMODE *psParams;
291
292         psParams = (struct DBG_IN_OVERRIDEMODE *)pvInBuffer;
293         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
294
295         ExtDBGDrivOverrideMode((struct DBG_STREAM *)psParams->pvStream,
296                                psParams->ui32Mode);
297
298         return IMG_TRUE;
299 }
300
301 u32 DBGDIOCDrivDefaultMode(void *pvInBuffer, void *pvOutBuffer)
302 {
303         u32 *pStream;
304         struct DBG_STREAM *psStream;
305
306         pStream = (u32 *) pvInBuffer;
307         psStream = (struct DBG_STREAM *)*pStream;
308
309         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
310
311         ExtDBGDrivDefaultMode(psStream);
312
313         return IMG_TRUE;
314 }
315
316 u32 DBGDIOCDrivSetMarker(void *pvInBuffer, void *pvOutBuffer)
317 {
318         struct DBG_IN_SETMARKER *psParams;
319
320         psParams = (struct DBG_IN_SETMARKER *)pvInBuffer;
321         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
322
323         ExtDBGDrivSetMarker((struct DBG_STREAM *)psParams->pvStream,
324                             psParams->ui32Marker);
325
326         return IMG_TRUE;
327 }
328
329 u32 DBGDIOCDrivGetMarker(void *pvInBuffer, void *pvOutBuffer)
330 {
331         u32 *pStream;
332         struct DBG_STREAM *psStream;
333         u32 *pui32Current;
334
335         pStream = (u32 *) pvInBuffer;
336         psStream = (struct DBG_STREAM *)*pStream;
337         pui32Current = (u32 *) pvOutBuffer;
338
339         *pui32Current = ExtDBGDrivGetMarker(psStream);
340
341         return IMG_TRUE;
342 }
343
344 u32 DBGDIOCDrivGetServiceTable(void *pvInBuffer,
345                                       void *pvOutBuffer)
346 {
347         u32 *pui32Out;
348
349         PVR_UNREFERENCED_PARAMETER(pvInBuffer);
350         pui32Out = (u32 *) pvOutBuffer;
351
352         *pui32Out = DBGDrivGetServiceTable();
353
354         return IMG_TRUE;
355 }
356
357 u32 DBGDIOCDrivWriteLF(void *pvInBuffer, void *pvOutBuffer)
358 {
359         struct DBG_IN_WRITE_LF *psInParams;
360         u32 *pui32BytesCopied;
361
362         psInParams = (struct DBG_IN_WRITE_LF *)pvInBuffer;
363         pui32BytesCopied = (u32 *) pvOutBuffer;
364
365         *pui32BytesCopied = ExtDBGDrivWriteLF(psInParams->pvStream,
366                                               psInParams->pui8InBuffer,
367                                               psInParams->ui32BufferSize,
368                                               psInParams->ui32Level,
369                                               psInParams->ui32Flags);
370
371         return IMG_TRUE;
372 }
373
374 u32 DBGDIOCDrivReadLF(void *pvInBuffer, void *pvOutBuffer)
375 {
376         u32 *pui32BytesCopied;
377         struct DBG_IN_READ *psInParams;
378
379         psInParams = (struct DBG_IN_READ *)pvInBuffer;
380         pui32BytesCopied = (u32 *) pvOutBuffer;
381
382         *pui32BytesCopied =
383             ExtDBGDrivReadLF((struct DBG_STREAM *)psInParams->pvStream,
384                              psInParams->ui32OutBufferSize,
385                              psInParams->pui8OutBuffer);
386
387         return IMG_TRUE;
388 }
389
390 u32 DBGDIOCDrivWaitForEvent(void *pvInBuffer, void *pvOutBuffer)
391 {
392         enum DBG_EVENT eEvent = (enum DBG_EVENT)(*(u32 *) pvInBuffer);
393
394         PVR_UNREFERENCED_PARAMETER(pvOutBuffer);
395
396         ExtDBGDrivWaitForEvent(eEvent);
397
398         return IMG_TRUE;
399 }