vx_osl.c
资源名称:bcm4702.rar [点击查看]
上传用户:yuanda199
上传日期:2022-06-26
资源大小:412k
文件大小:4k
源码类别:
VxWorks
开发平台:
C/C++
- /*
- Copyright 2001, Broadcom Corporation
- All Rights Reserved.
- This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
- the contents of this file may not be disclosed to third parties, copied or
- duplicated in any form, in whole or in part, without the prior written
- permission of Broadcom Corporation.
- */
- /*
- * VxWorks 5.x END OS Layer
- *
- * Copyright(c) 2001 Broadcom Corp.
- * $Id: vx_osl.c,v 1.1 Broadcom SDK $
- */
- #include <hnbutypedefs.h>
- #include <vx_osl.h>
- #include <cacheLib.h>
- #include <bcmutils.h>
- #ifndef MSI
- #include <drv/pci/pciConfigLib.h>
- #endif
- #define PKTRSV 32 /* #bytes to reserve at the front of each cluster buffer */
- #define SAMEPAGE(x, y) (((ulong)(x) & ~4095) == ((ulong)(y) & ~4095))
- void*
- osl_pktget(void *drv, uint len, bool send)
- {
- END_OBJ *end;
- M_BLK_ID m;
- /* size requested should fit in our cluster buffer */
- ASSERT(len < (VXCLSIZE - sizeof (CL_BUF) - PKTRSV));
- /* drv is a pointer to an END_OBJ in disguise */
- end = (END_OBJ*)drv;
- /* older chips cannot dma address buffers which cross 4Kbyte boundaries */
- if ((m = netTupleGet(end->pNetPool, (len + PKTRSV), M_DONTWAIT, MT_DATA, FALSE))) {
- ASSERT(SAMEPAGE(m->mBlkHdr.mData, (m->mBlkHdr.mData + len - 1)));
- /* reserve a few bytes */
- m->mBlkHdr.mData += PKTRSV;
- m->mBlkHdr.mLen = len;
- /* ensure the cookie field is cleared */
- PKTSETCOOKIE(m, NULL);
- }
- return ((void*) m);
- }
- void
- osl_pktfree(void *drv, M_BLK_ID m, bool send)
- {
- netMblkClChainFree(m);
- }
- uchar*
- osl_pktpush(void *drv, M_BLK_ID m, uint nbytes)
- {
- ASSERT(M_HEADROOM(m) >= (int)nbytes);
- m->mBlkHdr.mData -= nbytes;
- m->mBlkHdr.mLen += nbytes;
- return (m->mBlkHdr.mData);
- }
- uchar*
- osl_pktpull(void *drv, M_BLK_ID m, uint nbytes)
- {
- ASSERT((int)nbytes <= m->mBlkHdr.mLen);
- m->mBlkHdr.mData += nbytes;
- m->mBlkHdr.mLen -= nbytes;
- return (m->mBlkHdr.mData);
- }
- void*
- osl_pktdup(void *drv, void *p)
- {
- END_OBJ *end;
- M_BLK_ID m;
- /* drv is a pointer to an END_OBJ in disguise */
- end = (END_OBJ*)drv;
- m = netMblkChainDup(end->pNetPool, (M_BLK_ID)p, 0, M_COPYALL, M_DONTWAIT);
- return (m);
- }
- void
- osl_assert(char *exp, char *file, int line)
- {
- extern void __assert(char *msg);
- char tempbuf[255];
- sprintf(tempbuf, "assertion "%s" failed: file "%s", line %dn", exp, file, line);
- __assert(tempbuf);
- }
- void*
- osl_dma_alloc_consistent(void *dev, uint size, void **pap)
- {
- void *va;
- va = cacheDmaMalloc(size);
- *pap = (void *)CACHE_DMA_VIRT_TO_PHYS(va);
- return (va);
- }
- void
- osl_dma_free_consistent(void *dev, uint size, void *va, void *pa)
- {
- cacheDmaFree(va);
- }
- void*
- osl_dma_map(void *dev, void *va, uint size, uint direction)
- {
- if (direction == DMA_TX)
- cacheFlush(DATA_CACHE, va, size);
- else
- cacheInvalidate(DATA_CACHE, va, size);
- return ((void*)CACHE_DMA_VIRT_TO_PHYS(va));
- }
- #define DELAY_PER_US 20
- void
- osl_delay(uint us)
- {
- volatile uint n;
- n = us * DELAY_PER_US;
- while (n--)
- ;
- }
- uint32
- osl_pci_read_config(pciinfo_t *pciinfo, uint offset, uint size)
- {
- uint32 val;
- ASSERT(size == 4);
- pciConfigInLong(pciinfo->bus, pciinfo->dev, pciinfo->func, offset, &val);
- return(val);
- }
- void
- osl_pci_write_config(pciinfo_t *pciinfo, uint offset, uint size, uint val)
- {
- ASSERT(size == 4);
- pciConfigOutLong(pciinfo->bus, pciinfo->dev, pciinfo->func, offset, val);
- }
- void
- osl_pcmcia_read_attr(void *shared, uint offset, void *buf, int size)
- {
- int i;
- for (i = 0; i < size; i++)
- ((uint8*)buf)[i] = rreg8(((uint8*)shared + (offset + i) * 2));
- }
- void
- osl_pcmcia_write_attr(void *shared, uint offset, void *buf, int size)
- {
- int i;
- for (i = 0; i < size; i++)
- wreg8(((uint8*)shared + (offset + i) * 2), ((uint8*)buf)[i]);
- }