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 2007, 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.
19 #include <linux/version.h>
20 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
21 #include <linux/config.h>
23 #include <linux/autoconf.h>
25 #include <linux/module.h>
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__
32 #define __NO_VERSION__
34 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
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_))
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>
46 #include <linux/slab.h>
49 #include <linux/types.h>
50 #include <linux/init.h>
52 #include <linux/string.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/netdevice.h>
58 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
59 #include <linux/workqueue.h>
61 #include <linux/tqueue.h>
63 #define work_struct tq_struct
66 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
69 #define schedule_work(_work) schedule_task((_work))
71 #ifndef flush_scheduled_work
72 #define flush_scheduled_work() flush_scheduled_tasks()
74 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
76 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
77 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func)
79 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func, _data)
80 typedef void (*work_func_t
)(void *work
);
83 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
84 /* Some distributions have their own 2.6.x compatibility layers */
86 typedef void irqreturn_t
;
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) */
95 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
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>
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.
109 cs_error(client_handle_t handle
, int func
, int ret
)
111 error_info_t err
= { func
, ret
};
112 CardServices(ReportError
, handle
, &err
);
116 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15))
118 typedef struct pcmcia_device dev_link_t
;
122 #endif /* CONFIG_PCMCIA */
131 #define __devinit __init
133 #ifndef __devinitdata
134 #define __devinitdata
137 #define __devexit_p(x) x
140 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
142 #define pci_get_drvdata(dev) (dev)->sysdata
143 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
146 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
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 */
157 struct list_head node
;
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
165 void (*suspend
)(struct pci_dev
*dev
); /* Device suspended */
166 void (*resume
)(struct pci_dev
*dev
); /* Device woken up */
169 #define MODULE_DEVICE_TABLE(type, name)
170 #define PCI_ANY_ID (~0)
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
);
177 #endif /* PCI registration */
179 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
181 #define module_init(x) int init_module(void) { return x(); }
182 #define module_exit(x) void cleanup_module(void) { x(); }
184 #define module_init(x) __initcall(x);
185 #define module_exit(x) __exitcall(x);
187 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
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)
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)
200 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
201 #define pci_enable_device(dev) do { } while (0)
204 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
205 #define net_device device
208 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
213 * See linux/Documentation/DMA-mapping.txt
216 #ifndef PCI_DMA_TODEVICE
217 #define PCI_DMA_TODEVICE 1
218 #define PCI_DMA_FROMDEVICE 2
221 typedef u32 dma_addr_t
;
223 /* Pure 2^n version of get_order */
224 static inline int get_order(unsigned long size
)
228 size
= (size
-1) >> (PAGE_SHIFT
-1);
237 static inline void *pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
238 dma_addr_t
*dma_handle
)
241 int gfp
= GFP_ATOMIC
| GFP_DMA
;
243 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
246 memset(ret
, 0, size
);
247 *dma_handle
= virt_to_bus(ret
);
251 static inline void pci_free_consistent(struct pci_dev
*hwdev
, size_t size
,
252 void *vaddr
, dma_addr_t dma_handle
)
254 free_pages((unsigned long)vaddr
, get_order(size
));
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
);
260 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
261 #define pci_unmap_single(cookie, address, size, dir)
264 #endif /* DMA mapping */
266 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
268 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
269 #define netif_down(dev) do { (dev)->start = 0; } while (0)
271 /* pcmcia-cs provides its own netdevice compatibility layer */
272 #ifndef _COMPAT_NETDEVICE_H
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.
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)
290 static inline void netif_start_queue(struct net_device
*dev
)
297 #define netif_queue_stopped(dev) (dev)->tbusy
298 #define netif_running(dev) (dev)->start
300 #endif /* _COMPAT_NETDEVICE_H */
302 #define netif_device_attach(dev) netif_start_queue(dev)
303 #define netif_device_detach(dev) netif_stop_queue(dev)
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
)
309 queue_task(tasklet
, &tq_immediate
);
310 mark_bh(IMMEDIATE_BH
);
313 static inline void tasklet_init(struct tasklet_struct
*tasklet
,
314 void (*func
)(unsigned long),
317 tasklet
->next
= NULL
;
319 tasklet
->routine
= (void (*)(void *))func
;
320 tasklet
->data
= (void *)data
;
322 #define tasklet_kill(tasklet) { do{} while (0); }
324 /* 2.4.x introduced del_timer_sync() */
325 #define del_timer_sync(timer) del_timer(timer)
329 #define netif_down(dev)
333 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
336 * Emit code to initialise a tq_struct's routine and data pointers
338 #define PREPARE_TQUEUE(_tq, _routine, _data) \
340 (_tq)->routine = _routine; \
341 (_tq)->data = _data; \
345 * Emit code to initialise all of a tq_struct
347 #define INIT_TQUEUE(_tq, _routine, _data) \
349 INIT_LIST_HEAD(&(_tq)->list); \
351 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
354 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
356 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
358 /* Power management related routines */
361 pci_save_state(struct pci_dev
*dev
, u32
*buffer
)
365 for (i
= 0; i
< 16; i
++)
366 pci_read_config_dword(dev
, i
* 4, &buffer
[i
]);
372 pci_restore_state(struct pci_dev
*dev
, u32
*buffer
)
377 for (i
= 0; i
< 16; i
++)
378 pci_write_config_dword(dev
, i
* 4, buffer
[i
]);
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.
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
);
396 #endif /* PCI power management */
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)
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
409 #define OLD_MOD_INC_USE_COUNT do {} while (0)
410 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
413 #ifndef SET_NETDEV_DEV
414 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
417 #ifndef HAVE_FREE_NETDEV
418 #define free_netdev(dev) kfree(dev)
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
427 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
428 #define DRV_SUSPEND_STATE_TYPE pm_message_t
430 #define DRV_SUSPEND_STATE_TYPE uint32
433 #endif /* _linuxver_h_ */
This page took 0.068796 seconds and 5 git commands to generate.