blob: 02da997ad12cedc723ff42b0027323f30001ec7b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Peter Zijlstrae360adb2010-10-14 14:01:34 +08002#ifndef _LINUX_IRQ_WORK_H
3#define _LINUX_IRQ_WORK_H
4
Huang Ying38aaf802011-09-08 14:00:46 +08005#include <linux/llist.h>
6
Frederic Weisbeckerbc6679a2012-10-19 16:43:41 -04007/*
8 * An entry can be in one of four states:
9 *
10 * free NULL, 0 -> {claimed} : free to be used
11 * claimed NULL, 3 -> {pending} : claimed to be enqueued
12 * pending next, 3 -> {busy} : queued, pending callback
13 * busy NULL, 2 -> {free, claimed} : callback in progress, can be claimed
14 */
15
Bartosz Golaszewski6baf9e62018-01-05 05:19:56 +010016#define IRQ_WORK_PENDING BIT(0)
17#define IRQ_WORK_BUSY BIT(1)
18
19/* Doesn't want IPI, wait for tick: */
20#define IRQ_WORK_LAZY BIT(2)
21
22#define IRQ_WORK_CLAIMED (IRQ_WORK_PENDING | IRQ_WORK_BUSY)
Frederic Weisbeckerbc6679a2012-10-19 16:43:41 -040023
Peter Zijlstrae360adb2010-10-14 14:01:34 +080024struct irq_work {
Frederic Weisbecker153bedb2019-11-08 17:08:55 +010025 atomic_t flags;
Huang Ying38aaf802011-09-08 14:00:46 +080026 struct llist_node llnode;
Peter Zijlstrae360adb2010-10-14 14:01:34 +080027 void (*func)(struct irq_work *);
28};
29
30static inline
Huang Ying38aaf802011-09-08 14:00:46 +080031void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
Peter Zijlstrae360adb2010-10-14 14:01:34 +080032{
Frederic Weisbecker153bedb2019-11-08 17:08:55 +010033 atomic_set(&work->flags, 0);
Huang Ying38aaf802011-09-08 14:00:46 +080034 work->func = func;
Peter Zijlstrae360adb2010-10-14 14:01:34 +080035}
36
Frederic Weisbecker153bedb2019-11-08 17:08:55 +010037#define DEFINE_IRQ_WORK(name, _f) struct irq_work name = { \
38 .flags = ATOMIC_INIT(0), \
39 .func = (_f) \
40}
41
Peter Zijlstra6a02ad662014-02-03 18:11:08 +010042
Peter Zijlstracd578ab2014-02-11 16:01:16 +010043bool irq_work_queue(struct irq_work *work);
Frederic Weisbecker47885012014-05-08 01:37:48 +020044bool irq_work_queue_on(struct irq_work *work, int cpu);
Frederic Weisbecker47885012014-05-08 01:37:48 +020045
Frederic Weisbecker76a33062014-08-16 18:37:19 +020046void irq_work_tick(void);
Huang Ying38aaf802011-09-08 14:00:46 +080047void irq_work_sync(struct irq_work *work);
Peter Zijlstrae360adb2010-10-14 14:01:34 +080048
Frederic Weisbecker00b42952012-11-07 21:03:07 +010049#ifdef CONFIG_IRQ_WORK
Peter Zijlstrac5c38ef2014-09-06 15:43:02 +020050#include <asm/irq_work.h>
51
Steven Rostedt71ad00d2015-03-19 10:18:51 -040052void irq_work_run(void);
Frederic Weisbecker00b42952012-11-07 21:03:07 +010053bool irq_work_needs_cpu(void);
54#else
James Hoganfe8d5262013-03-22 15:04:37 -070055static inline bool irq_work_needs_cpu(void) { return false; }
Steven Rostedt71ad00d2015-03-19 10:18:51 -040056static inline void irq_work_run(void) { }
Frederic Weisbecker00b42952012-11-07 21:03:07 +010057#endif
58
Peter Zijlstrae360adb2010-10-14 14:01:34 +080059#endif /* _LINUX_IRQ_WORK_H */