irq.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. #ifdef CONFIG_IRQ_PER_CPU
  66. # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
  67. # define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  68. #else
  69. # define CHECK_IRQ_PER_CPU(var) 0
  70. # define IRQ_NO_BALANCING_MASK IRQ_NO_BALANCING
  71. #endif
  72. struct proc_dir_entry;
  73. struct msi_desc;
  74. /**
  75. * struct irq_chip - hardware interrupt chip descriptor
  76. *
  77. * @name: name for /proc/interrupts
  78. * @startup: start up the interrupt (defaults to ->enable if NULL)
  79. * @shutdown: shut down the interrupt (defaults to ->disable if NULL)
  80. * @enable: enable the interrupt (defaults to chip->unmask if NULL)
  81. * @disable: disable the interrupt
  82. * @ack: start of a new interrupt
  83. * @mask: mask an interrupt source
  84. * @mask_ack: ack and mask an interrupt source
  85. * @unmask: unmask an interrupt source
  86. * @eoi: end of interrupt - chip level
  87. * @end: end of interrupt - flow level
  88. * @set_affinity: set the CPU affinity on SMP machines
  89. * @retrigger: resend an IRQ to the CPU
  90. * @set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  91. * @set_wake: enable/disable power-management wake-on of an IRQ
  92. *
  93. * @bus_lock: function to lock access to slow bus (i2c) chips
  94. * @bus_sync_unlock: function to sync and unlock slow bus (i2c) chips
  95. *
  96. * @release: release function solely used by UML
  97. * @typename: obsoleted by name, kept as migration helper
  98. */
  99. struct irq_chip {
  100. const char *name;
  101. unsigned int (*startup)(unsigned int irq);
  102. void (*shutdown)(unsigned int irq);
  103. void (*enable)(unsigned int irq);
  104. void (*disable)(unsigned int irq);
  105. void (*ack)(unsigned int irq);
  106. void (*mask)(unsigned int irq);
  107. void (*mask_ack)(unsigned int irq);
  108. void (*unmask)(unsigned int irq);
  109. void (*eoi)(unsigned int irq);
  110. void (*end)(unsigned int irq);
  111. int (*set_affinity)(unsigned int irq,
  112. const struct cpumask *dest);
  113. int (*retrigger)(unsigned int irq);
  114. int (*set_type)(unsigned int irq, unsigned int flow_type);
  115. int (*set_wake)(unsigned int irq, unsigned int on);
  116. void (*bus_lock)(unsigned int irq);
  117. void (*bus_sync_unlock)(unsigned int irq);
  118. /* Currently used only by UML, might disappear one day.*/
  119. #ifdef CONFIG_IRQ_RELEASE_METHOD
  120. void (*release)(unsigned int irq, void *dev_id);
  121. #endif
  122. /*
  123. * For compatibility, ->typename is copied into ->name.
  124. * Will disappear.
  125. */
  126. const char *typename;
  127. };
  128. struct timer_rand_state;
  129. struct irq_2_iommu;
  130. /**
  131. * struct irq_desc - interrupt descriptor
  132. * @irq: interrupt number for this descriptor
  133. * @timer_rand_state: pointer to timer rand state struct
  134. * @kstat_irqs: irq stats per cpu
  135. * @irq_2_iommu: iommu with this irq
  136. * @handle_irq: highlevel irq-events handler [if NULL, __do_IRQ()]
  137. * @chip: low level interrupt hardware access
  138. * @msi_desc: MSI descriptor
  139. * @handler_data: per-IRQ data for the irq_chip methods
  140. * @chip_data: platform-specific per-chip private data for the chip
  141. * methods, to allow shared chip implementations
  142. * @action: the irq action chain
  143. * @status: status information
  144. * @depth: disable-depth, for nested irq_disable() calls
  145. * @wake_depth: enable depth, for multiple set_irq_wake() callers
  146. * @irq_count: stats field to detect stalled irqs
  147. * @last_unhandled: aging timer for unhandled count
  148. * @irqs_unhandled: stats field for spurious unhandled interrupts
  149. * @lock: locking for SMP
  150. * @affinity: IRQ affinity on SMP
  151. * @node: node index useful for balancing
  152. * @pending_mask: pending rebalanced interrupts
  153. * @threads_active: number of irqaction threads currently running
  154. * @wait_for_threads: wait queue for sync_irq to wait for threaded handlers
  155. * @dir: /proc/irq/ procfs entry
  156. * @name: flow handler name for /proc/interrupts output
  157. */
  158. struct irq_desc {
  159. unsigned int irq;
  160. struct timer_rand_state *timer_rand_state;
  161. unsigned int *kstat_irqs;
  162. #ifdef CONFIG_INTR_REMAP
  163. struct irq_2_iommu *irq_2_iommu;
  164. #endif
  165. irq_flow_handler_t handle_irq;
  166. struct irq_chip *chip;
  167. struct msi_desc *msi_desc;
  168. void *handler_data;
  169. void *chip_data;
  170. struct irqaction *action; /* IRQ action list */
  171. unsigned int status; /* IRQ status */
  172. unsigned int depth; /* nested irq disables */
  173. unsigned int wake_depth; /* nested wake enables */
  174. unsigned int irq_count; /* For detecting broken IRQs */
  175. unsigned long last_unhandled; /* Aging timer for unhandled count */
  176. unsigned int irqs_unhandled;
  177. raw_spinlock_t lock;
  178. #ifdef CONFIG_SMP
  179. cpumask_var_t affinity;
  180. unsigned int node;
  181. #ifdef CONFIG_GENERIC_PENDING_IRQ
  182. cpumask_var_t pending_mask;
  183. #endif
  184. #endif
  185. atomic_t threads_active;
  186. wait_queue_head_t wait_for_threads;
  187. #ifdef CONFIG_PROC_FS
  188. struct proc_dir_entry *dir;
  189. #endif
  190. const char *name;
  191. } ____cacheline_internodealigned_in_smp;
  192. extern void arch_init_copy_chip_data(struct irq_desc *old_desc,
  193. struct irq_desc *desc, int node);
  194. extern void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc);
  195. #ifndef CONFIG_SPARSE_IRQ
  196. extern struct irq_desc irq_desc[NR_IRQS];
  197. #endif
  198. #ifdef CONFIG_NUMA_IRQ_DESC
  199. extern struct irq_desc *move_irq_desc(struct irq_desc *old_desc, int node);
  200. #else
  201. static inline struct irq_desc *move_irq_desc(struct irq_desc *desc, int node)
  202. {
  203. return desc;
  204. }
  205. #endif
  206. extern struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node);
  207. /*
  208. * Pick up the arch-dependent methods:
  209. */
  210. #include <asm/hw_irq.h>
  211. extern int setup_irq(unsigned int irq, struct irqaction *new);
  212. extern void remove_irq(unsigned int irq, struct irqaction *act);
  213. #ifdef CONFIG_GENERIC_HARDIRQS
  214. #ifdef CONFIG_SMP
  215. #ifdef CONFIG_GENERIC_PENDING_IRQ
  216. void move_native_irq(int irq);
  217. void move_masked_irq(int irq);
  218. #else /* CONFIG_GENERIC_PENDING_IRQ */
  219. static inline void move_irq(int irq)
  220. {
  221. }
  222. static inline void move_native_irq(int irq)
  223. {
  224. }
  225. static inline void move_masked_irq(int irq)
  226. {
  227. }
  228. #endif /* CONFIG_GENERIC_PENDING_IRQ */
  229. #else /* CONFIG_SMP */
  230. #define move_native_irq(x)
  231. #define move_masked_irq(x)
  232. #endif /* CONFIG_SMP */
  233. extern int no_irq_affinity;
  234. static inline int irq_balancing_disabled(unsigned int irq)
  235. {
  236. struct irq_desc *desc;
  237. desc = irq_to_desc(irq);
  238. return desc->status & IRQ_NO_BALANCING_MASK;
  239. }
  240. /* Handle irq action chains: */
  241. extern irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action);
  242. /*
  243. * Built-in IRQ handlers for various IRQ types,
  244. * callable via desc->handle_irq()
  245. */
  246. extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
  247. extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
  248. extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
  249. extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
  250. extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
  251. extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
  252. extern void handle_nested_irq(unsigned int irq);
  253. /*
  254. * Monolithic do_IRQ implementation.
  255. */
  256. #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
  257. extern unsigned int __do_IRQ(unsigned int irq);
  258. #endif
  259. /*
  260. * Architectures call this to let the generic IRQ layer
  261. * handle an interrupt. If the descriptor is attached to an
  262. * irqchip-style controller then we call the ->handle_irq() handler,
  263. * and it calls __do_IRQ() if it's attached to an irqtype-style controller.
  264. */
  265. static inline void generic_handle_irq_desc(unsigned int irq, struct irq_desc *desc)
  266. {
  267. #ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
  268. desc->handle_irq(irq, desc);
  269. #else
  270. if (likely(desc->handle_irq))
  271. desc->handle_irq(irq, desc);
  272. else
  273. __do_IRQ(irq);
  274. #endif
  275. }
  276. static inline void generic_handle_irq(unsigned int irq)
  277. {
  278. generic_handle_irq_desc(irq, irq_to_desc(irq));
  279. }
  280. /* Handling of unhandled and spurious interrupts: */
  281. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  282. irqreturn_t action_ret);
  283. /* Resending of interrupts :*/
  284. void check_irq_resend(struct irq_desc *desc, unsigned int irq);
  285. /* Enable/disable irq debugging output: */
  286. extern int noirqdebug_setup(char *str);
  287. /* Checks whether the interrupt can be requested by request_irq(): */
  288. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  289. /* Dummy irq-chip implementations: */
  290. extern struct irq_chip no_irq_chip;
  291. extern struct irq_chip dummy_irq_chip;
  292. extern void
  293. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  294. irq_flow_handler_t handle);
  295. extern void
  296. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  297. irq_flow_handler_t handle, const char *name);
  298. extern void
  299. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  300. const char *name);
  301. /* caller has locked the irq_desc and both params are valid */
  302. static inline void __set_irq_handler_unlocked(int irq,
  303. irq_flow_handler_t handler)
  304. {
  305. struct irq_desc *desc;
  306. desc = irq_to_desc(irq);
  307. desc->handle_irq = handler;
  308. }
  309. /*
  310. * Set a highlevel flow handler for a given IRQ:
  311. */
  312. static inline void
  313. set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
  314. {
  315. __set_irq_handler(irq, handle, 0, NULL);
  316. }
  317. /*
  318. * Set a highlevel chained flow handler for a given IRQ.
  319. * (a chained handler is automatically enabled and set to
  320. * IRQ_NOREQUEST and IRQ_NOPROBE)
  321. */
  322. static inline void
  323. set_irq_chained_handler(unsigned int irq,
  324. irq_flow_handler_t handle)
  325. {
  326. __set_irq_handler(irq, handle, 1, NULL);
  327. }
  328. extern void set_irq_nested_thread(unsigned int irq, int nest);
  329. extern void set_irq_noprobe(unsigned int irq);
  330. extern void set_irq_probe(unsigned int irq);
  331. /* Handle dynamic irq creation and destruction */
  332. extern unsigned int create_irq_nr(unsigned int irq_want, int node);
  333. extern int create_irq(void);
  334. extern void destroy_irq(unsigned int irq);
  335. /* Test to see if a driver has successfully requested an irq */
  336. static inline int irq_has_action(unsigned int irq)
  337. {
  338. struct irq_desc *desc = irq_to_desc(irq);
  339. return desc->action != NULL;
  340. }
  341. /* Dynamic irq helper functions */
  342. extern void dynamic_irq_init(unsigned int irq);
  343. extern void dynamic_irq_cleanup(unsigned int irq);
  344. /* Set/get chip/data for an IRQ: */
  345. extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
  346. extern int set_irq_data(unsigned int irq, void *data);
  347. extern int set_irq_chip_data(unsigned int irq, void *data);
  348. extern int set_irq_type(unsigned int irq, unsigned int type);
  349. extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
  350. #define get_irq_chip(irq) (irq_to_desc(irq)->chip)
  351. #define get_irq_chip_data(irq) (irq_to_desc(irq)->chip_data)
  352. #define get_irq_data(irq) (irq_to_desc(irq)->handler_data)
  353. #define get_irq_msi(irq) (irq_to_desc(irq)->msi_desc)
  354. #define get_irq_desc_chip(desc) ((desc)->chip)
  355. #define get_irq_desc_chip_data(desc) ((desc)->chip_data)
  356. #define get_irq_desc_data(desc) ((desc)->handler_data)
  357. #define get_irq_desc_msi(desc) ((desc)->msi_desc)
  358. #endif /* CONFIG_GENERIC_HARDIRQS */
  359. #endif /* !CONFIG_S390 */
  360. #ifdef CONFIG_SMP
  361. /**
  362. * alloc_desc_masks - allocate cpumasks for irq_desc
  363. * @desc: pointer to irq_desc struct
  364. * @node: node which will be handling the cpumasks
  365. * @boot: true if need bootmem
  366. *
  367. * Allocates affinity and pending_mask cpumask if required.
  368. * Returns true if successful (or not required).
  369. */
  370. static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
  371. bool boot)
  372. {
  373. gfp_t gfp = GFP_ATOMIC;
  374. if (boot)
  375. gfp = GFP_NOWAIT;
  376. #ifdef CONFIG_CPUMASK_OFFSTACK
  377. if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
  378. return false;
  379. #ifdef CONFIG_GENERIC_PENDING_IRQ
  380. if (!alloc_cpumask_var_node(&desc->pending_mask, gfp, node)) {
  381. free_cpumask_var(desc->affinity);
  382. return false;
  383. }
  384. #endif
  385. #endif
  386. return true;
  387. }
  388. static inline void init_desc_masks(struct irq_desc *desc)
  389. {
  390. cpumask_setall(desc->affinity);
  391. #ifdef CONFIG_GENERIC_PENDING_IRQ
  392. cpumask_clear(desc->pending_mask);
  393. #endif
  394. }
  395. /**
  396. * init_copy_desc_masks - copy cpumasks for irq_desc
  397. * @old_desc: pointer to old irq_desc struct
  398. * @new_desc: pointer to new irq_desc struct
  399. *
  400. * Insures affinity and pending_masks are copied to new irq_desc.
  401. * If !CONFIG_CPUMASKS_OFFSTACK the cpumasks are embedded in the
  402. * irq_desc struct so the copy is redundant.
  403. */
  404. static inline void init_copy_desc_masks(struct irq_desc *old_desc,
  405. struct irq_desc *new_desc)
  406. {
  407. #ifdef CONFIG_CPUMASK_OFFSTACK
  408. cpumask_copy(new_desc->affinity, old_desc->affinity);
  409. #ifdef CONFIG_GENERIC_PENDING_IRQ
  410. cpumask_copy(new_desc->pending_mask, old_desc->pending_mask);
  411. #endif
  412. #endif
  413. }
  414. static inline void free_desc_masks(struct irq_desc *old_desc,
  415. struct irq_desc *new_desc)
  416. {
  417. free_cpumask_var(old_desc->affinity);
  418. #ifdef CONFIG_GENERIC_PENDING_IRQ
  419. free_cpumask_var(old_desc->pending_mask);
  420. #endif
  421. }
  422. #else /* !CONFIG_SMP */
  423. static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
  424. bool boot)
  425. {
  426. return true;
  427. }
  428. static inline void init_desc_masks(struct irq_desc *desc)
  429. {
  430. }
  431. static inline void init_copy_desc_masks(struct irq_desc *old_desc,
  432. struct irq_desc *new_desc)
  433. {
  434. }
  435. static inline void free_desc_masks(struct irq_desc *old_desc,
  436. struct irq_desc *new_desc)
  437. {
  438. }
  439. #endif /* CONFIG_SMP */
  440. #endif /* _LINUX_IRQ_H */