iommu/tegra: smmu: Reserve SMMU reg regions precisely
PATCH 1/3 iommu/tegra: smmu: Reserve SMMU reg regions precisely
SMMU register regions are located into 3 blocks discontiguously.
Get them and reserve each region respectively. This allows other module to use/reserve other register regions between SMMU register blocks.
--- drivers/iommu/tegra-smmu.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 36 insertions(+), 8 deletions(-)
drivers/iommu/tegra-smmu.c +36 -8
@@ -173,6 +173,8 @@#define SMMU_ASID_DISABLE 0#define SMMU_ASID_ASID (n) ((n) & ~SMMU_ASID_ENABLE(0)) +#define NUM_SMMU_REG_BLOCKS 3 +#define smmu_client_enable_hwgrp (c, m) smmu_client_set_hwgrp(c, m, 1)#define smmu_client_disable_hwgrp (c) smmu_client_set_hwgrp(c, 0, 0)#define __smmu_client_enable_hwgrp (c, m) __smmu_client_set_hwgrp(c, m, 1)
@@ -866,7 +868,7 @@ static int tegra_smmu_resume(struct device *dev)static int tegra_smmu_probe (struct platform_device *pdev) {struct smmu_device *smmu; -struct resource *regs, *window; +struct resource *res[NUM_SMMU_REG_BLOCKS ], *window;struct device *dev = &pdev->dev;int i, err =0 ;
@@ -875,9 +877,25 @@ static int tegra_smmu_probe(struct platform_device *pdev)BUILD_BUG_ON (PAGE_SHIFT !=SMMU_PAGE_SHIFT ); - regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - window =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); -if (!regs || !window) { +for (i =0 ; i <ARRAY_SIZE (res); i++) { + res[i] =platform_get_resource (pdev,IORESOURCE_MEM , i); +if (!res[i]) +return -ENODEV ; + + res[i] =devm_request_mem_region (&pdev->dev, res[i]->start, +resource_size (res[i]), +dev_name (&pdev->dev)); +if (res[i]) +continue ; + +while (--i >=0 ) +devm_release_mem_region (&pdev->dev, res[i]->start, +resource_size (res[i])); +return -EIO ; + } + + window =platform_get_resource (pdev,IORESOURCE_MEM ,3 ); +if (!window) {dev_err (dev,"No SMMU resources\n" );return -ENODEV ; }
@@ -892,7 +910,8 @@ static int tegra_smmu_probe(struct platform_device *pdev) smmu->num_as =SMMU_NUM_ASIDS ; smmu->iovmm_base = (unsigned long )window->start; smmu->page_count =resource_size (window) >>SMMU_PAGE_SHIFT ; - smmu->regs =devm_ioremap (dev, regs->start,resource_size (regs)); + smmu->regs =devm_ioremap (dev, res[0 ]->start, + res[2 ]->end - res[0 ]->start +1 );if (!smmu->regs) {dev_err (dev,"failed to remap SMMU registers\n" ); err = -ENXIO ;
@@ -905,7 +924,7 @@ static int tegra_smmu_probe(struct platform_device *pdev) smmu->asid_security =0 ; smmu->as =devm_kzalloc (dev, -sizeof (smmu->as[0 ]) * smmu->num_as,GFP_KERNEL ); +sizeof (smmu->as[0 ]) * smmu->num_as,GFP_KERNEL );if (!smmu->as) {dev_err (dev,"failed to allocate smmu_as\n" ); err = -ENOMEM ;
@@ -950,6 +969,9 @@ fail:devm_kfree (dev, smmu->as); }devm_kfree (dev, smmu); +for (i =0 ; i <ARRAY_SIZE (res); i++) +devm_release_mem_region (&pdev->dev, res[i]->start, +resource_size (res[i]));return err; }
@@ -957,12 +979,11 @@ 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);
@@ -973,6 +994,13 @@ static int tegra_smmu_remove(struct platform_device *pdev)devm_iounmap (dev, smmu->regs);devm_kfree (dev, smmu); smmu_handle =NULL ; +for (i =0 ; i <NUM_SMMU_REG_BLOCKS ; i++) { +struct resource *res; + + res =platform_get_resource (pdev,IORESOURCE_MEM , i); +devm_release_mem_region (&pdev->dev, res->start, +resource_size (res)); + }return 0 ; }
Signature · 1 line
1.7.5.4
PATCH 2/3 iommu/tegra: smmu: Add device tree support for SMMU
Add device tree support for Tegra30 IOMMU(SMMU).
--- .../bindings/iommu/nvidia,tegra30-smmu.txt | 20 ++++++++ drivers/iommu/tegra-smmu.c | 47 +++++++++++++++----- 2 files changed, 55 insertions(+), 12 deletions(-)
Documentation/devicetree/bindings/iommu/nvidia,tegra30-smmu.txt new file +20 -0
@@ -0,0 +1,20 @@ +NVIDIA Tegra 30 IOMMU H/W, SMMU (System Memory Management Unit) + +Required properties: +- compatible : "nvidia,tegra30-smmu" +- reg : Should contain 3 register ranges(address and length) for each + of the SMMU register blocks. +- interrupts : Should contain MC General interrupt. +- asids : # of ASIDs +- dma-window: IOVA start address and length. + +Example: + smmu: smmu@7000f000 { + compatible = "nvidia,tegra30-smmu"; + reg = <0x7000f010 0x2c /* controller registers */ + 0x7000f1f0 0x10 /* statics */ + 0x7000f228 0x5c>; /* module configuration */ + interrupts = <0 13 0x40>; + asids = <4>; /* # of ASIDs */ + dma-window = <0 0x40000000>; /* IOVA start & length */ + };
drivers/iommu/tegra-smmu.c +35 -12
100 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 3/3 arm/dts: Tegra30: Add device tree support for SMMU
In reply to Hiroshi DOYUAdd device tree support for Tegra30 IOMMU(SMMU).
--- arch/arm/boot/dts/tegra30.dtsi | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
arch/arm/boot/dts/tegra30.dtsi +10 -0
@@ -224,4 +224,14 @@ nvidia,ahub-cif-ids = <8 8>; }; }; + + smmu: smmu at 7000f000 { + compatible = "nvidia,tegra30-smmu"; + reg = <0x7000f010 0x2c /* controller registers */ + 0x7000f1f0 0x10 /* statics */ + 0x7000f228 0x5c>; /* module configuration */ + interrupts = <0 13 0x40>; + asids = <4>; /* # of ASIDs */ + dma-window = <0 0x40000000>; /* IOVA start & length */ + }; };
Signature · 1 line
1.7.5.4
Quoted 7 lines · Hiroshi DOYU
SMMU register regions are located into 3 blocks discontiguously.
Get them and reserve each region respectively. This allows other module to use/reserve other register regions between SMMU register blocks.
Signed-off-by Hiroshi DOYU <[email protected]>
This patch depends on the other series you sent which adds the Tegra AHB driver, and modifies the SMMU driver to use it. At least you need to mention the dependencies so e.g. these patches don't get applied without the other series.
Quoted 11 lines
drivers/iommu/tegra-smmu.c +4
-3@@ -875,9 +877,25 @@ static int tegra_smmu_probe(struct platform_device *pdev)BUILD_BUG_ON (PAGE_SHIFT !=SMMU_PAGE_SHIFT ); - regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - window =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); -if (!regs || !window) { +for (i =0 ; i <ARRAY_SIZE (res); i++) { + res[i] =platform_get_resource (pdev,IORESOURCE_MEM , i); +if (!res[i]) +return -ENODEV ;
drivers/iommu/tegra-smmu.c static int tegra_smmu_probe(struct platform_device *pdev) · line 893
Quoted 10 lines
drivers/iommu/tegra-smmu.c +10
-0+ + res[i] =devm_request_mem_region (&pdev->dev, res[i]->start, +resource_size (res[i]), +dev_name (&pdev->dev)); +if (res[i]) +continue ; + +while (--i >=0 ) +devm_release_mem_region (&pdev->dev, res[i]->start, +resource_size (res[i]));
The whole point of using the devm_* functions is that you no longer need to write out all the error-handling and freeing code related to those allocations. A similar comment applies to many other parts of this patch.
Quoted 9 lines
drivers/iommu/tegra-smmu.c +5
-0+return -EIO ; + } + + window =platform_get_resource (pdev,IORESOURCE_MEM ,3 ); +if (!window) {dev_err (dev,"No SMMU resources\n" );return -ENODEV ; }
drivers/iommu/tegra-smmu.c static int tegra_smmu_probe(struct platform_device *pdev) · line 914
Quoted 6 lines
drivers/iommu/tegra-smmu.c +2
-1@@ -892,7 +910,8 @@ static int tegra_smmu_probe(struct platform_device *pdev) smmu->num_as =SMMU_NUM_ASIDS ; smmu->iovmm_base = (unsigned long )window->start; smmu->page_count =resource_size (window) >>SMMU_PAGE_SHIFT ; - smmu->regs =devm_ioremap (dev, regs->start,resource_size (regs)); + smmu->regs =devm_ioremap (dev, res[0 ]->start, + res[2 ]->end - res[0 ]->start +1 );
So, you've retrieved 3 separate resources for the address space, but only call ioremap once. That doesn't seem right; there should be a 1:1 relationship between the number of resources and ioremap calls. This is only working because the SMMU driver isn't calling request_mem_region for this whole range, and hence isn't conflicting with the request_mem_region and ioremap callss that the AHB driver is (or rather, should be) performing...
drivers/iommu/tegra-smmu.c static int tegra_smmu_probe(struct platform_device *pdev) · line 927
Quoted 3 lines
drivers/iommu/tegra-smmu.c +1
-1smmu->as =devm_kzalloc (dev, -sizeof (smmu->as[0 ]) * smmu->num_as,GFP_KERNEL ); +sizeof (smmu->as[0 ]) * smmu->num_as,GFP_KERNEL );
That looks unrelated.
Re: [PATCH 2/3] iommu/tegra: smmu: Add device tree support for SMMU
In reply to Hiroshi DOYUdrivers/iommu/tegra-smmu.c static int tegra_smmu_resume(struct device *dev) · line 887
Quoted 6 lines · Hiroshi DOYU
Add device tree support for Tegra30 IOMMU(SMMU).
drivers/iommu/tegra-smmu.c +2
-0+ err =of_parse_dma_window (dev->of_node,"dma-window" ,0 ,NULL , + &base, &size);
This patch also depends on "dt: Add general DMA window parser" that you sent earlier.
drivers/iommu/tegra-smmu.c static int tegra_smmu_resume(struct device *dev) · line 897
Quoted 3 lines
drivers/iommu/tegra-smmu.c +3
-0+ asids =be32_to_cpup (of_get_property (dev->of_node,"asids" ,NULL )); +if (!asids) +return -ENODEV ;
What if of_get_property() fails?
BTW, does the # ASIDs vary? I wonder if it's worth representing it in the device tree or not. If this driver has a chance of working unmodified on some future chip just by updating this DT property without any code changes, then it seems reasonable to have it in DT.
Re: [PATCH 2/3] iommu/tegra: smmu: Add device tree support for SMMU
From: Stephen Warren <[email protected]>
Subject: Re: [PATCH 2/3] iommu/tegra: smmu: Add device tree support for SMMU
Date: Mon, 23 Apr 2012 20:27:28 +0200
Message-ID: <[email protected]>
Quoted 11 lines · Hiroshi DOYU
drivers/iommu/tegra-smmu.c static int tegra_smmu_resume(struct device *dev) · line 887
Quoted 6 lines
Add device tree support for Tegra30 IOMMU(SMMU).
drivers/iommu/tegra-smmu.c +2
-0+ err =of_parse_dma_window (dev->of_node,"dma-window" ,0 ,NULL , + &base, &size);This patch also depends on "dt: Add general DMA window parser" that you sent earlier.
Quoted 5 lines
drivers/iommu/tegra-smmu.c static int tegra_smmu_resume(struct device *dev) · line 897
Quoted 3 lines
drivers/iommu/tegra-smmu.c +3
-0+ asids =be32_to_cpup (of_get_property (dev->of_node,"asids" ,NULL )); +if (!asids) +return -ENODEV ;What if
of_get_property()fails?
Ok, need to be checked. I'll fix.
Quoted 4 lines
BTW, does the # ASIDs vary? I wonder if it's worth representing it in the device tree or not. If this driver has a chance of working unmodified on some future chip just by updating this DT property without any code changes, then it seems reasonable to have it in DT.
Yes, ASID should be passed from DT.
Re: [PATCH 3/3] arm/dts: Tegra30: Add device tree support for SMMU
In reply to Hiroshi DOYUQuoted 5 lines · Hiroshi DOYU
Add device tree support for Tegra30 IOMMU(SMMU).
arch/arm/boot/dts/tegra30.dtsi +1
-0+ smmu: smmu at 7000f000 {
...
arch/arm/boot/dts/tegra30.dtsi line 233
Quoted 1 line
arch/arm/boot/dts/tegra30.dtsi +1
-0+ interrupts = <0 13 0x40>;
This interrupt is on the 3rd IRQ controller (or GIC bank) so should be (2*32)+13, i.e. 75 not 13.