Merge branch 'for-2.6.30' into for-2.6.31
[pandora-kernel.git] / drivers / staging / comedi / comedi_rt.h
1 /*
2     module/comedi_rt.h
3     header file for real-time structures, variables, and constants
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24 #ifndef _COMEDI_RT_H
25 #define _COMEDI_RT_H
26
27 #ifndef _COMEDIDEV_H
28 #error comedi_rt.h should only be included by comedidev.h
29 #endif
30
31 #include <linux/kdev_t.h>
32 #include <linux/slab.h>
33 #include <linux/errno.h>
34 #include <linux/spinlock.h>
35 #include <linux/delay.h>
36
37 #ifdef CONFIG_COMEDI_RT
38
39 #ifdef CONFIG_COMEDI_RTAI
40 #include <rtai.h>
41 #include <rtai_sched.h>
42 #include <rtai_version.h>
43 #endif
44 #ifdef CONFIG_COMEDI_RTL
45 #include <rtl_core.h>
46 #include <rtl_time.h>
47 /* #ifdef RTLINUX_VERSION_CODE */
48 #include <rtl_sync.h>
49 /* #endif */
50 #define rt_printk rtl_printf
51 #endif
52 #ifdef CONFIG_COMEDI_FUSION
53 #define rt_printk(format, args...) printk(format , ## args)
54 #endif /* CONFIG_COMEDI_FUSION */
55 #ifdef CONFIG_PRIORITY_IRQ
56 #define rt_printk printk
57 #endif
58
59 int comedi_request_irq(unsigned int irq, irqreturn_t(*handler) (int,
60                 void *PT_REGS_ARG), unsigned long flags, const char *device,
61                 struct comedi_device *dev_id);
62 void comedi_free_irq(unsigned int irq, struct comedi_device *dev_id);
63 void comedi_rt_init(void);
64 void comedi_rt_cleanup(void);
65 int comedi_switch_to_rt(struct comedi_device *dev);
66 void comedi_switch_to_non_rt(struct comedi_device *dev);
67 void comedi_rt_pend_wakeup(wait_queue_head_t *q);
68 extern int rt_pend_call(void (*func) (int arg1, void *arg2), int arg1,
69         void *arg2);
70
71 #else
72
73 #define comedi_request_irq(a, b, c, d, e) request_irq(a, b, c, d, e)
74 #define comedi_free_irq(a, b) free_irq(a, b)
75 #define comedi_rt_init() do {} while (0)
76 #define comedi_rt_cleanup() do {} while (0)
77 #define comedi_switch_to_rt(a) (-1)
78 #define comedi_switch_to_non_rt(a) do {} while (0)
79 #define comedi_rt_pend_wakeup(a) do {} while (0)
80
81 #define rt_printk(format, args...)      printk(format, ##args)
82
83 #endif
84
85 /* Define a spin_lock_irqsave function that will work with rt or without.
86  * Use inline functions instead of just macros to enforce some type checking.
87  */
88 #define comedi_spin_lock_irqsave(lock_ptr, flags) \
89         (flags = __comedi_spin_lock_irqsave(lock_ptr))
90
91 static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t *lock_ptr)
92 {
93         unsigned long flags;
94
95 #if defined(CONFIG_COMEDI_RTAI)
96         flags = rt_spin_lock_irqsave(lock_ptr);
97
98 #elif defined(CONFIG_COMEDI_RTL)
99         rtl_spin_lock_irqsave(lock_ptr, flags);
100
101 #elif defined(CONFIG_COMEDI_RTL_V1)
102         rtl_spin_lock_irqsave(lock_ptr, flags);
103
104 #elif defined(CONFIG_COMEDI_FUSION)
105         rthal_spin_lock_irqsave(lock_ptr, flags);
106 #else
107         spin_lock_irqsave(lock_ptr, flags);
108
109 #endif
110
111         return flags;
112 }
113
114 static inline void comedi_spin_unlock_irqrestore(spinlock_t *lock_ptr,
115         unsigned long flags)
116 {
117
118 #if defined(CONFIG_COMEDI_RTAI)
119         rt_spin_unlock_irqrestore(flags, lock_ptr);
120
121 #elif defined(CONFIG_COMEDI_RTL)
122         rtl_spin_unlock_irqrestore(lock_ptr, flags);
123
124 #elif defined(CONFIG_COMEDI_RTL_V1)
125         rtl_spin_unlock_irqrestore(lock_ptr, flags);
126 #elif defined(CONFIG_COMEDI_FUSION)
127         rthal_spin_unlock_irqrestore(lock_ptr, flags);
128 #else
129         spin_unlock_irqrestore(lock_ptr, flags);
130
131 #endif
132
133 }
134
135 /* define a RT safe udelay */
136 static inline void comedi_udelay(unsigned int usec)
137 {
138 #if defined(CONFIG_COMEDI_RTAI)
139         static const int nanosec_per_usec = 1000;
140         rt_busy_sleep(usec * nanosec_per_usec);
141 #elif defined(CONFIG_COMEDI_RTL)
142         static const int nanosec_per_usec = 1000;
143         rtl_delay(usec * nanosec_per_usec);
144 #else
145         udelay(usec);
146 #endif
147 }
148
149 #endif