source: svn/newcon3bcm2_21bu/magnum/portinginterface/xpt/7552/bxpt_rsbuf_priv.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 15.2 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bxpt_rsbuf_priv.c $
11 * $brcm_Revision: Hydra_Software_Devel/7 $
12 * $brcm_Date: 3/8/12 3:41p $
13 *
14 * Porting interface code for the data transport core.
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/xpt/base2/bxpt_rsbuf_priv.c $
19 *
20 * Hydra_Software_Devel/7   3/8/12 3:41p gmullen
21 * SW7425-2497: Merged to Hydra
22 *
23 * Hydra_Software_Devel/SW7425-2497/1   3/5/12 4:30p gmullen
24 * SW7425-2497: Checks for errors in data pipeline
25 *
26 * Hydra_Software_Devel/6   12/20/11 1:29p gmullen
27 * SW7358-176: Merged to Hydra
28 *
29 * Hydra_Software_Devel/SW7358-176/1   12/20/11 1:05p gmullen
30 * SW7358-175: Added per-client control of XC and RS buffer alloc
31 *
32 * Hydra_Software_Devel/5   9/13/11 4:17p gmullen
33 * SW7425-690: Fixed memory leak in MPOD RS buffer code
34 *
35 * Hydra_Software_Devel/4   8/22/11 5:45p gmullen
36 * SW7231-319: Merged to Hydra branch
37 *
38 * Hydra_Software_Devel/SW7231-319/1   8/16/11 2:15p gmullen
39 * SW7231-319: Initial support for B0
40 *
41 * Hydra_Software_Devel/3   3/8/11 9:58a gmullen
42 * SW7425-156: Fixed incorrect blockout calculations
43 *
44 * Hydra_Software_Devel/2   10/28/10 2:08p gmullen
45 * SW7422-20: Checkin ported files
46 *
47 * Hydra_Software_Devel/18   7/27/10 5:11p gmullen
48 * SW3548-3013: Added error checking to BMEM allocs
49 *
50 * Hydra_Software_Devel/17   4/16/09 7:20p piyushg
51 * PR53728: Each of the XC buffer clients (Remux, RAVE, and the Mesg
52 * filters) would get a separate API to set
53 * their input bitrates. That API would take a client handle and the ID of
54 * the parser band. The XPT PI would
55 * then walk backwards through the pipeline, increasing only the bitrates
56 * for the XC and RS buffers that it
57 * needs to.
58 *
59 * Hydra_Software_Devel/16   8/15/08 1:13p gmullen
60 * PR45729: Fixed initial value for RsBufBO[] and XcBufBO[]
61 *
62 * Hydra_Software_Devel/15   6/17/08 5:55p gmullen
63 * PR43710: Fixed parser all-pass mode.
64 *
65 * Hydra_Software_Devel/14   5/7/08 10:47a gmullen
66 * PR42443: Removed call to change band rates when changing parser mode.
67 *
68 * Hydra_Software_Devel/13   8/13/07 10:01a gmullen
69 * PR33983: Changed band rate calc to 100kb resolution.
70 *
71 * Hydra_Software_Devel/12   3/2/07 11:13a gmullen
72 * PR28354: Workaround for the memory hole.
73 *
74 * Hydra_Software_Devel/11   11/14/06 10:57a gmullen
75 * PR25771: All buffers are 256 bytes, unless user specifies larger.
76 *
77 * Hydra_Software_Devel/10   11/2/06 4:31p gmullen
78 * PR25402: Added support for secure heap to RS and XC buffer code.
79 *
80 * Hydra_Software_Devel/9   8/29/06 8:37a gmullen
81 * PR23896: Fixed similar leak in rs buf code.,
82 *
83 * Hydra_Software_Devel/8   7/24/06 6:37p gmullen
84 * PR22836: If PB0 support is requested, force PB1 support.
85 *
86 * Hydra_Software_Devel/7   7/21/06 11:05a gmullen
87 * PR22601: Fixed memory deallocation bug in BXPT_P_RsBuf_Shutdown
88 *
89 * Hydra_Software_Devel/6   7/20/06 5:30p katrep
90 * PR22365: Added better mangement of XC buffer client BW for playback.XC
91 * buf for PB is given max BW & BW throtle is done at PB engine.Spare BW
92 * enabllag is used to provide more BW for PB if available.
93 *
94 * Hydra_Software_Devel/5   7/12/06 5:54p gmullen
95 * PR21042: XC and RS buffers can be customized to reduce total memory
96 * needs.
97 *
98 * Hydra_Software_Devel/4   6/16/06 11:47a katrep
99 * PR20631: Added support for parser bands 5 and 6,init the RS bufffer
100 * according to number of parser band not not according to the number if
101 * input bands
102 *
103 * Hydra_Software_Devel/3   4/13/06 4:02p gmullen
104 * PR20914: Ported over Prashant's fix from 7401A0
105 *
106 * Hydra_Software_Devel/2   2/1/06 10:19a gmullen
107 * PR18998: Fixed overflow issue in RAVE ITB/CDB, added support for PB
108 * channels.
109 *
110 * Hydra_Software_Devel/4   8/26/05 2:01p gmullen
111 * PR15309: Added DirecTV support, RAVE video support, cleaned up RS and
112 * XC buffer code.
113 *
114 * Hydra_Software_Devel/3   7/26/05 5:48p gmullen
115 * PR15309: Fixed buffer size issue in bxpt_rave.c and added buffer
116 * shutdown code to other blocks.
117 *
118 * Hydra_Software_Devel/2   7/19/05 1:27p gmullen
119 * PR15309: Fixed buffer alloc bugs.
120 *
121 * Hydra_Software_Devel/1   7/15/05 9:04a gmullen
122 * PR15309: Inita i
123 *
124 *
125 *
126 ***************************************************************************/
127
128#include "bstd.h"
129#include "bxpt_priv.h"
130#include "bxpt.h"
131#include "bkni.h"
132#include "bint.h"
133#include "bxpt_rsbuf_priv.h"
134#include "bchp_xpt_rsbuff.h"
135
136#define INPUT_BAND_BUF_SIZE         (200* 1024)
137#define PLAYBACK_BUF_SIZE           (8 * 1024)
138#define MINIMUM_BUF_SIZE            (256)
139#define BUFFER_PTR_REG_STEPSIZE     (BCHP_XPT_RSBUFF_BASE_POINTER_IBP1 - BCHP_XPT_RSBUFF_BASE_POINTER_IBP0)
140#define MAX_BITRATE                 ( 108000000 )
141#define BLOCKOUT_REG_STEPSIZE       (BCHP_XPT_RSBUFF_BO_IBP1 - BCHP_XPT_RSBUFF_BO_IBP0)
142#define DEFAULT_PACKET_LEN          (188)
143
144/* Threshold for pause generation when XC Buffer for a corresponding band is almost full */
145#define DEFAULT_PACKET_PAUSE_LEVEL  ( 12 )
146
147#if( BDBG_DEBUG_BUILD == 1 )
148BDBG_MODULE( xpt_rsbuf_priv );
149#endif
150
151static BERR_Code AllocateBuffer(
152    BXPT_Handle hXpt,               
153    unsigned BaseRegAddr,       /* [in] Which client buffer we are dealing with */
154    unsigned WhichInstance,
155    unsigned long Size          /* [in] Size in bytes. Must be a multiple of 256. */
156    )
157{
158    uint32_t Offset;
159    void *Buffer;
160
161    BERR_Code ExitCode = BERR_SUCCESS;
162
163    /* If there is a secure heap defined, use it. */
164    BMEM_Handle hMem = hXpt->hRHeap ? hXpt->hRHeap : hXpt->hMemory;
165
166    BaseRegAddr = BaseRegAddr + WhichInstance * BUFFER_PTR_REG_STEPSIZE;
167
168    /* Size must be a multiple of 256. */
169    Size = Size - ( Size % 256 );
170
171    Buffer = BMEM_AllocAligned( hMem, Size, 8, 0 ); 
172    if( !Buffer )
173    {
174        BDBG_ERR(( "RS buffer alloc failed!" ));
175        ExitCode = BERR_TRACE( BERR_OUT_OF_DEVICE_MEMORY );
176        goto Done;
177    }
178    BMEM_ConvertAddressToOffset( hMem, Buffer, &Offset );
179
180    BREG_Write32( hXpt->hRegister, BaseRegAddr, Offset );                   /* Set BASE */
181    BREG_Write32( hXpt->hRegister, BaseRegAddr + 4, Offset + Size - 1 );    /* Set END */
182    BREG_Write32( hXpt->hRegister, BaseRegAddr + 8, Offset - 1 );           /* Set WRITE */
183    BREG_Write32( hXpt->hRegister, BaseRegAddr + 12, Offset - 1 );          /* Set VALID */
184    BREG_Write32( hXpt->hRegister, BaseRegAddr + 16, Offset - 1 );          /* Set READ */
185    BREG_Write32( hXpt->hRegister, BaseRegAddr + 20, 0 );                   /* Set WATERMARK */
186
187    Done:
188    return( ExitCode );
189}
190
191static BERR_Code DeleteBuffer(
192    BXPT_Handle hXpt, 
193    unsigned BaseRegAddr,       /* [in] Which client buffer we are dealing with */
194    unsigned WhichInstance
195    )
196{
197    uint32_t Offset;
198    void *Buffer;
199
200    BERR_Code ExitCode = BERR_SUCCESS;
201
202    /* If there is a secure heap defined, use it. */
203    BMEM_Handle hMem = hXpt->hRHeap ? hXpt->hRHeap : hXpt->hMemory;
204
205    BaseRegAddr = BaseRegAddr + WhichInstance * BUFFER_PTR_REG_STEPSIZE;
206
207    Offset = BREG_Read32( hXpt->hRegister, BaseRegAddr );
208    BMEM_ConvertOffsetToAddress( hMem, Offset, ( void ** ) &Buffer );
209    BMEM_Free( hMem, Buffer );
210   
211    return( ExitCode );
212}
213
214static BERR_Code SetBufferEnable( 
215    BXPT_Handle hXpt, 
216    unsigned EnableRegAddr,
217    unsigned Index,
218    bool EnableIt
219    )
220{
221    uint32_t EnReg;
222
223    BERR_Code ExitCode = BERR_SUCCESS;
224
225    EnReg = BREG_Read32( hXpt->hRegister, EnableRegAddr );
226    if( EnableIt )
227    {
228        EnReg |= ( 1ul << Index );
229    }
230    else
231    {
232        EnReg &= ~( 1ul << Index );
233    }
234    BREG_Write32( hXpt->hRegister, EnableRegAddr, EnReg ); 
235   
236    return( ExitCode );
237}
238
239static unsigned long ComputeBlockOut( 
240        unsigned long PeakRate,                 /* [in] Max data rate (in bps) the band will handle. */
241    unsigned PacketLen              /* [in] Packet size ,130 for dss and 188 for mpeg */
242    )
243{
244    if( PeakRate < BXPT_MIN_PARSER_RATE )
245    {
246        BDBG_WRN(( "Minimum buffer rate is %u bps. PeakRate will be clamped to this value", BXPT_MIN_PARSER_RATE ));
247        PeakRate = BXPT_MIN_PARSER_RATE;
248    }
249    else if( PeakRate > BXPT_MAX_PARSER_RATE )
250    {
251        BDBG_WRN(( "Maximum buffer rate is %u bps. PeakRate will be clamped to this value", BXPT_MAX_PARSER_RATE ));
252        PeakRate = BXPT_MAX_PARSER_RATE;
253    }
254
255    return (10800 * PacketLen * 8) / ( PeakRate / 10000 );
256}
257
258static BERR_Code SetBlockout(
259    BXPT_Handle hXpt,           /* [in] Handle for this transport */
260    unsigned BufferTypeBlockoutAddr,
261    unsigned WhichInstance,
262    unsigned long NewB0       
263    )
264{
265    uint32_t Reg, RegAddr;
266
267    BERR_Code ExitCode = BERR_SUCCESS;
268
269    BDBG_ASSERT( hXpt );
270
271    RegAddr = BufferTypeBlockoutAddr + WhichInstance * BLOCKOUT_REG_STEPSIZE;
272    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
273    Reg &= ~BCHP_MASK( XPT_RSBUFF_BO_IBP0, BO_COUNT );
274    Reg |= BCHP_FIELD_DATA( XPT_RSBUFF_BO_IBP0, BO_COUNT, NewB0 );
275    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
276
277    return( ExitCode );
278}
279
280/*
281** These functions are called internally from BXPT_Open() and BXPT_Close().
282** Users should NOT uses these functions directly.
283*/
284
285BERR_Code BXPT_P_RsBuf_Init(
286        BXPT_Handle hXpt,                       /* [in] Handle for this transport */
287    const BXPT_BandWidthConfig *BandwidthConfig
288        )
289{
290    unsigned ii;
291
292    BERR_Code ExitCode = BERR_SUCCESS;
293    unsigned totalAllocated = 0;
294
295    BDBG_ASSERT( hXpt );
296    BDBG_ASSERT( BandwidthConfig );
297
298    #if BXPT_HAS_IB_PID_PARSERS
299    for( ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++ )
300    {
301        if( BandwidthConfig->MaxInputRate[ ii ] )
302        {
303            BDBG_MSG(( "Alloc RS for IB parser %u, %u bps", ii, BandwidthConfig->MaxInputRate[ ii ] ));
304            AllocateBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_IBP0, ii, INPUT_BAND_BUF_SIZE );
305            SetBlockout( hXpt, BCHP_XPT_RSBUFF_BO_IBP0, ii, 
306               ComputeBlockOut( BandwidthConfig->MaxInputRate[ ii ], DEFAULT_PACKET_LEN ) );
307            SetBufferEnable( hXpt, BCHP_XPT_RSBUFF_IBP_BUFFER_ENABLE, ii, true );
308            totalAllocated += INPUT_BAND_BUF_SIZE;
309        }
310        else
311        {
312            AllocateBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_IBP0, ii, MINIMUM_BUF_SIZE );
313            totalAllocated += MINIMUM_BUF_SIZE;
314        }
315    }
316    #endif
317
318    #if BXPT_HAS_PLAYBACK_PARSERS
319    for( ii = 0; ii < BXPT_NUM_PLAYBACKS; ii++ )
320    {
321        if( BandwidthConfig->MaxPlaybackRate[ ii ] )
322        {
323            BDBG_MSG(( "Alloc RS for PB parser %u, %u bps", ii, BandwidthConfig->MaxPlaybackRate[ ii ] ));
324            AllocateBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_PBP0, ii, PLAYBACK_BUF_SIZE );
325            SetBlockout( hXpt, BCHP_XPT_RSBUFF_BO_PBP0, ii, 
326               ComputeBlockOut( 2 * BandwidthConfig->MaxPlaybackRate[ ii ], DEFAULT_PACKET_LEN ) );
327            SetBufferEnable( hXpt, BCHP_XPT_RSBUFF_PBP_BUFFER_ENABLE, ii, true );
328            totalAllocated += INPUT_BAND_BUF_SIZE;
329        }
330        else
331        {
332            AllocateBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_PBP0, ii, MINIMUM_BUF_SIZE );
333            totalAllocated += MINIMUM_BUF_SIZE;
334        }
335    }
336    #endif
337
338    #if BXPT_HAS_MPOD_RSBUF
339    for( ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++ )
340    {
341        if( BandwidthConfig->MaxInputRate[ ii ] )
342        {
343            BDBG_MSG(( "Alloc RS for IB MPOD parser %u, %u bps", ii, BandwidthConfig->MaxInputRate[ ii ] ));
344            AllocateBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_MPOD_IBP0, ii, INPUT_BAND_BUF_SIZE );
345            SetBlockout( hXpt, BCHP_XPT_RSBUFF_BO_MPOD_IBP0, ii, 
346               ComputeBlockOut( BandwidthConfig->MaxInputRate[ ii ], DEFAULT_PACKET_LEN ) );
347            SetBufferEnable( hXpt, BCHP_XPT_RSBUFF_MPOD_IBP_BUFFER_ENABLE, ii, true );
348            totalAllocated += INPUT_BAND_BUF_SIZE;
349        }
350        else
351        {
352            AllocateBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_MPOD_IBP0, ii, MINIMUM_BUF_SIZE );
353            totalAllocated += MINIMUM_BUF_SIZE;
354        }
355    }
356    #endif
357
358    BDBG_MSG(( "RS totalAllocated: %u bytes", totalAllocated ));
359    return ExitCode;
360}
361
362BERR_Code BXPT_P_RsBuf_Shutdown(
363        BXPT_Handle hXpt                        /* [in] Handle for this transport */
364        )
365{
366    unsigned ii;
367
368    BERR_Code ExitCode = BERR_SUCCESS;
369
370    BDBG_ASSERT( hXpt );
371
372    #if BXPT_HAS_IB_PID_PARSERS
373    for( ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++ )
374    {
375        ExitCode |= SetBufferEnable( hXpt, BCHP_XPT_RSBUFF_IBP_BUFFER_ENABLE, ii, false );
376        ExitCode |= DeleteBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_IBP0, ii );
377        if( ExitCode != BERR_SUCCESS )
378        {
379            BDBG_ERR(( "Disable/Delete of RS Buffer %d failed", ii ));
380            goto Done;
381        }
382    }
383    #endif
384
385    #if BXPT_HAS_PLAYBACK_PARSERS
386    for( ii = 0; ii < BXPT_NUM_PLAYBACKS; ii++ )
387    {
388        ExitCode |= SetBufferEnable( hXpt, BCHP_XPT_RSBUFF_PBP_BUFFER_ENABLE, ii, false );
389        ExitCode |= DeleteBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_PBP0, ii );
390        if( ExitCode != BERR_SUCCESS )
391        {
392            BDBG_ERR(( "Disable/Delete of RS Buffer %d failed", ii ));
393            goto Done;
394        }
395    }
396    #endif
397
398    #if BXPT_HAS_MPOD_RSBUF
399    for( ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++ )
400    {
401        ExitCode |= SetBufferEnable( hXpt, BCHP_XPT_RSBUFF_MPOD_IBP_BUFFER_ENABLE, ii, false );
402        ExitCode |= DeleteBuffer( hXpt, BCHP_XPT_RSBUFF_BASE_POINTER_MPOD_IBP0, ii );
403        if( ExitCode != BERR_SUCCESS )
404        {
405            BDBG_ERR(( "Disable/Delete of RS MPOD Buffer %d failed", ii ));
406            goto Done;
407        }
408    }
409    #endif
410
411    Done:
412    return ExitCode;
413}
414
415BERR_Code BXPT_P_RsBuf_ReportOverflows( 
416    BXPT_Handle hXpt
417    )
418{
419    uint32_t Overflow;
420    unsigned BufferNum;
421
422    BERR_Code Status = 0;
423
424#if BXPT_HAS_MPOD_RSBUF
425    Overflow = BREG_Read32( hXpt->hRegister, BCHP_XPT_RSBUFF_MPOD_IBP_BUFFER_ENABLE ) & 
426        BREG_Read32( hXpt->hRegister, BCHP_XPT_RSBUFF_MPOD_IBP_OVERFLOW_STATUS );
427    Status |= Overflow;
428    for( BufferNum = 0; BufferNum < BXPT_NUM_PID_PARSERS; BufferNum++ )
429    {
430        if (Overflow & 1 << BufferNum)
431            BDBG_ERR(( "RS MPOD buffer has overflowed. Consider increasing BXPT_BandWidthConfig.MaxInputRate[%u]", BufferNum ));
432    }
433#endif
434
435    Overflow = BREG_Read32( hXpt->hRegister, BCHP_XPT_RSBUFF_IBP_BUFFER_ENABLE ) & 
436        BREG_Read32( hXpt->hRegister, BCHP_XPT_RSBUFF_IBP_OVERFLOW_STATUS );
437    Status |= Overflow;
438    for( BufferNum = 0; BufferNum < BXPT_NUM_PID_PARSERS; BufferNum++ )
439    {
440        if (Overflow & 1 << BufferNum)
441            BDBG_ERR(( "RS buffer has overflowed. Consider increasing BXPT_BandWidthConfig.MaxInputRate[%u]", BufferNum ));
442    }
443
444    Overflow = BREG_Read32( hXpt->hRegister, BCHP_XPT_RSBUFF_PBP_BUFFER_ENABLE ) & 
445        BREG_Read32( hXpt->hRegister, BCHP_XPT_RSBUFF_PBP_OVERFLOW_STATUS );
446    Status |= Overflow;
447    for( BufferNum = 0; BufferNum < BXPT_NUM_PLAYBACKS; BufferNum++ )
448    {
449        if (Overflow & 1 << BufferNum)
450            BDBG_ERR(( "RS buffer has overflowed. Consider increasing BXPT_BandWidthConfig.MaxPlaybackRate[%u]", BufferNum ));
451    }
452
453    return Status;
454}
455
Note: See TracBrowser for help on using the repository browser.