Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp784773ybg; Thu, 19 Mar 2020 08:42:41 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtMXjrIslF3C+qh6evrF4uFqwDbhrhfni8LWdITTRvUGkTAtN39iI7MuEaF5Vs3HK2ywR6x X-Received: by 2002:aca:4fc7:: with SMTP id d190mr2878171oib.100.1584632561801; Thu, 19 Mar 2020 08:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584632561; cv=none; d=google.com; s=arc-20160816; b=hiCST8K0FlqCzOdM2N6BRMI7o9Jgzvv7UbC9uXuH1ReRxmXlAqsZ/3/lh+SBW1tPy0 IKeTKiy7uMdCWEmffKc0e+M0rzgUZFeXBrmyJYLjTZyc7ezBPZrMSzXXwxgt3u+s5dCs 6l6Bbp+EzwQGLlxbxgPeViiq7p7IkRjgjGOeE3sfmcElGFzVyiiYJZ9JYH3TVkKyJxWf XLGfPqQDjEJ5NqKTDMkAYQk3PF+a03vgDpfYqANHqyQot7VT75jlsUW9yqlxFV+js5P4 f1btlPbrRxJ88JYJsUxGwAHy68FWFjCiPVqESb1ppUiGyz86rAC5Kchh0SvdW2TILA2D SiqA== 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=jifwEYistL+xFd3De8UtfB/j3toP9hDtTk48up8yqrk=; b=Bh+77Y988d5wpugBorPFjFV4AspimpHnHIYIBwK3hg/KaF5SDE1Cbvd7TbF4XKBubS YWitH7XRrp+TDrAHUmSCt2K7M4MF9od5KVuTWBS9W1yHtb/vElC0kKLi64xrHrAY4gWK UVuI1aq9eC6fqDjSjNEoOQlvCcSaNZI36rarbXAXCik/BaAFlOMcW7rXOXf1EmMqA1I/ cOEfYuv03yeZZsUFXXA+k0haVa3sH7ZChA/x0oiyrqIpmtzoGkNDNp93gOrRVmyFFyuR rRVm5aF8aKaBaEebV//i8gJyaS1Xx4WownQK7iA/I1GJYjSn64Hi+X5oFRmrnVlUBO7p 6YwA== 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 z10si1421960otq.214.2020.03.19.08.42.28; Thu, 19 Mar 2020 08:42:41 -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 S1728250AbgCSPlU (ORCPT + 99 others); Thu, 19 Mar 2020 11:41:20 -0400 Received: from inva020.nxp.com ([92.121.34.13]:41470 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728165AbgCSPlO (ORCPT ); Thu, 19 Mar 2020 11:41:14 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id EB0CF1A0113; Thu, 19 Mar 2020 16:41:12 +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 DEB5E1A010E; Thu, 19 Mar 2020 16:41:12 +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 91415205C2; Thu, 19 Mar 2020 16:41:12 +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: Diana Craciun Subject: [PATCH 09/10] bus/fsl-mc: Add a container setup function Date: Thu, 19 Mar 2020 17:40:50 +0200 Message-Id: <20200319154051.30609-10-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 Both DPRC driver and VFIO driver use a initialization code for the DPRC. Introduced a new function which groups this initialization code. The function is exported and may be used by VFIO as well. Signed-off-by: Diana Craciun --- drivers/bus/fsl-mc/dprc-driver.c | 77 +++++++++++++++++++++----------- drivers/bus/fsl-mc/mc-io.c | 7 ++- include/linux/fsl/mc.h | 2 + 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c index a655e3fee291..0fe45c301858 100644 --- a/drivers/bus/fsl-mc/dprc-driver.c +++ b/drivers/bus/fsl-mc/dprc-driver.c @@ -570,16 +570,15 @@ static int dprc_setup_irq(struct fsl_mc_device *mc_dev) } /** - * dprc_probe - callback invoked when a DPRC is being bound to this driver + * dprc_setup - opens and creates a mc_io for DPRC * * @mc_dev: Pointer to fsl-mc device representing a DPRC * * It opens the physical DPRC in the MC. - * It scans the DPRC to discover the MC objects contained in it. - * It creates the interrupt pool for the MC bus associated with the DPRC. - * It configures the interrupts for the DPRC device itself. + * It configures the DPRC portal used to communicate with MC */ -static int dprc_probe(struct fsl_mc_device *mc_dev) + +int dprc_setup(struct fsl_mc_device *mc_dev) { int error; size_t region_size; @@ -589,12 +588,6 @@ static int dprc_probe(struct fsl_mc_device *mc_dev) bool msi_domain_set = false; u16 major_ver, minor_ver; - if (!is_fsl_mc_bus_dprc(mc_dev)) - return -EINVAL; - - if (dev_get_msi_domain(&mc_dev->dev)) - return -EINVAL; - if (!mc_dev->mc_io) { /* * This is a child DPRC: @@ -678,35 +671,69 @@ static int dprc_probe(struct fsl_mc_device *mc_dev) goto error_cleanup_open; } + return 0; + +error_cleanup_open: + (void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); + +error_cleanup_msi_domain: + if (msi_domain_set) + dev_set_msi_domain(&mc_dev->dev, NULL); + + if (mc_io_created) { + fsl_destroy_mc_io(mc_dev->mc_io); + mc_dev->mc_io = NULL; + } + + return error; +} +EXPORT_SYMBOL_GPL(dprc_setup); + +/** + * dprc_probe - callback invoked when a DPRC is being bound to this driver + * + * @mc_dev: Pointer to fsl-mc device representing a DPRC + * + * It opens the physical DPRC in the MC. + * It scans the DPRC to discover the MC objects contained in it. + * It creates the interrupt pool for the MC bus associated with the DPRC. + * It configures the interrupts for the DPRC device itself. + */ +static int dprc_probe(struct fsl_mc_device *mc_dev) +{ + int error; + + if (!is_fsl_mc_bus_dprc(mc_dev)) + return -EINVAL; + + if (dev_get_msi_domain(&mc_dev->dev)) + return -EINVAL; + + error = dprc_setup(mc_dev); + if (error < 0) + return error; + /* * Discover MC objects in DPRC object: */ error = dprc_scan_container(mc_dev, NULL, true); if (error < 0) - goto error_cleanup_open; + goto dprc_cleanup; /* * Configure interrupt for the DPRC object associated with this MC bus: */ error = dprc_setup_irq(mc_dev); if (error < 0) - goto error_cleanup_open; + goto scan_cleanup; dev_info(&mc_dev->dev, "DPRC device bound to driver"); return 0; -error_cleanup_open: - (void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); - -error_cleanup_msi_domain: - if (msi_domain_set) - dev_set_msi_domain(&mc_dev->dev, NULL); - - if (mc_io_created) { - fsl_destroy_mc_io(mc_dev->mc_io); - mc_dev->mc_io = NULL; - } - +scan_cleanup: + device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); +dprc_cleanup: + dprc_cleanup(mc_dev); return error; } diff --git a/drivers/bus/fsl-mc/mc-io.c b/drivers/bus/fsl-mc/mc-io.c index 6ae48ad80409..e1dfe4a76519 100644 --- a/drivers/bus/fsl-mc/mc-io.c +++ b/drivers/bus/fsl-mc/mc-io.c @@ -129,7 +129,12 @@ int __must_check fsl_create_mc_io(struct device *dev, */ void fsl_destroy_mc_io(struct fsl_mc_io *mc_io) { - struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; + struct fsl_mc_device *dpmcp_dev; + + if (!mc_io) + return; + + dpmcp_dev = mc_io->dpmcp_dev; if (dpmcp_dev) fsl_mc_io_unset_dpmcp(mc_io); diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h index e3ba273a1122..59b39c635ec9 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -480,6 +480,8 @@ int dprc_scan_container(struct fsl_mc_device *mc_bus_dev, const char *driver_override, bool alloc_interrupts); +int dprc_setup(struct fsl_mc_device *mc_dev); + int dprc_cleanup(struct fsl_mc_device *mc_dev); /* -- 2.17.1