Skip to contentSkip to conversation

ALSA: Drop hackish GFP giveaway for CONTINUOUS pages

PATCH In review Takashi Iwai 2 participants 7 messages Aug 23, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ALSA: Drop hackish GFP giveaway for CONTINUOUS pages

Hi,

this is a series of cleanup patches for dropping the current hackish way of passing the GFP_* flags for CONTINOUS and VMALLOC memory allocations. There are only three users for this legacy feature, and all of them seem superfluous. And, if any driver requires the memory restriction in future, it can now pass the proper device pointer for specifying the DMA mask.

Takashi

===

Takashi Iwai (5):
ALSA: vx: Drop superfluous GFP setup
ALSA: pdaudiocf: Drop superfluous GFP setup
ASoC: Intel: sst: Switch to standard device pages
ALSA: memalloc: Drop special handling of GFP for CONTINUOUS allocation
ALSA: doc: Drop snd_dma_continuous_data() usages

 .../kernel-api/writing-an-alsa-driver.rst     |  21 ++--
 include/sound/memalloc.h                      |   3 -
 sound/core/memalloc.c                         | 113 ++++++++----------
 sound/drivers/vx/vx_pcm.c                     |   3 +-
 sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c        |   3 +-
 sound/soc/intel/atom/sst-mfld-platform-pcm.c  |   7 +-
 6 files changed, 61 insertions(+), 89 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/5 ALSA: vx: Drop superfluous GFP setup

The extra setup with GFP_DMA32 is superfluous for this driver. The whole operation is a simple copy loop, and there is no memory address restriction at all. Drop the useless GFP setup.

---
 sound/drivers/vx/vx_pcm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/drivers/vx/vx_pcm.c +1 -2
index 3924f5283745..ceaeb257003b 100644
@@ -1215,8 +1215,7 @@ int snd_vx_pcm_new(struct vx_core *chip)
 		if (ins)
 			snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &vx_pcm_capture_ops);
 		snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC,
-					       snd_dma_continuous_data(GFP_KERNEL | GFP_DMA32),
-					       0, 0);
+					       NULL, 0, 0);
 
 		pcm->private_data = chip;
 		pcm->private_free = snd_vx_pcm_free;
Signature · 1 line
2.35.3
#2 lore raw

PATCH 2/5 ALSA: pdaudiocf: Drop superfluous GFP setup

In reply to Takashi Iwai

The extra setup with GFP_DMA32 is superfluous for this driver. The whole operation is a simple copy loop, and there is no memory address restriction at all. Drop the useless GFP setup.

---
 sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c +1 -2
index dfc4295b69c4..aaa82ec36540 100644
@@ -257,8 +257,7 @@ int snd_pdacf_pcm_new(struct snd_pdacf *chip)
 		return err;
 		
 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pdacf_pcm_capture_ops);
-	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC,
-				       snd_dma_continuous_data(GFP_KERNEL | GFP_DMA32),
+	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL,
 				       0, 0);
 
 	pcm->private_data = chip;
Signature · 1 line
2.35.3
#3 lore raw

PATCH 3/5 ASoC: Intel: sst: Switch to standard device pages

In reply to Takashi Iwai

ASoC Atom SST driver is using the continuous RAM pages with GFP_DMA flag for its PCM buffer, but this should work fine with the standard DMA pages. As a part of cleanup work, this patch replaces the buffer allocation to the standard device pages with SNDRV_DMA_TYPE_DEV.

---
 sound/soc/intel/atom/sst-mfld-platform-pcm.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
sound/soc/intel/atom/sst-mfld-platform-pcm.c +3 -4
index a56dd48c045f..c75616a5fd0a 100644
@@ -676,10 +676,9 @@ static int sst_soc_pcm_new(struct snd_soc_component *component,
 
 	if (dai->driver->playback.channels_min ||
 			dai->driver->capture.channels_min) {
-		snd_pcm_set_managed_buffer_all(pcm,
-			SNDRV_DMA_TYPE_CONTINUOUS,
-			snd_dma_continuous_data(GFP_DMA),
-			SST_MIN_BUFFER, SST_MAX_BUFFER);
+		snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
+					       pcm->card->dev,
+					       SST_MIN_BUFFER, SST_MAX_BUFFER);
 	}
 	return 0;
 }
Signature · 1 line
2.35.3
maintainer Reviewed-by on v1 3/5
#4 lore raw

Re: [PATCH 3/5] ASoC: Intel: sst: Switch to standard device pages

Quoted 18 lines · Takashi Iwai

ASoC Atom SST driver is using the continuous RAM pages with GFP_DMA flag for its PCM buffer, but this should work fine with the standard DMA pages. As a part of cleanup work, this patch replaces the buffer allocation to the standard device pages with SNDRV_DMA_TYPE_DEV.

---
  sound/soc/intel/atom/sst-mfld-platform-pcm.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
sound/soc/intel/atom/sst-mfld-platform-pcm.c +0 -0
index a56dd48c045f..c75616a5fd0a 100644
@@ -676,10 +676,9 @@ static int sst_soc_pcm_new(struct snd_soc_component *component,
 
  	if (dai->driver->playback.channels_min ||
  			dai->driver->capture.channels_min) {

sound/soc/intel/atom/sst-mfld-platform-pcm.c static int sst_soc_pcm_new(struct snd_soc_component *component, · line 684

Quoted 10 lines
sound/soc/intel/atom/sst-mfld-platform-pcm.c +3 -4
-		snd_pcm_set_managed_buffer_all(pcm,
-			SNDRV_DMA_TYPE_CONTINUOUS,
-			snd_dma_continuous_data(GFP_DMA),
-			SST_MIN_BUFFER, SST_MAX_BUFFER);
+		snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
+					       pcm->card->dev,
+					       SST_MIN_BUFFER, SST_MAX_BUFFER);
  	}
  	return 0;
  }
#5 lore raw

PATCH 4/5 ALSA: memalloc: Drop special handling of GFP for CONTINUOUS allocation

In reply to Takashi Iwai

Now that all users of snd_dma_continuous_data() is gone, let's drop this ugly (and dangerous) way.

After this commit, SNDRV_DMA_TYPE_CONTINUOUS may take the standard device pointer instead of the hacked pointer by the macro above, and the memalloc core refers to the coherent_dma_mask of the given device like other SNDRV_DMA_TYPE. It's still allowed to pass NULL there, and in that case, the allocation is performed always in the normal zone.

For SNDRV_DMA_TYPE_VMALLOC, the device pointer is simply ignored.

---
 include/sound/memalloc.h |   3 --
 sound/core/memalloc.c    | 113 +++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 68 deletions(-)
include/sound/memalloc.h +0 -3
index 8d79cebf95f3..43d524580bd2 100644
@@ -26,9 +26,6 @@ struct snd_dma_device {
 	struct device *dev;		/* generic device */
 };
 
-#define snd_dma_continuous_data(x)	((struct device *)(__force unsigned long)(x))
-
-
 /*
  * buffer types
  */
sound/core/memalloc.c +48 -65

182 lines not on this page · raw message

Signature · 1 line
2.35.3
#6 lore raw

PATCH 5/5 ALSA: doc: Drop snd_dma_continuous_data() usages

In reply to Takashi Iwai

Update the documentation to follow the recent change of the memory allocation helpers. The macro snd_dma_continuous_data() is gone, and the driver needs to set up the coherent dma mask for allocating in the lower memory addresses, instead.

---
 .../kernel-api/writing-an-alsa-driver.rst     | 21 +++++++------------
 1 file changed, 8 insertions(+), 13 deletions(-)
Documentation/sound/kernel-api/writing-an-alsa-driver.rst +8 -13
index 176b73583b7a..07a620c5ca74 100644
@@ -3565,13 +3565,17 @@ given size.
 The second argument (type) and the third argument (device pointer) are
 dependent on the bus. For normal devices, pass the device pointer
 (typically identical as ``card->dev``) to the third argument with
-``SNDRV_DMA_TYPE_DEV`` type. For the continuous buffer unrelated to the
+``SNDRV_DMA_TYPE_DEV`` type.
+
+For the continuous buffer unrelated to the
 bus can be pre-allocated with ``SNDRV_DMA_TYPE_CONTINUOUS`` type.
 You can pass NULL to the device pointer in that case, which is the
 default mode implying to allocate with ``GFP_KERNEL`` flag.
-If you need a different GFP flag, you can pass it by encoding the flag
-into the device pointer via a special macro
-:c:func:`snd_dma_continuous_data()`.
+If you need a restricted (lower) address, set up the coherent DMA mask
+bits for the device, and pass the device pointer, like the normal
+device memory allocations.  For this type, it's still allowed to pass
+NULL to the device pointer, too, if no address restriction is needed.
+
 For the scatter-gather buffers, use ``SNDRV_DMA_TYPE_DEV_SG`` with the
 device pointer (see the `Non-Contiguous Buffers`_ section).
 
@@ -3811,15 +3815,6 @@ arguments here.  Since each vmalloc call should succeed at any time,
 we don't need to pre-allocate the buffers like other continuous
 pages.
 
-If you need the 32bit DMA allocation, pass the device pointer encoded
-by :c:func:`snd_dma_continuous_data()` with ``GFP_KERNEL|__GFP_DMA32``
-argument.
-
-::
-
-  snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC,
-          snd_dma_continuous_data(GFP_KERNEL | __GFP_DMA32), 0, 0);
-
 Proc Interface
 ==============
 
Signature · 1 line
2.35.3