1 /* $OpenBSD: irq_work.h,v 1.9 2022/07/27 07:08:34 jsg Exp $ */ 2 /* 3 * Copyright (c) 2015 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _LINUX_IRQ_WORK_H 19 #define _LINUX_IRQ_WORK_H 20 21 #include <sys/param.h> 22 #include <sys/systm.h> 23 #include <sys/task.h> 24 25 #include <linux/llist.h> 26 27 struct workqueue_struct; 28 29 extern struct workqueue_struct *system_wq; 30 31 struct irq_node { 32 struct llist_node llist; 33 }; 34 35 struct irq_work { 36 struct task task; 37 struct taskq *tq; 38 struct irq_node node; 39 }; 40 41 typedef void (*irq_work_func_t)(struct irq_work *); 42 43 static inline void 44 init_irq_work(struct irq_work *work, irq_work_func_t func) 45 { 46 work->tq = (struct taskq *)system_wq; 47 task_set(&work->task, (void (*)(void *))func, work); 48 } 49 50 static inline bool 51 irq_work_queue(struct irq_work *work) 52 { 53 return task_add(work->tq, &work->task); 54 } 55 56 static inline void 57 irq_work_sync(struct irq_work *work) 58 { 59 taskq_barrier(work->tq); 60 } 61 62 #endif 63