Implemented device_detach(), and bus_generic_detach() - both are needed by

the updated mii code on destruction.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23032 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-11-30 18:50:40 +00:00
parent debb1200cc
commit 82edabb115
3 changed files with 42 additions and 9 deletions

View File

@ -378,14 +378,6 @@ bus_get_dma_tag(device_t dev)
}
int
bus_generic_detach(device_t dev)
{
UNIMPLEMENTED();
return B_ERROR;
}
int
bus_generic_suspend(device_t dev)
{

View File

@ -329,9 +329,11 @@ device_delete_child(device_t parent, device_t child)
if ((atomic_and(&parent->flags, ~DEVICE_ATTACHED) & DEVICE_ATTACHED) != 0
&& parent->methods.detach != NULL) {
int status = parent->methods.detach(parent);
if (status != 0)
if (status != 0) {
atomic_or(&parent->flags, DEVICE_ATTACHED);
return status;
}
}
if (parent->flags & DEVICE_DESC_ALLOCED)
free((char *)parent->description);
@ -365,6 +367,24 @@ device_attach(device_t device)
}
int
device_detach(device_t device)
{
if (device->driver == NULL)
return B_ERROR;
if ((atomic_and(&device->flags, ~DEVICE_ATTACHED) & DEVICE_ATTACHED) != 0) {
int result = device->methods.detach(device);
if (result != 0) {
atomic_or(&device->flags, DEVICE_ATTACHED);
return result;
}
}
return 0;
}
int
bus_generic_attach(device_t dev)
{
@ -394,6 +414,26 @@ bus_generic_attach(device_t dev)
}
int
bus_generic_detach(device_t device)
{
device_t child = NULL;
if ((device->flags & DEVICE_ATTACHED) == 0)
return B_ERROR;
while (true) {
child = list_get_next_item(&device->children, child);
if (child == NULL)
break;
device_detach(child);
}
return 0;
}
// #pragma mark - Misc, Malloc

View File

@ -144,6 +144,7 @@ device_t device_add_child(device_t dev, const char *name, int unit);
int device_delete_child(device_t dev, device_t child);
int device_is_attached(device_t dev);
int device_attach(device_t dev);
int device_detach(device_t dev);
int bus_generic_print_child(device_t dev, device_t child);
void bus_generic_driver_added(device_t dev, driver_t *driver);
int bus_generic_attach(device_t dev);