Skip to content

Conversation

@kv2019i
Copy link
Collaborator

@kv2019i kv2019i commented May 19, 2025

The HDA DMA hardware keeps track of data in the DMA buffer using hardware Read and Write Position registers. The software uses the struct audio_stream with w_ptr and r_ptr for a similar purpose. If the software w_ptr and r_ptr do not point to the same location as the hardware Write and Read Position registers, the problem occurs.

Such desynchronization happens upon a pipeline reset. The dma_buffer is freed during a reset in dai-zephyr or host-zephyr and reallocated in prepare() after the pipeline resume. The reallocated dma_buffer has w_ptr and r_ptr set to NULL, while the hardware HDA DMA Read and Write Position registers retain their values.

If, for example, in the DAI playback case, the difference between the Write Position register and w_ptr is more than one period, the problem could easily go unnoticed as the hardware simply copies older data. In case where the difference between the Write Position and w_ptr is more than 0 but less than one period, the DMA copies part of the new data and part of the old data, resulting in glitches.

This fix ensures that the software w_ptr and r_ptr stay in sync with the hardware HDA DMA Write and Read Position registers.

(cherry picked from commit a84870f)

The HDA DMA hardware keeps track of data in the DMA buffer using hardware
Read and Write Position registers. The software uses the struct
audio_stream with w_ptr and r_ptr for a similar purpose. If the software
w_ptr and r_ptr do not point to the same location as the hardware Write
and Read Position registers, the problem occurs.

Such desynchronization happens upon a pipeline reset. The dma_buffer is
freed during a reset in dai-zephyr or host-zephyr and reallocated in
prepare() after the pipeline resume. The reallocated dma_buffer has w_ptr
and r_ptr set to NULL, while the hardware HDA DMA Read and Write Position
registers retain their values.

If, for example, in the DAI playback case, the difference between the
Write Position register and w_ptr is more than one period, the problem
could easily go unnoticed as the hardware simply copies older data. In
case where the difference between the Write Position and w_ptr is more
than 0 but less than one period, the DMA copies part of the new data and
part of the old data, resulting in glitches.

This fix ensures that the software w_ptr and r_ptr stay in sync with
the hardware HDA DMA Write and Read Position registers.

Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com>
(cherry picked from commit a84870f)
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i added this to the v2.13 milestone May 19, 2025
@kv2019i kv2019i changed the title hda-dma: Fix HDA DMA position regs going out of sync with w_ptr/r_ptr. [stable-v2.13] hda-dma: Fix HDA DMA position regs going out of sync with w_ptr/r_ptr. May 19, 2025
@lgirdwood lgirdwood merged commit 2913f9d into thesofproject:stable-v2.13 May 19, 2025
35 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants