Skip to content

Commit f6602b8

Browse files
committed
ASoC: SOF: ipc4-topology: Refresh copier IPC payload before widget setup
The ipc_config_data buffer for copier widgets is built once during ipc_prepare (called from sof_pcm_setup_connected_widgets) and cached for reuse. For host copiers this buffer contains the copier_data with gtw_cfg.node_id (host DMA ID). For DAI copiers it additionally includes a dma_config_tlv trailer with stream_id and dma_channel_id for HDA link DMA. On suspend/resume, both host and link DMA streams are released and re-allocated with potentially different stream tags. The underlying copier_data and dma_config_tlv structures are correctly updated by host_config and sdw_hda_dai_hw_params respectively. However, since the widget list (spcm->stream[].list) persists across suspend, sof_pcm_hw_params skips sof_pcm_setup_connected_widgets and ipc_prepare never runs again to rebuild ipc_config_data. The stale cached payload is then sent to firmware with boot-time DMA channel assignments, causing DMA channel conflicts that lead to firmware errors and crashes. Fix this by refreshing copier_data and dma_config_tlv portions of ipc_config_data in sof_ipc4_widget_setup right before the IPC message is sent. This ensures the payload always reflects the current DMA state regardless of whether ipc_prepare ran. For DAI copiers, the gtw_cfg.config_length in copier_data is temporarily inflated to include the TLV size (matching the ipc_config_data layout) before copying, then restored, mirroring what _sof_ipc4_prepare_copier_module does when first building the buffer. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 04e1037 commit f6602b8

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

sound/soc/sof/ipc4-topology.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,15 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32043204
ipc_size = ipc4_copier->ipc_config_size;
32053205
ipc_data = ipc4_copier->ipc_config_data;
32063206

3207+
/*
3208+
* Refresh copier_data in ipc_config_data for host copiers.
3209+
* The node_id may have been updated by host_config after
3210+
* ipc_prepare, e.g. when host stream tags change after a
3211+
* suspend/resume cycle.
3212+
*/
3213+
if (swidget->id != snd_soc_dapm_buffer)
3214+
memcpy(ipc_data, &ipc4_copier->data, sizeof(ipc4_copier->data));
3215+
32073216
msg = &ipc4_copier->msg;
32083217
break;
32093218
}
@@ -3212,6 +3221,9 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32123221
{
32133222
struct snd_sof_dai *dai = swidget->private;
32143223
struct sof_ipc4_copier *ipc4_copier = dai->private;
3224+
struct sof_ipc4_copier_data *copier_data;
3225+
u32 gtw_cfg_config_length;
3226+
u32 tlv_size;
32153227

32163228
pipeline = pipe_widget->private;
32173229
if (pipeline->use_chain_dma)
@@ -3220,6 +3232,27 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32203232
ipc_size = ipc4_copier->ipc_config_size;
32213233
ipc_data = ipc4_copier->ipc_config_data;
32223234

3235+
/*
3236+
* Refresh copier_data and dma_config_tlv in ipc_config_data.
3237+
* These may have been updated after ipc_prepare, e.g. when
3238+
* link DMA stream tags change after a suspend/resume cycle.
3239+
*
3240+
* copier_data->gtw_cfg.config_length does not include the
3241+
* TLV size (it was restored after _sof_ipc4_prepare_copier_module),
3242+
* so temporarily inflate it to match the ipc_config_data layout.
3243+
*/
3244+
copier_data = &ipc4_copier->data;
3245+
gtw_cfg_config_length = copier_data->gtw_cfg.config_length * 4;
3246+
tlv_size = ipc_size - sizeof(*copier_data) - gtw_cfg_config_length;
3247+
3248+
copier_data->gtw_cfg.config_length += tlv_size / 4;
3249+
memcpy(ipc_data, copier_data, sizeof(*copier_data));
3250+
copier_data->gtw_cfg.config_length = gtw_cfg_config_length / 4;
3251+
3252+
if (tlv_size)
3253+
memcpy(ipc_data + sizeof(*copier_data) + gtw_cfg_config_length,
3254+
&ipc4_copier->dma_config_tlv, tlv_size);
3255+
32233256
msg = &ipc4_copier->msg;
32243257
break;
32253258
}

0 commit comments

Comments
 (0)