ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / message / fusion / linux_compat.h
1 /* drivers/message/fusion/linux_compat.h */
2
3 #ifndef FUSION_LINUX_COMPAT_H
4 #define FUSION_LINUX_COMPAT_H
5 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6
7 #include <linux/version.h>
8 #include <linux/config.h>
9 #include <linux/kernel.h>
10 #include <linux/pci.h>
11
12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13
14 #ifndef rwlock_init
15 #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
16 #endif
17
18 #define SET_NICE(current,x) do {(current)->nice = (x);} while (0)
19
20 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
21 #       if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
22                 typedef unsigned int dma_addr_t;
23 #       endif
24 #else
25 #       if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42)
26                 typedef unsigned int dma_addr_t;
27 #       endif
28 #endif
29
30 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
31 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
32
33 /* This block snipped from lk-2.2.18/include/linux/init.h { */
34 /*
35  * Used for initialization calls..
36  */
37 typedef int (*initcall_t)(void);
38 typedef void (*exitcall_t)(void);
39
40 #define __init_call     __attribute__ ((unused,__section__ (".initcall.init")))
41 #define __exit_call     __attribute__ ((unused,__section__ (".exitcall.exit")))
42
43 extern initcall_t __initcall_start, __initcall_end;
44
45 #define __initcall(fn)                                                          \
46         static initcall_t __initcall_##fn __init_call = fn
47 #define __exitcall(fn)                                                          \
48         static exitcall_t __exitcall_##fn __exit_call = fn
49
50 #ifdef MODULE
51 /* These macros create a dummy inline: gcc 2.9x does not count alias
52  as usage, hence the `unused function' warning when __init functions
53  are declared static. We use the dummy __*_module_inline functions
54  both to kill the warning and check the type of the init/cleanup
55  function. */
56 typedef int (*__init_module_func_t)(void);
57 typedef void (*__cleanup_module_func_t)(void);
58 #define module_init(x) \
59         int init_module(void) __attribute__((alias(#x))); \
60         static inline __init_module_func_t __init_module_inline(void) \
61         { return x; }
62 #define module_exit(x) \
63         void cleanup_module(void) __attribute__((alias(#x))); \
64         static inline __cleanup_module_func_t __cleanup_module_inline(void) \
65         { return x; }
66
67 #else
68 #define module_init(x)  __initcall(x);
69 #define module_exit(x)  __exitcall(x);
70 #endif
71 /* } block snipped from lk-2.2.18/include/linux/init.h */
72
73 /* This block snipped from lk-2.2.18/include/linux/sched.h { */
74 /*
75  * Used prior to schedule_timeout calls..
76  */
77 #define __set_current_state(state_value)        do { current->state = state_value; } while (0)
78 #ifdef CONFIG_SMP
79 #define set_current_state(state_value)          do { __set_current_state(state_value); mb(); } while (0)
80 #else
81 #define set_current_state(state_value)          __set_current_state(state_value)
82 #endif
83 /* } block snipped from lk-2.2.18/include/linux/sched.h */
84
85 /* procfs compat stuff... */
86 #define proc_mkdir(x,y)                 create_proc_entry(x, S_IFDIR, y)
87
88 /* MUTEX compat stuff... */
89 #define DECLARE_MUTEX(name)             struct semaphore name=MUTEX
90 #define DECLARE_MUTEX_LOCKED(name)      struct semaphore name=MUTEX_LOCKED
91 #define init_MUTEX(x)                   *(x)=MUTEX
92 #define init_MUTEX_LOCKED(x)            *(x)=MUTEX_LOCKED
93
94 /* Wait queues. */
95 #define DECLARE_WAIT_QUEUE_HEAD(name)   \
96         struct wait_queue * (name) = NULL
97 #define DECLARE_WAITQUEUE(name, task)   \
98         struct wait_queue (name) = { (task), NULL }
99
100 #if defined(__sparc__) && defined(__sparc_v9__)
101 /* The sparc64 ioremap implementation is wrong in 2.2.x,
102  * but fixing it would break all of the drivers which
103  * workaround it.  Fixed in 2.3.x onward. -DaveM
104  */
105 #define ARCH_IOREMAP(base)      ((unsigned long) (base))
106 #else
107 #define ARCH_IOREMAP(base)      ioremap(base)
108 #endif
109
110 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
111 #else           /* LINUX_VERSION_CODE must be >= KERNEL_VERSION(2,2,18) */
112
113 /* No ioremap bugs in >2.3.x kernels. */
114 #define ARCH_IOREMAP(base)      ioremap(base)
115
116 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
117 #endif          /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
118
119
120 /*
121  * Inclined to use:
122  *   #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
123  * here, but MODULE_LICENSE defined in 2.4.9-6 and 2.4.9-13
124  * breaks the rule:-(
125  */
126 #ifndef MODULE_LICENSE
127 #define MODULE_LICENSE(license)
128 #endif
129
130
131 /* PCI/driver subsystem { */
132 #define PCI_BASEADDR_FLAGS(idx)         resource[idx].flags
133 #define PCI_BASEADDR_START(idx)         resource[idx].start
134 #define PCI_BASEADDR_SIZE(dev,idx)      (dev)->resource[idx].end - (dev)->resource[idx].start + 1
135
136 /* Compatability for the 2.3.x PCI DMA API. */
137 #ifndef PCI_DMA_BIDIRECTIONAL
138 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
139
140 #define PCI_DMA_BIDIRECTIONAL   0
141 #define PCI_DMA_TODEVICE        1
142 #define PCI_DMA_FROMDEVICE      2
143 #define PCI_DMA_NONE            3
144
145 #ifdef __KERNEL__
146 #include <asm/page.h>
147 /* Pure 2^n version of get_order */
148 static __inline__ int __get_order(unsigned long size)
149 {
150         int order;
151
152         size = (size-1) >> (PAGE_SHIFT-1);
153         order = -1;
154         do {
155                 size >>= 1;
156                 order++;
157         } while (size);
158         return order;
159 }
160 #endif
161
162 #define pci_alloc_consistent(hwdev, size, dma_handle) \
163 ({      void *__ret = (void *)__get_free_pages(GFP_ATOMIC, __get_order(size)); \
164         if (__ret != NULL) { \
165                 memset(__ret, 0, size); \
166                 *(dma_handle) = virt_to_bus(__ret); \
167         } \
168         __ret; \
169 })
170
171 #define pci_free_consistent(hwdev, size, vaddr, dma_handle) \
172         free_pages((unsigned long)vaddr, __get_order(size))
173
174 #define pci_map_single(hwdev, ptr, size, direction) \
175         virt_to_bus(ptr);
176
177 #define pci_unmap_single(hwdev, dma_addr, size, direction) \
178         do { /* Nothing to do */ } while (0)
179
180 #define pci_map_sg(hwdev, sg, nents, direction) (nents)
181 #define pci_unmap_sg(hwdev, sg, nents, direction) \
182         do { /* Nothing to do */ } while(0)
183
184 #define sg_dma_address(sg)      (virt_to_bus((sg)->address))
185 #define sg_dma_len(sg)          ((sg)->length)
186
187 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
188 #endif /* PCI_DMA_BIDIRECTIONAL */
189
190
191 #define mpt_work_struct work_struct
192 #define MPT_INIT_WORK(_task, _func, _data) INIT_WORK(_task, _func, _data)
193 #define mpt_sync_irq(_irq) synchronize_irq(_irq)
194
195 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
196 #endif /* _LINUX_COMPAT_H */
197