irq.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. #ifndef CONFIG_GENERIC_HARDIRQS_NO_COMPAT
  45. #define IRQ_INPROGRESS 0x00000100 /* DEPRECATED */
  46. #endif
  47. #define IRQ_DISABLED 0x00000200 /* IRQ disabled - do not enter! */
  48. #define IRQ_PENDING 0x00000400 /* IRQ pending - replay on enable */
  49. #define IRQ_REPLAY 0x00000800 /* IRQ has been replayed but not acked yet */
  50. #define IRQ_WAITING 0x00002000 /* IRQ not yet seen - for autodetection */
  51. #define IRQ_LEVEL 0x00004000 /* IRQ level triggered */
  52. #define IRQ_MASKED 0x00008000 /* IRQ masked - shouldn't be seen again */
  53. #define IRQ_PER_CPU 0x00010000 /* IRQ is per CPU */
  54. #define IRQ_NOPROBE 0x00020000 /* IRQ is not valid for probing */
  55. #define IRQ_NOREQUEST 0x00040000 /* IRQ cannot be requested */
  56. #define IRQ_NOAUTOEN 0x00080000 /* IRQ will not be enabled on request irq */
  57. #define IRQ_WAKEUP 0x00100000 /* IRQ triggers system wakeup */
  58. #define IRQ_MOVE_PENDING 0x00200000 /* need to re-target IRQ destination */
  59. #define IRQ_NO_BALANCING 0x00400000 /* IRQ is excluded from balancing */
  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 | IRQ_NO_BALANCING | \
  68. IRQ_PER_CPU | IRQ_NESTED_THREAD)
  69. #ifdef CONFIG_IRQ_PER_CPU
  70. # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
  71. # define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  72. #else
  73. # define CHECK_IRQ_PER_CPU(var) 0
  74. # define IRQ_NO_BALANCING_MASK IRQ_NO_BALANCING
  75. #endif
  76. /*
  77. * Return value for chip->irq_set_affinity()
  78. *
  79. * IRQ_SET_MASK_OK - OK, core updates irq_data.affinity
  80. * IRQ_SET_MASK_NOCPY - OK, chip did update irq_data.affinity
  81. */
  82. enum {
  83. IRQ_SET_MASK_OK = 0,
  84. IRQ_SET_MASK_OK_NOCOPY,
  85. };
  86. struct msi_desc;
  87. /**
  88. * struct irq_data - per irq and irq chip data passed down to chip functions
  89. * @irq: interrupt number
  90. * @node: node index useful for balancing
  91. * @chip: low level interrupt hardware access
  92. * @handler_data: per-IRQ data for the irq_chip methods
  93. * @chip_data: platform-specific per-chip private data for the chip
  94. * methods, to allow shared chip implementations
  95. * @msi_desc: MSI descriptor
  96. * @affinity: IRQ affinity on SMP
  97. *
  98. * The fields here need to overlay the ones in irq_desc until we
  99. * cleaned up the direct references and switched everything over to
  100. * irq_data.
  101. */
  102. struct irq_data {
  103. unsigned int irq;
  104. unsigned int node;
  105. struct irq_chip *chip;
  106. void *handler_data;
  107. void *chip_data;
  108. struct msi_desc *msi_desc;
  109. #ifdef CONFIG_SMP
  110. cpumask_var_t affinity;
  111. #endif
  112. };
  113. /**
  114. * struct irq_chip - hardware interrupt chip descriptor
  115. *
  116. * @name: name for /proc/interrupts
  117. * @startup: deprecated, replaced by irq_startup
  118. * @shutdown: deprecated, replaced by irq_shutdown
  119. * @enable: deprecated, replaced by irq_enable
  120. * @disable: deprecated, replaced by irq_disable
  121. * @ack: deprecated, replaced by irq_ack
  122. * @mask: deprecated, replaced by irq_mask
  123. * @mask_ack: deprecated, replaced by irq_mask_ack
  124. * @unmask: deprecated, replaced by irq_unmask
  125. * @eoi: deprecated, replaced by irq_eoi
  126. * @end: deprecated, will go away with __do_IRQ()
  127. * @set_affinity: deprecated, replaced by irq_set_affinity
  128. * @retrigger: deprecated, replaced by irq_retrigger
  129. * @set_type: deprecated, replaced by irq_set_type
  130. * @set_wake: deprecated, replaced by irq_wake
  131. * @bus_lock: deprecated, replaced by irq_bus_lock
  132. * @bus_sync_unlock: deprecated, replaced by irq_bus_sync_unlock
  133. *
  134. * @irq_startup: start up the interrupt (defaults to ->enable if NULL)
  135. * @irq_shutdown: shut down the interrupt (defaults to ->disable if NULL)
  136. * @irq_enable: enable the interrupt (defaults to chip->unmask if NULL)
  137. * @irq_disable: disable the interrupt
  138. * @irq_ack: start of a new interrupt
  139. * @irq_mask: mask an interrupt source
  140. * @irq_mask_ack: ack and mask an interrupt source
  141. * @irq_unmask: unmask an interrupt source
  142. * @irq_eoi: end of interrupt
  143. * @irq_set_affinity: set the CPU affinity on SMP machines
  144. * @irq_retrigger: resend an IRQ to the CPU
  145. * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  146. * @irq_set_wake: enable/disable power-management wake-on of an IRQ
  147. * @irq_bus_lock: function to lock access to slow bus (i2c) chips
  148. * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
  149. *
  150. * @release: release function solely used by UML
  151. */
  152. struct irq_chip {
  153. const char *name;
  154. #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
  155. unsigned int (*startup)(unsigned int irq);
  156. void (*shutdown)(unsigned int irq);
  157. void (*enable)(unsigned int irq);
  158. void (*disable)(unsigned int irq);
  159. void (*ack)(unsigned int irq);
  160. void (*mask)(unsigned int irq);
  161. void (*mask_ack)(unsigned int irq);
  162. void (*unmask)(unsigned int irq);
  163. void (*eoi)(unsigned int irq);
  164. void (*end)(unsigned int irq);
  165. int (*set_affinity)(unsigned int irq,
  166. const struct cpumask *dest);
  167. int (*retrigger)(unsigned int irq);
  168. int (*set_type)(unsigned int irq, unsigned int flow_type);
  169. int (*set_wake)(unsigned int irq, unsigned int on);
  170. void (*bus_lock)(unsigned int irq);
  171. void (*bus_sync_unlock)(unsigned int irq);
  172. #endif
  173. unsigned int (*irq_startup)(struct irq_data *data);
  174. void (*irq_shutdown)(struct irq_data *data);
  175. void (*irq_enable)(struct irq_data *data);
  176. void (*irq_disable)(struct irq_data *data);
  177. void (*irq_ack)(struct irq_data *data);
  178. void (*irq_mask)(struct irq_data *data);
  179. void (*irq_mask_ack)(struct irq_data *data);
  180. void (*irq_unmask)(struct irq_data *data);
  181. void (*irq_eoi)(struct irq_data *data);
  182. int (*irq_set_affinity)(struct irq_data *data, const struct cpumask *dest, bool force);
  183. int (*irq_retrigger)(struct irq_data *data);
  184. int (*irq_set_type)(struct irq_data *data, unsigned int flow_type);
  185. int (*irq_set_wake)(struct irq_data *data, unsigned int on);
  186. void (*irq_bus_lock)(struct irq_data *data);
  187. void (*irq_bus_sync_unlock)(struct irq_data *data);
  188. /* Currently used only by UML, might disappear one day.*/
  189. #ifdef CONFIG_IRQ_RELEASE_METHOD
  190. void (*release)(unsigned int irq, void *dev_id);
  191. #endif
  192. };
  193. /* This include will go away once we isolated irq_desc usage to core code */
  194. #include <linux/irqdesc.h>
  195. /*
  196. * Pick up the arch-dependent methods:
  197. */
  198. #include <asm/hw_irq.h>
  199. #ifndef NR_IRQS_LEGACY
  200. # define NR_IRQS_LEGACY 0
  201. #endif
  202. #ifndef ARCH_IRQ_INIT_FLAGS
  203. # define ARCH_IRQ_INIT_FLAGS 0
  204. #endif
  205. #define IRQ_DEFAULT_INIT_FLAGS (IRQ_DISABLED | ARCH_IRQ_INIT_FLAGS)
  206. struct irqaction;
  207. extern int setup_irq(unsigned int irq, struct irqaction *new);
  208. extern void remove_irq(unsigned int irq, struct irqaction *act);
  209. #ifdef CONFIG_GENERIC_HARDIRQS
  210. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ)
  211. void move_native_irq(int irq);
  212. void move_masked_irq(int irq);
  213. #else
  214. static inline void move_native_irq(int irq) { }
  215. static inline void move_masked_irq(int irq) { }
  216. #endif
  217. extern int no_irq_affinity;
  218. /* Handle irq action chains: */
  219. extern irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action);
  220. /*
  221. * Built-in IRQ handlers for various IRQ types,
  222. * callable via desc->handle_irq()
  223. */
  224. extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
  225. extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
  226. extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
  227. extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
  228. extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
  229. extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
  230. extern void handle_nested_irq(unsigned int irq);
  231. /* Handling of unhandled and spurious interrupts: */
  232. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  233. irqreturn_t action_ret);
  234. /* Enable/disable irq debugging output: */
  235. extern int noirqdebug_setup(char *str);
  236. /* Checks whether the interrupt can be requested by request_irq(): */
  237. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  238. /* Dummy irq-chip implementations: */
  239. extern struct irq_chip no_irq_chip;
  240. extern struct irq_chip dummy_irq_chip;
  241. extern void
  242. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  243. irq_flow_handler_t handle);
  244. extern void
  245. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  246. irq_flow_handler_t handle, const char *name);
  247. extern void
  248. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  249. const char *name);
  250. /*
  251. * Set a highlevel flow handler for a given IRQ:
  252. */
  253. static inline void
  254. set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
  255. {
  256. __set_irq_handler(irq, handle, 0, NULL);
  257. }
  258. /*
  259. * Set a highlevel chained flow handler for a given IRQ.
  260. * (a chained handler is automatically enabled and set to
  261. * IRQ_NOREQUEST and IRQ_NOPROBE)
  262. */
  263. static inline void
  264. set_irq_chained_handler(unsigned int irq, irq_flow_handler_t handle)
  265. {
  266. __set_irq_handler(irq, handle, 1, NULL);
  267. }
  268. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
  269. static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
  270. {
  271. irq_modify_status(irq, 0, set);
  272. }
  273. static inline void irq_clear_status_flags(unsigned int irq, unsigned long clr)
  274. {
  275. irq_modify_status(irq, clr, 0);
  276. }
  277. static inline void irq_set_noprobe(unsigned int irq)
  278. {
  279. irq_modify_status(irq, 0, IRQ_NOPROBE);
  280. }
  281. static inline void irq_set_probe(unsigned int irq)
  282. {
  283. irq_modify_status(irq, IRQ_NOPROBE, 0);
  284. }
  285. static inline void irq_set_nested_thread(unsigned int irq, bool nest)
  286. {
  287. if (nest)
  288. irq_set_status_flags(irq, IRQ_NESTED_THREAD);
  289. else
  290. irq_clear_status_flags(irq, IRQ_NESTED_THREAD);
  291. }
  292. /* Handle dynamic irq creation and destruction */
  293. extern unsigned int create_irq_nr(unsigned int irq_want, int node);
  294. extern int create_irq(void);
  295. extern void destroy_irq(unsigned int irq);
  296. /*
  297. * Dynamic irq helper functions. Obsolete. Use irq_alloc_desc* and
  298. * irq_free_desc instead.
  299. */
  300. extern void dynamic_irq_cleanup(unsigned int irq);
  301. static inline void dynamic_irq_init(unsigned int irq)
  302. {
  303. dynamic_irq_cleanup(irq);
  304. }
  305. /* Set/get chip/data for an IRQ: */
  306. extern int irq_set_chip(unsigned int irq, struct irq_chip *chip);
  307. extern int irq_set_handler_data(unsigned int irq, void *data);
  308. extern int irq_set_chip_data(unsigned int irq, void *data);
  309. extern int irq_set_irq_type(unsigned int irq, unsigned int type);
  310. extern int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry);
  311. extern struct irq_data *irq_get_irq_data(unsigned int irq);
  312. static inline struct irq_chip *irq_get_chip(unsigned int irq)
  313. {
  314. struct irq_data *d = irq_get_irq_data(irq);
  315. return d ? d->chip : NULL;
  316. }
  317. static inline struct irq_chip *irq_data_get_irq_chip(struct irq_data *d)
  318. {
  319. return d->chip;
  320. }
  321. static inline void *irq_get_chip_data(unsigned int irq)
  322. {
  323. struct irq_data *d = irq_get_irq_data(irq);
  324. return d ? d->chip_data : NULL;
  325. }
  326. static inline void *irq_data_get_irq_chip_data(struct irq_data *d)
  327. {
  328. return d->chip_data;
  329. }
  330. static inline void *irq_get_handler_data(unsigned int irq)
  331. {
  332. struct irq_data *d = irq_get_irq_data(irq);
  333. return d ? d->handler_data : NULL;
  334. }
  335. static inline void *irq_data_get_irq_handler_data(struct irq_data *d)
  336. {
  337. return d->handler_data;
  338. }
  339. static inline struct msi_desc *irq_get_msi_desc(unsigned int irq)
  340. {
  341. struct irq_data *d = irq_get_irq_data(irq);
  342. return d ? d->msi_desc : NULL;
  343. }
  344. static inline struct msi_desc *irq_data_get_msi(struct irq_data *d)
  345. {
  346. return d->msi_desc;
  347. }
  348. #ifndef CONFIG_GENERIC_HARDIRQS_NO_COMPAT
  349. /* Please do not use: Use the replacement functions instead */
  350. static inline int set_irq_chip(unsigned int irq, struct irq_chip *chip)
  351. {
  352. return irq_set_chip(irq, chip);
  353. }
  354. static inline int set_irq_data(unsigned int irq, void *data)
  355. {
  356. return irq_set_handler_data(irq, data);
  357. }
  358. static inline int set_irq_chip_data(unsigned int irq, void *data)
  359. {
  360. return irq_set_chip_data(irq, data);
  361. }
  362. static inline int set_irq_type(unsigned int irq, unsigned int type)
  363. {
  364. return irq_set_irq_type(irq, type);
  365. }
  366. static inline int set_irq_msi(unsigned int irq, struct msi_desc *entry)
  367. {
  368. return irq_set_msi_desc(irq, entry);
  369. }
  370. static inline struct irq_chip *get_irq_chip(unsigned int irq)
  371. {
  372. return irq_get_chip(irq);
  373. }
  374. static inline void *get_irq_chip_data(unsigned int irq)
  375. {
  376. return irq_get_chip_data(irq);
  377. }
  378. static inline void *get_irq_data(unsigned int irq)
  379. {
  380. return irq_get_handler_data(irq);
  381. }
  382. static inline void *irq_data_get_irq_data(struct irq_data *d)
  383. {
  384. return irq_data_get_irq_handler_data(d);
  385. }
  386. static inline struct msi_desc *get_irq_msi(unsigned int irq)
  387. {
  388. return irq_get_msi_desc(irq);
  389. }
  390. static inline void set_irq_noprobe(unsigned int irq)
  391. {
  392. irq_set_noprobe(irq);
  393. }
  394. static inline void set_irq_probe(unsigned int irq)
  395. {
  396. irq_set_probe(irq);
  397. }
  398. static inline void set_irq_nested_thread(unsigned int irq, int nest)
  399. {
  400. irq_set_nested_thread(irq, nest);
  401. }
  402. #endif
  403. int irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node);
  404. void irq_free_descs(unsigned int irq, unsigned int cnt);
  405. int irq_reserve_irqs(unsigned int from, unsigned int cnt);
  406. static inline int irq_alloc_desc(int node)
  407. {
  408. return irq_alloc_descs(-1, 0, 1, node);
  409. }
  410. static inline int irq_alloc_desc_at(unsigned int at, int node)
  411. {
  412. return irq_alloc_descs(at, at, 1, node);
  413. }
  414. static inline int irq_alloc_desc_from(unsigned int from, int node)
  415. {
  416. return irq_alloc_descs(-1, from, 1, node);
  417. }
  418. static inline void irq_free_desc(unsigned int irq)
  419. {
  420. irq_free_descs(irq, 1);
  421. }
  422. static inline int irq_reserve_irq(unsigned int irq)
  423. {
  424. return irq_reserve_irqs(irq, 1);
  425. }
  426. #endif /* CONFIG_GENERIC_HARDIRQS */
  427. #endif /* !CONFIG_S390 */
  428. #endif /* _LINUX_IRQ_H */