]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/can_sysdep.h
56cfc4ed2ffcfbf20cfda693b460770ccbbd18a0
[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 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
31 #include <linux/malloc.h>
32 #else
33 #include <linux/slab.h>
34 #endif
35
36
37 /* Next is not sctrictly correct, because of 2.3.0, 2.3.1, 2.3.2
38    kernels need next definitions  too */
39 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,19)) /* may need correction */
40   #define wait_queue_head_t struct wait_queue *
41   #define wait_queue_t      struct wait_queue
42   #define init_waitqueue_head(queue_head) (*queue_head=NULL)
43   #define init_waitqueue_entry(qentry,qtask) \
44                         (qentry->next=NULL,qentry->task=qtask)
45   #define DECLARE_WAIT_QUEUE_HEAD(name) \
46         struct wait_queue * name=NULL
47   #define DECLARE_WAITQUEUE(wait, current) \
48         struct wait_queue wait = { current, NULL }
49   #define init_MUTEX(sem) (*sem=MUTEX)
50   #define DECLARE_MUTEX(name) struct semaphore name=MUTEX
51 #endif /* 2.2.19 */
52
53
54 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
55
56 #define MINOR_NR \
57         (MINOR(file->f_dentry->d_inode->i_rdev))
58
59 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
60
61 #define MINOR_NR \
62         (minor(file->f_dentry->d_inode->i_rdev))
63
64 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
65
66 #ifndef CAN_WITH_RTL
67 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68)) && !defined(IRQ_RETVAL))
68   typedef void can_irqreturn_t;
69   #define CAN_IRQ_NONE
70   #define CAN_IRQ_HANDLED
71   #define CAN_IRQ_RETVAL(x)
72 #else /* <=2.5.67 */
73   typedef irqreturn_t can_irqreturn_t;
74   #define CAN_IRQ_NONE    IRQ_NONE
75   #define CAN_IRQ_HANDLED IRQ_HANDLED
76   #define CAN_IRQ_RETVAL  IRQ_RETVAL
77 #endif /* <=2.5.67 */
78 #else /*CAN_WITH_RTL*/
79   typedef int can_irqreturn_t;
80   #define CAN_IRQ_NONE        0
81   #define CAN_IRQ_HANDLED     1
82   #define CAN_IRQ_RETVAL(x)   ((x) != 0)
83 #endif /*CAN_WITH_RTL*/
84
85 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,33))
86    #define can_synchronize_irq(irqnum) synchronize_irq()
87 #else /* >=2.5.33 */
88    #define can_synchronize_irq synchronize_irq
89 #endif
90
91 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
92   #define del_timer_sync del_timer
93 #endif /* <2.4.0 */
94
95 #define CAN_ENABLE_KERN_FASYNC
96
97 #ifndef CAN_WITH_RTL
98 /* Standard LINUX kernel */
99
100 #define can_spinlock_t             spinlock_t
101 #define can_spin_irqflags_t        unsigned long
102 #define can_spin_lock              spin_lock
103 #define can_spin_unlock            spin_unlock
104 #define can_spin_lock_irqsave      spin_lock_irqsave
105 #define can_spin_unlock_irqrestore spin_unlock_irqrestore
106 #define can_spin_lock_init         spin_lock_init
107
108 #if defined(CONFIG_PREEMPT) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
109 #define can_preempt_disable        preempt_disable
110 #define can_preempt_enable         preempt_enable
111 #else /*CONFIG_PREEMPT*/
112 #define can_preempt_disable()      do { } while (0)
113 #define can_preempt_enable()       do { } while (0)
114 #endif /*CONFIG_PREEMPT*/
115
116 #define can_enable_irq             enable_irq
117 #define can_disable_irq            disable_irq
118
119 #define can_printk                 printk
120
121 #else /*CAN_WITH_RTL*/
122
123 #define can_spinlock_t             rtl_spinlock_t
124 #define can_spin_irqflags_t        rtl_irqstate_t
125 #define can_spin_lock              rtl_spin_lock
126 #define can_spin_unlock            rtl_spin_unlock
127 #define can_spin_lock_irqsave      rtl_spin_lock_irqsave
128 #define can_spin_unlock_irqrestore rtl_spin_unlock_irqrestore
129 #define can_spin_lock_init         rtl_spin_lock_init
130
131 #define can_preempt_disable()      do { } while (0)
132 #define can_preempt_enable()       do { } while (0)
133
134 #define can_enable_irq             rtl_hard_enable_irq
135 #define can_disable_irq            rtl_hard_disable_irq
136
137 #define can_printk                 rtl_printf
138
139 /*
140  * terrible hack to test rtl_file private_data concept, ugh !!!
141  * this would result in crash on architectures,  where 
142  * sizeof(int) < sizeof(void *)
143  */
144 #define can_set_rtl_file_private_data(fptr, p) do{ fptr->f_minor=(long)(p); } while(0)
145 #define can_get_rtl_file_private_data(fptr) ((void*)((fptr)->f_minor))
146
147 #endif /*CAN_WITH_RTL*/
148
149 #endif /*_CAN_SYSDEP_H*/