linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support
@ 2014-04-17 10:33 Laurent Pinchart
  2014-04-17 10:33 ` [PATCH v2 1/5] iommu/ipmmu-vmsa: Refactor micro-TLB lookup Laurent Pinchart
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 10:33 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: linux-sh-u79uwXL29TY76Z2rM5mHXA

Hello,

This patch set adds DT support to the Renesas VMSA-compatible IPMMU driver.
The first patch refactors the driver to remove dependencies on platform data,
the second patch adds the DT bindings documentation and the third patch
implement them in the driver.

The next two patches show real-life examples for IPMMU DT bindings usage.
Patch 4/5 adds IPMMU DT nodes to the r8a7791 SoC dtsi file, and patch 5/5
enables IOMMU support for the VSP1 on the same platform.

The patches are based on top of the IPMMU driver previously submitted to the
iommu mailing list. The last patch additionally requires to VSP1 DT support
patch series previously submitted to the linux-media mailing list and is thus
a test patch only at the moment, not meant to be merged yet.

The DT bindings are pretty simple, with only three standard properties in the
IPMMU DT node. The driver doesn't need to know the number of micro-TLBs (a
micro-TLB being a port to which a bus master device is attached, identified by
a number similar in purpose to a stream ID), so I've decided not to specify it
in DT. The micro-TLBs are configured when a bus master device is attached or
detached, and at that point the device provides its micro-TLB number.

The only reason I can foresee why the number of micro-TLBs would be useful is 
to iterate over micro-TLBs when the driver probes the device to disable them 
all. A mask would probably be better than a number in that case, and I think 
we can always add that later if we find a need for it.

The device to IOMMU association is represented in the bus master device nodes
using an iommus property, similarly to interrupts or clocks. This model departs
from the ARM SMMU DT bindings that represent the same information inside the
IOMMU DT node. Will, please feel free to tell me if you believe this model
isn't good.

Every IPMMU instance serves multiple bus master devices and implements four
independent page tables and TLBs. Each bus master can be freely assigned to one
of the page tables, lowering the risk of TLB miss when multiple bus masters
require address translation at the same time. I've decided not to express the
bus master to page table association in DT as this seems to me to be a software
configuration decision, not a hardware property. Feel free to disagree.

As a side note, there's no API at the moment to configure that association. My
plan is to assign bus masters to page tables automatically in the driver in a
round-robin way. A more configurable solution might be needed later, but I
believe that's out of scope of DT.

Changes since v1:

- Fixed typos
- Add a missing of_node_put()

Cc: devicetree@vger.kernel.org
Cc: Will Deacon <will.deacon@arm.com>

Laurent Pinchart (5):
  iommu/ipmmu-vmsa: Refactor micro-TLB lookup
  iommu/ipmmu-vmsa: Add device tree bindings documentation
  iommu/ipmmu-vmsa: Add device tree support
  ARM: shmobile: r8a7791: Add IPMMU DT nodes
  ARM: shmobile: r8a7791: Enable IOMMU support for the VSP1

 .../bindings/iommu/renesas,ipmmu-vmsa.txt          |  35 ++++++
 arch/arm/boot/dts/r8a7791.dtsi                     |  54 ++++++++++
 drivers/iommu/ipmmu-vmsa.c                         | 117 +++++++++++++--------
 3 files changed, 165 insertions(+), 41 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt

-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 1/5] iommu/ipmmu-vmsa: Refactor micro-TLB lookup
  2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
@ 2014-04-17 10:33 ` Laurent Pinchart
       [not found] ` <1397730807-5993-1-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 10:33 UTC (permalink / raw)
  To: iommu; +Cc: linux-sh

Cache the micro-TLB number in archdata allocated in the .add_device
handler instead of looking it up when the deviced is attached and
detached. This simplifies the .attach_dev and .detach_dev operations and
prepares for DT support.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/iommu/ipmmu-vmsa.c | 92 ++++++++++++++++++++++++++--------------------
 1 file changed, 52 insertions(+), 40 deletions(-)

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index a8a940a..49e00f7 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -44,6 +44,11 @@ struct ipmmu_vmsa_domain {
 	pgd_t *pgd;
 };
 
+struct ipmmu_vmsa_archdata {
+	struct ipmmu_vmsa_device *mmu;
+	unsigned int utlb;
+};
+
 static DEFINE_SPINLOCK(ipmmu_devices_lock);
 static LIST_HEAD(ipmmu_devices);
 
@@ -265,14 +270,19 @@ static void ipmmu_tlb_invalidate(struct ipmmu_vmsa_domain *domain)
  * Enable MMU translation for the microTLB.
  */
 static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
-			      const struct ipmmu_vmsa_master *master)
+			      unsigned int utlb)
 {
 	struct ipmmu_vmsa_device *mmu = domain->mmu;
 
+	/*
+	 * TODO: Reference-count the microTLB as several bus masters can be
+	 * connected to the same microTLB.
+	 */
+
 	/* TODO: What should we set the ASID to ? */
-	ipmmu_write(mmu, IMUASID(master->utlb), 0);
+	ipmmu_write(mmu, IMUASID(utlb), 0);
 	/* TODO: Do we need to flush the microTLB ? */
-	ipmmu_write(mmu, IMUCTR(master->utlb),
+	ipmmu_write(mmu, IMUCTR(utlb),
 		    IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_FLUSH |
 		    IMUCTR_MMUEN);
 }
@@ -281,11 +291,11 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
  * Disable MMU translation for the microTLB.
  */
 static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain,
-			       const struct ipmmu_vmsa_master *master)
+			       unsigned int utlb)
 {
 	struct ipmmu_vmsa_device *mmu = domain->mmu;
 
-	ipmmu_write(mmu, IMUCTR(master->utlb), 0);
+	ipmmu_write(mmu, IMUCTR(utlb), 0);
 }
 
 static void ipmmu_flush_pgtable(struct ipmmu_vmsa_device *mmu, void *addr,
@@ -674,21 +684,6 @@ static int ipmmu_handle_mapping(struct ipmmu_vmsa_domain *domain,
  * IOMMU Operations
  */
 
-static const struct ipmmu_vmsa_master *
-ipmmu_find_master(struct ipmmu_vmsa_device *ipmmu, struct device *dev)
-{
-	const struct ipmmu_vmsa_master *master = ipmmu->pdata->masters;
-	const char *devname = dev_name(dev);
-	unsigned int i;
-
-	for (i = 0; i < ipmmu->pdata->num_masters; ++i, ++master) {
-		if (strcmp(master->name, devname) = 0)
-			return master;
-	}
-
-	return NULL;
-}
-
 static int ipmmu_domain_init(struct iommu_domain *io_domain)
 {
 	struct ipmmu_vmsa_domain *domain;
@@ -727,9 +722,9 @@ static void ipmmu_domain_destroy(struct iommu_domain *io_domain)
 static int ipmmu_attach_device(struct iommu_domain *io_domain,
 			       struct device *dev)
 {
-	struct ipmmu_vmsa_device *mmu = dev->archdata.iommu;
+	struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
+	struct ipmmu_vmsa_device *mmu = archdata->mmu;
 	struct ipmmu_vmsa_domain *domain = io_domain->priv;
-	const struct ipmmu_vmsa_master *master;
 	unsigned long flags;
 	int ret = 0;
 
@@ -759,11 +754,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
 	if (ret < 0)
 		return ret;
 
-	master = ipmmu_find_master(mmu, dev);
-	if (!master)
-		return -EINVAL;
-
-	ipmmu_utlb_enable(domain, master);
+	ipmmu_utlb_enable(domain, archdata->utlb);
 
 	return 0;
 }
@@ -771,14 +762,10 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
 static void ipmmu_detach_device(struct iommu_domain *io_domain,
 				struct device *dev)
 {
+	struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
 	struct ipmmu_vmsa_domain *domain = io_domain->priv;
-	const struct ipmmu_vmsa_master *master;
 
-	master = ipmmu_find_master(domain->mmu, dev);
-	if (!master)
-		return;
-
-	ipmmu_utlb_disable(domain, master);
+	ipmmu_utlb_disable(domain, archdata->utlb);
 
 	/*
 	 * TODO: Optimize by disabling the context when no device is attached.
@@ -839,11 +826,26 @@ static phys_addr_t ipmmu_iova_to_phys(struct iommu_domain *io_domain,
 	return __pfn_to_phys(pte_pfn(pte)) | (iova & ~PAGE_MASK);
 }
 
+static int ipmmu_find_utlb(struct ipmmu_vmsa_device *mmu, struct device *dev)
+{
+	const struct ipmmu_vmsa_master *master = mmu->pdata->masters;
+	const char *devname = dev_name(dev);
+	unsigned int i;
+
+	for (i = 0; i < mmu->pdata->num_masters; ++i, ++master) {
+		if (strcmp(master->name, devname) = 0)
+			return master->utlb;
+	}
+
+	return -1;
+}
+
 static int ipmmu_add_device(struct device *dev)
 {
-	const struct ipmmu_vmsa_master *master = NULL;
+	struct ipmmu_vmsa_archdata *archdata;
 	struct ipmmu_vmsa_device *mmu;
 	struct iommu_group *group;
+	int utlb = -1;
 	int ret;
 
 	if (dev->archdata.iommu) {
@@ -856,10 +858,10 @@ static int ipmmu_add_device(struct device *dev)
 	spin_lock(&ipmmu_devices_lock);
 
 	list_for_each_entry(mmu, &ipmmu_devices, list) {
-		master = ipmmu_find_master(mmu, dev);
-		if (master) {
+		utlb = ipmmu_find_utlb(mmu, dev);
+		if (utlb >= 0) {
 			/*
-			 * TODO Take a reference to the master to protect
+			 * TODO Take a reference to the MMU to protect
 			 * against device removal.
 			 */
 			break;
@@ -868,10 +870,10 @@ static int ipmmu_add_device(struct device *dev)
 
 	spin_unlock(&ipmmu_devices_lock);
 
-	if (!master)
+	if (utlb < 0)
 		return -ENODEV;
 
-	if (!master->utlb >= mmu->num_utlbs)
+	if (utlb >= mmu->num_utlbs)
 		return -EINVAL;
 
 	/* Create a device group and add the device to it. */
@@ -889,7 +891,15 @@ static int ipmmu_add_device(struct device *dev)
 		return ret;
 	}
 
-	dev->archdata.iommu = mmu;
+	archdata = kzalloc(sizeof(*archdata), GFP_KERNEL);
+	if (!archdata) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	archdata->mmu = mmu;
+	archdata->utlb = utlb;
+	dev->archdata.iommu = archdata;
 
 	/*
 	 * Create the ARM mapping, used by the ARM DMA mapping core to allocate
@@ -923,6 +933,7 @@ static int ipmmu_add_device(struct device *dev)
 	return 0;
 
 error:
+	kfree(dev->archdata.iommu);
 	dev->archdata.iommu = NULL;
 	iommu_group_remove_device(dev);
 	return ret;
@@ -932,6 +943,7 @@ static void ipmmu_remove_device(struct device *dev)
 {
 	arm_iommu_detach_device(dev);
 	iommu_group_remove_device(dev);
+	kfree(dev->archdata.iommu);
 	dev->archdata.iommu = NULL;
 }
 
-- 
1.8.3.2


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

* [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation
       [not found] ` <1397730807-5993-1-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
@ 2014-04-17 10:33   ` Laurent Pinchart
       [not found]     ` <1397730807-5993-3-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 10:33 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: linux-sh-u79uwXL29TY76Z2rM5mHXA

Cc: devicetree@vger.kernel.org
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../bindings/iommu/renesas,ipmmu-vmsa.txt          | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt

diff --git a/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt b/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt
new file mode 100644
index 0000000..2b16a75
--- /dev/null
+++ b/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt
@@ -0,0 +1,35 @@
+* Renesas VMSA-Compatible IOMMU
+
+The IPMMU is an IOMMU implementation compatible with the ARM VMSA page tables.
+It provides address translation for bus masters outside of the CPU, each
+connected to the IPMMU through a port called micro-TLB.
+
+
+Required Properties:
+
+  - compatible: Must contain "renesas,ipmmu-vmsa".
+  - reg: Base address and size of the IPMMU registers.
+  - interrupts: Specifier for the MMU fault interrupt.
+
+
+Each bus master connected to an IPMMU must reference the IPMMU in its device
+node with the following property:
+
+  - iommus: A reference to the IPMMU in two cells. The first cell is a phandle
+    to the IPMMU and the second cell the number of the micro-TLB that the
+    device is connected to.
+
+
+Example: R8A7791 IPMMU-MX and VSP1-D0 bus master
+
+	ipmmu_mx: mmu@fe951800 {
+		compatible = "renasas,ipmmu-vmsa";
+		reg = <0 0xfe951800 0 0x800>;
+		interrupts = <0 222 IRQ_TYPE_LEVEL_HIGH>;
+	};
+
+	vsp1@fe928000 {
+		...
+		iommus = <&ipmmu_mx 13>;
+		...
+	};
-- 
1.8.3.2


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

* [PATCH v2 3/5] iommu/ipmmu-vmsa: Add device tree support
  2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
  2014-04-17 10:33 ` [PATCH v2 1/5] iommu/ipmmu-vmsa: Refactor micro-TLB lookup Laurent Pinchart
       [not found] ` <1397730807-5993-1-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
@ 2014-04-17 10:33 ` Laurent Pinchart
  2014-04-17 10:33 ` [PATCH v2 4/5] ARM: shmobile: r8a7791: Add IPMMU DT nodes Laurent Pinchart
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 10:33 UTC (permalink / raw)
  To: iommu; +Cc: linux-sh

Make platform data optional when the device is instantiated from DT and
look up the micro-TLB number in the bus master DT node.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/iommu/ipmmu-vmsa.c | 39 +++++++++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 49e00f7..d277bde 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -16,6 +16,7 @@
 #include <linux/io.h>
 #include <linux/iommu.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_data/ipmmu-vmsa.h>
 #include <linux/platform_device.h>
 #include <linux/sizes.h>
@@ -828,16 +829,33 @@ static phys_addr_t ipmmu_iova_to_phys(struct iommu_domain *io_domain,
 
 static int ipmmu_find_utlb(struct ipmmu_vmsa_device *mmu, struct device *dev)
 {
-	const struct ipmmu_vmsa_master *master = mmu->pdata->masters;
-	const char *devname = dev_name(dev);
-	unsigned int i;
+	struct of_phandle_args args;
+	int ret;
+
+	if (mmu->pdata) {
+		const struct ipmmu_vmsa_master *master = mmu->pdata->masters;
+		const char *devname = dev_name(dev);
+		unsigned int i;
 
-	for (i = 0; i < mmu->pdata->num_masters; ++i, ++master) {
-		if (strcmp(master->name, devname) = 0)
-			return master->utlb;
+		for (i = 0; i < mmu->pdata->num_masters; ++i, ++master) {
+			if (strcmp(master->name, devname) = 0)
+				return master->utlb;
+		}
+
+		return -1;
 	}
 
-	return -1;
+	ret = of_parse_phandle_with_fixed_args(dev->of_node, "iommus",
+					       1, 0, &args);
+	if (ret < 0)
+		return -1;
+
+	of_node_put(args.np);
+
+	if (args.np != mmu->dev->of_node)
+		return -1;
+
+	return args.args[0];
 }
 
 static int ipmmu_add_device(struct device *dev)
@@ -980,7 +998,7 @@ static int ipmmu_probe(struct platform_device *pdev)
 	int irq;
 	int ret;
 
-	if (!pdev->dev.platform_data) {
+	if (!IS_ENABLED(CONFIG_OF) && !pdev->dev.platform_data) {
 		dev_err(&pdev->dev, "missing platform data\n");
 		return -EINVAL;
 	}
@@ -1046,10 +1064,15 @@ static int ipmmu_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id ipmmu_of_ids[] = {
+	{ .compatible = "renesas,ipmmu-vmsa", },
+};
+
 static struct platform_driver ipmmu_driver = {
 	.driver = {
 		.owner = THIS_MODULE,
 		.name = "ipmmu-vmsa",
+		.of_match_table = of_match_ptr(ipmmu_of_ids),
 	},
 	.probe = ipmmu_probe,
 	.remove	= ipmmu_remove,
-- 
1.8.3.2


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

* [PATCH v2 4/5] ARM: shmobile: r8a7791: Add IPMMU DT nodes
  2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
                   ` (2 preceding siblings ...)
  2014-04-17 10:33 ` [PATCH v2 3/5] iommu/ipmmu-vmsa: Add device tree support Laurent Pinchart
@ 2014-04-17 10:33 ` Laurent Pinchart
  2014-04-17 10:33 ` [PATCH v2 5/5] [TEST] ARM: shmobile: r8a7791: Enable IOMMU support for the VSP1 Laurent Pinchart
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 10:33 UTC (permalink / raw)
  To: iommu; +Cc: linux-sh

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 arch/arm/boot/dts/r8a7791.dtsi | 49 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/arch/arm/boot/dts/r8a7791.dtsi b/arch/arm/boot/dts/r8a7791.dtsi
index 909d786..d1e446c 100644
--- a/arch/arm/boot/dts/r8a7791.dtsi
+++ b/arch/arm/boot/dts/r8a7791.dtsi
@@ -909,4 +909,53 @@
 		#size-cells = <0>;
 		status = "disabled";
 	};
+
+	ipmmu_sy0: mmu@e6280800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xe6280800 0 0x800>;
+		interrupts = <0 223 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	ipmmu_sy1: mmu@e6290800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xe6290800 0 0x800>;
+		interrupts = <0 225 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	ipmmu_ds: mmu@e6740800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xe6740800 0 0x800>;
+		interrupts = <0 198 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	ipmmu_mp: mmu@ec680800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xec680800 0 0x800>;
+		interrupts = <0 226 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	ipmmu_mx: mmu@fe951800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xfe951800 0 0x800>;
+		interrupts = <0 222 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	ipmmu_rt: mmu@ffc80800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xffc80800 0 0x800>;
+		interrupts = <0 307 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	ipmmu_gp: mmu@e62a0800 {
+		compatible = "renesas,ipmmu-vmsa";
+		reg = <0 0xe62a0800 0 0x800>;
+		interrupts = <0 260 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
 };
-- 
1.8.3.2


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

* [PATCH v2 5/5] [TEST] ARM: shmobile: r8a7791: Enable IOMMU support for the VSP1
  2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
                   ` (3 preceding siblings ...)
  2014-04-17 10:33 ` [PATCH v2 4/5] ARM: shmobile: r8a7791: Add IPMMU DT nodes Laurent Pinchart
@ 2014-04-17 10:33 ` Laurent Pinchart
  2014-04-17 11:12 ` [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation Laurent Pinchart
  2014-04-17 11:12 ` [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
  6 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 10:33 UTC (permalink / raw)
  To: iommu; +Cc: linux-sh

Not for merge yet.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 arch/arm/boot/dts/r8a7791.dtsi | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/r8a7791.dtsi b/arch/arm/boot/dts/r8a7791.dtsi
index d1e446c..e024602 100644
--- a/arch/arm/boot/dts/r8a7791.dtsi
+++ b/arch/arm/boot/dts/r8a7791.dtsi
@@ -508,6 +508,8 @@
 		interrupts = <0 267 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&mstp1_clks R8A7791_CLK_VSP1_S>;
 
+		iommus = <&ipmmu_mx 10>;
+
 		renesas,has-lut;
 		renesas,has-sru;
 		renesas,#rpf = <5>;
@@ -521,6 +523,8 @@
 		interrupts = <0 246 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&mstp1_clks R8A7791_CLK_VSP1_DU0>;
 
+		iommus = <&ipmmu_mx 13>;
+
 		renesas,has-lif;
 		renesas,has-lut;
 		renesas,#rpf = <4>;
@@ -534,6 +538,8 @@
 		interrupts = <0 247 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&mstp1_clks R8A7791_CLK_VSP1_DU1>;
 
+		iommus = <&ipmmu_mx 14>;
+
 		renesas,has-lif;
 		renesas,has-lut;
 		renesas,#rpf = <4>;
@@ -942,7 +948,6 @@
 		compatible = "renesas,ipmmu-vmsa";
 		reg = <0 0xfe951800 0 0x800>;
 		interrupts = <0 222 IRQ_TYPE_LEVEL_HIGH>;
-		status = "disabled";
 	};
 
 	ipmmu_rt: mmu@ffc80800 {
-- 
1.8.3.2


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

* Re: [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation
       [not found]     ` <1397730807-5993-3-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
@ 2014-04-17 11:08       ` Geert Uytterhoeven
       [not found]         ` <CAMuHMdVy6963wk_k7=BbOwBJ-LC7M8Yd7OAwVahERCMPzddN4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Geert Uytterhoeven @ 2014-04-17 11:08 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Linux-sh list

Hi Laurent,

On Thu, Apr 17, 2014 at 12:33 PM, Laurent Pinchart
<laurent.pinchart+renesas@ideasonboard.com> wrote:
> Cc: devicetree@vger.kernel.org
> Cc: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

How come your git-send-email didn't honor the two CC lines aboves?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation
       [not found]         ` <CAMuHMdVy6963wk_k7=BbOwBJ-LC7M8Yd7OAwVahERCMPzddN4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-04-17 11:11           ` Laurent Pinchart
  0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 11:11 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Laurent Pinchart, Linux-sh list

On Thursday 17 April 2014 13:08:01 Geert Uytterhoeven wrote:
> Hi Laurent,
> 
> On Thu, Apr 17, 2014 at 12:33 PM, Laurent Pinchart
> 
> <laurent.pinchart+renesas@ideasonboard.com> wrote:
> > Cc: devicetree@vger.kernel.org
> > Cc: Will Deacon <will.deacon@arm.com>
> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> 
> How come your git-send-email didn't honor the two CC lines aboves?

Because I've made a mistake, obviously :-/ Sorry about that. I'll resend this 
patch and the cover letter.

-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation
  2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
                   ` (4 preceding siblings ...)
  2014-04-17 10:33 ` [PATCH v2 5/5] [TEST] ARM: shmobile: r8a7791: Enable IOMMU support for the VSP1 Laurent Pinchart
@ 2014-04-17 11:12 ` Laurent Pinchart
  2014-04-17 11:12 ` [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
  6 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 11:12 UTC (permalink / raw)
  To: iommu; +Cc: linux-sh, devicetree, Will Deacon

Cc: devicetree@vger.kernel.org
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 .../bindings/iommu/renesas,ipmmu-vmsa.txt          | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt

diff --git a/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt b/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt
new file mode 100644
index 0000000..2b16a75
--- /dev/null
+++ b/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt
@@ -0,0 +1,35 @@
+* Renesas VMSA-Compatible IOMMU
+
+The IPMMU is an IOMMU implementation compatible with the ARM VMSA page tables.
+It provides address translation for bus masters outside of the CPU, each
+connected to the IPMMU through a port called micro-TLB.
+
+
+Required Properties:
+
+  - compatible: Must contain "renesas,ipmmu-vmsa".
+  - reg: Base address and size of the IPMMU registers.
+  - interrupts: Specifier for the MMU fault interrupt.
+
+
+Each bus master connected to an IPMMU must reference the IPMMU in its device
+node with the following property:
+
+  - iommus: A reference to the IPMMU in two cells. The first cell is a phandle
+    to the IPMMU and the second cell the number of the micro-TLB that the
+    device is connected to.
+
+
+Example: R8A7791 IPMMU-MX and VSP1-D0 bus master
+
+	ipmmu_mx: mmu@fe951800 {
+		compatible = "renasas,ipmmu-vmsa";
+		reg = <0 0xfe951800 0 0x800>;
+		interrupts = <0 222 IRQ_TYPE_LEVEL_HIGH>;
+	};
+
+	vsp1@fe928000 {
+		...
+		iommus = <&ipmmu_mx 13>;
+		...
+	};
-- 
1.8.3.2


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

* [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support
  2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
                   ` (5 preceding siblings ...)
  2014-04-17 11:12 ` [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation Laurent Pinchart
@ 2014-04-17 11:12 ` Laurent Pinchart
  2014-04-17 15:55   ` Will Deacon
  6 siblings, 1 reply; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 11:12 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, Will Deacon,
	linux-sh-u79uwXL29TY76Z2rM5mHXA

Hello,

This patch set adds DT support to the Renesas VMSA-compatible IPMMU driver.
The first patch refactors the driver to remove dependencies on platform data,
the second patch adds the DT bindings documentation and the third patch
implement them in the driver.

The next two patches show real-life examples for IPMMU DT bindings usage.
Patch 4/5 adds IPMMU DT nodes to the r8a7791 SoC dtsi file, and patch 5/5
enables IOMMU support for the VSP1 on the same platform.

The patches are based on top of the IPMMU driver previously submitted to the
iommu mailing list. The last patch additionally requires to VSP1 DT support
patch series previously submitted to the linux-media mailing list and is thus
a test patch only at the moment, not meant to be merged yet.

The DT bindings are pretty simple, with only three standard properties in the
IPMMU DT node. The driver doesn't need to know the number of micro-TLBs (a
micro-TLB being a port to which a bus master device is attached, identified by
a number similar in purpose to a stream ID), so I've decided not to specify it
in DT. The micro-TLBs are configured when a bus master device is attached or
detached, and at that point the device provides its micro-TLB number.

The only reason I can foresee why the number of micro-TLBs would be useful is 
to iterate over micro-TLBs when the driver probes the device to disable them 
all. A mask would probably be better than a number in that case, and I think 
we can always add that later if we find a need for it.

The device to IOMMU association is represented in the bus master device nodes
using an iommus property, similarly to interrupts or clocks. This model departs
from the ARM SMMU DT bindings that represent the same information inside the
IOMMU DT node. Will, please feel free to tell me if you believe this model
isn't good.

Every IPMMU instance serves multiple bus master devices and implements four
independent page tables and TLBs. Each bus master can be freely assigned to one
of the page tables, lowering the risk of TLB miss when multiple bus masters
require address translation at the same time. I've decided not to express the
bus master to page table association in DT as this seems to me to be a software
configuration decision, not a hardware property. Feel free to disagree.

As a side note, there's no API at the moment to configure that association. My
plan is to assign bus masters to page tables automatically in the driver in a
round-robin way. A more configurable solution might be needed later, but I
believe that's out of scope of DT.

Changes since v1:

- Fixed typos
- Add a missing of_node_put()

Cc: devicetree@vger.kernel.org
Cc: Will Deacon <will.deacon@arm.com>

Laurent Pinchart (5):
  iommu/ipmmu-vmsa: Refactor micro-TLB lookup
  iommu/ipmmu-vmsa: Add device tree bindings documentation
  iommu/ipmmu-vmsa: Add device tree support
  ARM: shmobile: r8a7791: Add IPMMU DT nodes
  ARM: shmobile: r8a7791: Enable IOMMU support for the VSP1

 .../bindings/iommu/renesas,ipmmu-vmsa.txt          |  35 ++++++
 arch/arm/boot/dts/r8a7791.dtsi                     |  54 ++++++++++
 drivers/iommu/ipmmu-vmsa.c                         | 117 +++++++++++++--------
 3 files changed, 165 insertions(+), 41 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support
  2014-04-17 11:12 ` [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
@ 2014-04-17 15:55   ` Will Deacon
  2014-04-17 22:50     ` Laurent Pinchart
  0 siblings, 1 reply; 12+ messages in thread
From: Will Deacon @ 2014-04-17 15:55 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On Thu, Apr 17, 2014 at 12:12:57PM +0100, Laurent Pinchart wrote:
> Hello,

Hi Laurent,

> This patch set adds DT support to the Renesas VMSA-compatible IPMMU driver.
> The first patch refactors the driver to remove dependencies on platform data,
> the second patch adds the DT bindings documentation and the third patch
> implement them in the driver.
> 
> The next two patches show real-life examples for IPMMU DT bindings usage.
> Patch 4/5 adds IPMMU DT nodes to the r8a7791 SoC dtsi file, and patch 5/5
> enables IOMMU support for the VSP1 on the same platform.
> 
> The patches are based on top of the IPMMU driver previously submitted to the
> iommu mailing list. The last patch additionally requires to VSP1 DT support
> patch series previously submitted to the linux-media mailing list and is thus
> a test patch only at the moment, not meant to be merged yet.
> 
> The DT bindings are pretty simple, with only three standard properties in the
> IPMMU DT node. The driver doesn't need to know the number of micro-TLBs (a
> micro-TLB being a port to which a bus master device is attached, identified by
> a number similar in purpose to a stream ID), so I've decided not to specify it
> in DT. The micro-TLBs are configured when a bus master device is attached or
> detached, and at that point the device provides its micro-TLB number.
> 
> The only reason I can foresee why the number of micro-TLBs would be useful is 
> to iterate over micro-TLBs when the driver probes the device to disable them 
> all. A mask would probably be better than a number in that case, and I think 
> we can always add that later if we find a need for it.
> 
> The device to IOMMU association is represented in the bus master device nodes
> using an iommus property, similarly to interrupts or clocks. This model departs
> from the ARM SMMU DT bindings that represent the same information inside the
> IOMMU DT node. Will, please feel free to tell me if you believe this model
> isn't good.

If this model works for you, then I'm also fine with it. The only complaint
is that we now have a needless difference between the ARM SMMU driver and
your driver in the way that the device <-> smmu topology is described. I'd
be happy to try and move my driver over to your binding, but that would
break all existing users and, whilst there aren't any in-tree .dts files
using the ARM SMMU, I doubt it would be a popular move.

> Every IPMMU instance serves multiple bus master devices and implements four
> independent page tables and TLBs. Each bus master can be freely assigned to one
> of the page tables, lowering the risk of TLB miss when multiple bus masters
> require address translation at the same time. I've decided not to express the
> bus master to page table association in DT as this seems to me to be a software
> configuration decision, not a hardware property. Feel free to disagree.

Isn't the master -> page table association a dynamic property, defined by
the (runtime) configuration of IOMMU domains? That is, you have one page
table per domain and the act of attaching a device to a domain associates
it with that page table? Or do you need an identity-mapped page table in
order to pass-through transactions when no translation is configured?

Will

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

* Re: [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support
  2014-04-17 15:55   ` Will Deacon
@ 2014-04-17 22:50     ` Laurent Pinchart
  0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-04-17 22:50 UTC (permalink / raw)
  To: Will Deacon
  Cc: Laurent Pinchart, iommu@lists.linux-foundation.org,
	linux-sh@vger.kernel.org, devicetree@vger.kernel.org

Hi Will,

On Thursday 17 April 2014 16:55:19 Will Deacon wrote:
> On Thu, Apr 17, 2014 at 12:12:57PM +0100, Laurent Pinchart wrote:
> > Hello,
> 
> Hi Laurent,
> 
> > This patch set adds DT support to the Renesas VMSA-compatible IPMMU
> > driver. The first patch refactors the driver to remove dependencies on
> > platform data, the second patch adds the DT bindings documentation and the
> > third patch implement them in the driver.
> > 
> > The next two patches show real-life examples for IPMMU DT bindings usage.
> > Patch 4/5 adds IPMMU DT nodes to the r8a7791 SoC dtsi file, and patch 5/5
> > enables IOMMU support for the VSP1 on the same platform.
> > 
> > The patches are based on top of the IPMMU driver previously submitted to
> > the iommu mailing list. The last patch additionally requires to VSP1 DT
> > support patch series previously submitted to the linux-media mailing list
> > and is thus a test patch only at the moment, not meant to be merged yet.
> > 
> > The DT bindings are pretty simple, with only three standard properties in
> > the IPMMU DT node. The driver doesn't need to know the number of
> > micro-TLBs (a micro-TLB being a port to which a bus master device is
> > attached, identified by a number similar in purpose to a stream ID), so
> > I've decided not to specify it in DT. The micro-TLBs are configured when
> > a bus master device is attached or detached, and at that point the device
> > provides its micro-TLB number.
> > 
> > The only reason I can foresee why the number of micro-TLBs would be useful
> > is to iterate over micro-TLBs when the driver probes the device to
> > disable them all. A mask would probably be better than a number in that
> > case, and I think we can always add that later if we find a need for it.
> > 
> > The device to IOMMU association is represented in the bus master device
> > nodes using an iommus property, similarly to interrupts or clocks. This
> > model departs from the ARM SMMU DT bindings that represent the same
> > information inside the IOMMU DT node. Will, please feel free to tell me
> > if you believe this model isn't good.
> 
> If this model works for you, then I'm also fine with it. The only complaint
> is that we now have a needless difference between the ARM SMMU driver and
> your driver in the way that the device <-> smmu topology is described. I'd
> be happy to try and move my driver over to your binding, but that would
> break all existing users and, whilst there aren't any in-tree .dts files
> using the ARM SMMU, I doubt it would be a popular move.

I'm also slightly unhappy with having two different models. Of course, if I 
had thought that the two models were equally good, I would have followed yours 
:-) It seems more natural to me to express the association with an IOMMU as a 
resource, similarly to clocks, GPIOs or interrupts. It would also allow easier 
support for devices that use multiple IOMMUs (which should be pretty uncommon, 
in my case devices can have several independent bus master ports, but they all 
go through the same IOMMU, with different micro-TLBs/stream IDs).

There's no other mainline IOMMU driver that model the bus masters to IOMMU 
relationship in DT, so it's probably a good time to discuss this issue as 
broadly as possible and decide on sane rules. If we have to live with 
different models, so be it, but I think we should establish a default model at 
least for new drivers. It would especially be useful if we want to handle 
device to domain association in common code, which I believe would be a good 
target.

> > Every IPMMU instance serves multiple bus master devices and implements
> > four independent page tables and TLBs. Each bus master can be freely
> > assigned to one of the page tables, lowering the risk of TLB miss when
> > multiple bus masters require address translation at the same time. I've
> > decided not to express the bus master to page table association in DT as
> > this seems to me to be a software configuration decision, not a hardware
> > property. Feel free to disagree.
>
> Isn't the master -> page table association a dynamic property, defined by
> the (runtime) configuration of IOMMU domains? That is, you have one page
> table per domain and the act of attaching a device to a domain associates
> it with that page table?

That's correct. The IPMMU has four domains and handles more than four devices. 
I thus need to decide to which domain to attach each device. Doing so in a 
round-robin fashion is an acceptable first implementation, but fine-tuning 
might be needed at some point for performance reasons.

> Or do you need an identity-mapped page table in order to pass-through
> transactions when no translation is configured?

Fortunately I don't need that.

-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2014-04-17 22:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-17 10:33 [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
2014-04-17 10:33 ` [PATCH v2 1/5] iommu/ipmmu-vmsa: Refactor micro-TLB lookup Laurent Pinchart
     [not found] ` <1397730807-5993-1-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
2014-04-17 10:33   ` [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation Laurent Pinchart
     [not found]     ` <1397730807-5993-3-git-send-email-laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
2014-04-17 11:08       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdVy6963wk_k7=BbOwBJ-LC7M8Yd7OAwVahERCMPzddN4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-17 11:11           ` Laurent Pinchart
2014-04-17 10:33 ` [PATCH v2 3/5] iommu/ipmmu-vmsa: Add device tree support Laurent Pinchart
2014-04-17 10:33 ` [PATCH v2 4/5] ARM: shmobile: r8a7791: Add IPMMU DT nodes Laurent Pinchart
2014-04-17 10:33 ` [PATCH v2 5/5] [TEST] ARM: shmobile: r8a7791: Enable IOMMU support for the VSP1 Laurent Pinchart
2014-04-17 11:12 ` [PATCH v2 2/5] iommu/ipmmu-vmsa: Add device tree bindings documentation Laurent Pinchart
2014-04-17 11:12 ` [PATCH v2 0/5] Renesas VMSA-compatible IPMMU DT support Laurent Pinchart
2014-04-17 15:55   ` Will Deacon
2014-04-17 22:50     ` Laurent Pinchart

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