interrupt.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* interrupt.h */
  3. #ifndef _LINUX_INTERRUPT_H
  4. #define _LINUX_INTERRUPT_H
  5. #include <linux/kernel.h>
  6. #include <linux/bitops.h>
  7. #include <linux/cpumask.h>
  8. #include <linux/irqreturn.h>
  9. #include <linux/irqnr.h>
  10. #include <linux/hardirq.h>
  11. #include <linux/irqflags.h>
  12. #include <linux/hrtimer.h>
  13. #include <linux/kref.h>
  14. #include <linux/workqueue.h>
  15. #include <linux/atomic.h>
  16. #include <asm/ptrace.h>
  17. #include <asm/irq.h>
  18. #include <asm/sections.h>
  19. /*
  20. * These correspond to the IORESOURCE_IRQ_* defines in
  21. * linux/ioport.h to select the interrupt line behaviour. When
  22. * requesting an interrupt without specifying a IRQF_TRIGGER, the
  23. * setting should be assumed to be "as already configured", which
  24. * may be as per machine or firmware initialisation.
  25. */
  26. #define IRQF_TRIGGER_NONE 0x00000000
  27. #define IRQF_TRIGGER_RISING 0x00000001
  28. #define IRQF_TRIGGER_FALLING 0x00000002
  29. #define IRQF_TRIGGER_HIGH 0x00000004
  30. #define IRQF_TRIGGER_LOW 0x00000008
  31. #define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
  32. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
  33. #define IRQF_TRIGGER_PROBE 0x00000010
  34. /*
  35. * These flags used only by the kernel as part of the
  36. * irq handling routines.
  37. *
  38. * IRQF_SHARED - allow sharing the irq among several devices
  39. * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
  40. * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
  41. * IRQF_PERCPU - Interrupt is per cpu
  42. * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
  43. * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
  44. * registered first in a shared interrupt is considered for
  45. * performance reasons)
  46. * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished.
  47. * Used by threaded interrupts which need to keep the
  48. * irq line disabled until the threaded handler has been run.
  49. * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend. Does not guarantee
  50. * that this interrupt will wake the system from a suspended
  51. * state. See Documentation/power/suspend-and-interrupts.rst
  52. * IRQF_FORCE_RESUME - Force enable it on resume even if IRQF_NO_SUSPEND is set
  53. * IRQF_NO_THREAD - Interrupt cannot be threaded
  54. * IRQF_EARLY_RESUME - Resume IRQ early during syscore instead of at device
  55. * resume time.
  56. * IRQF_COND_SUSPEND - If the IRQ is shared with a NO_SUSPEND user, execute this
  57. * interrupt handler after suspending interrupts. For system
  58. * wakeup devices users need to implement wakeup detection in
  59. * their interrupt handlers.
  60. */
  61. #define IRQF_SHARED 0x00000080
  62. #define IRQF_PROBE_SHARED 0x00000100
  63. #define __IRQF_TIMER 0x00000200
  64. #define IRQF_PERCPU 0x00000400
  65. #define IRQF_NOBALANCING 0x00000800
  66. #define IRQF_IRQPOLL 0x00001000
  67. #define IRQF_ONESHOT 0x00002000
  68. #define IRQF_NO_SUSPEND 0x00004000
  69. #define IRQF_FORCE_RESUME 0x00008000
  70. #define IRQF_NO_THREAD 0x00010000
  71. #define IRQF_EARLY_RESUME 0x00020000
  72. #define IRQF_COND_SUSPEND 0x00040000
  73. #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
  74. /*
  75. * These values can be returned by request_any_context_irq() and
  76. * describe the context the interrupt will be run in.
  77. *
  78. * IRQC_IS_HARDIRQ - interrupt runs in hardirq context
  79. * IRQC_IS_NESTED - interrupt runs in a nested threaded context
  80. */
  81. enum {
  82. IRQC_IS_HARDIRQ = 0,
  83. IRQC_IS_NESTED,
  84. };
  85. typedef irqreturn_t (*irq_handler_t)(int, void *);
  86. /**
  87. * struct irqaction - per interrupt action descriptor
  88. * @handler: interrupt handler function
  89. * @name: name of the device
  90. * @dev_id: cookie to identify the device
  91. * @percpu_dev_id: cookie to identify the device
  92. * @next: pointer to the next irqaction for shared interrupts
  93. * @irq: interrupt number
  94. * @flags: flags (see IRQF_* above)
  95. * @thread_fn: interrupt handler function for threaded interrupts
  96. * @thread: thread pointer for threaded interrupts
  97. * @secondary: pointer to secondary irqaction (force threading)
  98. * @thread_flags: flags related to @thread
  99. * @thread_mask: bitmask for keeping track of @thread activity
  100. * @dir: pointer to the proc/irq/NN/name entry
  101. */
  102. struct irqaction {
  103. irq_handler_t handler;
  104. void *dev_id;
  105. void __percpu *percpu_dev_id;
  106. struct irqaction *next;
  107. irq_handler_t thread_fn;
  108. struct task_struct *thread;
  109. struct irqaction *secondary;
  110. unsigned int irq;
  111. unsigned int flags;
  112. unsigned long thread_flags;
  113. unsigned long thread_mask;
  114. const char *name;
  115. struct proc_dir_entry *dir;
  116. } ____cacheline_internodealigned_in_smp;
  117. extern irqreturn_t no_action(int cpl, void *dev_id);
  118. /*
  119. * If a (PCI) device interrupt is not connected we set dev->irq to
  120. * IRQ_NOTCONNECTED. This causes request_irq() to fail with -ENOTCONN, so we
  121. * can distingiush that case from other error returns.
  122. *
  123. * 0x80000000 is guaranteed to be outside the available range of interrupts
  124. * and easy to distinguish from other possible incorrect values.
  125. */
  126. #define IRQ_NOTCONNECTED (1U << 31)
  127. extern int __must_check
  128. request_threaded_irq(unsigned int irq, irq_handler_t handler,
  129. irq_handler_t thread_fn,
  130. unsigned long flags, const char *name, void *dev);
  131. /**
  132. * request_irq - Add a handler for an interrupt line
  133. * @irq: The interrupt line to allocate
  134. * @handler: Function to be called when the IRQ occurs.
  135. * Primary handler for threaded interrupts
  136. * If NULL, the default primary handler is installed
  137. * @flags: Handling flags
  138. * @name: Name of the device generating this interrupt
  139. * @dev: A cookie passed to the handler function
  140. *
  141. * This call allocates an interrupt and establishes a handler; see
  142. * the documentation for request_threaded_irq() for details.
  143. */
  144. static inline int __must_check
  145. request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
  146. const char *name, void *dev)
  147. {
  148. return request_threaded_irq(irq, handler, NULL, flags, name, dev);
  149. }
  150. extern int __must_check
  151. request_any_context_irq(unsigned int irq, irq_handler_t handler,
  152. unsigned long flags, const char *name, void *dev_id);
  153. extern int __must_check
  154. __request_percpu_irq(unsigned int irq, irq_handler_t handler,
  155. unsigned long flags, const char *devname,
  156. void __percpu *percpu_dev_id);
  157. extern int __must_check
  158. request_nmi(unsigned int irq, irq_handler_t handler, unsigned long flags,
  159. const char *name, void *dev);
  160. static inline int __must_check
  161. request_percpu_irq(unsigned int irq, irq_handler_t handler,
  162. const char *devname, void __percpu *percpu_dev_id)
  163. {
  164. return __request_percpu_irq(irq, handler, 0,
  165. devname, percpu_dev_id);
  166. }
  167. extern int __must_check
  168. request_percpu_nmi(unsigned int irq, irq_handler_t handler,
  169. const char *devname, void __percpu *dev);
  170. extern const void *free_irq(unsigned int, void *);
  171. extern void free_percpu_irq(unsigned int, void __percpu *);
  172. extern const void *free_nmi(unsigned int irq, void *dev_id);
  173. extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id);
  174. struct device;
  175. extern int __must_check
  176. devm_request_threaded_irq(struct device *dev, unsigned int irq,
  177. irq_handler_t handler, irq_handler_t thread_fn,
  178. unsigned long irqflags, const char *devname,
  179. void *dev_id);
  180. static inline int __must_check
  181. devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
  182. unsigned long irqflags, const char *devname, void *dev_id)
  183. {
  184. return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
  185. devname, dev_id);
  186. }
  187. extern int __must_check
  188. devm_request_any_context_irq(struct device *dev, unsigned int irq,
  189. irq_handler_t handler, unsigned long irqflags,
  190. const char *devname, void *dev_id);
  191. extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
  192. /*
  193. * On lockdep we dont want to enable hardirqs in hardirq
  194. * context. Use local_irq_enable_in_hardirq() to annotate
  195. * kernel code that has to do this nevertheless (pretty much
  196. * the only valid case is for old/broken hardware that is
  197. * insanely slow).
  198. *
  199. * NOTE: in theory this might break fragile code that relies
  200. * on hardirq delivery - in practice we dont seem to have such
  201. * places left. So the only effect should be slightly increased
  202. * irqs-off latencies.
  203. */
  204. #ifdef CONFIG_LOCKDEP
  205. # define local_irq_enable_in_hardirq() do { } while (0)
  206. #else
  207. # define local_irq_enable_in_hardirq() local_irq_enable()
  208. #endif
  209. extern void disable_irq_nosync(unsigned int irq);
  210. extern bool disable_hardirq(unsigned int irq);
  211. extern void disable_irq(unsigned int irq);
  212. extern void disable_percpu_irq(unsigned int irq);
  213. extern void enable_irq(unsigned int irq);
  214. extern void enable_percpu_irq(unsigned int irq, unsigned int type);
  215. extern bool irq_percpu_is_enabled(unsigned int irq);
  216. extern void irq_wake_thread(unsigned int irq, void *dev_id);
  217. extern void disable_nmi_nosync(unsigned int irq);
  218. extern void disable_percpu_nmi(unsigned int irq);
  219. extern void enable_nmi(unsigned int irq);
  220. extern void enable_percpu_nmi(unsigned int irq, unsigned int type);
  221. extern int prepare_percpu_nmi(unsigned int irq);
  222. extern void teardown_percpu_nmi(unsigned int irq);
  223. extern int irq_inject_interrupt(unsigned int irq);
  224. /* The following three functions are for the core kernel use only. */
  225. extern void suspend_device_irqs(void);
  226. extern void resume_device_irqs(void);
  227. extern void rearm_wake_irq(unsigned int irq);
  228. /**
  229. * struct irq_affinity_notify - context for notification of IRQ affinity changes
  230. * @irq: Interrupt to which notification applies
  231. * @kref: Reference count, for internal use
  232. * @work: Work item, for internal use
  233. * @notify: Function to be called on change. This will be
  234. * called in process context.
  235. * @release: Function to be called on release. This will be
  236. * called in process context. Once registered, the
  237. * structure must only be freed when this function is
  238. * called or later.
  239. */
  240. struct irq_affinity_notify {
  241. unsigned int irq;
  242. struct kref kref;
  243. struct work_struct work;
  244. void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  245. void (*release)(struct kref *ref);
  246. };
  247. #define IRQ_AFFINITY_MAX_SETS 4
  248. /**
  249. * struct irq_affinity - Description for automatic irq affinity assignements
  250. * @pre_vectors: Don't apply affinity to @pre_vectors at beginning of
  251. * the MSI(-X) vector space
  252. * @post_vectors: Don't apply affinity to @post_vectors at end of
  253. * the MSI(-X) vector space
  254. * @nr_sets: The number of interrupt sets for which affinity
  255. * spreading is required
  256. * @set_size: Array holding the size of each interrupt set
  257. * @calc_sets: Callback for calculating the number and size
  258. * of interrupt sets
  259. * @priv: Private data for usage by @calc_sets, usually a
  260. * pointer to driver/device specific data.
  261. */
  262. struct irq_affinity {
  263. unsigned int pre_vectors;
  264. unsigned int post_vectors;
  265. unsigned int nr_sets;
  266. unsigned int set_size[IRQ_AFFINITY_MAX_SETS];
  267. void (*calc_sets)(struct irq_affinity *, unsigned int nvecs);
  268. void *priv;
  269. };
  270. /**
  271. * struct irq_affinity_desc - Interrupt affinity descriptor
  272. * @mask: cpumask to hold the affinity assignment
  273. * @is_managed: 1 if the interrupt is managed internally
  274. */
  275. struct irq_affinity_desc {
  276. struct cpumask mask;
  277. unsigned int is_managed : 1;
  278. };
  279. #if defined(CONFIG_SMP)
  280. extern cpumask_var_t irq_default_affinity;
  281. /* Internal implementation. Use the helpers below */
  282. extern int __irq_set_affinity(unsigned int irq, const struct cpumask *cpumask,
  283. bool force);
  284. /**
  285. * irq_set_affinity - Set the irq affinity of a given irq
  286. * @irq: Interrupt to set affinity
  287. * @cpumask: cpumask
  288. *
  289. * Fails if cpumask does not contain an online CPU
  290. */
  291. static inline int
  292. irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
  293. {
  294. return __irq_set_affinity(irq, cpumask, false);
  295. }
  296. /**
  297. * irq_force_affinity - Force the irq affinity of a given irq
  298. * @irq: Interrupt to set affinity
  299. * @cpumask: cpumask
  300. *
  301. * Same as irq_set_affinity, but without checking the mask against
  302. * online cpus.
  303. *
  304. * Solely for low level cpu hotplug code, where we need to make per
  305. * cpu interrupts affine before the cpu becomes online.
  306. */
  307. static inline int
  308. irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
  309. {
  310. return __irq_set_affinity(irq, cpumask, true);
  311. }
  312. extern int irq_can_set_affinity(unsigned int irq);
  313. extern int irq_select_affinity(unsigned int irq);
  314. extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m);
  315. extern int
  316. irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
  317. struct irq_affinity_desc *
  318. irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd);
  319. unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
  320. const struct irq_affinity *affd);
  321. #else /* CONFIG_SMP */
  322. static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
  323. {
  324. return -EINVAL;
  325. }
  326. static inline int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
  327. {
  328. return 0;
  329. }
  330. static inline int irq_can_set_affinity(unsigned int irq)
  331. {
  332. return 0;
  333. }
  334. static inline int irq_select_affinity(unsigned int irq) { return 0; }
  335. static inline int irq_set_affinity_hint(unsigned int irq,
  336. const struct cpumask *m)
  337. {
  338. return -EINVAL;
  339. }
  340. static inline int
  341. irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify)
  342. {
  343. return 0;
  344. }
  345. static inline struct irq_affinity_desc *
  346. irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd)
  347. {
  348. return NULL;
  349. }
  350. static inline unsigned int
  351. irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
  352. const struct irq_affinity *affd)
  353. {
  354. return maxvec;
  355. }
  356. #endif /* CONFIG_SMP */
  357. /*
  358. * Special lockdep variants of irq disabling/enabling.
  359. * These should be used for locking constructs that
  360. * know that a particular irq context which is disabled,
  361. * and which is the only irq-context user of a lock,
  362. * that it's safe to take the lock in the irq-disabled
  363. * section without disabling hardirqs.
  364. *
  365. * On !CONFIG_LOCKDEP they are equivalent to the normal
  366. * irq disable/enable methods.
  367. */
  368. static inline void disable_irq_nosync_lockdep(unsigned int irq)
  369. {
  370. disable_irq_nosync(irq);
  371. #ifdef CONFIG_LOCKDEP
  372. local_irq_disable();
  373. #endif
  374. }
  375. static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
  376. {
  377. disable_irq_nosync(irq);
  378. #ifdef CONFIG_LOCKDEP
  379. local_irq_save(*flags);
  380. #endif
  381. }
  382. static inline void disable_irq_lockdep(unsigned int irq)
  383. {
  384. disable_irq(irq);
  385. #ifdef CONFIG_LOCKDEP
  386. local_irq_disable();
  387. #endif
  388. }
  389. static inline void enable_irq_lockdep(unsigned int irq)
  390. {
  391. #ifdef CONFIG_LOCKDEP
  392. local_irq_enable();
  393. #endif
  394. enable_irq(irq);
  395. }
  396. static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
  397. {
  398. #ifdef CONFIG_LOCKDEP
  399. local_irq_restore(*flags);
  400. #endif
  401. enable_irq(irq);
  402. }
  403. /* IRQ wakeup (PM) control: */
  404. extern int irq_set_irq_wake(unsigned int irq, unsigned int on);
  405. static inline int enable_irq_wake(unsigned int irq)
  406. {
  407. return irq_set_irq_wake(irq, 1);
  408. }
  409. static inline int disable_irq_wake(unsigned int irq)
  410. {
  411. return irq_set_irq_wake(irq, 0);
  412. }
  413. /*
  414. * irq_get_irqchip_state/irq_set_irqchip_state specific flags
  415. */
  416. enum irqchip_irq_state {
  417. IRQCHIP_STATE_PENDING, /* Is interrupt pending? */
  418. IRQCHIP_STATE_ACTIVE, /* Is interrupt in progress? */
  419. IRQCHIP_STATE_MASKED, /* Is interrupt masked? */
  420. IRQCHIP_STATE_LINE_LEVEL, /* Is IRQ line high? */
  421. };
  422. extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  423. bool *state);
  424. extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  425. bool state);
  426. #ifdef CONFIG_IRQ_FORCED_THREADING
  427. # ifdef CONFIG_PREEMPT_RT
  428. # define force_irqthreads (true)
  429. # else
  430. extern bool force_irqthreads;
  431. # endif
  432. #else
  433. #define force_irqthreads (0)
  434. #endif
  435. #ifndef local_softirq_pending
  436. #ifndef local_softirq_pending_ref
  437. #define local_softirq_pending_ref irq_stat.__softirq_pending
  438. #endif
  439. #define local_softirq_pending() (__this_cpu_read(local_softirq_pending_ref))
  440. #define set_softirq_pending(x) (__this_cpu_write(local_softirq_pending_ref, (x)))
  441. #define or_softirq_pending(x) (__this_cpu_or(local_softirq_pending_ref, (x)))
  442. #endif /* local_softirq_pending */
  443. /* Some architectures might implement lazy enabling/disabling of
  444. * interrupts. In some cases, such as stop_machine, we might want
  445. * to ensure that after a local_irq_disable(), interrupts have
  446. * really been disabled in hardware. Such architectures need to
  447. * implement the following hook.
  448. */
  449. #ifndef hard_irq_disable
  450. #define hard_irq_disable() do { } while(0)
  451. #endif
  452. /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
  453. frequency threaded job scheduling. For almost all the purposes
  454. tasklets are more than enough. F.e. all serial device BHs et
  455. al. should be converted to tasklets, not to softirqs.
  456. */
  457. enum
  458. {
  459. HI_SOFTIRQ=0,
  460. TIMER_SOFTIRQ,
  461. NET_TX_SOFTIRQ,
  462. NET_RX_SOFTIRQ,
  463. BLOCK_SOFTIRQ,
  464. IRQ_POLL_SOFTIRQ,
  465. TASKLET_SOFTIRQ,
  466. SCHED_SOFTIRQ,
  467. HRTIMER_SOFTIRQ,
  468. RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
  469. NR_SOFTIRQS
  470. };
  471. #define SOFTIRQ_STOP_IDLE_MASK (~(1 << RCU_SOFTIRQ))
  472. /* Softirq's where the handling might be long: */
  473. #define LONG_SOFTIRQ_MASK ((1 << NET_TX_SOFTIRQ) | \
  474. (1 << NET_RX_SOFTIRQ) | \
  475. (1 << BLOCK_SOFTIRQ) | \
  476. (1 << IRQ_POLL_SOFTIRQ) | \
  477. (1 << TASKLET_SOFTIRQ))
  478. /* map softirq index to softirq name. update 'softirq_to_name' in
  479. * kernel/softirq.c when adding a new softirq.
  480. */
  481. extern const char * const softirq_to_name[NR_SOFTIRQS];
  482. /* softirq mask and active fields moved to irq_cpustat_t in
  483. * asm/hardirq.h to get better cache usage. KAO
  484. */
  485. struct softirq_action
  486. {
  487. void (*action)(struct softirq_action *);
  488. };
  489. asmlinkage void do_softirq(void);
  490. asmlinkage void __do_softirq(void);
  491. #ifdef __ARCH_HAS_DO_SOFTIRQ
  492. void do_softirq_own_stack(void);
  493. #else
  494. static inline void do_softirq_own_stack(void)
  495. {
  496. __do_softirq();
  497. }
  498. #endif
  499. extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  500. extern void softirq_init(void);
  501. extern void __raise_softirq_irqoff(unsigned int nr);
  502. extern void raise_softirq_irqoff(unsigned int nr);
  503. extern void raise_softirq(unsigned int nr);
  504. DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  505. DECLARE_PER_CPU(__u32, active_softirqs);
  506. static inline struct task_struct *this_cpu_ksoftirqd(void)
  507. {
  508. return this_cpu_read(ksoftirqd);
  509. }
  510. /* Tasklets --- multithreaded analogue of BHs.
  511. This API is deprecated. Please consider using threaded IRQs instead:
  512. https://lore.kernel.org/lkml/20200716081538.2sivhkj4hcyrusem@linutronix.de
  513. Main feature differing them of generic softirqs: tasklet
  514. is running only on one CPU simultaneously.
  515. Main feature differing them of BHs: different tasklets
  516. may be run simultaneously on different CPUs.
  517. Properties:
  518. * If tasklet_schedule() is called, then tasklet is guaranteed
  519. to be executed on some cpu at least once after this.
  520. * If the tasklet is already scheduled, but its execution is still not
  521. started, it will be executed only once.
  522. * If this tasklet is already running on another CPU (or schedule is called
  523. from tasklet itself), it is rescheduled for later.
  524. * Tasklet is strictly serialized wrt itself, but not
  525. wrt another tasklets. If client needs some intertask synchronization,
  526. he makes it with spinlocks.
  527. */
  528. struct tasklet_struct
  529. {
  530. struct tasklet_struct *next;
  531. unsigned long state;
  532. atomic_t count;
  533. bool use_callback;
  534. union {
  535. void (*func)(unsigned long data);
  536. void (*callback)(struct tasklet_struct *t);
  537. };
  538. unsigned long data;
  539. };
  540. #define DECLARE_TASKLET(name, _callback) \
  541. struct tasklet_struct name = { \
  542. .count = ATOMIC_INIT(0), \
  543. .callback = _callback, \
  544. .use_callback = true, \
  545. }
  546. #define DECLARE_TASKLET_DISABLED(name, _callback) \
  547. struct tasklet_struct name = { \
  548. .count = ATOMIC_INIT(1), \
  549. .callback = _callback, \
  550. .use_callback = true, \
  551. }
  552. #define from_tasklet(var, callback_tasklet, tasklet_fieldname) \
  553. container_of(callback_tasklet, typeof(*var), tasklet_fieldname)
  554. #define DECLARE_TASKLET_OLD(name, _func) \
  555. struct tasklet_struct name = { \
  556. .count = ATOMIC_INIT(0), \
  557. .func = _func, \
  558. }
  559. #define DECLARE_TASKLET_DISABLED_OLD(name, _func) \
  560. struct tasklet_struct name = { \
  561. .count = ATOMIC_INIT(1), \
  562. .func = _func, \
  563. }
  564. enum
  565. {
  566. TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
  567. TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
  568. };
  569. #ifdef CONFIG_SMP
  570. static inline int tasklet_trylock(struct tasklet_struct *t)
  571. {
  572. return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  573. }
  574. static inline void tasklet_unlock(struct tasklet_struct *t)
  575. {
  576. smp_mb__before_atomic();
  577. clear_bit(TASKLET_STATE_RUN, &(t)->state);
  578. }
  579. static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  580. {
  581. while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
  582. }
  583. #else
  584. #define tasklet_trylock(t) 1
  585. #define tasklet_unlock_wait(t) do { } while (0)
  586. #define tasklet_unlock(t) do { } while (0)
  587. #endif
  588. extern void __tasklet_schedule(struct tasklet_struct *t);
  589. static inline void tasklet_schedule(struct tasklet_struct *t)
  590. {
  591. if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  592. __tasklet_schedule(t);
  593. }
  594. extern void __tasklet_hi_schedule(struct tasklet_struct *t);
  595. static inline void tasklet_hi_schedule(struct tasklet_struct *t)
  596. {
  597. if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  598. __tasklet_hi_schedule(t);
  599. }
  600. static inline void tasklet_disable_nosync(struct tasklet_struct *t)
  601. {
  602. atomic_inc(&t->count);
  603. smp_mb__after_atomic();
  604. }
  605. static inline void tasklet_disable(struct tasklet_struct *t)
  606. {
  607. tasklet_disable_nosync(t);
  608. tasklet_unlock_wait(t);
  609. smp_mb();
  610. }
  611. static inline void tasklet_enable(struct tasklet_struct *t)
  612. {
  613. smp_mb__before_atomic();
  614. atomic_dec(&t->count);
  615. }
  616. extern void tasklet_kill(struct tasklet_struct *t);
  617. extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  618. extern void tasklet_init(struct tasklet_struct *t,
  619. void (*func)(unsigned long), unsigned long data);
  620. extern void tasklet_setup(struct tasklet_struct *t,
  621. void (*callback)(struct tasklet_struct *));
  622. /*
  623. * Autoprobing for irqs:
  624. *
  625. * probe_irq_on() and probe_irq_off() provide robust primitives
  626. * for accurate IRQ probing during kernel initialization. They are
  627. * reasonably simple to use, are not "fooled" by spurious interrupts,
  628. * and, unlike other attempts at IRQ probing, they do not get hung on
  629. * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
  630. *
  631. * For reasonably foolproof probing, use them as follows:
  632. *
  633. * 1. clear and/or mask the device's internal interrupt.
  634. * 2. sti();
  635. * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs
  636. * 4. enable the device and cause it to trigger an interrupt.
  637. * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
  638. * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple
  639. * 7. service the device to clear its pending interrupt.
  640. * 8. loop again if paranoia is required.
  641. *
  642. * probe_irq_on() returns a mask of allocated irq's.
  643. *
  644. * probe_irq_off() takes the mask as a parameter,
  645. * and returns the irq number which occurred,
  646. * or zero if none occurred, or a negative irq number
  647. * if more than one irq occurred.
  648. */
  649. #if !defined(CONFIG_GENERIC_IRQ_PROBE)
  650. static inline unsigned long probe_irq_on(void)
  651. {
  652. return 0;
  653. }
  654. static inline int probe_irq_off(unsigned long val)
  655. {
  656. return 0;
  657. }
  658. static inline unsigned int probe_irq_mask(unsigned long val)
  659. {
  660. return 0;
  661. }
  662. #else
  663. extern unsigned long probe_irq_on(void); /* returns 0 on failure */
  664. extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */
  665. extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */
  666. #endif
  667. #ifdef CONFIG_PROC_FS
  668. /* Initialize /proc/irq/ */
  669. extern void init_irq_proc(void);
  670. #else
  671. static inline void init_irq_proc(void)
  672. {
  673. }
  674. #endif
  675. #ifdef CONFIG_IRQ_TIMINGS
  676. void irq_timings_enable(void);
  677. void irq_timings_disable(void);
  678. u64 irq_timings_next_event(u64 now);
  679. #endif
  680. struct seq_file;
  681. int show_interrupts(struct seq_file *p, void *v);
  682. int arch_show_interrupts(struct seq_file *p, int prec);
  683. extern int early_irq_init(void);
  684. extern int arch_probe_nr_irqs(void);
  685. extern int arch_early_irq_init(void);
  686. /*
  687. * We want to know which function is an entrypoint of a hardirq or a softirq.
  688. */
  689. #ifndef __irq_entry
  690. # define __irq_entry __section(".irqentry.text")
  691. #endif
  692. #define __softirq_entry __section(".softirqentry.text")
  693. #endif