Commit 4c6773c3 authored by Daniel Hellstrom's avatar Daniel Hellstrom Committed by David S. Miller

sparc32,leon: add support for extended interrupt controller

The extended IRQ controller gives the LEON 16 more IRQs.

The patch installs a custom handler for the exetended controller
IRQ, where a register is read and the "real" IRQ causing IRQ is
determined.
Signed-off-by: default avatarDaniel Hellstrom <daniel@gaisler.com>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d61a38b2
...@@ -183,7 +183,6 @@ static inline void leon_srmmu_enabletlb(void) ...@@ -183,7 +183,6 @@ static inline void leon_srmmu_enabletlb(void)
/* macro access for leon_readnobuffer_reg() */ /* macro access for leon_readnobuffer_reg() */
#define LEON_BYPASSCACHE_LOAD_VA(x) leon_readnobuffer_reg((unsigned long)(x)) #define LEON_BYPASSCACHE_LOAD_VA(x) leon_readnobuffer_reg((unsigned long)(x))
extern void sparc_leon_eirq_register(int eirq);
extern void leon_init(void); extern void leon_init(void);
extern void leon_switch_mm(void); extern void leon_switch_mm(void);
extern void leon_init_IRQ(void); extern void leon_init_IRQ(void);
...@@ -339,9 +338,9 @@ struct leon2_cacheregs { ...@@ -339,9 +338,9 @@ struct leon2_cacheregs {
#include <linux/interrupt.h> #include <linux/interrupt.h>
struct device_node; struct device_node;
extern int sparc_leon_eirq_get(int eirq, int cpu); extern unsigned int leon_build_device_irq(unsigned int real_irq,
extern irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id); irq_flow_handler_t flow_handler,
extern void sparc_leon_eirq_register(int eirq); const char *name, int do_ack);
extern void leon_clear_clock_irq(void); extern void leon_clear_clock_irq(void);
extern void leon_load_profile_irq(int cpu, unsigned int limit); extern void leon_load_profile_irq(int cpu, unsigned int limit);
extern void leon_init_timers(irq_handler_t counter_fn); extern void leon_init_timers(irq_handler_t counter_fn);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <asm/leon_amba.h> #include <asm/leon_amba.h>
#include <asm/traps.h> #include <asm/traps.h>
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/smp.h>
#include "prom.h" #include "prom.h"
#include "irq.h" #include "irq.h"
...@@ -36,37 +37,51 @@ static DEFINE_SPINLOCK(leon_irq_lock); ...@@ -36,37 +37,51 @@ static DEFINE_SPINLOCK(leon_irq_lock);
unsigned long leon3_gptimer_irq; /* interrupt controller irq number */ unsigned long leon3_gptimer_irq; /* interrupt controller irq number */
unsigned long leon3_gptimer_idx; /* Timer Index (0..6) within Timer Core */ unsigned long leon3_gptimer_idx; /* Timer Index (0..6) within Timer Core */
unsigned int sparc_leon_eirq; unsigned int sparc_leon_eirq;
#define LEON_IMASK ((&leon3_irqctrl_regs->mask[0])) #define LEON_IMASK (&leon3_irqctrl_regs->mask[0])
#define LEON_IACK (&leon3_irqctrl_regs->iclear)
#define LEON_DO_ACK_HW 1
/* Return the IRQ of the pending IRQ on the extended IRQ controller */ /* Return the last ACKed IRQ by the Extended IRQ controller. It has already
int sparc_leon_eirq_get(int eirq, int cpu) * been (automatically) ACKed when the CPU takes the trap.
*/
static inline unsigned int leon_eirq_get(int cpu)
{ {
return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f; return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
} }
irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id) /* Handle one or multiple IRQs from the extended interrupt controller */
static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
{ {
printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n"); unsigned int eirq;
return IRQ_HANDLED; int cpu = hard_smp_processor_id();
eirq = leon_eirq_get(cpu);
if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
generic_handle_irq(irq_map[eirq]->irq);
} }
/* The extended IRQ controller has been found, this function registers it */ /* The extended IRQ controller has been found, this function registers it */
void sparc_leon_eirq_register(int eirq) void leon_eirq_setup(unsigned int eirq)
{ {
int irq; unsigned long mask, oldmask;
unsigned int veirq;
/* Register a "BAD" handler for this interrupt, it should never happen */ if (eirq < 1 || eirq > 0xf) {
irq = request_irq(eirq, sparc_leon_eirq_isr, printk(KERN_ERR "LEON EXT IRQ NUMBER BAD: %d\n", eirq);
(IRQF_DISABLED | SA_STATIC_ALLOC), "extirq", NULL); return;
if (irq) {
printk(KERN_ERR
"sparc_leon_eirq_register: unable to attach IRQ%d\n",
eirq);
} else {
sparc_leon_eirq = eirq;
} }
veirq = leon_build_device_irq(eirq, leon_handle_ext_irq, "extirq", 0);
/*
* Unmask the Extended IRQ, the IRQs routed through the Ext-IRQ
* controller have a mask-bit of their own, so this is safe.
*/
irq_link(veirq);
mask = 1 << eirq;
oldmask = LEON3_BYPASS_LOAD_PA(LEON_IMASK);
LEON3_BYPASS_STORE_PA(LEON_IMASK, (oldmask | mask));
sparc_leon_eirq = eirq;
} }
static inline unsigned long get_irqmask(unsigned int irq) static inline unsigned long get_irqmask(unsigned int irq)
...@@ -119,16 +134,33 @@ static void leon_shutdown_irq(struct irq_data *data) ...@@ -119,16 +134,33 @@ static void leon_shutdown_irq(struct irq_data *data)
irq_unlink(data->irq); irq_unlink(data->irq);
} }
/* Used by external level sensitive IRQ handlers on the LEON: ACK IRQ ctrl */
static void leon_eoi_irq(struct irq_data *data)
{
unsigned long mask = (unsigned long)data->chip_data;
if (mask & LEON_DO_ACK_HW)
LEON3_BYPASS_STORE_PA(LEON_IACK, mask & ~LEON_DO_ACK_HW);
}
static struct irq_chip leon_irq = { static struct irq_chip leon_irq = {
.name = "leon", .name = "leon",
.irq_startup = leon_startup_irq, .irq_startup = leon_startup_irq,
.irq_shutdown = leon_shutdown_irq, .irq_shutdown = leon_shutdown_irq,
.irq_mask = leon_mask_irq, .irq_mask = leon_mask_irq,
.irq_unmask = leon_unmask_irq, .irq_unmask = leon_unmask_irq,
.irq_eoi = leon_eoi_irq,
}; };
static unsigned int leon_build_device_irq(struct platform_device *op, /*
unsigned int real_irq) * Build a LEON IRQ for the edge triggered LEON IRQ controller:
* Edge (normal) IRQ - handle_simple_irq, ack=DONT-CARE, never ack
* Level IRQ (PCI|Level-GPIO) - handle_fasteoi_irq, ack=1, ack after ISR
* Per-CPU Edge - handle_percpu_irq, ack=0
*/
unsigned int leon_build_device_irq(unsigned int real_irq,
irq_flow_handler_t flow_handler,
const char *name, int do_ack)
{ {
unsigned int irq; unsigned int irq;
unsigned long mask; unsigned long mask;
...@@ -142,17 +174,26 @@ static unsigned int leon_build_device_irq(struct platform_device *op, ...@@ -142,17 +174,26 @@ static unsigned int leon_build_device_irq(struct platform_device *op,
if (irq == 0) if (irq == 0)
goto out; goto out;
if (do_ack)
mask |= LEON_DO_ACK_HW;
irq_set_chip_and_handler_name(irq, &leon_irq, irq_set_chip_and_handler_name(irq, &leon_irq,
handle_simple_irq, "edge"); flow_handler, name);
irq_set_chip_data(irq, (void *)mask); irq_set_chip_data(irq, (void *)mask);
out: out:
return irq; return irq;
} }
static unsigned int _leon_build_device_irq(struct platform_device *op,
unsigned int real_irq)
{
return leon_build_device_irq(real_irq, handle_simple_irq, "edge", 0);
}
void __init leon_init_timers(irq_handler_t counter_fn) void __init leon_init_timers(irq_handler_t counter_fn)
{ {
int irq; int irq, eirq;
struct device_node *rootnp, *np, *nnp; struct device_node *rootnp, *np, *nnp;
struct property *pp; struct property *pp;
int len; int len;
...@@ -262,11 +303,17 @@ void __init leon_init_timers(irq_handler_t counter_fn) ...@@ -262,11 +303,17 @@ void __init leon_init_timers(irq_handler_t counter_fn)
icsel = LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->icsel[cpu/8]); icsel = LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->icsel[cpu/8]);
icsel = (icsel >> ((7 - (cpu&0x7)) * 4)) & 0xf; icsel = (icsel >> ((7 - (cpu&0x7)) * 4)) & 0xf;
leon3_irqctrl_regs += icsel; leon3_irqctrl_regs += icsel;
/* Probe extended IRQ controller */
eirq = (LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->mpstatus)
>> 16) & 0xf;
if (eirq != 0)
leon_eirq_setup(eirq);
} else { } else {
goto bad; goto bad;
} }
irq = leon_build_device_irq(NULL, leon3_gptimer_irq + leon3_gptimer_idx); irq = _leon_build_device_irq(NULL, leon3_gptimer_irq+leon3_gptimer_idx);
err = request_irq(irq, counter_fn, IRQF_TIMER, "timer", NULL); err = request_irq(irq, counter_fn, IRQF_TIMER, "timer", NULL);
if (err) { if (err) {
...@@ -394,7 +441,7 @@ void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu) ...@@ -394,7 +441,7 @@ void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
void __init leon_init_IRQ(void) void __init leon_init_IRQ(void)
{ {
sparc_irq_config.init_timers = leon_init_timers; sparc_irq_config.init_timers = leon_init_timers;
sparc_irq_config.build_device_irq = leon_build_device_irq; sparc_irq_config.build_device_irq = _leon_build_device_irq;
BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq, BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq,
BTFIXUPCALL_NORM); BTFIXUPCALL_NORM);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment