All of lore.kernel.org
 help / color / mirror / Atom feed
* dma_alloc_coherent
@ 2016-02-08  4:01 Vishwas Srivastava
  2016-02-08  6:24 ` dma_alloc_coherent Ran Shalit
  0 siblings, 1 reply; 12+ messages in thread
From: Vishwas Srivastava @ 2016-02-08  4:01 UTC (permalink / raw)
  To: kernelnewbies

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@kernelnewbies.org>
wrote:

> Send Kernelnewbies mailing list submissions to
>         kernelnewbies at kernelnewbies.org
>
> 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 at kernelnewbies.org
>


>
> You can reach the person managing the list at
>         kernelnewbies-owner at kernelnewbies.org
>
> 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@gmail.com>
> Subject: Re: dma_alloc_coherent
> To: Denis Kirjanov <kirjanov@gmail.com>
> Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
> Message-ID:
>         <
> CAJ2oMhLi9LV6QQ-Yr1yNKgoBwC_ET-qTwDAGGrDc9BGZLKNNXA at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> On Fri, Feb 5, 2016 at 11:15 AM, Denis Kirjanov <kirjanov@gmail.com>
> wrote:
> > On 2/5/16, Ran Shalit <ranshalit@gmail.com> 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@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 at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
> End of Kernelnewbies Digest, Vol 63, Issue 7
> ********************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160208/232c5080/attachment-0001.html 

^ permalink raw reply	[flat|nested] 12+ messages in thread
* dma_alloc_coherent
@ 2016-02-05  8:53 Ran Shalit
  2016-02-05  9:15 ` dma_alloc_coherent Denis Kirjanov
  0 siblings, 1 reply; 12+ messages in thread
From: Ran Shalit @ 2016-02-05  8:53 UTC (permalink / raw)
  To: kernelnewbies

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 ?

Thank you,
Ran

^ permalink raw reply	[flat|nested] 12+ messages in thread
* dma_alloc_coherent
@ 2011-10-12 18:17 bob jonny
  2011-10-13  4:24 ` dma_alloc_coherent rohan puri
  0 siblings, 1 reply; 12+ messages in thread
From: bob jonny @ 2011-10-12 18:17 UTC (permalink / raw)
  To: kernelnewbies


In dma_alloc_coherent(), where is it allocating memory from, and how does it know that that memory is cache coherent? Does every device have it's cache coherent memory? I got lost at function pointer struct dma_map_ops ops, is there an easy way to figure out what ops->alloc_coherent() points to?
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111012/8e392753/attachment.html 

^ permalink raw reply	[flat|nested] 12+ messages in thread
* dma_alloc_coherent
@ 2006-04-04 18:07 Kartik Babu
  0 siblings, 0 replies; 12+ messages in thread
From: Kartik Babu @ 2006-04-04 18:07 UTC (permalink / raw)
  To: linux-kernel

  I'm trying to replace consistent_alloc in a driver that was written 
for the 2.4 kernel with dma_alloc_coherent. My question is that I do not 
use a struct device * pointer at all. Browsing through the source for 
the 2.6.12
on ARM XScale PXA255, I see that this argument may be NULL.

 Still, I'd like to know if passing NULL has any side effects. If so, 
what are they?

 I do however have a cdev structure taht I use for device registration, 
but I do not see how that would help.

Thanks
Kartik

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-02-08 10:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <5XY8B-82x-1@gated-at.bofh.it>
2006-04-04 23:45 ` dma_alloc_coherent Robert Hancock
2006-04-05 14:12   ` dma_alloc_coherent Kartik Babu
2016-02-08  4:01 dma_alloc_coherent Vishwas Srivastava
2016-02-08  6:24 ` dma_alloc_coherent Ran Shalit
2016-02-08  6:59   ` dma_alloc_coherent Saumendra Dash
2016-02-08 10:35     ` dma_alloc_coherent sanjeev sharma
  -- strict thread matches above, loose matches on Subject: below --
2016-02-05  8:53 dma_alloc_coherent Ran Shalit
2016-02-05  9:15 ` dma_alloc_coherent Denis Kirjanov
2016-02-06 19:22   ` dma_alloc_coherent Ran Shalit
2011-10-12 18:17 dma_alloc_coherent bob jonny
2011-10-13  4:24 ` dma_alloc_coherent rohan puri
2006-04-04 18:07 dma_alloc_coherent Kartik Babu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.