irq.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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/gfp.h>
  17. #include <linux/irqreturn.h>
  18. #include <linux/irqnr.h>
  19. #include <linux/errno.h>
  20. #include <linux/topology.h>
  21. #include <linux/wait.h>
  22. #include <asm/irq.h>
  23. #include <asm/ptrace.h>
  24. #include <asm/irq_regs.h>
  25. struct irq_desc;
  26. typedef void (*irq_flow_handler_t)(unsigned int irq,
  27. struct irq_desc *desc);
  28. /*
  29. * IRQ line status.
  30. *
  31. * Bits 0-7 are reserved for the IRQF_* bits in linux/interrupt.h
  32. *
  33. * IRQ types
  34. */
  35. #define IRQ_TYPE_NONE 0x00000000 /* Default, unspecified type */
  36. #define IRQ_TYPE_EDGE_RISING 0x00000001 /* Edge rising type */
  37. #define IRQ_TYPE_EDGE_FALLING 0x00000002 /* Edge falling type */
  38. #define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
  39. #define IRQ_TYPE_LEVEL_HIGH 0x00000004 /* Level high type */
  40. #define IRQ_TYPE_LEVEL_LOW 0x00000008 /* Level low type */
  41. #define IRQ_TYPE_SENSE_MASK 0x0000000f /* Mask of the above */
  42. #define IRQ_TYPE_PROBE 0x00000010 /* Probing in progress */
  43. /* Internal flags */
  44. #define IRQ_INPROGRESS 0x00000100 /* IRQ handler active - do not enter! */
  45. #define IRQ_DISABLED 0x00000200 /* IRQ disabled - do not enter! */
  46. #define IRQ_PENDING 0x00000400 /* IRQ pending - replay on enable */
  47. #define IRQ_REPLAY 0x00000800 /* IRQ has been replayed but not acked yet */
  48. #define IRQ_AUTODETECT 0x00001000 /* IRQ is being autodetected */
  49. #define IRQ_WAITING 0x00002000 /* IRQ not yet seen - for autodetection */
  50. #define IRQ_LEVEL 0x00004000 /* IRQ level triggered */
  51. #define IRQ_MASKED 0x00008000 /* IRQ masked - shouldn't be seen again */
  52. #define IRQ_PER_CPU 0x00010000 /* IRQ is per CPU */
  53. #define IRQ_NOPROBE 0x00020000 /* IRQ is not valid for probing */
  54. #define IRQ_NOREQUEST 0x00040000 /* IRQ cannot be requested */
  55. #define IRQ_NOAUTOEN 0x00080000 /* IRQ will not be enabled on request irq */
  56. #define IRQ_WAKEUP 0x00100000 /* IRQ triggers system wakeup */
  57. #define IRQ_MOVE_PENDING 0x00200000 /* need to re-target IRQ destination */
  58. #define IRQ_NO_BALANCING 0x00400000 /* IRQ is excluded from balancing */
  59. #define IRQ_SPURIOUS_DISABLED 0x00800000 /* IRQ was disabled by the spurious trap */
  60. #define IRQ_MOVE_PCNTXT 0x01000000 /* IRQ migration from process context */
  61. #define IRQ_AFFINITY_SET 0x02000000 /* IRQ affinity was set from userspace*/
  62. #define IRQ_SUSPENDED 0x04000000 /* IRQ has gone through suspend sequence */
  63. #define IRQ_ONESHOT 0x08000000 /* IRQ is not unmasked after hardirq */
  64. #define IRQ_NESTED_THREAD 0x10000000 /* IRQ is nested into another, no own handler thread */
  65. #define IRQF_MODIFY_MASK \
  66. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  67. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL)
  68. #ifdef CONFIG_IRQ_PER_CPU
  69. # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
  70. # define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  71. #else
  72. # define CHECK_IRQ_PER_CPU(var) 0
  73. # define IRQ_NO_BALANCING_MASK IRQ_NO_BALANCING
  74. #endif
  75. struct msi_desc;
  76. /**
  77. * struct irq_data - per irq and irq chip data passed down to chip functions
  78. * @irq: interrupt number
  79. * @node: node index useful for balancing
  80. * @chip: low level interrupt hardware access
  81. * @handler_data: per-IRQ data for the irq_chip methods
  82. * @chip_data: platform-specific per-chip private data for the chip
  83. * methods, to allow shared chip implementations
  84. * @msi_desc: MSI descriptor
  85. * @affinity: IRQ affinity on SMP
  86. * @irq_2_iommu: iommu with this irq
  87. *
  88. * The fields here need to overlay the ones in irq_desc until we
  89. * cleaned up the direct references and switched everything over to
  90. * irq_data.
  91. */
  92. struct irq_data {
  93. unsigned int irq;
  94. unsigned int node;
  95. struct irq_chip *chip;
  96. void *handler_data;
  97. void *chip_data;
  98. struct msi_desc *msi_desc;
  99. #ifdef CONFIG_SMP
  100. cpumask_var_t affinity;
  101. #endif
  102. #ifdef CONFIG_INTR_REMAP
  103. struct irq_2_iommu *irq_2_iommu;
  104. #endif
  105. };
  106. /**
  107. * struct irq_chip - hardware interrupt chip descriptor
  108. *
  109. * @name: name for /proc/interrupts
  110. * @startup: deprecated, replaced by irq_startup
  111. * @shutdown: deprecated, replaced by irq_shutdown
  112. * @enable: deprecated, replaced by irq_enable
  113. * @disable: deprecated, replaced by irq_disable
  114. * @ack: deprecated, replaced by irq_ack
  115. * @mask: deprecated, replaced by irq_mask
  116. * @mask_ack: deprecated, replaced by irq_mask_ack
  117. * @unmask: deprecated, replaced by irq_unmask
  118. * @eoi: deprecated, replaced by irq_eoi
  119. * @end: deprecated, will go away with __do_IRQ()
  120. * @set_affinity: deprecated, replaced by irq_set_affinity
  121. * @retrigger: deprecated, replaced by irq_retrigger
  122. * @set_type: deprecated, replaced by irq_set_type
  123. * @set_wake: deprecated, replaced by irq_wake
  124. * @bus_lock: deprecated, replaced by irq_bus_lock
  125. * @bus_sync_unlock: deprecated, replaced by irq_bus_sync_unlock
  126. *
  127. * @irq_startup: start up the interrupt (defaults to ->enable if NULL)
  128. * @irq_shutdown: shut down the interrupt (defaults to ->disable if NULL)
  129. * @irq_enable: enable the interrupt (defaults to chip->unmask if NULL)
  130. * @irq_disable: disable the interrupt
  131. * @irq_ack: start of a new interrupt
  132. * @irq_mask: mask an interrupt source
  133. * @irq_mask_ack: ack and mask an interrupt source
  134. * @irq_unmask: unmask an interrupt source
  135. * @irq_eoi: end of interrupt
  136. * @irq_set_affinity: set the CPU affinity on SMP machines
  137. * @irq_retrigger: resend an IRQ to the CPU
  138. * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  139. * @irq_set_wake: enable/disable power-management wake-on of an IRQ
  140. * @irq_bus_lock: function to lock access to slow bus (i2c) chips
  141. * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
  142. *
  143. * @release: release function solely used by UML
  144. */
  145. struct irq_chip {
  146. const char *name;
  147. #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
  148. unsigned int (*startup)(unsigned int irq);
  149. void (*shutdown)(unsigned int irq);
  150. void (*enable)(unsigned int irq);
  151. void (*disable)(unsigned int irq);
  152. void (*ack)(unsigned int irq);
  153. void (*mask)(unsigned int irq);
  154. void (*mask_ack)(unsigned int irq);
  155. void (*unmask)(unsigned int irq);
  156. void (*eoi)(unsigned int irq);
  157. void (*end)(unsigned int irq);
  158. int (*set_affinity)(unsigned int irq,
  159. const struct cpumask *dest);
  160. int (*retrigger)(unsigned int irq);
  161. int (*set_type)(unsigned int irq, unsigned int flow_type);
  162. int (*set_wake)(unsigned int irq, unsigned int on);
  163. void (*bus_lock)(unsigned int irq);
  164. void (*bus_sync_unlock)(unsigned int irq);
  165. #endif
  166. unsigned int (*irq_startup)(struct irq_data *data);
  167. void (*irq_shutdown)(struct irq_data *data);
  168. void (*irq_enable)(struct irq_data *data);
  169. void (*irq_disable)(struct irq_data *data);
  170. void (*irq_ack)(struct irq_data *data);
  171. void (*irq_mask)(struct irq_data *data);
  172. void (*irq_mask_ack)(struct irq_data *data);
  173. void (*irq_unmask)(struct irq_data *data);
  174. void (*irq_eoi)(struct irq_data *data);
  175. int (*irq_set_affinity)(struct irq_data *data, const struct cpumask *dest, bool force);
  176. int (*irq_retrigger)(struct irq_data *data);
  177. int (*irq_set_type)(struct irq_data *data, unsigned int flow_type);
  178. int (*irq_set_wake)(struct irq_data *data, unsigned int on);
  179. void (*irq_bus_lock)(struct irq_data *data);
  180. void (*irq_bus_sync_unlock)(struct irq_data *data);
  181. /* Currently used only by UML, might disappear one day.*/
  182. #ifdef CONFIG_IRQ_RELEASE_METHOD
  183. void (*release)(unsigned int irq, void *dev_id);
  184. #endif
  185. };
  186. /* This include will go away once we isolated irq_desc usage to core code */
  187. #include <linux/irqdesc.h>
  188. /*
  189. * Pick up the arch-dependent methods:
  190. */
  191. #include <asm/hw_irq.h>
  192. struct irqaction;
  193. extern int setup_irq(unsigned int irq, struct irqaction *new);
  194. extern void remove_irq(unsigned int irq, struct irqaction *act);
  195. #ifdef CONFIG_GENERIC_HARDIRQS
  196. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ)
  197. void move_native_irq(int irq);
  198. void move_masked_irq(int irq);
  199. #else
  200. static inline void move_native_irq(int irq) { }
  201. static inline void move_masked_irq(int irq) { }
  202. #endif
  203. extern int no_irq_affinity;
  204. /* Handle irq action chains: */
  205. extern irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action);
  206. /*
  207. * Built-in IRQ handlers for various IRQ types,
  208. * callable via desc->handle_irq()
  209. */
  210. extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
  211. extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
  212. extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
  213. extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
  214. extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
  215. extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
  216. extern void handle_nested_irq(unsigned int irq);
  217. /* Handling of unhandled and spurious interrupts: */
  218. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  219. irqreturn_t action_ret);
  220. /* Enable/disable irq debugging output: */
  221. extern int noirqdebug_setup(char *str);
  222. /* Checks whether the interrupt can be requested by request_irq(): */
  223. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  224. /* Dummy irq-chip implementations: */
  225. extern struct irq_chip no_irq_chip;
  226. extern struct irq_chip dummy_irq_chip;
  227. extern void
  228. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  229. irq_flow_handler_t handle);
  230. extern void
  231. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  232. irq_flow_handler_t handle, const char *name);
  233. extern void
  234. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  235. const char *name);
  236. /*
  237. * Set a highlevel flow handler for a given IRQ:
  238. */
  239. static inline void
  240. set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
  241. {
  242. __set_irq_handler(irq, handle, 0, NULL);
  243. }
  244. /*
  245. * Set a highlevel chained flow handler for a given IRQ.
  246. * (a chained handler is automatically enabled and set to
  247. * IRQ_NOREQUEST and IRQ_NOPROBE)
  248. */
  249. static inline void
  250. set_irq_chained_handler(unsigned int irq,
  251. irq_flow_handler_t handle)
  252. {
  253. __set_irq_handler(irq, handle, 1, NULL);
  254. }
  255. extern void set_irq_nested_thread(unsigned int irq, int nest);
  256. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
  257. static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
  258. {
  259. irq_modify_status(irq, 0, set);
  260. }
  261. static inline void irq_clear_status_flags(unsigned int irq, unsigned long clr)
  262. {
  263. irq_modify_status(irq, clr, 0);
  264. }
  265. static inline void set_irq_noprobe(unsigned int irq)
  266. {
  267. irq_modify_status(irq, 0, IRQ_NOPROBE);
  268. }
  269. static inline void set_irq_probe(unsigned int irq)
  270. {
  271. irq_modify_status(irq, IRQ_NOPROBE, 0);
  272. }
  273. /* Handle dynamic irq creation and destruction */
  274. extern unsigned int create_irq_nr(unsigned int irq_want, int node);
  275. extern int create_irq(void);
  276. extern void destroy_irq(unsigned int irq);
  277. /* Dynamic irq helper functions */
  278. extern void dynamic_irq_init(unsigned int irq);
  279. void dynamic_irq_init_keep_chip_data(unsigned int irq);
  280. extern void dynamic_irq_cleanup(unsigned int irq);
  281. void dynamic_irq_cleanup_keep_chip_data(unsigned int irq);
  282. /* Set/get chip/data for an IRQ: */
  283. extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
  284. extern int set_irq_data(unsigned int irq, void *data);
  285. extern int set_irq_chip_data(unsigned int irq, void *data);
  286. extern int set_irq_type(unsigned int irq, unsigned int type);
  287. extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
  288. #define get_irq_chip(irq) (irq_to_desc(irq)->irq_data.chip)
  289. #define get_irq_chip_data(irq) (irq_to_desc(irq)->irq_data.chip_data)
  290. #define get_irq_data(irq) (irq_to_desc(irq)->irq_data.handler_data)
  291. #define get_irq_msi(irq) (irq_to_desc(irq)->irq_data.msi_desc)
  292. #endif /* CONFIG_GENERIC_HARDIRQS */
  293. #endif /* !CONFIG_S390 */
  294. #endif /* _LINUX_IRQ_H */