handle.c 6.2 KB

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