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 2004, 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/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__
31 #if defined(MODULE) && defined(MODVERSIONS)
32 #include <linux/modversions.h>
35 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
36 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9))
37 #include <linux/malloc.h>
39 #include <linux/slab.h>
42 #include <linux/types.h>
43 #include <linux/init.h>
44 #include <linux/module.h>
46 #include <linux/string.h>
47 #include <linux/pci.h>
48 #include <linux/interrupt.h>
49 #include <linux/netdevice.h>
52 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))
53 #include <linux/workqueue.h>
55 #include <linux/tqueue.h>
56 #define work_struct tq_struct
57 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
58 #define schedule_work(_work) schedule_task((_work))
59 #define flush_scheduled_work() flush_scheduled_tasks()
62 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
63 /* Some distributions have their own 2.6.x compatibility layers */
65 typedef void irqreturn_t
;
72 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
74 #include <pcmcia/version.h>
75 #include <pcmcia/cs_types.h>
76 #include <pcmcia/cs.h>
77 #include <pcmcia/cistpl.h>
78 #include <pcmcia/cisreg.h>
79 #include <pcmcia/ds.h>
81 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69))
82 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
83 * does this, but it's not in 2.4 so we do our own for now. */
85 cs_error(client_handle_t handle
, int func
, int ret
)
87 error_info_t err
= { func
, ret
};
88 CardServices(ReportError
, handle
, &err
);
92 #endif /* CONFIG_PCMCIA */
101 #define __devinit __init
103 #ifndef __devinitdata
104 #define __devinitdata
107 #define __devexit_p(x) x
110 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
112 #define pci_get_drvdata(dev) (dev)->sysdata
113 #define pci_set_drvdata(dev, value) (dev)->sysdata=(value)
116 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
119 struct pci_device_id
{
120 unsigned int vendor
, device
; /* Vendor and device ID or PCI_ANY_ID */
121 unsigned int subvendor
, subdevice
; /* Subsystem ID's or PCI_ANY_ID */
122 unsigned int class, class_mask
; /* (class,subclass,prog-if) triplet */
123 unsigned long driver_data
; /* Data private to the driver */
127 struct list_head node
;
129 const struct pci_device_id
*id_table
; /* NULL if wants all devices */
130 int (*probe
)(struct pci_dev
*dev
, const struct pci_device_id
*id
); /* New device inserted */
131 void (*remove
)(struct pci_dev
*dev
); /* Device removed (NULL if not a hot-plug capable driver) */
132 void (*suspend
)(struct pci_dev
*dev
); /* Device suspended */
133 void (*resume
)(struct pci_dev
*dev
); /* Device woken up */
136 #define MODULE_DEVICE_TABLE(type, name)
137 #define PCI_ANY_ID (~0)
140 #define pci_module_init pci_register_driver
141 extern int pci_register_driver(struct pci_driver
*drv
);
142 extern void pci_unregister_driver(struct pci_driver
*drv
);
144 #endif /* PCI registration */
146 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18))
148 #define module_init(x) int init_module(void) { return x(); }
149 #define module_exit(x) void cleanup_module(void) { x(); }
151 #define module_init(x) __initcall(x);
152 #define module_exit(x) __exitcall(x);
156 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
157 #define list_for_each(pos, head) \
158 for (pos = (head)->next; pos != (head); pos = pos->next)
161 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13))
162 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
163 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,44))
164 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
167 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,23))
168 #define pci_enable_device(dev) do { } while (0)
171 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,14))
172 #define net_device device
175 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42))
180 * See linux/Documentation/DMA-mapping.txt
183 #ifndef PCI_DMA_TODEVICE
184 #define PCI_DMA_TODEVICE 1
185 #define PCI_DMA_FROMDEVICE 2
188 typedef u32 dma_addr_t
;
190 /* Pure 2^n version of get_order */
191 static inline int get_order(unsigned long size
)
195 size
= (size
-1) >> (PAGE_SHIFT
-1);
204 static inline void *pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
205 dma_addr_t
*dma_handle
)
208 int gfp
= GFP_ATOMIC
| GFP_DMA
;
210 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
213 memset(ret
, 0, size
);
214 *dma_handle
= virt_to_bus(ret
);
218 static inline void pci_free_consistent(struct pci_dev
*hwdev
, size_t size
,
219 void *vaddr
, dma_addr_t dma_handle
)
221 free_pages((unsigned long)vaddr
, get_order(size
));
224 extern uint
pci_map_single(void *dev
, void *va
, uint size
, int direction
);
225 extern void pci_unmap_single(void *dev
, uint pa
, uint size
, int direction
);
227 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
228 #define pci_unmap_single(cookie, address, size, dir)
231 #endif /* DMA mapping */
233 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43))
235 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
236 #define netif_down(dev) do { (dev)->start = 0; } while(0)
238 /* pcmcia-cs provides its own netdevice compatibility layer */
239 #ifndef _COMPAT_NETDEVICE_H
244 * For pre-softnet kernels we need to tell the upper layer not to
245 * re-enter start_xmit() while we are in there. However softnet
246 * guarantees not to enter while we are in there so there is no need
247 * to do the netif_stop_queue() dance unless the transmit queue really
248 * gets stuck. This should also improve performance according to tests
249 * done by Aman Singla.
252 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
253 #define netif_wake_queue(dev) do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while(0)
254 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
256 static inline void netif_start_queue(struct net_device
*dev
)
263 #define netif_queue_stopped(dev) (dev)->tbusy
264 #define netif_running(dev) (dev)->start
266 #endif /* _COMPAT_NETDEVICE_H */
268 #define netif_device_attach(dev) netif_start_queue(dev)
269 #define netif_device_detach(dev) netif_stop_queue(dev)
271 /* 2.4.x renamed bottom halves to tasklets */
272 #define tasklet_struct tq_struct
273 static inline void tasklet_schedule(struct tasklet_struct
*tasklet
)
275 queue_task(tasklet
, &tq_immediate
);
276 mark_bh(IMMEDIATE_BH
);
279 static inline void tasklet_init(struct tasklet_struct
*tasklet
,
280 void (*func
)(unsigned long),
283 tasklet
->next
= NULL
;
285 tasklet
->routine
= (void (*)(void *))func
;
286 tasklet
->data
= (void *)data
;
288 #define tasklet_kill(tasklet) {do{} while(0);}
290 /* 2.4.x introduced del_timer_sync() */
291 #define del_timer_sync(timer) del_timer(timer)
295 #define netif_down(dev)
299 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3))
302 * Emit code to initialise a tq_struct's routine and data pointers
304 #define PREPARE_TQUEUE(_tq, _routine, _data) \
306 (_tq)->routine = _routine; \
307 (_tq)->data = _data; \
311 * Emit code to initialise all of a tq_struct
313 #define INIT_TQUEUE(_tq, _routine, _data) \
315 INIT_LIST_HEAD(&(_tq)->list); \
317 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
322 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6))
324 /* Power management related routines */
327 pci_save_state(struct pci_dev
*dev
, u32
*buffer
)
331 for (i
= 0; i
< 16; i
++)
332 pci_read_config_dword(dev
, i
* 4,&buffer
[i
]);
338 pci_restore_state(struct pci_dev
*dev
, u32
*buffer
)
343 for (i
= 0; i
< 16; i
++)
344 pci_write_config_dword(dev
,i
* 4, buffer
[i
]);
347 * otherwise, write the context information we know from bootup.
348 * This works around a problem where warm-booting from Windows
349 * combined with a D3(hot)->D0 transition causes PCI config
350 * header data to be forgotten.
353 for (i
= 0; i
< 6; i
++)
354 pci_write_config_dword(dev
,
355 PCI_BASE_ADDRESS_0
+ (i
* 4),
356 pci_resource_start(dev
, i
));
357 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, dev
->irq
);
362 #endif /* PCI power management */
364 /* Old cp0 access macros deprecated in 2.4.19 */
365 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
366 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
369 /* Module refcount handled internally in 2.6.x */
370 #ifndef SET_MODULE_OWNER
371 #define SET_MODULE_OWNER(dev) do {} while (0)
372 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
373 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
375 #define OLD_MOD_INC_USE_COUNT do {} while (0)
376 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
379 #ifndef SET_NETDEV_DEV
380 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
383 #ifndef HAVE_FREE_NETDEV
384 #define free_netdev(dev) kfree(dev)
387 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
388 /* struct packet_type redefined in 2.6.x */
389 #define af_packet_priv data
392 #endif /* _linuxver_h_ */
This page took 0.055082 seconds and 5 git commands to generate.