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