Mark i2c slave devices busy while they own the bus.

Many i2c slave drivers are in modules that can be unloaded.  If they detach
while IO is in progress the bus would be hung forever.  Conversely,
lower-layer drivers (iicbus and the hardware driver) also live in modules
and other kinds of bad things happen if they get detached while IO is in
progress.  Because device_busy() propagates up to parents, marking the slave
device busy while it owns the bus solves both kinds of problems that come
with detaching i2c devices while IO is in progress.
This commit is contained in:
Ian Lepore 2019-05-23 14:02:39 +00:00
parent f28ecf2b63
commit 721e81adce
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=348164

View File

@ -128,6 +128,12 @@ iicbus_request_bus(device_t bus, device_t dev, int how)
++sc->owncount;
if (sc->owner == NULL) {
sc->owner = dev;
/*
* Mark the device busy while it owns the bus, to
* prevent detaching the device, bus, or hardware
* controller, until ownership is relinquished.
*/
device_busy(dev);
/*
* Drop the lock around the call to the bus driver, it
* should be allowed to sleep in the IIC_WAIT case.
@ -177,6 +183,7 @@ iicbus_release_bus(device_t bus, device_t dev)
IICBUS_LOCK(sc);
sc->owner = NULL;
wakeup_one(sc);
device_unbusy(dev);
}
IICBUS_UNLOCK(sc);
return (0);