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>
19 #endif /*CAN_WITH_RTL*/
21 /*#define __NO_VERSION__*/
22 /*#include <linux/module.h>*/
24 #include <linux/version.h>
25 #include <linux/wait.h>
26 #include <linux/list.h>
28 #include <linux/ioport.h>
29 #include <linux/delay.h>
30 #include <linux/sched.h>
31 #include <linux/interrupt.h>
32 #include <asm/errno.h>
35 #include <asm/atomic.h>
37 #include <asm/uaccess.h>
39 #include "lincan_config.h"
42 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
43 #define CAN_ENABLE_KERN_FASYNC
45 #define CAN_ENABLE_PCI_SUPPORT
47 #ifdef CONFIG_OC_LINCANVME
48 #define CAN_ENABLE_VME_SUPPORT
52 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
53 #include <linux/malloc.h>
55 #include <linux/slab.h>
58 #ifdef CAN_ENABLE_PCI_SUPPORT
59 #include "linux/pci.h"
60 #endif /*CAN_ENABLE_PCI_SUPPORT*/
62 /* Next is not sctrictly correct, because of 2.3.0, 2.3.1, 2.3.2
63 kernels need next definitions too */
64 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,19)) /* may need correction */
65 #define wait_queue_head_t struct wait_queue *
66 #define wait_queue_t struct wait_queue
67 #define init_waitqueue_head(queue_head) (*queue_head=NULL)
68 #define init_waitqueue_entry(qentry,qtask) \
69 (qentry->next=NULL,qentry->task=qtask)
70 #define DECLARE_WAIT_QUEUE_HEAD(name) \
71 struct wait_queue * name=NULL
72 #define DECLARE_WAITQUEUE(wait, current) \
73 struct wait_queue wait = { current, NULL }
74 #define init_MUTEX(sem) (*sem=MUTEX)
75 #define DECLARE_MUTEX(name) struct semaphore name=MUTEX
78 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)) && !defined(DECLARE_TASKLET)
79 #define tasklet_struct tq_struct
80 #define DECLARE_TASKLET(_name, _func, _data) \
81 struct tq_struct _name = { sync: 0, routine: _func, data: (void*)_data }
83 /* void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data); */
84 #define tasklet_init(_tasklet, _func, _data) \
86 /* (_tasklet)->next=NULL; */ \
87 /* Above not needed for 2.2.x and buggy for 2.4.x */ \
89 (_tasklet)->routine=_func; \
90 (_tasklet)->data=(void*)_data; \
93 /* void tasklet_schedule(struct tasklet_struct *t) */
94 #define tasklet_schedule(_tasklet) \
96 queue_task(_tasklet,&tq_immediate); \
97 mark_bh(IMMEDIATE_BH); \
100 /* void tasklet_kill(struct tasklet_struct *t); */
101 #define tasklet_kill(_tasklet) \
107 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
110 (MINOR(file->f_dentry->d_inode->i_rdev))
112 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
115 (minor(file->f_dentry->d_inode->i_rdev))
117 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
120 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68)) && !defined(IRQ_RETVAL))
121 typedef void can_irqreturn_t;
123 #define CAN_IRQ_HANDLED
124 #define CAN_IRQ_RETVAL(x)
126 typedef irqreturn_t can_irqreturn_t;
127 #define CAN_IRQ_NONE IRQ_NONE
128 #define CAN_IRQ_HANDLED IRQ_HANDLED
129 #define CAN_IRQ_RETVAL IRQ_RETVAL
130 #endif /* <=2.5.67 */
131 #else /*CAN_WITH_RTL*/
132 typedef int can_irqreturn_t;
133 #define CAN_IRQ_NONE 0
134 #define CAN_IRQ_HANDLED 1
135 #define CAN_IRQ_RETVAL(x) ((x) != 0)
136 #endif /*CAN_WITH_RTL*/
138 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,33))
139 #define can_synchronize_irq(irqnum) synchronize_irq()
141 #define can_synchronize_irq synchronize_irq
144 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
145 #define del_timer_sync del_timer
149 /* Standard LINUX kernel */
151 #define can_spinlock_t spinlock_t
152 #define can_spin_irqflags_t unsigned long
153 #define can_spin_lock spin_lock
154 #define can_spin_unlock spin_unlock
155 #define can_spin_lock_irqsave spin_lock_irqsave
156 #define can_spin_unlock_irqrestore spin_unlock_irqrestore
157 #define can_spin_lock_init spin_lock_init
159 #if defined(CONFIG_PREEMPT) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
160 #define can_preempt_disable preempt_disable
161 #define can_preempt_enable preempt_enable
162 #else /*CONFIG_PREEMPT*/
163 #define can_preempt_disable() do { } while (0)
164 #define can_preempt_enable() do { } while (0)
165 #endif /*CONFIG_PREEMPT*/
167 #define can_enable_irq enable_irq
168 #define can_disable_irq disable_irq
170 #define can_printk printk
172 #else /*CAN_WITH_RTL*/
174 #define can_spinlock_t rtl_spinlock_t
175 #define can_spin_irqflags_t rtl_irqstate_t
176 #define can_spin_lock rtl_spin_lock
177 #define can_spin_unlock rtl_spin_unlock
178 #define can_spin_lock_irqsave rtl_spin_lock_irqsave
179 #define can_spin_unlock_irqrestore rtl_spin_unlock_irqrestore
180 #define can_spin_lock_init rtl_spin_lock_init
182 #define can_preempt_disable() do { } while (0)
183 #define can_preempt_enable() do { } while (0)
185 #define can_enable_irq rtl_hard_enable_irq
186 #define can_disable_irq rtl_hard_disable_irq
188 #define can_printk rtl_printf
191 * terrible hack to test rtl_file private_data concept, ugh !!!
192 * this would result in crash on architectures, where
193 * sizeof(int) < sizeof(void *)
195 #define can_set_rtl_file_private_data(fptr, p) do{ fptr->f_minor=(long)(p); } while(0)
196 #define can_get_rtl_file_private_data(fptr) ((void*)((fptr)->f_minor))
198 extern can_spinlock_t can_irq_manipulation_lock;
200 #endif /*CAN_WITH_RTL*/
202 #endif /*_CAN_SYSDEP_H*/