Skip to content

Commit e238b68

Browse files
ujfalusibroonie
authored andcommitted
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: Peter Ujfalusi <[email protected]> Reviewed-by: Pierre-Louis Bossart <[email protected]> Reviewed-by: Bard Liao <[email protected]> Reviewed-by: Ranjani Sridharan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent c447636 commit e238b68

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

sound/soc/sof/ipc4-control.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidge
8989
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
9090
struct sof_ipc4_gain *gain = swidget->private;
9191
struct sof_ipc4_msg *msg = &cdata->msg;
92-
struct sof_ipc4_gain_data data;
92+
struct sof_ipc4_gain_params params;
9393
bool all_channels_equal = true;
9494
u32 value;
9595
int ret, i;
@@ -109,20 +109,20 @@ sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidge
109109
*/
110110
for (i = 0; i < scontrol->num_channels; i++) {
111111
if (all_channels_equal) {
112-
data.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
113-
data.init_val = cdata->chanv[0].value;
112+
params.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
113+
params.init_val = cdata->chanv[0].value;
114114
} else {
115-
data.channels = cdata->chanv[i].channel;
116-
data.init_val = cdata->chanv[i].value;
115+
params.channels = cdata->chanv[i].channel;
116+
params.init_val = cdata->chanv[i].value;
117117
}
118118

119119
/* set curve type and duration from topology */
120-
data.curve_duration_l = gain->data.curve_duration_l;
121-
data.curve_duration_h = gain->data.curve_duration_h;
122-
data.curve_type = gain->data.curve_type;
120+
params.curve_duration_l = gain->data.params.curve_duration_l;
121+
params.curve_duration_h = gain->data.params.curve_duration_h;
122+
params.curve_type = gain->data.params.curve_type;
123123

124-
msg->data_ptr = &data;
125-
msg->data_size = sizeof(data);
124+
msg->data_ptr = &params;
125+
msg->data_size = sizeof(params);
126126

127127
ret = sof_ipc4_set_get_kcontrol_data(scontrol, true, lock);
128128
msg->data_ptr = NULL;

sound/soc/sof/ipc4-topology.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ static const struct sof_topology_token comp_ext_tokens[] = {
130130

131131
static const struct sof_topology_token gain_tokens[] = {
132132
{SOF_TKN_GAIN_RAMP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
133-
get_token_u32, offsetof(struct sof_ipc4_gain_data, curve_type)},
133+
get_token_u32, offsetof(struct sof_ipc4_gain_params, curve_type)},
134134
{SOF_TKN_GAIN_RAMP_DURATION,
135135
SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
136-
offsetof(struct sof_ipc4_gain_data, curve_duration_l)},
136+
offsetof(struct sof_ipc4_gain_params, curve_duration_l)},
137137
{SOF_TKN_GAIN_VAL, SND_SOC_TPLG_TUPLE_TYPE_WORD,
138-
get_token_u32, offsetof(struct sof_ipc4_gain_data, init_val)},
138+
get_token_u32, offsetof(struct sof_ipc4_gain_params, init_val)},
139139
};
140140

141141
/* SRC */
@@ -720,24 +720,24 @@ static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget)
720720

721721
swidget->private = gain;
722722

723-
gain->data.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
724-
gain->data.init_val = SOF_IPC4_VOL_ZERO_DB;
723+
gain->data.params.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
724+
gain->data.params.init_val = SOF_IPC4_VOL_ZERO_DB;
725725

726-
ret = sof_ipc4_get_audio_fmt(scomp, swidget, &gain->available_fmt, &gain->base_config);
726+
ret = sof_ipc4_get_audio_fmt(scomp, swidget, &gain->available_fmt, &gain->data.base_config);
727727
if (ret)
728728
goto err;
729729

730-
ret = sof_update_ipc_object(scomp, &gain->data, SOF_GAIN_TOKENS, swidget->tuples,
731-
swidget->num_tuples, sizeof(gain->data), 1);
730+
ret = sof_update_ipc_object(scomp, &gain->data.params, SOF_GAIN_TOKENS,
731+
swidget->tuples, swidget->num_tuples, sizeof(gain->data), 1);
732732
if (ret) {
733733
dev_err(scomp->dev, "Parsing gain tokens failed\n");
734734
goto err;
735735
}
736736

737737
dev_dbg(scomp->dev,
738738
"pga widget %s: ramp type: %d, ramp duration %d, initial gain value: %#x\n",
739-
swidget->widget->name, gain->data.curve_type, gain->data.curve_duration_l,
740-
gain->data.init_val);
739+
swidget->widget->name, gain->data.params.curve_type,
740+
gain->data.params.curve_duration_l, gain->data.params.init_val);
741741

742742
ret = sof_ipc4_widget_setup_msg(swidget, &gain->msg);
743743
if (ret)
@@ -1826,7 +1826,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
18261826
u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
18271827
int ret;
18281828

1829-
ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &gain->base_config,
1829+
ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &gain->data.base_config,
18301830
pipeline_params, available_fmt);
18311831
if (ret < 0)
18321832
return ret;
@@ -1836,7 +1836,7 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
18361836
out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
18371837
out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
18381838

1839-
ret = sof_ipc4_init_output_audio_fmt(sdev, &gain->base_config, available_fmt,
1839+
ret = sof_ipc4_init_output_audio_fmt(sdev, &gain->data.base_config, available_fmt,
18401840
out_ref_rate, out_ref_channels, out_ref_valid_bits);
18411841
if (ret < 0) {
18421842
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,
18451845
}
18461846

18471847
/* update pipeline memory usage */
1848-
sof_ipc4_update_resource_usage(sdev, swidget, &gain->base_config);
1848+
sof_ipc4_update_resource_usage(sdev, swidget, &gain->data.base_config);
18491849

18501850
return 0;
18511851
}
@@ -2324,9 +2324,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
23242324
{
23252325
struct sof_ipc4_gain *gain = swidget->private;
23262326

2327-
ipc_size = sizeof(struct sof_ipc4_base_module_cfg) +
2328-
sizeof(struct sof_ipc4_gain_data);
2329-
ipc_data = gain;
2327+
ipc_size = sizeof(gain->data);
2328+
ipc_data = &gain->data;
23302329

23312330
msg = &gain->msg;
23322331
break;

sound/soc/sof/ipc4-topology.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,32 +361,40 @@ struct sof_ipc4_control_msg_payload {
361361
} __packed;
362362

363363
/**
364-
* struct sof_ipc4_gain_data - IPC gain blob
364+
* struct sof_ipc4_gain_params - IPC gain parameters
365365
* @channels: Channels
366366
* @init_val: Initial value
367367
* @curve_type: Curve type
368368
* @reserved: reserved for future use
369369
* @curve_duration_l: Curve duration low part
370370
* @curve_duration_h: Curve duration high part
371371
*/
372-
struct sof_ipc4_gain_data {
372+
struct sof_ipc4_gain_params {
373373
uint32_t channels;
374374
uint32_t init_val;
375375
uint32_t curve_type;
376376
uint32_t reserved;
377377
uint32_t curve_duration_l;
378378
uint32_t curve_duration_h;
379-
} __aligned(8);
379+
} __packed __aligned(4);
380380

381381
/**
382-
* struct sof_ipc4_gain - gain config data
382+
* struct sof_ipc4_gain_data - IPC gain init blob
383383
* @base_config: IPC base config data
384+
* @params: Initial parameters for the gain module
385+
*/
386+
struct sof_ipc4_gain_data {
387+
struct sof_ipc4_base_module_cfg base_config;
388+
struct sof_ipc4_gain_params params;
389+
} __packed __aligned(4);
390+
391+
/**
392+
* struct sof_ipc4_gain - gain config data
384393
* @data: IPC gain blob
385394
* @available_fmt: Available audio format
386395
* @msg: message structure for gain
387396
*/
388397
struct sof_ipc4_gain {
389-
struct sof_ipc4_base_module_cfg base_config;
390398
struct sof_ipc4_gain_data data;
391399
struct sof_ipc4_available_audio_format available_fmt;
392400
struct sof_ipc4_msg msg;

0 commit comments

Comments
 (0)