/include/linux/irq.h

https://gitlab.com/simplified-mandatory-access-control-kernel/ossecus-simplified-mandatory-access-control-kernel · C Header · 424 lines · 260 code · 67 blank · 97 comment · 1 complexity · f524c6278cfa29f9eda5983b8817d6ef MD5 · raw file

  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. *
  87. * The fields here need to overlay the ones in irq_desc until we
  88. * cleaned up the direct references and switched everything over to
  89. * irq_data.
  90. */
  91. struct irq_data {
  92. unsigned int irq;
  93. unsigned int node;
  94. struct irq_chip *chip;
  95. void *handler_data;
  96. void *chip_data;
  97. struct msi_desc *msi_desc;
  98. #ifdef CONFIG_SMP
  99. cpumask_var_t affinity;
  100. #endif
  101. };
  102. /**
  103. * struct irq_chip - hardware interrupt chip descriptor
  104. *
  105. * @name: name for /proc/interrupts
  106. * @startup: deprecated, replaced by irq_startup
  107. * @shutdown: deprecated, replaced by irq_shutdown
  108. * @enable: deprecated, replaced by irq_enable
  109. * @disable: deprecated, replaced by irq_disable
  110. * @ack: deprecated, replaced by irq_ack
  111. * @mask: deprecated, replaced by irq_mask
  112. * @mask_ack: deprecated, replaced by irq_mask_ack
  113. * @unmask: deprecated, replaced by irq_unmask
  114. * @eoi: deprecated, replaced by irq_eoi
  115. * @end: deprecated, will go away with __do_IRQ()
  116. * @set_affinity: deprecated, replaced by irq_set_affinity
  117. * @retrigger: deprecated, replaced by irq_retrigger
  118. * @set_type: deprecated, replaced by irq_set_type
  119. * @set_wake: deprecated, replaced by irq_wake
  120. * @bus_lock: deprecated, replaced by irq_bus_lock
  121. * @bus_sync_unlock: deprecated, replaced by irq_bus_sync_unlock
  122. *
  123. * @irq_startup: start up the interrupt (defaults to ->enable if NULL)
  124. * @irq_shutdown: shut down the interrupt (defaults to ->disable if NULL)
  125. * @irq_enable: enable the interrupt (defaults to chip->unmask if NULL)
  126. * @irq_disable: disable the interrupt
  127. * @irq_ack: start of a new interrupt
  128. * @irq_mask: mask an interrupt source
  129. * @irq_mask_ack: ack and mask an interrupt source
  130. * @irq_unmask: unmask an interrupt source
  131. * @irq_eoi: end of interrupt
  132. * @irq_set_affinity: set the CPU affinity on SMP machines
  133. * @irq_retrigger: resend an IRQ to the CPU
  134. * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  135. * @irq_set_wake: enable/disable power-management wake-on of an IRQ
  136. * @irq_bus_lock: function to lock access to slow bus (i2c) chips
  137. * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
  138. *
  139. * @release: release function solely used by UML
  140. */
  141. struct irq_chip {
  142. const char *name;
  143. #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
  144. unsigned int (*startup)(unsigned int irq);
  145. void (*shutdown)(unsigned int irq);
  146. void (*enable)(unsigned int irq);
  147. void (*disable)(unsigned int irq);
  148. void (*ack)(unsigned int irq);
  149. void (*mask)(unsigned int irq);
  150. void (*mask_ack)(unsigned int irq);
  151. void (*unmask)(unsigned int irq);
  152. void (*eoi)(unsigned int irq);
  153. void (*end)(unsigned int irq);
  154. int (*set_affinity)(unsigned int irq,
  155. const struct cpumask *dest);
  156. int (*retrigger)(unsigned int irq);
  157. int (*set_type)(unsigned int irq, unsigned int flow_type);
  158. int (*set_wake)(unsigned int irq, unsigned int on);
  159. void (*bus_lock)(unsigned int irq);
  160. void (*bus_sync_unlock)(unsigned int irq);
  161. #endif
  162. unsigned int (*irq_startup)(struct irq_data *data);
  163. void (*irq_shutdown)(struct irq_data *data);
  164. void (*irq_enable)(struct irq_data *data);
  165. void (*irq_disable)(struct irq_data *data);
  166. void (*irq_ack)(struct irq_data *data);
  167. void (*irq_mask)(struct irq_data *data);
  168. void (*irq_mask_ack)(struct irq_data *data);
  169. void (*irq_unmask)(struct irq_data *data);
  170. void (*irq_eoi)(struct irq_data *data);
  171. int (*irq_set_affinity)(struct irq_data *data, const struct cpumask *dest, bool force);
  172. int (*irq_retrigger)(struct irq_data *data);
  173. int (*irq_set_type)(struct irq_data *data, unsigned int flow_type);
  174. int (*irq_set_wake)(struct irq_data *data, unsigned int on);
  175. void (*irq_bus_lock)(struct irq_data *data);
  176. void (*irq_bus_sync_unlock)(struct irq_data *data);
  177. /* Currently used only by UML, might disappear one day.*/
  178. #ifdef CONFIG_IRQ_RELEASE_METHOD
  179. void (*release)(unsigned int irq, void *dev_id);
  180. #endif
  181. };
  182. /* This include will go away once we isolated irq_desc usage to core code */
  183. #include <linux/irqdesc.h>
  184. /*
  185. * Pick up the arch-dependent methods:
  186. */
  187. #include <asm/hw_irq.h>
  188. #ifndef NR_IRQS_LEGACY
  189. # define NR_IRQS_LEGACY 0
  190. #endif
  191. #ifndef ARCH_IRQ_INIT_FLAGS
  192. # define ARCH_IRQ_INIT_FLAGS 0
  193. #endif
  194. #define IRQ_DEFAULT_INIT_FLAGS (IRQ_DISABLED | ARCH_IRQ_INIT_FLAGS)
  195. struct irqaction;
  196. extern int setup_irq(unsigned int irq, struct irqaction *new);
  197. extern void remove_irq(unsigned int irq, struct irqaction *act);
  198. #ifdef CONFIG_GENERIC_HARDIRQS
  199. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ)
  200. void move_native_irq(int irq);
  201. void move_masked_irq(int irq);
  202. #else
  203. static inline void move_native_irq(int irq) { }
  204. static inline void move_masked_irq(int irq) { }
  205. #endif
  206. extern int no_irq_affinity;
  207. /* Handle irq action chains: */
  208. extern irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action);
  209. /*
  210. * Built-in IRQ handlers for various IRQ types,
  211. * callable via desc->handle_irq()
  212. */
  213. extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
  214. extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
  215. extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
  216. extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
  217. extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
  218. extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
  219. extern void handle_nested_irq(unsigned int irq);
  220. /* Handling of unhandled and spurious interrupts: */
  221. extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
  222. irqreturn_t action_ret);
  223. /* Enable/disable irq debugging output: */
  224. extern int noirqdebug_setup(char *str);
  225. /* Checks whether the interrupt can be requested by request_irq(): */
  226. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  227. /* Dummy irq-chip implementations: */
  228. extern struct irq_chip no_irq_chip;
  229. extern struct irq_chip dummy_irq_chip;
  230. extern void
  231. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  232. irq_flow_handler_t handle);
  233. extern void
  234. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  235. irq_flow_handler_t handle, const char *name);
  236. extern void
  237. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  238. const char *name);
  239. /*
  240. * Set a highlevel flow handler for a given IRQ:
  241. */
  242. static inline void
  243. set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
  244. {
  245. __set_irq_handler(irq, handle, 0, NULL);
  246. }
  247. /*
  248. * Set a highlevel chained flow handler for a given IRQ.
  249. * (a chained handler is automatically enabled and set to
  250. * IRQ_NOREQUEST and IRQ_NOPROBE)
  251. */
  252. static inline void
  253. set_irq_chained_handler(unsigned int irq,
  254. irq_flow_handler_t handle)
  255. {
  256. __set_irq_handler(irq, handle, 1, NULL);
  257. }
  258. extern void set_irq_nested_thread(unsigned int irq, int nest);
  259. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
  260. static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
  261. {
  262. irq_modify_status(irq, 0, set);
  263. }
  264. static inline void irq_clear_status_flags(unsigned int irq, unsigned long clr)
  265. {
  266. irq_modify_status(irq, clr, 0);
  267. }
  268. static inline void set_irq_noprobe(unsigned int irq)
  269. {
  270. irq_modify_status(irq, 0, IRQ_NOPROBE);
  271. }
  272. static inline void set_irq_probe(unsigned int irq)
  273. {
  274. irq_modify_status(irq, IRQ_NOPROBE, 0);
  275. }
  276. /* Handle dynamic irq creation and destruction */
  277. extern unsigned int create_irq_nr(unsigned int irq_want, int node);
  278. extern int create_irq(void);
  279. extern void destroy_irq(unsigned int irq);
  280. /*
  281. * Dynamic irq helper functions. Obsolete. Use irq_alloc_desc* and
  282. * irq_free_desc instead.
  283. */
  284. extern void dynamic_irq_cleanup(unsigned int irq);
  285. static inline void dynamic_irq_init(unsigned int irq)
  286. {
  287. dynamic_irq_cleanup(irq);
  288. }
  289. /* Set/get chip/data for an IRQ: */
  290. extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
  291. extern int set_irq_data(unsigned int irq, void *data);
  292. extern int set_irq_chip_data(unsigned int irq, void *data);
  293. extern int set_irq_type(unsigned int irq, unsigned int type);
  294. extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
  295. extern struct irq_data *irq_get_irq_data(unsigned int irq);
  296. static inline struct irq_chip *get_irq_chip(unsigned int irq)
  297. {
  298. struct irq_data *d = irq_get_irq_data(irq);
  299. return d ? d->chip : NULL;
  300. }
  301. static inline struct irq_chip *irq_data_get_irq_chip(struct irq_data *d)
  302. {
  303. return d->chip;
  304. }
  305. static inline void *get_irq_chip_data(unsigned int irq)
  306. {
  307. struct irq_data *d = irq_get_irq_data(irq);
  308. return d ? d->chip_data : NULL;
  309. }
  310. static inline void *irq_data_get_irq_chip_data(struct irq_data *d)
  311. {
  312. return d->chip_data;
  313. }
  314. static inline void *get_irq_data(unsigned int irq)
  315. {
  316. struct irq_data *d = irq_get_irq_data(irq);
  317. return d ? d->handler_data : NULL;
  318. }
  319. static inline void *irq_data_get_irq_data(struct irq_data *d)
  320. {
  321. return d->handler_data;
  322. }
  323. static inline struct msi_desc *get_irq_msi(unsigned int irq)
  324. {
  325. struct irq_data *d = irq_get_irq_data(irq);
  326. return d ? d->msi_desc : NULL;
  327. }
  328. static inline struct msi_desc *irq_data_get_msi(struct irq_data *d)
  329. {
  330. return d->msi_desc;
  331. }
  332. int irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node);
  333. void irq_free_descs(unsigned int irq, unsigned int cnt);
  334. int irq_reserve_irqs(unsigned int from, unsigned int cnt);
  335. static inline int irq_alloc_desc(int node)
  336. {
  337. return irq_alloc_descs(-1, 0, 1, node);
  338. }
  339. static inline int irq_alloc_desc_at(unsigned int at, int node)
  340. {
  341. return irq_alloc_descs(at, at, 1, node);
  342. }
  343. static inline int irq_alloc_desc_from(unsigned int from, int node)
  344. {
  345. return irq_alloc_descs(-1, from, 1, node);
  346. }
  347. static inline void irq_free_desc(unsigned int irq)
  348. {
  349. irq_free_descs(irq, 1);
  350. }
  351. static inline int irq_reserve_irq(unsigned int irq)
  352. {
  353. return irq_reserve_irqs(irq, 1);
  354. }
  355. #endif /* CONFIG_GENERIC_HARDIRQS */
  356. #endif /* !CONFIG_S390 */
  357. #endif /* _LINUX_IRQ_H */