irq.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. struct timer_rand_state;
  124. struct irq_2_iommu;
  125. /**
  126. * struct irq_desc - interrupt descriptor
  127. *
  128. * @handle_irq: highlevel irq-events handler [if NULL, __do_IRQ()]
  129. * @chip: low level interrupt hardware access
  130. * @msi_desc: MSI descriptor
  131. * @handler_data: per-IRQ data for the irq_chip methods
  132. * @chip_data: platform-specific per-chip private data for the chip
  133. * methods, to allow shared chip implementations
  134. * @action: the irq action chain
  135. * @status: status information
  136. * @depth: disable-depth, for nested irq_disable() calls
  137. * @wake_depth: enable depth, for multiple set_irq_wake() callers
  138. * @irq_count: stats field to detect stalled irqs
  139. * @irqs_unhandled: stats field for spurious unhandled interrupts
  140. * @last_unhandled: aging timer for unhandled count
  141. * @lock: locking for SMP
  142. * @affinity: IRQ affinity on SMP
  143. * @cpu: cpu index useful for balancing
  144. * @pending_mask: pending rebalanced interrupts
  145. * @dir: /proc/irq/ procfs entry
  146. * @affinity_entry: /proc/irq/smp_affinity procfs entry on SMP
  147. * @name: flow handler name for /proc/interrupts output
  148. */
  149. struct irq_desc {
  150. unsigned int irq;
  151. #ifdef CONFIG_HAVE_DYN_ARRAY
  152. unsigned int *kstat_irqs;
  153. #endif
  154. irq_flow_handler_t handle_irq;
  155. struct irq_chip *chip;
  156. struct msi_desc *msi_desc;
  157. void *handler_data;
  158. void *chip_data;
  159. struct irqaction *action; /* IRQ action list */
  160. unsigned int status; /* IRQ status */
  161. unsigned int depth; /* nested irq disables */
  162. unsigned int wake_depth; /* nested wake enables */
  163. unsigned int irq_count; /* For detecting broken IRQs */
  164. unsigned int irqs_unhandled;
  165. unsigned long last_unhandled; /* Aging timer for unhandled count */
  166. spinlock_t lock;
  167. #ifdef CONFIG_SMP
  168. cpumask_t affinity;
  169. unsigned int cpu;
  170. #endif
  171. #ifdef CONFIG_GENERIC_PENDING_IRQ
  172. cpumask_t pending_mask;
  173. #endif
  174. #ifdef CONFIG_PROC_FS
  175. struct proc_dir_entry *dir;
  176. #endif
  177. const char *name;
  178. } ____cacheline_internodealigned_in_smp;
  179. #ifndef CONFIG_HAVE_DYN_ARRAY
  180. /* could be removed if we get rid of all irq_desc reference */
  181. extern struct irq_desc irq_desc[NR_IRQS];
  182. #else
  183. extern struct irq_desc *irq_desc;
  184. #endif
  185. static inline struct irq_desc *irq_to_desc(unsigned int irq)
  186. {
  187. return (irq < nr_irqs) ? irq_desc + irq : NULL;
  188. }
  189. #ifdef CONFIG_HAVE_DYN_ARRAY
  190. #define kstat_irqs_this_cpu(DESC) \
  191. ((DESC)->kstat_irqs[smp_processor_id()])
  192. #endif
  193. /*
  194. * Migration helpers for obsolete names, they will go away:
  195. */
  196. #define hw_interrupt_type irq_chip
  197. typedef struct irq_chip hw_irq_controller;
  198. #define no_irq_type no_irq_chip
  199. typedef struct irq_desc irq_desc_t;
  200. /*
  201. * Pick up the arch-dependent methods:
  202. */
  203. #include <asm/hw_irq.h>
  204. extern int setup_irq(unsigned int irq, struct irqaction *new);
  205. #ifdef CONFIG_GENERIC_HARDIRQS
  206. #ifdef CONFIG_SMP
  207. #ifdef CONFIG_GENERIC_PENDING_IRQ
  208. void set_pending_irq(unsigned int irq, cpumask_t mask);
  209. void move_native_irq(int irq);
  210. void move_masked_irq(int irq);
  211. #else /* CONFIG_GENERIC_PENDING_IRQ */
  212. static inline void move_irq(int irq)
  213. {
  214. }
  215. static inline void move_native_irq(int irq)
  216. {
  217. }
  218. static inline void move_masked_irq(int irq)
  219. {
  220. }
  221. static inline void set_pending_irq(unsigned int irq, cpumask_t mask)
  222. {
  223. }
  224. #endif /* CONFIG_GENERIC_PENDING_IRQ */
  225. #else /* CONFIG_SMP */
  226. #define move_native_irq(x)
  227. #define move_masked_irq(x)
  228. #endif /* CONFIG_SMP */
  229. extern int no_irq_affinity;
  230. static inline int irq_balancing_disabled(unsigned int irq)
  231. {
  232. struct irq_desc *desc;
  233. desc = irq_to_desc(irq);
  234. return desc->status & IRQ_NO_BALANCING_MASK;
  235. }
  236. /* Handle irq action chains: */
  237. extern int handle_IRQ_event(unsigned int irq, struct irqaction *action);
  238. /*
  239. * Built-in IRQ handlers for various IRQ types,
  240. * callable via desc->chip->handle_irq()
  241. */
  242. extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
  243. extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
  244. extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
  245. extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
  246. extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
  247. extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
  248. /*
  249. * Monolithic do_IRQ implementation.
  250. */
  251. #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
  252. extern unsigned int __do_IRQ(unsigned int irq);
  253. #endif
  254. /*
  255. * Architectures call this to let the generic IRQ layer
  256. * handle an interrupt. If the descriptor is attached to an
  257. * irqchip-style controller then we call the ->handle_irq() handler,
  258. * and it calls __do_IRQ() if it's attached to an irqtype-style controller.
  259. */
  260. static inline void generic_handle_irq_desc(unsigned int irq, struct irq_desc *desc)
  261. {
  262. #ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
  263. desc->handle_irq(irq, desc);
  264. #else
  265. if (likely(desc->handle_irq))
  266. desc->handle_irq(irq, desc);
  267. else
  268. __do_IRQ(irq);
  269. #endif
  270. }
  271. static inline void generic_handle_irq(unsigned int irq)
  272. {
  273. generic_handle_irq_desc(irq, irq_to_desc(irq));
  274. }
  275. /* Handling of unhandled and spurious interrupts: */
  276. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  277. int action_ret);
  278. /* Resending of interrupts :*/
  279. void check_irq_resend(struct irq_desc *desc, unsigned int irq);
  280. /* Enable/disable irq debugging output: */
  281. extern int noirqdebug_setup(char *str);
  282. /* Checks whether the interrupt can be requested by request_irq(): */
  283. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  284. /* Dummy irq-chip implementations: */
  285. extern struct irq_chip no_irq_chip;
  286. extern struct irq_chip dummy_irq_chip;
  287. extern void
  288. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  289. irq_flow_handler_t handle);
  290. extern void
  291. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  292. irq_flow_handler_t handle, const char *name);
  293. extern void
  294. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  295. const char *name);
  296. /* caller has locked the irq_desc and both params are valid */
  297. static inline void __set_irq_handler_unlocked(int irq,
  298. irq_flow_handler_t handler)
  299. {
  300. struct irq_desc *desc;
  301. desc = irq_to_desc(irq);
  302. desc->handle_irq = handler;
  303. }
  304. /*
  305. * Set a highlevel flow handler for a given IRQ:
  306. */
  307. static inline void
  308. set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
  309. {
  310. __set_irq_handler(irq, handle, 0, NULL);
  311. }
  312. /*
  313. * Set a highlevel chained flow handler for a given IRQ.
  314. * (a chained handler is automatically enabled and set to
  315. * IRQ_NOREQUEST and IRQ_NOPROBE)
  316. */
  317. static inline void
  318. set_irq_chained_handler(unsigned int irq,
  319. irq_flow_handler_t handle)
  320. {
  321. __set_irq_handler(irq, handle, 1, NULL);
  322. }
  323. extern void set_irq_noprobe(unsigned int irq);
  324. extern void set_irq_probe(unsigned int irq);
  325. /* Handle dynamic irq creation and destruction */
  326. extern unsigned int create_irq_nr(unsigned int irq_want);
  327. extern int create_irq(void);
  328. extern void destroy_irq(unsigned int irq);
  329. /* Test to see if a driver has successfully requested an irq */
  330. static inline int irq_has_action(unsigned int irq)
  331. {
  332. struct irq_desc *desc = irq_to_desc(irq);
  333. return desc->action != NULL;
  334. }
  335. /* Dynamic irq helper functions */
  336. extern void dynamic_irq_init(unsigned int irq);
  337. extern void dynamic_irq_cleanup(unsigned int irq);
  338. /* Set/get chip/data for an IRQ: */
  339. extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
  340. extern int set_irq_data(unsigned int irq, void *data);
  341. extern int set_irq_chip_data(unsigned int irq, void *data);
  342. extern int set_irq_type(unsigned int irq, unsigned int type);
  343. extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
  344. #define get_irq_chip(irq) (irq_to_desc(irq)->chip)
  345. #define get_irq_chip_data(irq) (irq_to_desc(irq)->chip_data)
  346. #define get_irq_data(irq) (irq_to_desc(irq)->handler_data)
  347. #define get_irq_msi(irq) (irq_to_desc(irq)->msi_desc)
  348. #endif /* CONFIG_GENERIC_HARDIRQS */
  349. #endif /* !CONFIG_S390 */
  350. #endif /* _LINUX_IRQ_H */