irq.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. #ifndef _LINUX_IRQ_H
  2. #define _LINUX_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/smp.h>
  11. #ifndef CONFIG_S390
  12. #include <linux/linkage.h>
  13. #include <linux/cache.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/cpumask.h>
  16. #include <linux/irqreturn.h>
  17. #include <asm/irq.h>
  18. #include <asm/ptrace.h>
  19. /*
  20. * IRQ line status.
  21. */
  22. #define IRQ_INPROGRESS 1 /* IRQ handler active - do not enter! */
  23. #define IRQ_DISABLED 2 /* IRQ disabled - do not enter! */
  24. #define IRQ_PENDING 4 /* IRQ pending - replay on enable */
  25. #define IRQ_REPLAY 8 /* IRQ has been replayed but not acked yet */
  26. #define IRQ_AUTODETECT 16 /* IRQ is being autodetected */
  27. #define IRQ_WAITING 32 /* IRQ not yet seen - for autodetection */
  28. #define IRQ_LEVEL 64 /* IRQ level triggered */
  29. #define IRQ_MASKED 128 /* IRQ masked - shouldn't be seen again */
  30. #ifdef CONFIG_IRQ_PER_CPU
  31. # define IRQ_PER_CPU 256 /* IRQ is per CPU */
  32. # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
  33. #else
  34. # define CHECK_IRQ_PER_CPU(var) 0
  35. #endif
  36. #define IRQ_NOPROBE 512 /* IRQ is not valid for probing */
  37. #define IRQ_NOREQUEST 1024 /* IRQ cannot be requested */
  38. #define IRQ_NOAUTOEN 2048 /* IRQ will not be enabled on request irq */
  39. #define IRQ_DELAYED_DISABLE \
  40. 4096 /* IRQ disable (masking) happens delayed. */
  41. /*
  42. * IRQ types, see also include/linux/interrupt.h
  43. */
  44. #define IRQ_TYPE_NONE 0x0000 /* Default, unspecified type */
  45. #define IRQ_TYPE_EDGE_RISING 0x0001 /* Edge rising type */
  46. #define IRQ_TYPE_EDGE_FALLING 0x0002 /* Edge falling type */
  47. #define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
  48. #define IRQ_TYPE_LEVEL_HIGH 0x0004 /* Level high type */
  49. #define IRQ_TYPE_LEVEL_LOW 0x0008 /* Level low type */
  50. #define IRQ_TYPE_SIMPLE 0x0010 /* Simple type */
  51. #define IRQ_TYPE_PERCPU 0x0020 /* Per CPU type */
  52. #define IRQ_TYPE_PROBE 0x0040 /* Probing in progress */
  53. struct proc_dir_entry;
  54. /**
  55. * struct irq_chip - hardware interrupt chip descriptor
  56. *
  57. * @name: name for /proc/interrupts
  58. * @startup: start up the interrupt (defaults to ->enable if NULL)
  59. * @shutdown: shut down the interrupt (defaults to ->disable if NULL)
  60. * @enable: enable the interrupt (defaults to chip->unmask if NULL)
  61. * @disable: disable the interrupt (defaults to chip->mask if NULL)
  62. * @ack: start of a new interrupt
  63. * @mask: mask an interrupt source
  64. * @mask_ack: ack and mask an interrupt source
  65. * @unmask: unmask an interrupt source
  66. * @end: end of interrupt
  67. * @set_affinity: set the CPU affinity on SMP machines
  68. * @retrigger: resend an IRQ to the CPU
  69. * @set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  70. * @set_wake: enable/disable power-management wake-on of an IRQ
  71. *
  72. * @release: release function solely used by UML
  73. * @typename: obsoleted by name, kept as migration helper
  74. */
  75. struct irq_chip {
  76. const char *name;
  77. unsigned int (*startup)(unsigned int irq);
  78. void (*shutdown)(unsigned int irq);
  79. void (*enable)(unsigned int irq);
  80. void (*disable)(unsigned int irq);
  81. void (*ack)(unsigned int irq);
  82. void (*mask)(unsigned int irq);
  83. void (*mask_ack)(unsigned int irq);
  84. void (*unmask)(unsigned int irq);
  85. void (*end)(unsigned int irq);
  86. void (*set_affinity)(unsigned int irq, cpumask_t dest);
  87. int (*retrigger)(unsigned int irq);
  88. int (*set_type)(unsigned int irq, unsigned int flow_type);
  89. int (*set_wake)(unsigned int irq, unsigned int on);
  90. /* Currently used only by UML, might disappear one day.*/
  91. #ifdef CONFIG_IRQ_RELEASE_METHOD
  92. void (*release)(unsigned int irq, void *dev_id);
  93. #endif
  94. /*
  95. * For compatibility, ->typename is copied into ->name.
  96. * Will disappear.
  97. */
  98. const char *typename;
  99. };
  100. /**
  101. * struct irq_desc - interrupt descriptor
  102. *
  103. * @handle_irq: highlevel irq-events handler [if NULL, __do_IRQ()]
  104. * @chip: low level interrupt hardware access
  105. * @handler_data: per-IRQ data for the irq_chip methods
  106. * @chip_data: platform-specific per-chip private data for the chip
  107. * methods, to allow shared chip implementations
  108. * @action: the irq action chain
  109. * @status: status information
  110. * @depth: disable-depth, for nested irq_disable() calls
  111. * @irq_count: stats field to detect stalled irqs
  112. * @irqs_unhandled: stats field for spurious unhandled interrupts
  113. * @lock: locking for SMP
  114. * @affinity: IRQ affinity on SMP
  115. * @cpu: cpu index useful for balancing
  116. * @pending_mask: pending rebalanced interrupts
  117. * @move_irq: need to re-target IRQ destination
  118. * @dir: /proc/irq/ procfs entry
  119. * @affinity_entry: /proc/irq/smp_affinity procfs entry on SMP
  120. *
  121. * Pad this out to 32 bytes for cache and indexing reasons.
  122. */
  123. struct irq_desc {
  124. void fastcall (*handle_irq)(unsigned int irq,
  125. struct irq_desc *desc,
  126. struct pt_regs *regs);
  127. struct irq_chip *chip;
  128. void *handler_data;
  129. void *chip_data;
  130. struct irqaction *action; /* IRQ action list */
  131. unsigned int status; /* IRQ status */
  132. unsigned int depth; /* nested irq disables */
  133. unsigned int irq_count; /* For detecting broken IRQs */
  134. unsigned int irqs_unhandled;
  135. spinlock_t lock;
  136. #ifdef CONFIG_SMP
  137. cpumask_t affinity;
  138. unsigned int cpu;
  139. #endif
  140. #if defined(CONFIG_GENERIC_PENDING_IRQ) || defined(CONFIG_IRQBALANCE)
  141. cpumask_t pending_mask;
  142. unsigned int move_irq; /* need to re-target IRQ dest */
  143. #endif
  144. #ifdef CONFIG_PROC_FS
  145. struct proc_dir_entry *dir;
  146. #endif
  147. } ____cacheline_aligned;
  148. extern struct irq_desc irq_desc[NR_IRQS];
  149. /*
  150. * Migration helpers for obsolete names, they will go away:
  151. */
  152. #define hw_interrupt_type irq_chip
  153. typedef struct irq_chip hw_irq_controller;
  154. #define no_irq_type no_irq_chip
  155. typedef struct irq_desc irq_desc_t;
  156. /*
  157. * Pick up the arch-dependent methods:
  158. */
  159. #include <asm/hw_irq.h>
  160. extern int setup_irq(unsigned int irq, struct irqaction *new);
  161. #ifdef CONFIG_GENERIC_HARDIRQS
  162. #ifdef CONFIG_SMP
  163. static inline void set_native_irq_info(int irq, cpumask_t mask)
  164. {
  165. irq_desc[irq].affinity = mask;
  166. }
  167. #else
  168. static inline void set_native_irq_info(int irq, cpumask_t mask)
  169. {
  170. }
  171. #endif
  172. #ifdef CONFIG_SMP
  173. #if defined(CONFIG_GENERIC_PENDING_IRQ) || defined(CONFIG_IRQBALANCE)
  174. void set_pending_irq(unsigned int irq, cpumask_t mask);
  175. void move_native_irq(int irq);
  176. #ifdef CONFIG_PCI_MSI
  177. /*
  178. * Wonder why these are dummies?
  179. * For e.g the set_ioapic_affinity_vector() calls the set_ioapic_affinity_irq()
  180. * counter part after translating the vector to irq info. We need to perform
  181. * this operation on the real irq, when we dont use vector, i.e when
  182. * pci_use_vector() is false.
  183. */
  184. static inline void move_irq(int irq)
  185. {
  186. }
  187. static inline void set_irq_info(int irq, cpumask_t mask)
  188. {
  189. }
  190. #else /* CONFIG_PCI_MSI */
  191. static inline void move_irq(int irq)
  192. {
  193. move_native_irq(irq);
  194. }
  195. static inline void set_irq_info(int irq, cpumask_t mask)
  196. {
  197. set_native_irq_info(irq, mask);
  198. }
  199. #endif /* CONFIG_PCI_MSI */
  200. #else /* CONFIG_GENERIC_PENDING_IRQ || CONFIG_IRQBALANCE */
  201. static inline void move_irq(int irq)
  202. {
  203. }
  204. static inline void move_native_irq(int irq)
  205. {
  206. }
  207. static inline void set_pending_irq(unsigned int irq, cpumask_t mask)
  208. {
  209. }
  210. static inline void set_irq_info(int irq, cpumask_t mask)
  211. {
  212. set_native_irq_info(irq, mask);
  213. }
  214. #endif /* CONFIG_GENERIC_PENDING_IRQ */
  215. #else /* CONFIG_SMP */
  216. #define move_irq(x)
  217. #define move_native_irq(x)
  218. #endif /* CONFIG_SMP */
  219. #ifdef CONFIG_IRQBALANCE
  220. extern void set_balance_irq_affinity(unsigned int irq, cpumask_t mask);
  221. #else
  222. static inline void set_balance_irq_affinity(unsigned int irq, cpumask_t mask)
  223. {
  224. }
  225. #endif
  226. #ifdef CONFIG_AUTO_IRQ_AFFINITY
  227. extern int select_smp_affinity(unsigned int irq);
  228. #else
  229. static inline int select_smp_affinity(unsigned int irq)
  230. {
  231. return 1;
  232. }
  233. #endif
  234. extern int no_irq_affinity;
  235. /* Handle irq action chains: */
  236. extern int handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
  237. struct irqaction *action);
  238. /*
  239. * Built-in IRQ handlers for various IRQ types,
  240. * callable via desc->chip->handle_irq()
  241. */
  242. extern void fastcall
  243. handle_level_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs);
  244. extern void fastcall
  245. handle_fastack_irq(unsigned int irq, struct irq_desc *desc,
  246. struct pt_regs *regs);
  247. extern void fastcall
  248. handle_edge_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs);
  249. extern void fastcall
  250. handle_simple_irq(unsigned int irq, struct irq_desc *desc,
  251. struct pt_regs *regs);
  252. extern void fastcall
  253. handle_percpu_irq(unsigned int irq, struct irq_desc *desc,
  254. struct pt_regs *regs);
  255. extern void fastcall
  256. handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs);
  257. /*
  258. * Get a descriptive string for the highlevel handler, for
  259. * /proc/interrupts output:
  260. */
  261. extern const char *
  262. handle_irq_name(void fastcall (*handle)(unsigned int, struct irq_desc *,
  263. struct pt_regs *));
  264. /*
  265. * Monolithic do_IRQ implementation.
  266. * (is an explicit fastcall, because i386 4KSTACKS calls it from assembly)
  267. */
  268. extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
  269. /*
  270. * Architectures call this to let the generic IRQ layer
  271. * handle an interrupt. If the descriptor is attached to an
  272. * irqchip-style controller then we call the ->handle_irq() handler,
  273. * and it calls __do_IRQ() if it's attached to an irqtype-style controller.
  274. */
  275. static inline void generic_handle_irq(unsigned int irq, struct pt_regs *regs)
  276. {
  277. struct irq_desc *desc = irq_desc + irq;
  278. if (likely(desc->handle_irq))
  279. desc->handle_irq(irq, desc, regs);
  280. else
  281. __do_IRQ(irq, regs);
  282. }
  283. /* Handling of unhandled and spurious interrupts: */
  284. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  285. int action_ret, struct pt_regs *regs);
  286. /* Resending of interrupts :*/
  287. void check_irq_resend(struct irq_desc *desc, unsigned int irq);
  288. /* Initialize /proc/irq/ */
  289. extern void init_irq_proc(void);
  290. /* Enable/disable irq debugging output: */
  291. extern int noirqdebug_setup(char *str);
  292. /* Checks whether the interrupt can be requested by request_irq(): */
  293. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  294. /* Dummy irq-chip implementation: */
  295. extern struct irq_chip no_irq_chip;
  296. extern void
  297. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  298. void fastcall (*handle)(unsigned int,
  299. struct irq_desc *,
  300. struct pt_regs *));
  301. extern void
  302. __set_irq_handler(unsigned int irq,
  303. void fastcall (*handle)(unsigned int, struct irq_desc *,
  304. struct pt_regs *),
  305. int is_chained);
  306. /*
  307. * Set a highlevel flow handler for a given IRQ:
  308. */
  309. static inline void
  310. set_irq_handler(unsigned int irq,
  311. void fastcall (*handle)(unsigned int, struct irq_desc *,
  312. struct pt_regs *))
  313. {
  314. __set_irq_handler(irq, handle, 0);
  315. }
  316. /*
  317. * Set a highlevel chained flow handler for a given IRQ.
  318. * (a chained handler is automatically enabled and set to
  319. * IRQ_NOREQUEST and IRQ_NOPROBE)
  320. */
  321. static inline void
  322. set_irq_chained_handler(unsigned int irq,
  323. void fastcall (*handle)(unsigned int, struct irq_desc *,
  324. struct pt_regs *))
  325. {
  326. __set_irq_handler(irq, handle, 1);
  327. }
  328. #endif /* CONFIG_GENERIC_HARDIRQS */
  329. #endif /* !CONFIG_S390 */
  330. #endif /* _LINUX_IRQ_H */