1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2018 Intel Corporation. All rights reserved.
4  *
5  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6  *         Keyon Jie <yang.jie@linux.intel.com>
7  */
8 
9 /**
10  * \file include/ipc/stream.h
11  * \brief IPC definitions for streams.
12  * \author Liam Girdwood <liam.r.girdwood@linux.intel.com>
13  * \author Keyon Jie <yang.jie@linux.intel.com>
14  */
15 
16 #ifndef __IPC_STREAM_H__
17 #define __IPC_STREAM_H__
18 
19 #include <ipc/header.h>
20 #include <stdint.h>
21 
22 /*
23  * Stream configuration.
24  */
25 
26 #define SOF_IPC_MAX_CHANNELS			8
27 
28 /* common sample rates for use in masks */
29 #define SOF_RATE_8000		(1 <<  0) /**< 8000Hz  */
30 #define SOF_RATE_11025		(1 <<  1) /**< 11025Hz */
31 #define SOF_RATE_12000		(1 <<  2) /**< 12000Hz */
32 #define SOF_RATE_16000		(1 <<  3) /**< 16000Hz */
33 #define SOF_RATE_22050		(1 <<  4) /**< 22050Hz */
34 #define SOF_RATE_24000		(1 <<  5) /**< 24000Hz */
35 #define SOF_RATE_32000		(1 <<  6) /**< 32000Hz */
36 #define SOF_RATE_44100		(1 <<  7) /**< 44100Hz */
37 #define SOF_RATE_48000		(1 <<  8) /**< 48000Hz */
38 #define SOF_RATE_64000		(1 <<  9) /**< 64000Hz */
39 #define SOF_RATE_88200		(1 << 10) /**< 88200Hz */
40 #define SOF_RATE_96000		(1 << 11) /**< 96000Hz */
41 #define SOF_RATE_176400		(1 << 12) /**< 176400Hz */
42 #define SOF_RATE_192000		(1 << 13) /**< 192000Hz */
43 
44 /* continuous and non-standard rates for flexibility */
45 #define SOF_RATE_CONTINUOUS	(1 << 30)  /**< range */
46 #define SOF_RATE_KNOT		(1 << 31)  /**< non-continuous */
47 
48 /* generic PCM flags for runtime settings */
49 #define SOF_PCM_FLAG_XRUN_STOP	(1 << 0) /**< Stop on any XRUN */
50 
51 /* stream PCM frame format */
52 enum sof_ipc_frame {
53 	SOF_IPC_FRAME_S16_LE = 0,
54 	SOF_IPC_FRAME_S24_4LE,
55 	SOF_IPC_FRAME_S32_LE,
56 	SOF_IPC_FRAME_FLOAT,
57 	/* other formats here */
58 	SOF_IPC_FRAME_S24_3LE,
59 };
60 
61 /* stream buffer format */
62 enum sof_ipc_buffer_format {
63 	SOF_IPC_BUFFER_INTERLEAVED,
64 	SOF_IPC_BUFFER_NONINTERLEAVED,
65 	/* other formats here */
66 };
67 
68 /* stream direction */
69 enum sof_ipc_stream_direction {
70 	SOF_IPC_STREAM_PLAYBACK = 0,
71 	SOF_IPC_STREAM_CAPTURE,
72 };
73 
74 /* stream ring info */
75 struct sof_ipc_host_buffer {
76 	struct sof_ipc_hdr hdr;
77 	uint32_t phy_addr;
78 	uint32_t pages;
79 	uint32_t size;
80 	uint32_t reserved[3];
81 } __attribute__((packed, aligned(4)));
82 
83 struct sof_ipc_stream_params {
84 	struct sof_ipc_hdr hdr;
85 	struct sof_ipc_host_buffer buffer;
86 	uint32_t direction;	/**< enum sof_ipc_stream_direction */
87 	uint32_t frame_fmt;	/**< enum sof_ipc_frame */
88 	uint32_t buffer_fmt;	/**< enum sof_ipc_buffer_format */
89 	uint32_t rate;
90 	uint16_t stream_tag;
91 	uint16_t channels;
92 	uint16_t sample_valid_bytes;
93 	uint16_t sample_container_bytes;
94 
95 	uint32_t host_period_bytes;
96 	uint16_t no_stream_position; /**< 1 means don't send stream position */
97 	uint8_t cont_update_posn; /**< 1 means continuous update stream position */
98 	uint8_t reserved0;
99 	uint16_t ext_data_length; /**< 0 means no extended data */
100 
101 	uint8_t reserved[2];
102 	uint16_t chmap[SOF_IPC_MAX_CHANNELS];	/**< channel map - SOF_CHMAP_ */
103 	int8_t data[]; /**< extended data */
104 } __attribute__((packed, aligned(4)));
105 
106 /* PCM params info - SOF_IPC_STREAM_PCM_PARAMS */
107 struct sof_ipc_pcm_params {
108 	struct sof_ipc_cmd_hdr hdr;
109 	uint32_t comp_id;
110 	uint32_t flags;		/**< generic PCM flags - SOF_PCM_FLAG_ */
111 	uint32_t reserved[2];
112 	struct sof_ipc_stream_params params;
113 } __attribute__((packed, aligned(4)));
114 
115 /* PCM params info reply - SOF_IPC_STREAM_PCM_PARAMS_REPLY */
116 struct sof_ipc_pcm_params_reply {
117 	struct sof_ipc_reply rhdr;
118 	uint32_t comp_id;
119 	uint32_t posn_offset;
120 } __attribute__((packed, aligned(4)));
121 
122 /* free stream - SOF_IPC_STREAM_PCM_PARAMS */
123 struct sof_ipc_stream {
124 	struct sof_ipc_cmd_hdr hdr;
125 	uint32_t comp_id;
126 } __attribute__((packed, aligned(4)));
127 
128 /* flags indicating which time stamps are in sync with each other */
129 #define	SOF_TIME_HOST_SYNC	(1 << 0)
130 #define	SOF_TIME_DAI_SYNC	(1 << 1)
131 #define	SOF_TIME_WALL_SYNC	(1 << 2)
132 #define	SOF_TIME_STAMP_SYNC	(1 << 3)
133 
134 /* flags indicating which time stamps are valid */
135 #define	SOF_TIME_HOST_VALID	(1 << 8)
136 #define	SOF_TIME_DAI_VALID	(1 << 9)
137 #define	SOF_TIME_WALL_VALID	(1 << 10)
138 #define	SOF_TIME_STAMP_VALID	(1 << 11)
139 
140 /* flags indicating time stamps are 64bit else 3use low 32bit */
141 #define	SOF_TIME_HOST_64	(1 << 16)
142 #define	SOF_TIME_DAI_64		(1 << 17)
143 #define	SOF_TIME_WALL_64	(1 << 18)
144 #define	SOF_TIME_STAMP_64	(1 << 19)
145 
146 struct sof_ipc_stream_posn {
147 	struct sof_ipc_reply rhdr;
148 	uint32_t comp_id;	/**< host component ID */
149 	uint32_t flags;		/**< SOF_TIME_ */
150 	uint32_t wallclock_hz;	/**< frequency of wallclock in Hz */
151 	uint32_t timestamp_ns;	/**< resolution of timestamp in ns */
152 	uint64_t host_posn;	/**< host DMA position in bytes */
153 	uint64_t dai_posn;	/**< DAI DMA position in bytes */
154 	uint64_t comp_posn;	/**< comp position in bytes */
155 	uint64_t wallclock;	/**< audio wall clock */
156 	uint64_t timestamp;	/**< system time stamp */
157 	uint32_t xrun_comp_id;	/**< comp ID of XRUN component */
158 	int32_t xrun_size;	/**< XRUN size in bytes */
159 } __attribute__((packed, aligned(4)));
160 
161 #endif /* __IPC_STREAM_H__ */
162