File: /usr/src/linux/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 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
15 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
16 typedef unsigned int dma_addr_t;
17 # endif
18 #else
19 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42)
20 typedef unsigned int dma_addr_t;
21 # endif
22 #endif
23
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
25 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
26
27 /* This block snipped from lk-2.2.18/include/linux/init.h { */
28 /*
29 * Used for initialization calls..
30 */
31 typedef int (*initcall_t)(void);
32 typedef void (*exitcall_t)(void);
33
34 #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
35 #define __exit_call __attribute__ ((unused,__section__ (".exitcall.exit")))
36
37 extern initcall_t __initcall_start, __initcall_end;
38
39 #define __initcall(fn) \
40 static initcall_t __initcall_##fn __init_call = fn
41 #define __exitcall(fn) \
42 static exitcall_t __exitcall_##fn __exit_call = fn
43
44 #ifdef MODULE
45 /* These macros create a dummy inline: gcc 2.9x does not count alias
46 as usage, hence the `unused function' warning when __init functions
47 are declared static. We use the dummy __*_module_inline functions
48 both to kill the warning and check the type of the init/cleanup
49 function. */
50 typedef int (*__init_module_func_t)(void);
51 typedef void (*__cleanup_module_func_t)(void);
52 #define module_init(x) \
53 int init_module(void) __attribute__((alias(#x))); \
54 extern inline __init_module_func_t __init_module_inline(void) \
55 { return x; }
56 #define module_exit(x) \
57 void cleanup_module(void) __attribute__((alias(#x))); \
58 extern inline __cleanup_module_func_t __cleanup_module_inline(void) \
59 { return x; }
60
61 #else
62 #define module_init(x) __initcall(x);
63 #define module_exit(x) __exitcall(x);
64 #endif
65 /* } block snipped from lk-2.2.18/include/linux/init.h */
66
67 /* Wait queues. */
68 #define DECLARE_WAIT_QUEUE_HEAD(name) \
69 struct wait_queue * (name) = NULL
70 #define DECLARE_WAITQUEUE(name, task) \
71 struct wait_queue (name) = { (task), NULL }
72
73 #if defined(__sparc__) && defined(__sparc_v9__)
74 /* The sparc64 ioremap implementation is wrong in 2.2.x,
75 * but fixing it would break all of the drivers which
76 * workaround it. Fixed in 2.3.x onward. -DaveM
77 */
78 #define ARCH_IOREMAP(base) ((unsigned long) (base))
79 #else
80 #define ARCH_IOREMAP(base) ioremap(base)
81 #endif
82
83 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
84 #else /* LINUX_VERSION_CODE must be >= KERNEL_VERSION(2,2,18) */
85
86 /* No ioremap bugs in >2.3.x kernels. */
87 #define ARCH_IOREMAP(base) ioremap(base)
88
89 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
90 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
91
92
93 /* PCI/driver subsystem { */
94 #ifndef pci_for_each_dev
95 #define pci_for_each_dev(dev) for((dev)=pci_devices; (dev)!=NULL; (dev)=(dev)->next)
96 #define pci_peek_next_dev(dev) ((dev)->next ? (dev)->next : NULL)
97 #define DEVICE_COUNT_RESOURCE 6
98 #define PCI_BASEADDR_FLAGS(idx) base_address[idx]
99 #define PCI_BASEADDR_START(idx) base_address[idx] & ~0xFUL
100 /*
101 * We have to keep track of the original value using
102 * a temporary, and not by just sticking pdev->base_address[x]
103 * back. pdev->base_address[x] is an opaque cookie that can
104 * be used by the PCI implementation on a given Linux port
105 * for any purpose. -DaveM
106 */
107 #define PCI_BASEADDR_SIZE(__pdev, __idx) \
108 ({ unsigned int size, tmp; \
109 pci_read_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), &tmp); \
110 pci_write_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), 0xffffffff); \
111 pci_read_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), &size); \
112 pci_write_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), tmp); \
113 (4 - size); \
114 })
115 #else
116 #define pci_peek_next_dev(dev) ((dev) != pci_dev_g(&pci_devices) ? pci_dev_g((dev)->global_list.next) : NULL)
117 #define PCI_BASEADDR_FLAGS(idx) resource[idx].flags
118 #define PCI_BASEADDR_START(idx) resource[idx].start
119 #define PCI_BASEADDR_SIZE(dev,idx) (dev)->resource[idx].end - (dev)->resource[idx].start + 1
120 #endif /* } ifndef pci_for_each_dev */
121
122
123 /* procfs compat stuff... */
124 #ifdef CONFIG_PROC_FS
125 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,28)
126 #define CREATE_PROCDIR_ENTRY(x,y) create_proc_entry(x, S_IFDIR, y)
127 /* This is a macro so we don't need to pull all the procfs
128 * headers into this file. -DaveM
129 */
130 #define create_proc_read_entry(name, mode, base, __read_proc, __data) \
131 ({ struct proc_dir_entry *__res=create_proc_entry(name,mode,base); \
132 if (__res) { \
133 __res->read_proc=(__read_proc); \
134 __res->data=(__data); \
135 } \
136 __res; \
137 })
138 #else
139 #define CREATE_PROCDIR_ENTRY(x,y) proc_mkdir(x, y)
140 #endif
141 #endif
142
143 /* Compatability for the 2.3.x PCI DMA API. */
144 #ifndef PCI_DMA_BIDIRECTIONAL
145 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
146
147 #define PCI_DMA_BIDIRECTIONAL 0
148 #define PCI_DMA_TODEVICE 1
149 #define PCI_DMA_FROMDEVICE 2
150 #define PCI_DMA_NONE 3
151
152 #ifdef __KERNEL__
153 #include <asm/page.h>
154 /* Pure 2^n version of get_order */
155 static __inline__ int __get_order(unsigned long size)
156 {
157 int order;
158
159 size = (size-1) >> (PAGE_SHIFT-1);
160 order = -1;
161 do {
162 size >>= 1;
163 order++;
164 } while (size);
165 return order;
166 }
167 #endif
168
169 #define pci_alloc_consistent(hwdev, size, dma_handle) \
170 ({ void *__ret = (void *)__get_free_pages(GFP_ATOMIC, __get_order(size)); \
171 if (__ret != NULL) { \
172 memset(__ret, 0, size); \
173 *(dma_handle) = virt_to_bus(__ret); \
174 } \
175 __ret; \
176 })
177
178 #define pci_free_consistent(hwdev, size, vaddr, dma_handle) \
179 free_pages((unsigned long)vaddr, __get_order(size))
180
181 #define pci_map_single(hwdev, ptr, size, direction) \
182 virt_to_bus(ptr);
183
184 #define pci_unmap_single(hwdev, dma_addr, size, direction) \
185 do { /* Nothing to do */ } while (0)
186
187 #define pci_map_sg(hwdev, sg, nents, direction) (nents)
188 #define pci_unmap_sg(hwdev, sg, nents, direction) \
189 do { /* Nothing to do */ } while(0)
190
191 #define sg_dma_address(sg) (virt_to_bus((sg)->address))
192 #define sg_dma_len(sg) ((sg)->length)
193
194 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
195 #endif /* PCI_DMA_BIDIRECTIONAL */
196
197 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
198 #endif /* _LINUX_COMPAT_H */
199
200