dma-direct: Export dma_direct_alloc() and dma_direct_free()
PATCH 1/1 dma-direct: Export dma_direct_alloc() and dma_direct_free()
From: Thierry Reding <[email protected]>
Drivers that are built as modules may want to use these functions, so make them available like the rest of the functions.
--- kernel/dma/direct.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/dma/direct.c +2 -0
@@ -200,6 +200,7 @@ void *dma_direct_alloc(struct device *dev, size_t size,return arch_dma_alloc (dev, size, dma_handle, gfp, attrs);return dma_direct_alloc_pages (dev, size, dma_handle, gfp, attrs); } +EXPORT_SYMBOL (dma_direct_alloc);void dma_direct_free (struct device *dev,size_t size,void *cpu_addr,dma_addr_t dma_addr,unsigned long attrs)
@@ -209,6 +210,7 @@ void dma_direct_free(struct device *dev, size_t size,else dma_direct_free_pages (dev, size, cpu_addr, dma_addr, attrs); } +EXPORT_SYMBOL (dma_direct_free);#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE ) || \ defined(CONFIG_SWIOTLB )
Signature · 1 line
2.19.1
Quoted 6 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Drivers that are built as modules may want to use these functions, so make them available like the rest of the functions.
Signed-off-by Thierry Reding <[email protected]>
How do they want to use these functions? The proper way is to call dma_alloc_coherent / dma_alloc_free and let the DMA API handle the rest.
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Drivers that are built as modules may want to use these functions, so make them available like the rest of the functions.
Signed-off-by Thierry Reding <[email protected]>How do they want to use these functions? The proper way is to call
dma_alloc_coherent/dma_alloc_freeand let the DMA API handle the rest.
This is again for the host1x driver and Tegra DRM where we had a similar situation a little while ago where we needed to explicitly detach from a DMA/IOMMU mapping.
I ran into a similar situation on Tegra186 (which has an ARM SMMU). The host1x driver needs to allocate memory for a push buffer that commands are written to. This push buffer is mapped translated through the SMMU using direct IOMMU API usage. We use the same domain to also map command buffers that userspace can pass in.
The problem is that if I use dma_alloc_coherent(), then the memory will already be mapped via the SMMU at that point and then the driver, not knowing that memory has already been mapped, will attempt to map an IOVA which will cause an SMMU fault when the host1x tries to access the memory.
I didn't find an equivalent to arm_iommu_detach_device() for non-ARM, but then stumbled across this and thought it was rather convenient for these cases. If there's a better way to deal with this situation, I'd be happy to do so.
Thierry
Quoted 10 lines · Thierry Reding
The problem is that if I use
dma_alloc_coherent(), then the memory will already be mapped via the SMMU at that point and then the driver, not knowing that memory has already been mapped, will attempt to map an IOVA which will cause an SMMU fault when the host1x tries to access the memory.I didn't find an equivalent to
arm_iommu_detach_device()for non-ARM, but then stumbled across this and thought it was rather convenient for these cases. If there's a better way to deal with this situation, I'd be happy to do so.
So you basically do a dma_direct_alloc + iommu_map? Can you send me a pointer to your code? Maybe we need to add a proper IOMMU-layer API for that.
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Thierry Reding
The problem is that if I use
dma_alloc_coherent(), then the memory will already be mapped via the SMMU at that point and then the driver, not knowing that memory has already been mapped, will attempt to map an IOVA which will cause an SMMU fault when the host1x tries to access the memory.
Quoted 8 lines
Quoted 4 lines
I didn't find an equivalent to
arm_iommu_detach_device()for non-ARM, but then stumbled across this and thought it was rather convenient for these cases. If there's a better way to deal with this situation, I'd be happy to do so.So you basically do a
dma_direct_alloc+iommu_map? Can you send me a pointer to your code? Maybe we need to add a proper IOMMU-layer API for that.
Sure, here you go:
Thierry
Quoted 3 lines · Thierry Reding
Sure, here you go:
Yes, I think we I can come up with a nicer helper for that.
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Thierry Reding
Sure, here you go:
Yes, I think we I can come up with a nicer helper for that.
One thing I could also try is to remove direct IOMMU API usage at least from the host1x driver. I think this might work nowadays.
For Tegra DRM we still need direct IOMMU API usage because we need to be able to map into an IOMMU domain without knowing the struct device * that we're mapping for (it could be needed by any of up to four display controllers). For host1x we always only have one struct device *, so the DMA mapping API should be good enough.
Thierry
Quoted 4 lines · Thierry Reding
Quoted 3 lines
Quoted 1 line
Yes, I think we I can come up with a nicer helper for that.
Quoted 8 lines
One thing I could also try is to remove direct IOMMU API usage at least from the host1x driver. I think this might work nowadays.
For Tegra DRM we still need direct IOMMU API usage because we need to be able to map into an IOMMU domain without knowing the struct device * that we're mapping for (it could be needed by any of up to four display controllers). For host1x we always only have one struct device *, so the DMA mapping API should be good enough.
If you can convert it to plain DMA API usage, please do.
I did look into an IOMMU API memory allocator, and while we can do it easily for coherent devices, we need some arch hooks for non-coherent device support. With a pending series from me we have those for arm64, but 32-bit arm support will require a lot more work first.
Marek Szyprowski
maintainerHi Thierry,
Quoted 6 lines · Thierry Reding
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Thierry Reding
Sure, here you go:
Yes, I think we I can come up with a nicer helper for that.
Quoted 8 lines
One thing I could also try is to remove direct IOMMU API usage at least from the host1x driver. I think this might work nowadays.
For Tegra DRM we still need direct IOMMU API usage because we need to be able to map into an IOMMU domain without knowing the struct device * that we're mapping for (it could be needed by any of up to four display controllers). For host1x we always only have one struct device *, so the DMA mapping API should be good enough.
In case of Tegra DRM you may try to use Exynos DRM approach. Exynos DRM also consists of more than one DMA capable device and uses one common IOMMU address space for them. It is achieved by attaching all those devices to the IOMMU domain of the first CRTC device that has been registered. Then that device is used for DMA-mapping calls. It is not very elegant, but works fine and allows to use standard DMA-mapping calls.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland