mpc5200: Add RTDM LPBFIFO driver and demo RTDM FPGA device driver
PATCH 1/1 mpc5200: Add RTDM LPBFIFO driver and demo RTDM FPGA device driver
From: Stefan Roese <[email protected]>
This patch adds support for the RTDM LPB (LocalPlusBus) FIFO driver for the MPC5200. It will be used for DMA support in an RTDM FPGA device driver. This rt-fpga.c driver is a custom device driver, but might be useful for other developers as well. Thats why I included it here too.
The lpb-fifo driver is ported from the Linux kernel lpb-fifo driver:
arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
With all locking etc changed from Linux call to Xenomai/RTDM calls.
--- ksrc/drivers/Config.in | 1 + ksrc/drivers/Kconfig | 1 + ksrc/drivers/Makefile | 6 +- ksrc/drivers/mpc5200_dma/Config.in | 10 + ksrc/drivers/mpc5200_dma/Kconfig | 10 + ksrc/drivers/mpc5200_dma/Makefile | 31 ++ ksrc/drivers/mpc5200_dma/rt-fpga.c | 701 ++++++++++++++++++++++++++ ksrc/drivers/mpc5200_dma/rt-fpga.h | 35 ++ ksrc/drivers/mpc5200_dma/rt_mpc52xx_lpbfifo.c | 569 +++++++++++++++++++++ scripts/Modules.frag | 3 +- 10 files changed, 1364 insertions(+), 3 deletions(-) create mode 100644 ksrc/drivers/mpc5200_dma/Config.in create mode 100644 ksrc/drivers/mpc5200_dma/Kconfig create mode 100644 ksrc/drivers/mpc5200_dma/Makefile create mode 100644 ksrc/drivers/mpc5200_dma/rt-fpga.c create mode 100644 ksrc/drivers/mpc5200_dma/rt-fpga.h create mode 100644 ksrc/drivers/mpc5200_dma/rt_mpc52xx_lpbfifo.c
ksrc/drivers/Config.in +1 -0
@@ -12,5 +12,6 @@ comment 'Drivers' source drivers/xenomai/can/Config.in source drivers/xenomai/analogy/Config.in source drivers/xenomai/ipc/Config.in + source drivers/xenomai/mpc5200_dma/Config.in endmenu fi
ksrc/drivers/Kconfig +1 -0
@@ -7,5 +7,6 @@ source "drivers/xenomai/testing/Kconfig" source "drivers/xenomai/can/Kconfig" source "drivers/xenomai/analogy/Kconfig" source "drivers/xenomai/ipc/Kconfig" +source "drivers/xenomai/mpc5200_dma/Kconfig" endmenu
ksrc/drivers/Makefile +4 -2
@@ -2,13 +2,13 @@ ifneq ($(VERSION).$(PATCHLEVEL),2.4) # Makefile frag for Linux v2.6 and v3.x -obj-$(CONFIG_XENOMAI) += serial/ testing/ can/ analogy/ ipc/ +obj-$(CONFIG_XENOMAI) += serial/ testing/ can/ analogy/ ipc/ mpc5200_dma/ else # Makefile frag for Linux v2.4 -mod-subdirs := serial testing can analogy ipc +mod-subdirs := serial testing can analogy ipc mpc5200_dma subdir-$(CONFIG_XENO_DRIVERS_16550A) += serial
@@ -20,6 +20,8 @@ subdir-$(CONFIG_XENO_DRIVERS_CAN) += can subdir-$(CONFIG_XENO_DRIVERS_ANALOGY) += analogy subdir-$(CONFIG_XENO_DRIVERS_MPIPE) += ipc +subdir-$(CONFIG_XENO_DRIVERS_MPC5200_DMA) += mpc5200_dma + include $(TOPDIR)/Rules.make endif
ksrc/drivers/mpc5200_dma/Config.in new file +10 -0
@@ -0,0 +1,10 @@ +# +# Xenomai configuration for Linux v2.4 +# + +mainmenu_option next_comment +comment 'MPC5200 DMA drivers' + +dep_tristate 'MPC5200 DMA FPGA driver' CONFIG_XENO_DRIVERS_MPC5200_DMA $CONFIG_XENO_SKIN_RTDM + +endmenu
ksrc/drivers/mpc5200_dma/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +menu "MPC5200 DMA drivers" + +config XENO_DRIVERS_MPC5200_DMA + depends on XENO_SKIN_RTDM && PPC_MPC52xx && PPC_MPC5200_LPBFIFO + tristate "MPC5200 DMA based driver to receive data from an FPGA" + help + This is a driver to demonstrate the usage of the RTDM DMA + infrastructure on the MPC5200. + +endmenu
ksrc/drivers/mpc5200_dma/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +ifneq ($(VERSION).$(PATCHLEVEL),2.4) + +# Makefile frag for Linux v2.6 and v3.x + +EXTRA_CFLAGS += -D__IN_XENOMAI__ -Iinclude/xenomai + +obj-$(CONFIG_XENO_DRIVERS_MPC5200_DMA) += xeno_rt-fpga.o xeno_rt_mpc52xx_lpbfifo.o + +xeno_rt-fpga-y := rt-fpga.o +xeno_rt_mpc52xx_lpbfifo-y := rt_mpc52xx_lpbfifo.o + +else + +# Makefile frag for Linux v2.4 + +O_TARGET := built-in.o + +obj-$(CONFIG_XENO_DRIVERS_MPC5200_DMA) += xeno_rt-fpga.o xeno_rt_mpc52xx_lpbfifo.o + +xeno_mpc5200_dma-objs := rt-fpga.o rt_mpc52xx_lpbfifo.o + +export-objs := $(xeno_mpc5200_dma-objs) + +EXTRA_CFLAGS += -D__IN_XENOMAI__ -I$(TOPDIR)/include/xenomai -I$(TOPDIR)/include/xenomai/compat + +include $(TOPDIR)/Rules.make + +xeno_mpc5200_dma.o: $(xeno_mpc5200_dma-objs) + $(LD) -r -o $@ $(xeno_mpc5200_dma-objs) + +endif
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +701 -0
701 lines not on this page · raw message
ksrc/drivers/mpc5200_dma/rt-fpga.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Xenomai RTDM device driver for A3M071 FPGA with interrupt support +* +* Copyright (C) 2012 Stefan Roese <[email protected]> +*/ + +#ifndef _RT_FPGA_H +#define _RT_FPGA_H + +/* +* IOCTL's for this FPGA driver +*/ +#define RTIOC_TYPE_TESTING RTDM_CLASS_TESTING +#define FPGA_CONFIG \ + _IOW(RTIOC_TYPE_TESTING, 0x00, struct fpga_rw_data) +#define FPGA_READ_WORD \ + _IOR(RTIOC_TYPE_TESTING, 0x01, struct fpga_rw_data) +#define FPGA_WRITE_WORD \ + _IOW(RTIOC_TYPE_TESTING, 0x02, struct fpga_rw_data) +#define FPGA_SET_TIMEOUT \ + _IOW(RTIOC_TYPE_TESTING, 0x03, struct fpga_rw_data) +#define FPGA_GET_CYCLES_MISSED \ + _IOR(RTIOC_TYPE_TESTING, 0x04, struct fpga_rw_data) + +struct fpga_rw_data { +unsigned int offset; +unsigned short value; +unsigned int count; +unsigned int write_offset; +unsigned int write_count; +unsigned int timeout; +int cycles_missed; +}; + +#endif
ksrc/drivers/mpc5200_dma/rt_mpc52xx_lpbfifo.c new file +569 -0
569 lines not on this page · raw message
scripts/Modules.frag +2 -1
@@ -21,4 +21,5 @@ DRIVERS-$(CONFIG_XENO_DRIVERS_CAN_SJA1000_PEAK_PCI) += drivers/xenomai/can/sja10 DRIVERS-$(CONFIG_XENO_DRIVERS_CAN_SJA1000_PEAK_DNG) += drivers/xenomai/can/sja1000/xeno_can_peak_dng.o DRIVERS-$(CONFIG_XENO_DRIVERS_CAN_SJA1000_IXXAT_PCI) += drivers/xenomai/can/sja1000/xeno_can_ixxat_pci.o DRIVERS-$(CONFIG_XENO_DRIVERS_CAN_SJA1000_EMS_PCI) += drivers/xenomai/can/sja1000/xeno_can_ems_pci.o - +DRIVERS-$(CONFIG_XENO_DRIVERS_MPC5200_DMA) += drivers/xenomai/mpc5200_dma/rt-fpga.o +DRIVERS-$(CONFIG_XENO_DRIVERS_MPC5200_DMA) += drivers/xenomai/mpc5200_dma/rt_mpc52xx_lpbfifo.o
Signature · 1 line
1.8.0
Quoted 21 lines · On 11/15/2012 03:19 PM, [email protected] wrote:
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +21
-0+/* +* NO_DMA: +* +* Define to enable memcpy() for blockdata transfer instead of DMA +* support. This is available only for test purposes. Should be disabled +* or even removed in the final driver version. +*/ +#if 0 +#define NO_DMA +#endif + +/* +* PRINT_READ_TIME: +* +* Print min and max times consumed by the blockdata transfer, either +* per DMA or per memcpy. Should be disbaled or even removed in the +* final driver version. +*/ +#if 1 +#define PRINT_READ_TIME +#endif
ksrc/drivers/mpc5200_dma/rt-fpga.c line 72
Quoted 10 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +10
-0+ +/* +* DEBUG: +* +* Define to print debug informations. Should be disabled in the +* final driver of course. +*/ +#if 0 +#define DEBUG +#endif
This is dead code, please use Kconfig or remove the dead code entirely.
Quoted 4 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +4
-0+/* +* Block until the blockdata is completely read into +* the buffer (done in interrupt) +*/
ksrc/drivers/mpc5200_dma/rt-fpga.c line 495
Quoted 10 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +10
-0+ ret =rtdm_event_timedwait (&fpga_ctx->read_event, + fpga_ctx->info->timeout,NULL ); + +/* +* Mark blockdata as read +*/ + fpga_ctx->blockdata_ready =0 ; + +if (ret) +return ret;
You set blockdata_ready whatever the return value of rtdm_event_timedwait so, what if rtdm_event_timedwait fails? and you do it without any kind of mutual exclusion, so, what if another thread or an irq is doing something between the call to rtdm_event_timedwait and the moment where that variable is set to 0?
Signature · 1 line
Gilles.
Hi Gilles,
Quoted 26 lines · Gilles Chanteperdrix
Quoted 25 lines · On 11/15/2012 03:19 PM, [email protected] wrote:
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +25
-0+/* +* NO_DMA: +* +* Define to enable memcpy() for blockdata transfer instead of DMA +* support. This is available only for test purposes. Should be disabled +* or even removed in the final driver version. +*/ +#if 0 +#define NO_DMA +#endif + +/* +* PRINT_READ_TIME: +* +* Print min and max times consumed by the blockdata transfer, either +* per DMA or per memcpy. Should be disbaled or even removed in the +* final driver version. +*/ +#if 1 +#define PRINT_READ_TIME +#endif + +/* +* DEBUG: +*
Quoted 8 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c line 72
Quoted 6 lines
+ * Define to print debug informations. Should be disabled in the
+ * final driver of course.
+ */ksrc/drivers/mpc5200_dma/rt-fpga.c new file +3
-0+#if 0 +#define DEBUG +#endif This is dead code, please use
Kconfigor remove the dead code entirely.
Yes. Will move to Kconfig option.
Quoted 9 lines
Quoted 9 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +9
-0+/* +* Block until the blockdata is completely read into +* the buffer (done in interrupt) +*/ + ret =rtdm_event_timedwait (&fpga_ctx->read_event, + fpga_ctx->info->timeout,NULL ); + +/* +* Mark blockdata as read
Quoted 8 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c line 310
Quoted 5 lines
ksrc/drivers/mpc5200_dma/rt-fpga.c new file +5
-0+*/ + fpga_ctx->blockdata_ready =0 ; + +if (ret) +return ret;You set
blockdata_readywhatever the return value ofrtdm_event_timedwaitso, what ifrtdm_event_timedwaitfails?
Even when rtdm_event_timedwait() fails (timeout) the blockdata_ready flag needs to be reset. As it marks the last read access from the application (task) to be finished. So re-setting it to 0 even in the timeout case was done intentionally here.
Quoted 3 lines
and you do it without any kind of mutual exclusion, so, what if another thread or an irq is doing something between the call to
rtdm_event_timedwaitand the moment where that variable is set to 0?
Only one thread can access the read function at a time (synchronized with ctx->reading). So there can be no clashes with other read-threads here. And the interrupt shall set the blockdata_ready flag upon the cycle data interrupt. To signal new data ready for reading. So I don't see where some synchronization method is needed here.
Thanks for the review,
Stefan