Commit e238b68e authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Mark Brown

ASoC: SOF: ipc4-topology: Correct data structures for the GAIN module

Move the base_cfg to struct sof_ipc4_gain_data. This struct
describes the message payload passed to the firmware via the mailbox.

It is not wise to be 'clever' and try to use the first part of a struct
as IPC message without marking the message section as packed and aligned.
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/20231129131411.27516-3-peter.ujfalusi@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent c4476369
...@@ -89,7 +89,7 @@ sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidge ...@@ -89,7 +89,7 @@ sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidge
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data; struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
struct sof_ipc4_gain *gain = swidget->private; struct sof_ipc4_gain *gain = swidget->private;
struct sof_ipc4_msg *msg = &cdata->msg; struct sof_ipc4_msg *msg = &cdata->msg;
struct sof_ipc4_gain_data data; struct sof_ipc4_gain_params params;
bool all_channels_equal = true; bool all_channels_equal = true;
u32 value; u32 value;
int ret, i; int ret, i;
...@@ -109,20 +109,20 @@ sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidge ...@@ -109,20 +109,20 @@ sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidge
*/ */
for (i = 0; i < scontrol->num_channels; i++) { for (i = 0; i < scontrol->num_channels; i++) {
if (all_channels_equal) { if (all_channels_equal) {
data.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK; params.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
data.init_val = cdata->chanv[0].value; params.init_val = cdata->chanv[0].value;
} else { } else {
data.channels = cdata->chanv[i].channel; params.channels = cdata->chanv[i].channel;
data.init_val = cdata->chanv[i].value; params.init_val = cdata->chanv[i].value;
} }
/* set curve type and duration from topology */ /* set curve type and duration from topology */
data.curve_duration_l = gain->data.curve_duration_l; params.curve_duration_l = gain->data.params.curve_duration_l;
data.curve_duration_h = gain->data.curve_duration_h; params.curve_duration_h = gain->data.params.curve_duration_h;
data.curve_type = gain->data.curve_type; params.curve_type = gain->data.params.curve_type;
msg->data_ptr = &data; msg->data_ptr = &params;
msg->data_size = sizeof(data); msg->data_size = sizeof(params);
ret = sof_ipc4_set_get_kcontrol_data(scontrol, true, lock); ret = sof_ipc4_set_get_kcontrol_data(scontrol, true, lock);
msg->data_ptr = NULL; msg->data_ptr = NULL;
......
...@@ -130,12 +130,12 @@ static const struct sof_topology_token comp_ext_tokens[] = { ...@@ -130,12 +130,12 @@ static const struct sof_topology_token comp_ext_tokens[] = {
static const struct sof_topology_token gain_tokens[] = { static const struct sof_topology_token gain_tokens[] = {
{SOF_TKN_GAIN_RAMP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD, {SOF_TKN_GAIN_RAMP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
get_token_u32, offsetof(struct sof_ipc4_gain_data, curve_type)}, get_token_u32, offsetof(struct sof_ipc4_gain_params, curve_type)},
{SOF_TKN_GAIN_RAMP_DURATION, {SOF_TKN_GAIN_RAMP_DURATION,
SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc4_gain_data, curve_duration_l)}, offsetof(struct sof_ipc4_gain_params, curve_duration_l)},
{SOF_TKN_GAIN_VAL, SND_SOC_TPLG_TUPLE_TYPE_WORD, {SOF_TKN_GAIN_VAL, SND_SOC_TPLG_TUPLE_TYPE_WORD,
get_token_u32, offsetof(struct sof_ipc4_gain_data, init_val)}, get_token_u32, offsetof(struct sof_ipc4_gain_params, init_val)},
}; };
/* SRC */ /* SRC */
...@@ -720,15 +720,15 @@ static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget) ...@@ -720,15 +720,15 @@ static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget)
swidget->private = gain; swidget->private = gain;
gain->data.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK; gain->data.params.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
gain->data.init_val = SOF_IPC4_VOL_ZERO_DB; gain->data.params.init_val = SOF_IPC4_VOL_ZERO_DB;
ret = sof_ipc4_get_audio_fmt(scomp, swidget, &gain->available_fmt, &gain->base_config); ret = sof_ipc4_get_audio_fmt(scomp, swidget, &gain->available_fmt, &gain->data.base_config);
if (ret) if (ret)
goto err; goto err;
ret = sof_update_ipc_object(scomp, &gain->data, SOF_GAIN_TOKENS, swidget->tuples, ret = sof_update_ipc_object(scomp, &gain->data.params, SOF_GAIN_TOKENS,
swidget->num_tuples, sizeof(gain->data), 1); swidget->tuples, swidget->num_tuples, sizeof(gain->data), 1);
if (ret) { if (ret) {
dev_err(scomp->dev, "Parsing gain tokens failed\n"); dev_err(scomp->dev, "Parsing gain tokens failed\n");
goto err; goto err;
...@@ -736,8 +736,8 @@ static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget) ...@@ -736,8 +736,8 @@ static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget)
dev_dbg(scomp->dev, dev_dbg(scomp->dev,
"pga widget %s: ramp type: %d, ramp duration %d, initial gain value: %#x\n", "pga widget %s: ramp type: %d, ramp duration %d, initial gain value: %#x\n",
swidget->widget->name, gain->data.curve_type, gain->data.curve_duration_l, swidget->widget->name, gain->data.params.curve_type,
gain->data.init_val); gain->data.params.curve_duration_l, gain->data.params.init_val);
ret = sof_ipc4_widget_setup_msg(swidget, &gain->msg); ret = sof_ipc4_widget_setup_msg(swidget, &gain->msg);
if (ret) if (ret)
...@@ -1826,7 +1826,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget, ...@@ -1826,7 +1826,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
u32 out_ref_rate, out_ref_channels, out_ref_valid_bits; u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
int ret; int ret;
ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &gain->base_config, ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &gain->data.base_config,
pipeline_params, available_fmt); pipeline_params, available_fmt);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1836,7 +1836,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget, ...@@ -1836,7 +1836,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg); out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg); out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
ret = sof_ipc4_init_output_audio_fmt(sdev, &gain->base_config, available_fmt, ret = sof_ipc4_init_output_audio_fmt(sdev, &gain->data.base_config, available_fmt,
out_ref_rate, out_ref_channels, out_ref_valid_bits); out_ref_rate, out_ref_channels, out_ref_valid_bits);
if (ret < 0) { if (ret < 0) {
dev_err(sdev->dev, "Failed to initialize output format for %s", dev_err(sdev->dev, "Failed to initialize output format for %s",
...@@ -1845,7 +1845,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget, ...@@ -1845,7 +1845,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
} }
/* update pipeline memory usage */ /* update pipeline memory usage */
sof_ipc4_update_resource_usage(sdev, swidget, &gain->base_config); sof_ipc4_update_resource_usage(sdev, swidget, &gain->data.base_config);
return 0; return 0;
} }
...@@ -2324,9 +2324,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget ...@@ -2324,9 +2324,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
{ {
struct sof_ipc4_gain *gain = swidget->private; struct sof_ipc4_gain *gain = swidget->private;
ipc_size = sizeof(struct sof_ipc4_base_module_cfg) + ipc_size = sizeof(gain->data);
sizeof(struct sof_ipc4_gain_data); ipc_data = &gain->data;
ipc_data = gain;
msg = &gain->msg; msg = &gain->msg;
break; break;
......
...@@ -361,7 +361,7 @@ struct sof_ipc4_control_msg_payload { ...@@ -361,7 +361,7 @@ struct sof_ipc4_control_msg_payload {
} __packed; } __packed;
/** /**
* struct sof_ipc4_gain_data - IPC gain blob * struct sof_ipc4_gain_params - IPC gain parameters
* @channels: Channels * @channels: Channels
* @init_val: Initial value * @init_val: Initial value
* @curve_type: Curve type * @curve_type: Curve type
...@@ -369,24 +369,32 @@ struct sof_ipc4_control_msg_payload { ...@@ -369,24 +369,32 @@ struct sof_ipc4_control_msg_payload {
* @curve_duration_l: Curve duration low part * @curve_duration_l: Curve duration low part
* @curve_duration_h: Curve duration high part * @curve_duration_h: Curve duration high part
*/ */
struct sof_ipc4_gain_data { struct sof_ipc4_gain_params {
uint32_t channels; uint32_t channels;
uint32_t init_val; uint32_t init_val;
uint32_t curve_type; uint32_t curve_type;
uint32_t reserved; uint32_t reserved;
uint32_t curve_duration_l; uint32_t curve_duration_l;
uint32_t curve_duration_h; uint32_t curve_duration_h;
} __aligned(8); } __packed __aligned(4);
/** /**
* struct sof_ipc4_gain - gain config data * struct sof_ipc4_gain_data - IPC gain init blob
* @base_config: IPC base config data * @base_config: IPC base config data
* @params: Initial parameters for the gain module
*/
struct sof_ipc4_gain_data {
struct sof_ipc4_base_module_cfg base_config;
struct sof_ipc4_gain_params params;
} __packed __aligned(4);
/**
* struct sof_ipc4_gain - gain config data
* @data: IPC gain blob * @data: IPC gain blob
* @available_fmt: Available audio format * @available_fmt: Available audio format
* @msg: message structure for gain * @msg: message structure for gain
*/ */
struct sof_ipc4_gain { struct sof_ipc4_gain {
struct sof_ipc4_base_module_cfg base_config;
struct sof_ipc4_gain_data data; struct sof_ipc4_gain_data data;
struct sof_ipc4_available_audio_format available_fmt; struct sof_ipc4_available_audio_format available_fmt;
struct sof_ipc4_msg msg; struct sof_ipc4_msg msg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment