blob: 0e81035b678f00817969cfae6c4ab6469da66a1d [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
16#define IRQ_WORK_PENDING 1UL
17#define IRQ_WORK_BUSY 2UL
18#define IRQ_WORK_FLAGS 3UL
19#define IRQ_WORK_LAZY 4UL /* Doesn't want IPI, wait for tick */
20
Peter Zijlstrae360adb2010-10-14 14:01:34 +080021struct irq_work {
Huang Ying38aaf802011-09-08 14:00:46 +080022 unsigned long flags;
23 struct llist_node llnode;
Peter Zijlstrae360adb2010-10-14 14:01:34 +080024 void (*func)(struct irq_work *);
25};
26
27static inline
Huang Ying38aaf802011-09-08 14:00:46 +080028void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
Peter Zijlstrae360adb2010-10-14 14:01:34 +080029{
Huang Ying38aaf802011-09-08 14:00:46 +080030 work->flags = 0;
31 work->func = func;
Peter Zijlstrae360adb2010-10-14 14:01:34 +080032}
33
Peter Zijlstra6a02ad662014-02-03 18:11:08 +010034#define DEFINE_IRQ_WORK(name, _f) struct irq_work name = { .func = (_f), }
35
Peter Zijlstracd578ab2014-02-11 16:01:16 +010036bool irq_work_queue(struct irq_work *work);
Frederic Weisbecker47885012014-05-08 01:37:48 +020037bool irq_work_queue_on(struct irq_work *work, int cpu);
Frederic Weisbecker47885012014-05-08 01:37:48 +020038
Frederic Weisbecker76a33062014-08-16 18:37:19 +020039void irq_work_tick(void);
Huang Ying38aaf802011-09-08 14:00:46 +080040void irq_work_sync(struct irq_work *work);
Peter Zijlstrae360adb2010-10-14 14:01:34 +080041
Frederic Weisbecker00b42952012-11-07 21:03:07 +010042#ifdef CONFIG_IRQ_WORK
Peter Zijlstrac5c38ef2014-09-06 15:43:02 +020043#include <asm/irq_work.h>
44
Steven Rostedt71ad00d2015-03-19 10:18:51 -040045void irq_work_run(void);
Frederic Weisbecker00b42952012-11-07 21:03:07 +010046bool irq_work_needs_cpu(void);
47#else
James Hoganfe8d5262013-03-22 15:04:37 -070048static inline bool irq_work_needs_cpu(void) { return false; }
Steven Rostedt71ad00d2015-03-19 10:18:51 -040049static inline void irq_work_run(void) { }
Frederic Weisbecker00b42952012-11-07 21:03:07 +010050#endif
51
Peter Zijlstrae360adb2010-10-14 14:01:34 +080052#endif /* _LINUX_IRQ_WORK_H */