[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / srvkm / common / refcount.c
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 #if defined(PVRSRV_REFCOUNT_DEBUG)
44 #include "services_headers.h"
46 #ifndef __linux__
47 #warning Reference count debugging is not thread-safe on this platform
48 #define PVRSRV_LOCK_CCB()
49 #define PVRSRV_UNLOCK_CCB()
50 #else /* __linux__ */
51 #include <linux/spinlock.h>
52 static DEFINE_SPINLOCK(gsCCBLock);
53 #define PVRSRV_LOCK_CCB() \
54 { \
55 unsigned long flags; \
56 spin_lock_irqsave(&gsCCBLock, flags);
57 #define PVRSRV_UNLOCK_CCB() \
58 spin_unlock_irqrestore(&gsCCBLock, flags); \
59 }
60 #endif /* __linux__ */
62 #define PVRSRV_REFCOUNT_CCB_MAX 512
63 #define PVRSRV_REFCOUNT_CCB_MESG_MAX 80
65 #define PVRSRV_REFCOUNT_CCB_DEBUG_SYNCINFO (1U << 0)
66 #define PVRSRV_REFCOUNT_CCB_DEBUG_MEMINFO (1U << 1)
67 #define PVRSRV_REFCOUNT_CCB_DEBUG_BM_BUF (1U << 2)
68 #define PVRSRV_REFCOUNT_CCB_DEBUG_BM_BUF2 (1U << 3)
69 #define PVRSRV_REFCOUNT_CCB_DEBUG_BM_XPROC (1U << 4)
71 #if defined(__linux__)
72 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP (1U << 16)
73 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2 (1U << 17)
74 #define PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC (1U << 18)
75 #else
76 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP 0
77 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2 0
78 #define PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC 0
79 #endif
81 #define PVRSRV_REFCOUNT_CCB_DEBUG_ALL ~0U
83 /*static const IMG_UINT guiDebugMask = PVRSRV_REFCOUNT_CCB_DEBUG_ALL;*/
84 static const IMG_UINT guiDebugMask =
85 PVRSRV_REFCOUNT_CCB_DEBUG_SYNCINFO |
86 #if defined(SUPPORT_ION)
87 PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC |
88 #endif
89 PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2;
91 typedef struct
92 {
93 const IMG_CHAR *pszFile;
94 IMG_INT iLine;
95 IMG_UINT32 ui32PID;
96 IMG_CHAR pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX];
97 }
98 PVRSRV_REFCOUNT_CCB;
100 static PVRSRV_REFCOUNT_CCB gsRefCountCCB[PVRSRV_REFCOUNT_CCB_MAX];
101 static IMG_UINT giOffset;
103 static const IMG_CHAR gszHeader[] =
104 /* 10 20 30 40 50 60 70
105 * 345678901234567890123456789012345678901234567890123456789012345678901
106 */
107 "TYPE SYNCINFO MEMINFO MEMHANDLE OTHER REF REF' SIZE PID";
108 /* NCINFO deadbeef deadbeef deadbeef deadbeef 1234 1234 deadbeef */
110 #define PVRSRV_REFCOUNT_CCB_FMT_STRING "%8.8s %8p %8p %8p %8p %.4d %.4d %.8x"
112 IMG_INTERNAL
113 void PVRSRVDumpRefCountCCB(void)
114 {
115 int i;
117 PVRSRV_LOCK_CCB();
119 PVR_LOG(("%s", gszHeader));
121 for(i = 0; i < PVRSRV_REFCOUNT_CCB_MAX; i++)
122 {
123 PVRSRV_REFCOUNT_CCB *psRefCountCCBEntry =
124 &gsRefCountCCB[(giOffset + i) % PVRSRV_REFCOUNT_CCB_MAX];
126 /* Early on, we won't have MAX_REFCOUNT_CCB_SIZE messages */
127 if(!psRefCountCCBEntry->pszFile)
128 continue;
130 PVR_LOG(("%s %d %s:%d", psRefCountCCBEntry->pcMesg,
131 psRefCountCCBEntry->ui32PID,
132 psRefCountCCBEntry->pszFile,
133 psRefCountCCBEntry->iLine));
134 }
136 PVRSRV_UNLOCK_CCB();
137 }
139 IMG_INTERNAL
140 void PVRSRVKernelSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
141 PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo,
142 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
143 {
144 IMG_UINT32 ui32RefValue = OSAtomicRead(psKernelSyncInfo->pvRefCount);
146 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_SYNCINFO))
147 goto skip;
149 PVRSRV_LOCK_CCB();
151 gsRefCountCCB[giOffset].pszFile = pszFile;
152 gsRefCountCCB[giOffset].iLine = iLine;
153 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
154 snprintf(gsRefCountCCB[giOffset].pcMesg,
155 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
156 PVRSRV_REFCOUNT_CCB_FMT_STRING,
157 "SYNCINFO",
158 psKernelSyncInfo,
159 psKernelMemInfo,
160 NULL,
161 (psKernelMemInfo) ? psKernelMemInfo->sMemBlk.hOSMemHandle : NULL,
162 ui32RefValue,
163 ui32RefValue + 1,
164 (psKernelMemInfo) ? psKernelMemInfo->uAllocSize : 0);
165 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
166 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
168 PVRSRV_UNLOCK_CCB();
170 skip:
171 PVRSRVAcquireSyncInfoKM(psKernelSyncInfo);
172 }
174 IMG_INTERNAL
175 void PVRSRVKernelSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
176 PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo,
177 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
178 {
179 IMG_UINT32 ui32RefValue = OSAtomicRead(psKernelSyncInfo->pvRefCount);
181 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_SYNCINFO))
182 goto skip;
184 PVRSRV_LOCK_CCB();
186 gsRefCountCCB[giOffset].pszFile = pszFile;
187 gsRefCountCCB[giOffset].iLine = iLine;
188 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
189 snprintf(gsRefCountCCB[giOffset].pcMesg,
190 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
191 PVRSRV_REFCOUNT_CCB_FMT_STRING,
192 "SYNCINFO",
193 psKernelSyncInfo,
194 psKernelMemInfo,
195 (psKernelMemInfo) ? psKernelMemInfo->sMemBlk.hOSMemHandle : NULL,
196 NULL,
197 ui32RefValue,
198 ui32RefValue - 1,
199 (psKernelMemInfo) ? psKernelMemInfo->uAllocSize : 0);
200 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
201 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
203 PVRSRV_UNLOCK_CCB();
205 skip:
206 PVRSRVReleaseSyncInfoKM(psKernelSyncInfo);
207 }
209 IMG_INTERNAL
210 void PVRSRVKernelMemInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
211 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
212 {
213 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_MEMINFO))
214 goto skip;
216 PVRSRV_LOCK_CCB();
218 gsRefCountCCB[giOffset].pszFile = pszFile;
219 gsRefCountCCB[giOffset].iLine = iLine;
220 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
221 snprintf(gsRefCountCCB[giOffset].pcMesg,
222 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
223 PVRSRV_REFCOUNT_CCB_FMT_STRING,
224 "MEMINFO",
225 psKernelMemInfo->psKernelSyncInfo,
226 psKernelMemInfo,
227 psKernelMemInfo->sMemBlk.hOSMemHandle,
228 NULL,
229 psKernelMemInfo->ui32RefCount,
230 psKernelMemInfo->ui32RefCount + 1,
231 psKernelMemInfo->uAllocSize);
232 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
233 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
235 PVRSRV_UNLOCK_CCB();
237 skip:
238 psKernelMemInfo->ui32RefCount++;
239 }
241 IMG_INTERNAL
242 void PVRSRVKernelMemInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
243 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
244 {
245 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_MEMINFO))
246 goto skip;
248 PVRSRV_LOCK_CCB();
250 gsRefCountCCB[giOffset].pszFile = pszFile;
251 gsRefCountCCB[giOffset].iLine = iLine;
252 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
253 snprintf(gsRefCountCCB[giOffset].pcMesg,
254 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
255 PVRSRV_REFCOUNT_CCB_FMT_STRING,
256 "MEMINFO",
257 psKernelMemInfo->psKernelSyncInfo,
258 psKernelMemInfo,
259 psKernelMemInfo->sMemBlk.hOSMemHandle,
260 NULL,
261 psKernelMemInfo->ui32RefCount,
262 psKernelMemInfo->ui32RefCount - 1,
263 psKernelMemInfo->uAllocSize);
264 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
265 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
267 PVRSRV_UNLOCK_CCB();
269 skip:
270 psKernelMemInfo->ui32RefCount--;
271 }
273 IMG_INTERNAL
274 void PVRSRVBMBufIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine, BM_BUF *pBuf)
275 {
276 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_BM_BUF))
277 goto skip;
279 PVRSRV_LOCK_CCB();
281 gsRefCountCCB[giOffset].pszFile = pszFile;
282 gsRefCountCCB[giOffset].iLine = iLine;
283 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
284 snprintf(gsRefCountCCB[giOffset].pcMesg,
285 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
286 PVRSRV_REFCOUNT_CCB_FMT_STRING,
287 "BM_BUF",
288 NULL,
289 NULL,
290 BM_HandleToOSMemHandle(pBuf),
291 pBuf,
292 pBuf->ui32RefCount,
293 pBuf->ui32RefCount + 1,
294 (pBuf->pMapping) ? pBuf->pMapping->uSize : 0);
295 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
296 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
298 PVRSRV_UNLOCK_CCB();
300 skip:
301 pBuf->ui32RefCount++;
302 }
304 IMG_INTERNAL
305 void PVRSRVBMBufDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine, BM_BUF *pBuf)
306 {
307 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_BM_BUF))
308 goto skip;
310 PVRSRV_LOCK_CCB();
312 gsRefCountCCB[giOffset].pszFile = pszFile;
313 gsRefCountCCB[giOffset].iLine = iLine;
314 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
315 snprintf(gsRefCountCCB[giOffset].pcMesg,
316 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
317 PVRSRV_REFCOUNT_CCB_FMT_STRING,
318 "BM_BUF",
319 NULL,
320 NULL,
321 BM_HandleToOSMemHandle(pBuf),
322 pBuf,
323 pBuf->ui32RefCount,
324 pBuf->ui32RefCount - 1,
325 (pBuf->pMapping) ? pBuf->pMapping->uSize : 0);
326 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
327 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
329 PVRSRV_UNLOCK_CCB();
331 skip:
332 pBuf->ui32RefCount--;
333 }
335 IMG_INTERNAL
336 void PVRSRVBMBufIncExport2(const IMG_CHAR *pszFile, IMG_INT iLine, BM_BUF *pBuf)
337 {
338 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_BM_BUF2))
339 goto skip;
341 PVRSRV_LOCK_CCB();
343 gsRefCountCCB[giOffset].pszFile = pszFile;
344 gsRefCountCCB[giOffset].iLine = iLine;
345 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
346 snprintf(gsRefCountCCB[giOffset].pcMesg,
347 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
348 PVRSRV_REFCOUNT_CCB_FMT_STRING,
349 "BM_BUF2",
350 NULL,
351 NULL,
352 BM_HandleToOSMemHandle(pBuf),
353 pBuf,
354 pBuf->ui32ExportCount,
355 pBuf->ui32ExportCount + 1,
356 (pBuf->pMapping) ? pBuf->pMapping->uSize : 0);
357 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
358 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
360 PVRSRV_UNLOCK_CCB();
362 skip:
363 pBuf->ui32ExportCount++;
364 }
366 IMG_INTERNAL
367 void PVRSRVBMBufDecExport2(const IMG_CHAR *pszFile, IMG_INT iLine, BM_BUF *pBuf)
368 {
369 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_BM_BUF2))
370 goto skip;
372 PVRSRV_LOCK_CCB();
374 gsRefCountCCB[giOffset].pszFile = pszFile;
375 gsRefCountCCB[giOffset].iLine = iLine;
376 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
377 snprintf(gsRefCountCCB[giOffset].pcMesg,
378 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
379 PVRSRV_REFCOUNT_CCB_FMT_STRING,
380 "BM_BUF2",
381 NULL,
382 NULL,
383 BM_HandleToOSMemHandle(pBuf),
384 pBuf,
385 pBuf->ui32ExportCount,
386 pBuf->ui32ExportCount - 1,
387 (pBuf->pMapping) ? pBuf->pMapping->uSize : 0);
388 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
389 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
391 PVRSRV_UNLOCK_CCB();
393 skip:
394 pBuf->ui32ExportCount--;
395 }
397 IMG_INTERNAL
398 void PVRSRVBMXProcIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine, IMG_UINT32 ui32Index)
399 {
400 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_BM_XPROC))
401 goto skip;
403 PVRSRV_LOCK_CCB();
405 gsRefCountCCB[giOffset].pszFile = pszFile;
406 gsRefCountCCB[giOffset].iLine = iLine;
407 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
408 snprintf(gsRefCountCCB[giOffset].pcMesg,
409 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
410 PVRSRV_REFCOUNT_CCB_FMT_STRING,
411 "BM_XPROC",
412 NULL,
413 NULL,
414 gXProcWorkaroundShareData[ui32Index].hOSMemHandle,
415 (IMG_VOID *) ui32Index,
416 gXProcWorkaroundShareData[ui32Index].ui32RefCount,
417 gXProcWorkaroundShareData[ui32Index].ui32RefCount + 1,
418 gXProcWorkaroundShareData[ui32Index].ui32Size);
419 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
420 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
422 PVRSRV_UNLOCK_CCB();
424 skip:
425 gXProcWorkaroundShareData[ui32Index].ui32RefCount++;
426 }
428 IMG_INTERNAL
429 void PVRSRVBMXProcDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine, IMG_UINT32 ui32Index)
430 {
431 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_BM_XPROC))
432 goto skip;
434 PVRSRV_LOCK_CCB();
436 gsRefCountCCB[giOffset].pszFile = pszFile;
437 gsRefCountCCB[giOffset].iLine = iLine;
438 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
439 snprintf(gsRefCountCCB[giOffset].pcMesg,
440 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
441 PVRSRV_REFCOUNT_CCB_FMT_STRING,
442 "BM_XPROC",
443 NULL,
444 NULL,
445 gXProcWorkaroundShareData[ui32Index].hOSMemHandle,
446 (IMG_VOID *) ui32Index,
447 gXProcWorkaroundShareData[ui32Index].ui32RefCount,
448 gXProcWorkaroundShareData[ui32Index].ui32RefCount - 1,
449 gXProcWorkaroundShareData[ui32Index].ui32Size);
450 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
451 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
453 PVRSRV_UNLOCK_CCB();
455 skip:
456 gXProcWorkaroundShareData[ui32Index].ui32RefCount--;
457 }
459 #if defined(__linux__)
461 /* mmap refcounting is Linux specific */
463 IMG_INTERNAL
464 void PVRSRVOffsetStructIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
465 PKV_OFFSET_STRUCT psOffsetStruct)
466 {
467 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_MMAP))
468 goto skip;
470 PVRSRV_LOCK_CCB();
472 gsRefCountCCB[giOffset].pszFile = pszFile;
473 gsRefCountCCB[giOffset].iLine = iLine;
474 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
475 snprintf(gsRefCountCCB[giOffset].pcMesg,
476 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
477 PVRSRV_REFCOUNT_CCB_FMT_STRING,
478 "MMAP",
479 NULL,
480 NULL,
481 psOffsetStruct->psLinuxMemArea,
482 psOffsetStruct,
483 psOffsetStruct->ui32RefCount,
484 psOffsetStruct->ui32RefCount + 1,
485 psOffsetStruct->uiRealByteSize);
486 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
487 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
489 PVRSRV_UNLOCK_CCB();
491 skip:
492 psOffsetStruct->ui32RefCount++;
493 }
495 IMG_INTERNAL
496 void PVRSRVOffsetStructDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
497 PKV_OFFSET_STRUCT psOffsetStruct)
498 {
499 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_MMAP))
500 goto skip;
502 PVRSRV_LOCK_CCB();
504 gsRefCountCCB[giOffset].pszFile = pszFile;
505 gsRefCountCCB[giOffset].iLine = iLine;
506 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
507 snprintf(gsRefCountCCB[giOffset].pcMesg,
508 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
509 PVRSRV_REFCOUNT_CCB_FMT_STRING,
510 "MMAP",
511 NULL,
512 NULL,
513 psOffsetStruct->psLinuxMemArea,
514 psOffsetStruct,
515 psOffsetStruct->ui32RefCount,
516 psOffsetStruct->ui32RefCount - 1,
517 psOffsetStruct->uiRealByteSize);
518 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
519 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
521 PVRSRV_UNLOCK_CCB();
523 skip:
524 psOffsetStruct->ui32RefCount--;
525 }
527 IMG_INTERNAL
528 void PVRSRVOffsetStructIncMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
529 PKV_OFFSET_STRUCT psOffsetStruct)
530 {
531 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2))
532 goto skip;
534 PVRSRV_LOCK_CCB();
536 gsRefCountCCB[giOffset].pszFile = pszFile;
537 gsRefCountCCB[giOffset].iLine = iLine;
538 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
539 snprintf(gsRefCountCCB[giOffset].pcMesg,
540 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
541 PVRSRV_REFCOUNT_CCB_FMT_STRING,
542 "MMAP2",
543 NULL,
544 NULL,
545 psOffsetStruct->psLinuxMemArea,
546 psOffsetStruct,
547 psOffsetStruct->ui32Mapped,
548 psOffsetStruct->ui32Mapped + 1,
549 psOffsetStruct->uiRealByteSize);
550 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
551 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
553 PVRSRV_UNLOCK_CCB();
555 skip:
556 psOffsetStruct->ui32Mapped++;
557 }
559 IMG_INTERNAL
560 void PVRSRVOffsetStructDecMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
561 PKV_OFFSET_STRUCT psOffsetStruct)
562 {
563 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2))
564 goto skip;
566 PVRSRV_LOCK_CCB();
568 gsRefCountCCB[giOffset].pszFile = pszFile;
569 gsRefCountCCB[giOffset].iLine = iLine;
570 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
571 snprintf(gsRefCountCCB[giOffset].pcMesg,
572 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
573 PVRSRV_REFCOUNT_CCB_FMT_STRING,
574 "MMAP2",
575 NULL,
576 NULL,
577 psOffsetStruct->psLinuxMemArea,
578 psOffsetStruct,
579 psOffsetStruct->ui32Mapped,
580 psOffsetStruct->ui32Mapped - 1,
581 psOffsetStruct->uiRealByteSize);
582 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
583 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
585 PVRSRV_UNLOCK_CCB();
587 skip:
588 psOffsetStruct->ui32Mapped--;
589 }
591 #if defined(SUPPORT_ION)
592 PVRSRV_ERROR PVRSRVIonBufferSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
593 IMG_HANDLE hUnique,
594 IMG_HANDLE hDevCookie,
595 IMG_HANDLE hDevMemContext,
596 PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo,
597 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
598 {
599 PVRSRV_ERROR eError;
601 /*
602 We have to do the call 1st as we need to Ion syninfo which it returns
603 */
604 eError = PVRSRVIonBufferSyncAcquire(hUnique,
605 hDevCookie,
606 hDevMemContext,
607 ppsIonSyncInfo);
609 if (eError == PVRSRV_OK)
610 {
611 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC))
612 goto skip;
614 PVRSRV_LOCK_CCB();
616 gsRefCountCCB[giOffset].pszFile = pszFile;
617 gsRefCountCCB[giOffset].iLine = iLine;
618 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
619 snprintf(gsRefCountCCB[giOffset].pcMesg,
620 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
621 PVRSRV_REFCOUNT_CCB_FMT_STRING,
622 "ION_SYNC",
623 (*ppsIonSyncInfo)->psSyncInfo,
624 psKernelMemInfo,
625 NULL,
626 *ppsIonSyncInfo,
627 (*ppsIonSyncInfo)->ui32RefCount - 1,
628 (*ppsIonSyncInfo)->ui32RefCount,
629 0);
630 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
631 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
633 PVRSRV_UNLOCK_CCB();
634 }
636 skip:
637 return eError;
638 }
640 void PVRSRVIonBufferSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
641 PVRSRV_ION_SYNC_INFO *psIonSyncInfo,
642 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
643 {
644 if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC))
645 goto skip;
647 PVRSRV_LOCK_CCB();
649 gsRefCountCCB[giOffset].pszFile = pszFile;
650 gsRefCountCCB[giOffset].iLine = iLine;
651 gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
652 snprintf(gsRefCountCCB[giOffset].pcMesg,
653 PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
654 PVRSRV_REFCOUNT_CCB_FMT_STRING,
655 "ION_SYNC",
656 psIonSyncInfo->psSyncInfo,
657 psKernelMemInfo,
658 NULL,
659 psIonSyncInfo,
660 psIonSyncInfo->ui32RefCount,
661 psIonSyncInfo->ui32RefCount - 1,
662 0);
663 gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
664 giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
666 PVRSRV_UNLOCK_CCB();
667 skip:
668 PVRSRVIonBufferSyncRelease(psIonSyncInfo);
669 }
671 #endif /* defined (SUPPORT_ION) */
673 #endif /* defined(__linux__) */
675 #endif /* defined(PVRSRV_REFCOUNT_DEBUG) */