handle.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * linux/kernel/irq/handle.c
  3. *
  4. * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
  5. * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
  6. *
  7. * This file contains the core interrupt handling code.
  8. *
  9. * Detailed information is available in Documentation/DocBook/genericirq
  10. *
  11. */
  12. #include <linux/irq.h>
  13. #include <linux/module.h>
  14. #include <linux/random.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel_stat.h>
  17. #include "internals.h"
  18. /**
  19. * handle_bad_irq - handle spurious and unhandled irqs
  20. */
  21. void fastcall
  22. handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
  23. {
  24. print_irq_desc(irq, desc);
  25. kstat_this_cpu.irqs[irq]++;
  26. ack_bad_irq(irq);
  27. }
  28. /*
  29. * Linux has a controller-independent interrupt architecture.
  30. * Every controller has a 'controller-template', that is used
  31. * by the main code to do the right thing. Each driver-visible
  32. * interrupt source is transparently wired to the appropriate
  33. * controller. Thus drivers need not be aware of the
  34. * interrupt-controller.
  35. *
  36. * The code is designed to be easily extended with new/different
  37. * interrupt controllers, without having to do assembly magic or
  38. * having to touch the generic code.
  39. *
  40. * Controller mappings for all interrupt sources:
  41. */
  42. struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
  43. [0 ... NR_IRQS-1] = {
  44. .status = IRQ_DISABLED,
  45. .chip = &no_irq_chip,
  46. .handle_irq = handle_bad_irq,
  47. .depth = 1,
  48. .lock = SPIN_LOCK_UNLOCKED,
  49. #ifdef CONFIG_SMP
  50. .affinity = CPU_MASK_ALL
  51. #endif
  52. }
  53. };
  54. /*
  55. * What should we do if we get a hw irq event on an illegal vector?
  56. * Each architecture has to answer this themself.
  57. */
  58. static void ack_bad(unsigned int irq)
  59. {
  60. print_irq_desc(irq, irq_desc + irq);
  61. ack_bad_irq(irq);
  62. }
  63. /*
  64. * NOP functions
  65. */
  66. static void noop(unsigned int irq)
  67. {
  68. }
  69. static unsigned int noop_ret(unsigned int irq)
  70. {
  71. return 0;
  72. }
  73. /*
  74. * Generic no controller implementation
  75. */
  76. struct irq_chip no_irq_chip = {
  77. .name = "none",
  78. .startup = noop_ret,
  79. .shutdown = noop,
  80. .enable = noop,
  81. .disable = noop,
  82. .ack = ack_bad,
  83. .end = noop,
  84. };
  85. /*
  86. * Special, empty irq handler:
  87. */
  88. irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
  89. {
  90. return IRQ_NONE;
  91. }
  92. /**
  93. * handle_IRQ_event - irq action chain handler
  94. * @irq: the interrupt number
  95. * @regs: pointer to a register structure
  96. * @action: the interrupt action chain for this irq
  97. *
  98. * Handles the action chain of an irq event
  99. */
  100. irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
  101. struct irqaction *action)
  102. {
  103. irqreturn_t ret, retval = IRQ_NONE;
  104. unsigned int status = 0;
  105. if (!(action->flags & SA_INTERRUPT))
  106. local_irq_enable();
  107. do {
  108. ret = action->handler(irq, action->dev_id, regs);
  109. if (ret == IRQ_HANDLED)
  110. status |= action->flags;
  111. retval |= ret;
  112. action = action->next;
  113. } while (action);
  114. if (status & SA_SAMPLE_RANDOM)
  115. add_interrupt_randomness(irq);
  116. local_irq_disable();
  117. return retval;
  118. }
  119. /**
  120. * __do_IRQ - original all in one highlevel IRQ handler
  121. * @irq: the interrupt number
  122. * @regs: pointer to a register structure
  123. *
  124. * __do_IRQ handles all normal device IRQ's (the special
  125. * SMP cross-CPU interrupts have their own specific
  126. * handlers).
  127. *
  128. * This is the original x86 implementation which is used for every
  129. * interrupt type.
  130. */
  131. fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
  132. {
  133. struct irq_desc *desc = irq_desc + irq;
  134. struct irqaction *action;
  135. unsigned int status;
  136. kstat_this_cpu.irqs[irq]++;
  137. if (CHECK_IRQ_PER_CPU(desc->status)) {
  138. irqreturn_t action_ret;
  139. /*
  140. * No locking required for CPU-local interrupts:
  141. */
  142. if (desc->chip->ack)
  143. desc->chip->ack(irq);
  144. action_ret = handle_IRQ_event(irq, regs, desc->action);
  145. desc->chip->end(irq);
  146. return 1;
  147. }
  148. spin_lock(&desc->lock);
  149. if (desc->chip->ack)
  150. desc->chip->ack(irq);
  151. /*
  152. * REPLAY is when Linux resends an IRQ that was dropped earlier
  153. * WAITING is used by probe to mark irqs that are being tested
  154. */
  155. status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
  156. status |= IRQ_PENDING; /* we _want_ to handle it */
  157. /*
  158. * If the IRQ is disabled for whatever reason, we cannot
  159. * use the action we have.
  160. */
  161. action = NULL;
  162. if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
  163. action = desc->action;
  164. status &= ~IRQ_PENDING; /* we commit to handling */
  165. status |= IRQ_INPROGRESS; /* we are handling it */
  166. }
  167. desc->status = status;
  168. /*
  169. * If there is no IRQ handler or it was disabled, exit early.
  170. * Since we set PENDING, if another processor is handling
  171. * a different instance of this same irq, the other processor
  172. * will take care of it.
  173. */
  174. if (unlikely(!action))
  175. goto out;
  176. /*
  177. * Edge triggered interrupts need to remember
  178. * pending events.
  179. * This applies to any hw interrupts that allow a second
  180. * instance of the same irq to arrive while we are in do_IRQ
  181. * or in the handler. But the code here only handles the _second_
  182. * instance of the irq, not the third or fourth. So it is mostly
  183. * useful for irq hardware that does not mask cleanly in an
  184. * SMP environment.
  185. */
  186. for (;;) {
  187. irqreturn_t action_ret;
  188. spin_unlock(&desc->lock);
  189. action_ret = handle_IRQ_event(irq, regs, action);
  190. spin_lock(&desc->lock);
  191. if (!noirqdebug)
  192. note_interrupt(irq, desc, action_ret, regs);
  193. if (likely(!(desc->status & IRQ_PENDING)))
  194. break;
  195. desc->status &= ~IRQ_PENDING;
  196. }
  197. desc->status &= ~IRQ_INPROGRESS;
  198. out:
  199. /*
  200. * The ->end() handler has to deal with interrupts which got
  201. * disabled while the handler was running.
  202. */
  203. desc->chip->end(irq);
  204. spin_unlock(&desc->lock);
  205. return 1;
  206. }