An Overview of The Dmaengine Subsystem: Free Electrons
An Overview of The Dmaengine Subsystem: Free Electrons
An Overview of The Dmaengine Subsystem: Free Electrons
An Overview of
the DMAEngine Free Electrons
Maxime Ripard
Free Electrons
[email protected]
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 1/29
Maxime Ripard
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 2/29
An Overview of the DMAEngine Subsystem
Introduction
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 3/29
Peripheral DMA vs...
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 4/29
... DMA Controllers
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 5/29
Transfer Width
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 6/29
Burst Size
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 7/29
Scatter Gather
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 8/29
Scatter Gather Descriptors
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 9/29
Cyclic Transfers
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 10/29
Realistic DMA Controller
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 11/29
An Overview of the DMAEngine Subsystem
Linux Support
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 12/29
APIs
I DMAEngine
I Merged in 2006, in 2.6.18
I Subsystem to handle memory-to-device transfers
I Async TX
I Merged in 2007, in 2.6.23
I Initially part of the raid5 code to support the XScale offload
engines
I Subsystem to handle memory to memory operations (memcpy,
XOR, etc.)
I Implemented on top of dmaengine, but takes many shortcuts,
instead of being a real client.
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 13/29
Slave consumer API
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 14/29
An Overview of the DMAEngine Subsystem
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 15/29
struct dma_device and its Fields
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 16/29
DMA Transfer Types 1/2
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 17/29
DMA Transfer Types 2/2
I DMA_PQ
I Memory to memory P+Q computation
I DMA_PQ_VAL
I Memory buffer parity check using P+Q
I DMA_INTERRUPT
I The device is able to generate a dummy transfer that will
generate interrupts
I DMA_SLAVE
I Memory to device transfers
I DMA_CYCLIC
I The device is able to handle cyclic transfers
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 18/29
Weird Transfer Types
I DMA_PRIVATE
I Async TX doesn’t go through dma_request_channel but
circumvents it, and just starts using any random channel it can
I It does so unless you set this flag
I DMA_ASYNC_TX
I Set by the core when you support all Async TX transfer types
I Used only if ASYNC_TX_ENABLE_CHANNEL_SWITCH is enabled
I Used by dma_find_channel, which is a non-exclusive
equivalent of dma_request_channel, used only by Async TX
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 19/29
Channels Resources Allocation
I device_alloc_chan_resources and
device_free_chan_resources
I Called by the framework when your channel is first requested
I Allows to allocate custom resources for your channel, and free
them when you’re done
I Optional (since 3.20)
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 20/29
Transaction Descriptor Retrieval Functions
I device_prep_dma_*
I Optional, but have to match the transfer types you declared
I Should create both the software descriptor, for Linux and
clients to identify the transfer, and the hardware descriptor
matching it for the dma controller
I Should also ensure that the parameters of this transfer match
what the driver supports
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 21/29
Submitting Pending Jobs
I device_issue_pending
I Should take the first descriptor of the transaction and start it
I Should go through all the descriptors in the list, notifying the
client using an optional callback that the transfer is done
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 22/29
Transfer Status Reporting
I device_tx_status
I Reports the current state of a given transaction descriptor
I Does so using the dma_set_residue function, and returns
only a flag saying whether it’s done or in progress
I This is where the granularity we used earlier comes into action.
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 23/29
Channel configuration
I device_control
I Takes an additional flag, that represents the action to perform
on the channel
I DMA_PAUSE
I Pauses a given channel
I DMA_RESUME
I Resumes a given channel
I DMA_TERMINATE_ALL
I Aborts all transfers on a given channel
I DMA_SLAVE_CONFIG
I Configures a given channel with new parameters
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 24/29
Capabilities
I device_slave_caps
I Returns various pieces of information about the controller
I Can the transfer be paused? terminated?
I Which transfer widths are supported?
I Which slave directions are supported?
I Used by generic layers to get an idea of what the device
they’re going to use is capable of (only ASoC so far)
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 25/29
An Overview of the DMAEngine Subsystem
Recent Developments
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 26/29
Generic Capabilities (4.0)
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 27/29
Scheduled DMA
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 28/29
Questions?
Maxime Ripard
[email protected]
Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com 29/29