Handling an IRP_MN_STOP_DEVICE Request (Windows 2000 and later)

An IRP_MN_STOP_DEVICE request is handled first by the top driver in the device stack and then by each next lower driver. A driver handles stop IRPs in its DispatchPnP routine.

A driver handles an IRP_MN_STOP_DEVICE request with a procedure such as the following:

  1. Ensure that the device is paused.

    If a driver did not completely pause the device in response to the IRP_MN_QUERY_STOP_DEVICE request, it must do so now. Set a HOLD_NEW_REQUESTS flag in the device extension and perform any other necessary operations to pause the device.

    The device might lose power during the resource-rebalance operation and thus might lose device state. Drivers for the device should save any device state information and restore it when they receive the subsequent IRP_MN_START_DEVICE request.

  2. Release the hardware resources for the device.

    In a function driver, the exact operations depend on the device and the driver but can include disconnecting an interrupt with IoDisconnectInterrupt, freeing physical address ranges with MmUnmapIoSpace, and freeing I/O ports.

    If a filter or bus driver acquired any hardware resources for the device, that driver must release the resources in response to an IRP_MN_STOP_DEVICE request.

  3. Set Irp->IoStatus.Status to STATUS_SUCCESS.

  4. Pass the IRP to the next lower driver or complete the IRP.

    • In a function or filter driver, set up the next stack location with IoSkipCurrentIrpStackLocation, pass the IRP to the next lower driver with IoCallDriver, and return the status from IoCallDriver as the return status from the DispatchPnP routine. Do not complete the IRP.

    • In a bus driver, complete the IRP using IoCompleteRequest with IO_NO_INCREMENT and return from the DispatchPnP routine.

While the device is stopped to rebalance resources, a driver cannot start any IRPs that access the device. A driver must queue such IRPs, as described in Holding Incoming IRPs When A Device Is Paused, or fail them if the driver does not implement an IRP-holding queue and must not drop I/O requests.