devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194
@ 2021-06-28 18:11 Thierry Reding
  2021-06-28 18:11 ` [PATCH 1/2] ASoC: tegra: Use ADMAIF component for DMA allocations Thierry Reding
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Thierry Reding @ 2021-06-28 18:11 UTC (permalink / raw)
  To: Thierry Reding, Liam Girdwood, Mark Brown
  Cc: Rob Herring, Jon Hunter, Sameer Pujar, linux-tegra, alsa-devel,
	devicetree

From: Thierry Reding <treding@nvidia.com>

This small series addresses a minor issue with how IOMMU support is
wired up on various Tegra generations. Currently the virtual "card"
device is used to allocate DMA memory for, but since that device does
not actually exist, the path to memory cannot be correctly described.

To address this, this series moves to using the ADMAIF as the DMA device
for audio. This is a real device that can have a proper DMA mask set and
with which a stream ID can be associated with in the SMMU. The memory
accesses technically originate from the ADMA controller (that the ADMAIF
uses), but DMA channel are dynamically allocated at runtime while DMA
memory is allocated at driver load time, drivers won't have access to
the ADMA device yet.

Further patches will be required to correct this issue on Tegra186 and
Tegra210, but I wanted to get feedback on this approach first.

Thierry

Thierry Reding (2):
  ASoC: tegra: Use ADMAIF component for DMA allocations
  arm64: tegra: Enable audio IOMMU support on Tegra194

 arch/arm64/boot/dts/nvidia/tegra194.dtsi |  4 ++++
 sound/soc/tegra/tegra_pcm.c              | 21 +++++++++------------
 2 files changed, 13 insertions(+), 12 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] ASoC: tegra: Use ADMAIF component for DMA allocations
  2021-06-28 18:11 [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
@ 2021-06-28 18:11 ` Thierry Reding
  2021-06-28 18:11 ` [PATCH 2/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
  2021-06-30 16:10 ` (subset) [PATCH 0/2] " Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Thierry Reding @ 2021-06-28 18:11 UTC (permalink / raw)
  To: Thierry Reding, Liam Girdwood, Mark Brown
  Cc: Rob Herring, Jon Hunter, Sameer Pujar, linux-tegra, alsa-devel,
	devicetree

From: Thierry Reding <treding@nvidia.com>

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: Thierry Reding <treding@nvidia.com>
---
 sound/soc/tegra/tegra_pcm.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/sound/soc/tegra/tegra_pcm.c b/sound/soc/tegra/tegra_pcm.c
index 573374b89b10..33bdbdfb24ba 100644
--- a/sound/soc/tegra/tegra_pcm.c
+++ b/sound/soc/tegra/tegra_pcm.c
@@ -213,19 +213,19 @@ snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component,
 }
 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)
 {
 	struct snd_pcm_substream *substream = pcm->streams[stream].substream;
 	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)
 		return -ENOMEM;
 
 	buf->private_data = NULL;
 	buf->dev.type = SNDRV_DMA_TYPE_DEV;
-	buf->dev.dev = pcm->card->dev;
+	buf->dev.dev = dev;
 	buf->bytes = size;
 
 	return 0;
@@ -244,31 +244,28 @@ static void tegra_pcm_deallocate_dma_buffer(struct snd_pcm *pcm, int stream)
 	if (!buf->area)
 		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;
 }
 
-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)
 {
-	struct snd_card *card = rtd->card->snd_card;
 	struct snd_pcm *pcm = rtd->pcm;
 	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)
 		return ret;
 
 	if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
-		ret = tegra_pcm_preallocate_dma_buffer(pcm,
-			SNDRV_PCM_STREAM_PLAYBACK, size);
+		ret = tegra_pcm_preallocate_dma_buffer(dev, pcm, SNDRV_PCM_STREAM_PLAYBACK, size);
 		if (ret)
 			goto err;
 	}
 
 	if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
-		ret = tegra_pcm_preallocate_dma_buffer(pcm,
-			SNDRV_PCM_STREAM_CAPTURE, size);
+		ret = tegra_pcm_preallocate_dma_buffer(dev, pcm, SNDRV_PCM_STREAM_CAPTURE, size);
 		if (ret)
 			goto err_free_play;
 	}
@@ -284,7 +281,7 @@ static int tegra_pcm_dma_allocate(struct snd_soc_pcm_runtime *rtd,
 int tegra_pcm_construct(struct snd_soc_component *component,
 			struct snd_soc_pcm_runtime *rtd)
 {
-	return tegra_pcm_dma_allocate(rtd, tegra_pcm_hardware.buffer_bytes_max);
+	return tegra_pcm_dma_allocate(component->dev, rtd, tegra_pcm_hardware.buffer_bytes_max);
 }
 EXPORT_SYMBOL_GPL(tegra_pcm_construct);
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] arm64: tegra: Enable audio IOMMU support on Tegra194
  2021-06-28 18:11 [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
  2021-06-28 18:11 ` [PATCH 1/2] ASoC: tegra: Use ADMAIF component for DMA allocations Thierry Reding
@ 2021-06-28 18:11 ` Thierry Reding
  2021-06-30 16:10 ` (subset) [PATCH 0/2] " Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Thierry Reding @ 2021-06-28 18:11 UTC (permalink / raw)
  To: Thierry Reding, Liam Girdwood, Mark Brown
  Cc: Rob Herring, Jon Hunter, Sameer Pujar, linux-tegra, alsa-devel,
	devicetree

From: Thierry Reding <treding@nvidia.com>

Add iommus and interconnects properties to the ADMAIF device tree node
on Tegra194. This ensures that the correct SID is used for translation
of physical to I/O virtual addresses and that the path to system memory
is properly described, which in turn can impact the range of memory that
the device can address.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/boot/dts/nvidia/tegra194.dtsi b/arch/arm64/boot/dts/nvidia/tegra194.dtsi
index 1fa503ab390d..b957cb8df927 100644
--- a/arch/arm64/boot/dts/nvidia/tegra194.dtsi
+++ b/arch/arm64/boot/dts/nvidia/tegra194.dtsi
@@ -200,6 +200,10 @@ tegra_admaif: admaif@290f000 {
 						    "rx19", "tx19",
 						    "rx20", "tx20";
 					status = "disabled";
+					interconnects = <&mc TEGRA194_MEMORY_CLIENT_APEDMAR &emc>,
+							<&mc TEGRA194_MEMORY_CLIENT_APEDMAW &emc>;
+					interconnect-names = "dma-mem", "write";
+					iommus = <&smmu TEGRA194_SID_APE>;
 				};
 
 				tegra_i2s1: i2s@2901000 {
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: (subset) [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194
  2021-06-28 18:11 [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
  2021-06-28 18:11 ` [PATCH 1/2] ASoC: tegra: Use ADMAIF component for DMA allocations Thierry Reding
  2021-06-28 18:11 ` [PATCH 2/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
@ 2021-06-30 16:10 ` Mark Brown
  2021-06-30 17:08   ` Thierry Reding
  2 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2021-06-30 16:10 UTC (permalink / raw)
  To: Thierry Reding, Liam Girdwood
  Cc: Mark Brown, Jon Hunter, Sameer Pujar, linux-tegra, devicetree,
	alsa-devel, Rob Herring

On Mon, 28 Jun 2021 20:11:16 +0200, Thierry Reding wrote:
> This small series addresses a minor issue with how IOMMU support is
> wired up on various Tegra generations. Currently the virtual "card"
> device is used to allocate DMA memory for, but since that device does
> not actually exist, the path to memory cannot be correctly described.
> 
> To address this, this series moves to using the ADMAIF as the DMA device
> for audio. This is a real device that can have a proper DMA mask set and
> with which a stream ID can be associated with in the SMMU. The memory
> accesses technically originate from the ADMA controller (that the ADMAIF
> uses), but DMA channel are dynamically allocated at runtime while DMA
> memory is allocated at driver load time, drivers won't have access to
> the ADMA device yet.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: tegra: Use ADMAIF component for DMA allocations
      commit: e6b66edfef64698d4d9ed3847c95cdfab9bde579

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: (subset) [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194
  2021-06-30 16:10 ` (subset) [PATCH 0/2] " Mark Brown
@ 2021-06-30 17:08   ` Thierry Reding
  2021-07-01 12:51     ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Reding @ 2021-06-30 17:08 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jon Hunter, Sameer Pujar, linux-tegra, devicetree,
	alsa-devel, Rob Herring

[-- Attachment #1: Type: text/plain, Size: 2682 bytes --]

On Wed, Jun 30, 2021 at 05:10:33PM +0100, Mark Brown wrote:
> On Mon, 28 Jun 2021 20:11:16 +0200, Thierry Reding wrote:
> > This small series addresses a minor issue with how IOMMU support is
> > wired up on various Tegra generations. Currently the virtual "card"
> > device is used to allocate DMA memory for, but since that device does
> > not actually exist, the path to memory cannot be correctly described.
> > 
> > To address this, this series moves to using the ADMAIF as the DMA device
> > for audio. This is a real device that can have a proper DMA mask set and
> > with which a stream ID can be associated with in the SMMU. The memory
> > accesses technically originate from the ADMA controller (that the ADMAIF
> > uses), but DMA channel are dynamically allocated at runtime while DMA
> > memory is allocated at driver load time, drivers won't have access to
> > the ADMA device yet.
> > 
> > [...]
> 
> Applied to
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
> 
> Thanks!
> 
> [1/2] ASoC: tegra: Use ADMAIF component for DMA allocations
>       commit: e6b66edfef64698d4d9ed3847c95cdfab9bde579
> 
> All being well this means that it will be integrated into the linux-next
> tree (usually sometime in the next 24 hours) and sent to Linus during
> the next merge window (or sooner if it is a bug fix), however if
> problems are discovered then the patch may be dropped or reverted.
> 
> You may get further e-mails resulting from automated or manual testing
> and review of the tree, please engage with people reporting problems and
> send followup patches addressing any issues that are reported if needed.
> 
> If any updates are required or you are submitting further changes they
> should be sent as incremental updates against current git, existing
> patches will not be replaced.
> 
> Please add any relevant lists and maintainers to the CCs when replying
> to this mail.

Hi Mark,

Looks like I was a bit quick on the trigger with this one. Turns out
this breaks audio on Tegra186 because we had already merged the patch
that adds the iommus property to the wrong device tree node, so the
damage had already been done and we're going to have to provide a
backwards-compatibility fallback.

I've got a v2 of this series that incorporates the fallback (which is
just a two-line addition, luckily) but I wanted to give it another spin
in our test farm to make sure it's safe this time.

Could you drop this patch from your queue at this time? I can send out
the updated patch once I'm convinced it isn't going to regress further.

Thanks and sorry for the noise,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: (subset) [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194
  2021-06-30 17:08   ` Thierry Reding
@ 2021-07-01 12:51     ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-07-01 12:51 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Liam Girdwood, Jon Hunter, Sameer Pujar, linux-tegra, devicetree,
	alsa-devel, Rob Herring

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

On Wed, Jun 30, 2021 at 07:08:40PM +0200, Thierry Reding wrote:

> Could you drop this patch from your queue at this time? I can send out
> the updated patch once I'm convinced it isn't going to regress further.

OK since it's the top commit, in general it's better to send reverts for
things like this though - like some other people I rarely rebase or
otherwise modify existing commits.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-01 12:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 18:11 [PATCH 0/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
2021-06-28 18:11 ` [PATCH 1/2] ASoC: tegra: Use ADMAIF component for DMA allocations Thierry Reding
2021-06-28 18:11 ` [PATCH 2/2] arm64: tegra: Enable audio IOMMU support on Tegra194 Thierry Reding
2021-06-30 16:10 ` (subset) [PATCH 0/2] " Mark Brown
2021-06-30 17:08   ` Thierry Reding
2021-07-01 12:51     ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).