summaryrefslogtreecommitdiffstats
path: root/pvr-source/services4/srvkm/common/ttrace.c
blob: 574bf25c315c6257b9ed37a50c07c1e75700cdb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
/*************************************************************************/ /*!
@Title          Timed Trace functions
@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@License        Dual MIT/GPLv2

The contents of this file are subject to the MIT license as set out below.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 ("GPL") in which case the provisions
of GPL are applicable instead of those above.

If you wish to allow use of your version of this file only under the terms of
GPL, and not to allow others to use your version of this file under the terms
of the MIT license, indicate your decision by deleting the provisions above
and replace them with the notice and other provisions required by GPL as set
out in the file called "GPL-COPYING" included in this distribution. If you do
not delete the provisions above, a recipient may use your version of this file
under the terms of either the MIT license or GPL.

This License is also included in this distribution in the file called
"MIT-COPYING".

EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ /**************************************************************************/
#if defined (TTRACE)

#include "services_headers.h"
#include "ttrace.h"

#if defined(PVRSRV_NEED_PVR_DPF)
#define CHECKSIZE(n,m) \
	if ((n & m) != n) \
		PVR_DPF((PVR_DBG_ERROR,"Size check failed for " #m))
#else
#define CHECKSIZE(n,m)
#endif

#define TIME_TRACE_HASH_TABLE_SIZE	32

HASH_TABLE *g_psBufferTable;
IMG_UINT32 g_ui32HostUID;
IMG_HANDLE g_psTimer;

/* Trace buffer struct */
typedef struct
{
	IMG_UINT32	ui32Woff;	/* Offset to where next item will be written */
	IMG_UINT32	ui32Roff;	/* Offset to where to start reading from */
	IMG_UINT32	ui32ByteCount;	/* Number of bytes in buffer */
	IMG_UINT8	ui8Data[0];
} sTimeTraceBuffer;

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceItemSize

 @Description

 Calculate the size of a trace item

 @Input psTraceItem :	Trace item

 @Return size of trace item

******************************************************************************/
static IMG_UINT32
PVRSRVTimeTraceItemSize(IMG_UINT32 *psTraceItem)
{
	IMG_UINT32 ui32Size = PVRSRV_TRACE_ITEM_SIZE;

	ui32Size += READ_HEADER(SIZE, psTraceItem[PVRSRV_TRACE_DATA_HEADER]);

	return ui32Size;
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceAllocItem

 @Description

 Allocate a trace item from the buffer of the current process

 @Output ppsTraceItem :	Pointer to allocated trace item

 @Input ui32Size : Size of data packet to be allocated

 @Return none

******************************************************************************/
static IMG_VOID
PVRSRVTimeTraceAllocItem(IMG_UINT32 **pui32Item, IMG_UINT32 ui32Size)
{
	IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
	IMG_UINT32 ui32AllocOffset;
	sTimeTraceBuffer *psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);

	/* The caller only asks for extra data space */
	ui32Size += PVRSRV_TRACE_ITEM_SIZE;

	/* Always round to 32-bit */
	ui32Size = ((ui32Size - 1) & (~0x3)) + 0x04;

	if (!psBuffer)
	{
		PVRSRV_ERROR eError;

		PVR_DPF((PVR_DBG_MESSAGE, "PVRSRVTimeTraceAllocItem: Creating buffer for PID %u", (IMG_UINT32) ui32PID));
		eError = PVRSRVTimeTraceBufferCreate(ui32PID);
		if (eError != PVRSRV_OK)
		{
			*pui32Item = IMG_NULL;
			PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Failed to create buffer"));
			return;
		}
		
		psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
		if (psBuffer == IMG_NULL)
		{
			*pui32Item = NULL;
			PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Failed to retrieve buffer"));
			return;
		}
	}

	/* Can't allocate more then buffer size */
	if (ui32Size >= TIME_TRACE_BUFFER_SIZE)
	{
		*pui32Item = NULL;
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Error trace item too large (%d)", ui32Size));
		return;
	}

	/* FIXME: Enter critical section? */

	/* Always ensure we have enough space to write a padding message */
	if ((psBuffer->ui32Woff + ui32Size + PVRSRV_TRACE_ITEM_SIZE) > TIME_TRACE_BUFFER_SIZE)
	{
		IMG_UINT32 *ui32WriteEOB = (IMG_UINT32 *) &psBuffer->ui8Data[psBuffer->ui32Woff];
		IMG_UINT32 ui32Remain = TIME_TRACE_BUFFER_SIZE - psBuffer->ui32Woff;

		/* Not enough space at the end of the buffer, back to the start */
		*ui32WriteEOB++ = WRITE_HEADER(GROUP, PVRSRV_TRACE_GROUP_PADDING);
		*ui32WriteEOB++ = 0;		/* Don't need timestamp */
		*ui32WriteEOB++ = 0;		/* Don't need UID */
		*ui32WriteEOB = WRITE_HEADER(SIZE, (ui32Remain - PVRSRV_TRACE_ITEM_SIZE));
		psBuffer->ui32ByteCount += ui32Remain;
		psBuffer->ui32Woff = ui32AllocOffset = 0;
	}
	else
		ui32AllocOffset = psBuffer->ui32Woff;

	psBuffer->ui32Woff = psBuffer->ui32Woff + ui32Size;
	psBuffer->ui32ByteCount += ui32Size;

	/* This allocation will start overwritting past our read pointer, move the read pointer along */
	while (psBuffer->ui32ByteCount > TIME_TRACE_BUFFER_SIZE)
	{
		IMG_UINT32 *psReadItem = (IMG_UINT32 *) &psBuffer->ui8Data[psBuffer->ui32Roff];
		IMG_UINT32 ui32ReadSize;

		ui32ReadSize = PVRSRVTimeTraceItemSize(psReadItem);
		psBuffer->ui32Roff = (psBuffer->ui32Roff + ui32ReadSize) & (TIME_TRACE_BUFFER_SIZE - 1);
		psBuffer->ui32ByteCount -= ui32ReadSize;
	}

	*pui32Item = (IMG_UINT32 *) &psBuffer->ui8Data[ui32AllocOffset];
	/* FIXME: Exit critical section? */
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceBufferCreate

 @Description

 Create a trace buffer.

 Note: We assume that this will only be called once per process.

 @Input ui32PID : PID of the process that is creating the buffer

 @Return none

******************************************************************************/
PVRSRV_ERROR PVRSRVTimeTraceBufferCreate(IMG_UINT32 ui32PID)
{
	sTimeTraceBuffer *psBuffer;
	PVRSRV_ERROR eError = PVRSRV_OK;

	eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT,
					sizeof(sTimeTraceBuffer) + TIME_TRACE_BUFFER_SIZE,
					(IMG_VOID **)&psBuffer, IMG_NULL,
					"Time Trace Buffer");
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceBufferCreate: Error allocating trace buffer"));
		return eError;
	}

	OSMemSet(psBuffer, 0, TIME_TRACE_BUFFER_SIZE);

	if (!HASH_Insert(g_psBufferTable, (IMG_UINTPTR_T) ui32PID, (IMG_UINTPTR_T) psBuffer))
	{
		OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(sTimeTraceBuffer) + TIME_TRACE_BUFFER_SIZE,
				psBuffer, NULL);
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceBufferCreate: Error adding trace buffer to hash table"));
		return PVRSRV_ERROR_OUT_OF_MEMORY;
	}

	return eError;
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceBufferDestroy

 @Description

 Destroy a trace buffer.

 Note: We assume that this will only be called once per process.

 @Input ui32PID : PID of the process that is creating the buffer

 @Return none

******************************************************************************/
PVRSRV_ERROR PVRSRVTimeTraceBufferDestroy(IMG_UINT32 ui32PID)
{
	sTimeTraceBuffer *psBuffer;

#if defined(DUMP_TTRACE_BUFFERS_ON_EXIT)
	PVRSRVDumpTimeTraceBuffers();
#endif
	psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
	if (psBuffer)
	{
		OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(sTimeTraceBuffer) + TIME_TRACE_BUFFER_SIZE,
				psBuffer, NULL);
		HASH_Remove(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
		return PVRSRV_OK;
	}

	PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceBufferDestroy: Can't find trace buffer in hash table"));
	return PVRSRV_ERROR_INVALID_PARAMS;
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceInit

 @Description

 Initialise the timed trace subsystem.

 @Return Error

******************************************************************************/
PVRSRV_ERROR PVRSRVTimeTraceInit(IMG_VOID)
{
	g_psBufferTable = HASH_Create(TIME_TRACE_HASH_TABLE_SIZE);

	/* Create hash table to store the per process buffers in */
	if (!g_psBufferTable)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceInit: Error creating hash table"));
		return PVRSRV_ERROR_OUT_OF_MEMORY;
	}

	/* Create the kernel buffer */
	PVRSRVTimeTraceBufferCreate(KERNEL_ID);

	g_psTimer = OSFuncHighResTimerCreate();

	if (!g_psTimer)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceInit: Error creating timer"));
		return PVRSRV_ERROR_INIT_FAILURE;
	}
	return PVRSRV_OK;
}

static PVRSRV_ERROR _PVRSRVTimeTraceBufferDestroy(IMG_UINTPTR_T hKey, IMG_UINTPTR_T hData)
{
	PVR_UNREFERENCED_PARAMETER(hData);
	PVR_DPF((PVR_DBG_MESSAGE, "_PVRSRVTimeTraceBufferDestroy: Destroying buffer for PID %u", (IMG_UINT32) hKey));

	PVRSRVTimeTraceBufferDestroy(hKey);
	return PVRSRV_OK;
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceDeinit

 @Description

  De-initialise the timed trace subsystem.

 @Return Error

******************************************************************************/
IMG_VOID PVRSRVTimeTraceDeinit(IMG_VOID)
{
	PVRSRVTimeTraceBufferDestroy(KERNEL_ID);
	/* Free any buffers the where created at alloc item time */
	HASH_Iterate(g_psBufferTable, _PVRSRVTimeTraceBufferDestroy);
	HASH_Delete(g_psBufferTable);
	OSFuncHighResTimerDestroy(g_psTimer);
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceWriteHeader

 @Description

 Write the header for a trace item.

 @Input pui32TraceItem : Pointer to trace item

 @Input ui32Group : Trace item's group ID

 @Input ui32Class : Trace item's class ID

 @Input ui32Token : Trace item's ui32Token ID

 @Input ui32Size : Trace item's data payload size

 @Input ui32Type : Trace item's data type

 @Input ui32Count : Trace item's data count

 @Return Pointer to data payload space, or NULL if no data payload

******************************************************************************/
#ifdef INLINE_IS_PRAGMA
#pragma inline(PVRSRVTimeTraceWriteHeader)
#endif
static INLINE IMG_VOID *PVRSRVTimeTraceWriteHeader(IMG_UINT32 *pui32TraceItem, IMG_UINT32 ui32Group,
							IMG_UINT32 ui32Class, IMG_UINT32 ui32Token,
							IMG_UINT32 ui32Size, IMG_UINT32 ui32Type,
							IMG_UINT32 ui32Count)
{
	/* Sanity check arg's */
	CHECKSIZE(ui32Group, PVRSRV_TRACE_GROUP_MASK);
	CHECKSIZE(ui32Class, PVRSRV_TRACE_CLASS_MASK);
	CHECKSIZE(ui32Token, PVRSRV_TRACE_TOKEN_MASK);

	CHECKSIZE(ui32Size, PVRSRV_TRACE_SIZE_MASK);
	CHECKSIZE(ui32Type, PVRSRV_TRACE_TYPE_MASK);
	CHECKSIZE(ui32Count, PVRSRV_TRACE_COUNT_MASK);

	/* Trace header */
	pui32TraceItem[PVRSRV_TRACE_HEADER] = WRITE_HEADER(GROUP, ui32Group);
	pui32TraceItem[PVRSRV_TRACE_HEADER] |= WRITE_HEADER(CLASS, ui32Class);
	pui32TraceItem[PVRSRV_TRACE_HEADER] |= WRITE_HEADER(TOKEN, ui32Token);

	/* Data header */
	pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] = WRITE_HEADER(SIZE, ui32Size);
	pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] |= WRITE_HEADER(TYPE, ui32Type);
	pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] |= WRITE_HEADER(COUNT, ui32Count);

	pui32TraceItem[PVRSRV_TRACE_TIMESTAMP] = OSFuncHighResTimerGetus(g_psTimer);
	pui32TraceItem[PVRSRV_TRACE_HOSTUID] = g_ui32HostUID++;

	return ui32Size?((IMG_VOID *) &pui32TraceItem[PVRSRV_TRACE_DATA_PAYLOAD]):NULL;
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceArray

 @Description

 Write trace item with an array of data

 @Input ui32Group : Trace item's group ID

 @Input ui32Class : Trace item's class ID

 @Input ui32Token : Trace item's ui32Token ID

 @Input ui32Size : Trace item's data payload size

 @Input ui32Type : Trace item's data type

 @Input ui32Count : Trace item's data count

 @Input pui8Data : Pointer to data array

 @Return Pointer to data payload space, or NULL if no data payload

******************************************************************************/
IMG_VOID PVRSRVTimeTraceArray(IMG_UINT32 ui32Group, IMG_UINT32 ui32Class, IMG_UINT32 ui32Token,
				IMG_UINT32 ui32Type, IMG_UINT32 ui32Count, IMG_UINT8 *pui8Data)
{
	IMG_UINT32 *pui32TraceItem;
	IMG_UINT32 ui32Size, ui32TypeSize;
	IMG_UINT8 *ui8Ptr;

	/* Only the 1st 4 sizes are for ui types, others are "special" */
	switch (ui32Type)
	{
		case PVRSRV_TRACE_TYPE_UI8:	ui32TypeSize = 1;
						break;
		case PVRSRV_TRACE_TYPE_UI16:	ui32TypeSize = 2;
						break;
		case PVRSRV_TRACE_TYPE_UI32:	ui32TypeSize = 4;
						break;
		case PVRSRV_TRACE_TYPE_UI64:	ui32TypeSize = 8;
						break;
		default:
			PVR_DPF((PVR_DBG_ERROR, "Unsupported size\n"));
			return;
	}

	ui32Size = ui32TypeSize * ui32Count;

	/* Allocate space from the buffer */
	PVRSRVTimeTraceAllocItem(&pui32TraceItem, ui32Size);

	if (!pui32TraceItem)
	{
		PVR_DPF((PVR_DBG_ERROR, "Can't find buffer\n"));
		return;
	}

	ui8Ptr = PVRSRVTimeTraceWriteHeader(pui32TraceItem, ui32Group, ui32Class, ui32Token,
						ui32Size, ui32Type, ui32Count);

	if (ui8Ptr)
	{
		OSMemCopy(ui8Ptr, pui8Data, ui32Size);
	}
}

/*!
******************************************************************************

 @Function	PVRSRVTimeTraceSyncObject

 @Description

 Write trace item with a sync object

 @Input ui32Group : Trace item's group ID

 @Input ui32Token : Trace item's ui32Token ID

 @Input psSync : Sync object

 @Input ui8SyncOpp : Sync object operation

 @Return None

******************************************************************************/
IMG_VOID PVRSRVTimeTraceSyncObject(IMG_UINT32 ui32Group, IMG_UINT32 ui32Token,
				   PVRSRV_KERNEL_SYNC_INFO *psSync, IMG_UINT8 ui8SyncOp)
{
	IMG_UINT32 *pui32TraceItem;
	IMG_UINT32 *ui32Ptr;
	IMG_UINT32 ui32Size = PVRSRV_TRACE_TYPE_SYNC_SIZE;


	PVRSRVTimeTraceAllocItem(&pui32TraceItem, ui32Size);

	if (!pui32TraceItem)
	{
		PVR_DPF((PVR_DBG_ERROR, "Can't find buffer\n"));
		return;
	}

	ui32Ptr = PVRSRVTimeTraceWriteHeader(pui32TraceItem, ui32Group, PVRSRV_TRACE_CLASS_SYNC,
						ui32Token, ui32Size, PVRSRV_TRACE_TYPE_SYNC, 1);

	ui32Ptr[PVRSRV_TRACE_SYNC_UID] = psSync->ui32UID;
	ui32Ptr[PVRSRV_TRACE_SYNC_WOP] = psSync->psSyncData->ui32WriteOpsPending;
	ui32Ptr[PVRSRV_TRACE_SYNC_WOC] = psSync->psSyncData->ui32WriteOpsComplete;
	ui32Ptr[PVRSRV_TRACE_SYNC_ROP] = psSync->psSyncData->ui32ReadOpsPending;
	ui32Ptr[PVRSRV_TRACE_SYNC_ROC] = psSync->psSyncData->ui32ReadOpsComplete;
	ui32Ptr[PVRSRV_TRACE_SYNC_RO2P] = psSync->psSyncData->ui32ReadOps2Pending;
	ui32Ptr[PVRSRV_TRACE_SYNC_RO2C] = psSync->psSyncData->ui32ReadOps2Complete;
	ui32Ptr[PVRSRV_TRACE_SYNC_WO_DEV_VADDR] = psSync->sWriteOpsCompleteDevVAddr.uiAddr;
	ui32Ptr[PVRSRV_TRACE_SYNC_RO_DEV_VADDR] = psSync->sReadOpsCompleteDevVAddr.uiAddr;
	ui32Ptr[PVRSRV_TRACE_SYNC_RO2_DEV_VADDR] = psSync->sReadOps2CompleteDevVAddr.uiAddr;
	ui32Ptr[PVRSRV_TRACE_SYNC_OP] = ui8SyncOp;
}

/*!
******************************************************************************

 @Function	PVRSRVDumpTimeTraceBuffer

 @Description

 Dump the contents of the trace buffer.

 @Input hKey : Trace item's group ID

 @Input hData : Trace item's ui32Token ID

 @Return Error

******************************************************************************/
static PVRSRV_ERROR PVRSRVDumpTimeTraceBuffer(IMG_UINTPTR_T hKey, IMG_UINTPTR_T hData)
{
	sTimeTraceBuffer *psBuffer = (sTimeTraceBuffer *) hData;
	IMG_UINT32 ui32ByteCount = psBuffer->ui32ByteCount;
	IMG_UINT32 ui32Walker = psBuffer->ui32Roff;
	IMG_UINT32 ui32Read, ui32LineLen, ui32EOL, ui32MinLine;

	PVR_DPF((PVR_DBG_ERROR, "TTB for PID %u:\n", (IMG_UINT32) hKey));

	while (ui32ByteCount)
	{
		IMG_UINT32 *pui32Buffer = (IMG_UINT32 *) &psBuffer->ui8Data[ui32Walker];

		ui32LineLen = (ui32ByteCount/sizeof(IMG_UINT32));
		ui32EOL = (TIME_TRACE_BUFFER_SIZE - ui32Walker)/sizeof(IMG_UINT32);
		ui32MinLine = (ui32LineLen < ui32EOL)?ui32LineLen:ui32EOL;

		if (ui32MinLine >= 4)
		{
			PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X %08X %08X %08X", ui32ByteCount,
					pui32Buffer[0], pui32Buffer[1], pui32Buffer[2], pui32Buffer[3]));
			ui32Read = 4 * sizeof(IMG_UINT32);
		}
		else if (ui32MinLine >= 3)
		{
			PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X %08X %08X", ui32ByteCount,
					pui32Buffer[0], pui32Buffer[1], pui32Buffer[2]));
			ui32Read = 3 * sizeof(IMG_UINT32);
		}
		else if (ui32MinLine >= 2)
		{
			PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X %08X", ui32ByteCount,
					pui32Buffer[0], pui32Buffer[1]));
			ui32Read = 2 * sizeof(IMG_UINT32);
		}
		else
		{
			PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X", ui32ByteCount,
					pui32Buffer[0]));
			ui32Read = sizeof(IMG_UINT32);
		}

		ui32Walker = (ui32Walker + ui32Read) & (TIME_TRACE_BUFFER_SIZE - 1);
		ui32ByteCount -= ui32Read;
	}

	return PVRSRV_OK;
}

/*!
******************************************************************************

 @Function	PVRSRVDumpTimeTraceBuffers

 @Description

 Dump the contents of all the trace buffers.

 @Return None

******************************************************************************/
IMG_VOID PVRSRVDumpTimeTraceBuffers(IMG_VOID)
{
	HASH_Iterate(g_psBufferTable, PVRSRVDumpTimeTraceBuffer);
}

#endif /* TTRACE */