drm/linux: Add linux/hardirq.h
[dragonfly.git] / sys / dev / drm / include / linux / interrupt.h
blobe77ccc65bf3373a330c200170d08d75f24c575c2
1 /*
2 * Copyright (c) 2017 François Tigeot
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef _LINUX_INTERRUPT_H_
28 #define _LINUX_INTERRUPT_H_
30 #include <linux/kernel.h>
31 #include <linux/bitops.h>
32 #include <linux/irqflags.h>
33 #include <linux/hardirq.h>
34 #include <linux/hrtimer.h>
35 #include <linux/kref.h>
37 #include <linux/atomic.h>
39 struct tasklet_struct {
40 unsigned long state;
41 void (*func)(unsigned long);
42 unsigned long data;
43 struct lock lock;
46 enum {
47 TASKLET_STATE_SCHED,
48 TASKLET_STATE_RUN
52 * TODO: verify these points:
53 * - tasklets that have the same type cannot be run on multiple processors at the same time
54 * - tasklets always run on the processor from which they were originally
55 * submitted
56 * - when a tasklet is scheduled, its state is set to TASKLET_STATE_SCHED, and the tasklet
57 * added to a queue
58 * - during the execution of its function, the tasklet state is set to TASKLET_STATE_RUN
59 * and the TASKLET_STATE_SCHED state is removed
62 /* XXX scheduling and execution should be handled separately */
63 static inline void
64 tasklet_schedule(struct tasklet_struct *t)
66 set_bit(TASKLET_STATE_SCHED, &t->state);
68 lockmgr(&t->lock, LK_EXCLUSIVE);
69 clear_bit(TASKLET_STATE_SCHED, &t->state);
71 set_bit(TASKLET_STATE_RUN, &t->state);
72 if (t->func)
73 t->func(t->data);
74 clear_bit(TASKLET_STATE_RUN, &t->state);
76 lockmgr(&t->lock, LK_RELEASE);
79 /* This function ensures that the tasklet is not scheduled to run again */
80 /* XXX this doesn't kill anything */
81 static inline void
82 tasklet_kill(struct tasklet_struct *t)
84 lockmgr(&t->lock, LK_EXCLUSIVE);
85 clear_bit(TASKLET_STATE_SCHED, &t->state);
86 lockmgr(&t->lock, LK_RELEASE);
89 static inline void
90 tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data)
92 lockinit(&t->lock, "ltasklet", 0, LK_CANRECURSE);
93 t->state = 0;
94 t->func = func;
95 t->data = data;
98 #endif /* _LINUX_INTERRUPT_H_ */