* [PATCH] driver core: Add the ability to bind drivers to devices from userspace
2005-06-24 5:14 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
@ 2005-06-24 5:15 ` Greg KH
0 siblings, 0 replies; 17+ messages in thread
From: Greg KH @ 2005-06-24 5:15 UTC (permalink / raw)
To: linux-kernel; +Cc: Patrick Mochel
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>
---
drivers/base/base.h | 1 +
drivers/base/bus.c | 36 ++++++++++++++++++++++++++++++++++++
drivers/base/dd.c | 2 +-
3 files changed, 38 insertions(+), 1 deletion(-)
--- gregkh-2.6.orig/drivers/base/bus.c 2005-06-22 23:21:11.000000000 -0700
+++ gregkh-2.6/drivers/base/bus.c 2005-06-22 23:23:19.000000000 -0700
@@ -133,6 +133,40 @@
decl_subsys(bus, &ktype_bus, NULL);
+/*
+ * 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 int driver_bind_helper(struct device *dev, void *data)
+{
+ const char *name = data;
+
+ if ((dev->driver == NULL) &&
+ (strcmp(name, dev->bus_id) == 0))
+ return 1;
+ return 0;
+}
+
+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_bind_helper);
+ if (dev) {
+ 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)
{
struct klist_node * n = klist_next(i);
@@ -396,6 +430,7 @@
module_add_driver(drv->owner, drv);
driver_add_attrs(bus, drv);
+ driver_create_file(drv, &driver_attr_bind);
}
return error;
}
@@ -413,6 +448,7 @@
void bus_remove_driver(struct device_driver * drv)
{
if (drv->bus) {
+ driver_remove_file(drv, &driver_attr_bind);
driver_remove_attrs(drv->bus, drv);
klist_remove(&drv->knode_bus);
pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
--- gregkh-2.6.orig/drivers/base/base.h 2005-06-22 23:20:58.000000000 -0700
+++ gregkh-2.6/drivers/base/base.h 2005-06-22 23:21:14.000000000 -0700
@@ -5,6 +5,7 @@
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)
{
--- gregkh-2.6.orig/drivers/base/dd.c 2005-06-22 23:21:13.000000000 -0700
+++ gregkh-2.6/drivers/base/dd.c 2005-06-22 23:21:14.000000000 -0700
@@ -75,7 +75,7 @@
*
* 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;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [GIT PATCH] Driver core patches for 2.6.13-rc1
@ 2005-06-30 6:02 Greg KH
2005-06-30 6:04 ` [PATCH] driver core: add bus_find_device & driver_find_device functions Greg KH
` (2 more replies)
0 siblings, 3 replies; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:02 UTC (permalink / raw)
To: Linus Torvalds, Andrew Morton; +Cc: linux-kernel
Here are some small patches for the driver core. They fix a bug that
has caused some people to see deadlocks when some drivers are unloaded
(like ieee1394), and add the ability to bind and unbind drivers from
devices from userspace (something that people have been asking for for a
long time.)
Please pull from:
rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
or if master.kernel.org hasn't synced up yet:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
thanks,
greg k-h
drivers/base/base.h | 1
drivers/base/bus.c | 117 +++++++++++++++++++++++++++++++++++++++++--------
drivers/base/core.c | 2
drivers/base/dd.c | 2
drivers/base/driver.c | 35 ++++++++++++++
include/linux/device.h | 7 ++
6 files changed, 143 insertions(+), 21 deletions(-)
--------------------
Cornelia Huck:
driver core: add bus_find_device & driver_find_device functions
Greg Kroah-Hartman:
driver core: Add the ability to bind drivers to devices from userspace
driver core: change bus_rescan_devices to return void
driver core: Add the ability to unbind drivers to devices from userspace
Patrick Mochel:
Driver core: Use klist_del() instead of klist_remove().
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] driver core: add bus_find_device & driver_find_device functions
2005-06-30 6:02 [GIT PATCH] Driver core patches for 2.6.13-rc1 Greg KH
@ 2005-06-30 6:04 ` Greg KH
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
2005-06-30 6:19 ` [GIT PATCH] Driver core patches for 2.6.13-rc1 Dmitry Torokhov
2005-06-30 17:22 ` John Lenz
2 siblings, 1 reply; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:04 UTC (permalink / raw)
To: linux-kernel; +Cc: cohuck
[PATCH] driver core: add bus_find_device & driver_find_device functions
Add bus_find_device() and driver_find_device() which allow searching for a
device in the bus's resp. the driver's klist and obtain a reference on it.
Signed-off-by: Cornelia Huck <cohuck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
commit 0edb586049e57c56e625536476931117a57671e9
tree 9d92bb9821d134d199d62de1ff3096ff2b73fdc7
parent fd782a4a99d2d3e818b9465c427b10f7f027d7da
author Cornelia Huck <cohuck@de.ibm.com> Wed, 22 Jun 2005 16:59:51 +0200
committer Greg Kroah-Hartman <gregkh@suse.de> Wed, 29 Jun 2005 22:48:03 -0700
drivers/base/bus.c | 34 ++++++++++++++++++++++++++++++++++
drivers/base/driver.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/device.h | 5 +++++
3 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -177,6 +177,39 @@ int bus_for_each_dev(struct bus_type * b
return error;
}
+/**
+ * bus_find_device - device iterator for locating a particular device.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @data: Data to pass to match function
+ * @match: Callback function to check device
+ *
+ * This is similar to the bus_for_each_dev() function above, but it
+ * returns a reference to a device that is 'found' for later use, as
+ * determined by the @match callback.
+ *
+ * The callback should return 0 if the device doesn't match and non-zero
+ * if it does. If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more devices.
+ */
+struct device * bus_find_device(struct bus_type *bus,
+ struct device *start, void *data,
+ int (*match)(struct device *, void *))
+{
+ struct klist_iter i;
+ struct device *dev;
+
+ if (!bus)
+ return NULL;
+
+ klist_iter_init_node(&bus->klist_devices, &i,
+ (start ? &start->knode_bus : NULL));
+ while ((dev = next_device(&i)))
+ if (match(dev, data) && get_device(dev))
+ break;
+ klist_iter_exit(&i);
+ return dev;
+}
static struct device_driver * next_driver(struct klist_iter * i)
@@ -557,6 +590,7 @@ int __init buses_init(void)
EXPORT_SYMBOL_GPL(bus_for_each_dev);
+EXPORT_SYMBOL_GPL(bus_find_device);
EXPORT_SYMBOL_GPL(bus_for_each_drv);
EXPORT_SYMBOL_GPL(bus_add_device);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -56,6 +56,41 @@ EXPORT_SYMBOL_GPL(driver_for_each_device
/**
+ * driver_find_device - device iterator for locating a particular device.
+ * @driver: The device's driver
+ * @start: Device to begin with
+ * @data: Data to pass to match function
+ * @match: Callback function to check device
+ *
+ * This is similar to the driver_for_each_device() function above, but
+ * it returns a reference to a device that is 'found' for later use, as
+ * determined by the @match callback.
+ *
+ * The callback should return 0 if the device doesn't match and non-zero
+ * if it does. If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more devices.
+ */
+struct device * driver_find_device(struct device_driver *drv,
+ struct device * start, void * data,
+ int (*match)(struct device *, void *))
+{
+ struct klist_iter i;
+ struct device *dev;
+
+ if (!drv)
+ return NULL;
+
+ klist_iter_init_node(&drv->klist_devices, &i,
+ (start ? &start->knode_driver : NULL));
+ while ((dev = next_device(&i)))
+ if (match(dev, data) && get_device(dev))
+ break;
+ klist_iter_exit(&i);
+ return dev;
+}
+EXPORT_SYMBOL_GPL(driver_find_device);
+
+/**
* driver_create_file - create sysfs file for driver.
* @drv: driver.
* @attr: driver attribute descriptor.
diff --git a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -80,6 +80,8 @@ extern struct bus_type * find_bus(char *
int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
int (*fn)(struct device *, void *));
+struct device * bus_find_device(struct bus_type *bus, struct device *start,
+ void *data, int (*match)(struct device *, void *));
int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
void * data, int (*fn)(struct device_driver *, void *));
@@ -142,6 +144,9 @@ extern void driver_remove_file(struct de
extern int driver_for_each_device(struct device_driver * drv, struct device * start,
void * data, int (*fn)(struct device *, void *));
+struct device * driver_find_device(struct device_driver *drv,
+ struct device *start, void *data,
+ int (*match)(struct device *, void *));
/*
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] driver core: Add the ability to unbind drivers to devices from userspace
2005-06-30 6:04 ` [PATCH] driver core: add bus_find_device & driver_find_device functions Greg KH
@ 2005-06-30 6:04 ` Greg KH
2005-06-30 6:04 ` [PATCH] driver core: change bus_rescan_devices to return void Greg KH
2005-06-30 6:25 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Dmitry Torokhov
0 siblings, 2 replies; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:04 UTC (permalink / raw)
To: linux-kernel; +Cc: gregkh
[PATCH] driver core: Add the ability to unbind drivers to devices from userspace
This adds a single file, "unbind", to the sysfs directory of every
device that is currently bound to a driver. To unbind the driver from
the device, write anything to this file and they will be disconnected
from each other.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
commit 151ef38f7c0ec1b0420f04438b0316e3a30bf2e4
tree 3aa6504e12c08f70cacb7f9de6ef5858b45ee86d
parent 0edb586049e57c56e625536476931117a57671e9
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/bus.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -133,6 +133,34 @@ static struct kobj_type ktype_bus = {
decl_subsys(bus, &ktype_bus, NULL);
+/* Manually detach a device from it's associated driver. */
+static int driver_helper(struct device *dev, void *data)
+{
+ const char *name = data;
+
+ if (strcmp(name, dev->bus_id) == 0)
+ return 1;
+ return 0;
+}
+
+static ssize_t driver_unbind(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 == drv)) {
+ device_release_driver(dev);
+ err = count;
+ }
+ return err;
+}
+static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
+
+
static struct device * next_device(struct klist_iter * i)
{
struct klist_node * n = klist_next(i);
@@ -396,6 +424,7 @@ int bus_add_driver(struct device_driver
module_add_driver(drv->owner, drv);
driver_add_attrs(bus, drv);
+ driver_create_file(drv, &driver_attr_unbind);
}
return error;
}
@@ -413,6 +442,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_unbind);
driver_remove_attrs(drv->bus, drv);
klist_remove(&drv->knode_bus);
pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] driver core: change bus_rescan_devices to return void
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
@ 2005-06-30 6:04 ` Greg KH
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to bind drivers to devices from userspace Greg KH
2005-06-30 6:25 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Dmitry Torokhov
1 sibling, 1 reply; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:04 UTC (permalink / raw)
To: linux-kernel; +Cc: gregkh
[PATCH] driver core: change bus_rescan_devices to return void
No one was looking at the return value of bus_rescan_devices, and it
really wasn't anything that anyone in the kernel would ever care about.
So change it which enabled some counting code to be removed also.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
commit 23d3d602cb96addd3c1158424fb01a49ea5e81b1
tree 2daa85579c964bfe3d1a91fe365d202b8f38422b
parent afdce75f1eaebcf358b7594ba7969aade105c3b0
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/bus.c | 27 +++++++++------------------
include/linux/device.h | 2 +-
2 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -483,31 +483,22 @@ void bus_remove_driver(struct device_dri
/* Helper for bus_rescan_devices's iter */
static int bus_rescan_devices_helper(struct device *dev, void *data)
{
- int *count = data;
-
- if (!dev->driver && (device_attach(dev) > 0))
- (*count)++;
-
+ if (!dev->driver)
+ device_attach(dev);
return 0;
}
-
/**
- * bus_rescan_devices - rescan devices on the bus for possible drivers
- * @bus: the bus to scan.
+ * bus_rescan_devices - rescan devices on the bus for possible drivers
+ * @bus: the bus to scan.
*
- * This function will look for devices on the bus with no driver
- * attached and rescan it against existing drivers to see if it
- * matches any. Calls device_attach(). Returns the number of devices
- * that were sucessfully bound to a driver.
+ * This function will look for devices on the bus with no driver
+ * attached and rescan it against existing drivers to see if it matches
+ * any by calling device_attach() for the unbound devices.
*/
-int bus_rescan_devices(struct bus_type * bus)
+void bus_rescan_devices(struct bus_type * bus)
{
- int count = 0;
-
- bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
-
- return count;
+ bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
}
diff --git a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -69,7 +69,7 @@ struct bus_type {
extern int bus_register(struct bus_type * bus);
extern void bus_unregister(struct bus_type * bus);
-extern int bus_rescan_devices(struct bus_type * bus);
+extern void bus_rescan_devices(struct bus_type * bus);
extern struct bus_type * get_bus(struct bus_type * bus);
extern void put_bus(struct bus_type * bus);
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] driver core: Add the ability to bind drivers to devices from userspace
2005-06-30 6:04 ` [PATCH] driver core: change bus_rescan_devices to return void Greg KH
@ 2005-06-30 6:04 ` Greg KH
2005-06-30 6:04 ` [PATCH] Driver core: Use klist_del() instead of klist_remove() Greg KH
0 siblings, 1 reply; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:04 UTC (permalink / raw)
To: linux-kernel; +Cc: gregkh
[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;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] Driver core: Use klist_del() instead of klist_remove().
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to bind drivers to devices from userspace Greg KH
@ 2005-06-30 6:04 ` Greg KH
0 siblings, 0 replies; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:04 UTC (permalink / raw)
To: linux-kernel; +Cc: mochel
[PATCH] Driver core: Use klist_del() instead of klist_remove().
Use klist_del() instead of klist_remove() when unregistering devices.
This will prevent a deadlock when executing a recursive unregister using
device_for_each_child().
Signed-off-by Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
commit d62c0f9fd2d3943a3eca85b490d86e1605000ccb
tree c9fc174992f7746f680becdeaa1bdb6924108c0f
parent 23d3d602cb96addd3c1158424fb01a49ea5e81b1
author Patrick Mochel <mochel@digitalimplant.org> Fri, 24 Jun 2005 08:39:33 -0700
committer Greg Kroah-Hartman <gregkh@suse.de> Wed, 29 Jun 2005 22:48:05 -0700
drivers/base/core.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -333,7 +333,7 @@ void device_del(struct device * dev)
struct device * parent = dev->parent;
if (parent)
- klist_remove(&dev->knode_parent);
+ klist_del(&dev->knode_parent);
/* Notify the platform of the removal, in case they
* need to do anything...
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GIT PATCH] Driver core patches for 2.6.13-rc1
2005-06-30 6:02 [GIT PATCH] Driver core patches for 2.6.13-rc1 Greg KH
2005-06-30 6:04 ` [PATCH] driver core: add bus_find_device & driver_find_device functions Greg KH
@ 2005-06-30 6:19 ` Dmitry Torokhov
2005-06-30 6:27 ` Greg KH
2005-06-30 17:22 ` John Lenz
2 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2005-06-30 6:19 UTC (permalink / raw)
To: linux-kernel; +Cc: Greg KH, Linus Torvalds, Andrew Morton
On Thursday 30 June 2005 01:02, Greg KH wrote:
> Here are some small patches for the driver core. They fix a bug that
> has caused some people to see deadlocks when some drivers are unloaded
> (like ieee1394), and add the ability to bind and unbind drivers from
> devices from userspace (something that people have been asking for for a
> long time.)
>
Please don't until all buses are either audited or prepared to handle
"surprise" disconnects.
--
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] driver core: Add the ability to unbind drivers to devices from userspace
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
2005-06-30 6:04 ` [PATCH] driver core: change bus_rescan_devices to return void Greg KH
@ 2005-06-30 6:25 ` Dmitry Torokhov
2005-06-30 6:29 ` Greg KH
1 sibling, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2005-06-30 6:25 UTC (permalink / raw)
To: linux-kernel, Greg K-H; +Cc: gregkh
On Thursday 30 June 2005 01:04, Greg KH wrote:
> [PATCH] driver core: Add the ability to unbind drivers to devices from userspace
>
> This adds a single file, "unbind", to the sysfs directory of every
> device that is currently bound to a driver. To unbind the driver from
> the device, write anything to this file and they will be disconnected
> from each other.
>
Comment and the patch disagree with each other.
> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
>
> ---
> commit 151ef38f7c0ec1b0420f04438b0316e3a30bf2e4
> tree 3aa6504e12c08f70cacb7f9de6ef5858b45ee86d
> parent 0edb586049e57c56e625536476931117a57671e9
> 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/bus.c | 30 ++++++++++++++++++++++++++++++
> 1 files changed, 30 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -133,6 +133,34 @@ static struct kobj_type ktype_bus = {
> decl_subsys(bus, &ktype_bus, NULL);
>
>
> +/* Manually detach a device from it's associated driver. */
> +static int driver_helper(struct device *dev, void *data)
> +{
> + const char *name = data;
> +
> + if (strcmp(name, dev->bus_id) == 0)
> + return 1;
> + return 0;
> +}
> +
> +static ssize_t driver_unbind(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 == drv)) {
> + device_release_driver(dev);
> + err = count;
> + }
> + return err;
> +}
> +static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
> +
> +
> static struct device * next_device(struct klist_iter * i)
> {
> struct klist_node * n = klist_next(i);
> @@ -396,6 +424,7 @@ int bus_add_driver(struct device_driver
> module_add_driver(drv->owner, drv);
>
> driver_add_attrs(bus, drv);
> + driver_create_file(drv, &driver_attr_unbind);
> }
> return error;
> }
> @@ -413,6 +442,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_unbind);
> driver_remove_attrs(drv->bus, drv);
> klist_remove(&drv->knode_bus);
> pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
>
> -
> 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/
>
--
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GIT PATCH] Driver core patches for 2.6.13-rc1
2005-06-30 6:19 ` [GIT PATCH] Driver core patches for 2.6.13-rc1 Dmitry Torokhov
@ 2005-06-30 6:27 ` Greg KH
0 siblings, 0 replies; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:27 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-kernel, Linus Torvalds, Andrew Morton
On Thu, Jun 30, 2005 at 01:19:26AM -0500, Dmitry Torokhov wrote:
> On Thursday 30 June 2005 01:02, Greg KH wrote:
> > Here are some small patches for the driver core. They fix a bug that
> > has caused some people to see deadlocks when some drivers are unloaded
> > (like ieee1394), and add the ability to bind and unbind drivers from
> > devices from userspace (something that people have been asking for for a
> > long time.)
> >
>
> Please don't until all buses are either audited or prepared to handle
> "surprise" disconnects.
That's what bugfixes after 2.6.13-rc2 are for :)
Seriously, I don't think this is a big deal. But I will work with you
on getting any remaining issues you have solved. For now, the patches
should stay for their usefulness to others. I'll continue this
conversation in the other thread about the bind/unbind stuff.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] driver core: Add the ability to unbind drivers to devices from userspace
2005-06-30 6:25 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Dmitry Torokhov
@ 2005-06-30 6:29 ` Greg KH
0 siblings, 0 replies; 17+ messages in thread
From: Greg KH @ 2005-06-30 6:29 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-kernel, gregkh
On Thu, Jun 30, 2005 at 01:25:39AM -0500, Dmitry Torokhov wrote:
> On Thursday 30 June 2005 01:04, Greg KH wrote:
> > [PATCH] driver core: Add the ability to unbind drivers to devices from userspace
> >
> > This adds a single file, "unbind", to the sysfs directory of every
> > device that is currently bound to a driver. To unbind the driver from
> > the device, write anything to this file and they will be disconnected
> > from each other.
> >
>
> Comment and the patch disagree with each other.
bleah, you are right, that was the old comment with the new patch. Oh
well...
thanks,
greg k-h
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GIT PATCH] Driver core patches for 2.6.13-rc1
2005-06-30 6:02 [GIT PATCH] Driver core patches for 2.6.13-rc1 Greg KH
2005-06-30 6:04 ` [PATCH] driver core: add bus_find_device & driver_find_device functions Greg KH
2005-06-30 6:19 ` [GIT PATCH] Driver core patches for 2.6.13-rc1 Dmitry Torokhov
@ 2005-06-30 17:22 ` John Lenz
2005-06-30 19:45 ` Greg KH
2 siblings, 1 reply; 17+ messages in thread
From: John Lenz @ 2005-06-30 17:22 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Thu, June 30, 2005 1:02 am, Greg KH said:
> Here are some small patches for the driver core. They fix a bug that
> has caused some people to see deadlocks when some drivers are unloaded
> (like ieee1394), and add the ability to bind and unbind drivers from
> devices from userspace (something that people have been asking for for a
> long time.)
As long as there are a whole bunch of class API changes going on, I would
request that the class_interface add and remove functions get passed the
class_interface pointer as well as the class_device. This way, the same
function can be used on multiple class_interfaces.
John
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GIT PATCH] Driver core patches for 2.6.13-rc1
2005-06-30 17:22 ` John Lenz
@ 2005-06-30 19:45 ` Greg KH
2005-06-30 21:18 ` [PATCH] add class_interface pointer to add and remove functions John Lenz
0 siblings, 1 reply; 17+ messages in thread
From: Greg KH @ 2005-06-30 19:45 UTC (permalink / raw)
To: John Lenz; +Cc: linux-kernel
On Thu, Jun 30, 2005 at 12:22:49PM -0500, John Lenz wrote:
> On Thu, June 30, 2005 1:02 am, Greg KH said:
> > Here are some small patches for the driver core. They fix a bug that
> > has caused some people to see deadlocks when some drivers are unloaded
> > (like ieee1394), and add the ability to bind and unbind drivers from
> > devices from userspace (something that people have been asking for for a
> > long time.)
>
> As long as there are a whole bunch of class API changes going on, I would
> request that the class_interface add and remove functions get passed the
> class_interface pointer as well as the class_device. This way, the same
> function can be used on multiple class_interfaces.
I'm sorry, I seem to have missed the patch in this email that implements
this feature...
:)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] add class_interface pointer to add and remove functions
2005-06-30 19:45 ` Greg KH
@ 2005-06-30 21:18 ` John Lenz
2005-07-03 20:59 ` Greg KH
0 siblings, 1 reply; 17+ messages in thread
From: John Lenz @ 2005-06-30 21:18 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Thu, June 30, 2005 2:45 pm, Greg KH said:
> On Thu, Jun 30, 2005 at 12:22:49PM -0500, John Lenz wrote:
>> As long as there are a whole bunch of class API changes going on, I would
>> request that the class_interface add and remove functions get passed the
>> class_interface pointer as well as the class_device. This way, the same
>> function can be used on multiple class_interfaces.
>
> I'm sorry, I seem to have missed the patch in this email that implements
> this feature...
>
Here is a patch that updates every usage of class_interface I could find.
Signed-off-by: John Lenz <lenz@cs.wisc.edu>
Index: linux-2.6.12/drivers/message/i2o/device.c
===================================================================
--- linux-2.6.12.orig/drivers/message/i2o/device.c 2005-06-30 11:54:55.000000000 -0500
+++ linux-2.6.12/drivers/message/i2o/device.c 2005-06-30 16:00:55.756158383 -0500
@@ -385,7 +385,7 @@
*
* Returns 0 on success or negative error code on failure.
*/
-static int i2o_device_class_add(struct class_device *cd)
+static int i2o_device_class_add(struct class_interface *class_intf, struct class_device *cd)
{
struct i2o_device *i2o_dev, *tmp;
struct i2o_controller *c;
Index: linux-2.6.12/drivers/base/class.c
===================================================================
--- linux-2.6.12.orig/drivers/base/class.c 2005-06-30 11:54:52.000000000 -0500
+++ linux-2.6.12/drivers/base/class.c 2005-06-30 15:58:53.321286879 -0500
@@ -505,7 +505,7 @@
list_add_tail(&class_dev->node, &parent->children);
list_for_each_entry(class_intf, &parent->interfaces, node)
if (class_intf->add)
- class_intf->add(class_dev);
+ class_intf->add(class_intf, class_dev);
up(&parent->sem);
}
kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
@@ -585,7 +585,7 @@
list_del_init(&class_dev->node);
list_for_each_entry(class_intf, &parent->interfaces, node)
if (class_intf->remove)
- class_intf->remove(class_dev);
+ class_intf->remove(class_intf, class_dev);
up(&parent->sem);
}
@@ -688,7 +688,7 @@
list_add_tail(&class_intf->node, &parent->interfaces);
if (class_intf->add) {
list_for_each_entry(class_dev, &parent->children, node)
- class_intf->add(class_dev);
+ class_intf->add(class_intf, class_dev);
}
up(&parent->sem);
@@ -707,7 +707,7 @@
list_del_init(&class_intf->node);
if (class_intf->remove) {
list_for_each_entry(class_dev, &parent->children, node)
- class_intf->remove(class_dev);
+ class_intf->remove(class_intf, class_dev);
}
up(&parent->sem);
Index: linux-2.6.12/drivers/pcmcia/ds.c
===================================================================
--- linux-2.6.12.orig/drivers/pcmcia/ds.c 2005-06-30 11:54:56.000000000 -0500
+++ linux-2.6.12/drivers/pcmcia/ds.c 2005-06-30 16:02:14.382619884 -0500
@@ -1148,7 +1148,7 @@
.requery = pcmcia_bus_rescan,
};
-static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev)
+static int __devinit pcmcia_bus_add_socket(struct class_interface *class_intf, struct class_device *class_dev)
{
struct pcmcia_socket *socket = class_get_devdata(class_dev);
int ret;
@@ -1183,7 +1183,7 @@
return 0;
}
-static void pcmcia_bus_remove_socket(struct class_device *class_dev)
+static void pcmcia_bus_remove_socket(struct class_interface *class_intf, struct class_device *class_dev)
{
struct pcmcia_socket *socket = class_get_devdata(class_dev);
Index: linux-2.6.12/drivers/scsi/sg.c
===================================================================
--- linux-2.6.12.orig/drivers/scsi/sg.c 2005-06-30 11:54:57.000000000 -0500
+++ linux-2.6.12/drivers/scsi/sg.c 2005-06-30 16:06:23.123755439 -0500
@@ -104,8 +104,8 @@
#define SG_DEV_ARR_LUMP 32 /* amount to over allocate sg_dev_arr by */
-static int sg_add(struct class_device *);
-static void sg_remove(struct class_device *);
+static int sg_add(struct class_interface *class_intf, struct class_device *);
+static void sg_remove(struct class_interface *class_intf, struct class_device *);
static Scsi_Request *dummy_cmdp; /* only used for sizeof */
@@ -1507,7 +1507,7 @@
}
static int
-sg_add(struct class_device *cl_dev)
+sg_add(struct class_interface *class_intf, struct class_device *cl_dev)
{
struct scsi_device *scsidp = to_scsi_device(cl_dev->dev);
struct gendisk *disk;
@@ -1583,7 +1583,7 @@
}
static void
-sg_remove(struct class_device *cl_dev)
+sg_remove(struct class_interface *class_intf, struct class_device *cl_dev)
{
struct scsi_device *scsidp = to_scsi_device(cl_dev->dev);
Sg_device *sdp = NULL;
Index: linux-2.6.12/drivers/pcmcia/socket_sysfs.c
===================================================================
--- linux-2.6.12.orig/drivers/pcmcia/socket_sysfs.c 2005-06-30 11:54:56.000000000 -0500
+++ linux-2.6.12/drivers/pcmcia/socket_sysfs.c 2005-06-30 16:04:24.233249703 -0500
@@ -342,7 +342,7 @@
.write = pccard_store_cis,
};
-static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
+static int __devinit pccard_sysfs_add_socket(struct class_interface *class_intf, struct class_device *class_dev)
{
struct class_device_attribute **attr;
int ret = 0;
@@ -358,7 +358,7 @@
return ret;
}
-static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev)
+static void __devexit pccard_sysfs_remove_socket(struct class_interface *class_intf, struct class_device *class_dev)
{
struct class_device_attribute **attr;
Index: linux-2.6.12/drivers/pcmcia/rsrc_nonstatic.c
===================================================================
--- linux-2.6.12.orig/drivers/pcmcia/rsrc_nonstatic.c 2005-06-30 11:54:56.000000000 -0500
+++ linux-2.6.12/drivers/pcmcia/rsrc_nonstatic.c 2005-06-30 16:03:49.738193763 -0500
@@ -994,7 +994,7 @@
NULL,
};
-static int __devinit pccard_sysfs_add_rsrc(struct class_device *class_dev)
+static int __devinit pccard_sysfs_add_rsrc(struct class_interface *class_intf, struct class_device *class_dev)
{
struct pcmcia_socket *s = class_get_devdata(class_dev);
struct class_device_attribute **attr;
@@ -1011,7 +1011,7 @@
return ret;
}
-static void __devexit pccard_sysfs_remove_rsrc(struct class_device *class_dev)
+static void __devexit pccard_sysfs_remove_rsrc(struct class_interface *class_intf, struct class_device *class_dev)
{
struct pcmcia_socket *s = class_get_devdata(class_dev);
struct class_device_attribute **attr;
Index: linux-2.6.12/include/linux/device.h
===================================================================
--- linux-2.6.12.orig/include/linux/device.h 2005-06-30 11:54:59.000000000 -0500
+++ linux-2.6.12/include/linux/device.h 2005-06-30 15:59:44.921353866 -0500
@@ -246,8 +246,8 @@
struct list_head node;
struct class *class;
- int (*add) (struct class_device *);
- void (*remove) (struct class_device *);
+ int (*add) (struct class_interface *, struct class_device *);
+ void (*remove) (struct class_interface *, struct class_device *);
};
extern int class_interface_register(struct class_interface *);
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] add class_interface pointer to add and remove functions
2005-06-30 21:18 ` [PATCH] add class_interface pointer to add and remove functions John Lenz
@ 2005-07-03 20:59 ` Greg KH
2005-07-06 2:35 ` John Lenz
0 siblings, 1 reply; 17+ messages in thread
From: Greg KH @ 2005-07-03 20:59 UTC (permalink / raw)
To: John Lenz; +Cc: linux-kernel
On Thu, Jun 30, 2005 at 04:18:42PM -0500, John Lenz wrote:
> On Thu, June 30, 2005 2:45 pm, Greg KH said:
> > On Thu, Jun 30, 2005 at 12:22:49PM -0500, John Lenz wrote:
> >> As long as there are a whole bunch of class API changes going on, I would
> >> request that the class_interface add and remove functions get passed the
> >> class_interface pointer as well as the class_device. This way, the same
> >> function can be used on multiple class_interfaces.
> >
> > I'm sorry, I seem to have missed the patch in this email that implements
> > this feature...
> >
>
> Here is a patch that updates every usage of class_interface I could find.
Do you have a patch that will take advantage of this change? I would
prefer to have that before accepting this patch.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] add class_interface pointer to add and remove functions
2005-07-03 20:59 ` Greg KH
@ 2005-07-06 2:35 ` John Lenz
2005-07-06 7:17 ` Greg KH
0 siblings, 1 reply; 17+ messages in thread
From: John Lenz @ 2005-07-06 2:35 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Sun, July 3, 2005 3:59 pm, Greg KH said:
> On Thu, Jun 30, 2005 at 04:18:42PM -0500, John Lenz wrote:
>> Here is a patch that updates every usage of class_interface I could
>> find.
>
> Do you have a patch that will take advantage of this change? I would
> prefer to have that before accepting this patch.
>
No, not for inclusion. I needed this change while I was working on the
touchscreen driver for Zaurus (http://www.cs.wisc.edu/~lenz/zaurus). I
have not yet completed that driver, and am currently working on some other
drivers. So I won't really have a patch until I (or someone else, we can
always use volunteers!) goes back and tries to work on the touchscreen
driver.
I just thought that since the class API is changing anyway, this API
change could come along. Otherwise I will resubmit this patch when I (or
someone else) gets around to working on the touchscreen driver.
John
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] add class_interface pointer to add and remove functions
2005-07-06 2:35 ` John Lenz
@ 2005-07-06 7:17 ` Greg KH
0 siblings, 0 replies; 17+ messages in thread
From: Greg KH @ 2005-07-06 7:17 UTC (permalink / raw)
To: John Lenz; +Cc: linux-kernel
On Tue, Jul 05, 2005 at 09:35:53PM -0500, John Lenz wrote:
> On Sun, July 3, 2005 3:59 pm, Greg KH said:
> > On Thu, Jun 30, 2005 at 04:18:42PM -0500, John Lenz wrote:
> >> Here is a patch that updates every usage of class_interface I could
> >> find.
> >
> > Do you have a patch that will take advantage of this change? I would
> > prefer to have that before accepting this patch.
> >
>
> No, not for inclusion. I needed this change while I was working on the
> touchscreen driver for Zaurus (http://www.cs.wisc.edu/~lenz/zaurus). I
> have not yet completed that driver, and am currently working on some other
> drivers. So I won't really have a patch until I (or someone else, we can
> always use volunteers!) goes back and tries to work on the touchscreen
> driver.
>
> I just thought that since the class API is changing anyway, this API
> change could come along. Otherwise I will resubmit this patch when I (or
> someone else) gets around to working on the touchscreen driver.
Yeah, I prefer to wait until someone uses it. There's no reason we
can't change the API any time we need to :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2005-07-06 9:10 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-30 6:02 [GIT PATCH] Driver core patches for 2.6.13-rc1 Greg KH
2005-06-30 6:04 ` [PATCH] driver core: add bus_find_device & driver_find_device functions Greg KH
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
2005-06-30 6:04 ` [PATCH] driver core: change bus_rescan_devices to return void Greg KH
2005-06-30 6:04 ` [PATCH] driver core: Add the ability to bind drivers to devices from userspace Greg KH
2005-06-30 6:04 ` [PATCH] Driver core: Use klist_del() instead of klist_remove() Greg KH
2005-06-30 6:25 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Dmitry Torokhov
2005-06-30 6:29 ` Greg KH
2005-06-30 6:19 ` [GIT PATCH] Driver core patches for 2.6.13-rc1 Dmitry Torokhov
2005-06-30 6:27 ` Greg KH
2005-06-30 17:22 ` John Lenz
2005-06-30 19:45 ` Greg KH
2005-06-30 21:18 ` [PATCH] add class_interface pointer to add and remove functions John Lenz
2005-07-03 20:59 ` Greg KH
2005-07-06 2:35 ` John Lenz
2005-07-06 7:17 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2005-06-24 5:12 [RFC] bind and unbind drivers from userspace through sysfs Greg KH
2005-06-24 5:14 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
2005-06-24 5:15 ` [PATCH] driver core: Add the ability to bind " Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox