]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/can_sysdep.h
CPC-PCI second chip IRQ corrected. Message timestamp code added.
[lincan.git] / lincan / include / can_sysdep.h
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
8  */
9
10 #ifndef _CAN_SYSDEP_H
11 #define _CAN_SYSDEP_H
12
13 #ifdef CAN_WITH_RTL
14 #include <rtl.h>
15 #include <rtl_sync.h>
16 #include <rtl_core.h>
17 #include <rtl_mutex.h>
18 #include <rtl_sched.h>
19 #endif /*CAN_WITH_RTL*/
20
21 /*#define __NO_VERSION__*/
22 /*#include <linux/module.h>*/
23
24 #include <linux/version.h>
25 #include <linux/wait.h>
26 #include <linux/list.h>
27 #include <linux/fs.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>
33
34 #include <asm/io.h>
35 #include <asm/atomic.h>
36 #include <asm/irq.h>
37 #include <asm/uaccess.h>
38
39 #include "lincan_config.h"
40
41 /*optional features*/
42 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
43 #define CAN_ENABLE_KERN_FASYNC
44 #ifdef CONFIG_PCI
45 #define CAN_ENABLE_PCI_SUPPORT
46 #endif
47 #ifdef CONFIG_OC_LINCANVME
48 #define CAN_ENABLE_VME_SUPPORT
49 #endif
50 #endif
51
52 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
53 #include <linux/malloc.h>
54 #else
55 #include <linux/slab.h>
56 #endif
57
58 #ifdef CAN_ENABLE_PCI_SUPPORT
59 #include "linux/pci.h"
60 #endif /*CAN_ENABLE_PCI_SUPPORT*/
61
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
76 #endif /* 2.2.19 */
77
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 }
82
83   /* void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data); */
84   #define tasklet_init(_tasklet, _func, _data) \
85     do{ \
86        /* (_tasklet)->next=NULL; */ \
87        /* Above not needed for 2.2.x and buggy for 2.4.x */ \
88        (_tasklet)->sync=0; \
89        (_tasklet)->routine=_func; \
90        (_tasklet)->data=(void*)_data; \
91     }while(0)
92
93   /* void tasklet_schedule(struct tasklet_struct *t) */
94   #define tasklet_schedule(_tasklet) \
95     do{ \
96        queue_task(_tasklet,&tq_immediate); \
97        mark_bh(IMMEDIATE_BH); \
98     }while(0)
99
100   /* void tasklet_kill(struct tasklet_struct *t); */
101   #define tasklet_kill(_tasklet) \
102                 synchronize_irq()
103
104 #endif /* 2.4.0 */
105
106
107 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
108
109 #define MINOR_NR \
110         (MINOR(file->f_dentry->d_inode->i_rdev))
111
112 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
113
114 #define MINOR_NR \
115         (minor(file->f_dentry->d_inode->i_rdev))
116
117 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
118
119 #ifndef CAN_WITH_RTL
120 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68)) && !defined(IRQ_RETVAL))
121   typedef void can_irqreturn_t;
122   #define CAN_IRQ_NONE
123   #define CAN_IRQ_HANDLED
124   #define CAN_IRQ_RETVAL(x)
125 #else /* <=2.5.67 */
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*/
137
138 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,33))
139    #define can_synchronize_irq(irqnum) synchronize_irq()
140 #else /* >=2.5.33 */
141    #define can_synchronize_irq synchronize_irq
142 #endif
143
144 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
145   #define del_timer_sync del_timer
146 #endif /* <2.4.0 */
147
148 #ifdef __HAVE_ARCH_CMPXCHG
149   #define CAN_HAVE_ARCH_CMPXCHG
150 #endif
151
152 #ifndef CAN_WITH_RTL
153 /* Standard LINUX kernel */
154
155 #define can_spinlock_t             spinlock_t
156 #define can_spin_irqflags_t        unsigned long
157 #define can_spin_lock              spin_lock
158 #define can_spin_unlock            spin_unlock
159 #define can_spin_lock_irqsave      spin_lock_irqsave
160 #define can_spin_unlock_irqrestore spin_unlock_irqrestore
161 #define can_spin_lock_init         spin_lock_init
162
163 #if defined(CONFIG_PREEMPT) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
164 #define can_preempt_disable        preempt_disable
165 #define can_preempt_enable         preempt_enable
166 #else /*CONFIG_PREEMPT*/
167 #define can_preempt_disable()      do { } while (0)
168 #define can_preempt_enable()       do { } while (0)
169 #endif /*CONFIG_PREEMPT*/
170
171 #define can_enable_irq             enable_irq
172 #define can_disable_irq            disable_irq
173
174 #define can_printk                 printk
175
176 #else /*CAN_WITH_RTL*/
177
178 #define can_spinlock_t             rtl_spinlock_t
179 #define can_spin_irqflags_t        rtl_irqstate_t
180 #define can_spin_lock              rtl_spin_lock
181 #define can_spin_unlock            rtl_spin_unlock
182 #define can_spin_lock_irqsave      rtl_spin_lock_irqsave
183 #define can_spin_unlock_irqrestore rtl_spin_unlock_irqrestore
184 #define can_spin_lock_init         rtl_spin_lock_init
185
186 #define can_preempt_disable()      do { } while (0)
187 #define can_preempt_enable()       do { } while (0)
188
189 #define can_enable_irq             rtl_hard_enable_irq
190 #define can_disable_irq            rtl_hard_disable_irq
191
192 #define can_printk                 rtl_printf
193
194 /*
195  * terrible hack to test rtl_file private_data concept, ugh !!!
196  * this would result in crash on architectures,  where 
197  * sizeof(int) < sizeof(void *)
198  */
199 #define can_set_rtl_file_private_data(fptr, p) do{ fptr->f_minor=(long)(p); } while(0)
200 #define can_get_rtl_file_private_data(fptr) ((void*)((fptr)->f_minor))
201
202 extern can_spinlock_t can_irq_manipulation_lock;
203
204 #endif /*CAN_WITH_RTL*/
205
206 /* CAN message timestamp source, it is called from interrupt context */
207 #define can_gettimeofday do_gettimeofday
208
209 #endif /*_CAN_SYSDEP_H*/