]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/can_sysdep.h
Added option for VME bus support
[lincan.git] / lincan / include / can_sysdep.h
1 #ifndef _CAN_SYSDEP_H
2 #define _CAN_SYSDEP_H
3
4 #ifdef CAN_WITH_RTL
5 #include <rtl.h>
6 #include <rtl_sync.h>
7 #include <rtl_core.h>
8 #include <rtl_mutex.h>
9 #include <rtl_sched.h>
10 #endif /*CAN_WITH_RTL*/
11
12 /*#define __NO_VERSION__*/
13 /*#include <linux/module.h>*/
14
15 #include <linux/version.h>
16 #include <linux/wait.h>
17 #include <linux/list.h>
18 #include <linux/fs.h>
19 #include <linux/ioport.h>
20 #include <linux/delay.h>
21 #include <linux/sched.h>
22 #include <linux/interrupt.h>
23 #include <asm/errno.h>
24
25 #include <asm/io.h>
26 #include <asm/atomic.h>
27 #include <asm/irq.h>
28 #include <asm/uaccess.h>
29
30 /*optional features*/
31 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
32 #define CAN_ENABLE_KERN_FASYNC
33 #ifdef CONFIG_PCI
34 #define CAN_ENABLE_PCI_SUPPORT
35 #endif
36 #ifdef CONFIG_OC_LINCAN_VME
37 #define CAN_ENABLE_VME_SUPPORT
38 #endif
39 #endif
40
41 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
42 #include <linux/malloc.h>
43 #else
44 #include <linux/slab.h>
45 #endif
46
47 #ifdef CAN_ENABLE_PCI_SUPPORT
48 #include "linux/pci.h"
49 #endif /*CAN_ENABLE_PCI_SUPPORT*/
50
51 /* Next is not sctrictly correct, because of 2.3.0, 2.3.1, 2.3.2
52    kernels need next definitions  too */
53 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,19)) /* may need correction */
54   #define wait_queue_head_t struct wait_queue *
55   #define wait_queue_t      struct wait_queue
56   #define init_waitqueue_head(queue_head) (*queue_head=NULL)
57   #define init_waitqueue_entry(qentry,qtask) \
58                         (qentry->next=NULL,qentry->task=qtask)
59   #define DECLARE_WAIT_QUEUE_HEAD(name) \
60         struct wait_queue * name=NULL
61   #define DECLARE_WAITQUEUE(wait, current) \
62         struct wait_queue wait = { current, NULL }
63   #define init_MUTEX(sem) (*sem=MUTEX)
64   #define DECLARE_MUTEX(name) struct semaphore name=MUTEX
65 #endif /* 2.2.19 */
66
67 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)) && !defined(DECLARE_TASKLET)
68   #define tasklet_struct tq_struct
69   #define DECLARE_TASKLET(_name, _func, _data) \
70                 struct tq_struct _name = { sync: 0, routine: _func, data: (void*)_data }
71
72   /* void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data); */
73   #define tasklet_init(_tasklet, _func, _data) \
74     do{ \
75        /* (_tasklet)->next=NULL; */ \
76        /* Above not needed for 2.2.x and buggy for 2.4.x */ \
77        (_tasklet)->sync=0; \
78        (_tasklet)->routine=_func; \
79        (_tasklet)->data=(void*)_data; \
80     }while(0)
81
82   /* void tasklet_schedule(struct tasklet_struct *t) */
83   #define tasklet_schedule(_tasklet) \
84     do{ \
85        queue_task(_tasklet,&tq_immediate); \
86        mark_bh(IMMEDIATE_BH); \
87     }while(0)
88
89   /* void tasklet_kill(struct tasklet_struct *t); */
90   #define tasklet_kill(_tasklet) \
91                 synchronize_irq()
92
93 #endif /* 2.4.0 */
94
95
96 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
97
98 #define MINOR_NR \
99         (MINOR(file->f_dentry->d_inode->i_rdev))
100
101 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
102
103 #define MINOR_NR \
104         (minor(file->f_dentry->d_inode->i_rdev))
105
106 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
107
108 #ifndef CAN_WITH_RTL
109 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68)) && !defined(IRQ_RETVAL))
110   typedef void can_irqreturn_t;
111   #define CAN_IRQ_NONE
112   #define CAN_IRQ_HANDLED
113   #define CAN_IRQ_RETVAL(x)
114 #else /* <=2.5.67 */
115   typedef irqreturn_t can_irqreturn_t;
116   #define CAN_IRQ_NONE    IRQ_NONE
117   #define CAN_IRQ_HANDLED IRQ_HANDLED
118   #define CAN_IRQ_RETVAL  IRQ_RETVAL
119 #endif /* <=2.5.67 */
120 #else /*CAN_WITH_RTL*/
121   typedef int can_irqreturn_t;
122   #define CAN_IRQ_NONE        0
123   #define CAN_IRQ_HANDLED     1
124   #define CAN_IRQ_RETVAL(x)   ((x) != 0)
125 #endif /*CAN_WITH_RTL*/
126
127 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,33))
128    #define can_synchronize_irq(irqnum) synchronize_irq()
129 #else /* >=2.5.33 */
130    #define can_synchronize_irq synchronize_irq
131 #endif
132
133 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
134   #define del_timer_sync del_timer
135 #endif /* <2.4.0 */
136
137 #ifndef CAN_WITH_RTL
138 /* Standard LINUX kernel */
139
140 #define can_spinlock_t             spinlock_t
141 #define can_spin_irqflags_t        unsigned long
142 #define can_spin_lock              spin_lock
143 #define can_spin_unlock            spin_unlock
144 #define can_spin_lock_irqsave      spin_lock_irqsave
145 #define can_spin_unlock_irqrestore spin_unlock_irqrestore
146 #define can_spin_lock_init         spin_lock_init
147
148 #if defined(CONFIG_PREEMPT) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
149 #define can_preempt_disable        preempt_disable
150 #define can_preempt_enable         preempt_enable
151 #else /*CONFIG_PREEMPT*/
152 #define can_preempt_disable()      do { } while (0)
153 #define can_preempt_enable()       do { } while (0)
154 #endif /*CONFIG_PREEMPT*/
155
156 #define can_enable_irq             enable_irq
157 #define can_disable_irq            disable_irq
158
159 #define can_printk                 printk
160
161 #else /*CAN_WITH_RTL*/
162
163 #define can_spinlock_t             rtl_spinlock_t
164 #define can_spin_irqflags_t        rtl_irqstate_t
165 #define can_spin_lock              rtl_spin_lock
166 #define can_spin_unlock            rtl_spin_unlock
167 #define can_spin_lock_irqsave      rtl_spin_lock_irqsave
168 #define can_spin_unlock_irqrestore rtl_spin_unlock_irqrestore
169 #define can_spin_lock_init         rtl_spin_lock_init
170
171 #define can_preempt_disable()      do { } while (0)
172 #define can_preempt_enable()       do { } while (0)
173
174 #define can_enable_irq             rtl_hard_enable_irq
175 #define can_disable_irq            rtl_hard_disable_irq
176
177 #define can_printk                 rtl_printf
178
179 /*
180  * terrible hack to test rtl_file private_data concept, ugh !!!
181  * this would result in crash on architectures,  where 
182  * sizeof(int) < sizeof(void *)
183  */
184 #define can_set_rtl_file_private_data(fptr, p) do{ fptr->f_minor=(long)(p); } while(0)
185 #define can_get_rtl_file_private_data(fptr) ((void*)((fptr)->f_minor))
186
187 extern can_spinlock_t can_irq_manipulation_lock;
188
189 #endif /*CAN_WITH_RTL*/
190
191 #endif /*_CAN_SYSDEP_H*/