16.8.3 Claiming Hardware Resources

When a device driver’s ConfigCallback routine returns, its DriverEntry routine can use the configuration information collected from its subkeys under \Registry\Machine\Hardware\Description, from calls to HalGetBusData or HalGetBusDataByOffset, and/or from its Parameters subkey(s) under \Registry\Machine\System\CurrentControlSet\Services\DriverName in calls to one or more of HalTranslateBusAddress, HalGetInterruptVector, and HalGetAdapter. The driver can use the values returned by these HAL support routines as parameters to “higher-level” NT routines such as MmMapIoSpace, IoConnectInterrupt, HalAllocateCommonBuffer, and, after initialization IoAllocateAdapterChannel.

When an NT device driver has set up any NT objects that it needs, such as device objects, but before the driver attempts to access its device(s) registers or I/O ports, the DriverEntry routine must call one of the following support routines one or more times to write configuration information about the hardware resources the driver and its device(s) will be using into the registry:

A successful call to IoReportResourceUsage, IoAssignResources, or HalAssignSlotResources claims a set of hardware resources for the caller in the \Registry\Machine\Hardware\ResourceMap tree. Making such a call prevents device drivers that load later from trying to use the hardware resources already claimed by a loaded driver.

    NT device driver writers should consider the following fact about calls to IoReportResourceUsage, IoAssignResources, or HalAssignSlotResources:

A subsequent call to any of the preceding support routines to claim resources for the same device(s) overwrites the existing resource claims for the driver or for the particular device in the registry ResourceMap.

Any NT device driver can call one or more of these routines more than once to claim resources for itself or for a particular device. If it does, the caller cannot attempt to claim a single resource at a time, assuming that its previously claimed resources remain claimed. Instead, such a caller must augment the list of claimed resources for the driver or for any particular device at each call to these support routines.