convert brcm-2.4 to the new target structure
[openwrt/svn-archive/archive.git] / target / linux / brcm-2.4 / files / arch / mips / bcm947xx / include / linuxver.h
1 /*
2 * Linux-specific abstractions to gain some independence from linux kernel versions.
3 * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
4 *
5 * Copyright 2006, Broadcom Corporation
6 * All Rights Reserved.
7 *
8 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
11 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 *
13 * $Id: linuxver.h,v 1.1.1.10 2006/02/27 03:43:16 honor Exp $
14 */
15
16 #ifndef _linuxver_h_
17 #define _linuxver_h_
18
19 #include <linux/config.h>
20 #include <linux/version.h>
21
22 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
23 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
24 #ifdef __UNDEF_NO_VERSION__
25 #undef __NO_VERSION__
26 #else
27 #define __NO_VERSION__
28 #endif
29 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
30
31 #if defined(MODULE) && defined(MODVERSIONS)
32 #include <linux/modversions.h>
33 #endif
34
35 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
36 #include <linux/moduleparam.h>
37 #endif
38
39
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
41 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
42 #define module_param_string(_name_, _string_, _size_, _perm_) \
43 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
44 #endif
45
46 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
47 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
48 #include <linux/malloc.h>
49 #else
50 #include <linux/slab.h>
51 #endif
52
53 #include <linux/types.h>
54 #include <linux/init.h>
55 #include <linux/mm.h>
56 #include <linux/string.h>
57 #include <linux/pci.h>
58 #include <linux/interrupt.h>
59 #include <linux/netdevice.h>
60 #include <asm/io.h>
61
62 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
63 #include <linux/workqueue.h>
64 #else
65 #include <linux/tqueue.h>
66 #ifndef work_struct
67 #define work_struct tq_struct
68 #endif
69 #ifndef INIT_WORK
70 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
71 #endif
72 #ifndef schedule_work
73 #define schedule_work(_work) schedule_task((_work))
74 #endif
75 #ifndef flush_scheduled_work
76 #define flush_scheduled_work() flush_scheduled_tasks()
77 #endif
78 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
79
80 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
81 /* Some distributions have their own 2.6.x compatibility layers */
82 #ifndef IRQ_NONE
83 typedef void irqreturn_t;
84 #define IRQ_NONE
85 #define IRQ_HANDLED
86 #define IRQ_RETVAL(x)
87 #endif
88 #else
89 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
90 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
91
92 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
93
94 #include <pcmcia/version.h>
95 #include <pcmcia/cs_types.h>
96 #include <pcmcia/cs.h>
97 #include <pcmcia/cistpl.h>
98 #include <pcmcia/cisreg.h>
99 #include <pcmcia/ds.h>
100
101 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 69))
102 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
103 * does this, but it's not in 2.4 so we do our own for now.
104 */
105 static inline void
106 cs_error(client_handle_t handle, int func, int ret)
107 {
108 error_info_t err = { func, ret };
109 CardServices(ReportError, handle, &err);
110 }
111 #endif
112
113 #endif /* CONFIG_PCMCIA */
114
115 #ifndef __exit
116 #define __exit
117 #endif
118 #ifndef __devexit
119 #define __devexit
120 #endif
121 #ifndef __devinit
122 #define __devinit __init
123 #endif
124 #ifndef __devinitdata
125 #define __devinitdata
126 #endif
127 #ifndef __devexit_p
128 #define __devexit_p(x) x
129 #endif
130
131 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
132
133 #define pci_get_drvdata(dev) (dev)->sysdata
134 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
135
136 /*
137 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
138 */
139
140 struct pci_device_id {
141 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
142 unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
143 unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
144 unsigned long driver_data; /* Data private to the driver */
145 };
146
147 struct pci_driver {
148 struct list_head node;
149 char *name;
150 const struct pci_device_id *id_table; /* NULL if wants all devices */
151 int (*probe)(struct pci_dev *dev,
152 const struct pci_device_id *id); /* New device inserted */
153 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug
154 * capable driver)
155 */
156 void (*suspend)(struct pci_dev *dev); /* Device suspended */
157 void (*resume)(struct pci_dev *dev); /* Device woken up */
158 };
159
160 #define MODULE_DEVICE_TABLE(type, name)
161 #define PCI_ANY_ID (~0)
162
163 /* compatpci.c */
164 #define pci_module_init pci_register_driver
165 extern int pci_register_driver(struct pci_driver *drv);
166 extern void pci_unregister_driver(struct pci_driver *drv);
167
168 #endif /* PCI registration */
169
170 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
171 #ifdef MODULE
172 #define module_init(x) int init_module(void) { return x(); }
173 #define module_exit(x) void cleanup_module(void) { x(); }
174 #else
175 #define module_init(x) __initcall(x);
176 #define module_exit(x) __exitcall(x);
177 #endif
178 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
179
180 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
181 #define list_for_each(pos, head) \
182 for (pos = (head)->next; pos != (head); pos = pos->next)
183 #endif
184
185 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
186 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
187 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
188 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
189 #endif
190
191 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
192 #define pci_enable_device(dev) do { } while (0)
193 #endif
194
195 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
196 #define net_device device
197 #endif
198
199 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
200
201 /*
202 * DMA mapping
203 *
204 * See linux/Documentation/DMA-mapping.txt
205 */
206
207 #ifndef PCI_DMA_TODEVICE
208 #define PCI_DMA_TODEVICE 1
209 #define PCI_DMA_FROMDEVICE 2
210 #endif
211
212 typedef u32 dma_addr_t;
213
214 /* Pure 2^n version of get_order */
215 static inline int get_order(unsigned long size)
216 {
217 int order;
218
219 size = (size-1) >> (PAGE_SHIFT-1);
220 order = -1;
221 do {
222 size >>= 1;
223 order++;
224 } while (size);
225 return order;
226 }
227
228 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
229 dma_addr_t *dma_handle)
230 {
231 void *ret;
232 int gfp = GFP_ATOMIC | GFP_DMA;
233
234 ret = (void *)__get_free_pages(gfp, get_order(size));
235
236 if (ret != NULL) {
237 memset(ret, 0, size);
238 *dma_handle = virt_to_bus(ret);
239 }
240 return ret;
241 }
242 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
243 void *vaddr, dma_addr_t dma_handle)
244 {
245 free_pages((unsigned long)vaddr, get_order(size));
246 }
247 #ifdef ILSIM
248 extern uint pci_map_single(void *dev, void *va, uint size, int direction);
249 extern void pci_unmap_single(void *dev, uint pa, uint size, int direction);
250 #else
251 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
252 #define pci_unmap_single(cookie, address, size, dir)
253 #endif
254
255 #endif /* DMA mapping */
256
257 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
258
259 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
260 #define netif_down(dev) do { (dev)->start = 0; } while (0)
261
262 /* pcmcia-cs provides its own netdevice compatibility layer */
263 #ifndef _COMPAT_NETDEVICE_H
264
265 /*
266 * SoftNet
267 *
268 * For pre-softnet kernels we need to tell the upper layer not to
269 * re-enter start_xmit() while we are in there. However softnet
270 * guarantees not to enter while we are in there so there is no need
271 * to do the netif_stop_queue() dance unless the transmit queue really
272 * gets stuck. This should also improve performance according to tests
273 * done by Aman Singla.
274 */
275
276 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
277 #define netif_wake_queue(dev) \
278 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
279 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
280
281 static inline void netif_start_queue(struct net_device *dev)
282 {
283 dev->tbusy = 0;
284 dev->interrupt = 0;
285 dev->start = 1;
286 }
287
288 #define netif_queue_stopped(dev) (dev)->tbusy
289 #define netif_running(dev) (dev)->start
290
291 #endif /* _COMPAT_NETDEVICE_H */
292
293 #define netif_device_attach(dev) netif_start_queue(dev)
294 #define netif_device_detach(dev) netif_stop_queue(dev)
295
296 /* 2.4.x renamed bottom halves to tasklets */
297 #define tasklet_struct tq_struct
298 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
299 {
300 queue_task(tasklet, &tq_immediate);
301 mark_bh(IMMEDIATE_BH);
302 }
303
304 static inline void tasklet_init(struct tasklet_struct *tasklet,
305 void (*func)(unsigned long),
306 unsigned long data)
307 {
308 tasklet->next = NULL;
309 tasklet->sync = 0;
310 tasklet->routine = (void (*)(void *))func;
311 tasklet->data = (void *)data;
312 }
313 #define tasklet_kill(tasklet) { do{} while (0); }
314
315 /* 2.4.x introduced del_timer_sync() */
316 #define del_timer_sync(timer) del_timer(timer)
317
318 #else
319
320 #define netif_down(dev)
321
322 #endif /* SoftNet */
323
324 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
325
326 /*
327 * Emit code to initialise a tq_struct's routine and data pointers
328 */
329 #define PREPARE_TQUEUE(_tq, _routine, _data) \
330 do { \
331 (_tq)->routine = _routine; \
332 (_tq)->data = _data; \
333 } while (0)
334
335 /*
336 * Emit code to initialise all of a tq_struct
337 */
338 #define INIT_TQUEUE(_tq, _routine, _data) \
339 do { \
340 INIT_LIST_HEAD(&(_tq)->list); \
341 (_tq)->sync = 0; \
342 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
343 } while (0)
344
345 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
346
347 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
348
349 /* Power management related routines */
350
351 static inline int
352 pci_save_state(struct pci_dev *dev, u32 *buffer)
353 {
354 int i;
355 if (buffer) {
356 for (i = 0; i < 16; i++)
357 pci_read_config_dword(dev, i * 4, &buffer[i]);
358 }
359 return 0;
360 }
361
362 static inline int
363 pci_restore_state(struct pci_dev *dev, u32 *buffer)
364 {
365 int i;
366
367 if (buffer) {
368 for (i = 0; i < 16; i++)
369 pci_write_config_dword(dev, i * 4, buffer[i]);
370 }
371 /*
372 * otherwise, write the context information we know from bootup.
373 * This works around a problem where warm-booting from Windows
374 * combined with a D3(hot)->D0 transition causes PCI config
375 * header data to be forgotten.
376 */
377 else {
378 for (i = 0; i < 6; i ++)
379 pci_write_config_dword(dev,
380 PCI_BASE_ADDRESS_0 + (i * 4),
381 pci_resource_start(dev, i));
382 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
383 }
384 return 0;
385 }
386
387 #endif /* PCI power management */
388
389 /* Old cp0 access macros deprecated in 2.4.19 */
390 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
391 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
392 #endif
393
394 /* Module refcount handled internally in 2.6.x */
395 #ifndef SET_MODULE_OWNER
396 #define SET_MODULE_OWNER(dev) do {} while (0)
397 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
398 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
399 #else
400 #define OLD_MOD_INC_USE_COUNT do {} while (0)
401 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
402 #endif
403
404 #ifndef SET_NETDEV_DEV
405 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
406 #endif
407
408 #ifndef HAVE_FREE_NETDEV
409 #define free_netdev(dev) kfree(dev)
410 #endif
411
412 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
413 /* struct packet_type redefined in 2.6.x */
414 #define af_packet_priv data
415 #endif
416
417 #endif /* _linuxver_h_ */