From patchwork Thu Mar 9 15:35:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9613587 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 20595604D9 for ; Thu, 9 Mar 2017 15:38:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0068D2867B for ; Thu, 9 Mar 2017 15:38:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8EC42867F; Thu, 9 Mar 2017 15:38:42 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F16FF2867B for ; Thu, 9 Mar 2017 15:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pyGm3NDUI1Ba1zxmukJWsX2ydIiw/X3a5xT39b5cUwQ=; b=PmfXL+WEkvOhXfX9ebWnFKTtYr BHoFIi6xPuKFcG2GscTzNiUwG0nsxX3bPzv5BuAj4uB3LefiF1N7C8pRmAOgBI1xG1zkvh5fNijM+ P248YB4hEvmaxTc6knHfZLWQrvze00CpCwDf475mDiFU3FT75C/FWuzCR7pp3qYDtUwh8mqylAyVA W3Jm57kEVmo2uBsPFA2ZRuNAOXhtd1GH9PIfQLtenXIvYmd1j/Tysk++k5xxzSfif1TxnnHqEh8yo y8grC1nt4eaTm0HO6lQhOfKZDsfKLS086n3qYjYDUbVrfrQ+iBoZ5JN7ZPK7+xchHGM68WBn2KGyl zGiJSvZQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cm09G-00007p-Pf; Thu, 09 Mar 2017 15:38:38 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cm07a-0007A4-4I for linux-arm-kernel@lists.infradead.org; Thu, 09 Mar 2017 15:36:56 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 873D4607E5; Thu, 9 Mar 2017 15:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1489073796; bh=VEKEKaxiOXATr/czZ+ENa2nJLThgl3Iiq12nohChwCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VaeYOPP/MC91nLFnqn7sNgEeZUIkJUwOBSSnfwQU5VEb2551HWqYkLRzBf/A5oPJl MBpo7RQuij8tODFnak1JF4iL4VWThG5VjE7Vz8e3xKFI2yRG2/g0m1b5OecZ73FHep 0mTjclcbuYgdfxm10X7JrkCwg6JImMTN9sHlCv/I= 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 EDA8D6085E; Thu, 9 Mar 2017 15:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1489073793; bh=VEKEKaxiOXATr/czZ+ENa2nJLThgl3Iiq12nohChwCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ik5kr1e7w/XstVy0C+lZDK9yANRsFPHGI1DStGvaib6k4xw0hQvxd1SmAMktF1NlN YqrjndIbJFsHtamCcrluxq8vKYL69Xrf+WX5z5u1q/9Pva3cEmdzj3NZJ3QQ4v0nqG eVjzUHF2pUyOyIktbVCpZIWJmcAuVc58+Ekfv3F0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org EDA8D6085E 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, linux-clk@vger.kernel.org, sboyd@codeaurora.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mathieu.poirier@linaro.org, mark.rutland@arm.com Subject: [PATCH V3 4/5] iommu/arm-smmu: Invoke pm_runtime during probe, add/remove device Date: Thu, 9 Mar 2017 21:05:47 +0530 Message-Id: <1489073748-3659-5-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1489073748-3659-1-git-send-email-sricharan@codeaurora.org> References: <1489073748-3659-1-git-send-email-sricharan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170309_073654_216731_526AAC44 X-CRM114-Status: GOOD ( 15.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sricharan@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index f29e28bf..6370421 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1216,11 +1216,16 @@ 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; + unsigned long ret; int irq; if (!smmu) return; + ret = pm_runtime_get_sync(smmu->dev); + if (IS_ERR_VALUE(ret)) + dev_warn(smmu->dev, "runtime resume failed"); + /* * Disable the context bank and free the page tables before freeing * it. @@ -1235,6 +1240,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 (IS_ERR_VALUE(ret)) + dev_warn(smmu->dev, "runtime suspend failed"); } static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) @@ -1663,6 +1672,7 @@ static int arm_smmu_add_device(struct device *dev) struct arm_smmu_master_cfg *cfg; struct iommu_fwspec *fwspec = dev->iommu_fwspec; int i, ret; + unsigned long err; if (using_legacy_binding) { ret = arm_smmu_register_legacy_master(dev, &smmu); @@ -1703,12 +1713,20 @@ static int arm_smmu_add_device(struct device *dev) while (i--) cfg->smendx[i] = INVALID_SMENDX; + err = pm_runtime_get_sync(smmu->dev); + if (IS_ERR_VALUE(err)) + goto out_free; + ret = arm_smmu_master_alloc_smes(dev); if (ret) goto out_free; iommu_device_link(&smmu->iommu, dev); + err = pm_runtime_put_sync(smmu->dev); + if (IS_ERR_VALUE(err)) + goto out_free; + return 0; out_free: @@ -1723,7 +1741,7 @@ static void arm_smmu_remove_device(struct device *dev) struct iommu_fwspec *fwspec = dev->iommu_fwspec; struct arm_smmu_master_cfg *cfg; struct arm_smmu_device *smmu; - + unsigned long ret; if (!fwspec || fwspec->ops != &arm_smmu_ops) return; @@ -1731,8 +1749,23 @@ static void arm_smmu_remove_device(struct device *dev) cfg = fwspec->iommu_priv; smmu = cfg->smmu; + /* + * 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 (IS_ERR_VALUE(ret)) + dev_warn(smmu->dev, "runtime resume failed"); + iommu_device_unlink(&smmu->iommu, dev); arm_smmu_master_free_smes(fwspec); + + ret = pm_runtime_put_sync(smmu->dev); + if (IS_ERR_VALUE(ret)) + dev_warn(smmu->dev, "runtime suspend failed"); + iommu_group_remove_device(dev); kfree(fwspec->iommu_priv); iommu_fwspec_free(dev); @@ -2316,6 +2349,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) struct arm_smmu_device *smmu; struct device *dev = &pdev->dev; int num_irqs, i, err; + unsigned long ret; smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); if (!smmu) { @@ -2375,7 +2409,12 @@ static int arm_smmu_device_probe(struct platform_device *pdev) return err; } + platform_set_drvdata(pdev, smmu); pm_runtime_enable(dev); + ret = pm_runtime_get_sync(dev); + if (IS_ERR_VALUE(ret)) + return ret; + err = arm_smmu_device_cfg_probe(smmu); if (err) return err; @@ -2417,9 +2456,11 @@ static int arm_smmu_device_probe(struct platform_device *pdev) return err; } - platform_set_drvdata(pdev, smmu); arm_smmu_device_reset(smmu); arm_smmu_test_smr_masks(smmu); + ret = pm_runtime_put_sync(dev); + if (IS_ERR_VALUE(ret)) + return err; /* Oh, for a proper bus abstraction */ if (!iommu_present(&platform_bus_type)) @@ -2449,6 +2490,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; }