From patchwork Thu Mar 9 15:35:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9613581 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 68EEB604D9 for ; Thu, 9 Mar 2017 15:37:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48AA928676 for ; Thu, 9 Mar 2017 15:37:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D79528679; Thu, 9 Mar 2017 15:37:08 +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 C906C28677 for ; Thu, 9 Mar 2017 15:37:07 +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=dGt7L0BZ6fMMVelHoksJoFxdEf7p7A32NkzbFWk7hnI=; b=GGSToIamqYgx6X3ArlebqbCNTK 6wz4JrNR/PHHOHlqiw82q4gMSCN2tU7xc1x2G2Ha1kKiUaRRBRiz1GUMJ3J46O2QCQiAj/WGw6gT9 LSTWwuHyKETHlm5/sMkUm54ppfcnSfSTAtpTN1w/k4g2F27NfH4pSmnsXW0JgeG2Cjk8JCF8szQLt rXQA137gx3LVi2yoeQnhRSLl3RE86blx6kNDo+ArBE0npDzGz3/pzqkMUDqfH5ZvLry4eqL+4SyO2 KSUFKdgaMvHjYQ2L9pSJ4/A3HpgTQlaMTuMSPFMwpm1h1kXTKsIkbZ1ZDwYtD+E7usz8WkrG5e4ES WnQBbVQA==; 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 1cm07n-0007OL-GM; Thu, 09 Mar 2017 15:37:07 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cm07L-00078U-4Y for linux-arm-kernel@lists.infradead.org; Thu, 09 Mar 2017 15:36:40 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6B5C0607BB; Thu, 9 Mar 2017 15:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1489073779; bh=Qy0PFRFY0iKqiByGUkK8sOydJPotF+by6UPZVzVZVS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QuUAdXsqAuUwQR+8vmgXcaSjPM+/Hdh9jOnDsOPtqgIhGR6zELHFcHvrpRkJ6bc8U wU6si0eoaEsuTiBsv2sLJCIrfbFOL0sWNMQE6Pn31cEoM0n2nvFG/BytVYYdYpd/+n 3wa41OSq3ymsF1xp5JaGqoWOUPaSNOHLo2/f4A6Y= 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 9D23C607B8; Thu, 9 Mar 2017 15:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1489073778; bh=Qy0PFRFY0iKqiByGUkK8sOydJPotF+by6UPZVzVZVS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NM4TnE+BRrHIAxTplAC1MZiH875SDN1EFLJvPd1Yq8XlavQ8fz+N+qqElCVQITyL6 fXogh7oOww2j0XleM3Ggf+v3Z1JuME4g0l/3c6miNmfGjn5+TdupaKE++/pZRqDL7B JvOAfFpTA07mb5Sb9d3TNg5m2CM+vasod1czcxcg= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9D23C607B8 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 1/5] iommu/arm-smmu: Add pm_runtime/sleep ops Date: Thu, 9 Mar 2017 21:05:44 +0530 Message-Id: <1489073748-3659-2-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_073639_260751_C764844E X-CRM114-Status: GOOD ( 17.33 ) 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 needs to be functional only when the respective master's using it are active. The device_link feature helps to track such functional dependencies, so that the iommu gets powered when the master device enables itself using pm_runtime. So by adapting the smmu driver for runtime pm, above said dependency can be addressed. This patch adds the pm runtime/sleep callbacks to the driver and also the functions to parse the smmu clocks from DT and enable them in resume/suspend. Signed-off-by: Sricharan R --- drivers/iommu/arm-smmu.c | 74 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index abf6496..f7e11d3 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -340,6 +341,13 @@ struct arm_smmu_master_cfg { #define for_each_cfg_sme(fw, i, idx) \ for (i = 0; idx = fwspec_smendx(fw, i), i < fw->num_ids; ++i) +struct arm_smmu_clks { + void *clks; + int (*init_clocks)(struct arm_smmu_device *smmu); + int (*enable_clocks)(struct arm_smmu_device *smmu); + void (*disable_clocks)(struct arm_smmu_device *smmu); +}; + struct arm_smmu_device { struct device *dev; @@ -387,7 +395,7 @@ struct arm_smmu_device { u32 num_global_irqs; u32 num_context_irqs; unsigned int *irqs; - + struct arm_smmu_clks smmu_clks; u32 cavium_id_base; /* Specific to Cavium */ /* IOMMU core code handle */ @@ -1958,16 +1966,24 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) struct arm_smmu_match_data { enum arm_smmu_arch_version version; enum arm_smmu_implementation model; + struct arm_smmu_clks smmu_clks; }; -#define ARM_SMMU_MATCH_DATA(name, ver, imp) \ -static struct arm_smmu_match_data name = { .version = ver, .model = imp } - -ARM_SMMU_MATCH_DATA(smmu_generic_v1, ARM_SMMU_V1, GENERIC_SMMU); -ARM_SMMU_MATCH_DATA(smmu_generic_v2, ARM_SMMU_V2, GENERIC_SMMU); -ARM_SMMU_MATCH_DATA(arm_mmu401, ARM_SMMU_V1_64K, GENERIC_SMMU); -ARM_SMMU_MATCH_DATA(arm_mmu500, ARM_SMMU_V2, ARM_MMU500); -ARM_SMMU_MATCH_DATA(cavium_smmuv2, ARM_SMMU_V2, CAVIUM_SMMUV2); +#define ARM_SMMU_MATCH_DATA(name, ver, imp, init, enable, disable) \ +static struct arm_smmu_match_data name = { .version = ver, .model = imp, \ + .smmu_clks.init_clocks = init, \ + .smmu_clks.enable_clocks = enable, \ + .smmu_clks.disable_clocks = disable } + +ARM_SMMU_MATCH_DATA(smmu_generic_v1, ARM_SMMU_V1, GENERIC_SMMU, + NULL, NULL, NULL); +ARM_SMMU_MATCH_DATA(smmu_generic_v2, ARM_SMMU_V2, GENERIC_SMMU, + NULL, NULL, NULL); +ARM_SMMU_MATCH_DATA(arm_mmu401, ARM_SMMU_V1_64K, GENERIC_SMMU, + NULL, NULL, NULL); +ARM_SMMU_MATCH_DATA(arm_mmu500, ARM_SMMU_V2, ARM_MMU500, NULL, NULL, NULL); +ARM_SMMU_MATCH_DATA(cavium_smmuv2, ARM_SMMU_V2, CAVIUM_SMMUV2, + NULL, NULL, NULL); static const struct of_device_id arm_smmu_of_match[] = { { .compatible = "arm,smmu-v1", .data = &smmu_generic_v1 }, @@ -2054,6 +2070,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev, data = of_device_get_match_data(dev); smmu->version = data->version; smmu->model = data->model; + smmu->smmu_clks = data->smmu_clks; parse_driver_options(smmu); @@ -2135,6 +2152,13 @@ static int arm_smmu_device_probe(struct platform_device *pdev) smmu->irqs[i] = irq; } + if (smmu->smmu_clks.init_clocks) { + err = smmu->smmu_clks.init_clocks(smmu); + if (err) + return err; + } + + pm_runtime_enable(dev); err = arm_smmu_device_cfg_probe(smmu); if (err) return err; @@ -2211,10 +2235,42 @@ static int arm_smmu_device_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int arm_smmu_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct arm_smmu_device *smmu = platform_get_drvdata(pdev); + int ret = 0; + + if (smmu->smmu_clks.enable_clocks) + ret = smmu->smmu_clks.enable_clocks(smmu); + + return ret; +} + +static int arm_smmu_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct arm_smmu_device *smmu = platform_get_drvdata(pdev); + + if (smmu->smmu_clks.disable_clocks) + smmu->smmu_clks.disable_clocks(smmu); + + return 0; +} +#endif + +static const struct dev_pm_ops arm_smmu_pm_ops = { + SET_RUNTIME_PM_OPS(arm_smmu_suspend, arm_smmu_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) +}; + static struct platform_driver arm_smmu_driver = { .driver = { .name = "arm-smmu", .of_match_table = of_match_ptr(arm_smmu_of_match), + .pm = &arm_smmu_pm_ops, }, .probe = arm_smmu_device_probe, .remove = arm_smmu_device_remove,