Why dma_alloc_coherent don't return direct mapped vaddr?

Li Chen me at linux.beauty
Fri Jul 22 01:19:19 PDT 2022


 ---- On Fri, 22 Jul 2022 14:50:17 +0800  Arnd Bergmann <arnd at arndb.de> wrote --- 
 > On Fri, Jul 22, 2022 at 4:57 AM Li Chen <me at linux.beauty> wrote:
 > >  ---- On Thu, 21 Jul 2022 15:06:57 +0800  Arnd Bergmann <arnd at arndb.de> wrote ---
 > >  > in between.
 > >
 > > Thanks for your answer! My device is a misc character device, just like
 > > https://lwn.net/ml/linux-kernel/20220711122459.13773-5-me@linux.beauty/
 > > IIUC, its dma_addr is always the same with phy addr. If I want to alloc from
 > > reserved memory and then mmap to userspace with vm_insert_pages, are
 > > cma_alloc/dma_alloc_contigous/dma_alloc_from_contigous better choices?
 > 
 > In the driver, you should only ever use dma_alloc_coherent() for getting
 > a coherent DMA buffer, the other functions are just the implementation
 > details behind that.
 > 
 > To map this buffer to user space, your mmap() function should call
 > dma_mmap_coherent(), which in turn does the correct translation
 > from device specific dma_addr_t values into pages and uses the
 > correct caching attributes.

Yeah, dma_mmap_coherent() is best if I don't care about direct IO.
But if we need **direct I/O**, dma_mmap_cohere cannot be used because it uses remap_pfn_range internally, which will set vma 
to be VM_IO and VM_PFNMAP, so I think I still have to go back to get struct page from rmem and use vm_insert_pages to insert pages into vma, right?

Regards,
Li



More information about the linux-arm-kernel mailing list