added NdisMAllocateSharedMemory and NdisMFreeSharedMemory and fixed a couple minor bugs

svn path=/trunk/; revision=5980
This commit is contained in:
Vizzini 2003-09-04 07:01:51 +00:00
parent dc354a8e32
commit 4517f7f992

View file

@ -4,11 +4,13 @@
* FILE: ndis/memory.c
* PURPOSE: Memory management routines
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
* Vizzini (vizzini@plasmic.com)
* REVISIONS:
* CSH 01/08-2000 Created
* 8/15/2003 Vizzini - DMA support
*/
#include <ndissys.h>
#include <miniport.h>
/*
* @implemented
@ -25,15 +27,18 @@ NdisAllocateMemoryWithTag(
* VirtualAddress = a pointer to the returned memory block
* Length = the number of requested bytes
* Tag = 32-bit pool tag
* NOTES:
* NDIS 5.0
* RETURNS:
* NDIS_STATUS_SUCCESS on success
* NDIS_STATUS_FAILURE on failure
*/
{
PVOID Block;
/* Plain nonpaged memory with tag */
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
Block = ExAllocatePoolWithTag(NonPagedPool, Length, Tag);
*VirtualAddress = Block;
if (!Block)
return NDIS_STATUS_FAILURE;
@ -125,7 +130,7 @@ NdisMUpdateSharedMemory(
/*
* @unimplemented
* @implemented
*/
NDIS_STATUS
EXPORT
@ -142,8 +147,13 @@ NdisAllocateMemory(
* Length = Size of the memory block to allocate
* MemoryFlags = Flags to specify special restrictions
* HighestAcceptableAddress = Specifies -1
* RETURNS:
* NDIS_STATUS_SUCCESS on success
* NDIS_STATUS_FAILURE on failure
*/
{
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
if (MemoryFlags & NDIS_MEMORY_NONCACHED)
{
*VirtualAddress = MmAllocateNonCachedMemory(Length);
@ -172,7 +182,7 @@ NdisAllocateMemory(
/*
* @unimplemented
* @implemented
*/
VOID
EXPORT
@ -188,6 +198,8 @@ NdisFreeMemory(
* MemoryFlags = Memory flags passed to NdisAllocateMemory
*/
{
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
if (MemoryFlags & NDIS_MEMORY_NONCACHED)
{
MmFreeNonCachedMemory(VirtualAddress, Length);
@ -235,7 +247,7 @@ NdisImmediateWriteSharedMemory(
/*
* @unimplemented
* @implemented
*/
VOID
EXPORT
@ -245,8 +257,23 @@ NdisMAllocateSharedMemory(
IN BOOLEAN Cached,
OUT PVOID *VirtualAddress,
OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
/*
* FUNCTION: Allocate a common buffer for DMA
* ARGUMENTS:
* MiniportAdapterHandle: Handle passed into MiniportInitialize
* Length: Number of bytes to allocate
* Cached: Whether or not the memory can be cached
* VirtualAddress: Pointer to memory is returned here
* PhysicalAddress: Physical address corresponding to virtual address
* NOTES:
* - Cached is ignored; we always allocate non-cached
*/
{
UNIMPLEMENTED
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportAdapterHandle;
NDIS_DbgPrint(MAX_TRACE,("Called.\n"));
*VirtualAddress = HalAllocateCommonBuffer(Adapter->AdapterObject, Length, PhysicalAddress, Cached);
}
@ -261,14 +288,42 @@ NdisMAllocateSharedMemoryAsync(
IN BOOLEAN Cached,
IN PVOID Context)
{
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
UNIMPLEMENTED
return NDIS_STATUS_FAILURE;
}
/*
* @implemented
*/
VOID
STDCALL
NdisMFreeSharedMemoryPassive(
PVOID Context)
/*
* FUNCTION: Free a common buffer
* ARGUMENTS:
* Context: Pointer to a miniport shared memory context
* NOTES:
* - Called by NdisMFreeSharedMemory to do the actual work
*/
{
PMINIPORT_SHARED_MEMORY Memory = (PMINIPORT_SHARED_MEMORY)Context;
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
HalFreeCommonBuffer(Memory->AdapterObject, Memory->Length, Memory->PhysicalAddress,
Memory->VirtualAddress, Memory->Cached);
ExFreePool(Memory);
}
/*
* @unimplemented
* @implemented
*/
VOID
EXPORT
@ -278,8 +333,45 @@ NdisMFreeSharedMemory(
IN BOOLEAN Cached,
IN PVOID VirtualAddress,
IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
/*
* FUNCTION: Free a shared memory block
* ARGUMENTS:
* MiniportAdapterHandle: Handle passed into MiniportInitialize
* Length: Number of bytes in the block to free
* Cached: Whether or not the memory was cached
* VirtualAddress: Address to free
* PhysicalAddress: corresponding physical addres
* NOTES:
* - This function can be called at dispatch_level or passive_level.
* Therefore we have to do this in a worker thread.
*/
{
UNIMPLEMENTED
HANDLE ThreadHandle;
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportAdapterHandle;
PMINIPORT_SHARED_MEMORY Memory;
NDIS_DbgPrint(MAX_TRACE,("Called.\n"));
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
/* Must be NonpagedPool because by definition we're at DISPATCH_LEVEL */
Memory = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_SHARED_MEMORY));
if(!Memory)
{
NDIS_DbgPrint(MID_TRACE, ("Insufficient resources\n"));
return;
}
Memory->AdapterObject = Adapter->AdapterObject;
Memory->Length = Length;
Memory->PhysicalAddress = PhysicalAddress;
Memory->VirtualAddress = VirtualAddress;
Memory->Cached = Cached;
PsCreateSystemThread(&ThreadHandle, THREAD_ALL_ACCESS, 0, 0, 0, NdisMFreeSharedMemoryPassive, Memory);
ZwClose(ThreadHandle);
}
/* EOF */