~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/gpu/pvr/pdump/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 *
 
3
 * Copyright (C) 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/errno.h>
 
28
#include <linux/module.h>
 
29
#include <linux/fs.h>
 
30
#include <linux/kernel.h>
 
31
#include <linux/kdev_t.h>
 
32
#include <linux/pci.h>
 
33
#include <linux/list.h>
 
34
#include <linux/init.h>
 
35
#include <linux/vmalloc.h>
 
36
#include <linux/version.h>
 
37
 
 
38
#if defined(LDM_PLATFORM) && !defined(SUPPORT_DRI_DRM)
 
39
#include <linux/platform_device.h>
 
40
#endif
 
41
 
 
42
#if defined(LDM_PCI) && !defined(SUPPORT_DRI_DRM)
 
43
#include <linux/pci.h>
 
44
#endif
 
45
 
 
46
#include <asm/uaccess.h>
 
47
 
 
48
#if defined(SUPPORT_DRI_DRM)
 
49
#include "drmP.h"
 
50
#include "drm.h"
 
51
#endif
 
52
 
 
53
#include "img_types.h"
 
54
#include "linuxsrv.h"
 
55
#include "dbgdriv_ioctl.h"
 
56
#include "dbgdrvif.h"
 
57
#include "dbgdriv.h"
 
58
#include "hostfunc.h"
 
59
#include "hotkey.h"
 
60
#include "pvr_debug.h"
 
61
#include "pvrmodule.h"
 
62
#include "pvr_uaccess.h"
 
63
 
 
64
#if defined(SUPPORT_DRI_DRM)
 
65
 
 
66
#include "pvr_drm_shared.h"
 
67
#include "pvr_drm.h"
 
68
 
 
69
#else
 
70
 
 
71
#define DRVNAME "dbgdrv"
 
72
MODULE_SUPPORTED_DEVICE(DRVNAME);
 
73
 
 
74
#if (defined(LDM_PLATFORM) || defined(LDM_PCI)) && !defined(SUPPORT_DRI_DRM)
 
75
static struct class *psDbgDrvClass;
 
76
#endif
 
77
 
 
78
static int AssignedMajorNumber = 0;
 
79
 
 
80
long dbgdrv_ioctl(struct file *, unsigned int, unsigned long);
 
81
 
 
82
static int dbgdrv_open(struct inode unref__ * pInode, struct file unref__ * pFile)
 
83
{
 
84
        return 0;
 
85
}
 
86
 
 
87
static int dbgdrv_release(struct inode unref__ * pInode, struct file unref__ * pFile)
 
88
{
 
89
        return 0;
 
90
}
 
91
 
 
92
static int dbgdrv_mmap(struct file* pFile, struct vm_area_struct* ps_vma)
 
93
{
 
94
        return 0;
 
95
}
 
96
 
 
97
static struct file_operations dbgdrv_fops = {
 
98
        .owner          = THIS_MODULE,
 
99
        .unlocked_ioctl = dbgdrv_ioctl,
 
100
        .open           = dbgdrv_open,
 
101
        .release        = dbgdrv_release,
 
102
        .mmap           = dbgdrv_mmap,
 
103
};
 
104
 
 
105
#endif
 
106
 
 
107
IMG_VOID DBGDrvGetServiceTable(IMG_VOID **fn_table);
 
108
 
 
109
IMG_VOID DBGDrvGetServiceTable(IMG_VOID **fn_table)
 
110
{
 
111
        extern DBGKM_SERVICE_TABLE g_sDBGKMServices;
 
112
 
 
113
        *fn_table = &g_sDBGKMServices;
 
114
}
 
115
 
 
116
#if defined(SUPPORT_DRI_DRM)
 
117
void dbgdrv_cleanup(void)
 
118
#else
 
119
static void __exit dbgdrv_cleanup(void)
 
120
#endif
 
121
{
 
122
#if !defined(SUPPORT_DRI_DRM)
 
123
#if defined(LDM_PLATFORM) || defined(LDM_PCI)
 
124
        device_destroy(psDbgDrvClass, MKDEV(AssignedMajorNumber, 0));
 
125
        class_destroy(psDbgDrvClass);
 
126
#endif
 
127
        unregister_chrdev(AssignedMajorNumber, DRVNAME);
 
128
#endif
 
129
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
 
130
        HostDestroyEventObjects();
 
131
#endif
 
132
        HostDestroyMutex(g_pvAPIMutex);
 
133
        return;
 
134
}
 
135
 
 
136
#if defined(SUPPORT_DRI_DRM)
 
137
IMG_INT dbgdrv_init(void)
 
138
#else
 
139
static int __init dbgdrv_init(void)
 
140
#endif
 
141
{
 
142
#if (defined(LDM_PLATFORM) || defined(LDM_PCI)) && !defined(SUPPORT_DRI_DRM)
 
143
        struct device *psDev;
 
144
#endif
 
145
 
 
146
#if !defined(SUPPORT_DRI_DRM)
 
147
        int err = -EBUSY;
 
148
#endif
 
149
 
 
150
 
 
151
        if ((g_pvAPIMutex=HostCreateMutex()) == IMG_NULL)
 
152
        {
 
153
                return -ENOMEM;
 
154
        }
 
155
 
 
156
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
 
157
 
 
158
        (void) HostCreateEventObjects();
 
159
#endif
 
160
 
 
161
#if !defined(SUPPORT_DRI_DRM)
 
162
        AssignedMajorNumber =
 
163
        register_chrdev(AssignedMajorNumber, DRVNAME, &dbgdrv_fops);
 
164
 
 
165
        if (AssignedMajorNumber <= 0)
 
166
        {
 
167
                PVR_DPF((PVR_DBG_ERROR," unable to get major\n"));
 
168
                goto ErrDestroyEventObjects;
 
169
        }
 
170
 
 
171
#if defined(LDM_PLATFORM) || defined(LDM_PCI)
 
172
 
 
173
        psDbgDrvClass = class_create(THIS_MODULE, DRVNAME);
 
174
        if (IS_ERR(psDbgDrvClass))
 
175
        {
 
176
                PVR_DPF((PVR_DBG_ERROR, "%s: unable to create class (%ld)",
 
177
                                 __func__, PTR_ERR(psDbgDrvClass)));
 
178
                goto ErrUnregisterCharDev;
 
179
        }
 
180
 
 
181
        psDev = device_create(psDbgDrvClass, NULL, MKDEV(AssignedMajorNumber, 0),
 
182
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
 
183
                                                  NULL,
 
184
#endif
 
185
                                                  DRVNAME);
 
186
        if (IS_ERR(psDev))
 
187
        {
 
188
                PVR_DPF((PVR_DBG_ERROR, "%s: unable to create device (%ld)",
 
189
                                                                __func__, PTR_ERR(psDev)));
 
190
                goto ErrDestroyClass;
 
191
        }
 
192
#endif
 
193
#endif
 
194
 
 
195
        return 0;
 
196
 
 
197
#if !defined(SUPPORT_DRI_DRM)
 
198
ErrDestroyEventObjects:
 
199
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
 
200
        HostDestroyEventObjects();
 
201
#endif
 
202
#if defined(LDM_PLATFORM) || defined(LDM_PCI)
 
203
ErrUnregisterCharDev:
 
204
        unregister_chrdev(AssignedMajorNumber, DRVNAME);
 
205
ErrDestroyClass:
 
206
        class_destroy(psDbgDrvClass);
 
207
#endif
 
208
        return err;
 
209
#endif
 
210
}
 
211
 
 
212
#if defined(SUPPORT_DRI_DRM)
 
213
int dbgdrv_ioctl(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile)
 
214
#else
 
215
long dbgdrv_ioctl(struct file *file, unsigned int ioctlCmd, unsigned long arg)
 
216
#endif
 
217
{
 
218
        IOCTL_PACKAGE *pIP = (IOCTL_PACKAGE *) arg;
 
219
        char *buffer, *in, *out;
 
220
        unsigned int cmd;
 
221
 
 
222
        if((pIP->ui32InBufferSize > (PAGE_SIZE >> 1) ) || (pIP->ui32OutBufferSize > (PAGE_SIZE >> 1)))
 
223
        {
 
224
                PVR_DPF((PVR_DBG_ERROR,"Sizes of the buffers are too large, cannot do ioctl\n"));
 
225
                return -1;
 
226
        }
 
227
 
 
228
        buffer = (char *) HostPageablePageAlloc(1);
 
229
        if(!buffer)
 
230
        {
 
231
                PVR_DPF((PVR_DBG_ERROR,"Failed to allocate buffer, cannot do ioctl\n"));
 
232
                return -EFAULT;
 
233
        }
 
234
 
 
235
        in = buffer;
 
236
        out = buffer + (PAGE_SIZE >>1);
 
237
 
 
238
        if(pvr_copy_from_user(in, pIP->pInBuffer, pIP->ui32InBufferSize) != 0)
 
239
        {
 
240
                goto init_failed;
 
241
        }
 
242
 
 
243
 
 
244
        cmd = MAKEIOCTLINDEX(pIP->ui32Cmd) - DEBUG_SERVICE_IOCTL_BASE - 1;
 
245
 
 
246
        if(pIP->ui32Cmd == DEBUG_SERVICE_READ)
 
247
        {
 
248
                IMG_UINT32 *pui32BytesCopied = (IMG_UINT32 *)out;
 
249
                DBG_IN_READ *psReadInParams = (DBG_IN_READ *)in;
 
250
                DBG_STREAM *psStream;
 
251
                IMG_CHAR *ui8Tmp;
 
252
 
 
253
                ui8Tmp = vmalloc(psReadInParams->ui32OutBufferSize);
 
254
 
 
255
                if(!ui8Tmp)
 
256
                {
 
257
                        goto init_failed;
 
258
                }
 
259
 
 
260
                psStream = SID2PStream(psReadInParams->hStream);
 
261
                if(!psStream)
 
262
                {
 
263
                        goto init_failed;
 
264
                }
 
265
 
 
266
                *pui32BytesCopied = ExtDBGDrivRead(psStream,
 
267
                                                                                   psReadInParams->bReadInitBuffer,
 
268
                                                                                   psReadInParams->ui32OutBufferSize,
 
269
                                                                                   ui8Tmp);
 
270
 
 
271
                if(pvr_copy_to_user(psReadInParams->u.pui8OutBuffer,
 
272
                                                ui8Tmp,
 
273
                                                *pui32BytesCopied) != 0)
 
274
                {
 
275
                        vfree(ui8Tmp);
 
276
                        goto init_failed;
 
277
                }
 
278
 
 
279
                vfree(ui8Tmp);
 
280
        }
 
281
        else
 
282
        {
 
283
                (g_DBGDrivProc[cmd])(in, out);
 
284
        }
 
285
 
 
286
        if(copy_to_user(pIP->pOutBuffer, out, pIP->ui32OutBufferSize) != 0)
 
287
        {
 
288
                goto init_failed;
 
289
        }
 
290
 
 
291
        HostPageablePageFree((IMG_VOID *)buffer);
 
292
        return 0;
 
293
 
 
294
init_failed:
 
295
        HostPageablePageFree((IMG_VOID *)buffer);
 
296
        return -EFAULT;
 
297
}
 
298
 
 
299
 
 
300
IMG_VOID RemoveHotKey (IMG_UINT32 hHotKey)
 
301
{
 
302
        PVR_UNREFERENCED_PARAMETER(hHotKey);
 
303
}
 
304
 
 
305
IMG_VOID DefineHotKey (IMG_UINT32 ui32ScanCode, IMG_UINT32 ui32ShiftState, PHOTKEYINFO psInfo)
 
306
{
 
307
        PVR_UNREFERENCED_PARAMETER(ui32ScanCode);
 
308
        PVR_UNREFERENCED_PARAMETER(ui32ShiftState);
 
309
        PVR_UNREFERENCED_PARAMETER(psInfo);
 
310
}
 
311
 
 
312
EXPORT_SYMBOL(DBGDrvGetServiceTable);
 
313
 
 
314
#if !defined(SUPPORT_DRI_DRM)
 
315
subsys_initcall(dbgdrv_init);
 
316
module_exit(dbgdrv_cleanup);
 
317
#endif