From: Dmitry Torokhov <dtor_core@ameritech.net>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@home-tj.org>, Greg KH <greg@kroah.com>,
rusty@rustcorp.com.au, mochel@osdl.org
Subject: [PATCH 2/3] Add drvctl handler to PCI bus
Date: Mon, 8 Nov 2004 02:25:56 -0500 [thread overview]
Message-ID: <200411080225.58532.dtor_core@ameritech.net> (raw)
In-Reply-To: <200411080223.56536.dtor_core@ameritech.net>
===================================================================
ChangeSet@1.1962, 2004-11-08 02:06:19-05:00, dtor_core@ameritech.net
PCI: Add devctl method to PCI bus. The following commands are
available: "detach", "attach <driver>", and "rescan".
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
pci-driver.c | 58 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 44 insertions(+), 14 deletions(-)
===================================================================
diff -Nru a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
--- a/drivers/pci/pci-driver.c 2004-11-08 02:20:22 -05:00
+++ b/drivers/pci/pci-driver.c 2004-11-08 02:20:22 -05:00
@@ -186,7 +186,7 @@
* PCI device id structure
* @ids: array of PCI device id structures to search in
* @dev: the PCI device structure to match against
- *
+ *
* Used by a driver to check whether a PCI device present in the
* system is in its list of supported devices.Returns the matching
* pci_device_id structure or %NULL if there is no match.
@@ -204,12 +204,12 @@
/**
* pci_device_probe_static()
- *
+ *
* returns 0 and sets pci_dev->driver when drv claims pci_dev, else error.
*/
static int
pci_device_probe_static(struct pci_driver *drv, struct pci_dev *pci_dev)
-{
+{
int error = -ENODEV;
const struct pci_device_id *id;
@@ -227,13 +227,13 @@
/**
* __pci_device_probe()
- *
+ *
* returns 0 on success, else error.
* side-effect: pci_dev->driver is set to drv when drv claims pci_dev.
*/
static int
__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
-{
+{
int error = 0;
if (!pci_dev->driver && drv->probe) {
@@ -314,7 +314,7 @@
}
-/*
+/*
* Default resume method for devices that have no driver provided resume,
* or not even a driver at all.
*/
@@ -394,10 +394,10 @@
/**
* pci_register_driver - register a new pci driver
* @drv: the driver structure to register
- *
+ *
* Adds the driver structure to the list of registered drivers.
- * Returns a negative value on error, otherwise 0.
- * If no error occured, the driver remains registered even if
+ * Returns a negative value on error, otherwise 0.
+ * If no error occured, the driver remains registered even if
* no device was claimed during registration.
*/
int pci_register_driver(struct pci_driver *drv)
@@ -425,7 +425,7 @@
/**
* pci_unregister_driver - unregister a pci driver
* @drv: the driver structure to unregister
- *
+ *
* Deletes the driver structure from the list of registered PCI drivers,
* gives it a chance to clean up by calling its remove() function for
* each device it was responsible for, and marks those devices as
@@ -447,7 +447,7 @@
* pci_dev_driver - get the pci_driver of a device
* @dev: the device to query
*
- * Returns the appropriate pci_driver structure or %NULL if there is no
+ * Returns the appropriate pci_driver structure or %NULL if there is no
* registered driver for the device.
*/
struct pci_driver *
@@ -457,7 +457,7 @@
return dev->driver;
else {
int i;
- for(i=0; i<=PCI_ROM_RESOURCE; i++)
+ for(i = 0; i <= PCI_ROM_RESOURCE; i++)
if (dev->resource[i].flags & IORESOURCE_BUSY)
return &pci_compat_driver;
}
@@ -468,12 +468,12 @@
* pci_bus_match - Tell if a PCI device structure has a matching PCI device id structure
* @ids: array of PCI device id structures to search in
* @dev: the PCI device structure to match against
- *
+ *
* Used by a driver to check whether a PCI device present in the
* system is in its list of supported devices.Returns the matching
* pci_device_id structure or %NULL if there is no match.
*/
-static int pci_bus_match(struct device * dev, struct device_driver * drv)
+static int pci_bus_match(struct device * dev, struct device_driver * drv)
{
const struct pci_dev * pci_dev = to_pci_dev(dev);
struct pci_driver * pci_drv = to_pci_driver(drv);
@@ -490,6 +490,35 @@
return pci_bus_match_dynids(pci_dev, pci_drv);
}
+/*
+ * This is PCI bus's drvctl method that handles manual device binding.
+ */
+static int pci_rebind_driver(struct device *dev, const char *action,
+ struct device_driver *drv, char *args)
+{
+ int retval = 0;
+
+ if (!strcmp(action, "detach")) {
+ down_write(&dev->bus->subsys.rwsem);
+ device_release_driver(dev);
+ up_write(&dev->bus->subsys.rwsem);
+ } else if (!strcmp(action, "rescan")) {
+ down_write(&dev->bus->subsys.rwsem);
+ device_release_driver(dev);
+ device_attach(dev);
+ up_write(&dev->bus->subsys.rwsem);
+ } else if (!strcmp(action, "attach") && drv) {
+ down_write(&dev->bus->subsys.rwsem);
+ device_release_driver(dev);
+ driver_probe_device(drv, dev);
+ up_write(&dev->bus->subsys.rwsem);
+ } else {
+ retval = -EINVAL;
+ }
+
+ return retval;
+}
+
/**
* pci_dev_get - increments the reference count of the pci device structure
* @dev: the device being referenced
@@ -534,6 +563,7 @@
.name = "pci",
.match = pci_bus_match,
.hotplug = pci_hotplug,
+ .drvctl = pci_rebind_driver,
.suspend = pci_device_suspend,
.resume = pci_device_resume,
.dev_attrs = pci_dev_attrs,
next prev parent reply other threads:[~2004-11-08 7:28 UTC|newest]
Thread overview: 17+ 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 ` [PATCH 2.6.10-rc1 4/4] driver-model: attach/detach sysfs node implemented Tejun Heo
2004-11-04 17:05 ` 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 ` Dmitry Torokhov [this message]
2004-11-08 7:26 ` [PATCH 3/3] Add bind_mode default device/driver attributes 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=200411080225.58532.dtor_core@ameritech.net \
--to=dtor_core@ameritech.net \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.org \
--cc=rusty@rustcorp.com.au \
--cc=tj@home-tj.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.