title: What is the difference between dma_mmap_coherent and remap_pfn_range?
body: <p>Currently, I am using an <a href="https://github.com/claudioscordino/mmap_alloc/blob/master/mmap_alloc.c" rel="noreferrer">example driver</a> to learn from, and from which I have based my own custom driver around. The mmap code is very nearly identical, save for the fact that I allow the user to manage their own requested size and base my memory allocation around that and the fact that I automatically create the char device within /dev.</p>
  
  <p>To explain the context, for my use case, I'd like to narrow out an issue that I'm having. <code>dma_mmap_coherent</code> testably works when using kmalloc'd memory, but when I have a reserved physical address region that I want to use remap_pfn_range with it quietly appears to work, and dmesg doesn't report any errors, but when I go to read, no matter what I've written there it always returns 0xff bytes. This is true whether I use the iowrite &amp; ioread in kernel land after ioremap'ing the memory or trying to write in userland using a small mmap'ing userland test.</p>
  
  <p>I've done as much research on the topic as I can I think. All I can find for documentation of remap_pfn_range is the <a href="https://www.kernel.org/doc/htmldocs/kernel-api/API-remap-pfn-range.html" rel="noreferrer">kernel.org page</a>, and some kernel gmain mailing list archives on remap_pfn_range replacing remap_page_range. As for dma_mmap_coherent, I was able to find a little bit more, <a href="https://events.linuxfoundation.org/sites/events/files/slides/20140429-dma.pdf" rel="noreferrer">including a presentation from the linux archives</a>. </p>
  
  <p>Ultimately there has to be a difference; there seems to be so many different ways to map kernel memory into user land. The particular question I have is: what is the difference between <code>dma_mmap_coherent</code> and <code>remap_pfn_range</code>? </p>
  
  <p><strong>Edit</strong> it might be nice to provide a general overview of the ways to map kernel memory into userland in general, covering how different apis would be used in a kernel driver mmap callback.</p>