irq.h 13 KB

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