Skip to content

Commit d8b502a

Browse files
ujfalusibroonie
authored andcommitted
ASoC: SOF: trace: Use proper DMA direction for the trace data buffer
Buffers allocated with snd_dma_alloc_pages() will have DMA direction DMA_BIDIRECTIONAL. The trace data memory is only used for one DMA direction: DMA_FROM_DEVICE, DMA only writes there, never reads. We also need to do a sync before accessing (reading with CPU) from the trace data buffer to copy it to user space. Note: snd_dma_buffer_sync() is also used for normal playback and capture streams to make sure that the data is available for the DMA or CPU. Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20220310171651.249385-4-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 7e4bfcf commit d8b502a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

sound/soc/sof/trace.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer,
320320
if (count > avail)
321321
count = avail;
322322

323+
/*
324+
* make sure that all trace data is available for the CPU as the trace
325+
* data buffer might be allocated from non consistent memory.
326+
* Note: snd_dma_buffer_sync() is called for normal audio playback and
327+
* capture streams also.
328+
*/
329+
snd_dma_buffer_sync(&sdev->dmatb, SNDRV_DMA_SYNC_CPU);
323330
/* copy available trace data to debugfs */
324331
rem = copy_to_user(buffer, ((u8 *)(dfse->buf) + lpos), count);
325332
if (rem)
@@ -464,8 +471,9 @@ int snd_sof_init_trace(struct snd_sof_dev *sdev)
464471
}
465472

466473
/* allocate trace data buffer */
467-
ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
468-
DMA_BUF_SIZE_FOR_TRACE, &sdev->dmatb);
474+
ret = snd_dma_alloc_dir_pages(SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
475+
DMA_FROM_DEVICE, DMA_BUF_SIZE_FOR_TRACE,
476+
&sdev->dmatb);
469477
if (ret < 0) {
470478
dev_err(sdev->dev,
471479
"error: can't alloc buffer for trace %d\n", ret);

0 commit comments

Comments
 (0)