Commit 0dfc21c1 authored by Thierry Reding's avatar Thierry Reding Committed by Mark Brown

ASoC: tegra: Use ADMAIF component for DMA allocations

DMA memory is currently allocated for the soundcard device, which is a
virtual device added for the sole purpose of "stitching" together the
audio device. It is not a real device and therefore doesn't have a DMA
mask or a description of the path to and from memory of accesses.

Memory accesses really originate from the ADMA controller that provides
the DMA channels used by the PCM component. However, since the DMA
memory is allocated up-front and the DMA channels aren't known at that
point, there is no way of knowing the DMA channel provider at allocation
time.

The next best physical device in the memory path is the ADMAIF. Use it
as the device to allocate DMA memory to. iommus and interconnects device
tree properties can thus be added to the ADMAIF device tree node to
describe the memory access path for audio.
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20210708103432.1690385-2-thierry.reding@gmail.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 9cf76a72
...@@ -213,19 +213,19 @@ snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component, ...@@ -213,19 +213,19 @@ snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component,
} }
EXPORT_SYMBOL_GPL(tegra_pcm_pointer); EXPORT_SYMBOL_GPL(tegra_pcm_pointer);
static int tegra_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream, static int tegra_pcm_preallocate_dma_buffer(struct device *dev, struct snd_pcm *pcm, int stream,
size_t size) size_t size)
{ {
struct snd_pcm_substream *substream = pcm->streams[stream].substream; struct snd_pcm_substream *substream = pcm->streams[stream].substream;
struct snd_dma_buffer *buf = &substream->dma_buffer; struct snd_dma_buffer *buf = &substream->dma_buffer;
buf->area = dma_alloc_wc(pcm->card->dev, size, &buf->addr, GFP_KERNEL); buf->area = dma_alloc_wc(dev, size, &buf->addr, GFP_KERNEL);
if (!buf->area) if (!buf->area)
return -ENOMEM; return -ENOMEM;
buf->private_data = NULL; buf->private_data = NULL;
buf->dev.type = SNDRV_DMA_TYPE_DEV; buf->dev.type = SNDRV_DMA_TYPE_DEV;
buf->dev.dev = pcm->card->dev; buf->dev.dev = dev;
buf->bytes = size; buf->bytes = size;
return 0; return 0;
...@@ -244,31 +244,28 @@ static void tegra_pcm_deallocate_dma_buffer(struct snd_pcm *pcm, int stream) ...@@ -244,31 +244,28 @@ static void tegra_pcm_deallocate_dma_buffer(struct snd_pcm *pcm, int stream)
if (!buf->area) if (!buf->area)
return; return;
dma_free_wc(pcm->card->dev, buf->bytes, buf->area, buf->addr); dma_free_wc(buf->dev.dev, buf->bytes, buf->area, buf->addr);
buf->area = NULL; buf->area = NULL;
} }
static int tegra_pcm_dma_allocate(struct snd_soc_pcm_runtime *rtd, static int tegra_pcm_dma_allocate(struct device *dev, struct snd_soc_pcm_runtime *rtd,
size_t size) size_t size)
{ {
struct snd_card *card = rtd->card->snd_card;
struct snd_pcm *pcm = rtd->pcm; struct snd_pcm *pcm = rtd->pcm;
int ret; int ret;
ret = dma_set_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (ret < 0) if (ret < 0)
return ret; return ret;
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
ret = tegra_pcm_preallocate_dma_buffer(pcm, ret = tegra_pcm_preallocate_dma_buffer(dev, pcm, SNDRV_PCM_STREAM_PLAYBACK, size);
SNDRV_PCM_STREAM_PLAYBACK, size);
if (ret) if (ret)
goto err; goto err;
} }
if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
ret = tegra_pcm_preallocate_dma_buffer(pcm, ret = tegra_pcm_preallocate_dma_buffer(dev, pcm, SNDRV_PCM_STREAM_CAPTURE, size);
SNDRV_PCM_STREAM_CAPTURE, size);
if (ret) if (ret)
goto err_free_play; goto err_free_play;
} }
...@@ -284,7 +281,16 @@ static int tegra_pcm_dma_allocate(struct snd_soc_pcm_runtime *rtd, ...@@ -284,7 +281,16 @@ static int tegra_pcm_dma_allocate(struct snd_soc_pcm_runtime *rtd,
int tegra_pcm_construct(struct snd_soc_component *component, int tegra_pcm_construct(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtd) struct snd_soc_pcm_runtime *rtd)
{ {
return tegra_pcm_dma_allocate(rtd, tegra_pcm_hardware.buffer_bytes_max); struct device *dev = component->dev;
/*
* Fallback for backwards-compatibility with older device trees that
* have the iommus property in the virtual, top-level "sound" node.
*/
if (!of_get_property(dev->of_node, "iommus", NULL))
dev = rtd->card->snd_card->dev;
return tegra_pcm_dma_allocate(dev, rtd, tegra_pcm_hardware.buffer_bytes_max);
} }
EXPORT_SYMBOL_GPL(tegra_pcm_construct); EXPORT_SYMBOL_GPL(tegra_pcm_construct);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment