Skip to content

Commit 5967a53

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 106e683 commit 5967a53

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
@@ -3186,6 +3186,15 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
31863186
ipc_size = ipc4_copier->ipc_config_size;
31873187
ipc_data = ipc4_copier->ipc_config_data;
31883188

3189+
/*
3190+
* Refresh copier_data in ipc_config_data for host copiers.
3191+
* The node_id may have been updated by host_config after
3192+
* ipc_prepare, e.g. when host stream tags change after a
3193+
* suspend/resume cycle.
3194+
*/
3195+
if (swidget->id != snd_soc_dapm_buffer)
3196+
memcpy(ipc_data, &ipc4_copier->data, sizeof(ipc4_copier->data));
3197+
31893198
msg = &ipc4_copier->msg;
31903199
break;
31913200
}
@@ -3194,6 +3203,9 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
31943203
{
31953204
struct snd_sof_dai *dai = swidget->private;
31963205
struct sof_ipc4_copier *ipc4_copier = dai->private;
3206+
struct sof_ipc4_copier_data *copier_data;
3207+
u32 gtw_cfg_config_length;
3208+
u32 tlv_size;
31973209

31983210
pipeline = pipe_widget->private;
31993211
if (pipeline->use_chain_dma)
@@ -3202,6 +3214,27 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32023214
ipc_size = ipc4_copier->ipc_config_size;
32033215
ipc_data = ipc4_copier->ipc_config_data;
32043216

3217+
/*
3218+
* Refresh copier_data and dma_config_tlv in ipc_config_data.
3219+
* These may have been updated after ipc_prepare, e.g. when
3220+
* link DMA stream tags change after a suspend/resume cycle.
3221+
*
3222+
* copier_data->gtw_cfg.config_length does not include the
3223+
* TLV size (it was restored after _sof_ipc4_prepare_copier_module),
3224+
* so temporarily inflate it to match the ipc_config_data layout.
3225+
*/
3226+
copier_data = &ipc4_copier->data;
3227+
gtw_cfg_config_length = copier_data->gtw_cfg.config_length * 4;
3228+
tlv_size = ipc_size - sizeof(*copier_data) - gtw_cfg_config_length;
3229+
3230+
copier_data->gtw_cfg.config_length += tlv_size / 4;
3231+
memcpy(ipc_data, copier_data, sizeof(*copier_data));
3232+
copier_data->gtw_cfg.config_length = gtw_cfg_config_length / 4;
3233+
3234+
if (tlv_size)
3235+
memcpy(ipc_data + sizeof(*copier_data) + gtw_cfg_config_length,
3236+
&ipc4_copier->dma_config_tlv, tlv_size);
3237+
32053238
msg = &ipc4_copier->msg;
32063239
break;
32073240
}

0 commit comments

Comments
 (0)