Add intermediate states for attaching and detaching that will be
reused by the enhached newbus locking once it is checked in. This change can be easilly MFCed to STABLE_8 at the appropriate moment. Reviewed by: jhb, scottl Tested by: Giovanni Trematerra <giovanni dot trematerra at gmail dot com>
This commit is contained in:
parent
7141ae0d62
commit
ef39f869d5
@ -2625,10 +2625,16 @@ device_attach(device_t dev)
|
||||
{
|
||||
int error;
|
||||
|
||||
if (dev->state >= DS_ATTACHING)
|
||||
return (0);
|
||||
device_sysctl_init(dev);
|
||||
if (!device_is_quiet(dev))
|
||||
device_print_child(dev->parent, dev);
|
||||
dev->state = DS_ATTACHING;
|
||||
if ((error = DEVICE_ATTACH(dev)) != 0) {
|
||||
KASSERT(dev->state == DS_ATTACHING,
|
||||
("%s: %p device state must not been changing", __func__,
|
||||
dev));
|
||||
printf("device_attach: %s%d attach returned %d\n",
|
||||
dev->driver->name, dev->unit, error);
|
||||
/* Unset the class; set in device_probe_child */
|
||||
@ -2639,6 +2645,8 @@ device_attach(device_t dev)
|
||||
dev->state = DS_NOTPRESENT;
|
||||
return (error);
|
||||
}
|
||||
KASSERT(dev->state == DS_ATTACHING,
|
||||
("%s: %p device state must not been changing", __func__, dev));
|
||||
device_sysctl_update(dev);
|
||||
dev->state = DS_ATTACHED;
|
||||
devadded(dev);
|
||||
@ -2674,8 +2682,16 @@ device_detach(device_t dev)
|
||||
if (dev->state != DS_ATTACHED)
|
||||
return (0);
|
||||
|
||||
if ((error = DEVICE_DETACH(dev)) != 0)
|
||||
dev->state = DS_DETACHING;
|
||||
if ((error = DEVICE_DETACH(dev)) != 0) {
|
||||
KASSERT(dev->state == DS_DETACHING,
|
||||
("%s: %p device state must not been changing", __func__,
|
||||
dev));
|
||||
dev->state = DS_ATTACHED;
|
||||
return (error);
|
||||
}
|
||||
KASSERT(dev->state == DS_DETACHING,
|
||||
("%s: %p device state must not been changing", __func__, dev));
|
||||
devremoved(dev);
|
||||
if (!device_is_quiet(dev))
|
||||
device_printf(dev, "detached\n");
|
||||
@ -2730,7 +2746,7 @@ device_quiesce(device_t dev)
|
||||
int
|
||||
device_shutdown(device_t dev)
|
||||
{
|
||||
if (dev->state < DS_ATTACHED)
|
||||
if (dev->state < DS_ATTACHED || dev->state == DS_DETACHING)
|
||||
return (0);
|
||||
return (DEVICE_SHUTDOWN(dev));
|
||||
}
|
||||
|
@ -52,8 +52,11 @@ struct u_businfo {
|
||||
typedef enum device_state {
|
||||
DS_NOTPRESENT, /**< @brief not probed or probe failed */
|
||||
DS_ALIVE, /**< @brief probe succeeded */
|
||||
DS_ATTACHING, /**< @brief attaching is in progress */
|
||||
DS_ATTACHED, /**< @brief attach method called */
|
||||
DS_BUSY /**< @brief device is open */
|
||||
DS_BUSY, /**< @brief device is open */
|
||||
DS_DETACHING /**< @brief detaching is in progress */
|
||||
|
||||
} device_state_t;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user