From fc48fbd1b359a5fe8540a8c700195c15c5ad8040 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Thu, 14 Mar 2024 16:43:24 +0200 Subject: [PATCH] audio: dai-zephyr: convert DMA src/dst addresses to host-relative addresses The DMAC has the same view of the address space as the HOST. As such, the source and destination addresses need to be converted to HOST-relative addresses before attempting to perform a DMA transfer. This is only relevant for platforms for which the DSP and HOST have different views of the address space (e.g: i.MX8ULP). Also, if a platform doesn't define the `local_to_host` macro (used for converting DSP local address to HOST-relative address) we assume that the HOST and the DSP have the same view of the address space. As such, we also add a definition of `local_to_host` which will just return the passed address. Signed-off-by: Laurentiu Mihalcea --- src/audio/dai-zephyr.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index a9662254b..0f0d0f43e 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -41,6 +41,14 @@ #include #include +/* note: if this macro is not defined + * then that means the HOST and the DSP + * have the same view of the address space. + */ +#ifndef local_to_host +#define local_to_host(addr) (addr) +#endif /* local_to_host */ + static const struct comp_driver comp_dai; LOG_MODULE_REGISTER(dai_comp, CONFIG_SOF_LOG_LEVEL); @@ -751,12 +759,18 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev) for (i = 0; i < dma_cfg->block_count; i++) { dma_block_cfg->dest_scatter_en = config->scatter; dma_block_cfg->block_size = config->elem_array.elems[i].size; - dma_block_cfg->source_address = config->elem_array.elems[i].src; - dma_block_cfg->dest_address = config->elem_array.elems[i].dest; if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { + dma_block_cfg->source_address = + local_to_host(config->elem_array.elems[i].src); + dma_block_cfg->dest_address = + config->elem_array.elems[i].dest; dma_block_cfg->source_addr_adj = DMA_ADDR_ADJ_DECREMENT; dma_block_cfg->dest_addr_adj = DMA_ADDR_ADJ_INCREMENT; } else { + dma_block_cfg->source_address = + config->elem_array.elems[i].src; + dma_block_cfg->dest_address = + local_to_host(config->elem_array.elems[i].dest); dma_block_cfg->source_addr_adj = DMA_ADDR_ADJ_INCREMENT; dma_block_cfg->dest_addr_adj = DMA_ADDR_ADJ_DECREMENT; }