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 14 #ifndef STUB 15 #include <sys/types.h> 16 #include <sys/systm.h> 17 #define STUB() do { printf("%s: stub\n", __func__); } while(0) 18 #endif 19 20 #define IRQF_SHARED 0 21 22 #define disable_irq(x) intr_disable() 23 #define enable_irq(x) intr_enable() 24 25 #define request_irq(irq, hdlr, flags, name, dev) (0) 26 #define free_irq(irq, dev) 27 28 struct tasklet_struct { 29 void (*func)(unsigned long); 30 unsigned long data; 31 unsigned long state; 32 atomic_t count; 33 struct task task; 34 }; 35 36 #define TASKLET_STATE_SCHED 1 37 #define TASKLET_STATE_RUN 0 38 39 extern struct taskq *taskletq; 40 void tasklet_run(void *); 41 42 static inline void 43 tasklet_init(struct tasklet_struct *ts, void (*func)(unsigned long), 44 unsigned long data) 45 { 46 ts->func = func; 47 ts->data = data; 48 ts->state = 0; 49 atomic_set(&ts->count, 0); 50 task_set(&ts->task, tasklet_run, ts); 51 } 52 53 static inline int 54 tasklet_trylock(struct tasklet_struct *ts) 55 { 56 return !test_and_set_bit(TASKLET_STATE_RUN, &ts->state); 57 } 58 59 static inline void 60 tasklet_unlock(struct tasklet_struct *ts) 61 { 62 smp_mb__before_atomic(); 63 clear_bit(TASKLET_STATE_RUN, &ts->state); 64 } 65 66 static inline void 67 tasklet_unlock_wait(struct tasklet_struct *ts) 68 { 69 while (test_bit(TASKLET_STATE_RUN, &ts->state)) 70 barrier(); 71 } 72 73 static inline void 74 tasklet_kill(struct tasklet_struct *ts) 75 { 76 clear_bit(TASKLET_STATE_SCHED, &ts->state); 77 task_del(taskletq, &ts->task); 78 tasklet_unlock_wait(ts); 79 } 80 81 static inline void 82 tasklet_schedule(struct tasklet_struct *ts) 83 { 84 set_bit(TASKLET_STATE_SCHED, &ts->state); 85 task_add(taskletq, &ts->task); 86 } 87 88 static inline void 89 tasklet_hi_schedule(struct tasklet_struct *ts) 90 { 91 set_bit(TASKLET_STATE_SCHED, &ts->state); 92 task_add(taskletq, &ts->task); 93 } 94 95 #endif 96