xref: /linux/Documentation/sound/designs/compress-accel.rst (revision c771600c6af14749609b49565ffb4cac2959710d)
104177158SJaroslav Kysela==================================
204177158SJaroslav KyselaALSA Co-processor Acceleration API
304177158SJaroslav Kysela==================================
404177158SJaroslav Kysela
504177158SJaroslav KyselaJaroslav Kysela <perex@perex.cz>
604177158SJaroslav Kysela
704177158SJaroslav Kysela
804177158SJaroslav KyselaOverview
904177158SJaroslav Kysela========
1004177158SJaroslav Kysela
1104177158SJaroslav KyselaThere is a requirement to expose the audio hardware that accelerates various
1204177158SJaroslav Kyselatasks for user space such as sample rate converters, compressed
1304177158SJaroslav Kyselastream decoders, etc.
1404177158SJaroslav Kysela
1504177158SJaroslav KyselaThis is description for the API extension for the compress ALSA API which
1604177158SJaroslav Kyselais able to handle "tasks" that are not bound to real-time operations
1704177158SJaroslav Kyselaand allows for the serialization of operations.
1804177158SJaroslav Kysela
1904177158SJaroslav KyselaRequirements
2004177158SJaroslav Kysela============
2104177158SJaroslav Kysela
2204177158SJaroslav KyselaThe main requirements are:
2304177158SJaroslav Kysela
2404177158SJaroslav Kysela- serialization of multiple tasks for user space to allow multiple
2504177158SJaroslav Kysela  operations without user space intervention
2604177158SJaroslav Kysela
2704177158SJaroslav Kysela- separate buffers (input + output) for each operation
2804177158SJaroslav Kysela
2904177158SJaroslav Kysela- expose buffers using mmap to user space
3004177158SJaroslav Kysela
3104177158SJaroslav Kysela- signal user space when the task is finished (standard poll mechanism)
3204177158SJaroslav Kysela
3304177158SJaroslav KyselaDesign
3404177158SJaroslav Kysela======
3504177158SJaroslav Kysela
3604177158SJaroslav KyselaA new direction SND_COMPRESS_ACCEL is introduced to identify
3704177158SJaroslav Kyselathe passthrough API.
3804177158SJaroslav Kysela
3904177158SJaroslav KyselaThe API extension shares device enumeration and parameters handling from
4004177158SJaroslav Kyselathe main compressed API. All other realtime streaming ioctls are deactivated
4104177158SJaroslav Kyselaand a new set of task related ioctls are introduced. The standard
4204177158SJaroslav Kyselaread/write/mmap I/O operations are not supported in the passthrough device.
4304177158SJaroslav Kysela
4404177158SJaroslav KyselaDevice ("stream") state handling is reduced to OPEN/SETUP. All other
4504177158SJaroslav Kyselastates are not available for the passthrough mode.
4604177158SJaroslav Kysela
4704177158SJaroslav KyselaData I/O mechanism is using standard dma-buf interface with all advantages
4804177158SJaroslav Kyselalike mmap, standard I/O, buffer sharing etc. One buffer is used for the
4904177158SJaroslav Kyselainput data and second (separate) buffer is used for the output data. Each task
5004177158SJaroslav Kyselahave separate I/O buffers.
5104177158SJaroslav Kysela
5204177158SJaroslav KyselaFor the buffering parameters, the fragments means a limit of allocated tasks
5304177158SJaroslav Kyselafor given device. The fragment_size limits the input buffer size for the given
5404177158SJaroslav Kyseladevice. The output buffer size is determined by the driver (may be different
5504177158SJaroslav Kyselafrom the input buffer size).
5604177158SJaroslav Kysela
5704177158SJaroslav KyselaState Machine
5804177158SJaroslav Kysela=============
5904177158SJaroslav Kysela
60*f42eb493SBagas SanjayaThe passthrough audio stream state machine is described below::
6104177158SJaroslav Kysela
6204177158SJaroslav Kysela                                       +----------+
6304177158SJaroslav Kysela                                       |          |
6404177158SJaroslav Kysela                                       |   OPEN   |
6504177158SJaroslav Kysela                                       |          |
6604177158SJaroslav Kysela                                       +----------+
6704177158SJaroslav Kysela                                             |
6804177158SJaroslav Kysela                                             |
6904177158SJaroslav Kysela                                             | compr_set_params()
7004177158SJaroslav Kysela                                             |
7104177158SJaroslav Kysela                                             v
7204177158SJaroslav Kysela         all passthrough task ops      +----------+
7304177158SJaroslav Kysela  +------------------------------------|          |
7404177158SJaroslav Kysela  |                                    |   SETUP  |
7504177158SJaroslav Kysela  |                                    |
7604177158SJaroslav Kysela  |                                    +----------+
7704177158SJaroslav Kysela  |                                          |
7804177158SJaroslav Kysela  +------------------------------------------+
7904177158SJaroslav Kysela
8004177158SJaroslav Kysela
8104177158SJaroslav KyselaPassthrough operations (ioctls)
8204177158SJaroslav Kysela===============================
8304177158SJaroslav Kysela
8404177158SJaroslav KyselaAll operations are protected using stream->device->lock (mutex).
8504177158SJaroslav Kysela
8604177158SJaroslav KyselaCREATE
8704177158SJaroslav Kysela------
8804177158SJaroslav KyselaCreates a set of input/output buffers. The input buffer size is
8904177158SJaroslav Kyselafragment_size. Allocates unique seqno.
9004177158SJaroslav Kysela
9104177158SJaroslav KyselaThe hardware drivers allocate internal 'struct dma_buf' for both input and
9204177158SJaroslav Kyselaoutput buffers (using 'dma_buf_export()' function). The anonymous
9304177158SJaroslav Kyselafile descriptors for those buffers are passed to user space.
9404177158SJaroslav Kysela
9504177158SJaroslav KyselaFREE
9604177158SJaroslav Kysela----
9704177158SJaroslav KyselaFree a set of input/output buffers. If a task is active, the stop
9804177158SJaroslav Kyselaoperation is executed before. If seqno is zero, operation is executed for all
9904177158SJaroslav Kyselatasks.
10004177158SJaroslav Kysela
10104177158SJaroslav KyselaSTART
10204177158SJaroslav Kysela-----
10304177158SJaroslav KyselaStarts (queues) a task. There are two cases of the task start - right after
10404177158SJaroslav Kyselathe task is created. In this case, origin_seqno must be zero.
10504177158SJaroslav KyselaThe second case is for reusing of already finished task. The origin_seqno
10604177158SJaroslav Kyselamust identify the task to be reused. In both cases, a new seqno value
10704177158SJaroslav Kyselais allocated and returned to user space.
10804177158SJaroslav Kysela
10904177158SJaroslav KyselaThe prerequisite is that application filled input dma buffer with
11004177158SJaroslav Kyselanew source data and set input_size to pass the real data size to the driver.
11104177158SJaroslav Kysela
11204177158SJaroslav KyselaThe order of data processing is preserved (first started job must be
11304177158SJaroslav Kyselafinished at first).
11404177158SJaroslav Kysela
11504177158SJaroslav KyselaIf the multiple tasks require a state handling (e.g. resampling operation),
11604177158SJaroslav Kyselathe user space may set SND_COMPRESS_TFLG_NEW_STREAM flag to mark the
11704177158SJaroslav Kyselastart of the new stream data. It is useful to keep the allocated buffers
11804177158SJaroslav Kyselafor the new operation rather using open/close mechanism.
11904177158SJaroslav Kysela
12004177158SJaroslav KyselaSTOP
12104177158SJaroslav Kysela----
12204177158SJaroslav KyselaStop (dequeues) a task. If seqno is zero, operation is executed for all
12304177158SJaroslav Kyselatasks.
12404177158SJaroslav Kysela
12504177158SJaroslav KyselaSTATUS
12604177158SJaroslav Kysela------
12704177158SJaroslav KyselaObtain the task status (active, finished). Also, the driver will set
12804177158SJaroslav Kyselathe real output data size (valid area in the output buffer).
12904177158SJaroslav Kysela
13004177158SJaroslav KyselaCredits
13104177158SJaroslav Kysela=======
13204177158SJaroslav Kysela- Shengjiu Wang <shengjiu.wang@gmail.com>
13304177158SJaroslav Kysela- Takashi Iwai <tiwai@suse.de>
13404177158SJaroslav Kysela- Vinod Koul <vkoul@kernel.org>
135