1 /* can_sysdep.h - hides differences between individual Linux kernel
2 * versions and RT extensions
3 * Linux CAN-bus device driver.
4 * Written by Pavel Pisa - OCERA team member
5 * email:pisa@cmp.felk.cvut.cz
6 * This software is released under the GPL-License.
7 * Version lincan-0.3 17 Jun 2004
17 #include <rtl_mutex.h>
18 #include <rtl_sched.h>
20 #endif /*CAN_WITH_RTL*/
22 /*#define __NO_VERSION__*/
23 /*#include <linux/module.h>*/
25 #include <linux/version.h>
26 #include <linux/wait.h>
27 #include <linux/list.h>
29 #include <linux/ioport.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
32 #include <linux/interrupt.h>
33 #include <asm/errno.h>
36 #include <asm/atomic.h>
38 #include <asm/uaccess.h>
40 #include "lincan_config.h"
43 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
44 #define CAN_ENABLE_KERN_FASYNC
46 #define CAN_ENABLE_PCI_SUPPORT
48 #ifdef CONFIG_OC_LINCANVME
49 #define CAN_ENABLE_VME_SUPPORT
53 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
54 #include <linux/malloc.h>
56 #include <linux/slab.h>
59 #ifdef CAN_ENABLE_PCI_SUPPORT
60 #include "linux/pci.h"
61 #endif /*CAN_ENABLE_PCI_SUPPORT*/
63 /* Next is not sctrictly correct, because of 2.3.0, 2.3.1, 2.3.2
64 kernels need next definitions too */
65 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,19)) /* may need correction */
66 #define wait_queue_head_t struct wait_queue *
67 #define wait_queue_t struct wait_queue
68 #define init_waitqueue_head(queue_head) (*queue_head=NULL)
69 #define init_waitqueue_entry(qentry,qtask) \
70 (qentry->next=NULL,qentry->task=qtask)
71 #define DECLARE_WAIT_QUEUE_HEAD(name) \
72 struct wait_queue * name=NULL
73 #define DECLARE_WAITQUEUE(wait, current) \
74 struct wait_queue wait = { current, NULL }
75 #define init_MUTEX(sem) (*sem=MUTEX)
76 #define DECLARE_MUTEX(name) struct semaphore name=MUTEX
79 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)) && !defined(DECLARE_TASKLET)
80 #define tasklet_struct tq_struct
81 #define DECLARE_TASKLET(_name, _func, _data) \
82 struct tq_struct _name = { sync: 0, routine: _func, data: (void*)_data }
84 /* void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data); */
85 #define tasklet_init(_tasklet, _func, _data) \
87 /* (_tasklet)->next=NULL; */ \
88 /* Above not needed for 2.2.x and buggy for 2.4.x */ \
90 (_tasklet)->routine=_func; \
91 (_tasklet)->data=(void*)_data; \
94 /* void tasklet_schedule(struct tasklet_struct *t) */
95 #define tasklet_schedule(_tasklet) \
97 queue_task(_tasklet,&tq_immediate); \
98 mark_bh(IMMEDIATE_BH); \
101 /* void tasklet_kill(struct tasklet_struct *t); */
102 #define tasklet_kill(_tasklet) \
108 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
111 (MINOR(file->f_dentry->d_inode->i_rdev))
113 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
116 (minor(file->f_dentry->d_inode->i_rdev))
118 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
121 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68)) && !defined(IRQ_RETVAL))
122 typedef void can_irqreturn_t;
124 #define CAN_IRQ_HANDLED
125 #define CAN_IRQ_RETVAL(x)
127 typedef irqreturn_t can_irqreturn_t;
128 #define CAN_IRQ_NONE IRQ_NONE
129 #define CAN_IRQ_HANDLED IRQ_HANDLED
130 #define CAN_IRQ_RETVAL IRQ_RETVAL
131 #endif /* <=2.5.67 */
132 #else /*CAN_WITH_RTL*/
133 typedef int can_irqreturn_t;
134 #define CAN_IRQ_NONE 0
135 #define CAN_IRQ_HANDLED 1
136 #define CAN_IRQ_RETVAL(x) ((x) != 0)
137 #endif /*CAN_WITH_RTL*/
139 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,33))
140 #define can_synchronize_irq(irqnum) synchronize_irq()
142 #define can_synchronize_irq synchronize_irq
145 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
146 #define del_timer_sync del_timer
149 #ifdef __HAVE_ARCH_CMPXCHG
150 #define CAN_HAVE_ARCH_CMPXCHG
154 /* Standard LINUX kernel */
156 #define can_spinlock_t spinlock_t
157 #define can_spin_irqflags_t unsigned long
158 #define can_spin_lock spin_lock
159 #define can_spin_unlock spin_unlock
160 #define can_spin_lock_irqsave spin_lock_irqsave
161 #define can_spin_unlock_irqrestore spin_unlock_irqrestore
162 #define can_spin_lock_init spin_lock_init
164 #ifndef DEFINE_SPINLOCK
165 #define CAN_DEFINE_SPINLOCK(x) can_spinlock_t x = SPIN_LOCK_UNLOCKED
166 #else /*DEFINE_SPINLOCK*/
167 #define CAN_DEFINE_SPINLOCK DEFINE_SPINLOCK
168 #endif /*DEFINE_SPINLOCK*/
170 #if defined(CONFIG_PREEMPT) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
171 #define can_preempt_disable preempt_disable
172 #define can_preempt_enable preempt_enable
173 #else /*CONFIG_PREEMPT*/
174 #define can_preempt_disable() do { } while (0)
175 #define can_preempt_enable() do { } while (0)
176 #endif /*CONFIG_PREEMPT*/
178 #define can_enable_irq enable_irq
179 #define can_disable_irq disable_irq
181 #define can_printk printk
183 /* CAN message timestamp source, it is called from interrupt context */
184 #define can_gettimeofday do_gettimeofday
186 #else /*CAN_WITH_RTL*/
188 #define can_spinlock_t rtl_spinlock_t
189 #define can_spin_irqflags_t rtl_irqstate_t
190 #define can_spin_lock rtl_spin_lock
191 #define can_spin_unlock rtl_spin_unlock
192 #define can_spin_lock_irqsave rtl_spin_lock_irqsave
193 #define can_spin_unlock_irqrestore rtl_spin_unlock_irqrestore
194 #define can_spin_lock_init rtl_spin_lock_init
196 #define CAN_DEFINE_SPINLOCK(x) can_spinlock_t x = SPIN_LOCK_UNLOCKED
198 #define can_preempt_disable() do { } while (0)
199 #define can_preempt_enable() do { } while (0)
201 #define can_enable_irq rtl_hard_enable_irq
202 #define can_disable_irq rtl_hard_disable_irq
204 #define can_printk rtl_printf
207 * terrible hack to test rtl_file private_data concept, ugh !!!
208 * this would result in crash on architectures, where
209 * sizeof(int) < sizeof(void *)
211 #define can_set_rtl_file_private_data(fptr, p) do{ fptr->f_minor=(long)(p); } while(0)
212 #define can_get_rtl_file_private_data(fptr) ((void*)((fptr)->f_minor))
214 extern can_spinlock_t can_irq_manipulation_lock;
216 /* CAN message timestamp source, it is called from interrupt context */
217 #define can_gettimeofday(ptr) do {\
218 struct timespec temp_timespec;\
219 clock_gettime(CLOCK_REALTIME,&temp_timespec);\
220 ptr->tv_usec=temp_timespec.tv_nsec/1000;\
221 ptr->tv_sec=temp_timespec.tv_sec;\
224 #endif /*CAN_WITH_RTL*/
226 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4))
227 #include <linux/kthread.h>
228 #define can_kthread_create kthread_create
229 #define can_kthread_run kthread_run
230 #define can_kthread_bind kthread_bind
231 #define can_kthread_stop kthread_stop
232 #define can_kthread_should_stop kthread_should_stop
234 #define can_kthread_create
235 #define can_kthread_run
236 #define can_kthread_bind
237 #define can_kthread_stop
238 #define can_kthread_should_stop
242 #endif /*_CAN_SYSDEP_H*/