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