<div dir="ltr"><div>Hi Ran,<br></div> the api which you have mentioned...<br><div><pre>void *
dma_alloc_coherent(struct device *dev, size_t size,
                         dma_addr_t *dma_handle, gfp_t flag)<br><br></pre><pre>is the kernel api to alloc consistent memory.<br><br></pre><pre>DMA devices understand the physical addresses not the virtual addresses.<br><br></pre><pre>which means that we must supply to the dma device, the physical address, to read<br></pre><pre>from or to write to.<br></pre><pre>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 base<br>address of the allocated memory) and the returned value of this api is the <br>kernel virtual address.<br></pre><div><div class="gmail_extra">if the *CPU* has to operate on this memory (assume that the memory is dma'ed by the dma device and cpu want to read it for further processing ) it should use the virtual address, so the returned value of this api, as the base address.<br></div><div class="gmail_extra">However, if the dma device has to operate on this memory (assume device want to write to this memory), it should use the *dma_handle* , which is the physical address (base) of the dma memory.<br><br></div><div class="gmail_extra">Now the question is how the dma device knows about this *physical* address?<br></div><div class="gmail_extra">The answer is that the "dma controller" register would have a register to accept this physical address.<br><br></div><div class="gmail_extra">So the sequence of steps probably would be, in your case:<br></div><div class="gmail_extra">1: allocate the dma memory<br></div><div class="gmail_extra">2: programme the dma controller register with the physical address returned by this api, plus the size of the transaction and may be some more registers for setting some kind of flags (depends on your dma device)<br></div><div class="gmail_extra">3: programme the dma controller's dma *start* bit.<br><br></div><div class="gmail_extra">after this the dma starts and dma device starts writing to the memory .<br><br><br></div><div class="gmail_extra">I hope, this clarifies you.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Feb 7, 2016 at 10:30 PM, <span dir="ltr"><<a href="mailto:kernelnewbies-request@kernelnewbies.org" target="_blank">kernelnewbies-request@kernelnewbies.org</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">Send Kernelnewbies mailing list submissions to<br>
<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:kernelnewbies-request@kernelnewbies.org">kernelnewbies-request@kernelnewbies.org</a><br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
You can reach the person managing the list at<br>
<a href="mailto:kernelnewbies-owner@kernelnewbies.org">kernelnewbies-owner@kernelnewbies.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Kernelnewbies digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: dma_alloc_coherent (Ran Shalit)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sat, 6 Feb 2016 21:22:49 +0200<br>
From: Ran Shalit <<a href="mailto:ranshalit@gmail.com">ranshalit@gmail.com</a>><br>
Subject: Re: dma_alloc_coherent<br>
To: Denis Kirjanov <<a href="mailto:kirjanov@gmail.com">kirjanov@gmail.com</a>><br>
Cc: kernelnewbies <<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a>><br>
Message-ID:<br>
<<a href="mailto:CAJ2oMhLi9LV6QQ-Yr1yNKgoBwC_ET-qTwDAGGrDc9BGZLKNNXA@mail.gmail.com">CAJ2oMhLi9LV6QQ-Yr1yNKgoBwC_ET-qTwDAGGrDc9BGZLKNNXA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
On Fri, Feb 5, 2016 at 11:15 AM, Denis Kirjanov <<a href="mailto:kirjanov@gmail.com">kirjanov@gmail.com</a>> wrote:<br>
> On 2/5/16, Ran Shalit <<a href="mailto:ranshalit@gmail.com">ranshalit@gmail.com</a>> wrote:<br>
>> Hello,<br>
>><br>
>> I read the readme about dma API, but still don't understand how it<br>
>> should be used<br>
>> It is said that dma_alloc_coherent is responsible for allocating the<br>
>> buffer.<br>
><br>
>><br>
>> 1. But how to trigger the dma transaction to start ?<br>
>> 2. Is there a callback when it is finished ?<br>
><br>
> It's used for data transfer between IO device and system memory. You<br>
> allocate a kernel buffer for DMA transaction (in this case dma from<br>
> device to system memory) and setup your device for dma transfer. An IO<br>
> device usually generates an interrupt when DMA transfer completes.<br>
> Denis<br>
<br>
If I understand correctly the full picture how to use dma is as<br>
following (schematics):<br>
<br>
buf = dma_alloc_coherent(); <<-- done once at the lifetime<br>
<br>
every time we need to trigger dma:<br>
<br>
//start transaction now<br>
writeb(buf, DMA_ADDR) <<- juat an example, actually it is totally<br>
depends on dma device<br>
writeb(START_DMA, DMA_ADDR+2) <<- juat an example, actually it is<br>
totally depends on dma device<br>
<br>
//usually we also register on irq for callback on finishing the transaction.<br>
<br>
hope I got it all correct, if you have any comments please add.<br>
<br>
Thanks,<br>
Ran<br>
<br>
<br>
<br>
------------------------------<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>
<br>
<br>
End of Kernelnewbies Digest, Vol 63, Issue 7<br>
********************************************<br>
</blockquote></div><br></div></div></div></div>