18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  compress_offload.h - compress offload header definations
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2011 Intel Corporation
68c2ecf20Sopenharmony_ci *  Authors:	Vinod Koul <vinod.koul@linux.intel.com>
78c2ecf20Sopenharmony_ci *		Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
88c2ecf20Sopenharmony_ci *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *  This program is free software; you can redistribute it and/or modify
118c2ecf20Sopenharmony_ci *  it under the terms of the GNU General Public License as published by
128c2ecf20Sopenharmony_ci *  the Free Software Foundation; version 2 of the License.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *  This program is distributed in the hope that it will be useful, but
158c2ecf20Sopenharmony_ci *  WITHOUT ANY WARRANTY; without even the implied warranty of
168c2ecf20Sopenharmony_ci *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
178c2ecf20Sopenharmony_ci *  General Public License for more details.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci *  You should have received a copy of the GNU General Public License along
208c2ecf20Sopenharmony_ci *  with this program; if not, write to the Free Software Foundation, Inc.,
218c2ecf20Sopenharmony_ci *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci#ifndef __COMPRESS_OFFLOAD_H
278c2ecf20Sopenharmony_ci#define __COMPRESS_OFFLOAD_H
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <linux/types.h>
308c2ecf20Sopenharmony_ci#include <sound/asound.h>
318c2ecf20Sopenharmony_ci#include <sound/compress_params.h>
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 2, 0)
358c2ecf20Sopenharmony_ci/**
368c2ecf20Sopenharmony_ci * struct snd_compressed_buffer - compressed buffer
378c2ecf20Sopenharmony_ci * @fragment_size: size of buffer fragment in bytes
388c2ecf20Sopenharmony_ci * @fragments: number of such fragments
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_cistruct snd_compressed_buffer {
418c2ecf20Sopenharmony_ci	__u32 fragment_size;
428c2ecf20Sopenharmony_ci	__u32 fragments;
438c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/**
468c2ecf20Sopenharmony_ci * struct snd_compr_params - compressed stream params
478c2ecf20Sopenharmony_ci * @buffer: buffer description
488c2ecf20Sopenharmony_ci * @codec: codec parameters
498c2ecf20Sopenharmony_ci * @no_wake_mode: dont wake on fragment elapsed
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_cistruct snd_compr_params {
528c2ecf20Sopenharmony_ci	struct snd_compressed_buffer buffer;
538c2ecf20Sopenharmony_ci	struct snd_codec codec;
548c2ecf20Sopenharmony_ci	__u8 no_wake_mode;
558c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/**
588c2ecf20Sopenharmony_ci * struct snd_compr_tstamp - timestamp descriptor
598c2ecf20Sopenharmony_ci * @byte_offset: Byte offset in ring buffer to DSP
608c2ecf20Sopenharmony_ci * @copied_total: Total number of bytes copied from/to ring buffer to/by DSP
618c2ecf20Sopenharmony_ci * @pcm_frames: Frames decoded or encoded by DSP. This field will evolve by
628c2ecf20Sopenharmony_ci *	large steps and should only be used to monitor encoding/decoding
638c2ecf20Sopenharmony_ci *	progress. It shall not be used for timing estimates.
648c2ecf20Sopenharmony_ci * @pcm_io_frames: Frames rendered or received by DSP into a mixer or an audio
658c2ecf20Sopenharmony_ci * output/input. This field should be used for A/V sync or time estimates.
668c2ecf20Sopenharmony_ci * @sampling_rate: sampling rate of audio
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_cistruct snd_compr_tstamp {
698c2ecf20Sopenharmony_ci	__u32 byte_offset;
708c2ecf20Sopenharmony_ci	__u32 copied_total;
718c2ecf20Sopenharmony_ci	__u32 pcm_frames;
728c2ecf20Sopenharmony_ci	__u32 pcm_io_frames;
738c2ecf20Sopenharmony_ci	__u32 sampling_rate;
748c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/**
778c2ecf20Sopenharmony_ci * struct snd_compr_avail - avail descriptor
788c2ecf20Sopenharmony_ci * @avail: Number of bytes available in ring buffer for writing/reading
798c2ecf20Sopenharmony_ci * @tstamp: timestamp information
808c2ecf20Sopenharmony_ci */
818c2ecf20Sopenharmony_cistruct snd_compr_avail {
828c2ecf20Sopenharmony_ci	__u64 avail;
838c2ecf20Sopenharmony_ci	struct snd_compr_tstamp tstamp;
848c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cienum snd_compr_direction {
878c2ecf20Sopenharmony_ci	SND_COMPRESS_PLAYBACK = 0,
888c2ecf20Sopenharmony_ci	SND_COMPRESS_CAPTURE
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/**
928c2ecf20Sopenharmony_ci * struct snd_compr_caps - caps descriptor
938c2ecf20Sopenharmony_ci * @codecs: pointer to array of codecs
948c2ecf20Sopenharmony_ci * @direction: direction supported. Of type snd_compr_direction
958c2ecf20Sopenharmony_ci * @min_fragment_size: minimum fragment supported by DSP
968c2ecf20Sopenharmony_ci * @max_fragment_size: maximum fragment supported by DSP
978c2ecf20Sopenharmony_ci * @min_fragments: min fragments supported by DSP
988c2ecf20Sopenharmony_ci * @max_fragments: max fragments supported by DSP
998c2ecf20Sopenharmony_ci * @num_codecs: number of codecs supported
1008c2ecf20Sopenharmony_ci * @reserved: reserved field
1018c2ecf20Sopenharmony_ci */
1028c2ecf20Sopenharmony_cistruct snd_compr_caps {
1038c2ecf20Sopenharmony_ci	__u32 num_codecs;
1048c2ecf20Sopenharmony_ci	__u32 direction;
1058c2ecf20Sopenharmony_ci	__u32 min_fragment_size;
1068c2ecf20Sopenharmony_ci	__u32 max_fragment_size;
1078c2ecf20Sopenharmony_ci	__u32 min_fragments;
1088c2ecf20Sopenharmony_ci	__u32 max_fragments;
1098c2ecf20Sopenharmony_ci	__u32 codecs[MAX_NUM_CODECS];
1108c2ecf20Sopenharmony_ci	__u32 reserved[11];
1118c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/**
1148c2ecf20Sopenharmony_ci * struct snd_compr_codec_caps - query capability of codec
1158c2ecf20Sopenharmony_ci * @codec: codec for which capability is queried
1168c2ecf20Sopenharmony_ci * @num_descriptors: number of codec descriptors
1178c2ecf20Sopenharmony_ci * @descriptor: array of codec capability descriptor
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_cistruct snd_compr_codec_caps {
1208c2ecf20Sopenharmony_ci	__u32 codec;
1218c2ecf20Sopenharmony_ci	__u32 num_descriptors;
1228c2ecf20Sopenharmony_ci	struct snd_codec_desc descriptor[MAX_NUM_CODEC_DESCRIPTORS];
1238c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/**
1268c2ecf20Sopenharmony_ci * enum sndrv_compress_encoder
1278c2ecf20Sopenharmony_ci * @SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the
1288c2ecf20Sopenharmony_ci * end of the track
1298c2ecf20Sopenharmony_ci * @SNDRV_COMPRESS_ENCODER_DELAY: no of samples inserted by the encoder at the
1308c2ecf20Sopenharmony_ci * beginning of the track
1318c2ecf20Sopenharmony_ci */
1328c2ecf20Sopenharmony_cienum sndrv_compress_encoder {
1338c2ecf20Sopenharmony_ci	SNDRV_COMPRESS_ENCODER_PADDING = 1,
1348c2ecf20Sopenharmony_ci	SNDRV_COMPRESS_ENCODER_DELAY = 2,
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/**
1388c2ecf20Sopenharmony_ci * struct snd_compr_metadata - compressed stream metadata
1398c2ecf20Sopenharmony_ci * @key: key id
1408c2ecf20Sopenharmony_ci * @value: key value
1418c2ecf20Sopenharmony_ci */
1428c2ecf20Sopenharmony_cistruct snd_compr_metadata {
1438c2ecf20Sopenharmony_ci	 __u32 key;
1448c2ecf20Sopenharmony_ci	 __u32 value[8];
1458c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(4)));
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/*
1488c2ecf20Sopenharmony_ci * compress path ioctl definitions
1498c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_GET_CAPS: Query capability of DSP
1508c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_GET_CODEC_CAPS: Query capability of a codec
1518c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_SET_PARAMS: Set codec and stream parameters
1528c2ecf20Sopenharmony_ci * Note: only codec params can be changed runtime and stream params cant be
1538c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_GET_PARAMS: Query codec params
1548c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_TSTAMP: get the current timestamp value
1558c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_AVAIL: get the current buffer avail value.
1568c2ecf20Sopenharmony_ci * This also queries the tstamp properties
1578c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_PAUSE: Pause the running stream
1588c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_RESUME: resume a paused stream
1598c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_START: Start a stream
1608c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_STOP: stop a running stream, discarding ring buffer content
1618c2ecf20Sopenharmony_ci * and the buffers currently with DSP
1628c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_DRAIN: Play till end of buffers and stop after that
1638c2ecf20Sopenharmony_ci * SNDRV_COMPRESS_IOCTL_VERSION: Query the API version
1648c2ecf20Sopenharmony_ci */
1658c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_IOCTL_VERSION	_IOR('C', 0x00, int)
1668c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_GET_CAPS		_IOWR('C', 0x10, struct snd_compr_caps)
1678c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_GET_CODEC_CAPS	_IOWR('C', 0x11,\
1688c2ecf20Sopenharmony_ci						struct snd_compr_codec_caps)
1698c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_SET_PARAMS	_IOW('C', 0x12, struct snd_compr_params)
1708c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_GET_PARAMS	_IOR('C', 0x13, struct snd_codec)
1718c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_SET_METADATA	_IOW('C', 0x14,\
1728c2ecf20Sopenharmony_ci						 struct snd_compr_metadata)
1738c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_GET_METADATA	_IOWR('C', 0x15,\
1748c2ecf20Sopenharmony_ci						 struct snd_compr_metadata)
1758c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_TSTAMP		_IOR('C', 0x20, struct snd_compr_tstamp)
1768c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_AVAIL		_IOR('C', 0x21, struct snd_compr_avail)
1778c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_PAUSE		_IO('C', 0x30)
1788c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_RESUME		_IO('C', 0x31)
1798c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_START		_IO('C', 0x32)
1808c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_STOP		_IO('C', 0x33)
1818c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_DRAIN		_IO('C', 0x34)
1828c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_NEXT_TRACK	_IO('C', 0x35)
1838c2ecf20Sopenharmony_ci#define SNDRV_COMPRESS_PARTIAL_DRAIN	_IO('C', 0x36)
1848c2ecf20Sopenharmony_ci/*
1858c2ecf20Sopenharmony_ci * TODO
1868c2ecf20Sopenharmony_ci * 1. add mmap support
1878c2ecf20Sopenharmony_ci *
1888c2ecf20Sopenharmony_ci */
1898c2ecf20Sopenharmony_ci#define SND_COMPR_TRIGGER_DRAIN 7 /*FIXME move this to pcm.h */
1908c2ecf20Sopenharmony_ci#define SND_COMPR_TRIGGER_NEXT_TRACK 8
1918c2ecf20Sopenharmony_ci#define SND_COMPR_TRIGGER_PARTIAL_DRAIN 9
1928c2ecf20Sopenharmony_ci#endif
193