1 /**********************************************************************
3 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
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.
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.
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.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
25 ******************************************************************************/
27 #ifndef __BRIDGED_PVR_BRIDGE_H__
28 #define __BRIDGED_PVR_BRIDGE_H__
30 #include "pvr_bridge.h"
32 #define PVRSRV_GET_BRIDGE_ID(X) _IOC_NR(X)
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);
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)
48 #define ASSIGN_AND_RETURN_ON_ERROR(error, src, res) \
51 if ((error) != PVRSRV_OK) \
53 } while (error != PVRSRV_OK)
55 #define ASSIGN_AND_EXIT_ON_ERROR(error, src) \
56 ASSIGN_AND_RETURN_ON_ERROR(error, src, 0)
58 static inline enum PVRSRV_ERROR NewHandleBatch(
59 struct PVRSRV_PER_PROCESS_DATA *psPerProc, u32 ui32BatchSize)
61 enum PVRSRV_ERROR eError;
63 PVR_ASSERT(!psPerProc->bHandlesBatched);
65 eError = PVRSRVNewHandleBatch(psPerProc->psHandleBase, ui32BatchSize);
67 if (eError == PVRSRV_OK)
68 psPerProc->bHandlesBatched = IMG_TRUE;
73 #define NEW_HANDLE_BATCH_OR_ERROR(error, psPerProc, ui32BatchSize) \
74 ASSIGN_AND_EXIT_ON_ERROR(error, NewHandleBatch(psPerProc, \
77 static inline enum PVRSRV_ERROR
78 CommitHandleBatch(struct PVRSRV_PER_PROCESS_DATA *psPerProc)
80 PVR_ASSERT(psPerProc->bHandlesBatched);
82 psPerProc->bHandlesBatched = IMG_FALSE;
84 return PVRSRVCommitHandleBatch(psPerProc->psHandleBase);
87 #define COMMIT_HANDLE_BATCH_OR_ERROR(error, psPerProc) \
88 ASSIGN_AND_EXIT_ON_ERROR(error, CommitHandleBatch(psPerProc))
90 static inline void ReleaseHandleBatch(struct PVRSRV_PER_PROCESS_DATA *psPerProc)
92 if (psPerProc->bHandlesBatched) {
93 psPerProc->bHandlesBatched = IMG_FALSE;
95 PVRSRVReleaseHandleBatch(psPerProc->psHandleBase);
99 int DummyBW(u32 ui32BridgeID, void *psBridgeIn, void *psBridgeOut,
100 struct PVRSRV_PER_PROCESS_DATA *psPerProc);
102 #if defined(DEBUG_BRIDGE_KM)
103 #define BRIDGE_DISPATCH_TABLE_ENTRY_COUNT (1 << _IOC_NRBITS)
105 struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY {
106 const char *pszFunctionName;
108 u32 ui32CopyFromUserTotalBytes;
109 u32 ui32CopyToUserTotalBytes;
112 extern struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY
113 g_BridgeDispatchTable[BRIDGE_DISPATCH_TABLE_ENTRY_COUNT];
115 void PVRSRVBridgeIDCheck(u32 id, const char *function);
117 #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) do { \
118 PVR_ASSERT(X == PVRSRV_GET_BRIDGE_ID(Y)); \
119 PVRSRVBridgeIDCheck((X), __func__); \
122 struct PVRSRV_BRIDGE_GLOBAL_STATS {
124 u32 ui32TotalCopyFromUserBytes;
125 u32 ui32TotalCopyToUserBytes;
127 extern struct PVRSRV_BRIDGE_GLOBAL_STATS g_BridgeGlobalStats;
131 #define PVRSRV_BRIDGE_ASSERT_CMD(X, Y) PVR_UNREFERENCED_PARAMETER(X)
133 #endif /* DEBUG_BRIDGE_KM */
135 int BridgedDispatchKM(struct file *filp,
136 struct PVRSRV_PER_PROCESS_DATA *psPerProc,
137 struct PVRSRV_BRIDGE_PACKAGE *psBridgePackageKM);