irq.h 12 KB

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