Re: dma_alloc_coherent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ran,
             the api which you have mentioned...
void *
dma_alloc_coherent(struct device *dev, size_t size,
			     dma_addr_t *dma_handle, gfp_t flag)

is the kernel api to alloc consistent memory.

DMA devices understand the physical addresses not the virtual addresses.

which means that we must supply to the dma device, the physical address, to read
from or to write to.
The second argument of this api is an input argument which is updated 
by the kernel if this api returns a success (and contains the physical base
address of the allocated memory) and the returned value of this api is the
kernel virtual address.
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.
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.

Now the question is how the dma device knows about this *physical* address?
The answer is that the "dma controller" register would have a register to accept this physical address.

So the sequence of steps probably would be, in your case:
1: allocate the dma memory
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)
3: programme the dma controller's dma *start* bit.

after this the dma starts and dma device starts writing to the memory .


I hope, this clarifies you.




On Sun, Feb 7, 2016 at 10:30 PM, <kernelnewbies-request@xxxxxxxxxxxxxxxxx> wrote:
Send Kernelnewbies mailing list submissions to
        kernelnewbies@xxxxxxxxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
or, via email, send a message with subject or body 'help' to
        kernelnewbies-request@xxxxxxxxxxxxxxxxx
 

You can reach the person managing the list at
        kernelnewbies-owner@xxxxxxxxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Kernelnewbies digest..."


Today's Topics:

   1. Re: dma_alloc_coherent (Ran Shalit)


----------------------------------------------------------------------

Message: 1
Date: Sat, 6 Feb 2016 21:22:49 +0200
From: Ran Shalit <ranshalit@xxxxxxxxx>
Subject: Re: dma_alloc_coherent
To: Denis Kirjanov <kirjanov@xxxxxxxxx>
Cc: kernelnewbies <kernelnewbies@xxxxxxxxxxxxxxxxx>
Message-ID:
        <CAJ2oMhLi9LV6QQ-Yr1yNKgoBwC_ET-qTwDAGGrDc9BGZLKNNXA@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset=UTF-8

On Fri, Feb 5, 2016 at 11:15 AM, Denis Kirjanov <kirjanov@xxxxxxxxx> wrote:
> On 2/5/16, Ran Shalit <ranshalit@xxxxxxxxx> wrote:
>> Hello,
>>
>> I read the readme about dma API, but still don't understand how it
>> should be used
>> It is said that dma_alloc_coherent is responsible for allocating the
>> buffer.
>
>>
>> 1. But how to trigger the dma transaction to start ?
>> 2. Is there a callback when it is finished ?
>
> It's used for data transfer between IO device and system memory. You
> allocate a kernel buffer for DMA transaction (in this case dma from
> device to system memory) and setup your device for dma transfer. An IO
> device usually generates an interrupt when DMA transfer completes.
> Denis

If I understand correctly the full picture how to use dma is as
following (schematics):

buf = dma_alloc_coherent(); <<-- done once at the lifetime

every time we need to trigger dma:

//start transaction now
writeb(buf, DMA_ADDR) <<- juat an example, actually it is totally
depends on dma device
writeb(START_DMA, DMA_ADDR+2) <<- juat an example, actually it is
totally depends on dma device

//usually we also register on irq for callback on finishing the transaction.

 hope I got it all correct, if you have any comments please add.

Thanks,
Ran



------------------------------

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


End of Kernelnewbies Digest, Vol 63, Issue 7
********************************************

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux