]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/irq/handle.c
Merge branch 'linus' into irq/threaded
[linux-2.6-omap-h63xx.git] / kernel / irq / handle.c
index f51eaee921b603b202bf184cdfdaee3a8da2ca08..d82142be8dd2c8fddc340058ff9cd73373f6a31b 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/rculist.h>
 #include <linux/hash.h>
+#include <trace/irq.h>
 #include <linux/bootmem.h>
 
 #include "internals.h"
@@ -82,19 +83,21 @@ static struct irq_desc irq_desc_init = {
 
 void init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
 {
-       unsigned long bytes;
-       char *ptr;
        int node;
-
-       /* Compute how many bytes we need per irq and allocate them */
-       bytes = nr * sizeof(unsigned int);
+       void *ptr;
 
        node = cpu_to_node(cpu);
-       ptr = kzalloc_node(bytes, GFP_ATOMIC, node);
-       printk(KERN_DEBUG "  alloc kstat_irqs on cpu %d node %d\n", cpu, node);
+       ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
 
-       if (ptr)
-               desc->kstat_irqs = (unsigned int *)ptr;
+       /*
+        * don't overwite if can not get new one
+        * init_copy_kstat_irqs() could still use old one
+        */
+       if (ptr) {
+               printk(KERN_DEBUG "  alloc kstat_irqs on cpu %d node %d\n",
+                        cpu, node);
+               desc->kstat_irqs = ptr;
+       }
 }
 
 static void init_one_irq_desc(int irq, struct irq_desc *desc, int cpu)
@@ -237,6 +240,7 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
        }
 };
 
+static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS];
 int __init early_irq_init(void)
 {
        struct irq_desc *desc;
@@ -253,6 +257,7 @@ int __init early_irq_init(void)
        for (i = 0; i < count; i++) {
                desc[i].irq = i;
                init_alloc_desc_masks(&desc[i], 0, true);
+               desc[i].kstat_irqs = kstat_irqs_all[i];
        }
        return arch_early_irq_init();
 }
@@ -268,6 +273,11 @@ struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
 }
 #endif /* !CONFIG_SPARSE_IRQ */
 
+void clear_kstat_irqs(struct irq_desc *desc)
+{
+       memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs)));
+}
+
 /*
  * What should we do if we get a hw irq event on an illegal vector?
  * Each architecture has to answer this themself.
@@ -329,6 +339,18 @@ irqreturn_t no_action(int cpl, void *dev_id)
        return IRQ_NONE;
 }
 
+static void warn_no_thread(unsigned int irq, struct irqaction *action)
+{
+       if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
+               return;
+
+       printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
+              "but no thread function available.", irq, action->name);
+}
+
+DEFINE_TRACE(irq_handler_entry);
+DEFINE_TRACE(irq_handler_exit);
+
 /**
  * handle_IRQ_event - irq action chain handler
  * @irq:       the interrupt number
@@ -341,13 +363,56 @@ irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
        irqreturn_t ret, retval = IRQ_NONE;
        unsigned int status = 0;
 
+       WARN_ONCE(!in_irq(), "BUG: IRQ handler called from non-hardirq context!");
+
        if (!(action->flags & IRQF_DISABLED))
                local_irq_enable_in_hardirq();
 
        do {
+               trace_irq_handler_entry(irq, action);
                ret = action->handler(irq, action->dev_id);
-               if (ret == IRQ_HANDLED)
+               trace_irq_handler_exit(irq, action, ret);
+
+               switch (ret) {
+               case IRQ_WAKE_THREAD:
+                       /*
+                        * Set result to handled so the spurious check
+                        * does not trigger.
+                        */
+                       ret = IRQ_HANDLED;
+
+                       /*
+                        * Catch drivers which return WAKE_THREAD but
+                        * did not set up a thread function
+                        */
+                       if (unlikely(!action->thread_fn)) {
+                               warn_no_thread(irq, action);
+                               break;
+                       }
+
+                       /*
+                        * Wake up the handler thread for this
+                        * action. In case the thread crashed and was
+                        * killed we just pretend that we handled the
+                        * interrupt. The hardirq handler above has
+                        * disabled the device interrupt, so no irq
+                        * storm is lurking.
+                        */
+                       if (likely(!test_bit(IRQTF_DIED,
+                                            &action->thread_flags))) {
+                               set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
+                               wake_up_process(action->thread);
+                       }
+
+                       /* Fall through to add to randomness */
+               case IRQ_HANDLED:
                        status |= action->flags;
+                       break;
+
+               default:
+                       break;
+               }
+
                retval |= ret;
                action = action->next;
        } while (action);
@@ -360,6 +425,11 @@ irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
 }
 
 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
+
+#ifdef CONFIG_ENABLE_WARN_DEPRECATED
+# warning __do_IRQ is deprecated. Please convert to proper flow handlers
+#endif
+
 /**
  * __do_IRQ - original all in one highlevel IRQ handler
  * @irq:       the interrupt number
@@ -480,12 +550,10 @@ void early_init_irq_lock_class(void)
        }
 }
 
-#ifdef CONFIG_SPARSE_IRQ
 unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
 {
        struct irq_desc *desc = irq_to_desc(irq);
        return desc ? desc->kstat_irqs[cpu] : 0;
 }
-#endif
 EXPORT_SYMBOL(kstat_irqs_cpu);