~gma500/emgd/trunk

« back to all changes in this revision

Viewing changes to emgd-dkms-1.5.15.2856/pvr/services4/srvkm/env/linux/pvr_debug.c

  • Committer: José Bernardo Bandos
  • Date: 2010-08-28 16:04:10 UTC
  • Revision ID: jbs@jbs-laptop-20100828160410-nw5zohdn37oupdv2
First step to add emgd drivers from meego

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
  
 
28
#ifndef AUTOCONF_INCLUDED
 
29
 #include <linux/config.h>
 
30
#endif
 
31
 
 
32
#include <asm/io.h>
 
33
#include <asm/uaccess.h>
 
34
#include <linux/kernel.h>
 
35
#include <linux/hardirq.h>
 
36
#include <linux/module.h>
 
37
#include <linux/spinlock.h>
 
38
#include <linux/tty.h>                  
 
39
#include <stdarg.h>
 
40
#include "img_types.h"
 
41
#include "servicesext.h"
 
42
#include "pvr_debug.h"
 
43
#include "proc.h"
 
44
#include "mutex.h"
 
45
#include "linkage.h"
 
46
 
 
47
#if defined(PVRSRV_NEED_PVR_DPF)
 
48
 
 
49
#define PVR_MAX_FILEPATH_LEN 256
 
50
 
 
51
static IMG_UINT32 gPVRDebugLevel = DBGPRIV_WARNING;
 
52
 
 
53
#endif 
 
54
 
 
55
#define PVR_MAX_MSG_LEN PVR_MAX_DEBUG_MESSAGE_LEN
 
56
 
 
57
static IMG_CHAR gszBufferNonIRQ[PVR_MAX_MSG_LEN + 1];
 
58
 
 
59
static IMG_CHAR gszBufferIRQ[PVR_MAX_MSG_LEN + 1];
 
60
 
 
61
static PVRSRV_LINUX_MUTEX gsDebugMutexNonIRQ;
 
62
 
 
63
static spinlock_t gsDebugLockIRQ = SPIN_LOCK_UNLOCKED;
 
64
 
 
65
#define USE_SPIN_LOCK (in_interrupt() || !preemptible())
 
66
 
 
67
static inline void GetBufferLock(unsigned long *pulLockFlags)
 
68
{
 
69
        if (USE_SPIN_LOCK)
 
70
        {
 
71
                spin_lock_irqsave(&gsDebugLockIRQ, *pulLockFlags);
 
72
        }
 
73
        else
 
74
        {
 
75
                LinuxLockMutex(&gsDebugMutexNonIRQ);
 
76
        }
 
77
}
 
78
 
 
79
static inline void ReleaseBufferLock(unsigned long ulLockFlags)
 
80
{
 
81
        if (USE_SPIN_LOCK)
 
82
        {
 
83
                spin_unlock_irqrestore(&gsDebugLockIRQ, ulLockFlags);
 
84
        }
 
85
        else
 
86
        {
 
87
                LinuxUnLockMutex(&gsDebugMutexNonIRQ);
 
88
        }
 
89
}
 
90
 
 
91
static inline void SelectBuffer(IMG_CHAR **ppszBuf, IMG_UINT32 *pui32BufSiz)
 
92
{
 
93
        if (USE_SPIN_LOCK)
 
94
        {
 
95
                *ppszBuf = gszBufferIRQ;
 
96
                *pui32BufSiz = sizeof(gszBufferIRQ);
 
97
        }
 
98
        else
 
99
        {
 
100
                *ppszBuf = gszBufferNonIRQ;
 
101
                *pui32BufSiz = sizeof(gszBufferNonIRQ);
 
102
        }
 
103
}
 
104
 
 
105
static IMG_BOOL VBAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz, const IMG_CHAR* pszFormat, va_list VArgs)
 
106
{
 
107
        IMG_UINT32 ui32Used;
 
108
        IMG_UINT32 ui32Space;
 
109
        IMG_INT32 i32Len;
 
110
 
 
111
        ui32Used = strlen(pszBuf);
 
112
        BUG_ON(ui32Used >= ui32BufSiz);
 
113
        ui32Space = ui32BufSiz - ui32Used;
 
114
 
 
115
        i32Len = vsnprintf(&pszBuf[ui32Used], ui32Space, pszFormat, VArgs);
 
116
        pszBuf[ui32BufSiz - 1] = 0;
 
117
 
 
118
        
 
119
        return (i32Len < 0 || i32Len >= ui32Space);
 
120
}
 
121
 
 
122
IMG_VOID PVRDPFInit(IMG_VOID)
 
123
{
 
124
    LinuxInitMutex(&gsDebugMutexNonIRQ);
 
125
}
 
126
 
 
127
IMG_VOID PVRSRVReleasePrintf(const IMG_CHAR *pszFormat, ...)
 
128
{
 
129
        va_list vaArgs;
 
130
        unsigned long ulLockFlags = 0;
 
131
        IMG_CHAR *pszBuf;
 
132
        IMG_UINT32 ui32BufSiz;
 
133
 
 
134
        SelectBuffer(&pszBuf, &ui32BufSiz);
 
135
 
 
136
        va_start(vaArgs, pszFormat);
 
137
 
 
138
        GetBufferLock(&ulLockFlags);
 
139
        strncpy (pszBuf, "PVR_K: ", (ui32BufSiz -1));
 
140
 
 
141
        if (VBAppend(pszBuf, ui32BufSiz, pszFormat, vaArgs))
 
142
        {
 
143
                printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
 
144
        }
 
145
        else
 
146
        {
 
147
                printk(KERN_INFO "%s\n", pszBuf);
 
148
        }
 
149
 
 
150
        ReleaseBufferLock(ulLockFlags);
 
151
        va_end(vaArgs);
 
152
 
 
153
}
 
154
 
 
155
#if defined(PVRSRV_NEED_PVR_ASSERT)
 
156
 
 
157
IMG_VOID PVRSRVDebugAssertFail(const IMG_CHAR* pszFile, IMG_UINT32 uLine)
 
158
{
 
159
        PVRSRVDebugPrintf(DBGPRIV_FATAL, pszFile, uLine, "Debug assertion failed!");
 
160
        BUG();
 
161
}
 
162
 
 
163
#endif 
 
164
 
 
165
#if defined(PVRSRV_NEED_PVR_TRACE)
 
166
 
 
167
IMG_VOID PVRSRVTrace(const IMG_CHAR* pszFormat, ...)
 
168
{
 
169
        va_list VArgs;
 
170
        unsigned long ulLockFlags = 0;
 
171
        IMG_CHAR *pszBuf;
 
172
        IMG_UINT32 ui32BufSiz;
 
173
 
 
174
        SelectBuffer(&pszBuf, &ui32BufSiz);
 
175
 
 
176
        va_start(VArgs, pszFormat);
 
177
 
 
178
        GetBufferLock(&ulLockFlags);
 
179
 
 
180
        strncpy(pszBuf, "PVR: ", (ui32BufSiz -1));
 
181
 
 
182
        if (VBAppend(pszBuf, ui32BufSiz, pszFormat, VArgs))
 
183
        {
 
184
                printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
 
185
        }
 
186
        else
 
187
        {
 
188
                printk(KERN_INFO "%s\n", pszBuf);
 
189
        }
 
190
        
 
191
        ReleaseBufferLock(ulLockFlags);
 
192
 
 
193
        va_end(VArgs);
 
194
}
 
195
 
 
196
#endif 
 
197
 
 
198
#if defined(PVRSRV_NEED_PVR_DPF)
 
199
 
 
200
static IMG_BOOL BAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz, const IMG_CHAR *pszFormat, ...)
 
201
{
 
202
                va_list VArgs;
 
203
                IMG_BOOL bTrunc;
 
204
 
 
205
                va_start (VArgs, pszFormat);
 
206
                
 
207
                bTrunc = VBAppend(pszBuf, ui32BufSiz, pszFormat, VArgs);
 
208
 
 
209
                va_end (VArgs);
 
210
 
 
211
                return bTrunc;
 
212
}
 
213
 
 
214
IMG_VOID PVRSRVDebugPrintf      (
 
215
                                                IMG_UINT32      ui32DebugLevel,
 
216
                                                const IMG_CHAR* pszFullFileName,
 
217
                                                IMG_UINT32      ui32Line,
 
218
                                                const IMG_CHAR* pszFormat,
 
219
                                                ...
 
220
                                        )
 
221
{
 
222
        IMG_BOOL bTrace, bDebug;
 
223
        const IMG_CHAR *pszFileName = pszFullFileName;  
 
224
        IMG_CHAR *pszLeafName;  
 
225
                
 
226
        bTrace = gPVRDebugLevel & ui32DebugLevel & DBGPRIV_CALLTRACE;
 
227
        bDebug = ((gPVRDebugLevel & DBGPRIV_ALLLEVELS) >= ui32DebugLevel);
 
228
 
 
229
        if (bTrace || bDebug)
 
230
        {
 
231
                va_list vaArgs;
 
232
                unsigned long ulLockFlags = 0;
 
233
                IMG_CHAR *pszBuf;
 
234
                IMG_UINT32 ui32BufSiz;
 
235
 
 
236
                SelectBuffer(&pszBuf, &ui32BufSiz);
 
237
 
 
238
                va_start(vaArgs, pszFormat);
 
239
 
 
240
                GetBufferLock(&ulLockFlags);
 
241
 
 
242
                
 
243
                if (bDebug)
 
244
                {
 
245
                        switch(ui32DebugLevel)
 
246
                        {
 
247
                                case DBGPRIV_FATAL:
 
248
                                {
 
249
                                        strncpy (pszBuf, "PVR_K:(Fatal): ", (ui32BufSiz -1));
 
250
                                        break;
 
251
                                }
 
252
                                case DBGPRIV_ERROR:
 
253
                                {
 
254
                                        strncpy (pszBuf, "PVR_K:(Error): ", (ui32BufSiz -1));
 
255
                                        break;
 
256
                                }
 
257
                                case DBGPRIV_WARNING:
 
258
                                {
 
259
                                        strncpy (pszBuf, "PVR_K:(Warning): ", (ui32BufSiz -1));
 
260
                                        break;
 
261
                                }
 
262
                                case DBGPRIV_MESSAGE:
 
263
                                {
 
264
                                        strncpy (pszBuf, "PVR_K:(Message): ", (ui32BufSiz -1));
 
265
                                        break;
 
266
                                }
 
267
                                case DBGPRIV_VERBOSE:
 
268
                                {
 
269
                                        strncpy (pszBuf, "PVR_K:(Verbose): ", (ui32BufSiz -1));
 
270
                                        break;
 
271
                                }
 
272
                                default:
 
273
                                {
 
274
                                        strncpy (pszBuf, "PVR_K:(Unknown message level)", (ui32BufSiz -1));
 
275
                                        break;
 
276
                                }
 
277
                        }
 
278
                }
 
279
                else
 
280
                {
 
281
                        strncpy (pszBuf, "PVR_K: ", (ui32BufSiz -1));
 
282
                }
 
283
 
 
284
                if (VBAppend(pszBuf, ui32BufSiz, pszFormat, vaArgs))
 
285
                {
 
286
                        printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
 
287
                }
 
288
                else
 
289
                {
 
290
                        
 
291
                        if (!bTrace)
 
292
                        {
 
293
#ifdef DEBUG_LOG_PATH_TRUNCATE
 
294
                                
 
295
                                static IMG_CHAR szFileNameRewrite[PVR_MAX_FILEPATH_LEN];
 
296
 
 
297
                                IMG_CHAR* pszTruncIter;
 
298
                                IMG_CHAR* pszTruncBackInter;
 
299
        
 
300
                                
 
301
                                pszFileName = pszFullFileName + strlen(DEBUG_LOG_PATH_TRUNCATE)+1;
 
302
  
 
303
                                
 
304
                                strncpy(szFileNameRewrite, pszFileName,PVR_MAX_FILEPATH_LEN);
 
305
 
 
306
                                if(strlen(szFileNameRewrite) == PVR_MAX_FILEPATH_LEN-1) {
 
307
                                        IMG_CHAR szTruncateMassage[] = "FILENAME TRUNCATED";
 
308
                                        strcpy(szFileNameRewrite + (PVR_MAX_FILEPATH_LEN - 1 - strlen(szTruncateMassage)), szTruncateMassage);
 
309
                                }
 
310
 
 
311
                                pszTruncIter = szFileNameRewrite;
 
312
                                while(*pszTruncIter++ != 0) 
 
313
                                {
 
314
                                        IMG_CHAR* pszNextStartPoint;
 
315
                                        
 
316
                                        if(
 
317
                                           !( ( *pszTruncIter == '/' && (pszTruncIter-4 >= szFileNameRewrite) ) && 
 
318
                                                 ( *(pszTruncIter-1) == '.') &&
 
319
                                                 ( *(pszTruncIter-2) == '.') &&
 
320
                                                 ( *(pszTruncIter-3) == '/') )  
 
321
                                           ) continue;
 
322
  
 
323
                                        
 
324
                                        pszTruncBackInter = pszTruncIter - 3;
 
325
                                        while(*(--pszTruncBackInter) != '/') 
 
326
                                        {
 
327
                                                if(pszTruncBackInter <= szFileNameRewrite) break;
 
328
                                        }
 
329
                                        pszNextStartPoint = pszTruncBackInter;
 
330
 
 
331
                                        
 
332
                                        while(*pszTruncIter != 0) 
 
333
                                        {
 
334
                                                *pszTruncBackInter++ = *pszTruncIter++;
 
335
                                        }
 
336
                                        *pszTruncBackInter = 0;
 
337
 
 
338
                                        
 
339
                                        pszTruncIter = pszNextStartPoint;
 
340
                                }
 
341
 
 
342
                                pszFileName = szFileNameRewrite;
 
343
                                
 
344
                                if(*pszFileName == '/') pszFileName++;
 
345
#endif
 
346
 
 
347
#if !defined(__sh__)
 
348
                                pszLeafName = (IMG_CHAR *)strrchr (pszFileName, '\\');
 
349
        
 
350
                                if (pszLeafName)
 
351
                                {
 
352
                                        pszFileName = pszLeafName;
 
353
                        } 
 
354
#endif 
 
355
 
 
356
                                if (BAppend(pszBuf, ui32BufSiz, " [%lu, %s]", ui32Line, pszFileName))
 
357
                                {
 
358
                                        printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
 
359
                                }
 
360
                                else
 
361
                                {
 
362
                                        printk(KERN_INFO "%s\n", pszBuf);
 
363
                                }
 
364
                        }
 
365
                        else
 
366
                        {
 
367
                                printk(KERN_INFO "%s\n", pszBuf);
 
368
                        }
 
369
                }
 
370
 
 
371
                ReleaseBufferLock(ulLockFlags);
 
372
 
 
373
                va_end (vaArgs);
 
374
        }
 
375
}
 
376
 
 
377
#endif 
 
378
 
 
379
#if defined(DEBUG)
 
380
 
 
381
IMG_VOID PVRDebugSetLevel(IMG_UINT32 uDebugLevel)
 
382
{
 
383
        printk(KERN_INFO "PVR: Setting Debug Level = 0x%x\n",(IMG_UINT)uDebugLevel);
 
384
 
 
385
        gPVRDebugLevel = uDebugLevel;
 
386
}
 
387
 
 
388
IMG_INT PVRDebugProcSetLevel(struct file *file, const IMG_CHAR *buffer, IMG_UINT32 count, IMG_VOID *data)
 
389
{
 
390
#define _PROC_SET_BUFFER_SZ             2
 
391
        IMG_CHAR data_buffer[_PROC_SET_BUFFER_SZ];
 
392
 
 
393
        if (count != _PROC_SET_BUFFER_SZ)
 
394
        {
 
395
                return -EINVAL;
 
396
        }
 
397
        else
 
398
        {
 
399
                if (copy_from_user(data_buffer, buffer, count))
 
400
                        return -EINVAL;
 
401
                if (data_buffer[count - 1] != '\n')
 
402
                        return -EINVAL;
 
403
                PVRDebugSetLevel(data_buffer[0] - '0');
 
404
        }
 
405
        return (count);
 
406
}
 
407
 
 
408
#ifdef PVR_PROC_USE_SEQ_FILE
 
409
void ProcSeqShowDebugLevel(struct seq_file *sfile,void* el)     
 
410
{
 
411
        seq_printf(sfile, "%lu\n", gPVRDebugLevel);
 
412
}
 
413
 
 
414
#else 
 
415
IMG_INT PVRDebugProcGetLevel(IMG_CHAR *page, IMG_CHAR **start, off_t off, IMG_INT count, IMG_INT *eof, IMG_VOID *data)
 
416
{
 
417
        if (off == 0) {
 
418
                *start = (IMG_CHAR *)1;
 
419
                return printAppend(page, count, 0, "%lu\n", gPVRDebugLevel);
 
420
        }
 
421
        *eof = 1;
 
422
        return 0;
 
423
}
 
424
#endif 
 
425
 
 
426
#endif