Skip to content

Commit

Permalink
ASoC: SOF: Add bytes_get/put control IPC ops for IPC3
Browse files Browse the repository at this point in the history
Define and set the bytes_get/put IPC control ops for IPC3.

Signed-off-by: Ranjani Sridharan <[email protected]>
Reviewed-by: Péter Ujfalusi <[email protected]>
Reviewed-by: Pierre-Louis Bossart <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
ranj063 authored and broonie committed Mar 18, 2022
1 parent 049307a commit 544ac88
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 54 deletions.
64 changes: 10 additions & 54 deletions sound/soc/sof/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,73 +190,29 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct soc_bytes_ext *be =
(struct soc_bytes_ext *)kcontrol->private_value;
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size;

snd_sof_refresh_control(scontrol);

if (be->max > sizeof(ucontrol->value.bytes.data)) {
dev_err_ratelimited(scomp->dev,
"error: data max %d exceeds ucontrol data array size\n",
be->max);
return -EINVAL;
}

/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
if (data->size > be->max - sizeof(*data)) {
dev_err_ratelimited(scomp->dev,
"error: %u bytes of control data is invalid, max is %zu\n",
data->size, be->max - sizeof(*data));
return -EINVAL;
}

size = data->size + sizeof(*data);
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;

/* copy back to kcontrol */
memcpy(ucontrol->value.bytes.data, data, size);
if (tplg_ops->control->bytes_get)
return tplg_ops->control->bytes_get(scontrol, ucontrol);

return 0;
}

int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct soc_bytes_ext *be =
(struct soc_bytes_ext *)kcontrol->private_value;
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size;

if (be->max > sizeof(ucontrol->value.bytes.data)) {
dev_err_ratelimited(scomp->dev,
"error: data max %d exceeds ucontrol data array size\n",
be->max);
return -EINVAL;
}

/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
if (data->size > be->max - sizeof(*data)) {
dev_err_ratelimited(scomp->dev,
"error: data size too big %u bytes max is %zu\n",
data->size, be->max - sizeof(*data));
return -EINVAL;
}

size = data->size + sizeof(*data);

/* copy from kcontrol */
memcpy(data, ucontrol->value.bytes.data, size);
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;

/* notify DSP of byte control updates */
if (pm_runtime_active(scomp->dev))
snd_sof_ipc_set_get_comp_data(scontrol, true);
if (tplg_ops->control->bytes_put)
return tplg_ops->control->bytes_put(scontrol, ucontrol);

return 0;
}
Expand Down
67 changes: 67 additions & 0 deletions sound/soc/sof/ipc3-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,71 @@ static bool sof_ipc3_enum_put(struct snd_sof_control *scontrol,
return change;
}

static int sof_ipc3_bytes_get(struct snd_sof_control *scontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_abi_hdr *data = cdata->data;
size_t size;

snd_sof_refresh_control(scontrol);

if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
dev_err_ratelimited(scomp->dev, "data max %zu exceeds ucontrol data array size\n",
scontrol->max_size);
return -EINVAL;
}

/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
if (data->size > scontrol->max_size - sizeof(*data)) {
dev_err_ratelimited(scomp->dev,
"%u bytes of control data is invalid, max is %zu\n",
data->size, scontrol->max_size - sizeof(*data));
return -EINVAL;
}

size = data->size + sizeof(*data);

/* copy back to kcontrol */
memcpy(ucontrol->value.bytes.data, data, size);

return 0;
}

static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_abi_hdr *data = cdata->data;
size_t size;

if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
dev_err_ratelimited(scomp->dev, "data max %zu exceeds ucontrol data array size\n",
scontrol->max_size);
return -EINVAL;
}

/* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */
if (data->size > scontrol->max_size - sizeof(*data)) {
dev_err_ratelimited(scomp->dev, "data size too big %u bytes max is %zu\n",
data->size, scontrol->max_size - sizeof(*data));
return -EINVAL;
}

size = data->size + sizeof(*data);

/* copy from kcontrol */
memcpy(data, ucontrol->value.bytes.data, size);

/* notify DSP of byte control updates */
if (pm_runtime_active(scomp->dev))
return snd_sof_ipc_set_get_comp_data(scontrol, true);

return 0;
}

static void snd_sof_update_control(struct snd_sof_control *scontrol,
struct sof_ipc_ctrl_data *cdata)
{
Expand Down Expand Up @@ -352,5 +417,7 @@ const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
.switch_get = sof_ipc3_switch_get,
.enum_put = sof_ipc3_enum_put,
.enum_get = sof_ipc3_enum_get,
.bytes_put = sof_ipc3_bytes_put,
.bytes_get = sof_ipc3_bytes_get,
.update = sof_ipc3_control_update,
};

0 comments on commit 544ac88

Please sign in to comment.