surprise removal sent to non-removable PCI device

I have a PCI device embedded into the system chipset installed on the
motherboard. The motherboard is in a notebook that has a docking station.
The following behavior is observed:

  1. Boot the notebook while docked.
  2. Disable the device in the Device Manager.
  3. The device receives a remove IRP, as usual, the red cross appears upon
    it.
  4. Start->Undock, physically remove the laptop from the dock when the OS
    says it is safe to do.
  5. The OS automatically starts the device, it is now fully functional, the
    red cross disappears.
  6. Dock the notebook.
  7. The device receives a surprise removal IRP, followed by a remove IRP.
  8. In the Device Manager, the red cross appears upon it.

The steps 4…8 can now be repeated multiple times.

I can understand the automatic enable/disable action, since the notebook
appears to have 2 Hardware Profiles, so the OS maintains a separate
enabled/disabled device state in each profile.

What I’m confused with is the surprise removal. It appear that it would be
safer to use the normal remove IRP, given that the device is physically
non-removable. Needless to say, this surprise removal IRP comes as a real
surprise to me (and my driver :slight_smile:

In the “Handling an IRP_MN_SURPRISE_REMOVAL Request” in the DDK, of the four
reasons listed for it, only the following one seems to be vaguely applicable
to my device:

a… The bus is enumerated for another reason and the surprise-removed device
is not included in the list of children. The PnP Manager initiates its
surprise removal operations.

But why would the pci.sys not include my device into the list of children in
this particular case, when the whole device removal seems to be initiated
not by a hardware event at all, but because the “docked” hardware profile
has this device disabled?