INFO: Using Portio Sample to Access Memory Mapped Registers (323595)



The information in this article applies to:

  • Microsoft Windows 2000 Driver Development Kit (DDK)

This article was previously published under Q323595

SUMMARY

The Portio sample that is available in the Windows 2000 DDK was originally written to access the following registers:
  • Input/output (I/O) mapped device registers (which are frequently referred as I/O ports).
  • Memory mapped device registers (which are frequently referred as memory mapped I/O).
You can modify the accompanying .inf file so that PnP Manager assigns an I/O ports range or a memory range to the devices that are associated with this driver to access device registers. However, to successfully access memory mapped registers, you must make additional changes.

MORE INFORMATION

The PortMemoryType member in the device extension (structure LOCAL_DEVICE_INFO that is declared in the Genport.h file) indicates which type of device registers the driver is accessing. A PortMemoryType value of 1 indicates I/O ports. A PortMemoryType value of 0 indicates a memory range.

The PortMemoryType member directs the driver to access the device registers by using the appropriate HAL functions for I/O mapped or memory mapped I/O. This variable is set to 1 during initialization and is never changed. As a result, the driver cannot access any memory range that is assigned.

If the driver is designed to access memory mapped I/O, you must set the PortMemoryType member in the device extension to 0 accordingly. Consider the following scenarios:
  • If the driver is designed to always access memory mapped registers, set PortMemoryType to 0 during initialization.
  • If the driver is designed to access both I/O ports and memory mapped I/O, you must set PortMemoryType dynamically to 0 when the memory range is mapped for a particular device (that is, when the MmMapIoSpace function is called) and then set PortMemoryType to 1 when the memory is unmapped (that is, when the MmUnmapIoSpace function is called).
To assign a memory range to the Portio driver, you must modify its .inf file to include a LogConfig section with a MemConfig directive. The following excerpt includes the relevant part of Genport.inf to include a specific memory range:
[PortIO_Inst.NT]
CopyFiles=PortIO.CopyFiles
LogConfig=MemIO.LC0

[MemIO.LC0]
ConfigPriority=DESIRED
MemConfig=D0000-D03FF
				
To set PortMemoryType to 0 during initialization, replace the assignment to the mentioned variable into the GpdAddDevice function of the Genport.c file as follows:
deviceInfo->PortMemoryType = 0; // was set to 1
				

Modification Type:MinorLast Reviewed:7/22/2004
Keywords:kbinfo kbKMode kbWDM KB323595