handle.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. * Generic dummy implementation which can be used for
  87. * real dumb interrupt sources
  88. */
  89. struct irq_chip dummy_irq_chip = {
  90. .name = "dummy",
  91. .startup = noop_ret,
  92. .shutdown = noop,
  93. .enable = noop,
  94. .disable = noop,
  95. .ack = noop,
  96. .mask = noop,
  97. .unmask = noop,
  98. .end = noop,
  99. };
  100. /*
  101. * Special, empty irq handler:
  102. */
  103. irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
  104. {
  105. return IRQ_NONE;
  106. }
  107. /**
  108. * handle_IRQ_event - irq action chain handler
  109. * @irq: the interrupt number
  110. * @regs: pointer to a register structure
  111. * @action: the interrupt action chain for this irq
  112. *
  113. * Handles the action chain of an irq event
  114. */
  115. irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
  116. struct irqaction *action)
  117. {
  118. irqreturn_t ret, retval = IRQ_NONE;
  119. unsigned int status = 0;
  120. handle_dynamic_tick(action);
  121. if (!(action->flags & IRQF_DISABLED))
  122. local_irq_enable_in_hardirq();
  123. do {
  124. ret = action->handler(irq, action->dev_id, regs);
  125. if (ret == IRQ_HANDLED)
  126. status |= action->flags;
  127. retval |= ret;
  128. action = action->next;
  129. } while (action);
  130. if (status & IRQF_SAMPLE_RANDOM)
  131. add_interrupt_randomness(irq);
  132. local_irq_disable();
  133. return retval;
  134. }
  135. /**
  136. * __do_IRQ - original all in one highlevel IRQ handler
  137. * @irq: the interrupt number
  138. * @regs: pointer to a register structure
  139. *
  140. * __do_IRQ handles all normal device IRQ's (the special
  141. * SMP cross-CPU interrupts have their own specific
  142. * handlers).
  143. *
  144. * This is the original x86 implementation which is used for every
  145. * interrupt type.
  146. */
  147. fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
  148. {
  149. struct irq_desc *desc = irq_desc + irq;
  150. struct irqaction *action;
  151. unsigned int status;
  152. kstat_this_cpu.irqs[irq]++;
  153. if (CHECK_IRQ_PER_CPU(desc->status)) {
  154. irqreturn_t action_ret;
  155. /*
  156. * No locking required for CPU-local interrupts:
  157. */
  158. if (desc->chip->ack)
  159. desc->chip->ack(irq);
  160. action_ret = handle_IRQ_event(irq, regs, desc->action);
  161. desc->chip->end(irq);
  162. return 1;
  163. }
  164. spin_lock(&desc->lock);
  165. if (desc->chip->ack)
  166. desc->chip->ack(irq);
  167. /*
  168. * REPLAY is when Linux resends an IRQ that was dropped earlier
  169. * WAITING is used by probe to mark irqs that are being tested
  170. */
  171. status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
  172. status |= IRQ_PENDING; /* we _want_ to handle it */
  173. /*
  174. * If the IRQ is disabled for whatever reason, we cannot
  175. * use the action we have.
  176. */
  177. action = NULL;
  178. if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
  179. action = desc->action;
  180. status &= ~IRQ_PENDING; /* we commit to handling */
  181. status |= IRQ_INPROGRESS; /* we are handling it */
  182. }
  183. desc->status = status;
  184. /*
  185. * If there is no IRQ handler or it was disabled, exit early.
  186. * Since we set PENDING, if another processor is handling
  187. * a different instance of this same irq, the other processor
  188. * will take care of it.
  189. */
  190. if (unlikely(!action))
  191. goto out;
  192. /*
  193. * Edge triggered interrupts need to remember
  194. * pending events.
  195. * This applies to any hw interrupts that allow a second
  196. * instance of the same irq to arrive while we are in do_IRQ
  197. * or in the handler. But the code here only handles the _second_
  198. * instance of the irq, not the third or fourth. So it is mostly
  199. * useful for irq hardware that does not mask cleanly in an
  200. * SMP environment.
  201. */
  202. for (;;) {
  203. irqreturn_t action_ret;
  204. spin_unlock(&desc->lock);
  205. action_ret = handle_IRQ_event(irq, regs, action);
  206. spin_lock(&desc->lock);
  207. if (!noirqdebug)
  208. note_interrupt(irq, desc, action_ret, regs);
  209. if (likely(!(desc->status & IRQ_PENDING)))
  210. break;
  211. desc->status &= ~IRQ_PENDING;
  212. }
  213. desc->status &= ~IRQ_INPROGRESS;
  214. out:
  215. /*
  216. * The ->end() handler has to deal with interrupts which got
  217. * disabled while the handler was running.
  218. */
  219. desc->chip->end(irq);
  220. spin_unlock(&desc->lock);
  221. return 1;
  222. }
  223. #ifdef CONFIG_TRACE_IRQFLAGS
  224. /*
  225. * lockdep: we want to handle all irq_desc locks as a single lock-class:
  226. */
  227. static struct lock_class_key irq_desc_lock_class;
  228. void early_init_irq_lock_class(void)
  229. {
  230. int i;
  231. for (i = 0; i < NR_IRQS; i++)
  232. lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
  233. }
  234. #endif