From: Stefan on
Is it really so, what I just have read: MmAllocateContiguousMemory should
not used
in WDM drivers? Why?
I use it to put a scatter gather list into my hardware. With
AllocateCommonBuffer I cannot
define a HighestAcceptableAddress. My DMA controller supports 64 bit
transfers, but
for the SGList entries there is only one 32 bit register.
So, what is the right way?

Thanks in advance. Stefan


From: Ilya Konstantinov on
Stefan wrote:
> Is it really so, what I just have read: MmAllocateContiguousMemory should
> not used
> in WDM drivers? Why?

Because WDM gives you a framework -- an orderly way of doing things, so
you'll have the best chances of making things work right, which is very
important with drivers. Among others, WDM gives you a standard way of
doing DMA, including SG DMA.

> I use it to put a scatter gather list into my hardware. With
> AllocateCommonBuffer I cannot
> define a HighestAcceptableAddress. My DMA controller supports 64 bit
> transfers, but
> for the SGList entries there is only one 32 bit register.

In SCATTER_GATHER_LIST's SCATTER_GATHER_ELEMENT, I see that the Address
field is defined as a PHYSICAL_ADDRESS -- that is, a 64bit memory
address.

In the DEVICE_DESCRIPTION structure which you pass to IoGetDmaAdapter,
there's a Dma32BitAddresses and Dma64BitAddresses flag, which hints the
sg-list/common-buffer allocator of the highest acceptable address.

> So, what is the right way?

Trusting WDM's DMA management functions.

From: Maxim S. Shatskih on
> Because WDM gives you a framework -- an orderly way of doing things, so
> you'll have the best chances of making things work right, which is very
> important with drivers. Among others, WDM gives you a standard way of
> doing DMA, including SG DMA.

MmAllocateContiguousMemory is intended for use in DMA adapter objects (this is
nearly the only use of this function) and is really used by them - like by one
in PCI.SYS.

->AllocateCommonBuffer is based on MmAllocateContiguousMemory, but adds the bus
specifics like the highest acceptable physical address and so on.

Isolating the bus/chipset specifics from the hardware driver is a good idea,
and Windows provides you with this.

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