[PATCH] driver core: Add the ability to bind drivers to devices from userspace

From: Greg KH (gregkh_at_suse.de)
Date: 06/30/05

  • Next message: Greg KH: "[PATCH] driver core: Add the ability to unbind drivers to devices from userspace"
    Date:	Wed, 29 Jun 2005 23:04:22 -0700
    To: linux-kernel@vger.kernel.org
    
    

    [PATCH] driver core: Add the ability to bind drivers to devices from userspace

    This adds a single file, "bind", to the sysfs directory of every driver
    registered with the driver core. To bind a device to a driver, write
    the bus id of the device you wish to bind to that specific driver to the
    "bind" file (remember to not add a trailing \n). If that bus id matches
    a device on that bus, and it does not currently have a driver bound to
    it, the probe sequence will be initiated with that driver and device.

    Note, this requires that the driver itself be willing and able to accept
    that device (usually through a device id type table). This patch does
    not make it possible to override the driver's id table.

    Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

    ---
    commit afdce75f1eaebcf358b7594ba7969aade105c3b0
    tree 5374a0e85e03c8706a1dd95478b9d0a3312917e0
    parent 151ef38f7c0ec1b0420f04438b0316e3a30bf2e4
    author Greg Kroah-Hartman <gregkh@suse.de> Wed, 22 Jun 2005 16:09:05 -0700
    committer Greg Kroah-Hartman <gregkh@suse.de> Wed, 29 Jun 2005 22:48:04 -0700
     drivers/base/base.h |    1 +
     drivers/base/bus.c  |   26 ++++++++++++++++++++++++++
     drivers/base/dd.c   |    2 +-
     3 files changed, 28 insertions(+), 1 deletions(-)
    diff --git a/drivers/base/base.h b/drivers/base/base.h
    --- a/drivers/base/base.h
    +++ b/drivers/base/base.h
    @@ -5,6 +5,7 @@ extern int bus_add_driver(struct device_
     extern void bus_remove_driver(struct device_driver *);
     
     extern void driver_detach(struct device_driver * drv);
    +extern int driver_probe_device(struct device_driver *, struct device *);
     
     static inline struct class_device *to_class_dev(struct kobject *obj)
     {
    diff --git a/drivers/base/bus.c b/drivers/base/bus.c
    --- a/drivers/base/bus.c
    +++ b/drivers/base/bus.c
    @@ -160,6 +160,30 @@ static ssize_t driver_unbind(struct devi
     }
     static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
     
    +/*
    + * Manually attach a device to a driver.
    + * Note: the driver must want to bind to the device,
    + * it is not possible to override the driver's id table.
    + */
    +static ssize_t driver_bind(struct device_driver *drv,
    +			   const char *buf, size_t count)
    +{
    +	struct bus_type *bus = get_bus(drv->bus);
    +	struct device *dev;
    +	int err = -ENODEV;
    +
    +	dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
    +	if ((dev) &&
    +	    (dev->driver == NULL)) {
    +		down(&dev->sem);
    +		err = driver_probe_device(drv, dev);
    +		up(&dev->sem);
    +		put_device(dev);
    +	}
    +	return err;
    +}
    +static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
    +
     
     static struct device * next_device(struct klist_iter * i)
     {
    @@ -425,6 +449,7 @@ int bus_add_driver(struct device_driver 
     
     		driver_add_attrs(bus, drv);
     		driver_create_file(drv, &driver_attr_unbind);
    +		driver_create_file(drv, &driver_attr_bind);
     	}
     	return error;
     }
    @@ -442,6 +467,7 @@ int bus_add_driver(struct device_driver 
     void bus_remove_driver(struct device_driver * drv)
     {
     	if (drv->bus) {
    +		driver_remove_file(drv, &driver_attr_bind);
     		driver_remove_file(drv, &driver_attr_unbind);
     		driver_remove_attrs(drv->bus, drv);
     		klist_remove(&drv->knode_bus);
    diff --git a/drivers/base/dd.c b/drivers/base/dd.c
    --- a/drivers/base/dd.c
    +++ b/drivers/base/dd.c
    @@ -65,7 +65,7 @@ void device_bind_driver(struct device * 
      *
      *	This function must be called with @dev->sem held.
      */
    -static int driver_probe_device(struct device_driver * drv, struct device * dev)
    +int driver_probe_device(struct device_driver * drv, struct device * dev)
     {
     	int ret = 0;
     
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Greg KH: "[PATCH] driver core: Add the ability to unbind drivers to devices from userspace"

    Relevant Pages

    • Re: pci probe
      ... PCI Hotplug is showing up in more places that people ... called for two PCI devices and bind to both of them. ... No, you can specify multiple devices in the same device id table, and ... your driver will get called for all of the matching devices. ...
      (Linux-Kernel)
    • Re: [RFC] bind and unbind drivers from userspace through sysfs
      ... which will detect the kindof device plugged and will load proper driver. ... In bind mode case ... driver should work with given hardware. ... imagine I have a MUX controller (4 AUX ports) and I have standard PS/2 ...
      (Linux-Kernel)
    • Re: [SOLARIS 10][X86] metadb problem
      ... read the "FAQ on the rootnex bind warning ... can wrongly return more cookies than a driver specifies is ... This is a bug ... If it cannot handle that number of cookies, ...
      (comp.unix.solaris)
    • Re: NDIS IM Layering
      ... have their FilterClass specified as failover in their respective INF ... cannot have more than one modifying LWF in the same stack, ... then it will bind to one or the other but not both. ... modifying driver will probably bind as 802.3 above the Microsoft Native ...
      (microsoft.public.development.device.drivers)
    • Re: How does a passthru driver intercept wireless wan network traf
      ... I'm also trying to get the passthru filter to work with wwan. ... in the driver or it might be in hardware. ... passthru driver fails to bind to. ... NdisOpenAdapter would fail, and the passthru driver was not able to ...
      (microsoft.public.windowsce.embedded)