Merge branches 'tracing/ftrace', 'tracing/syscalls' and 'linus' into tracing/core
[linux-2.6.git] / arch / parisc / kernel / irq.c
index 197936d..2b5f591 100644 (file)
@@ -22,7 +22,6 @@
  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 #include <linux/bitops.h>
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -36,8 +35,8 @@
 
 #undef PARISC_IRQ_CR16_COUNTS
 
-extern irqreturn_t timer_interrupt(int, void *, struct pt_regs *);
-extern irqreturn_t ipi_interrupt(int, void *, struct pt_regs *);
+extern irqreturn_t timer_interrupt(int, void *);
+extern irqreturn_t ipi_interrupt(int, void *);
 
 #define EIEM_MASK(irq)       (1UL<<(CPU_IRQ_MAX - irq))
 
@@ -46,6 +45,13 @@ extern irqreturn_t ipi_interrupt(int, void *, struct pt_regs *);
 */
 static volatile unsigned long cpu_eiem = 0;
 
+/*
+** local ACK bitmap ... habitually set to 1, but reset to zero
+** between ->ack() and ->end() of the interrupt to prevent
+** re-interruption of a processing interrupt.
+*/
+static DEFINE_PER_CPU(unsigned long, local_ack_eiem) = ~0UL;
+
 static void cpu_disable_irq(unsigned int irq)
 {
        unsigned long eirr_bit = EIEM_MASK(irq);
@@ -63,13 +69,6 @@ static void cpu_enable_irq(unsigned int irq)
 
        cpu_eiem |= eirr_bit;
 
-       /* FIXME: while our interrupts aren't nested, we cannot reset
-        * the eiem mask if we're already in an interrupt.  Once we
-        * implement nested interrupts, this can go away
-        */
-       if (!in_interrupt())
-               set_eiem(cpu_eiem);
-
        /* This is just a simple NOP IPI.  But what it does is cause
         * all the other CPUs to do a set_eiem(cpu_eiem) at the end
         * of the interrupt handler */
@@ -85,32 +84,61 @@ static unsigned int cpu_startup_irq(unsigned int irq)
 void no_ack_irq(unsigned int irq) { }
 void no_end_irq(unsigned int irq) { }
 
+void cpu_ack_irq(unsigned int irq)
+{
+       unsigned long mask = EIEM_MASK(irq);
+       int cpu = smp_processor_id();
+
+       /* Clear in EIEM so we can no longer process */
+       per_cpu(local_ack_eiem, cpu) &= ~mask;
+
+       /* disable the interrupt */
+       set_eiem(cpu_eiem & per_cpu(local_ack_eiem, cpu));
+
+       /* and now ack it */
+       mtctl(mask, 23);
+}
+
+void cpu_end_irq(unsigned int irq)
+{
+       unsigned long mask = EIEM_MASK(irq);
+       int cpu = smp_processor_id();
+
+       /* set it in the eiems---it's no longer in process */
+       per_cpu(local_ack_eiem, cpu) |= mask;
+
+       /* enable the interrupt */
+       set_eiem(cpu_eiem & per_cpu(local_ack_eiem, cpu));
+}
+
 #ifdef CONFIG_SMP
-int cpu_check_affinity(unsigned int irq, cpumask_t *dest)
+int cpu_check_affinity(unsigned int irq, const struct cpumask *dest)
 {
        int cpu_dest;
 
        /* timer and ipi have to always be received on all CPUs */
-       if (irq == TIMER_IRQ || irq == IPI_IRQ) {
+       if (CHECK_IRQ_PER_CPU(irq)) {
                /* Bad linux design decision.  The mask has already
                 * been set; we must reset it */
-               irq_affinity[irq] = CPU_MASK_ALL;
+               cpumask_setall(&irq_desc[irq].affinity);
                return -EINVAL;
        }
 
        /* whatever mask they set, we just allow one CPU */
        cpu_dest = first_cpu(*dest);
-       *dest = cpumask_of_cpu(cpu_dest);
 
-       return 0;
+       return cpu_dest;
 }
 
-static void cpu_set_affinity_irq(unsigned int irq, cpumask_t dest)
+static void cpu_set_affinity_irq(unsigned int irq, const struct cpumask *dest)
 {
-       if (cpu_check_affinity(irq, &dest))
+       int cpu_dest;
+
+       cpu_dest = cpu_check_affinity(irq, dest);
+       if (cpu_dest < 0)
                return;
 
-       irq_affinity[irq] = dest;
+       cpumask_copy(&irq_desc[irq].affinity, dest);
 }
 #endif
 
@@ -120,11 +148,15 @@ static struct hw_interrupt_type cpu_interrupt_type = {
        .shutdown       = cpu_disable_irq,
        .enable         = cpu_enable_irq,
        .disable        = cpu_disable_irq,
-       .ack            = no_ack_irq,
-       .end            = no_end_irq,
+       .ack            = cpu_ack_irq,
+       .end            = cpu_end_irq,
 #ifdef CONFIG_SMP
        .set_affinity   = cpu_set_affinity_irq,
 #endif
+       /* XXX: Needs to be written.  We managed without it so far, but
+        * we really ought to write it.
+        */
+       .retrigger      = NULL,
 };
 
 int show_interrupts(struct seq_file *p, void *v)
@@ -158,7 +190,7 @@ int show_interrupts(struct seq_file *p, void *v)
                seq_printf(p, "%10u ", kstat_irqs(i));
 #endif
 
-               seq_printf(p, " %14s", irq_desc[i].handler->typename);
+               seq_printf(p, " %14s", irq_desc[i].chip->typename);
 #ifndef PARISC_IRQ_CR16_COUNTS
                seq_printf(p, "  %s", action->name);
 
@@ -206,16 +238,16 @@ int show_interrupts(struct seq_file *p, void *v)
 ** Then use that to get the Transaction address and data.
 */
 
-int cpu_claim_irq(unsigned int irq, struct hw_interrupt_type *type, void *data)
+int cpu_claim_irq(unsigned int irq, struct irq_chip *type, void *data)
 {
        if (irq_desc[irq].action)
                return -EBUSY;
-       if (irq_desc[irq].handler != &cpu_interrupt_type)
+       if (irq_desc[irq].chip != &cpu_interrupt_type)
                return -EBUSY;
 
        if (type) {
-               irq_desc[irq].handler = type;
-               irq_desc[irq].handler_data = data;
+               irq_desc[irq].chip = type;
+               irq_desc[irq].chip_data = data;
                cpu_interrupt_type.enable(irq);
        }
        return 0;
@@ -265,10 +297,10 @@ int txn_alloc_irq(unsigned int bits_wide)
 unsigned long txn_affinity_addr(unsigned int irq, int cpu)
 {
 #ifdef CONFIG_SMP
-       irq_affinity[irq] = cpumask_of_cpu(cpu);
+       cpumask_copy(&irq_desc[irq].affinity, cpumask_of(cpu));
 #endif
 
-       return cpu_data[cpu].txn_addr;
+       return per_cpu(cpu_data, cpu).txn_addr;
 }
 
 
@@ -279,8 +311,9 @@ unsigned long txn_alloc_addr(unsigned int virt_irq)
        next_cpu++; /* assign to "next" CPU we want this bugger on */
 
        /* validate entry */
-       while ((next_cpu < NR_CPUS) && (!cpu_data[next_cpu].txn_addr || 
-               !cpu_online(next_cpu)))
+       while ((next_cpu < NR_CPUS) &&
+               (!per_cpu(cpu_data, next_cpu).txn_addr ||
+                !cpu_online(next_cpu)))
                next_cpu++;
 
        if (next_cpu >= NR_CPUS) 
@@ -295,82 +328,67 @@ unsigned int txn_alloc_data(unsigned int virt_irq)
        return virt_irq - CPU_IRQ_BASE;
 }
 
+static inline int eirr_to_irq(unsigned long eirr)
+{
+       int bit = fls_long(eirr);
+       return (BITS_PER_LONG - bit) + TIMER_IRQ;
+}
+
 /* ONLY called from entry.S:intr_extint() */
 void do_cpu_irq_mask(struct pt_regs *regs)
 {
+       struct pt_regs *old_regs;
        unsigned long eirr_val;
-
-       irq_enter();
-
-       /*
-        * Don't allow TIMER or IPI nested interrupts.
-        * Allowing any single interrupt to nest can lead to that CPU
-        * handling interrupts with all enabled interrupts unmasked.
-        */
-       set_eiem(0UL);
-
-       /* 1) only process IRQs that are enabled/unmasked (cpu_eiem)
-        * 2) We loop here on EIRR contents in order to avoid
-        *    nested interrupts or having to take another interrupt
-        *    when we could have just handled it right away.
-        */
-       for (;;) {
-               unsigned long bit = (1UL << (BITS_PER_LONG - 1));
-               unsigned int irq;
-               eirr_val = mfctl(23) & cpu_eiem;
-               if (!eirr_val)
-                       break;
-
-               mtctl(eirr_val, 23); /* reset bits we are going to process */
-
-               /* Work our way from MSb to LSb...same order we alloc EIRs */
-               for (irq = TIMER_IRQ; eirr_val && bit; bit>>=1, irq++) {
+       int irq, cpu = smp_processor_id();
 #ifdef CONFIG_SMP
-                       cpumask_t dest = irq_affinity[irq];
+       cpumask_t dest;
 #endif
-                       if (!(bit & eirr_val))
-                               continue;
 
-                       /* clear bit in mask - can exit loop sooner */
-                       eirr_val &= ~bit;
+       old_regs = set_irq_regs(regs);
+       local_irq_disable();
+       irq_enter();
 
-#ifdef CONFIG_SMP
-                       /* FIXME: because generic set affinity mucks
-                        * with the affinity before sending it to us
-                        * we can get the situation where the affinity is
-                        * wrong for our CPU type interrupts */
-                       if (irq != TIMER_IRQ && irq != IPI_IRQ &&
-                           !cpu_isset(smp_processor_id(), dest)) {
-                               int cpu = first_cpu(dest);
-
-                               printk(KERN_DEBUG "redirecting irq %d from CPU %d to %d\n",
-                                      irq, smp_processor_id(), cpu);
-                               gsc_writel(irq + CPU_IRQ_BASE,
-                                          cpu_data[cpu].hpa);
-                               continue;
-                       }
-#endif
+       eirr_val = mfctl(23) & cpu_eiem & per_cpu(local_ack_eiem, cpu);
+       if (!eirr_val)
+               goto set_out;
+       irq = eirr_to_irq(eirr_val);
 
-                       __do_IRQ(irq, regs);
-               }
+#ifdef CONFIG_SMP
+       cpumask_copy(&dest, &irq_desc[irq].affinity);
+       if (CHECK_IRQ_PER_CPU(irq_desc[irq].status) &&
+           !cpu_isset(smp_processor_id(), dest)) {
+               int cpu = first_cpu(dest);
+
+               printk(KERN_DEBUG "redirecting irq %d from CPU %d to %d\n",
+                      irq, smp_processor_id(), cpu);
+               gsc_writel(irq + CPU_IRQ_BASE,
+                          per_cpu(cpu_data, cpu).hpa);
+               goto set_out;
        }
+#endif
+       __do_IRQ(irq);
 
-       set_eiem(cpu_eiem);     /* restore original mask */
+ out:
        irq_exit();
-}
+       set_irq_regs(old_regs);
+       return;
 
+ set_out:
+       set_eiem(cpu_eiem & per_cpu(local_ack_eiem, cpu));
+       goto out;
+}
 
 static struct irqaction timer_action = {
        .handler = timer_interrupt,
        .name = "timer",
-       .flags = SA_INTERRUPT,
+       .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_PERCPU | IRQF_IRQPOLL,
 };
 
 #ifdef CONFIG_SMP
 static struct irqaction ipi_action = {
        .handler = ipi_interrupt,
        .name = "IPI",
-       .flags = SA_INTERRUPT,
+       .flags = IRQF_DISABLED | IRQF_PERCPU,
 };
 #endif
 
@@ -378,11 +396,11 @@ static void claim_cpu_irqs(void)
 {
        int i;
        for (i = CPU_IRQ_BASE; i <= CPU_IRQ_MAX; i++) {
-               irq_desc[i].handler = &cpu_interrupt_type;
+               irq_desc[i].chip = &cpu_interrupt_type;
        }
 
        irq_desc[TIMER_IRQ].action = &timer_action;
-       irq_desc[TIMER_IRQ].status |= IRQ_PER_CPU;
+       irq_desc[TIMER_IRQ].status = IRQ_PER_CPU;
 #ifdef CONFIG_SMP
        irq_desc[IPI_IRQ].action = &ipi_action;
        irq_desc[IPI_IRQ].status = IRQ_PER_CPU;
@@ -404,14 +422,7 @@ void __init init_IRQ(void)
 
 }
 
-void hw_resend_irq(struct hw_interrupt_type *type, unsigned int irq)
-{
-       /* XXX: Needs to be written.  We managed without it so far, but
-        * we really ought to write it.
-        */
-}
-
 void ack_bad_irq(unsigned int irq)
 {
-       printk("unexpected IRQ %d\n", irq);
+       printk(KERN_WARNING "unexpected IRQ %d\n", irq);
 }