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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

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

Only if the size is <= 4096, otherwise you’d need to pass a scatter/gather list,
which is essentially what an MDL is, so the correct thing to do is pass an MDL,
and have the driver convert it to physical addresses.

If you really need a single physical address, there are calls to allocate physically
contiguous memory, but they are unlikely to work after the system has been booted for a while.

-DH
----- Original Message -----
From: “Hassan I Khan”
To: “NT Developers Interest List”
Sent: Wednesday, June 06, 2001 5:19 PM
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@syssoftsol.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

> 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 ?

Yes, but using HalAllocateCommonBuffer is a much better way of doing this.

Max


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