All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] RTDM mmap and DMA
@ 2007-12-14 11:24 Perrine Martignoni
  2007-12-18  9:21 ` Stéphane ANCELOT
  2007-12-18  9:29 ` Jan Kiszka
  0 siblings, 2 replies; 23+ messages in thread
From: Perrine Martignoni @ 2007-12-14 11:24 UTC (permalink / raw)
  To: xenomai-help

[-- Attachment #1: Type: text/plain, Size: 228 bytes --]

Hi,

Currently, I write an RTDM module and I would like to do DMA and mmap to
perform transfers who have hard constraints.
I would like to know if there is an example in a driver who would help me to
do this.


Regards,
Perrine

[-- Attachment #2: Type: text/html, Size: 256 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [Xenomai-help] RTDM mmap and DMA
@ 2007-12-14 13:59 Fillod Stephane
  2007-12-14 15:50 ` Perrine Martignoni
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Fillod Stephane @ 2007-12-14 13:59 UTC (permalink / raw)
  To: Perrine Martignoni, xenomai-help

[-- Attachment #1: Type: text/plain, Size: 1128 bytes --]

Perrine Martignoni wrote:
>Currently, I write an RTDM module and I would like to do DMA and mmap
to perform transfers who have hard constraints.
>I would like to know if there is an example in a driver who would help
me to do this.

I'm looking for the same need, except I'm not using RTDM, and everything
is in userland. Using the attached patch against Xenomai 2.4.0, I hope
to make it to work with something like this:

        RT_HEAP_INFO info;
        RT_HEAP heap;
        void *user_addr;	/* DMA buffer, user access */
        unsigned long dma_addr;	/* for use with the DMA controller */

        /* Allocate memory, suitable for DMA. This occurs before
entering RT land. */
        err = rt_heap_create (&heap,
                        name,
                        heapsz,
                        H_SHARED|H_DMA);
        if (err) { /* ... */ }

        err = rt_heap_alloc (&heap, 0, TM_INFINITE, &user_addr);
        if (err) { /* ... */ }

        err = rt_heap_inquire (&heap, &info);
        if (err) { /* ... */ }

        dma_addr = info.phys_addr;

Any comments?
-- 
Stephane

[-- Attachment #2: heap_dma.patch --]
[-- Type: application/octet-stream, Size: 1633 bytes --]

--- ksrc/nucleus/heap.c	8 Dec 2007 09:15:19 -0000	1.1.1.5
+++ ksrc/nucleus/heap.c	14 Dec 2007 13:36:16 -0000
@@ -1180,7 +1180,15 @@
 		 * space. Assume that we can wait to get the required memory.
 		 */
 
-		ptr = kmalloc(size, kmflags | GFP_KERNEL);
+#define MAX_KMALLOC_SIZE (128*1024)
+		if (size <= MAX_KMALLOC_SIZE)
+			ptr = kmalloc(size, kmflags | GFP_KERNEL);
+		else {
+			unsigned long order;
+			for (order = 0; ((1UL << order) << PAGE_SHIFT) < size; order++)
+				;
+			ptr = (void*) __get_free_pages(kmflags | GFP_KERNEL, order);
+		}
 
 		if (!ptr)
 			return NULL;
@@ -1212,7 +1220,14 @@
 		for (vaddr = vabase; vaddr < vabase + size; vaddr += PAGE_SIZE)
 			ClearPageReserved(virt_to_page(vaddr));
 
-		kfree(ptr);
+		if (size <= MAX_KMALLOC_SIZE)
+			kfree(ptr);
+		else {
+			unsigned long order;
+			for (order = 0; ((1UL << order) << PAGE_SHIFT) < size; order++)
+				;
+			free_pages((unsigned long)ptr, order);
+		}
 	}
 }
 
--- ksrc/skins/native/heap.c	10 Dec 2007 09:59:07 -0000	1.5
+++ ksrc/skins/native/heap.c	14 Dec 2007 13:36:16 -0000
@@ -730,6 +730,7 @@
 	info->usablemem = xnheap_usable_mem(&heap->heap_base);
 	info->usedmem = xnheap_used_mem(&heap->heap_base);
 	info->mode = heap->mode;
+	info->phys_addr = (heap->mode & H_SINGLE) ? virt_to_phys(heap->sba):0;
 
       unlock_and_exit:
 
--- include/native/heap.h	25 Nov 2007 16:50:04 -0000	1.1.1.3
+++ include/native/heap.h	14 Dec 2007 13:36:29 -0000
@@ -48,6 +48,8 @@
 
     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
 
+    unsigned long phys_addr;	/* !< Physical address. */
+
 } RT_HEAP_INFO;
 
 typedef struct rt_heap_placeholder {

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [Xenomai-help] RTDM mmap and DMA
@ 2007-12-17 14:40 Fillod Stephane
  0 siblings, 0 replies; 23+ messages in thread
From: Fillod Stephane @ 2007-12-17 14:40 UTC (permalink / raw)
  To: xenomai-help

Perrine Martignoni wrote:
> I don't know how memory heaps really work but it seems that memory
heaps are shared between user and kernel spaces.
> So, if I do like this I don't need mmap, am I wrong ?

Indeed. rt_heap's take care of mmap'ing as long as the H_MAPPABLE is
set.

http://www.xenomai.org/documentation/trunk/html/api/group__native__heap.
html

>How is done the DMA transfer after ?

You're the only one who knows how to program your DMA (i.e. read your
chip reference
manual). Generally, embedded DMA only "speak" physical addresses. Hence
the patch
sent previously in this discussion.
-- 
Stephane


^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [Xenomai-help] RTDM mmap and DMA
@ 2007-12-18 17:40 Fillod Stephane
  2007-12-18 17:55 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 23+ messages in thread
From: Fillod Stephane @ 2007-12-18 17:40 UTC (permalink / raw)
  To: xenomai-help

Gilles Chanteperdrix wrote:
>On Dec 18, 2007 1:47 PM, Jan Kiszka <jan.kiszka@domain.hid> wrote:
>> Perrine Martignoni wrote:
>> > Thanks for the explanation.
>> > But how can I do to allocate the DMA area ? with the Dma-api of
Linux or
>> > Xenomai offers the possibility to do this ? and what about memory
heap with
>> > H_DMA ?
>> > I'm a bit confused with all of this.
>>
>> Yes, allocation and registration (pci_map*/pci_unmap*) is intended to
>> run via normal Linux. H_DMA (if you were using heaps here), which
leads
>> to GFP_DMA, is only involved for old ISA hardware.
>
>GFP_DMA may also make a big difference on some ARMs. See
>arch/arm/common/dmabounce.c for details.

Not only ARMs. The H_DMA flag appears to work fine with PowerPCs (PQ).
This is quite 
handy in order to obtain physically contiguous memory, from a user task
context. 
The question though is whether there's the below 16 MB address mask in
action,
which is kind of stupid most of the time on embedded PowerPCs.
The patch I sent previously about rt_heap_inquire is also useful to get 
the physical address of the buffer (hint hint: care to commit it?),
which
is needed by most embedded DMAs.

-- 
Stephane


^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [Xenomai-help] RTDM mmap and DMA
@ 2007-12-27 15:39 Fillod Stephane
  2007-12-27 15:43 ` Gilles Chanteperdrix
  2007-12-28 21:59 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 23+ messages in thread
From: Fillod Stephane @ 2007-12-27 15:39 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai-help

Gilles Chanteperdrix wrote:
>Fillod Stephane wrote:
> > Perrine Martignoni wrote:
> > >Currently, I write an RTDM module and I would like to do DMA and
mmap
> > to perform transfers who have hard constraints.
> > >I would like to know if there is an example in a driver who would
help
> > me to do this.
> > 
> > I'm looking for the same need, except I'm not using RTDM, and
everything
> > is in userland. Using the attached patch against Xenomai 2.4.0, I
hope
> > to make it to work with something like this:
>
>I propose the attached modifications. Is it Ok for you ?

Yes, your patch is much cleaner, esp. wrt KMALLOC_MAX_SIZE which I was
not aware of.

The documentation needs an update, and a link to RT_HEAP_INFO.
Does any Doxygen guru knows how to make rt_heap_inquire a hyperlink
in the above chunk?

--- ksrc/skins/native/heap.c    17 Dec 2007 14:36:15 -0000      1.6
+++ ksrc/skins/native/heap.c    27 Dec 2007 15:23:06 -0000
@@ -201,8 +201,8 @@
  *
  * - H_DMA causes the block pool associated to the heap to be
  * allocated in physically contiguous memory, suitable for DMA
- * operations with I/O devices. A 128Kb limit exists for @a heapsize
- * when this flag is passed.
+ * operations with I/O devices. The physical address of the
+ * heap can be obtained by a call to rt_heap_inquire.
  *
  * @return 0 is returned upon success. Otherwise:
  *
--- include/native/heap.h       17 Dec 2007 14:36:09 -0000      1.2
+++ include/native/heap.h       27 Dec 2007 15:34:22 -0000
@@ -34,6 +34,10 @@
 #define H_SINGLE   0x400       /* Manage as single-block area. */
 #define H_SHARED   (H_MAPPABLE|H_SINGLE) /* I.e. shared memory segment.
*/

+/** Structure containing heap-information useful to users.
+ *
+ *  @see rt_heap_inquire()
+ */
 typedef struct rt_heap_info {

     int nwaiters;              /* !< Number of pending tasks. */

Thanks!
-- 
Stephane


^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [Xenomai-help] RTDM mmap and DMA
@ 2008-01-03 18:40 Fillod Stephane
  0 siblings, 0 replies; 23+ messages in thread
From: Fillod Stephane @ 2008-01-03 18:40 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai-help

Gilles Chanteperdrix wrote:
[...]
> Ok. I merged the patch I sent, as well as this patch (fixed to make
> rt_heap_inquire a hyperlink) in trunk. However, I did not commit it in
> the v2.[34].x branch, since it is a patch which breaks the ABI (size
of
> the rt_heap_info structure changes). Should I increment the ABI
revision
?

Albeit it is a minor ABI break, I guess this is the policy expected by 
Xenomai dev.

> Beware: your mailer broke your patch by adding a newline. It may be a
> better idea to send the patch as a plain text attachment, it avoids
such
> surprises. I have already seen a site explaining how to teach your
> mailer not to do this, but I do not have the URL at hand.

Sorry about that. My MUA is a corporate crap, not even able to respect
the References: field. I'll make sure to always use attached files in
the future.
-- 
Stephane


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

end of thread, other threads:[~2008-01-03 18:40 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-14 11:24 [Xenomai-help] RTDM mmap and DMA Perrine Martignoni
2007-12-18  9:21 ` Stéphane ANCELOT
2007-12-18  9:29 ` Jan Kiszka
2007-12-18 10:10   ` Gilles Chanteperdrix
2007-12-18 10:16     ` Perrine Martignoni
2007-12-18 10:18       ` Gilles Chanteperdrix
2007-12-18 10:12   ` Perrine Martignoni
2007-12-18 12:47     ` Jan Kiszka
2007-12-18 13:20       ` Gilles Chanteperdrix
2007-12-18 14:11       ` Perrine Martignoni
2007-12-18 14:22         ` Jan Kiszka
2007-12-18 14:41           ` Perrine Martignoni
  -- strict thread matches above, loose matches on Subject: below --
2007-12-14 13:59 Fillod Stephane
2007-12-14 15:50 ` Perrine Martignoni
2007-12-23 13:09 ` Gilles Chanteperdrix
2007-12-26 23:37 ` Gilles Chanteperdrix
2007-12-17 14:40 Fillod Stephane
2007-12-18 17:40 Fillod Stephane
2007-12-18 17:55 ` Gilles Chanteperdrix
2007-12-27 15:39 Fillod Stephane
2007-12-27 15:43 ` Gilles Chanteperdrix
2007-12-28 21:59 ` Gilles Chanteperdrix
2008-01-03 18:40 Fillod Stephane

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.