Skip to content

Commit 67ec2a0

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: Add bytes_ext control IPC ops for IPC3
Define and set the get/put/volatile_get control IPC ops for byte controls for IPC3. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20220317175044.1752400-11-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 544ac88 commit 67ec2a0

2 files changed

Lines changed: 188 additions & 180 deletions

File tree

sound/soc/sof/control.c

Lines changed: 17 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,6 @@ static void update_mute_led(struct snd_sof_control *scontrol,
4545
#endif
4646
}
4747

48-
static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
49-
{
50-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
51-
struct snd_soc_component *scomp = scontrol->scomp;
52-
int ret;
53-
54-
if (!scontrol->comp_data_dirty)
55-
return;
56-
57-
if (!pm_runtime_active(scomp->dev))
58-
return;
59-
60-
/* set the ABI header values */
61-
cdata->data->magic = SOF_ABI_MAGIC;
62-
cdata->data->abi = SOF_ABI_VERSION;
63-
64-
/* refresh the component data from DSP */
65-
scontrol->comp_data_dirty = false;
66-
ret = snd_sof_ipc_set_get_comp_data(scontrol, false);
67-
if (ret < 0) {
68-
dev_err(scomp->dev, "Failed to get control data: %d\n", ret);
69-
70-
/* Set the flag to re-try next time to get the data */
71-
scontrol->comp_data_dirty = true;
72-
}
73-
}
74-
7548
int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
7649
struct snd_ctl_elem_value *ucontrol)
7750
{
@@ -221,74 +194,18 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
221194
const unsigned int __user *binary_data,
222195
unsigned int size)
223196
{
224-
struct soc_bytes_ext *be =
225-
(struct soc_bytes_ext *)kcontrol->private_value;
197+
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
226198
struct snd_sof_control *scontrol = be->dobj.private;
227199
struct snd_soc_component *scomp = scontrol->scomp;
228-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
229-
struct snd_ctl_tlv header;
230-
const struct snd_ctl_tlv __user *tlvd =
231-
(const struct snd_ctl_tlv __user *)binary_data;
200+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
201+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
232202

233203
/* make sure we have at least a header */
234204
if (size < sizeof(struct snd_ctl_tlv))
235205
return -EINVAL;
236206

237-
/*
238-
* The beginning of bytes data contains a header from where
239-
* the length (as bytes) is needed to know the correct copy
240-
* length of data from tlvd->tlv.
241-
*/
242-
if (copy_from_user(&header, tlvd, sizeof(struct snd_ctl_tlv)))
243-
return -EFAULT;
244-
245-
/* make sure TLV info is consistent */
246-
if (header.length + sizeof(struct snd_ctl_tlv) > size) {
247-
dev_err_ratelimited(scomp->dev, "error: inconsistent TLV, data %d + header %zu > %d\n",
248-
header.length, sizeof(struct snd_ctl_tlv), size);
249-
return -EINVAL;
250-
}
251-
252-
/* be->max is coming from topology */
253-
if (header.length > be->max) {
254-
dev_err_ratelimited(scomp->dev, "error: Bytes data size %d exceeds max %d.\n",
255-
header.length, be->max);
256-
return -EINVAL;
257-
}
258-
259-
/* Check that header id matches the command */
260-
if (header.numid != cdata->cmd) {
261-
dev_err_ratelimited(scomp->dev,
262-
"error: incorrect numid %d\n",
263-
header.numid);
264-
return -EINVAL;
265-
}
266-
267-
if (copy_from_user(cdata->data, tlvd->tlv, header.length))
268-
return -EFAULT;
269-
270-
if (cdata->data->magic != SOF_ABI_MAGIC) {
271-
dev_err_ratelimited(scomp->dev,
272-
"error: Wrong ABI magic 0x%08x.\n",
273-
cdata->data->magic);
274-
return -EINVAL;
275-
}
276-
277-
if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) {
278-
dev_err_ratelimited(scomp->dev, "error: Incompatible ABI version 0x%08x.\n",
279-
cdata->data->abi);
280-
return -EINVAL;
281-
}
282-
283-
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
284-
if (cdata->data->size > be->max - sizeof(struct sof_abi_hdr)) {
285-
dev_err_ratelimited(scomp->dev, "error: Mismatch in ABI data size (truncated?).\n");
286-
return -EINVAL;
287-
}
288-
289-
/* notify DSP of byte control updates */
290-
if (pm_runtime_active(scomp->dev))
291-
snd_sof_ipc_set_get_comp_data(scontrol, true);
207+
if (tplg_ops->control->bytes_ext_put)
208+
return tplg_ops->control->bytes_ext_put(scontrol, binary_data, size);
292209

293210
return 0;
294211
}
@@ -299,67 +216,24 @@ int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int _
299216
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
300217
struct snd_sof_control *scontrol = be->dobj.private;
301218
struct snd_soc_component *scomp = scontrol->scomp;
302-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
303-
struct snd_ctl_tlv header;
304-
struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data;
305-
size_t data_size;
306-
int ret;
307-
int err;
308-
309-
/*
310-
* Decrement the limit by ext bytes header size to
311-
* ensure the user space buffer is not exceeded.
312-
*/
313-
if (size < sizeof(struct snd_ctl_tlv))
314-
return -ENOSPC;
315-
size -= sizeof(struct snd_ctl_tlv);
219+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
220+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
221+
int ret, err;
316222

317223
ret = pm_runtime_get_sync(scomp->dev);
318224
if (ret < 0 && ret != -EACCES) {
319-
dev_err_ratelimited(scomp->dev, "error: bytes_ext get failed to resume %d\n", ret);
225+
dev_err_ratelimited(scomp->dev, "%s: failed to resume %d\n", __func__, ret);
320226
pm_runtime_put_noidle(scomp->dev);
321227
return ret;
322228
}
323229

324-
/* set the ABI header values */
325-
cdata->data->magic = SOF_ABI_MAGIC;
326-
cdata->data->abi = SOF_ABI_VERSION;
327-
/* get all the component data from DSP */
328-
ret = snd_sof_ipc_set_get_comp_data(scontrol, false);
329-
if (ret < 0)
330-
goto out;
331-
332-
/* check data size doesn't exceed max coming from topology */
333-
if (cdata->data->size > be->max - sizeof(struct sof_abi_hdr)) {
334-
dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %zu.\n",
335-
cdata->data->size,
336-
be->max - sizeof(struct sof_abi_hdr));
337-
ret = -EINVAL;
338-
goto out;
339-
}
340-
341-
data_size = cdata->data->size + sizeof(struct sof_abi_hdr);
230+
if (tplg_ops->control->bytes_ext_volatile_get)
231+
ret = tplg_ops->control->bytes_ext_volatile_get(scontrol, binary_data, size);
342232

343-
/* make sure we don't exceed size provided by user space for data */
344-
if (data_size > size) {
345-
ret = -ENOSPC;
346-
goto out;
347-
}
348-
349-
header.numid = cdata->cmd;
350-
header.length = data_size;
351-
if (copy_to_user(tlvd, &header, sizeof(struct snd_ctl_tlv))) {
352-
ret = -EFAULT;
353-
goto out;
354-
}
355-
356-
if (copy_to_user(tlvd->tlv, cdata->data, data_size))
357-
ret = -EFAULT;
358-
out:
359233
pm_runtime_mark_last_busy(scomp->dev);
360234
err = pm_runtime_put_autosuspend(scomp->dev);
361235
if (err < 0)
362-
dev_err_ratelimited(scomp->dev, "error: bytes_ext get failed to idle %d\n", err);
236+
dev_err_ratelimited(scomp->dev, "%s: failed to idle %d\n", __func__, err);
363237

364238
return ret;
365239
}
@@ -368,51 +242,14 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
368242
unsigned int __user *binary_data,
369243
unsigned int size)
370244
{
371-
struct soc_bytes_ext *be =
372-
(struct soc_bytes_ext *)kcontrol->private_value;
245+
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
373246
struct snd_sof_control *scontrol = be->dobj.private;
374247
struct snd_soc_component *scomp = scontrol->scomp;
375-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
376-
struct snd_ctl_tlv header;
377-
struct snd_ctl_tlv __user *tlvd =
378-
(struct snd_ctl_tlv __user *)binary_data;
379-
size_t data_size;
380-
381-
snd_sof_refresh_control(scontrol);
382-
383-
/*
384-
* Decrement the limit by ext bytes header size to
385-
* ensure the user space buffer is not exceeded.
386-
*/
387-
if (size < sizeof(struct snd_ctl_tlv))
388-
return -ENOSPC;
389-
size -= sizeof(struct snd_ctl_tlv);
390-
391-
/* set the ABI header values */
392-
cdata->data->magic = SOF_ABI_MAGIC;
393-
cdata->data->abi = SOF_ABI_VERSION;
394-
395-
/* check data size doesn't exceed max coming from topology */
396-
if (cdata->data->size > be->max - sizeof(struct sof_abi_hdr)) {
397-
dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %zu.\n",
398-
cdata->data->size,
399-
be->max - sizeof(struct sof_abi_hdr));
400-
return -EINVAL;
401-
}
402-
403-
data_size = cdata->data->size + sizeof(struct sof_abi_hdr);
404-
405-
/* make sure we don't exceed size provided by user space for data */
406-
if (data_size > size)
407-
return -ENOSPC;
408-
409-
header.numid = cdata->cmd;
410-
header.length = data_size;
411-
if (copy_to_user(tlvd, &header, sizeof(struct snd_ctl_tlv)))
412-
return -EFAULT;
248+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
249+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
413250

414-
if (copy_to_user(tlvd->tlv, cdata->data, data_size))
415-
return -EFAULT;
251+
if (tplg_ops->control->bytes_ext_get)
252+
return tplg_ops->control->bytes_ext_get(scontrol, binary_data, size);
416253

417254
return 0;
418255
}

0 commit comments

Comments
 (0)