📄 csdma.c
字号:
//**********************************************************************
//
// Filename: CsDma.c
//
// Description:
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to
// use this source code. For a copy of the EULA, please see the
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
//
//**********************************************************************
#include "csdma.h"
//
// Global pointer to the virtual memory starting address of DMA buffers
//
static DWORD g_pvDmaVirtualBase;
static DWORD g_CurrVirMemAddr;
static DWORD VirtualToPhysAddress(DWORD Virtual);
//****************************************************************************
// DMAInitMem()
//****************************************************************************
BOOL DMAInitMem(PCHIP pChip)
{
BOOL status=TRUE;
//Reserved the first 64 byte for communication between modulars (libs).
g_pvDmaVirtualBase = CS8950_VIRTUAL_MEMORY+16;
g_CurrVirMemAddr = CS8950_VIRTUAL_MEMORY+16;
//@melody The buffer of Non-copying Rx Indication
// Use the memory reserved for EDBG because CS8950 NDIS driver and Debugger cannot
// run at the same time. They are exclusive.
// CS8950_MEMORY_SIZE_RXINDICATE=CS8950_MEMORY_SIZE x 2 = 0x30000*2=0x60000
//memset((PVOID)g_pvDmaVirtualBase, 0, CS8950_MEMORY_SIZE);
memset((PVOID)g_pvDmaVirtualBase, 0, CS8950_MEMORY_SIZE_RXINDICATE);
return status;
}
//****************************************************************************
// DMARelMem()
//****************************************************************************
void DMARelMem(PCHIP pChip)
{
PCD pCD;
int index;
pCD = pChip->pData;
g_pvDmaVirtualBase = CS8950_VIRTUAL_MEMORY+16;
g_CurrVirMemAddr = CS8950_VIRTUAL_MEMORY+16;
//Free the Rx packet Que and the Rx buffer Que
/*
* NdisFreePacket and NdisFreeBuffer has to be called before the
* packet pool and the buffer pool can be released.
*/
if(pCD->ReceivePacketPool)
{
for(index = 0; index < TOTAL_RX_PKT_CNT; index++)
{
if (pCD->RxPacketPtQ[index])
NdisFreePacket(pCD->RxPacketPtQ[index]);
}
/* Free the packet pool */
NdisFreePacketPool(pCD->ReceivePacketPool);
}
if(pCD->ReceiveBufferPool)
{
for(index = 0; index < TOTAL_RX_PKT_CNT; index++)
{
if (pCD->RxBuffPtQ[index])
NdisFreeBuffer(pCD->RxBuffPtQ[index]);
}
/* Free the Buffer pool */
NdisFreeBufferPool(pCD->ReceiveBufferPool);
}
}
//****************************************************************************
// VirtualToPhysAddress()
//****************************************************************************
static DWORD VirtualToPhysAddress(DWORD addrVirtual)
{
//
// Make sure that the given virtual address is within the range of our buffer.
//
ASSERT((addrVirtual >= g_pvDmaVirtualBase) &&
(addrVirtual < (g_pvDmaVirtualBase + CS8950_MEMORY_SIZE_RXINDICATE)));
// (addrVirtual < (g_pvDmaVirtualBase + CS8950_MEMORY_SIZE)));
//
// Physical address is the base physical address plus the offset
// in the virtual address space. (Make this more flexible later.)
//
return (addrVirtual + (ULONG)CS8950_PHYSICAL_MEMORY - (ULONG)CS8950_VIRTUAL_MEMORY);
}
/*************************************************************************
*
* VosAllocSharedMemory()
*
*************************************************************************/
BOOL VosAllocSharedMemory
(
PCHIP pChip,
WORD Size,
PVOID *ppMemory,
DWORD *pPhysAddr
)
{
*ppMemory=(PVOID) g_CurrVirMemAddr;
*pPhysAddr=VirtualToPhysAddress(g_CurrVirMemAddr);
g_CurrVirMemAddr += (DWORD)Size;
//The address must start with 32 bits aligment
switch (g_CurrVirMemAddr & 3 )
{
case 1 :
g_CurrVirMemAddr += 3;
break;
case 2 :
g_CurrVirMemAddr += 2;
break;
case 3 :
g_CurrVirMemAddr += 1;
break;
default: // do nothing
break;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -