Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WDF Dma Transaction Issue

39 views
Skip to first unread message

Murugesan

unread,
Nov 2, 2009, 4:03:01 PM11/2/09
to
Hi all,

I need to perform DMA for 8 bytes for which i've failed.
I've followed the following sequence.

pMem = MmAllocateContiguousMemory(8, HighAddress)
if((pMem == NULL) || FdoData == NULL)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"pcial_dma_transfer() FAILED pMem || FdoData = NULL\n");
return !STATUS_SUCCESS;
}

pMdl = IoAllocateMdl(pMem , 8, FALSE, TRUE, NULL);

if (pMdl == NULL)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"IoAllocateMdl FAILED\n");
return !STATUS_SUCCESS;
}


DmaDirection = (rw == DMARW_CNL_TO_HOST) ?
WdfDmaDirectionReadFromDevice:
WdfDmaDirectionWriteToDevice;

status = WdfDmaTransactionCreate( FdoData->WdfDmaEnabler,
WDF_NO_OBJECT_ATTRIBUTES,
&dmaTransaction );
if(status == STATUS_SUCCESS)
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionCreate SUCCESS\n");
else
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionCreate ERROR\n");


status = WdfDmaTransactionInitialize(
dmaTransaction,
ProgramDmaFunction,
DmaDirection,
pMdl,
pMem,
length);

if(status == STATUS_SUCCESS)
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionInitialize SUCCESS\n");
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionInitialize ERROR status=0x%x\n",status);
return status;
}

status = WdfDmaTransactionExecute( dmaTransaction, NULL);

if(status == STATUS_SUCCESS)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionExecute SUCCESS\n");
}
else
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionExecute ERROR\n");


Where in the ProgramDmaFunction(), i've initiated h/w DMA operations by
fetching the physical address from the input
scatter gather list element, poll for DMA completion interrupt bit &
complete the DMA with wdfdmacompletedfinal & released
the dmatransaction.

After this sequence, when i checked the value of pMem, it remains unchanged
as zero which is not my expected value.

I have the following questions related with it.

1. Can we perform DMA for 8 bytes using dmatransaction ?( I have no other
option of PIO since my h/w design is in such a way, that supports only DMA)
2. What is wrong in the above mentioned sequence ?
3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ? [
Right now, i've some problem with the interrupt, so only polling mode is used)
4. I won't initiate DMA on the context of a wdfrequest, so i can't use
WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
because all the sample drivers provided by microsoft has used
WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
EvtIoQueue dispatched by any WdfRequest.

Thanks in advance,
Murugesan.S

eagersh

unread,
Nov 5, 2009, 9:57:21 PM11/5/09
to
On Nov 2, 2:03 pm, Murugesan <Muruge...@discussions.microsoft.com>
wrote:

You should check in your Hardware Engineer group if DMA engine could
support such small transaction.
It is very inefficient to use DMA for this amount of data. You should
use simple Read/Write PCI operations for such transfer.

Igor Sharovar

Murugesan

unread,
Nov 11, 2009, 1:37:01 AM11/11/09
to
Hi Igor,

I am pretty sure that my h/w DMA engine supports such small transaction. I
have a reference driver in linux which does the same operation. As I
mentioned earlier, the h/w has not mapped these buffers into PCI registers.
So I cannot do PCI read/write, performing DMA is the only way as per my h/w
design. I am wondering whether KMDF DMA methodology supports such small
transaction. Also why they haven't provided any sample which performs DMA
using the memory allocated in the same layer ?
Is any thing incorrect in my sequence of DMA operation other than the number
of bytes ?

Murugesan

"eagersh" wrote:

> .
>

eagersh

unread,
Nov 11, 2009, 2:41:30 PM11/11/09
to
On Nov 10, 11:37 pm, Murugesan <Muruge...@discussions.microsoft.com>

If you hardware does not support Read/Write PCI transactions how could
you control DMA operation? You need at least access to DMA registers
of the device. And you could do it only through PCI Read/Write.
Do I miss something?

Igor Sharovar

Murugesan

unread,
Nov 13, 2009, 3:04:03 PM11/13/09
to
Sorry Igor, my information might be unclear.I doesn't mean like that. We have
a separate core which follows a vendor specific protocol. Some registers are
there to control this core which is in a separate memory in the h/w & can be
read/write only by using DMA.
We have some registers mapped from PCI space separately which includes DMA
ADDR registers, DMA Control registers. The registers to control the core are
not mapped to PCI space, so slave access to these registers are not possible.
Core regiser read/write can only done through DMA. Now my question is does
framework supports to perform DMA for such
small length?

Murugesan

agersh" wrote:

> .
>

eagersh

unread,
Nov 16, 2009, 7:46:29 PM11/16/09
to
On Nov 13, 1:04 pm, Murugesan <Muruge...@discussions.microsoft.com>
wrote:

> Sorry Igor, my information might be unclear.I doesn't mean like that. We have
> a separate core which follows a vendor specific protocol. Some registers are
> there to control this core which is in a separate memory in the h/w & can be
> read/write only by using DMA.
> We have some registers mapped from PCI space separately which includes DMA
> ADDR registers, DMA Control registers. The registers to control the core are
> not mapped to PCI space, so slave access to these registers are not possible.
> Core regiser read/write can only done through DMA. Now my question is does
> framework supports to perform DMA for such
> small length?
>
> Murugesan
>

If your DMA registers are not mapped to PCI address space how could
initiate DMA transaction?
It is not matter if you have small or big buffer to transfer. Windows
framework only provides MDL or physical memory which you could use for
DMA transfer but initiate DMA transaction must be done by your driver.
You driver must prepare dma operation and starts it. You could look a
sample in WDK - PLX9x5x which shows how a driver does DMA operations.

Igor Sharovar

Murugesan

unread,
Nov 18, 2009, 1:10:02 AM11/18/09
to
OK. Actually I have two different sets of registers in my hw.
One set of registers are mapped to PCI space which includes DMA ADDR
registers, DMA control registers[these registers are used to initiate DMA
transaction.
Other set of registers are in hw buffer. This register space is completly
different and these are not mapped to PCI space. Read/Write to these
registers are done using DMA with the DMA control registers. These set of
registers are interface independent i.e they can be read/write using
PCI[dma]/SDIO. Read/Write to these second set of registers are only possible
via DMA[PCI] or CMD53[SDIO].
I hope this would explain my hw design.
I've already verified the WDK samples, based on that i've posted some
questions in my first post.
Coming back to original questions in my first post,

1. Can we perform DMA for 8 bytes using dmatransaction ?

YES.[From your previous answer]

2. What is wrong in the above mentioned sequence ?

I have provided a pseudo code in my first post. Please get back to my
first post.

3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ?
[ Right now, i've some problem with the interrupt, so only polling mode is
used)

4. I haven't initiated DMA on the context of a wdfrequest, so i can't use

WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
because all the sample drivers provided by microsoft has used
WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
EvtIoQueue dispatched by any WdfRequest.


Murugesan


"eagersh" wrote:

> .
>

eagersh

unread,
Nov 18, 2009, 2:53:31 PM11/18/09
to
On Nov 17, 11:10 pm, Murugesan <Muruge...@discussions.microsoft.com>
wrote:

> OK. Actually I have two different sets of registers in my hw.
> One set of registers are mapped to PCI space which includes DMA ADDR
> registers, DMA control registers[these registers are used to initiate DMA
> transaction.
> Other set of registers are in hw buffer. This register space is completly
> different and these are not mapped to PCI space. Read/Write to these
> registers are done using DMA with the DMA control registers. These set of
> registers are interface independent i.e they can be read/write using
> PCI[dma]/SDIO. Read/Write to these second set of registers are only possible
> via DMA[PCI] or CMD53[SDIO].
> I hope this would explain my hw design.
> I've already verified the WDK samples, based on that i've posted some
> questions in my first post.
> Coming back to original questions in my first post,
>
> 1. Can we perform DMA for 8 bytes using dmatransaction ?
>  YES.[From your previous answer]
There is only one limitation but it is not from Windows side. You
should check what kind of aliment of memory your hardware support.


> 2. What is wrong in the above mentioned sequence ?
>   I have provided a pseudo code in my first post. Please get back to my
> first post.

Is your ProgramDmaFunction called?
If it is, you should show this function too.
I have one comments. Usually if you allocate memory and MDL you need
to call MmBuildMdlForNonPagedPool. I don't know if this could be
related if you allocate a buffer by using MmAllocateContiguousMemory.
For 8 bytes buffer you don't need to use MmAllocateContiguousMemory
anyway.


> 3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ?
> [ Right now, i've some problem with the interrupt, so only polling mode is
> used)

No. This function is not linked to interrupt. It is only tells WDF
that DMA transaction is complete and ProgramDmaFunction should not be
called again.

> 4. I haven't initiated DMA on the context of a wdfrequest, so i can't use
> WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
> because all the sample drivers provided by microsoft has used
> WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
> EvtIoQueue dispatched by any WdfRequest.

No, it should not be an issue.

Igor Sharovar

Abhishek R [MSFT]

unread,
Nov 19, 2009, 1:55:19 AM11/19/09
to
Some suggestions -
- Did you call MmProbeAndLockPages() or BuildMdlFromScatterGatherList() for
the memory you allocated? If you haven't built the PFN array for the MDL
then you won’t be able to do DMA to it.
- Call WdfDmaTransactionDmaCompleted instead of
WdfDmaTransactionDmaCompletedFinal when terminating the transaction.
- Check the WDF log for errors (!wdflogdump debugger extension)
- Enable driver verifier and WDF verifier on your driver
- Try allocating non-cached memory to see if it makes a difference (
MmAllocateContiguousMemorySpecifyCache)
- Use h/w analyzers to see if dma transaction actually takes place

"Murugesan" <Muru...@discussions.microsoft.com> wrote in message
news:37A20A0C-F067-4B9E...@microsoft.com...

Murugesan

unread,
Nov 23, 2009, 2:14:01 AM11/23/09
to
Guys, Thanks for your reply. I think the issue might be the memory to get
paged out. From Abishek & Igor's answers I could infer that I've missed to
lock the physical pages or to use MmBuildMdlForNonPagedPool. This might be
the reason for failure. I'll add corresponding functionalities.

Thanks,
Murugesan.S

"Abhishek R [MSFT]" wrote:

> .
>

0 new messages