On a PnP system, a device transitions through various PnP states as it is configured, started, possibly stopped to rebalance resources, and possibly removed. This section provides an overview of the PnP device states. The overview is a road map for much of the PnP support required in a driver. Other parts of this documentation describe each state transition in detail.
The following figure shows the PnP states for a device and how a device transitions from one state to another.
Device States from the PnP Perspective
Starting at the top left of the previous figure, a PnP device is physically present in the system because either the user just inserted the device or the device was present at boot time. The device is not yet known to the system software.
To begin software configuration for the device, the PnP Manager and the parent bus driver enumerate the device. The PnP Manager, possibly with help from user-mode components, identifies the drivers for the device, including the function driver and any optional filter drivers. The PnP manager calls the DriverEntry routine of each driver if the driver is not yet loaded. See Adding a PnP Device to a Running System for more information on reporting and enumerating a PnP device.
Once a driver is initialized, it must be ready to initialize its devices. The PnP Manager calls a driver's AddDevice routine for each device the driver controls.
When a driver receives an IRP_MN_START_DEVICE request from the PnP Manager, the driver starts the device and is ready to process I/O requests for the device. See Starting a Device for information on handling an IRP_MN_START_DEVICE request.
If the PnP Manager must reconfigure the hardware resources of an active device, it sends IRP_MN_QUERY_STOP_DEVICE and IRP_MN_STOP_DEVICE requests to the device's drivers. After it reconfigures the hardware resources, the PnP Manager directs the drivers to restart the device by sending an IRP_MN_START_DEVICE request. See Stopping a Device for information on handling stop IRPs. (The drivers for a boot-configured device can receive IRP_MN_QUERY_STOP_DEVICE and IRP_MN_STOP_DEVICE requests before the device has been started, although this step is not shown in the previous figure.)
On Windows 98/Me, the PnP Manager also sends IRP_MN_QUERY_STOP_DEVICE and IRP_MN_STOP_DEVICE requests when a device is being disabled. Drivers on these systems also receive an IRP_MN_STOP_DEVICE request after a failed start.
When a PnP device is being physically removed from the system or has already been removed, the PnP Manager sends various remove IRPs to the device's drivers, directing them to remove the device's software representation (device objects, and so forth). See Removing a Device for information on handling remove IRPs.
At some point after all of a driver's devices have been removed, the PnP Manager calls the drivers Unload routine and unloads the driver.