xref: /dragonfly/sys/dev/drm/include/linux/interrupt.h (revision 265a1428)
1 /*
2  * Copyright (c) 2017-2019 François Tigeot <ftigeot@wolfpond.org>
3  * All rights reserved.
4  *
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.
14  *
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.
25  */
26 
27 #ifndef _LINUX_INTERRUPT_H_
28 #define _LINUX_INTERRUPT_H_
29 
30 #include <linux/kernel.h>
31 #include <linux/bitops.h>
32 #include <linux/preempt.h>
33 #include <linux/cpumask.h>
34 #include <linux/irqreturn.h>
35 #include <linux/hardirq.h>
36 #include <linux/irqflags.h>
37 #include <linux/hrtimer.h>
38 #include <linux/kref.h>
39 
40 #include <linux/atomic.h>
41 
42 #define IRQF_SHARED	0x00000080
43 
44 struct tasklet_struct {
45 	unsigned long state;
46 	void (*func)(unsigned long);
47 	unsigned long data;
48 	struct lock lock;
49 };
50 
51 enum {
52 	TASKLET_STATE_SCHED,
53 	TASKLET_STATE_RUN
54 };
55 
56 /*
57  * TODO: verify these points:
58  * - tasklets that have the same type cannot be run on multiple processors at the same time
59  * - tasklets always run on the processor from which they were originally
60  *   submitted
61  * - when a tasklet is scheduled, its state is set to TASKLET_STATE_SCHED, and the tasklet
62  *   added to a queue
63  * - during the execution of its function, the tasklet state is set to TASKLET_STATE_RUN
64  *   and the TASKLET_STATE_SCHED state is removed
65  */
66 
67 /* XXX scheduling and execution should be handled separately */
68 static inline void
69 tasklet_schedule(struct tasklet_struct *t)
70 {
71 	set_bit(TASKLET_STATE_SCHED, &t->state);
72 
73 	lockmgr(&t->lock, LK_EXCLUSIVE);
74 	clear_bit(TASKLET_STATE_SCHED, &t->state);
75 
76 	set_bit(TASKLET_STATE_RUN, &t->state);
77 	if (t->func)
78 		t->func(t->data);
79 	clear_bit(TASKLET_STATE_RUN, &t->state);
80 
81 	lockmgr(&t->lock, LK_RELEASE);
82 }
83 
84 /* This function ensures that the tasklet is not scheduled to run again */
85 /* XXX this doesn't kill anything */
86 static inline void
87 tasklet_kill(struct tasklet_struct *t)
88 {
89 	lockmgr(&t->lock, LK_EXCLUSIVE);
90 	clear_bit(TASKLET_STATE_SCHED, &t->state);
91 	lockmgr(&t->lock, LK_RELEASE);
92 }
93 
94 static inline void
95 tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data)
96 {
97 	lockinit(&t->lock, "ltasklet", 0, LK_CANRECURSE);
98 	t->state = 0;
99 	t->func = func;
100 	t->data = data;
101 }
102 
103 typedef irqreturn_t (*irq_handler_t)(int, void *);
104 
105 int request_irq(unsigned int irq, irq_handler_t handler,
106 		unsigned long flags, const char *name, void *dev);
107 
108 void free_irq(unsigned int irq, void *dev_id);
109 
110 #endif	/* _LINUX_INTERRUPT_H_ */
111