RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / htbserver.c
1 /*************************************************************************/ /*!
2 @File           htbserver.c
3 @Title          Host Trace Buffer server implementation.
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Host Trace Buffer provides a mechanism to log Host events to a
6                 buffer in a similar way to the Firmware Trace mechanism.
7                 Host Trace Buffer logs data using a Transport Layer buffer.
8                 The Transport Layer and pvrtld tool provides the mechanism to
9                 retrieve the trace data.
10 @License        Dual MIT/GPLv2
11
12 The contents of this file are subject to the MIT license as set out below.
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
23
24 Alternatively, the contents of this file may be used under the terms of
25 the GNU General Public License Version 2 ("GPL") in which case the provisions
26 of GPL are applicable instead of those above.
27
28 If you wish to allow use of your version of this file only under the terms of
29 GPL, and not to allow others to use your version of this file under the terms
30 of the MIT license, indicate your decision by deleting the provisions above
31 and replace them with the notice and other provisions required by GPL as set
32 out in the file called "GPL-COPYING" included in this distribution. If you do
33 not delete the provisions above, a recipient may use your version of this file
34 under the terms of either the MIT license or GPL.
35
36 This License is also included in this distribution in the file called
37 "MIT-COPYING".
38
39 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
40 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
41 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
42 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
43 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
44 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
45 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 */ /**************************************************************************/
47
48 #include "htbserver.h"
49 #include "htbuffer.h"
50 #include "htbuffer_types.h"
51 #include "tlstream.h"
52 #include "pvrsrv_tlcommon.h"
53 #include "img_types.h"
54 #include "pvrsrv_error.h"
55 #include "osfunc.h"
56 #include "allocmem.h"
57 #include "pvr_notifier.h"
58 #include "pvrsrv.h"
59 #include "pvrsrv_apphint.h"
60
61 /* size of circular buffer controlling the maximum number of concurrent PIDs logged */
62 #define HTB_MAX_NUM_PID 8
63
64 /* number of times to try rewriting a log entry */
65 #define HTB_LOG_RETRY_COUNT 5
66
67 /*************************************************************************/ /*!
68   Host Trace Buffer control information structure
69 */ /**************************************************************************/
70 typedef struct
71 {
72         IMG_CHAR *pszBufferName;        /*!< Name to use for the trace buffer,
73                                          this will be required to request
74                                          trace data from TL.
75                                          Once set this may not be changed */
76
77         IMG_UINT32 ui32BufferSize;      /*!< Requested buffer size in bytes
78                                          Once set this may not be changed */
79
80         HTB_OPMODE_CTRL eOpMode;        /*!< Control what trace data is dropped if
81                                          the buffer is full.
82                                          Once set this may not be changed */
83
84 /*      IMG_UINT32 ui32GroupEnable; */  /*!< Flags word controlling groups to be
85                                          logged */
86
87         IMG_UINT32 ui32LogLevel;        /*!< Log level to control messages logged */
88
89         IMG_UINT32 aui32EnablePID[HTB_MAX_NUM_PID]; /*!< PIDs to enable logging for
90                                                      a specific set of processes */
91
92         IMG_UINT32 ui32PIDCount;        /*!< Current number of PIDs being logged */
93
94         IMG_UINT32 ui32PIDHead;         /*!< Head of the PID circular buffer */
95
96         HTB_LOGMODE_CTRL eLogMode;      /*!< Logging mode control */
97
98         IMG_BOOL bLogDropSignalled;     /*!< Flag indicating if a log message has
99                                          been signalled as dropped */
100
101         /* synchronisation parameters */
102         IMG_UINT64 ui64SyncOSTS;
103         IMG_UINT64 ui64SyncCRTS;
104         IMG_UINT32 ui32SyncCalcClkSpd;
105         IMG_UINT32 ui32SyncMarker;
106
107 } HTB_CTRL_INFO;
108
109
110 /*************************************************************************/ /*!
111 */ /**************************************************************************/
112 static const IMG_UINT32 MapFlags[] =
113 {
114         0,                          /* HTB_OPMODE_UNDEF = 0 */
115         TL_FLAG_RESERVE_DROP_NEWER, /* HTB_OPMODE_DROPLATEST */
116         0,                          /* HTB_OPMODE_DROPOLDEST */
117         TL_FLAG_RESERVE_BLOCK       /* HTB_OPMODE_BLOCK */
118 };
119
120 static_assert(0 == HTB_OPMODE_UNDEF,      "Unexpected value for HTB_OPMODE_UNDEF");
121 static_assert(1 == HTB_OPMODE_DROPLATEST, "Unexpected value for HTB_OPMODE_DROPLATEST");
122 static_assert(2 == HTB_OPMODE_DROPOLDEST, "Unexpected value for HTB_OPMODE_DROPOLDEST");
123 static_assert(3 == HTB_OPMODE_BLOCK,      "Unexpected value for HTB_OPMODE_BLOCK");
124
125 static const IMG_UINT32 g_ui32TLBaseFlags = 0; //TL_FLAG_NO_SIGNAL_ON_COMMIT
126
127 /* Minimum TL buffer size,
128  * large enough for around 60 worst case messages or 200 average messages
129  */
130 #define HTB_TL_BUFFER_SIZE_MIN  (0x10000)
131
132
133 static HTB_CTRL_INFO g_sCtrl  = {0};
134 static IMG_BOOL g_bConfigured = IMG_FALSE;
135 static IMG_HANDLE g_hTLStream = NULL;
136
137
138 /************************************************************************/ /*!
139  @Function      _LookupFlags
140  @Description   Convert HTBuffer Operation mode to TLStream flags
141
142  @Input         eModeHTBuffer   Operation Mode
143
144  @Return        IMG_UINT32      TLStream FLags
145 */ /**************************************************************************/
146 static IMG_UINT32
147 _LookupFlags( HTB_OPMODE_CTRL eMode )
148 {
149         return (eMode < (sizeof(MapFlags)/sizeof(MapFlags[0])))? MapFlags[eMode]: 0;
150 }
151
152
153 /************************************************************************/ /*!
154  @Function      _HTBLogDebugInfo
155  @Description   Debug dump handler used to dump the state of the HTB module.
156                 Called for each verbosity level during a debug dump. Function
157                 only prints state when called for High verbosity.
158
159  @Input         hDebugRequestHandle See PFN_DBGREQ_NOTIFY
160
161  @Input         ui32VerbLevel       See PFN_DBGREQ_NOTIFY
162
163  @Input         pfnDumpDebugPrintf  See PFN_DBGREQ_NOTIFY
164
165  @Input         pvDumpDebugFile     See PFN_DBGREQ_NOTIFY
166
167 */ /**************************************************************************/
168 static void _HTBLogDebugInfo(
169                 PVRSRV_DBGREQ_HANDLE hDebugRequestHandle,
170                 IMG_UINT32 ui32VerbLevel,
171                 DUMPDEBUG_PRINTF_FUNC *pfnDumpDebugPrintf,
172                 void *pvDumpDebugFile
173 )
174 {
175         PVR_UNREFERENCED_PARAMETER(hDebugRequestHandle);
176
177         if (ui32VerbLevel == DEBUG_REQUEST_VERBOSITY_HIGH)
178         {
179
180                 if (g_bConfigured)
181                 {
182                         IMG_INT i;
183
184                         PVR_DUMPDEBUG_LOG("------[ HTB Log state: On ]------");
185
186                         PVR_DUMPDEBUG_LOG("HTB Log mode: %d", g_sCtrl.eLogMode);
187                         PVR_DUMPDEBUG_LOG("HTB Log level: %d", g_sCtrl.ui32LogLevel);
188                         PVR_DUMPDEBUG_LOG("HTB Buffer Opmode: %d", g_sCtrl.eOpMode);
189
190                         for (i=0; i < HTB_FLAG_NUM_EL; i++)
191                         {
192                                 PVR_DUMPDEBUG_LOG("HTB Log group %d: %x", i, g_auiHTBGroupEnable[i]);
193                         }
194                 }
195                 else
196                 {
197                         PVR_DUMPDEBUG_LOG("------[ HTB Log state: Off ]------");
198                 }
199         }
200 }
201
202 /************************************************************************/ /*!
203  @Function      HTBDeviceCreate
204  @Description   Initialisation actions for HTB at device creation.
205
206  @Input         psDeviceNode    Reference to the device node in context
207
208  @Return        eError          Internal services call returned eError error
209                                 number
210 */ /**************************************************************************/
211 PVRSRV_ERROR
212 HTBDeviceCreate(
213                 PVRSRV_DEVICE_NODE *psDeviceNode
214 )
215 {
216         PVRSRV_ERROR eError = PVRSRV_OK;
217
218         eError = PVRSRVRegisterDbgRequestNotify(&psDeviceNode->hHtbDbgReqNotify,
219                         psDeviceNode, &_HTBLogDebugInfo, DEBUG_REQUEST_HTB, NULL);
220         PVR_LOG_IF_ERROR(eError, "PVRSRVRegisterDbgRequestNotify");
221
222         return eError;
223 }
224
225 /************************************************************************/ /*!
226  @Function      HTBIDeviceDestroy
227  @Description   De-initialisation actions for HTB at device destruction.
228
229  @Input         psDeviceNode    Reference to the device node in context
230
231 */ /**************************************************************************/
232 void
233 HTBDeviceDestroy(
234                 PVRSRV_DEVICE_NODE *psDeviceNode
235 )
236 {
237         if (psDeviceNode->hHtbDbgReqNotify)
238         {
239                 /* No much we can do if it fails, driver unloading */
240                 (void)PVRSRVUnregisterDbgRequestNotify(psDeviceNode->hHtbDbgReqNotify);
241                 psDeviceNode->hHtbDbgReqNotify = NULL;
242         }
243 }
244
245
246 /************************************************************************/ /*!
247  @Function      HTBDeInit
248  @Description   Close the Host Trace Buffer and free all resources. Must
249                 perform a no-op if already de-initialised.
250
251  @Return        eError          Internal services call returned eError error
252                                 number
253 */ /**************************************************************************/
254 PVRSRV_ERROR
255 HTBDeInit( void )
256 {
257         if (g_hTLStream)
258         {
259                 TLStreamClose( g_hTLStream );
260                 g_hTLStream = NULL;
261         }
262
263         if (g_sCtrl.pszBufferName)
264         {
265                 OSFreeMem( g_sCtrl.pszBufferName );
266                 g_sCtrl.pszBufferName = NULL;
267         }
268
269         return PVRSRV_OK;
270 }
271
272
273 /*************************************************************************/ /*!
274  AppHint interface functions
275 */ /**************************************************************************/
276 static
277 PVRSRV_ERROR _HTBSetLogGroup(const PVRSRV_DEVICE_NODE *psDeviceNode,
278                              const void *psPrivate,
279                              IMG_UINT32 ui32Value)
280 {
281         PVR_UNREFERENCED_PARAMETER(psDeviceNode);
282         PVR_UNREFERENCED_PARAMETER(psPrivate);
283
284         return HTBControlKM(1, &ui32Value, 0, 0,
285                             HTB_LOGMODE_UNDEF, HTB_OPMODE_UNDEF);
286 }
287
288 static
289 PVRSRV_ERROR _HTBReadLogGroup(const PVRSRV_DEVICE_NODE *psDeviceNode,
290                               const void *psPrivate,
291                               IMG_UINT32 *pui32Value)
292 {
293         PVR_UNREFERENCED_PARAMETER(psDeviceNode);
294         PVR_UNREFERENCED_PARAMETER(psPrivate);
295
296         *pui32Value = g_auiHTBGroupEnable[0];
297         return PVRSRV_OK;
298 }
299
300 static
301 PVRSRV_ERROR _HTBSetOpMode(const PVRSRV_DEVICE_NODE *psDeviceNode,
302                            const void *psPrivate,
303                            IMG_UINT32 ui32Value)
304 {
305         PVR_UNREFERENCED_PARAMETER(psDeviceNode);
306         PVR_UNREFERENCED_PARAMETER(psPrivate);
307
308         return HTBControlKM(0, NULL, 0, 0, HTB_LOGMODE_UNDEF, ui32Value);
309 }
310
311 static
312 PVRSRV_ERROR _HTBReadOpMode(const PVRSRV_DEVICE_NODE *psDeviceNode,
313                             const void *psPrivate,
314                             IMG_UINT32 *pui32Value)
315 {
316         PVR_UNREFERENCED_PARAMETER(psDeviceNode);
317         PVR_UNREFERENCED_PARAMETER(psPrivate);
318
319         *pui32Value = (IMG_UINT32)g_sCtrl.eOpMode;
320         return PVRSRV_OK;
321 }
322
323 /*************************************************************************/ /*!
324  @Function      HTBConfigureKM
325  @Description   Configure or update the configuration of the Host Trace Buffer
326
327  @Input         ui32NameSize    Size of the pszName string
328
329  @Input         pszName         Name to use for the underlying data buffer
330
331  @Input         ui32BufferSize  Size of the underlying data buffer
332
333  @Return        eError          Internal services call returned eError error
334                                 number
335 */ /**************************************************************************/
336 PVRSRV_ERROR
337 HTBConfigureKM(
338                 IMG_UINT32 ui32NameSize,
339                 const IMG_CHAR * pszName,
340                 const IMG_UINT32 ui32BufferSize
341 )
342 {
343         if ( !g_sCtrl.pszBufferName )
344         {
345                 g_sCtrl.ui32BufferSize = (ui32BufferSize < HTB_TL_BUFFER_SIZE_MIN)? HTB_TL_BUFFER_SIZE_MIN: ui32BufferSize;
346                 ui32NameSize = (ui32NameSize > PRVSRVTL_MAX_STREAM_NAME_SIZE)? PRVSRVTL_MAX_STREAM_NAME_SIZE: ui32NameSize;
347                 g_sCtrl.pszBufferName = OSAllocMem(ui32NameSize * sizeof(IMG_CHAR));
348                 OSStringNCopy(g_sCtrl.pszBufferName, pszName, ui32NameSize);
349                 g_sCtrl.pszBufferName[ui32NameSize-1] = 0;
350
351                 /* initialise rest of state */
352                 g_sCtrl.eOpMode = HTB_OPMODE_DROPLATEST;
353                 g_sCtrl.ui32LogLevel = 0;
354                 g_sCtrl.ui32PIDCount = 0;
355                 g_sCtrl.ui32PIDHead = 0;
356                 g_sCtrl.eLogMode = HTB_LOGMODE_ALLPID;
357                 g_sCtrl.bLogDropSignalled = IMG_FALSE;
358
359                 PVRSRVAppHintRegisterHandlersUINT32(APPHINT_ID_EnableHTBLogGroup,
360                                                     _HTBReadLogGroup,
361                                                     _HTBSetLogGroup,
362                                                     NULL,
363                                                     NULL);
364                 PVRSRVAppHintRegisterHandlersUINT32(APPHINT_ID_HTBOperationMode,
365                                                     _HTBReadOpMode,
366                                                     _HTBSetOpMode,
367                                                     NULL,
368                                                     NULL);
369         }
370         else
371         {
372                 PVR_DPF((PVR_DBG_ERROR, "HTBConfigureKM: Reconfiguration is not supported\n"));
373         }
374
375         return PVRSRV_OK;
376 }
377
378
379 static void
380 _OnTLReaderOpenCallback( void *pvArg )
381 {
382         if ( g_hTLStream )
383         {
384                 PVRSRV_ERROR eError;
385                 IMG_UINT32 ui32Time = OSClockus();
386                 eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_FWSYNC_SCALE,
387                                 ((IMG_UINT32)((g_sCtrl.ui64SyncOSTS>>32)&0xffffffff)),
388                                 ((IMG_UINT32)(g_sCtrl.ui64SyncOSTS&0xffffffff)),
389                                 ((IMG_UINT32)((g_sCtrl.ui64SyncCRTS>>32)&0xffffffff)),
390                                 ((IMG_UINT32)(g_sCtrl.ui64SyncCRTS&0xffffffff)),
391                                 g_sCtrl.ui32SyncCalcClkSpd);
392         }
393
394         PVR_UNREFERENCED_PARAMETER(pvArg);
395 }
396
397
398 /*************************************************************************/ /*!
399  @Function      HTBControlKM
400  @Description   Update the configuration of the Host Trace Buffer
401
402  @Input         ui32NumFlagGroups Number of group enable flags words
403
404  @Input         aui32GroupEnable  Flags words controlling groups to be logged
405
406  @Input         ui32LogLevel    Log level to record
407
408  @Input         ui32EnablePID   PID to enable logging for a specific process
409
410  @Input         eLogMode        Enable logging for all or specific processes,
411
412  @Input         eOpMode         Control the behaviour of the data buffer
413
414  @Return        eError          Internal services call returned eError error
415                                 number
416 */ /**************************************************************************/
417 PVRSRV_ERROR
418 HTBControlKM(
419         const IMG_UINT32 ui32NumFlagGroups,
420         const IMG_UINT32 * aui32GroupEnable,
421         const IMG_UINT32 ui32LogLevel,
422         const IMG_UINT32 ui32EnablePID,
423         const HTB_LOGMODE_CTRL eLogMode,
424         const HTB_OPMODE_CTRL eOpMode
425 )
426 {
427         PVRSRV_ERROR eError = PVRSRV_OK;
428         IMG_UINT32 ui32RetryCount = HTB_LOG_RETRY_COUNT;
429         IMG_UINT32 i;
430         IMG_UINT32 ui32Time = OSClockus();
431
432         if ( !g_bConfigured && g_sCtrl.pszBufferName && ui32NumFlagGroups )
433         {
434                 eError = TLStreamCreate(
435                                 &g_hTLStream,
436                                 g_sCtrl.pszBufferName,
437                                 g_sCtrl.ui32BufferSize,
438                                 _LookupFlags(HTB_OPMODE_DROPLATEST) | g_ui32TLBaseFlags,
439                                 _OnTLReaderOpenCallback, NULL, NULL, NULL );
440                 PVR_LOGR_IF_ERROR( eError, "TLStreamCreate");
441                 g_bConfigured = IMG_TRUE;
442         }
443
444         if ( HTB_OPMODE_UNDEF != eOpMode && g_sCtrl.eOpMode != eOpMode)
445         {
446                 g_sCtrl.eOpMode = eOpMode;
447                 eError = TLStreamReconfigure(g_hTLStream, _LookupFlags(g_sCtrl.eOpMode | g_ui32TLBaseFlags));
448                 while ( PVRSRV_ERROR_NOT_READY == eError && ui32RetryCount-- )
449                 {
450                         OSReleaseThreadQuanta();
451                         eError = TLStreamReconfigure(g_hTLStream, _LookupFlags(g_sCtrl.eOpMode | g_ui32TLBaseFlags));
452                 }
453                 PVR_LOGR_IF_ERROR( eError, "TLStreamReconfigure");
454         }
455
456         if ( ui32EnablePID )
457         {
458                 g_sCtrl.aui32EnablePID[g_sCtrl.ui32PIDHead] = ui32EnablePID;
459                 g_sCtrl.ui32PIDHead++;
460                 g_sCtrl.ui32PIDHead %= HTB_MAX_NUM_PID;
461                 g_sCtrl.ui32PIDCount++;
462                 if ( g_sCtrl.ui32PIDCount > HTB_MAX_NUM_PID )
463                 {
464                         g_sCtrl.ui32PIDCount = HTB_MAX_NUM_PID;
465                 }
466         }
467
468         /* HTB_LOGMODE_ALLPID overrides ui32EnablePID */
469         if ( HTB_LOGMODE_ALLPID == eLogMode )
470         {
471                 OSCachedMemSet(g_sCtrl.aui32EnablePID, 0, sizeof(g_sCtrl.aui32EnablePID));
472                 g_sCtrl.ui32PIDCount = 0;
473                 g_sCtrl.ui32PIDHead = 0;
474         }
475         if ( HTB_LOGMODE_UNDEF != eLogMode )
476         {
477                 g_sCtrl.eLogMode = eLogMode;
478         }
479
480         if ( ui32NumFlagGroups )
481         {
482                 for (i = 0; i < HTB_FLAG_NUM_EL && i < ui32NumFlagGroups; i++)
483                 {
484                         g_auiHTBGroupEnable[i] = aui32GroupEnable[i];
485                 }
486                 for (; i < HTB_FLAG_NUM_EL; i++)
487                 {
488                         g_auiHTBGroupEnable[i] = 0;
489                 }
490         }
491
492         if ( ui32LogLevel )
493         {
494                 g_sCtrl.ui32LogLevel = ui32LogLevel;
495         }
496
497         /* Dump the current configuration state */
498         eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_OPMODE, g_sCtrl.eOpMode);
499         PVR_LOG_IF_ERROR( eError, "HTBLog");
500         eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_ENABLE_GROUP, g_auiHTBGroupEnable[0]);
501         PVR_LOG_IF_ERROR( eError, "HTBLog");
502         eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_LOG_LEVEL, g_sCtrl.ui32LogLevel);
503         PVR_LOG_IF_ERROR( eError, "HTBLog");
504         eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_LOGMODE, g_sCtrl.eLogMode);
505         PVR_LOG_IF_ERROR( eError, "HTBLog");
506         for (i = 0; i < g_sCtrl.ui32PIDCount; i++)
507         {
508                 eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_ENABLE_PID, g_sCtrl.aui32EnablePID[i]);
509                 PVR_LOG_IF_ERROR( eError, "HTBLog");
510         }
511
512         if (0 != g_sCtrl.ui32SyncMarker && 0 != g_sCtrl.ui32SyncCalcClkSpd)
513         {
514                 eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_FWSYNC_MARK_RPT,
515                                 g_sCtrl.ui32SyncMarker);
516                 PVR_LOG_IF_ERROR( eError, "HTBLog");
517                 eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_FWSYNC_SCALE_RPT, 
518                                 ((IMG_UINT32)((g_sCtrl.ui64SyncOSTS>>32)&0xffffffff)), ((IMG_UINT32)(g_sCtrl.ui64SyncOSTS&0xffffffff)),
519                                 ((IMG_UINT32)((g_sCtrl.ui64SyncCRTS>>32)&0xffffffff)), ((IMG_UINT32)(g_sCtrl.ui64SyncCRTS&0xffffffff)),
520                                 g_sCtrl.ui32SyncCalcClkSpd);
521                 PVR_LOG_IF_ERROR( eError, "HTBLog");
522         }
523
524         return eError;
525 }
526
527 /*************************************************************************/ /*!
528 */ /**************************************************************************/
529 static IMG_BOOL
530 _ValidPID( IMG_UINT32 PID )
531 {
532         IMG_UINT32 i;
533
534         for (i = 0; i < g_sCtrl.ui32PIDCount; i++)
535         {
536                 if ( g_sCtrl.aui32EnablePID[i] == PID )
537                 {
538                         return IMG_TRUE;
539                 }
540         }
541         return IMG_FALSE;
542 }
543
544
545 /*************************************************************************/ /*!
546  @Function      HTBSyncPartitionMarker
547  @Description   Write an HTB sync partition marker to the HTB log
548
549  @Input         ui33Marker      Marker value
550
551 */ /**************************************************************************/
552 void
553 HTBSyncPartitionMarker(
554         const IMG_UINT32 ui32Marker
555 )
556 {
557         g_sCtrl.ui32SyncMarker = ui32Marker;
558         if ( g_hTLStream )
559         {
560                 PVRSRV_ERROR eError;
561                 IMG_UINT32 ui32Time = OSClockus();
562                 eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_FWSYNC_MARK, ui32Marker);
563                 if (PVRSRV_OK != eError)
564                 {
565                         PVR_DPF((PVR_DBG_WARNING, "%s() failed (%s) in %s()", "HTBLog", PVRSRVGETERRORSTRING(eError), __func__));
566                 }
567                 if (0 != g_sCtrl.ui32SyncCalcClkSpd)
568                 {
569                         eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_FWSYNC_SCALE,
570                                         ((IMG_UINT32)((g_sCtrl.ui64SyncOSTS>>32)&0xffffffff)), ((IMG_UINT32)(g_sCtrl.ui64SyncOSTS&0xffffffff)),
571                                         ((IMG_UINT32)((g_sCtrl.ui64SyncCRTS>>32)&0xffffffff)), ((IMG_UINT32)(g_sCtrl.ui64SyncCRTS&0xffffffff)),
572                                         g_sCtrl.ui32SyncCalcClkSpd);
573                         if (PVRSRV_OK != eError)
574                         {
575                                 PVR_DPF((PVR_DBG_WARNING, "%s() failed (%s) in %s()", "HTBLog", PVRSRVGETERRORSTRING(eError), __func__));
576                         }
577                 }
578         }
579 }
580
581
582 /*************************************************************************/ /*!
583  @Function      HTBSyncScale
584  @Description   Write FW-Host synchronisation data to the HTB log when clocks
585                 change or are re-calibrated
586
587  @Input         bLogValues      IMG_TRUE if value should be immediately written
588                                 out to the log
589
590  @Input         ui32OSTS        OS Timestamp
591
592  @Input         ui32CRTS        Rogue timestamp
593
594  @Input         ui32CalcClkSpd  Calculated clock speed
595
596 */ /**************************************************************************/
597 void
598 HTBSyncScale(
599         const IMG_BOOL bLogValues,
600         const IMG_UINT64 ui64OSTS,
601         const IMG_UINT64 ui64CRTS,
602         const IMG_UINT32 ui32CalcClkSpd
603 )
604 {
605         g_sCtrl.ui64SyncOSTS = ui64OSTS;
606         g_sCtrl.ui64SyncCRTS = ui64CRTS;
607         g_sCtrl.ui32SyncCalcClkSpd = ui32CalcClkSpd;
608         if ( g_hTLStream && bLogValues)
609         {
610                 PVRSRV_ERROR eError;
611                 IMG_UINT32 ui32Time = OSClockus();
612                 eError = HTBLog(0, 0, ui32Time, HTB_SF_CTRL_FWSYNC_SCALE,
613                                 ((IMG_UINT32)((ui64OSTS>>32)&0xffffffff)), ((IMG_UINT32)(ui64OSTS&0xffffffff)),
614                                 ((IMG_UINT32)((ui64CRTS>>32)&0xffffffff)), ((IMG_UINT32)(ui64CRTS&0xffffffff)),
615                                 ui32CalcClkSpd);
616                 PVR_DPF((PVR_DBG_WARNING, "%s() failed (%s) in %s()", "HTBLog", PVRSRVGETERRORSTRING(eError), __func__));
617         }
618 }
619
620
621 /*************************************************************************/ /*!
622  @Function      HTBLogKM
623  @Description   Record a Host Trace Buffer log event
624
625  @Input         PID             The PID of the process the event is associated
626                                 with. This is provided as an argument rather
627                                 than querying internally so that events associated
628                                 with a particular process, but performed by
629                                 another can be logged correctly.
630
631  @Input                 ui32TimeStamp   The timestamp to be associated with this log event
632
633  @Input         SF                      The log event ID
634
635  @Input                 ...                             Log parameters
636
637  @Return        PVRSRV_OK       Success.
638
639 */ /**************************************************************************/
640 PVRSRV_ERROR
641 HTBLogKM(
642                 IMG_UINT32 PID,
643                 IMG_UINT32 ui32TimeStamp,
644                 HTB_LOG_SFids SF,
645                 IMG_UINT32 ui32NumArgs,
646                 IMG_UINT32 * aui32Args
647 )
648 {
649         /* format of messages is: SF:PID:TIME:[PARn]*
650          * 32-bit timestamp (us) gives about 1h before looping
651          * Buffer allocated on the stack so don't need a semaphore to guard it
652          */
653         IMG_UINT32 aui32MessageBuffer[HTB_LOG_HEADER_SIZE+HTB_LOG_MAX_PARAMS];
654
655         PVRSRV_ERROR eError = PVRSRV_ERROR_NOT_ENABLED;
656         IMG_UINT32 ui32RetryCount = HTB_LOG_RETRY_COUNT;
657         IMG_UINT32 * pui32Message = aui32MessageBuffer;
658         IMG_UINT32 ui32MessageSize = 4 * (HTB_LOG_HEADER_SIZE+ui32NumArgs);
659
660         if ( g_hTLStream
661                         && ( 0 == PID || ~0 == PID || HTB_LOGMODE_ALLPID == g_sCtrl.eLogMode || _ValidPID(PID) )
662 /*                      && ( g_sCtrl.ui32GroupEnable & (0x1 << HTB_SF_GID(SF)) ) */
663 /*                      && ( g_sCtrl.ui32LogLevel >= HTB_SF_LVL(SF) ) */
664                         )
665         {
666                 *pui32Message++ = SF;
667                 *pui32Message++ = PID;
668                 *pui32Message++ = ui32TimeStamp;
669                 while ( ui32NumArgs )
670                 {
671                         ui32NumArgs--;
672                         pui32Message[ui32NumArgs] = aui32Args[ui32NumArgs];
673                 }
674
675                 eError = TLStreamWrite( g_hTLStream, (IMG_UINT8*)aui32MessageBuffer, ui32MessageSize );
676                 while ( PVRSRV_ERROR_NOT_READY == eError && ui32RetryCount-- )
677                 {
678                         OSReleaseThreadQuanta();
679                         eError = TLStreamWrite( g_hTLStream, (IMG_UINT8*)aui32MessageBuffer, ui32MessageSize );
680                 }
681
682                 if ( PVRSRV_OK == eError )
683                 {
684                         g_sCtrl.bLogDropSignalled = IMG_FALSE;
685                 }
686                 else if ( PVRSRV_ERROR_STREAM_RESERVE_TOO_BIG != eError || !g_sCtrl.bLogDropSignalled )
687                 {
688                         PVR_DPF((PVR_DBG_WARNING, "%s() failed (%s) in %s()", "TLStreamWrite", PVRSRVGETERRORSTRING(eError), __func__));
689                 }
690                 if ( PVRSRV_ERROR_STREAM_RESERVE_TOO_BIG == eError )
691                 {
692                         g_sCtrl.bLogDropSignalled = IMG_TRUE;
693                 }
694         }
695
696         return eError;
697 }
698
699 /* EOF */
700
701