* @brief Quiesces a set of device drivers from a device class * * Quiesce a device driver from a devclass. This is normally called * automatically by DRIVER_MODULE(). * * If the driver is currently attached to any devices, * devclass_quiesece_driver() will first attempt to quiesce each * device. * * @param dc the devclass to edit * @param driver the driver to unregister */
| 1304 | * @param driver the driver to unregister |
| 1305 | */ |
| 1306 | static int |
| 1307 | devclass_quiesce_driver(devclass_t busclass, driver_t *driver) |
| 1308 | { |
| 1309 | devclass_t dc = devclass_find(driver->name); |
| 1310 | driverlink_t dl; |
| 1311 | device_t dev; |
| 1312 | int i; |
| 1313 | int error; |
| 1314 | |
| 1315 | PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass))); |
| 1316 | |
| 1317 | if (!dc) |
| 1318 | return (0); |
| 1319 | |
| 1320 | /* |
| 1321 | * Find the link structure in the bus' list of drivers. |
| 1322 | */ |
| 1323 | TAILQ_FOREACH(dl, &busclass->drivers, link) { |
| 1324 | if (dl->driver == driver) |
| 1325 | break; |
| 1326 | } |
| 1327 | |
| 1328 | if (!dl) { |
| 1329 | PDEBUG(("%s not found in %s list", driver->name, |
| 1330 | busclass->name)); |
| 1331 | return (ENOENT); |
| 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * Quiesce all devices. We iterate through all the devices in |
| 1336 | * the devclass of the driver and quiesce any which are using |
| 1337 | * the driver and which have a parent in the devclass which we |
| 1338 | * are quiescing. |
| 1339 | * |
| 1340 | * Note that since a driver can be in multiple devclasses, we |
| 1341 | * should not quiesce devices which are not children of |
| 1342 | * devices in the affected devclass. |
| 1343 | */ |
| 1344 | for (i = 0; i < dc->maxunit; i++) { |
| 1345 | if (dc->devices[i]) { |
| 1346 | dev = dc->devices[i]; |
| 1347 | if (dev->driver == driver && dev->parent && |
| 1348 | dev->parent->devclass == busclass) { |
| 1349 | if ((error = device_quiesce(dev)) != 0) |
| 1350 | return (error); |
| 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | return (0); |
| 1356 | } |
| 1357 | |
| 1358 | /** |
| 1359 | * @internal |
no test coverage detected