title: How to work with reserved CMA memory?
body: <p>I would like to allocate piece of physically contiguous reserved memory (in predefined physical addresses) for my device with DMA support.
  As I see CMA has three options:
  1. To reserve memory via kernel config file. 2. To reserve memory via kernel cmdline. 3. To reserve memory via device-tree memory node.
  In the first case: size and number of areas could be reserved.</p>
  
  <pre><code>CONFIG_DMA_CMA=y
  CONFIG_CMA_AREAS=7
  CONFIG_CMA_SIZE_MBYTES=8
  </code></pre>
  
  <p>So I could use:</p>
  
  <pre><code>start_cma_virt = dma_alloc_coherent(dev-&gt;cmadev, (size_t)size_cma, &amp;start_cma_dma, GFP_KERNEL);
  </code></pre>
  
  <p>in my driver to allocate contiguous memory. I could use it max 7 times and it will be possible allocate up to 8M. But unfortunately </p>
  
  <pre><code>dma_contiguous_reserve(min(arm_dma_limit, arm_lowmem_limit));
  </code></pre>
  
  <p>from arch/arm/mm/init.c:</p>
  
  <pre><code>void __init arm_memblock_init(struct meminfo *mi,const struct machine_desc *mdesc)
  </code></pre>
  
  <p>it is impossible to set predefined physical addresses for contiguous allocation.
  Of Course I could use kernel cmdline:</p>
  
  <pre><code>mem=cma=cmadevlabel=8M@32M cma_map=mydevname=cmadevlabel
  //struct device *dev = cmadev-&gt;dev; /*dev-&gt;name is mydevname*/
  </code></pre>
  
  <p>After that dma_alloc_coherent() should alloc memory in physical memory area from 32M + 8M (0x2000000 + 0x800000) up to 0x27FFFFF.
  But unfortunately I have problem with this solution. Maybe my cmdline has error?
  Next one try was device tree implementation.</p>
  
  <pre><code>cmadev_region: mycma {
      /*no-map;*/ /*DMA coherent memory*/
      /*reusable;*/
      reg = &lt;0x02000000 0x00100000&gt;;      
  };
  </code></pre>
  
  <p>And phandle in some node:</p>
  
  <pre><code>memory-region = &lt;&amp;cmadev_region&gt;;
  </code></pre>
  
  <p>As I saw in kernel usual it should be used like:</p>
  
  <pre><code>of_find_node_by_name(); //find needed node
  of_parse_phandle(); //resolve a phandle property to a device_node pointer
  of_get_address(); //get DT __be32 physical addresses
  of_translate_address(); //DT represent local (bus, device) addresses so translate it to CPU physical addresses 
  request_mem_region(); //reserve IOMAP memory (cat /proc/iomem)
  ioremap(); //alloc entry in page table for reserved memory and return kernel logical addresses.
  </code></pre>
  
  <p>But I want use DMA via (as I know only one external API function dma_alloc_coherent) dma_alloc_coherent() instead IO-MAP ioremap(). But how call</p>
  
  <p>start_cma_virt = dma_alloc_coherent(dev->cmadev, (size_t)size_cma, &amp;start_cma_dma, GFP_KERNEL);</p>
  
  <p>associate memory from device-tree (reg = &lt;0x02000000 0x00100000>;) to dev->cmadev ? In case with cmdline it is clear it has device name and addresses region.
  Does reserved memory after call of_parse_phandle() automatically should be booked for your special driver (which parse DT). And next call dma_alloc_coherent will allocate dma area inside memory from cmadev_region: mycma? </p>