PCI BAR mapping

Hi,

I’m working on WDF driver for PCIe card which has 1MB of memory mapped
behind BAR0. I use the following function to map this memory and use it in
the driver:
MmMapIoSpace( desc->u.Memory.Start, desc->u.Memory.Length, MmNonCached );
This works as expected.
I need to be able to access the same memory from the user mode application.
Is there a way to map the same memory to user space? How to do this? In
Linux this is done with mmap() function. Is there something equivalent in
Windows?

Thanks in advance.
Best regards,
Danijel

danijel spasojevic wrote:

I’m working on WDF driver for PCIe card which has 1MB of memory mapped
behind BAR0. I use the following function to map this memory and use
it in the driver:
MmMapIoSpace( desc->u.Memory.Start, desc->u.Memory.Length, MmNonCached );
This works as expected.
I need to be able to access the same memory from the user mode
application. Is there a way to map the same memory to user space? How
to do this? In Linux this is done with mmap() function. Is there
something equivalent in Windows?

Although it is possible to do so (using MmMapLockedPagesSpecifyCache),
it is almost always a better idea to keep the physical device access
only in the kernel, and have the user-mode application request what it
wants using ioctls. Otherwise, you run in to security and
synchronization issues.

Ioctls are quick.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

First be really sure you have to map it to user space, this can open
wonderful security holes in a system. If you do need to do this then
MmMapLockedPagesSpecifyCache is your friend, use IoAllocateMdl then
MmBuildMdlForNonPagedPool to build the MDL for the memory you mapped
with MmMapIoSpace. Be aware you have to handle tracking of the process
and cleaning up the memory etc. And of course if more than one process
is mapping this piece of memory, or the memory will also be referenced
by the kernel, you have the fun of dealing with synchronization issues
that can make this a pain.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“danijel spasojevic” wrote in message
news:xxxxx@ntdev:

> Hi,
>
> I’m working on WDF driver for PCIe card which has 1MB of memory mapped
> behind BAR0. I use the following function to map this memory and use it in
> the driver:
> MmMapIoSpace( desc->u.Memory.Start, desc->u.Memory.Length, MmNonCached );
> This works as expected.
> I need to be able to access the same memory from the user mode application.
> Is there a way to map the same memory to user space? How to do this? In
> Linux this is done with mmap() function. Is there something equivalent in
> Windows?
>
> Thanks in advance.
> Best regards,
> Danijel