upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / arch / arm / kernel / irq.c
1 /*
2  *  linux/arch/arm/kernel/irq.c
3  *
4  *  Copyright (C) 1992 Linus Torvalds
5  *  Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  *  This file contains the code used by various IRQ handling routines:
12  *  asking for different IRQ's should be done through these routines
13  *  instead of just grabbing them. Thus setups with different IRQ numbers
14  *  shouldn't result in any weird surprises, and installing new handlers
15  *  should be easier.
16  *
17  *  IRQ's are in fact implemented a bit like signal handlers for the kernel.
18  *  Naturally it's not a 1:1 relation, but there are similarities.
19  */
20 #include <linux/config.h>
21 #include <linux/kernel_stat.h>
22 #include <linux/module.h>
23 #include <linux/signal.h>
24 #include <linux/ioport.h>
25 #include <linux/interrupt.h>
26 #include <linux/ptrace.h>
27 #include <linux/slab.h>
28 #include <linux/random.h>
29 #include <linux/smp.h>
30 #include <linux/init.h>
31 #include <linux/seq_file.h>
32 #include <linux/errno.h>
33 #include <linux/list.h>
34 #include <linux/kallsyms.h>
35
36 #include <asm/irq.h>
37 #include <asm/system.h>
38 #include <asm/mach/irq.h>
39
40 /*
41  * Maximum IRQ count.  Currently, this is arbitary.  However, it should
42  * not be set too low to prevent false triggering.  Conversely, if it
43  * is set too high, then you could miss a stuck IRQ.
44  *
45  * Maybe we ought to set a timer and re-enable the IRQ at a later time?
46  */
47 #define MAX_IRQ_CNT     100000
48
49 static int noirqdebug;
50 static volatile unsigned long irq_err_count;
51 static spinlock_t irq_controller_lock = SPIN_LOCK_UNLOCKED;
52 static LIST_HEAD(irq_pending);
53
54 struct irqdesc irq_desc[NR_IRQS];
55 void (*init_arch_irq)(void) __initdata = NULL;
56
57 /*
58  * Dummy mask/unmask handler
59  */
60 void dummy_mask_unmask_irq(unsigned int irq)
61 {
62 }
63
64 irqreturn_t no_action(int irq, void *dev_id, struct pt_regs *regs)
65 {
66         return IRQ_NONE;
67 }
68
69 void do_bad_IRQ(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
70 {
71         irq_err_count += 1;
72         printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
73 }
74
75 static struct irqchip bad_chip = {
76         .ack    = dummy_mask_unmask_irq,
77         .mask   = dummy_mask_unmask_irq,
78         .unmask = dummy_mask_unmask_irq,
79 };
80
81 static struct irqdesc bad_irq_desc = {
82         .chip           = &bad_chip,
83         .handle         = do_bad_IRQ,
84         .pend           = LIST_HEAD_INIT(bad_irq_desc.pend),
85         .disable_depth  = 1,
86 };
87
88 /**
89  *      disable_irq_nosync - disable an irq without waiting
90  *      @irq: Interrupt to disable
91  *
92  *      Disable the selected interrupt line.  Enables and disables
93  *      are nested.  We do this lazily.
94  *
95  *      This function may be called from IRQ context.
96  */
97 void disable_irq_nosync(unsigned int irq)
98 {
99         struct irqdesc *desc = irq_desc + irq;
100         unsigned long flags;
101
102         spin_lock_irqsave(&irq_controller_lock, flags);
103         desc->disable_depth++;
104         list_del_init(&desc->pend);
105         spin_unlock_irqrestore(&irq_controller_lock, flags);
106 }
107 EXPORT_SYMBOL(disable_irq_nosync);
108
109 /**
110  *      disable_irq - disable an irq and wait for completion
111  *      @irq: Interrupt to disable
112  *
113  *      Disable the selected interrupt line.  Enables and disables
114  *      are nested.  This functions waits for any pending IRQ
115  *      handlers for this interrupt to complete before returning.
116  *      If you use this function while holding a resource the IRQ
117  *      handler may need you will deadlock.
118  *
119  *      This function may be called - with care - from IRQ context.
120  */
121 void disable_irq(unsigned int irq)
122 {
123         struct irqdesc *desc = irq_desc + irq;
124
125         disable_irq_nosync(irq);
126         if (desc->action)
127                 synchronize_irq(irq);
128 }
129 EXPORT_SYMBOL(disable_irq);
130
131 /**
132  *      enable_irq - enable interrupt handling on an irq
133  *      @irq: Interrupt to enable
134  *
135  *      Re-enables the processing of interrupts on this IRQ line.
136  *      Note that this may call the interrupt handler, so you may
137  *      get unexpected results if you hold IRQs disabled.
138  *
139  *      This function may be called from IRQ context.
140  */
141 void enable_irq(unsigned int irq)
142 {
143         struct irqdesc *desc = irq_desc + irq;
144         unsigned long flags;
145
146         spin_lock_irqsave(&irq_controller_lock, flags);
147         if (unlikely(!desc->disable_depth)) {
148                 printk("enable_irq(%u) unbalanced from %p\n", irq,
149                         __builtin_return_address(0));
150         } else if (!--desc->disable_depth) {
151                 desc->probing = 0;
152                 desc->chip->unmask(irq);
153
154                 /*
155                  * If the interrupt is waiting to be processed,
156                  * try to re-run it.  We can't directly run it
157                  * from here since the caller might be in an
158                  * interrupt-protected region.
159                  */
160                 if (desc->pending && list_empty(&desc->pend)) {
161                         desc->pending = 0;
162                         if (!desc->chip->retrigger ||
163                             desc->chip->retrigger(irq))
164                                 list_add(&desc->pend, &irq_pending);
165                 }
166         }
167         spin_unlock_irqrestore(&irq_controller_lock, flags);
168 }
169 EXPORT_SYMBOL(enable_irq);
170
171 /*
172  * Enable wake on selected irq
173  */
174 void enable_irq_wake(unsigned int irq)
175 {
176         struct irqdesc *desc = irq_desc + irq;
177         unsigned long flags;
178
179         spin_lock_irqsave(&irq_controller_lock, flags);
180         if (desc->chip->wake)
181                 desc->chip->wake(irq, 1);
182         spin_unlock_irqrestore(&irq_controller_lock, flags);
183 }
184 EXPORT_SYMBOL(enable_irq_wake);
185
186 void disable_irq_wake(unsigned int irq)
187 {
188         struct irqdesc *desc = irq_desc + irq;
189         unsigned long flags;
190
191         spin_lock_irqsave(&irq_controller_lock, flags);
192         if (desc->chip->wake)
193                 desc->chip->wake(irq, 0);
194         spin_unlock_irqrestore(&irq_controller_lock, flags);
195 }
196 EXPORT_SYMBOL(disable_irq_wake);
197
198 int show_interrupts(struct seq_file *p, void *v)
199 {
200         int i = *(loff_t *) v, cpu;
201         struct irqaction * action;
202         unsigned long flags;
203
204         if (i == 0) {
205                 char cpuname[12];
206
207                 seq_printf(p, "    ");
208                 for_each_present_cpu(cpu) {
209                         sprintf(cpuname, "CPU%d", cpu);
210                         seq_printf(p, " %10s", cpuname);
211                 }
212                 seq_putc(p, '\n');
213         }
214
215         if (i < NR_IRQS) {
216                 spin_lock_irqsave(&irq_controller_lock, flags);
217                 action = irq_desc[i].action;
218                 if (!action)
219                         goto unlock;
220
221                 seq_printf(p, "%3d: ", i);
222                 for_each_present_cpu(cpu)
223                         seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[i]);
224                 seq_printf(p, "  %s", action->name);
225                 for (action = action->next; action; action = action->next)
226                         seq_printf(p, ", %s", action->name);
227
228                 seq_putc(p, '\n');
229 unlock:
230                 spin_unlock_irqrestore(&irq_controller_lock, flags);
231         } else if (i == NR_IRQS) {
232 #ifdef CONFIG_ARCH_ACORN
233                 show_fiq_list(p, v);
234 #endif
235                 seq_printf(p, "Err: %10lu\n", irq_err_count);
236         }
237         return 0;
238 }
239
240 /*
241  * IRQ lock detection.
242  *
243  * Hopefully, this should get us out of a few locked situations.
244  * However, it may take a while for this to happen, since we need
245  * a large number if IRQs to appear in the same jiffie with the
246  * same instruction pointer (or within 2 instructions).
247  */
248 static int check_irq_lock(struct irqdesc *desc, int irq, struct pt_regs *regs)
249 {
250         unsigned long instr_ptr = instruction_pointer(regs);
251
252         if (desc->lck_jif == jiffies &&
253             desc->lck_pc >= instr_ptr && desc->lck_pc < instr_ptr + 8) {
254                 desc->lck_cnt += 1;
255
256                 if (desc->lck_cnt > MAX_IRQ_CNT) {
257                         printk(KERN_ERR "IRQ LOCK: IRQ%d is locking the system, disabled\n", irq);
258                         return 1;
259                 }
260         } else {
261                 desc->lck_cnt = 0;
262                 desc->lck_pc  = instruction_pointer(regs);
263                 desc->lck_jif = jiffies;
264         }
265         return 0;
266 }
267
268 static void
269 report_bad_irq(unsigned int irq, struct pt_regs *regs, struct irqdesc *desc, int ret)
270 {
271         static int count = 100;
272         struct irqaction *action;
273
274         if (!count || noirqdebug)
275                 return;
276
277         count--;
278
279         if (ret != IRQ_HANDLED && ret != IRQ_NONE) {
280                 printk("irq%u: bogus retval mask %x\n", irq, ret);
281         } else {
282                 printk("irq%u: nobody cared\n", irq);
283         }
284         show_regs(regs);
285         dump_stack();
286         printk(KERN_ERR "handlers:");
287         action = desc->action;
288         do {
289                 printk("\n" KERN_ERR "[<%p>]", action->handler);
290                 print_symbol(" (%s)", (unsigned long)action->handler);
291                 action = action->next;
292         } while (action);
293         printk("\n");
294 }
295
296 static int
297 __do_irq(unsigned int irq, struct irqaction *action, struct pt_regs *regs)
298 {
299         unsigned int status;
300         int ret, retval = 0;
301
302         spin_unlock(&irq_controller_lock);
303
304         if (!(action->flags & SA_INTERRUPT))
305                 local_irq_enable();
306
307         status = 0;
308         do {
309                 ret = action->handler(irq, action->dev_id, regs);
310                 if (ret == IRQ_HANDLED)
311                         status |= action->flags;
312                 retval |= ret;
313                 action = action->next;
314         } while (action);
315
316         if (status & SA_SAMPLE_RANDOM)
317                 add_interrupt_randomness(irq);
318
319         spin_lock_irq(&irq_controller_lock);
320
321         return retval;
322 }
323
324 /*
325  * This is for software-decoded IRQs.  The caller is expected to
326  * handle the ack, clear, mask and unmask issues.
327  */
328 void
329 do_simple_IRQ(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
330 {
331         struct irqaction *action;
332         const int cpu = smp_processor_id();
333
334         desc->triggered = 1;
335
336         kstat_cpu(cpu).irqs[irq]++;
337
338         action = desc->action;
339         if (action) {
340                 int ret = __do_irq(irq, action, regs);
341                 if (ret != IRQ_HANDLED)
342                         report_bad_irq(irq, regs, desc, ret);
343         }
344 }
345
346 /*
347  * Most edge-triggered IRQ implementations seem to take a broken
348  * approach to this.  Hence the complexity.
349  */
350 void
351 do_edge_IRQ(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
352 {
353         const int cpu = smp_processor_id();
354
355         desc->triggered = 1;
356
357         /*
358          * If we're currently running this IRQ, or its disabled,
359          * we shouldn't process the IRQ.  Instead, turn on the
360          * hardware masks.
361          */
362         if (unlikely(desc->running || desc->disable_depth))
363                 goto running;
364
365         /*
366          * Acknowledge and clear the IRQ, but don't mask it.
367          */
368         desc->chip->ack(irq);
369
370         /*
371          * Mark the IRQ currently in progress.
372          */
373         desc->running = 1;
374
375         kstat_cpu(cpu).irqs[irq]++;
376
377         do {
378                 struct irqaction *action;
379
380                 action = desc->action;
381                 if (!action)
382                         break;
383
384                 if (desc->pending && !desc->disable_depth) {
385                         desc->pending = 0;
386                         desc->chip->unmask(irq);
387                 }
388
389                 __do_irq(irq, action, regs);
390         } while (desc->pending && !desc->disable_depth);
391
392         desc->running = 0;
393
394         /*
395          * If we were disabled or freed, shut down the handler.
396          */
397         if (likely(desc->action && !check_irq_lock(desc, irq, regs)))
398                 return;
399
400  running:
401         /*
402          * We got another IRQ while this one was masked or
403          * currently running.  Delay it.
404          */
405         desc->pending = 1;
406         desc->chip->mask(irq);
407         desc->chip->ack(irq);
408 }
409
410 /*
411  * Level-based IRQ handler.  Nice and simple.
412  */
413 void
414 do_level_IRQ(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
415 {
416         struct irqaction *action;
417         const int cpu = smp_processor_id();
418
419         desc->triggered = 1;
420
421         /*
422          * Acknowledge, clear _AND_ disable the interrupt.
423          */
424         desc->chip->ack(irq);
425
426         if (likely(!desc->disable_depth)) {
427                 kstat_cpu(cpu).irqs[irq]++;
428
429                 /*
430                  * Return with this interrupt masked if no action
431                  */
432                 action = desc->action;
433                 if (action) {
434                         int ret = __do_irq(irq, desc->action, regs);
435
436                         if (ret != IRQ_HANDLED)
437                                 report_bad_irq(irq, regs, desc, ret);
438
439                         if (likely(!desc->disable_depth &&
440                                    !check_irq_lock(desc, irq, regs)))
441                                 desc->chip->unmask(irq);
442                 }
443         }
444 }
445
446 static void do_pending_irqs(struct pt_regs *regs)
447 {
448         struct list_head head, *l, *n;
449
450         do {
451                 struct irqdesc *desc;
452
453                 /*
454                  * First, take the pending interrupts off the list.
455                  * The act of calling the handlers may add some IRQs
456                  * back onto the list.
457                  */
458                 head = irq_pending;
459                 INIT_LIST_HEAD(&irq_pending);
460                 head.next->prev = &head;
461                 head.prev->next = &head;
462
463                 /*
464                  * Now run each entry.  We must delete it from our
465                  * list before calling the handler.
466                  */
467                 list_for_each_safe(l, n, &head) {
468                         desc = list_entry(l, struct irqdesc, pend);
469                         list_del_init(&desc->pend);
470                         desc->handle(desc - irq_desc, desc, regs);
471                 }
472
473                 /*
474                  * The list must be empty.
475                  */
476                 BUG_ON(!list_empty(&head));
477         } while (!list_empty(&irq_pending));
478 }
479
480 /*
481  * do_IRQ handles all hardware IRQ's.  Decoded IRQs should not
482  * come via this function.  Instead, they should provide their
483  * own 'handler'
484  */
485 asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
486 {
487         struct irqdesc *desc = irq_desc + irq;
488
489         /*
490          * Some hardware gives randomly wrong interrupts.  Rather
491          * than crashing, do something sensible.
492          */
493         if (irq >= NR_IRQS)
494                 desc = &bad_irq_desc;
495
496         irq_enter();
497         spin_lock(&irq_controller_lock);
498         desc->handle(irq, desc, regs);
499
500         /*
501          * Now re-run any pending interrupts.
502          */
503         if (!list_empty(&irq_pending))
504                 do_pending_irqs(regs);
505
506         spin_unlock(&irq_controller_lock);
507         irq_exit();
508 }
509
510 void __set_irq_handler(unsigned int irq, irq_handler_t handle, int is_chained)
511 {
512         struct irqdesc *desc;
513         unsigned long flags;
514
515         if (irq >= NR_IRQS) {
516                 printk(KERN_ERR "Trying to install handler for IRQ%d\n", irq);
517                 return;
518         }
519
520         if (handle == NULL)
521                 handle = do_bad_IRQ;
522
523         desc = irq_desc + irq;
524
525         if (is_chained && desc->chip == &bad_chip)
526                 printk(KERN_WARNING "Trying to install chained handler for IRQ%d\n", irq);
527
528         spin_lock_irqsave(&irq_controller_lock, flags);
529         if (handle == do_bad_IRQ) {
530                 desc->chip->mask(irq);
531                 desc->chip->ack(irq);
532                 desc->disable_depth = 1;
533         }
534         desc->handle = handle;
535         if (handle != do_bad_IRQ && is_chained) {
536                 desc->valid = 0;
537                 desc->probe_ok = 0;
538                 desc->disable_depth = 0;
539                 desc->chip->unmask(irq);
540         }
541         spin_unlock_irqrestore(&irq_controller_lock, flags);
542 }
543
544 void set_irq_chip(unsigned int irq, struct irqchip *chip)
545 {
546         struct irqdesc *desc;
547         unsigned long flags;
548
549         if (irq >= NR_IRQS) {
550                 printk(KERN_ERR "Trying to install chip for IRQ%d\n", irq);
551                 return;
552         }
553
554         if (chip == NULL)
555                 chip = &bad_chip;
556
557         desc = irq_desc + irq;
558         spin_lock_irqsave(&irq_controller_lock, flags);
559         desc->chip = chip;
560         spin_unlock_irqrestore(&irq_controller_lock, flags);
561 }
562
563 int set_irq_type(unsigned int irq, unsigned int type)
564 {
565         struct irqdesc *desc;
566         unsigned long flags;
567         int ret = -ENXIO;
568
569         if (irq >= NR_IRQS) {
570                 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
571                 return -ENODEV;
572         }
573
574         desc = irq_desc + irq;
575         if (desc->chip->type) {
576                 spin_lock_irqsave(&irq_controller_lock, flags);
577                 ret = desc->chip->type(irq, type);
578                 spin_unlock_irqrestore(&irq_controller_lock, flags);
579         }
580
581         return ret;
582 }
583 EXPORT_SYMBOL(set_irq_type);
584
585 void set_irq_flags(unsigned int irq, unsigned int iflags)
586 {
587         struct irqdesc *desc;
588         unsigned long flags;
589
590         if (irq >= NR_IRQS) {
591                 printk(KERN_ERR "Trying to set irq flags for IRQ%d\n", irq);
592                 return;
593         }
594
595         desc = irq_desc + irq;
596         spin_lock_irqsave(&irq_controller_lock, flags);
597         desc->valid = (iflags & IRQF_VALID) != 0;
598         desc->probe_ok = (iflags & IRQF_PROBE) != 0;
599         desc->noautoenable = (iflags & IRQF_NOAUTOEN) != 0;
600         spin_unlock_irqrestore(&irq_controller_lock, flags);
601 }
602
603 int setup_irq(unsigned int irq, struct irqaction *new)
604 {
605         int shared = 0;
606         struct irqaction *old, **p;
607         unsigned long flags;
608         struct irqdesc *desc;
609
610         /*
611          * Some drivers like serial.c use request_irq() heavily,
612          * so we have to be careful not to interfere with a
613          * running system.
614          */
615         if (new->flags & SA_SAMPLE_RANDOM) {
616                 /*
617                  * This function might sleep, we want to call it first,
618                  * outside of the atomic block.
619                  * Yes, this might clear the entropy pool if the wrong
620                  * driver is attempted to be loaded, without actually
621                  * installing a new handler, but is this really a problem,
622                  * only the sysadmin is able to do this.
623                  */
624                 rand_initialize_irq(irq);
625         }
626
627         /*
628          * The following block of code has to be executed atomically
629          */
630         desc = irq_desc + irq;
631         spin_lock_irqsave(&irq_controller_lock, flags);
632         p = &desc->action;
633         if ((old = *p) != NULL) {
634                 /* Can't share interrupts unless both agree to */
635                 if (!(old->flags & new->flags & SA_SHIRQ)) {
636                         spin_unlock_irqrestore(&irq_controller_lock, flags);
637                         return -EBUSY;
638                 }
639
640                 /* add new interrupt at end of irq queue */
641                 do {
642                         p = &old->next;
643                         old = *p;
644                 } while (old);
645                 shared = 1;
646         }
647
648         *p = new;
649
650         if (!shared) {
651                 desc->probing = 0;
652                 desc->running = 0;
653                 desc->pending = 0;
654                 desc->disable_depth = 1;
655                 if (!desc->noautoenable) {
656                         desc->disable_depth = 0;
657                         desc->chip->unmask(irq);
658                 }
659         }
660
661         spin_unlock_irqrestore(&irq_controller_lock, flags);
662         return 0;
663 }
664
665 /**
666  *      request_irq - allocate an interrupt line
667  *      @irq: Interrupt line to allocate
668  *      @handler: Function to be called when the IRQ occurs
669  *      @irqflags: Interrupt type flags
670  *      @devname: An ascii name for the claiming device
671  *      @dev_id: A cookie passed back to the handler function
672  *
673  *      This call allocates interrupt resources and enables the
674  *      interrupt line and IRQ handling. From the point this
675  *      call is made your handler function may be invoked. Since
676  *      your handler function must clear any interrupt the board
677  *      raises, you must take care both to initialise your hardware
678  *      and to set up the interrupt handler in the right order.
679  *
680  *      Dev_id must be globally unique. Normally the address of the
681  *      device data structure is used as the cookie. Since the handler
682  *      receives this value it makes sense to use it.
683  *
684  *      If your interrupt is shared you must pass a non NULL dev_id
685  *      as this is required when freeing the interrupt.
686  *
687  *      Flags:
688  *
689  *      SA_SHIRQ                Interrupt is shared
690  *
691  *      SA_INTERRUPT            Disable local interrupts while processing
692  *
693  *      SA_SAMPLE_RANDOM        The interrupt can be used for entropy
694  *
695  */
696 int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *),
697                  unsigned long irq_flags, const char * devname, void *dev_id)
698 {
699         unsigned long retval;
700         struct irqaction *action;
701
702         if (irq >= NR_IRQS || !irq_desc[irq].valid || !handler ||
703             (irq_flags & SA_SHIRQ && !dev_id))
704                 return -EINVAL;
705
706         action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
707         if (!action)
708                 return -ENOMEM;
709
710         action->handler = handler;
711         action->flags = irq_flags;
712         cpus_clear(action->mask);
713         action->name = devname;
714         action->next = NULL;
715         action->dev_id = dev_id;
716
717         retval = setup_irq(irq, action);
718
719         if (retval)
720                 kfree(action);
721         return retval;
722 }
723
724 EXPORT_SYMBOL(request_irq);
725
726 /**
727  *      free_irq - free an interrupt
728  *      @irq: Interrupt line to free
729  *      @dev_id: Device identity to free
730  *
731  *      Remove an interrupt handler. The handler is removed and if the
732  *      interrupt line is no longer in use by any driver it is disabled.
733  *      On a shared IRQ the caller must ensure the interrupt is disabled
734  *      on the card it drives before calling this function.
735  *
736  *      This function must not be called from interrupt context.
737  */
738 void free_irq(unsigned int irq, void *dev_id)
739 {
740         struct irqaction * action, **p;
741         unsigned long flags;
742
743         if (irq >= NR_IRQS || !irq_desc[irq].valid) {
744                 printk(KERN_ERR "Trying to free IRQ%d\n",irq);
745                 dump_stack();
746                 return;
747         }
748
749         spin_lock_irqsave(&irq_controller_lock, flags);
750         for (p = &irq_desc[irq].action; (action = *p) != NULL; p = &action->next) {
751                 if (action->dev_id != dev_id)
752                         continue;
753
754                 /* Found it - now free it */
755                 *p = action->next;
756                 break;
757         }
758         spin_unlock_irqrestore(&irq_controller_lock, flags);
759
760         if (!action) {
761                 printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
762                 dump_stack();
763         } else {
764                 synchronize_irq(irq);
765                 kfree(action);
766         }
767 }
768
769 EXPORT_SYMBOL(free_irq);
770
771 static DECLARE_MUTEX(probe_sem);
772
773 /* Start the interrupt probing.  Unlike other architectures,
774  * we don't return a mask of interrupts from probe_irq_on,
775  * but return the number of interrupts enabled for the probe.
776  * The interrupts which have been enabled for probing is
777  * instead recorded in the irq_desc structure.
778  */
779 unsigned long probe_irq_on(void)
780 {
781         unsigned int i, irqs = 0;
782         unsigned long delay;
783
784         down(&probe_sem);
785
786         /*
787          * first snaffle up any unassigned but
788          * probe-able interrupts
789          */
790         spin_lock_irq(&irq_controller_lock);
791         for (i = 0; i < NR_IRQS; i++) {
792                 if (!irq_desc[i].probe_ok || irq_desc[i].action)
793                         continue;
794
795                 irq_desc[i].probing = 1;
796                 irq_desc[i].triggered = 0;
797                 if (irq_desc[i].chip->type)
798                         irq_desc[i].chip->type(i, IRQT_PROBE);
799                 irq_desc[i].chip->unmask(i);
800                 irqs += 1;
801         }
802         spin_unlock_irq(&irq_controller_lock);
803
804         /*
805          * wait for spurious interrupts to mask themselves out again
806          */
807         for (delay = jiffies + HZ/10; time_before(jiffies, delay); )
808                 /* min 100ms delay */;
809
810         /*
811          * now filter out any obviously spurious interrupts
812          */
813         spin_lock_irq(&irq_controller_lock);
814         for (i = 0; i < NR_IRQS; i++) {
815                 if (irq_desc[i].probing && irq_desc[i].triggered) {
816                         irq_desc[i].probing = 0;
817                         irqs -= 1;
818                 }
819         }
820         spin_unlock_irq(&irq_controller_lock);
821
822         return irqs;
823 }
824
825 EXPORT_SYMBOL(probe_irq_on);
826
827 unsigned int probe_irq_mask(unsigned long irqs)
828 {
829         unsigned int mask = 0, i;
830
831         spin_lock_irq(&irq_controller_lock);
832         for (i = 0; i < 16 && i < NR_IRQS; i++)
833                 if (irq_desc[i].probing && irq_desc[i].triggered)
834                         mask |= 1 << i;
835         spin_unlock_irq(&irq_controller_lock);
836
837         up(&probe_sem);
838
839         return mask;
840 }
841 EXPORT_SYMBOL(probe_irq_mask);
842
843 /*
844  * Possible return values:
845  *  >= 0 - interrupt number
846  *    -1 - no interrupt/many interrupts
847  */
848 int probe_irq_off(unsigned long irqs)
849 {
850         unsigned int i;
851         int irq_found = NO_IRQ;
852
853         /*
854          * look at the interrupts, and find exactly one
855          * that we were probing has been triggered
856          */
857         spin_lock_irq(&irq_controller_lock);
858         for (i = 0; i < NR_IRQS; i++) {
859                 if (irq_desc[i].probing &&
860                     irq_desc[i].triggered) {
861                         if (irq_found != NO_IRQ) {
862                                 irq_found = NO_IRQ;
863                                 goto out;
864                         }
865                         irq_found = i;
866                 }
867         }
868
869         if (irq_found == -1)
870                 irq_found = NO_IRQ;
871 out:
872         spin_unlock_irq(&irq_controller_lock);
873
874         up(&probe_sem);
875
876         return irq_found;
877 }
878
879 EXPORT_SYMBOL(probe_irq_off);
880
881 void __init init_irq_proc(void)
882 {
883 }
884
885 void __init init_IRQ(void)
886 {
887         struct irqdesc *desc;
888         extern void init_dma(void);
889         int irq;
890
891         for (irq = 0, desc = irq_desc; irq < NR_IRQS; irq++, desc++) {
892                 *desc = bad_irq_desc;
893                 INIT_LIST_HEAD(&desc->pend);
894         }
895
896         init_arch_irq();
897         init_dma();
898 }
899
900 static int __init noirqdebug_setup(char *str)
901 {
902         noirqdebug = 1;
903         return 1;
904 }
905
906 __setup("noirqdebug", noirqdebug_setup);