From 9831a9ded7701416f5eab1ab745383041bdb42dc Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Wed, 14 Feb 2024 13:48:22 +0200 Subject: [PATCH] audio: dai-zephyr: reset DMA buffer cursors on TRIGGER_RELEASE On NXP platforms, stopping the DMAC and then re-configuring it leads to the internal DMA buffer cursors being reset. Leaving the SOF DMA buffer cursors in the same state means the DMA driver and SOF may potentially end up with two different views of the same buffer (from the cursors' point of view). This in, turn, may lead to the DAI consuming stale data because of the values of "free" and "pending" queried from dma_reload() stopping dai_common_copy() from copying new data. To fix this, reset the read and write cursors of the DMA buffer from SOF side. This way, both SOF and the DMA driver will have the same initial view of the DMA buffer cursors. Signed-off-by: Laurentiu Mihalcea --- src/audio/dai-zephyr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 5ea7869ca396..5aa2e4da6487 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -1069,6 +1069,16 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev, buffer_zero(dd->dma_buffer); } + /* DMA driver and SOF's view of the DMA buffer's + * read and write cursors must be the same to + * avoid scenarios in which the DMA driver + * reports false "free" and "pending" values, thus + * leading to the DMA copying stale data due to + * dma_status() stopping dai_common_copy() from + * updating the data. + */ + audio_stream_reset(&dd->dma_buffer->stream); + /* only start the DAI if we are not XRUN handling */ if (dd->xrun == 0) { /* recover valid start position */