From: Tejun Heo <tj@home-tj.org>
To: rusty@rustcorp.com.au, mochel@osdl.org, greg@kroah.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.10-rc1 4/4] driver-model: attach/detach sysfs node implemented
Date: Thu, 4 Nov 2004 16:46:28 +0900 [thread overview]
Message-ID: <20041104074628.GK25567@home-tj.org> (raw)
In-Reply-To: <20041104074330.GG25567@home-tj.org>
ma_04_manual_attach.patch
This patch implements device interface nodes attach and detach.
Reading attach node shows the name of applicable drivers. Writing a
driver name attaches the device to the driver. Writing anything to
the write-only detach node detaches the driver from the currently
associated driver.
Signed-off-by: Tejun Heo <tj@home-tj.org>
Index: linux-export/drivers/base/interface.c
===================================================================
--- linux-export.orig/drivers/base/interface.c 2004-11-04 11:04:15.000000000 +0900
+++ linux-export/drivers/base/interface.c 2004-11-04 11:04:15.000000000 +0900
@@ -13,6 +13,7 @@
#include <linux/err.h>
#include <linux/stat.h>
#include <linux/string.h>
+#include <linux/ctype.h>
/**
* detach_state - control the default power state for the device.
@@ -46,7 +47,113 @@ static ssize_t detach_state_store(struct
static DEVICE_ATTR(detach_state, 0644, detach_state_show, detach_state_store);
+/**
+ * attach - manually attaches the device to the specified driver
+ *
+ * When read, this node shows the list of the attachable drivers.
+ * Writing the name of a driver attaches the device to the
+ * driver.
+ */
+
+struct attach_show_arg {
+ struct device * dev;
+ char * buf;
+ size_t left;
+};
+
+static int attach_show_helper(struct device_driver * drv, void * void_arg)
+{
+ struct attach_show_arg * arg = void_arg;
+ int ret;
+
+ if (drv->bus->match(arg->dev, drv)) {
+ ret = snprintf(arg->buf, arg->left, "%s\n", drv->name);
+ if (ret >= arg->left)
+ return -ENOSPC;
+ arg->buf += ret;
+ arg->left -= ret;
+ }
+
+ return 0;
+}
+
+static ssize_t attach_show(struct device * dev, char * buf)
+{
+ struct attach_show_arg arg = { dev, buf, PAGE_SIZE };
+ int ret = 0;
+
+ if (dev->bus->match)
+ ret = bus_for_each_drv(dev->bus, NULL, &arg, attach_show_helper);
+
+ return ret ?: PAGE_SIZE - arg.left;
+}
+
+static int attach_store_helper(struct device_driver * drv, void * arg)
+{
+ const char * p = *(void **)arg;
+ int len;
+
+ len = strlen(drv->name);
+ if (!strncmp(drv->name, p, len) &&
+ (p[len] == '\0' || isspace(p[len]))) {
+ *(void **)(arg) = get_driver(drv);
+ return 1;
+ }
+
+ return 0;
+}
+
+static ssize_t attach_store(struct device * dev, const char * buf, size_t n)
+{
+ void * arg = (void *)buf;
+ struct device_driver *drv;
+ int error;
+
+ if (bus_for_each_drv(dev->bus, NULL, &arg, attach_store_helper) == 0)
+ return -ENOENT;
+ drv = arg;
+
+ /* Skip driver name */
+ while (*buf != '\0' && !isspace(*buf))
+ buf++;
+
+ /* Attach */
+ error = -EBUSY;
+ down_write(&dev->bus->subsys.rwsem);
+ if (dev->driver == NULL)
+ error = driver_probe_device(drv, dev, buf);
+ up_write(&dev->bus->subsys.rwsem);
+
+ if (error)
+ printk(KERN_WARNING "%s: probe of %s failed with error %d\n",
+ drv->name, dev->bus_id, error);
+
+ return error ?: n;
+}
+
+static DEVICE_ATTR(attach, 0644, attach_show, attach_store);
+
+
+/**
+ * detach - manually detaches the device from its associated driver.
+ *
+ * This is a write-only node. When any value is written, it detaches
+ * the device from its associated driver.
+ */
+static ssize_t detach_store(struct device * dev, const char * buf, size_t n)
+{
+ down_write(&dev->bus->subsys.rwsem);
+ device_release_driver(dev);
+ up_write(&dev->bus->subsys.rwsem);
+ return n;
+}
+
+static DEVICE_ATTR(detach, 0200, NULL, detach_store);
+
+
struct attribute * dev_default_attrs[] = {
&dev_attr_detach_state.attr,
+ &dev_attr_attach.attr,
+ &dev_attr_detach.attr,
NULL,
};
next prev parent reply other threads:[~2004-11-04 7:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-04 7:43 [PATCH 2.6.10-rc1 0/4] driver-model: manual device attach Tejun Heo
2004-11-04 7:44 ` [PATCH 2.6.10-rc1 1/4] driver-model: sysctl node dev.autoattach Tejun Heo
2004-11-04 7:45 ` [PATCH 2.6.10-rc1 2/4] driver-model: devparam expanded to accept direct per-device parameters via @args argument Tejun Heo
2004-11-04 7:45 ` [PATCH 2.6.10-rc1 3/4] driver-model: detach_state functions renamed Tejun Heo
2004-11-04 7:46 ` Tejun Heo [this message]
2004-11-04 17:05 ` [PATCH 2.6.10-rc1 4/4] driver-model: attach/detach sysfs node implemented Dmitry Torokhov
2004-11-04 17:49 ` Greg KH
2004-11-04 10:27 ` [PATCH 2.6.10-rc1 0/4] driver-model: manual device attach Martin Waitz
2004-11-04 17:53 ` Greg KH
2004-11-05 4:50 ` Tejun Heo
2004-11-05 5:02 ` Dmitry Torokhov
2004-11-05 6:32 ` Tejun Heo
2004-11-05 14:53 ` Dmitry Torokhov
2004-11-08 7:23 ` Dmitry Torokhov
2004-11-08 7:23 ` [PATCH 1/3] Add drvctl default device attribute Dmitry Torokhov
2004-11-08 7:25 ` [PATCH 2/3] Add drvctl handler to PCI bus Dmitry Torokhov
2004-11-08 7:26 ` [PATCH 3/3] Add bind_mode default device/driver attributes Dmitry Torokhov
2004-11-04 19:06 [PATCH 2.6.10-rc1 4/4] driver-model: attach/detach sysfs node implemented Dmitry Torokhov
2004-11-05 4:45 ` Tejun Heo
2004-11-05 5:17 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041104074628.GK25567@home-tj.org \
--to=tj@home-tj.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.org \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®