handle.c 6.2 KB

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