Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3516259pxa; Wed, 26 Aug 2020 02:30:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL02BiNGKgQWSFgMUnLlvVt3KUbN2N+az7b3c4auqAygxualmJYiK5tIAwX4wvSnqab69b X-Received: by 2002:a17:906:9ad3:: with SMTP id ah19mr10352400ejc.372.1598434236952; Wed, 26 Aug 2020 02:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598434236; cv=none; d=google.com; s=arc-20160816; b=Eos5hv5Q0kB2DWk913I58IZj8HT25y7+7ySYQ/ywwTezzB8js08wi2+4QGQQpGqCsv Ulb6No3cxuUfEa55DOGomxvZD2M/iPYywmhbQzMEveahUiy+u4xW6dAMuLzFqdwe3OED ICqhv10RnfRsSFDHKATJC2RW64AwhlHBQTWI1nVKcw+9DMaEQS8/hFLlqPAPb3y564Jf DzYij7ybOv6+qHdcBjz0q/uleTlPP3Ae3iPwD1J1QHGO2FlC6zyOQmUNnIulGsu7BREi NHoCt1bOpPO/KiWrdUPhfKo9eIsPaZ65QsjXPQV5IE8qf8TSxU46UBywgoh04Jiam4a7 odXA== 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=6ZYLVXsd9H/13H4CrSoCQoHpoQCiLPI1S6+XGhQwCAQ=; b=KnFJ3kH3+LupgthCUkw4ap0q4+vMwj51Ji6jIXDvRyNckOlc+xQ5jJcOkupfKP9WnJ m8TW9/qtfok1JWoSXeAtyV5araZz/oGKNqGuIPXlPo7j0AvQ7SjKCEMisZYCoEHLiXIG yi3x76jsbBavW2jHOPPdDglyd666N4RqJQfdk451xIq0tlGPgdiwNunqP4KRy6GBEqpy Txgv9hOH0usmuxSBaO9/bEHhXsFf3Pqubw/uB3bVL0HLM8nmi5I64zHg0pAVrfqn6JIE YPiABs9B97KdibJAM76APaSOMlXmZpIG3c69Adnr5Wy21G8FuEP2xxfkB1le03hsFYAv FCQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n12si1151361ejz.288.2020.08.26.02.30.13; Wed, 26 Aug 2020 02:30:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728049AbgHZJ0N (ORCPT + 99 others); Wed, 26 Aug 2020 05:26:13 -0400 Received: from inva021.nxp.com ([92.121.34.21]:43304 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727991AbgHZJ0F (ORCPT ); Wed, 26 Aug 2020 05:26:05 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 767372007C6; Wed, 26 Aug 2020 11:26:03 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 69D432007B4; Wed, 26 Aug 2020 11:26:03 +0200 (CEST) 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 0D5772030A; Wed, 26 Aug 2020 11:26:03 +0200 (CEST) From: Diana Craciun To: linux-kernel@vger.kernel.org, laurentiu.tudor@nxp.com Cc: stuyoder@gmail.com, leoyang.li@nxp.com, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, bharatb.linux@gmail.com, Bharat Bhushan , Diana Craciun Subject: [PATCH v4 03/13] bus/fsl-mc: add support for 'driver_override' in the mc-bus Date: Wed, 26 Aug 2020 12:25:17 +0300 Message-Id: <20200826092527.4992-4-diana.craciun@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200826092527.4992-1-diana.craciun@oss.nxp.com> References: <20200826092527.4992-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 --- The patche do not address the comment regarding moving driver_override in the core code. I prefer not to tie these patches on that change and address that separately. drivers/bus/fsl-mc/fsl-mc-bus.c | 54 +++++++++++++++++++++++++++++++++ include/linux/fsl/mc.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index b69794e7364d..9a884936e53e 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 * */ @@ -78,6 +79,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); + 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, }; @@ -748,6 +799,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 a428c61ead6e..3b5f0c98636d 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -161,6 +161,7 @@ struct fsl_mc_obj_desc { * @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. @@ -194,6 +195,7 @@ struct fsl_mc_device { struct fsl_mc_device_irq **irqs; struct fsl_mc_resource *resource; struct device_link *consumer_link; + char *driver_override; }; #define to_fsl_mc_device(_dev) \ -- 2.17.1