1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2019-2020 Intel Corporation. All rights reserved.
8 // Author: Cezary Rojewski <cezary.rojewski@intel.com>
15 * sof_ipc_probe_init - initialize data probing
16 * @sdev: SOF sound device
17 * @stream_tag: Extractor stream tag
18 * @buffer_size: DMA buffer size to set for extractor
20 * Host chooses whether extraction is supported or not by providing
21 * valid stream tag to DSP. Once specified, stream described by that
22 * tag will be tied to DSP for extraction for the entire lifetime of
25 * Probing is initialized only once and each INIT request must be
26 * matched by DEINIT call.
28 int sof_ipc_probe_init(struct snd_sof_dev
*sdev
,
29 u32 stream_tag
, size_t buffer_size
)
31 struct sof_ipc_probe_dma_add_params
*msg
;
32 struct sof_ipc_reply reply
;
33 size_t size
= struct_size(msg
, dma
, 1);
36 msg
= kmalloc(size
, GFP_KERNEL
);
40 msg
->hdr
.cmd
= SOF_IPC_GLB_PROBE
| SOF_IPC_PROBE_INIT
;
42 msg
->dma
[0].stream_tag
= stream_tag
;
43 msg
->dma
[0].dma_buffer_size
= buffer_size
;
45 ret
= sof_ipc_tx_message(sdev
->ipc
, msg
->hdr
.cmd
, msg
, msg
->hdr
.size
,
46 &reply
, sizeof(reply
));
50 EXPORT_SYMBOL(sof_ipc_probe_init
);
53 * sof_ipc_probe_deinit - cleanup after data probing
54 * @sdev: SOF sound device
56 * Host sends DEINIT request to free previously initialized probe
57 * on DSP side once it is no longer needed. DEINIT only when there
58 * are no probes connected and with all injectors detached.
60 int sof_ipc_probe_deinit(struct snd_sof_dev
*sdev
)
62 struct sof_ipc_cmd_hdr msg
;
63 struct sof_ipc_reply reply
;
65 msg
.size
= sizeof(msg
);
66 msg
.cmd
= SOF_IPC_GLB_PROBE
| SOF_IPC_PROBE_DEINIT
;
68 return sof_ipc_tx_message(sdev
->ipc
, msg
.cmd
, &msg
, msg
.size
,
69 &reply
, sizeof(reply
));
71 EXPORT_SYMBOL(sof_ipc_probe_deinit
);
73 static int sof_ipc_probe_info(struct snd_sof_dev
*sdev
, unsigned int cmd
,
74 void **params
, size_t *num_params
)
76 struct sof_ipc_probe_info_params msg
= {{{0}}};
77 struct sof_ipc_probe_info_params
*reply
;
84 reply
= kzalloc(SOF_IPC_MSG_MAX_SIZE
, GFP_KERNEL
);
87 msg
.rhdr
.hdr
.size
= sizeof(msg
);
88 msg
.rhdr
.hdr
.cmd
= SOF_IPC_GLB_PROBE
| cmd
;
90 ret
= sof_ipc_tx_message(sdev
->ipc
, msg
.rhdr
.hdr
.cmd
, &msg
,
91 msg
.rhdr
.hdr
.size
, reply
, SOF_IPC_MSG_MAX_SIZE
);
92 if (ret
< 0 || reply
->rhdr
.error
< 0)
95 if (!reply
->num_elems
)
98 if (cmd
== SOF_IPC_PROBE_DMA_INFO
)
99 bytes
= sizeof(reply
->dma
[0]);
101 bytes
= sizeof(reply
->desc
[0]);
102 bytes
*= reply
->num_elems
;
103 *params
= kmemdup(&reply
->dma
[0], bytes
, GFP_KERNEL
);
108 *num_params
= reply
->num_elems
;
116 * sof_ipc_probe_dma_info - retrieve list of active injection dmas
117 * @sdev: SOF sound device
118 * @dma: Returned list of active dmas
119 * @num_dma: Returned count of active dmas
121 * Host sends DMA_INFO request to obtain list of injection dmas it
122 * can use to transfer data over with.
124 * Note that list contains only injection dmas as there is only one
125 * extractor (dma) and it is always assigned on probing init.
126 * DSP knows exactly where data from extraction probes is going to,
127 * which is not the case for injection where multiple streams
130 int sof_ipc_probe_dma_info(struct snd_sof_dev
*sdev
,
131 struct sof_probe_dma
**dma
, size_t *num_dma
)
133 return sof_ipc_probe_info(sdev
, SOF_IPC_PROBE_DMA_INFO
,
134 (void **)dma
, num_dma
);
136 EXPORT_SYMBOL(sof_ipc_probe_dma_info
);
139 * sof_ipc_probe_dma_add - attach to specified dmas
140 * @sdev: SOF sound device
141 * @dma: List of streams (dmas) to attach to
142 * @num_dma: Number of elements in @dma
144 * Contrary to extraction, injection streams are never assigned
145 * on init. Before attempting any data injection, host is responsible
146 * for specifying streams which will be later used to transfer data
147 * to connected probe points.
149 int sof_ipc_probe_dma_add(struct snd_sof_dev
*sdev
,
150 struct sof_probe_dma
*dma
, size_t num_dma
)
152 struct sof_ipc_probe_dma_add_params
*msg
;
153 struct sof_ipc_reply reply
;
154 size_t size
= struct_size(msg
, dma
, num_dma
);
157 msg
= kmalloc(size
, GFP_KERNEL
);
160 msg
->hdr
.size
= size
;
161 msg
->num_elems
= num_dma
;
162 msg
->hdr
.cmd
= SOF_IPC_GLB_PROBE
| SOF_IPC_PROBE_DMA_ADD
;
163 memcpy(&msg
->dma
[0], dma
, size
- sizeof(*msg
));
165 ret
= sof_ipc_tx_message(sdev
->ipc
, msg
->hdr
.cmd
, msg
, msg
->hdr
.size
,
166 &reply
, sizeof(reply
));
170 EXPORT_SYMBOL(sof_ipc_probe_dma_add
);
173 * sof_ipc_probe_dma_remove - detach from specified dmas
174 * @sdev: SOF sound device
175 * @stream_tag: List of stream tags to detach from
176 * @num_stream_tag: Number of elements in @stream_tag
178 * Host sends DMA_REMOVE request to free previously attached stream
179 * from being occupied for injection. Each detach operation should
180 * match equivalent DMA_ADD. Detach only when all probes tied to
181 * given stream have been disconnected.
183 int sof_ipc_probe_dma_remove(struct snd_sof_dev
*sdev
,
184 unsigned int *stream_tag
, size_t num_stream_tag
)
186 struct sof_ipc_probe_dma_remove_params
*msg
;
187 struct sof_ipc_reply reply
;
188 size_t size
= struct_size(msg
, stream_tag
, num_stream_tag
);
191 msg
= kmalloc(size
, GFP_KERNEL
);
194 msg
->hdr
.size
= size
;
195 msg
->num_elems
= num_stream_tag
;
196 msg
->hdr
.cmd
= SOF_IPC_GLB_PROBE
| SOF_IPC_PROBE_DMA_REMOVE
;
197 memcpy(&msg
->stream_tag
[0], stream_tag
, size
- sizeof(*msg
));
199 ret
= sof_ipc_tx_message(sdev
->ipc
, msg
->hdr
.cmd
, msg
, msg
->hdr
.size
,
200 &reply
, sizeof(reply
));
204 EXPORT_SYMBOL(sof_ipc_probe_dma_remove
);
207 * sof_ipc_probe_points_info - retrieve list of active probe points
208 * @sdev: SOF sound device
209 * @desc: Returned list of active probes
210 * @num_desc: Returned count of active probes
212 * Host sends PROBE_POINT_INFO request to obtain list of active probe
213 * points, valid for disconnection when given probe is no longer
216 int sof_ipc_probe_points_info(struct snd_sof_dev
*sdev
,
217 struct sof_probe_point_desc
**desc
, size_t *num_desc
)
219 return sof_ipc_probe_info(sdev
, SOF_IPC_PROBE_POINT_INFO
,
220 (void **)desc
, num_desc
);
222 EXPORT_SYMBOL(sof_ipc_probe_points_info
);
225 * sof_ipc_probe_points_add - connect specified probes
226 * @sdev: SOF sound device
227 * @desc: List of probe points to connect
228 * @num_desc: Number of elements in @desc
230 * Dynamically connects to provided set of endpoints. Immediately
231 * after connection is established, host must be prepared to
232 * transfer data from or to target stream given the probing purpose.
234 * Each probe point should be removed using PROBE_POINT_REMOVE
235 * request when no longer needed.
237 int sof_ipc_probe_points_add(struct snd_sof_dev
*sdev
,
238 struct sof_probe_point_desc
*desc
, size_t num_desc
)
240 struct sof_ipc_probe_point_add_params
*msg
;
241 struct sof_ipc_reply reply
;
242 size_t size
= struct_size(msg
, desc
, num_desc
);
245 msg
= kmalloc(size
, GFP_KERNEL
);
248 msg
->hdr
.size
= size
;
249 msg
->num_elems
= num_desc
;
250 msg
->hdr
.cmd
= SOF_IPC_GLB_PROBE
| SOF_IPC_PROBE_POINT_ADD
;
251 memcpy(&msg
->desc
[0], desc
, size
- sizeof(*msg
));
253 ret
= sof_ipc_tx_message(sdev
->ipc
, msg
->hdr
.cmd
, msg
, msg
->hdr
.size
,
254 &reply
, sizeof(reply
));
258 EXPORT_SYMBOL(sof_ipc_probe_points_add
);
261 * sof_ipc_probe_points_remove - disconnect specified probes
262 * @sdev: SOF sound device
263 * @buffer_id: List of probe points to disconnect
264 * @num_buffer_id: Number of elements in @desc
266 * Removes previously connected probes from list of active probe
267 * points and frees all resources on DSP side.
269 int sof_ipc_probe_points_remove(struct snd_sof_dev
*sdev
,
270 unsigned int *buffer_id
, size_t num_buffer_id
)
272 struct sof_ipc_probe_point_remove_params
*msg
;
273 struct sof_ipc_reply reply
;
274 size_t size
= struct_size(msg
, buffer_id
, num_buffer_id
);
277 msg
= kmalloc(size
, GFP_KERNEL
);
280 msg
->hdr
.size
= size
;
281 msg
->num_elems
= num_buffer_id
;
282 msg
->hdr
.cmd
= SOF_IPC_GLB_PROBE
| SOF_IPC_PROBE_POINT_REMOVE
;
283 memcpy(&msg
->buffer_id
[0], buffer_id
, size
- sizeof(*msg
));
285 ret
= sof_ipc_tx_message(sdev
->ipc
, msg
->hdr
.cmd
, msg
, msg
->hdr
.size
,
286 &reply
, sizeof(reply
));
290 EXPORT_SYMBOL(sof_ipc_probe_points_remove
);