The PoRegisterDeviceForIdleDetection routine enables or cancels idle detection and sets idle time-out values for a device.
PULONG
PoRegisterDeviceForIdleDetection(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG ConservationIdleTime,
IN ULONG PerformanceIdleTime,
IN DEVICE_POWER_STATE State
);
PoRegisterDeviceForIdleDetection returns a pointer to the idle counter to indicate that idle detection has been enabled. It returns NULL to indicate that idle detection has been disabled, that an idle counter could not be allocated, or that one or both of the time-out values were invalid.
Declared in wdm.h and ntddk.h. Include ntddk.h or wdm.h.
PoRegisterDeviceForIdleDetection enables drivers to use the idle detection mechanism provided by the Power Manager. Drivers call PoRegisterDeviceForIdleDetection for any of the following reasons:
After enabling a device for idle detection, a driver calls PoSetDeviceBusy whenever the device is in use, passing the non-NULL idle pointer returned by PoRegisterDeviceForIdleDetection. Calling PoSetDeviceBusy restarts the idle countdown. Note that a driver must not pass a NULL pointer to PoSetDeviceBusy.
Whenever the device satisfies the current idle time-out value, the Power Manager sends an IRP_MN_SET_POWER request to the top of the device stack, specifying device power state State. In response to the IRP, each driver performs any device-specific tasks required before the power state transition, then passes the IRP to the next-lower driver. When the IRP reaches the bus driver, that driver puts the device in the requested lower power state and completes the IRP.
PoRegisterDeviceForIdleDetection sets time-out values for both conservation and performance. The ConservationIdleTime value applies when the system power policy optimizes for conservation; the PerformanceIdleTime value applies when the system power policy optimizes for performance. Typically, the applicable policy depends upon the power source: when running with AC power, the system optimizes for performance, and when running off a battery, the system optimizes for conservation. Certain devices can specify time-out values of -1 to use the standard power policy time-outs for their device class. The standard time-out values provide for better system integration for supported standard device classes. At present, WDM supports this feature for devices of type FILE_DEVICE_DISK and FILE_DEVICE_MASS_STORAGE. PoRegisterDeviceForIdleDetection returns NULL if -1 is specified for a device of an unsupported type. (For information about device types, see Specifying Device Types.)
Only one idle detection can be set per device. Subsequent calls to PoRegisterDeviceForIdleDetection change the idle detection values.
If both ConservationIdleTime and PerformanceIdleTime are zero, this routine cancels all idle detection for the device and returns NULL.
PoRegisterDeviceForIdleDetection can free a driver from the need to perform its own idle detection. However, drivers can also implement their own idle detection.
Callers of PoRegisterDeviceForIdleDetection must be running at IRQL < DISPATCH_LEVEL.