gpu: pvr: pdumpfs: make frame_count_max configurable
[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 struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY {
103         int (*pfFunction)(u32 ui32BridgeID, void *psBridgeIn, void *psBridgeOut,
104                           struct PVRSRV_PER_PROCESS_DATA *psPerProc);
105 #if defined(DEBUG_BRIDGE_KM)
106         const char *pszIOCName;
107         const char *pszFunctionName;
108         u32 ui32CallCount;
109         u32 ui32CopyFromUserTotalBytes;
110         u32 ui32CopyToUserTotalBytes;
111 #endif
112 };
113
114 #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (PVRSRV_BRIDGE_LAST_SGX_CMD+1)
115 #define PVRSRV_BRIDGE_LAST_DEVICE_CMD      PVRSRV_BRIDGE_LAST_SGX_CMD
116
117 extern struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY
118             g_BridgeDispatchTable[BRIDGE_DISPATCH_TABLE_ENTRY_COUNT];
119
120 void _SetDispatchTableEntry(u32 ui32Index,
121                             const char *pszIOCName,
122                             int (*pfFunction) (u32 ui32BridgeID,
123                                                void *psBridgeIn,
124                                                void *psBridgeOut,
125                                                struct PVRSRV_PER_PROCESS_DATA *
126                                                psPerProc),
127                             const char *pszFunctionName);
128
129 #define SetDispatchTableEntry(ui32Index, pfFunction) \
130         _SetDispatchTableEntry(PVRSRV_GET_BRIDGE_ID(ui32Index), #ui32Index, \
131            (int (*)(u32 ui32BridgeID, void *psBridgeIn, void *psBridgeOut,  \
132            struct PVRSRV_PER_PROCESS_DATA *psPerProc))pfFunction, #pfFunction)
133
134 #define DISPATCH_TABLE_GAP_THRESHOLD 5
135
136 #if defined(CONFIG_PVR_DEBUG_EXTRA)
137 #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) PVR_ASSERT(X == PVRSRV_GET_BRIDGE_ID(Y))
138 #else
139 #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) PVR_UNREFERENCED_PARAMETER(X)
140 #endif
141
142 #if defined(DEBUG_BRIDGE_KM)
143 struct PVRSRV_BRIDGE_GLOBAL_STATS {
144         u32 ui32IOCTLCount;
145         u32 ui32TotalCopyFromUserBytes;
146         u32 ui32TotalCopyToUserBytes;
147 };
148
149 extern struct PVRSRV_BRIDGE_GLOBAL_STATS g_BridgeGlobalStats;
150 #endif
151
152 enum PVRSRV_ERROR CommonBridgeInit(void);
153
154 int BridgedDispatchKM(struct file *filp,
155                         struct PVRSRV_PER_PROCESS_DATA *psPerProc,
156                         struct PVRSRV_BRIDGE_PACKAGE *psBridgePackageKM);
157
158 #endif