Skip to content

Commit

Permalink
zephyr: dai: Use the buffer_alloc_range function to allocate a buffer
Browse files Browse the repository at this point in the history
Changed buffer allocation functions to buffer_alloc_range and
buffer_set_size_range. This makes it possible to allocate the buffer even
if the suggested size given in ipc cannot be met.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki committed May 22, 2024
1 parent f5e363f commit c2f8576
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
uint32_t period_count;
uint32_t period_bytes;
uint32_t buffer_size;
uint32_t buffer_size_preferred;
uint32_t addr_align;
uint32_t align;
int err;
Expand Down Expand Up @@ -873,21 +874,24 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
comp_err(dev, "dai_set_dma_buffer(): no valid dma buffer period count");
return -EINVAL;
}

buffer_size = ALIGN_UP(period_count * period_bytes, align);
period_count = MAX(period_count,
SOF_DIV_ROUND_UP(dd->ipc_config.dma_buffer_size, period_bytes));
*pc = period_count;
buffer_size_preferred = ALIGN_UP(period_count * period_bytes, align);

/* alloc DMA buffer or change its size if exists */
if (dd->dma_buffer) {
err = buffer_set_size(dd->dma_buffer, buffer_size, addr_align);
err = buffer_set_size_range(dd->dma_buffer, buffer_size_preferred, buffer_size,
addr_align);

if (err < 0) {
comp_err(dev, "dai_set_dma_buffer(): buffer_size = %u failed", buffer_size);
return err;
}
} else {
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
addr_align, false);
dd->dma_buffer = buffer_alloc_range(buffer_size_preferred, buffer_size,
SOF_MEM_CAPS_DMA, 0, addr_align, false);
if (!dd->dma_buffer) {
comp_err(dev, "dai_set_dma_buffer(): failed to alloc dma buffer");
return -ENOMEM;
Expand All @@ -904,6 +908,7 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
dd->sampling = get_sample_bytes(hw_params.frame_fmt);
}

*pc = audio_stream_get_size(&dd->dma_buffer->stream) / period_bytes;
dd->fast_mode = dd->ipc_config.feature_mask & BIT(IPC4_COPIER_FAST_MODE);
return 0;
}
Expand Down

0 comments on commit c2f8576

Please sign in to comment.