handle.c 6.1 KB

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