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