~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/kernel/irq.c

Version: ~ [ linux-5.1.2 ] ~ [ linux-5.0.16 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.43 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.119 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.176 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.179 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.139 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.67 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp