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(cdev, &msg, NULL, 0);
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;
149 msg.primary = mentry->id;
150 msg.primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_DELETE_INSTANCE);
151 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
152 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
153 msg.extension = SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(INVALID_PIPELINE_ID);
154 msg.extension |= SOF_IPC4_MOD_EXT_CORE_ID(0);
159 return sof_client_ipc_tx_message(cdev, &msg, NULL, 0);
163 * ipc4_probes_points_info - retrieve list of active probe points
164 * @cdev: SOF client device
165 * @desc: Returned list of active probes
166 * @num_desc: Returned count of active probes
167 * @return: 0 on success, negative error code on error
169 * Dummy implementation returning empty list of probes.
171 static int ipc4_probes_points_info(struct sof_client_dev *cdev,
172 struct sof_probe_point_desc **desc,
175 /* TODO: Firmware side implementation needed first */
182 * ipc4_probes_points_add - connect specified probes
183 * @cdev: SOF client device
184 * @desc: List of probe points to connect
185 * @num_desc: Number of elements in @desc
186 * @return: 0 on success, negative error code on error
188 * Translates the generic probe point presentation to an IPC4
189 * message to dynamically connect the provided set of endpoints.
191 static int ipc4_probes_points_add(struct sof_client_dev *cdev,
192 struct sof_probe_point_desc *desc,
195 struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
196 struct sof_ipc4_probe_point *points;
197 struct sof_ipc4_msg msg;
200 /* The sof_probe_point_desc and sof_ipc4_probe_point structs
201 * are of same size and even the integers are the same in the
202 * same order, and similar meaning, but since there is no
203 * performance issue I wrote the conversion explicitly open for
204 * future development.
206 points = kcalloc(num_desc, sizeof(*points), GFP_KERNEL);
210 for (i = 0; i < num_desc; i++) {
211 points[i].point_id = desc[i].buffer_id;
212 points[i].purpose = desc[i].purpose;
213 points[i].stream_tag = desc[i].stream_tag;
216 msg.primary = mentry->id;
217 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
218 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
220 msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_PROBE_POINTS);
222 msg.data_size = sizeof(*points) * num_desc;
223 msg.data_ptr = points;
225 ret = sof_client_ipc_set_get_data(cdev, &msg, true);
233 * ipc4_probes_points_remove - disconnect specified probes
234 * @cdev: SOF client device
235 * @buffer_id: List of probe points to disconnect
236 * @num_buffer_id: Number of elements in @desc
237 * @return: 0 on success, negative error code on error
239 * Converts the generic buffer_id to IPC4 probe_point_id and remove
240 * the probe points with an IPC4 for message.
242 static int ipc4_probes_points_remove(struct sof_client_dev *cdev,
243 unsigned int *buffer_id, size_t num_buffer_id)
245 struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
246 struct sof_ipc4_msg msg;
247 u32 *probe_point_ids;
250 probe_point_ids = kcalloc(num_buffer_id, sizeof(*probe_point_ids),
252 if (!probe_point_ids)
255 for (i = 0; i < num_buffer_id; i++)
256 probe_point_ids[i] = buffer_id[i];
258 msg.primary = mentry->id;
259 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
260 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
263 SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_PROBE_POINTS_DISCONNECT);
265 msg.data_size = num_buffer_id * sizeof(*probe_point_ids);
266 msg.data_ptr = probe_point_ids;
268 ret = sof_client_ipc_set_get_data(cdev, &msg, true);
270 kfree(probe_point_ids);
275 const struct sof_probes_ipc_ops ipc4_probe_ops = {
276 .init = ipc4_probes_init,
277 .deinit = ipc4_probes_deinit,
278 .points_info = ipc4_probes_points_info,
279 .points_add = ipc4_probes_points_add,
280 .points_remove = ipc4_probes_points_remove,