You can, and it will work, occasionally :-). (which is really ‘no’)
There’s a number of problems with this approach, the most
significant/obvious is that virtual memory returned by ExAllocatePool() is
not physically contiguous.
Additionally, the value returned by MmGetPhysicalAddress is a
processor-relative physical address, and it’s entirely legal (although
admitedly somewhat rare right now) that this is not the same as the
‘logical’ address - the address that your device needs to put on the bus.
Finally, the bus may actually (again, rare) be configured such that your
device can’t even ‘see’ the address returned by MmGetPhysicalAddress() -
those addresses may not be forwarded accross bridges and such going back
toward the CPU (perhaps because the bus may have more accessible physical
address space than the CPU), etc.
Anyway…
A correct approach is to use HalAllocateCommonBuffer() on NT 4.0, or to use
DMA_OPERATIONS->AllocateCommonBuffer() on Windows 98/Me/2k/XP. An even
better approach (with hardware that supports scatter-gather) is to use the
corresponding scatter-gather functions (IoMapTransfer for NT4,
DMA_OPERATIONS->MapTransfer for 98, and DMA_OPERATIONS->GetScatterGatherList
for the newer OS’s). Note that in the scatter-gather case, you may still
need to allocate a common buffer to store the descriptors for each
scatter-gather element. I’ve also left out something called
‘non-scatter-gather packet-based’ DMA which has similar characteristics to
both common buffer and scatter-gather DMA, and is essentially an abstract,
somewhat opaque software solution to the scatter-gather problem for hardware
that does not support scatter-gather.
-Tim
Timothy A. Johns — xxxxx@driverdev.com
Driver Development Corporation — 800.841.0092
Bring Up Your Hardware — Fast. www.driverdev.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Hassan I Khan
Sent: Wednesday, June 06, 2001 5:20 PM
To: NT Developers Interest List
Subject: [ntdev] MmGetPhysicalAddress
Can I allocate memory using ExAllocatePool(NonPagedPool,…) and then use
MmGetPhysicalAddress to pass that memory’s physical address to a
device on,
say, PCI bus, so it can r/w to that memory ?
Thanks,
Hassan
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
You are currently subscribed to ntdev as: xxxxx@driverdev.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com