1
/**********************************************************************
3
* Copyright (C) Imagination Technologies Ltd. All rights reserved.
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.
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.
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.
18
* The full GNU General Public License is included in this distribution in
19
* the file called "COPYING".
21
* Contact Information:
22
* Imagination Technologies Ltd. <gpl-support@imgtec.com>
23
* Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
25
******************************************************************************/
27
#include <linux/errno.h>
28
#include <linux/module.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>
38
#if defined(LDM_PLATFORM) && !defined(SUPPORT_DRI_DRM)
39
#include <linux/platform_device.h>
42
#if defined(LDM_PCI) && !defined(SUPPORT_DRI_DRM)
43
#include <linux/pci.h>
46
#include <asm/uaccess.h>
48
#if defined(SUPPORT_DRI_DRM)
53
#include "img_types.h"
55
#include "dbgdriv_ioctl.h"
60
#include "pvr_debug.h"
61
#include "pvrmodule.h"
62
#include "pvr_uaccess.h"
64
#if defined(SUPPORT_DRI_DRM)
66
#include "pvr_drm_shared.h"
71
#define DRVNAME "dbgdrv"
72
MODULE_SUPPORTED_DEVICE(DRVNAME);
74
#if (defined(LDM_PLATFORM) || defined(LDM_PCI)) && !defined(SUPPORT_DRI_DRM)
75
static struct class *psDbgDrvClass;
78
static int AssignedMajorNumber = 0;
80
long dbgdrv_ioctl(struct file *, unsigned int, unsigned long);
82
static int dbgdrv_open(struct inode unref__ * pInode, struct file unref__ * pFile)
87
static int dbgdrv_release(struct inode unref__ * pInode, struct file unref__ * pFile)
92
static int dbgdrv_mmap(struct file* pFile, struct vm_area_struct* ps_vma)
97
static struct file_operations dbgdrv_fops = {
99
.unlocked_ioctl = dbgdrv_ioctl,
101
.release = dbgdrv_release,
107
IMG_VOID DBGDrvGetServiceTable(IMG_VOID **fn_table);
109
IMG_VOID DBGDrvGetServiceTable(IMG_VOID **fn_table)
111
extern DBGKM_SERVICE_TABLE g_sDBGKMServices;
113
*fn_table = &g_sDBGKMServices;
116
#if defined(SUPPORT_DRI_DRM)
117
void dbgdrv_cleanup(void)
119
static void __exit dbgdrv_cleanup(void)
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);
127
unregister_chrdev(AssignedMajorNumber, DRVNAME);
129
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
130
HostDestroyEventObjects();
132
HostDestroyMutex(g_pvAPIMutex);
136
#if defined(SUPPORT_DRI_DRM)
137
IMG_INT dbgdrv_init(void)
139
static int __init dbgdrv_init(void)
142
#if (defined(LDM_PLATFORM) || defined(LDM_PCI)) && !defined(SUPPORT_DRI_DRM)
143
struct device *psDev;
146
#if !defined(SUPPORT_DRI_DRM)
151
if ((g_pvAPIMutex=HostCreateMutex()) == IMG_NULL)
156
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
158
(void) HostCreateEventObjects();
161
#if !defined(SUPPORT_DRI_DRM)
162
AssignedMajorNumber =
163
register_chrdev(AssignedMajorNumber, DRVNAME, &dbgdrv_fops);
165
if (AssignedMajorNumber <= 0)
167
PVR_DPF((PVR_DBG_ERROR," unable to get major\n"));
168
goto ErrDestroyEventObjects;
171
#if defined(LDM_PLATFORM) || defined(LDM_PCI)
173
psDbgDrvClass = class_create(THIS_MODULE, DRVNAME);
174
if (IS_ERR(psDbgDrvClass))
176
PVR_DPF((PVR_DBG_ERROR, "%s: unable to create class (%ld)",
177
__func__, PTR_ERR(psDbgDrvClass)));
178
goto ErrUnregisterCharDev;
181
psDev = device_create(psDbgDrvClass, NULL, MKDEV(AssignedMajorNumber, 0),
182
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
188
PVR_DPF((PVR_DBG_ERROR, "%s: unable to create device (%ld)",
189
__func__, PTR_ERR(psDev)));
190
goto ErrDestroyClass;
197
#if !defined(SUPPORT_DRI_DRM)
198
ErrDestroyEventObjects:
199
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
200
HostDestroyEventObjects();
202
#if defined(LDM_PLATFORM) || defined(LDM_PCI)
203
ErrUnregisterCharDev:
204
unregister_chrdev(AssignedMajorNumber, DRVNAME);
206
class_destroy(psDbgDrvClass);
212
#if defined(SUPPORT_DRI_DRM)
213
int dbgdrv_ioctl(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile)
215
long dbgdrv_ioctl(struct file *file, unsigned int ioctlCmd, unsigned long arg)
218
IOCTL_PACKAGE *pIP = (IOCTL_PACKAGE *) arg;
219
char *buffer, *in, *out;
222
if((pIP->ui32InBufferSize > (PAGE_SIZE >> 1) ) || (pIP->ui32OutBufferSize > (PAGE_SIZE >> 1)))
224
PVR_DPF((PVR_DBG_ERROR,"Sizes of the buffers are too large, cannot do ioctl\n"));
228
buffer = (char *) HostPageablePageAlloc(1);
231
PVR_DPF((PVR_DBG_ERROR,"Failed to allocate buffer, cannot do ioctl\n"));
236
out = buffer + (PAGE_SIZE >>1);
238
if(pvr_copy_from_user(in, pIP->pInBuffer, pIP->ui32InBufferSize) != 0)
244
cmd = MAKEIOCTLINDEX(pIP->ui32Cmd) - DEBUG_SERVICE_IOCTL_BASE - 1;
246
if(pIP->ui32Cmd == DEBUG_SERVICE_READ)
248
IMG_UINT32 *pui32BytesCopied = (IMG_UINT32 *)out;
249
DBG_IN_READ *psReadInParams = (DBG_IN_READ *)in;
250
DBG_STREAM *psStream;
253
ui8Tmp = vmalloc(psReadInParams->ui32OutBufferSize);
260
psStream = SID2PStream(psReadInParams->hStream);
266
*pui32BytesCopied = ExtDBGDrivRead(psStream,
267
psReadInParams->bReadInitBuffer,
268
psReadInParams->ui32OutBufferSize,
271
if(pvr_copy_to_user(psReadInParams->u.pui8OutBuffer,
273
*pui32BytesCopied) != 0)
283
(g_DBGDrivProc[cmd])(in, out);
286
if(copy_to_user(pIP->pOutBuffer, out, pIP->ui32OutBufferSize) != 0)
291
HostPageablePageFree((IMG_VOID *)buffer);
295
HostPageablePageFree((IMG_VOID *)buffer);
300
IMG_VOID RemoveHotKey (IMG_UINT32 hHotKey)
302
PVR_UNREFERENCED_PARAMETER(hHotKey);
305
IMG_VOID DefineHotKey (IMG_UINT32 ui32ScanCode, IMG_UINT32 ui32ShiftState, PHOTKEYINFO psInfo)
307
PVR_UNREFERENCED_PARAMETER(ui32ScanCode);
308
PVR_UNREFERENCED_PARAMETER(ui32ShiftState);
309
PVR_UNREFERENCED_PARAMETER(psInfo);
312
EXPORT_SYMBOL(DBGDrvGetServiceTable);
314
#if !defined(SUPPORT_DRI_DRM)
315
subsys_initcall(dbgdrv_init);
316
module_exit(dbgdrv_cleanup);