irq_work.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_IRQ_WORK_H
  3. #define _LINUX_IRQ_WORK_H
  4. #include <linux/smp_types.h>
  5. #include <linux/rcuwait.h>
  6. /*
  7. * An entry can be in one of four states:
  8. *
  9. * free NULL, 0 -> {claimed} : free to be used
  10. * claimed NULL, 3 -> {pending} : claimed to be enqueued
  11. * pending next, 3 -> {busy} : queued, pending callback
  12. * busy NULL, 2 -> {free, claimed} : callback in progress, can be claimed
  13. */
  14. struct irq_work {
  15. struct __call_single_node node;
  16. void (*func)(struct irq_work *);
  17. struct rcuwait irqwait;
  18. };
  19. #define __IRQ_WORK_INIT(_func, _flags) (struct irq_work){ \
  20. .node = { .u_flags = (_flags), }, \
  21. .func = (_func), \
  22. .irqwait = __RCUWAIT_INITIALIZER(irqwait), \
  23. }
  24. #define IRQ_WORK_INIT(_func) __IRQ_WORK_INIT(_func, 0)
  25. #define IRQ_WORK_INIT_LAZY(_func) __IRQ_WORK_INIT(_func, IRQ_WORK_LAZY)
  26. #define IRQ_WORK_INIT_HARD(_func) __IRQ_WORK_INIT(_func, IRQ_WORK_HARD_IRQ)
  27. #define DEFINE_IRQ_WORK(name, _f) \
  28. struct irq_work name = IRQ_WORK_INIT(_f)
  29. static inline
  30. void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
  31. {
  32. *work = IRQ_WORK_INIT(func);
  33. }
  34. static inline bool irq_work_is_pending(struct irq_work *work)
  35. {
  36. return atomic_read(&work->node.a_flags) & IRQ_WORK_PENDING;
  37. }
  38. static inline bool irq_work_is_busy(struct irq_work *work)
  39. {
  40. return atomic_read(&work->node.a_flags) & IRQ_WORK_BUSY;
  41. }
  42. static inline bool irq_work_is_hard(struct irq_work *work)
  43. {
  44. return atomic_read(&work->node.a_flags) & IRQ_WORK_HARD_IRQ;
  45. }
  46. bool irq_work_queue(struct irq_work *work);
  47. bool irq_work_queue_on(struct irq_work *work, int cpu);
  48. void irq_work_tick(void);
  49. void irq_work_sync(struct irq_work *work);
  50. #ifdef CONFIG_IRQ_WORK
  51. #include <asm/irq_work.h>
  52. void irq_work_run(void);
  53. bool irq_work_needs_cpu(void);
  54. void irq_work_single(void *arg);
  55. #else
  56. static inline bool irq_work_needs_cpu(void) { return false; }
  57. static inline void irq_work_run(void) { }
  58. static inline void irq_work_single(void *arg) { }
  59. #endif
  60. #endif /* _LINUX_IRQ_WORK_H */