xref: /openbsd-src/sys/dev/pci/drm/include/linux/interrupt.h (revision ff0e7be1ebbcc809ea8ad2b6dafe215824da9e46)
1 /* Public domain. */
2 
3 #ifndef _LINUX_INTERRUPT_H
4 #define _LINUX_INTERRUPT_H
5 
6 #include <sys/task.h>
7 
8 #include <machine/intr.h>
9 #include <linux/hardirq.h>
10 #include <linux/irqflags.h>
11 #include <linux/atomic.h>
12 #include <linux/irqreturn.h>
13 
14 struct seq_file;
15 
16 #define IRQF_SHARED	0
17 
18 #define request_irq(irq, hdlr, flags, name, dev)	(0)
19 
20 static inline void
21 free_irq(unsigned int irq, void *dev)
22 {
23 }
24 
25 typedef irqreturn_t (*irq_handler_t)(int, void *);
26 
27 struct tasklet_struct {
28 	union {
29 		void (*func)(unsigned long);
30 		void (*callback)(struct tasklet_struct *);
31 	};
32 	bool use_callback;
33 	unsigned long data;
34 	unsigned long state;
35 	atomic_t count;
36 	struct task task;
37 };
38 
39 #define TASKLET_STATE_SCHED	1
40 #define TASKLET_STATE_RUN	0
41 
42 #define from_tasklet(x, t, f) \
43 	container_of(t, typeof(*x), f)
44 
45 extern struct taskq *taskletq;
46 void tasklet_run(void *);
47 void tasklet_unlock_wait(struct tasklet_struct *);
48 void tasklet_unlock_spin_wait(struct tasklet_struct *);
49 
50 static inline void
51 tasklet_init(struct tasklet_struct *ts, void (*func)(unsigned long),
52     unsigned long data)
53 {
54 	ts->func = func;
55 	ts->data = data;
56 	ts->state = 0;
57 	atomic_set(&ts->count, 0);
58 	ts->use_callback = false;
59 	task_set(&ts->task, tasklet_run, ts);
60 }
61 
62 static inline void
63 tasklet_setup(struct tasklet_struct *ts,
64     void (*callback)(struct tasklet_struct *))
65 {
66 	ts->callback = callback;
67 	ts->data = 0;
68 	ts->state = 0;
69 	atomic_set(&ts->count, 0);
70 	ts->use_callback = true;
71 	task_set(&ts->task, tasklet_run, ts);
72 }
73 
74 static inline int
75 tasklet_trylock(struct tasklet_struct *ts)
76 {
77 	return !test_and_set_bit(TASKLET_STATE_RUN, &ts->state);
78 }
79 
80 static inline void
81 tasklet_unlock(struct tasklet_struct *ts)
82 {
83 	smp_mb__before_atomic();
84 	clear_bit(TASKLET_STATE_RUN, &ts->state);
85 }
86 
87 static inline void
88 tasklet_kill(struct tasklet_struct *ts)
89 {
90 	clear_bit(TASKLET_STATE_SCHED, &ts->state);
91 	task_del(taskletq, &ts->task);
92 	tasklet_unlock_wait(ts);
93 }
94 
95 static inline void
96 tasklet_schedule(struct tasklet_struct *ts)
97 {
98 	set_bit(TASKLET_STATE_SCHED, &ts->state);
99 	task_add(taskletq, &ts->task);
100 }
101 
102 static inline void
103 tasklet_hi_schedule(struct tasklet_struct *ts)
104 {
105 	set_bit(TASKLET_STATE_SCHED, &ts->state);
106 	task_add(taskletq, &ts->task);
107 }
108 
109 static inline void
110 tasklet_disable_nosync(struct tasklet_struct *ts)
111 {
112 	atomic_inc(&ts->count);
113 	smp_mb__after_atomic();
114 }
115 
116 static inline void
117 tasklet_enable(struct tasklet_struct *ts)
118 {
119 	smp_mb__before_atomic();
120 	atomic_dec(&ts->count);
121 }
122 
123 #endif
124