linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2
@ 2022-11-11 13:55 AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property AngeloGioacchino Del Regno
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

This series adds support for handling "v2" firmware's IOMMU, found
on at least MSM8956 and MSM8976 (some other SoCs also need the same
but I honestly don't remember which ones precisely).

This is strictly required to get functional IOMMUs on these SoCs.

I'm sorry for not performing a much needed schema conversion on
qcom,iommu.txt, but I really didn't have time to do that :-(

This series was tested on Sony Xperia X and X Compact (MSM8956):
ADSP, LPASS, Venus, MSS, MDP and GPU are happy :-)

AngeloGioacchino Del Regno (7):
  dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property
  iommu/qcom: Use the asid read from device-tree if specified
  iommu/qcom: Properly reset the IOMMU context
  iommu/qcom: Index contexts by asid number to allow asid 0
  dt-bindings: iommu: qcom,iommu: Document QSMMU v2 compatibles
  iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts
  dt-bindings: iommu: qcom,iommu: Document MSM8976 compatible

 .../devicetree/bindings/iommu/qcom,iommu.txt  | 11 ++-
 drivers/iommu/arm/arm-smmu/qcom_iommu.c       | 77 +++++++++++++++----
 2 files changed, 69 insertions(+), 19 deletions(-)

-- 
2.38.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  2022-11-14  8:23   ` Krzysztof Kozlowski
  2022-11-11 13:55 ` [PATCH 2/7] iommu/qcom: Use the asid read from device-tree if specified AngeloGioacchino Del Regno
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

Add a new "qcom,ctx-num" property to force an ASID number on IOMMU
contexts where required.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
index 059139abce35..7d4e0a18b08e 100644
--- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
+++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
@@ -46,6 +46,7 @@ to non-secure vs secure interrupt line.
                      for routing of context bank irq's to secure vs non-
                      secure lines.  (Ie. if the iommu contains secure
                      context banks)
+- qcom,ctx-num     : The ASID number associated to the context bank
 
 
 ** Examples:
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/7] iommu/qcom: Use the asid read from device-tree if specified
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 3/7] iommu/qcom: Properly reset the IOMMU context AngeloGioacchino Del Regno
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

As specified in this driver, the context banks are 0x1000 apart but
on some SoCs the context number does not necessarily match this
logic, hence we end up using the wrong ASID: keeping in mind that
this IOMMU implementation relies heavily on SCM (TZ) calls, it is
mandatory that we communicate the right context number.

Since this is all about how context banks are mapped in firmware,
which may be board dependent (as a different firmware version may
eventually change the expected context bank numbers), introduce a
new property "qcom,ctx-num": when found, the ASID will be forced
as read from the devicetree.

When "qcom,ctx-num" is not found, this driver retains the previous
behavior as to avoid breaking older devicetrees or systems that do
not require forcing ASID numbers.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index bfd7b51eb5db..491a8093f3d6 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -551,7 +551,8 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 	 * index into qcom_iommu->ctxs:
 	 */
 	if (WARN_ON(asid < 1) ||
-	    WARN_ON(asid > qcom_iommu->num_ctxs)) {
+	    WARN_ON(asid > qcom_iommu->num_ctxs) ||
+	    WARN_ON(qcom_iommu->ctxs[asid - 1] == NULL)) {
 		put_device(&iommu_pdev->dev);
 		return -EINVAL;
 	}
@@ -638,7 +639,8 @@ static int qcom_iommu_sec_ptbl_init(struct device *dev)
 
 static int get_asid(const struct device_node *np)
 {
-	u32 reg;
+	u32 reg, val;
+	int asid;
 
 	/* read the "reg" property directly to get the relative address
 	 * of the context bank, and calculate the asid from that:
@@ -646,7 +648,17 @@ static int get_asid(const struct device_node *np)
 	if (of_property_read_u32_index(np, "reg", 0, &reg))
 		return -ENODEV;
 
-	return reg / 0x1000;      /* context banks are 0x1000 apart */
+	/*
+	 * Context banks are 0x1000 apart but, in some cases, the ASID
+	 * number doesn't match to this logic and needs to be passed
+	 * from the DT configuration explicitly.
+	 */
+	if (of_property_read_u32(np, "qcom,ctx-num", &val))
+		asid = reg / 0x1000;
+	else
+		asid = val;
+
+	return asid;
 }
 
 static int qcom_iommu_ctx_probe(struct platform_device *pdev)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/7] iommu/qcom: Properly reset the IOMMU context
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 2/7] iommu/qcom: Use the asid read from device-tree if specified AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 4/7] iommu/qcom: Index contexts by asid number to allow asid 0 AngeloGioacchino Del Regno
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

Avoid context faults by resetting the context(s) entirely at
detach_dev() time and also do the same before programming the
context for domain initialization.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 491a8093f3d6..5b127ac41b5e 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -223,6 +223,20 @@ static irqreturn_t qcom_iommu_fault(int irq, void *dev)
 	return IRQ_HANDLED;
 }
 
+static void qcom_iommu_reset_ctx(struct qcom_iommu_ctx *ctx)
+{
+	iommu_writel(ctx, ARM_SMMU_CB_FAR, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_FSR, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_PAR, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_TCR2, 0);
+	iommu_writel(ctx, ARM_SMMU_CB_TCR, 0);
+	iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, 0);
+	iommu_writeq(ctx, ARM_SMMU_CB_TTBR1, 0);
+}
+
 static int qcom_iommu_init_domain(struct iommu_domain *domain,
 				  struct qcom_iommu_dev *qcom_iommu,
 				  struct device *dev)
@@ -273,6 +287,8 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
 			ctx->secure_init = true;
 		}
 
+		qcom_iommu_reset_ctx(ctx);
+
 		/* TTBRs */
 		iommu_writeq(ctx, ARM_SMMU_CB_TTBR0,
 				pgtbl_cfg.arm_lpae_s1_cfg.ttbr |
@@ -401,8 +417,8 @@ static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *de
 	for (i = 0; i < fwspec->num_ids; i++) {
 		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
 
-		/* Disable the context bank: */
-		iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
+		/* Disable and reset the context bank */
+		qcom_iommu_reset_ctx(ctx);
 
 		ctx->domain = NULL;
 	}
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/7] iommu/qcom: Index contexts by asid number to allow asid 0
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
                   ` (2 preceding siblings ...)
  2022-11-11 13:55 ` [PATCH 3/7] iommu/qcom: Properly reset the IOMMU context AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 5/7] dt-bindings: iommu: qcom,iommu: Document QSMMU v2 compatibles AngeloGioacchino Del Regno
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

This driver was indexing the contexts by asid-1, which is probably
done under the assumption that the first ASID is always 1.

Unfortunately this is not always true: at least for MSM8956 and
MSM8976's GPU IOMMU, the gpu_user context's ASID number is zero.
To allow using a zero asid number, index the contexts by `asid`
instead of by `asid - 1`.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 5b127ac41b5e..1fcee74154f0 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -52,7 +52,7 @@ struct qcom_iommu_dev {
 	void __iomem		*local_base;
 	u32			 sec_id;
 	u8			 num_ctxs;
-	struct qcom_iommu_ctx	*ctxs[];   /* indexed by asid-1 */
+	struct qcom_iommu_ctx	*ctxs[];   /* indexed by asid */
 };
 
 struct qcom_iommu_ctx {
@@ -94,7 +94,7 @@ static struct qcom_iommu_ctx * to_ctx(struct qcom_iommu_domain *d, unsigned asid
 	struct qcom_iommu_dev *qcom_iommu = d->iommu;
 	if (!qcom_iommu)
 		return NULL;
-	return qcom_iommu->ctxs[asid - 1];
+	return qcom_iommu->ctxs[asid];
 }
 
 static inline void
@@ -563,12 +563,10 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 	qcom_iommu = platform_get_drvdata(iommu_pdev);
 
 	/* make sure the asid specified in dt is valid, so we don't have
-	 * to sanity check this elsewhere, since 'asid - 1' is used to
-	 * index into qcom_iommu->ctxs:
+	 * to sanity check this elsewhere:
 	 */
-	if (WARN_ON(asid < 1) ||
-	    WARN_ON(asid > qcom_iommu->num_ctxs) ||
-	    WARN_ON(qcom_iommu->ctxs[asid - 1] == NULL)) {
+	if (WARN_ON(asid >= qcom_iommu->num_ctxs) ||
+	    WARN_ON(qcom_iommu->ctxs[asid] == NULL)) {
 		put_device(&iommu_pdev->dev);
 		return -EINVAL;
 	}
@@ -726,7 +724,7 @@ static int qcom_iommu_ctx_probe(struct platform_device *pdev)
 
 	dev_dbg(dev, "found asid %u\n", ctx->asid);
 
-	qcom_iommu->ctxs[ctx->asid - 1] = ctx;
+	qcom_iommu->ctxs[ctx->asid] = ctx;
 
 	return 0;
 }
@@ -738,7 +736,7 @@ static int qcom_iommu_ctx_remove(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, NULL);
 
-	qcom_iommu->ctxs[ctx->asid - 1] = NULL;
+	qcom_iommu->ctxs[ctx->asid] = NULL;
 
 	return 0;
 }
@@ -779,7 +777,7 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct resource *res;
 	struct clk *clk;
-	int ret, max_asid = 0;
+	int ret, num_ctxs, max_asid = 0;
 
 	/* find the max asid (which is 1:1 to ctx bank idx), so we know how
 	 * many child ctx devices we have:
@@ -787,11 +785,13 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
 	for_each_child_of_node(dev->of_node, child)
 		max_asid = max(max_asid, get_asid(child));
 
-	qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, max_asid),
+	num_ctxs = max_asid + 1;
+
+	qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, num_ctxs),
 				  GFP_KERNEL);
 	if (!qcom_iommu)
 		return -ENOMEM;
-	qcom_iommu->num_ctxs = max_asid;
+	qcom_iommu->num_ctxs = num_ctxs;
 	qcom_iommu->dev = dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/7] dt-bindings: iommu: qcom,iommu: Document QSMMU v2 compatibles
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
                   ` (3 preceding siblings ...)
  2022-11-11 13:55 ` [PATCH 4/7] iommu/qcom: Index contexts by asid number to allow asid 0 AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 6/7] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 7/7] dt-bindings: iommu: qcom,iommu: Document MSM8976 compatible AngeloGioacchino Del Regno
  6 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

Add compatible strings for "qcom,msm-iommu-v2" for the inner node,
"qcom,msm-iommu-v2-ns" and "qcom,msm-iommu-v2-sec" for the context
bank nodes to support Qualcomm's secure fw "SMMU v2" implementation.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
index 7d4e0a18b08e..b762772f80e7 100644
--- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
+++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
@@ -11,7 +11,10 @@ to non-secure vs secure interrupt line.
 
                         "qcom,msm8916-iommu"
 
-                     Followed by "qcom,msm-iommu-v1".
+                     Followed by one of:
+
+                        - "qcom,msm-iommu-v1"
+                        - "qcom,msm-iommu-v2"
 
 - clock-names      : Should be a pair of "iface" (required for IOMMUs
                      register group access) and "bus" (required for
@@ -36,6 +39,8 @@ to non-secure vs secure interrupt line.
   - compatible     : Should be one of:
         - "qcom,msm-iommu-v1-ns"  : non-secure context bank
         - "qcom,msm-iommu-v1-sec" : secure context bank
+        - "qcom,msm-iommu-v2-ns"  : non-secure QSMMUv2/QSMMU500 context bank
+        - "qcom,msm-iommu-v2-sec" : secure QSMMUv2/QSMMU500 context bank
   - reg            : Base address and size of context bank within the iommu
   - interrupts     : The context fault irq.
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/7] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
                   ` (4 preceding siblings ...)
  2022-11-11 13:55 ` [PATCH 5/7] dt-bindings: iommu: qcom,iommu: Document QSMMU v2 compatibles AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  2022-11-11 13:55 ` [PATCH 7/7] dt-bindings: iommu: qcom,iommu: Document MSM8976 compatible AngeloGioacchino Del Regno
  6 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

On some SoCs like MSM8956, MSM8976 and others, secure contexts are
also secured: these get programmed by the bootloader or TZ (as usual)
but their "interesting" registers are locked out by the hypervisor,
disallowing direct register writes from Linux and, in many cases,
completely disallowing the reprogramming of TTBR, TCR, MAIR and other
registers including, but not limited to, resetting contexts.
This is referred downstream as a "v2" IOMMU but this is effectively
a "v2 firmware configuration" instead.

Luckily, the described behavior of version 2 is effective only on
secure contexts and not on non-secure ones: add support for that,
finally getting a completely working IOMMU on at least MSM8956/76.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 1fcee74154f0..bba5274bf8d4 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -59,6 +59,7 @@ struct qcom_iommu_ctx {
 	struct device		*dev;
 	void __iomem		*base;
 	bool			 secure_init;
+	bool			 secured_ctx;
 	u8			 asid;      /* asid and ctx bank # are 1:1 */
 	struct iommu_domain	*domain;
 };
@@ -287,6 +288,12 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
 			ctx->secure_init = true;
 		}
 
+		/* Secured QSMMU-500/QSMMU-v2 contexts cannot be programmed */
+		if (ctx->secured_ctx) {
+			ctx->domain = domain;
+			continue;
+		}
+
 		qcom_iommu_reset_ctx(ctx);
 
 		/* TTBRs */
@@ -418,7 +425,8 @@ static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *de
 		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
 
 		/* Disable and reset the context bank */
-		qcom_iommu_reset_ctx(ctx);
+		if (!ctx->secured_ctx)
+			qcom_iommu_reset_ctx(ctx);
 
 		ctx->domain = NULL;
 	}
@@ -699,10 +707,14 @@ static int qcom_iommu_ctx_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return -ENODEV;
 
+	if (of_device_is_compatible(dev->of_node, "qcom,msm-iommu-v2-sec"))
+		ctx->secured_ctx = true;
+
 	/* clear IRQs before registering fault handler, just in case the
 	 * boot-loader left us a surprise:
 	 */
-	iommu_writel(ctx, ARM_SMMU_CB_FSR, iommu_readl(ctx, ARM_SMMU_CB_FSR));
+	if (!ctx->secured_ctx)
+		iommu_writel(ctx, ARM_SMMU_CB_FSR, iommu_readl(ctx, ARM_SMMU_CB_FSR));
 
 	ret = devm_request_irq(dev, irq,
 			       qcom_iommu_fault,
@@ -744,6 +756,8 @@ static int qcom_iommu_ctx_remove(struct platform_device *pdev)
 static const struct of_device_id ctx_of_match[] = {
 	{ .compatible = "qcom,msm-iommu-v1-ns" },
 	{ .compatible = "qcom,msm-iommu-v1-sec" },
+	{ .compatible = "qcom,msm-iommu-v2-ns" },
+	{ .compatible = "qcom,msm-iommu-v2-sec" },
 	{ /* sentinel */ }
 };
 
@@ -761,7 +775,8 @@ static bool qcom_iommu_has_secure_context(struct qcom_iommu_dev *qcom_iommu)
 	struct device_node *child;
 
 	for_each_child_of_node(qcom_iommu->dev->of_node, child) {
-		if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec")) {
+		if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec") ||
+		    of_device_is_compatible(child, "qcom,msm-iommu-v2-sec")) {
 			of_node_put(child);
 			return true;
 		}
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/7] dt-bindings: iommu: qcom,iommu: Document MSM8976 compatible
  2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
                   ` (5 preceding siblings ...)
  2022-11-11 13:55 ` [PATCH 6/7] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts AngeloGioacchino Del Regno
@ 2022-11-11 13:55 ` AngeloGioacchino Del Regno
  6 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-11 13:55 UTC (permalink / raw)
  To: agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno

Add "qcom,msm8976-iommu" to support IOMMUs on this SoC.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
index b762772f80e7..b7a5822ac00d 100644
--- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
+++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt
@@ -9,7 +9,8 @@ to non-secure vs secure interrupt line.
 
 - compatible       : Should be one of:
 
-                        "qcom,msm8916-iommu"
+                        - "qcom,msm8916-iommu"
+                        - "qcom,msm8976-iommu"
 
                      Followed by one of:
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property
  2022-11-11 13:55 ` [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property AngeloGioacchino Del Regno
@ 2022-11-14  8:23   ` Krzysztof Kozlowski
  2022-11-14 10:54     ` AngeloGioacchino Del Regno
  0 siblings, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-14  8:23 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming

On 11/11/2022 14:55, AngeloGioacchino Del Regno wrote:
> Add a new "qcom,ctx-num" property to force an ASID number on IOMMU
> contexts where required.
> 
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>  Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 1 +

This is already a v2:
https://lore.kernel.org/all/20220527212901.29268-1-konrad.dybcio@somainline.org/

and your v2 was a v3...

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property
  2022-11-14  8:23   ` Krzysztof Kozlowski
@ 2022-11-14 10:54     ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-14 10:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, agross
  Cc: andersson, konrad.dybcio, joro, will, robin.murphy, robh+dt,
	krzysztof.kozlowski+dt, robdclark, linux-arm-msm, iommu,
	devicetree, linux-kernel, linux-arm-kernel, marijn.suijten,
	kernel, luca, a39.skl, phone-devel, ~postmarketos/upstreaming

Il 14/11/22 09:23, Krzysztof Kozlowski ha scritto:
> On 11/11/2022 14:55, AngeloGioacchino Del Regno wrote:
>> Add a new "qcom,ctx-num" property to force an ASID number on IOMMU
>> contexts where required.
>>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>>   Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 1 +
> 
> This is already a v2:
> https://lore.kernel.org/all/20220527212901.29268-1-konrad.dybcio@somainline.org/
> 
> and your v2 was a v3...
> 

I honestly didn't remember that this got sent again 5 months ago... besides,
I have to send a new version anyway because of a code fix, should I name it v3?

Regards,
Angelo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-11-14 10:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-11 13:55 [PATCH 0/7] Add support for Qualcomm's legacy IOMMU v2 AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 1/7] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property AngeloGioacchino Del Regno
2022-11-14  8:23   ` Krzysztof Kozlowski
2022-11-14 10:54     ` AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 2/7] iommu/qcom: Use the asid read from device-tree if specified AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 3/7] iommu/qcom: Properly reset the IOMMU context AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 4/7] iommu/qcom: Index contexts by asid number to allow asid 0 AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 5/7] dt-bindings: iommu: qcom,iommu: Document QSMMU v2 compatibles AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 6/7] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts AngeloGioacchino Del Regno
2022-11-11 13:55 ` [PATCH 7/7] dt-bindings: iommu: qcom,iommu: Document MSM8976 compatible AngeloGioacchino Del Regno

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).