PageRenderTime 181ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/gpu/pvr/bridged_pvr_bridge.h

https://bitbucket.org/wisechild/galaxy-nexus
C++ Header | 232 lines | 165 code | 42 blank | 25 comment | 10 complexity | 3268c9263c6e299b6432857bb086cf0c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 __BRIDGED_PVR_BRIDGE_H__
  27. #define __BRIDGED_PVR_BRIDGE_H__
  28. #include "pvr_bridge.h"
  29. #if defined(__cplusplus)
  30. extern "C" {
  31. #endif
  32. #if defined(__linux__)
  33. #define PVRSRV_GET_BRIDGE_ID(X) _IOC_NR(X)
  34. #else
  35. #define PVRSRV_GET_BRIDGE_ID(X) ((X) - PVRSRV_IOWR(PVRSRV_BRIDGE_CORE_CMD_FIRST))
  36. #endif
  37. #ifndef ENOMEM
  38. #define ENOMEM 12
  39. #endif
  40. #ifndef EFAULT
  41. #define EFAULT 14
  42. #endif
  43. #ifndef ENOTTY
  44. #define ENOTTY 25
  45. #endif
  46. #if defined(DEBUG_BRIDGE_KM)
  47. PVRSRV_ERROR
  48. CopyFromUserWrapper(PVRSRV_PER_PROCESS_DATA *pProcData,
  49. IMG_UINT32 ui32BridgeID,
  50. IMG_VOID *pvDest,
  51. IMG_VOID *pvSrc,
  52. IMG_UINT32 ui32Size);
  53. PVRSRV_ERROR
  54. CopyToUserWrapper(PVRSRV_PER_PROCESS_DATA *pProcData,
  55. IMG_UINT32 ui32BridgeID,
  56. IMG_VOID *pvDest,
  57. IMG_VOID *pvSrc,
  58. IMG_UINT32 ui32Size);
  59. #else
  60. #define CopyFromUserWrapper(pProcData, ui32BridgeID, pvDest, pvSrc, ui32Size) \
  61. OSCopyFromUser(pProcData, pvDest, pvSrc, ui32Size)
  62. #define CopyToUserWrapper(pProcData, ui32BridgeID, pvDest, pvSrc, ui32Size) \
  63. OSCopyToUser(pProcData, pvDest, pvSrc, ui32Size)
  64. #endif
  65. #define ASSIGN_AND_RETURN_ON_ERROR(error, src, res) \
  66. do \
  67. { \
  68. (error) = (src); \
  69. if ((error) != PVRSRV_OK) \
  70. { \
  71. return (res); \
  72. } \
  73. } while ((error) != PVRSRV_OK);
  74. #define ASSIGN_AND_EXIT_ON_ERROR(error, src) \
  75. ASSIGN_AND_RETURN_ON_ERROR(error, src, 0)
  76. #if defined (PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
  77. #ifdef INLINE_IS_PRAGMA
  78. #pragma inline(NewHandleBatch)
  79. #endif
  80. static INLINE PVRSRV_ERROR
  81. NewHandleBatch(PVRSRV_PER_PROCESS_DATA *psPerProc,
  82. IMG_UINT32 ui32BatchSize)
  83. {
  84. PVRSRV_ERROR eError;
  85. PVR_ASSERT(!psPerProc->bHandlesBatched);
  86. eError = PVRSRVNewHandleBatch(psPerProc->psHandleBase, ui32BatchSize);
  87. if (eError == PVRSRV_OK)
  88. {
  89. psPerProc->bHandlesBatched = IMG_TRUE;
  90. }
  91. return eError;
  92. }
  93. #define NEW_HANDLE_BATCH_OR_ERROR(error, psPerProc, ui32BatchSize) \
  94. ASSIGN_AND_EXIT_ON_ERROR(error, NewHandleBatch(psPerProc, ui32BatchSize))
  95. #ifdef INLINE_IS_PRAGMA
  96. #pragma inline(CommitHandleBatch)
  97. #endif
  98. static INLINE PVRSRV_ERROR
  99. CommitHandleBatch(PVRSRV_PER_PROCESS_DATA *psPerProc)
  100. {
  101. PVR_ASSERT(psPerProc->bHandlesBatched);
  102. psPerProc->bHandlesBatched = IMG_FALSE;
  103. return PVRSRVCommitHandleBatch(psPerProc->psHandleBase);
  104. }
  105. #define COMMIT_HANDLE_BATCH_OR_ERROR(error, psPerProc) \
  106. ASSIGN_AND_EXIT_ON_ERROR(error, CommitHandleBatch(psPerProc))
  107. #ifdef INLINE_IS_PRAGMA
  108. #pragma inline(ReleaseHandleBatch)
  109. #endif
  110. static INLINE IMG_VOID
  111. ReleaseHandleBatch(PVRSRV_PER_PROCESS_DATA *psPerProc)
  112. {
  113. if (psPerProc->bHandlesBatched)
  114. {
  115. psPerProc->bHandlesBatched = IMG_FALSE;
  116. PVRSRVReleaseHandleBatch(psPerProc->psHandleBase);
  117. }
  118. }
  119. #else
  120. #define NEW_HANDLE_BATCH_OR_ERROR(error, psPerProc, ui32BatchSize)
  121. #define COMMIT_HANDLE_BATCH_OR_ERROR(error, psPerProc)
  122. #define ReleaseHandleBatch(psPerProc)
  123. #endif
  124. IMG_INT
  125. DummyBW(IMG_UINT32 ui32BridgeID,
  126. IMG_VOID *psBridgeIn,
  127. IMG_VOID *psBridgeOut,
  128. PVRSRV_PER_PROCESS_DATA *psPerProc);
  129. typedef IMG_INT (*BridgeWrapperFunction)(IMG_UINT32 ui32BridgeID,
  130. IMG_VOID *psBridgeIn,
  131. IMG_VOID *psBridgeOut,
  132. PVRSRV_PER_PROCESS_DATA *psPerProc);
  133. typedef struct _PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY
  134. {
  135. BridgeWrapperFunction pfFunction;
  136. #if defined(DEBUG_BRIDGE_KM)
  137. const IMG_CHAR *pszIOCName;
  138. const IMG_CHAR *pszFunctionName;
  139. IMG_UINT32 ui32CallCount;
  140. IMG_UINT32 ui32CopyFromUserTotalBytes;
  141. IMG_UINT32 ui32CopyToUserTotalBytes;
  142. #endif
  143. }PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY;
  144. #if defined(SUPPORT_VGX) || defined(SUPPORT_MSVDX)
  145. #if defined(SUPPORT_VGX)
  146. #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (PVRSRV_BRIDGE_LAST_VGX_CMD+1)
  147. #define PVRSRV_BRIDGE_LAST_DEVICE_CMD PVRSRV_BRIDGE_LAST_VGX_CMD
  148. #else
  149. #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (PVRSRV_BRIDGE_LAST_MSVDX_CMD+1)
  150. #define PVRSRV_BRIDGE_LAST_DEVICE_CMD PVRSRV_BRIDGE_LAST_MSVDX_CMD
  151. #endif
  152. #else
  153. #if defined(SUPPORT_SGX)
  154. #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (PVRSRV_BRIDGE_LAST_SGX_CMD+1)
  155. #define PVRSRV_BRIDGE_LAST_DEVICE_CMD PVRSRV_BRIDGE_LAST_SGX_CMD
  156. #else
  157. #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (PVRSRV_BRIDGE_LAST_NON_DEVICE_CMD+1)
  158. #define PVRSRV_BRIDGE_LAST_DEVICE_CMD PVRSRV_BRIDGE_LAST_NON_DEVICE_CMD
  159. #endif
  160. #endif
  161. extern PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY g_BridgeDispatchTable[BRIDGE_DISPATCH_TABLE_ENTRY_COUNT];
  162. IMG_VOID
  163. _SetDispatchTableEntry(IMG_UINT32 ui32Index,
  164. const IMG_CHAR *pszIOCName,
  165. BridgeWrapperFunction pfFunction,
  166. const IMG_CHAR *pszFunctionName);
  167. #define SetDispatchTableEntry(ui32Index, pfFunction) \
  168. _SetDispatchTableEntry(PVRSRV_GET_BRIDGE_ID(ui32Index), #ui32Index, (BridgeWrapperFunction)pfFunction, #pfFunction)
  169. #define DISPATCH_TABLE_GAP_THRESHOLD 5
  170. #if defined(DEBUG)
  171. #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) PVR_ASSERT(X == PVRSRV_GET_BRIDGE_ID(Y))
  172. #else
  173. #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) PVR_UNREFERENCED_PARAMETER(X)
  174. #endif
  175. #if defined(DEBUG_BRIDGE_KM)
  176. typedef struct _PVRSRV_BRIDGE_GLOBAL_STATS
  177. {
  178. IMG_UINT32 ui32IOCTLCount;
  179. IMG_UINT32 ui32TotalCopyFromUserBytes;
  180. IMG_UINT32 ui32TotalCopyToUserBytes;
  181. }PVRSRV_BRIDGE_GLOBAL_STATS;
  182. extern PVRSRV_BRIDGE_GLOBAL_STATS g_BridgeGlobalStats;
  183. #endif
  184. PVRSRV_ERROR CommonBridgeInit(IMG_VOID);
  185. IMG_INT BridgedDispatchKM(PVRSRV_PER_PROCESS_DATA * psPerProc,
  186. PVRSRV_BRIDGE_PACKAGE * psBridgePackageKM);
  187. #if defined (__cplusplus)
  188. }
  189. #endif
  190. #endif