Re: [PATCH 3/3] iommu/arm-smmu-qcom: Add support for the interconnect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxxx>
> Signed-off-by: Parikshit Pareek <quic_ppareek@xxxxxxxxxxx>
> ---
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);
From 8112d8f8b9a43178af3b203e3fcf94cbd24510a4 Mon Sep 17 00:00:00 2001
From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxx>
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


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [Linux for Sparc]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux