Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp784865ybg; Thu, 19 Mar 2020 08:42:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsi3prfKSQDi70qrl8Jjtndlf1Vy+vGKDy6SLEy1Nvp/F31w+SCFhtspSYyDCh10V+YJ21h X-Received: by 2002:a54:4388:: with SMTP id u8mr2810637oiv.67.1584632569479; Thu, 19 Mar 2020 08:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584632569; cv=none; d=google.com; s=arc-20160816; b=he3x+zSbu7PYw4GjE+qEyri83VWeNW6R+gHCoGU61vNl08Us9YkhX+SoL5e+RjK8Lk CxsnGj3SxF3M8VoUGVoBPoLmjYiD6nAQEijW47dsqWHxjP5NQQYHA8Y5bMPRoF1lv3Lg 6U07kbBuKeYIo4f3TzYhah8n+IkxVDgRk8AsyagzKJl3LCG8X8dbpcHfLFre5YoROtv6 JBvyBVXnbdZ8Jan1v3Z1HhwYnj5/TaRUTv3umJz0t7Rq3OFfdZu6MjbjGix8z0Wuj2Xi YKInsxhsM5LNOKFsLFmf7EWOvHhElGngI10sk2mYxpO+M3hwFmMr2NVSE+YLas7oZje1 cysw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=3yMHoZJScxAFDn2myfDt/o39MHiPVvSUDHWpphyGw3E=; b=oWim35DBwTse408hDdlldGRDEXDFTwJQt+sBZuMLRLFzxsBmMe+dUwnJxh3/tsWtQQ cVY2h8Y/NuqL1QQob9ffI9WREfxCDci766FlAC8suYPpyQDqNYklX0B5g8/kM7nF80xE MuukvjrCyJA40CJwElWXyitavcKB7xQjkQm+u4mb6ltt3wU2jc9dZVa7PSUw5lE0ncLu Z3qeAfql+3fuW0jDAHwR1EvkUCY8WI/FmtyG6OX2wpTFwWOXgSGjy2odHECLC7YFjjIw L7pnn5HdZgn/v3Ru1F7RGrYW1c/UQgx1K83wSx2cG+XUGZelVkHJQIh/GpfVIGMT8lf0 bPIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s200si1172442oie.188.2020.03.19.08.42.36; Thu, 19 Mar 2020 08:42:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727476AbgCSPlf (ORCPT + 99 others); Thu, 19 Mar 2020 11:41:35 -0400 Received: from inva020.nxp.com ([92.121.34.13]:41424 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbgCSPlM (ORCPT ); Thu, 19 Mar 2020 11:41:12 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 50FB81A00E0; Thu, 19 Mar 2020 16:41:10 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 425061A00C6; Thu, 19 Mar 2020 16:41:10 +0100 (CET) Received: from fsr-ub1864-111.ea.freescale.net (fsr-ub1864-111.ea.freescale.net [10.171.82.141]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id E0DD3205C2; Thu, 19 Mar 2020 16:41:09 +0100 (CET) From: Diana Craciun To: linux-kernel@vger.kernel.org, laurentiu.tudor@nxp.com, stuyoder@gmail.com, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, bharatb.yadav@gmail.com Cc: Bharat Bhushan , Diana Craciun Subject: [PATCH 03/10] bus/fsl-mc: add support for 'driver_override' in the mc-bus Date: Thu, 19 Mar 2020 17:40:44 +0200 Message-Id: <20200319154051.30609-4-diana.craciun@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319154051.30609-1-diana.craciun@oss.nxp.com> References: <20200319154051.30609-1-diana.craciun@oss.nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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: Bharat Bhushan Signed-off-by: Laurentiu Tudor Signed-off-by: Diana Craciun --- drivers/bus/fsl-mc/fsl-mc-bus.c | 54 +++++++++++++++++++++++++++++++++ include/linux/fsl/mc.h | 1 + 2 files changed, 55 insertions(+) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index c78d10ea641f..baf8259262a9 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -3,6 +3,7 @@ * Freescale Management Complex (MC) bus driver * * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. + * Copyright 2019-2020 NXP * Author: German Rivera * */ @@ -83,6 +84,12 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv) struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); bool found = false; + /* 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; @@ -147,8 +154,52 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(modalias); +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 >= (PAGE_SIZE - 1)) + 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 snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override); +} +static DEVICE_ATTR_RW(driver_override); + static struct attribute *fsl_mc_dev_attrs[] = { &dev_attr_modalias.attr, + &dev_attr_driver_override.attr, NULL, }; @@ -704,6 +755,9 @@ EXPORT_SYMBOL_GPL(fsl_mc_device_add); */ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) { + kfree(mc_dev->driver_override); + mc_dev->driver_override = NULL; + /* * The device-specific remove callback will get invoked by device_del() */ diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h index 54d9436600c7..88095fd30c80 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -194,6 +194,7 @@ struct fsl_mc_device { struct fsl_mc_device_irq **irqs; struct fsl_mc_resource *resource; struct device_link *consumer_link; + const char *driver_override; }; #define to_fsl_mc_device(_dev) \ -- 2.17.1