fixes for bc_cat
[sgx.git] / pvr / bridged_pvr_bridge.h
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 #ifndef __BRIDGED_PVR_BRIDGE_H__
28 #define __BRIDGED_PVR_BRIDGE_H__
29
30 #include "pvr_bridge.h"
31
32 #define PVRSRV_GET_BRIDGE_ID(X) _IOC_NR(X)
33
34 #if defined(DEBUG_BRIDGE_KM)
35 enum PVRSRV_ERROR CopyFromUserWrapper(struct PVRSRV_PER_PROCESS_DATA *pProcData,
36                                       u32 ui32BridgeID, void *pvDest,
37                                       void __user *pvSrc, u32 ui32Size);
38 enum PVRSRV_ERROR CopyToUserWrapper(struct PVRSRV_PER_PROCESS_DATA *pProcData,
39                                     u32 ui32BridgeID, void __user *pvDest,
40                                     void *pvSrc, u32 ui32Size);
41 #else
42 #define CopyFromUserWrapper(pProcData, ui32BridgeID, pvDest, pvSrc, ui32Size) \
43         OSCopyFromUser(pProcData, pvDest, pvSrc, ui32Size)
44 #define CopyToUserWrapper(pProcData, ui32BridgeID, pvDest, pvSrc, ui32Size) \
45         OSCopyToUser(pProcData, pvDest, pvSrc, ui32Size)
46 #endif
47
48 #define ASSIGN_AND_RETURN_ON_ERROR(error, src, res)             \
49         do {                                                    \
50                 (error) = (src);                                \
51                 if ((error) != PVRSRV_OK)                       \
52                         return res;                             \
53         } while (error != PVRSRV_OK)
54
55 #define ASSIGN_AND_EXIT_ON_ERROR(error, src)            \
56         ASSIGN_AND_RETURN_ON_ERROR(error, src, 0)
57
58 static inline enum PVRSRV_ERROR NewHandleBatch(
59                 struct PVRSRV_PER_PROCESS_DATA *psPerProc, u32 ui32BatchSize)
60 {
61         enum PVRSRV_ERROR eError;
62
63         PVR_ASSERT(!psPerProc->bHandlesBatched);
64
65         eError = PVRSRVNewHandleBatch(psPerProc->psHandleBase, ui32BatchSize);
66
67         if (eError == PVRSRV_OK)
68                 psPerProc->bHandlesBatched = IMG_TRUE;
69
70         return eError;
71 }
72
73 #define NEW_HANDLE_BATCH_OR_ERROR(error, psPerProc, ui32BatchSize)      \
74         ASSIGN_AND_EXIT_ON_ERROR(error, NewHandleBatch(psPerProc,       \
75                                  ui32BatchSize))
76
77 static inline enum PVRSRV_ERROR
78 CommitHandleBatch(struct PVRSRV_PER_PROCESS_DATA *psPerProc)
79 {
80         PVR_ASSERT(psPerProc->bHandlesBatched);
81
82         psPerProc->bHandlesBatched = IMG_FALSE;
83
84         return PVRSRVCommitHandleBatch(psPerProc->psHandleBase);
85 }
86
87 #define COMMIT_HANDLE_BATCH_OR_ERROR(error, psPerProc)                  \
88         ASSIGN_AND_EXIT_ON_ERROR(error, CommitHandleBatch(psPerProc))
89
90 static inline void ReleaseHandleBatch(struct PVRSRV_PER_PROCESS_DATA *psPerProc)
91 {
92         if (psPerProc->bHandlesBatched) {
93                 psPerProc->bHandlesBatched = IMG_FALSE;
94
95                 PVRSRVReleaseHandleBatch(psPerProc->psHandleBase);
96         }
97 }
98
99 int DummyBW(u32 ui32BridgeID, void *psBridgeIn, void *psBridgeOut,
100             struct PVRSRV_PER_PROCESS_DATA *psPerProc);
101
102 #if defined(DEBUG_BRIDGE_KM)
103 #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (1 << _IOC_NRBITS)
104
105 struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY {
106         const char *pszFunctionName;
107         u32 ui32CallCount;
108         u32 ui32CopyFromUserTotalBytes;
109         u32 ui32CopyToUserTotalBytes;
110 };
111
112 extern struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY
113             g_BridgeDispatchTable[BRIDGE_DISPATCH_TABLE_ENTRY_COUNT];
114
115 void PVRSRVBridgeIDCheck(u32 id, const char *function);
116
117 #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) do { \
118         PVR_ASSERT(X == PVRSRV_GET_BRIDGE_ID(Y)); \
119         PVRSRVBridgeIDCheck((X), __func__);       \
120         } while (0)
121
122 struct PVRSRV_BRIDGE_GLOBAL_STATS {
123         u32 ui32IOCTLCount;
124         u32 ui32TotalCopyFromUserBytes;
125         u32 ui32TotalCopyToUserBytes;
126 };
127 extern struct PVRSRV_BRIDGE_GLOBAL_STATS g_BridgeGlobalStats;
128
129 #else
130
131 #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) PVR_UNREFERENCED_PARAMETER(X)
132
133 #endif /* DEBUG_BRIDGE_KM */
134
135 int BridgedDispatchKM(struct file *filp,
136                         struct PVRSRV_PER_PROCESS_DATA *psPerProc,
137                         struct PVRSRV_BRIDGE_PACKAGE *psBridgePackageKM);
138
139 #endif