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