If your device can operate without a ROM that runs as part of BIOS or UEFI
startup, then you’ll probably already support hot-plug. If you’re using
KMDF, then you’d have to go out of your way to break hot-plug support.
Supporting clean surprise-removal (where the user just yanks out the device
without cleanly requesting that it be ejected) is harder. You have to
design the hardware so that there are no registers where you can’t tell the
difference between the device disappearing and valid reads. Once you’ve
done that, you need to structure your code so that no garbage reads from the
device will cause your code to do unbounded things.
Devices tend to exist along a spectrum, from the simplest device where all
control happens via programmed I/O to registers on the device to a device
where all interaction with the device, after initial setup, happens by
reading and writing work lists in memory, usually through a common buffer.
Initiating I/O then involves setting up a work list and then writing to a
“doorbell” register on the device.
Devices at the simpler end of the spectrum are harder to prove correct in
this respect when the device might disappear between any two instructions in
your driver.
Beyond the hardware considerations, supporting hot-plug well requires that
the upper-edge interface to your driver is well designed. (You don’t say
what it is, and that would narrow the topic considerably.) When your device
is unplugged, there will presumably be handles open to it. The device
instance won’t be removed until all of these handles are closed. Your
client applications need to listen for PnP notifications, or you have to
help them along by pending an IOCTL that gets completed when they should
tear down and close their handles. (The former is general, and works for
all drivers, the latter is less complicated.)
It’s entirely likely that you will eventually encounter a situation where
your device is removed and then reinserted, faster than the teardown for the
first instance can complete. For this period of time, it will be the case
that there are two instances of your driver active for the very same device.
To be sure that this isn’t a problem, you need to stop initiating attempts
to access your device the very moment that you know that it’s gone. And you
absolutely must guarantee that no further hardware access occurs after you
complete IRP_MN_SURPRISE_REMOVAL. As soon as that IRP completes, the PnP
manager may load up the second instance of your driver. You don’t want the
two contending for your device.
Jake Oshins
Windows Kernel Group
This post implies no warranties and confers no rights.
wrote in message news:xxxxx@ntdev…
Hi everyone,
We have a PCIe based device and a WDF based driver that supports the device.
We would like to add hot plug/hot remove capability to the driver.
I was looking for general guide lines on how to add hot plug/remove support
to the driver?
What capabilities KMDF has to support hot plug for PCIe based devices?
Thanks for your help
pada