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.
18 #include <bcmendian.h>
20 #include <linux_osl.h>
22 #include <linux/delay.h>
24 #include <asm/paccess.h>
28 #define PCI_CFG_RETRY 10
31 osl_pktget(void *drv
, uint len
, bool send
)
35 if ((skb
= dev_alloc_skb(len
)) == NULL
)
40 /* ensure the cookie field is cleared */
41 PKTSETCOOKIE(skb
, NULL
);
49 struct sk_buff
*skb
, *nskb
;
51 skb
= (struct sk_buff
*) p
;
53 /* perversion: we use skb->next to chain multi-skb packets */
57 if (skb
->destructor
) {
58 /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if destructor exists */
59 dev_kfree_skb_any(skb
);
61 /* can free immediately (even in_irq()) if destructor does not exist */
69 osl_pci_read_config(void *loc
, uint offset
, uint size
)
73 uint retry
=PCI_CFG_RETRY
;
75 /* only 4byte access supported */
78 pdev
= (struct pci_dev
*)loc
;
80 pci_read_config_dword(pdev
, offset
, &val
);
81 if (val
!= 0xffffffff)
90 osl_pci_write_config(void *loc
, uint offset
, uint size
, uint val
)
93 uint retry
=PCI_CFG_RETRY
;
95 /* only 4byte access supported */
98 pdev
= (struct pci_dev
*)loc
;
101 pci_write_config_dword(pdev
, offset
, val
);
102 if (offset
!=PCI_BAR0_WIN
)
104 if (osl_pci_read_config(loc
,offset
,size
) == val
)
111 osl_pcmcia_attr(void *osh
, uint offset
, char *buf
, int size
, bool write
)
116 osl_pcmcia_read_attr(void *osh
, uint offset
, void *buf
, int size
)
118 osl_pcmcia_attr(osh
, offset
, (char *) buf
, size
, FALSE
);
122 osl_pcmcia_write_attr(void *osh
, uint offset
, void *buf
, int size
)
124 osl_pcmcia_attr(osh
, offset
, (char *) buf
, size
, TRUE
);
130 osl_assert(char *exp
, char *file
, int line
)
134 sprintf(tempbuf
, "assertion \"%s\" failed: file \"%s\", line %d\n", exp
, file
, line
);
141 osl_malloc(uint size
)
143 return (kmalloc(size
, GFP_ATOMIC
));
147 osl_mfree(void *addr
, uint size
)
162 #endif /* defined(BCMDBG) || defined(BINOSL) */
165 * BINOSL selects the slightly slower function-call-based binary compatible osl.
170 osl_printf(const char *format
, ...)
176 /* sprintf into a local buffer because there *is* no "vprintk()".. */
177 va_start(args
, format
);
178 len
= vsprintf(buf
, format
, args
);
181 if (len
> sizeof (buf
)) {
182 printk("osl_printf: buffer overrun\n");
186 return (printk(buf
));
190 osl_sprintf(char *buf
, const char *format
, ...)
195 va_start(args
, format
);
196 rc
= vsprintf(buf
, format
, args
);
202 osl_strcmp(const char *s1
, const char *s2
)
204 return (strcmp(s1
, s2
));
208 osl_strncmp(const char *s1
, const char *s2
, uint n
)
210 return (strncmp(s1
, s2
, n
));
220 osl_strcpy(char *d
, const char *s
)
222 return (strcpy(d
, s
));
226 osl_strncpy(char *d
, const char *s
, uint n
)
228 return (strncpy(d
, s
, n
));
232 bcopy(const void *src
, void *dst
, int len
)
234 memcpy(dst
, src
, len
);
238 bcmp(const void *b1
, const void *b2
, int len
)
240 return (memcmp(b1
, b2
, len
));
244 bzero(void *b
, int len
)
246 memset(b
, '\0', len
);
250 osl_readl(volatile uint32
*r
)
256 osl_readw(volatile uint16
*r
)
262 osl_readb(volatile uint8
*r
)
268 osl_writel(uint32 v
, volatile uint32
*r
)
274 osl_writew(uint16 v
, volatile uint16
*r
)
280 osl_writeb(uint8 v
, volatile uint8
*r
)
286 osl_uncached(void *va
)
289 return ((void*)KSEG1ADDR(va
));
301 cycles
= read_c0_count() * 2;
302 #elif defined(__i386__)
311 osl_reg_map(uint32 pa
, uint size
)
313 return (ioremap_nocache((unsigned long)pa
, (unsigned long)size
));
317 osl_reg_unmap(void *va
)
323 osl_busprobe(uint32
*val
, uint32 addr
)
326 return get_dbe(*val
, (uint32
*)addr
);
334 osl_dma_alloc_consistent(void *dev
, uint size
, ulong
*pap
)
336 return (pci_alloc_consistent((struct pci_dev
*)dev
, size
, (dma_addr_t
*)pap
));
340 osl_dma_free_consistent(void *dev
, void *va
, uint size
, ulong pa
)
342 pci_free_consistent((struct pci_dev
*)dev
, size
, va
, (dma_addr_t
)pa
);
346 osl_dma_map(void *dev
, void *va
, uint size
, int direction
)
350 dir
= (direction
== DMA_TX
)? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
;
351 return (pci_map_single(dev
, va
, size
, dir
));
355 osl_dma_unmap(void *dev
, uint pa
, uint size
, int direction
)
359 dir
= (direction
== DMA_TX
)? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
;
360 pci_unmap_single(dev
, (uint32
)pa
, size
, dir
);
370 osl_pktdata(void *drv
, void *skb
)
372 return (((struct sk_buff
*)skb
)->data
);
376 osl_pktlen(void *drv
, void *skb
)
378 return (((struct sk_buff
*)skb
)->len
);
382 osl_pktheadroom(void *drv
, void *skb
)
384 return (uint
) skb_headroom((struct sk_buff
*) skb
);
388 osl_pkttailroom(void *drv
, void *skb
)
390 return (uint
) skb_tailroom((struct sk_buff
*) skb
);
394 osl_pktnext(void *drv
, void *skb
)
396 return (((struct sk_buff
*)skb
)->next
);
400 osl_pktsetnext(void *skb
, void *x
)
402 ((struct sk_buff
*)skb
)->next
= (struct sk_buff
*)x
;
406 osl_pktsetlen(void *drv
, void *skb
, uint len
)
408 __skb_trim((struct sk_buff
*)skb
, len
);
412 osl_pktpush(void *drv
, void *skb
, int bytes
)
414 return (skb_push((struct sk_buff
*)skb
, bytes
));
418 osl_pktpull(void *drv
, void *skb
, int bytes
)
420 return (skb_pull((struct sk_buff
*)skb
, bytes
));
424 osl_pktdup(void *drv
, void *skb
)
426 return (skb_clone((struct sk_buff
*)skb
, GFP_ATOMIC
));
430 osl_pktcookie(void *skb
)
432 return ((void*)((struct sk_buff
*)skb
)->csum
);
436 osl_pktsetcookie(void *skb
, void *x
)
438 ((struct sk_buff
*)skb
)->csum
= (uint
)x
;
442 osl_pktlink(void *skb
)
444 return (((struct sk_buff
*)skb
)->prev
);
448 osl_pktsetlink(void *skb
, void *x
)
450 ((struct sk_buff
*)skb
)->prev
= (struct sk_buff
*)x
;
454 osl_pktprio(void *skb
)
456 return (((struct sk_buff
*)skb
)->priority
);
460 osl_pktsetprio(void *skb
, uint x
)
462 ((struct sk_buff
*)skb
)->priority
= x
;
This page took 0.058993 seconds and 5 git commands to generate.