Skip to content

Commit 95ea8f4

Browse files
committed
dai: use ibs/obs for dma buffer size calculation
Use ibs/obs size from ipc4_base_module_cfg to properly calculate period_count. It is especially important when FW aggregation mode is enabled and there are multiple DMAs allocated under one copier instance. That way period count for every DMA will be correctly evaluated and used for DMA buffer size calculation. Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
1 parent 2711784 commit 95ea8f4

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/audio/dai-zephyr.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,38 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
848848

849849
/* calculate DMA buffer size */
850850
period_count = dd->dma->plat_data.period_count;
851+
852+
#if CONFIG_IPC_MAJOR_4
853+
/* Use ibs/obs from copier gtw config to calculate DMA buffer size in ms.
854+
* This is used to calculate correct period count value.
855+
* It is especially important for FW aggregation use case, when Copier
856+
* receives whole DMA buffer size in GTW config but should be able to
857+
* allocate multiple DMA's implicitly.
858+
* E.g. if dma_buffer_size received in Copier GTW config is 7680 bytes and FW
859+
* should aggregate two streams 1ch/24_32bit/48kHz and 3ch/24_32bit/48kHz into one
860+
* 4ch/24_32bit/48kHz stream, then FW will have to allocate two DMA's with sizes
861+
* 1920 and 5760 bytes respectively and same 10 ms period for both to avoid
862+
* glitches.
863+
*/
864+
struct ipc4_copier_module_cfg *copier_cfg = dd->dai_spec_config;
865+
uint32_t dma_buff_ms_size;
866+
867+
if (dev->direction == SOF_IPC_STREAM_CAPTURE)
868+
dma_buff_ms_size = dd->ipc_config.dma_buffer_size / copier_cfg->base.ibs;
869+
else
870+
dma_buff_ms_size = dd->ipc_config.dma_buffer_size / copier_cfg->base.obs;
871+
872+
period_count = MAX(period_count, dma_buff_ms_size);
873+
#else
874+
period_count = MAX(
875+
period_count, SOF_DIV_ROUND_UP(dd->ipc_config.dma_buffer_size, period_bytes));
876+
#endif /* CONFIG_IPC_MAJOR_4 */
877+
851878
if (!period_count) {
852879
comp_err(dev, "dai_set_dma_buffer(): no valid dma buffer period count");
853880
return -EINVAL;
854881
}
855-
period_count = MAX(period_count,
856-
SOF_DIV_ROUND_UP(dd->ipc_config.dma_buffer_size, period_bytes));
882+
857883
buffer_size = ALIGN_UP(period_count * period_bytes, align);
858884
*pc = period_count;
859885

0 commit comments

Comments
 (0)