1
/**********************************************************************
3
* Copyright(c) 2008 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/version.h>
28
#include <linux/errno.h>
29
#include <linux/module.h>
31
#include <linux/kernel.h>
33
#include <linux/string.h>
35
#include <linux/vmalloc.h>
36
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
37
#include <linux/mutex.h>
39
#include <asm/semaphore.h>
41
#include <linux/hardirq.h>
43
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
44
#include <linux/sched.h>
45
#include <linux/wait.h>
46
#include <linux/jiffies.h>
47
#include <linux/delay.h>
50
#include "img_types.h"
51
#include "pvr_debug.h"
54
#include "dbgdriv/common/hostfunc.h"
56
#if !defined(SUPPORT_DRI_DRM)
57
IMG_UINT32 gPVRDebugLevel = DBGPRIV_WARNING;
59
#define PVR_STRING_TERMINATOR '\0'
60
#define PVR_IS_FILE_SEPARATOR(character) ( ((character) == '\\') || ((character) == '/') )
62
void PVRSRVDebugPrintf (
63
IMG_UINT32 ui32DebugLevel,
64
const IMG_CHAR* pszFileName,
66
const IMG_CHAR* pszFormat,
70
IMG_BOOL bTrace, bDebug;
72
IMG_CHAR *pszLeafName;
74
pszLeafName = (char *)strrchr (pszFileName, '\\');
78
pszFileName = pszLeafName;
82
bTrace = gPVRDebugLevel & ui32DebugLevel & DBGPRIV_CALLTRACE;
83
bDebug = ((gPVRDebugLevel & DBGPRIV_ALLLEVELS) >= ui32DebugLevel);
88
static char szBuffer[256];
90
va_start (vaArgs, pszFormat);
95
switch(ui32DebugLevel)
99
strcpy (szBuffer, "PVR_K:(Fatal): ");
104
strcpy (szBuffer, "PVR_K:(Error): ");
107
case DBGPRIV_WARNING:
109
strcpy (szBuffer, "PVR_K:(Warning): ");
112
case DBGPRIV_MESSAGE:
114
strcpy (szBuffer, "PVR_K:(Message): ");
117
case DBGPRIV_VERBOSE:
119
strcpy (szBuffer, "PVR_K:(Verbose): ");
124
strcpy (szBuffer, "PVR_K:(Unknown message level)");
131
strcpy (szBuffer, "PVR_K: ");
134
vsprintf (&szBuffer[strlen(szBuffer)], pszFormat, vaArgs);
140
sprintf (&szBuffer[strlen(szBuffer)], " [%d, %s]", (int)ui32Line, pszFileName);
143
printk(KERN_INFO "%s\r\n", szBuffer);
150
IMG_VOID HostMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_UINT32 ui32Size)
152
memset(pvDest, (int) ui8Value, (size_t) ui32Size);
155
IMG_VOID HostMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
157
#if defined(USE_UNOPTIMISED_MEMCPY)
158
unsigned char *src,*dst;
161
src=(unsigned char *)pvSrc;
162
dst=(unsigned char *)pvDst;
163
for(i=0;i<ui32Size;i++)
168
memcpy(pvDst, pvSrc, ui32Size);
172
IMG_UINT32 HostReadRegistryDWORDFromString(char *pcKey, char *pcValueName, IMG_UINT32 *pui32Data)
178
IMG_VOID * HostPageablePageAlloc(IMG_UINT32 ui32Pages)
180
return (void*)vmalloc(ui32Pages * PAGE_SIZE);
183
IMG_VOID HostPageablePageFree(IMG_VOID * pvBase)
188
IMG_VOID * HostNonPageablePageAlloc(IMG_UINT32 ui32Pages)
190
return (void*)vmalloc(ui32Pages * PAGE_SIZE);
193
IMG_VOID HostNonPageablePageFree(IMG_VOID * pvBase)
198
IMG_VOID * HostMapKrnBufIntoUser(IMG_VOID * pvKrnAddr, IMG_UINT32 ui32Size, IMG_VOID **ppvMdl)
204
IMG_VOID HostUnMapKrnBufFromUser(IMG_VOID * pvUserAddr, IMG_VOID * pvMdl, IMG_VOID * pvProcess)
209
IMG_VOID HostCreateRegDeclStreams(IMG_VOID)
214
IMG_VOID * HostCreateMutex(IMG_VOID)
216
struct semaphore *psSem;
218
psSem = kmalloc(sizeof(*psSem), GFP_KERNEL);
227
IMG_VOID HostAquireMutex(IMG_VOID * pvMutex)
229
BUG_ON(in_interrupt());
231
#if defined(PVR_DEBUG_DBGDRV_DETECT_HOST_MUTEX_COLLISIONS)
232
if (down_trylock((struct semaphore *)pvMutex))
234
printk(KERN_INFO "HostAquireMutex: Waiting for mutex\n");
235
down((struct semaphore *)pvMutex);
238
down((struct semaphore *)pvMutex);
242
IMG_VOID HostReleaseMutex(IMG_VOID * pvMutex)
244
up((struct semaphore *)pvMutex);
247
IMG_VOID HostDestroyMutex(IMG_VOID * pvMutex)
255
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
257
#define EVENT_WAIT_TIMEOUT_MS 500
258
#define EVENT_WAIT_TIMEOUT_JIFFIES (EVENT_WAIT_TIMEOUT_MS * HZ / 1000)
260
static int iStreamData;
261
static wait_queue_head_t sStreamDataEvent;
263
IMG_INT32 HostCreateEventObjects(IMG_VOID)
265
init_waitqueue_head(&sStreamDataEvent);
270
IMG_VOID HostWaitForEvent(DBG_EVENT eEvent)
274
case DBG_EVENT_STREAM_DATA:
276
wait_event_interruptible_timeout(sStreamDataEvent, iStreamData != 0, EVENT_WAIT_TIMEOUT_JIFFIES);
281
msleep_interruptible(EVENT_WAIT_TIMEOUT_MS);
286
IMG_VOID HostSignalEvent(DBG_EVENT eEvent)
290
case DBG_EVENT_STREAM_DATA:
292
wake_up_interruptible(&sStreamDataEvent);
299
IMG_VOID HostDestroyEventObjects(IMG_VOID)