1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright(c) 2019-2022 Intel Corporation. All rights reserved.
5 // Author: Jyri Sarha <jyri.sarha@intel.com>
9 #include <sound/sof/ipc4/header.h>
10 #include <uapi/sound/sof/header.h>
12 #include "ipc4-priv.h"
13 #include "sof-client.h"
14 #include "sof-client-probes.h"
16 enum sof_ipc4_dma_type {
17 SOF_IPC4_DMA_HDA_HOST_OUTPUT = 0,
18 SOF_IPC4_DMA_HDA_HOST_INPUT = 1,
19 SOF_IPC4_DMA_HDA_LINK_OUTPUT = 8,
20 SOF_IPC4_DMA_HDA_LINK_INPUT = 9,
21 SOF_IPC4_DMA_DMIC_LINK_INPUT = 11,
22 SOF_IPC4_DMA_I2S_LINK_OUTPUT = 12,
23 SOF_IPC4_DMA_I2S_LINK_INPUT = 13,
26 enum sof_ipc4_probe_runtime_param {
27 SOF_IPC4_PROBE_INJECTION_DMA = 1,
28 SOF_IPC4_PROBE_INJECTION_DMA_DETACH,
29 SOF_IPC4_PROBE_POINTS,
30 SOF_IPC4_PROBE_POINTS_DISCONNECT,
33 struct sof_ipc4_probe_gtw_cfg {
36 } __packed __aligned(4);
38 #define SOF_IPC4_PROBE_NODE_ID_INDEX(x) ((x) & GENMASK(7, 0))
39 #define SOF_IPC4_PROBE_NODE_ID_TYPE(x) (((x) << 8) & GENMASK(12, 8))
41 struct sof_ipc4_probe_cfg {
42 struct sof_ipc4_base_module_cfg base;
43 struct sof_ipc4_probe_gtw_cfg gtw_cfg;
44 } __packed __aligned(4);
46 enum sof_ipc4_probe_type {
47 SOF_IPC4_PROBE_TYPE_INPUT = 0,
48 SOF_IPC4_PROBE_TYPE_OUTPUT,
49 SOF_IPC4_PROBE_TYPE_INTERNAL
52 struct sof_ipc4_probe_point {
56 } __packed __aligned(4);
58 #define INVALID_PIPELINE_ID 0xFF
61 * sof_ipc4_probe_get_module_info - Get IPC4 module info for probe module
62 * @cdev: SOF client device
63 * @return: Pointer to IPC4 probe module info
65 * Look up the IPC4 probe module info based on the hard coded uuid and
66 * store the value for the future calls.
68 static struct sof_man4_module *sof_ipc4_probe_get_module_info(struct sof_client_dev *cdev)
70 struct sof_probes_priv *priv = cdev->data;
71 struct device *dev = &cdev->auxdev.dev;
72 static const guid_t probe_uuid =
73 GUID_INIT(0x7CAD0808, 0xAB10, 0xCD23,
74 0xEF, 0x45, 0x12, 0xAB, 0x34, 0xCD, 0x56, 0xEF);
76 if (!priv->ipc_priv) {
77 struct sof_ipc4_fw_module *fw_module =
78 sof_client_ipc4_find_module(cdev, &probe_uuid);
81 dev_err(dev, "%s: no matching uuid found", __func__);
85 priv->ipc_priv = &fw_module->man4_module_entry;
88 return (struct sof_man4_module *)priv->ipc_priv;
92 * ipc4_probes_init - initialize data probing
93 * @cdev: SOF client device
94 * @stream_tag: Extractor stream tag
95 * @buffer_size: DMA buffer size to set for extractor
96 * @return: 0 on success, negative error code on error
98 * Host chooses whether extraction is supported or not by providing
99 * valid stream tag to DSP. Once specified, stream described by that
100 * tag will be tied to DSP for extraction for the entire lifetime of
103 * Probing is initialized only once and each INIT request must be
104 * matched by DEINIT call.
106 static int ipc4_probes_init(struct sof_client_dev *cdev, u32 stream_tag,
109 struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
110 struct sof_ipc4_msg msg;
111 struct sof_ipc4_probe_cfg cfg;
116 memset(&cfg, '\0', sizeof(cfg));
117 cfg.gtw_cfg.node_id = SOF_IPC4_PROBE_NODE_ID_INDEX(stream_tag - 1) |
118 SOF_IPC4_PROBE_NODE_ID_TYPE(SOF_IPC4_DMA_HDA_HOST_INPUT);
120 cfg.gtw_cfg.dma_buffer_size = buffer_size;
122 msg.primary = mentry->id;
123 msg.primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_INIT_INSTANCE);
124 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
125 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
126 msg.extension = SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(INVALID_PIPELINE_ID);
127 msg.extension |= SOF_IPC4_MOD_EXT_CORE_ID(0);
129 msg.data_size = sizeof(cfg);
132 return sof_client_ipc_tx_message_no_reply(cdev, &msg);
136 * ipc4_probes_deinit - cleanup after data probing
137 * @cdev: SOF client device
138 * @return: 0 on success, negative error code on error
140 * Host sends DEINIT request to free previously initialized probe
141 * on DSP side once it is no longer needed. DEINIT only when there
142 * are no probes connected and with all injectors detached.
144 static int ipc4_probes_deinit(struct sof_client_dev *cdev)
146 struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
147 struct sof_ipc4_msg msg;
152 msg.primary = mentry->id;
153 msg.primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_DELETE_INSTANCE);
154 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
155 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
156 msg.extension = SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(INVALID_PIPELINE_ID);
157 msg.extension |= SOF_IPC4_MOD_EXT_CORE_ID(0);
162 return sof_client_ipc_tx_message_no_reply(cdev, &msg);
166 * ipc4_probes_points_info - retrieve list of active probe points
167 * @cdev: SOF client device
168 * @desc: Returned list of active probes
169 * @num_desc: Returned count of active probes
170 * @return: 0 on success, negative error code on error
172 * Dummy implementation returning empty list of probes.
174 static int ipc4_probes_points_info(struct sof_client_dev *cdev,
175 struct sof_probe_point_desc **desc,
178 /* TODO: Firmware side implementation needed first */
185 * ipc4_probes_points_add - connect specified probes
186 * @cdev: SOF client device
187 * @desc: List of probe points to connect
188 * @num_desc: Number of elements in @desc
189 * @return: 0 on success, negative error code on error
191 * Translates the generic probe point presentation to an IPC4
192 * message to dynamically connect the provided set of endpoints.
194 static int ipc4_probes_points_add(struct sof_client_dev *cdev,
195 struct sof_probe_point_desc *desc,
198 struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
199 struct sof_ipc4_probe_point *points;
200 struct sof_ipc4_msg msg;
206 /* The sof_probe_point_desc and sof_ipc4_probe_point structs
207 * are of same size and even the integers are the same in the
208 * same order, and similar meaning, but since there is no
209 * performance issue I wrote the conversion explicitly open for
210 * future development.
212 points = kcalloc(num_desc, sizeof(*points), GFP_KERNEL);
216 for (i = 0; i < num_desc; i++) {
217 points[i].point_id = desc[i].buffer_id;
218 points[i].purpose = desc[i].purpose;
219 points[i].stream_tag = desc[i].stream_tag;
222 msg.primary = mentry->id;
223 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
224 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
226 msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_PROBE_POINTS);
228 msg.data_size = sizeof(*points) * num_desc;
229 msg.data_ptr = points;
231 ret = sof_client_ipc_set_get_data(cdev, &msg, true);
239 * ipc4_probes_points_remove - disconnect specified probes
240 * @cdev: SOF client device
241 * @buffer_id: List of probe points to disconnect
242 * @num_buffer_id: Number of elements in @desc
243 * @return: 0 on success, negative error code on error
245 * Converts the generic buffer_id to IPC4 probe_point_id and remove
246 * the probe points with an IPC4 for message.
248 static int ipc4_probes_points_remove(struct sof_client_dev *cdev,
249 unsigned int *buffer_id, size_t num_buffer_id)
251 struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
252 struct sof_ipc4_msg msg;
253 u32 *probe_point_ids;
259 probe_point_ids = kcalloc(num_buffer_id, sizeof(*probe_point_ids),
261 if (!probe_point_ids)
264 for (i = 0; i < num_buffer_id; i++)
265 probe_point_ids[i] = buffer_id[i];
267 msg.primary = mentry->id;
268 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
269 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
272 SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_PROBE_POINTS_DISCONNECT);
274 msg.data_size = num_buffer_id * sizeof(*probe_point_ids);
275 msg.data_ptr = probe_point_ids;
277 ret = sof_client_ipc_set_get_data(cdev, &msg, true);
279 kfree(probe_point_ids);
284 const struct sof_probes_ipc_ops ipc4_probe_ops = {
285 .init = ipc4_probes_init,
286 .deinit = ipc4_probes_deinit,
287 .points_info = ipc4_probes_points_info,
288 .points_add = ipc4_probes_points_add,
289 .points_remove = ipc4_probes_points_remove,