irq.h 13 KB

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