Page MenuHomeFreeBSD

D47673.id146700.diff
No OneTemporary

D47673.id146700.diff

diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -3402,6 +3402,22 @@
*/
int
bus_generic_probe(device_t dev)
+{
+ bus_identify_children(dev);
+ return (0);
+}
+
+/**
+ * @brief Ask drivers to add child devices of the given device.
+ *
+ * This function allows drivers for child devices of a bus to identify
+ * child devices and add them as children of the given device. NB:
+ * The driver for @param dev must implement the BUS_ADD_CHILD method.
+ *
+ * @param dev the parent device
+ */
+void
+bus_identify_children(device_t dev)
{
devclass_t dc = dev->devclass;
driverlink_t dl;
@@ -3420,8 +3436,6 @@
continue;
DEVICE_IDENTIFY(dl->driver, dev);
}
-
- return (0);
}
/**
@@ -3433,14 +3447,29 @@
*/
int
bus_generic_attach(device_t dev)
+{
+ bus_attach_children(dev);
+ return (0);
+}
+
+/**
+ * @brief Probe and attach all children of the given device
+ *
+ * This function attempts to attach a device driver to each unattached
+ * child of the given device using device_probe_and_attach(). If an
+ * individual child fails to attach this function continues attaching
+ * other children.
+ *
+ * @param dev the parent device
+ */
+void
+bus_attach_children(device_t dev)
{
device_t child;
TAILQ_FOREACH(child, &dev->children, link) {
device_probe_and_attach(child);
}
-
- return (0);
}
/**
@@ -3454,7 +3483,7 @@
bus_delayed_attach_children(device_t dev)
{
/* Probe and attach the bus children when interrupts are available */
- config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
+ config_intrhook_oneshot((ich_func_t)bus_attach_children, dev);
return (0);
}
@@ -3468,6 +3497,32 @@
*/
int
bus_generic_detach(device_t dev)
+{
+ int error;
+
+ error = bus_detach_children(dev);
+ if (error != 0)
+ return (error);
+
+ return (0);
+}
+
+/**
+ * @brief Detach drivers from all children of a device
+ *
+ * This function attempts to detach a device driver from each attached
+ * child of the given device using device_detach(). If an individual
+ * child fails to detach this function stops and returns an error.
+ * NB: Children that were successfully detached are not re-attached if
+ * an error occurs.
+ *
+ * @param dev the parent device
+ *
+ * @retval 0 success
+ * @retval non-zero a device would not detach
+ */
+int
+bus_detach_children(device_t dev)
{
device_t child;
int error;
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -591,8 +591,12 @@
int bus_child_present(device_t child);
int bus_child_pnpinfo(device_t child, struct sbuf *sb);
int bus_child_location(device_t child, struct sbuf *sb);
+
+void bus_attach_children(device_t dev);
+int bus_detach_children(device_t dev);
void bus_enumerate_hinted_children(device_t bus);
int bus_delayed_attach_children(device_t bus);
+void bus_identify_children(device_t dev);
static __inline struct resource *
bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 21, 3:48 AM (14 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14746070
Default Alt Text
D47673.id146700.diff (2 KB)

Event Timeline