irq.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #ifndef __irq_h
  2. #define __irq_h
  3. /*
  4. * Please do not include this file in generic code. There is currently
  5. * no requirement for any architecture to implement anything held
  6. * within this file.
  7. *
  8. * Thanks. --rmk
  9. */
  10. #include <linux/config.h>
  11. #if !defined(CONFIG_ARCH_S390)
  12. #include <linux/linkage.h>
  13. #include <linux/cache.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/cpumask.h>
  16. #include <asm/irq.h>
  17. #include <asm/ptrace.h>
  18. /*
  19. * IRQ line status.
  20. */
  21. #define IRQ_INPROGRESS 1 /* IRQ handler active - do not enter! */
  22. #define IRQ_DISABLED 2 /* IRQ disabled - do not enter! */
  23. #define IRQ_PENDING 4 /* IRQ pending - replay on enable */
  24. #define IRQ_REPLAY 8 /* IRQ has been replayed but not acked yet */
  25. #define IRQ_AUTODETECT 16 /* IRQ is being autodetected */
  26. #define IRQ_WAITING 32 /* IRQ not yet seen - for autodetection */
  27. #define IRQ_LEVEL 64 /* IRQ level triggered */
  28. #define IRQ_MASKED 128 /* IRQ masked - shouldn't be seen again */
  29. #if defined(ARCH_HAS_IRQ_PER_CPU)
  30. # define IRQ_PER_CPU 256 /* IRQ is per CPU */
  31. # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
  32. #else
  33. # define CHECK_IRQ_PER_CPU(var) 0
  34. #endif
  35. /*
  36. * Interrupt controller descriptor. This is all we need
  37. * to describe about the low-level hardware.
  38. */
  39. struct hw_interrupt_type {
  40. const char * typename;
  41. unsigned int (*startup)(unsigned int irq);
  42. void (*shutdown)(unsigned int irq);
  43. void (*enable)(unsigned int irq);
  44. void (*disable)(unsigned int irq);
  45. void (*ack)(unsigned int irq);
  46. void (*end)(unsigned int irq);
  47. void (*set_affinity)(unsigned int irq, cpumask_t dest);
  48. /* Currently used only by UML, might disappear one day.*/
  49. #ifdef CONFIG_IRQ_RELEASE_METHOD
  50. void (*release)(unsigned int irq, void *dev_id);
  51. #endif
  52. };
  53. typedef struct hw_interrupt_type hw_irq_controller;
  54. /*
  55. * This is the "IRQ descriptor", which contains various information
  56. * about the irq, including what kind of hardware handling it has,
  57. * whether it is disabled etc etc.
  58. *
  59. * Pad this out to 32 bytes for cache and indexing reasons.
  60. */
  61. typedef struct irq_desc {
  62. hw_irq_controller *handler;
  63. void *handler_data;
  64. struct irqaction *action; /* IRQ action list */
  65. unsigned int status; /* IRQ status */
  66. unsigned int depth; /* nested irq disables */
  67. unsigned int irq_count; /* For detecting broken interrupts */
  68. unsigned int irqs_unhandled;
  69. spinlock_t lock;
  70. #if defined (CONFIG_GENERIC_PENDING_IRQ) || defined (CONFIG_IRQBALANCE)
  71. unsigned int move_irq; /* Flag need to re-target intr dest*/
  72. #endif
  73. } ____cacheline_aligned irq_desc_t;
  74. extern irq_desc_t irq_desc [NR_IRQS];
  75. /* Return a pointer to the irq descriptor for IRQ. */
  76. static inline irq_desc_t *
  77. irq_descp (int irq)
  78. {
  79. return irq_desc + irq;
  80. }
  81. #include <asm/hw_irq.h> /* the arch dependent stuff */
  82. extern int setup_irq(unsigned int irq, struct irqaction * new);
  83. #ifdef CONFIG_GENERIC_HARDIRQS
  84. extern cpumask_t irq_affinity[NR_IRQS];
  85. #ifdef CONFIG_SMP
  86. static inline void set_native_irq_info(int irq, cpumask_t mask)
  87. {
  88. irq_affinity[irq] = mask;
  89. }
  90. #else
  91. static inline void set_native_irq_info(int irq, cpumask_t mask)
  92. {
  93. }
  94. #endif
  95. #ifdef CONFIG_SMP
  96. #if defined (CONFIG_GENERIC_PENDING_IRQ) || defined (CONFIG_IRQBALANCE)
  97. extern cpumask_t pending_irq_cpumask[NR_IRQS];
  98. static inline void set_pending_irq(unsigned int irq, cpumask_t mask)
  99. {
  100. irq_desc_t *desc = irq_desc + irq;
  101. unsigned long flags;
  102. spin_lock_irqsave(&desc->lock, flags);
  103. desc->move_irq = 1;
  104. pending_irq_cpumask[irq] = mask;
  105. spin_unlock_irqrestore(&desc->lock, flags);
  106. }
  107. static inline void
  108. move_native_irq(int irq)
  109. {
  110. cpumask_t tmp;
  111. irq_desc_t *desc = irq_descp(irq);
  112. if (likely (!desc->move_irq))
  113. return;
  114. desc->move_irq = 0;
  115. if (likely(cpus_empty(pending_irq_cpumask[irq])))
  116. return;
  117. if (!desc->handler->set_affinity)
  118. return;
  119. /* note - we hold the desc->lock */
  120. cpus_and(tmp, pending_irq_cpumask[irq], cpu_online_map);
  121. /*
  122. * If there was a valid mask to work with, please
  123. * do the disable, re-program, enable sequence.
  124. * This is *not* particularly important for level triggered
  125. * but in a edge trigger case, we might be setting rte
  126. * when an active trigger is comming in. This could
  127. * cause some ioapics to mal-function.
  128. * Being paranoid i guess!
  129. */
  130. if (unlikely(!cpus_empty(tmp))) {
  131. desc->handler->disable(irq);
  132. desc->handler->set_affinity(irq,tmp);
  133. desc->handler->enable(irq);
  134. }
  135. cpus_clear(pending_irq_cpumask[irq]);
  136. }
  137. #ifdef CONFIG_PCI_MSI
  138. /*
  139. * Wonder why these are dummies?
  140. * For e.g the set_ioapic_affinity_vector() calls the set_ioapic_affinity_irq()
  141. * counter part after translating the vector to irq info. We need to perform
  142. * this operation on the real irq, when we dont use vector, i.e when
  143. * pci_use_vector() is false.
  144. */
  145. static inline void move_irq(int irq)
  146. {
  147. }
  148. static inline void set_irq_info(int irq, cpumask_t mask)
  149. {
  150. }
  151. #else // CONFIG_PCI_MSI
  152. static inline void move_irq(int irq)
  153. {
  154. move_native_irq(irq);
  155. }
  156. static inline void set_irq_info(int irq, cpumask_t mask)
  157. {
  158. set_native_irq_info(irq, mask);
  159. }
  160. #endif // CONFIG_PCI_MSI
  161. #else // CONFIG_GENERIC_PENDING_IRQ || CONFIG_IRQBALANCE
  162. #define move_irq(x)
  163. #define move_native_irq(x)
  164. #define set_pending_irq(x,y)
  165. static inline void set_irq_info(int irq, cpumask_t mask)
  166. {
  167. set_native_irq_info(irq, mask);
  168. }
  169. #endif // CONFIG_GENERIC_PENDING_IRQ
  170. #else // CONFIG_SMP
  171. #define move_irq(x)
  172. #define move_native_irq(x)
  173. #endif // CONFIG_SMP
  174. extern int no_irq_affinity;
  175. extern int noirqdebug_setup(char *str);
  176. extern fastcall int handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
  177. struct irqaction *action);
  178. extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
  179. extern void note_interrupt(unsigned int irq, irq_desc_t *desc,
  180. int action_ret, struct pt_regs *regs);
  181. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  182. extern void init_irq_proc(void);
  183. #endif
  184. extern hw_irq_controller no_irq_type; /* needed in every arch ? */
  185. #endif
  186. #endif /* __irq_h */