1 From f2991d30ff590bf932483a6dfc16c7ebe2f83341 Mon Sep 17 00:00:00 2001
2 From: Laurentiu Tudor <laurentiu.tudor@nxp.com>
3 Date: Fri, 13 Apr 2018 12:42:40 +0300
4 Subject: [PATCH] bus: fsl-mc: add device binding path 'driver_override'
6 This patch is required for vfio-fsl-mc meta driver to successfully bind
7 layerscape container devices for device passthrough. This patch adds
8 a mechanism to allow a layerscape device to specify a driver rather than
9 a layerscape driver provide a device match.
11 This patch is based on following proposed patches for PCI and platform
13 - https://lkml.org/lkml/2014/4/8/571 :- For Platform devices
14 - http://lists-archives.com/linux-kernel/28030441-pci-introduce-new-device-binding-path-using-pci_dev-driver_override.html
17 Example to allow a device (dprc.1) to specifically bind
18 with driver (vfio-fsl-mc):-
19 - echo vfio-fsl-mc > /sys/bus/fsl-mc/devices/dprc.1/driver_override
20 - echo dprc.1 > /sys/bus/fsl-mc/drivers/fsl_mc_dprc/unbind
21 - echo dprc.1 > /sys/bus/fsl-mc/drivers/vfio-fsl-mc/bind
23 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
24 Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
26 drivers/bus/fsl-mc/fsl-mc-bus.c | 53 +++++++++++++++++++++++++++++++++++++++++
27 1 file changed, 53 insertions(+)
29 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c
30 +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
31 @@ -83,6 +83,12 @@ static int fsl_mc_bus_match(struct devic
32 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
35 + /* When driver_override is set, only bind to the matching driver */
36 + if (mc_dev->driver_override) {
37 + found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
41 if (!mc_drv->match_id_table)
44 @@ -147,8 +153,52 @@ static ssize_t modalias_show(struct devi
46 static DEVICE_ATTR_RO(modalias);
48 +static ssize_t driver_override_store(struct device *dev,
49 + struct device_attribute *attr,
50 + const char *buf, size_t count)
52 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
53 + const char *driver_override, *old = mc_dev->driver_override;
56 + if (WARN_ON(dev->bus != &fsl_mc_bus_type))
59 + if (count >= (PAGE_SIZE - 1))
62 + driver_override = kstrndup(buf, count, GFP_KERNEL);
63 + if (!driver_override)
66 + cp = strchr(driver_override, '\n');
70 + if (strlen(driver_override)) {
71 + mc_dev->driver_override = driver_override;
73 + kfree(driver_override);
74 + mc_dev->driver_override = NULL;
82 +static ssize_t driver_override_show(struct device *dev,
83 + struct device_attribute *attr, char *buf)
85 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
87 + return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override);
89 +static DEVICE_ATTR_RW(driver_override);
91 static struct attribute *fsl_mc_dev_attrs[] = {
92 &dev_attr_modalias.attr,
93 + &dev_attr_driver_override.attr,
97 @@ -749,6 +799,9 @@ EXPORT_SYMBOL_GPL(fsl_mc_device_add);
99 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
101 + kfree(mc_dev->driver_override);
102 + mc_dev->driver_override = NULL;
105 * The device-specific remove callback will get invoked by device_del()