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:
Attilio Rao 2009-09-03 13:40:41 +00:00
parent 19dbe46d28
commit 80002a63db
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=196779
2 changed files with 22 additions and 3 deletions

View File

@ -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));
}

View File

@ -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;
/**