Problems mapping PCI Device registers into User application memory

We have an NT Legacy driver that, amongst other things, maps the registers
of a PCI device into User application memory space. (There are reasons for
doing this.) It does this by taking the memory value obtained from the
resource list, translating it and then uses IoAllocateMdl,
MmBuildMdlForNonPagedPool and MmMapLockedPages. The address obtained is
then passed to the application which is then able to access the PCI
registers directly via pointers. It has been working fine.

We have the same code in the WDM version of the driver (the translated
memory address is obtained directly from the translated resource list),
but it doesn’t work. When the application attempts to write to a register
in mapped memory, the PC crashes with a black screen that displays
*** Hardware Malfunction
Call your hardware vendor for support
NMI: Parity Check / Memory Parity Error
*** The system has halted
However, the driver is able to use the same pointer to perform reads and
writes without any problems.

In both the NT and WDM cases, the routine that performs the mapping
operation is called in response to IRP_MJ_CREATE, so the context should be
that of the User application.

If I change the WDM driver code and specify KernelMode to MmMapLockedPages
instead of UserMode, the application throws an exception when a read of
the mapped memory is attempted.

Can anyone tell me how to get the WDM version working and why it should
require different treatment to the NT4 case?

Any help would be appreciated.

Richard


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

Couple of quick possibilities:

  1. Beware a change that occured in an NT 4 service pack regarding the value
    returned from MmMapLockedPages. See the following KB article for more
    details:
    http://support.microsoft.com/support/kb/articles/Q199/3/11.ASP

  2. Make sure your device is powered up when your application tries to
    access it. In general, your driver can power it up in the first call to
    your IRP_MJ_CREATE handler, and power it down in the last call to the
    IRP_MJ_CLOSE handler.

-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 Richard Edmonds
Sent: Wednesday, May 30, 2001 10:39 AM
To: NT Developers Interest List
Cc: xxxxx@cix.co.uk
Subject: [ntdev] Problems mapping PCI Device registers into User
application memory

We have an NT Legacy driver that, amongst other things, maps the
registers
of a PCI device into User application memory space. (There are
reasons for
doing this.) It does this by taking the memory value obtained from the
resource list, translating it and then uses IoAllocateMdl,
MmBuildMdlForNonPagedPool and MmMapLockedPages. The address obtained is
then passed to the application which is then able to access the PCI
registers directly via pointers. It has been working fine.

We have the same code in the WDM version of the driver (the translated
memory address is obtained directly from the translated resource list),
but it doesn’t work. When the application attempts to write to a register
in mapped memory, the PC crashes with a black screen that displays
*** Hardware Malfunction
Call your hardware vendor for support
NMI: Parity Check / Memory Parity Error
*** The system has halted
However, the driver is able to use the same pointer to perform reads and
writes without any problems.

In both the NT and WDM cases, the routine that performs the mapping
operation is called in response to IRP_MJ_CREATE, so the context
should be
that of the User application.

If I change the WDM driver code and specify KernelMode to
MmMapLockedPages
instead of UserMode, the application throws an exception when a read of
the mapped memory is attempted.

Can anyone tell me how to get the WDM version working and why it should
require different treatment to the NT4 case?

Any help would be appreciated.

Richard


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

Hello Richard,

It is really not recommended to map PCI device registers into user-mode
memory. There are many problems you could face, in user-mode, that are
not a problem in kernel-mode (issues with not using HAL functions, and
also issues with getting preempted before completing all necessary
calls, to name a few).

Having said that, the procedure outlined in the following KB Article:

http://support.microsoft.com/support/kb/articles/Q189/3/27.asp

should work for both NT4 legacy drivers and Win2000 WDM drivers.

Regards,
Youssef

-----Original Message-----
From: Richard Edmonds [mailto:xxxxx@cix.co.uk]
Sent: Wednesday, May 30, 2001 10:39 AM
To: NT Developers Interest List
Cc: xxxxx@cix.co.uk
Subject: [ntdev] Problems mapping PCI Device registers into User
application memory

We have an NT Legacy driver that, amongst other things, maps the
registers
of a PCI device into User application memory space. (There are reasons
for
doing this.) It does this by taking the memory value obtained from the
resource list, translating it and then uses IoAllocateMdl,
MmBuildMdlForNonPagedPool and MmMapLockedPages. The address obtained is
then passed to the application which is then able to access the PCI
registers directly via pointers. It has been working fine.

We have the same code in the WDM version of the driver (the translated
memory address is obtained directly from the translated resource list),
but it doesn’t work. When the application attempts to write to a
register
in mapped memory, the PC crashes with a black screen that displays
*** Hardware Malfunction
Call your hardware vendor for support
NMI: Parity Check / Memory Parity Error
*** The system has halted
However, the driver is able to use the same pointer to perform reads and

writes without any problems.

In both the NT and WDM cases, the routine that performs the mapping
operation is called in response to IRP_MJ_CREATE, so the context should
be
that of the User application.

If I change the WDM driver code and specify KernelMode to
MmMapLockedPages
instead of UserMode, the application throws an exception when a read of
the mapped memory is attempted.

Can anyone tell me how to get the WDM version working and why it should
require different treatment to the NT4 case?

Any help would be appreciated.

Richard


You are currently subscribed to ntdev as: xxxxx@microsoft.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