xref: /openbsd-src/sys/dev/pci/drm/include/linux/irq_work.h (revision 4e1ee0786f11cc571bd0be17d38e46f635c719fc)
1 /*	$OpenBSD: irq_work.h,v 1.5 2021/08/11 16:14:00 sthen 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 struct workqueue_struct;
26 
27 extern struct workqueue_struct *system_wq;
28 
29 struct irq_work {
30 	struct task task;
31 	struct taskq *tq;
32 };
33 
34 typedef void (*irq_work_func_t)(struct irq_work *);
35 
36 static inline void
37 init_irq_work(struct irq_work *work, irq_work_func_t func)
38 {
39 	work->tq = (struct taskq *)system_wq;
40 	task_set(&work->task, (void (*)(void *))func, work);
41 }
42 
43 static inline bool
44 irq_work_queue(struct irq_work *work)
45 {
46 	return task_add(work->tq, &work->task);
47 }
48 
49 static inline void
50 irq_work_sync(struct irq_work *work)
51 {
52 	taskq_barrier(work->tq);
53 }
54 
55 #endif
56