Allocating Physical Memory Block for PCI Base Address Regisrer Mapping

  • Thread starter Thread starter Boby George
  • Start date Start date
B

Boby George

Hi Everyone,

In my current project, I have a requirement to map a piece of physical
memory into one of the PCI base address register. This BAR maps the
inbound PCI cycles to the local memory of this board. This PCI device
do not support DMA. I have added the following code in the AddDevice
function for this PCI WDM Driver.

LowestAcceptableAddress.QuadPart = 0x0000000000000000;
HighestAcceptableAddress.QuadPart = 0x00000000FFFFFFFF;
BoundaryAddressMultiple.QuadPart = 0x0000000000000000;

fdoData->pNPVirtualMemory =
(PULONG)MmAllocateContiguousMemorySpecifyCache(
0x10000,
LowestAcceptableAddress,
HighestAcceptableAddress,
BoundaryAddressMultiple,
MmNonCached
);

fdoData->pNPPhysicalMemory = MmGetPhysicalAddress(
fdoData->pNPVirtualMemory);
PI7C9X110DebugPrint(INFO,
"NP MEMORY VA:0x%x PA:0x%x\n",
fdoData->pNPVirtualMemory,fdoData->pNPPhysicalMemory);

Note:
fdoData->pNPVirtualMemory is declared as PULONG
fdoData->pNPPhysicalMemory is declared as PHYSICAL_ADDRESS


I plug in the value in fdoData->pNPPhysicalMemory variable to the PCI
Device BAR. But somehow inbound mapping still don't seem to work.

One of the question is, is MmGetPhysicalAddress really returning a
physical address of the memory that can be used with PCI devices. I see
that in places in MSDN, not to use the physical address returned by
MmGetPhysicalAddress for DMA. Even though I am not using DMA, does this
statement still apply to my design?

Below is what I get from windbg for the pool, which says 0x10000 is my
physical address for the non-paged pool.

Windbg Output:
PI7C9X110: NP MEMORY VA:0xf6a21000 PA:0x10000

Thanks in Advance,

Boby
 
Back
Top