All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/5] drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping
@ 2018-04-25 10:10 ` Thierry Reding
  0 siblings, 0 replies; 42+ messages in thread
From: Thierry Reding @ 2018-04-25 10:10 UTC (permalink / raw)
  To: Christoph Hellwig, Joerg Roedel
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Russell King,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Daniel Vetter,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

From: Thierry Reding <treding@nvidia.com>

Depending on the kernel configuration, early ARM architecture setup code
may have attached the GPU to a DMA/IOMMU mapping that transparently uses
the IOMMU to back the DMA API. Tegra requires special handling for IOMMU
backed buffers (a special bit in the GPU's MMU page tables indicates the
memory path to take: via the SMMU or directly to the memory controller).
Transparently backing DMA memory with an IOMMU prevents Nouveau from
properly handling such memory accesses and causes memory access faults.

As a side-note: buffers other than those allocated in instance memory
don't need to be physically contiguous from the GPU's perspective since
the GPU can map them into contiguous buffers using its own MMU. Mapping
these buffers through the IOMMU is unnecessary and will even lead to
performance degradation because of the additional translation.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
I had already sent this out independently to fix a regression that was
introduced in v4.16, but then Christoph pointed out that it should've
been sent to a wider audience and should use a core API rather than
calling into architecture code directly.

I've added it to this series for easier reference and to show the need
for the new API.

 .../drm/nouveau/nvkm/engine/device/tegra.c    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
index 78597da6313a..23428a7056e9 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
@@ -19,6 +19,11 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
+
+#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)
+#include <asm/dma-iommu.h>
+#endif
+
 #include <core/tegra.h>
 #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
 #include "priv.h"
@@ -105,6 +110,20 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev)
 	unsigned long pgsize_bitmap;
 	int ret;
 
+#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)
+	if (dev->archdata.mapping) {
+		struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
+
+		arm_iommu_release_mapping(mapping);
+		arm_iommu_detach_device(dev);
+
+		if (dev->archdata.dma_coherent)
+			set_dma_ops(dev, &arm_coherent_dma_ops);
+		else
+			set_dma_ops(dev, &arm_dma_ops);
+	}
+#endif
+
 	if (!tdev->func->iommu_bit)
 		return;
 
-- 
2.17.0

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

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

end of thread, other threads:[~2018-04-30 12:49 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-25 10:10 [PATCH v2 1/5] drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping Thierry Reding
2018-04-25 10:10 ` Thierry Reding
     [not found] ` <20180425101051.15349-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-25 10:10   ` [PATCH v2 2/5] dma-mapping: Introduce dma_iommu_detach_device() API Thierry Reding
2018-04-25 10:10     ` Thierry Reding
     [not found]     ` <20180425101051.15349-2-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-25 15:19       ` Christoph Hellwig
2018-04-25 15:19         ` Christoph Hellwig
     [not found]         ` <20180425151934.GC16075-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-04-26 12:11           ` Thierry Reding
2018-04-26 12:11             ` Thierry Reding
2018-04-30 11:02             ` Thierry Reding
2018-04-30 11:02               ` Thierry Reding
2018-04-30 11:41               ` Robin Murphy
2018-04-30 11:41                 ` Robin Murphy
     [not found]                 ` <e549979d-9f53-a329-da1a-ed5139958762-5wv7dgnIgG8@public.gmane.org>
2018-04-30 12:12                   ` Thierry Reding
2018-04-30 12:12                     ` Thierry Reding
2018-04-30 12:49                     ` Robin Murphy
2018-04-30 12:49                       ` Robin Murphy
2018-04-25 10:10   ` [PATCH v2 3/5] ARM: dma-mapping: Implement arch_iommu_detach_device() Thierry Reding
2018-04-25 10:10     ` Thierry Reding
     [not found]     ` <20180425101051.15349-3-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-25 15:20       ` Christoph Hellwig
2018-04-25 15:20         ` Christoph Hellwig
     [not found]         ` <20180425152049.GD16075-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-04-26 12:14           ` Thierry Reding
2018-04-26 12:14             ` Thierry Reding
2018-04-25 10:10   ` [PATCH v2 4/5] drm/nouveau: tegra: Use dma_iommu_detach_device() Thierry Reding
2018-04-25 10:10     ` Thierry Reding
2018-04-25 10:10   ` [PATCH v2 5/5] ARM: Unconditionally enable ARM_DMA_USE_IOMMU Thierry Reding
2018-04-25 10:10     ` Thierry Reding
     [not found]     ` <20180425101051.15349-5-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-25 10:25       ` Russell King - ARM Linux
2018-04-25 10:25         ` Russell King - ARM Linux
2018-04-25 15:17         ` Christoph Hellwig
2018-04-25 15:17           ` Christoph Hellwig
2018-04-25 15:18   ` [PATCH v2 1/5] drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping Christoph Hellwig
2018-04-25 15:18     ` Christoph Hellwig
     [not found]     ` <20180425151815.GB16075-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-04-26 12:09       ` Thierry Reding
2018-04-26 12:09         ` Thierry Reding
2018-04-25 15:28 ` Jordan Crouse
2018-04-25 15:28   ` Jordan Crouse
     [not found]   ` <20180425152849.GA2447-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org>
2018-04-26 12:41     ` Thierry Reding
2018-04-26 12:41       ` Thierry Reding
2018-04-26 12:59       ` Mikko Perttunen
2018-04-26 12:59         ` Mikko Perttunen
     [not found]         ` <fd6e0d90-7614-296b-2927-7b2745e8fbde-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2018-04-26 13:14           ` Thierry Reding
2018-04-26 13:14             ` Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.