From 8a0ce01e9200c604139b76b5addc40a3f6e8dd01 Mon Sep 17 00:00:00 2001 From: njl Date: Mon, 4 Apr 2005 15:26:51 +0000 Subject: 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 --- sys/kern/subr_bus.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'sys/kern/subr_bus.c') 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 -- cgit v1.1