2005-04-16 15:20:36 -07:00
/*
2014-01-01 16:35:32 +01:00
* This file is subject to the terms and conditions of the GNU General Public
* License . See the file " COPYING " in the main directory of this archive
* for more details .
*
2005-04-16 15:20:36 -07:00
* Carsten Langgaard , carstenl @ mips . com
* Copyright ( C ) 2000 , 2001 , 2004 MIPS Technologies , Inc .
* Copyright ( C ) 2001 Ralf Baechle
2013-10-30 15:52:10 -05:00
* Copyright ( C ) 2013 Imagination Technologies Ltd .
2005-04-16 15:20:36 -07:00
*
* Routines for generic manipulation of the interrupts found on the MIPS
2014-01-01 16:35:32 +01:00
* Malta board . The interrupt controller is located in the South Bridge
* a PIIX4 device with two internal 82 C95 interrupt controllers .
2005-04-16 15:20:36 -07:00
*/
# include <linux/init.h>
# include <linux/irq.h>
# include <linux/sched.h>
2009-06-19 14:05:26 +01:00
# include <linux/smp.h>
2005-04-16 15:20:36 -07:00
# include <linux/interrupt.h>
2008-01-24 19:52:49 +03:00
# include <linux/io.h>
2014-10-20 12:03:53 -07:00
# include <linux/irqchip/mips-gic.h>
2005-04-16 15:20:36 -07:00
# include <linux/kernel_stat.h>
2007-02-05 04:42:11 +02:00
# include <linux/kernel.h>
2005-04-16 15:20:36 -07:00
# include <linux/random.h>
2008-04-28 17:14:26 +01:00
# include <asm/traps.h>
2005-04-16 15:20:36 -07:00
# include <asm/i8259.h>
2005-07-14 15:57:16 +00:00
# include <asm/irq_cpu.h>
2006-10-15 09:17:43 +01:00
# include <asm/irq_regs.h>
2014-01-15 10:31:54 +00:00
# include <asm/mips-cm.h>
2005-04-16 15:20:36 -07:00
# include <asm/mips-boards/malta.h>
# include <asm/mips-boards/maltaint.h>
# include <asm/gt64120.h>
# include <asm/mips-boards/generic.h>
# include <asm/mips-boards/msc01_pci.h>
2005-07-14 15:57:16 +00:00
# include <asm/msc01_ic.h>
2012-03-28 18:30:02 +01:00
# include <asm/setup.h>
2013-10-30 15:52:10 -05:00
# include <asm/rtlx.h>
2008-04-28 17:14:26 +01:00
2014-10-20 12:03:51 -07:00
static void __iomem * _msc01_biu_base ;
2005-04-16 15:20:36 -07:00
2010-02-27 12:53:32 +01:00
static DEFINE_RAW_SPINLOCK ( mips_irq_lock ) ;
2005-04-16 15:20:36 -07:00
static inline int mips_pcibios_iack ( void )
{
int irq ;
/*
* Determine highest priority pending interrupt by performing
* a PCI Interrupt Acknowledge cycle .
*/
2007-04-27 15:58:41 +01:00
switch ( mips_revision_sconid ) {
case MIPS_REVISION_SCON_SOCIT :
case MIPS_REVISION_SCON_ROCIT :
case MIPS_REVISION_SCON_SOCITSC :
case MIPS_REVISION_SCON_SOCITSCP :
2008-01-24 19:52:45 +03:00
MSC_READ ( MSC01_PCI_IACK , irq ) ;
2005-04-16 15:20:36 -07:00
irq & = 0xff ;
break ;
2007-04-27 15:58:41 +01:00
case MIPS_REVISION_SCON_GT64120 :
2005-04-16 15:20:36 -07:00
irq = GT_READ ( GT_PCI0_IACK_OFS ) ;
irq & = 0xff ;
break ;
2007-04-27 15:58:41 +01:00
case MIPS_REVISION_SCON_BONITO :
2005-04-16 15:20:36 -07:00
/* The following will generate a PCI IACK cycle on the
* Bonito controller . It ' s a little bit kludgy , but it
* was the easiest way to implement it in hardware at
* the given time .
*/
BONITO_PCIMAP_CFG = 0x20000 ;
/* Flush Bonito register block */
2011-03-29 11:48:22 +02:00
( void ) BONITO_PCIMAP_CFG ;
2013-01-22 12:59:30 +01:00
iob ( ) ; /* sync */
2005-04-16 15:20:36 -07:00
2009-07-10 01:53:54 -07:00
irq = __raw_readl ( ( u32 * ) _pcictrl_bonito_pcicfg ) ;
2013-01-22 12:59:30 +01:00
iob ( ) ; /* sync */
2005-04-16 15:20:36 -07:00
irq & = 0xff ;
BONITO_PCIMAP_CFG = 0 ;
break ;
default :
2014-01-01 16:35:32 +01:00
pr_emerg ( " Unknown system controller. \n " ) ;
2005-04-16 15:20:36 -07:00
return - 1 ;
}
return irq ;
}
2005-07-14 15:57:16 +00:00
static inline int get_int ( void )
2005-04-16 15:20:36 -07:00
{
unsigned long flags ;
2005-07-14 15:57:16 +00:00
int irq ;
2010-02-27 12:53:32 +01:00
raw_spin_lock_irqsave ( & mips_irq_lock , flags ) ;
2005-04-16 15:20:36 -07:00
2005-07-14 15:57:16 +00:00
irq = mips_pcibios_iack ( ) ;
2005-04-16 15:20:36 -07:00
/*
2005-08-16 15:44:06 +00:00
* The only way we can decide if an interrupt is spurious
* is by checking the 8259 registers . This needs a spinlock
* on an SMP system , so leave it up to the generic code . . .
2005-04-16 15:20:36 -07:00
*/
2010-02-27 12:53:32 +01:00
raw_spin_unlock_irqrestore ( & mips_irq_lock , flags ) ;
2005-04-16 15:20:36 -07:00
2005-07-14 15:57:16 +00:00
return irq ;
2005-04-16 15:20:36 -07:00
}
2006-10-07 19:44:33 +01:00
static void malta_hw0_irqdispatch ( void )
2005-04-16 15:20:36 -07:00
{
int irq ;
2005-07-14 15:57:16 +00:00
irq = get_int ( ) ;
2006-04-05 09:45:45 +01:00
if ( irq < 0 ) {
2008-01-24 19:52:54 +03:00
/* interrupt has already been cleared */
return ;
2006-04-05 09:45:45 +01:00
}
2005-04-16 15:20:36 -07:00
2006-10-07 19:44:33 +01:00
do_IRQ ( MALTA_INT_BASE + irq ) ;
2013-10-30 15:52:10 -05:00
2014-02-28 10:23:01 -08:00
# ifdef CONFIG_MIPS_VPE_APSP_API_MT
2013-10-30 15:52:10 -05:00
if ( aprp_hook )
aprp_hook ( ) ;
# endif
2005-04-16 15:20:36 -07:00
}
2014-09-18 14:47:24 -07:00
static irqreturn_t i8259_handler ( int irq , void * dev_id )
2008-04-28 17:14:26 +01:00
{
2014-09-18 14:47:24 -07:00
malta_hw0_irqdispatch ( ) ;
return IRQ_HANDLED ;
2008-04-28 17:14:26 +01:00
}
2006-10-07 19:44:33 +01:00
static void corehi_irqdispatch ( void )
2005-04-16 15:20:36 -07:00
{
2006-10-07 19:44:33 +01:00
unsigned int intedge , intsteer , pcicmd , pcibadaddr ;
2008-01-24 19:52:45 +03:00
unsigned int pcimstat , intisr , inten , intpol ;
2007-10-11 23:46:15 +01:00
unsigned int intrcause , datalo , datahi ;
2006-10-15 09:17:43 +01:00
struct pt_regs * regs = get_irq_regs ( ) ;
2005-04-16 15:20:36 -07:00
2014-01-01 16:35:32 +01:00
pr_emerg ( " CoreHI interrupt, shouldn't happen, we die here! \n " ) ;
pr_emerg ( " epc : %08lx \n Status: %08lx \n "
" Cause : %08lx \n badVaddr : %08lx \n " ,
regs - > cp0_epc , regs - > cp0_status ,
regs - > cp0_cause , regs - > cp0_badvaddr ) ;
2005-07-14 15:57:16 +00:00
/* Read all the registers and then print them as there is a
problem with interspersed printk ' s upsetting the Bonito controller .
Do it for the others too .
*/
2007-04-27 15:58:41 +01:00
switch ( mips_revision_sconid ) {
2008-01-24 19:52:45 +03:00
case MIPS_REVISION_SCON_SOCIT :
2007-04-27 15:58:41 +01:00
case MIPS_REVISION_SCON_ROCIT :
case MIPS_REVISION_SCON_SOCITSC :
case MIPS_REVISION_SCON_SOCITSCP :
2008-01-24 19:52:45 +03:00
ll_msc_irq ( ) ;
break ;
case MIPS_REVISION_SCON_GT64120 :
intrcause = GT_READ ( GT_INTRCAUSE_OFS ) ;
datalo = GT_READ ( GT_CPUERR_ADDRLO_OFS ) ;
datahi = GT_READ ( GT_CPUERR_ADDRHI_OFS ) ;
2014-01-01 16:35:32 +01:00
pr_emerg ( " GT_INTRCAUSE = %08x \n " , intrcause ) ;
pr_emerg ( " GT_CPUERR_ADDR = %02x%08x \n " ,
2008-01-24 19:52:42 +03:00
datahi , datalo ) ;
2008-01-24 19:52:45 +03:00
break ;
case MIPS_REVISION_SCON_BONITO :
pcibadaddr = BONITO_PCIBADADDR ;
pcimstat = BONITO_PCIMSTAT ;
intisr = BONITO_INTISR ;
inten = BONITO_INTEN ;
intpol = BONITO_INTPOL ;
intedge = BONITO_INTEDGE ;
intsteer = BONITO_INTSTEER ;
pcicmd = BONITO_PCICMD ;
2014-01-01 16:35:32 +01:00
pr_emerg ( " BONITO_INTISR = %08x \n " , intisr ) ;
pr_emerg ( " BONITO_INTEN = %08x \n " , inten ) ;
pr_emerg ( " BONITO_INTPOL = %08x \n " , intpol ) ;
pr_emerg ( " BONITO_INTEDGE = %08x \n " , intedge ) ;
pr_emerg ( " BONITO_INTSTEER = %08x \n " , intsteer ) ;
pr_emerg ( " BONITO_PCICMD = %08x \n " , pcicmd ) ;
pr_emerg ( " BONITO_PCIBADADDR = %08x \n " , pcibadaddr ) ;
pr_emerg ( " BONITO_PCIMSTAT = %08x \n " , pcimstat ) ;
2008-01-24 19:52:45 +03:00
break ;
}
2005-04-16 15:20:36 -07:00
2008-01-24 19:52:45 +03:00
die ( " CoreHi interrupt " , regs ) ;
2005-04-16 15:20:36 -07:00
}
2014-09-18 14:47:24 -07:00
static irqreturn_t corehi_handler ( int irq , void * dev_id )
{
corehi_irqdispatch ( ) ;
return IRQ_HANDLED ;
}
2008-04-28 17:14:26 +01:00
# ifdef CONFIG_MIPS_MT_SMP
# define MIPS_CPU_IPI_RESCHED_IRQ 0 /* SW int 0 for resched */
# define C_RESCHED C_SW0
# define MIPS_CPU_IPI_CALL_IRQ 1 /* SW int 1 for resched */
# define C_CALL C_SW1
static int cpu_ipi_resched_irq , cpu_ipi_call_irq ;
static void ipi_resched_dispatch ( void )
{
do_IRQ ( MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ ) ;
}
static void ipi_call_dispatch ( void )
{
do_IRQ ( MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ ) ;
}
static irqreturn_t ipi_resched_interrupt ( int irq , void * dev_id )
{
2014-02-28 10:23:01 -08:00
# ifdef CONFIG_MIPS_VPE_APSP_API_CMP
2013-10-30 15:52:10 -05:00
if ( aprp_hook )
aprp_hook ( ) ;
# endif
2011-04-05 17:23:39 +02:00
scheduler_ipi ( ) ;
2008-04-28 17:14:26 +01:00
return IRQ_HANDLED ;
}
static irqreturn_t ipi_call_interrupt ( int irq , void * dev_id )
{
2015-07-24 16:57:49 +01:00
generic_smp_call_function_interrupt ( ) ;
2008-04-28 17:14:26 +01:00
return IRQ_HANDLED ;
}
static struct irqaction irq_resched = {
. handler = ipi_resched_interrupt ,
2011-11-22 14:38:03 +00:00
. flags = IRQF_PERCPU ,
2008-04-28 17:14:26 +01:00
. name = " IPI_resched "
} ;
static struct irqaction irq_call = {
. handler = ipi_call_interrupt ,
2011-11-22 14:38:03 +00:00
. flags = IRQF_PERCPU ,
2008-04-28 17:14:26 +01:00
. name = " IPI_call "
} ;
2014-09-18 14:47:24 -07:00
# endif /* CONFIG_MIPS_MT_SMP */
2008-04-28 17:14:26 +01:00
2005-07-14 15:57:16 +00:00
static struct irqaction i8259irq = {
2014-09-18 14:47:24 -07:00
. handler = i8259_handler ,
2011-07-23 12:41:24 +00:00
. name = " XT-PIC cascade " ,
. flags = IRQF_NO_THREAD ,
2005-07-14 15:57:16 +00:00
} ;
static struct irqaction corehi_irqaction = {
2014-09-18 14:47:24 -07:00
. handler = corehi_handler ,
2011-07-23 12:41:24 +00:00
. name = " CoreHi " ,
. flags = IRQF_NO_THREAD ,
2005-07-14 15:57:16 +00:00
} ;
2014-01-01 16:35:32 +01:00
static msc_irqmap_t msc_irqmap [ ] __initdata = {
2005-07-14 15:57:16 +00:00
{ MSC01C_INT_TMR , MSC01_IRQ_EDGE , 0 } ,
{ MSC01C_INT_PCI , MSC01_IRQ_LEVEL , 0 } ,
} ;
2014-01-01 16:35:32 +01:00
static int msc_nr_irqs __initdata = ARRAY_SIZE ( msc_irqmap ) ;
2005-07-14 15:57:16 +00:00
2014-01-01 16:35:32 +01:00
static msc_irqmap_t msc_eicirqmap [ ] __initdata = {
2005-07-14 15:57:16 +00:00
{ MSC01E_INT_SW0 , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_SW1 , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_I8259A , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_SMI , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_COREHI , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_CORELO , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_TMR , MSC01_IRQ_EDGE , 0 } ,
{ MSC01E_INT_PCI , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_PERFCTR , MSC01_IRQ_LEVEL , 0 } ,
{ MSC01E_INT_CPUCTR , MSC01_IRQ_LEVEL , 0 }
} ;
2008-04-28 17:14:26 +01:00
2014-01-01 16:35:32 +01:00
static int msc_nr_eicirqs __initdata = ARRAY_SIZE ( msc_eicirqmap ) ;
2005-07-14 15:57:16 +00:00
2009-07-10 01:54:09 -07:00
void __init arch_init_ipiirq ( int irq , struct irqaction * action )
{
setup_irq ( irq , action ) ;
2011-03-27 15:19:28 +02:00
irq_set_handler ( irq , handle_percpu_irq ) ;
2009-07-10 01:54:09 -07:00
}
2005-04-16 15:20:36 -07:00
void __init arch_init_irq ( void )
{
2014-09-18 14:47:24 -07:00
int corehi_irq , i8259_irq ;
2005-04-16 15:20:36 -07:00
init_i8259_irqs ( ) ;
2005-07-14 15:57:16 +00:00
if ( ! cpu_has_veic )
2007-01-08 02:14:29 +09:00
mips_cpu_irq_init ( ) ;
2005-07-14 15:57:16 +00:00
2014-01-15 10:31:54 +00:00
if ( mips_cm_present ( ) ) {
write_gcr_gic_base ( GIC_BASE_ADDR | CM_GCR_GIC_BASE_GICEN_MSK ) ;
2008-04-28 17:14:26 +01:00
gic_present = 1 ;
} else {
2009-07-10 01:54:25 -07:00
if ( mips_revision_sconid = = MIPS_REVISION_SCON_ROCIT ) {
2014-10-20 12:03:51 -07:00
_msc01_biu_base = ioremap_nocache ( MSC01_BIU_REG_BASE ,
2009-07-10 01:54:25 -07:00
MSC01_BIU_ADDRSPACE_SZ ) ;
2014-10-20 12:03:51 -07:00
gic_present =
( __raw_readl ( _msc01_biu_base + MSC01_SC_CFG_OFS ) &
MSC01_SC_CFG_GICPRES_MSK ) > >
MSC01_SC_CFG_GICPRES_SHF ;
2009-07-10 01:54:25 -07:00
}
2008-04-28 17:14:26 +01:00
}
if ( gic_present )
2009-07-10 01:54:09 -07:00
pr_debug ( " GIC present \n " ) ;
2008-04-28 17:14:26 +01:00
2008-01-24 19:52:45 +03:00
switch ( mips_revision_sconid ) {
case MIPS_REVISION_SCON_SOCIT :
case MIPS_REVISION_SCON_ROCIT :
2007-05-08 14:05:39 +01:00
if ( cpu_has_veic )
2008-01-24 19:52:47 +03:00
init_msc_irqs ( MIPS_MSC01_IC_REG_BASE ,
MSC01E_INT_BASE , msc_eicirqmap ,
msc_nr_eicirqs ) ;
2007-05-08 14:05:39 +01:00
else
2008-01-24 19:52:47 +03:00
init_msc_irqs ( MIPS_MSC01_IC_REG_BASE ,
MSC01C_INT_BASE , msc_irqmap ,
msc_nr_irqs ) ;
2007-05-08 14:05:39 +01:00
break ;
2008-01-24 19:52:45 +03:00
case MIPS_REVISION_SCON_SOCITSC :
case MIPS_REVISION_SCON_SOCITSCP :
2005-07-14 15:57:16 +00:00
if ( cpu_has_veic )
2008-01-24 19:52:47 +03:00
init_msc_irqs ( MIPS_SOCITSC_IC_REG_BASE ,
MSC01E_INT_BASE , msc_eicirqmap ,
msc_nr_eicirqs ) ;
2005-07-14 15:57:16 +00:00
else
2008-01-24 19:52:47 +03:00
init_msc_irqs ( MIPS_SOCITSC_IC_REG_BASE ,
MSC01C_INT_BASE , msc_irqmap ,
msc_nr_irqs ) ;
2005-07-14 15:57:16 +00:00
}
2008-04-28 17:14:26 +01:00
if ( gic_present ) {
int i ;
2014-09-18 14:47:24 -07:00
gic_init ( GIC_BASE_ADDR , GIC_ADDRSPACE_SZ , MIPSCPU_INT_GIC ,
MIPS_GIC_IRQ_BASE ) ;
2014-01-15 10:31:54 +00:00
if ( ! mips_cm_present ( ) ) {
2008-04-28 17:14:26 +01:00
/* Enable the GIC */
2014-10-20 12:03:51 -07:00
i = __raw_readl ( _msc01_biu_base + MSC01_SC_CFG_OFS ) ;
__raw_writel ( i | ( 0x1 < < MSC01_SC_CFG_GICENA_SHF ) ,
_msc01_biu_base + MSC01_SC_CFG_OFS ) ;
2008-04-28 17:14:26 +01:00
pr_debug ( " GIC Enabled \n " ) ;
}
2014-09-18 14:47:24 -07:00
i8259_irq = MIPS_GIC_IRQ_BASE + GIC_INT_I8259A ;
corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI ;
2008-04-28 17:14:26 +01:00
} else {
2009-07-10 01:54:09 -07:00
# if defined(CONFIG_MIPS_MT_SMP)
2008-04-28 17:14:26 +01:00
/* set up ipi interrupts */
if ( cpu_has_veic ) {
set_vi_handler ( MSC01E_INT_SW0 , ipi_resched_dispatch ) ;
set_vi_handler ( MSC01E_INT_SW1 , ipi_call_dispatch ) ;
cpu_ipi_resched_irq = MSC01E_INT_SW0 ;
cpu_ipi_call_irq = MSC01E_INT_SW1 ;
} else {
2014-01-01 16:35:32 +01:00
cpu_ipi_resched_irq = MIPS_CPU_IRQ_BASE +
MIPS_CPU_IPI_RESCHED_IRQ ;
cpu_ipi_call_irq = MIPS_CPU_IRQ_BASE +
MIPS_CPU_IPI_CALL_IRQ ;
2008-04-28 17:14:26 +01:00
}
2009-07-10 01:54:09 -07:00
arch_init_ipiirq ( cpu_ipi_resched_irq , & irq_resched ) ;
arch_init_ipiirq ( cpu_ipi_call_irq , & irq_call ) ;
2008-04-28 17:14:26 +01:00
# endif
2014-09-18 14:47:24 -07:00
if ( cpu_has_veic ) {
set_vi_handler ( MSC01E_INT_I8259A ,
malta_hw0_irqdispatch ) ;
set_vi_handler ( MSC01E_INT_COREHI ,
corehi_irqdispatch ) ;
i8259_irq = MSC01E_INT_BASE + MSC01E_INT_I8259A ;
corehi_irq = MSC01E_INT_BASE + MSC01E_INT_COREHI ;
} else {
i8259_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_I8259A ;
corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI ;
}
2009-07-10 01:54:09 -07:00
}
2014-09-18 14:47:24 -07:00
setup_irq ( i8259_irq , & i8259irq ) ;
setup_irq ( corehi_irq , & corehi_irqaction ) ;
2008-04-28 17:14:26 +01:00
}
void malta_be_init ( void )
{
2014-01-01 16:35:32 +01:00
/* Could change CM error mask register. */
2008-04-28 17:14:26 +01:00
}
int malta_be_handler ( struct pt_regs * regs , int is_fixup )
{
/* This duplicates the handling in do_be which seems wrong */
int retval = is_fixup ? MIPS_BE_FIXUP : MIPS_BE_FATAL ;
2015-07-09 10:40:47 +01:00
mips_cm_error_report ( ) ;
2008-04-28 17:14:26 +01:00
return retval ;
2005-04-16 15:20:36 -07:00
}