How can I get physical address memory from logical address memory?
Hi!
I need to allocate memory and I used malloc, but the problem is that I get only the logical address of memory. How can I get the corresponding physical memory?
Thanks
Pedro Fernandes
Re: How can I get physical address memory from logical address memory?
You can't, because it's virtual memory in modern OS. Why you need it at all?
Re: How can I get physical address memory from logical address memory?
My problem is that I have to configure DMA of the DS3134 (Chateau - Channelized T1 and E1 And Universal HDLC Controller) and it only works with the physical address memory. I can't pass logical addresses to it.
Re: How can I get physical address memory from logical address memory?
You have to be in kernel mode and use corresponding functions. malloc isn't appropriate for you( I suppose, that we are speaking about NT )
Re: How can I get physical address memory from logical address memory?
If you really want to access physical memory on
your system, use this method. This code is sure
to break your program if you do not know 100% how the physical
circuitry of your computer works.
If you know the physical address of the memory buffer, you must obtain an address that you can physically access.Windows NT is a virtual memory operating system, requiring us to map the physical address. This is a two-step process
m_nBufferMemorySize = 4 * 1024 * 1024;
m_pLAW = (unsigned char *)VirtualAlloc(
0,
m_nBufferMemorySize,
MEM_RESERVE,
PAGE_NOACCESS);
VirtualCopy(m_pLAW,
(LPVOID)(m_nLAWPhysical>>8),
m_nBufferMemorySize,
PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
First, reserve space in the virtual address space for the size of the mapped region, in this case 4MB, using VirtualAlloc. This is equivalent to saving a contiguous range of addresses within the 4GB virtual address range. Next, use the function VirtualCopy to set the page table entries to map the physical frame buffer address in m_nLAWPhysical into the reserved address range. The variable m_pLAW can now be used to directly access the frame buffer and memory-mapped registers on the chip. You can now read and write to physical RAM.
The library that contains the VirtualCopy function is not available on all
releases of Visual C++. So look around for it.
Re: How can I get physical address memory from logical address memory?
You may consult the Articles in the Win2000 Device Driver Kit:
Virtual Device Drivers\...\Memory-Mapped IO, and
Virtual Device Drivers\...\DMA
clem