Skip to contentSkip to conversation

soc-pcm: Add separate snd_pcm_runtime for BEs

RFC PATCH In review Codrin Ciubotariu 2 participants 13 messages May 19, 2021 – May 24, 2021

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

cover soc-pcm: Add separate snd_pcm_runtime for BEs

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

Codrin Ciubotariu (6):
ALSA: core: pcm: Create helpers to allocate/free struct
snd_pcm_runtime
ALSA: pcm: Export constraints initialization functions
ALSA: pcm: Check for substream->ops before substream->ops->mmap
ALSA: pcm: Create function for snd_pcm_runtime initialization
ASoC: soc-pcm: Create new snd_pcm_runtime for BE DAIs
ASoC: dmaengine: Allocate buffer if substream is unmanaged

 include/sound/pcm.h                   |   7 ++
 sound/core/pcm.c                      |  82 ++++++++++-------
 sound/core/pcm_native.c               | 116 +++++++++++++-----------
 sound/soc/soc-generic-dmaengine-pcm.c |  18 ++++
 sound/soc/soc-pcm.c                   | 126 ++++++++++++++++++--------
 5 files changed, 229 insertions(+), 120 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

RFC PATCH 1/6 ALSA: core: pcm: Create helpers to allocate/free struct snd_pcm_runtime

Create helpers to be able to reuse code for allocation and freeing of struct snd_pcm_runtime.

---
 include/sound/pcm.h |  2 ++
 sound/core/pcm.c    | 82 +++++++++++++++++++++++++++------------------
 2 files changed, 52 insertions(+), 32 deletions(-)
include/sound/pcm.h +2 -0
index 2e1200d17d0c..025b4d2ba0fe 100644
@@ -574,6 +574,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm)
 }
 #endif
 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
+struct snd_pcm_runtime *snd_pcm_runtime_alloc(void);
+void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime);
 int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
 			   struct snd_pcm_substream **rsubstream);
 void snd_pcm_release_substream(struct snd_pcm_substream *substream);
sound/core/pcm.c +50 -32

114 lines not on this page · raw message

Signature · 1 line
2.27.0
#2 lore raw

RFC PATCH 2/6 ALSA: pcm: Export constraints initialization functions

In reply to Codrin Ciubotariu

Export the functions needed to initialize the constraints. These functions will be used in soc-pcm to initialize the BE constraints.

---
 include/sound/pcm.h     | 3 +++
 sound/core/pcm_native.c | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
include/sound/pcm.h +3 -0
index 025b4d2ba0fe..2907ed2b937f 100644
@@ -1021,6 +1021,9 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
 			snd_pcm_hw_rule_func_t func, void *private,
 			int dep, ...);
 
+int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
+int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
+
 /**
  * snd_pcm_hw_constraint_single() - Constrain parameter to a single value
  * @runtime: PCM runtime instance
sound/core/pcm_native.c +4 -2
index 8dbe86cf2e4f..54e0eab2a57e 100644
@@ -2400,7 +2400,7 @@ static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params *params,
 	return snd_interval_refine(hw_param_interval(params, rule->var), &t);
 }		
 
-static int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
+int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
@@ -2523,8 +2523,9 @@ static int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
 		return err;
 	return 0;
 }
+EXPORT_SYMBOL(snd_pcm_hw_constraints_init);
 
-static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
+int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_pcm_hardware *hw = &runtime->hw;
@@ -2607,6 +2608,7 @@ static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
 
 	return 0;
 }
+EXPORT_SYMBOL(snd_pcm_hw_constraints_complete);
 
 static void pcm_release_private(struct snd_pcm_substream *substream)
 {
Signature · 1 line
2.27.0
#3 lore raw

RFC PATCH 3/6 ALSA: pcm: Check for substream->ops before substream->ops->mmap

In reply to Codrin Ciubotariu

substreams, like the internal ones, might not have ops set. Check it, before looking at substream->ops->mmap.

---
 sound/core/pcm_native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/pcm_native.c +1 -1
index 54e0eab2a57e..cb0164d55593 100644
@@ -246,7 +246,7 @@ static bool hw_support_mmap(struct snd_pcm_substream *substream)
 	if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP))
 		return false;
 
-	if (substream->ops->mmap ||
+	if ((substream->ops && substream->ops->mmap) ||
 	    (substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_DEV &&
 	     substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_DEV_UC))
 		return true;
Signature · 1 line
2.27.0
#4 lore raw

RFC PATCH 4/6 ALSA: pcm: Create function for snd_pcm_runtime initialization

In reply to Codrin Ciubotariu

Group the setting of snd_pcm_runtime members in a separate function. This allows for code reutilization. Also, check for substream->ops before substream->ops->copy_user .

---
 include/sound/pcm.h     |   2 +
 sound/core/pcm_native.c | 108 ++++++++++++++++++++++------------------
 2 files changed, 61 insertions(+), 49 deletions(-)
include/sound/pcm.h +2 -0
index 2907ed2b937f..8e6bd4525c02 100644
@@ -576,6 +576,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm)
 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
 struct snd_pcm_runtime *snd_pcm_runtime_alloc(void);
 void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime);
+void snd_pcm_runtime_set(struct snd_pcm_substream *substream,
+			 struct snd_pcm_hw_params *params);
 int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
 			   struct snd_pcm_substream **rsubstream);
 void snd_pcm_release_substream(struct snd_pcm_substream *substream);
sound/core/pcm_native.c +59 -49

125 lines not on this page · raw message

Signature · 1 line
2.27.0
#5 lore raw

RFC PATCH 5/6 ASoC: soc-pcm: Create new snd_pcm_runtime for BE DAIs

In reply to Codrin Ciubotariu

The BE DAIs are different than the FE DAIs. They have different HW capabilities, different HW constraints and different HW parameters. Also, the buffer used to read/write data from/to user-space to/from FE DAIs has nothing to do with the BE DAIs. For this reason, this patch creates a new snd_pcm_runtime for the BE DAIs. The new structure can be used to better represent the HW capabilities, so the HW parameters are no longer copied from the FE, but created separately. For BE DAIs that need a buffer to move the data to/from the FE DAIs (no dev-to-dev DMA capability), the new snd_pcm_runtime can store the needed parameters to allocate the buffer and set the DMA transfers.

---
 sound/soc/soc-pcm.c | 126 +++++++++++++++++++++++++++++++-------------
 1 file changed, 90 insertions(+), 36 deletions(-)
sound/soc/soc-pcm.c +90 -36
index 8659089a87a0..7d95df20541e 100644
@@ -1134,7 +1134,6 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
 
 	dpcm->be = be;
 	dpcm->fe = fe;
-	be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
 	dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
 	spin_lock_irqsave(&fe->card->dpcm_lock, flags);
 	list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
@@ -1150,34 +1149,6 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
 	return 1;
 }
 
-/* reparent a BE onto another FE */
-static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
-			struct snd_soc_pcm_runtime *be, int stream)
-{
-	struct snd_soc_dpcm *dpcm;
-	struct snd_pcm_substream *fe_substream, *be_substream;
-
-	/* reparent if BE is connected to other FEs */
-	if (!be->dpcm[stream].users)
-		return;
-
-	be_substream = snd_soc_dpcm_get_substream(be, stream);
-
-	for_each_dpcm_fe(be, stream, dpcm) {
-		if (dpcm->fe == fe)
-			continue;
-
-		dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
-			stream ? "capture" : "playback",
-			dpcm->fe->dai_link->name,
-			stream ? "<-" : "->", dpcm->be->dai_link->name);
-
-		fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
-		be_substream->runtime = fe_substream->runtime;
-		break;
-	}
-}
-
 /* disconnect a BE and FE */
 void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
 {
@@ -1196,9 +1167,6 @@ void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
 			stream ? "capture" : "playback", fe->dai_link->name,
 			stream ? "<-" : "->", dpcm->be->dai_link->name);
 
-		/* BEs still alive need new FE */
-		dpcm_be_reparent(fe, dpcm->be, stream);
-
 		dpcm_remove_debugfs_state(dpcm);
 
 		spin_lock_irqsave(&fe->card->dpcm_lock, flags);
@@ -1468,7 +1436,12 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
 		}
 
 		soc_pcm_close(be_substream);
-		be_substream->runtime = NULL;
+
+		if (be_substream->runtime) {
+			snd_pcm_runtime_free(be_substream->runtime);
+			be_substream->runtime = NULL;
+		}
+
 		be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
 	}
 }
@@ -1482,6 +1455,7 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
 	/* only startup BE DAIs that are either sinks or sources to this FE DAI */
 	for_each_dpcm_be(fe, stream, dpcm) {
 		struct snd_pcm_substream *be_substream;
+		struct snd_pcm_runtime *runtime;
 
 		be = dpcm->be;
 		be_substream = snd_soc_dpcm_get_substream(be, stream);
@@ -1514,7 +1488,23 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
 		dev_dbg(be->dev, "ASoC: open %s BE %s\n",
 			stream ? "capture" : "playback", be->dai_link->name);
 
-		be_substream->runtime = be->dpcm[stream].runtime;
+		runtime = snd_pcm_runtime_alloc();
+		if (!runtime) {
+			err = -ENOMEM;
+			goto unwind;
+		}
+
+		be_substream->runtime = runtime;
+
+		/* initialize the BE constraints */
+		err = snd_pcm_hw_constraints_init(be_substream);
+		if (err < 0) {
+			dev_err(be->dev,
+				"dpcm_be_hw_constraints_init failed: %d\n",
+				err);
+			goto unwind;
+		}
+
 		err = soc_pcm_open(be_substream);
 		if (err < 0) {
 			be->dpcm[stream].users--;
@@ -1527,6 +1517,14 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
 			goto unwind;
 		}
 
+		err = snd_pcm_hw_constraints_complete(be_substream);
+		if (err < 0) {
+			dev_err(fe->dev,
+				"snd_pcm_hw_constraints_complete failed: %d\n",
+				err);
+			goto unwind;
+		}
+
 		be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
 		count++;
 	}
@@ -1897,6 +1895,14 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
 		if (ret < 0)
 			goto unwind;
 
+		/* apply constrains */
+		dpcm->hw_params.rmask = ~0U;
+		ret = snd_pcm_hw_refine(be_substream, &dpcm->hw_params);
+		if (ret < 0) {
+			dev_err(fe->dev, "failed to refine hw parameters: %d\n", ret);
+			goto unwind;
+		}
+
 		/* copy the fixed-up hw params for BE dai */
 		memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params,
 		       sizeof(struct snd_pcm_hw_params));
@@ -1918,6 +1924,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
 			goto unwind;
 
 		be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
+		snd_pcm_runtime_set(be_substream, &dpcm->hw_params);
 	}
 	return 0;
 
@@ -1949,17 +1956,64 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
 	return ret;
 }
 
+static int dpcm_be_dai_hw_params_init(struct snd_soc_pcm_runtime *fe, int stream)
+{
+	struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
+	int k;
+
+	for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK;
+	     k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++)
+		snd_mask_any(hw_param_mask(params, k));
+
+	for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL;
+	     k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
+		snd_interval_any(hw_param_interval(params, k));
+
+	return 0;
+}
+
 static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
 				 struct snd_pcm_hw_params *params)
 {
 	struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
 	int ret, stream = substream->stream;
+	struct snd_interval *t, *dpcm_t;
 
 	mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
 	dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
 
-	memcpy(&fe->dpcm[stream].hw_params, params,
-			sizeof(struct snd_pcm_hw_params));
+	/* initialize the BE HW params */
+	dpcm_be_dai_hw_params_init(fe, stream);
+
+	/* FIXME: a very low period time will make the CPU take too many
+	 * interrupts, which might end up not having enough time to actually
+	 * fill the buffer(s); for now, the BE min period time will be half of
+	 * the FE min period time
+	 */
+	t = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
+	dpcm_t = hw_param_interval(&fe->dpcm[stream].hw_params,
+				   SNDRV_PCM_HW_PARAM_PERIOD_TIME);
+	dpcm_t->min = t->min / 2;
+
+	if (fe->dai_link->dpcm_merged_format) {
+		memcpy(hw_param_interval(&fe->dpcm[stream].hw_params,
+					 SNDRV_PCM_HW_PARAM_FORMAT),
+		       hw_param_interval(params, SNDRV_PCM_HW_PARAM_FORMAT),
+		       sizeof(struct snd_interval));
+	}
+	if (fe->dai_link->dpcm_merged_chan) {
+		memcpy(hw_param_interval(&fe->dpcm[stream].hw_params,
+					 SNDRV_PCM_HW_PARAM_CHANNELS),
+		       hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS),
+		       sizeof(struct snd_interval));
+	}
+	if (fe->dai_link->dpcm_merged_rate) {
+		memcpy(hw_param_interval(&fe->dpcm[stream].hw_params,
+					 SNDRV_PCM_HW_PARAM_RATE),
+		       hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE),
+		       sizeof(struct snd_interval));
+	}
+
 	ret = dpcm_be_dai_hw_params(fe, stream);
 	if (ret < 0)
 		goto out;
Signature · 1 line
2.27.0
#6 lore raw

RFC PATCH 6/6 ASoC: dmaengine: Allocate buffer if substream is unmanaged

In reply to Codrin Ciubotariu

pcm_construct/pcm_destruct callbacks are not called for BE DAIs. This means that, if the generic dmaengine driver is used, there is no managed buffer allocation (or pre-allocation). To be able to use the generic dmaengine driver for BE DAI links, allocate the buffer in the hw_params callback if there is no managed buffer.

---
 sound/soc/soc-generic-dmaengine-pcm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
sound/soc/soc-generic-dmaengine-pcm.c +18 -0
index 9ef80a48707e..c915da71e1cd 100644
@@ -98,6 +98,22 @@ static int dmaengine_pcm_hw_params(struct snd_soc_component *component,
 			return ret;
 	}
 
+	if (!substream->managed_buffer_alloc) {
+		substream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV_IRAM;
+		substream->dma_buffer.dev.dev = chan->device->dev;
+		return snd_pcm_lib_malloc_pages(substream,
+						params_buffer_bytes(params));
+	}
+
+	return 0;
+}
+
+static int dmaengine_pcm_hw_free(struct snd_soc_component *component,
+				 struct snd_pcm_substream *substream)
+{
+	if (!substream->managed_buffer_alloc)
+		return snd_pcm_lib_free_pages(substream);
+
 	return 0;
 }
 
@@ -332,6 +348,7 @@ static const struct snd_soc_component_driver dmaengine_pcm_component = {
 	.open		= dmaengine_pcm_open,
 	.close		= dmaengine_pcm_close,
 	.hw_params	= dmaengine_pcm_hw_params,
+	.hw_free	= dmaengine_pcm_hw_free,
 	.trigger	= dmaengine_pcm_trigger,
 	.pointer	= dmaengine_pcm_pointer,
 	.pcm_construct	= dmaengine_pcm_new,
@@ -343,6 +360,7 @@ static const struct snd_soc_component_driver dmaengine_pcm_component_process = {
 	.open		= dmaengine_pcm_open,
 	.close		= dmaengine_pcm_close,
 	.hw_params	= dmaengine_pcm_hw_params,
+	.hw_free	= dmaengine_pcm_hw_free,
 	.trigger	= dmaengine_pcm_trigger,
 	.pointer	= dmaengine_pcm_pointer,
 	.copy_user	= dmaengine_copy_user,
Signature · 1 line
2.27.0
#7 lore raw
In reply to Codrin Ciubotariu
Quoted 22 lines · Codrin Ciubotariu

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

Quoted 8 lines

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

I'm also concerned about the handling of other fields in runtime object, maybe allocating a complete runtime object for each BE is an overkill and fragile. Could it be rather only hw_constraints to be unique for each BE, instead?

Also, the last patch allows only IRAM type, which sounds already doubtful. The dmaengine code should be generic.

Last but not least, one minor nitpick: please use EXPORT_SYMBOL_GPL() for the newly introduced symbols.

thanks,

Takashi

#8 lore raw
Quoted 35 lines · Takashi Iwai

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 22 lines · Codrin Ciubotariu

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

Quoted 8 lines

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

Quoted 4 lines

I'm also concerned about the handling of other fields in runtime object, maybe allocating a complete runtime object for each BE is an overkill and fragile. Could it be rather only hw_constraints to be unique for each BE, instead?

I tried with only the hw constraints in the previous patchset and it's difficult to handle the snd_pcm_hw_rule_add() calls, without changing the function's declaration. This solution requires no changes to constraints API, nor to their 'clients'. I agree that handling all the runtime fields might be over-complicated. From what I see, the scary ones are used to describe the buffer and the status of the transfers. I do not think there are BEs that use these values at this moment (the FE ones). I think that the HW params, private section, hardware description and maybe DMA members (at least in my case) are mostly needed by BEs.

Quoted 2 lines

Also, the last patch allows only IRAM type, which sounds already doubtful. The dmaengine code should be generic.

dmaengine, when used with normal PCM, preallocates only IRAM buffers [1]. This BE buffer would only be needed if DMA dev-to-mem or mem-to-dev transfers are needed, between FE and BE. I agree that it could be handled differently, I added it here mostly to express my goal, which is to use the generic dmaengine for BEs. My DMA has no dev-to-dev DMA capability, so I need a buffer to move the data between FE and BE.

Quoted 3 lines

Last but not least, one minor nitpick: please use EXPORT_SYMBOL_GPL() for the newly introduced symbols.

Sure, this is an oversight on my side. I will make all of them EXPORT_SYMBOL_GPL.

Thank you very much for your review!

Best regards,
Codrin

[1]
https://elixir.bootlin.com/linux/v5.13-rc2/source/sound/soc/soc-generic-dmaengine-pcm.c#L266

#9 lore raw
Quoted 42 lines · On Wed, 19 May 2021 17:08:10 +0200, <[email protected]> wrote:
Quoted 35 lines · Takashi Iwai

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 22 lines · Codrin Ciubotariu

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

Quoted 8 lines

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

Quoted 4 lines

I'm also concerned about the handling of other fields in runtime object, maybe allocating a complete runtime object for each BE is an overkill and fragile. Could it be rather only hw_constraints to be unique for each BE, instead?

Quoted 9 lines

I tried with only the hw constraints in the previous patchset and it's difficult to handle the snd_pcm_hw_rule_add() calls, without changing the function's declaration. This solution requires no changes to constraints API, nor to their 'clients'. I agree that handling all the runtime fields might be over-complicated. From what I see, the scary ones are used to describe the buffer and the status of the transfers. I do not think there are BEs that use these values at this moment (the FE ones). I think that the HW params, private section, hardware description and maybe DMA members (at least in my case) are mostly needed by BEs.

OK, I'll check your previous series again, but my gut feeling is for pursuit to the hw_constraints hacks. e.g. we may split snd_pcm_hw_constraints and snd_pcm_hw_rule, too, if that matters.

Quoted 9 lines
Quoted 2 lines

Also, the last patch allows only IRAM type, which sounds already doubtful. The dmaengine code should be generic.

dmaengine, when used with normal PCM, preallocates only IRAM buffers [1]. This BE buffer would only be needed if DMA dev-to-mem or mem-to-dev transfers are needed, between FE and BE. I agree that it could be handled differently, I added it here mostly to express my goal, which is to use the generic dmaengine for BEs. My DMA has no dev-to-dev DMA capability, so I need a buffer to move the data between FE and BE.

Ah, right, I overlooked that part... It's confusing. Maybe it's in that style just because it falls back to SNDRV_DMA_TYPE_DEV? It's another discussion, in anyway.

thanks,

Takashi

#10 lore raw
Quoted 54 lines · Takashi Iwai
Quoted 42 lines · On Wed, 19 May 2021 17:08:10 +0200, <[email protected]> wrote:
Quoted 35 lines · Takashi Iwai

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 22 lines · Codrin Ciubotariu

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

Quoted 8 lines

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

Quoted 4 lines

I'm also concerned about the handling of other fields in runtime object, maybe allocating a complete runtime object for each BE is an overkill and fragile. Could it be rather only hw_constraints to be unique for each BE, instead?

Quoted 9 lines

I tried with only the hw constraints in the previous patchset and it's difficult to handle the snd_pcm_hw_rule_add() calls, without changing the function's declaration. This solution requires no changes to constraints API, nor to their 'clients'. I agree that handling all the runtime fields might be over-complicated. From what I see, the scary ones are used to describe the buffer and the status of the transfers. I do not think there are BEs that use these values at this moment (the FE ones). I think that the HW params, private section, hardware description and maybe DMA members (at least in my case) are mostly needed by BEs.

Quoted 3 lines

OK, I'll check your previous series again, but my gut feeling is for pursuit to the hw_constraints hacks. e.g. we may split snd_pcm_hw_constraints and snd_pcm_hw_rule, too, if that matters.

Something like adding snd_pcm_hw_rule directly under snd_pcm_runtime, to store the BE constraints? It could work, but I think we should also be able to remove rules, if one BE gets disconnected. This means that we will need a way to identify or separate them, for each BE, right?

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

Also, the last patch allows only IRAM type, which sounds already doubtful. The dmaengine code should be generic.

dmaengine, when used with normal PCM, preallocates only IRAM buffers [1]. This BE buffer would only be needed if DMA dev-to-mem or mem-to-dev transfers are needed, between FE and BE. I agree that it could be handled differently, I added it here mostly to express my goal, which is to use the generic dmaengine for BEs. My DMA has no dev-to-dev DMA capability, so I need a buffer to move the data between FE and BE.

Quoted 3 lines

Ah, right, I overlooked that part... It's confusing. Maybe it's in that style just because it falls back to SNDRV_DMA_TYPE_DEV? It's another discussion, in anyway.

Right, it falls back to SNDRV_DMA_TYPE_DEV. [1]

Thanks and best regards,
Codrin

[1]
https://elixir.bootlin.com/linux/v5.13-rc2/source/sound/core/memalloc.c#L154

#11 lore raw
Quoted 60 lines · On Thu, 20 May 2021 15:59:02 +0200, <[email protected]> wrote:
Quoted 54 lines · Takashi Iwai
Quoted 42 lines · On Wed, 19 May 2021 17:08:10 +0200, <[email protected]> wrote:
Quoted 35 lines · Takashi Iwai

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 22 lines · Codrin Ciubotariu

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

Quoted 8 lines

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

Quoted 4 lines

I'm also concerned about the handling of other fields in runtime object, maybe allocating a complete runtime object for each BE is an overkill and fragile. Could it be rather only hw_constraints to be unique for each BE, instead?

Quoted 9 lines

I tried with only the hw constraints in the previous patchset and it's difficult to handle the snd_pcm_hw_rule_add() calls, without changing the function's declaration. This solution requires no changes to constraints API, nor to their 'clients'. I agree that handling all the runtime fields might be over-complicated. From what I see, the scary ones are used to describe the buffer and the status of the transfers. I do not think there are BEs that use these values at this moment (the FE ones). I think that the HW params, private section, hardware description and maybe DMA members (at least in my case) are mostly needed by BEs.

Quoted 3 lines

OK, I'll check your previous series again, but my gut feeling is for pursuit to the hw_constraints hacks. e.g. we may split snd_pcm_hw_constraints and snd_pcm_hw_rule, too, if that matters.

Quoted 5 lines

Something like adding snd_pcm_hw_rule directly under snd_pcm_runtime, to store the BE constraints? It could work, but I think we should also be able to remove rules, if one BE gets disconnected. This means that we will need a way to identify or separate them, for each BE, right?

Well, if each BE needs a different set of hw constraint rules, it needs its own unique copies instead of sharing the rules. Is it your requirement?

Takashi

#12 lore raw
Quoted 70 lines · Takashi Iwai

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 60 lines · On Thu, 20 May 2021 15:59:02 +0200, <[email protected]> wrote:
Quoted 54 lines · Takashi Iwai
Quoted 42 lines · On Wed, 19 May 2021 17:08:10 +0200, <[email protected]> wrote:
Quoted 35 lines · Takashi Iwai

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 22 lines · Codrin Ciubotariu

This patchset adds a different snd_pcm_runtime in the BE's substream, replacing the FE's snd_pcm_runtime. With a different structure, the BE HW capabilities and constraints will no longer merge with the FE ones. This allows for error detection if the be_hw_params_fixup() applies HW parameters not supported by the BE DAIs. Also, it calculates values needed for mem-to-dev/dev-to-mem DMA transfers, such as buffer size and period size, if needed.

The first 4 patches are preparatory patches, that just group and export functions used to allocate and initialize the snd_pcm_runtime. Also, the functions that set and apply the HW constraints are exported.
The 5th patch does (almost) everything need to create the new snd_pcm_runtime for BEs, which includes allocation, initializing the HW capabilities, HW constraints and HW parameters. The BE HW parameters are no longer copied from the FE. They are recalculated, based on HW capabilities, constraints and the be_hw_params_fixup() callback.
The 6th and last patch basically adds support for the PCM generic dmaengine to be used as a platform driver for BE DAI links. It allocates a buffer, needed by the DMA transfers that do not support dev-to-dev transfers between FE and BE DAIs.

Quoted 8 lines

This is a superset of
https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/182630.html
which only handles the BE HW constraints. This patchset aims to be more complete, defining a a snd_pcm_runtime between each FE and BE and can be used between any DAI link connection. I am sure I am not handling all the needed members of snd_pcm_runtime (such as handling struct snd_pcm_mmap_status *status), but I would like to have your feedback regarding this idea.

Quoted 4 lines

I'm also concerned about the handling of other fields in runtime object, maybe allocating a complete runtime object for each BE is an overkill and fragile. Could it be rather only hw_constraints to be unique for each BE, instead?

Quoted 9 lines

I tried with only the hw constraints in the previous patchset and it's difficult to handle the snd_pcm_hw_rule_add() calls, without changing the function's declaration. This solution requires no changes to constraints API, nor to their 'clients'. I agree that handling all the runtime fields might be over-complicated. From what I see, the scary ones are used to describe the buffer and the status of the transfers. I do not think there are BEs that use these values at this moment (the FE ones). I think that the HW params, private section, hardware description and maybe DMA members (at least in my case) are mostly needed by BEs.

Quoted 3 lines

OK, I'll check your previous series again, but my gut feeling is for pursuit to the hw_constraints hacks. e.g. we may split snd_pcm_hw_constraints and snd_pcm_hw_rule, too, if that matters.

Quoted 5 lines

Something like adding snd_pcm_hw_rule directly under snd_pcm_runtime, to store the BE constraints? It could work, but I think we should also be able to remove rules, if one BE gets disconnected. This means that we will need a way to identify or separate them, for each BE, right?

Quoted 3 lines

Well, if each BE needs a different set of hw constraint rules, it needs its own unique copies instead of sharing the rules. Is it your requirement?

Yes, I am thinking that the constraints should be grouped for one BE, since the HW parameters are the same for all the DAIs(CPUs and codecs) in a BE.
Also, I think that the separation of snd_pcm_hardware is important. From what I understand now, the BE CPUs snd_soc_pcm_stream structures are ignored entirely and the codecs snd_soc_pcm_stream structures are considered only if fe->dai_link->dpcm_merged_* flags are set [1]. This means that be_hw_params_fixup() callback (BE HW params) is not affected by the BE drivers' snd_soc_pcm_stream. We are relying on the fact that developers know what capabilities the BE DAIs have, in order to set be_hw_params_fixup. Even though HW capabilities are subject to change if HW bugs are discovered... Am I making sense?
I still prefer the separate snd_pcm_runtime, since, for my case, I am able to set different runtime->(rate, channels, subformat, frame_bits, sample_bits, period/buffer_size, etc.) and later use bytes_to_* and *_to_bytes() callbacks freely, but if this step is too big, maybe we can split it up and start with something we can all agree on the HW constraints.

Thank you for your time!

Best regards,
Codrin

[1]
https://elixir.bootlin.com/linux/v5.13-rc3/source/sound/soc/soc-pcm.c#L1768