1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2674e95caSDavid Howells /*
3674e95caSDavid Howells  *  compress_offload.h - compress offload header definations
4674e95caSDavid Howells  *
5674e95caSDavid Howells  *  Copyright (C) 2011 Intel Corporation
6674e95caSDavid Howells  *  Authors:	Vinod Koul <vinod.koul@linux.intel.com>
7674e95caSDavid Howells  *		Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
8674e95caSDavid Howells  */
9674e95caSDavid Howells #ifndef __COMPRESS_OFFLOAD_H
10674e95caSDavid Howells #define __COMPRESS_OFFLOAD_H
11674e95caSDavid Howells 
12674e95caSDavid Howells #include <linux/types.h>
13674e95caSDavid Howells #include <sound/asound.h>
14674e95caSDavid Howells #include <sound/compress_params.h>
15674e95caSDavid Howells 
16674e95caSDavid Howells 
1754ce83a3SVinod Koul #define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 2, 0)
18674e95caSDavid Howells /**
19f533ccb6STakashi Iwai  * struct snd_compressed_buffer - compressed buffer
20674e95caSDavid Howells  * @fragment_size: size of buffer fragment in bytes
21674e95caSDavid Howells  * @fragments: number of such fragments
22674e95caSDavid Howells  */
23674e95caSDavid Howells struct snd_compressed_buffer {
24674e95caSDavid Howells 	__u32 fragment_size;
25674e95caSDavid Howells 	__u32 fragments;
262da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
27674e95caSDavid Howells 
28674e95caSDavid Howells /**
29f533ccb6STakashi Iwai  * struct snd_compr_params - compressed stream params
30674e95caSDavid Howells  * @buffer: buffer description
31674e95caSDavid Howells  * @codec: codec parameters
32674e95caSDavid Howells  * @no_wake_mode: dont wake on fragment elapsed
33674e95caSDavid Howells  */
34674e95caSDavid Howells struct snd_compr_params {
35674e95caSDavid Howells 	struct snd_compressed_buffer buffer;
36674e95caSDavid Howells 	struct snd_codec codec;
37674e95caSDavid Howells 	__u8 no_wake_mode;
382da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
39674e95caSDavid Howells 
40674e95caSDavid Howells /**
41f533ccb6STakashi Iwai  * struct snd_compr_tstamp - timestamp descriptor
42674e95caSDavid Howells  * @byte_offset: Byte offset in ring buffer to DSP
43674e95caSDavid Howells  * @copied_total: Total number of bytes copied from/to ring buffer to/by DSP
44674e95caSDavid Howells  * @pcm_frames: Frames decoded or encoded by DSP. This field will evolve by
45674e95caSDavid Howells  *	large steps and should only be used to monitor encoding/decoding
46674e95caSDavid Howells  *	progress. It shall not be used for timing estimates.
47674e95caSDavid Howells  * @pcm_io_frames: Frames rendered or received by DSP into a mixer or an audio
48674e95caSDavid Howells  * output/input. This field should be used for A/V sync or time estimates.
49674e95caSDavid Howells  * @sampling_rate: sampling rate of audio
50674e95caSDavid Howells  */
51674e95caSDavid Howells struct snd_compr_tstamp {
52674e95caSDavid Howells 	__u32 byte_offset;
53674e95caSDavid Howells 	__u32 copied_total;
546733cf57STakashi Iwai 	__u32 pcm_frames;
556733cf57STakashi Iwai 	__u32 pcm_io_frames;
56674e95caSDavid Howells 	__u32 sampling_rate;
572da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
58674e95caSDavid Howells 
59674e95caSDavid Howells /**
60f533ccb6STakashi Iwai  * struct snd_compr_avail - avail descriptor
61674e95caSDavid Howells  * @avail: Number of bytes available in ring buffer for writing/reading
621a6ab46fSMasanari Iida  * @tstamp: timestamp information
63674e95caSDavid Howells  */
64674e95caSDavid Howells struct snd_compr_avail {
65674e95caSDavid Howells 	__u64 avail;
66674e95caSDavid Howells 	struct snd_compr_tstamp tstamp;
672da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
68674e95caSDavid Howells 
69674e95caSDavid Howells enum snd_compr_direction {
70674e95caSDavid Howells 	SND_COMPRESS_PLAYBACK = 0,
71674e95caSDavid Howells 	SND_COMPRESS_CAPTURE
72674e95caSDavid Howells };
73674e95caSDavid Howells 
74674e95caSDavid Howells /**
75f533ccb6STakashi Iwai  * struct snd_compr_caps - caps descriptor
76674e95caSDavid Howells  * @codecs: pointer to array of codecs
77674e95caSDavid Howells  * @direction: direction supported. Of type snd_compr_direction
78674e95caSDavid Howells  * @min_fragment_size: minimum fragment supported by DSP
79674e95caSDavid Howells  * @max_fragment_size: maximum fragment supported by DSP
80674e95caSDavid Howells  * @min_fragments: min fragments supported by DSP
81674e95caSDavid Howells  * @max_fragments: max fragments supported by DSP
82674e95caSDavid Howells  * @num_codecs: number of codecs supported
83674e95caSDavid Howells  * @reserved: reserved field
84674e95caSDavid Howells  */
85674e95caSDavid Howells struct snd_compr_caps {
86674e95caSDavid Howells 	__u32 num_codecs;
87674e95caSDavid Howells 	__u32 direction;
88674e95caSDavid Howells 	__u32 min_fragment_size;
89674e95caSDavid Howells 	__u32 max_fragment_size;
90674e95caSDavid Howells 	__u32 min_fragments;
91674e95caSDavid Howells 	__u32 max_fragments;
92674e95caSDavid Howells 	__u32 codecs[MAX_NUM_CODECS];
93674e95caSDavid Howells 	__u32 reserved[11];
942da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
95674e95caSDavid Howells 
96674e95caSDavid Howells /**
97f533ccb6STakashi Iwai  * struct snd_compr_codec_caps - query capability of codec
98674e95caSDavid Howells  * @codec: codec for which capability is queried
99674e95caSDavid Howells  * @num_descriptors: number of codec descriptors
100674e95caSDavid Howells  * @descriptor: array of codec capability descriptor
101674e95caSDavid Howells  */
102674e95caSDavid Howells struct snd_compr_codec_caps {
103674e95caSDavid Howells 	__u32 codec;
104674e95caSDavid Howells 	__u32 num_descriptors;
105674e95caSDavid Howells 	struct snd_codec_desc descriptor[MAX_NUM_CODEC_DESCRIPTORS];
1062da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
107674e95caSDavid Howells 
108674e95caSDavid Howells /**
109*b05d834eSTakashi Iwai  * enum sndrv_compress_encoder - encoder metadata key
1109727b490SJeeja KP  * @SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the
1119727b490SJeeja KP  * end of the track
1129727b490SJeeja KP  * @SNDRV_COMPRESS_ENCODER_DELAY: no of samples inserted by the encoder at the
1139727b490SJeeja KP  * beginning of the track
1149727b490SJeeja KP  */
115f533ccb6STakashi Iwai enum sndrv_compress_encoder {
1169727b490SJeeja KP 	SNDRV_COMPRESS_ENCODER_PADDING = 1,
1179727b490SJeeja KP 	SNDRV_COMPRESS_ENCODER_DELAY = 2,
1189727b490SJeeja KP };
1199727b490SJeeja KP 
1209727b490SJeeja KP /**
121f533ccb6STakashi Iwai  * struct snd_compr_metadata - compressed stream metadata
1229727b490SJeeja KP  * @key: key id
1239727b490SJeeja KP  * @value: key value
1249727b490SJeeja KP  */
1259727b490SJeeja KP struct snd_compr_metadata {
1269727b490SJeeja KP 	 __u32 key;
1279727b490SJeeja KP 	 __u32 value[8];
1282da38e0cSVinod Koul } __attribute__((packed, aligned(4)));
1299727b490SJeeja KP 
130f7b6603cSMauro Carvalho Chehab /*
131674e95caSDavid Howells  * compress path ioctl definitions
132674e95caSDavid Howells  * SNDRV_COMPRESS_GET_CAPS: Query capability of DSP
133674e95caSDavid Howells  * SNDRV_COMPRESS_GET_CODEC_CAPS: Query capability of a codec
134674e95caSDavid Howells  * SNDRV_COMPRESS_SET_PARAMS: Set codec and stream parameters
135674e95caSDavid Howells  * Note: only codec params can be changed runtime and stream params cant be
136674e95caSDavid Howells  * SNDRV_COMPRESS_GET_PARAMS: Query codec params
137674e95caSDavid Howells  * SNDRV_COMPRESS_TSTAMP: get the current timestamp value
138674e95caSDavid Howells  * SNDRV_COMPRESS_AVAIL: get the current buffer avail value.
139674e95caSDavid Howells  * This also queries the tstamp properties
140674e95caSDavid Howells  * SNDRV_COMPRESS_PAUSE: Pause the running stream
141674e95caSDavid Howells  * SNDRV_COMPRESS_RESUME: resume a paused stream
142674e95caSDavid Howells  * SNDRV_COMPRESS_START: Start a stream
143674e95caSDavid Howells  * SNDRV_COMPRESS_STOP: stop a running stream, discarding ring buffer content
144674e95caSDavid Howells  * and the buffers currently with DSP
145674e95caSDavid Howells  * SNDRV_COMPRESS_DRAIN: Play till end of buffers and stop after that
146674e95caSDavid Howells  * SNDRV_COMPRESS_IOCTL_VERSION: Query the API version
147674e95caSDavid Howells  */
148674e95caSDavid Howells #define SNDRV_COMPRESS_IOCTL_VERSION	_IOR('C', 0x00, int)
149674e95caSDavid Howells #define SNDRV_COMPRESS_GET_CAPS		_IOWR('C', 0x10, struct snd_compr_caps)
150674e95caSDavid Howells #define SNDRV_COMPRESS_GET_CODEC_CAPS	_IOWR('C', 0x11,\
151674e95caSDavid Howells 						struct snd_compr_codec_caps)
152674e95caSDavid Howells #define SNDRV_COMPRESS_SET_PARAMS	_IOW('C', 0x12, struct snd_compr_params)
153674e95caSDavid Howells #define SNDRV_COMPRESS_GET_PARAMS	_IOR('C', 0x13, struct snd_codec)
1549727b490SJeeja KP #define SNDRV_COMPRESS_SET_METADATA	_IOW('C', 0x14,\
1559727b490SJeeja KP 						 struct snd_compr_metadata)
1569727b490SJeeja KP #define SNDRV_COMPRESS_GET_METADATA	_IOWR('C', 0x15,\
1579727b490SJeeja KP 						 struct snd_compr_metadata)
158674e95caSDavid Howells #define SNDRV_COMPRESS_TSTAMP		_IOR('C', 0x20, struct snd_compr_tstamp)
159674e95caSDavid Howells #define SNDRV_COMPRESS_AVAIL		_IOR('C', 0x21, struct snd_compr_avail)
160674e95caSDavid Howells #define SNDRV_COMPRESS_PAUSE		_IO('C', 0x30)
161674e95caSDavid Howells #define SNDRV_COMPRESS_RESUME		_IO('C', 0x31)
162674e95caSDavid Howells #define SNDRV_COMPRESS_START		_IO('C', 0x32)
163674e95caSDavid Howells #define SNDRV_COMPRESS_STOP		_IO('C', 0x33)
164674e95caSDavid Howells #define SNDRV_COMPRESS_DRAIN		_IO('C', 0x34)
1659727b490SJeeja KP #define SNDRV_COMPRESS_NEXT_TRACK	_IO('C', 0x35)
1669727b490SJeeja KP #define SNDRV_COMPRESS_PARTIAL_DRAIN	_IO('C', 0x36)
167674e95caSDavid Howells /*
168674e95caSDavid Howells  * TODO
169674e95caSDavid Howells  * 1. add mmap support
170674e95caSDavid Howells  *
171674e95caSDavid Howells  */
172674e95caSDavid Howells #define SND_COMPR_TRIGGER_DRAIN 7 /*FIXME move this to pcm.h */
1739727b490SJeeja KP #define SND_COMPR_TRIGGER_NEXT_TRACK 8
1749727b490SJeeja KP #define SND_COMPR_TRIGGER_PARTIAL_DRAIN 9
175674e95caSDavid Howells #endif
176