/* =============================================================================
 *
 *            TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
 *
 *  Property of Texas Instruments
 *  For Unrestricted Internal Use Only 
 *  Unauthorized reproduction and/or distribution is strictly
 *  prohibited.
 *  This product is protected under copyright law and trade secret law  
 *  as an unpublished work.
 *  Created 2008, (C) Copyright 2008 Texas Instruments.  All rights 
 *  reserved.
 */
/**
 *  @Component    INTH - Project specific Interrupt handler fucntions
 *
 *  @Filename     INTH.h
 *
 *  @Description  Contains Interrupt (IRQ) handler functions allowing
 *                the registering of interrupt handlers for specific vectors.
 *                This file allso contains primary ARM11 irq handler.
 *
 *                Available Functions:
 *                   INTH_InitHandler - Initialisess all interrupt handlers
 *                   INTH_SetupInterrupt - registers and sets up interupt handler
 *                   INTH_RegisterHandler - registers specific handlers
 *                   INTH_GetIntCount - Get interupt count for a vector
 *                   INTH_IRQHandler - HLL IRQ Handler
 *                   INTH_FIQHandler - HLL FIQ Handler
 *                   INTH_BusError - UMA Bus Error handler
 *
 *//*======================================================================== */
#ifndef __INTH_H
#define __INTH_H

/* ============================================================================
* INCLUDE FILES (only if necessary)
* =============================================================================
*/

#include "cslr_a15_gic400_r2p0_0.h"

#ifdef __cplusplus
extern "C"
{
#endif

#pragma SWI_ALIAS(go_secure, 0);

#define INTH_MAX_CORE_NUM      4

#define AINTC_GET_GIC_EVT_ID(x) (x & CSL_CORTEXA15_GICC_IAR_ACKINTID_MASK) >>\
                                          CSL_CORTEXA15_GICC_IAR_ACKINTID_SHIFT

#define AINTC_GET_GIC_SRC_ID(x) (x & CSL_CORTEXA15_GICC_IAR_CPUID_MASK) >>\
                                          CSL_CORTEXA15_GICC_IAR_CPUID_SHIFT

/*-------------------------------------------------------------------------*//**
 * @TYPE         INTH_Handler_t
 *
 * @BRIEF        function pointer to interrupt handlers
 *
 * @DESCRIPTION  A function pointer to interrupt handlers. The functions should
 *               be defined in the following format:
 *
 *               void PREFIX_IntHandler(Uint8 inInterrupt);
 *
 *//*------------------------------------------------------------------------ */
typedef void (*INTH_Handler_t)(Uint32);

/*-------------------------------------------------------------------------*//**
 * @TYPE         INTH_Action_t
 *
 * @BRIEF        Action to perform
 *
 * @DESCRIPTION  List of possible actions
 *
 *
 *//*------------------------------------------------------------------------ */
typedef enum INTH_Type_Action
{
    INTH_ACTION_DISABLE = 0,
    INTH_ACTION_ENABLE
} INTH_Action_t;


/*-------------------------------------------------------------------------*//**
 * @TYPE         INTH_Group_t
 *
 * @BRIEF        Specifies the type of interrupt
 *
 * @DESCRIPTION  Specifies the type of interrupt
 *
 *//*------------------------------------------------------------------------ */
typedef enum INTH_Group_label
{
    INTH_TYPE_GROUP_0 = 0,
    INTH_TYPE_GROUP_1   
} INTH_Group_t;

/*-------------------------------------------------------------------------*//**
 * @TYPE         INTH_InterruptKind_t
 *
 * @BRIEF        Copy from INTCTL
 *
 * @DESCRIPTION  Copy from INTCTL
 *
 *//*------------------------------------------------------------------------ */
typedef enum INTH_InterruptKind_label
{
    INTH_TYPE_IRQ,
    INTH_TYPE_FIQ,
    INTH_TYPE_MAX = INTH_TYPE_FIQ

} INTH_InterruptKind_t;
//#define INTH_IRQ INTCTL_IRQ
//#define INTH_FIQ INTCTL_FIQ

/*-------------------------------------------------------------------------*//**
 * @TYPE         INTH_SGI_Forward_List_t
 *
 * @DESCRIPTION  SGI forwarding types.
 *
 *//*------------------------------------------------------------------------ */
typedef enum INTH_SGI_Target_Mode
{
    TARGET_CPUS_LIST = 0x0,
    TARGET_ALL_CPUS,         // Excludes Self
    TARGET_ONLY_SELF,
    TARGET_KIND_MAX
}INTH_SGI_Target_Mode_t;

/* ----------------------------------------------------------------------------
* TYPE: ReturnCode_t        
*
* DESCRIPTION:  Return codes to be returned by all library functions 
*
* -----------------------------------------------------------------------------
*/
typedef enum ReturnCode_label {
    RET_OK = 0, 
    RET_FAIL, 
    RET_BAD_NULL_PARAM,
    RET_PARAM_OUT_OF_RANGE,
    RET_INVALID_ID,
    RET_EMPTY,
    RET_FULL,
    RET_TIMEOUT,
    RET_INVALID_OPERATION,
    
    /* Beach register tests return codes */
    RET_POR_FAIL,               /* Power on reset fail */
    RET_READ_INTEG_FAIL,        /* Read Integrity fail  */
    RET_READ_ONLY_FAIL,         /* Read only fail */
    RET_WRTIE_ONLY_FAIL,        /* Write only fail */
    RET_RE_UP_FAIL,             /* Read exclusivity Up fail */
    RET_RE_DOWN_FAIL,           /* Read exclusivity Down fail */
    RET_BUSY,

    /* Add new error codes at end of above list */
         
    RET_NUM_RET_CODES     /* this should ALWAYS be LAST entry */
} ReturnCode_t, *pReturnCode_t;


/*-------------------------------------------------------------------------*//**
 * @TYPE         INTH_
 *
 * @BRIEF        Copy from INTCTL
 *
 * @DESCRIPTION  Copy from INTCTL
 *
 *//*------------------------------------------------------------------------ */
typedef Uint8 INTH_Priority_t;

/* ============================================================================
* EXPORTED VARIABLES
* =============================================================================
*/


/* ============================================================================
* EXPORTED FUNCTIONS/MACROS
* =============================================================================
*/

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_InitHandler
 *
 * @BRIEF         Interrupt handler initialisation
 *
 * @param[in,out] void
 *
 * @RETURNS       void       
 *
 * @DESCRIPTION   Carries out Interrupt handler initialisation for all 
 *                interrupt vectors of a specified type
 *
 * @METHOD        Initializes GIC
 *
 * @NOTES         This function should not be called directly by test cases.
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_InitHandler(void);

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_RegisterHandler
 *
 * @BRIEF         Installs the specified interrupt handler
 *
 * @param[in,out] in const Uint32 intVector (Interrupt vector for which 
 *                          to install interrupt)
 *                in const INTH_Handler_t intHandler (interrupt handler for 
 *                                  specified vector (NULL is valid input))
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was 
 *                                               set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Installs the specified interrupt handler for the specified
 *                interrupt vector/type and clears the interrupt counter
 *
 * @METHOD        Checks input parameters
 *                installs handler in array with offset on vector
 *                Reset interrupt counter.
 *
 * @NOTES         In general it is better to use the function 
 *                INTH_SetupInterrupt
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_RegisterHandler( const Uint32          intVector,
                                          const INTH_Handler_t    intHandler);

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_SetupInterrupt
 *
 * @BRIEF         Installs the specified interrupt handler
 *
 * @param[in,out] in const Uint32 intVector (Interrupt vector for which to 
 *                install interrupt)
 *                in const INTH_Handler_t intHandler (interrupt handler for 
 *                specified vector (NULL is valid input))
 *                in const INTH_InterruptKind_t intKind (Specifies type of 
 *                interrupt)
 *                in const INTH_Priority intPriority (Specifies interrupt 
 *                priority)
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was 
 *                                               set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Installs the specified interrupt handler for the specified
 *                interrupt vector/type, clears the interrupt counter and
 *                configure interrupt controler specific stuff
 *
 * @METHOD        Checks input parameters
 *                installs handler in array with offset on vector
 *                Reset interrupt counter.
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_SetupInterrupt( const Uint32          intVector,
                                         const INTH_Handler_t  intHandler,
                                         Uint8                 intTargetId,
                                         const INTH_Priority_t intPriority);


/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_EnableInterrupt
 *
 * @BRIEF         Enable the specified interrupt
 *
 * @param[in,out] in const Uint32 intVector (Interrupt vector for which
 *                                           to enable interrupt)
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was 
 *                                               set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Enable the specified interrupt
 *
 * @METHOD        Call Interrupt Controler enable.
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_EnableInterrupt( const Uint32   intVector);

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_DisableInterrupt
 *
 * @BRIEF         Disable the specified interrupt
 *
 * @param[in,out] in const Uint32 intVector (Interrupt vector for which to 
 *                                           disable interrupt)
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was 
 *                                               set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Disable the specified interrupt
 *
 * @METHOD        Call Interrupt Controler disable.
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_DisableInterrupt( const Uint32   intVector);


/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_GetIntCount
 *
 * @BRIEF         Gives the number of interrupts
 *
 * @param[in,out] in const Uint32 intVector (Interrupt vector for which to get 
 *                                           count value)
 *                out Uint32 *const pIntCount (Number of interrupts since 
 *                                             Handler registered)
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was 
 *                                               set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Gives the number of interrupts for a given type that occured
 *                since the interrupt handler was registered or count cleared
 *
 * @METHOD        Checks input parameters
 *                read value from array  with vector as the offset
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_GetIntCount( const Uint32         intVector,
                                      Uint32 *const        pIntCount);

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_GetIntHandler
 *
 * @BRIEF         Gives interrupt handler address
 *
 * @param[in,out] in const Uint32 intVector (Interrupt vector for which 
 *                                           to get handler address)
 *                out INTH_Handler_t *const pIntHandler (Address of the current
 *                                                       interrupts Handler)
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was 
 *                                               set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Gives the interrupt handler address for a specific interrupt 
 *                type
 *
 * @METHOD        Checks input parameters
 *                read value from array  with vector as the offset
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_GetIntHandler( const Uint32          intVector,
                                        INTH_Handler_t *const   pIntHandler);

/* ------------------------------------------------------------------------*//**
* @FUNCTION      INTH_SetSwInt
 *
 * @BRIEF        Generates interrupt.
 *
 * @param[in,out] Uint8 intVector (Interrupt vector  to trigger)
 *                const INTH_SGI_Target_Mode_t (Target Mode)
 *                const  Uint8 trgtList  (Target List)
 *
 * @RETURNS       ReturnCode_t       
 *                    RET_OK                   No errors
                      RET_BAD_NULL_PARAM       Bad Parameter passed
                      RET_PARAM_OUT_OF_RANGE   Parameter out of range
 *
 * @DESCRIPTION   Triggers the specified SGI
 *
 * @METHOD        Call set s/w interrupt
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_SetSwInt( const Uint8                sgiId,
                                   const INTH_SGI_Target_Mode_t trgtType, 
                                   const  Uint8               trgtList);

/* ------------------------------------------------------------------------*//**
* @FUNCTION      INTH_ClrSwInt
 *
 * @BRIEF        Clears interrupt
 *
 * @param[in,out] Uint8 intVector (Interrupt vector  to clear)
 *                out INTH_Handler_t *const pIntHandler (Address of the current interrupts Handler)
 *
 * @RETURNS       ReturnCode_t       
 *                    RET_OK                   No errors
                      RET_BAD_NULL_PARAM       Bad Parameter passed
                      RET_PARAM_OUT_OF_RANGE   Parameter out of range
 *
 * @DESCRIPTION   Clears the specified interrupt by setting the appropriate bit in the 
 *                Software Interrupt Clear register.
 *
 * @METHOD        Call set s/w interrupt
 *
 *//*------------------------------------------------------------------------ */
//extern ReturnCode_t INTH_ClrSwInt( const Uint8 intVector );

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_ClearIntCount
 *
 * @BRIEF         Reset interrupt count to 0
 *
 * @param[in,out] in const UWORD16/Uint8 intVector (Interrupt vector for which to clear count value)
 *
 * @RETURNS       ReturnCode_t       
 *                     RET_OK                    No errors occured
 *                     RET_BAD_NULL_PARAM        Address/pointer Paramater was set to 0/NULL
 *                     RET_PARAM_OUT_OF_RANGE    intGroup parameter invalid
 *
 * @DESCRIPTION   Reset interrupt count to 0
 *
 * @METHOD        Checks input parameters
 *                Set count for specified register to 0
 *
 *//*------------------------------------------------------------------------ */
extern ReturnCode_t INTH_ClearIntCount( const Uint32 intVector);

extern void INTH_SetEndOfInt(Uint32 eoiVal);

extern void INTH_DeactivateInt(Uint32 dirVal);

extern ReturnCode_t INTH_Set_Pending(Uint32 intVector);

extern ReturnCode_t INTH_Clear_Pending(Uint32 intVector);

extern void INTH_Set_Active(Uint32 intVector);

extern void INTH_Clear_Active(Uint32 intVector);

/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_IRQHandler
 *
 * @BRIEF         primary/HLL interrupt handler
 *
 * @param[in,out] void
 *
 * @RETURNS       void
 *
 * @DESCRIPTION   This is primary/HLL interrupt handler that CPU will jump to
 *                when ARM11/UMA IRQ interrupt occurs
 *
 * @METHOD        Get active interrupt vector
 *                increment interrupt vector counter
 *                Jump to registered handler if exists
 *                validate next interrupt
 *
 * @NOTES         This function should not be called directly by test cases.
 *
 *//*------------------------------------------------------------------------ */
extern void INTH_IRQHandler( void );

// Function defined in AINTC_Common lib
void go_secure(unsigned int (*fcn_p)(),...);  
/* ------------------------------------------------------------------------*//**
 * @FUNCTION      INTH_FIQHandler
 *
 * @BRIEF         primary/HLL interrupt handler
 *
 * @param[in,out] void
 *
 * @RETURNS       void
 *
 * @DESCRIPTION   This is primary/HLL interrupt handler that CPU will jump to
 *                when ARM11/UMA FIQ interrupt occurs
 *
 * @METHOD        Get active interrupt vector
 *                increment interrupt vector counter
 *                Jump to registered handler if exists
 *                validate next interrupt
 *
 * @NOTES         This function should not be called directly by test cases.
 *
 *//*------------------------------------------------------------------------ */

//extern void INTH_FIQHandler( void );


#ifdef __cplusplus
}
#endif

#endif    /* __INTH_H */

/* Nothing past this point */
