Skip to contentSkip to conversation

iommu/msm: Add DT adaptation and generic bindings support

PATCH Superseded Sricharan R 5 participants 20 messages May 20, 2016 – May 25, 2016

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover iommu/msm: Add DT adaptation and generic bindings support

The msm_iommu.c driver currently works based on platform data.
A single master device can be connected to more than one iommu and multiple contexts in each of the iommu. This association between master and iommus was represented from platform data using parent/child devices. The master drivers were responsible for attaching all of the iommus/context to a domain. Now the platform data support is removed and DT support is added. The master/iommus are added through generic iommu bindings.

This is essentially rework of the patch posted earlier by Rob Clark <[email protected]>. This series folds the changes in to the existing driver with the addition of generic bindings.

        http://www.spinics.net/lists/linux-arm-msm/msg10077.html

Tested this series on ifc6410 board.

[V5] Changed the compatible binding name as per comments, added comments
for usage of barriers in patch 6.

[V4] Addressed comments for making the iommu compatible binding more soc
specific and updated the documentation for the iommu clocks.

[V3] Addressed comments to correct the usage
of the #iommu-cells binding, improve the flush_iotlb_range function, added a new patch to use writel_relaxed for register access and split up the documentation patch.

[V2] Adapted the driver to use generic ARMV7S short descriptor pagetable ops
and addressed comments.

[V1]
https://lists.linuxfoundation.org/pipermail/iommu/2015-August/014074.html

Sricharan R (7):
iommu/msm: Add DT adaptation
documentation: iommu: Add bindings for msm,iommu-v0 ip iommu/msm: Move the contents from msm_iommu_dev.c to msm_iommu.c iommu/msm: Add support for generic master bindings iommu/msm: use generic ARMV7S short descriptor pagetable ops iommu/msm: Use writel_relaxed and add a barrier iommu/msm: Remove driver BROKEN

 .../devicetree/bindings/iommu/msm,iommu-v0.txt     |  64 ++
 drivers/iommu/Kconfig                              |   2 +-
 drivers/iommu/Makefile                             |   2 +-
 drivers/iommu/msm_iommu.c                          | 885 +++++++++++----------
 drivers/iommu/msm_iommu.h                          |  73 +-
 drivers/iommu/msm_iommu_dev.c                      | 381 ---------
 drivers/iommu/msm_iommu_hw-8xxx.h                  | 109 +--
 7 files changed, 636 insertions(+), 880 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iommu/msm,iommu-v0.txt
 delete mode 100644 drivers/iommu/msm_iommu_dev.c
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH v5 1/7 iommu/msm: Add DT adaptation

The driver currently works based on platform data. Remove this and add support for DT. A single master can have multiple ports connected to more than one iommu.

                      master
                        |
                        |
                        |
           ------------------------
           |                      |
         IOMMU0                 IOMMU1
           |                      |
      ctx0   ctx1            ctx0   ctx1

This association of master and iommus/contexts were previously represented by platform data parent/child device details. The client drivers were responsible for programming all of the iommus/contexts for the device. Now while adapting to generic DT bindings we maintain the list of iommus, contexts that each master domain is connected to and program all of them on attach/detach.

---
 drivers/iommu/msm_iommu.c     | 252 ++++++++++++++++++---------------
 drivers/iommu/msm_iommu.h     |  73 ++++------
 drivers/iommu/msm_iommu_dev.c | 315 ++++++++++--------------------------------
 3 files changed, 237 insertions(+), 403 deletions(-)
drivers/iommu/msm_iommu.c +138 -114
index e321fa5..bc1a4e3 100644
@@ -48,6 +48,7 @@ __asm__ __volatile__ (							\
 static int msm_iommu_tex_class[4];
 
 DEFINE_SPINLOCK(msm_iommu_lock);
+static LIST_HEAD(qcom_iommu_devices);
 
 struct msm_priv {
 	unsigned long *pgtable;
@@ -60,35 +61,37 @@ static struct msm_priv *to_msm_priv(struct iommu_domain *dom)
 	return container_of(dom, struct msm_priv, domain);
 }
 
-static int __enable_clocks(struct msm_iommu_drvdata *drvdata)
+static int __enable_clocks(struct msm_iommu_dev *iommu)
 {
 	int ret;
 
-	ret = clk_enable(drvdata->pclk);
+	ret = clk_enable(iommu->pclk);
 	if (ret)
 		goto fail;
 
-	if (drvdata->clk) {
-		ret = clk_enable(drvdata->clk);
+	if (iommu->clk) {
+		ret = clk_enable(iommu->clk);
 		if (ret)
-			clk_disable(drvdata->pclk);
+			clk_disable(iommu->pclk);
 	}
 fail:
 	return ret;
 }
 
-static void __disable_clocks(struct msm_iommu_drvdata *drvdata)
+static void __disable_clocks(struct msm_iommu_dev *iommu)
 {
-	clk_disable(drvdata->clk);
-	clk_disable(drvdata->pclk);
+	if (iommu->clk)
+		clk_disable(iommu->clk);
+	clk_disable(iommu->pclk);
 }
 
 static int __flush_iotlb(struct iommu_domain *domain)
 {
 	struct msm_priv *priv = to_msm_priv(domain);
-	struct msm_iommu_drvdata *iommu_drvdata;
-	struct msm_iommu_ctx_drvdata *ctx_drvdata;
+	struct msm_iommu_dev *iommu = NULL;
+	struct msm_iommu_ctx_dev *master;
 	int ret = 0;
+
 #ifndef CONFIG_IOMMU_PGTABLES_L2
 	unsigned long *fl_table = priv->pgtable;
 	int i;
@@ -105,24 +108,67 @@ static int __flush_iotlb(struct iommu_domain *domain)
 	}
 #endif
 
-	list_for_each_entry(ctx_drvdata, &priv->list_attached, attached_elm) {
-
-		BUG_ON(!ctx_drvdata->pdev || !ctx_drvdata->pdev->dev.parent);
-
-		iommu_drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
-		BUG_ON(!iommu_drvdata);
-
-		ret = __enable_clocks(iommu_drvdata);
+	list_for_each_entry(iommu, &priv->list_attached, dom_node) {
+		ret = __enable_clocks(iommu);
 		if (ret)
 			goto fail;
 
-		SET_CTX_TLBIALL(iommu_drvdata->base, ctx_drvdata->num, 0);
-		__disable_clocks(iommu_drvdata);
+		list_for_each_entry(master, &iommu->ctx_list, list)
+			SET_CTX_TLBIALL(iommu->base, master->num, 0);
+
+		__disable_clocks(iommu);
 	}
 fail:
 	return ret;
 }
 
+static int msm_iommu_alloc_ctx(unsigned long *map, int start, int end)
+{
+	int idx;
+
+	do {
+		idx = find_next_zero_bit(map, end, start);
+		if (idx == end)
+			return -ENOSPC;
+	} while (test_and_set_bit(idx, map));
+
+	return idx;
+}
+
+static void msm_iommu_free_ctx(unsigned long *map, int idx)
+{
+	clear_bit(idx, map);
+}
+
+static void config_mids(struct msm_iommu_dev *iommu,
+			struct msm_iommu_ctx_dev *master)
+{
+	int mid, ctx, i;
+
+	for (i = 0; i < master->num_mids; i++) {
+		mid = master->mids[i];
+		ctx = master->num;
+
+		SET_M2VCBR_N(iommu->base, mid, 0);
+		SET_CBACR_N(iommu->base, ctx, 0);
+
+		/* Set VMID = 0 */
+		SET_VMID(iommu->base, mid, 0);
+
+		/* Set the context number for that MID to this context */
+		SET_CBNDX(iommu->base, mid, ctx);
+
+		/* Set MID associated with this context bank to 0*/
+		SET_CBVMID(iommu->base, ctx, 0);
+
+		/* Set the ASID for TLB tagging for this context */
+		SET_CONTEXTIDR_ASID(iommu->base, ctx, ctx);
+
+		/* Set security bit override to be Non-secure */
+		SET_NSCFG(iommu->base, mid, 3);
+	}
+}
+
 static void __reset_context(void __iomem *base, int ctx)
 {
 	SET_BPRCOSH(base, ctx, 0);
@@ -272,94 +318,76 @@ static void msm_iommu_domain_free(struct iommu_domain *domain)
 
 static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 {
-	struct msm_priv *priv;
-	struct msm_iommu_ctx_dev *ctx_dev;
-	struct msm_iommu_drvdata *iommu_drvdata;
-	struct msm_iommu_ctx_drvdata *ctx_drvdata;
-	struct msm_iommu_ctx_drvdata *tmp_drvdata;
 	int ret = 0;
 	unsigned long flags;
+	struct msm_iommu_dev *iommu;
+	struct msm_priv *priv = to_msm_priv(domain);
+	struct msm_iommu_ctx_dev *master;
 
 	spin_lock_irqsave(&msm_iommu_lock, flags);
-
-	priv = to_msm_priv(domain);
-
-	if (!dev) {
-		ret = -EINVAL;
-		goto fail;
-	}
-
-	iommu_drvdata = dev_get_drvdata(dev->parent);
-	ctx_drvdata = dev_get_drvdata(dev);
-	ctx_dev = dev->platform_data;
-
-	if (!iommu_drvdata || !ctx_drvdata || !ctx_dev) {
-		ret = -EINVAL;
-		goto fail;
-	}
-
-	if (!list_empty(&ctx_drvdata->attached_elm)) {
-		ret = -EBUSY;
-		goto fail;
-	}
-
-	list_for_each_entry(tmp_drvdata, &priv->list_attached, attached_elm)
-		if (tmp_drvdata == ctx_drvdata) {
-			ret = -EBUSY;
-			goto fail;
+	list_for_each_entry(iommu, &qcom_iommu_devices, dev_node) {
+		master = list_first_entry(&iommu->ctx_list,
+					  struct msm_iommu_ctx_dev,
+					  list);
+		if (master->of_node == dev->of_node) {
+			ret = __enable_clocks(iommu);
+			if (ret)
+				goto fail;
+
+			list_for_each_entry(master, &iommu->ctx_list, list) {
+				if (master->num) {
+					dev_err(dev, "domain already attached");
+					ret = -EEXIST;
+					goto fail;
+				}
+				master->num =
+					msm_iommu_alloc_ctx(iommu->context_map,
+							    0, iommu->ncb);
+					if (IS_ERR_VALUE(master->num)) {
+						ret = -ENODEV;
+						goto fail;
+					}
+				config_mids(iommu, master);
+				__program_context(iommu->base, master->num,
+						  __pa(priv->pgtable));
+			}
+			__disable_clocks(iommu);
+			list_add(&iommu->dom_node, &priv->list_attached);
 		}
+	}
 
-	ret = __enable_clocks(iommu_drvdata);
-	if (ret)
-		goto fail;
-
-	__program_context(iommu_drvdata->base, ctx_dev->num,
-			  __pa(priv->pgtable));
-
-	__disable_clocks(iommu_drvdata);
-	list_add(&(ctx_drvdata->attached_elm), &priv->list_attached);
 	ret = __flush_iotlb(domain);
-
 fail:
 	spin_unlock_irqrestore(&msm_iommu_lock, flags);
+
 	return ret;
 }
 
 static void msm_iommu_detach_dev(struct iommu_domain *domain,
 				 struct device *dev)
 {
-	struct msm_priv *priv;
-	struct msm_iommu_ctx_dev *ctx_dev;
-	struct msm_iommu_drvdata *iommu_drvdata;
-	struct msm_iommu_ctx_drvdata *ctx_drvdata;
+	struct msm_priv *priv = to_msm_priv(domain);
 	unsigned long flags;
+	struct msm_iommu_dev *iommu;
+	struct msm_iommu_ctx_dev *master;
 	int ret;
 
 	spin_lock_irqsave(&msm_iommu_lock, flags);
-	priv = to_msm_priv(domain);
-
-	if (!dev)
-		goto fail;
-
-	iommu_drvdata = dev_get_drvdata(dev->parent);
-	ctx_drvdata = dev_get_drvdata(dev);
-	ctx_dev = dev->platform_data;
-
-	if (!iommu_drvdata || !ctx_drvdata || !ctx_dev)
-		goto fail;
-
 	ret = __flush_iotlb(domain);
 	if (ret)
 		goto fail;
 
-	ret = __enable_clocks(iommu_drvdata);
-	if (ret)
-		goto fail;
-
-	__reset_context(iommu_drvdata->base, ctx_dev->num);
-	__disable_clocks(iommu_drvdata);
-	list_del_init(&ctx_drvdata->attached_elm);
+	list_for_each_entry(iommu, &priv->list_attached, dom_node) {
+		ret = __enable_clocks(iommu);
+		if (ret)
+			goto fail;
 
+		list_for_each_entry(master, &iommu->ctx_list, list) {
+			msm_iommu_free_ctx(iommu->context_map, master->num);
+			__reset_context(iommu->base, master->num);
+		}
+		__disable_clocks(iommu);
+	}
 fail:
 	spin_unlock_irqrestore(&msm_iommu_lock, flags);
 }
@@ -555,47 +583,46 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
 					  dma_addr_t va)
 {
 	struct msm_priv *priv;
-	struct msm_iommu_drvdata *iommu_drvdata;
-	struct msm_iommu_ctx_drvdata *ctx_drvdata;
+	struct msm_iommu_dev *iommu;
+	struct msm_iommu_ctx_dev *master;
 	unsigned int par;
 	unsigned long flags;
-	void __iomem *base;
 	phys_addr_t ret = 0;
-	int ctx;
 
 	spin_lock_irqsave(&msm_iommu_lock, flags);
 
 	priv = to_msm_priv(domain);
-	if (list_empty(&priv->list_attached))
-		goto fail;
+	iommu = list_first_entry(&priv->list_attached,
+				 struct msm_iommu_dev, dom_node);
 
-	ctx_drvdata = list_entry(priv->list_attached.next,
-				 struct msm_iommu_ctx_drvdata, attached_elm);
-	iommu_drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
+	if (list_empty(&iommu->ctx_list))
+		goto fail;
 
-	base = iommu_drvdata->base;
-	ctx = ctx_drvdata->num;
+	master = list_first_entry(&iommu->ctx_list,
+				  struct msm_iommu_ctx_dev, list);
+	if (!master)
+		goto fail;
 
-	ret = __enable_clocks(iommu_drvdata);
+	ret = __enable_clocks(iommu);
 	if (ret)
 		goto fail;
 
 	/* Invalidate context TLB */
-	SET_CTX_TLBIALL(base, ctx, 0);
-	SET_V2PPR(base, ctx, va & V2Pxx_VA);
+	SET_CTX_TLBIALL(iommu->base, master->num, 0);
+	SET_V2PPR(iommu->base, master->num, va & V2Pxx_VA);
 
-	par = GET_PAR(base, ctx);
+	par = GET_PAR(iommu->base, master->num);
 
 	/* We are dealing with a supersection */
-	if (GET_NOFAULT_SS(base, ctx))
+	if (GET_NOFAULT_SS(iommu->base, master->num))
 		ret = (par & 0xFF000000) | (va & 0x00FFFFFF);
 	else	/* Upper 20 bits from PAR, lower 12 from VA */
 		ret = (par & 0xFFFFF000) | (va & 0x00000FFF);
 
-	if (GET_FAULT(base, ctx))
+	if (GET_FAULT(iommu->base, master->num))
 		ret = 0;
 
-	__disable_clocks(iommu_drvdata);
+	__disable_clocks(iommu);
 fail:
 	spin_unlock_irqrestore(&msm_iommu_lock, flags);
 	return ret;
@@ -635,37 +662,34 @@ static void print_ctx_regs(void __iomem *base, int ctx)
 
 irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
 {
-	struct msm_iommu_drvdata *drvdata = dev_id;
-	void __iomem *base;
+	struct msm_iommu_dev *iommu = dev_id;
 	unsigned int fsr;
 	int i, ret;
 
 	spin_lock(&msm_iommu_lock);
 
-	if (!drvdata) {
+	if (!iommu) {
 		pr_err("Invalid device ID in context interrupt handler\n");
 		goto fail;
 	}
 
-	base = drvdata->base;
-
 	pr_err("Unexpected IOMMU page fault!\n");
-	pr_err("base = %08x\n", (unsigned int) base);
+	pr_err("base = %08x\n", (unsigned int)iommu->base);
 
-	ret = __enable_clocks(drvdata);
+	ret = __enable_clocks(iommu);
 	if (ret)
 		goto fail;
 
-	for (i = 0; i < drvdata->ncb; i++) {
-		fsr = GET_FSR(base, i);
+	for (i = 0; i < iommu->ncb; i++) {
+		fsr = GET_FSR(iommu->base, i);
 		if (fsr) {
 			pr_err("Fault occurred in context %d.\n", i);
 			pr_err("Interesting registers:\n");
-			print_ctx_regs(base, i);
-			SET_FSR(base, i, 0x4000000F);
+			print_ctx_regs(iommu->base, i);
+			SET_FSR(iommu->base, i, 0x4000000F);
 		}
 	}
-	__disable_clocks(drvdata);
+	__disable_clocks(iommu);
 fail:
 	spin_unlock(&msm_iommu_lock);
 	return 0;
drivers/iommu/msm_iommu.h +26 -47

100 lines not on this page · raw message

drivers/iommu/msm_iommu_dev.c +73 -242

370 lines not on this page · raw message

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#2 lore raw

PATCH v5 2/7 documentation: iommu: Add bindings for msm, iommu-v0 ip

In reply to Sricharan R

The MSM IOMMU is an implementation compatible with the ARM VMSA short descriptor page tables. It provides address translation for bus masters outside of the CPU, each connected to the IOMMU through a port called micro-TLB. Adding the DT bindings for the same.

---
 .../devicetree/bindings/iommu/msm,iommu-v0.txt     | 64 ++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iommu/msm,iommu-v0.txt
Documentation/devicetree/bindings/iommu/msm,iommu-v0.txt new file +64 -0
new file mode 100644
index 0000000..2023638
@@ -0,0 +1,64 @@
+* QCOM IOMMU
+
+The MSM IOMMU is an implementation compatible with the ARM VMSA short
+descriptor page tables. It provides address translation for bus masters outside
+of the CPU, each connected to the IOMMU through a port called micro-TLB.
+
+Required Properties:
+
+  - compatible: Must contain "qcom,apq8064-iommu".
+  - reg: Base address and size of the IOMMU registers.
+  - interrupts: Specifiers for the MMU fault interrupts. For instances that
+    support secure mode two interrupts must be specified, for non-secure and
+    secure mode, in that order. For instances that don't support secure mode a
+    single interrupt must be specified.
+  - #iommu-cells: The number of cells needed to specify the stream id. This
+		  is always 1.
+  - qcom,ncb:	  The total number of context banks in the IOMMU.
+  - clocks	: List of clocks to be used during SMMU register access. See
+		  Documentation/devicetree/bindings/clock/clock-bindings.txt
+		  for information about the format. For each clock specified
+		  here, there must be a corresponding entry in clock-names
+		  (see below).
+
+  - clock-names	: List of clock names corresponding to the clocks specified in
+		  the "clocks" property (above).
+		  Should be "smmu_pclk" for specifying the interface clock
+		  required for iommu's register accesses.
+		  Should be "smmu_clk" for specifying the functional clock
+		  required by iommu for bus accesses.
+
+Each bus master connected to an IOMMU must reference the IOMMU in its device
+node with the following property:
+
+  - iommus: A reference to the IOMMU in multiple cells. The first cell is a
+	    phandle to the IOMMU and the second cell is the stream id.
+	    A single master device can be connected to more than one iommu
+	    and multiple contexts in each of the iommu. So multiple entries
+	    are required to list all the iommus and the stream ids that the
+	    master is connected to.
+
+Example: mdp iommu and its bus master
+
+                mdp_port0: iommu at 7500000 {
+			compatible = "qcom,apq8064-iommu";
+			#iommu-cells = <1>;
+			clock-names =
+			    "smmu_pclk",
+			    "smmu_clk";
+			clocks =
+			    <&mmcc SMMU_AHB_CLK>,
+			    <&mmcc MDP_AXI_CLK>;
+			reg = <0x07500000 0x100000>;
+			interrupts =
+			    <GIC_SPI 63 0>,
+			    <GIC_SPI 64 0>;
+			qcom,ncb = <2>;
+		};
+
+		mdp: qcom,mdp at 5100000 {
+			compatible = "qcom,mdp";
+			...
+			iommus = <&mdp_port0 0
+				  &mdp_port0 2>;
+		};
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#3 lore raw

PATCH v5 2/7 documentation: iommu: Add bindings for msm,iommu-v0 ip

Quoted 10 lines · Sricharan R

The MSM IOMMU is an implementation compatible with the ARM VMSA short descriptor page tables. It provides address translation for bus masters outside of the CPU, each connected to the IOMMU through a port called micro-TLB. Adding the DT bindings for the same.

---
 .../devicetree/bindings/iommu/msm,iommu-v0.txt     | 64 ++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iommu/msm,iommu-v0.txt
#4 lore raw

PATCH v5 3/7 iommu/msm: Move the contents from msm_iommu_dev.c to msm_iommu.c

In reply to Sricharan R

There are only two functions left in msm_iommu_dev.c. Move it to msm_iommu.c and delete the file.

---
 drivers/iommu/Makefile        |   2 +-
 drivers/iommu/msm_iommu.c     | 182 ++++++++++++++++++++++++++++++++++++
 drivers/iommu/msm_iommu_dev.c | 212 ------------------------------------------
 3 files changed, 183 insertions(+), 213 deletions(-)
 delete mode 100644 drivers/iommu/msm_iommu_dev.c
drivers/iommu/Makefile +1 -1
index f7134f7..8695ead 100644
@@ -7,7 +7,7 @@ obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
 obj-$(CONFIG_IOMMU_IOVA) += iova.o
 obj-$(CONFIG_OF_IOMMU)	+= of_iommu.o
-obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o msm_iommu_dev.o
+obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o
 obj-$(CONFIG_QCOM_IOMMU_V1) += qcom/
 obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
 obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o
drivers/iommu/msm_iommu.c +182 -0

200 lines not on this page · raw message

drivers/iommu/msm_iommu_dev.c deleted +0 -212

212 lines not on this page · raw message

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#5 lore raw

PATCH v5 4/7 iommu/msm: Add support for generic master bindings

In reply to Sricharan R

This adds the xlate callback which gets invoked during device registration from DT. The master devices gets added through this.

---
 drivers/iommu/msm_iommu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)
drivers/iommu/msm_iommu.c +59 -2
index 792b352..8ab0643 100644
@@ -28,6 +28,7 @@
 #include <linux/iommu.h>
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <linux/of_iommu.h>
 
 #include <asm/cacheflush.h>
 #include <asm/sizes.h>
@@ -702,6 +703,54 @@ static void print_ctx_regs(void __iomem *base, int ctx)
 	       GET_PRRR(base, ctx), GET_NMRR(base, ctx));
 }
 
+static void insert_iommu_master(struct device *dev,
+				struct msm_iommu_dev **iommu,
+				struct of_phandle_args *spec)
+{
+	struct msm_iommu_ctx_dev *master = dev->archdata.iommu;
+	int sid;
+
+	if (list_empty(&(*iommu)->ctx_list)) {
+		master = kzalloc(sizeof(*master), GFP_ATOMIC);
+		master->of_node = dev->of_node;
+		list_add(&master->list, &(*iommu)->ctx_list);
+		dev->archdata.iommu = master;
+	}
+
+	for (sid = 0; sid < master->num_mids; sid++)
+		if (master->mids[sid] == spec->args[0]) {
+			dev_warn(dev, "Stream ID 0x%hx repeated; ignoring\n",
+				 sid);
+			return;
+		}
+
+	master->mids[master->num_mids++] = spec->args[0];
+}
+
+static int qcom_iommu_of_xlate(struct device *dev,
+			       struct of_phandle_args *spec)
+{
+	struct msm_iommu_dev *iommu;
+	unsigned long flags;
+	int ret = 0;
+
+	spin_lock_irqsave(&msm_iommu_lock, flags);
+	list_for_each_entry(iommu, &qcom_iommu_devices, dev_node)
+		if (iommu->dev->of_node == spec->np)
+			break;
+
+	if (!iommu || iommu->dev->of_node != spec->np) {
+		ret = -ENODEV;
+		goto fail;
+	}
+
+	insert_iommu_master(dev, &iommu, spec);
+fail:
+	spin_unlock_irqrestore(&msm_iommu_lock, flags);
+
+	return ret;
+}
+
 irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
 {
 	struct msm_iommu_dev *iommu = dev_id;
@@ -737,7 +786,7 @@ fail:
 	return 0;
 }
 
-static const struct iommu_ops msm_iommu_ops = {
+static struct iommu_ops msm_iommu_ops = {
 	.capable = msm_iommu_capable,
 	.domain_alloc = msm_iommu_domain_alloc,
 	.domain_free = msm_iommu_domain_free,
@@ -748,6 +797,7 @@ static const struct iommu_ops msm_iommu_ops = {
 	.map_sg = default_iommu_map_sg,
 	.iova_to_phys = msm_iommu_iova_to_phys,
 	.pgsize_bitmap = MSM_IOMMU_PGSIZES,
+	.of_xlate = qcom_iommu_of_xlate,
 };
 
 static int msm_iommu_probe(struct platform_device *pdev)
@@ -837,6 +887,7 @@ static int msm_iommu_probe(struct platform_device *pdev)
 	}
 
 	list_add(&iommu->dev_node, &qcom_iommu_devices);
+	of_iommu_set_ops(pdev->dev.of_node, &msm_iommu_ops);
 
 	pr_info("device mapped at %p, irq %d with %d ctx banks\n",
 		iommu->base, iommu->irq, iommu->ncb);
@@ -935,7 +986,13 @@ static int __init msm_iommu_init(void)
 	return 0;
 }
 
-subsys_initcall(msm_iommu_init);
+static int __init msm_iommu_of_setup(struct device_node *np)
+{
+	msm_iommu_init();
+	return 0;
+}
+
+IOMMU_OF_DECLARE(msm_iommu_of, "qcom,apq8064-iommu", msm_iommu_of_setup);
 
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Stepan Moskovchenko <[email protected]>");
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#6 lore raw

PATCH v5 5/7 iommu/msm: use generic ARMV7S short descriptor pagetable ops

In reply to Sricharan R

This iommu uses the armv7 short descriptor format. So use the generic ARMV7S pagetable ops instead of rewriting the same stuff in the driver.

---
 drivers/iommu/Kconfig     |   1 +
 drivers/iommu/msm_iommu.c | 400 ++++++++++++----------------------------------
 2 files changed, 104 insertions(+), 297 deletions(-)
drivers/iommu/Kconfig +1 -0
index 232a54a..761be35 100644
@@ -92,6 +92,7 @@ config MSM_IOMMU
 	depends on ARCH_MSM8X60 || ARCH_MSM8960 || COMPILE_TEST
 	depends on BROKEN
 	select IOMMU_API
+	select IOMMU_IO_PGTABLE_ARMV7S
 	help
 	  Support for the IOMMUs found on certain Qualcomm SOCs.
 	  These IOMMUs allow virtualization of the address space used by most
drivers/iommu/msm_iommu.c +103 -297

553 lines not on this page · raw message

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#7 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

In reply to Sricharan R

While using the generic pagetable ops the tlb maintenance operation gets completed in the sync callback. So use writel_relaxed for all register access and add a mb() at appropriate places.

---
 drivers/iommu/msm_iommu.c         |  24 +++++++--
 drivers/iommu/msm_iommu_hw-8xxx.h | 109 ++++++++++++++++++++------------------
 2 files changed, 79 insertions(+), 54 deletions(-)
drivers/iommu/msm_iommu.c +21 -3
index 0299a37..dfcaeef 100644
@@ -124,6 +124,9 @@ static void msm_iommu_reset(void __iomem *base, int ncb)
 		SET_TLBLKCR(base, ctx, 0);
 		SET_CONTEXTIDR(base, ctx, 0);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static void __flush_iotlb(void *cookie)
@@ -141,6 +144,9 @@ static void __flush_iotlb(void *cookie)
 		list_for_each_entry(master, &iommu->ctx_list, list)
 			SET_CTX_TLBIALL(iommu->base, master->num, 0);
 
+		/* To ensure completion of TLBIALL above */
+		mb();
+
 		__disable_clocks(iommu);
 	}
 fail:
@@ -181,7 +187,8 @@ fail:
 
 static void __flush_iotlb_sync(void *cookie)
 {
-	/* To avoid a null function pointer */
+	/* To ensure completion of the TLBIVA in __flush_iotlb_range */
+	mb();
 }
 
 static const struct iommu_gather_ops msm_iommu_gather_ops = {
@@ -235,6 +242,9 @@ static void config_mids(struct msm_iommu_dev *iommu,
 		/* Set security bit override to be Non-secure */
 		SET_NSCFG(iommu->base, mid, 3);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static void __reset_context(void __iomem *base, int ctx)
@@ -257,6 +267,9 @@ static void __reset_context(void __iomem *base, int ctx)
 	SET_TLBFLPTER(base, ctx, 0);
 	SET_TLBSLPTER(base, ctx, 0);
 	SET_TLBLKCR(base, ctx, 0);
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static void __program_context(void __iomem *base, int ctx,
@@ -305,6 +318,9 @@ static void __program_context(void __iomem *base, int ctx,
 
 	/* Enable the MMU */
 	SET_M(base, ctx, 1);
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)
@@ -500,7 +516,8 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
 	/* Invalidate context TLB */
 	SET_CTX_TLBIALL(iommu->base, master->num, 0);
 	SET_V2PPR(iommu->base, master->num, va & V2Pxx_VA);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	par = GET_PAR(iommu->base, master->num);
 
 	/* We are dealing with a supersection */
@@ -714,7 +731,8 @@ static int msm_iommu_probe(struct platform_device *pdev)
 	par = GET_PAR(iommu->base, 0);
 	SET_V2PCFG(iommu->base, 0, 0);
 	SET_M(iommu->base, 0, 0);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	if (!par) {
 		pr_err("Invalid PAR value detected\n");
 		ret = -ENODEV;
drivers/iommu/msm_iommu_hw-8xxx.h +58 -51

141 lines not on this page · raw message

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#8 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Quoted 15 lines · On Friday 20 May 2016 16:24:53 Sricharan R wrote:

While using the generic pagetable ops the tlb maintenance operation gets completed in the sync callback. So use writel_relaxed for all register access and add a mb() at appropriate places.

---
 drivers/iommu/msm_iommu.c         |  24 +++++++--
 drivers/iommu/msm_iommu_hw-8xxx.h | 109 ++++++++++++++++++++------------------
 2 files changed, 79 insertions(+), 54 deletions(-)
drivers/iommu/msm_iommu.c +0 -0
index 0299a37..dfcaeef 100644

drivers/iommu/msm_iommu.c static void msm_iommu_reset(void __iomem *base, int ncb) · line 130

Quoted 7 lines
drivers/iommu/msm_iommu.c +3 -0
@@ -124,6 +124,9 @@ static void msm_iommu_reset(void __iomem *base, int ncb)
 		SET_TLBLKCR(base, ctx, 0);
 		SET_CONTEXTIDR(base, ctx, 0);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }

Why do the above use the relaxed writes? Do you have any performance numbers showing that skipping the sync for the reset makes a measurable difference?

How did you prove that skipping the sync before the write is safe?

How about resetting the iommu less often instead?

drivers/iommu/msm_iommu.c static void __flush_iotlb(void *cookie) · line 152

Quoted 11 lines
drivers/iommu/msm_iommu.c +3 -0
 static void __flush_iotlb(void *cookie)
@@ -141,6 +144,9 @@ static void __flush_iotlb(void *cookie)
 		list_for_each_entry(master, &iommu->ctx_list, list)
 			SET_CTX_TLBIALL(iommu->base, master->num, 0);
 
+		/* To ensure completion of TLBIALL above */
+		mb();
+
 		__disable_clocks(iommu);
 	}
 fail:

__disable_clocks() takes spinlocks and accesses the hardware, which in turn will also involve multiple syncs, so this seems like a premature optimization.

Have you tried just leaving the clocks enabled? I'd suspect you could gain more performance that way.

drivers/iommu/msm_iommu.c fail: · line 192

Quoted 8 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -181,7 +187,8 @@ fail:
 
 static void __flush_iotlb_sync(void *cookie)
 {
-	/* To avoid a null function pointer */
+	/* To ensure completion of the TLBIVA in __flush_iotlb_range */
+	mb();
 }

I don't understand the specific race from the comment.

What operation comes after this that relies on __flush_iotlb_range having completed, and how does an mb() guarantee this?

This seems to be a bug fix that is unrelated to the change to use writel_relaxed(), so better split it out into a separate patch, with a longer changeset description. Did you spot this race by running into incorrect data, or by inspection?

drivers/iommu/msm_iommu.c static void config_mids(struct msm_iommu_dev *iommu, · line 249

Quoted 10 lines
drivers/iommu/msm_iommu.c +3 -0
 static const struct iommu_gather_ops msm_iommu_gather_ops = {
@@ -235,6 +242,9 @@ static void config_mids(struct msm_iommu_dev *iommu,
 		/* Set security bit override to be Non-secure */
 		SET_NSCFG(iommu->base, mid, 3);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 

This looks similar to the msm_iommu_reset() case. Maybe put those two into one patch, or find a way to run config_mids() less often so it doesn't show up in the profiles any more.

If you hit this often enough that it causes performance problems, it's more likely that there is a bug in your code than that changing to relaxed accessors is a good idea.

Quoted 12 lines
drivers/iommu/msm_iommu.c +3 -0
 static void __reset_context(void __iomem *base, int ctx)
@@ -257,6 +267,9 @@ static void __reset_context(void __iomem *base, int ctx)
 	SET_TLBFLPTER(base, ctx, 0);
 	SET_TLBSLPTER(base, ctx, 0);
 	SET_TLBLKCR(base, ctx, 0);
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static void __program_context(void __iomem *base, int ctx,

drivers/iommu/msm_iommu.c static void __program_context(void __iomem *base, int ctx, · line 326

Quoted 9 lines
drivers/iommu/msm_iommu.c +3 -0
@@ -305,6 +318,9 @@ static void __program_context(void __iomem *base, int ctx,
 
 	/* Enable the MMU */
 	SET_M(base, ctx, 1);
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)

Maybe one more patch for these? I can see that __reset_context/__program_context would be run often enough to make a difference, though maybe not as much as the flushes.

Also, split this in two patches: one that adds a comment describing how you proved that you don't need barriers before the writes, and another one adding the barrier afterwards, with a description of the failure scenario.

drivers/iommu/msm_iommu.c static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, · line 523

Quoted 10 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -500,7 +516,8 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
 	/* Invalidate context TLB */
 	SET_CTX_TLBIALL(iommu->base, master->num, 0);
 	SET_V2PPR(iommu->base, master->num, va & V2Pxx_VA);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	par = GET_PAR(iommu->base, master->num);
 
 	/* We are dealing with a supersection */

In this case, I'd say it's better to rewrite the function to avoid the
read: iova_to_phys() should be fast, and not require hardware access. Getting rid of the hardware access by using an in-memory cache for this should gain more than just removing the barriers, as an MMIO read is always slow.

drivers/iommu/msm_iommu.c static int msm_iommu_probe(struct platform_device *pdev) · line 736

Quoted 8 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -714,7 +731,8 @@ static int msm_iommu_probe(struct platform_device *pdev)
 	par = GET_PAR(iommu->base, 0);
 	SET_V2PCFG(iommu->base, 0, 0);
 	SET_M(iommu->base, 0, 0);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	if (!par) {

Probe() clearly isn't performance sensitive, so please back this out and use the non-relaxed accessors.

Quoted 11 lines
drivers/iommu/msm_iommu_hw-8xxx.h +2 -1
index fc16010..fe2c5ca 100644
@@ -24,13 +24,19 @@
 #define GET_CTX_REG(reg, base, ctx) \
 				(readl((base) + (reg) + ((ctx) << CTX_SHIFT)))
 
-#define SET_GLOBAL_REG(reg, base, val)	writel((val), ((base) + (reg)))
+/*
+ * The writes to the global/context registers needs to be synced only after

drivers/iommu/msm_iommu_hw-8xxx.h line 36

Quoted 10 lines
drivers/iommu/msm_iommu_hw-8xxx.h +7 -2
+ * all the configuration writes are done. So use relaxed accessors and
+ * a barrier at the end.
+ */
+#define SET_GLOBAL_REG_RELAXED(reg, base, val) \
+			       writel_relaxed((val), ((base) + (reg)))
 
-#define SET_CTX_REG(reg, base, ctx, val) \
-			writel((val), ((base) + (reg) + ((ctx) << CTX_SHIFT)))
+#define SET_CTX_REG_RELAXED(reg, base, ctx, val) \
+		writel_relaxed((val), ((base) + (reg) + ((ctx) << CTX_SHIFT)))

Please add the relaxed accessors first in a separate patch, and then change over one user@a time before you remove the non-relaxed ones.

It's hard to believe that all users are actually performance critical, so start with the ones that gain the most performance. As commented above, some of the conversions seem particularly fishy and it's likely that a slow reset() function should not be fixed by making reset() faster but by calling it less often.

drivers/iommu/msm_iommu_hw-8xxx.h do { \ · line 147

Quoted 13 lines
drivers/iommu/msm_iommu_hw-8xxx.h +7 -5
 /* Context register setters/getters */
-#define SET_SCTLR(b, c, v)	 SET_CTX_REG(SCTLR, (b), (c), (v))
-#define SET_ACTLR(b, c, v)	 SET_CTX_REG(ACTLR, (b), (c), (v))
-#define SET_CONTEXTIDR(b, c, v)	 SET_CTX_REG(CONTEXTIDR, (b), (c), (v))
-#define SET_TTBR0(b, c, v)	 SET_CTX_REG(TTBR0, (b), (c), (v))
-#define SET_TTBR1(b, c, v)	 SET_CTX_REG(TTBR1, (b), (c), (v))
+#define SET_SCTLR(b, c, v)	 SET_CTX_REG_RELAXED(SCTLR, (b), (c), (v))
+#define SET_ACTLR(b, c, v)	 SET_CTX_REG_RELAXED(ACTLR, (b), (c), (v))
+#define SET_CONTEXTIDR(b, c, v)	 SET_CTX_REG_RELAXED(CONTEXTIDR, (b), (c), (v))
+#define SET_TTBR0(b, c, v)	 SET_CTX_REG_RELAXED(TTBR0, (b), (c), (v))
+#define SET_TTBR1(b, c, v)	 SET_CTX_REG_RELAXED(TTBR1, (b), (c), (v))
+#define SET_TTBCR(b, c, v)	 SET_CTX_REG_RELAXED(TTBCR, (b), (c), (v))
+#define SET_PAR(b, c, v)	 SET_CTX_REG_RELAXED(PAR, (b), (c), (v))

Can you just remove those macros, and open-code the function calls?

This is an unnecessary obfuscation that now also hides the fact that you are using relaxed accessors.

Arnd

#9 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Quoted 20 lines · On Friday 20 May 2016 13:44:10 Arnd Bergmann wrote:
Quoted 6 lines
 #define GET_CTX_REG(reg, base, ctx) \
                              (readl((base) + (reg) + ((ctx) << CTX_SHIFT)))
drivers/iommu/msm_iommu_hw-8xxx.h +2 -1
-#define SET_GLOBAL_REG(reg, base, val)       writel((val), ((base) + (reg)))
+/*
+ * The writes to the global/context registers needs to be synced only after

drivers/iommu/msm_iommu_hw-8xxx.h line 36

Quoted 10 lines
drivers/iommu/msm_iommu_hw-8xxx.h +7 -2
+ * all the configuration writes are done. So use relaxed accessors and
+ * a barrier at the end.
+ */
+#define SET_GLOBAL_REG_RELAXED(reg, base, val) \
+                            writel_relaxed((val), ((base) + (reg)))
 
-#define SET_CTX_REG(reg, base, ctx, val) \
-                     writel((val), ((base) + (reg) + ((ctx) << CTX_SHIFT)))
+#define SET_CTX_REG_RELAXED(reg, base, ctx, val) \
+             writel_relaxed((val), ((base) + (reg) + ((ctx) << CTX_SHIFT)))

Please add the relaxed accessors first in a separate patch, and then change over one user at a time before you remove the non-relaxed ones.

Quoted 5 lines

It's hard to believe that all users are actually performance critical, so start with the ones that gain the most performance. As commented above, some of the conversions seem particularly fishy and it's likely that a slow reset() function should not be fixed by making reset() faster but by calling it less often.

One more thing, please also convert them into inline functions when you modify them, and use normal names such as

static inline void msm_iommu_write(struct msm_iommu_dev *iommu, unsigned int reg, u32 val)

{
	writel(val, iommu->base + reg);
}

static inline void msm_iommu_context_write(struct msm_iommu_ctx_dev *ctx, unsigned int reg, u32 val)

{
	writel(val, ctx->iommu->base + ctx << CTX_SHIFT + reg, val);
}

Arnd

author
#10 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

In reply to Arnd Bergmann

Hi Arnd,

Quoted 13 lines

drivers/iommu/msm_iommu.c static void msm_iommu_reset(void __iomem *base, int ncb) · line 130

Quoted 8 lines
drivers/iommu/msm_iommu.c +3 -0
@@ -124,6 +124,9 @@ static void msm_iommu_reset(void __iomem *base, int ncb)
 		SET_TLBLKCR(base, ctx, 0);
 		SET_CONTEXTIDR(base, ctx, 0);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }

Why do the above use the relaxed writes? Do you have any performance numbers showing that skipping the sync for the reset makes a measurable difference?

Quoted 4 lines

How did you prove that skipping the sync before the write is safe?

How about resetting the iommu less often instead?

I had measured the numbers only for the full usecase path, not for the reset path alone. I saw improvement of about 5% on full numbers.
As you said, the reset path would be called only less often
and might not bring a measurable change. I did not see a difference in behavior when changing the sync to happen after the writes. But my understanding was that the sync after the writes was required to ensure write completion.

I should have made smaller patches to do this change.
The only patch relevant for this series is the one that changes the write in _iotlb_range function. Rest of the changes, should be added one by one in a separate series.

Quoted 16 lines

drivers/iommu/msm_iommu.c static void __flush_iotlb(void *cookie) · line 152

Quoted 11 lines
drivers/iommu/msm_iommu.c +3 -0
 static void __flush_iotlb(void *cookie)
@@ -141,6 +144,9 @@ static void __flush_iotlb(void *cookie)
 		list_for_each_entry(master, &iommu->ctx_list, list)
 			SET_CTX_TLBIALL(iommu->base, master->num, 0);
 
+		/* To ensure completion of TLBIALL above */
+		mb();
+
 		__disable_clocks(iommu);
 	}
 fail:

__disable_clocks() takes spinlocks and accesses the hardware, which in turn will also involve multiple syncs, so this seems like a premature optimization.

Quoted 2 lines

Have you tried just leaving the clocks enabled? I'd suspect you could gain more performance that way.

I have not tried by keep clocks enabled always. But intention here was to have more granular clock control. But agree that the barrier might not be needed in this case as it is indirectly taken care. I will remove this here and explain it.

Quoted 12 lines

drivers/iommu/msm_iommu.c fail: · line 192

Quoted 9 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -181,7 +187,8 @@ fail:
 
 static void __flush_iotlb_sync(void *cookie)
 {
-	/* To avoid a null function pointer */
+	/* To ensure completion of the TLBIVA in __flush_iotlb_range */
+	mb();
 }

I don't understand the specific race from the comment.

Quoted 3 lines

What operation comes after this that relies on __flush_iotlb_range having completed, and how does an mb() guarantee this?

The flush_iotlb_range operation invalidates the tlb for writes to pagetable and the finally calls the sync operation to ensure completion of the flush and this is required before returning back to the client of the iommu. In the case of this iommu, only a barrier is required to ensure completion of the invalidate operation.

Quoted 5 lines

This seems to be a bug fix that is unrelated to the change to use writel_relaxed(), so better split it out into a separate patch, with a longer changeset description. Did you spot this race by running into incorrect data, or by inspection?

No i did not see a data corruption issue without the mb(), but that it would have been hidden in someother way as well. Another difference was the sync was done before the write previously and now its moved after the write. As i understand sync after the write is correct. So i will change this patch with more description and move rest of that changes out.

Quoted 15 lines

drivers/iommu/msm_iommu.c static void config_mids(struct msm_iommu_dev *iommu, · line 249

Quoted 10 lines
drivers/iommu/msm_iommu.c +3 -0
 static const struct iommu_gather_ops msm_iommu_gather_ops = {
@@ -235,6 +242,9 @@ static void config_mids(struct msm_iommu_dev *iommu,
 		/* Set security bit override to be Non-secure */
 		SET_NSCFG(iommu->base, mid, 3);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 

This looks similar to the msm_iommu_reset() case. Maybe put those two into one patch, or find a way to run config_mids() less often so it doesn't show up in the profiles any more.

Quoted 4 lines

If you hit this often enough that it causes performance problems, it's more likely that there is a bug in your code than that changing to relaxed accessors is a good idea.

Ok, similar to reset this is called less often compared to flushes and may not show difference in performance. I will move this out.

Quoted 26 lines
Quoted 12 lines
drivers/iommu/msm_iommu.c +3 -0
 static void __reset_context(void __iomem *base, int ctx)
@@ -257,6 +267,9 @@ static void __reset_context(void __iomem *base, int ctx)
 	SET_TLBFLPTER(base, ctx, 0);
 	SET_TLBSLPTER(base, ctx, 0);
 	SET_TLBLKCR(base, ctx, 0);
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static void __program_context(void __iomem *base, int ctx,

drivers/iommu/msm_iommu.c static void __program_context(void __iomem *base, int ctx, · line 326

Quoted 9 lines
drivers/iommu/msm_iommu.c +3 -0
@@ -305,6 +318,9 @@ static void __program_context(void __iomem *base, int ctx,
 
 	/* Enable the MMU */
 	SET_M(base, ctx, 1);
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }
 
 static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)

Maybe one more patch for these? I can see that __reset_context/__program_context would be run often enough to make a difference, though maybe not as much as the flushes.

Quoted 4 lines

Also, split this in two patches: one that adds a comment describing how you proved that you don't need barriers before the writes, and another one adding the barrier afterwards, with a description of the failure scenario.

ok, i will split it. I did not see a failure though explicitly. It is based on the understanding that the sync after the write is more appropriate
than before it.

Quoted 10 lines
Quoted 10 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -500,7 +516,8 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
 	/* Invalidate context TLB */
 	SET_CTX_TLBIALL(iommu->base, master->num, 0);
 	SET_V2PPR(iommu->base, master->num, va & V2Pxx_VA);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	par = GET_PAR(iommu->base, master->num);
 
Quoted 7 lines

drivers/iommu/msm_iommu.c static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, · line 523

Quoted 1 line
drivers/iommu/msm_iommu.c +0 -0
 	/* We are dealing with a supersection */

In this case, I'd say it's better to rewrite the function to avoid the
read: iova_to_phys() should be fast, and not require hardware access. Getting rid of the hardware access by using an in-memory cache for this should gain more than just removing the barriers, as an MMIO read is always slow

Ok, you mean using the software walk through ? I will check on this to measure
the latency difference. If thats true, then the iopgtable ops itself provides a
function for iova_to_phys conversion, so that can be used.

Quoted 13 lines

drivers/iommu/msm_iommu.c static int msm_iommu_probe(struct platform_device *pdev) · line 736

Quoted 9 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -714,7 +731,8 @@ static int msm_iommu_probe(struct platform_device *pdev)
 	par = GET_PAR(iommu->base, 0);
 	SET_V2PCFG(iommu->base, 0, 0);
 	SET_M(iommu->base, 0, 0);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	if (!par) {

Probe() clearly isn't performance sensitive, so please back this out and use the non-relaxed accessors.

ok, will change this back.

Quoted 17 lines
Quoted 17 lines
drivers/iommu/msm_iommu_hw-8xxx.h +7 -1
index fc16010..fe2c5ca 100644
@@ -24,13 +24,19 @@
 #define GET_CTX_REG(reg, base, ctx) \
 				(readl((base) + (reg) + ((ctx) << CTX_SHIFT)))
 
-#define SET_GLOBAL_REG(reg, base, val)	writel((val), ((base) + (reg)))
+/*
+ * The writes to the global/context registers needs to be synced only after
+ * all the configuration writes are done. So use relaxed accessors and
+ * a barrier at the end.
+ */
+#define SET_GLOBAL_REG_RELAXED(reg, base, val) \
+			       writel_relaxed((val), ((base) + (reg)))
 
Quoted 8 lines

drivers/iommu/msm_iommu_hw-8xxx.h line 36

Quoted 4 lines
drivers/iommu/msm_iommu_hw-8xxx.h +2 -2
-#define SET_CTX_REG(reg, base, ctx, val) \
-			writel((val), ((base) + (reg) + ((ctx) << CTX_SHIFT)))
+#define SET_CTX_REG_RELAXED(reg, base, ctx, val) \
+		writel_relaxed((val), ((base) + (reg) + ((ctx) << CTX_SHIFT)))

Please add the relaxed accessors first in a separate patch, and then change over one user at a time before you remove the non-relaxed ones.

ok

Quoted 5 lines

It's hard to believe that all users are actually performance critical, so start with the ones that gain the most performance. As commented above, some of the conversions seem particularly fishy and it's likely that a slow reset() function should not be fixed by making reset() faster but by calling it less often.

Ok. Will change this. So i will split this in to separate series, one patch to modify relevant the flush_iotlb_range function in this series and rest of all changes as a driver improvement in one more.

Quoted 4 lines

Can you just remove those macros, and open-code the function calls?

This is an unnecessary obfuscation that now also hides the fact that you are using relaxed accessors.

Ok, will make this in to inline functions to make it obvious.

Regards,
Sricharan

#11 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Quoted 17 lines · CEST Sricharan

Hi Arnd,

Quoted 15 lines

drivers/iommu/msm_iommu.c static void msm_iommu_reset(void __iomem *base, int ncb) · line 130

Quoted 8 lines
drivers/iommu/msm_iommu.c +3 -0
@@ -124,6 +124,9 @@ static void msm_iommu_reset(void __iomem *base, int ncb)
 		SET_TLBLKCR(base, ctx, 0);
 		SET_CONTEXTIDR(base, ctx, 0);
 	}
+
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 }

Why do the above use the relaxed writes? Do you have any performance numbers showing that skipping the sync for the reset makes a measurable difference?

How did you prove that skipping the sync before the write is safe?

Quoted 8 lines
Quoted 2 lines

How about resetting the iommu less often instead?

I had measured the numbers only for the full usecase path, not for the reset path alone. I saw improvement of about 5% on full numbers. As you said, the reset path would be called only less often
and might not bring a measurable change. I did not see a difference in behavior when changing the sync to happen after the writes.

Ok, then better not change it.

Quoted 2 lines

But my understanding was that
the sync after the writes was required to ensure write completion.

Can you cite the relevant documentation on this? Is this specific to the Qualcomm CPU implementation or the IOMMU? I don't think the ARM architecture requires anything like this in general.

Quoted 3 lines

I should have made smaller patches to do this change.
The only patch relevant for this series is the one that changes the write in _iotlb_range function. Rest of the changes, should be added one by one in a separate series.

If you see the same 5% performance improvement with a simpler change, then better do only that. The IOMMU infrastructure is rather sensitive to having correct barriers everywhere, so this minimizes the risk of getting it wrong somewhere.

Quoted 15 lines
Quoted 11 lines

drivers/iommu/msm_iommu.c fail: · line 192

Quoted 8 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -181,7 +187,8 @@ fail:
 
 static void __flush_iotlb_sync(void *cookie)
 {
-	/* To avoid a null function pointer */
+	/* To ensure completion of the TLBIVA in __flush_iotlb_range */
+	mb();
 }

I don't understand the specific race from the comment.

Quoted 3 lines

What operation comes after this that relies on __flush_iotlb_range having completed, and how does an mb() guarantee this?

Quoted 5 lines

The flush_iotlb_range operation invalidates the tlb for writes to pagetable and the finally calls the sync operation to ensure completion of the flush and this is required before returning back to the client of the iommu. In the case of this iommu, only a barrier is required to ensure completion of the invalidate operation.

This doesn't answer my question: What operation would a client do that requires the flush to be completed here? A barrier is always defined in terms of things that come before it in combination with things that come after it.

Any operation that could trigger a DMA from a device is required to have a barrier preceding it (usually wmb() one implied by writel()), so this is clearly not about a driver that installs a DMA mapping before starting a DMA, but I don't see what else it would be.

Quoted 6 lines
Quoted 5 lines

This seems to be a bug fix that is unrelated to the change to use writel_relaxed(), so better split it out into a separate patch, with a longer changeset description. Did you spot this race by running into incorrect data, or by inspection?

Quoted 6 lines

No i did not see a data corruption issue without the mb(), but that it would have been hidden in someother way as well. Another difference was the sync was done before the write previously and now its moved after the write. As i understand sync after the write is correct. So i will change this patch with more description and move rest of that changes out.

Ok.

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -500,7 +516,8 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
 	/* Invalidate context TLB */
 	SET_CTX_TLBIALL(iommu->base, master->num, 0);
 	SET_V2PPR(iommu->base, master->num, va & V2Pxx_VA);
-
+	/* Ensure completion of relaxed writes from the above SET macros */
+	mb();
 	par = GET_PAR(iommu->base, master->num);
 
Quoted 7 lines

drivers/iommu/msm_iommu.c static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, · line 523

Quoted 1 line
drivers/iommu/msm_iommu.c +0 -0
 	/* We are dealing with a supersection */

In this case, I'd say it's better to rewrite the function to avoid the
read: iova_to_phys() should be fast, and not require hardware access. Getting rid of the hardware access by using an in-memory cache for this should gain more than just removing the barriers, as an MMIO read is always slow

Quoted 3 lines

Ok, you mean using the software walk through ? I will check on this to measure
the latency difference. If thats true, then the iopgtable ops itself provides a
function for iova_to_phys conversion, so that can be used.

I hadn't realized that this is a lookup in the hardware, rather than reading a static register. It's probably a good idea to check this anyway.

Arnd

author
#12 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Hi Arnd,

<snip..>

Quoted 8 lines
Quoted 5 lines

I had measured the numbers only for the full usecase path, not for the reset path alone. I saw improvement of about 5% on full numbers. As you said, the reset path would be called only less often
and might not bring a measurable change. I did not see a difference in behavior when changing the sync to happen after the writes.

Ok, then better not change it.

Ok.

Quoted 7 lines
Quoted 2 lines

But my understanding was that
the sync after the writes was required to ensure write completion.

Can you cite the relevant documentation on this? Is this specific to the Qualcomm CPU implementation or the IOMMU? I don't think the ARM architecture requires anything like this in general.

My explanation was not correct. So the whole reason for doing the sync here was to make sure that client is going to observe the effect the of tlb invalidation before starting any dma operation. But as you have explained below, if it is implicit that any operation
from a device that could trigger a dma should have an barrier preceding
that, then the a sync here may not be needed.

Quoted 27 lines
Quoted 16 lines
Quoted 12 lines

drivers/iommu/msm_iommu.c fail: · line 192

Quoted 9 lines
drivers/iommu/msm_iommu.c +2 -1
@@ -181,7 +187,8 @@ fail:
 
 static void __flush_iotlb_sync(void *cookie)
 {
-	/* To avoid a null function pointer */
+	/* To ensure completion of the TLBIVA in __flush_iotlb_range */
+	mb();
 }

I don't understand the specific race from the comment.

Quoted 3 lines

What operation comes after this that relies on __flush_iotlb_range having completed, and how does an mb() guarantee this?

Quoted 5 lines

The flush_iotlb_range operation invalidates the tlb for writes to pagetable and the finally calls the sync operation to ensure completion of the flush and this is required before returning back to the client of the iommu. In the case of this iommu, only a barrier is required to ensure completion of the invalidate operation.

This doesn't answer my question: What operation would a client do that requires the flush to be completed here? A barrier is always defined in terms of things that come before it in combination with things that come after it.

Quoted 5 lines

Any operation that could trigger a DMA from a device is required to have a barrier preceding it (usually wmb() one implied by writel()), so this is clearly not about a driver that installs a DMA mapping before starting a DMA, but I don't see what else it would be.

Ok, so i was doing this from the idea that, other iommu drivers
where polling on a status bit in their sync call to ensure completion
of pending TLB invalidations. But in this case, there is no status bit.
So added a barrier to have no ordering issues before the client
triggers the dma operation. But as you say above that it is implicit that the device would have a barrier before starting the trigger, then the barrier here becomes redundant.

<snip..>

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

In this case, I'd say it's better to rewrite the function to avoid the
read: iova_to_phys() should be fast, and not require hardware access. Getting rid of the hardware access by using an in-memory cache for this should gain more than just removing the barriers, as an MMIO read is always slow

Quoted 7 lines
Quoted 3 lines

Ok, you mean using the software walk through ? I will check on this to measure
the latency difference. If thats true, then the iopgtable ops itself provides a
function for iova_to_phys conversion, so that can be used.

I hadn't realized that this is a lookup in the hardware, rather than reading a static register. It's probably a good idea to check this anyway.

Ok, will measure the difference and have the better one.

Regards,
Sricharan

#13 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Quoted 7 lines · CEST Sricharan
Quoted 6 lines

Any operation that could trigger a DMA from a device is required to have a barrier preceding it (usually wmb() one implied by writel()), so this is clearly not about a driver that installs a DMA mapping before starting a DMA, but I don't see what else it would be.

Quoted 7 lines

Ok, so i was doing this from the idea that, other iommu drivers
where polling on a status bit in their sync call to ensure completion
of pending TLB invalidations. But in this case, there is no status bit.
So added a barrier to have no ordering issues before the client
triggers the dma operation. But as you say above that it is implicit that the device would have a barrier before starting the trigger, then the barrier here becomes redundant.

Ok. There are two more things to note here:

* On other platforms, polling the register is likely required because an MMIO write is "posted", meaning that a sync after writel() will only ensure that it has left the CPU write queue, but it may still be on the bus fabric and whatever side-effects are triggered by the write are normally not guaranteed to be completed even after the 'sync'. You need to check the datasheet for your IOMMU to find out whether the 'dsb' instruction actually has any effect on the IOMMU. If not, then neither the barrier that you add here nor the barrier in the following writel() is sufficient.

* The one barrier that is normally required in an IOMMU is between updating the in-memory page tables and the following MMIO store that triggers the TLB flush for that entry. This barrier is implied by writel() but not writel_relaxed(). If you don't have a hardware page table walker in your IOMMU, you don't need to worry about this.

Arnd

author
#14 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Hi Arnd,

Quoted 10 lines
Quoted 7 lines

Ok, so i was doing this from the idea that, other iommu drivers
where polling on a status bit in their sync call to ensure completion
of pending TLB invalidations. But in this case, there is no status bit.
So added a barrier to have no ordering issues before the client
triggers the dma operation. But as you say above that it is implicit that the device would have a barrier before starting the trigger, then the barrier here becomes redundant.

Ok. There are two more things to note here:

Quoted 10 lines

* On other platforms, polling the register is likely required because an MMIO write is "posted", meaning that a sync after writel() will only ensure that it has left the CPU write queue, but it may still be on the bus fabric and whatever side-effects are triggered by the write are normally not guaranteed to be completed even after the 'sync'. You need to check the datasheet for your IOMMU to find out whether the 'dsb' instruction actually has any effect on the IOMMU. If not, then neither the barrier that you add here nor the barrier in the following writel() is sufficient.

Thanks for the detailed explanation.
i will check this. So with this, i think that if the iommu does not
support polling for its status, then it should listen to 'dsb' otherwise there will no be no way of make it coherent ?

Quoted 7 lines

* The one barrier that is normally required in an IOMMU is between updating the in-memory page tables and the following MMIO store that triggers the TLB flush for that entry. This barrier is implied by writel() but not writel_relaxed(). If you don't have a hardware page table walker in your IOMMU, you don't need to worry about this.

To get my understanding correct here, is the barrier required here because
of speculative fetch ?

Regards,
Sricharan

#15 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Quoted 22 lines · CEST Sricharan

Hi Arnd,

Quoted 10 lines
Quoted 7 lines

Ok, so i was doing this from the idea that, other iommu drivers
where polling on a status bit in their sync call to ensure completion
of pending TLB invalidations. But in this case, there is no status bit.
So added a barrier to have no ordering issues before the client
triggers the dma operation. But as you say above that it is implicit that the device would have a barrier before starting the trigger, then the barrier here becomes redundant.

Ok. There are two more things to note here:

Quoted 10 lines

* On other platforms, polling the register is likely required because an MMIO write is "posted", meaning that a sync after writel() will only ensure that it has left the CPU write queue, but it may still be on the bus fabric and whatever side-effects are triggered by the write are normally not guaranteed to be completed even after the 'sync'. You need to check the datasheet for your IOMMU to find out whether the 'dsb' instruction actually has any effect on the IOMMU. If not, then neither the barrier that you add here nor the barrier in the following writel() is sufficient.

Quoted 4 lines

Thanks for the detailed explanation.
i will check this. So with this, i think that if the iommu does not
support polling for its status, then it should listen to 'dsb' otherwise there will no be no way of make it coherent ?

It's more likely that you have to do a readl() after the writel() to any address inside of the device in order to ensure the writel() has completed, but that is something that the hardware manual for the iommu should describe.

Quoted 9 lines
Quoted 7 lines

* The one barrier that is normally required in an IOMMU is between updating the in-memory page tables and the following MMIO store that triggers the TLB flush for that entry. This barrier is implied by writel() but not writel_relaxed(). If you don't have a hardware page table walker in your IOMMU, you don't need to worry about this.

To get my understanding correct here, is the barrier required here because
of speculative fetch ?

It doesn't have to be a speculative fetch, it could also be a normal fetch triggered by a DMA. The point is that the CPU is free to reorder the store to (io page table) memory relative to the store to the IOMMU flush register, and when you directly follow up with a store to the DMA master that triggers a transfer, this transfer can hit the IOMMU and cause the stale page table entry to be read.

I guess in practice the barrier that comes before the MMIO write to the DMA master would ensure ordering of the DMA after both the IOPTE update and the MMIO flush (unless there was the speculative fetch you mentioned), but this is where I'm no longer confident enough in my pwn understanding of th ordering rules to rely on that. Having the barrier between the IOPTE update and the flush certainly leaves no room for ambiguity.

Arnd

author
#16 lore raw

PATCH v5 6/7 iommu/msm: Use writel_relaxed and add a barrier

Hi Arnd,

Quoted 15 lines
Quoted 10 lines
Quoted 10 lines

* On other platforms, polling the register is likely required because an MMIO write is "posted", meaning that a sync after writel() will only ensure that it has left the CPU write queue, but it may still be on the bus fabric and whatever side-effects are triggered by the write are normally not guaranteed to be completed even after the 'sync'. You need to check the datasheet for your IOMMU to find out whether the 'dsb' instruction actually has any effect on the IOMMU. If not, then neither the barrier that you add here nor the barrier in the following writel() is sufficient.

Quoted 4 lines

Thanks for the detailed explanation.
i will check this. So with this, i think that if the iommu does not
support polling for its status, then it should listen to 'dsb' otherwise there will no be no way of make it coherent ?

Quoted 5 lines

It's more likely that you have to do a readl() after the writel() to any address inside of the device in order to ensure the writel() has completed, but that is something that the hardware manual for the iommu should describe.

ok, get it. So will do it as required for here.

Quoted 17 lines
Quoted 9 lines
Quoted 7 lines

* The one barrier that is normally required in an IOMMU is between updating the in-memory page tables and the following MMIO store that triggers the TLB flush for that entry. This barrier is implied by writel() but not writel_relaxed(). If you don't have a hardware page table walker in your IOMMU, you don't need to worry about this.

To get my understanding correct here, is the barrier required here because
of speculative fetch ?

It doesn't have to be a speculative fetch, it could also be a normal fetch triggered by a DMA. The point is that the CPU is free to reorder the store to (io page table) memory relative to the store to the IOMMU flush register, and when you directly follow up with a store to the DMA master that triggers a transfer, this transfer can hit the IOMMU and cause the stale page table entry to be read.

Quoted 7 lines

I guess in practice the barrier that comes before the MMIO write to the DMA master would ensure ordering of the DMA after both the IOPTE update and the MMIO flush (unless there was the speculative fetch you mentioned), but this is where I'm no longer confident enough in my pwn understanding of th ordering rules to rely on that. Having the barrier between the IOPTE update and the flush certainly leaves no room for ambiguity.

Ok understand. Also i think speculative access if any, should
go away if unmap is done first and then remap by clients.

Regards,
Sricharan

#17 lore raw

PATCH v5 7/7 iommu/msm: Remove driver BROKEN

In reply to Sricharan R

Now that the driver is DT adapted, bus_set_iommu gets called only when on compatible matching. So the driver should not break multiplatform builds now. So remove the BROKEN config.

---
 drivers/iommu/Kconfig | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/Kconfig +0 -1
index 761be35..f3d9fd0 100644
@@ -90,7 +90,6 @@ config MSM_IOMMU
 	bool "MSM IOMMU Support"
 	depends on ARM
 	depends on ARCH_MSM8X60 || ARCH_MSM8960 || COMPILE_TEST
-	depends on BROKEN
 	select IOMMU_API
 	select IOMMU_IO_PGTABLE_ARMV7S
 	help
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#18 lore raw

v5 cover iommu/msm: Add DT adaptation and generic bindings support

In reply to Sricharan R
Quoted 27 lines · Sricharan R

The msm_iommu.c driver currently works based on platform data.
A single master device can be connected to more than one iommu and multiple contexts in each of the iommu. This association between master and iommus was represented from platform data using parent/child devices. The master drivers were responsible for attaching all of the iommus/context to a domain. Now the platform data support is removed and DT support is added. The master/iommus are added through generic iommu bindings.

This is essentially rework of the patch posted earlier by Rob Clark <[email protected]>. This series folds the changes in to the existing driver with the addition of generic bindings.

         http://www.spinics.net/lists/linux-arm-msm/msg10077.html

Tested this series on ifc6410 board.

[V5] Changed the compatible binding name as per comments, added comments
for usage of barriers in patch 6.

[V4] Addressed comments for making the iommu compatible binding more soc
specific and updated the documentation for the iommu clocks.

[V3] Addressed comments to correct the usage
of the #iommu-cells binding, improve the flush_iotlb_range function, added a new patch to use writel_relaxed for register access and split up the documentation patch.

Quoted 5 lines

[V2] Adapted the driver to use generic ARMV7S short descriptor pagetable ops
and addressed comments.

[V1]

    https://lists.linuxfoundation.org/pipermail/iommu/2015-August/014074.html

Tested with the drm/msm driver as an iommu client on IFC6410 board (APQ8064).

Quoted 21 lines

Sricharan R (7):
iommu/msm: Add DT adaptation
documentation: iommu: Add bindings for msm,iommu-v0 ip iommu/msm: Move the contents from msm_iommu_dev.c to msm_iommu.c iommu/msm: Add support for generic master bindings iommu/msm: use generic ARMV7S short descriptor pagetable ops iommu/msm: Use writel_relaxed and add a barrier iommu/msm: Remove driver BROKEN

  .../devicetree/bindings/iommu/msm,iommu-v0.txt     |  64 ++
  drivers/iommu/Kconfig                              |   2 +-
  drivers/iommu/Makefile                             |   2 +-
  drivers/iommu/msm_iommu.c                          | 885 +++++++++++----------
  drivers/iommu/msm_iommu.h                          |  73 +-
  drivers/iommu/msm_iommu_dev.c                      | 381 ---------
  drivers/iommu/msm_iommu_hw-8xxx.h                  | 109 +--
  7 files changed, 636 insertions(+), 880 deletions(-)

create mode 100644 Documentation/devicetree/bindings/iommu/msm,iommu-v0.txt delete mode 100644 drivers/iommu/msm_iommu_dev.c

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
Forum, hosted by The Linux Foundation
#19 lore raw

v5 cover iommu/msm: Add DT adaptation and generic bindings support

In reply to Sricharan R

Hi Sricharan,

Thanks for the patchset,

Quoted 7 lines · Sricharan R

The msm_iommu.c driver currently works based on platform data.
A single master device can be connected to more than one iommu and multiple contexts in each of the iommu. This association between master and iommus was represented from platform data using parent/child devices. The master drivers were responsible for attaching all of the iommus/context to a domain. Now the platform data support is removed and DT support is added. The master/iommus are added through generic iommu bindings.

...

Quoted 20 lines

[V1]

    https://lists.linuxfoundation.org/pipermail/iommu/2015-August/014074.html

Sricharan R (7):
iommu/msm: Add DT adaptation
documentation: iommu: Add bindings for msm,iommu-v0 ip iommu/msm: Move the contents from msm_iommu_dev.c to msm_iommu.c iommu/msm: Add support for generic master bindings iommu/msm: use generic ARMV7S short descriptor pagetable ops iommu/msm: Use writel_relaxed and add a barrier iommu/msm: Remove driver BROKEN

  .../devicetree/bindings/iommu/msm,iommu-v0.txt     |  64 ++
  drivers/iommu/Kconfig                              |   2 +-
  drivers/iommu/Makefile                             |   2 +-
  drivers/iommu/msm_iommu.c                          | 885 +++++++++++----------
  drivers/iommu/msm_iommu.h                          |  73 +-
  drivers/iommu/msm_iommu_dev.c                      | 381 ---------
  drivers/iommu/msm_iommu_hw-8xxx.h                  | 109 +--
  7 files changed, 636 insertions(+), 880 deletions(-)
Quoted 2 lines

create mode 100644 Documentation/devicetree/bindings/iommu/msm,iommu-v0.txt delete mode 100644 drivers/iommu/msm_iommu_dev.c

Tested It on IFC6410 and DB600c.

--srini