Re: [RFC PATCH] dma-mapping: create iommu mapping for newly allocated dma coherent mem
From: Christoph Hellwig
Date: Mon Apr 22 2019 - 14:11:22 EST
On Mon, Apr 22, 2019 at 07:51:25PM +0300, laurentiu.tudor@xxxxxxx wrote:
> From: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>
>
> If possible / available call into the DMA API to get a proper iommu
> mapping and a dma address for the newly allocated coherent dma memory.
I don't think this is so simple. The original use case of
dma_declare_coherent_memory was memory that is local to a device, where
we copy in data through a MMIO mapping and the device can then access
it. This use case still seems to be alive in the ohci-sm501 and
ohci-tmio drivers. Going through the iommu in those cases would be
counter productive.
The other use cases, including the OF ones seem to be (and Marek who
added that support should correct me if I'm wrong) normal host DRAM
that is just set aside for the device.
So if we want to support these prealloc pools with an iommu we need to
split the use cases. I have to say I really hate the way we do the DMA
"coherent" allocations, so I'm all in favor of that, it just hasn't
bubbled up towards the front of my todo list yet.
My highlevel plan here would be:
a) move the two OHCI drivers away from our current DMA declare
coherent code, and just use a trivial genalloc allocator for
their MMIO space, given that the USB layer already wraps the
dma_alloc/free APIs anyway
b) move the rest of the DMA coherent stuff into the actual dma
map ops, similar to how we handle CMA allocations. In fact
we should probably do this by a new page allocation helper
that tries CMA, "coherent" or the page allocator as fallback
b) also merge the OF-side handling of CMA vs "coherent" into a
single implementation. Preferably dropping the misleading
"coherent" name while we are at it.