1*3f2dd94aSFrançois Tigeot /*
2*3f2dd94aSFrançois Tigeot * Copyright (c) 2020 François Tigeot <ftigeot@wolfpond.org>
3*3f2dd94aSFrançois Tigeot * All rights reserved.
4*3f2dd94aSFrançois Tigeot *
5*3f2dd94aSFrançois Tigeot * Redistribution and use in source and binary forms, with or without
6*3f2dd94aSFrançois Tigeot * modification, are permitted provided that the following conditions
7*3f2dd94aSFrançois Tigeot * are met:
8*3f2dd94aSFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
9*3f2dd94aSFrançois Tigeot * notice unmodified, this list of conditions, and the following
10*3f2dd94aSFrançois Tigeot * disclaimer.
11*3f2dd94aSFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
12*3f2dd94aSFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
13*3f2dd94aSFrançois Tigeot * documentation and/or other materials provided with the distribution.
14*3f2dd94aSFrançois Tigeot *
15*3f2dd94aSFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*3f2dd94aSFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*3f2dd94aSFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*3f2dd94aSFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*3f2dd94aSFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*3f2dd94aSFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*3f2dd94aSFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTIRQ_WORKUPTION) HOWEVER CAUSED AND ON ANY
22*3f2dd94aSFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*3f2dd94aSFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*3f2dd94aSFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*3f2dd94aSFrançois Tigeot */
26*3f2dd94aSFrançois Tigeot
27*3f2dd94aSFrançois Tigeot #ifndef _LINUX_IRQ_WORK_H_
28*3f2dd94aSFrançois Tigeot #define _LINUX_IRQ_WORK_H_
29*3f2dd94aSFrançois Tigeot
30*3f2dd94aSFrançois Tigeot #include <linux/llist.h>
31*3f2dd94aSFrançois Tigeot
32*3f2dd94aSFrançois Tigeot #include <linux/workqueue.h>
33*3f2dd94aSFrançois Tigeot
34*3f2dd94aSFrançois Tigeot struct irq_work {
35*3f2dd94aSFrançois Tigeot struct work_struct ws;
36*3f2dd94aSFrançois Tigeot };
37*3f2dd94aSFrançois Tigeot
38*3f2dd94aSFrançois Tigeot static inline void
init_irq_work(struct irq_work * work,void (* func)(struct irq_work *))39*3f2dd94aSFrançois Tigeot init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
40*3f2dd94aSFrançois Tigeot {
41*3f2dd94aSFrançois Tigeot INIT_WORK(&work->ws, (void (*)(struct work_struct *))func);
42*3f2dd94aSFrançois Tigeot }
43*3f2dd94aSFrançois Tigeot
44*3f2dd94aSFrançois Tigeot static inline bool
irq_work_queue(struct irq_work * work)45*3f2dd94aSFrançois Tigeot irq_work_queue(struct irq_work *work)
46*3f2dd94aSFrançois Tigeot {
47*3f2dd94aSFrançois Tigeot /* XXX: irq_works are supposed to be processed in hardirq context */
48*3f2dd94aSFrançois Tigeot queue_work(system_highpri_wq, &work->ws);
49*3f2dd94aSFrançois Tigeot
50*3f2dd94aSFrançois Tigeot return true;
51*3f2dd94aSFrançois Tigeot }
52*3f2dd94aSFrançois Tigeot
53*3f2dd94aSFrançois Tigeot #endif /* _LINUX_IRQ_WORK_H_ */
54