blob: a81f0eba7b3e20f4de6ec56596682283e26a8b77 [file] [log] [blame]
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* isrentry.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* This Module defines the IRQ service routines for all IRQ sources
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
/*******************************************************************************
* Include header files.
*******************************************************************************/
#ifdef __MTK_TARGET__
#include <mips/mt.h>
#endif
#include "reg_base.h"
#include "isrentry.h"
#include "intrCtrl.h"
#include "md97/idle_service.h"
#include "drv_rstctl.h"
#include "kal_hrt_api.h"
#include "sync_data.h"
#include "kal_general_types.h"
#include "kal_public_api.h"
#include "kal_public_defs.h"
#include "us_timer.h"
#include "drv_mdcirq.h"
#include "drv_mdcirq_reg.h"
#include "kal_iram_section_defs.h"
#include "drv_vpe_irq.h"
#include "kal_cpuinfo.h"
#include "mips_ia_utils.h"
#include "drv_vpe_irq.h"
#include "ex_public.h"
#include "SST_sla.h"
#include "swtr.h"
#include "kal_internal_api.h"
#include "syscomp_config.h"
#include "kal_wp_hook.h"
#if defined(__ESL_DBG_UTIL__)
#include "esl_debug.h"
#else /* __ESL_DBG_UTIL__ */
#define esl_printf(donothing...) do {;}while(0)
#endif /* __ESL_DBG_UTIL__ */
/*************************************************************************
* Define function prototypes and data structures.
*************************************************************************/
extern void kal_hrt_mt_save(kal_uint32 irqvector, kal_mt_stack_ptr *stack_ptr);
extern void kal_hrt_mt_restore(kal_uint32 irqvector, kal_mt_stack_ptr *stack_ptr);
#if defined(__DUMMY_L1_ON_TARGET_4G5G__)
extern void xl1r_vpe_idle_setup_False(void);
#endif
/*************************************************************************
* Define imported global data.
*************************************************************************/
extern kal_uint16 HWIRQCode2SWIRQCode[];
extern kal_uint16 SWIRQCode2HWIRQCode[];
extern const isr_config_s isr_config_tbl[];
/*************************************************************************
* Define global data.
*************************************************************************/
irqlisr_entry lisr_dispatch_tbl[NUM_IRQ_SOURCES];
__MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ZI(4) void *processing_lisr[MDCIRQ_TOTAL_VPE_NUM];
__MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_RW(4) kal_uint32 processing_irqx[MDCIRQ_TOTAL_VPE_NUM] = {IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT, IRQ_NOT_LISR_CONTEXT};
__MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ZI(4) kal_uint32 processing_irqCnt[MDCIRQ_TOTAL_VPE_NUM];
__MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ZI(4) kal_uint32 max_processing_irqCnt[MDCIRQ_TOTAL_VPE_NUM];
/* spurious interrupt log */
#define SPURIOUS_IRQ_LOG_SIZE 20
kal_uint32 spurious_count[MDCIRQ_TOTAL_VPE_NUM] = {0};
kal_uint32 spurious_id[MDCIRQ_TOTAL_VPE_NUM][SPURIOUS_IRQ_LOG_SIZE];
/*************************************************************************
* Macro Definitions for "CIRQ Dispatch Misbehaviour" SW Workaround *
*************************************************************************/
#define MDCIRQ_DUMMY_DI() \
do{ \
__asm__ __volatile__( \
"di\n\t" \
"ehb\n\t" \
); \
} while(0)
#define MDCIRQ_DUMMY_EI() \
do{ \
__asm__ __volatile__( \
"ei\n\t" \
"ehb\n\t" \
); \
} while(0)
/* Delay 3T CIRQ cycles for GCR_VPE_IRQ_STATE and IE_status to sync to CIRQ *
* 3T CIRQ cycles = 18T CPU cycles --> 3 * 6(shaolin to cirq clock ratio) * 2 *
* (dual issue impact) = 36 ALU Instructions */
// 3T CIRQ cycles * Dual issue impact
#define MDCIRQ_DELAY_CYCLES 3 * 2
// MDCIRQ_DELAY_CYCLES * (5 nop + 1 addiu from for loop) = 36 ALU Instructions
#define MDCIRQ_DELAY_LOOP() \
do{ \
register kal_uint32 _delay_loop; \
for(_delay_loop = 0; _delay_loop < MDCIRQ_DELAY_CYCLES; _delay_loop++) { \
__asm__ __volatile__( \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
); \
} \
}while(0)
/*************************************************************************
* Macro Definitions for "CIRQ Dispatch Misbehaviour" SW Workaround End *
*************************************************************************/
/*************************************************************************
* FUNCTION
* MDCIRQ_IRQ_LISR_Init
*
* DESCRIPTION
* This function implement IRQ's LISR (Low-level Interrupt Service Routine)
* Table initialization.
*
* CALLS
*
* CALL BY
*
* PARAMETERS
*
* RETURNS
*
*************************************************************************/
void MDCIRQ_IRQ_LISR_Init()
{
kal_uint32 i;
for (i = NUM_IRQ_SOURCES; i != 0; i--)
{
MDCIRQ_IRQ_Register_LISR(i - 1, MDCIRQ_IRQ_Default_LISR, "NULL handler");
}
}
/*************************************************************************
* FUNCTION
* MDCIRQ_IRQ_Register_LISR
*
* DESCRIPTION
* This function implement method to register IRQ's LISR.
*
* CALLS
*
* CALL BY
*
* PARAMETERS
* HWIRQID - vector number to register
* reg_lisr - register LISR's handler
* description - LISR's description pointer to be saved.
* Remember, the routine won't duplicate the description,
* therefore, caller shouldn't free the description.
*
* RETURNS
*
*************************************************************************/
void MDCIRQ_IRQ_Register_LISR(kal_uint16 HWIRQCode, void (*reg_lisr)(kal_uint32), char* description)
{
kal_uint32 savedMask, SWIRQCode;
/* Caller:
* 1. MDCIRQ_IRQ_LISR_Init() call this API for all IRQ LISR init.
* 2. Users call this API register their LISR. If user already fill LISR info in gen97_isr_config.h, return directly.
*/
if(isr_config_tbl[HWIRQCode].irq_hdlr != (irq_isr_hdlr_ptr)MDCIRQ_IRQ_Default_LISR
&& (irq_isr_hdlr_ptr)reg_lisr != (irq_isr_hdlr_ptr)MDCIRQ_IRQ_Default_LISR)
{
return;
}
savedMask = kal_hrt_SaveAndSetIRQMask();
SWIRQCode = (kal_uint32)HWIRQCode2SWIRQCode[HWIRQCode];
lisr_dispatch_tbl[HWIRQCode].vector = SWIRQCode;
lisr_dispatch_tbl[HWIRQCode].lisr_handler = reg_lisr;
lisr_dispatch_tbl[HWIRQCode].description = description;
kal_hrt_RestoreIRQMask(savedMask);
}
/**************************************************************************
* FUNCTION
* MDCIRQ_IRQ_Register_LISR_isrc
*
* DESCRIPTION
* This function implement method to register IRQ's LISR.
* This is internal API.
* SS team help users register LISR.
*
* CALLER
* stack_init_lisrs()
*
***************************************************************************/
void MDCIRQ_IRQ_Register_LISR_isrc(kal_uint32 HWIRQCode, void (*reg_lisr)(kal_uint32), char* description)
{
kal_uint32 savedMask, SWIRQCode;
/* If user DO NOT fill LISR info in gen97_isr_config.h, that means user should register LISR by himself. */
if((irq_isr_hdlr_ptr)reg_lisr == (irq_isr_hdlr_ptr)MDCIRQ_IRQ_Default_LISR)
{
return;
}
savedMask = kal_hrt_SaveAndSetIRQMask();
SWIRQCode = (kal_uint32)HWIRQCode2SWIRQCode[HWIRQCode];
lisr_dispatch_tbl[HWIRQCode].vector = SWIRQCode;
lisr_dispatch_tbl[HWIRQCode].lisr_handler = reg_lisr;
lisr_dispatch_tbl[HWIRQCode].description = description;
kal_hrt_RestoreIRQMask(savedMask);
}
/*************************************************************************
* FUNCTION
* MDCIRQ_IRQ_Retrieve_LISR
*
* DESCRIPTION
* This function implement to retrieve register LISR handler
*
* CALLS
*
* CALL BY
*
* PARAMETERS
*
* RETURNS
*
*************************************************************************/
void* MDCIRQ_IRQ_Retrieve_LISR(kal_uint16 HWIRQCode)
{
return(void*)(lisr_dispatch_tbl[HWIRQCode].lisr_handler);
}
/*************************************************************************
* FUNCTION
* IRQ_Default_LISR
*
* DESCRIPTION
* This function implement default IRQ' LISR
*
* CALLS
*
* CALL BY
* IRQ_LISR_Init()
*
* PARAMETERS
*
* RETURNS
*
*************************************************************************/
void MDCIRQ_IRQ_Default_LISR(kal_uint32 irq_id)
{
kal_fatal_error_handler(KAL_ERROR_NON_REGISTERED_LISR, irq_id);
}
void INT_Timer_Interrupt(void)
{
kal_timer_interrupt();
}
void isrC_Main(kal_uint32 vector)
{
kal_uint32 vpe_num;
kal_uint32 irqx_swcode, irqx_swcode_non_spurious;
kal_uint32 irqx_hwcode, irqx_hwcode_non_spurious;
void *processing_lisr_backup;
kal_uint32 processing_irqx_backup;
kal_uint32 ori_vpe_state;
kal_mt_stack_ptr mt_stack_ptr_backup = {{NULL}};
ASSERT_EXL_SAFE(vector == VPE_IRQID_MDCIRQ);
vpe_num = kal_get_current_vpe_id();
processing_lisr_backup = processing_lisr[vpe_num];
processing_irqx_backup = processing_irqx[vpe_num];
#if defined(__MDCIRQ_GCR_SIGNAL_DISABLE__)
irqx_swcode = DRV_Reg32(MDCIRQ_VPE_IRQ_ID_BASE + (vpe_num<<2));
#else
irqx_swcode = DRV_Reg32(MDCIRQ_GCR_VPE_IRQ_ID_BASE + (vpe_num<<2));
#endif
irqx_swcode_non_spurious = irqx_swcode & 0x1ff;
/* Set&backup VPE IRQ state */
ori_vpe_state = drv_mdcirq_SaveAndSet_VPE_state(vpe_num, irqx_swcode_non_spurious);
/* Reset TC's priority according IRQ's Priority */
register miu_reg32_t tc_priority;
if (irqx_swcode < IRQ_HRT_PRIORITY_THRESHOLD) {
// HRT IRQs
tc_priority = HRT_CONTEXT_GRP;
} else {
// Non-HRT IRQs and Spurious IRQs
tc_priority = kal_get_current_domain();
}
miu_mtc0(MIU_C0_TCSCHEDULE, tc_priority << MIU_C0_TCSCHEDULE_PRIO_BITFIELD_BEG);
#if defined(__DUMMY_L1_ON_TARGET_4G5G__)
/* Record current VPE is not in Idletask for KS IODT FPGA */
xl1r_vpe_idle_setup_False();
#endif
irqx_hwcode_non_spurious = (kal_uint32)SWIRQCode2HWIRQCode[irqx_swcode_non_spurious];
irqx_hwcode = irqx_hwcode_non_spurious | (irqx_swcode&0x200);
/* Use HW code to do IRQ logging */
esl_printf(ESL_SIM_TIME_FLAG|ESL_WALL_TIME_FLAG, "[ISR-%d S]\n", irqx_hwcode);
/* These global variable will be used by others. The meaning should keep the same as 93*/
processing_irqx[vpe_num] = irqx_hwcode_non_spurious;
processing_lisr[vpe_num] = (void*)lisr_dispatch_tbl[irqx_hwcode_non_spurious].lisr_handler;
processing_irqCnt[vpe_num]++;
if(processing_irqCnt[vpe_num]>max_processing_irqCnt[vpe_num])
{
max_processing_irqCnt[vpe_num] = processing_irqCnt[vpe_num];
}
SLA_LoggingLISR(0xaaaa0000 | ((kal_uint32)irqx_hwcode), vpe_num);
/************************************************************************************
* SW workaround for "CIRQ Dispatch Misbehaviour" *
* When low priority IRQ is enterting IRQ handler flow (readID ~ set vpe state), and *
* high priority IRQ is choosing best vpe according to vpe state, the high priority *
* IRQ will dispatch to the same VPE and preempt low priority IRQ since vpe state *
* of the low priority IRQ has not yet been updated to CIRQ. This may cause two *
* critical LISRS to run on the same VPE while other VPEs are in IDLE. Therefore, we *
* trigger a dummy DI/EI below to force high priority IRQ to be resent to other VPEs.*
*************************************************************************************/
#if defined(__MDCIRQ_GCR_SIGNAL_DISABLE__)
/* Dummy read APB_VPE_IRQ_STATE to guarantee value has been written to CIRQ */
ASSERT_EXL_SAFE(MDCIRQ_READ_REG_INDEX(MDCIRQ_VPE_IRQ_STATE_BASE, vpe_num) == irqx_swcode_non_spurious);
#else
/* Dummy read GCR_VPE_IRQ_STATE to guarantee value has been written to GCR,
then wait for 3T CIRQ clock so that the GCR value is synced to CIRQ */
ASSERT_EXL_SAFE(MDCIRQ_READ_REG_INDEX(MDCIRQ_GCR_VPE_IRQ_STATE_BASE, vpe_num) == irqx_swcode_non_spurious);
MDCIRQ_DELAY_LOOP();
#endif
/* Dummy DI/EI to force pending IRQs to be resent */
MDCIRQ_DUMMY_DI();
MDCIRQ_DELAY_LOOP();
MDCIRQ_DUMMY_EI();
/************************************************************************************
* SW workaround for "CIRQ Dispatch Misbehaviour" End *
*************************************************************************************/
/* Non-Spurious IRQ */
if(!(irqx_hwcode&0x200))
{
kal_hrt_mt_save(irqx_hwcode_non_spurious, &mt_stack_ptr_backup);
#if defined(__MDCIRQ_OSIPI_SPECIAL_FLOW__)
/* Mask OSIPI in the first IRQ LISR (because OSIPI is the lowest priority) */
if( processing_irqCnt[vpe_num] == 1 )
{
VPE_IRQ_MASK(VPE_IRQID_OSIPI);
}
#endif
if((kal_get_current_domain() == KAL_DOMAIN_CHRT) && (processing_irqCnt[vpe_num] == 1))
{
// enable and kick WDT
drv_rstctl_set_check_bit((vpeid_e)vpe_num);
drv_rstctl_set_kick_bit((vpeid_e)vpe_num);
}
wp_hook_dispatchLISR_start(vpe_num,irqx_hwcode_non_spurious);
Clear_EXL();
lisr_dispatch_tbl[irqx_hwcode_non_spurious].lisr_handler(irqx_hwcode_non_spurious);
if(Ibit_Status()!=1) //Ibit cannot be disabled after LISR!
{
kal_fatal_error_handler(KAL_ERROR_INTERRUPT_DISABLED_AFTER_LISR_FAILED, (kal_uint32)processing_lisr[vpe_num]);
}
Set_EXL();
wp_hook_dispatchLISR_end(vpe_num,irqx_hwcode_non_spurious);
#if defined(__MDCIRQ_OSIPI_SPECIAL_FLOW__)
/* Unmask OSIPI after the first IRQ LISR */
if( processing_irqCnt[vpe_num] == 1 )
{
VPE_IRQ_UNMASK(VPE_IRQID_OSIPI);
}
#endif
if((kal_get_current_domain() == KAL_DOMAIN_CHRT) && (processing_irqCnt[vpe_num] == 1))
{
// disable WDT
drv_rstctl_clr_check_bit((vpeid_e)vpe_num);
// set wait variable
Idle_Service_Prepare_WAIT();
}
kal_hrt_mt_restore(irqx_hwcode_non_spurious, &mt_stack_ptr_backup);
}
else // spurious IRQ
{
spurious_id[vpe_num][spurious_count[vpe_num]%SPURIOUS_IRQ_LOG_SIZE] = irqx_hwcode;
spurious_count[vpe_num]++;
}
processing_irqx[vpe_num] = processing_irqx_backup;
processing_lisr[vpe_num] = processing_lisr_backup;
processing_irqCnt[vpe_num]--;
SLA_LoggingLISR(0xaaaaaaaa, vpe_num);
/* Use HW code to do IRQ logging */
esl_printf(ESL_SIM_TIME_FLAG|ESL_WALL_TIME_FLAG, "[ISR-%d E]\n", irqx_hwcode);
drv_mdcirq_Restore_VPE_state(vpe_num, ori_vpe_state);
/* Non-Spurious IRQ */
if(!(irqx_hwcode&0x200))
{
/* IRQ idx in SW code view */
if( processing_irqx_backup == IRQ_NOT_LISR_CONTEXT)
MDCIRQ_SYS_endIsr(vpe_num, processing_irqx_backup);
else
MDCIRQ_SYS_endIsr(vpe_num, (kal_uint32)HWIRQCode2SWIRQCode[processing_irqx_backup]);
}
}