mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "J. German Rivera" <German.Rivera@freescale.com>
To: <gregkh@linuxfoundation.org>, <arnd@arndb.de>,
	<devel@driverdev.osuosl.org>, <linux-kernel@vger.kernel.org>
Cc: <stuart.yoder@freescale.com>, <itai.katz@freescale.com>,
	<scottwood@freescale.com>, <agraf@suse.de>,
	<bhamciu1@freescale.com>, <R89243@freescale.com>,
	<bhupesh.sharma@freescale.com>, <nir.erez@freescale.com>,
	<richard.schmitt@freescale.com>, <dan.carpenter@oracle.com>,
	Bharat Bhushan <bharat.bhushan@freescale.com>,
	"J. German Rivera" <German.Rivera@freescale.com>
Subject: [PATCH v4 2/7] staging: fsl_-mc: add device binding path 'driver_override'
Date: Tue, 9 Jun 2015 16:59:03 -0500	[thread overview]
Message-ID: <1433887148-2310-3-git-send-email-German.Rivera@freescale.com> (raw)
In-Reply-To: <1433887148-2310-1-git-send-email-German.Rivera@freescale.com>

From: Bharat Bhushan <bharat.bhushan@freescale.com>

This patch is required for vfio-fsl-mc meta driver to successfully bind
layerscape container devices for device passthrough. This patch adds
a mechanism to allow a layerscape device to specify a driver rather than
a layerscape driver provide a device match.

This patch is based on following proposed patches for PCI and platform devices
- https://lkml.org/lkml/2014/4/8/571  :- For Platform devices
- http://lists-archives.com/linux-kernel/28030441-pci-introduce-new-device-binding-path-using-pci_dev-driver_override.html  :- For PCI devices

Example to allow a device (dprc.1) to specifically bind
with driver (vfio-fsl-mc):-
- echo vfio-fsl-mc > /sys/bus/fsl-mc/devices/dprc.1/driver_override
- echo dprc.1 > /sys/bus/fsl-mc/drivers/fsl_mc_dprc/unbind
- echo dprc.1 > /sys/bus/fsl-mc/drivers/vfio-fsl-mc/bind

Signed-off-by: J. German Rivera <German.Rivera@freescale.com>
Reviewed-by: Stuart Yoder <stuart.yoder@freescale.com>
Tested-by: Stuart Yoder <stuart.yoder@freescale.com>
---
 drivers/staging/fsl-mc/bus/mc-bus.c | 67 +++++++++++++++++++++++++++++++++++++
 drivers/staging/fsl-mc/include/mc.h |  2 ++
 2 files changed, 69 insertions(+)

diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c
index 9d98828..fdd3d17 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -58,6 +58,12 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
 	if (WARN_ON(!fsl_mc_bus_type.dev_root))
 		goto out;

+	/* When driver_override is set, only bind to the matching driver */
+	if (mc_dev->driver_override) {
+		found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
+		goto out;
+	}
+
 	if (!mc_drv->match_id_table)
 		goto out;

@@ -116,10 +122,69 @@ static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }

+static ssize_t driver_override_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+	const char *driver_override, *old = mc_dev->driver_override;
+	char *cp;
+
+	if (WARN_ON(dev->bus != &fsl_mc_bus_type))
+		return -EINVAL;
+
+	if (count > PATH_MAX)
+		return -EINVAL;
+
+	driver_override = kstrndup(buf, count, GFP_KERNEL);
+	if (!driver_override)
+		return -ENOMEM;
+
+	cp = strchr(driver_override, '\n');
+	if (cp)
+		*cp = '\0';
+
+	if (strlen(driver_override)) {
+		mc_dev->driver_override = driver_override;
+	} else {
+		kfree(driver_override);
+		mc_dev->driver_override = NULL;
+	}
+
+	kfree(old);
+
+	return count;
+}
+
+static ssize_t driver_override_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+
+	return sprintf(buf, "%s\n", mc_dev->driver_override);
+}
+
+static DEVICE_ATTR_RW(driver_override);
+
+static struct attribute *fsl_mc_dev_attrs[] = {
+	&dev_attr_driver_override.attr,
+	NULL,
+};
+
+static const struct attribute_group fsl_mc_dev_group = {
+	.attrs = fsl_mc_dev_attrs,
+};
+
+static const struct attribute_group *fsl_mc_dev_groups[] = {
+	&fsl_mc_dev_group,
+	NULL,
+};
+
 struct bus_type fsl_mc_bus_type = {
 	.name = "fsl-mc",
 	.match = fsl_mc_bus_match,
 	.uevent = fsl_mc_bus_uevent,
+	.dev_groups = fsl_mc_dev_groups,
 };
 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);

@@ -492,6 +557,8 @@ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
 			fsl_mc_bus_type.dev_root = NULL;
 	}

+	kfree(mc_dev->driver_override);
+	mc_dev->driver_override = NULL;
 	if (!mc_bus)
 		kmem_cache_free(mc_dev_cache, mc_dev);
 	else
diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h
index c543a84..322b594 100644
--- a/drivers/staging/fsl-mc/include/mc.h
+++ b/drivers/staging/fsl-mc/include/mc.h
@@ -145,6 +145,7 @@ struct fsl_mc_device_irq {
  * @regions: pointer to array of MMIO region entries
  * @irqs: pointer to array of pointers to interrupts allocated to this device
  * @resource: generic resource associated with this MC object device, if any.
+ * @driver_override: Driver name to force a match
  *
  * Generic device object for MC object devices that are "attached" to a
  * MC bus.
@@ -177,6 +178,7 @@ struct fsl_mc_device {
 	struct resource *regions;
 	struct fsl_mc_device_irq **irqs;
 	struct fsl_mc_resource *resource;
+	const char *driver_override;
 };

 #define to_fsl_mc_device(_dev) \
--
2.3.3


  parent reply	other threads:[~2015-06-09 22:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09 21:59 [PATCH v4 0/7] staging: fsl-mc: New functionality to the MC bus driver J. German Rivera
2015-06-09 21:59 ` [PATCH v4 1/7] staging: fsl-mc: MC bus IRQ support J. German Rivera
2015-06-09 21:59 ` J. German Rivera [this message]
2015-06-09 21:59 ` [PATCH v4 3/7] staging: fsl-mc: Propagate driver_override for a child DPRC's children J. German Rivera
2015-06-09 21:59 ` [PATCH v4 4/7] staging: fsl-mc: Upgraded MC bus driver to match MC fw 7.0.0 J. German Rivera
2015-06-09 21:59 ` [PATCH v4 5/7] staging: fsl-mc: Allow the MC bus driver to run without GIC support J. German Rivera
2015-06-09 21:59 ` [PATCH v4 6/7] staging: fsl-mc: Add locking to serialize mc_send_command() calls J. German Rivera
2015-06-10 11:59   ` Dan Carpenter
2015-06-09 21:59 ` [PATCH v4 7/7] staging: fsl-mc: Use DPMCP IRQ and completion var to wait for MC J. German Rivera
2015-06-09 22:11 ` [PATCH v4 0/7] staging: fsl-mc: New functionality to the MC bus driver Fabio Estevam
2015-06-09 23:07   ` Jose Rivera
2015-06-13  0:18 ` Greg KH
2015-06-13  8:46   ` doubt about sm7xxfb (was: Re: [PATCH v4 0/7] staging: fsl-mc: New functionality to the MC bus driver) Sudip Mukherjee
2015-06-13 16:28     ` Greg KH
2015-06-13 16:57       ` Joe Perches
2015-06-15  5:17         ` Sudip Mukherjee
2015-06-15  6:36           ` Joe Perches
2015-06-19 10:29     ` Dan Carpenter
2015-06-20 11:20       ` Sudip Mukherjee
2015-06-18 15:01   ` [PATCH v4 0/7] staging: fsl-mc: New functionality to the MC bus driver Jose Rivera
2015-06-18 23:02     ` Greg KH

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=1433887148-2310-3-git-send-email-German.Rivera@freescale.com \
    --to=german.rivera@freescale.com \
    --cc=R89243@freescale.com \
    --cc=agraf@suse.de \
    --cc=arnd@arndb.de \
    --cc=bhamciu1@freescale.com \
    --cc=bharat.bhushan@freescale.com \
    --cc=bhupesh.sharma@freescale.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=itai.katz@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nir.erez@freescale.com \
    --cc=richard.schmitt@freescale.com \
    --cc=scottwood@freescale.com \
    --cc=stuart.yoder@freescale.com \
    /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®