Skip to contentSkip to conversation

iommu/tegra: smmu: Add device tree support for SMMU

PATCH Superseded Hiroshi DOYU 6 participants 27 messages May 10, 2012 – Jun 25, 2012 3 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover iommu/tegra: smmu: Add device tree support for SMMU

This series add device tree support for Tegra30 IOMMU(SMMU).

This requires the following patches sent earlier:

DMA window:
http://article.gmane.org/gmane.linux.ports.tegra/4603

AHB:
http://article.gmane.org/gmane.linux.ports.tegra/4657

Hiroshi DOYU (2):
iommu/tegra: smmu: Add device tree support for SMMU
ARM: dt: tegra30.dtsi: Add SMMU node

 .../bindings/iommu/nvidia,tegra30-smmu.txt         |   21 +++
 arch/arm/boot/dts/tegra30.dtsi                     |   10 ++
 drivers/iommu/Kconfig                              |    2 +-
 drivers/iommu/tegra-smmu.c                         |  150 +++++++++++++-------
 4 files changed, 128 insertions(+), 55 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iommu/nvidia,tegra30-smmu.txt
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/2 iommu/tegra: smmu: Add device tree support for SMMU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

---
This patch requires the following ones, sent earlier:

DMA window:
http://article.gmane.org/gmane.linux.ports.tegra/4603

AHB:
http://article.gmane.org/gmane.linux.ports.tegra/4657

---
 .../bindings/iommu/nvidia,tegra30-smmu.txt         |   21 +++
 drivers/iommu/Kconfig                              |    2 +-
 drivers/iommu/tegra-smmu.c                         |  150 +++++++++++++-------
 3 files changed, 118 insertions(+), 55 deletions(-)
Documentation/devicetree/bindings/iommu/nvidia,tegra30-smmu.txt new file +21 -0
new file mode 100644
index 0000000..89fb543
@@ -0,0 +1,21 @@
+NVIDIA Tegra 30 IOMMU H/W, SMMU (System Memory Management Unit)
+
+Required properties:
+- compatible : "nvidia,tegra30-smmu"
+- reg : Should contain 3 register banks(address and length) for each
+  of the SMMU register blocks.
+- interrupts : Should contain MC General interrupt.
+- nvidia,#asids : # of ASIDs
+- dma-window : IOVA start address and length.
+- nvidia,ahb : phandle to the ahb bus connected to SMMU.
+
+Example:
+	smmu {
+		compatible = "nvidia,tegra30-smmu";
+		reg = <0x7000f010 0x02c
+		       0x7000f1f0 0x010
+		       0x7000f228 0x05c>;
+		nvidia,#asids = <4>;		/* # of ASIDs */
+		dma-window = <0 0x40000000>;	/* IOVA start & length */
+		nvidia,ahb = <&ahb>;
+	};
drivers/iommu/Kconfig +1 -1
index c698437..bc711b3 100644
@@ -154,7 +154,7 @@ config TEGRA_IOMMU_GART
 
 config TEGRA_IOMMU_SMMU
 	bool "Tegra SMMU IOMMU Support"
-	depends on ARCH_TEGRA_3x_SOC
+	depends on ARCH_TEGRA_3x_SOC && TEGRA_AHB
 	select IOMMU_API
 	help
 	  Enables support for remapping discontiguous physical memory
drivers/iommu/tegra-smmu.c +96 -54

278 lines not on this page · raw message

Signature · 1 line
1.7.5.4
Acked-by on v1 1/2
#2 lore raw
Quoted 7 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

I expect patch 1 will go through the IOMMU tree, and I'll take patch 2 through the Tegra tree.

Acked-by
#3 lore raw
Quoted 10 lines · Stephen Warren
Quoted 7 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

g.

#4 lore raw
In reply to Stephen Warren
Quoted 7 lines · Stephen Warren
Quoted 6 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

Quoted 6 lines
Quoted 1 line

I expect patch 1 will go through the IOMMU tree, and I'll take patch 2 through the Tegra tree.

Any reason for splitting it up? The patches touch mostly drivers/iommu. So to avoid conflicts its probably the best to apply them together.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#5 lore raw
Quoted 10 lines · Joerg Roedel
Quoted 9 lines · Stephen Warren
Quoted 7 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

Quoted 7 lines
Quoted 4 lines

I expect patch 1 will go through the IOMMU tree, and I'll take patch 2 through the Tegra tree.

Any reason for splitting it up? The patches touch mostly drivers/iommu. So to avoid conflicts its probably the best to apply them together.

Patch 1 is the driver that touches drivers/iommu and related documentation, whereas patch 2 touches the device tree file in arch/arm/boot/dts. Either of the patches would get conflicts if they were merged into the "other" tree.

#6 lore raw
In reply to Hiroshi DOYU
Quoted 6 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

Quoted 6 lines

---
This patch requires the following ones, sent earlier:

DMA window:
http://article.gmane.org/gmane.linux.ports.tegra/4603

This patch has been merged even though the patch above isn't present in the kernel anywhere, let alone in the history of the iommu tree. This breaks compilation in linux-next.

Quoted 2 lines

AHB:
http://article.gmane.org/gmane.linux.ports.tegra/4657

This patch is in linux-next, but also is not in the history of the iommu tree, so will break bisection of the iommu tree for Tegra.

#7 lore raw
Quoted 18 lines · Stephen Warren
Quoted 6 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

Quoted 6 lines

---
This patch requires the following ones, sent earlier:

DMA window:
http://article.gmane.org/gmane.linux.ports.tegra/4603

This patch has been merged even though the patch above isn't present in the kernel anywhere, let alone in the history of the iommu tree. This breaks compilation in linux-next.

Quoted 5 lines
Quoted 2 lines

AHB:
http://article.gmane.org/gmane.linux.ports.tegra/4657

This patch is in linux-next, but also is not in the history of the iommu tree, so will break bisection of the iommu tree for Tegra.

Joerg,

Can this patch please be dropped or reverted? It's still breaking tegra_defconfig in next-20120517 since the dependencies I mentioned above aren't satisfied. At this stage, it seems unlikely that the DMA window parsing change is going to make it into 3.5, so this isn't just a temporary issue.

Thanks.

#8 lore raw

Hi Stephen and Joerg,

Quoted 25 lines · On Thu, 17 May 2012 18:48:39 +0200 Stephen Warren <[email protected]> wrote:
Quoted 18 lines · Stephen Warren
Quoted 6 lines · Hiroshi DOYU

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

Quoted 6 lines

---
This patch requires the following ones, sent earlier:

DMA window:
http://article.gmane.org/gmane.linux.ports.tegra/4603

This patch has been merged even though the patch above isn't present in the kernel anywhere, let alone in the history of the iommu tree. This breaks compilation in linux-next.

Quoted 5 lines
Quoted 2 lines

AHB:
http://article.gmane.org/gmane.linux.ports.tegra/4657

This patch is in linux-next, but also is not in the history of the iommu tree, so will break bisection of the iommu tree for Tegra.

Quoted 7 lines

Joerg,

Can this patch please be dropped or reverted? It's still breaking tegra_defconfig in next-20120517 since the dependencies I mentioned above aren't satisfied. At this stage, it seems unlikely that the DMA window parsing change is going to make it into 3.5, so this isn't just a temporary issue.

I can move of_get_dma_window() function into tegra-smmu.c as a static function. I just want SMMU available with DT for the furthuer development. Then, it's also possible to promote that function global later as is in the origianl patch.

I'm posting that patch follows this email. Please take it if this proposal is acceptable.

#9 lore raw

PATCH 1/1 iommu/tegra: smmu: Add DMA window parser

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can be promoted as a global function for general use.

---
Based on the discussion:
http://marc.info/?l=linux-tegra&m=133732046606458&w=2

---
 drivers/iommu/tegra-smmu.c |   50 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
drivers/iommu/tegra-smmu.c +50 -0
index 192fc4a..7fc444b 100644
@@ -874,6 +874,56 @@ static struct iommu_ops smmu_iommu_ops = {
 	.pgsize_bitmap	= SMMU_IOMMU_PGSIZES,
 };
 
+static int of_get_dma_window(struct device_node *dn,
+			const char *propname, int index,
+			unsigned long *busno,
+			dma_addr_t *addr, size_t *size)
+{
+	const __be32 *dma_window, *end;
+	int bytes, cur_index = 0;
+
+	if (!dn || !addr || !size)
+		return -EINVAL;
+
+	if (!propname)
+		propname = "dma-window";
+
+	dma_window = of_get_property(dn, propname, &bytes);
+	if (!dma_window)
+		return -ENODEV;
+	end = dma_window + bytes / sizeof(*dma_window);
+
+	while (dma_window < end) {
+		u32 cells;
+		const void *prop;
+
+		/* busno is always one cell */
+		if (busno)
+			*busno = be32_to_cpup(dma_window++);
+
+		prop = of_get_property(dn, "#dma-address-cells", NULL);
+		if (!prop)
+			prop = of_get_property(dn, "#address-cells", NULL);
+
+		cells = prop ? be32_to_cpup(prop) : of_n_addr_cells(dn);
+		if (!cells)
+			return -EINVAL;
+		*addr = of_read_number(dma_window, cells);
+		dma_window += cells;
+
+		prop = of_get_property(dn, "#dma-size-cells", NULL);
+		cells = prop ? be32_to_cpup(prop) : of_n_size_cells(dn);
+		if (!cells)
+			return -EINVAL;
+		*size = of_read_number(dma_window, cells);
+		dma_window += cells;
+
+		if (cur_index++ == index)
+			break;
+	}
+	return 0;
+}
+
 static int tegra_smmu_suspend(struct device *dev)
 {
 	struct smmu_device *smmu = dev_get_drvdata(dev);
Signature · 1 line
1.7.5.4
Acked-by on v1 1/1
#10 lore raw

Re: [PATCH 1/1] iommu/tegra: smmu: Add DMA window parser

Quoted 7 lines · Hiroshi DOYU

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can be promoted as a global function for general use.

Hiroshi,

Once this is accepted, it might be worth following up on the original of_get_dma_window thread and noting that once it's approved, an updated version of the patch will be needed to remove this code at the same time.

A couple comments below though:

drivers/iommu/tegra-smmu.c static struct iommu_ops smmu_iommu_ops = { · line 883

Quoted 7 lines
drivers/iommu/tegra-smmu.c +7 -0
+static int of_get_dma_window(struct device_node *dn,
+			const char *propname, int index,
+			unsigned long *busno,
+			dma_addr_t *addr, size_t *size)
+{
+	const __be32 *dma_window, *end;
+	int bytes, cur_index = 0;

Since bytes is an out parameter from of_get_property, do you need to wrap the declaration in uninitialized_var() to prevent a compile warning like the other patch you sent me downstream?

Quoted 8 lines
drivers/iommu/tegra-smmu.c +8 -0
+	if (!dn || !addr || !size)
+		return -EINVAL;
+
+	if (!propname)
+		propname = "dma-window";
+
+	dma_window = of_get_property(dn, propname, &bytes);
+	if (!dma_window)

drivers/iommu/tegra-smmu.c static struct iommu_ops smmu_iommu_ops = { · line 902

Quoted 10 lines
drivers/iommu/tegra-smmu.c +10 -0
+		return -ENODEV;
+	end = dma_window + bytes / sizeof(*dma_window);
+
+	while (dma_window < end) {
+		u32 cells;
+		const void *prop;
+
+		/* busno is always one cell */
+		if (busno)
+			*busno = be32_to_cpup(dma_window++);

Shouldn't the ++ happen even if (!busno)?

Once those are fixed, in the interests of fixing the compile error,

#11 lore raw

Re: [PATCH 1/1] iommu/tegra: smmu: Add DMA window parser

Hi Stephen, Joerg,

Stephen Warren <[email protected]> wrote @ Fri, 18 May 2012 17:15:34 +0200:

Quoted 41 lines · Hiroshi DOYU
Quoted 7 lines

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can be promoted as a global function for general use.

Hiroshi,

Once this is accepted, it might be worth following up on the original of_get_dma_window thread and noting that once it's approved, an updated version of the patch will be needed to remove this code at the same time.

A couple comments below though:

drivers/iommu/tegra-smmu.c static struct iommu_ops smmu_iommu_ops = { · line 883

Quoted 7 lines
drivers/iommu/tegra-smmu.c +7 -0
+static int of_get_dma_window(struct device_node *dn,
+			const char *propname, int index,
+			unsigned long *busno,
+			dma_addr_t *addr, size_t *size)
+{
+	const __be32 *dma_window, *end;
+	int bytes, cur_index = 0;

Since bytes is an out parameter from of_get_property, do you need to wrap the declaration in uninitialized_var() to prevent a compile warning like the other patch you sent me downstream?

Quoted 12 lines
drivers/iommu/tegra-smmu.c +12 -0
+	if (!dn || !addr || !size)
+		return -EINVAL;
+
+	if (!propname)
+		propname = "dma-window";
+
+	dma_window = of_get_property(dn, propname, &bytes);
+	if (!dma_window)
+		return -ENODEV;
+	end = dma_window + bytes / sizeof(*dma_window);
+
+	while (dma_window < end) {
Quoted 8 lines

drivers/iommu/tegra-smmu.c static struct iommu_ops smmu_iommu_ops = { · line 902

Quoted 6 lines
drivers/iommu/tegra-smmu.c +6 -0
+		u32 cells;
+		const void *prop;
+
+		/* busno is always one cell */
+		if (busno)
+			*busno = be32_to_cpup(dma_window++);

Shouldn't the ++ happen even if (!busno)?

Hm...the above code happens to work with our "dma-window" format right now, but most likely this seems incmpatible with "ibm,dma-window" format. I couldn't find the official format previously. I'm wondering that those "(ibm,)dma-window" and "(ibm,)dma-range" may be able to be generally used since those parameters are quite common to any IOMMUs. I'll hold off those patches at least this time

Joerg, as Stephen proposed originally. Could you please revert or drop the original one this time?

[PATCH 1/2] iommu/tegra: smmu: Add device tree support for SMMU

PS: I'm being off-line'd mostly next four weeks, and my response would be delayed.

#12 lore raw

Re: [PATCH 1/1] iommu/tegra: smmu: Add DMA window parser

Quoted 4 lines · Hiroshi Doyu

Joerg, as Stephen proposed originally. Could you please revert or drop the original one this time?

[PATCH 1/2] iommu/tegra: smmu: Add device tree support for SMMU

I removed the patch from my tree.

Regards,

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

PATCH 1/5 iommu/tegra: smmu: Add DMA window parser, of_get_dma_window()

From: Hiroshi Doyu <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can be promoted as a global function for general use to replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

---
Based on the discussion:
http://marc.info/?l=linux-tegra&m=133732046606458&w=2

---
 drivers/iommu/tegra-smmu.c |   70 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)
drivers/iommu/tegra-smmu.c +70 -0
index ecd6790..6f87ae4 100644
@@ -30,6 +30,7 @@
 #include <linux/sched.h>
 #include <linux/iommu.h>
 #include <linux/io.h>
+#include <linux/of.h>
 
 #include <asm/page.h>
 #include <asm/cacheflush.h>
@@ -858,6 +859,75 @@ static struct iommu_ops smmu_iommu_ops = {
 	.pgsize_bitmap	= SMMU_IOMMU_PGSIZES,
 };
 
+/**
+ * of_get_dma_window - Parse *dma-window property and returns 0 if found.
+ *
+ * @dn: device node
+ * @prefix: prefix for property name if any
+ * @index: index to start to parse
+ * @busno: Returns busno if supported. Otherwise pass NULL
+ * @addr: Returns address that DMA starts
+ * @size: Returns the range that DMA can handle
+ *
+ * This supports different formats flexibly. "prefix" can be
+ * configured if any. "busno" and "index" are optionally
+ * specified. Set 0(or NULL) if not used.
+ */
+static int of_get_dma_window(struct device_node *dn,
+			const char *prefix, int index,
+			unsigned long *busno,
+			dma_addr_t *addr, size_t *size)
+{
+	const __be32 *dma_window, *end;
+	int bytes, cur_index = 0;
+	char propname[NAME_MAX], addrname[NAME_MAX], sizename[NAME_MAX];
+	const char *s = "";
+
+	if (!dn || !addr || !size)
+		return -EINVAL;
+
+	if (prefix)
+		s = prefix;
+	snprintf(propname, sizeof(propname), "%sdma-window", s);
+	snprintf(addrname, sizeof(addrname), "%s#dma-address-cells", s);
+	snprintf(sizename, sizeof(sizename), "%s#dma-size-cells", s);
+
+	dma_window = of_get_property(dn, propname, &bytes);
+	if (!dma_window)
+		return -ENODEV;
+	end = dma_window + bytes / sizeof(*dma_window);
+
+	while (dma_window < end) {
+		u32 cells;
+		const void *prop;
+
+		/* busno is one cell if supported */
+		if (busno)
+			*busno = be32_to_cpup(dma_window++);
+
+		prop = of_get_property(dn, addrname, NULL);
+		if (!prop)
+			prop = of_get_property(dn, "#address-cells", NULL);
+
+		cells = prop ? be32_to_cpup(prop) : of_n_addr_cells(dn);
+		if (!cells)
+			return -EINVAL;
+		*addr = of_read_number(dma_window, cells);
+		dma_window += cells;
+
+		prop = of_get_property(dn, sizename, NULL);
+		cells = prop ? be32_to_cpup(prop) : of_n_size_cells(dn);
+		if (!cells)
+			return -EINVAL;
+		*size = of_read_number(dma_window, cells);
+		dma_window += cells;
+
+		if (cur_index++ == index)
+			break;
+	}
+	return 0;
+}
+
 static int tegra_smmu_suspend(struct device *dev)
 {
 	struct smmu_device *smmu = dev_get_drvdata(dev);
Signature · 1 line
1.7.5.4

A message that is not in the archive (sent off-list or not yet received): 1340176620-13012-1-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#16 lore raw

PATCH 2/5 iommu/tegra: smmu: Add device tree support for SMMU

From: Hiroshi Doyu <[email protected]>

From: Hiroshi Doyu <[email protected]>

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

---
 .../bindings/iommu/nvidia,tegra30-smmu.txt         |   21 +++
 drivers/iommu/Kconfig                              |    2 +-
 drivers/iommu/tegra-smmu.c                         |  147 ++++++++++++-------
 3 files changed, 115 insertions(+), 55 deletions(-)
Documentation/devicetree/bindings/iommu/nvidia,tegra30-smmu.txt new file +21 -0
new file mode 100644
index 0000000..89fb543
@@ -0,0 +1,21 @@
+NVIDIA Tegra 30 IOMMU H/W, SMMU (System Memory Management Unit)
+
+Required properties:
+- compatible : "nvidia,tegra30-smmu"
+- reg : Should contain 3 register banks(address and length) for each
+  of the SMMU register blocks.
+- interrupts : Should contain MC General interrupt.
+- nvidia,#asids : # of ASIDs
+- dma-window : IOVA start address and length.
+- nvidia,ahb : phandle to the ahb bus connected to SMMU.
+
+Example:
+	smmu {
+		compatible = "nvidia,tegra30-smmu";
+		reg = <0x7000f010 0x02c
+		       0x7000f1f0 0x010
+		       0x7000f228 0x05c>;
+		nvidia,#asids = <4>;		/* # of ASIDs */
+		dma-window = <0 0x40000000>;	/* IOVA start & length */
+		nvidia,ahb = <&ahb>;
+	};
drivers/iommu/Kconfig +1 -1
index 3408937..969fc4b 100644
@@ -154,7 +154,7 @@ config TEGRA_IOMMU_GART
 
 config TEGRA_IOMMU_SMMU
 	bool "Tegra SMMU IOMMU Support"
-	depends on ARCH_TEGRA_3x_SOC
+	depends on ARCH_TEGRA_3x_SOC && TEGRA_AHB
 	select IOMMU_API
 	help
 	  Enables support for remapping discontiguous physical memory
drivers/iommu/tegra-smmu.c +93 -54

269 lines not on this page · raw message

Signature · 1 line
1.7.5.4

A message that is not in the archive (sent off-list or not yet received): 1340176620-13012-2-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#18 lore raw

PATCH v2 2/5 iommu/tegra: smmu: Add device tree support for SMMU

From: Hiroshi Doyu <[email protected]>

The necessary info is expected to pass from DT.

For more precise resource reservation, there shouldn't be any overlapping of register range between SMMU and MC. SMMU register offset needs to be calculated correctly, based on its register bank.

---
Update:
Header files are added because of the removal of of_get_dma_window().

---
 .../bindings/iommu/nvidia,tegra30-smmu.txt         |   21 +++
 drivers/iommu/Kconfig                              |    2 +-
 drivers/iommu/tegra-smmu.c                         |  149 +++++++++++++-------
 3 files changed, 117 insertions(+), 55 deletions(-)
Documentation/devicetree/bindings/iommu/nvidia,tegra30-smmu.txt new file +21 -0
new file mode 100644
index 0000000..89fb543
@@ -0,0 +1,21 @@
+NVIDIA Tegra 30 IOMMU H/W, SMMU (System Memory Management Unit)
+
+Required properties:
+- compatible : "nvidia,tegra30-smmu"
+- reg : Should contain 3 register banks(address and length) for each
+  of the SMMU register blocks.
+- interrupts : Should contain MC General interrupt.
+- nvidia,#asids : # of ASIDs
+- dma-window : IOVA start address and length.
+- nvidia,ahb : phandle to the ahb bus connected to SMMU.
+
+Example:
+	smmu {
+		compatible = "nvidia,tegra30-smmu";
+		reg = <0x7000f010 0x02c
+		       0x7000f1f0 0x010
+		       0x7000f228 0x05c>;
+		nvidia,#asids = <4>;		/* # of ASIDs */
+		dma-window = <0 0x40000000>;	/* IOVA start & length */
+		nvidia,ahb = <&ahb>;
+	};
drivers/iommu/Kconfig +1 -1
index 4826af6..9f69b56 100644
@@ -158,7 +158,7 @@ config TEGRA_IOMMU_GART
 
 config TEGRA_IOMMU_SMMU
 	bool "Tegra SMMU IOMMU Support"
-	depends on ARCH_TEGRA_3x_SOC
+	depends on ARCH_TEGRA_3x_SOC && TEGRA_AHB
 	select IOMMU_API
 	help
 	  Enables support for remapping discontiguous physical memory
drivers/iommu/tegra-smmu.c +95 -54

277 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#19 lore raw

PATCH 3/5 iommu/tegra: smmu: Simplify allocation at once

In reply to a message not in the archive

From: Hiroshi Doyu <[email protected]>

From: Hiroshi Doyu <[email protected]>

To simplify the code, alloc necessary data at once.

---
 drivers/iommu/tegra-smmu.c |   29 +++++++++--------------------
 1 files changed, 9 insertions(+), 20 deletions(-)
drivers/iommu/tegra-smmu.c +9 -20
index 9ebb887..5447f05 100644
@@ -240,8 +240,6 @@ struct smmu_device {
 	spinlock_t	lock;
 	char		*name;
 	struct device	*dev;
-	int		num_as;
-	struct smmu_as	*as;		/* Run-time allocated array */
 	struct page *avp_vector_page;	/* dummy page shared by all AS's */
 
 	/*
@@ -253,6 +251,9 @@ struct smmu_device {
 	unsigned long asid_security;
 
 	struct device_node *ahb;
+
+	int		num_as;
+	struct smmu_as	as[0];		/* Run-time allocated array */
 };
 
 static struct smmu_device *smmu_handle; /* unique for a system */
@@ -970,15 +971,18 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int i, asids, err = 0;
 	dma_addr_t base;
-	size_t size;
-	const void *prop;
+	size_t bytes, size;
 
 	if (smmu_handle)
 		return -EIO;
 
 	BUILD_BUG_ON(PAGE_SHIFT != SMMU_PAGE_SHIFT);
 
-	smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL);
+	if (of_property_read_u32(dev->of_node, "nvidia,#asids", &asids))
+		return -ENODEV;
+
+	bytes = sizeof(*smmu) + asids * sizeof(*smmu->as);
+	smmu = devm_kzalloc(dev, bytes, GFP_KERNEL);
 	if (!smmu) {
 		dev_err(dev, "failed to allocate smmu_device\n");
 		return -ENOMEM;
@@ -1006,13 +1010,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	if (!size)
 		return -EINVAL;
 
-	prop = of_get_property(dev->of_node, "nvidia,#asids", NULL);
-	if (!prop)
-		return -ENODEV;
-	asids = be32_to_cpup(prop);
-	if (!asids)
-		return -ENODEV;
-
 	smmu->ahb = of_parse_phandle(dev->of_node, "nvidia,ahb", 0);
 	if (!smmu->ahb)
 		return -ENODEV;
@@ -1027,14 +1024,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	smmu->translation_enable_2 = ~0;
 	smmu->asid_security = 0;
 
-	smmu->as = devm_kzalloc(dev,
-			sizeof(smmu->as[0]) * smmu->num_as, GFP_KERNEL);
-	if (!smmu->as) {
-		dev_err(dev, "failed to allocate smmu_as\n");
-		err = -ENOMEM;
-		goto fail;
-	}
-
 	for (i = 0; i < smmu->num_as; i++) {
 		struct smmu_as *as = &smmu->as[i];
 
Signature · 1 line
1.7.5.4
#20 lore raw

PATCH 4/5 iommu/tegra: smmu: Remove unnecessary cleanups with devm_*()

In reply to a message not in the archive

From: Hiroshi Doyu <[email protected]>

From: Hiroshi Doyu <[email protected]>

Remove unnecessary cleanup procedures with devm_*() functions.

---
 drivers/iommu/tegra-smmu.c |   37 ++++++-------------------------------
 1 files changed, 6 insertions(+), 31 deletions(-)
drivers/iommu/tegra-smmu.c +6 -31
index 5447f05..3ef7dea 100644
@@ -1039,51 +1039,26 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	spin_lock_init(&smmu->lock);
 	err = smmu_setup_regs(smmu);
 	if (err)
-		goto fail;
+		return err;
 	platform_set_drvdata(pdev, smmu);
 
 	smmu->avp_vector_page = alloc_page(GFP_KERNEL);
 	if (!smmu->avp_vector_page)
-		goto fail;
+		return -ENOMEM;
 
 	smmu_handle = smmu;
 	return 0;
-
-fail:
-	if (smmu->avp_vector_page)
-		__free_page(smmu->avp_vector_page);
-	if (smmu && smmu->as) {
-		for (i = 0; i < smmu->num_as; i++) {
-			if (smmu->as[i].pdir_page) {
-				ClearPageReserved(smmu->as[i].pdir_page);
-				__free_page(smmu->as[i].pdir_page);
-			}
-		}
-		devm_kfree(dev, smmu->as);
-	}
-	devm_kfree(dev, smmu);
-	return err;
 }
 
 static int tegra_smmu_remove(struct platform_device *pdev)
 {
 	struct smmu_device *smmu = platform_get_drvdata(pdev);
-	struct device *dev = smmu->dev;
+	int i;
 
 	smmu_write(smmu, SMMU_CONFIG_DISABLE, SMMU_CONFIG);
-	platform_set_drvdata(pdev, NULL);
-	if (smmu->as) {
-		int i;
-
-		for (i = 0; i < smmu->num_as; i++)
-			free_pdir(&smmu->as[i]);
-		devm_kfree(dev, smmu->as);
-	}
-	if (smmu->avp_vector_page)
-		__free_page(smmu->avp_vector_page);
-	if (smmu->regs)
-		devm_iounmap(dev, smmu->regs);
-	devm_kfree(dev, smmu);
+	for (i = 0; i < smmu->num_as; i++)
+		free_pdir(&smmu->as[i]);
+	__free_page(smmu->avp_vector_page);
 	smmu_handle = NULL;
 	return 0;
 }
Signature · 1 line
1.7.5.4
#21 lore raw

PATCH 5/5 iommu/tegra: smmu: Fix uninitialized var warning

In reply to a message not in the archive

From: Hiroshi Doyu <[email protected]>

From: Hiroshi Doyu <[email protected]>

For the compiler warning, uninitizlized var when getting value by a pointer.

---
 drivers/iommu/tegra-smmu.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/tegra-smmu.c +2 -2
index 3ef7dea..536e24c 100644
@@ -970,8 +970,8 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	struct smmu_device *smmu;
 	struct device *dev = &pdev->dev;
 	int i, asids, err = 0;
-	dma_addr_t base;
-	size_t bytes, size;
+	dma_addr_t uninitialized_var(base);
+	size_t bytes, uninitialized_var(size);
 
 	if (smmu_handle)
 		return -EIO;
Signature · 1 line
1.7.5.4
#22 lore raw

Re: [PATCH 1/5] iommu/tegra: smmu: Add DMA window parser, of_get_dma_window()

In reply to a message not in the archive
Quoted 11 lines · Hiroshi DOYU

From: Hiroshi Doyu <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can be promoted as a global function for general use to replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

Quoted 4 lines

---
Based on the discussion:
http://marc.info/?l=linux-tegra&m=133732046606458&w=2

Hmmm. This function really should be in some common location and available for all drivers to use. Can't we add it to that common location from the start? What prevented the earlier patch that did this from getting merged into 3.5?

One thing that might help here would be /not/ to add the common code to drivers/of/of_dma.c as was done in the earlier revisions of this patch - I believe that Grant has been trying to push subsystem-specific OF functionality into files in those individual subsystems, so that drivers/of can be kept for core support. Perhaps this patch should create drivers/iommu/of_iommu.c or similar?

But I wonder: Is this function likely to be useful outside of drivers/iommu/ - you mentioned that similar code already exists in the two arch-specific prom_parse.c files; where are the existing users of those functions. If not in drivers/iommu/, then probably drivers/iommu/ isn't a good place to put the new common function...

drivers/iommu/tegra-smmu.c static struct iommu_ops smmu_iommu_ops = { · line 890

Quoted 11 lines
drivers/iommu/tegra-smmu.c +7 -0
 
+static int of_get_dma_window(struct device_node *dn,
+			const char *prefix, int index,
+			unsigned long *busno,
+			dma_addr_t *addr, size_t *size)
 
+	const char *s = "";
 
+	if (prefix)
+		s = prefix;

One minor nit, you could just do this and remove variable s:

if (!prefix)

    prefix = "";
#23 lore raw

Re: [PATCH 1/5] iommu/tegra: smmu: Add DMA window parser, of_get_dma_window()

Stephen Warren <[email protected]> wrote @ Wed, 20 Jun 2012 19:11:51 +0200:

Quoted 17 lines · Hiroshi DOYU
Quoted 11 lines

From: Hiroshi Doyu <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can be promoted as a global function for general use to replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

Quoted 4 lines

---
Based on the discussion:
http://marc.info/?l=linux-tegra&m=133732046606458&w=2

Quoted 4 lines

Hmmm. This function really should be in some common location and available for all drivers to use. Can't we add it to that common location from the start? What prevented the earlier patch that did this from getting merged into 3.5?

It's because there was no feedback against the original patches(the common location ones, *1,*2) from DT side.

*1: http://article.gmane.org/gmane.linux.ports.tegra/4468
*2: https://lkml.org/lkml/2012/4/30/153

Quoted 6 lines

One thing that might help here would be /not/ to add the common code to drivers/of/of_dma.c as was done in the earlier revisions of this patch - I believe that Grant has been trying to push subsystem-specific OF functionality into files in those individual subsystems, so that drivers/of can be kept for core support. Perhaps this patch should create drivers/iommu/of_iommu.c or similar?

"drivers/iommu/of_iommu.c" seems quite reasonable for this function.

Quoted 5 lines

But I wonder: Is this function likely to be useful outside of drivers/iommu/ - you mentioned that similar code already exists in the two arch-specific prom_parse.c files; where are the existing users of those functions. If not in drivers/iommu/, then probably drivers/iommu/ isn't a good place to put the new common function...

There are the following 3 users of of_parse_dma_window() as below. All of them are IOMMU related, but they are architecture specific ones, not for the standard IOMMU API. I guess that the current trend is to convert Arch specific IOMMU API to the standard one basically.

  arch/powerpc/kernel/vio.c 	of_parse_dma_window(dev->dev.of_node, dma_window,
  arch/powerpc/platforms/cell/iommu.c 	of_parse_dma_window(np, dma_window, &index, base, size);
  arch/powerpc/platforms/pseries/iommu.c 	of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);

I think that the common "dma-window" DT parser is necessary for the standard IOMMU because "dma-window" info is dealt as DOMAIN_ATTR_GEOMETRY in the following Joerg's patch too.

[PATCH 0/5] IOMMU: Make IOMMU-API ready for GART-like hardware

    https://lkml.org/lkml/2012/1/19/170

If it's ok to have of_get_dma_window() in "drivers/iommu/of_iommu.c", I'll post that version.

Any comment?

#24 lore raw

Re: [PATCH 1/5] iommu/tegra: smmu: Add DMA window parser, of_get_dma_window()

On 06/21/2012 12:46 AM, Hiroshi Doyu wrote:
...

Quoted 13 lines

There are the following 3 users of of_parse_dma_window() as below. All of them are IOMMU related, but they are architecture specific ones, not for the standard IOMMU API. I guess that the current trend is to convert Arch specific IOMMU API to the standard one basically.

  arch/powerpc/kernel/vio.c 	of_parse_dma_window(dev->dev.of_node, dma_window,
  arch/powerpc/platforms/cell/iommu.c 	of_parse_dma_window(np, dma_window, &index, base, size);
  arch/powerpc/platforms/pseries/iommu.c 	of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);

I think that the common "dma-window" DT parser is necessary for the standard IOMMU because "dma-window" info is dealt as DOMAIN_ATTR_GEOMETRY in the following Joerg's patch too.

Quoted 5 lines

[PATCH 0/5] IOMMU: Make IOMMU-API ready for GART-like hardware

    https://lkml.org/lkml/2012/1/19/170

If it's ok to have of_get_dma_window() in "drivers/iommu/of_iommu.c", I'll post that version.

Sounds sane to me.

#25 lore raw

PATCH v2 1/5 iommu: Add DMA window parser, of_get_dma_window()

From: Hiroshi DOYU <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

---
Update:
Move of_get_dma_window() in drivers/iommu/of_iommu.c

Based on the discussion:
http://marc.info/?l=linux-tegra&m=133732046606458&w=2

---
 drivers/iommu/Kconfig    |    4 ++
 drivers/iommu/Makefile   |    1 +
 drivers/iommu/of_iommu.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_iommu.h |   21 +++++++++++
 4 files changed, 116 insertions(+), 0 deletions(-)
drivers/iommu/Kconfig +4 -0
index 3408937..4826af6 100644
@@ -13,6 +13,10 @@ menuconfig IOMMU_SUPPORT
 
 if IOMMU_SUPPORT
 
+config OF_IOMMU
+       def_bool y
+       depends on OF
+
 # MSM IOMMU support
 config MSM_IOMMU
 	bool "MSM IOMMU Support"
drivers/iommu/Makefile +1 -0
index 76e54ef..14a4d5f 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_IOMMU_API) += iommu.o
+obj-$(CONFIG_OF_IOMMU)	+= of_iommu.o
 obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o msm_iommu_dev.o
 obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
 obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o
drivers/iommu/of_iommu.c new file +90 -0

90 lines not on this page · raw message

include/linux/of_iommu.h new file +21 -0
new file mode 100644
index 0000000..51a560f
@@ -0,0 +1,21 @@
+#ifndef __OF_IOMMU_H
+#define __OF_IOMMU_H
+
+#ifdef CONFIG_OF_IOMMU
+
+extern int of_get_dma_window(struct device_node *dn, const char *prefix,
+			     int index, unsigned long *busno, dma_addr_t *addr,
+			     size_t *size);
+
+#else
+
+static inline int of_get_dma_window(struct device_node *dn, const char *prefix,
+			    int index, unsigned long *busno, dma_addr_t *addr,
+			    size_t *size)
+{
+	return -EINVAL;
+}
+
+#endif	/* CONFIG_OF_IOMMU */
+
+#endif /* __OF_IOMMU_H */
Signature · 1 line
1.7.5.4
Acked-by on v2 1/5
#26 lore raw

Re: [v2 1/5] iommu: Add DMA window parser, of_get_dma_window()

Quoted 11 lines · Hiroshi Doyu

From: Hiroshi DOYU <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Can replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

BTW, I only see patches 1 & 2 of 5 in this series; did you only mean to post just 2 patches or did the others get lost on the way to my system somehow?

#27 lore raw

Re: [v2 1/5] iommu: Add DMA window parser, of_get_dma_window()

Quoted 7 lines · On Thu, 21 Jun 2012 18:18:59 +0200 Stephen Warren…
Quoted 6 lines · Hiroshi Doyu

From: Hiroshi DOYU <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Quoted 7 lines
Quoted 5 lines

Can replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

Thanks.

Quoted 3 lines

BTW, I only see patches 1 & 2 of 5 in this series; did you only mean to post just 2 patches or did the others get lost on the way to my system somehow?

I reposted only [1/5] and [2/5] as "v2" because the rests are same. Probably it was better to send a whole series again. Sorry for confusion.

#28 lore raw

Re: [v2 1/5] iommu: Add DMA window parser, of_get_dma_window()

Quoted 20 lines · Hiroshi Doyu
Quoted 7 lines · On Thu, 21 Jun 2012 18:18:59 +0200 Stephen Warren…
Quoted 6 lines · Hiroshi Doyu

From: Hiroshi DOYU <[email protected]>

This code was based on:
"arch/microblaze/kernel/prom_parse.c"
"arch/powerpc/kernel/prom_parse.c"

Quoted 7 lines
Quoted 5 lines

Can replace "of_parse_dma_window()" in the above. This supports different formats flexibly. "prefix" can be configured if any. "busno" and "index" are optionally specified. Set NULL and 0 if not used.

Thanks.

Quoted 7 lines
Quoted 3 lines

BTW, I only see patches 1 & 2 of 5 in this series; did you only mean to post just 2 patches or did the others get lost on the way to my system somehow?

I reposted only [1/5] and [2/5] as "v2" because the rests are same. Probably it was better to send a whole series again. Sorry for confusion.

Please repost the whole series with the Acks included as a new thread so that I can easily apply them.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#29 lore raw

PATCH 2/2 ARM: dt: tegra30.dtsi: Add SMMU node

In reply to Hiroshi DOYU

Add a node for the Tegra30 SMMU

---
 arch/arm/boot/dts/tegra30.dtsi |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
arch/arm/boot/dts/tegra30.dtsi +10 -0
index 167ccbc..e9792ac 100644
@@ -238,4 +238,14 @@
 		       0x7000f284 0x17c>;
 		interrupts = <0 77 0x04>;
 	};
+
+	smmu {
+		compatible = "nvidia,tegra30-smmu";
+		reg = <0x7000f010 0x02c
+		       0x7000f1f0 0x010
+		       0x7000f228 0x05c>;
+		nvidia,#asids = <4>;		/* # of ASIDs */
+		dma-window = <0 0x40000000>;	/* IOVA start & length */
+		nvidia,ahb = <&ahb>;
+	};
 };
Signature · 1 line
1.7.5.4