Skip to contentSkip to conversation

PPC405: DMA-Problem with OCM (interrupt-example)

Xenomai-core Niklaus Giger 3 participants 8 messages Jan 17, 2007 – Jan 22, 2007

lore
Share & tools
lore
#0 lore raw

Hi

I tried to simply an example program how to use interrupts with Xenomai (see attached Makefile & dma_4xx_int_module.c).

The interrupt part of the example works, but the DMA transfer (memory to memory) using the OnChipMemory fails. I think I must somewhere specify that the src/dst adressed should not be cached, but I do not know how to do it. (I tried to use virt_to_phys and virt_to_bus but failed miserably.) The OCM is initialised in my board specific __init by calling:

Quoted 2 lines

io_block_mapping(mfdcr(DCRN_OCMDSARC), mfdcr(DCRN_OCMDSARC),
4*1024, _PAGE_IO);

A simple insmod/rmmod cycle gives me the following output:

Quoted 11 lines
                     init_module: SRC f4000000 DST f4000103
                     init_module: residue 111 status 0xa00f100
             xenomai_irq_handler: IRQ  8 uipr 0xffffff87 uier 0x003f0000
uisr 0xc0809807 xenomai_irq_handler: residue 0 status 0x1a00f000
src at f4000000 is Could we use a DMA + interrupt to copy a string?
dst at f4000103 is Should be overwritten.
                  cleanup_module: dma_ch.control 0x0 0
                  cleanup_module: IRQ  8 uipr 0xffffff87 uier 0x003f0000

uisr 0xc0009807 cleanup_module: residue 0 status 0x1a00f000 src at f4000000 is Could we use a DMA + interrupt to copy a string? dst at f4000103 is Should be overwritten.

Does anybody have a clue?

If this question is off topic, which mailing list would you reccomend?
(http://ozlabs.org/pipermail/linuxppc-embedded/ ??)

Is the example code otherwise good enough to be accepted as an example how to attach a interrupt?

Best regards

Signature · 1 line
Niklaus Giger
#1 lore raw
Quoted 3 lines · Niklaus Giger

...
Is the example code otherwise good enough to be accepted as an example how to attach a interrupt?

Can't help with your core issue, but I can comment on the IRQ code:

Please use RTDM for in-kernel demos like this. Unless you embed the IRQ handling into an application directly, RTDM is the preferred way to go - as you are then designing a driver.

When porting to RTDM, watch out for the latest change I just checked in:
there is now no need to enable an IRQ line explicitly after requesting it.

Jan

#2 lore raw
In reply to Niklaus Giger
Quoted 7 lines · Niklaus Giger

Hi

I tried to simply an example program how to use interrupts with Xenomai (see attached Makefile & dma_4xx_int_module.c).

The interrupt part of the example works, but the DMA transfer (memory to
memory) using the OnChipMemory fails. I think I must somewhere specify that the src/dst adressed should not be cached, but I do not know how to do it.

consistant_alloc() should help. It's used in the kernel in various places, e.g. in "drivers/net/ibm_emac".

Quoted 19 lines

(I tried to use virt_to_phys and virt_to_bus but failed miserably.) The OCM is initialised in my board specific __init by calling:

Quoted 2 lines

io_block_mapping(mfdcr(DCRN_OCMDSARC), mfdcr(DCRN_OCMDSARC),
4*1024, _PAGE_IO);

A simple insmod/rmmod cycle gives me the following output:

Quoted 11 lines
                     init_module: SRC f4000000 DST f4000103
                     init_module: residue 111 status 0xa00f100
             xenomai_irq_handler: IRQ  8 uipr 0xffffff87 uier 0x003f0000
uisr 0xc0809807 xenomai_irq_handler: residue 0 status 0x1a00f000
src at f4000000 is Could we use a DMA + interrupt to copy a string?
dst at f4000103 is Should be overwritten.
                  cleanup_module: dma_ch.control 0x0 0
                  cleanup_module: IRQ  8 uipr 0xffffff87 uier 0x003f0000

uisr 0xc0009807 cleanup_module: residue 0 status 0x1a00f000 src at f4000000 is Could we use a DMA + interrupt to copy a string? dst at f4000103 is Should be overwritten.

Quoted 4 lines

Does anybody have a clue?

If this question is off topic, which mailing list would you reccomend?
(http://ozlabs.org/pipermail/linuxppc-embedded/ ??)

linuxppc-embedded is OK.

Quoted 1 line

Is the example code otherwise good enough to be accepted as an example how to attach a interrupt?

Wolfgang.

#3 lore raw

Re: [Xenomai-core] PPC405: DMA-problem solved!

Am Donnerstag, 18. Januar 2007 09:31 schrieb Wolfgang Grandegger:

Quoted 6 lines
Quoted 5 lines · Niklaus Giger

Hi

I tried to simply an example program how to use interrupts with Xenomai (see attached Makefile & dma_4xx_int_module.c).

Quoted 7 lines
Quoted 4 lines

The interrupt part of the example works, but the DMA transfer (memory to memory) using the OnChipMemory fails. I think I must somewhere specify that the src/dst adressed should not be cached, but I do not know how to do it.

consistant_alloc() should help. It's used in the kernel in various places, e.g. in "drivers/net/ibm_emac".

Thank you for your tips.

After fixing two bugs in arch/ppc/syslib/ppc4xx_dma.c. See
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
my example code worked (tested with DMA channel 0 and DMA channel 3). <..>

Interrupt code is ported to RTDM.

@Jan: Can the attached patch be applied?

Best regards

Signature · 1 line
Niklaus Giger
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +167 -0
Index: examples/rtdm/pp4xx_interrupt/dma_4xx_int_module.c
===================================================================
@@ -0,0 +1,167 @@
+/* * Written by Niklaus Giger <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ ****************************************************************************
+ *
+ * This is an example howto write a Xenomai kernel module which handles a
+ * HW interrupt. The example is PPC4xx specific (testd on a PPC405 board)
+ * Probably also works on a PPC44x (not yet tested, needs a different irq?).
+ *
+ * Beware!
+ * The following patches must be applied to your kernel to fix bugs
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
+ *
+ * Beware!
+ * The kernel option PPC4xx DMA must be activated for this test.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <asm/ppc4xx_dma.h>
+
+#include <rtdm/rtdm_driver.h>
+#include <rtdm/rtdm.h>
+rtdm_irq_t irq_handle;
+
+MODULE_DESCRIPTION("PPC4xx DMA3 interrupt demo");
+MODULE_AUTHOR("[email protected]");
+MODULE_LICENSE("GPL");
+
+#define DMA_NR 3
+int irq = DMA_NR + 5; /* DMA-x interrupt line  on PPC405GPr */
+
+#define TEST_STRING  "Could we use a DMA + interrupt to copy a string?"
+#define TEST_STRING2 "Should be overwritten."
+#define STRING_SIZE 128
+
+char *SRC;
+char *DST;
+
+static ppc_dma_ch_t p_init;
+
+#define show_irq(irq) 	{						\
+	printk("%32s: IRQ %2d uipr 0x%08x uier 0x%08x uisr 0x%08x\n",	\
+		__FUNCTION__, irq, 					\
+		mfdcr(DCRN_UIC_PR(UIC0)), mfdcr(DCRN_UIC_ER(UIC0)),	\
+		mfdcr(DCRN_UIC_SR(UIC0)));				\
+	printk("%32s: residue %d status 0x08%x cntrl 0x%08x\n",__FUNCTION__,\
+		ppc4xx_get_dma_residue(DMA_NR),				\
+		ppc4xx_get_dma_status(),				\
+		mfdcr(DCRN_DMACR0 + (DMA_NR * 0x8)));			\
+	printk("src at %p is %s\ndst at %p is %s\n", (char *)SRC,	\
+		SRC, &DST[0], &DST[0]); }
+
+void dma_mem_to_mem(void *src, void *dst, unsigned int length,
+			unsigned int use_interrupt)
+{
+#warning Do not use dma_mem_to_mem for OnChipMemory! It will not work.
+	int res = 0;
+	memset((char *)&p_init, sizeof(p_init), 0);
+	p_init.polarity = 0;
+	p_init.pwidth   = PW_8;
+ 	res = ppc4xx_init_dma_channel(DMA_NR, &p_init);
+	if (res) {
+		printk("%32s: nit_dma_channel return %d %d bytes dest %p\n",
+			__FUNCTION__, res, length, dst);
+	}
+	res = ppc4xx_clr_dma_status(DMA_NR);
+	if (res) { 
+		printk("%32s: ppc4xx_clr_dma_status %d\n", __FUNCTION__, res);
+	}
+#warning flush_dcache_all is a performance killer, but I do not know at the 
+#warning moment how to flush only the parts needed
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+
+	ppc4xx_set_dma_mode(DMA_NR, DMA_MODE_MM);
+	ppc4xx_set_src_addr(DMA_NR, virt_to_bus(src));
+	ppc4xx_set_dst_addr(DMA_NR, virt_to_bus(dst));
+	ppc4xx_set_dma_count(DMA_NR, length);
+	ppc4xx_enable_dma(DMA_NR);
+	if (use_interrupt) {
+		res = ppc4xx_enable_dma_interrupt(DMA_NR);
+	} else {
+		res = ppc4xx_disable_dma_interrupt(DMA_NR);
+	}
+	if (res) { 
+		printk("%32s: en/disable_dma_interrupt %d return %d per %d\n",
+		__FUNCTION__, use_interrupt, res, 
+		ppc4xx_get_peripheral_width(DMA_NR));
+	}
+}
+
+int dma_irq_handler(rtdm_irq_t *irq_handle)
+{
+	ppc4xx_disable_dma(DMA_NR);
+	ppc4xx_disable_dma_interrupt(DMA_NR);
+	show_irq(irq);
+	return RTDM_IRQ_HANDLED;
+}
+
+int init_module()
+{
+	if (rtdm_irq_request(&irq_handle, irq,  dma_irq_handler, 0, "dma3_4xx", 0)) {
+		printk("%s:%s Error: rtdm_irq_request failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}
+	show_irq(irq);
+	if (rtdm_irq_enable (&irq_handle)) {
+		printk("%s:%s Error: rtdm_irq_enable failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}
+
+	SRC = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(STRING_SIZE));
+	DST = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(STRING_SIZE));
+
+	strncpy(SRC, TEST_STRING,  STRING_SIZE);
+	strncpy(DST, TEST_STRING2, STRING_SIZE);
+
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+	dma_mem_to_mem(SRC, DST, STRING_SIZE, 1);
+	if (ppc4xx_get_dma_residue(DMA_NR)) { 
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	return 0;
+	
+	
+}
+
+void cleanup_module ()
+{
+	ppc_dma_ch_t dma_ch;
+	if (ppc4xx_get_dma_residue(DMA_NR)) {
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	ppc4xx_get_channel_config(DMA_NR, &dma_ch);
+	printk("%32s: dma_ch.control 0x%x %d SRC %p %s\n",__FUNCTION__, dma_ch.control,
+		dma_ch.pwidth, SRC,__TIME__);
+
+	if (rtdm_irq_disable (&irq_handle)) {
+		printk("%32s: rtdm_irq_disable failed\n",__FUNCTION__);
+	}
+	if (rtdm_irq_free (&irq_handle)) {
+		printk("%32s: rtdm_irq_free failed\n",__FUNCTION__);
+	}
+	show_irq(irq);
+}
rtdm/pp4xx_interrupt/Makefile +47 -0

47 lines not on this page · raw message

common/Makefile +11 -3
Index: examples/common/Makefile
===================================================================
@@ -3,9 +3,9 @@
 ### List of applications to be build
 APPLICATIONS = hw_direct_io
 
-### Note: to override the search path for the xeno-config script, use "make XENO=..."
+### Note: to override the search path for the xeno-config script, use "make XENOCONFIG=..."
+### Note: if you installed it into a non standard place add DESTDIR=/path/to/installed/xenomai"
 
-
 ### List of modules to be build
 MODULES =
 
@@ -14,6 +14,8 @@
 
 ### Note: to override the kernel source path, use "make KSRC=..."
 
+# default place to install the resulting binaries
+EXEC_PREFIX := $(DESTDIR)/usr/xenomai/bin
 
 
 ###### USER SPACE BUILD (no change required normally) ######
@@ -24,7 +26,9 @@
 ### Sanity check
 ifeq ($(XENOCONFIG),)
 all::
-	@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
+	@echo ">>> Invoke make like this: \"make XENOCONFIG=/path/to/xeno-config\" <<<"
+	@echo ">>> add KSRC=.. to override the default kernel source at /lib/modules/$(shell uname -r)/build <<<"
+	@echo ">>> add DESTDIR=/path/to/installed/xenomai if you installed it into a non standard place <<<"
 	@echo
 endif
 
@@ -40,6 +44,9 @@
 clean::
 	$(RM) $(APPLICATIONS) *.o
 
+install::   $(APPLICATIONS)
+	cp $(APPLICATIONS) $(EXEC_PREFIX)/
+
 endif
 
 
@@ -80,3 +87,4 @@
 	$(RM) -R .tmp*
 
 endif
+
#4 lore raw

Re: [Xenomai-core] PPC405: DMA-problem solved!

Quoted 22 lines · Niklaus Giger

Am Donnerstag, 18. Januar 2007 09:31 schrieb Wolfgang Grandegger:

Quoted 6 lines
Quoted 5 lines · Niklaus Giger

Hi

I tried to simply an example program how to use interrupts with Xenomai (see attached Makefile & dma_4xx_int_module.c).

Quoted 6 lines
Quoted 4 lines

The interrupt part of the example works, but the DMA transfer (memory to memory) using the OnChipMemory fails. I think I must somewhere specify that the src/dst adressed should not be cached, but I do not know how to do it.

consistant_alloc() should help. It's used in the kernel in various places, e.g. in "drivers/net/ibm_emac".

Thank you for your tips.

After fixing two bugs in arch/ppc/syslib/ppc4xx_dma.c. See
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
my example code worked (tested with DMA channel 0 and DMA channel 3). <..>

Quoted 3 lines

Interrupt code is ported to RTDM.

@Jan: Can the attached patch be applied?

Almost, just the usual nitpicking comments below. :)

rtdm/pp4xx_interrupt/dma_4xx_int_module.c

Quoted 11 lines

Best regards

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

Index: examples/rtdm/pp4xx_interrupt/dma_4xx_int_module.c
===================================================================

rtdm/pp4xx_interrupt/dma_4xx_int_module.c +0 -0

This demo is about how to use the driver API (/wrt interrupts) + how to do PPC4xx-specific DMA. So my suggestion:

examples/rtdm/driver-api/dma-ppc4xx.c

In any case, we need to resolve the arch dependency somehow. I guess it will currently not fly when I kick the full build in examples/ for a non-PPC platform. Any *simple* way to catch this? Would also be applicable to the heartbeat-x86 example then, though this will not cause build troubles.

Quoted 15 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +14 -0
@@ -0,0 +1,167 @@
+/* * Written by Niklaus Giger <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 24

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ ****************************************************************************
+ *
+ * This is an example howto write a Xenomai kernel module which handles a
+ * HW interrupt. The example is PPC4xx specific (testd on a PPC405 board)
+ * Probably also works on a PPC44x (not yet tested, needs a different irq?).
+ *
+ * Beware!
+ * The following patches must be applied to your kernel to fix bugs

Which kernel? I guess this issue will not persist forever.

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 29

Quoted 5 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +5 -0
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
+ *
+ * Beware!
+ * The kernel option PPC4xx DMA must be activated for this test.

Please provide the full CONFIG_OPTION_NAME here.

Quoted 34 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +34 -0
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <asm/ppc4xx_dma.h>
+
+#include <rtdm/rtdm_driver.h>
+#include <rtdm/rtdm.h>
+rtdm_irq_t irq_handle;
+
+MODULE_DESCRIPTION("PPC4xx DMA3 interrupt demo");
+MODULE_AUTHOR("[email protected]");
+MODULE_LICENSE("GPL");
+
+#define DMA_NR 3
+int irq = DMA_NR + 5; /* DMA-x interrupt line  on PPC405GPr */
+
+#define TEST_STRING  "Could we use a DMA + interrupt to copy a string?"
+#define TEST_STRING2 "Should be overwritten."
+#define STRING_SIZE 128
+
+char *SRC;
+char *DST;
+
+static ppc_dma_ch_t p_init;
+
+#define show_irq(irq) 	{						\
+	printk("%32s: IRQ %2d uipr 0x%08x uier 0x%08x uisr 0x%08x\n",	\
+		__FUNCTION__, irq, 					\
+		mfdcr(DCRN_UIC_PR(UIC0)), mfdcr(DCRN_UIC_ER(UIC0)),	\
+		mfdcr(DCRN_UIC_SR(UIC0)));				\
+	printk("%32s: residue %d status 0x08%x cntrl 0x%08x\n",__FUNCTION__,\

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 73

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+		ppc4xx_get_dma_residue(DMA_NR),				\
+		ppc4xx_get_dma_status(),				\
+		mfdcr(DCRN_DMACR0 + (DMA_NR * 0x8)));			\
+	printk("src at %p is %s\ndst at %p is %s\n", (char *)SRC,	\
+		SRC, &DST[0], &DST[0]); }
+
+void dma_mem_to_mem(void *src, void *dst, unsigned int length,
+			unsigned int use_interrupt)
+{
+#warning Do not use dma_mem_to_mem for OnChipMemory! It will not work.

Why do we have a compiler warning here, why not a comment?

Quoted 5 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +5 -0
+	int res = 0;
+	memset((char *)&p_init, sizeof(p_init), 0);
+	p_init.polarity = 0;
+	p_init.pwidth   = PW_8;
+ 	res = ppc4xx_init_dma_channel(DMA_NR, &p_init);

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 88

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+	if (res) {
+		printk("%32s: nit_dma_channel return %d %d bytes dest %p\n",
+			__FUNCTION__, res, length, dst);
+	}
+	res = ppc4xx_clr_dma_status(DMA_NR);
+	if (res) { 
+		printk("%32s: ppc4xx_clr_dma_status %d\n", __FUNCTION__, res);
+	}
+#warning flush_dcache_all is a performance killer, but I do not know at the 
+#warning moment how to flush only the parts needed

Can we resolve this? Wolfgang?

Quoted 30 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +30 -0
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+
+	ppc4xx_set_dma_mode(DMA_NR, DMA_MODE_MM);
+	ppc4xx_set_src_addr(DMA_NR, virt_to_bus(src));
+	ppc4xx_set_dst_addr(DMA_NR, virt_to_bus(dst));
+	ppc4xx_set_dma_count(DMA_NR, length);
+	ppc4xx_enable_dma(DMA_NR);
+	if (use_interrupt) {
+		res = ppc4xx_enable_dma_interrupt(DMA_NR);
+	} else {
+		res = ppc4xx_disable_dma_interrupt(DMA_NR);
+	}
+	if (res) { 
+		printk("%32s: en/disable_dma_interrupt %d return %d per %d\n",
+		__FUNCTION__, use_interrupt, res, 
+		ppc4xx_get_peripheral_width(DMA_NR));
+	}
+}
+
+int dma_irq_handler(rtdm_irq_t *irq_handle)
+{
+	ppc4xx_disable_dma(DMA_NR);
+	ppc4xx_disable_dma_interrupt(DMA_NR);
+	show_irq(irq);
+	return RTDM_IRQ_HANDLED;
+}
+
+int init_module()
+{
+	if (rtdm_irq_request(&irq_handle, irq,  dma_irq_handler, 0, "dma3_4xx", 0)) {

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 128

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+		printk("%s:%s Error: rtdm_irq_request failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}
+	show_irq(irq);
+	if (rtdm_irq_enable (&irq_handle)) {
+		printk("%s:%s Error: rtdm_irq_enable failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}

This demo will go to trunk, thus rtdm_irq_enable is no longer needed.

Quoted 24 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +24 -0
+
+	SRC = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(STRING_SIZE));
+	DST = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(STRING_SIZE));
+
+	strncpy(SRC, TEST_STRING,  STRING_SIZE);
+	strncpy(DST, TEST_STRING2, STRING_SIZE);
+
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+	dma_mem_to_mem(SRC, DST, STRING_SIZE, 1);
+	if (ppc4xx_get_dma_residue(DMA_NR)) { 
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	return 0;
+	
+	
+}
+
+void cleanup_module ()
+{
+	ppc_dma_ch_t dma_ch;
+	if (ppc4xx_get_dma_residue(DMA_NR)) {
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 162

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	ppc4xx_get_channel_config(DMA_NR, &dma_ch);
+	printk("%32s: dma_ch.control 0x%x %d SRC %p %s\n",__FUNCTION__, dma_ch.control,
+		dma_ch.pwidth, SRC,__TIME__);
+
+	if (rtdm_irq_disable (&irq_handle)) {
+		printk("%32s: rtdm_irq_disable failed\n",__FUNCTION__);
+	}

Disabling is typically not needed, unless it is the only way to silence the IRQ source. Keep in mind that this disabling would be fatal if the IRQ happened to be shared (though unusual on PPC, AFAIK).

Quoted 62 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +5 -0
+	if (rtdm_irq_free (&irq_handle)) {
+		printk("%32s: rtdm_irq_free failed\n",__FUNCTION__);
+	}
+	show_irq(irq);
+}

Index: examples/rtdm/pp4xx_interrupt/Makefile
===================================================================

rtdm/pp4xx_interrupt/Makefile +47 -0
@@ -0,0 +1,47 @@
+###### CONFIGURATION ######
+###### Please adapt it to your needs
+O:=/usr/src/build-hcu3-2.6.19.1
+DESTDIR:=/home/hcu/rootfs/niklaus_2.6.19
+KSRC:=/usr/src/linux-2.6.19.1
+
+ARCH:=ppc
+CROSS_COMPILE:=ppc_4xx-
+PATH:=/home/opt/eldk/4_0/usr/bin:/usr/local/bin:/usr/bin:/bin
+M:=$(shell pwd)
+
+### List of applications to be build
+XENO=$(DESTDIR)/usr/xenomai
+### Note: to override the search path for the xeno-config script, use "make XENOCONFIG=..."
+
+
+### List of modules to be build
+MODULES = dma_4xx_int_module
+
+### Note: to override the kernel source path, use "make KSRC=..."
+
+###### KERNEL MODULE BUILD (no change required normally) ######
+ifneq ($(MODULES),)
+
+OBJS     := ${patsubst %, %.o, $(MODULES)}
+CLEANMOD := ${patsubst %, .%*, $(MODULES)}
+PWD      := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
+
+### Kernel 2.6
+obj-m        := $(OBJS)
+EXTRA_CFLAGS :=-I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix $(ADD_CFLAGS)
+
+MODMAKE:=make CROSS_COMPILE=$(CROSS_COMPILE)  ARCH=$(ARCH) O=$(O) -C $(KSRC) M=$(M) PATH=$(PATH) -I$(KSRC)/include/xenomai
+
+modules:
+	$(MODMAKE) modules
+
+install:	modules
+	$(MODMAKE) INSTALL_MOD_PATH=$(DESTDIR) modules_install
+
+all::	modules
+
+clean::
+	$(RM) $(CLEANMOD) *.cmd *.o *.ko *.mod.c Module*.symvers
+	$(RM) -R .tmp*
+
+endif

Index: examples/common/Makefile
===================================================================

common/Makefile line 6

Quoted 5 lines
common/Makefile +1 -1
@@ -3,9 +3,9 @@
 ### List of applications to be build
 APPLICATIONS = hw_direct_io
 
-### Note: to override the search path for the xeno-config script, use "make XENO=..."
+### Note: to override the search path for the xeno-config script, use "make XENOCONFIG=..."

If you prefer XENOCONFIG, please provide patches for the whole examples repos. :)

common/Makefile line 7

Quoted 1 line
common/Makefile +1 -0
+### Note: if you installed it into a non standard place add DESTDIR=/path/to/installed/xenomai"

The hint to DESTDIR is useful, but the explanation should be more like "if Xenomai was installed with DESTDIR set, the same must be provided here".

Quoted 15 lines
common/Makefile +2 -1
-
 ### List of modules to be build
 MODULES =
 
@@ -14,6 +14,8 @@
 
 ### Note: to override the kernel source path, use "make KSRC=..."
 
+# default place to install the resulting binaries
+EXEC_PREFIX := $(DESTDIR)/usr/xenomai/bin
 
 
 ###### USER SPACE BUILD (no change required normally) ######

common/Makefile line 30

Quoted 6 lines
common/Makefile +2 -1
@@ -24,7 +26,9 @@
 ### Sanity check
 ifeq ($(XENOCONFIG),)
 all::
-	@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
+	@echo ">>> Invoke make like this: \"make XENOCONFIG=/path/to/xeno-config\" <<<"
+	@echo ">>> add KSRC=.. to override the default kernel source at /lib/modules/$(shell uname -r)/build <<<"

KSRC is unrelated here (user space part of the makefile).

common/Makefile line 31

Quoted 1 line
common/Makefile +1 -0
+	@echo ">>> add DESTDIR=/path/to/installed/xenomai if you installed it into a non standard place <<<"

See earlier comment.

common/Makefile line 49

Quoted 10 lines
common/Makefile +3 -0
 	@echo
 endif
 
@@ -40,6 +44,9 @@
 clean::
 	$(RM) $(APPLICATIONS) *.o
 
+install::   $(APPLICATIONS)
+	cp $(APPLICATIONS) $(EXEC_PREFIX)/
+

NACK. I'd rather like to keep the makefile focused (the next step would be to add uninstall, then ...).

common/Makefile line 90

Quoted 10 lines
common/Makefile +1 -0
 endif
 
 
@@ -80,3 +87,4 @@
 	$(RM) -R .tmp*
 
 endif
+

Jan

#5 lore raw

Re: [Xenomai-core] PPC405: DMA-problem solved!

Quoted 42 lines · Jan Kiszka
Quoted 21 lines · Niklaus Giger

Am Donnerstag, 18. Januar 2007 09:31 schrieb Wolfgang Grandegger:

Quoted 6 lines
Quoted 5 lines · Niklaus Giger

Hi

I tried to simply an example program how to use interrupts with Xenomai (see attached Makefile & dma_4xx_int_module.c).

Quoted 6 lines
Quoted 4 lines

The interrupt part of the example works, but the DMA transfer (memory to memory) using the OnChipMemory fails. I think I must somewhere specify that the src/dst adressed should not be cached, but I do not know how to do it.

consistant_alloc() should help. It's used in the kernel in various places, e.g. in "drivers/net/ibm_emac".

Thank you for your tips.

After fixing two bugs in arch/ppc/syslib/ppc4xx_dma.c. See
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
my example code worked (tested with DMA channel 0 and DMA channel 3). <..>

Quoted 3 lines

Interrupt code is ported to RTDM.

@Jan: Can the attached patch be applied?

Almost, just the usual nitpicking comments below. :)

rtdm/pp4xx_interrupt/dma_4xx_int_module.c

Quoted 10 lines

Best regards

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

Index: examples/rtdm/pp4xx_interrupt/dma_4xx_int_module.c
===================================================================

rtdm/pp4xx_interrupt/dma_4xx_int_module.c +0 -0

This demo is about how to use the driver API (/wrt interrupts) + how to do PPC4xx-specific DMA. So my suggestion:

Quoted 7 lines

examples/rtdm/driver-api/dma-ppc4xx.c

In any case, we need to resolve the arch dependency somehow. I guess it will currently not fly when I kick the full build in examples/ for a non-PPC platform. Any *simple* way to catch this? Would also be applicable to the heartbeat-x86 example then, though this will not cause build troubles.

The only simple way I see is referencing the configured kernel tree.

Quoted 19 lines
Quoted 19 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +18 -0
@@ -0,0 +1,167 @@
+/* * Written by Niklaus Giger <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ ****************************************************************************
+ *
Quoted 8 lines

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 24

Quoted 6 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +6 -0
+ * This is an example howto write a Xenomai kernel module which handles a
+ * HW interrupt. The example is PPC4xx specific (testd on a PPC405 board)
+ * Probably also works on a PPC44x (not yet tested, needs a different irq?).
+ *
+ * Beware!
+ * The following patches must be applied to your kernel to fix bugs

Which kernel? I guess this issue will not persist forever.

Hopefully not.

Quoted 65 lines

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 29

Quoted 6 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +5 -0
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
+ *
+ * Beware!
+ * The kernel option PPC4xx DMA must be activated for this test.

Please provide the full CONFIG_OPTION_NAME here.

Quoted 34 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +34 -0
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <asm/ppc4xx_dma.h>
+
+#include <rtdm/rtdm_driver.h>
+#include <rtdm/rtdm.h>
+rtdm_irq_t irq_handle;
+
+MODULE_DESCRIPTION("PPC4xx DMA3 interrupt demo");
+MODULE_AUTHOR("[email protected]");
+MODULE_LICENSE("GPL");
+
+#define DMA_NR 3
+int irq = DMA_NR + 5; /* DMA-x interrupt line  on PPC405GPr */
+
+#define TEST_STRING  "Could we use a DMA + interrupt to copy a string?"
+#define TEST_STRING2 "Should be overwritten."
+#define STRING_SIZE 128
+
+char *SRC;
+char *DST;
+
+static ppc_dma_ch_t p_init;
+
+#define show_irq(irq) 	{						\
+	printk("%32s: IRQ %2d uipr 0x%08x uier 0x%08x uisr 0x%08x\n",	\
+		__FUNCTION__, irq, 					\
+		mfdcr(DCRN_UIC_PR(UIC0)), mfdcr(DCRN_UIC_ER(UIC0)),	\
+		mfdcr(DCRN_UIC_SR(UIC0)));				\
+	printk("%32s: residue %d status 0x08%x cntrl 0x%08x\n",__FUNCTION__,\

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 73

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+		ppc4xx_get_dma_residue(DMA_NR),				\
+		ppc4xx_get_dma_status(),				\
+		mfdcr(DCRN_DMACR0 + (DMA_NR * 0x8)));			\
+	printk("src at %p is %s\ndst at %p is %s\n", (char *)SRC,	\
+		SRC, &DST[0], &DST[0]); }
+
+void dma_mem_to_mem(void *src, void *dst, unsigned int length,
+			unsigned int use_interrupt)
+{
+#warning Do not use dma_mem_to_mem for OnChipMemory! It will not work.

Why do we have a compiler warning here, why not a comment?

Quoted 9 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +9 -0
+	int res = 0;
+	memset((char *)&p_init, sizeof(p_init), 0);
+	p_init.polarity = 0;
+	p_init.pwidth   = PW_8;
+ 	res = ppc4xx_init_dma_channel(DMA_NR, &p_init);
+	if (res) {
+		printk("%32s: nit_dma_channel return %d %d bytes dest %p\n",
+			__FUNCTION__, res, length, dst);
+	}
Quoted 8 lines

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 88

Quoted 6 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +6 -0
+	res = ppc4xx_clr_dma_status(DMA_NR);
+	if (res) { 
+		printk("%32s: ppc4xx_clr_dma_status %d\n", __FUNCTION__, res);
+	}
+#warning flush_dcache_all is a performance killer, but I do not know at the 
+#warning moment how to flush only the parts needed

Can we resolve this? Wolfgang?

flush_dcache_range should do the job. Or even better use the DMA-API described in Documentation/DMA-API.txt to get DMA'able memory (as pointed out recently on the linuxppc-emmbedded ML).

Quoted 82 lines
Quoted 30 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +30 -0
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+
+	ppc4xx_set_dma_mode(DMA_NR, DMA_MODE_MM);
+	ppc4xx_set_src_addr(DMA_NR, virt_to_bus(src));
+	ppc4xx_set_dst_addr(DMA_NR, virt_to_bus(dst));
+	ppc4xx_set_dma_count(DMA_NR, length);
+	ppc4xx_enable_dma(DMA_NR);
+	if (use_interrupt) {
+		res = ppc4xx_enable_dma_interrupt(DMA_NR);
+	} else {
+		res = ppc4xx_disable_dma_interrupt(DMA_NR);
+	}
+	if (res) { 
+		printk("%32s: en/disable_dma_interrupt %d return %d per %d\n",
+		__FUNCTION__, use_interrupt, res, 
+		ppc4xx_get_peripheral_width(DMA_NR));
+	}
+}
+
+int dma_irq_handler(rtdm_irq_t *irq_handle)
+{
+	ppc4xx_disable_dma(DMA_NR);
+	ppc4xx_disable_dma_interrupt(DMA_NR);
+	show_irq(irq);
+	return RTDM_IRQ_HANDLED;
+}
+
+int init_module()
+{
+	if (rtdm_irq_request(&irq_handle, irq,  dma_irq_handler, 0, "dma3_4xx", 0)) {

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 128

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+		printk("%s:%s Error: rtdm_irq_request failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}
+	show_irq(irq);
+	if (rtdm_irq_enable (&irq_handle)) {
+		printk("%s:%s Error: rtdm_irq_enable failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}

This demo will go to trunk, thus rtdm_irq_enable is no longer needed.

Quoted 24 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +24 -0
+
+	SRC = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(STRING_SIZE));
+	DST = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(STRING_SIZE));
+
+	strncpy(SRC, TEST_STRING,  STRING_SIZE);
+	strncpy(DST, TEST_STRING2, STRING_SIZE);
+
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+	dma_mem_to_mem(SRC, DST, STRING_SIZE, 1);
+	if (ppc4xx_get_dma_residue(DMA_NR)) { 
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	return 0;
+	
+	
+}
+
+void cleanup_module ()
+{
+	ppc_dma_ch_t dma_ch;
+	if (ppc4xx_get_dma_residue(DMA_NR)) {
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 162

Quoted 10 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +10 -0
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	ppc4xx_get_channel_config(DMA_NR, &dma_ch);
+	printk("%32s: dma_ch.control 0x%x %d SRC %p %s\n",__FUNCTION__, dma_ch.control,
+		dma_ch.pwidth, SRC,__TIME__);
+
+	if (rtdm_irq_disable (&irq_handle)) {
+		printk("%32s: rtdm_irq_disable failed\n",__FUNCTION__);
+	}

Disabling is typically not needed, unless it is the only way to silence the IRQ source. Keep in mind that this disabling would be fatal if the IRQ happened to be shared (though unusual on PPC, AFAIK).

Quoted 5 lines

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 167

Quoted 5 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +5 -0
+	if (rtdm_irq_free (&irq_handle)) {
+		printk("%32s: rtdm_irq_free failed\n",__FUNCTION__);
+	}
+	show_irq(irq);
+}

And should we not also use rtdm_prinkt()?

Quoted 7 lines
Quoted 7 lines

Index: examples/rtdm/pp4xx_interrupt/Makefile
===================================================================

rtdm/pp4xx_interrupt/Makefile +2 -0
@@ -0,0 +1,47 @@
+###### CONFIGURATION ######
+###### Please adapt it to your needs
Quoted 8 lines

rtdm/pp4xx_interrupt/Makefile line 10

Quoted 8 lines
rtdm/pp4xx_interrupt/Makefile +8 -0
+O:=/usr/src/build-hcu3-2.6.19.1
+DESTDIR:=/home/hcu/rootfs/niklaus_2.6.19
+KSRC:=/usr/src/linux-2.6.19.1
+
+ARCH:=ppc
+CROSS_COMPILE:=ppc_4xx-
+PATH:=/home/opt/eldk/4_0/usr/bin:/usr/local/bin:/usr/bin:/bin
+M:=$(shell pwd)

This is your private stuff and should be removed.

Quoted 28 lines
Quoted 28 lines
rtdm/pp4xx_interrupt/Makefile +28 -0
+### List of applications to be build
+XENO=$(DESTDIR)/usr/xenomai
+### Note: to override the search path for the xeno-config script, use "make XENOCONFIG=..."
+
+
+### List of modules to be build
+MODULES = dma_4xx_int_module
+
+### Note: to override the kernel source path, use "make KSRC=..."
+
+###### KERNEL MODULE BUILD (no change required normally) ######
+ifneq ($(MODULES),)
+
+OBJS     := ${patsubst %, %.o, $(MODULES)}
+CLEANMOD := ${patsubst %, .%*, $(MODULES)}
+PWD      := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
+
+### Kernel 2.6
+obj-m        := $(OBJS)
+EXTRA_CFLAGS :=-I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix $(ADD_CFLAGS)
+
+MODMAKE:=make CROSS_COMPILE=$(CROSS_COMPILE)  ARCH=$(ARCH) O=$(O) -C $(KSRC) M=$(M) PATH=$(PATH) -I$(KSRC)/include/xenomai
+
+modules:
+	$(MODMAKE) modules
+
+install:	modules
+	$(MODMAKE) INSTALL_MOD_PATH=$(DESTDIR) modules_install
Quoted 8 lines

rtdm/pp4xx_interrupt/Makefile line 47

Quoted 8 lines
rtdm/pp4xx_interrupt/Makefile +8 -0
+
+all::	modules
+
+clean::
+	$(RM) $(CLEANMOD) *.cmd *.o *.ko *.mod.c Module*.symvers
+	$(RM) -R .tmp*
+
+endif

Anyway, the Makefile /examples/rtdm/driver-api/Makefile should work fine for this example as well.

Quoted 64 lines

common/Makefile line 6

Quoted 10 lines

Index: examples/common/Makefile
===================================================================

common/Makefile +1 -1
@@ -3,9 +3,9 @@
 ### List of applications to be build
 APPLICATIONS = hw_direct_io
 
-### Note: to override the search path for the xeno-config script, use "make XENO=..."
+### Note: to override the search path for the xeno-config script, use "make XENOCONFIG=..."

If you prefer XENOCONFIG, please provide patches for the whole examples repos. :)

common/Makefile line 7

Quoted 1 line
common/Makefile +1 -0
+### Note: if you installed it into a non standard place add DESTDIR=/path/to/installed/xenomai"

The hint to DESTDIR is useful, but the explanation should be more like "if Xenomai was installed with DESTDIR set, the same must be provided here".

Quoted 15 lines
common/Makefile +2 -1
-
 ### List of modules to be build
 MODULES =
 
@@ -14,6 +14,8 @@
 
 ### Note: to override the kernel source path, use "make KSRC=..."
 
+# default place to install the resulting binaries
+EXEC_PREFIX := $(DESTDIR)/usr/xenomai/bin
 
 
 ###### USER SPACE BUILD (no change required normally) ######

common/Makefile line 30

Quoted 6 lines
common/Makefile +2 -1
@@ -24,7 +26,9 @@
 ### Sanity check
 ifeq ($(XENOCONFIG),)
 all::
-	@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
+	@echo ">>> Invoke make like this: \"make XENOCONFIG=/path/to/xeno-config\" <<<"
+	@echo ">>> add KSRC=.. to override the default kernel source at /lib/modules/$(shell uname -r)/build <<<"

KSRC is unrelated here (user space part of the makefile).

common/Makefile line 31

Quoted 1 line
common/Makefile +1 -0
+	@echo ">>> add DESTDIR=/path/to/installed/xenomai if you installed it into a non standard place <<<"

See earlier comment.

common/Makefile line 49

Quoted 10 lines
common/Makefile +3 -0
 	@echo
 endif
 
@@ -40,6 +44,9 @@
 clean::
 	$(RM) $(APPLICATIONS) *.o
 
+install::   $(APPLICATIONS)
+	cp $(APPLICATIONS) $(EXEC_PREFIX)/
+

NACK. I'd rather like to keep the makefile focused (the next step would be to add uninstall, then ...).

Quoted 3 lines
common/Makefile +0 -0
 endif
 
 
Quoted 7 lines

common/Makefile line 90

Quoted 7 lines
common/Makefile +1 -0
@@ -80,3 +87,4 @@
 	$(RM) -R .tmp*
 
 endif
+

What does the hw_direct_io example do? As I see it, it's not related to Xenomai.

Wolfgang.

#7 lore raw

Re: [Xenomai-core] PPC405: DMA-problem solved!

In reply to Jan Kiszka

(Forgot to cc @xenomai-core this e-mail sent yesterday to Jan) Am Samstag, 20. Januar 2007 09:04 schrieben Sie:

Quoted 1 line

Niklaus Giger wrote:

<..>

Quoted 4 lines

This demo is about how to use the driver API (/wrt interrupts) + how to do PPC4xx-specific DMA. So my suggestion:

examples/rtdm/driver-api/dma-ppc4xx.c

Agreed. See new version in the attached patch.

Quoted 6 lines

In any case, we need to resolve the arch dependency somehow. I guess it will  currently not fly when I kick the full build in examples/ for a non-PPC platform. Any *simple* way to catch this? Would also be applicable to the heartbeat-x86 example then, though this will not cause build troubles.

Is my proposed solution in the Makefile okay for you? How do you kick your full build? Does it still work now?

<..>

Quoted 11 lines
Quoted 1 line

+ * The following patches must be applied to your kernel to fix bugs

Which kernel? I guess this issue will not persist forever.

Quoted 6 lines

+ *
http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html +
* http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
+ *
+ * Beware!
+ * The kernel option PPC4xx DMA must be activated for this test.

Please provide the full CONFIG_OPTION_NAME here.

Fixed.
<..>

Quoted 1 line

Why do we have a compiler warning here, why not a comment?

Fixed.

Quoted 5 lines
Quoted 2 lines

+#warning flush_dcache_all is a performance killer, but I do not know at the +#warning moment how to flush only the parts needed

Can we resolve this? Wolfgang?

Quoted 1 line

+   flush_dcache_all(); /* from arch/ppc/kernel/misc.S */

I think we cannot fix this, as it is probably a weakness of the port to PPC4xx. I tried various procedures *dcache* procedure which all lead to kernel oops. I changed the comment a little to reflect the change.

I looked also at dma_alloc_coherent, but this need a driver structure which I do not have in this example. I have no time at this moment to really dig deeper into the 4xx-DMA problems. But I might be forced to do it later once I get hands on our new PPC440EPx based board later (around March/April this year). I remember spending quite a few hours on this problem years ago on our first PPC403GA board (but running vxWorks).

<..>

Quoted 3 lines

This demo will go to trunk, thus rtdm_irq_enable is no longer needed.

Didn't know. Fixed.
<..>

Quoted 4 lines

Disabling is typically not needed, unless it is the only way to silence the IRQ source. Keep in mind that this disabling would be fatal if the IRQ happened to be shared (though unusual on PPC, AFAIK).

Thanks for catching this error. Fixed.
<..>

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+install::   $(APPLICATIONS)
+   cp $(APPLICATIONS) $(EXEC_PREFIX)/
+

NACK. I'd rather like to keep the makefile focused (the next step would be to add uninstall, then ...).

Added a comment on top of the Makefile about how to call it for cross compiling.

I changed the target to modules_install, but still think that this is useful for my use, eg. without it I have no direct way to access the kernel module from my NFS-mounted rootfs when I want to run a test on my target board. Another solution would be to add an example script to cross compile like the following (tested) snippet

Quoted 10 lines

make \
-C   /usr/src/linux-2.6.19.1 \
KSRC=/usr/src/linux-2.6.19.1 \
ARCH=ppc \
O=/usr/src/build-hcu3-2.6.19.1 \
INSTALL_MOD_PATH=/home/hcu/rootfs/niklaus_2.6.19 \
CROSS_COMPILE=ppc_4xx-  \
PATH=/opt/eldk/4_0/usr/bin:$PATH \
SUBDIRS=pwd \
modules modules_install

Thanks for your careful review.

Best regards
---
Niklaus Giger

rtdm/driver-api/dma-ppc4xx.c +169 -0
Index: examples/rtdm/driver-api/dma-ppc4xx.c
===================================================================
@@ -0,0 +1,169 @@
+/* * Written by Niklaus Giger <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ ****************************************************************************
+ *
+ * This is an example howto write a Xenomai kernel module which handles a
+ * HW interrupt. The example is PPC4xx specific (testd on a PPC405 board)
+ * Probably also works on a PPC44x (not yet tested, needs a different irq?).
+ *
+ * Beware!
+ * The following patches had to be applied against the 2.6.19.2 linux kernel
+ * to fix bugs in arch/ppc/syslib/ppc4xx_dma.c
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025697.html
+ * http://ozlabs.org/pipermail/linuxppc-embedded/2007-January/025700.html
+ *
+ * Beware!
+ * The kernel option CONFIG_PPC4xx_DMA must be activated for this test.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <asm/ppc4xx_dma.h>
+
+#include <rtdm/rtdm_driver.h>
+#include <rtdm/rtdm.h>
+rtdm_irq_t irq_handle;
+
+MODULE_DESCRIPTION("PPC4xx DMA3 interrupt demo");
+MODULE_AUTHOR("[email protected]");
+MODULE_LICENSE("GPL");
+
+#define DMA_NR 3
+int irq = DMA_NR + 5; /* DMA-x interrupt line  on PPC405GPr */
+
+#define TEST_STRING  "Could we use a DMA + interrupt to copy a string?"
+#define TEST_STRING2 "Should be overwritten."
+#define STRING_SIZE 128
+
+char *SRC;
+char *DST;
+
+static ppc_dma_ch_t p_init;
+
+#define show_irq(irq) 	{						\
+	printk("%32s: IRQ %2d uipr 0x%08x uier 0x%08x uisr 0x%08x\n",	\
+		__FUNCTION__, irq, 					\
+		mfdcr(DCRN_UIC_PR(UIC0)), mfdcr(DCRN_UIC_ER(UIC0)),	\
+		mfdcr(DCRN_UIC_SR(UIC0)));				\
+	printk("%32s: residue %d status 0x08%x cntrl 0x%08x\n",__FUNCTION__,\
+		ppc4xx_get_dma_residue(DMA_NR),				\
+		ppc4xx_get_dma_status(),				\
+		mfdcr(DCRN_DMACR0 + (DMA_NR * 0x8)));			\
+	printk("src at %p is %s\ndst at %p is %s\n", (char *)SRC,	\
+		SRC, &DST[0], &DST[0]); }
+
+void dma_mem_to_mem(void *src, void *dst, unsigned int length,
+			unsigned int use_interrupt)
+{
+	/* Do not use dma_mem_to_mem for OnChipMemory! It will not work. */
+	int res = 0;
+	memset((char *)&p_init, sizeof(p_init), 0);
+	p_init.polarity = 0;
+	p_init.pwidth   = PW_8;
+ 	res = ppc4xx_init_dma_channel(DMA_NR, &p_init);
+	if (res) {
+		printk("%32s: nit_dma_channel return %d %d bytes dest %p\n",
+			__FUNCTION__, res, length, dst);
+	}
+	res = ppc4xx_clr_dma_status(DMA_NR);
+	if (res) { 
+		printk("%32s: ppc4xx_clr_dma_status %d\n", __FUNCTION__, res);
+	}
+	/*
+	 * flush_dcache_all is a performance killer, but is does work on a
+	 * PPC405GPr as it does not use any of the DCU instructions like dcbf.
+	 * Procedures like flush_dcache_range produce:
+	 * Oops: kernel access of bad area, sig: 11 [#1]
+	 * Probably all these procedure should be fixe for PPC40x
+	*/
+	flush_dcache_all(); /* from arch/ppc/kernel/misc.S */
+	ppc4xx_set_dma_mode(DMA_NR, DMA_MODE_MM);
+	ppc4xx_set_src_addr(DMA_NR, virt_to_bus(src));
+	ppc4xx_set_dst_addr(DMA_NR, virt_to_bus(dst));
+	ppc4xx_set_dma_count(DMA_NR, length);
+	ppc4xx_enable_dma(DMA_NR);
+	if (use_interrupt) {
+		res = ppc4xx_enable_dma_interrupt(DMA_NR);
+	} else {
+		res = ppc4xx_disable_dma_interrupt(DMA_NR);
+	}
+	if (res) { 
+		printk("%32s: en/disable_dma_interrupt %d return %d per %d\n",
+		__FUNCTION__, use_interrupt, res, 
+		ppc4xx_get_peripheral_width(DMA_NR));
+	}
+}
+
+int dma_irq_handler(rtdm_irq_t *irq_handle)
+{
+	ppc4xx_disable_dma(DMA_NR);
+	ppc4xx_disable_dma_interrupt(DMA_NR);
+	show_irq(irq);
+	return RTDM_IRQ_HANDLED;
+}
+
+int init_module()
+{
+	if (rtdm_irq_request(&irq_handle, irq,  
+			dma_irq_handler, 0, "dma3_4xx", 0)) {
+		printk("%s:%s Error: rtdm_irq_request failed\n",
+			 __FILE__, __FUNCTION__);
+		return 1;
+	}
+	SRC = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, 
+				get_order(STRING_SIZE));
+	DST = (char *)__get_free_pages(GFP_KERNEL | GFP_DMA, 
+				get_order(STRING_SIZE));
+
+	strncpy(SRC, TEST_STRING,  STRING_SIZE);
+	strncpy(DST, TEST_STRING2, STRING_SIZE);
+
+	dma_mem_to_mem(SRC, DST, STRING_SIZE, 1);
+	if (ppc4xx_get_dma_residue(DMA_NR)) { 
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	return 0;
+	
+	
+}
+
+void cleanup_module ()
+{
+	ppc_dma_ch_t dma_ch;
+	if (ppc4xx_get_dma_residue(DMA_NR)) {
+		printk("%32s: residue %d status 0x%x\n",__FUNCTION__,
+		ppc4xx_get_dma_residue(DMA_NR),
+		ppc4xx_get_dma_status());
+	}
+	ppc4xx_get_channel_config(DMA_NR, &dma_ch);
+	printk("%32s: dma_ch.control 0x%x %d SRC %p %s\n",__FUNCTION__,
+		dma_ch.control,	dma_ch.pwidth, SRC,__TIME__);
+
+	if (rtdm_irq_free (&irq_handle)) {
+		printk("%32s: rtdm_irq_free failed\n",__FUNCTION__);
+	}
+	show_irq(irq);
+	if (strncmp(DST, TEST_STRING, STRING_SIZE) == 0) {
+		printk("%32s: DMA transfer succedded\n",__FUNCTION__);
+	} else {
+		printk("%32s: DMA transfer failed !!!!!\n",__FUNCTION__);
+	}
+}
rtdm/driver-api/Makefile +47 -9

86 lines not on this page · raw message

#6 lore raw

Re: [Xenomai-core] PPC405: DMA-problem solved!

In reply to Wolfgang Grandegger
Quoted 7 lines · Wolfgang Grandegger
Quoted 5 lines

In any case, we need to resolve the arch dependency somehow. I guess it will currently not fly when I kick the full build in examples/ for a non-PPC platform. Any *simple* way to catch this? Would also be applicable to the heartbeat-x86 example then, though this will not cause build troubles.

The only simple way I see is referencing the configured kernel tree.

Sourcing $KSRC/.config into the makefile and evaluating the ARCH? Would save us from passing ARCH on make invocation...

...

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +11 -0
+    int res = 0;
+    memset((char *)&p_init, sizeof(p_init), 0);
+    p_init.polarity = 0;
+    p_init.pwidth   = PW_8;
+     res = ppc4xx_init_dma_channel(DMA_NR, &p_init);
+    if (res) {
+        printk("%32s: nit_dma_channel return %d %d bytes dest %p\n",
+            __FUNCTION__, res, length, dst);
+    }
+    res = ppc4xx_clr_dma_status(DMA_NR);
+    if (res) { +        printk("%32s: ppc4xx_clr_dma_status %d\n",

__FUNCTION__, res);

(quoted diff) +2 -0
+    }
+#warning flush_dcache_all is a performance killer, but I do not know

at the +#warning moment how to flush only the parts needed

Quoted 5 lines
Quoted 1 line

Can we resolve this? Wolfgang?

flush_dcache_range should do the job. Or even better use the DMA-API described in Documentation/DMA-API.txt to get DMA'able memory (as pointed out recently on the linuxppc-emmbedded ML).

I definitely prefer to have a tested variant here that is as little invasive as possible. This is "educational" code, so we should not spread suboptimal patterns.

Quoted 7 lines
Quoted 5 lines

rtdm/pp4xx_interrupt/dma_4xx_int_module.c line 167

Quoted 5 lines
rtdm/pp4xx_interrupt/dma_4xx_int_module.c +5 -0
+    if (rtdm_irq_free (&irq_handle)) {
+        printk("%32s: rtdm_irq_free failed\n",__FUNCTION__);
+    }
+    show_irq(irq);
+}

And should we not also use rtdm_prinkt()?

Not strictly required here, we are in non-rt context.

Jan