FreeBSD/sys/kern/subr_bus.c
/**
 * @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
 */
@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
@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
int
devclass_add_driver(devclass_t dc, driver_t *driver, int pass, devclass_t *dcp)
{
	driverlink_t dl;
	const char *parentname;
	PDEBUG(("%s", DRIVERNAME(driver)));
	if (pass <= BUS_PASS_ROOT)
		return (EINVAL);
	dl = malloc(sizeof *dl, M_BUS, M_NOWAIT|M_ZERO);
	if (!dl)
		return (ENOMEM);
	kobj_class_compile((kobj_class_t) driver);
	if (driver->baseclasses)
		parentname = driver->baseclasses[0]->name;
	else
		parentname = NULL;
	*dcp = devclass_find_internal(driver->name, parentname, TRUE);
	dl->driver = driver;
	TAILQ_INSERT_TAIL(&dc->drivers, dl, link);
	driver->refs++;		
	dl->pass = pass;
	driver_register_pass(dl);
	devclass_driver_added(dc, driver);
	bus_data_generation_update();
	return (0);
}
int devclass_add_driver ( devclass_t dc , driver_t * driver , int pass , devclass_t * dcp ) { driverlink_t dl ; const char * parentname ; PDEBUG ( ( " " , DRIVERNAME ( driver ) ) ) ; if ( pass <= BUS_PASS_ROOT ) return ( EINVAL ) ; dl = malloc ( sizeof * dl , M_BUS , M_NOWAIT | M_ZERO ) ; if ( ! dl ) return ( ENOMEM ) ; kobj_class_compile ( ( kobj_class_t ) driver ) ; if ( driver -> baseclasses ) parentname = driver -> baseclasses [ 0 ] -> name ; else parentname = NULL ; * dcp = devclass_find_internal ( driver -> name , parentname , TRUE ) ; dl -> driver = driver ; TAILQ_INSERT_TAIL ( & dc -> drivers , dl , link ) ; driver -> refs ++ ; dl -> pass = pass ; driver_register_pass ( dl ) ; devclass_driver_added ( dc , driver ) ; bus_data_generation_update ( ) ; return ( 0 ) ; }
@brief Add a device driver to a device class
 Add a device driver to a devclass.
@brief Add a device driver to a device class Add a device driver to a devclass .
/* Don't allow invalid pass values. */ /*
	 * Compile the driver's methods. Also increase the reference count
	 * so that the class doesn't get freed when the last instance
	 * goes. This means we can safely use static methods and avoids a
	 * double-free in devclass_delete_driver.
	 */ /*
	 * If the driver has any base classes, make the
	 * devclass inherit from the devclass of the driver's
	 * first base class. This will allow the system to
	 * search for drivers in both devclasses for children
	 * of a device using this driver.
	 */ /* XXX: kobj_mtx */