2 * Linux OS Independent Layer
4 * Copyright 2004, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
20 /* use current 2.4.x calling conventions */
23 /* assert and panic */
24 #define ASSERT(exp) do {} while (0)
26 /* PCMCIA attribute space access macros */
27 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
29 dev_link_t link
; /* PCMCIA device pointer */
30 dev_node_t node
; /* PCMCIA node structure */
31 void *base
; /* Mapped attribute memory window */
32 size_t size
; /* Size of window */
33 void *drv
; /* Driver data */
36 #define OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
37 osl_pcmcia_read_attr((osh), (offset), (buf), (size))
38 #define OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
39 osl_pcmcia_write_attr((osh), (offset), (buf), (size))
40 extern void osl_pcmcia_read_attr(void *osh
, uint offset
, void *buf
, int size
);
41 extern void osl_pcmcia_write_attr(void *osh
, uint offset
, void *buf
, int size
);
43 /* PCI configuration space access macros */
44 #define OSL_PCI_READ_CONFIG(loc, offset, size) \
45 osl_pci_read_config((loc), (offset), (size))
46 #define OSL_PCI_WRITE_CONFIG(loc, offset, size, val) \
47 osl_pci_write_config((loc), (offset), (size), (val))
48 extern uint32
osl_pci_read_config(void *loc
, uint size
, uint offset
);
49 extern void osl_pci_write_config(void *loc
, uint offset
, uint size
, uint val
);
51 /* OSL initialization */
52 #define osl_init() do {} while (0)
54 /* host/bus architecture-specific byte swap */
55 #define BUS_SWAP32(v) (v)
57 /* general purpose memory allocation */
60 #if defined(BCMDBG_MEM)
62 #define MALLOC(size) osl_debug_malloc((size), __LINE__, __FILE__)
63 #define MFREE(addr, size) osl_debug_mfree((addr), (size))
64 #define MALLOCED() osl_malloced()
65 extern void* osl_debug_malloc(uint size
, int line
, char* file
);
66 extern void osl_debug_mfree(void *addr
, uint size
);
67 extern void osl_debug_memdump(void);
71 #define MALLOC(size) osl_malloc((size))
72 #define MFREE(addr, size) osl_mfree((addr), (size))
73 #define MALLOCED() osl_malloced()
77 extern void *osl_malloc(uint size
);
78 extern void osl_mfree(void *addr
, uint size
);
79 extern uint
osl_malloced(void);
83 #define MALLOC(size) kmalloc((size), GFP_ATOMIC)
84 #define MFREE(addr, size) kfree((addr))
85 #define MALLOCED() (0)
90 * BINOSL selects the slightly slower function-call-based binary compatible osl.
91 * Macros expand to calls to functions defined in linux_osl.c .
95 /* string library, kernel mode */
96 #define printf(fmt, args...) printk(fmt, ## args)
97 #include <linux/kernel.h>
98 #include <linux/string.h>
100 /* register access macros */
102 sizeof(*(r)) == sizeof(uint8) ? readb((volatile uint8*)(r)) : \
103 sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
104 readl((volatile uint32*)(r)) \
106 #define W_REG(r, v) do { \
107 switch (sizeof(*(r))) { \
108 case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
109 case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
110 case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
114 #define AND_REG(r, v) W_REG((r), R_REG(r) & (v))
115 #define OR_REG(r, v) W_REG((r), R_REG(r) | (v))
117 /* bcopy, bcmp, and bzero */
118 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
119 #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
120 #define bzero(b, len) memset((b), '\0', (len))
122 /* uncached virtual address */
124 #define OSL_UNCACHED(va) KSEG1ADDR((va))
125 #include <asm/addrspace.h>
127 #define OSL_UNCACHED(va) (va)
130 /* get processor cycle count */
132 #define OSL_GETCYCLES(x) ((x) = read_c0_count() * 2)
133 #elif defined(__i386__)
134 #define OSL_GETCYCLES(x) rdtscl((x))
136 #define OSL_GETCYCLES(x) ((x) = 0)
139 /* dereference an address that may cause a bus exception */
141 #if defined(MODULE) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17))
142 #define BUSPROBE(val, addr) panic("get_dbe() will not fixup a bus exception when compiled into a module")
144 #define BUSPROBE(val, addr) get_dbe((val), (addr))
145 #include <asm/paccess.h>
148 #define BUSPROBE(val, addr) ({ (val) = R_REG((addr)); 0; })
151 /* map/unmap physical to virtual I/O */
152 #define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
153 #define REG_UNMAP(va) iounmap((void *)(va))
155 /* allocate/free shared (dma-able) consistent (uncached) memory */
156 #define DMA_ALLOC_CONSISTENT(dev, size, pap) \
157 pci_alloc_consistent((dev), (size), (dma_addr_t*)(pap))
158 #define DMA_FREE_CONSISTENT(dev, va, size, pa) \
159 pci_free_consistent((dev), (size), (va), (dma_addr_t)(pa))
161 /* map/unmap direction */
162 #define DMA_TX PCI_DMA_TODEVICE
163 #define DMA_RX PCI_DMA_FROMDEVICE
165 /* map/unmap shared (dma-able) memory */
166 #define DMA_MAP(dev, va, size, direction, p) \
167 pci_map_single((dev), (va), (size), (direction))
168 #define DMA_UNMAP(dev, pa, size, direction, p) \
169 pci_unmap_single((dev), (dma_addr_t)(pa), (size), (direction))
171 /* microsecond delay */
172 #define OSL_DELAY(usec) udelay(usec)
173 #include <linux/delay.h>
175 /* shared (dma-able) memory access macros */
177 #define W_SM(r, v) (*(r) = (v))
178 #define BZERO_SM(r, len) memset((r), '\0', (len))
180 /* packet primitives */
181 #define PKTGET(drv, len, send) osl_pktget((drv), (len), (send))
182 #define PKTFREE(drv, skb, send) osl_pktfree((skb))
183 #define PKTDATA(drv, skb) (((struct sk_buff*)(skb))->data)
184 #define PKTLEN(drv, skb) (((struct sk_buff*)(skb))->len)
185 #define PKTHEADROOM(drv, skb) (PKTDATA(drv,skb)-(((struct sk_buff*)(skb))->head))
186 #define PKTTAILROOM(drv, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
187 #define PKTNEXT(drv, skb) (((struct sk_buff*)(skb))->next)
188 #define PKTSETNEXT(skb, x) (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
189 #define PKTSETLEN(drv, skb, len) __skb_trim((struct sk_buff*)(skb), (len))
190 #define PKTPUSH(drv, skb, bytes) skb_push((struct sk_buff*)(skb), (bytes))
191 #define PKTPULL(drv, skb, bytes) skb_pull((struct sk_buff*)(skb), (bytes))
192 #define PKTDUP(drv, skb) skb_clone((struct sk_buff*)(skb), GFP_ATOMIC)
193 #define PKTCOOKIE(skb) ((void*)((struct sk_buff*)(skb))->csum)
194 #define PKTSETCOOKIE(skb, x) (((struct sk_buff*)(skb))->csum = (uint)(x))
195 #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
196 #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
197 #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
198 #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
199 extern void *osl_pktget(void *drv
, uint len
, bool send
);
200 extern void osl_pktfree(void *skb
);
207 #define printf(fmt, args...) osl_printf((fmt), ## args)
209 #define sprintf(buf, fmt, args...) osl_sprintf((buf), (fmt), ## args)
211 #define strcmp(s1, s2) osl_strcmp((s1), (s2))
213 #define strncmp(s1, s2, n) osl_strncmp((s1), (s2), (n))
215 #define strlen(s) osl_strlen((s))
217 #define strcpy(d, s) osl_strcpy((d), (s))
219 #define strncpy(d, s, n) osl_strncpy((d), (s), (n))
221 extern int osl_printf(const char *format
, ...);
222 extern int osl_sprintf(char *buf
, const char *format
, ...);
223 extern int osl_strcmp(const char *s1
, const char *s2
);
224 extern int osl_strncmp(const char *s1
, const char *s2
, uint n
);
225 extern int osl_strlen(char *s
);
226 extern char* osl_strcpy(char *d
, const char *s
);
227 extern char* osl_strncpy(char *d
, const char *s
, uint n
);
229 /* register access macros */
231 sizeof(*(r)) == sizeof(uint8) ? osl_readb((volatile uint8*)(r)) : \
232 sizeof(*(r)) == sizeof(uint16) ? osl_readw((volatile uint16*)(r)) : \
233 osl_readl((volatile uint32*)(r)) \
235 #define W_REG(r, v) do { \
236 switch (sizeof(*(r))) { \
237 case sizeof(uint8): osl_writeb((uint8)(v), (volatile uint8*)(r)); break; \
238 case sizeof(uint16): osl_writew((uint16)(v), (volatile uint16*)(r)); break; \
239 case sizeof(uint32): osl_writel((uint32)(v), (volatile uint32*)(r)); break; \
242 #define AND_REG(r, v) W_REG((r), R_REG(r) & (v))
243 #define OR_REG(r, v) W_REG((r), R_REG(r) | (v))
244 extern uint8
osl_readb(volatile uint8
*r
);
245 extern uint16
osl_readw(volatile uint16
*r
);
246 extern uint32
osl_readl(volatile uint32
*r
);
247 extern void osl_writeb(uint8 v
, volatile uint8
*r
);
248 extern void osl_writew(uint16 v
, volatile uint16
*r
);
249 extern void osl_writel(uint32 v
, volatile uint32
*r
);
251 /* bcopy, bcmp, and bzero */
252 extern void bcopy(const void *src
, void *dst
, int len
);
253 extern int bcmp(const void *b1
, const void *b2
, int len
);
254 extern void bzero(void *b
, int len
);
256 /* uncached virtual address */
257 #define OSL_UNCACHED(va) osl_uncached((va))
258 extern void *osl_uncached(void *va
);
260 /* get processor cycle count */
261 #define OSL_GETCYCLES(x) ((x) = osl_getcycles())
262 extern uint
osl_getcycles(void);
264 /* dereference an address that may target abort */
265 #define BUSPROBE(val, addr) osl_busprobe(&(val), (addr))
266 extern int osl_busprobe(uint32
*val
, uint32 addr
);
268 /* map/unmap physical to virtual */
269 #define REG_MAP(pa, size) osl_reg_map((pa), (size))
270 #define REG_UNMAP(va) osl_reg_unmap((va))
271 extern void *osl_reg_map(uint32 pa
, uint size
);
272 extern void osl_reg_unmap(void *va
);
274 /* allocate/free shared (dma-able) consistent (uncached) memory */
275 #define DMA_ALLOC_CONSISTENT(dev, size, pap) \
276 osl_dma_alloc_consistent((dev), (size), (pap))
277 #define DMA_FREE_CONSISTENT(dev, va, size, pa) \
278 osl_dma_free_consistent((dev), (void*)(va), (size), (pa))
279 extern void *osl_dma_alloc_consistent(void *dev
, uint size
, ulong
*pap
);
280 extern void osl_dma_free_consistent(void *dev
, void *va
, uint size
, ulong pa
);
282 /* map/unmap direction */
286 /* map/unmap shared (dma-able) memory */
287 #define DMA_MAP(dev, va, size, direction, p) \
288 osl_dma_map((dev), (va), (size), (direction))
289 #define DMA_UNMAP(dev, pa, size, direction, p) \
290 osl_dma_unmap((dev), (pa), (size), (direction))
291 extern uint
osl_dma_map(void *dev
, void *va
, uint size
, int direction
);
292 extern void osl_dma_unmap(void *dev
, uint pa
, uint size
, int direction
);
294 /* microsecond delay */
295 #define OSL_DELAY(usec) osl_delay((usec))
296 extern void osl_delay(uint usec
);
298 /* shared (dma-able) memory access macros */
300 #define W_SM(r, v) (*(r) = (v))
301 #define BZERO_SM(r, len) bzero((r), (len))
303 /* packet primitives */
304 #define PKTGET(drv, len, send) osl_pktget((drv), (len), (send))
305 #define PKTFREE(drv, skb, send) osl_pktfree((skb))
306 #define PKTDATA(drv, skb) osl_pktdata((drv), (skb))
307 #define PKTLEN(drv, skb) osl_pktlen((drv), (skb))
308 #define PKTHEADROOM(drv, skb) osl_pktheadroom((drv), (skb))
309 #define PKTTAILROOM(drv, skb) osl_pkttailroom((drv), (skb))
310 #define PKTNEXT(drv, skb) osl_pktnext((drv), (skb))
311 #define PKTSETNEXT(skb, x) osl_pktsetnext((skb), (x))
312 #define PKTSETLEN(drv, skb, len) osl_pktsetlen((drv), (skb), (len))
313 #define PKTPUSH(drv, skb, bytes) osl_pktpush((drv), (skb), (bytes))
314 #define PKTPULL(drv, skb, bytes) osl_pktpull((drv), (skb), (bytes))
315 #define PKTDUP(drv, skb) osl_pktdup((drv), (skb))
316 #define PKTCOOKIE(skb) osl_pktcookie((skb))
317 #define PKTSETCOOKIE(skb, x) osl_pktsetcookie((skb), (x))
318 #define PKTLINK(skb) osl_pktlink((skb))
319 #define PKTSETLINK(skb, x) osl_pktsetlink((skb), (x))
320 #define PKTPRIO(skb) osl_pktprio((skb))
321 #define PKTSETPRIO(skb, x) osl_pktsetprio((skb), (x))
322 extern void *osl_pktget(void *drv
, uint len
, bool send
);
323 extern void osl_pktfree(void *skb
);
324 extern uchar
*osl_pktdata(void *drv
, void *skb
);
325 extern uint
osl_pktlen(void *drv
, void *skb
);
326 extern uint
osl_pktheadroom(void *drv
, void *skb
);
327 extern uint
osl_pkttailroom(void *drv
, void *skb
);
328 extern void *osl_pktnext(void *drv
, void *skb
);
329 extern void osl_pktsetnext(void *skb
, void *x
);
330 extern void osl_pktsetlen(void *drv
, void *skb
, uint len
);
331 extern uchar
*osl_pktpush(void *drv
, void *skb
, int bytes
);
332 extern uchar
*osl_pktpull(void *drv
, void *skb
, int bytes
);
333 extern void *osl_pktdup(void *drv
, void *skb
);
334 extern void *osl_pktcookie(void *skb
);
335 extern void osl_pktsetcookie(void *skb
, void *x
);
336 extern void *osl_pktlink(void *skb
);
337 extern void osl_pktsetlink(void *skb
, void *x
);
338 extern uint
osl_pktprio(void *skb
);
339 extern void osl_pktsetprio(void *skb
, uint x
);
343 #endif /* _linux_osl_h_ */
This page took 0.085309 seconds and 5 git commands to generate.