1. Callbacks for Power-Up and Power-Down
Drivers implement the EvtDeviceDOEntry and EvtDeviceDOExit callbacks to be notified when the device enters and exits the working state, respectively.
In a function driver (FDO), KMDF calls the EvtDeviceDOEntry callback after the device has entered the DO power state. The function driver’s EvtDeviceDOEntry
callback should initialize the device and perform any other tasks that
are required each time the device enters the working state.
In a bus driver (PDO), KMDF calls the EvtDeviceDOEntry callback to put the device into the DO
power state. (If you are familiar with WDM drivers, you probably
remember that a request to power up a device must be handled by the bus
driver first and then other drivers higher in the device stack. For a
request to lower the power state, the opposite is true.) A bus driver’s
EvtDeviceDOEntry callback should put the device hardware in the DO state and perform any additional initialization that the device requires at this time.
The EvtDeviceDOEntry callback is called with a pointer to the WDFDEVICE object and a pointer to an enumerator that identifies the most recent power state of the device, before the transition to DO began.
KMDF calls the EvtDeviceDOExit callback any time the device must leave the DO state. The callback is passed a pointer to the WDFDEVICE
object and a pointer to an enumerator that identifies the new power
state. In a function driver (FDO), the callback should perform any
final tasks that are required before the device changes power state. In
a bus driver, the callback should change the power state of the
physical hardware.
In the Featured Toaster sample, both of these functions are stubs.
2. Callback for Wake Signal Support
Drivers for devices that can generate wake signals implement the following callbacks to support wake-up:
EvtDeviceArmWakeFromSO and EvtDeviceDisarmWakeFromSO
EvtDeviceWakeFromSOTriggered
EvtDeviceArmWakeFromSx and EvtDeviceDisarmWakeFromSx
EvtDeviceWakeFromSxTriggered
To enable the wake signal, KMDF calls EvtDeviceArmWakeFromSO and EvtDeviceArmWakeFromSx while the device is in DO,
but while power-managed I/O is stopped. Therefore, the driver does not
receive I/O requests from power-managed queues while arming its device
and so is not required to synchronize its I/O operations with these
callbacks.
In the wake-arming callbacks, a function driver
should handle any device-specific tasks that are required to enable the
device to generate a wake signal. KMDF transitions the device out of
the DO state soon after the wake
signal is successfully enabled. The driver should not yet perform any
tasks related to power state change; KMDF calls the driver’s EvtDeviceDOExit function to do that.
The EvtDeviceDisarmWakeFromSO and EvtDeviceDisarmWakeFromSx
callbacks should undo any device-specific tasks that the driver
performed to enable the wake signal for its device. KMDF calls the
disarm callbacks after EvtDeviceDOEntry has returned the device to the DO state.
The Featured Toaster sample registers the ToasterEvtDeviceWakeArm function for both the EvtDeviceArmWakeFromSO and EvtDeviceArmWakeFromSx events. Likewise, it registers ToasterEvtDeviceWakeDisarm for both the EvtDeviceDisarmWakeFromSO and EvtDeviceDisarmWakeFromSx events.
In the Featured Toasted sample, these callbacks are stubs.
If the device triggers a wake signal when the system is in SO or Sx, the EvtDeviceWakeFromSOTriggered and EvtDeviceWakeFromSxTriggered events occur, respectively. KMDF calls these functions after the driver’s EvtDeviceDOEntry callback and before the EvtDeviceDisarmWakeFromSO or EvtDeviceDisarmWakeFromSx
callback. The wake-triggered callback should perform any tasks that are
required after the wake signal is triggered, but should not disarm the
wake signal.
The Featured Toaster sample registers the ToasterEvtDeviceWakeTriggered callback for both the EvtDeviceWakeFromSOTriggered and EvtDeviceWakeFromSxTriggered events. In the sample, this callback is a stub.