Streaming DMA Mappings

Streaming DMA mappings are an interface to the hardware that enables the processor to access a buffer that has been allocated for a single DMA operation. This interface is more complex than coherent mappings and requires the processor to call functions in order to access the buffer. Some platforms also require the processor to flush its write buffers when using a streaming mapping.

The interface to a streaming mapping can be divided into two parts: the DMA interface and the streaming DMA mapping routines. The DMA interface allows the driver to write data to the buffer, while the streaming DMA mapping routines ensure that the buffer is synchronized with the streaming mapping.

The DMA interface uses a new type of dma_addr_t to represent a bus address. This new type is created by the DMA subsystem and can be used to perform DMA operations. However, it should be treated as opaque by the driver, and its use should be limited to DMA support functions. If it is used by the CPU directly, it may cause unexpected problems.

The DMA interface can be used with any bus. However, in order to ensure that DMA addresses are mapped only when needed, it is recommended to use the DMA API instead of the bus-specific DMA API. In addition, the DMA layer ensures that the correct behavior is achieved on all architectures.

Streaming DMA mapping routines can be called from an interrupt context. These routines can be implemented as a series of “scatter/gather” buffers, or in a single operation. If the buffer is being mapped for the first time, the driver must ensure that all data in the buffer has been written to memory. During the mapping, the driver must not touch the contents of the buffer. This can be done by calling dma_map_single and dma_unmap_single. Both functions should use the same sg_dma_address. The function should return the number of DMA buffers passed to it. If the function returns NULL, something went wrong.

The DMA subsystem can allocate a scatter-list of struct page pointers. These struct page pointers are used to allocate the buffer in the scatter-list. During the scatter/gather operation, each struct page pointer corresponds to one buffer in the scatter-list. When the driver allocates a scatter-list, the driver can use the scatter-list to copy the buffer to the user and to unmap the buffer.

Streaming DMA mapping routines are a bit more complicated than coherent mapping routines, but they also allow more optimizations. The kernel recommends using streaming DMA mappings instead of coherent mappings. This is because streaming DMA mappings are outside of the coherency domain. This means that the data is not aligned to the underlying bus, and that the data can be scattered across the physical RAM in different locations. It also means that the driver cannot access the buffer until the DMA activity is complete. This can cause problems in cases where the processor is not coherent, such as in a system with a cache that does not support coherent DMA.