Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_IRQ_WORK_H
0003 #define _LINUX_IRQ_WORK_H
0004 
0005 #include <linux/smp_types.h>
0006 #include <linux/rcuwait.h>
0007 
0008 /*
0009  * An entry can be in one of four states:
0010  *
0011  * free      NULL, 0 -> {claimed}       : free to be used
0012  * claimed   NULL, 3 -> {pending}       : claimed to be enqueued
0013  * pending   next, 3 -> {busy}          : queued, pending callback
0014  * busy      NULL, 2 -> {free, claimed} : callback in progress, can be claimed
0015  */
0016 
0017 struct irq_work {
0018     struct __call_single_node node;
0019     void (*func)(struct irq_work *);
0020     struct rcuwait irqwait;
0021 };
0022 
0023 #define __IRQ_WORK_INIT(_func, _flags) (struct irq_work){   \
0024     .node = { .u_flags = (_flags), },           \
0025     .func = (_func),                    \
0026     .irqwait = __RCUWAIT_INITIALIZER(irqwait),      \
0027 }
0028 
0029 #define IRQ_WORK_INIT(_func) __IRQ_WORK_INIT(_func, 0)
0030 #define IRQ_WORK_INIT_LAZY(_func) __IRQ_WORK_INIT(_func, IRQ_WORK_LAZY)
0031 #define IRQ_WORK_INIT_HARD(_func) __IRQ_WORK_INIT(_func, IRQ_WORK_HARD_IRQ)
0032 
0033 #define DEFINE_IRQ_WORK(name, _f)               \
0034     struct irq_work name = IRQ_WORK_INIT(_f)
0035 
0036 static inline
0037 void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
0038 {
0039     *work = IRQ_WORK_INIT(func);
0040 }
0041 
0042 static inline bool irq_work_is_pending(struct irq_work *work)
0043 {
0044     return atomic_read(&work->node.a_flags) & IRQ_WORK_PENDING;
0045 }
0046 
0047 static inline bool irq_work_is_busy(struct irq_work *work)
0048 {
0049     return atomic_read(&work->node.a_flags) & IRQ_WORK_BUSY;
0050 }
0051 
0052 static inline bool irq_work_is_hard(struct irq_work *work)
0053 {
0054     return atomic_read(&work->node.a_flags) & IRQ_WORK_HARD_IRQ;
0055 }
0056 
0057 bool irq_work_queue(struct irq_work *work);
0058 bool irq_work_queue_on(struct irq_work *work, int cpu);
0059 
0060 void irq_work_tick(void);
0061 void irq_work_sync(struct irq_work *work);
0062 
0063 #ifdef CONFIG_IRQ_WORK
0064 #include <asm/irq_work.h>
0065 
0066 void irq_work_run(void);
0067 bool irq_work_needs_cpu(void);
0068 void irq_work_single(void *arg);
0069 #else
0070 static inline bool irq_work_needs_cpu(void) { return false; }
0071 static inline void irq_work_run(void) { }
0072 static inline void irq_work_single(void *arg) { }
0073 #endif
0074 
0075 #endif /* _LINUX_IRQ_WORK_H */