<div dir="ltr"><div><div><div><div>Hello Saumendra,<br><br></div>I would suggest you to go through the following link: 1) This will explain need of DMA with practical scenario 2) ARM DMA Mapping with example<br><br><a href="https://sanjeevsharmaengg.wordpress.com/2014/08/26/why-dma-required-in-linux-kernel/">https://sanjeevsharmaengg.wordpress.com/2014/08/26/why-dma-required-in-linux-kernel/</a> <br><br><a href="http://linuxkernelhacker.blogspot.in/2014/07/arm-dma-mapping-explained.html">http://linuxkernelhacker.blogspot.in/2014/07/arm-dma-mapping-explained.html</a> <br><br></div>I hope these link will give you more confidence around understanding of DMA.<br><br></div>Regards<br></div>Sanjeev Sharma <br><div><div><div><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 8, 2016 at 12:29 PM, Saumendra Dash <span dir="ltr"><<a href="mailto:saumendra.d@hcl.com" target="_blank">saumendra.d@hcl.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">>> Hi Ran,<br>
> the api which you have mentioned...<br>
><br>
>> void *<br>
>> dma_alloc_coherent(struct device *dev, size_t size,<br>
>> dma_addr_t *dma_handle, gfp_t flag)<br>
>><br>
>> is the kernel api to alloc consistent memory.<br>
>><br>
>> DMA devices understand the physical addresses not the virtual addresses.<br>
>><br>
>> which means that we must supply to the dma device, the physical<br>
>> address, to read<br>
>><br>
>> from or to write to.<br>
>><br>
>> The second argument of this api is an input argument which is updated<br>
>> by the kernel if this api returns a success (and contains the physical<br>
>> base address of the allocated memory) and the returned value of this<br>
>> api is the kernel virtual address.<br>
>><br>
>> if the *CPU* has to operate on this memory (assume that the memory is<br>
>> dma'ed by the dma device and cpu want to read it for further<br>
>> processing ) it should use the virtual address, so the returned value<br>
>> of this api, as the base address.<br>
>> However, if the dma device has to operate on this memory (assume<br>
>> device want to write to this memory), it should use the *dma_handle* ,<br>
>> which is the physical address (base) of the dma memory.<br>
>><br>
>> Now the question is how the dma device knows about this *physical* address?<br>
>> The answer is that the "dma controller" register would have a register<br>
>> to accept this physical address.<br>
>><br>
>> So the sequence of steps probably would be, in your case:<br>
>> 1: allocate the dma memory<br>
>> 2: programme the dma controller register with the physical address<br>
>> returned by this api, plus the size of the transaction and may be some<br>
>> more registers for setting some kind of flags (depends on your dma<br>
>> device)<br>
>> 3: programme the dma controller's dma *start* bit.<br>
>><br>
>> after this the dma starts and dma device starts writing to the memory .<br>
<br>
</div></div><span class="">Hi Vishwas,<br>
<br>
>That's fully clarify the questions about dma_alloc_coherent.<br>
<br>
>I also try to figure out what's the difference between dma_alloc_coherent and dma_map_single.<br>
<br>
>I could not find and important difference between these two methods.<br>
>1. With both methods I stil need to program the dma controller with the physical address and the start trigger.<br>
>2. I can still do the allocation whenever I want with both methods (for example at the initialization of the driver), 3. Not sure what the actuall dma_map_single does (and if it really necessary to use it), becuase it >seems I could just translate the virtual value from kmalloc into physical address and return it to the dma controller.<br>
<br>
</span>DMA transfers are done either in BURST mode or CYCLE STEALING mode.<br>
In Burst mode, the bus is captured for the entire duration of the transfer from the SRC to DST. In this case, the bus will be released when the Xfer is complete, so obviously it is not an efficient way of doing DMA. DMA_ALLOC_COHERENT() does this way.<br>
In Cycle Stealing mode, the DMA controller grab the bus when free, send a byte and then free the bus immediately. This process is repeated till the Xfer is complete, it is very efficient sine the bus is not grabbed for the entire transaction to complete. DMA_MAP_SINGLE() does this way.<br>
<br>
Hope this helps.<br>
<br>
Thanks,<br>
Saumendra<br>
<br>
<br>
::DISCLAIMER::<br>
----------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.<br>
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,<br>
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents<br>
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.<br>
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the<br>
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,<br>
distribution and / or publication of this message without the prior written consent of authorized representative of<br>
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.<br>
Before opening any email and/or attachments, please check them for viruses and other defects.<br>
<br>
----------------------------------------------------------------------------------------------------------------------------------------------------<br>
<div class=""><div class="h5"><br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br></div></div></div></div></div></div></div></div></div>