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 };
59 
60 /* stream buffer format */
61 enum sof_ipc_buffer_format {
62 	SOF_IPC_BUFFER_INTERLEAVED,
63 	SOF_IPC_BUFFER_NONINTERLEAVED,
64 	/* other formats here */
65 };
66 
67 /* stream direction */
68 enum sof_ipc_stream_direction {
69 	SOF_IPC_STREAM_PLAYBACK = 0,
70 	SOF_IPC_STREAM_CAPTURE,
71 };
72 
73 /* stream ring info */
74 struct sof_ipc_host_buffer {
75 	struct sof_ipc_hdr hdr;
76 	uint32_t phy_addr;
77 	uint32_t pages;
78 	uint32_t size;
79 	uint32_t reserved[3];
80 } __attribute__((packed, aligned(4)));
81 
82 struct sof_ipc_stream_params {
83 	struct sof_ipc_hdr hdr;
84 	struct sof_ipc_host_buffer buffer;
85 	uint32_t direction;	/**< enum sof_ipc_stream_direction */
86 	uint32_t frame_fmt;	/**< enum sof_ipc_frame */
87 	uint32_t buffer_fmt;	/**< enum sof_ipc_buffer_format */
88 	uint32_t rate;
89 	uint16_t stream_tag;
90 	uint16_t channels;
91 	uint16_t sample_valid_bytes;
92 	uint16_t sample_container_bytes;
93 
94 	uint32_t host_period_bytes;
95 	uint16_t no_stream_position; /**< 1 means don't send stream position */
96 
97 	uint16_t reserved[3];
98 	uint16_t chmap[SOF_IPC_MAX_CHANNELS];	/**< channel map - SOF_CHMAP_ */
99 } __attribute__((packed, aligned(4)));
100 
101 /* PCM params info - SOF_IPC_STREAM_PCM_PARAMS */
102 struct sof_ipc_pcm_params {
103 	struct sof_ipc_cmd_hdr hdr;
104 	uint32_t comp_id;
105 	uint32_t flags;		/**< generic PCM flags - SOF_PCM_FLAG_ */
106 	uint32_t reserved[2];
107 	struct sof_ipc_stream_params params;
108 } __attribute__((packed, aligned(4)));
109 
110 /* PCM params info reply - SOF_IPC_STREAM_PCM_PARAMS_REPLY */
111 struct sof_ipc_pcm_params_reply {
112 	struct sof_ipc_reply rhdr;
113 	uint32_t comp_id;
114 	uint32_t posn_offset;
115 } __attribute__((packed, aligned(4)));
116 
117 /* free stream - SOF_IPC_STREAM_PCM_PARAMS */
118 struct sof_ipc_stream {
119 	struct sof_ipc_cmd_hdr hdr;
120 	uint32_t comp_id;
121 } __attribute__((packed, aligned(4)));
122 
123 /* flags indicating which time stamps are in sync with each other */
124 #define	SOF_TIME_HOST_SYNC	(1 << 0)
125 #define	SOF_TIME_DAI_SYNC	(1 << 1)
126 #define	SOF_TIME_WALL_SYNC	(1 << 2)
127 #define	SOF_TIME_STAMP_SYNC	(1 << 3)
128 
129 /* flags indicating which time stamps are valid */
130 #define	SOF_TIME_HOST_VALID	(1 << 8)
131 #define	SOF_TIME_DAI_VALID	(1 << 9)
132 #define	SOF_TIME_WALL_VALID	(1 << 10)
133 #define	SOF_TIME_STAMP_VALID	(1 << 11)
134 
135 /* flags indicating time stamps are 64bit else 3use low 32bit */
136 #define	SOF_TIME_HOST_64	(1 << 16)
137 #define	SOF_TIME_DAI_64		(1 << 17)
138 #define	SOF_TIME_WALL_64	(1 << 18)
139 #define	SOF_TIME_STAMP_64	(1 << 19)
140 
141 struct sof_ipc_stream_posn {
142 	struct sof_ipc_reply rhdr;
143 	uint32_t comp_id;	/**< host component ID */
144 	uint32_t flags;		/**< SOF_TIME_ */
145 	uint32_t wallclock_hz;	/**< frequency of wallclock in Hz */
146 	uint32_t timestamp_ns;	/**< resolution of timestamp in ns */
147 	uint64_t host_posn;	/**< host DMA position in bytes */
148 	uint64_t dai_posn;	/**< DAI DMA position in bytes */
149 	uint64_t comp_posn;	/**< comp position in bytes */
150 	uint64_t wallclock;	/**< audio wall clock */
151 	uint64_t timestamp;	/**< system time stamp */
152 	uint32_t xrun_comp_id;	/**< comp ID of XRUN component */
153 	int32_t xrun_size;	/**< XRUN size in bytes */
154 } __attribute__((packed, aligned(4)));
155 
156 #endif /* __IPC_STREAM_H__ */
157