123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
#ifndef __COMPRESS_DRIVER_H
#define __COMPRESS_DRIVER_H
#include <linux/types.h>
#include <linux/sched.h>
#include <sound/core.h>
#include <sound/compress_offload.h>
#include <sound/asound.h>
#include <sound/pcm.h>
struct snd_compr_ops;
struct snd_compr_task_runtime {
struct list_head list;
struct dma_buf *input;
struct dma_buf *output;
u64 seqno;
u64 input_size;
u64 output_size;
u32 flags;
u8 state;
void *private_value;
};
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;
void *private_data;
unsigned char *dma_area;
dma_addr_t dma_addr;
size_t dma_bytes;
struct snd_dma_buffer *dma_buffer_p;
#if IS_ENABLED(CONFIG_SND_COMPRESS_ACCEL)
u32 active_tasks;
u32 total_tasks;
u64 task_seqno;
struct list_head tasks;
#endif
};
struct snd_compr_stream {
const char *name;
struct snd_compr_ops *ops;
struct snd_compr_runtime *runtime;
struct snd_compr *device;
struct delayed_work error_work;
enum snd_compr_direction direction;
bool metadata_set;
bool next_track;
bool partial_drain;
bool pause_in_draining;
void *private_data;
struct snd_dma_buffer dma_buffer;
};
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);
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);
int (*trigger)(struct snd_compr_stream *stream, int cmd);
int (*pointer)(struct snd_compr_stream *stream,
struct snd_compr_tstamp64 *tstamp);
int (*copy)(struct snd_compr_stream *stream, char __user *buf,
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);
#if IS_ENABLED(CONFIG_SND_COMPRESS_ACCEL)
int (*task_create) (struct snd_compr_stream *stream, struct snd_compr_task_runtime *task);
int (*task_start) (struct snd_compr_stream *stream, struct snd_compr_task_runtime *task);
int (*task_stop) (struct snd_compr_stream *stream, struct snd_compr_task_runtime *task);
int (*task_free) (struct snd_compr_stream *stream, struct snd_compr_task_runtime *task);
#endif
};
struct snd_compr {
const char *name;
struct device *dev;
struct snd_compr_ops *ops;
void *private_data;
struct snd_card *card;
unsigned int direction;
struct mutex lock;
struct list_head open_list;
int device;
bool use_pause_in_draining;
#ifdef CONFIG_SND_VERBOSE_PROCFS
char id[64];
struct snd_info_entry *proc_root;
struct snd_info_entry *proc_info_entry;
#endif
};
int snd_compress_new(struct snd_card *card, int device,
int type, const char *id, struct snd_compr *compr);
static inline void snd_compr_use_pause_in_draining(struct snd_compr_stream *substream)
{
substream->device->use_pause_in_draining = true;
}
static inline void snd_compr_fragment_elapsed(struct snd_compr_stream *stream)
{
wake_up(&stream->runtime->sleep);
}
static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
{
if (snd_BUG_ON(!stream))
return;
if (stream->partial_drain) {
stream->runtime->state = SNDRV_PCM_STATE_RUNNING;
stream->partial_drain = false;
} else {
stream->runtime->state = SNDRV_PCM_STATE_SETUP;
}
wake_up(&stream->runtime->sleep);
}
static inline void
snd_compr_set_runtime_buffer(struct snd_compr_stream *stream,
struct snd_dma_buffer *bufp)
{
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;
}
}
int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size);
int snd_compr_free_pages(struct snd_compr_stream *stream);
int snd_compr_stop_error(struct snd_compr_stream *stream,
snd_pcm_state_t state);
#if IS_ENABLED(CONFIG_SND_COMPRESS_ACCEL)
void snd_compr_task_finished(struct snd_compr_stream *stream,
struct snd_compr_task_runtime *task);
#endif
#endif