From: Christoph Hellwig > Sent: 28 January 2021 14:59 > > Add a helper to map memory allocated using dma_alloc_pages into > a user address space, similar to the dma_alloc_attrs function for > coherent allocations. > ... > +:: > + > + int > + dma_mmap_pages(struct device *dev, struct vm_area_struct *vma, > + size_t size, struct page *page) > + > +Map an allocation returned from dma_alloc_pages() into a user address space. > +dev and size must be the same as those passed into dma_alloc_pages(). > +page must be the pointer returned by dma_alloc_pages(). To be useful this needs to specify the offset into the user address area. (ie the offset in the mmap() buffer.) For example we have an fpga based PCIe card that converts internal addresses that refer to one of 512 16k 'pages' to 64bit PCIe bus master addresses. So it (sort of) contains its own iommu. So we can allocate (aligned) 16k kernel memory buffers with dma_alloc_coherent() and make them appear contiguous to the on-board PCIe bus master users. We then mmap() them into contiguous user addresses. So both 'ends' see contiguous addresses without requiring contiguous physical memory or requiring all the memory be allocated at the same time. Clearly in-kernel users have to allow for the 16k boundaries. But the large structures are accesses from user space. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)