1 /*************************************************************************/ /*!
2 @Title Services reference count debugging
3 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License Dual MIT/GPLv2
6 The contents of this file are subject to the MIT license as set out below.
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
30 This License is also included in this distribution in the file called
31 "MIT-COPYING".
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */ /**************************************************************************/
42 #ifndef __REFCOUNT_H__
43 #define __REFCOUNT_H__
45 #include "pvr_bridge_km.h"
46 #if defined(SUPPORT_ION)
47 #include "ion_sync.h"
48 #endif /* defined(SUPPORT_ION) */
49 #if defined(SUPPORT_DMABUF)
50 #include "dmabuf_sync.h"
51 #endif /* defined(SUPPORT_DMABUF) */
53 #if defined(PVRSRV_REFCOUNT_DEBUG)
55 void PVRSRVDumpRefCountCCB(void);
57 #define PVRSRVKernelSyncInfoIncRef(x...) \
58 PVRSRVKernelSyncInfoIncRef2(__FILE__, __LINE__, x)
59 #define PVRSRVKernelSyncInfoDecRef(x...) \
60 PVRSRVKernelSyncInfoDecRef2(__FILE__, __LINE__, x)
61 #define PVRSRVKernelMemInfoIncRef(x...) \
62 PVRSRVKernelMemInfoIncRef2(__FILE__, __LINE__, x)
63 #define PVRSRVKernelMemInfoDecRef(x...) \
64 PVRSRVKernelMemInfoDecRef2(__FILE__, __LINE__, x)
65 #define PVRSRVBMBufIncRef(x...) \
66 PVRSRVBMBufIncRef2(__FILE__, __LINE__, x)
67 #define PVRSRVBMBufDecRef(x...) \
68 PVRSRVBMBufDecRef2(__FILE__, __LINE__, x)
69 #define PVRSRVBMBufIncExport(x...) \
70 PVRSRVBMBufIncExport2(__FILE__, __LINE__, x)
71 #define PVRSRVBMBufDecExport(x...) \
72 PVRSRVBMBufDecExport2(__FILE__, __LINE__, x)
74 void PVRSRVKernelSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
75 PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo,
76 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
77 void PVRSRVKernelSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
78 PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo,
79 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
80 void PVRSRVKernelMemInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
81 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
82 void PVRSRVKernelMemInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
83 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
84 void PVRSRVBMBufIncRef2(const IMG_CHAR *pszFile,
85 IMG_INT iLine, BM_BUF *pBuf);
86 void PVRSRVBMBufDecRef2(const IMG_CHAR *pszFile,
87 IMG_INT iLine, BM_BUF *pBuf);
88 void PVRSRVBMBufIncExport2(const IMG_CHAR *pszFile,
89 IMG_INT iLine, BM_BUF *pBuf);
90 void PVRSRVBMBufDecExport2(const IMG_CHAR *pszFile,
91 IMG_INT iLine, BM_BUF *pBuf);
92 void PVRSRVBMXProcIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
93 IMG_UINT32 ui32Index);
94 void PVRSRVBMXProcDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
95 IMG_UINT32 ui32Index);
97 #if defined(__linux__)
99 /* mmap refcounting is Linux specific */
100 #include "mmap.h"
102 #define PVRSRVOffsetStructIncRef(x...) \
103 PVRSRVOffsetStructIncRef2(__FILE__, __LINE__, x)
104 #define PVRSRVOffsetStructDecRef(x...) \
105 PVRSRVOffsetStructDecRef2(__FILE__, __LINE__, x)
106 #define PVRSRVOffsetStructIncMapped(x...) \
107 PVRSRVOffsetStructIncMapped2(__FILE__, __LINE__, x)
108 #define PVRSRVOffsetStructDecMapped(x...) \
109 PVRSRVOffsetStructDecMapped2(__FILE__, __LINE__, x)
111 void PVRSRVOffsetStructIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
112 PKV_OFFSET_STRUCT psOffsetStruct);
113 void PVRSRVOffsetStructDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
114 PKV_OFFSET_STRUCT psOffsetStruct);
115 void PVRSRVOffsetStructIncMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
116 PKV_OFFSET_STRUCT psOffsetStruct);
117 void PVRSRVOffsetStructDecMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
118 PKV_OFFSET_STRUCT psOffsetStruct);
120 #if defined(SUPPORT_ION)
121 #define PVRSRVIonBufferSyncInfoIncRef(x...) \
122 PVRSRVIonBufferSyncInfoIncRef2(__FILE__, __LINE__, x)
123 #define PVRSRVIonBufferSyncInfoDecRef(x...) \
124 PVRSRVIonBufferSyncInfoDecRef2(__FILE__, __LINE__, x)
126 PVRSRV_ERROR PVRSRVIonBufferSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
127 IMG_HANDLE hUnique,
128 IMG_HANDLE hDevCookie,
129 IMG_HANDLE hDevMemContext,
130 PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo,
131 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
132 void PVRSRVIonBufferSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
133 PVRSRV_ION_SYNC_INFO *psIonSyncInfo,
134 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
135 #endif /* defined (SUPPORT_ION) */
137 #if defined(SUPPORT_DMABUF)
138 #define PVRSRVDmaBufSyncInfoIncRef(x...) \
139 PVRSRVDmaBufSyncInfoIncRef2(__FILE__, __LINE__, x)
140 #define PVRSRVDmaBufSyncInfoDecRef(x...) \
141 PVRSRVDmaBufSyncInfoDecRef2(__FILE__, __LINE__, x)
143 PVRSRV_ERROR PVRSRVDmaBufSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
144 IMG_HANDLE hUnique,
145 IMG_HANDLE hPriv,
146 IMG_HANDLE hDevCookie,
147 IMG_HANDLE hDevMemContext,
148 PVRSRV_DMABUF_SYNC_INFO **ppsDmaBufSyncInfo,
149 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
151 void PVRSRVDmaBufSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
152 PVRSRV_DMABUF_SYNC_INFO *psDmaBufSyncInfo,
153 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
154 #endif /* defined (SUPPORT_DMABUF) */
156 #endif /* defined(__linux__) */
158 #else /* defined(PVRSRV_REFCOUNT_DEBUG) */
160 static INLINE void PVRSRVDumpRefCountCCB(void) { }
162 static INLINE void PVRSRVKernelSyncInfoIncRef(PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo,
163 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
164 {
165 PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
166 PVRSRVAcquireSyncInfoKM(psKernelSyncInfo);
167 }
169 static INLINE void PVRSRVKernelSyncInfoDecRef(PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo,
170 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
171 {
172 PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
173 PVRSRVReleaseSyncInfoKM(psKernelSyncInfo);
174 }
176 static INLINE void PVRSRVKernelMemInfoIncRef(PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
177 {
178 psKernelMemInfo->ui32RefCount++;
179 }
181 static INLINE void PVRSRVKernelMemInfoDecRef(PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
182 {
183 psKernelMemInfo->ui32RefCount--;
184 }
186 static INLINE void PVRSRVBMBufIncRef(BM_BUF *pBuf)
187 {
188 pBuf->ui32RefCount++;
189 }
191 static INLINE void PVRSRVBMBufDecRef(BM_BUF *pBuf)
192 {
193 pBuf->ui32RefCount--;
194 }
196 static INLINE void PVRSRVBMBufIncExport(BM_BUF *pBuf)
197 {
198 pBuf->ui32ExportCount++;
199 }
201 static INLINE void PVRSRVBMBufDecExport(BM_BUF *pBuf)
202 {
203 pBuf->ui32ExportCount--;
204 }
206 static INLINE void PVRSRVBMXProcIncRef(IMG_UINT32 ui32Index)
207 {
208 gXProcWorkaroundShareData[ui32Index].ui32RefCount++;
209 }
211 static INLINE void PVRSRVBMXProcDecRef(IMG_UINT32 ui32Index)
212 {
213 gXProcWorkaroundShareData[ui32Index].ui32RefCount--;
214 }
216 #if defined(__linux__)
218 /* mmap refcounting is Linux specific */
219 #include "mmap.h"
221 static INLINE void PVRSRVOffsetStructIncRef(PKV_OFFSET_STRUCT psOffsetStruct)
222 {
223 psOffsetStruct->ui32RefCount++;
224 }
226 static INLINE void PVRSRVOffsetStructDecRef(PKV_OFFSET_STRUCT psOffsetStruct)
227 {
228 psOffsetStruct->ui32RefCount--;
229 }
231 static INLINE void PVRSRVOffsetStructIncMapped(PKV_OFFSET_STRUCT psOffsetStruct)
232 {
233 psOffsetStruct->ui32Mapped++;
234 }
236 static INLINE void PVRSRVOffsetStructDecMapped(PKV_OFFSET_STRUCT psOffsetStruct)
237 {
238 psOffsetStruct->ui32Mapped--;
239 }
241 #if defined(SUPPORT_ION)
242 static INLINE PVRSRV_ERROR PVRSRVIonBufferSyncInfoIncRef(IMG_HANDLE hUnique,
243 IMG_HANDLE hDevCookie,
244 IMG_HANDLE hDevMemContext,
245 PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo,
246 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
247 {
248 PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
250 return PVRSRVIonBufferSyncAcquire(hUnique,
251 hDevCookie,
252 hDevMemContext,
253 ppsIonSyncInfo);
254 }
256 static INLINE void PVRSRVIonBufferSyncInfoDecRef(PVRSRV_ION_SYNC_INFO *psIonSyncInfo,
257 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
258 {
259 PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
260 PVRSRVIonBufferSyncRelease(psIonSyncInfo);
261 }
262 #endif /* defined (SUPPORT_ION) */
264 #if defined(SUPPORT_DMABUF)
265 static INLINE PVRSRV_ERROR PVRSRVDmaBufSyncInfoIncRef(IMG_HANDLE hUnique,
266 IMG_HANDLE hPriv,
267 IMG_HANDLE hDevCookie,
268 IMG_HANDLE hDevMemContext,
269 PVRSRV_DMABUF_SYNC_INFO **ppsDmaBufSyncInfo,
270 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
271 {
272 PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
274 return PVRSRVDmaBufSyncAcquire(hUnique,
275 hPriv,
276 hDevCookie,
277 hDevMemContext,
278 ppsDmaBufSyncInfo);
279 }
281 static INLINE void PVRSRVDmaBufSyncInfoDecRef(PVRSRV_DMABUF_SYNC_INFO *psDmaBufSyncInfo,
282 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
283 {
284 PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
285 PVRSRVDmaBufSyncRelease(psDmaBufSyncInfo);
286 }
287 #endif /* defined (SUPPORT_DMABUF) */
289 #endif /* defined(__linux__) */
291 #endif /* defined(PVRSRV_REFCOUNT_DEBUG) */
293 #endif /* __REFCOUNT_H__ */