When I first came into contact with DMA, it was my junior computer principle. At that time, I was not very familiar with what DMA mode. I only knew it was a fast transmission speed without going through the CPU, but what is it like without going through the CPU? Still do not understand. This time, the I2C controller has the DMA mode, so you have the opportunity to get in touch with it.
What does DMA mean? http://baike.baidu.com/view/32471.htm. it's still true.
DMA working process:
The DMA in the embedded system is replaced by the DMA transmission when writing data registers. Like I2C devices, data is written to the data register when sending and receiving data. For example, if the register is i2c_data, It is writel (data, i2c_data) if the CPU is used for transmission. When DMA transmission is used, the length of the Buf to be transmitted is configured, and the source address is the address of the Buf, the destination address is i2c_data.
Note that the CPU is a virtual address, while the DMA is a physical address.
In fact, DMA transmission controls data transmission between two physical addresses.
In Linux, DMA transmission is used to call the following functions to implement external DMA.
For details, refer to the following simple explanation. The following is mainly about DMA transmission, and the same is true for receiving. Configure it.
1. initialize DMA
Dma_cap_zero (mask); dma_cap_set (dma_slave, mask);/* 1. init RX channel */DWS-> rxchan = dma_request_channel (mask, dma_chan_filter, Params); it mainly applies for DMA channels. The dma_chan_filter function is mainly used to find the request signal line of your DMA transmission device, which is entered at registration. The DMA slave that has been registered on the bus will be judged based on the true and false returned by this function. Buf = kmalloc (dma_buffer_size, gfp_kernel); // apply for an address. The data used for DMA transmission is placed here sg_init_one (& dma_dev-> dmatx. SG, Buf, dma_buffer_size); // initialization, mainly for the ing between the virtual address and the physical address during sending.
2. Start DMA
Struct dma_async_tx_descriptor * txdesc = NULL; struct dma_chan * txchan,; struct dma_slave_config txconf; txchan = DWS-> txchan;/* 2. prepare the Tx DMA transfer */txconf. direction = dma_to_device; // indicates that the DMA transmission direction is txconf. dst_addr = DWS-> dma_addr; // target address, physical address txconf. dst_maxburst = lnw_dma_msize_16; // maximum number of transmitted bytes txconf. dst_addr_width = dma_slave_buswidth_2_bytes; // The data Bit Width. txchan-> device-> device_control (txchan, Dma_slave_config, (unsigned long) & txconf); DWS-> tx_sgl.length = DWS-> Len; // The length of the data to be transmitted dma_map_sg (dma_dev-> Dev, & dmatx-> SG, 1, dma_to_device); // use this function to map virtual addresses to physical addresses. Txdesc = txchan-> device-> device_prep_slave_sg (txchan, & DWS-> tx_sgl, 1, dma_to_device, dma_prep_interrupt | callback); txdesc-> callback = callback; // The callback function txdesc-> callback_param = Params after transmission is complete; // The parameter dmaengine_submit (txdesc) in the callback function; dma_dev-> device_issue_pending (txchan); // start the DMA Transmission
After the configuration, the DMA will start to be transmitted. After the transmission is complete, the callback function will be called.