iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@linaro.org>
To: Parikshit Pareek <quic_ppareek@quicinc.com>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Joerg Roedel <joro@8bytes.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>
Cc: Manivannan Sadhasivam <mani@kernel.org>,
	Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
	Marijn Suijten <marijn.suijten@somainline.org>,
	Adam Skladowski <a39.skl@gmail.com>,
	linux-arm-msm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
	devicetree@vger.kernel.org,
	"linux-kernel @ vger . kernel . org Prasanna Kumar"
	<quic_kprasan@quicinc.com>,
	Shazad Hussain <quic_shazhuss@quicinc.com>
Subject: Re: [PATCH 3/3] iommu/arm-smmu-qcom: Add support for the interconnect
Date: Fri, 9 Jun 2023 10:56:43 +0200	[thread overview]
Message-ID: <e8700c76-17db-f0b1-c60b-20bf292f0a85@linaro.org> (raw)
In-Reply-To: <20230609055225.20717-1-quic_ppareek@quicinc.com>

[-- Attachment #1: Type: text/plain, Size: 2106 bytes --]



On 9.06.2023 07:52, Parikshit Pareek wrote:
> Introduce support to detect the interconnect, and set its bandwidth.
> For certain targets, we need to set the bandwidth of interconnect,
> connecting smmu to memory. This is accessed during memory mapped IO
> access to smmu registers, and during page tables walks.
> 
> Reported-by: Eric Chanudet <echanude@redhat.com>
> Signed-off-by: Parikshit Pareek <quic_ppareek@quicinc.com>
> ---
Quite recently, I've been toying with this too.. I coded it in
a way that allows it to be reused by other impls and uses OPP APIs.
Please take a look at the attached patch.

Konrad
>  drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> index c71afda79d64..6961d564869b 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> @@ -8,6 +8,7 @@
>  #include <linux/delay.h>
>  #include <linux/of_device.h>
>  #include <linux/firmware/qcom/qcom_scm.h>
> +#include <linux/interconnect.h>
>  
>  #include "arm-smmu.h"
>  #include "arm-smmu-qcom.h"
> @@ -549,6 +550,8 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu)
>  {
>  	const struct device_node *np = smmu->dev->of_node;
>  	const struct of_device_id *match;
> +	struct icc_path *icc_path;
> +	int ret, icc_bw;
>  
>  #ifdef CONFIG_ACPI
>  	if (np == NULL) {
> @@ -558,6 +561,19 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu)
>  	}
>  #endif
>  
> +	icc_path = devm_of_icc_get(smmu->dev, "tbu_mc");
> +	if (IS_ERR(icc_path))
> +		return (struct arm_smmu_device *)icc_path;
> +
> +	ret = of_property_read_u32(np, "icc_bw", &icc_bw);
> +
> +	/*if interconnect exists, check for the  bandwidth value*/
> +	if (icc_path && !ret) {
> +		ret = icc_set_bw(icc_path, 0, MBps_to_icc(icc_bw));
> +		if (ret)
> +			return ERR_PTR(ret);
> +	}
> +
>  	match = of_match_node(qcom_smmu_impl_of_match, np);
>  	if (match)
>  		return qcom_smmu_create(smmu, match->data);

[-- Attachment #2: 0001-smmu-opp-wip.patch --]
[-- Type: text/x-patch, Size: 2616 bytes --]

From 8112d8f8b9a43178af3b203e3fcf94cbd24510a4 Mon Sep 17 00:00:00 2001
From: Konrad Dybcio <konrad.dybcio@linaro.org>
Date: Tue, 30 May 2023 23:39:56 +0200
Subject: [PATCH] smmu opp wip

---
 drivers/iommu/arm/arm-smmu/arm-smmu.c | 41 ++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index a86acd76c1df..03448bf8ae7e 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -32,6 +32,7 @@
 #include <linux/of_device.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
 #include <linux/ratelimit.h>
 #include <linux/slab.h>
@@ -1970,7 +1971,10 @@ static int arm_smmu_device_dt_probe(struct arm_smmu_device *smmu,
 {
 	const struct arm_smmu_match_data *data;
 	struct device *dev = smmu->dev;
+	struct dev_pm_opp *opp;
 	bool legacy_binding;
+	unsigned int bw = 0;
+	int ret;
 
 	if (of_property_read_u32(dev->of_node, "#global-interrupts", global_irqs))
 		return dev_err_probe(dev, -ENODEV,
@@ -1998,7 +2002,25 @@ static int arm_smmu_device_dt_probe(struct arm_smmu_device *smmu,
 	if (of_dma_is_coherent(dev->of_node))
 		smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK;
 
-	return 0;
+	/* It's fine to omit the OPP table */
+	if (!dev_pm_opp_of_get_opp_desc_node(dev))
+		return 0;
+
+	ret = devm_pm_opp_of_add_table(dev);
+	if (ret)
+		return ret;
+
+	ret = dev_pm_opp_of_find_icc_paths(dev, NULL);
+	if (ret)
+		return ret;
+
+	opp = dev_pm_opp_find_bw_ceil(dev, &bw, 0);
+	if (IS_ERR(opp))
+		return PTR_ERR(opp);
+
+	dev_pm_opp_set_opp(dev, opp);
+
+	return ret;
 }
 
 static void arm_smmu_rmr_install_bypass_smr(struct arm_smmu_device *smmu)
@@ -2224,8 +2246,20 @@ static void arm_smmu_device_remove(struct platform_device *pdev)
 static int __maybe_unused arm_smmu_runtime_resume(struct device *dev)
 {
 	struct arm_smmu_device *smmu = dev_get_drvdata(dev);
+	struct dev_pm_opp *opp;
+	unsigned int bw = 0;
 	int ret;
 
+	if (PTR_ERR(dev_pm_opp_get_opp_table(dev)) < 0)
+		goto skip_opp;
+
+	opp = dev_pm_opp_find_bw_ceil(dev, &bw, 0);
+	if (IS_ERR(opp))
+		return PTR_ERR(opp);
+
+	dev_pm_opp_set_opp(dev, opp);
+
+skip_opp:
 	ret = clk_bulk_enable(smmu->num_clks, smmu->clks);
 	if (ret)
 		return ret;
@@ -2241,6 +2275,11 @@ static int __maybe_unused arm_smmu_runtime_suspend(struct device *dev)
 
 	clk_bulk_disable(smmu->num_clks, smmu->clks);
 
+	if (PTR_ERR(dev_pm_opp_get_opp_table(dev)) < 0)
+		return 0;
+
+	dev_pm_opp_set_opp(dev, NULL);
+
 	return 0;
 }
 
-- 
2.41.0


  reply	other threads:[~2023-06-09  8:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  5:41 [PATCH 0/3] arm64: dts: qcom: sa8775p: Add interconnect to SMMU Parikshit Pareek
2023-06-09  5:41 ` [PATCH 1/3] dt-bindings: arm-smmu: Add interconnect for qcom SMMUs Parikshit Pareek
2023-06-09  8:53   ` Konrad Dybcio
2023-06-09 13:23   ` Krzysztof Kozlowski
2023-06-09  5:41 ` [PATCH 2/3] arm64: dts: qcom: sa8775p: Add interconnect to PCIe SMMU Parikshit Pareek
2023-06-09 13:23   ` Krzysztof Kozlowski
2023-06-09  5:52 ` [PATCH 3/3] iommu/arm-smmu-qcom: Add support for the interconnect Parikshit Pareek
2023-06-09  8:56   ` Konrad Dybcio [this message]
2023-06-09  8:52 ` [PATCH 0/3] arm64: dts: qcom: sa8775p: Add interconnect to SMMU Konrad Dybcio
2023-06-09 12:56   ` Parikshit Pareek
2023-06-09 14:45     ` Robin Murphy
2023-06-09 14:52       ` Konrad Dybcio
2023-06-09 14:56         ` Dmitry Baryshkov
2023-06-09 15:39           ` Robin Murphy
2023-07-12 13:10             ` Shazad Hussain
2023-06-09 15:07         ` Robin Murphy
2023-06-09 15:22           ` Konrad Dybcio
2023-07-19 15:37 ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e8700c76-17db-f0b1-c60b-20bf292f0a85@linaro.org \
    --to=konrad.dybcio@linaro.org \
    --cc=a39.skl@gmail.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=marijn.suijten@somainline.org \
    --cc=quic_kprasan@quicinc.com \
    --cc=quic_ppareek@quicinc.com \
    --cc=quic_shazhuss@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).