an overview of the dmaengine subsystem€¦ · i dma_pause i pause a given channel i dma_resume i...

29
Embedded Linux Conference 2015 An Overview of the DMAEngine Subsystem Maxime Ripard [email protected] Copyright 2004-2018, Bootlin. Creative Commons BY-SA 3.0 license. Corrections, suggestions, contributions and translations are welcome! embedded Linux and kernel engineering - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/1

Upload: others

Post on 27-May-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Embedded Linux Conference 2015

An Overview ofthe DMAEngineSubsystemMaxime [email protected]

© Copyright 2004-2018, Bootlin.

Creative Commons BY-SA 3.0 license.

Corrections, suggestions, contributions and translations are welcome!

embedded Linux and kernel engineering

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/1

Page 2: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Maxime Ripard

I Embedded Linux engineer and trainer at BootlinI Embedded Linux development: kernel and driver

development, system integration, boot time and powerconsumption optimization, consulting, etc.

I Embedded Linux training, Linux driver development trainingand Android system development training, with materialsfreely available under a Creative Commons license.

I http://bootlin.com

I ContributionsI Kernel support for the sunXi SoCs from AllwinnerI Contributor to few open-source projects, Buildroot, an

open-source, simple and fast embedded Linux build system,Barebox, a modern bootloader.

I Living in Toulouse, south west of France

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/1

Page 3: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

An Overview of the DMAEngine Subsystem

Introduction

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/1

Page 4: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Device DMA vs...

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/1

Page 5: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

... DMA Controllers

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/1

Page 6: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Transfer Width

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/1

Page 7: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Burst Size

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1

Page 8: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Scatter Gather

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/1

Page 9: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Scatter Gather Descriptors

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/1

Page 10: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Cyclic Transfers

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/1

Page 11: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Realistic DMA Controller

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/1

Page 12: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

An Overview of the DMAEngine Subsystem

Linux Support

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/1

Page 13: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

APIs

I DMAEngineI Merged in 2006, in 2.6.18I Subsystem to handle memory-to-device transfers

I Async TXI Merged in 2007, in 2.6.23I Initially part of the raid5 code to support the XScale offload

enginesI 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.

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 13/1

Page 14: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Slave consumer API

1. Request a channel: dma_request_channel, or one of itsvariants

2. Configure the channel for our use: dmaengine_slave_config

3. Get a transaction descriptor for our transfer:dmaengine_prep_*

4. Put the transaction in the driver pending queue:dmaengine_submit

5. Issue pending requests (blocks and calls back your driver togive an update on the transfer status):dmaengine_issue_pending

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/1

Page 15: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

An Overview of the DMAEngine Subsystem

Slave Controller Drivers

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/1

Page 16: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

struct dma_device and its Fields

I DMAEngine, like any framework, relies on a structure youhave to fill with various pieces of information in order to do itsjob properly.

I Mostly:

channels Initialized list of the channels supported by thedriver, of the size of the number of channelssupported by your driver

* align Alignment in bytes for the Async TX buffers

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/1

Page 17: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

DMA Transfer Types 1/2

I The next step is to set which transfer types your driversupports

I This is done through the function dma_cap_set, which takesvarious flags as an argument:I DMA_MEMCPY

I Memory to memory copy

I DMA_SGI Memory to memory scatter gather

I DMA_INTERLEAVEI Memory to memory interleaved transfer

I DMA_XORI Memory to memory XOR

I DMA_XOR_VALI Memory buffer parity check using XOR

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/1

Page 18: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

DMA Transfer Types 2/2

I DMA_PQI Memory to memory P+Q computation

I DMA_PQ_VALI Memory buffer parity check using P+Q

I DMA_INTERRUPTI The device is able to generate a dummy transfer that will

generate interrupts

I DMA_SLAVEI Memory to device transfers

I DMA_CYCLICI The device is able to handle cyclic transfers

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/1

Page 19: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Weird Transfer Types

I DMA_PRIVATEI 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_TXI Set by the core when you support all Async TX transfer typesI Used only if ASYNC_TX_ENABLE_CHANNEL_SWITCH is enabledI Used by dma_find_channel, which is a non-exclusive

equivalent of dma_request_channel, used only by Async TX

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/1

Page 20: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Channels Resources Allocation

I device_alloc_chan_resources anddevice_free_chan_resources

I Called by the framework when your channel is first requested

I Allows to allocate custom resources for your channel, and freethem when you’re done

I Optional (since 3.20)

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/1

Page 21: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

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 andclients to identify the transfer, and the hardware descriptormatching it for the dma controller.

I Should also ensure that the parameters of this transfer matchwhat the driver supports

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/1

Page 22: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

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 theclient using an optional callback of the status of the transfer

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/1

Page 23: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

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 returnsonly a flag saying whether it’s done or in progress.

I This is where the granularity we used earlier comes into action.

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/1

Page 24: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Channel configuration

I device_control

I Takes an additional flag, to give the type of control to do onthe channelI DMA_PAUSE

I Pause a given channel

I DMA_RESUMEI Resume a given channel

I DMA_TERMINATE_ALLI Aborts all transfers on a given channel

I DMA_SLAVE_CONFIGI Configures a given channel with new parameters

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/1

Page 25: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Capabilities

I device_slave_caps

I Returns various pieces of information about the controllerI 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 devicethey’re going to use is capable of (only ASoC so far)

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/1

Page 26: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

An Overview of the DMAEngine Subsystem

Recent Developments

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/1

Page 27: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Generic Capabilities (3.20)

I Removal of device_slave_caps, and moved the logic in theframework

I Introduction of new variables in struct dma_device

* width Bitmask of supported transfer width, both assource and destination

directions Bitmask of the supported slave directions(memory to device, device to memory, device todevice)

granularity Granularity of the transfer residue your controllercan provide: bursts, chunks or descriptors

I Split of the device_control function in four independentfunctions: device_config, device_pause, device_resume,device_terminate_all

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 27/1

Page 28: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Scheduled DMA

I Many DMA controllers have more requests than channels

I These drivers usually have all the scheduling code

I Plus, every driver has a lot of administrative code, that is nottrivial to get right (callback deferral, allocation of thedescriptors, etc.), yet similar from one driver to another

I Scheduled DMA framework abstracts away most of it, andonly a few things remain in the drivers:I Interrupt managementI LLI related functions (iterators, configuration, etc.)I Scheduling hintsI Channel management (pause, resume, residues, etc.)

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/1

Page 29: An Overview of the DMAEngine Subsystem€¦ · I DMA_PAUSE I Pause a given channel I DMA_RESUME I Resume a given channel I DMA_TERMINATE_ALL I Aborts all transfers on a given channel

Questions? Suggestions?Comments?

Maxime [email protected]

Slides under CC-BY-SA 3.0http://bootlin.com/pub/conferences/2015/elc/ripard-dmaengine

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 29/1