From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x224f5d13emct1io4o54l/6ZNH2/VZI1qQ6/VT/qmcgcOS1oqyT7h/HDOcKCwouBuje24G2ao ARC-Seal: i=1; a=rsa-sha256; t=1517401428; cv=none; d=google.com; s=arc-20160816; b=jQbBLCFHhVlm3Vg/inrjEaOqPQBLTXCeBDQbL7BKlqKGCz48Y247v/FCIgXjd5y3Wz DGILcEqdkzmlJ/g0VGXS5/ONTPo/x5Ue3hxwinC/9WZP2rvsH3gfKICGgLAqgVGURtJG DCwoi64KF1sB56RDPfGHabbFDRDUQF6VM5QSyY8ZdGfkamOlwsJNDdA+jYoF3+Rpg6pW jQ32j6u2iuhziduSmB/CNQ6vp32eveuWGxpN7MbGO/BpQxOLsP6Q6zbdq503/SkIi1S0 BhAnlUnfQLDY6H0Lc8CHJf5//HR1HOOOjpbI0HijMmyMx5gBHq7s4PcRyShQ0PsMswn/ ypew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :arc-authentication-results; bh=TQeH9Zu780Qxyat9Uo3xchE4l7Ymv78UTBWHir8UEtc=; b=teBWoetv5I0KL0wZQ+dqi/PPhrTDmHVeUMLGSg8S9PVqnSyoM1AkQq8ytedFGfG13D Qn61vNR6pCFlaBx4b23lmVtgtGUhqYrjuMEV3L+7alEMxs7FI5xx5JetBR1U26riQ/RF GUF+tPnliarILQFAdqazJQAFFRIdEL+6bJvDS7hraonRE6p/WOAjIGOsMMszJdpRcBQ1 gGcJF+jRrQkDS2n3yd2iwQDAziX7sL7yVTEWdkargqN7Ws7KkinBGAeuk09+U3AwDzT6 Fecv0OHXTcckp4AZUQCZC18buRp/9b59puJX1WeL8OzcCvNAdmOd7VBB5sUYORKFmeX9 kflQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of robin.murphy@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=robin.murphy@arm.com Authentication-Results: mx.google.com; spf=pass (google.com: domain of robin.murphy@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=robin.murphy@arm.com Subject: Re: [PATCH v6 2/6] iommu/arm-smmu: Add pm_runtime/sleep ops To: Vivek Gautam , alex.williamson@redhat.com, robh+dt@kernel.org, mark.rutland@arm.com, rjw@rjwysocki.net, will.deacon@arm.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, sboyd@codeaurora.org Cc: gregkh@linuxfoundation.org, sricharan@codeaurora.org, m.szyprowski@samsung.com, architt@codeaurora.org, linux-arm-msm@vger.kernel.org References: <1516362223-22946-1-git-send-email-vivek.gautam@codeaurora.org> <1516362223-22946-3-git-send-email-vivek.gautam@codeaurora.org> From: Robin Murphy Message-ID: <9942b74d-7437-21cc-cbd7-38f2844c5d1d@arm.com> Date: Wed, 31 Jan 2018 12:23:43 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1516362223-22946-3-git-send-email-vivek.gautam@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590021062654092311?= X-GMAIL-MSGID: =?utf-8?q?1591110720305214112?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On 19/01/18 11:43, Vivek Gautam wrote: > From: Sricharan R > > 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 > Signed-off-by: Archit Taneja > [vivek: Clock rework to request bulk of clocks] > Signed-off-by: Vivek Gautam > --- > drivers/iommu/arm-smmu.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 53 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c > index 78d4c6b8f1ba..21acffe91a1c 100644 > --- a/drivers/iommu/arm-smmu.c > +++ b/drivers/iommu/arm-smmu.c > @@ -48,6 +48,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -205,6 +206,9 @@ struct arm_smmu_device { > u32 num_global_irqs; > u32 num_context_irqs; > unsigned int *irqs; > + struct clk_bulk_data *clocks; > + int num_clks; > + const char * const *clk_names; This seems unnecessary, as we use it a grand total of of once, during initialisation when we have the source data directly to hand. Just pass data->clks into arm_smmu_init_clks() as an additional argument. Otherwise, I think this looks reasonable; it's about as unobtrusive as it's going to get. Robin. > u32 cavium_id_base; /* Specific to Cavium */ > > @@ -1685,6 +1689,25 @@ static int arm_smmu_id_size_to_bits(int size) > } > } > > +static int arm_smmu_init_clocks(struct arm_smmu_device *smmu) > +{ > + int i; > + int num = smmu->num_clks; > + > + if (num < 1) > + return 0; > + > + smmu->clocks = devm_kcalloc(smmu->dev, num, > + sizeof(*smmu->clocks), GFP_KERNEL); > + if (!smmu->clocks) > + return -ENOMEM; > + > + for (i = 0; i < num; i++) > + smmu->clocks[i].id = smmu->clk_names[i]; > + > + return devm_clk_bulk_get(smmu->dev, num, smmu->clocks); > +} > + > static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) > { > unsigned long size; > @@ -1897,10 +1920,12 @@ 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; > + const char * const *clks; > + int num_clks; > }; > > #define ARM_SMMU_MATCH_DATA(name, ver, imp) \ > -static struct arm_smmu_match_data name = { .version = ver, .model = imp } > +static const 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); > @@ -2001,6 +2026,8 @@ 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->clk_names = data->clks; > + smmu->num_clks = data->num_clks; > > parse_driver_options(smmu); > > @@ -2099,6 +2126,10 @@ static int arm_smmu_device_probe(struct platform_device *pdev) > smmu->irqs[i] = irq; > } > > + err = arm_smmu_init_clocks(smmu); > + if (err) > + return err; > + > err = arm_smmu_device_cfg_probe(smmu); > if (err) > return err; > @@ -2197,7 +2228,27 @@ static int __maybe_unused arm_smmu_pm_resume(struct device *dev) > return 0; > } > > -static SIMPLE_DEV_PM_OPS(arm_smmu_pm_ops, NULL, arm_smmu_pm_resume); > +static int __maybe_unused arm_smmu_runtime_resume(struct device *dev) > +{ > + struct arm_smmu_device *smmu = dev_get_drvdata(dev); > + > + return clk_bulk_prepare_enable(smmu->num_clks, smmu->clocks); > +} > + > +static int __maybe_unused arm_smmu_runtime_suspend(struct device *dev) > +{ > + struct arm_smmu_device *smmu = dev_get_drvdata(dev); > + > + clk_bulk_disable_unprepare(smmu->num_clks, smmu->clocks); > + > + return 0; > +} > + > +static const struct dev_pm_ops arm_smmu_pm_ops = { > + SET_SYSTEM_SLEEP_PM_OPS(NULL, arm_smmu_pm_resume) > + SET_RUNTIME_PM_OPS(arm_smmu_runtime_suspend, > + arm_smmu_runtime_resume, NULL) > +}; > > static struct platform_driver arm_smmu_driver = { > .driver = { >