irq.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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_GENERIC_HARDIRQS
  12. # define nr_irqs NR_IRQS
  13. # define for_each_irq_desc(irq, desc) \
  14. for (irq = 0; irq < nr_irqs; irq++)
  15. #else
  16. extern int nr_irqs;
  17. # define for_each_irq_desc(irq, desc) \
  18. for (irq = 0, desc = irq_desc; irq < nr_irqs; irq++, desc++)
  19. #endif
  20. #ifndef CONFIG_S390
  21. #include <linux/linkage.h>
  22. #include <linux/cache.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/cpumask.h>
  25. #include <linux/irqreturn.h>
  26. #include <linux/errno.h>
  27. #include <asm/irq.h>
  28. #include <asm/ptrace.h>
  29. #include <asm/irq_regs.h>
  30. struct irq_desc;
  31. typedef void (*irq_flow_handler_t)(unsigned int irq,
  32. struct irq_desc *desc);
  33. /*
  34. * IRQ line status.
  35. *
  36. * Bits 0-7 are reserved for the IRQF_* bits in linux/interrupt.h
  37. *
  38. * IRQ types
  39. */
  40. #define IRQ_TYPE_NONE 0x00000000 /* Default, unspecified type */
  41. #define IRQ_TYPE_EDGE_RISING 0x00000001 /* Edge rising type */
  42. #define IRQ_TYPE_EDGE_FALLING 0x00000002 /* Edge falling type */
  43. #define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
  44. #define IRQ_TYPE_LEVEL_HIGH 0x00000004 /* Level high type */
  45. #define IRQ_TYPE_LEVEL_LOW 0x00000008 /* Level low type */
  46. #define IRQ_TYPE_SENSE_MASK 0x0000000f /* Mask of the above */
  47. #define IRQ_TYPE_PROBE 0x00000010 /* Probing in progress */
  48. /* Internal flags */
  49. #define IRQ_INPROGRESS 0x00000100 /* IRQ handler active - do not enter! */
  50. #define IRQ_DISABLED 0x00000200 /* IRQ disabled - do not enter! */
  51. #define IRQ_PENDING 0x00000400 /* IRQ pending - replay on enable */
  52. #define IRQ_REPLAY 0x00000800 /* IRQ has been replayed but not acked yet */
  53. #define IRQ_AUTODETECT 0x00001000 /* IRQ is being autodetected */
  54. #define IRQ_WAITING 0x00002000 /* IRQ not yet seen - for autodetection */
  55. #define IRQ_LEVEL 0x00004000 /* IRQ level triggered */
  56. #define IRQ_MASKED 0x00008000 /* IRQ masked - shouldn't be seen again */
  57. #define IRQ_PER_CPU 0x00010000 /* IRQ is per CPU */
  58. #define IRQ_NOPROBE 0x00020000 /* IRQ is not valid for probing */
  59. #define IRQ_NOREQUEST 0x00040000 /* IRQ cannot be requested */
  60. #define IRQ_NOAUTOEN 0x00080000 /* IRQ will not be enabled on request irq */
  61. #define IRQ_WAKEUP 0x00100000 /* IRQ triggers system wakeup */
  62. #define IRQ_MOVE_PENDING 0x00200000 /* need to re-target IRQ destination */
  63. #define IRQ_NO_BALANCING 0x00400000 /* IRQ is excluded from balancing */
  64. #define IRQ_SPURIOUS_DISABLED 0x00800000 /* IRQ was disabled by the spurious trap */
  65. #define IRQ_MOVE_PCNTXT 0x01000000 /* IRQ migration from process context */
  66. #ifdef CONFIG_IRQ_PER_CPU
  67. # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
  68. # define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  69. #else
  70. # define CHECK_IRQ_PER_CPU(var) 0
  71. # define IRQ_NO_BALANCING_MASK IRQ_NO_BALANCING
  72. #endif
  73. struct proc_dir_entry;
  74. struct msi_desc;
  75. /**
  76. * struct irq_chip - hardware interrupt chip descriptor
  77. *
  78. * @name: name for /proc/interrupts
  79. * @startup: start up the interrupt (defaults to ->enable if NULL)
  80. * @shutdown: shut down the interrupt (defaults to ->disable if NULL)
  81. * @enable: enable the interrupt (defaults to chip->unmask if NULL)
  82. * @disable: disable the interrupt (defaults to chip->mask if NULL)
  83. * @ack: start of a new interrupt
  84. * @mask: mask an interrupt source
  85. * @mask_ack: ack and mask an interrupt source
  86. * @unmask: unmask an interrupt source
  87. * @eoi: end of interrupt - chip level
  88. * @end: end of interrupt - flow level
  89. * @set_affinity: set the CPU affinity on SMP machines
  90. * @retrigger: resend an IRQ to the CPU
  91. * @set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  92. * @set_wake: enable/disable power-management wake-on of an IRQ
  93. *
  94. * @release: release function solely used by UML
  95. * @typename: obsoleted by name, kept as migration helper
  96. */
  97. struct irq_chip {
  98. const char *name;
  99. unsigned int (*startup)(unsigned int irq);
  100. void (*shutdown)(unsigned int irq);
  101. void (*enable)(unsigned int irq);
  102. void (*disable)(unsigned int irq);
  103. void (*ack)(unsigned int irq);
  104. void (*mask)(unsigned int irq);
  105. void (*mask_ack)(unsigned int irq);
  106. void (*unmask)(unsigned int irq);
  107. void (*eoi)(unsigned int irq);
  108. void (*end)(unsigned int irq);
  109. void (*set_affinity)(unsigned int irq, cpumask_t dest);
  110. int (*retrigger)(unsigned int irq);
  111. int (*set_type)(unsigned int irq, unsigned int flow_type);
  112. int (*set_wake)(unsigned int irq, unsigned int on);
  113. /* Currently used only by UML, might disappear one day.*/
  114. #ifdef CONFIG_IRQ_RELEASE_METHOD
  115. void (*release)(unsigned int irq, void *dev_id);
  116. #endif
  117. /*
  118. * For compatibility, ->typename is copied into ->name.
  119. * Will disappear.
  120. */
  121. const char *typename;
  122. };
  123. /**
  124. * struct irq_desc - interrupt descriptor
  125. *
  126. * @handle_irq: highlevel irq-events handler [if NULL, __do_IRQ()]
  127. * @chip: low level interrupt hardware access
  128. * @msi_desc: MSI descriptor
  129. * @handler_data: per-IRQ data for the irq_chip methods
  130. * @chip_data: platform-specific per-chip private data for the chip
  131. * methods, to allow shared chip implementations
  132. * @action: the irq action chain
  133. * @status: status information
  134. * @depth: disable-depth, for nested irq_disable() calls
  135. * @wake_depth: enable depth, for multiple set_irq_wake() callers
  136. * @irq_count: stats field to detect stalled irqs
  137. * @irqs_unhandled: stats field for spurious unhandled interrupts
  138. * @last_unhandled: aging timer for unhandled count
  139. * @lock: locking for SMP
  140. * @affinity: IRQ affinity on SMP
  141. * @cpu: cpu index useful for balancing
  142. * @pending_mask: pending rebalanced interrupts
  143. * @dir: /proc/irq/ procfs entry
  144. * @affinity_entry: /proc/irq/smp_affinity procfs entry on SMP
  145. * @name: flow handler name for /proc/interrupts output
  146. */
  147. struct irq_desc {
  148. unsigned int irq;
  149. irq_flow_handler_t handle_irq;
  150. struct irq_chip *chip;
  151. struct msi_desc *msi_desc;
  152. void *handler_data;
  153. void *chip_data;
  154. struct irqaction *action; /* IRQ action list */
  155. unsigned int status; /* IRQ status */
  156. unsigned int depth; /* nested irq disables */
  157. unsigned int wake_depth; /* nested wake enables */
  158. unsigned int irq_count; /* For detecting broken IRQs */
  159. unsigned int irqs_unhandled;
  160. unsigned long last_unhandled; /* Aging timer for unhandled count */
  161. spinlock_t lock;
  162. #ifdef CONFIG_SMP
  163. cpumask_t affinity;
  164. unsigned int cpu;
  165. #endif
  166. #ifdef CONFIG_GENERIC_PENDING_IRQ
  167. cpumask_t pending_mask;
  168. #endif
  169. #ifdef CONFIG_PROC_FS
  170. struct proc_dir_entry *dir;
  171. #endif
  172. const char *name;
  173. } ____cacheline_internodealigned_in_smp;
  174. extern struct irq_desc irq_desc[NR_IRQS];
  175. static inline struct irq_desc *irq_to_desc(unsigned int irq)
  176. {
  177. return (irq < nr_irqs) ? irq_desc + irq : NULL;
  178. }
  179. /*
  180. * Migration helpers for obsolete names, they will go away:
  181. */
  182. #define hw_interrupt_type irq_chip
  183. typedef struct irq_chip hw_irq_controller;
  184. #define no_irq_type no_irq_chip
  185. typedef struct irq_desc irq_desc_t;
  186. /*
  187. * Pick up the arch-dependent methods:
  188. */
  189. #include <asm/hw_irq.h>
  190. extern int setup_irq(unsigned int irq, struct irqaction *new);
  191. #ifdef CONFIG_GENERIC_HARDIRQS
  192. #ifdef CONFIG_SMP
  193. #ifdef CONFIG_GENERIC_PENDING_IRQ
  194. void set_pending_irq(unsigned int irq, cpumask_t mask);
  195. void move_native_irq(int irq);
  196. void move_masked_irq(int irq);
  197. #else /* CONFIG_GENERIC_PENDING_IRQ */
  198. static inline void move_irq(int irq)
  199. {
  200. }
  201. static inline void move_native_irq(int irq)
  202. {
  203. }
  204. static inline void move_masked_irq(int irq)
  205. {
  206. }
  207. static inline void set_pending_irq(unsigned int irq, cpumask_t mask)
  208. {
  209. }
  210. #endif /* CONFIG_GENERIC_PENDING_IRQ */
  211. #else /* CONFIG_SMP */
  212. #define move_native_irq(x)
  213. #define move_masked_irq(x)
  214. #endif /* CONFIG_SMP */
  215. extern int no_irq_affinity;
  216. static inline int irq_balancing_disabled(unsigned int irq)
  217. {
  218. struct irq_desc *desc;
  219. desc = irq_to_desc(irq);
  220. return desc->status & IRQ_NO_BALANCING_MASK;
  221. }
  222. /* Handle irq action chains: */
  223. extern int handle_IRQ_event(unsigned int irq, struct irqaction *action);
  224. /*
  225. * Built-in IRQ handlers for various IRQ types,
  226. * callable via desc->chip->handle_irq()
  227. */
  228. extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
  229. extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
  230. extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
  231. extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
  232. extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
  233. extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
  234. /*
  235. * Monolithic do_IRQ implementation.
  236. */
  237. #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
  238. extern unsigned int __do_IRQ(unsigned int irq);
  239. #endif
  240. /*
  241. * Architectures call this to let the generic IRQ layer
  242. * handle an interrupt. If the descriptor is attached to an
  243. * irqchip-style controller then we call the ->handle_irq() handler,
  244. * and it calls __do_IRQ() if it's attached to an irqtype-style controller.
  245. */
  246. static inline void generic_handle_irq_desc(unsigned int irq, struct irq_desc *desc)
  247. {
  248. #ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
  249. desc->handle_irq(irq, desc);
  250. #else
  251. if (likely(desc->handle_irq))
  252. desc->handle_irq(irq, desc);
  253. else
  254. __do_IRQ(irq);
  255. #endif
  256. }
  257. static inline void generic_handle_irq(unsigned int irq)
  258. {
  259. generic_handle_irq_desc(irq, irq_to_desc(irq));
  260. }
  261. /* Handling of unhandled and spurious interrupts: */
  262. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  263. int action_ret);
  264. /* Resending of interrupts :*/
  265. void check_irq_resend(struct irq_desc *desc, unsigned int irq);
  266. /* Enable/disable irq debugging output: */
  267. extern int noirqdebug_setup(char *str);
  268. /* Checks whether the interrupt can be requested by request_irq(): */
  269. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  270. /* Dummy irq-chip implementations: */
  271. extern struct irq_chip no_irq_chip;
  272. extern struct irq_chip dummy_irq_chip;
  273. extern void
  274. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  275. irq_flow_handler_t handle);
  276. extern void
  277. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  278. irq_flow_handler_t handle, const char *name);
  279. extern void
  280. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  281. const char *name);
  282. /* caller has locked the irq_desc and both params are valid */
  283. static inline void __set_irq_handler_unlocked(int irq,
  284. irq_flow_handler_t handler)
  285. {
  286. struct irq_desc *desc;
  287. desc = irq_to_desc(irq);
  288. desc->handle_irq = handler;
  289. }
  290. /*
  291. * Set a highlevel flow handler for a given IRQ:
  292. */
  293. static inline void
  294. set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
  295. {
  296. __set_irq_handler(irq, handle, 0, NULL);
  297. }
  298. /*
  299. * Set a highlevel chained flow handler for a given IRQ.
  300. * (a chained handler is automatically enabled and set to
  301. * IRQ_NOREQUEST and IRQ_NOPROBE)
  302. */
  303. static inline void
  304. set_irq_chained_handler(unsigned int irq,
  305. irq_flow_handler_t handle)
  306. {
  307. __set_irq_handler(irq, handle, 1, NULL);
  308. }
  309. extern void set_irq_noprobe(unsigned int irq);
  310. extern void set_irq_probe(unsigned int irq);
  311. /* Handle dynamic irq creation and destruction */
  312. extern unsigned int create_irq_nr(unsigned int irq_want);
  313. extern int create_irq(void);
  314. extern void destroy_irq(unsigned int irq);
  315. /* Test to see if a driver has successfully requested an irq */
  316. static inline int irq_has_action(unsigned int irq)
  317. {
  318. struct irq_desc *desc = irq_to_desc(irq);
  319. return desc->action != NULL;
  320. }
  321. /* Dynamic irq helper functions */
  322. extern void dynamic_irq_init(unsigned int irq);
  323. extern void dynamic_irq_cleanup(unsigned int irq);
  324. /* Set/get chip/data for an IRQ: */
  325. extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
  326. extern int set_irq_data(unsigned int irq, void *data);
  327. extern int set_irq_chip_data(unsigned int irq, void *data);
  328. extern int set_irq_type(unsigned int irq, unsigned int type);
  329. extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
  330. #define get_irq_chip(irq) (irq_to_desc(irq)->chip)
  331. #define get_irq_chip_data(irq) (irq_to_desc(irq)->chip_data)
  332. #define get_irq_data(irq) (irq_to_desc(irq)->handler_data)
  333. #define get_irq_msi(irq) (irq_to_desc(irq)->msi_desc)
  334. #endif /* CONFIG_GENERIC_HARDIRQS */
  335. #endif /* !CONFIG_S390 */
  336. #endif /* _LINUX_IRQ_H */