DMA Question

My XP driver does a READ DMA. The sequence is follows.

  1. sends and IRP for READ with buffer
  2. calls the DMA routine

I had confusion with MmGetSystemAddressForMdlSafe()
and MmGetMdlVirtualAddress() which
one should use when.

once the call comes to disptachroutine, I use
MmGetSystemAddressForMdlSafe() as follows.

if (Irp->MdlAddress != NULL)
{
currentAddress =
MmGetSystemAddressForMdlSafe(Irp->MdlAddress,NormalPagePriority);

if (currentAddress == NULL)
error;
}

PVOID pvDirectBuffer = currentAddress;
ULONG ulInputBufferLength =
irpSp->Parameters.DeviceIoControl.InputBufferLength;
ULONG ulDirectBufferLength =
irpSp->Parameters.DeviceIoControl.OutputBufferLength;
PVOID pvInputBuffer =
Irp->AssociatedIrp.SystemBuffer;

In the dma routine I use MmGetMdlVirtualAddress() to
get virtual address inorder to pass it to
MapTransfer() routine. Is it the way to do? I guess I
am trying to get virtual address twice and
screwing up the DMA and the DMA IS NOT WORKING.

Do I need to call only once for getting virtual
address? Can any body shed some light?


Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine’s Day
http://shopping.yahoo.com

MmGetMdlVirtualAddress returns the address originally supplied when
MmCreateMdl was called. This could be a user-mode address and thus
isn’t safe to use as an address most of the time.

MmGetSystemAddressForMdlSafe attempts to allocate a section of VA in the
kernel address space and maps a locked MDL into that range. This will
be a non-paged system address and can be accessed whenever your in
kernel mode (regardless of which process context you’re in).

MapTransfer basically uses the CurrentVa parameter to compute an offset
into the buffer (CurrentVa - MmGetMdlVirtualAddress(mdl)) and thus
should be relative to the MDL’s original address space.

-p

-----Original Message-----
From: Tom Pr [mailto:xxxxx@yahoo.com]
Sent: Wednesday, February 19, 2003 11:45 AM
To: NT Developers Interest List

My XP driver does a READ DMA. The sequence is follows.

  1. sends and IRP for READ with buffer
  2. calls the DMA routine

I had confusion with MmGetSystemAddressForMdlSafe() and
MmGetMdlVirtualAddress() which one should use when.

once the call comes to disptachroutine, I use
MmGetSystemAddressForMdlSafe() as follows.

if (Irp->MdlAddress != NULL)
{
currentAddress =
MmGetSystemAddressForMdlSafe(Irp->MdlAddress,NormalPagePriority);

if (currentAddress == NULL)
error;
}

PVOID pvDirectBuffer = currentAddress;
ULONG ulInputBufferLength =
irpSp->Parameters.DeviceIoControl.InputBufferLength;
ULONG ulDirectBufferLength =
irpSp->Parameters.DeviceIoControl.OutputBufferLength;
PVOID pvInputBuffer =
Irp->AssociatedIrp.SystemBuffer;

In the dma routine I use MmGetMdlVirtualAddress() to get virtual
address inorder to pass it to
MapTransfer() routine. Is it the way to do? I guess I am trying to get
virtual address twice and screwing up the DMA and the DMA IS NOT
WORKING.

Do I need to call only once for getting virtual address? Can any body
shed some light?


Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine’s Day
http://shopping.yahoo.com


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

> I guess I am trying to get virtual address twice and screwing up the DMA

and the DMA IS NOT WORKING.

Look at the definitions of MmGetMdlVirtualAddress and
MmGetSystemAddressForMdlSafe. They are macros and multiple calls to these
functions do not create problems.

-Srin.