Hi Kedar,
How to get the physical memroy address that is associated witht the
virtual memroy address that has been allocated by malloc() under windows
2000.
If you have a Mdl, which is set when you pass a user mode address to a
device, which is working
with direct IO (pDev->Flags & DO_DIRECT_IO), then you can use the MDL from
the IRP with MmMapLockedPages:
unsigned char* pData = (unsigned char*) MmMapLockedPages(pIrp->MdlAddress,
KernelMode);
Regards
Michael
Why do you need this?
The only valid need for physical addresses is for DMA, this is
achieved by using MDLs.
Set DO_DIRECT_IO in your driver, and the MDL which describes the app’s
buffer will be at Irp->MdlAddress. Pass it to DMA routines.
Max
----- Original Message -----
From: “kedar”
To: “NT Developers Interest List”
Sent: Tuesday, April 15, 2003 4:00 PM
Subject: [ntdev] virtual address to physical address
> Hai All,
>
> How to get the physical memroy address that is associated witht the
> virtual memroy address that has been allocated by malloc() under
windows
> 2000.
>
> Any information will be helpful.
>
> Thanks and regards,
> Kedar.
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
Hai All,
I am developing a user mode application which is used to test a hardware.
Harware needs buffers for the DMA transfers. So I need to write the
physical address in to the dma registers, memory allocated by malloc()
will be virtual address so i need to convert this to physical address.
Can you please suggest a solution to achieve this.
Thanks in advance.
Regards,
Kedar.
Speaking from minimal Windows-specific knowledge, here are some things
you should be aware of:
-
You will generally not be able to use memory allocated by malloc().
You will have to use memory allocated by a Win32 API, like
VirtualAlloc(), although I don’t believe you can even use this (I’m not
sure there’s a way to get the physical address of memory allocated by
VirtualAlloc()). There’s at least two other Win32 API sets that may do
what you want, but I don’t recall what they are. If you need to know, I
can look them up again.
-
You will have to make sure the data is actually paged into physical
memory – and can guarantee will remain paged in for the duration of the
DMA – before any DMA.
-
If your data to DMA is always less than or equal to the VM page size,
then you won’t have to worry. But if it’s more, you may have to take
extra measures to ensure that your physical memory is contiguous, unless
your DMA supports a scatter-gather or similar mechanism.
-
If your DMA controller has starting address alignment restrictions
which are more strict than the Windows VM page size, you will have to
take extra measures to ensure this alignment.
-
Under Windows NT, the program will probably need administrative
privelages to do this kind of low-level memory manipulation.
Hopefully someone with more experience can expound on these issues.
Chuck
----- Original Message -----
From: “kedar”
To: “NT Developers Interest List”
Sent: Monday, April 21, 2003 12:18 PM
Subject: [ntdev] virtual address to physical address
> Hai All,
>
> I am developing a user mode application which is used to test a
hardware.
> Harware needs buffers for the DMA transfers. So I need to write the
> physical address in to the dma registers, memory allocated by malloc()
> will be virtual address so i need to convert this to physical address.
>
> Can you please suggest a solution to achieve this.
>
> Thanks in advance.
>
> Regards,
> Kedar.
In NT, you must write a kernel mode driver to access your User App
buffers with data from the hardware.
Dominick Cafarelli
-----Original Message-----
From: kedar [mailto:xxxxx@hotmail.com]
Sent: Sunday, April 20, 2003 10:18 PM
To: NT Developers Interest List
Subject: [ntdev] virtual address to physical address
Hai All,
I am developing a user mode application which is used to test a
hardware. Harware needs buffers for the DMA transfers. So I need to
write the physical address in to the dma registers, memory allocated by
malloc() will be virtual address so i need to convert this to physical
address.
Can you please suggest a solution to achieve this.
Thanks in advance.
Regards,
Kedar.
You are currently subscribed to ntdev as: xxxxx@nai.com To
unsubscribe send a blank email to xxxxx@lists.osr.com
You cannot do this in user mode. Write a driver.
----- Original Message -----
From: “kedar”
To: “NT Developers Interest List”
Sent: Monday, April 21, 2003 9:18 AM
Subject: [ntdev] virtual address to physical address
> Hai All,
>
> I am developing a user mode application which is used to test a
hardware.
> Harware needs buffers for the DMA transfers. So I need to write the
> physical address in to the dma registers, memory allocated by
malloc()
> will be virtual address so i need to convert this to physical
address.
>
> Can you please suggest a solution to achieve this.
>
> Thanks in advance.
>
> Regards,
> Kedar.
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
Kedar,
Actually, physical addresses on NT based operating systems are abstracted,
so your device will need logical addresses. FYI, on x86 based platforms,
**most of the time**, these two are the same, that is logical == physical
address. This is why people can use the wrong functions such as
MmGetPhysicalAddress and their drivers will still work most of the time.
What you should probably do is what Max suggested, and use IOCTLs or
ReadFile/WriteFile to send your buffer from user-mode to kernel-mode using a
DIRECT buffering method. The system will then create an MDL for your user
buffer, and probe and lock the memory region for you ensuring that the
memory is accessible and will not be paged out when needed. Then, if you
need access to this buffer in your driver, you can use
MmGetSystemAddressForMdlSafe to map the memory pages and get a kernel
virtual address.
To get the logical addresses for the buffer, you can go a few different
ways. If your device supports scatter/gather DMA, then you should probably
use GetScatterGatherList which will create an array of memory chunks for you
with logical addresses that you can use to program your device. If your
device does not support scatter/gather, you can still use
GetScatterGatherList and handle the chunks individually, or you can use
MapTransfer. Don’t be confused in that these functions return the logical
addresses as type PHYSICAL_ADDRESS. These are still logical addresses.
I highly suggest you buy and read Walter Oney’s “Programming the Microsoft
Windows Driver Model 2nd edition”, as his book samples are the ONLY place I
have seen a complete and correct implementation of DMA transfers for Windows
platforms. There are a lot of incorrect implementations out there,
including a couple of free samples that have been available since NT4 and
which are still incorrect.
–
Bill McKenzie
Compuware Corporation
Watch your IRPs/IRBs/URBs/NDIS pkts with our free WDMSniffer tool:
http://frontline.compuware.com/nashua/patches/utility.htm
“kedar” wrote in message news:xxxxx@ntdev…
>
> Hai All,
>
> How to get the physical memroy address that is associated witht the
> virtual memroy address that has been allocated by malloc() under windows
> 2000.
>
> Any information will be helpful.
>
> Thanks and regards,
> Kedar.
>
>