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.
18 #include <linux/version.h>
19 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
20 #include <linux/config.h>
22 #include <linux/autoconf.h>
24 #include <linux/module.h>
26 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
27 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
28 #ifdef __UNDEF_NO_VERSION__
31 #define __NO_VERSION__
33 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
36 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
37 #define module_param_string(_name_, _string_, _size_, _perm_) \
38 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
41 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
42 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
43 #include <linux/malloc.h>
45 #include <linux/slab.h>
48 #include <linux/types.h>
49 #include <linux/init.h>
51 #include <linux/string.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/netdevice.h>
57 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
58 #include <linux/workqueue.h>
60 #include <linux/tqueue.h>
62 #define work_struct tq_struct
65 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
68 #define schedule_work(_work) schedule_task((_work))
70 #ifndef flush_scheduled_work
71 #define flush_scheduled_work() flush_scheduled_tasks()
73 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
75 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
76 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func)
78 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func, _data)
79 typedef void (*work_func_t
)(void *work
);
82 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
83 /* Some distributions have their own 2.6.x compatibility layers */
85 typedef void irqreturn_t
;
91 typedef irqreturn_t(*FN_ISR
) (int irq
, void *dev_id
, struct pt_regs
*ptregs
);
92 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
94 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
96 #include <pcmcia/version.h>
97 #include <pcmcia/cs_types.h>
98 #include <pcmcia/cs.h>
99 #include <pcmcia/cistpl.h>
100 #include <pcmcia/cisreg.h>
101 #include <pcmcia/ds.h>
103 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 69))
104 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
105 * does this, but it's not in 2.4 so we do our own for now.
108 cs_error(client_handle_t handle
, int func
, int ret
)
110 error_info_t err
= { func
, ret
};
111 CardServices(ReportError
, handle
, &err
);
115 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15))
117 typedef struct pcmcia_device dev_link_t
;
121 #endif /* CONFIG_PCMCIA */
130 #define __devinit __init
132 #ifndef __devinitdata
133 #define __devinitdata
136 #define __devexit_p(x) x
139 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
141 #define pci_get_drvdata(dev) (dev)->sysdata
142 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
145 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
148 struct pci_device_id
{
149 unsigned int vendor
, device
; /* Vendor and device ID or PCI_ANY_ID */
150 unsigned int subvendor
, subdevice
; /* Subsystem ID's or PCI_ANY_ID */
151 unsigned int class, class_mask
; /* (class,subclass,prog-if) triplet */
152 unsigned long driver_data
; /* Data private to the driver */
156 struct list_head node
;
158 const struct pci_device_id
*id_table
; /* NULL if wants all devices */
159 int (*probe
)(struct pci_dev
*dev
,
160 const struct pci_device_id
*id
); /* New device inserted */
161 void (*remove
)(struct pci_dev
*dev
); /* Device removed (NULL if not a hot-plug
164 void (*suspend
)(struct pci_dev
*dev
); /* Device suspended */
165 void (*resume
)(struct pci_dev
*dev
); /* Device woken up */
168 #define MODULE_DEVICE_TABLE(type, name)
169 #define PCI_ANY_ID (~0)
172 #define pci_module_init pci_register_driver
173 extern int pci_register_driver(struct pci_driver
*drv
);
174 extern void pci_unregister_driver(struct pci_driver
*drv
);
176 #endif /* PCI registration */
178 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
180 #define module_init(x) int init_module(void) { return x(); }
181 #define module_exit(x) void cleanup_module(void) { x(); }
183 #define module_init(x) __initcall(x);
184 #define module_exit(x) __exitcall(x);
186 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
188 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
189 #define list_for_each(pos, head) \
190 for (pos = (head)->next; pos != (head); pos = pos->next)
193 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
194 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
195 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
196 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
199 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
200 #define pci_enable_device(dev) do { } while (0)
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
204 #define net_device device
207 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
212 * See linux/Documentation/DMA-mapping.txt
215 #ifndef PCI_DMA_TODEVICE
216 #define PCI_DMA_TODEVICE 1
217 #define PCI_DMA_FROMDEVICE 2
220 typedef u32 dma_addr_t
;
222 /* Pure 2^n version of get_order */
223 static inline int get_order(unsigned long size
)
227 size
= (size
-1) >> (PAGE_SHIFT
-1);
236 static inline void *pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
237 dma_addr_t
*dma_handle
)
240 int gfp
= GFP_ATOMIC
| GFP_DMA
;
242 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
245 memset(ret
, 0, size
);
246 *dma_handle
= virt_to_bus(ret
);
250 static inline void pci_free_consistent(struct pci_dev
*hwdev
, size_t size
,
251 void *vaddr
, dma_addr_t dma_handle
)
253 free_pages((unsigned long)vaddr
, get_order(size
));
256 extern uint
pci_map_single(void *dev
, void *va
, uint size
, int direction
);
257 extern void pci_unmap_single(void *dev
, uint pa
, uint size
, int direction
);
259 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
260 #define pci_unmap_single(cookie, address, size, dir)
263 #endif /* DMA mapping */
265 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
267 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
268 #define netif_down(dev) do { (dev)->start = 0; } while (0)
270 /* pcmcia-cs provides its own netdevice compatibility layer */
271 #ifndef _COMPAT_NETDEVICE_H
276 * For pre-softnet kernels we need to tell the upper layer not to
277 * re-enter start_xmit() while we are in there. However softnet
278 * guarantees not to enter while we are in there so there is no need
279 * to do the netif_stop_queue() dance unless the transmit queue really
280 * gets stuck. This should also improve performance according to tests
281 * done by Aman Singla.
284 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
285 #define netif_wake_queue(dev) \
286 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
287 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
289 static inline void netif_start_queue(struct net_device
*dev
)
296 #define netif_queue_stopped(dev) (dev)->tbusy
297 #define netif_running(dev) (dev)->start
299 #endif /* _COMPAT_NETDEVICE_H */
301 #define netif_device_attach(dev) netif_start_queue(dev)
302 #define netif_device_detach(dev) netif_stop_queue(dev)
304 /* 2.4.x renamed bottom halves to tasklets */
305 #define tasklet_struct tq_struct
306 static inline void tasklet_schedule(struct tasklet_struct
*tasklet
)
308 queue_task(tasklet
, &tq_immediate
);
309 mark_bh(IMMEDIATE_BH
);
312 static inline void tasklet_init(struct tasklet_struct
*tasklet
,
313 void (*func
)(unsigned long),
316 tasklet
->next
= NULL
;
318 tasklet
->routine
= (void (*)(void *))func
;
319 tasklet
->data
= (void *)data
;
321 #define tasklet_kill(tasklet) { do{} while (0); }
323 /* 2.4.x introduced del_timer_sync() */
324 #define del_timer_sync(timer) del_timer(timer)
328 #define netif_down(dev)
332 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
335 * Emit code to initialise a tq_struct's routine and data pointers
337 #define PREPARE_TQUEUE(_tq, _routine, _data) \
339 (_tq)->routine = _routine; \
340 (_tq)->data = _data; \
344 * Emit code to initialise all of a tq_struct
346 #define INIT_TQUEUE(_tq, _routine, _data) \
348 INIT_LIST_HEAD(&(_tq)->list); \
350 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
353 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
355 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
357 /* Power management related routines */
360 pci_save_state(struct pci_dev
*dev
, u32
*buffer
)
364 for (i
= 0; i
< 16; i
++)
365 pci_read_config_dword(dev
, i
* 4, &buffer
[i
]);
371 pci_restore_state(struct pci_dev
*dev
, u32
*buffer
)
376 for (i
= 0; i
< 16; i
++)
377 pci_write_config_dword(dev
, i
* 4, buffer
[i
]);
380 * otherwise, write the context information we know from bootup.
381 * This works around a problem where warm-booting from Windows
382 * combined with a D3(hot)->D0 transition causes PCI config
383 * header data to be forgotten.
386 for (i
= 0; i
< 6; i
++)
387 pci_write_config_dword(dev
,
388 PCI_BASE_ADDRESS_0
+ (i
* 4),
389 pci_resource_start(dev
, i
));
390 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, dev
->irq
);
395 #endif /* PCI power management */
397 /* Old cp0 access macros deprecated in 2.4.19 */
398 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
399 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
402 /* Module refcount handled internally in 2.6.x */
403 #ifndef SET_MODULE_OWNER
404 #define SET_MODULE_OWNER(dev) do {} while (0)
405 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
406 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
408 #define OLD_MOD_INC_USE_COUNT do {} while (0)
409 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
412 #ifndef SET_NETDEV_DEV
413 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
416 #ifndef HAVE_FREE_NETDEV
417 #define free_netdev(dev) kfree(dev)
420 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
421 /* struct packet_type redefined in 2.6.x */
422 #define af_packet_priv data
426 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
427 #define DRV_SUSPEND_STATE_TYPE pm_message_t
429 #define DRV_SUSPEND_STATE_TYPE uint32
432 #endif /* _linuxver_h_ */
This page took 0.081442 seconds and 5 git commands to generate.