PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/gpu/pvr/pvr_debug.c

https://github.com/galaxyishere/samsung-kernel-latona
C | 421 lines | 306 code | 90 blank | 25 comment | 35 complexity | a4949e0c4b9ff170f4dc2e731232f325 MD5 | raw file
  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. #ifndef AUTOCONF_INCLUDED
  27. #include <linux/config.h>
  28. #endif
  29. #include <asm/io.h>
  30. #include <asm/uaccess.h>
  31. #include <linux/kernel.h>
  32. #include <linux/hardirq.h>
  33. #include <linux/module.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/string.h>
  36. #include <stdarg.h>
  37. #include "img_types.h"
  38. #include "servicesext.h"
  39. #include "pvr_debug.h"
  40. #include "srvkm.h"
  41. #include "proc.h"
  42. #include "mutex.h"
  43. #include "linkage.h"
  44. #include "pvr_uaccess.h"
  45. static IMG_BOOL VBAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz,
  46. const IMG_CHAR* pszFormat, va_list VArgs)
  47. IMG_FORMAT_PRINTF(3, 0);
  48. #if defined(PVRSRV_NEED_PVR_DPF)
  49. #define PVR_MAX_FILEPATH_LEN 256
  50. static IMG_BOOL BAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz,
  51. const IMG_CHAR *pszFormat, ...)
  52. IMG_FORMAT_PRINTF(3, 4);
  53. IMG_UINT32 gPVRDebugLevel =
  54. (DBGPRIV_FATAL | DBGPRIV_ERROR | DBGPRIV_WARNING);
  55. #endif
  56. #define PVR_MAX_MSG_LEN PVR_MAX_DEBUG_MESSAGE_LEN
  57. static IMG_CHAR gszBufferNonIRQ[PVR_MAX_MSG_LEN + 1];
  58. static IMG_CHAR gszBufferIRQ[PVR_MAX_MSG_LEN + 1];
  59. static PVRSRV_LINUX_MUTEX gsDebugMutexNonIRQ;
  60. static spinlock_t gsDebugLockIRQ = SPIN_LOCK_UNLOCKED;
  61. #if !defined (USE_SPIN_LOCK)
  62. #define USE_SPIN_LOCK (in_interrupt() || !preemptible())
  63. #endif
  64. static inline void GetBufferLock(unsigned long *pulLockFlags)
  65. {
  66. if (USE_SPIN_LOCK)
  67. {
  68. spin_lock_irqsave(&gsDebugLockIRQ, *pulLockFlags);
  69. }
  70. else
  71. {
  72. LinuxLockMutex(&gsDebugMutexNonIRQ);
  73. }
  74. }
  75. static inline void ReleaseBufferLock(unsigned long ulLockFlags)
  76. {
  77. if (USE_SPIN_LOCK)
  78. {
  79. spin_unlock_irqrestore(&gsDebugLockIRQ, ulLockFlags);
  80. }
  81. else
  82. {
  83. LinuxUnLockMutex(&gsDebugMutexNonIRQ);
  84. }
  85. }
  86. static inline void SelectBuffer(IMG_CHAR **ppszBuf, IMG_UINT32 *pui32BufSiz)
  87. {
  88. if (USE_SPIN_LOCK)
  89. {
  90. *ppszBuf = gszBufferIRQ;
  91. *pui32BufSiz = sizeof(gszBufferIRQ);
  92. }
  93. else
  94. {
  95. *ppszBuf = gszBufferNonIRQ;
  96. *pui32BufSiz = sizeof(gszBufferNonIRQ);
  97. }
  98. }
  99. static IMG_BOOL VBAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz, const IMG_CHAR* pszFormat, va_list VArgs)
  100. {
  101. IMG_UINT32 ui32Used;
  102. IMG_UINT32 ui32Space;
  103. IMG_INT32 i32Len;
  104. ui32Used = strlen(pszBuf);
  105. BUG_ON(ui32Used >= ui32BufSiz);
  106. ui32Space = ui32BufSiz - ui32Used;
  107. i32Len = vsnprintf(&pszBuf[ui32Used], ui32Space, pszFormat, VArgs);
  108. pszBuf[ui32BufSiz - 1] = 0;
  109. return (i32Len < 0 || i32Len >= (IMG_INT32)ui32Space) ? IMG_TRUE : IMG_FALSE;
  110. }
  111. IMG_VOID PVRDPFInit(IMG_VOID)
  112. {
  113. LinuxInitMutex(&gsDebugMutexNonIRQ);
  114. }
  115. IMG_VOID PVRSRVReleasePrintf(const IMG_CHAR *pszFormat, ...)
  116. {
  117. va_list vaArgs;
  118. unsigned long ulLockFlags = 0;
  119. IMG_CHAR *pszBuf;
  120. IMG_UINT32 ui32BufSiz;
  121. SelectBuffer(&pszBuf, &ui32BufSiz);
  122. va_start(vaArgs, pszFormat);
  123. GetBufferLock(&ulLockFlags);
  124. strncpy (pszBuf, "PVR_K: ", (ui32BufSiz -1));
  125. if (VBAppend(pszBuf, ui32BufSiz, pszFormat, vaArgs))
  126. {
  127. printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
  128. }
  129. else
  130. {
  131. printk(KERN_INFO "%s\n", pszBuf);
  132. }
  133. ReleaseBufferLock(ulLockFlags);
  134. va_end(vaArgs);
  135. }
  136. #if defined(PVRSRV_NEED_PVR_ASSERT)
  137. IMG_VOID PVRSRVDebugAssertFail(const IMG_CHAR* pszFile, IMG_UINT32 uLine)
  138. {
  139. PVRSRVDebugPrintf(DBGPRIV_FATAL, pszFile, uLine, "Debug assertion failed!");
  140. BUG();
  141. }
  142. #endif
  143. #if defined(PVRSRV_NEED_PVR_TRACE)
  144. IMG_VOID PVRSRVTrace(const IMG_CHAR* pszFormat, ...)
  145. {
  146. va_list VArgs;
  147. unsigned long ulLockFlags = 0;
  148. IMG_CHAR *pszBuf;
  149. IMG_UINT32 ui32BufSiz;
  150. SelectBuffer(&pszBuf, &ui32BufSiz);
  151. va_start(VArgs, pszFormat);
  152. GetBufferLock(&ulLockFlags);
  153. strncpy(pszBuf, "PVR: ", (ui32BufSiz -1));
  154. if (VBAppend(pszBuf, ui32BufSiz, pszFormat, VArgs))
  155. {
  156. printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
  157. }
  158. else
  159. {
  160. printk(KERN_INFO "%s\n", pszBuf);
  161. }
  162. ReleaseBufferLock(ulLockFlags);
  163. va_end(VArgs);
  164. }
  165. #endif
  166. #if defined(PVRSRV_NEED_PVR_DPF)
  167. static IMG_BOOL BAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz, const IMG_CHAR *pszFormat, ...)
  168. {
  169. va_list VArgs;
  170. IMG_BOOL bTrunc;
  171. va_start (VArgs, pszFormat);
  172. bTrunc = VBAppend(pszBuf, ui32BufSiz, pszFormat, VArgs);
  173. va_end (VArgs);
  174. return bTrunc;
  175. }
  176. IMG_VOID PVRSRVDebugPrintf (
  177. IMG_UINT32 ui32DebugLevel,
  178. const IMG_CHAR* pszFullFileName,
  179. IMG_UINT32 ui32Line,
  180. const IMG_CHAR* pszFormat,
  181. ...
  182. )
  183. {
  184. IMG_BOOL bTrace;
  185. const IMG_CHAR *pszFileName = pszFullFileName;
  186. IMG_CHAR *pszLeafName;
  187. bTrace = (IMG_BOOL)(ui32DebugLevel & DBGPRIV_CALLTRACE) ? IMG_TRUE : IMG_FALSE;
  188. if (gPVRDebugLevel & ui32DebugLevel)
  189. {
  190. va_list vaArgs;
  191. unsigned long ulLockFlags = 0;
  192. IMG_CHAR *pszBuf;
  193. IMG_UINT32 ui32BufSiz;
  194. SelectBuffer(&pszBuf, &ui32BufSiz);
  195. va_start(vaArgs, pszFormat);
  196. GetBufferLock(&ulLockFlags);
  197. if (bTrace == IMG_FALSE)
  198. {
  199. switch(ui32DebugLevel)
  200. {
  201. case DBGPRIV_FATAL:
  202. {
  203. strncpy (pszBuf, "PVR_K:(Fatal): ", (ui32BufSiz -1));
  204. break;
  205. }
  206. case DBGPRIV_ERROR:
  207. {
  208. strncpy (pszBuf, "PVR_K:(Error): ", (ui32BufSiz -1));
  209. break;
  210. }
  211. case DBGPRIV_WARNING:
  212. {
  213. strncpy (pszBuf, "PVR_K:(Warning): ", (ui32BufSiz -1));
  214. break;
  215. }
  216. case DBGPRIV_MESSAGE:
  217. {
  218. strncpy (pszBuf, "PVR_K:(Message): ", (ui32BufSiz -1));
  219. break;
  220. }
  221. case DBGPRIV_VERBOSE:
  222. {
  223. strncpy (pszBuf, "PVR_K:(Verbose): ", (ui32BufSiz -1));
  224. break;
  225. }
  226. default:
  227. {
  228. strncpy (pszBuf, "PVR_K:(Unknown message level)", (ui32BufSiz -1));
  229. break;
  230. }
  231. }
  232. }
  233. else
  234. {
  235. strncpy (pszBuf, "PVR_K: ", (ui32BufSiz -1));
  236. }
  237. if (VBAppend(pszBuf, ui32BufSiz, pszFormat, vaArgs))
  238. {
  239. printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
  240. }
  241. else
  242. {
  243. if (bTrace == IMG_FALSE)
  244. {
  245. #ifdef DEBUG_LOG_PATH_TRUNCATE
  246. static IMG_CHAR szFileNameRewrite[PVR_MAX_FILEPATH_LEN];
  247. IMG_CHAR* pszTruncIter;
  248. IMG_CHAR* pszTruncBackInter;
  249. if (strlen(pszFullFileName) > strlen(DEBUG_LOG_PATH_TRUNCATE)+1)
  250. pszFileName = pszFullFileName + strlen(DEBUG_LOG_PATH_TRUNCATE)+1;
  251. strncpy(szFileNameRewrite, pszFileName,PVR_MAX_FILEPATH_LEN);
  252. if(strlen(szFileNameRewrite) == PVR_MAX_FILEPATH_LEN-1) {
  253. IMG_CHAR szTruncateMassage[] = "FILENAME TRUNCATED";
  254. strcpy(szFileNameRewrite + (PVR_MAX_FILEPATH_LEN - 1 - strlen(szTruncateMassage)), szTruncateMassage);
  255. }
  256. pszTruncIter = szFileNameRewrite;
  257. while(*pszTruncIter++ != 0)
  258. {
  259. IMG_CHAR* pszNextStartPoint;
  260. if(
  261. !( ( *pszTruncIter == '/' && (pszTruncIter-4 >= szFileNameRewrite) ) &&
  262. ( *(pszTruncIter-1) == '.') &&
  263. ( *(pszTruncIter-2) == '.') &&
  264. ( *(pszTruncIter-3) == '/') )
  265. ) continue;
  266. pszTruncBackInter = pszTruncIter - 3;
  267. while(*(--pszTruncBackInter) != '/')
  268. {
  269. if(pszTruncBackInter <= szFileNameRewrite) break;
  270. }
  271. pszNextStartPoint = pszTruncBackInter;
  272. while(*pszTruncIter != 0)
  273. {
  274. *pszTruncBackInter++ = *pszTruncIter++;
  275. }
  276. *pszTruncBackInter = 0;
  277. pszTruncIter = pszNextStartPoint;
  278. }
  279. pszFileName = szFileNameRewrite;
  280. if(*pszFileName == '/') pszFileName++;
  281. #endif
  282. #if !defined(__sh__)
  283. pszLeafName = (IMG_CHAR *)strrchr (pszFileName, '\\');
  284. if (pszLeafName)
  285. {
  286. pszFileName = pszLeafName;
  287. }
  288. #endif
  289. if (BAppend(pszBuf, ui32BufSiz, " [%u, %s]", ui32Line, pszFileName))
  290. {
  291. printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
  292. }
  293. else
  294. {
  295. printk(KERN_INFO "%s\n", pszBuf);
  296. }
  297. }
  298. else
  299. {
  300. printk(KERN_INFO "%s\n", pszBuf);
  301. }
  302. }
  303. ReleaseBufferLock(ulLockFlags);
  304. va_end (vaArgs);
  305. }
  306. }
  307. #endif
  308. #if defined(DEBUG)
  309. IMG_INT PVRDebugProcSetLevel(struct file *file, const IMG_CHAR *buffer, IMG_UINT32 count, IMG_VOID *data)
  310. {
  311. #define _PROC_SET_BUFFER_SZ 2
  312. IMG_CHAR data_buffer[_PROC_SET_BUFFER_SZ];
  313. if (count != _PROC_SET_BUFFER_SZ)
  314. {
  315. return -EINVAL;
  316. }
  317. else
  318. {
  319. if (pvr_copy_from_user(data_buffer, buffer, count))
  320. return -EINVAL;
  321. if (data_buffer[count - 1] != '\n')
  322. return -EINVAL;
  323. gPVRDebugLevel = data_buffer[0] - '0';
  324. }
  325. return (count);
  326. }
  327. void ProcSeqShowDebugLevel(struct seq_file *sfile,void* el)
  328. {
  329. seq_printf(sfile, "%u\n", gPVRDebugLevel);
  330. }
  331. #endif