source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xvd/7552/bxvd_dbg.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 11.2 KB
Line 
1
2/***************************************************************************
3 *     Copyright (c) 2004-2011, Broadcom Corporation
4 *     All Rights Reserved
5 *     Confidential Property of Broadcom Corporation
6 *
7 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
8 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
9 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
10 *
11 * $brcm_Workfile: bxvd_dbg.c $
12 * $brcm_Revision: Hydra_Software_Devel/9 $
13 * $brcm_Date: 7/20/11 3:07p $
14 *
15 * Module Description:
16 *
17 *  Various debug utilities that the application can use to gather
18 *  information about XVD state.
19 *
20 *  Decoder debug information can be obtained using the following routines:
21 *
22 *      BXVD_DBG_ControlDecoderDebugLog
23 *      BXVD_DBG_SendDecoderDebugCommand
24 *      BXVD_DBG_ReadDecoderDebugLog
25 *
26 * Revision History:
27 *
28 * $brcm_Log: /magnum/portinginterface/xvd/7401/bxvd_dbg.c $
29 *
30 * Hydra_Software_Devel/9   7/20/11 3:07p davidp
31 * SW7420-2001: Reorder header-file includes.
32 *
33 * Hydra_Software_Devel/8   11/30/09 4:38p btosi
34 * SW7405-3245: added BXVD_DBG_* macros.  Map to either BDBG_INSTANCE_* or
35 * BDBG_*
36 * at compile.
37 *
38 * Hydra_Software_Devel/7   2/9/09 4:58p davidp
39 * PR40234: Byte swap each 4 byte word of the debug log for big endian
40 * systems.
41 *
42 * Hydra_Software_Devel/6   1/21/09 2:01p nilesh
43 * PR45052: Converted BDBG_xxx to BDBG_INSTANCE_xxx calls to support
44 * multiple channels
45 *
46 * Hydra_Software_Devel/5   5/5/08 5:50p davidp
47 * PR40234: DecodeLogSize incorrecting calculated in ReadDecoderDebugLog.
48 *
49 * Hydra_Software_Devel/4   4/25/08 5:40p davidp
50 * PR40234: Local address of WrPtr was incorrect in ReadDecoderDebugLog.
51 *
52 * Hydra_Software_Devel/3   4/18/08 3:19p davidp
53 * PR40234: Use symbolic constants, code cleanup.
54 *
55 * Hydra_Software_Devel/2   4/11/08 4:52p davidp
56 * PR40234: Merge decoder debug logging from branch.
57 *
58 * Hydra_Software_Devel/PR40234/1   4/10/08 3:42p davidp
59 * PR40234: Add support for decoder debug logging.
60 *
61 * Hydra_Software_Devel/1   4/3/08 3:14p davidp
62 * PR40234: Stub out xvd routines to support decoder debug logging.
63 *
64 ***************************************************************************/
65
66#include "bstd.h"                /* standard types */
67#include "bxvd.h"
68#include "bxvd_platform.h"
69#include "bxvd_priv.h"
70#include "bxvd_dbg.h"
71#include "bxvd_errors.h"
72
73BDBG_MODULE(BXVD_DBG);
74
75#define BXVD_P_SWAP32(a) (((a&0xFF)<<24)|((a&0xFF00)<<8)|((a&0xFF0000)>>8)|((a&0xFF000000)>>24))
76
77/***************************************************************************
78Summary:
79  Controls decoder debug logging
80
81Description:
82  This API controls the logging of decoders outer loop debug output. The debug
83  logging can be started or stopped.
84
85  Once the debug logging is enabled, the application must call
86  BXVD_DBG_ReadDecoderDebugLog to read the log. The
87
88  Decoder debug commands can be sent to the decoder using
89  BXVD_SendDecoderDebugCommand. The output of the command would then be
90  read using BXVD_DBG_ReadDecoderDebugLog.
91
92Returns:
93  BERR_SUCCESS
94  BERR_INVALID_PARAMETER
95  BXVD_ERR_DEBUG_LOG_NOBUFFER 
96
97See Also: BXVD_DBG_ReadDecoderDebugLog, BXVD_DBG_SendDecoderDebugCommand
98****************************************************************************/
99BERR_Code BXVD_DBG_ControlDecoderDebugLog
100(
101   BXVD_Handle            hXvd,          /* [in] device handle */
102   BXVD_DBG_DebugLogging  eDebugLogging  /* [in] start/stop logging */
103)
104{
105   bool bStart;
106   BERR_Code rc;
107
108   BDBG_ENTER(BXVD_DBG_ControlDecoderDebugLog);
109
110   if (hXvd == NULL)
111   {
112      return BERR_INVALID_PARAMETER;
113   }
114   
115   if (hXvd->uiDecoderDbgBufVirtAddr == (uint32_t)NULL)
116   {
117      BXVD_DBG_MSG(hXvd, ("Decoder debug log buffer not allocated!"));
118      return BXVD_ERR_DEBUG_LOG_NOBUFFER;
119   }
120
121   if (eDebugLogging == BXVD_DBG_DebugLogging_eStart)
122   {
123      bStart = true;
124   }
125   else
126   {
127      bStart = false;
128   }
129
130   rc = BXVD_P_HostCmdDbgLogControl( hXvd, bStart);
131
132   BDBG_LEAVE(BXVD_DBG_ControlDecoderDebugLog);
133
134   return rc;
135}
136
137/***************************************************************************
138Summary:
139  Send decoder debug commands to the decoder.
140
141Description:
142  This API sends a command string to the decoder. The command format is the
143  same format as used when using the debug prompt via the decoders outer loop
144  UART. 
145
146  Decoder debug commands are sent to the decoder using
147  BXVD_DBG_SendDecoderDebugCommand. The output of the command would then be
148  read using BXVD_DBG_ReadDecoderDebugLog.
149
150Returns:
151  BERR_SUCCESS
152  BERR_INVALID_PARAMETER
153  BXVD_ERR_DEBUG_LOG_NOBUFFER 
154
155See Also: BXVD_DBG_ControlDecoderDebugLog, BXVD_DBG_ReadDecoderDebugLog
156****************************************************************************/
157BERR_Code BXVD_DBG_SendDecoderDebugCommand
158(
159   BXVD_Handle hXvd,      /* [in] device handle */   
160   char        *pCommand  /* [in] pointer to a null terminated command string */
161)
162{
163   BERR_Code rc;
164
165   BDBG_ENTER(BXVD_DBG_SendDecoderDebugCommand);
166
167   if (hXvd == NULL)
168   {
169      return BERR_INVALID_PARAMETER;
170   }
171
172   if (hXvd->uiDecoderDbgBufVirtAddr == (uint32_t)NULL)
173   {
174      BXVD_DBG_MSG(hXvd, ("Decoder debug log buffer not allocated!"));
175      return BXVD_ERR_DEBUG_LOG_NOBUFFER;
176   }
177
178   rc = BXVD_P_HostCmdDbgLogCommand(hXvd, pCommand);
179
180   BDBG_LEAVE(BXVD_DBG_SendDecoderDebugCommand);
181
182   return rc;
183}
184
185/***************************************************************************
186Summary:
187  Read decoder debug log
188
189Description:
190  This API copies a maxium uiBufferSize of data from the decoders debug log
191  buffer to pLogBuffer. The number of bytes copied to the supplied buffer is
192  returned in pBufferCount.
193
194  If there are no bytes to be read, pBufferCount will be 0.
195
196  If an overflow of the decoder debug log buffer has occured, 
197  BERR_ERR_DEBUG_LOG_OVERFLOW will be returned as the function status.
198
199Returns:
200  BERR_SUCCESS
201  BERR_INVALID_PARAMETER
202  BXVD_ERR_DEBUG_LOG_OVERFLOW   
203
204See Also: BXVD_DBG_ControlDecoderDebugLog, BXVD_DBG_SendDecoderDebugCommand
205****************************************************************************/
206BERR_Code BXVD_DBG_ReadDecoderDebugLog
207(
208   BXVD_Handle hXvd,          /* [in] device handle */   
209   char        *pLogBuffer,   /* [in] pointer to buffer where log is copied to */
210   uint32_t    uiBufferSize,  /* [in] maximum number of bytes to copy to buffer */
211   uint32_t    *pBufferCount  /* [out] number of bytes copied from decoder log */
212)
213{
214   uint32_t * pDbgBufWrPtr;  /* Log ring buffer WR pointer, Decoder managed */
215   uint32_t * pDbgBufRdPtr;  /* Log ring buffer RD pointer, XVD managed */
216
217   uint32_t uiBufRdIndex;    /* Last Read char from buffer */
218   uint32_t uiBufWrIndex;    /* Last written char in buffer */
219   uint32_t uiByteCount;     /* Byte count of log segment to copy */
220
221#if BSTD_CPU_ENDIAN == BSTD_ENDIAN_BIG
222   uint32_t * pDbgBufPtr;  /* Log ring buffer long word pointer */
223   uint32_t * pBuf32;      /* Application buffer long word pointer */
224
225   uint32_t ui;
226#endif
227
228   uint32_t uiDecoderLogSize; 
229
230   char *pBuf;
231
232   bool bDone;
233   bool bBufferOverflow;
234
235   BERR_Code rc;
236   
237   BDBG_ENTER(BXVD_DBG_ReadDecoderDebugLog);
238
239   *pBufferCount = 0;
240   uiByteCount = 0;
241   pBuf = pLogBuffer; 
242
243   if (hXvd == NULL)
244   {
245      return BERR_INVALID_PARAMETER;
246   }
247
248   uiDecoderLogSize = (hXvd->stSettings.uiDecoderDebugLogBufferSize / BXVD_P_DBGLOG_ITEM_SIZE);
249
250   if (hXvd->uiDecoderDbgBufVirtAddr == (uint32_t)NULL)
251   {
252      BXVD_DBG_MSG(hXvd, ("Debug log buffer not allocated!"));
253      return BERR_INVALID_PARAMETER;
254   }
255
256   /* Read and write pointers */ 
257   pDbgBufRdPtr = (uint32_t *)(hXvd->uiDecoderDbgBufVirtAddr + BXVD_P_DBGLOG_RD_PTR);
258   pDbgBufWrPtr = (uint32_t *)(hXvd->uiDecoderDbgBufVirtAddr + BXVD_P_DBGLOG_WR_PTR);
259
260   /* Last char written */
261   uiBufWrIndex = *pDbgBufWrPtr;
262
263   /* Determine if overflow bit is set */
264   bBufferOverflow = (bool) (uiBufWrIndex & BXVD_P_DBGLOG_BUFFER_OVERFLOW);
265
266   /* Get Wr index */
267   uiBufWrIndex &= (~BXVD_P_DBGLOG_BUFFER_OVERFLOW); 
268
269   bDone = false;
270   while (!bDone)
271   {
272      uiBufRdIndex = *pDbgBufRdPtr;
273      if (uiBufRdIndex < uiBufWrIndex)
274      {
275         /* Read pointer less than Write pointer */
276         uiByteCount = (uiBufWrIndex  - uiBufRdIndex) * BXVD_P_DBGLOG_ITEM_SIZE;
277
278         if (uiByteCount > uiBufferSize)
279         {
280            uiByteCount = uiBufferSize;
281         }
282
283#if BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE
284         BKNI_Memcpy((void *)pBuf,
285                     (void *)(hXvd->uiDecoderDbgBufVirtAddr + (uiBufRdIndex * BXVD_P_DBGLOG_ITEM_SIZE)),
286                     uiByteCount);
287#else
288         pDbgBufPtr = (uint32_t *)(hXvd->uiDecoderDbgBufVirtAddr + (uiBufRdIndex * BXVD_P_DBGLOG_ITEM_SIZE));
289         pBuf32 = (uint32_t *) pBuf;
290
291         for (ui = 0; ui < uiByteCount/4; ui++)
292         {
293            *pBuf32 = BXVD_P_SWAP32(*pDbgBufPtr);
294
295            pDbgBufPtr++;
296            pBuf32++;
297         }
298#endif
299         /* Update temp app dest buf ptr */
300         pBuf += uiByteCount;
301         *pDbgBufRdPtr += (uiByteCount / BXVD_P_DBGLOG_ITEM_SIZE);
302
303         *pBufferCount += uiByteCount;
304
305         if ( *pDbgBufRdPtr >= uiDecoderLogSize)
306         {
307            *pDbgBufRdPtr = BXVD_P_DBGLOG_INITIAL_INDEX;
308         }
309
310         /* Rd pointer was less than Wr pointer, so we are done */
311         bDone = true; 
312      }
313      else if (uiBufRdIndex > uiBufWrIndex)
314      {
315         /* Write pointer back behind read pointer, read to end of buffer */
316         uiByteCount = (uiDecoderLogSize - uiBufRdIndex) * BXVD_P_DBGLOG_ITEM_SIZE;
317
318         /* If un-read data size greater then app buffer size, use ap size */
319         if (uiByteCount > uiBufferSize)
320         {
321            uiByteCount = uiBufferSize;
322         }
323
324#if BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE
325         BKNI_Memcpy((void *)pBuf,
326                     (void *)(hXvd->uiDecoderDbgBufVirtAddr + (uiBufRdIndex * BXVD_P_DBGLOG_ITEM_SIZE)),
327                     uiByteCount);
328#else
329         pDbgBufPtr = (uint32_t *)(hXvd->uiDecoderDbgBufVirtAddr + (uiBufRdIndex * BXVD_P_DBGLOG_ITEM_SIZE));
330         pBuf32 = (uint32_t *) pBuf;
331
332         for (ui = 0; ui < uiByteCount/4; ui++)
333         {
334            *pBuf32 = BXVD_P_SWAP32(*pDbgBufPtr);
335            pDbgBufPtr++;
336            /* Update temp app dest buf ptr */           
337            pBuf32++;;
338         }
339#endif
340         /* Update temp app dest buf ptr */
341         pBuf += uiByteCount;
342         *pDbgBufRdPtr += (uiByteCount / BXVD_P_DBGLOG_ITEM_SIZE);
343
344         *pBufferCount = uiByteCount; 
345
346         /* If end of buffer, reset to beginning */ 
347         if ( *pDbgBufRdPtr >= uiDecoderLogSize)
348         {
349            *pDbgBufRdPtr = BXVD_P_DBGLOG_INITIAL_INDEX;
350         }
351      }
352      else if (uiBufRdIndex == uiBufWrIndex)
353      {
354         *pBufferCount = uiByteCount;
355
356         /* Buffer is now empty, we are done */
357         bDone = true; 
358      }
359
360      /* Adjust remaining buf size for next time through loop */ 
361      uiBufferSize -= uiByteCount; 
362
363      if (uiBufferSize == 0)
364      {
365         /* No more space in application supplied buffer, we are done */
366         bDone = true; 
367      }
368   }
369
370   if (bBufferOverflow)
371   {
372      /* Overflow bit was set, return overflow */
373      rc = BXVD_ERR_DEBUG_LOG_OVERFLOW;
374   }
375   else
376   {
377      rc = BERR_SUCCESS;
378   }
379
380   BDBG_LEAVE(BXVD_DBG_ReadDecoderDebugLog);
381
382   return rc;
383}
384
385
Note: See TracBrowser for help on using the repository browser.