MCPcopy Create free account
hub / github.com/F-Stack/f-stack / devclass_add_driver

Function devclass_add_driver

freebsd/kern/subr_bus.c:1106–1156  ·  view source on GitHub ↗

* @brief Add a device driver to a device class * * Add a device driver to a devclass. This is normally called * automatically by DRIVER_MODULE(). The BUS_DRIVER_ADDED() method of * all devices in the devclass will be called to allow them to attempt * to re-probe any unmatched children. * * @param dc the devclass to edit * @param driver the driver to register */

Source from the content-addressed store, hash-verified

1104 * @param driver the driver to register
1105 */
1106int
1107devclass_add_driver(devclass_t dc, driver_t *driver, int pass, devclass_t *dcp)
1108{
1109 driverlink_t dl;
1110 const char *parentname;
1111
1112 PDEBUG(("%s", DRIVERNAME(driver)));
1113
1114 /* Don't allow invalid pass values. */
1115 if (pass <= BUS_PASS_ROOT)
1116 return (EINVAL);
1117
1118 dl = malloc(sizeof *dl, M_BUS, M_NOWAIT|M_ZERO);
1119 if (!dl)
1120 return (ENOMEM);
1121
1122 /*
1123 * Compile the driver's methods. Also increase the reference count
1124 * so that the class doesn't get freed when the last instance
1125 * goes. This means we can safely use static methods and avoids a
1126 * double-free in devclass_delete_driver.
1127 */
1128 kobj_class_compile((kobj_class_t) driver);
1129
1130 /*
1131 * If the driver has any base classes, make the
1132 * devclass inherit from the devclass of the driver's
1133 * first base class. This will allow the system to
1134 * search for drivers in both devclasses for children
1135 * of a device using this driver.
1136 */
1137 if (driver->baseclasses)
1138 parentname = driver->baseclasses[0]->name;
1139 else
1140 parentname = NULL;
1141 *dcp = devclass_find_internal(driver->name, parentname, TRUE);
1142
1143 dl->driver = driver;
1144 TAILQ_INSERT_TAIL(&dc->drivers, dl, link);
1145 driver->refs++; /* XXX: kobj_mtx */
1146 dl->pass = pass;
1147 driver_register_pass(dl);
1148
1149 if (device_frozen) {
1150 dl->flags |= DL_DEFERRED_PROBE;
1151 } else {
1152 devclass_driver_added(dc, driver);
1153 }
1154 bus_data_generation_update();
1155 return (0);
1156}
1157
1158/**
1159 * @brief Register that a device driver has been deleted from a devclass

Callers 1

driver_module_handlerFunction · 0.85

Calls 6

mallocFunction · 0.85
kobj_class_compileFunction · 0.85
devclass_find_internalFunction · 0.85
driver_register_passFunction · 0.85
devclass_driver_addedFunction · 0.85

Tested by

no test coverage detected