1
2
3
4
5
6
7
8
9
10
11#include "sof-priv.h"
12#include "probe.h"
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28int sof_ipc_probe_init(struct snd_sof_dev *sdev,
29 u32 stream_tag, size_t buffer_size)
30{
31 struct sof_ipc_probe_dma_add_params *msg;
32 struct sof_ipc_reply reply;
33 size_t size = struct_size(msg, dma, 1);
34 int ret;
35
36 msg = kmalloc(size, GFP_KERNEL);
37 if (!msg)
38 return -ENOMEM;
39 msg->hdr.size = size;
40 msg->hdr.cmd = SOF_IPC_GLB_PROBE | SOF_IPC_PROBE_INIT;
41 msg->num_elems = 1;
42 msg->dma[0].stream_tag = stream_tag;
43 msg->dma[0].dma_buffer_size = buffer_size;
44
45 ret = sof_ipc_tx_message(sdev->ipc, msg->hdr.cmd, msg, msg->hdr.size,
46 &reply, sizeof(reply));
47 kfree(msg);
48 return ret;
49}
50EXPORT_SYMBOL(sof_ipc_probe_init);
51
52
53
54
55
56
57
58
59
60int sof_ipc_probe_deinit(struct snd_sof_dev *sdev)
61{
62 struct sof_ipc_cmd_hdr msg;
63 struct sof_ipc_reply reply;
64
65 msg.size = sizeof(msg);
66 msg.cmd = SOF_IPC_GLB_PROBE | SOF_IPC_PROBE_DEINIT;
67
68 return sof_ipc_tx_message(sdev->ipc, msg.cmd, &msg, msg.size,
69 &reply, sizeof(reply));
70}
71EXPORT_SYMBOL(sof_ipc_probe_deinit);
72
73static int sof_ipc_probe_info(struct snd_sof_dev *sdev, unsigned int cmd,
74 void **params, size_t *num_params)
75{
76 struct sof_ipc_probe_info_params msg = {{{0}}};
77 struct sof_ipc_probe_info_params *reply;
78 size_t bytes;
79 int ret;
80
81 *params = NULL;
82 *num_params = 0;
83
84 reply = kzalloc(SOF_IPC_MSG_MAX_SIZE, GFP_KERNEL);
85 if (!reply)
86 return -ENOMEM;
87 msg.rhdr.hdr.size = sizeof(msg);
88 msg.rhdr.hdr.cmd = SOF_IPC_GLB_PROBE | cmd;
89
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)
93 goto exit;
94
95 if (!reply->num_elems)
96 goto exit;
97
98 if (cmd == SOF_IPC_PROBE_DMA_INFO)
99 bytes = sizeof(reply->dma[0]);
100 else
101 bytes = sizeof(reply->desc[0]);
102 bytes *= reply->num_elems;
103 *params = kmemdup(&reply->dma[0], bytes, GFP_KERNEL);
104 if (!*params) {
105 ret = -ENOMEM;
106 goto exit;
107 }
108 *num_params = reply->num_elems;
109
110exit:
111 kfree(reply);
112 return ret;
113}
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130int sof_ipc_probe_dma_info(struct snd_sof_dev *sdev,
131 struct sof_probe_dma **dma, size_t *num_dma)
132{
133 return sof_ipc_probe_info(sdev, SOF_IPC_PROBE_DMA_INFO,
134 (void **)dma, num_dma);
135}
136EXPORT_SYMBOL(sof_ipc_probe_dma_info);
137
138
139
140
141
142
143
144
145
146
147
148
149int sof_ipc_probe_dma_add(struct snd_sof_dev *sdev,
150 struct sof_probe_dma *dma, size_t num_dma)
151{
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);
155 int ret;
156
157 msg = kmalloc(size, GFP_KERNEL);
158 if (!msg)
159 return -ENOMEM;
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));
164
165 ret = sof_ipc_tx_message(sdev->ipc, msg->hdr.cmd, msg, msg->hdr.size,
166 &reply, sizeof(reply));
167 kfree(msg);
168 return ret;
169}
170EXPORT_SYMBOL(sof_ipc_probe_dma_add);
171
172
173
174
175
176
177
178
179
180
181
182
183int sof_ipc_probe_dma_remove(struct snd_sof_dev *sdev,
184 unsigned int *stream_tag, size_t num_stream_tag)
185{
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);
189 int ret;
190
191 msg = kmalloc(size, GFP_KERNEL);
192 if (!msg)
193 return -ENOMEM;
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));
198
199 ret = sof_ipc_tx_message(sdev->ipc, msg->hdr.cmd, msg, msg->hdr.size,
200 &reply, sizeof(reply));
201 kfree(msg);
202 return ret;
203}
204EXPORT_SYMBOL(sof_ipc_probe_dma_remove);
205
206
207
208
209
210
211
212
213
214
215
216int sof_ipc_probe_points_info(struct snd_sof_dev *sdev,
217 struct sof_probe_point_desc **desc, size_t *num_desc)
218{
219 return sof_ipc_probe_info(sdev, SOF_IPC_PROBE_POINT_INFO,
220 (void **)desc, num_desc);
221}
222EXPORT_SYMBOL(sof_ipc_probe_points_info);
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237int sof_ipc_probe_points_add(struct snd_sof_dev *sdev,
238 struct sof_probe_point_desc *desc, size_t num_desc)
239{
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);
243 int ret;
244
245 msg = kmalloc(size, GFP_KERNEL);
246 if (!msg)
247 return -ENOMEM;
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));
252
253 ret = sof_ipc_tx_message(sdev->ipc, msg->hdr.cmd, msg, msg->hdr.size,
254 &reply, sizeof(reply));
255 kfree(msg);
256 return ret;
257}
258EXPORT_SYMBOL(sof_ipc_probe_points_add);
259
260
261
262
263
264
265
266
267
268
269int sof_ipc_probe_points_remove(struct snd_sof_dev *sdev,
270 unsigned int *buffer_id, size_t num_buffer_id)
271{
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);
275 int ret;
276
277 msg = kmalloc(size, GFP_KERNEL);
278 if (!msg)
279 return -ENOMEM;
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));
284
285 ret = sof_ipc_tx_message(sdev->ipc, msg->hdr.cmd, msg, msg->hdr.size,
286 &reply, sizeof(reply));
287 kfree(msg);
288 return ret;
289}
290EXPORT_SYMBOL(sof_ipc_probe_points_remove);
291