irq_work.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /*
  6. * An entry can be in one of four states:
  7. *
  8. * free NULL, 0 -> {claimed} : free to be used
  9. * claimed NULL, 3 -> {pending} : claimed to be enqueued
  10. * pending next, 3 -> {busy} : queued, pending callback
  11. * busy NULL, 2 -> {free, claimed} : callback in progress, can be claimed
  12. */
  13. struct irq_work {
  14. union {
  15. struct __call_single_node node;
  16. struct {
  17. struct llist_node llnode;
  18. atomic_t flags;
  19. };
  20. };
  21. void (*func)(struct irq_work *);
  22. };
  23. static inline
  24. void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
  25. {
  26. atomic_set(&work->flags, 0);
  27. work->func = func;
  28. }
  29. #define DEFINE_IRQ_WORK(name, _f) struct irq_work name = { \
  30. .flags = ATOMIC_INIT(0), \
  31. .func = (_f) \
  32. }
  33. bool irq_work_queue(struct irq_work *work);
  34. bool irq_work_queue_on(struct irq_work *work, int cpu);
  35. void irq_work_tick(void);
  36. void irq_work_sync(struct irq_work *work);
  37. #ifdef CONFIG_IRQ_WORK
  38. #include <asm/irq_work.h>
  39. void irq_work_run(void);
  40. bool irq_work_needs_cpu(void);
  41. void irq_work_single(void *arg);
  42. #else
  43. static inline bool irq_work_needs_cpu(void) { return false; }
  44. static inline void irq_work_run(void) { }
  45. static inline void irq_work_single(void *arg) { }
  46. #endif
  47. #endif /* _LINUX_IRQ_WORK_H */