summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_bus.c
diff options
context:
space:
mode:
authornjl <njl@FreeBSD.org>2005-04-04 15:26:51 +0000
committernjl <njl@FreeBSD.org>2005-04-04 15:26:51 +0000
commit8a0ce01e9200c604139b76b5addc40a3f6e8dd01 (patch)
tree2fd7241d62840a6b94ee90132966b761e27bf097 /sys/kern/subr_bus.c
parentd8b17b2eac0bc6aa7fcc63f8f2aed9016c3a885d (diff)
downloadFreeBSD-src-8a0ce01e9200c604139b76b5addc40a3f6e8dd01.zip
FreeBSD-src-8a0ce01e9200c604139b76b5addc40a3f6e8dd01.tar.gz
Add devclass_get_drivers(9) which provides an array of pointers to driver
instances in a given devclass. This is useful for systems that want to call code in driver static methods, similar to device_identify(). Reviewed by: dfr MFC after: 2 weeks
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r--sys/kern/subr_bus.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 45d1718..16a2609 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -1134,6 +1134,47 @@ devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp)
}
/**
+ * @brief Get a list of drivers in the devclass
+ *
+ * An array containing a list of pointers to all the drivers in the
+ * given devclass is allocated and returned in @p *listp. The number
+ * of drivers in the array is returned in @p *countp. The caller should
+ * free the array using @c free(p, M_TEMP).
+ *
+ * @param dc the devclass to examine
+ * @param listp gives location for array pointer return value
+ * @param countp gives location for number of array elements
+ * return value
+ *
+ * @retval 0 success
+ * @retval ENOMEM the array allocation failed
+ */
+int
+devclass_get_drivers(devclass_t dc, driver_t ***listp, int *countp)
+{
+ driverlink_t dl;
+ driver_t **list;
+ int count;
+
+ count = 0;
+ TAILQ_FOREACH(dl, &dc->drivers, link)
+ count++;
+ list = malloc(count * sizeof(driver_t *), M_TEMP, M_NOWAIT);
+ if (list == NULL)
+ return (ENOMEM);
+
+ count = 0;
+ TAILQ_FOREACH(dl, &dc->drivers, link) {
+ list[count] = dl->driver;
+ count++;
+ }
+ *listp = list;
+ *countp = count;
+
+ return (0);
+}
+
+/**
* @brief Get the number of devices in a devclass
*
* @param dc the devclass to examine
OpenPOWER on IntegriCloud