irq.h 11 KB

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