2018-07-02 06:24:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*
|
2011-12-23 05:06:38 +00:00
|
|
|
* compress_driver.h - compress offload driver definations
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Intel Corporation
|
|
|
|
* Authors: Vinod Koul <vinod.koul@linux.intel.com>
|
|
|
|
* Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
|
|
|
|
*/
|
2018-07-02 06:24:57 +00:00
|
|
|
|
2011-12-23 05:06:38 +00:00
|
|
|
#ifndef __COMPRESS_DRIVER_H
|
|
|
|
#define __COMPRESS_DRIVER_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/sched.h>
|
2014-12-19 11:38:30 +00:00
|
|
|
#include <sound/core.h>
|
2011-12-23 05:06:38 +00:00
|
|
|
#include <sound/compress_offload.h>
|
|
|
|
#include <sound/asound.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
|
|
|
|
struct snd_compr_ops;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct snd_compr_runtime: runtime stream description
|
|
|
|
* @state: stream state
|
|
|
|
* @ops: pointer to DSP callbacks
|
|
|
|
* @buffer: pointer to kernel buffer, valid only when not in mmap mode or
|
|
|
|
* DSP doesn't implement copy
|
|
|
|
* @buffer_size: size of the above buffer
|
|
|
|
* @fragment_size: size of buffer fragment in bytes
|
|
|
|
* @fragments: number of such fragments
|
|
|
|
* @total_bytes_available: cumulative number of bytes made available in
|
|
|
|
* the ring buffer
|
|
|
|
* @total_bytes_transferred: cumulative bytes transferred by offload DSP
|
|
|
|
* @sleep: poll sleep
|
2014-10-28 15:55:13 +00:00
|
|
|
* @private_data: driver private data pointer
|
2020-02-18 14:39:16 +00:00
|
|
|
* @dma_area: virtual buffer address
|
|
|
|
* @dma_addr: physical buffer address (not accessible from main CPU)
|
|
|
|
* @dma_bytes: size of DMA area
|
|
|
|
* @dma_buffer_p: runtime dma buffer pointer
|
2011-12-23 05:06:38 +00:00
|
|
|
*/
|
|
|
|
struct snd_compr_runtime {
|
|
|
|
snd_pcm_state_t state;
|
|
|
|
struct snd_compr_ops *ops;
|
|
|
|
void *buffer;
|
|
|
|
u64 buffer_size;
|
|
|
|
u32 fragment_size;
|
|
|
|
u32 fragments;
|
|
|
|
u64 total_bytes_available;
|
|
|
|
u64 total_bytes_transferred;
|
|
|
|
wait_queue_head_t sleep;
|
2012-08-16 11:40:40 +00:00
|
|
|
void *private_data;
|
2020-02-18 14:39:16 +00:00
|
|
|
|
|
|
|
unsigned char *dma_area;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
size_t dma_bytes;
|
|
|
|
struct snd_dma_buffer *dma_buffer_p;
|
2011-12-23 05:06:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct snd_compr_stream: compressed stream
|
|
|
|
* @name: device name
|
|
|
|
* @ops: pointer to DSP callbacks
|
|
|
|
* @runtime: pointer to runtime structure
|
|
|
|
* @device: device pointer
|
2016-06-13 13:17:10 +00:00
|
|
|
* @error_work: delayed work used when closing the stream due to an error
|
2011-12-23 05:06:38 +00:00
|
|
|
* @direction: stream direction, playback/recording
|
2013-02-14 11:22:51 +00:00
|
|
|
* @metadata_set: metadata set flag, true when set
|
2015-03-04 01:56:13 +00:00
|
|
|
* @next_track: has userspace signal next track transition, true when set
|
2020-06-29 13:47:37 +00:00
|
|
|
* @partial_drain: undergoing partial_drain for stream, true when set
|
2020-11-26 12:34:52 +00:00
|
|
|
* @pause_in_draining: paused during draining state, true when set
|
2011-12-23 05:06:38 +00:00
|
|
|
* @private_data: pointer to DSP private data
|
2020-02-18 14:39:17 +00:00
|
|
|
* @dma_buffer: allocated buffer if any
|
2011-12-23 05:06:38 +00:00
|
|
|
*/
|
|
|
|
struct snd_compr_stream {
|
|
|
|
const char *name;
|
|
|
|
struct snd_compr_ops *ops;
|
|
|
|
struct snd_compr_runtime *runtime;
|
|
|
|
struct snd_compr *device;
|
2016-06-13 13:17:10 +00:00
|
|
|
struct delayed_work error_work;
|
2011-12-23 05:06:38 +00:00
|
|
|
enum snd_compr_direction direction;
|
2013-02-14 11:22:51 +00:00
|
|
|
bool metadata_set;
|
|
|
|
bool next_track;
|
2020-06-29 13:47:37 +00:00
|
|
|
bool partial_drain;
|
2020-11-26 12:34:52 +00:00
|
|
|
bool pause_in_draining;
|
2011-12-23 05:06:38 +00:00
|
|
|
void *private_data;
|
2020-02-18 14:39:17 +00:00
|
|
|
struct snd_dma_buffer dma_buffer;
|
2011-12-23 05:06:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct snd_compr_ops: compressed path DSP operations
|
|
|
|
* @open: Open the compressed stream
|
|
|
|
* This callback is mandatory and shall keep dsp ready to receive the stream
|
|
|
|
* parameter
|
|
|
|
* @free: Close the compressed stream, mandatory
|
|
|
|
* @set_params: Sets the compressed stream parameters, mandatory
|
|
|
|
* This can be called in during stream creation only to set codec params
|
|
|
|
* and the stream properties
|
|
|
|
* @get_params: retrieve the codec parameters, mandatory
|
2014-10-28 15:55:13 +00:00
|
|
|
* @set_metadata: Set the metadata values for a stream
|
2015-03-04 01:56:13 +00:00
|
|
|
* @get_metadata: retrieves the requested metadata values from stream
|
2011-12-23 05:06:38 +00:00
|
|
|
* @trigger: Trigger operations like start, pause, resume, drain, stop.
|
|
|
|
* This callback is mandatory
|
|
|
|
* @pointer: Retrieve current h/w pointer information. Mandatory
|
|
|
|
* @copy: Copy the compressed data to/from userspace, Optional
|
|
|
|
* Can't be implemented if DSP supports mmap
|
|
|
|
* @mmap: DSP mmap method to mmap DSP memory
|
|
|
|
* @ack: Ack for DSP when data is written to audio buffer, Optional
|
|
|
|
* Not valid if copy is implemented
|
|
|
|
* @get_caps: Retrieve DSP capabilities, mandatory
|
|
|
|
* @get_codec_caps: Retrieve capabilities for a specific codec, mandatory
|
|
|
|
*/
|
|
|
|
struct snd_compr_ops {
|
|
|
|
int (*open)(struct snd_compr_stream *stream);
|
|
|
|
int (*free)(struct snd_compr_stream *stream);
|
|
|
|
int (*set_params)(struct snd_compr_stream *stream,
|
|
|
|
struct snd_compr_params *params);
|
|
|
|
int (*get_params)(struct snd_compr_stream *stream,
|
|
|
|
struct snd_codec *params);
|
2013-02-14 11:22:51 +00:00
|
|
|
int (*set_metadata)(struct snd_compr_stream *stream,
|
|
|
|
struct snd_compr_metadata *metadata);
|
|
|
|
int (*get_metadata)(struct snd_compr_stream *stream,
|
|
|
|
struct snd_compr_metadata *metadata);
|
2011-12-23 05:06:38 +00:00
|
|
|
int (*trigger)(struct snd_compr_stream *stream, int cmd);
|
|
|
|
int (*pointer)(struct snd_compr_stream *stream,
|
|
|
|
struct snd_compr_tstamp *tstamp);
|
2013-04-18 10:01:38 +00:00
|
|
|
int (*copy)(struct snd_compr_stream *stream, char __user *buf,
|
2011-12-23 05:06:38 +00:00
|
|
|
size_t count);
|
|
|
|
int (*mmap)(struct snd_compr_stream *stream,
|
|
|
|
struct vm_area_struct *vma);
|
|
|
|
int (*ack)(struct snd_compr_stream *stream, size_t bytes);
|
|
|
|
int (*get_caps) (struct snd_compr_stream *stream,
|
|
|
|
struct snd_compr_caps *caps);
|
|
|
|
int (*get_codec_caps) (struct snd_compr_stream *stream,
|
|
|
|
struct snd_compr_codec_caps *codec);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct snd_compr: Compressed device
|
|
|
|
* @name: DSP device name
|
2015-01-30 07:16:35 +00:00
|
|
|
* @dev: associated device instance
|
2011-12-23 05:06:38 +00:00
|
|
|
* @ops: pointer to DSP callbacks
|
|
|
|
* @private_data: pointer to DSP pvt data
|
|
|
|
* @card: sound card pointer
|
|
|
|
* @direction: Playback or capture direction
|
|
|
|
* @lock: device lock
|
|
|
|
* @device: device id
|
2020-11-26 12:34:52 +00:00
|
|
|
* @use_pause_in_draining: allow pause in draining, true when set
|
2011-12-23 05:06:38 +00:00
|
|
|
*/
|
|
|
|
struct snd_compr {
|
|
|
|
const char *name;
|
2015-01-30 07:16:35 +00:00
|
|
|
struct device dev;
|
2011-12-23 05:06:38 +00:00
|
|
|
struct snd_compr_ops *ops;
|
|
|
|
void *private_data;
|
|
|
|
struct snd_card *card;
|
|
|
|
unsigned int direction;
|
|
|
|
struct mutex lock;
|
|
|
|
int device;
|
2020-11-26 12:34:52 +00:00
|
|
|
bool use_pause_in_draining;
|
2015-11-25 13:00:23 +00:00
|
|
|
#ifdef CONFIG_SND_VERBOSE_PROCFS
|
2016-11-14 21:22:27 +00:00
|
|
|
/* private: */
|
2015-11-25 13:00:23 +00:00
|
|
|
char id[64];
|
|
|
|
struct snd_info_entry *proc_root;
|
|
|
|
struct snd_info_entry *proc_info_entry;
|
|
|
|
#endif
|
2011-12-23 05:06:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* compress device register APIs */
|
|
|
|
int snd_compress_new(struct snd_card *card, int device,
|
2015-11-25 13:00:24 +00:00
|
|
|
int type, const char *id, struct snd_compr *compr);
|
2011-12-23 05:06:38 +00:00
|
|
|
|
2020-11-26 12:34:52 +00:00
|
|
|
/**
|
|
|
|
* snd_compr_use_pause_in_draining - Allow pause and resume in draining state
|
|
|
|
* @substream: compress substream to set
|
|
|
|
*
|
|
|
|
* Allow pause and resume in draining state.
|
|
|
|
* Only HW driver supports this transition can call this API.
|
|
|
|
*/
|
|
|
|
static inline void snd_compr_use_pause_in_draining(struct snd_compr_stream *substream)
|
|
|
|
{
|
|
|
|
substream->device->use_pause_in_draining = true;
|
|
|
|
}
|
|
|
|
|
2011-12-23 05:06:38 +00:00
|
|
|
/* dsp driver callback apis
|
|
|
|
* For playback: driver should call snd_compress_fragment_elapsed() to let the
|
|
|
|
* framework know that a fragment has been consumed from the ring buffer
|
|
|
|
*
|
|
|
|
* For recording: we want to know when a frame is available or when
|
|
|
|
* at least one frame is available so snd_compress_frame_elapsed()
|
|
|
|
* callback should be called when a encodeded frame is available
|
|
|
|
*/
|
|
|
|
static inline void snd_compr_fragment_elapsed(struct snd_compr_stream *stream)
|
|
|
|
{
|
|
|
|
wake_up(&stream->runtime->sleep);
|
|
|
|
}
|
|
|
|
|
2013-10-24 11:07:31 +00:00
|
|
|
static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
|
|
|
|
{
|
2013-11-07 09:08:22 +00:00
|
|
|
if (snd_BUG_ON(!stream))
|
|
|
|
return;
|
2013-10-24 11:07:31 +00:00
|
|
|
|
2020-06-29 13:47:37 +00:00
|
|
|
/* for partial_drain case we are back to running state on success */
|
|
|
|
if (stream->partial_drain) {
|
|
|
|
stream->runtime->state = SNDRV_PCM_STATE_RUNNING;
|
|
|
|
stream->partial_drain = false; /* clear this flag as well */
|
|
|
|
} else {
|
|
|
|
stream->runtime->state = SNDRV_PCM_STATE_SETUP;
|
|
|
|
}
|
2019-02-05 16:29:40 +00:00
|
|
|
|
2013-11-07 09:08:22 +00:00
|
|
|
wake_up(&stream->runtime->sleep);
|
2013-10-24 11:07:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 18:13:20 +00:00
|
|
|
/**
|
|
|
|
* snd_compr_set_runtime_buffer - Set the Compress runtime buffer
|
2020-02-18 14:39:16 +00:00
|
|
|
* @stream: compress stream to set
|
2018-11-15 18:13:20 +00:00
|
|
|
* @bufp: the buffer information, NULL to clear
|
|
|
|
*
|
|
|
|
* Copy the buffer information to runtime buffer when @bufp is non-NULL.
|
|
|
|
* Otherwise it clears the current buffer information.
|
|
|
|
*/
|
2020-02-18 14:39:16 +00:00
|
|
|
static inline void
|
|
|
|
snd_compr_set_runtime_buffer(struct snd_compr_stream *stream,
|
|
|
|
struct snd_dma_buffer *bufp)
|
2018-11-15 18:13:20 +00:00
|
|
|
{
|
2020-02-18 14:39:16 +00:00
|
|
|
struct snd_compr_runtime *runtime = stream->runtime;
|
|
|
|
|
|
|
|
if (bufp) {
|
|
|
|
runtime->dma_buffer_p = bufp;
|
|
|
|
runtime->dma_area = bufp->area;
|
|
|
|
runtime->dma_addr = bufp->addr;
|
|
|
|
runtime->dma_bytes = bufp->bytes;
|
|
|
|
} else {
|
|
|
|
runtime->dma_buffer_p = NULL;
|
|
|
|
runtime->dma_area = NULL;
|
|
|
|
runtime->dma_addr = 0;
|
|
|
|
runtime->dma_bytes = 0;
|
|
|
|
}
|
2018-11-15 18:13:20 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 14:39:17 +00:00
|
|
|
int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size);
|
|
|
|
int snd_compr_free_pages(struct snd_compr_stream *stream);
|
|
|
|
|
2016-06-13 13:17:10 +00:00
|
|
|
int snd_compr_stop_error(struct snd_compr_stream *stream,
|
|
|
|
snd_pcm_state_t state);
|
|
|
|
|
2011-12-23 05:06:38 +00:00
|
|
|
#endif
|