source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xpt/7552/bxpt_interrupt.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.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2011, 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_interrupt.c $
11 * $brcm_Revision: Hydra_Software_Devel/3 $
12 * $brcm_Date: 8/4/11 11:07a $
13 *
14 * Porting interface code for the data transport interrupt handlers.
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/xpt/base2/bxpt_interrupt.c $
19 *
20 * Hydra_Software_Devel/3   8/4/11 11:07a gmullen
21 * SW7346-399: Fixed coverity warnings
22 *
23 * Hydra_Software_Devel/2   10/28/10 2:08p gmullen
24 * SW7422-20: Checkin ported files
25 *
26 * Hydra_Software_Devel/2   11/27/06 4:24p katrep
27 * PR25431: Added code to detect the lost data ready interrupt and
28 * generate sw callback
29 *
30 * Hydra_Software_Devel/2   8/26/05 2:01p gmullen
31 * PR15309: Added DirecTV support, RAVE video support, cleaned up RS and
32 * XC buffer code.
33 *
34 * Hydra_Software_Devel/1   7/15/05 9:03a gmullen
35 * PR15309: Inita i
36 *
37 *
38 ***************************************************************************/
39
40#include "bstd.h"
41#include "bxpt.h"
42#include "bxpt_interrupt.h"
43#include "bkni.h"
44#include "bxpt_priv.h"
45
46#include "bchp_xpt_msg.h"
47
48#define INTERRUPT_BITS_PER_REGISTER             ( 32 )
49#define REGISTER_SIZE                                   ( 4 )   
50
51BDBG_MODULE( xpt_interrupt );
52
53
54static void MapBitAndAddress( 
55        int MessageBufferNum, 
56        uint32_t InAddress,
57        uint32_t *BitNum,
58        uint32_t *OutAddress
59        );
60
61static void SetBit( 
62        BXPT_Handle hXpt,                                               /* [in] Handle for this transport */
63        uint32_t Addr,
64        int BitNum
65        );
66
67static void ClearBit( 
68        BXPT_Handle hXpt,                                               /* [in] Handle for this transport */
69        uint32_t Addr,
70        int BitNum
71        );
72
73BERR_Code BXPT_Interrupt_EnableMessageInt( 
74        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
75        int MessageBufferNum,           /* [in] Which message buffer to watch. */
76        BINT_CallbackFunc Callback,             /* [in] Handler for this interrupt. */
77        void *Parm1,                                    /* [in] First arg to be passed to callback */
78        int Parm2                                               /* [in] Second arg to be passed to callback */
79        )
80{
81        BERR_Code ExitCode;
82
83        BKNI_EnterCriticalSection();
84        ExitCode = BXPT_Interrupt_EnableMessageInt_isr( hXpt, MessageBufferNum, Callback, Parm1, Parm2 );
85        BKNI_LeaveCriticalSection();
86
87        return ExitCode;
88}
89
90BERR_Code BXPT_Interrupt_DisableMessageInt( 
91        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
92        int MessageBufferNum            /* [in] Message interrupt to disable. */
93        )
94{
95        BERR_Code ExitCode;
96
97        BKNI_EnterCriticalSection();
98        ExitCode = BXPT_Interrupt_DisableMessageInt_isr( hXpt, MessageBufferNum );
99        BKNI_LeaveCriticalSection();
100
101        return ExitCode;
102}
103
104BERR_Code BXPT_Interrupt_EnableMessageInt_isr( 
105        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
106        int MessageBufferNum,           /* [in] Which message buffer to watch. */
107        BINT_CallbackFunc Callback,             /* [in] Handler for this interrupt. */
108        void *Parm1,                                    /* [in] First arg to be passed to callback */
109        int Parm2                                               /* [in] Second arg to be passed to callback */
110        )
111{
112        BERR_Code ExitCode = BERR_SUCCESS;
113
114        BDBG_ASSERT( hXpt );
115        BDBG_ASSERT( Callback );
116                                                                                           
117        if( MessageBufferNum >= BXPT_NUM_MESG_BUFFERS )
118        {
119                /* Bad interrupt number. Complain. */
120                BDBG_ERR(( "MessageBufferNum %lu is out of range!", ( unsigned long ) MessageBufferNum ));
121                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
122        }
123        else
124        {
125                uint32_t BitNum = 0;
126                uint32_t RegAddr = 0;
127
128                /* Load the callback into the jump table. */
129                hXpt->MesgIntrCallbacks[ MessageBufferNum ].Callback = Callback;
130                hXpt->MesgIntrCallbacks[ MessageBufferNum ].Parm1 = Parm1;
131                hXpt->MesgIntrCallbacks[ MessageBufferNum ].Parm2 = Parm2;
132
133                MapBitAndAddress( MessageBufferNum, BCHP_XPT_MSG_BUF_DAT_RDY_INTR_EN_00_31, &BitNum, &RegAddr );
134                SetBit( hXpt, RegAddr, BitNum );
135        }
136
137        return( ExitCode );
138}
139
140
141BERR_Code BXPT_Interrupt_DisableMessageInt_isr( 
142        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
143        int MessageBufferNum            /* [in] Message interrupt to disable. */
144        )
145{
146        BERR_Code ExitCode = BERR_SUCCESS;
147
148        BDBG_ASSERT( hXpt );
149       
150        if( MessageBufferNum >= BXPT_NUM_MESG_BUFFERS )
151        {
152                /* Bad interrupt number. Complain. */
153                BDBG_ERR(( "MessageBufferNum %lu is out of range!", ( unsigned long ) MessageBufferNum ));
154                ExitCode = BERR_TRACE(BERR_INVALID_PARAMETER);
155        }
156        else
157        {                               
158                uint32_t BitNum = 0;
159                uint32_t RegAddr = 0;
160         
161                MapBitAndAddress( MessageBufferNum, BCHP_XPT_MSG_BUF_DAT_RDY_INTR_EN_00_31, &BitNum, &RegAddr );
162                ClearBit( hXpt, RegAddr, BitNum );
163
164                /* Clear the callback entry the jump table. */
165                hXpt->MesgIntrCallbacks[ MessageBufferNum ].Callback = ( BINT_CallbackFunc ) NULL;
166        }
167
168        return( ExitCode );
169}
170
171
172BERR_Code BXPT_Interrupt_EnableMessageOverflowInt( 
173        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
174        int MessageBufferNum,           /* [in] Which message buffer to watch. */
175        BINT_CallbackFunc Callback,             /* [in] Handler for this interrupt. */
176        void *Parm1,                                    /* [in] First arg to be passed to callback */
177        int Parm2                                               /* [in] Second arg to be passed to callback */
178        )
179{
180        BERR_Code ExitCode;
181
182        BKNI_EnterCriticalSection();
183        ExitCode = BXPT_Interrupt_EnableMessageOverflowInt_isr( hXpt, MessageBufferNum, Callback, Parm1, Parm2 );
184        BKNI_LeaveCriticalSection();
185
186        return ExitCode;
187}
188
189
190BERR_Code BXPT_Interrupt_DisableMessageOverflowInt( 
191        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
192        int MessageBufferNum            /* [in] Message interrupt to disable. */
193        )
194{
195        BERR_Code ExitCode;
196
197        BKNI_EnterCriticalSection();
198        ExitCode = BXPT_Interrupt_DisableMessageOverflowInt_isr( hXpt, MessageBufferNum );
199        BKNI_LeaveCriticalSection();
200
201        return ExitCode;
202}
203
204
205BERR_Code BXPT_Interrupt_EnableMessageOverflowInt_isr( 
206        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
207        int MessageBufferNum,           /* [in] Which message buffer to watch. */
208        BINT_CallbackFunc Callback,             /* [in] Handler for this interrupt. */
209        void *Parm1,                                    /* [in] First arg to be passed to callback */
210        int Parm2                                               /* [in] Second arg to be passed to callback */
211        )
212{
213        BERR_Code ExitCode = BERR_SUCCESS;
214
215        BDBG_ASSERT( hXpt );
216        BDBG_ASSERT( Callback );
217                                                                                           
218        if( MessageBufferNum >= BXPT_NUM_MESG_BUFFERS )
219        {
220                /* Bad interrupt number. Complain. */
221                BDBG_ERR(( "MessageBufferNum %lu is out of range!", ( unsigned long ) MessageBufferNum ));
222                ExitCode = BERR_TRACE(BERR_INVALID_PARAMETER);
223        }
224        else
225        {
226                uint32_t BitNum = 0;
227                uint32_t RegAddr = 0;
228
229                /* Load the callback into the jump table. */
230                hXpt->OverflowIntrCallbacks[ MessageBufferNum ].Callback = Callback;
231                hXpt->OverflowIntrCallbacks[ MessageBufferNum ].Parm1 = Parm1;
232                hXpt->OverflowIntrCallbacks[ MessageBufferNum ].Parm2 = Parm2;
233
234                MapBitAndAddress( MessageBufferNum, BCHP_XPT_MSG_BUF_OVFL_INTR_EN_00_31, &BitNum, &RegAddr );
235                SetBit( hXpt, RegAddr, BitNum );
236        }
237
238        return( ExitCode );
239}
240
241
242BERR_Code BXPT_Interrupt_DisableMessageOverflowInt_isr( 
243        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
244        int MessageBufferNum            /* [in] Message interrupt to disable. */
245        )
246{
247        BERR_Code ExitCode = BERR_SUCCESS;
248
249        BDBG_ASSERT( hXpt );
250       
251        if( MessageBufferNum >= BXPT_NUM_MESG_BUFFERS )
252        {
253                /* Bad interrupt number. Complain. */
254                BDBG_ERR(( "MessageBufferNum %lu is out of range!", ( unsigned long ) MessageBufferNum ));
255                ExitCode = BERR_TRACE(BERR_INVALID_PARAMETER);
256        }
257        else
258        {
259                uint32_t BitNum = 0;
260                uint32_t RegAddr = 0;
261
262                MapBitAndAddress( MessageBufferNum, BCHP_XPT_MSG_BUF_OVFL_INTR_EN_00_31, &BitNum, &RegAddr );
263                ClearBit( hXpt, RegAddr, BitNum );
264       
265                MapBitAndAddress( MessageBufferNum, BCHP_XPT_MSG_BUF_OVFL_INTR_00_31, &BitNum, &RegAddr );
266                ClearBit( hXpt, RegAddr, BitNum );
267
268                /* Clear the callback entry the jump table. */
269                hXpt->OverflowIntrCallbacks[ MessageBufferNum ].Callback = ( BINT_CallbackFunc ) NULL;
270        }
271
272        return( ExitCode );
273}
274
275void BXPT_P_Interrupt_MsgVector_isr( 
276        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
277        int L1Shift             /* [in] Dummy arg. Not used by this interface. */
278        )
279{
280        unsigned i, j;
281        uint32_t Status, Mask, StatusAddr, MaskAddr;
282
283        BDBG_ASSERT( hXpt );
284        BSTD_UNUSED( L1Shift ); 
285
286        for( i = 0; i < BXPT_NUM_MESG_BUFFERS; i += INTERRUPT_BITS_PER_REGISTER )
287        {
288                StatusAddr = BCHP_XPT_MSG_BUF_DAT_RDY_INTR_00_31 + ( REGISTER_SIZE * ( i / INTERRUPT_BITS_PER_REGISTER ));
289                Status = BREG_Read32( hXpt->hRegister, StatusAddr );
290
291                MaskAddr = BCHP_XPT_MSG_BUF_DAT_RDY_INTR_EN_00_31 + ( REGISTER_SIZE * ( i / INTERRUPT_BITS_PER_REGISTER ));
292                Mask = BREG_Read32( hXpt->hRegister, MaskAddr );
293
294                if( Status & Mask )
295                {
296                        for( j = 0; j < INTERRUPT_BITS_PER_REGISTER; j++ )
297                        {
298                                if( ( Status & Mask ) & ( 1ul << j ) )
299                                {
300                                        BXPT_P_InterruptCallbackArgs *Cb = &hXpt->MesgIntrCallbacks[ i + j ];
301                                        if( Cb->Callback != ( BINT_CallbackFunc ) NULL )
302                                                (*( Cb->Callback )) ( Cb->Parm1, Cb->Parm2 );
303                                }
304                        }               
305                }
306        }
307}
308
309void BXPT_P_Interrupt_MsgSw_isr(
310    BXPT_Handle hXpt,                           /* [in] Handle for this transport */
311    int MessageBufferNum                    /* [in] Message Buffer */
312    )
313{
314    BXPT_P_InterruptCallbackArgs *Cb = &hXpt->MesgIntrCallbacks[ MessageBufferNum ];
315    if( Cb->Callback != ( BINT_CallbackFunc ) NULL )
316                        (*( Cb->Callback )) ( Cb->Parm1, Cb->Parm2 );
317}
318
319void BXPT_P_Interrupt_MsgOverflowVector_isr( 
320        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
321        int L1Shift             /* [in] Dummy arg. Not used by this interface. */
322        )
323{
324        unsigned i, j;
325        uint32_t Status, Mask, StatusAddr, MaskAddr;
326
327        BDBG_ASSERT( hXpt );
328        BSTD_UNUSED( L1Shift ); 
329
330        for( i = 0; i < BXPT_NUM_MESG_BUFFERS; i += INTERRUPT_BITS_PER_REGISTER )
331        {
332                StatusAddr = BCHP_XPT_MSG_BUF_OVFL_INTR_00_31 + ( REGISTER_SIZE * ( i / INTERRUPT_BITS_PER_REGISTER ));
333                Status = BREG_Read32( hXpt->hRegister, StatusAddr );
334
335                MaskAddr = BCHP_XPT_MSG_BUF_OVFL_INTR_EN_00_31 + ( REGISTER_SIZE * ( i / INTERRUPT_BITS_PER_REGISTER ));
336                Mask = BREG_Read32( hXpt->hRegister, MaskAddr );
337
338                if( Status & Mask )
339                {
340                        for( j = 0; j < INTERRUPT_BITS_PER_REGISTER; j++ )
341                        {
342                                if( ( Status & Mask ) & ( 1ul << j ) )
343                                {
344                                        BXPT_P_InterruptCallbackArgs *Cb = &hXpt->OverflowIntrCallbacks[ i + j ];
345
346                                        if( Cb->Callback != ( BINT_CallbackFunc ) NULL )
347                                                (*( Cb->Callback )) ( Cb->Parm1, Cb->Parm2 );
348                                }
349                        }               
350                }
351        }
352}
353 
354static void MapBitAndAddress( 
355        int MessageBufferNum, 
356        uint32_t InAddress,
357        uint32_t *BitNum,
358        uint32_t *OutAddress
359        )
360{
361        *OutAddress = InAddress + ( REGISTER_SIZE * ( MessageBufferNum / INTERRUPT_BITS_PER_REGISTER ) );
362        *BitNum = MessageBufferNum % INTERRUPT_BITS_PER_REGISTER;
363}
364
365static void SetBit( 
366        BXPT_Handle hXpt,                                               /* [in] Handle for this transport */
367        uint32_t Addr,
368        int BitNum
369        )
370{
371        uint32_t EnReg = BREG_Read32( hXpt->hRegister, Addr );
372
373        EnReg |= ( 1ul << BitNum );
374        BREG_Write32( hXpt->hRegister, Addr, EnReg );
375}
376       
377
378static void ClearBit( 
379        BXPT_Handle hXpt,                                               /* [in] Handle for this transport */
380        uint32_t Addr,
381        int BitNum
382        )
383{
384        uint32_t Reg = BREG_Read32( hXpt->hRegister, Addr );
385       
386        Reg &= ~( 1ul << BitNum );
387        BREG_Write32( hXpt->hRegister, Addr, Reg );
388}
389
390
391/* end of file */
392
Note: See TracBrowser for help on using the repository browser.