ScsiPortGetDeviceBase

PVOID ScsiPortGetDeviceBase(HwDeviceExtension, BusType, SystemIoBusNumber,
    IoAddress, NumberOfBytes, InIoSpace)
IN PVOID  HwDeviceExtension;
IN INTERFACE_TYPE  BusType;
IN ULONG  SystemIoBusNumber;
IN SCSI_PHYSICAL_ADDRESS  IoAddress;
IN ULONG  NumberOfBytes;
IN BOOLEAN  InIoSpace;
 

Returns a mapped system address that must be used to adjust device address ranges in that HBA's ACCESS_RANGE elements.

HwDeviceExtension
Points to the HBA miniport driver's storage for adapter data.
BusType
Specifies the type of bus, such as ISA or MCA. This value can be retrieved from the PORT_CONFIGURATION_INFORMATION structure.
SystemIoBusNumber
Specifies on which bus the HBA is connected. This value can be retrieved from the PORT_CONFIGURATION_INFORMATION structure.
IoAddress
Specifies the starting physical base address for the HBA.
NumberOfBytes
Specifies the range, in bytes, that the mapping covers. The driver must not access the hardware outside of this range.
InIoSpace
Specifies whether the address is in I/O space; otherwise, it is in memory space.

ScsiPortGetDeviceBase can be called only from an HBA miniport driver's HwFindAdapter routine. Calls from other HBA miniport driver routines result in system failure or in an incorrect operation. ScsiPortGetDeviceBase can be called several times.

Windows NT machines can have several I/O buses, or the system can map I/O space to memory. In order to make HBA miniport drivers portable, the addresses they use must be translated. The returned base address should be added to all references made to the hardware. Driver writers should make no assumptions about how many bits are used in the returned base address.

The following KB article describes a bug in the ScsiPortGetDeviceBase function which appears when you attempt to do memory mapped I/O: Q169584, BUG: Win95: ScsiPortGetDeviceBase Does Not Return Linear Address.

Note that the problem described won't happen if you use I/O mapping.

This problem does not frequently appear because most SCSI cards (at least PCI cards) have both a memory window and an I/O window. SCSIPORT.PDR will always default to the I/O window in these cases, thus avoiding use of the memory window.

When you call ScsiPortGetDeviceBase, you should check the returned address against the actual physical address. If they are the same, you need to call _MapPhysToLinear to obtain a linear address; otherwise, assume that the bug has been corrected. This is to accommodate any future bug fix. Note that _MapPhysToLinear call "breaks" NT miniport compatibility. If you want NT compatibility, you need to do conditional compilation, resulting in a different binary miniport for NT.

In order to incorporate _MapPhysToLinear into your miniport, you will need to include the DDK's "vxd wrappers": Setup your code as described below (See also Walt Oney's book, Systems Programming for Windows 95, page 131):

#define WANTVXDWRAPS
#include <vmm.h>
#include <vxdwraps.h>.
 

See Also

HwFindAdapter, ScsiPortFreeDeviceBase