WDF DMA Abstraction Question

Hi,

currently I’m thinking about a WDF driver design for a custom PCIe bus master DMA device.
The device provides standard DMA functions like DMA read and DMA write for which the driver design seems to be straight forward in packet based mode.

But the device has another test function in which it gets data from memory by DMA, performs an internal test and transfers the data back (by DMA) to the same memory location. The current hardware implementation does not allow splitting in two separate DMA write and read operations.

I want to initiate this test function from user space by calling DeviceIoControl with a pointer to the allocated memory. After the request is finished I want to compare the received data with the sent one.

Some questions:
1.) Is this functionality (inout DMA) supported in the
WDF DMA abstraction ?

2.) Which method should be defined in CTL_CODE for
this operation (METHOD_IN_DIRECT, OUT_DIRECT).

3.) Which DMA direction should be used in
WdfDmaTransactionInitializeUsingRequest ?

Thanks,
Sven

Windows packet based DMA does not support a read-modify-write DMA transfer
mode. If you enable driver verifier DMA checking, it will force DMA to go
through a temporary buffer, and it will only copy to OR from that temporary,
not both. Officially, you would need to use common memory for the DMA
operation, which the DMA device and CPU can read-write to/from at any time,
with assured cache coherence. You can’t magically turn a buffer passed down
to a driver into common memory; you need to allocate common memory in the
driver. Practically speaking, if you specify a device that does 64-bit
physical address and scatter gather when creating the DMA adapter object,
the virtual to physical address translation will supply the actual addresses
of the data buffers, and due to the fact that typical x86 systems are cache
coherent (not large ones anyway), your hardware will be able to do
read-modify-write cycles and have the right thing happen to the data.
Officially though, not all systems in the past or future guarantee cache
coherency between DMA and the CPU, so a driver that depends on this may find
itself broken. Like I said, it will also be declared broken by driver
verifier.

So, the answer to your actual question would be don’t use WDF DMA
transaction objects for read-modify-write operations, and do copy the data
to/from common memory, and only if this becomes a performance problem
consider alternatives.

Jan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-427640-
xxxxx@lists.osr.com] On Behalf Of xxxxx@synopsys.com
Sent: Wednesday, October 13, 2010 2:31 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] WDF DMA Abstraction Question

Hi,

currently I’m thinking about a WDF driver design for a custom PCIe bus
master DMA device.
The device provides standard DMA functions like DMA read and DMA write
for which the driver design seems to be straight forward in packet based
mode.

But the device has another test function in which it gets data from memory
by DMA, performs an internal test and transfers the data back (by DMA) to
the same memory location. The current hardware implementation does not
allow splitting in two separate DMA write and read operations.

I want to initiate this test function from user space by calling
DeviceIoControl
with a pointer to the allocated memory. After the request is finished I
want
to compare the received data with the sent one.

Some questions:
1.) Is this functionality (inout DMA) supported in the
WDF DMA abstraction ?

2.) Which method should be defined in CTL_CODE for
this operation (METHOD_IN_DIRECT, OUT_DIRECT).

3.) Which DMA direction should be used in
WdfDmaTransactionInitializeUsingRequest ?

Thanks,
Sven


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> I want to initiate this test function from user space by calling DeviceIoControl with a pointer to the

allocated memory. After the request is finished I want to compare the received data with the sent one.

Then you will need temporary buffer and memcpy/memcmp.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com