From 14b036dc8200ae792be1bbcffe754fff75318e29 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 12 Jan 2026 15:14:23 +0200 Subject: [PATCH] audio: dai-zephyr: minor cleanup of xrun handling code Some minor improvements to make the xrun handling code easier to follow. The current implementation is checking for DAI DMA overrun/underrun conditions both at start of a copy callback (using data from DMA driver dma_get_status()), as well as at end of copy callback (using dma_reload()). There is also two separate mechanisms to report xruns, one specific to IPC4 (CONFIG_XRUN_NOTIFICATIONS_ENABLE) and one common method using component.h interface (comp_underrun() and comp_underrun()). Add documentation to the xrun helper functions and rename dai_report_xrun() to dai_report_reload_xrun() to better reflect the actual implementation. Signed-off-by: Kai Vehmanen --- src/audio/dai-zephyr.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index fc04ed1c4d72..44ce24f20ea1 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -1468,7 +1468,13 @@ static int dai_comp_trigger(struct comp_dev *dev, int cmd) return dai_common_trigger(dd, dev, cmd); } -/* get status from dma and check for xrun */ +/** + * Get status from the DMA driver. + * + * After status call, a check for xrun condition is done and + * depending on configuration, a xrun report is optionally sent. + * See also xrun reporting done in dai_report_reload_xrun(). + */ static int dai_get_status(struct comp_dev *dev, struct dai_data *dd, struct dma_status *stat) { int ret = sof_dma_get_status(dd->chan->dma, dd->chan->index, stat); @@ -1494,8 +1500,13 @@ static int dai_get_status(struct comp_dev *dev, struct dai_data *dd, struct dma_ return ret; } -/* report xrun occurrence */ -static void dai_report_xrun(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes) +/** + * Report xrun occurrence after DAI DMA driver reports + * an error for a reload attempt of 'bytes' of data. + * + * See also xrun detection done in dai_get_status(). + */ +static void dai_report_reload_xrun(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes) { if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { comp_err(dev, "underrun due to no data available"); @@ -1584,7 +1595,7 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev, for (i = 0; i < num_endpoints; i++) { ret = sof_dma_reload(dd[i]->chan->dma, dd[i]->chan->index, 0); if (ret < 0) { - dai_report_xrun(dd[i], dev, 0); + dai_report_reload_xrun(dd[i], dev, 0); return ret; } } @@ -1613,7 +1624,7 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev, copy_bytes = frames * audio_stream_frame_bytes(&dd[i]->dma_buffer->stream); ret = sof_dma_reload(dd[i]->chan->dma, dd[i]->chan->index, copy_bytes); if (ret < 0) { - dai_report_xrun(dd[i], dev, copy_bytes); + dai_report_reload_xrun(dd[i], dev, copy_bytes); return ret; } @@ -1814,7 +1825,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun ret = sof_dma_reload(dd->chan->dma, dd->chan->index, copy_bytes); if (ret < 0) { - dai_report_xrun(dd, dev, copy_bytes); + dai_report_reload_xrun(dd, dev, copy_bytes); return ret; }