Putting it all together – Single-buffer DMA mapping
Let's consider the following case where we would like to map a single buffer (streaming mapping) and DMA data from the source, src
, to the destination, dst
. We will use a character device so that any write operation in this device will trig the DMA and any read operation will compare both the source and destination to check whether they match.
First, let's enumerate the header files required to pull the necessary APIs:
#define pr_fmt(fmt) "DMA-TEST: " fmt #include <linux/module.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/dma-mapping.h> #include <linux/fs.h> #include <linux/dmaengine.h> #include <linux/device.h> #include <linux/io.h> #include <linux/delay.h>
Let's now define some global variables for the driver:
/* we need page aligned buffers */ #define DMA_BUF_SIZE 2 * PAGE_SIZE static u32 *wbuf; static...