From patchwork Thu Feb 2 17:10:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9552581 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 08FE2602F0 for ; Thu, 2 Feb 2017 17:10:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2CA81FFC9 for ; Thu, 2 Feb 2017 17:10:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E794F28499; Thu, 2 Feb 2017 17:10:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A32E1FFC9 for ; Thu, 2 Feb 2017 17:10:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752095AbdBBRKp (ORCPT ); Thu, 2 Feb 2017 12:10:45 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:38380 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176AbdBBRKm (ORCPT ); Thu, 2 Feb 2017 12:10:42 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0E82D60C18; Thu, 2 Feb 2017 17:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1486055441; bh=hmn/ptzF3C6Djx25z3EBF6EqxpIFy4A6lGO14owY5fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZTKOxRrIpxHKkkPTo7Z+RT6OgSxgaBfqnBuY1w7LG26NmSUI8LDUDde+GCFjzeua+ fPJAWolySZ7A+yM8B9iKO663eXdM1l9zr6GqV/jWyH2sNg1nXPUm/3daxpT5rY8t3k FzLTlTS61vexSLUwDUu0mWtlBRkJ1UXfGC6TjB9g= Received: from blr-ubuntu-32.ap.qualcomm.com (unknown [202.46.23.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sricharan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C064160B68; Thu, 2 Feb 2017 17:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1486055439; bh=hmn/ptzF3C6Djx25z3EBF6EqxpIFy4A6lGO14owY5fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SEzfLraGSdACkOuYMMf5g7WdGPunmkQN3MhmL11y9Myr7tIpoCk8FsFBG3hLPbVaN adurARHtz6QqpGi659z73okhWFuEANQRgmW6RYtVkLGbVpEG5Tpb36aCY8vvqB0FI0 rZK6MmaXOdpL0BMZrzmSAe+8uc2LWAgFSFVz3Gm4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C064160B68 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sricharan@codeaurora.org From: Sricharan R To: robin.murphy@arm.com, will.deacon@arm.com, joro@8bytes.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, m.szyprowski@samsung.com, sboyd@codeaurora.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mathieu.poirier@linaro.org Cc: sricharan@codeaurora.org Subject: [PATCH V2 2/3] iommu/arm-smmu: Invoke pm_runtime during probe, add/remove device Date: Thu, 2 Feb 2017 22:40:19 +0530 Message-Id: <1486055420-19671-3-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1486055420-19671-1-git-send-email-sricharan@codeaurora.org> References: <1486055420-19671-1-git-send-email-sricharan@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The smmu device probe/remove and add/remove master device callbacks gets called when the smmu is not linked to its master, that is without the context of the master device. So calling runtime apis in those places separately. Signed-off-by: Sricharan R --- drivers/iommu/arm-smmu.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index cd2e3db..5170523 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1021,11 +1021,15 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain) struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_cfg *cfg = &smmu_domain->cfg; void __iomem *cb_base; - int irq; + int irq, ret; if (!smmu) return; + ret = pm_runtime_get_sync(smmu->dev); + if (ret) + dev_warn(smmu->dev, "runtime resume failed"); + /* * Disable the context bank and free the page tables before freeing * it. @@ -1040,6 +1044,10 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain) free_io_pgtable_ops(smmu_domain->pgtbl_ops); __arm_smmu_free_bitmap(smmu->context_map, cfg->cbndx); + + ret = pm_runtime_put_sync(smmu->dev); + if (ret) + dev_warn(smmu->dev, "runtime suspend failed"); } static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) @@ -1508,10 +1516,18 @@ static int arm_smmu_add_device(struct device *dev) while (i--) cfg->smendx[i] = INVALID_SMENDX; + ret = pm_runtime_get_sync(smmu->dev); + if (ret) + goto out_free; + ret = arm_smmu_master_alloc_smes(dev); if (ret) goto out_free; + ret = pm_runtime_put_sync(smmu->dev); + if (ret) + goto out_free; + return 0; out_free: @@ -1524,11 +1540,27 @@ static int arm_smmu_add_device(struct device *dev) static void arm_smmu_remove_device(struct device *dev) { struct iommu_fwspec *fwspec = dev->iommu_fwspec; + struct arm_smmu_device *smmu = fwspec_smmu(fwspec); + int ret; if (!fwspec || fwspec->ops != &arm_smmu_ops) return; + /* + * The device link between the master device and + * smmu is already purged at this point. + * So enable the power to smmu explicitly. + */ + + ret = pm_runtime_get_sync(smmu->dev); + if (ret) + dev_warn(smmu->dev, "runtime resume failed"); + arm_smmu_master_free_smes(fwspec); + + ret = pm_runtime_put_sync(smmu->dev); + if (ret) + dev_warn(smmu->dev, "runtime suspend failed"); iommu_group_remove_device(dev); kfree(fwspec->iommu_priv); iommu_fwspec_free(dev); @@ -2190,7 +2222,12 @@ static int arm_smmu_device_probe(struct platform_device *pdev) if (err) return err; + platform_set_drvdata(pdev, smmu); pm_runtime_enable(dev); + err = pm_runtime_get_sync(dev); + if (err) + return err; + err = arm_smmu_device_cfg_probe(smmu); if (err) return err; @@ -2217,9 +2254,11 @@ static int arm_smmu_device_probe(struct platform_device *pdev) } iommu_register_instance(dev->fwnode, &arm_smmu_ops); - platform_set_drvdata(pdev, smmu); arm_smmu_device_reset(smmu); arm_smmu_test_smr_masks(smmu); + err = pm_runtime_put_sync(dev); + if (err) + return err; /* Oh, for a proper bus abstraction */ if (!iommu_present(&platform_bus_type)) @@ -2249,6 +2288,8 @@ static int arm_smmu_device_remove(struct platform_device *pdev) /* Turn the thing off */ writel(sCR0_CLIENTPD, ARM_SMMU_GR0_NS(smmu) + ARM_SMMU_GR0_sCR0); + pm_runtime_force_suspend(smmu->dev); + return 0; }