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.
5 * Copyright 2006, Broadcom Corporation
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.
13 * $Id: linuxver.h,v 1.1.1.10 2006/02/27 03:43:16 honor Exp $
19 #include <linux/config.h>
20 #include <linux/version.h>
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__
27 #define __NO_VERSION__
29 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
31 #if defined(MODULE) && defined(MODVERSIONS)
32 #include <linux/modversions.h>
35 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
36 #include <linux/moduleparam.h>
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_))
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>
50 #include <linux/slab.h>
53 #include <linux/types.h>
54 #include <linux/init.h>
56 #include <linux/string.h>
57 #include <linux/pci.h>
58 #include <linux/interrupt.h>
59 #include <linux/netdevice.h>
62 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
63 #include <linux/workqueue.h>
65 #include <linux/tqueue.h>
67 #define work_struct tq_struct
70 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
73 #define schedule_work(_work) schedule_task((_work))
75 #ifndef flush_scheduled_work
76 #define flush_scheduled_work() flush_scheduled_tasks()
78 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
80 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
81 /* Some distributions have their own 2.6.x compatibility layers */
83 typedef void irqreturn_t
;
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) */
92 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
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>
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.
106 cs_error(client_handle_t handle
, int func
, int ret
)
108 error_info_t err
= { func
, ret
};
109 CardServices(ReportError
, handle
, &err
);
113 #endif /* CONFIG_PCMCIA */
122 #define __devinit __init
124 #ifndef __devinitdata
125 #define __devinitdata
128 #define __devexit_p(x) x
131 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
133 #define pci_get_drvdata(dev) (dev)->sysdata
134 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
137 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
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 */
148 struct list_head node
;
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
156 void (*suspend
)(struct pci_dev
*dev
); /* Device suspended */
157 void (*resume
)(struct pci_dev
*dev
); /* Device woken up */
160 #define MODULE_DEVICE_TABLE(type, name)
161 #define PCI_ANY_ID (~0)
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
);
168 #endif /* PCI registration */
170 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
172 #define module_init(x) int init_module(void) { return x(); }
173 #define module_exit(x) void cleanup_module(void) { x(); }
175 #define module_init(x) __initcall(x);
176 #define module_exit(x) __exitcall(x);
178 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
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)
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)
191 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
192 #define pci_enable_device(dev) do { } while (0)
195 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
196 #define net_device device
199 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
204 * See linux/Documentation/DMA-mapping.txt
207 #ifndef PCI_DMA_TODEVICE
208 #define PCI_DMA_TODEVICE 1
209 #define PCI_DMA_FROMDEVICE 2
212 typedef u32 dma_addr_t
;
214 /* Pure 2^n version of get_order */
215 static inline int get_order(unsigned long size
)
219 size
= (size
-1) >> (PAGE_SHIFT
-1);
228 static inline void *pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
229 dma_addr_t
*dma_handle
)
232 int gfp
= GFP_ATOMIC
| GFP_DMA
;
234 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
237 memset(ret
, 0, size
);
238 *dma_handle
= virt_to_bus(ret
);
242 static inline void pci_free_consistent(struct pci_dev
*hwdev
, size_t size
,
243 void *vaddr
, dma_addr_t dma_handle
)
245 free_pages((unsigned long)vaddr
, get_order(size
));
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
);
251 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
252 #define pci_unmap_single(cookie, address, size, dir)
255 #endif /* DMA mapping */
257 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
259 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
260 #define netif_down(dev) do { (dev)->start = 0; } while (0)
262 /* pcmcia-cs provides its own netdevice compatibility layer */
263 #ifndef _COMPAT_NETDEVICE_H
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.
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)
281 static inline void netif_start_queue(struct net_device
*dev
)
288 #define netif_queue_stopped(dev) (dev)->tbusy
289 #define netif_running(dev) (dev)->start
291 #endif /* _COMPAT_NETDEVICE_H */
293 #define netif_device_attach(dev) netif_start_queue(dev)
294 #define netif_device_detach(dev) netif_stop_queue(dev)
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
)
300 queue_task(tasklet
, &tq_immediate
);
301 mark_bh(IMMEDIATE_BH
);
304 static inline void tasklet_init(struct tasklet_struct
*tasklet
,
305 void (*func
)(unsigned long),
308 tasklet
->next
= NULL
;
310 tasklet
->routine
= (void (*)(void *))func
;
311 tasklet
->data
= (void *)data
;
313 #define tasklet_kill(tasklet) { do{} while (0); }
315 /* 2.4.x introduced del_timer_sync() */
316 #define del_timer_sync(timer) del_timer(timer)
320 #define netif_down(dev)
324 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
327 * Emit code to initialise a tq_struct's routine and data pointers
329 #define PREPARE_TQUEUE(_tq, _routine, _data) \
331 (_tq)->routine = _routine; \
332 (_tq)->data = _data; \
336 * Emit code to initialise all of a tq_struct
338 #define INIT_TQUEUE(_tq, _routine, _data) \
340 INIT_LIST_HEAD(&(_tq)->list); \
342 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
345 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
347 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
349 /* Power management related routines */
352 pci_save_state(struct pci_dev
*dev
, u32
*buffer
)
356 for (i
= 0; i
< 16; i
++)
357 pci_read_config_dword(dev
, i
* 4, &buffer
[i
]);
363 pci_restore_state(struct pci_dev
*dev
, u32
*buffer
)
368 for (i
= 0; i
< 16; i
++)
369 pci_write_config_dword(dev
, i
* 4, buffer
[i
]);
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.
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
);
387 #endif /* PCI power management */
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)
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
400 #define OLD_MOD_INC_USE_COUNT do {} while (0)
401 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
404 #ifndef SET_NETDEV_DEV
405 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
408 #ifndef HAVE_FREE_NETDEV
409 #define free_netdev(dev) kfree(dev)
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
417 #endif /* _linuxver_h_ */
This page took 0.090093 seconds and 5 git commands to generate.