How to map user space buffer address to physical address for DMA operation

Hi,
If there is any way in windows kernel driver(WDF) that we can map user space buffer address to physical address (logical address for device can access) for PCI device to operate DMA R/W. I mean don’t use the common buffer allocated in driver for mapping, I know this way. But using the user buffer address from read/write request.

Thanks

Abei

xxxxx@hotmail.com wrote:

If there is any way in windows kernel driver(WDF) that we can map user space buffer address to physical address (logical address for device can access) for PCI device to operate DMA R/W. I mean don’t use the common buffer allocated in driver for mapping, I know this way. But using the user buffer address from read/write request.

Of course. That’s what the whole set of WdfDmaTransaction APIs are
for. The framework will call you back with a scatter/gather list of
logical addresses for the user’s buffer.

Now, you do need to understand that your hardware MUST support
scatter/gather. User buffers are never physically contiguous, and you
can’t force them to be so. If you need contiguous buffers, then you
have little other choice but to allocate a common buffer and copy.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Your hardware does not need to support scatter/gather. If your hardware doesn’t support scatter/gather, Windows will provide you “system scatter/gather support” which will agglomerate physically discontiguous buffers and provide you a single base address and length.

Peter
OSR
@OSRDrivers

xxxxx@osr.com wrote:

Your hardware does not need to support scatter/gather. If your hardware doesn’t support scatter/gather, Windows will provide you “system scatter/gather support” which will agglomerate physically discontiguous buffers and provide you a single base address and length.

By copying?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you all for your help.
Sorry, I forgot one thing that my device don’t support scatter/gather feature. It only support packet mode. For better performance, the only thing I can do is to allocate bigger buffer for one DMA operation.
Now I allocate 1M common buffer and get its logical address to issue device DMA, but my driver must do a copy operation from common buffer to user rw request buffer. I want to cancel this copy operation, so I need to map user buffer virtual address to contiguous physical address for DMA. So can you help me to find the way or there is no way in windows driver?
Thank you very much!!!

Abei

You cannot “map user buffer virtual address to contiguous physical address”,
the buffer has pages associated with it already, and they are almost always
not contiguous. You are going to have to live with the cost of the copy.

Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Tuesday, September 20, 2016 9:23 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to map user space buffer address to physical address
for DMA operation

Thank you all for your help.
Sorry, I forgot one thing that my device don’t support scatter/gather
feature. It only support packet mode. For better performance, the only thing
I can do is to allocate bigger buffer for one DMA operation.
Now I allocate 1M common buffer and get its logical address to issue device
DMA, but my driver must do a copy operation from common buffer to user rw
request buffer. I want to cancel this copy operation, so I need to map user
buffer virtual address to contiguous physical address for DMA. So can you
help me to find the way or there is no way in windows driver?
Thank you very much!!!

Abei


NTDEV is sponsored by OSR

Visit the list online at:
http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at
http:</http:></http:></http:>

Hi, Peter:
What is the “system scatter/gather support” meaning? Could you please help to show me the exactly code or flow of “agglomerate physically discontiguous buffers and provide you a single base address and length”?
Thanks

Hi, Don:
Thank you answer for my question.
That is terrible news.

Yup.

OP: Just use the standard Windows DMA APIs: Set up,the WDF DMA Transaction, as Mr. Roberts suggested.

Don’t worry about the cost of the copy that the OS does. Just write your driver and make it work.

Peter
OSR
@OSRDrivers

Hi, Peter:
That is my current method.
Thanks

Hi Peter,
I noticed that my hardware also doesn’t support scatter/gather and requires a single base address and length. But I am writing an NDIS miniport driver, so will Windows still provide system/gather support and provide me a single base address and length ?
With regards,Jenson

Date: Tue, 20 Sep 2016 18:57:54 -0400
From: xxxxx@osr.com
To: xxxxx@lists.osr.com
Subject: RE:[ntdev] How to map user space buffer address to physical address for DMA operation

Your hardware does not need to support scatter/gather. If your hardware doesn’t support scatter/gather, Windows will provide you “system scatter/gather support” which will agglomerate physically discontiguous buffers and provide you a single base address and length.

Peter
OSR
@OSRDrivers


NTDEV is sponsored by OSR

Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

I haven’t touched NDIS in years, so I’m not the best person to ask.

I don’t see any reason why it *wouldn’t*… but I’m afraid I can’t give you a definitive NDIS answer.

Sorry!

Peter
OSR
@OSRDrivers

According to the docs too the scatter gather list should return a single address-length pair if your hardware doesn’t support SGDMA. But is that only for PCI and it doesn’t hold true for NDIS. When I did try to allocate SGList, it did return address-length pairs but our NIC couldn’t handle reading more than one address-length pair for a Netbuffer. Which annoyed me as the H/W guys said it was SGDMA capable, clearly it’s not.

So I am implementing the horrible copy a single buffer to a shared memory at time so that I can fix my interrupt sync issues. That is till the H/W guys implement the promised scatter gather functionality.

Thanks Peter for that info. I’ll open a new thread if necessary.

With regards,
Jenson Pais