~gma500/+junk/emgd152-natty

« back to all changes in this revision

Viewing changes to emgd-dkms-1.5.15.3082/pvr/tools/intern/debug/dbgdriv/linux/hostfunc.c

  • Committer: Luca Forina
  • Date: 2011-02-06 15:11:54 UTC
  • Revision ID: luca.forina@gmail.com-20110206151154-9dzn5ugxjub9qenb
Upload Emgd 1.5.2 for Natty (override Maverick)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/version.h>
 
28
#include <linux/errno.h>
 
29
#include <linux/module.h>
 
30
#include <linux/fs.h>
 
31
#include <linux/kernel.h>
 
32
#include <linux/mm.h>
 
33
#include <linux/string.h>
 
34
#include <asm/page.h>
 
35
#include <linux/vmalloc.h>
 
36
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
 
37
#include <linux/mutex.h>
 
38
#else
 
39
#include <asm/semaphore.h>
 
40
#endif
 
41
#include <linux/hardirq.h>
 
42
 
 
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>
 
48
#endif  
 
49
 
 
50
#include "img_types.h"
 
51
#include "pvr_debug.h"
 
52
 
 
53
#include "dbgdrvif.h"
 
54
#include "dbgdriv/common/hostfunc.h"
 
55
 
 
56
#if !defined(SUPPORT_DRI_DRM)
 
57
IMG_UINT32      gPVRDebugLevel = DBGPRIV_WARNING;
 
58
 
 
59
#define PVR_STRING_TERMINATOR           '\0'
 
60
#define PVR_IS_FILE_SEPARATOR(character) ( ((character) == '\\') || ((character) == '/') )
 
61
 
 
62
void PVRSRVDebugPrintf  (
 
63
                                                IMG_UINT32      ui32DebugLevel,
 
64
                                                const IMG_CHAR* pszFileName,
 
65
                                                IMG_UINT32      ui32Line,
 
66
                                                const IMG_CHAR* pszFormat,
 
67
                                                ...
 
68
                                        )
 
69
{
 
70
        IMG_BOOL bTrace, bDebug;
 
71
#if !defined(__sh__)
 
72
        IMG_CHAR *pszLeafName;
 
73
        
 
74
        pszLeafName = (char *)strrchr (pszFileName, '\\');
 
75
        
 
76
        if (pszLeafName)
 
77
        {
 
78
                pszFileName = pszLeafName;
 
79
        }
 
80
#endif 
 
81
                
 
82
        bTrace = gPVRDebugLevel & ui32DebugLevel & DBGPRIV_CALLTRACE;
 
83
        bDebug = ((gPVRDebugLevel & DBGPRIV_ALLLEVELS) >= ui32DebugLevel);
 
84
 
 
85
        if (bTrace || bDebug)
 
86
        {
 
87
                va_list vaArgs;
 
88
                static char szBuffer[256];
 
89
 
 
90
                va_start (vaArgs, pszFormat);
 
91
 
 
92
                
 
93
                if (bDebug)
 
94
                {
 
95
                        switch(ui32DebugLevel)
 
96
                        {
 
97
                                case DBGPRIV_FATAL:
 
98
                                {
 
99
                                        strcpy (szBuffer, "PVR_K:(Fatal): ");
 
100
                                        break;
 
101
                                }
 
102
                                case DBGPRIV_ERROR:
 
103
                                {
 
104
                                        strcpy (szBuffer, "PVR_K:(Error): ");
 
105
                                        break;
 
106
                                }
 
107
                                case DBGPRIV_WARNING:
 
108
                                {
 
109
                                        strcpy (szBuffer, "PVR_K:(Warning): ");
 
110
                                        break;
 
111
                                }
 
112
                                case DBGPRIV_MESSAGE:
 
113
                                {
 
114
                                        strcpy (szBuffer, "PVR_K:(Message): ");
 
115
                                        break;
 
116
                                }
 
117
                                case DBGPRIV_VERBOSE:
 
118
                                {
 
119
                                        strcpy (szBuffer, "PVR_K:(Verbose): ");
 
120
                                        break;
 
121
                                }
 
122
                                default:
 
123
                                {
 
124
                                        strcpy (szBuffer, "PVR_K:(Unknown message level)");
 
125
                                        break;
 
126
                                }
 
127
                        }
 
128
                }
 
129
                else
 
130
                {
 
131
                        strcpy (szBuffer, "PVR_K: ");
 
132
                }
 
133
 
 
134
                vsprintf (&szBuffer[strlen(szBuffer)], pszFormat, vaArgs);
 
135
 
 
136
                
 
137
 
 
138
                if (!bTrace)
 
139
                {
 
140
                        sprintf (&szBuffer[strlen(szBuffer)], " [%d, %s]", (int)ui32Line, pszFileName);
 
141
                }
 
142
 
 
143
                printk(KERN_INFO "%s\r\n", szBuffer);
 
144
 
 
145
                va_end (vaArgs);
 
146
        }
 
147
}
 
148
#endif  
 
149
 
 
150
IMG_VOID HostMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_UINT32 ui32Size)
 
151
{
 
152
        memset(pvDest, (int) ui8Value, (size_t) ui32Size);
 
153
}
 
154
 
 
155
IMG_VOID HostMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
 
156
{
 
157
#if defined(USE_UNOPTIMISED_MEMCPY)
 
158
    unsigned char *src,*dst;
 
159
    int i;
 
160
 
 
161
    src=(unsigned char *)pvSrc;
 
162
    dst=(unsigned char *)pvDst;
 
163
    for(i=0;i<ui32Size;i++)
 
164
    {
 
165
        dst[i]=src[i];
 
166
    }
 
167
#else
 
168
    memcpy(pvDst, pvSrc, ui32Size);
 
169
#endif
 
170
}
 
171
 
 
172
IMG_UINT32 HostReadRegistryDWORDFromString(char *pcKey, char *pcValueName, IMG_UINT32 *pui32Data)
 
173
{
 
174
    
 
175
        return 0;
 
176
}
 
177
 
 
178
IMG_VOID * HostPageablePageAlloc(IMG_UINT32 ui32Pages)
 
179
{
 
180
    return (void*)vmalloc(ui32Pages * PAGE_SIZE);
 
181
}
 
182
 
 
183
IMG_VOID HostPageablePageFree(IMG_VOID * pvBase)
 
184
{
 
185
    vfree(pvBase);
 
186
}
 
187
 
 
188
IMG_VOID * HostNonPageablePageAlloc(IMG_UINT32 ui32Pages)
 
189
{
 
190
    return (void*)vmalloc(ui32Pages * PAGE_SIZE);
 
191
}
 
192
 
 
193
IMG_VOID HostNonPageablePageFree(IMG_VOID * pvBase)
 
194
{
 
195
    vfree(pvBase);
 
196
}
 
197
 
 
198
IMG_VOID * HostMapKrnBufIntoUser(IMG_VOID * pvKrnAddr, IMG_UINT32 ui32Size, IMG_VOID **ppvMdl)
 
199
{
 
200
    
 
201
        return IMG_NULL;
 
202
}
 
203
 
 
204
IMG_VOID HostUnMapKrnBufFromUser(IMG_VOID * pvUserAddr, IMG_VOID * pvMdl, IMG_VOID * pvProcess)
 
205
{
 
206
    
 
207
}
 
208
 
 
209
IMG_VOID HostCreateRegDeclStreams(IMG_VOID)
 
210
{
 
211
    
 
212
}
 
213
 
 
214
IMG_VOID * HostCreateMutex(IMG_VOID)
 
215
{
 
216
        struct semaphore *psSem;
 
217
 
 
218
        psSem = kmalloc(sizeof(*psSem), GFP_KERNEL);
 
219
        if (psSem)
 
220
        {
 
221
                init_MUTEX(psSem);
 
222
        }
 
223
 
 
224
        return psSem;
 
225
}
 
226
 
 
227
IMG_VOID HostAquireMutex(IMG_VOID * pvMutex)
 
228
{
 
229
        BUG_ON(in_interrupt());
 
230
 
 
231
#if defined(PVR_DEBUG_DBGDRV_DETECT_HOST_MUTEX_COLLISIONS)
 
232
        if (down_trylock((struct semaphore *)pvMutex))
 
233
        {
 
234
                printk(KERN_INFO "HostAquireMutex: Waiting for mutex\n");
 
235
                down((struct semaphore *)pvMutex);
 
236
        }
 
237
#else
 
238
        down((struct semaphore *)pvMutex);
 
239
#endif
 
240
}
 
241
 
 
242
IMG_VOID HostReleaseMutex(IMG_VOID * pvMutex)
 
243
{
 
244
        up((struct semaphore *)pvMutex);
 
245
}
 
246
 
 
247
IMG_VOID HostDestroyMutex(IMG_VOID * pvMutex)
 
248
{
 
249
        if (pvMutex)
 
250
        {
 
251
                kfree(pvMutex);
 
252
        }
 
253
}
 
254
 
 
255
#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS)
 
256
 
 
257
#define EVENT_WAIT_TIMEOUT_MS   500
 
258
#define EVENT_WAIT_TIMEOUT_JIFFIES      (EVENT_WAIT_TIMEOUT_MS * HZ / 1000)
 
259
 
 
260
static int iStreamData;
 
261
static wait_queue_head_t sStreamDataEvent;
 
262
 
 
263
IMG_INT32 HostCreateEventObjects(IMG_VOID)
 
264
{
 
265
        init_waitqueue_head(&sStreamDataEvent);
 
266
 
 
267
        return 0;
 
268
}
 
269
 
 
270
IMG_VOID HostWaitForEvent(DBG_EVENT eEvent)
 
271
{
 
272
        switch(eEvent)
 
273
        {
 
274
                case DBG_EVENT_STREAM_DATA:
 
275
                        
 
276
                        wait_event_interruptible_timeout(sStreamDataEvent, iStreamData != 0, EVENT_WAIT_TIMEOUT_JIFFIES);
 
277
                        iStreamData = 0;
 
278
                        break;
 
279
                default:
 
280
                        
 
281
                        msleep_interruptible(EVENT_WAIT_TIMEOUT_MS);
 
282
                        break;
 
283
        }
 
284
}
 
285
 
 
286
IMG_VOID HostSignalEvent(DBG_EVENT eEvent)
 
287
{
 
288
        switch(eEvent)
 
289
        {
 
290
                case DBG_EVENT_STREAM_DATA:
 
291
                        iStreamData = 1;
 
292
                        wake_up_interruptible(&sStreamDataEvent);
 
293
                        break;
 
294
                default:
 
295
                        break;
 
296
        }
 
297
}
 
298
 
 
299
IMG_VOID HostDestroyEventObjects(IMG_VOID)
 
300
{
 
301
}
 
302
#endif