2005-04-17 02:20:36 +04:00
/*
2014-01-01 19:35:32 +04: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-17 02:20:36 +04:00
* Carsten Langgaard , carstenl @ mips . com
* Copyright ( C ) 2000 , 2001 , 2004 MIPS Technologies , Inc .
* Copyright ( C ) 2001 Ralf Baechle
2013-10-31 00:52:10 +04:00
* Copyright ( C ) 2013 Imagination Technologies Ltd .
2005-04-17 02:20:36 +04:00
*
* Routines for generic manipulation of the interrupts found on the MIPS
2014-01-01 19:35:32 +04:00
* Malta board . The interrupt controller is located in the South Bridge
* a PIIX4 device with two internal 82 C95 interrupt controllers .
2005-04-17 02:20:36 +04:00
*/
# include <linux/init.h>
# include <linux/irq.h>
2016-09-20 00:21:23 +03:00
# include <linux/irqchip.h>
2005-04-17 02:20:36 +04:00
# include <linux/sched.h>
2009-06-19 17:05:26 +04:00
# include <linux/smp.h>
2005-04-17 02:20:36 +04:00
# include <linux/interrupt.h>
2008-01-24 19:52:49 +03:00
# include <linux/io.h>
2016-09-20 00:21:23 +03:00
# include <linux/of_irq.h>
2005-04-17 02:20:36 +04:00
# include <linux/kernel_stat.h>
2007-02-05 05:42:11 +03:00
# include <linux/kernel.h>
2005-04-17 02:20:36 +04:00
# include <linux/random.h>
2008-04-28 20:14:26 +04:00
# include <asm/traps.h>
2005-04-17 02:20:36 +04:00
# include <asm/i8259.h>
2005-07-14 19:57:16 +04:00
# include <asm/irq_cpu.h>
2006-10-15 12:17:43 +04:00
# include <asm/irq_regs.h>
2005-04-17 02:20:36 +04:00
# include <asm/mips-boards/malta.h>
# include <asm/mips-boards/maltaint.h>
2017-08-13 07:36:34 +03:00
# include <asm/mips-cps.h>
2005-04-17 02:20:36 +04:00
# include <asm/gt64120.h>
# include <asm/mips-boards/generic.h>
# include <asm/mips-boards/msc01_pci.h>
2005-07-14 19:57:16 +04:00
# include <asm/msc01_ic.h>
2012-03-28 21:30:02 +04:00
# include <asm/setup.h>
2013-10-31 00:52:10 +04:00
# include <asm/rtlx.h>
2008-04-28 20:14:26 +04:00
2005-04-17 02:20:36 +04: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 18:58:41 +04: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-17 02:20:36 +04:00
irq & = 0xff ;
break ;
2007-04-27 18:58:41 +04:00
case MIPS_REVISION_SCON_GT64120 :
2005-04-17 02:20:36 +04:00
irq = GT_READ ( GT_PCI0_IACK_OFS ) ;
irq & = 0xff ;
break ;
2007-04-27 18:58:41 +04:00
case MIPS_REVISION_SCON_BONITO :
2005-04-17 02:20:36 +04: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 13:48:22 +04:00
( void ) BONITO_PCIMAP_CFG ;
2013-01-22 15:59:30 +04:00
iob ( ) ; /* sync */
2005-04-17 02:20:36 +04:00
2009-07-10 12:53:54 +04:00
irq = __raw_readl ( ( u32 * ) _pcictrl_bonito_pcicfg ) ;
2013-01-22 15:59:30 +04:00
iob ( ) ; /* sync */
2005-04-17 02:20:36 +04:00
irq & = 0xff ;
BONITO_PCIMAP_CFG = 0 ;
break ;
default :
2014-01-01 19:35:32 +04:00
pr_emerg ( " Unknown system controller. \n " ) ;
2005-04-17 02:20:36 +04:00
return - 1 ;
}
return irq ;
}
2006-10-07 22:44:33 +04:00
static void corehi_irqdispatch ( void )
2005-04-17 02:20:36 +04:00
{
2006-10-07 22:44:33 +04:00
unsigned int intedge , intsteer , pcicmd , pcibadaddr ;
2008-01-24 19:52:45 +03:00
unsigned int pcimstat , intisr , inten , intpol ;
2007-10-12 02:46:15 +04:00
unsigned int intrcause , datalo , datahi ;
2006-10-15 12:17:43 +04:00
struct pt_regs * regs = get_irq_regs ( ) ;
2005-04-17 02:20:36 +04:00
2014-01-01 19:35:32 +04: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 19:57:16 +04: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 18:58:41 +04:00
switch ( mips_revision_sconid ) {
2008-01-24 19:52:45 +03:00
case MIPS_REVISION_SCON_SOCIT :
2007-04-27 18:58:41 +04: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 19:35:32 +04: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 19:35:32 +04: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-17 02:20:36 +04:00
2008-01-24 19:52:45 +03:00
die ( " CoreHi interrupt " , regs ) ;
2005-04-17 02:20:36 +04:00
}
2014-09-19 01:47:24 +04:00
static irqreturn_t corehi_handler ( int irq , void * dev_id )
{
corehi_irqdispatch ( ) ;
return IRQ_HANDLED ;
}
2014-01-01 19:35:32 +04:00
static msc_irqmap_t msc_irqmap [ ] __initdata = {
2005-07-14 19:57:16 +04:00
{ MSC01C_INT_TMR , MSC01_IRQ_EDGE , 0 } ,
{ MSC01C_INT_PCI , MSC01_IRQ_LEVEL , 0 } ,
} ;
2014-01-01 19:35:32 +04:00
static int msc_nr_irqs __initdata = ARRAY_SIZE ( msc_irqmap ) ;
2005-07-14 19:57:16 +04:00
2014-01-01 19:35:32 +04:00
static msc_irqmap_t msc_eicirqmap [ ] __initdata = {
2005-07-14 19:57:16 +04: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 20:14:26 +04:00
2014-01-01 19:35:32 +04:00
static int msc_nr_eicirqs __initdata = ARRAY_SIZE ( msc_eicirqmap ) ;
2005-07-14 19:57:16 +04:00
2005-04-17 02:20:36 +04:00
void __init arch_init_irq ( void )
{
2016-09-20 00:21:23 +03:00
int corehi_irq ;
2014-09-19 01:47:24 +04:00
2017-04-06 18:58:09 +03:00
/*
* Preallocate the i8259 ' s expected virq ' s here . Since irqchip_init ( )
* will probe the irqchips in hierarchial order , i8259 is probed last .
* If anything allocates a virq before the i8259 is probed , it will
* be given one of the i8259 ' s expected range and consequently setup
* of the i8259 will fail .
*/
WARN ( irq_alloc_descs ( I8259A_IRQ_BASE , I8259A_IRQ_BASE ,
16 , numa_node_id ( ) ) < 0 ,
" Cannot reserve i8259 virqs at IRQ%d \n " , I8259A_IRQ_BASE ) ;
2016-09-20 00:21:23 +03:00
i8259_set_poll ( mips_pcibios_iack ) ;
irqchip_init ( ) ;
2008-04-28 20:14:26 +04: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 17:05:39 +04: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 17:05:39 +04: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 17:05:39 +04:00
break ;
2008-01-24 19:52:45 +03:00
case MIPS_REVISION_SCON_SOCITSC :
case MIPS_REVISION_SCON_SOCITSCP :
2005-07-14 19:57:16 +04: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 19:57:16 +04: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 19:57:16 +04:00
}
2017-08-13 07:36:34 +03:00
if ( mips_gic_present ( ) ) {
2014-09-19 01:47:24 +04:00
corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI ;
2017-03-30 22:06:12 +03:00
} else if ( cpu_has_veic ) {
set_vi_handler ( MSC01E_INT_COREHI , corehi_irqdispatch ) ;
corehi_irq = MSC01E_INT_BASE + MSC01E_INT_COREHI ;
2008-04-28 20:14:26 +04:00
} else {
2017-03-30 22:06:12 +03:00
corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI ;
2009-07-10 12:54:09 +04:00
}
2014-09-19 01:47:24 +04:00
2020-03-05 14:57:53 +03:00
if ( request_irq ( corehi_irq , corehi_handler , IRQF_NO_THREAD , " CoreHi " ,
NULL ) )
pr_err ( " Failed to request irq %d (CoreHi) \n " , corehi_irq ) ;
2008-04-28 20:14:26 +04:00
}