From: Olivier on
Hello,

Within a driver, is there a way to recover the physical addresses of memory
pages that are behind a user-mode buffer pointer given via an IOCTL, as an
example?

Thanks,

Olivier
From: Maxim S. Shatskih on
> Within a driver, is there a way to recover the physical addresses of memory
> pages that are behind a user-mode buffer pointer given via an IOCTL, as an
> example?

The only need in physical addresses considered to be valid in Windows is DMA, and, for DMA, you should use IoGetDmaAdapter and then the adapter object methods.

Declare your IOCTL as METHOD_xxx_DIRECT, then use DMA object methods on Irp->MdlAddress in the driver to build a scatter-gather list. Then feed the scatter-gather list to the hardware.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: Olivier on
Thank you, Maxim.

In fact, what I need to do with the user-mode buffer (which is in fact a
locked rect in a DirectX surface of sysmem pool) is to DMA-transfer it to my
device, which is not natively SG-able.

So what I need to do is to :
1) Pray that the actual buffer under the surface is quite contiguous
2) Recover the set of physical pages from the pointer given by
surface->LockRect in user-mode
3) Manually perform as much DMA transfers needed by the physical layout of
this buffer

My question is thus : does the DmaAdapter object perform any DMA-related
action beneath any call to GetScatterGatherList, and does it require the
underlying hardware to be SG-able, or can I safely use it in combination with
a custom AdapterListControl routine to prepare some kind of DMA bursts list
to be handled by my driver and device?

Thanks,

Olivier

"Maxim S. Shatskih" wrote:

> > Within a driver, is there a way to recover the physical addresses of memory
> > pages that are behind a user-mode buffer pointer given via an IOCTL, as an
> > example?
>
> The only need in physical addresses considered to be valid in Windows is DMA, and, for DMA, you should use IoGetDmaAdapter and then the adapter object methods.
>
> Declare your IOCTL as METHOD_xxx_DIRECT, then use DMA object methods on Irp->MdlAddress in the driver to build a scatter-gather list. Then feed the scatter-gather list to the hardware.
>
> --
> Maxim S. Shatskih
> Windows DDK MVP
> maxim(a)storagecraft.com
> http://www.storagecraft.com
>
>
From: Alexander Grigoriev on
There is no such thing as manual DMA. If your device supports DMA, but not
scatter-gather, you may need to copy data into your own contiguous buffer
(IoGetDmaAdapter+AllocateCommonBuffer). Use MmGetSystemAddressForMdlSafe if
you're using DIRECT IOCTL. For a BUFFERED IOCTL, the address you get is
already in system address space.

"Olivier" <o.antoine(a)discussions.microsoft.com> wrote in message
news:A7AA185C-9FBB-47A4-AD82-908FABF6EAE4(a)microsoft.com...
> Thank you, Maxim.
>
> In fact, what I need to do with the user-mode buffer (which is in fact a
> locked rect in a DirectX surface of sysmem pool) is to DMA-transfer it to
> my
> device, which is not natively SG-able.
>
> So what I need to do is to :
> 1) Pray that the actual buffer under the surface is quite contiguous
> 2) Recover the set of physical pages from the pointer given by
> surface->LockRect in user-mode
> 3) Manually perform as much DMA transfers needed by the physical layout of
> this buffer
>
> My question is thus : does the DmaAdapter object perform any DMA-related
> action beneath any call to GetScatterGatherList, and does it require the
> underlying hardware to be SG-able, or can I safely use it in combination
> with
> a custom AdapterListControl routine to prepare some kind of DMA bursts
> list
> to be handled by my driver and device?
>
> Thanks,
>
> Olivier
>
> "Maxim S. Shatskih" wrote:
>
>> > Within a driver, is there a way to recover the physical addresses of
>> > memory
>> > pages that are behind a user-mode buffer pointer given via an IOCTL, as
>> > an
>> > example?
>>
>> The only need in physical addresses considered to be valid in Windows is
>> DMA, and, for DMA, you should use IoGetDmaAdapter and then the adapter
>> object methods.
>>
>> Declare your IOCTL as METHOD_xxx_DIRECT, then use DMA object methods on
>> Irp->MdlAddress in the driver to build a scatter-gather list. Then feed
>> the scatter-gather list to the hardware.
>>
>> --
>> Maxim S. Shatskih
>> Windows DDK MVP
>> maxim(a)storagecraft.com
>> http://www.storagecraft.com
>>
>>


From: Olivier on
Alexander,

This - extra copy to common buffer - is especially what I need to get rid
of, for performances reason, because I am dealing with very high throughput
data (around 600MB/sec) and noticed a serious bottleneck around some host PC
ram accesses when doing such copy.

On the other hand, my IOCTL is a buffered one but I use it to pass a control
structure to my driver. This structure notably contains a pointer to a locked
DirectX surface, which I think is still in caller app context although the
control structure is copied to system address space as you stated.

Thanks,

Olivier

"Alexander Grigoriev" wrote:

> There is no such thing as manual DMA. If your device supports DMA, but not
> scatter-gather, you may need to copy data into your own contiguous buffer
> (IoGetDmaAdapter+AllocateCommonBuffer). Use MmGetSystemAddressForMdlSafe if
> you're using DIRECT IOCTL. For a BUFFERED IOCTL, the address you get is
> already in system address space.
>
> "Olivier" <o.antoine(a)discussions.microsoft.com> wrote in message
> news:A7AA185C-9FBB-47A4-AD82-908FABF6EAE4(a)microsoft.com...
> > Thank you, Maxim.
> >
> > In fact, what I need to do with the user-mode buffer (which is in fact a
> > locked rect in a DirectX surface of sysmem pool) is to DMA-transfer it to
> > my
> > device, which is not natively SG-able.
> >
> > So what I need to do is to :
> > 1) Pray that the actual buffer under the surface is quite contiguous
> > 2) Recover the set of physical pages from the pointer given by
> > surface->LockRect in user-mode
> > 3) Manually perform as much DMA transfers needed by the physical layout of
> > this buffer
> >
> > My question is thus : does the DmaAdapter object perform any DMA-related
> > action beneath any call to GetScatterGatherList, and does it require the
> > underlying hardware to be SG-able, or can I safely use it in combination
> > with
> > a custom AdapterListControl routine to prepare some kind of DMA bursts
> > list
> > to be handled by my driver and device?
> >
> > Thanks,
> >
> > Olivier
> >
> > "Maxim S. Shatskih" wrote:
> >
> >> > Within a driver, is there a way to recover the physical addresses of
> >> > memory
> >> > pages that are behind a user-mode buffer pointer given via an IOCTL, as
> >> > an
> >> > example?
> >>
> >> The only need in physical addresses considered to be valid in Windows is
> >> DMA, and, for DMA, you should use IoGetDmaAdapter and then the adapter
> >> object methods.
> >>
> >> Declare your IOCTL as METHOD_xxx_DIRECT, then use DMA object methods on
> >> Irp->MdlAddress in the driver to build a scatter-gather list. Then feed
> >> the scatter-gather list to the hardware.
> >>
> >> --
> >> Maxim S. Shatskih
> >> Windows DDK MVP
> >> maxim(a)storagecraft.com
> >> http://www.storagecraft.com
> >>
> >>
>
>
>