1*e17fad91Sjsg /* $OpenBSD: irq_work.h,v 1.9 2022/07/27 07:08:34 jsg Exp $ */
2979a8f2dSjsg /*
3979a8f2dSjsg * Copyright (c) 2015 Mark Kettenis
4979a8f2dSjsg *
5979a8f2dSjsg * Permission to use, copy, modify, and distribute this software for any
6979a8f2dSjsg * purpose with or without fee is hereby granted, provided that the above
7979a8f2dSjsg * copyright notice and this permission notice appear in all copies.
8979a8f2dSjsg *
9979a8f2dSjsg * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10979a8f2dSjsg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11979a8f2dSjsg * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12979a8f2dSjsg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13979a8f2dSjsg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14979a8f2dSjsg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15979a8f2dSjsg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16979a8f2dSjsg */
17979a8f2dSjsg
18979a8f2dSjsg #ifndef _LINUX_IRQ_WORK_H
19979a8f2dSjsg #define _LINUX_IRQ_WORK_H
20979a8f2dSjsg
21979a8f2dSjsg #include <sys/param.h>
22979a8f2dSjsg #include <sys/systm.h>
2399460583Sjsg #include <sys/task.h>
2499460583Sjsg
25*e17fad91Sjsg #include <linux/llist.h>
26*e17fad91Sjsg
2799460583Sjsg struct workqueue_struct;
2899460583Sjsg
2999460583Sjsg extern struct workqueue_struct *system_wq;
30979a8f2dSjsg
31*e17fad91Sjsg struct irq_node {
32*e17fad91Sjsg struct llist_node llist;
33*e17fad91Sjsg };
34*e17fad91Sjsg
35979a8f2dSjsg struct irq_work {
3699460583Sjsg struct task task;
3799460583Sjsg struct taskq *tq;
38*e17fad91Sjsg struct irq_node node;
39979a8f2dSjsg };
40979a8f2dSjsg
41979a8f2dSjsg typedef void (*irq_work_func_t)(struct irq_work *);
42979a8f2dSjsg
43979a8f2dSjsg static inline void
init_irq_work(struct irq_work * work,irq_work_func_t func)44979a8f2dSjsg init_irq_work(struct irq_work *work, irq_work_func_t func)
45979a8f2dSjsg {
4699460583Sjsg work->tq = (struct taskq *)system_wq;
4799460583Sjsg task_set(&work->task, (void (*)(void *))func, work);
48979a8f2dSjsg }
49979a8f2dSjsg
50979a8f2dSjsg static inline bool
irq_work_queue(struct irq_work * work)51979a8f2dSjsg irq_work_queue(struct irq_work *work)
52979a8f2dSjsg {
5399460583Sjsg return task_add(work->tq, &work->task);
54979a8f2dSjsg }
55979a8f2dSjsg
56ad8b1aafSjsg static inline void
irq_work_sync(struct irq_work * work)57ad8b1aafSjsg irq_work_sync(struct irq_work *work)
58ad8b1aafSjsg {
5999460583Sjsg taskq_barrier(work->tq);
60ad8b1aafSjsg }
61ad8b1aafSjsg
62979a8f2dSjsg #endif
63