Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754064AbbFIWJW (ORCPT ); Tue, 9 Jun 2015 18:09:22 -0400 Received: from mail-bn1bon0142.outbound.protection.outlook.com ([157.56.111.142]:20100 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753400AbbFIWIx (ORCPT ); Tue, 9 Jun 2015 18:08:53 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; From: "J. German Rivera" To: , , , CC: , , , , , , , , , , Bharat Bhushan , "J. German Rivera" Subject: [PATCH v4 2/7] staging: fsl_-mc: add device binding path 'driver_override' Date: Tue, 9 Jun 2015 16:59:03 -0500 Message-ID: <1433887148-2310-3-git-send-email-German.Rivera@freescale.com> X-Mailer: git-send-email 2.3.3 In-Reply-To: <1433887148-2310-1-git-send-email-German.Rivera@freescale.com> References: <1433887148-2310-1-git-send-email-German.Rivera@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD030;1:mBcApFPdxIeXdJtwl2rJ5Z8sHQaDhaKvDQhtZ3ejJEwEWUL7H0ZajpP5n6Hvxry7ezyzaYNnM8UiU+r3CWAIJKpBZ9czEoOpj2xGNu+TcyimykGeMQ9HmspuhQBJAhtYGcWFjWCqtDI5+da+vdbnlt/Iq7MN9PV1kL90KZAelNwVyeacchhUBysNiVVt3xrixa9rrnD+2vEKq3w/0BIRvfC5Ve83YI3gz/Z28giEWkOSyPlnLv+AAptVm4z8zezqbIEn2bPGLudWux6p2BhoQrc7lDMiR60M6Qr6kTY19swTzXNMHhcOMlrZ21flqYbpjTmFvzCnVbPVd+XUjH6biQ== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(189002)(199003)(62966003)(15975445007)(2950100001)(36756003)(5001920100001)(107886002)(189998001)(5001960100002)(77096005)(105606002)(50226001)(77156002)(5001770100001)(5890100001)(46102003)(47776003)(19580395003)(87936001)(2201001)(86362001)(50466002)(104016003)(50986999)(19580405001)(229853001)(48376002)(92566002)(106466001)(6806004)(85426001)(76176999)(4001430100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB454;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB454;2:bvYyqeNj27z6IaqUTylwpVl9kL7KTxb/mmrmIyR7MxKUQCtMnm9SEqwvf0Uxfm62;2:yGhZsaNmNm8C/5BEM+thpz8vzGT9I9GtUBRoMXq1KBpMUPFi9kAIHUVUV+TPRlOAiGcdrVU6XhsFXrMcdIFTU3tnOYSlyzBBaPTuR2Ia0ICWuJhhBR+iFsosCUnSXK4sYnL9wVJfB1Xx/xfmBidR8fH8kxias2yPZ4gp9+TngySLJvJ4IDfAdZcFlJC3qxuPA2SikKYybjw26sTWUhnlvaP/r8NKOEdjI4KpCsUcogY=;6:i8s0HWiiSw/hRa1t7mwcW9DLmA1X0UUqwOTY/BDwiv5ddW6kP3S6xwAAoyeSPPBiFqPRzEMuHitYApw4C1fu+2VKPU9jwdc3pgjJahbPVsruYnFJGdlGGMoFUojAt4zVSTR1EIBCUvawTDEWBJaiL/EUlkpOL7Vsi8u0ciEZZSYe1jZEQdgHVWvGJo7/8rL75mrp/HJcD4I0alX75ZSQGHtmQZJVrcxcDt0sh+XPkVwlMNYzGCHarko1tZhaZk5Lg4w3Hblrd/2FUr49vBZF2L89Uhyt1bMxTluLOd8Ynvn/uMMrp7S1tKNItDHqSfJNkD8YRfRh/FzQRldb6nf2ew==;3:eGVLlDZCUIs6gZHcIm2VfbGIxTWBxp/vnxZDdk5B4u+fpKfbePjv2obGjTKzYbX2xRz+eajRrpCv2AiPHzMdhtPqAoJlSH5N1iOidrRl/xZCvnbSz6nDuPFeCwJufUd/rMlgrs4zEsSnmYEGHHYT6/8UoYchNdwzLEzEGSwoya6re6XTB0QSKpkOObYOcH50aKNeOkZM1B9XcYhQviQauiHphRpf3p2dM5p4wAckLhLVkacMjgfG8JJ9KlyfOmLr9uDYUfK6y+OkFtyZYLvo7X7lhaHCMgtYp9TDMOuAgl5qgzzgRGasXfCnfHI2M5gY X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB454;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1363; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)(3002001);SRVR:BLUPR03MB454;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB454; X-Forefront-PRVS: 06022AA85F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB454;9:pXsVnam4h+zEk5pbtpSSQBWNAythl31yd/7PkEZIW8V?= =?us-ascii?Q?vsAvZH9iZQPb2Vw8CY/xZQ4Rla/NvfJg7b1K+w4TpLpLQix29Btq8CUk0PA+?= =?us-ascii?Q?NAfgJmE4Hn4vtXCsOKZcAzgyesVSYeasQpffi8wW+e+5Y8wsTqC+0TgUTcmP?= =?us-ascii?Q?jvK9G7agX3xbor2QSTnv8axybiBYo9zAOLyTOC33PSmwdFiFKV+MQavQR+5F?= =?us-ascii?Q?zLJG5SluCLDPe/gGwy2J6SAeEJ9+toFpYM9bM8dwcnecYNmPNqmJdoFmfQ3b?= =?us-ascii?Q?IceBlIQE9KIXbkKi7IYAo2PwZw5ETxF8lCdzeS31sURXuer6uhoWbCcw0gqP?= =?us-ascii?Q?FQrq8wYVMBEfAVEtfbcuTf0ReAl7Nkd40aUmJ+31R7b8Kiu9Z+sLJbqjdxzv?= =?us-ascii?Q?l+FILTAoc8DzGC2I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o1Ke4iG4/V5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2015 22:08:50.4034 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB454 X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1363;2:DJlNZvwgL55Q2kA/kjUnaH8Em7iIDztGA7zQ2e0pqlGjcxJrqETWmiUgoLEFJUHH;2:anL1b7d8PWos59Jarmc/QUyeiQbiThj+cRY044WiF9XzOSOu6vPOzB5+7wGBCqwilFY1PiIn/tXfF/sl9+0FU5fEb1isEGM14BNX0Pxchlr8jIqPHT/9q+/UD7/pcgD7hwzDkN/aUMLQiBr+7vHYhrceD3cfJ1uZysPYsr34IvyzJaxekBCk+vvx5JNIzP4ZV2BRFR2sFqzGqy/McqpC2JBHaKnpKh+VMQbenAfFk5o=;9:OUhnxXV+l35UWulo+e5UvP/cEf/9gzeBXY9zyK9Ecr6jAaLtccBIsHO4wcib5wk0ssOLiVpHe0WPQ9dsF745Iu/2z9I1DESrHfi2mnUVeDYY6cU8RVeoxSdM3TZrzFEoVKhhiNE3v5ob9tQ1UrNjnA== X-OriginatorOrg: freescale.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4718 Lines: 149 From: Bharat Bhushan 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 Reviewed-by: Stuart Yoder Tested-by: Stuart Yoder --- 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 -- 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/