Skip to contentSkip to conversation

Make the SOF control, PCM and PM code IPC agnostic

PATCH In review Ranjani Sridharan 2 participants 21 messages Mar 17, 2022 – Mar 18, 2022

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

cover Make the SOF control, PCM and PM code IPC agnostic

This series is a continuation to the SOF IPC abstraction work to support the new IPC version introduced in the SOF firmware. It makes the top-level control IO, PCM and PM code IPC-agnostic. Other than the first patch, the rest are purely for abstraction and include no changes in functionality.

Ranjani Sridharan (19):
ASoC: SOF: set up scheduler widget before all other widgets in the
pipeline
ASoC: SOF: Make sof_widget_setup/free IPC agnostic
ASoC: SOF: Make sof_suspend/resume IPC agnostic
ASoC: SOF: Introduce IPC ops for kcontrol IO
ASoC: SOF: Add IPC3 topology control ops
ASoC: SOF: Add volume_get/put IPC3 ops
ASoC: SOF: Add switch get/put IPC3 ops
ASoC: SOF: Add enum_get/put control ops for IPC3
ASoC: SOF: Add bytes_get/put control IPC ops for IPC3
ASoC: SOF: Add bytes_ext control IPC ops for IPC3
ASoC: SOF: Introduce IPC-specific PCM ops
ASoC: SOF: pcm: expose the sof_pcm_setup_connected_widgets() function
ASoC: SOF: Introduce IPC3 PCM hw_free op
ASoC: SOF: Define hw_params PCM op for IPC3
ASoC: SOF: Add trigger PCM op for IPC3
ASoC: SOF: Add dai_link_fixup PCM op for IPC3
ASoC: SOF: expose sof_route_setup()
ASoC: SOF: topology: Add ops for setting up and tearing down pipelines
ASoC: SOF: Add a new dai_get_clk topology IPC op

 sound/soc/sof/Makefile        |   2 +-
 sound/soc/sof/control.c       | 545 ++++---------------------------
 sound/soc/sof/intel/hda-dai.c |  97 +-----
 sound/soc/sof/intel/hda.c     | 169 +++-------
 sound/soc/sof/intel/hda.h     |   7 +-
 sound/soc/sof/ipc.c           |  10 +-
 sound/soc/sof/ipc3-control.c  | 594 ++++++++++++++++++++++++++++++++++
 sound/soc/sof/ipc3-ops.h      |  21 ++
 sound/soc/sof/ipc3-pcm.c      | 372 +++++++++++++++++++++
 sound/soc/sof/ipc3-topology.c | 384 +++++++++++++++++++++-
 sound/soc/sof/ipc3.c          |  45 +++
 sound/soc/sof/pcm.c           | 354 +++-----------------
 sound/soc/sof/pm.c            |  80 ++---
 sound/soc/sof/sof-audio.c     | 442 +++++--------------------
 sound/soc/sof/sof-audio.h     |  70 +++-
 sound/soc/sof/sof-priv.h      |  17 +-
 sound/soc/sof/topology.c      |  55 ++--
 17 files changed, 1805 insertions(+), 1459 deletions(-)
 create mode 100644 sound/soc/sof/ipc3-control.c
 create mode 100644 sound/soc/sof/ipc3-ops.h
 create mode 100644 sound/soc/sof/ipc3-pcm.c
 create mode 100644 sound/soc/sof/ipc3.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/19 ASoC: SOF: set up scheduler widget before all other widgets in the pipeline

For dynamic pipelines, We set up the DAI widget during BE DAI hw_params and this results in it getting set up before the scheduler widget for the pipeline it belongs to is set up. Move the scheduler widget set up into sof_widget_setup() to ensure that the scheduler widget is always the first widget in a pipeline to be set up and the last one to get freed after all the other widgets have been freed.

Fixes 5fcdbb2d45df ('ASoC: SOF: Add support for dynamic pipelines')
---
 sound/soc/sof/sof-audio.c | 82 +++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 38 deletions(-)
sound/soc/sof/sof-audio.c +44 -38
index 683c290bb69a..cc0d647a2d0d 100644
@@ -104,7 +104,7 @@ int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
 		.id = swidget->comp_id,
 	};
 	struct sof_ipc_reply reply;
-	int ret, ret1;
+	int ret, err;
 
 	if (!swidget->private)
 		return 0;
@@ -136,31 +136,41 @@ int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
 	}
 
 	/* continue to disable core even if IPC fails */
-	ret = sof_ipc_tx_message(sdev->ipc, ipc_free.hdr.cmd, &ipc_free, sizeof(ipc_free),
+	err = sof_ipc_tx_message(sdev->ipc, ipc_free.hdr.cmd, &ipc_free, sizeof(ipc_free),
 				 &reply, sizeof(reply));
-	if (ret < 0)
+	if (err < 0)
 		dev_err(sdev->dev, "error: failed to free widget %s\n", swidget->widget->name);
 
 	/*
 	 * disable widget core. continue to route setup status and complete flag
 	 * even if this fails and return the appropriate error
 	 */
-	ret1 = snd_sof_dsp_core_put(sdev, swidget->core);
-	if (ret1 < 0) {
+	ret = snd_sof_dsp_core_put(sdev, swidget->core);
+	if (ret < 0) {
 		dev_err(sdev->dev, "error: failed to disable target core: %d for widget %s\n",
 			swidget->core, swidget->widget->name);
-		if (!ret)
-			ret = ret1;
+		if (!err)
+			err = ret;
 	}
 
 	/* reset route setup status for all routes that contain this widget */
 	sof_reset_route_setup_status(sdev, swidget);
 	swidget->complete = 0;
 
-	if (!ret)
+	/*
+	 * free the scheduler widget (same as pipe_widget) associated with the current swidget.
+	 * skip for static pipelines
+	 */
+	if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
+		ret = sof_widget_free(sdev, swidget->pipe_widget);
+		if (ret < 0 && !err)
+			err = ret;
+	}
+
+	if (!err)
 		dev_dbg(sdev->dev, "widget %s freed\n", swidget->widget->name);
 
-	return ret;
+	return err;
 }
 EXPORT_SYMBOL(sof_widget_free);
 
@@ -181,12 +191,32 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
 	if (++swidget->use_count > 1)
 		return 0;
 
+	/*
+	 * The scheduler widget for a pipeline is not part of the connected DAPM
+	 * widget list and it needs to be set up before the widgets in the pipeline
+	 * are set up. The use_count for the scheduler widget is incremented for every
+	 * widget in a given pipeline to ensure that it is freed only after the last
+	 * widget in the pipeline is freed. Skip setting up scheduler widget for static pipelines.
+	 */
+	if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
+		if (!swidget->pipe_widget) {
+			dev_err(sdev->dev, "No scheduler widget set for %s\n",
+				swidget->widget->name);
+			ret = -EINVAL;
+			goto use_count_dec;
+		}
+
+		ret = sof_widget_setup(sdev, swidget->pipe_widget);
+		if (ret < 0)
+			goto use_count_dec;
+	}
+
 	/* enable widget core */
 	ret = snd_sof_dsp_core_get(sdev, swidget->core);
 	if (ret < 0) {
 		dev_err(sdev->dev, "error: failed to enable target core for widget %s\n",
 			swidget->widget->name);
-		goto use_count_dec;
+		goto pipe_widget_free;
 	}
 
 	switch (swidget->id) {
@@ -257,6 +287,9 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
 
 core_put:
 	snd_sof_dsp_core_put(sdev, swidget->core);
+pipe_widget_free:
+	if (swidget->id != snd_soc_dapm_scheduler)
+		sof_widget_free(sdev, swidget->pipe_widget);
 use_count_dec:
 	swidget->use_count--;
 	return ret;
@@ -374,36 +407,14 @@ int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, in
 	/* set up widgets in the list */
 	for_each_dapm_widgets(list, num_widgets, widget) {
 		struct snd_sof_widget *swidget = widget->dobj.private;
-		struct snd_sof_widget *pipe_widget;
 
 		if (!swidget)
 			continue;
 
-		/*
-		 * The scheduler widget for a pipeline is not part of the connected DAPM
-		 * widget list and it needs to be set up before the widgets in the pipeline
-		 * are set up. The use_count for the scheduler widget is incremented for every
-		 * widget in a given pipeline to ensure that it is freed only after the last
-		 * widget in the pipeline is freed.
-		 */
-		pipe_widget = swidget->pipe_widget;
-		if (!pipe_widget) {
-			dev_err(sdev->dev, "error: no pipeline widget found for %s\n",
-				swidget->widget->name);
-			ret = -EINVAL;
-			goto widget_free;
-		}
-
-		ret = sof_widget_setup(sdev, pipe_widget);
-		if (ret < 0)
-			goto widget_free;
-
 		/* set up the widget */
 		ret = sof_widget_setup(sdev, swidget);
-		if (ret < 0) {
-			sof_widget_free(sdev, pipe_widget);
+		if (ret < 0)
 			goto widget_free;
-		}
 	}
 
 	/*
@@ -456,7 +467,6 @@ int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, in
 			break;
 
 		sof_widget_free(sdev, swidget);
-		sof_widget_free(sdev, swidget->pipe_widget);
 	}
 
 	return ret;
@@ -490,10 +500,6 @@ int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int
 		ret = sof_widget_free(sdev, swidget);
 		if (ret < 0)
 			ret1 = ret;
-
-		ret = sof_widget_free(sdev, swidget->pipe_widget);
-		if (ret < 0)
-			ret1 = ret;
 	}
 
 	snd_soc_dapm_dai_free_widgets(&list);
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/19 ASoC: SOF: Make sof_widget_setup/free IPC agnostic

In reply to Ranjani Sridharan

Add 3 new topology IPC ops for widget_setup, widget_free and dai_config in order to make the pipeline management code IPC agnostic and implement the ops for IPC3.

Use the newly introduced tplg dai_config op to configure the DAI during BE DAI hw_params and hw_free.

Also, in preparation for IPC4, modify BE hw_params callback to skip setting up the DAI widget. All widgets will be set up during FW hw_params and the DAI_CONFIG IPC should be sent only if the widget use_count is > 0. With setting up/freeing removed from the BE hw_params, remove the configured flag as it is no longer needed.

---
 sound/soc/sof/intel/hda-dai.c |  97 +++----------------
 sound/soc/sof/intel/hda.c     | 169 +++++++++-------------------------
 sound/soc/sof/intel/hda.h     |   7 +-
 sound/soc/sof/ipc3-topology.c | 150 ++++++++++++++++++++++++++++++
 sound/soc/sof/sof-audio.c     | 136 +++++----------------------
 sound/soc/sof/sof-audio.h     |  13 ++-
 6 files changed, 246 insertions(+), 326 deletions(-)
sound/soc/sof/intel/hda-dai.c +13 -84
index 9b78eea8d76b..f9cb9f1f0237 100644
@@ -162,58 +162,19 @@ static int hda_link_dma_params(struct hdac_ext_stream *hext_stream,
 	return 0;
 }
 
-/* Update config for the DAI widget */
-static struct sof_ipc_dai_config *hda_dai_update_config(struct snd_soc_dapm_widget *w,
-							int channel)
-{
-	struct snd_sof_widget *swidget = w->dobj.private;
-	struct sof_dai_private_data *private;
-	struct sof_ipc_dai_config *config;
-	struct snd_sof_dai *sof_dai;
-
-	if (!swidget)
-		return NULL;
-
-	sof_dai = swidget->private;
-
-	if (!sof_dai || !sof_dai->private) {
-		dev_err(swidget->scomp->dev, "%s: No private data for DAI %s\n", __func__,
-			w->name);
-		return NULL;
-	}
-
-	private = sof_dai->private;
-	if (!private->dai_config) {
-		dev_err(swidget->scomp->dev, "%s: No config for DAI %s\n", __func__, w->name);
-		return NULL;
-	}
-
-	config = &private->dai_config[sof_dai->current_config];
-
-	/* update config with stream tag */
-	config->hda.link_dma_ch = channel;
-
-	return config;
-}
-
 static int hda_link_dai_widget_update(struct sof_intel_hda_stream *hda_stream,
 				      struct snd_soc_dapm_widget *w,
 				      int channel, bool widget_setup)
 {
-	struct snd_sof_dev *sdev = hda_stream->sdev;
-	struct sof_ipc_dai_config *config;
+	struct snd_sof_dai_config_data data;
 
-	config = hda_dai_update_config(w, channel);
-	if (!config) {
-		dev_err(sdev->dev, "error: no config for DAI %s\n", w->name);
-		return -ENOENT;
-	}
+	data.dai_data = channel;
 
 	/* set up/free DAI widget and send DAI_CONFIG IPC */
 	if (widget_setup)
-		return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_2_STEP_STOP);
+		return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_2_STEP_STOP, &data);
 
-	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE);
+	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
 }
 
 static int hda_link_hw_params(struct snd_pcm_substream *substream,
@@ -302,35 +263,16 @@ static int hda_link_dai_config_pause_push_ipc(struct snd_soc_dapm_widget *w)
 	struct snd_sof_widget *swidget = w->dobj.private;
 	struct snd_soc_component *component = swidget->scomp;
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
-	struct sof_dai_private_data *private;
-	struct sof_ipc_dai_config *config;
-	struct snd_sof_dai *sof_dai;
-	struct sof_ipc_reply reply;
-	int ret;
-
-	sof_dai = swidget->private;
-
-	if (!sof_dai || !sof_dai->private) {
-		dev_err(sdev->dev, "%s: No private data for DAI %s\n", __func__, w->name);
-		return -EINVAL;
-	}
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
+	int ret = 0;
 
-	private = sof_dai->private;
-	if (!private->dai_config) {
-		dev_err(sdev->dev, "%s: No config for DAI %s\n", __func__, w->name);
-		return -EINVAL;
+	if (tplg_ops->dai_config) {
+		ret = tplg_ops->dai_config(sdev, swidget, SOF_DAI_CONFIG_FLAGS_PAUSE, NULL);
+		if (ret < 0)
+			dev_err(sdev->dev, "%s: DAI config failed for widget %s\n", __func__,
+				w->name);
 	}
 
-	config = &private->dai_config[sof_dai->current_config];
-
-	/* set PAUSE command flag */
-	config->flags = FIELD_PREP(SOF_DAI_CONFIG_FLAGS_CMD_MASK, SOF_DAI_CONFIG_FLAGS_PAUSE);
-
-	ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size,
-				 &reply, sizeof(reply));
-	if (ret < 0)
-		dev_err(sdev->dev, "DAI config for %s failed during pause push\n", w->name);
-
 	return ret;
 }
 
@@ -470,30 +412,17 @@ struct ssp_dai_dma_data {
 static int ssp_dai_setup_or_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai,
 				 bool setup)
 {
-	struct snd_soc_component *component;
-	struct snd_sof_widget *swidget;
 	struct snd_soc_dapm_widget *w;
-	struct sof_ipc_fw_version *v;
-	struct snd_sof_dev *sdev;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		w = dai->playback_widget;
 	else
 		w = dai->capture_widget;
 
-	swidget = w->dobj.private;
-	component = swidget->scomp;
-	sdev = snd_soc_component_get_drvdata(component);
-	v = &sdev->fw_ready.version;
-
-	/* DAI_CONFIG IPC during hw_params is not supported in older firmware */
-	if (v->abi_version < SOF_ABI_VER(3, 18, 0))
-		return 0;
-
 	if (setup)
-		return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_NONE);
+		return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_NONE, NULL);
 
-	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE);
+	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, NULL);
 }
 
 static int ssp_dai_startup(struct snd_pcm_substream *substream,
sound/soc/sof/intel/hda.c +44 -125

227 lines not on this page · raw message

sound/soc/sof/intel/hda.h +5 -2
index 13b509c9f481..05e5e158614a 100644
@@ -17,6 +17,7 @@
 #include <sound/hda_codec.h>
 #include <sound/hdaudio_ext.h>
 #include "../sof-client-probes.h"
+#include "../sof-audio.h"
 #include "shim.h"
 
 /* PCI registers */
@@ -730,8 +731,10 @@ int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
 
 struct snd_sof_dai;
 struct sof_ipc_dai_config;
-int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_flags);
-int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_flags);
+int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
+			      struct snd_sof_dai_config_data *data);
+int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
+			     struct snd_sof_dai_config_data *data);
 
 #define SOF_HDA_POSITION_QUIRK_USE_SKYLAKE_LEGACY	(0) /* previous implementation */
 #define SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS	(1) /* recommended if VC0 only */
sound/soc/sof/ipc3-topology.c +150 -0

162 lines not on this page · raw message

sound/soc/sof/sof-audio.c +22 -114

183 lines not on this page · raw message

sound/soc/sof/sof-audio.h +12 -1
index 622d43707b27..19386184d8f3 100644
@@ -40,6 +40,11 @@ struct snd_sof_widget;
 struct snd_sof_route;
 struct snd_sof_control;
 
+struct snd_sof_dai_config_data {
+	int dai_index;
+	int dai_data; /* contains DAI-specific information */
+};
+
 /**
  * struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
  * @ipc_setup: Function pointer for setting up widget IPC params
@@ -69,6 +74,9 @@ struct sof_ipc_tplg_widget_ops {
  * @control_setup: Function pointer for setting up kcontrol IPC-specific data
  * @control_free: Function pointer for freeing kcontrol IPC-specific data
  * @pipeline_complete: Function pointer for pipeline complete IPC
+ * @widget_setup: Function pointer for setting up setup in the DSP
+ * @widget_free: Function pointer for freeing widget in the DSP
+ * @dai_config: Function pointer for sending DAI config IPC to the DSP
  */
 struct sof_ipc_tplg_ops {
 	const struct sof_ipc_tplg_widget_ops *widget;
@@ -77,6 +85,10 @@ struct sof_ipc_tplg_ops {
 	int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
 	int (*control_free)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
 	int (*pipeline_complete)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
+	int (*widget_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
+	int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
+	int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
+			  unsigned int flags, struct snd_sof_dai_config_data *data);
 };
 
 /** struct snd_sof_tuple - Tuple info
@@ -276,7 +288,6 @@ struct snd_sof_dai {
 
 	int number_configs;
 	int current_config;
-	bool configured; /* DAI configured during BE hw_params */
 	struct list_head list;	/* list in sdev dai list */
 	void *private;
 };
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/19 ASoC: SOF: Make sof_suspend/resume IPC agnostic

In reply to Ranjani Sridharan

Add a new set of IPC ops for PM with the ctx_save and ctx_restore ops for suspend/resume and implement the ops for IPC3.

---
 sound/soc/sof/Makefile        |  2 +-
 sound/soc/sof/ipc.c           |  1 +
 sound/soc/sof/ipc3-ops.h      | 19 +++++++++++
 sound/soc/sof/ipc3-topology.c |  7 ++--
 sound/soc/sof/ipc3.c          | 44 ++++++++++++++++++++++++
 sound/soc/sof/pm.c            | 63 ++++++++++++++---------------------
 sound/soc/sof/sof-priv.h      | 14 ++++++--
 7 files changed, 104 insertions(+), 46 deletions(-)
 create mode 100644 sound/soc/sof/ipc3-ops.h
 create mode 100644 sound/soc/sof/ipc3.c
sound/soc/sof/Makefile +1 -1
index e13dab59764c..59482903a243 100644
@@ -2,7 +2,7 @@
 
 snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
 		control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
-		ipc3-topology.o
+		ipc3-topology.o ipc3.o
 ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
 snd-sof-objs += sof-client.o
 endif
sound/soc/sof/ipc.c +1 -0
index 19a294cbbb8d..46a989be9a82 100644
@@ -17,6 +17,7 @@
 #include "sof-priv.h"
 #include "sof-audio.h"
 #include "ops.h"
+#include "ipc3-ops.h"
 
 typedef void (*ipc_rx_callback)(struct snd_sof_dev *sdev, void *msg_buf);
 
sound/soc/sof/ipc3-ops.h new file +19 -0
new file mode 100644
index 000000000000..5d8cab92c1a4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+/*
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * Copyright(c) 2021 Intel Corporation. All rights reserved.
+ *
+ * Author: Ranjani Sridharan <[email protected]>
+ */
+
+#ifndef __SOUND_SOC_SOF_IPC3_OPS_H
+#define __SOUND_SOC_SOF_IPC3_OPS_H
+
+#include "sof-priv.h"
+
+extern const struct sof_ipc_tplg_ops ipc3_tplg_ops;
+extern const struct sof_ipc_ops ipc3_ops;
+
+#endif
sound/soc/sof/ipc3-topology.c +2 -5
index 8d08ffb37008..bf0cf38f4524 100644
@@ -11,6 +11,7 @@
 #include <sound/pcm_params.h>
 #include "sof-priv.h"
 #include "sof-audio.h"
+#include "ipc3-ops.h"
 #include "ops.h"
 
 /* Full volume for default values */
@@ -2152,7 +2153,7 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TY
 				 sof_ipc3_widget_bind_event},
 };
 
-static const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
+const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
 	.widget = tplg_ipc3_widget_ops,
 	.route_setup = sof_ipc3_route_setup,
 	.control_setup = sof_ipc3_control_setup,
@@ -2163,7 +2164,3 @@ static const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
 	.widget_setup = sof_ipc3_widget_setup,
 	.dai_config = sof_ipc3_dai_config,
 };
-
-const struct sof_ipc_ops ipc3_ops = {
-	.tplg = &ipc3_tplg_ops,
-};
sound/soc/sof/ipc3.c new file +44 -0

44 lines not on this page · raw message

sound/soc/sof/pm.c +25 -38

100 lines not on this page · raw message

sound/soc/sof/sof-priv.h +12 -2
index 0b89c3e6ef21..3e883044dd0f 100644
@@ -360,18 +360,28 @@ struct snd_sof_ipc_msg {
 	bool ipc_complete;
 };
 
+/**
+ * struct sof_ipc_pm_ops - IPC-specific PM ops
+ * @ctx_save:		Function pointer for context save
+ * @ctx_restore:	Function pointer for context restore
+ */
+struct sof_ipc_pm_ops {
+	int (*ctx_save)(struct snd_sof_dev *sdev);
+	int (*ctx_restore)(struct snd_sof_dev *sdev);
+};
+
 struct sof_ipc_tplg_ops;
 
 /**
  * struct sof_ipc_ops - IPC-specific ops
  * @tplg:	Pointer to IPC-specific topology ops
+ * @pm:		Pointer to PM ops
  */
 struct sof_ipc_ops {
 	const struct sof_ipc_tplg_ops *tplg;
+	const struct sof_ipc_pm_ops *pm;
 };
 
-extern const struct sof_ipc_ops ipc3_ops;
-
 /* SOF generic IPC data */
 struct snd_sof_ipc {
 	struct snd_sof_dev *sdev;
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/19 ASoC: SOF: Introduce IPC ops for kcontrol IO

In reply to Ranjani Sridharan

Introduce IPC-specific ops for kcontrol IO in struct ipc_tplg_ops.

---
 sound/soc/sof/sof-audio.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
sound/soc/sof/sof-audio.h +24 -0
index 19386184d8f3..d241dd84e708 100644
@@ -45,6 +45,28 @@ struct snd_sof_dai_config_data {
 	int dai_data; /* contains DAI-specific information */
 };
 
+/**
+ * struct ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
+ */
+struct ipc_tplg_control_ops {
+	bool (*volume_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	int (*volume_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	bool (*switch_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	int (*switch_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	bool (*enum_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	int (*enum_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	int (*bytes_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	int (*bytes_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
+	int (*bytes_ext_get)(struct snd_sof_control *scontrol,
+			     const unsigned int __user *binary_data, unsigned int size);
+	int (*bytes_ext_volatile_get)(struct snd_sof_control *scontrol,
+				      const unsigned int __user *binary_data, unsigned int size);
+	int (*bytes_ext_put)(struct snd_sof_control *scontrol,
+			     const unsigned int __user *binary_data, unsigned int size);
+	/* update control data based on notification from the DSP */
+	void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message);
+};
+
 /**
  * struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
  * @ipc_setup: Function pointer for setting up widget IPC params
@@ -67,6 +89,7 @@ struct sof_ipc_tplg_widget_ops {
  * @widget: Array of pointers to IPC-specific ops for widgets. This should always be of size
  *	    SND_SOF_DAPM_TYPE_COUNT i.e one per widget type. Unsupported widget types will be
  *	    initialized to 0.
+ * @control: Pointer to the IPC-specific ops for topology kcontrol IO
  * @route_setup: Function pointer for setting up pipeline connections
  * @token_list: List of all tokens supported by the IPC version. The size of the token_list
  *		array should be SOF_TOKEN_COUNT. The unused elements in the array will be
@@ -80,6 +103,7 @@ struct sof_ipc_tplg_widget_ops {
  */
 struct sof_ipc_tplg_ops {
 	const struct sof_ipc_tplg_widget_ops *widget;
+	const struct ipc_tplg_control_ops *control;
 	int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
 	const struct sof_token_info *token_list;
 	int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
Signature · 1 line
2.25.1
#5 lore raw

PATCH 5/19 ASoC: SOF: Add IPC3 topology control ops

In reply to Ranjani Sridharan

Define the topology control IPC ops for IPC3, implement the control_notify op and use it.

---
 sound/soc/sof/Makefile        |   2 +-
 sound/soc/sof/control.c       | 144 -------------------------------
 sound/soc/sof/ipc.c           |   6 +-
 sound/soc/sof/ipc3-control.c  | 156 ++++++++++++++++++++++++++++++++++
 sound/soc/sof/ipc3-ops.h      |   1 +
 sound/soc/sof/ipc3-topology.c |   1 +
 sound/soc/sof/sof-audio.h     |   6 +-
 7 files changed, 166 insertions(+), 150 deletions(-)
 create mode 100644 sound/soc/sof/ipc3-control.c
sound/soc/sof/Makefile +1 -1
index 59482903a243..f6d68a3096d9 100644
@@ -2,7 +2,7 @@
 
 snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
 		control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
-		ipc3-topology.o ipc3.o
+		ipc3-topology.o ipc3.o ipc3-control.o
 ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
 snd-sof-objs += sof-client.o
 endif
sound/soc/sof/control.c +0 -144

147 lines not on this page · raw message

sound/soc/sof/ipc.c +4 -2
index 46a989be9a82..af0ae137842b 100644
@@ -470,6 +470,7 @@ EXPORT_SYMBOL(snd_sof_ipc_reply);
 
 static void ipc_comp_notification(struct snd_sof_dev *sdev, void *msg_buf)
 {
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 	struct sof_ipc_cmd_hdr *hdr = msg_buf;
 	u32 msg_type = hdr->cmd & SOF_CMD_TYPE_MASK;
 
@@ -482,7 +483,8 @@ static void ipc_comp_notification(struct snd_sof_dev *sdev, void *msg_buf)
 		return;
 	}
 
-	snd_sof_control_notify(sdev, msg_buf);
+	if (tplg_ops->control->update)
+		tplg_ops->control->update(sdev, msg_buf);
 }
 
 /* DSP firmware has sent host a message  */
@@ -1031,7 +1033,7 @@ struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev)
 	ipc->ops = &ipc3_ops;
 
 	/* check for mandatory ops */
-	if (!ipc->ops->tplg || !ipc->ops->tplg->widget) {
+	if (!ipc->ops->tplg || !ipc->ops->tplg->widget || !ipc->ops->tplg->control) {
 		dev_err(sdev->dev, "Invalid topology IPC ops\n");
 		return NULL;
 	}
sound/soc/sof/ipc3-control.c new file +156 -0

156 lines not on this page · raw message

sound/soc/sof/ipc3-ops.h +1 -0
index 5d8cab92c1a4..f3d6010d0b77 100644
@@ -15,5 +15,6 @@
 
 extern const struct sof_ipc_tplg_ops ipc3_tplg_ops;
 extern const struct sof_ipc_ops ipc3_ops;
+extern const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops;
 
 #endif
sound/soc/sof/ipc3-topology.c +1 -0
index bf0cf38f4524..55be97ee816b 100644
@@ -2155,6 +2155,7 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TY
 
 const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
 	.widget = tplg_ipc3_widget_ops,
+	.control = &tplg_ipc3_control_ops,
 	.route_setup = sof_ipc3_route_setup,
 	.control_setup = sof_ipc3_control_setup,
 	.control_free = sof_ipc3_control_free,
sound/soc/sof/sof-audio.h +3 -3
index d241dd84e708..bcd38c882078 100644
@@ -46,9 +46,9 @@ struct snd_sof_dai_config_data {
 };
 
 /**
- * struct ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
+ * struct sof_ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
  */
-struct ipc_tplg_control_ops {
+struct sof_ipc_tplg_control_ops {
 	bool (*volume_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
 	int (*volume_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
 	bool (*switch_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
@@ -103,7 +103,7 @@ struct sof_ipc_tplg_widget_ops {
  */
 struct sof_ipc_tplg_ops {
 	const struct sof_ipc_tplg_widget_ops *widget;
-	const struct ipc_tplg_control_ops *control;
+	const struct sof_ipc_tplg_control_ops *control;
 	int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
 	const struct sof_token_info *token_list;
 	int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
Signature · 1 line
2.25.1
#6 lore raw

PATCH 6/19 ASoC: SOF: Add volume_get/put IPC3 ops

In reply to Ranjani Sridharan

Define and set the volume_get/put control IPC ops for IPC3.

---
 sound/soc/sof/control.c      |  64 +++++-----------------
 sound/soc/sof/ipc3-control.c | 100 +++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 50 deletions(-)
sound/soc/sof/control.c +14 -50
index fb2311d880d3..9eb54b7024b3 100644
@@ -45,26 +45,6 @@ static void update_mute_led(struct snd_sof_control *scontrol,
 #endif
 }
 
-static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
-{
-	if (value >= size)
-		return volume_map[size - 1];
-
-	return volume_map[value];
-}
-
-static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
-{
-	int i;
-
-	for (i = 0; i < size; i++) {
-		if (volume_map[i] >= value)
-			return i;
-	}
-
-	return i - 1;
-}
-
 static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
 {
 	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
@@ -85,7 +65,8 @@ static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
 	scontrol->comp_data_dirty = false;
 	ret = snd_sof_ipc_set_get_comp_data(scontrol, false);
 	if (ret < 0) {
-		dev_err(scomp->dev, "error: failed to get control data: %d\n", ret);
+		dev_err(scomp->dev, "Failed to get control data: %d\n", ret);
+
 		/* Set the flag to re-try next time to get the data */
 		scontrol->comp_data_dirty = true;
 	}
@@ -94,19 +75,14 @@ static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
 int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_mixer_control *sm =
-		(struct soc_mixer_control *)kcontrol->private_value;
+	struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = sm->dobj.private;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	unsigned int i, channels = scontrol->num_channels;
+	struct snd_soc_component *scomp = scontrol->scomp;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	snd_sof_refresh_control(scontrol);
-
-	/* read back each channel */
-	for (i = 0; i < channels; i++)
-		ucontrol->value.integer.value[i] =
-			ipc_to_mixer(cdata->chanv[i].value,
-				     scontrol->volume_table, sm->max + 1);
+	if (tplg_ops->control->volume_get)
+		return tplg_ops->control->volume_get(scontrol, ucontrol);
 
 	return 0;
 }
@@ -114,28 +90,16 @@ int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
 int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_mixer_control *sm =
-		(struct soc_mixer_control *)kcontrol->private_value;
+	struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = sm->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	unsigned int i, channels = scontrol->num_channels;
-	bool change = false;
-	u32 value;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	/* update each channel */
-	for (i = 0; i < channels; i++) {
-		value = mixer_to_ipc(ucontrol->value.integer.value[i],
-				     scontrol->volume_table, sm->max + 1);
-		change = change || (value != cdata->chanv[i].value);
-		cdata->chanv[i].channel = i;
-		cdata->chanv[i].value = value;
-	}
+	if (tplg_ops->control->volume_put)
+		return tplg_ops->control->volume_put(scontrol, ucontrol);
 
-	/* notify DSP of mixer updates */
-	if (pm_runtime_active(scomp->dev))
-		snd_sof_ipc_set_get_comp_data(scontrol, true);
-	return change;
+	return false;
 }
 
 int snd_sof_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
sound/soc/sof/ipc3-control.c +100 -0

111 lines not on this page · raw message

Signature · 1 line
2.25.1
#7 lore raw

PATCH 7/19 ASoC: SOF: Add switch get/put IPC3 ops

In reply to Ranjani Sridharan

Add the switch_get/put control IPC ops for IPC3.

---
 sound/soc/sof/control.c      | 39 +++++++++-------------------
 sound/soc/sof/ipc3-control.c | 50 ++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 27 deletions(-)
sound/soc/sof/control.c +12 -27
index 9eb54b7024b3..f9f8bd37b480 100644
@@ -127,17 +127,14 @@ int snd_sof_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info
 int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_mixer_control *sm =
-		(struct soc_mixer_control *)kcontrol->private_value;
+	struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = sm->dobj.private;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	unsigned int i, channels = scontrol->num_channels;
-
-	snd_sof_refresh_control(scontrol);
+	struct snd_soc_component *scomp = scontrol->scomp;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	/* read back each channel */
-	for (i = 0; i < channels; i++)
-		ucontrol->value.integer.value[i] = cdata->chanv[i].value;
+	if (tplg_ops->control->switch_get)
+		return tplg_ops->control->switch_get(scontrol, ucontrol);
 
 	return 0;
 }
@@ -145,31 +142,19 @@ int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
 int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_mixer_control *sm =
-		(struct soc_mixer_control *)kcontrol->private_value;
+	struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = sm->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	unsigned int i, channels = scontrol->num_channels;
-	bool change = false;
-	u32 value;
-
-	/* update each channel */
-	for (i = 0; i < channels; i++) {
-		value = ucontrol->value.integer.value[i];
-		change = change || (value != cdata->chanv[i].value);
-		cdata->chanv[i].channel = i;
-		cdata->chanv[i].value = value;
-	}
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
 	if (scontrol->led_ctl.use_led)
 		update_mute_led(scontrol, kcontrol, ucontrol);
 
-	/* notify DSP of mixer updates */
-	if (pm_runtime_active(scomp->dev))
-		snd_sof_ipc_set_get_comp_data(scontrol, true);
+	if (tplg_ops->control->switch_put)
+		return tplg_ops->control->switch_put(scontrol, ucontrol);
 
-	return change;
+	return false;
 }
 
 int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
sound/soc/sof/ipc3-control.c +50 -0

61 lines not on this page · raw message

Signature · 1 line
2.25.1
#8 lore raw

PATCH 8/19 ASoC: SOF: Add enum_get/put control ops for IPC3

In reply to Ranjani Sridharan

Define and set the enum_get/put control IPC ops for IPC3.

---
 sound/soc/sof/control.c      | 39 +++++++++-------------------
 sound/soc/sof/ipc3-control.c | 50 ++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 27 deletions(-)
sound/soc/sof/control.c +12 -27
index f9f8bd37b480..499d426c5d38 100644
@@ -160,17 +160,14 @@ int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
 int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
 		     struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_enum *se =
-		(struct soc_enum *)kcontrol->private_value;
+	struct soc_enum *se = (struct soc_enum *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = se->dobj.private;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	unsigned int i, channels = scontrol->num_channels;
-
-	snd_sof_refresh_control(scontrol);
+	struct snd_soc_component *scomp = scontrol->scomp;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	/* read back each channel */
-	for (i = 0; i < channels; i++)
-		ucontrol->value.enumerated.item[i] = cdata->chanv[i].value;
+	if (tplg_ops->control->enum_get)
+		return tplg_ops->control->enum_get(scontrol, ucontrol);
 
 	return 0;
 }
@@ -178,28 +175,16 @@ int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
 int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
 		     struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_enum *se =
-		(struct soc_enum *)kcontrol->private_value;
+	struct soc_enum *se = (struct soc_enum *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = se->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	unsigned int i, channels = scontrol->num_channels;
-	bool change = false;
-	u32 value;
-
-	/* update each channel */
-	for (i = 0; i < channels; i++) {
-		value = ucontrol->value.enumerated.item[i];
-		change = change || (value != cdata->chanv[i].value);
-		cdata->chanv[i].channel = i;
-		cdata->chanv[i].value = value;
-	}
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	/* notify DSP of enum updates */
-	if (pm_runtime_active(scomp->dev))
-		snd_sof_ipc_set_get_comp_data(scontrol, true);
+	if (tplg_ops->control->enum_put)
+		return tplg_ops->control->enum_put(scontrol, ucontrol);
 
-	return change;
+	return false;
 }
 
 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
sound/soc/sof/ipc3-control.c +50 -0

61 lines not on this page · raw message

Signature · 1 line
2.25.1
#9 lore raw

PATCH 9/19 ASoC: SOF: Add bytes_get/put control IPC ops for IPC3

In reply to Ranjani Sridharan

Define and set the bytes_get/put IPC control ops for IPC3.

---
 sound/soc/sof/control.c      | 64 ++++++----------------------------
 sound/soc/sof/ipc3-control.c | 67 ++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 54 deletions(-)
sound/soc/sof/control.c +10 -54
index 499d426c5d38..2a4997e1cd1e 100644
@@ -190,35 +190,14 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
 		      struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_bytes_ext *be =
-		(struct soc_bytes_ext *)kcontrol->private_value;
+	struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = be->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	struct sof_abi_hdr *data = cdata->data;
-	size_t size;
-
-	snd_sof_refresh_control(scontrol);
-
-	if (be->max > sizeof(ucontrol->value.bytes.data)) {
-		dev_err_ratelimited(scomp->dev,
-				    "error: data max %d exceeds ucontrol data array size\n",
-				    be->max);
-		return -EINVAL;
-	}
-
-	/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
-	if (data->size > be->max - sizeof(*data)) {
-		dev_err_ratelimited(scomp->dev,
-				    "error: %u bytes of control data is invalid, max is %zu\n",
-				    data->size, be->max - sizeof(*data));
-		return -EINVAL;
-	}
-
-	size = data->size + sizeof(*data);
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	/* copy back to kcontrol */
-	memcpy(ucontrol->value.bytes.data, data, size);
+	if (tplg_ops->control->bytes_get)
+		return tplg_ops->control->bytes_get(scontrol, ucontrol);
 
 	return 0;
 }
@@ -226,37 +205,14 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
 int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
 		      struct snd_ctl_elem_value *ucontrol)
 {
-	struct soc_bytes_ext *be =
-		(struct soc_bytes_ext *)kcontrol->private_value;
+	struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = be->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	struct sof_abi_hdr *data = cdata->data;
-	size_t size;
-
-	if (be->max > sizeof(ucontrol->value.bytes.data)) {
-		dev_err_ratelimited(scomp->dev,
-				    "error: data max %d exceeds ucontrol data array size\n",
-				    be->max);
-		return -EINVAL;
-	}
-
-	/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
-	if (data->size > be->max - sizeof(*data)) {
-		dev_err_ratelimited(scomp->dev,
-				    "error: data size too big %u bytes max is %zu\n",
-				    data->size, be->max - sizeof(*data));
-		return -EINVAL;
-	}
-
-	size = data->size + sizeof(*data);
-
-	/* copy from kcontrol */
-	memcpy(data, ucontrol->value.bytes.data, size);
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	/* notify DSP of byte control updates */
-	if (pm_runtime_active(scomp->dev))
-		snd_sof_ipc_set_get_comp_data(scontrol, true);
+	if (tplg_ops->control->bytes_put)
+		return tplg_ops->control->bytes_put(scontrol, ucontrol);
 
 	return 0;
 }
sound/soc/sof/ipc3-control.c +67 -0

78 lines not on this page · raw message

Signature · 1 line
2.25.1
#10 lore raw

PATCH 10/19 ASoC: SOF: Add bytes_ext control IPC ops for IPC3

In reply to Ranjani Sridharan

Define and set the get/put/volatile_get control IPC ops for byte controls for IPC3.

---
 sound/soc/sof/control.c      | 197 +++--------------------------------
 sound/soc/sof/ipc3-control.c | 171 ++++++++++++++++++++++++++++++
 2 files changed, 188 insertions(+), 180 deletions(-)
sound/soc/sof/control.c +17 -180
index 2a4997e1cd1e..de1778c4002b 100644
@@ -45,33 +45,6 @@ static void update_mute_led(struct snd_sof_control *scontrol,
 #endif
 }
 
-static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
-{
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	struct snd_soc_component *scomp = scontrol->scomp;
-	int ret;
-
-	if (!scontrol->comp_data_dirty)
-		return;
-
-	if (!pm_runtime_active(scomp->dev))
-		return;
-
-	/* set the ABI header values */
-	cdata->data->magic = SOF_ABI_MAGIC;
-	cdata->data->abi = SOF_ABI_VERSION;
-
-	/* refresh the component data from DSP */
-	scontrol->comp_data_dirty = false;
-	ret = snd_sof_ipc_set_get_comp_data(scontrol, false);
-	if (ret < 0) {
-		dev_err(scomp->dev, "Failed to get control data: %d\n", ret);
-
-		/* Set the flag to re-try next time to get the data */
-		scontrol->comp_data_dirty = true;
-	}
-}
-
 int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_value *ucontrol)
 {
@@ -221,74 +194,18 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
 			  const unsigned int __user *binary_data,
 			  unsigned int size)
 {
-	struct soc_bytes_ext *be =
-		(struct soc_bytes_ext *)kcontrol->private_value;
+	struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = be->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	struct snd_ctl_tlv header;
-	const struct snd_ctl_tlv __user *tlvd =
-		(const struct snd_ctl_tlv __user *)binary_data;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
 	/* make sure we have at least a header */
 	if (size < sizeof(struct snd_ctl_tlv))
 		return -EINVAL;
 
-	/*
-	 * The beginning of bytes data contains a header from where
-	 * the length (as bytes) is needed to know the correct copy
-	 * length of data from tlvd->tlv.
-	 */
-	if (copy_from_user(&header, tlvd, sizeof(struct snd_ctl_tlv)))
-		return -EFAULT;
-
-	/* make sure TLV info is consistent */
-	if (header.length + sizeof(struct snd_ctl_tlv) > size) {
-		dev_err_ratelimited(scomp->dev, "error: inconsistent TLV, data %d + header %zu > %d\n",
-				    header.length, sizeof(struct snd_ctl_tlv), size);
-		return -EINVAL;
-	}
-
-	/* be->max is coming from topology */
-	if (header.length > be->max) {
-		dev_err_ratelimited(scomp->dev, "error: Bytes data size %d exceeds max %d.\n",
-				    header.length, be->max);
-		return -EINVAL;
-	}
-
-	/* Check that header id matches the command */
-	if (header.numid != cdata->cmd) {
-		dev_err_ratelimited(scomp->dev,
-				    "error: incorrect numid %d\n",
-				    header.numid);
-		return -EINVAL;
-	}
-
-	if (copy_from_user(cdata->data, tlvd->tlv, header.length))
-		return -EFAULT;
-
-	if (cdata->data->magic != SOF_ABI_MAGIC) {
-		dev_err_ratelimited(scomp->dev,
-				    "error: Wrong ABI magic 0x%08x.\n",
-				    cdata->data->magic);
-		return -EINVAL;
-	}
-
-	if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) {
-		dev_err_ratelimited(scomp->dev, "error: Incompatible ABI version 0x%08x.\n",
-				    cdata->data->abi);
-		return -EINVAL;
-	}
-
-	/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
-	if (cdata->data->size > be->max - sizeof(struct sof_abi_hdr)) {
-		dev_err_ratelimited(scomp->dev, "error: Mismatch in ABI data size (truncated?).\n");
-		return -EINVAL;
-	}
-
-	/* notify DSP of byte control updates */
-	if (pm_runtime_active(scomp->dev))
-		snd_sof_ipc_set_get_comp_data(scontrol, true);
+	if (tplg_ops->control->bytes_ext_put)
+		return tplg_ops->control->bytes_ext_put(scontrol, binary_data, size);
 
 	return 0;
 }
@@ -299,67 +216,24 @@ int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int _
 	struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = be->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	struct snd_ctl_tlv header;
-	struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data;
-	size_t data_size;
-	int ret;
-	int err;
-
-	/*
-	 * Decrement the limit by ext bytes header size to
-	 * ensure the user space buffer is not exceeded.
-	 */
-	if (size < sizeof(struct snd_ctl_tlv))
-		return -ENOSPC;
-	size -= sizeof(struct snd_ctl_tlv);
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
+	int ret, err;
 
 	ret = pm_runtime_get_sync(scomp->dev);
 	if (ret < 0 && ret != -EACCES) {
-		dev_err_ratelimited(scomp->dev, "error: bytes_ext get failed to resume %d\n", ret);
+		dev_err_ratelimited(scomp->dev, "%s: failed to resume %d\n", __func__, ret);
 		pm_runtime_put_noidle(scomp->dev);
 		return ret;
 	}
 
-	/* set the ABI header values */
-	cdata->data->magic = SOF_ABI_MAGIC;
-	cdata->data->abi = SOF_ABI_VERSION;
-	/* get all the component data from DSP */
-	ret = snd_sof_ipc_set_get_comp_data(scontrol, false);
-	if (ret < 0)
-		goto out;
-
-	/* check data size doesn't exceed max coming from topology */
-	if (cdata->data->size > be->max - sizeof(struct sof_abi_hdr)) {
-		dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %zu.\n",
-				    cdata->data->size,
-				    be->max - sizeof(struct sof_abi_hdr));
-		ret = -EINVAL;
-		goto out;
-	}
-
-	data_size = cdata->data->size + sizeof(struct sof_abi_hdr);
+	if (tplg_ops->control->bytes_ext_volatile_get)
+		ret = tplg_ops->control->bytes_ext_volatile_get(scontrol, binary_data, size);
 
-	/* make sure we don't exceed size provided by user space for data */
-	if (data_size > size) {
-		ret = -ENOSPC;
-		goto out;
-	}
-
-	header.numid = cdata->cmd;
-	header.length = data_size;
-	if (copy_to_user(tlvd, &header, sizeof(struct snd_ctl_tlv))) {
-		ret = -EFAULT;
-		goto out;
-	}
-
-	if (copy_to_user(tlvd->tlv, cdata->data, data_size))
-		ret = -EFAULT;
-out:
 	pm_runtime_mark_last_busy(scomp->dev);
 	err = pm_runtime_put_autosuspend(scomp->dev);
 	if (err < 0)
-		dev_err_ratelimited(scomp->dev, "error: bytes_ext get failed to idle %d\n", err);
+		dev_err_ratelimited(scomp->dev, "%s: failed to idle %d\n", __func__, err);
 
 	return ret;
 }
@@ -368,51 +242,14 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
 			  unsigned int __user *binary_data,
 			  unsigned int size)
 {
-	struct soc_bytes_ext *be =
-		(struct soc_bytes_ext *)kcontrol->private_value;
+	struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
 	struct snd_sof_control *scontrol = be->dobj.private;
 	struct snd_soc_component *scomp = scontrol->scomp;
-	struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
-	struct snd_ctl_tlv header;
-	struct snd_ctl_tlv __user *tlvd =
-		(struct snd_ctl_tlv __user *)binary_data;
-	size_t data_size;
-
-	snd_sof_refresh_control(scontrol);
-
-	/*
-	 * Decrement the limit by ext bytes header size to
-	 * ensure the user space buffer is not exceeded.
-	 */
-	if (size < sizeof(struct snd_ctl_tlv))
-		return -ENOSPC;
-	size -= sizeof(struct snd_ctl_tlv);
-
-	/* set the ABI header values */
-	cdata->data->magic = SOF_ABI_MAGIC;
-	cdata->data->abi = SOF_ABI_VERSION;
-
-	/* check data size doesn't exceed max coming from topology */
-	if (cdata->data->size > be->max - sizeof(struct sof_abi_hdr)) {
-		dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %zu.\n",
-				    cdata->data->size,
-				    be->max - sizeof(struct sof_abi_hdr));
-		return -EINVAL;
-	}
-
-	data_size = cdata->data->size + sizeof(struct sof_abi_hdr);
-
-	/* make sure we don't exceed size provided by user space for data */
-	if (data_size > size)
-		return -ENOSPC;
-
-	header.numid = cdata->cmd;
-	header.length = data_size;
-	if (copy_to_user(tlvd, &header, sizeof(struct snd_ctl_tlv)))
-		return -EFAULT;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
-	if (copy_to_user(tlvd->tlv, cdata->data, data_size))
-		return -EFAULT;
+	if (tplg_ops->control->bytes_ext_get)
+		return tplg_ops->control->bytes_ext_get(scontrol, binary_data, size);
 
 	return 0;
 }
sound/soc/sof/ipc3-control.c +171 -0

182 lines not on this page · raw message

Signature · 1 line
2.25.1
#11 lore raw

PATCH 11/19 ASoC: SOF: Introduce IPC-specific PCM ops

In reply to Ranjani Sridharan

Introduce the IPC-specific PCM ops that will be used to abstract the PCM related IPC's.

---
 sound/soc/sof/sof-audio.h | 17 +++++++++++++++++
 sound/soc/sof/sof-priv.h  |  3 +++
 2 files changed, 20 insertions(+)
sound/soc/sof/sof-audio.h +17 -0
index bcd38c882078..4d25e781e5ae 100644
@@ -45,6 +45,23 @@ struct snd_sof_dai_config_data {
 	int dai_data; /* contains DAI-specific information */
 };
 
+/**
+ * struct sof_ipc_pcm_ops - IPC-specific PCM ops
+ * @hw_params: Function pointer for hw_params
+ * @hw_free: Function pointer for hw_free
+ * @trigger: Function pointer for trigger
+ * @dai_link_fixup: Function pointer for DAI link fixup
+ */
+struct sof_ipc_pcm_ops {
+	int (*hw_params)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
+			 struct snd_pcm_hw_params *params,
+			 struct snd_sof_platform_stream_params *platform_params);
+	int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream);
+	int (*trigger)(struct snd_soc_component *component,  struct snd_pcm_substream *substream,
+		       int cmd);
+	int (*dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
+};
+
 /**
  * struct sof_ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
  */
sound/soc/sof/sof-priv.h +3 -0
index 3e883044dd0f..0d9b640ae24c 100644
@@ -371,15 +371,18 @@ struct sof_ipc_pm_ops {
 };
 
 struct sof_ipc_tplg_ops;
+struct sof_ipc_pcm_ops;
 
 /**
  * struct sof_ipc_ops - IPC-specific ops
  * @tplg:	Pointer to IPC-specific topology ops
  * @pm:		Pointer to PM ops
+ * @pcm:	Pointer to PCM ops
  */
 struct sof_ipc_ops {
 	const struct sof_ipc_tplg_ops *tplg;
 	const struct sof_ipc_pm_ops *pm;
+	const struct sof_ipc_pcm_ops *pcm;
 };
 
 /* SOF generic IPC data */
Signature · 1 line
2.25.1
#12 lore raw

PATCH 12/19 ASoC: SOF: pcm: expose the sof_pcm_setup_connected_widgets() function

In reply to Ranjani Sridharan

It will be used in IPC-specific code.

---
 sound/soc/sof/pcm.c       | 5 ++---
 sound/soc/sof/sof-audio.h | 2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)
sound/soc/sof/pcm.c +2 -3
index 1661b0bc6f12..47599b57ff19 100644
@@ -105,9 +105,8 @@ int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev
 	return ret;
 }
 
-static int sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev,
-					   struct snd_soc_pcm_runtime *rtd,
-					   struct snd_sof_pcm *spcm, int dir)
+int sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev, struct snd_soc_pcm_runtime *rtd,
+				    struct snd_sof_pcm *spcm, int dir)
 {
 	struct snd_soc_dai *dai;
 	int ret, j;
sound/soc/sof/sof-audio.h +2 -0
index 4d25e781e5ae..3ec3f746663a 100644
@@ -457,4 +457,6 @@ int get_token_uuid(void *elem, void *object, u32 offset);
 int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
 			  struct snd_sof_tuple *tuples, int num_tuples,
 			  size_t object_size, int token_instance_num);
+int sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev, struct snd_soc_pcm_runtime *rtd,
+				    struct snd_sof_pcm *spcm, int dir);
 #endif
Signature · 1 line
2.25.1
#13 lore raw

PATCH 13/19 ASoC: SOF: Introduce IPC3 PCM hw_free op

In reply to Ranjani Sridharan

Add the IPC3 PCM ops, define the hw_free op and modify all users to use the op.

---
 sound/soc/sof/Makefile    |  2 +-
 sound/soc/sof/ipc.c       |  5 +++--
 sound/soc/sof/ipc3-ops.h  |  1 +
 sound/soc/sof/ipc3-pcm.c  | 43 ++++++++++++++++++++++++++++++++++++++
 sound/soc/sof/ipc3.c      |  1 +
 sound/soc/sof/pcm.c       | 44 +++++++++++++--------------------------
 sound/soc/sof/sof-audio.c | 11 +++++++---
 7 files changed, 72 insertions(+), 35 deletions(-)
 create mode 100644 sound/soc/sof/ipc3-pcm.c
sound/soc/sof/Makefile +1 -1
index f6d68a3096d9..18acbc001b9a 100644
@@ -2,7 +2,7 @@
 
 snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
 		control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
-		ipc3-topology.o ipc3.o ipc3-control.o
+		ipc3-topology.o ipc3.o ipc3-control.o ipc3-pcm.o
 ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
 snd-sof-objs += sof-client.o
 endif
sound/soc/sof/ipc.c +3 -2
index af0ae137842b..5f5753608c79 100644
@@ -1033,8 +1033,9 @@ struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev)
 	ipc->ops = &ipc3_ops;
 
 	/* check for mandatory ops */
-	if (!ipc->ops->tplg || !ipc->ops->tplg->widget || !ipc->ops->tplg->control) {
-		dev_err(sdev->dev, "Invalid topology IPC ops\n");
+	if (!ipc->ops->pcm || !ipc->ops->tplg || !ipc->ops->tplg->widget ||
+	    !ipc->ops->tplg->control) {
+		dev_err(sdev->dev, "Invalid IPC ops\n");
 		return NULL;
 	}
 
sound/soc/sof/ipc3-ops.h +1 -0
index f3d6010d0b77..a4784626a3d7 100644
@@ -16,5 +16,6 @@
 extern const struct sof_ipc_tplg_ops ipc3_tplg_ops;
 extern const struct sof_ipc_ops ipc3_ops;
 extern const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops;
+extern const struct sof_ipc_pcm_ops ipc3_pcm_ops;
 
 #endif
sound/soc/sof/ipc3-pcm.c new file +43 -0

43 lines not on this page · raw message

sound/soc/sof/ipc3.c +1 -0
index e71cf30908c6..03e914b62728 100644
@@ -41,4 +41,5 @@ static const struct sof_ipc_pm_ops ipc3_pm_ops = {
 const struct sof_ipc_ops ipc3_ops = {
 	.tplg = &ipc3_tplg_ops,
 	.pm = &ipc3_pm_ops,
+	.pcm = &ipc3_pcm_ops,
 };
sound/soc/sof/pcm.c +15 -29

75 lines not on this page · raw message

sound/soc/sof/sof-audio.c +8 -3
index 7aa4ac313de3..5088ec7019ed 100644
@@ -591,12 +591,17 @@ int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify)
 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
 			struct snd_sof_pcm *spcm, int dir, bool free_widget_list)
 {
+	const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
 	int ret;
 
 	/* Send PCM_FREE IPC to reset pipeline */
-	ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
-	if (ret < 0)
-		return ret;
+	if (pcm_ops->hw_free && spcm->prepared[substream->stream]) {
+		ret = pcm_ops->hw_free(sdev->component, substream);
+		if (ret < 0)
+			return ret;
+	}
+
+	spcm->prepared[substream->stream] = false;
 
 	/* stop the DMA */
 	ret = snd_sof_pcm_platform_hw_free(sdev, substream);
Signature · 1 line
2.25.1
#14 lore raw

PATCH 14/19 ASoC: SOF: Define hw_params PCM op for IPC3

In reply to Ranjani Sridharan

Add the hw_params op for IPC3 and use it.

---
 sound/soc/sof/ipc3-pcm.c | 100 +++++++++++++++++++++++++++++++++++
 sound/soc/sof/pcm.c      | 110 ++++++---------------------------------
 2 files changed, 115 insertions(+), 95 deletions(-)
sound/soc/sof/ipc3-pcm.c +100 -0
index 96f498b4b2d6..b715199a2aaa 100644
@@ -38,6 +38,106 @@ static int sof_ipc3_pcm_hw_free(struct snd_soc_component *component,
 				  sizeof(stream), &reply, sizeof(reply));
 }
 
+static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component,
+				  struct snd_pcm_substream *substream,
+				  struct snd_pcm_hw_params *params,
+				  struct snd_sof_platform_stream_params *platform_params)
+{
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct sof_ipc_pcm_params_reply ipc_params_reply;
+	struct sof_ipc_pcm_params pcm;
+	struct snd_sof_pcm *spcm;
+	int ret;
+
+	spcm = snd_sof_find_spcm_dai(component, rtd);
+	if (!spcm)
+		return -EINVAL;
+
+	memset(&pcm, 0, sizeof(pcm));
+
+	/* number of pages should be rounded up */
+	pcm.params.buffer.pages = PFN_UP(runtime->dma_bytes);
+
+	/* set IPC PCM parameters */
+	pcm.hdr.size = sizeof(pcm);
+	pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
+	pcm.comp_id = spcm->stream[substream->stream].comp_id;
+	pcm.params.hdr.size = sizeof(pcm.params);
+	pcm.params.buffer.phy_addr = spcm->stream[substream->stream].page_table.addr;
+	pcm.params.buffer.size = runtime->dma_bytes;
+	pcm.params.direction = substream->stream;
+	pcm.params.sample_valid_bytes = params_width(params) >> 3;
+	pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
+	pcm.params.rate = params_rate(params);
+	pcm.params.channels = params_channels(params);
+	pcm.params.host_period_bytes = params_period_bytes(params);
+
+	/* container size */
+	ret = snd_pcm_format_physical_width(params_format(params));
+	if (ret < 0)
+		return ret;
+	pcm.params.sample_container_bytes = ret >> 3;
+
+	/* format */
+	switch (params_format(params)) {
+	case SNDRV_PCM_FORMAT_S16:
+		pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE;
+		break;
+	case SNDRV_PCM_FORMAT_S24:
+		pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE;
+		break;
+	case SNDRV_PCM_FORMAT_S32:
+		pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE;
+		break;
+	case SNDRV_PCM_FORMAT_FLOAT:
+		pcm.params.frame_fmt = SOF_IPC_FRAME_FLOAT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Update the IPC message with information from the platform */
+	pcm.params.stream_tag = platform_params->stream_tag;
+
+	if (platform_params->use_phy_address)
+		pcm.params.buffer.phy_addr = platform_params->phy_addr;
+
+	if (platform_params->no_ipc_position) {
+		/* For older ABIs set host_period_bytes to zero to inform
+		 * FW we don't want position updates. Newer versions use
+		 * no_stream_position for this purpose.
+		 */
+		if (v->abi_version < SOF_ABI_VER(3, 10, 0))
+			pcm.params.host_period_bytes = 0;
+		else
+			pcm.params.no_stream_position = 1;
+	}
+
+	dev_dbg(component->dev, "stream_tag %d", pcm.params.stream_tag);
+
+	/* send hw_params IPC to the DSP */
+	ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm),
+				 &ipc_params_reply, sizeof(ipc_params_reply));
+	if (ret < 0) {
+		dev_err(component->dev, "HW params ipc failed for stream %d\n",
+			pcm.params.stream_tag);
+		return ret;
+	}
+
+	ret = snd_sof_set_stream_data_offset(sdev, substream, ipc_params_reply.posn_offset);
+	if (ret < 0) {
+		dev_err(component->dev, "%s: invalid stream data offset for PCM %d\n",
+			__func__, spcm->pcm.pcm_id);
+		return ret;
+	}
+
+	return ret;
+}
+
 const struct sof_ipc_pcm_ops ipc3_pcm_ops = {
+	.hw_params = sof_ipc3_pcm_hw_params,
 	.hw_free = sof_ipc3_pcm_hw_free,
 };
sound/soc/sof/pcm.c +15 -95

147 lines not on this page · raw message

Signature · 1 line
2.25.1
#15 lore raw

PATCH 15/19 ASoC: SOF: Add trigger PCM op for IPC3

In reply to Ranjani Sridharan

Add the trigger PCM op for IPC3 and use it.

---
 sound/soc/sof/ipc3-pcm.c | 43 ++++++++++++++++++++++++++++++++++++++++
 sound/soc/sof/pcm.c      | 23 ++++++---------------
 2 files changed, 49 insertions(+), 17 deletions(-)
sound/soc/sof/ipc3-pcm.c +43 -0
index b715199a2aaa..d83d54540bbe 100644
@@ -137,7 +137,50 @@ static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component,
 	return ret;
 }
 
+static int sof_ipc3_pcm_trigger(struct snd_soc_component *component,
+				struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+	struct sof_ipc_stream stream;
+	struct sof_ipc_reply reply;
+	struct snd_sof_pcm *spcm;
+
+	spcm = snd_sof_find_spcm_dai(component, rtd);
+	if (!spcm)
+		return -EINVAL;
+
+	stream.hdr.size = sizeof(stream);
+	stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG;
+	stream.comp_id = spcm->stream[substream->stream].comp_id;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE;
+		break;
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
+		break;
+	case SNDRV_PCM_TRIGGER_START:
+		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START;
+		break;
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		fallthrough;
+	case SNDRV_PCM_TRIGGER_STOP:
+		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
+		break;
+	default:
+		dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* send IPC to the DSP */
+	return sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
+				  sizeof(stream), &reply, sizeof(reply));
+}
+
 const struct sof_ipc_pcm_ops ipc3_pcm_ops = {
 	.hw_params = sof_ipc3_pcm_hw_params,
 	.hw_free = sof_ipc3_pcm_hw_free,
+	.trigger = sof_ipc3_pcm_trigger,
 };
sound/soc/sof/pcm.c +6 -17
index 8a194c130981..dc55a04a1588 100644
@@ -274,13 +274,12 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
 {
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+	const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
 	struct snd_sof_pcm *spcm;
-	struct sof_ipc_stream stream;
-	struct sof_ipc_reply reply;
 	bool reset_hw_params = false;
 	bool free_widget_list = false;
 	bool ipc_first = false;
-	int ret;
+	int ret = 0;
 
 	/* nothing to do for BE */
 	if (rtd->dai_link->no_pcm)
@@ -293,17 +292,11 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
 	dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
 		spcm->pcm.pcm_id, substream->stream, cmd);
 
-	stream.hdr.size = sizeof(stream);
-	stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG;
-	stream.comp_id = spcm->stream[substream->stream].comp_id;
-
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE;
 		ipc_first = true;
 		break;
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
 		break;
 	case SNDRV_PCM_TRIGGER_START:
 		if (spcm->stream[substream->stream].suspend_ignored) {
@@ -315,7 +308,6 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
 			spcm->stream[substream->stream].suspend_ignored = false;
 			return 0;
 		}
-		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START;
 		break;
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 		if (sdev->system_suspend_target == SOF_SUSPEND_S0IX &&
@@ -332,13 +324,11 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
 		free_widget_list = true;
 		fallthrough;
 	case SNDRV_PCM_TRIGGER_STOP:
-		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
 		ipc_first = true;
 		reset_hw_params = true;
 		break;
 	default:
-		dev_err(component->dev, "error: unhandled trigger cmd %d\n",
-			cmd);
+		dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
 		return -EINVAL;
 	}
 
@@ -349,11 +339,10 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
 	if (!ipc_first)
 		snd_sof_pcm_platform_trigger(sdev, substream, cmd);
 
-	/* send IPC to the DSP */
-	ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
-				 sizeof(stream), &reply, sizeof(reply));
+	if (pcm_ops->trigger)
+		ret = pcm_ops->trigger(component, substream, cmd);
 
-	/* need to STOP DMA even if STOP IPC failed */
+	/* need to STOP DMA even if trigger IPC failed */
 	if (ipc_first)
 		snd_sof_pcm_platform_trigger(sdev, substream, cmd);
 
Signature · 1 line
2.25.1
#16 lore raw

PATCH 16/19 ASoC: SOF: Add dai_link_fixup PCM op for IPC3

In reply to Ranjani Sridharan

Define the dai_link_fixup PCM op for IPC3 and use it

---
 sound/soc/sof/ipc3-pcm.c | 186 +++++++++++++++++++++++++++++++++++++++
 sound/soc/sof/pcm.c      | 174 +-----------------------------------
 2 files changed, 189 insertions(+), 171 deletions(-)
sound/soc/sof/ipc3-pcm.c +186 -0
index d83d54540bbe..58b75943cf6d 100644
@@ -179,8 +179,194 @@ static int sof_ipc3_pcm_trigger(struct snd_soc_component *component,
 				  sizeof(stream), &reply, sizeof(reply));
 }
 
+static void ssp_dai_config_pcm_params_match(struct snd_sof_dev *sdev, const char *link_name,
+					    struct snd_pcm_hw_params *params)
+{
+	struct sof_ipc_dai_config *config;
+	struct snd_sof_dai *dai;
+	int i;
+
+	/*
+	 * Search for all matching DAIs as we can have both playback and capture DAI
+	 * associated with the same link.
+	 */
+	list_for_each_entry(dai, &sdev->dai_list, list) {
+		if (!dai->name || strcmp(link_name, dai->name))
+			continue;
+		for (i = 0; i < dai->number_configs; i++) {
+			struct sof_dai_private_data *private = dai->private;
+
+			config = &private->dai_config[i];
+			if (config->ssp.fsync_rate == params_rate(params)) {
+				dev_dbg(sdev->dev, "DAI config %d matches pcm hw params\n", i);
+				dai->current_config = i;
+				break;
+			}
+		}
+	}
+}
+
+static int sof_ipc3_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
+				       struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
+	struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+	struct snd_sof_dai *dai = snd_sof_find_dai(component, (char *)rtd->dai_link->name);
+	struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+	struct sof_dai_private_data *private;
+	struct snd_soc_dpcm *dpcm;
+
+	if (!dai) {
+		dev_err(component->dev, "%s: No DAI found with name %s\n", __func__,
+			rtd->dai_link->name);
+		return -EINVAL;
+	}
+
+	private = dai->private;
+	if (!private) {
+		dev_err(component->dev, "%s: No private data found for DAI %s\n", __func__,
+			rtd->dai_link->name);
+		return -EINVAL;
+	}
+
+	/* read format from topology */
+	snd_mask_none(fmt);
+
+	switch (private->comp_dai->config.frame_fmt) {
+	case SOF_IPC_FRAME_S16_LE:
+		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
+		break;
+	case SOF_IPC_FRAME_S24_4LE:
+		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
+		break;
+	case SOF_IPC_FRAME_S32_LE:
+		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
+		break;
+	default:
+		dev_err(component->dev, "No available DAI format!\n");
+		return -EINVAL;
+	}
+
+	/* read rate and channels from topology */
+	switch (private->dai_config->type) {
+	case SOF_DAI_INTEL_SSP:
+		/* search for config to pcm params match, if not found use default */
+		ssp_dai_config_pcm_params_match(sdev, (char *)rtd->dai_link->name, params);
+
+		rate->min = private->dai_config[dai->current_config].ssp.fsync_rate;
+		rate->max = private->dai_config[dai->current_config].ssp.fsync_rate;
+		channels->min = private->dai_config[dai->current_config].ssp.tdm_slots;
+		channels->max = private->dai_config[dai->current_config].ssp.tdm_slots;
+
+		dev_dbg(component->dev, "rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+
+		break;
+	case SOF_DAI_INTEL_DMIC:
+		/* DMIC only supports 16 or 32 bit formats */
+		if (private->comp_dai->config.frame_fmt == SOF_IPC_FRAME_S24_4LE) {
+			dev_err(component->dev, "Invalid fmt %d for DAI type %d\n",
+				private->comp_dai->config.frame_fmt,
+				private->dai_config->type);
+		}
+		break;
+	case SOF_DAI_INTEL_HDA:
+		/*
+		 * HDAudio does not follow the default trigger
+		 * sequence due to firmware implementation
+		 */
+		for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
+			struct snd_soc_pcm_runtime *fe = dpcm->fe;
+
+			fe->dai_link->trigger[SNDRV_PCM_STREAM_PLAYBACK] =
+				SND_SOC_DPCM_TRIGGER_POST;
+		}
+		break;
+	case SOF_DAI_INTEL_ALH:
+		/*
+		 * Dai could run with different channel count compared with
+		 * front end, so get dai channel count from topology
+		 */
+		channels->min = private->dai_config->alh.channels;
+		channels->max = private->dai_config->alh.channels;
+		break;
+	case SOF_DAI_IMX_ESAI:
+		rate->min = private->dai_config->esai.fsync_rate;
+		rate->max = private->dai_config->esai.fsync_rate;
+		channels->min = private->dai_config->esai.tdm_slots;
+		channels->max = private->dai_config->esai.tdm_slots;
+
+		dev_dbg(component->dev, "rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
+	case SOF_DAI_MEDIATEK_AFE:
+		rate->min = private->dai_config->afe.rate;
+		rate->max = private->dai_config->afe.rate;
+		channels->min = private->dai_config->afe.channels;
+		channels->max = private->dai_config->afe.channels;
+
+		dev_dbg(component->dev, "rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
+	case SOF_DAI_IMX_SAI:
+		rate->min = private->dai_config->sai.fsync_rate;
+		rate->max = private->dai_config->sai.fsync_rate;
+		channels->min = private->dai_config->sai.tdm_slots;
+		channels->max = private->dai_config->sai.tdm_slots;
+
+		dev_dbg(component->dev, "rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
+	case SOF_DAI_AMD_BT:
+		rate->min = private->dai_config->acpbt.fsync_rate;
+		rate->max = private->dai_config->acpbt.fsync_rate;
+		channels->min = private->dai_config->acpbt.tdm_slots;
+		channels->max = private->dai_config->acpbt.tdm_slots;
+
+		dev_dbg(component->dev,
+			"AMD_BT rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "AMD_BT channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
+	case SOF_DAI_AMD_SP:
+		rate->min = private->dai_config->acpsp.fsync_rate;
+		rate->max = private->dai_config->acpsp.fsync_rate;
+		channels->min = private->dai_config->acpsp.tdm_slots;
+		channels->max = private->dai_config->acpsp.tdm_slots;
+
+		dev_dbg(component->dev,
+			"AMD_SP rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "AMD_SP channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
+	case SOF_DAI_AMD_DMIC:
+		rate->min = private->dai_config->acpdmic.fsync_rate;
+		rate->max = private->dai_config->acpdmic.fsync_rate;
+		channels->min = private->dai_config->acpdmic.tdm_slots;
+		channels->max = private->dai_config->acpdmic.tdm_slots;
+
+		dev_dbg(component->dev,
+			"AMD_DMIC rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "AMD_DMIC channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
+	default:
+		dev_err(component->dev, "Invalid DAI type %d\n", private->dai_config->type);
+		break;
+	}
+
+	return 0;
+}
+
 const struct sof_ipc_pcm_ops ipc3_pcm_ops = {
 	.hw_params = sof_ipc3_pcm_hw_params,
 	.hw_free = sof_ipc3_pcm_hw_free,
 	.trigger = sof_ipc3_pcm_trigger,
+	.dai_link_fixup = sof_ipc3_pcm_dai_link_fixup,
 };
sound/soc/sof/pcm.c +3 -171

192 lines not on this page · raw message

Signature · 1 line
2.25.1
#17 lore raw

PATCH 17/19 ASoC: SOF: expose sof_route_setup()

In reply to Ranjani Sridharan

This will be used in IPC3-specific code.

---
 sound/soc/sof/sof-audio.c | 4 ++--
 sound/soc/sof/sof-audio.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
sound/soc/sof/sof-audio.c +2 -2
index 5088ec7019ed..8885709f40df 100644
@@ -204,8 +204,8 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
 }
 EXPORT_SYMBOL(sof_widget_setup);
 
-static int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
-			   struct snd_soc_dapm_widget *wsink)
+int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
+		    struct snd_soc_dapm_widget *wsink)
 {
 	const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
 	struct snd_sof_widget *src_widget = wsource->dobj.private;
sound/soc/sof/sof-audio.h +2 -0
index 3ec3f746663a..777da321e2aa 100644
@@ -441,6 +441,8 @@ void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
 
 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
+int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
+		    struct snd_soc_dapm_widget *wsink);
 
 /* PCM */
 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
Signature · 1 line
2.25.1
#18 lore raw

PATCH 18/19 ASoC: SOF: topology: Add ops for setting up and tearing down pipelines

In reply to Ranjani Sridharan

Introduce two new ops, set_up_all_pipelines and tear_down_all_pipelines in struct ipc_tplg_ops and define these for IPC3.

---
 sound/soc/sof/ipc3-topology.c | 197 ++++++++++++++++++++++++++++++++++
 sound/soc/sof/pm.c            |  17 +--
 sound/soc/sof/sof-audio.c     | 186 --------------------------------
 sound/soc/sof/sof-audio.h     |   6 +-
 sound/soc/sof/topology.c      |  55 +++++-----
 5 files changed, 235 insertions(+), 226 deletions(-)
sound/soc/sof/ipc3-topology.c +197 -0
index 55be97ee816b..3ac65dacc7b9 100644
@@ -2057,6 +2057,201 @@ static int sof_ipc3_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
 	return ret;
 }
 
+static int sof_ipc3_set_up_all_pipelines(struct snd_sof_dev *sdev, bool verify)
+{
+	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
+	struct snd_sof_widget *swidget;
+	struct snd_sof_route *sroute;
+	int ret;
+
+	/* restore pipeline components */
+	list_for_each_entry(swidget, &sdev->widget_list, list) {
+		/* only set up the widgets belonging to static pipelines */
+		if (!verify && swidget->dynamic_pipeline_widget)
+			continue;
+
+		/*
+		 * For older firmware, skip scheduler widgets in this loop,
+		 * sof_widget_setup() will be called in the 'complete pipeline' loop
+		 */
+		if (v->abi_version < SOF_ABI_VER(3, 19, 0) &&
+		    swidget->id == snd_soc_dapm_scheduler)
+			continue;
+
+		/* update DAI config. The IPC will be sent in sof_widget_setup() */
+		if (WIDGET_IS_DAI(swidget->id)) {
+			struct snd_sof_dai *dai = swidget->private;
+			struct sof_dai_private_data *private;
+			struct sof_ipc_dai_config *config;
+
+			if (!dai || !dai->private)
+				continue;
+			private = dai->private;
+			if (!private->dai_config)
+				continue;
+
+			config = private->dai_config;
+			/*
+			 * The link DMA channel would be invalidated for running
+			 * streams but not for streams that were in the PAUSED
+			 * state during suspend. So invalidate it here before setting
+			 * the dai config in the DSP.
+			 */
+			if (config->type == SOF_DAI_INTEL_HDA)
+				config->hda.link_dma_ch = DMA_CHAN_INVALID;
+		}
+
+		ret = sof_widget_setup(sdev, swidget);
+		if (ret < 0)
+			return ret;
+	}
+
+	/* restore pipeline connections */
+	list_for_each_entry(sroute, &sdev->route_list, list) {
+		/* only set up routes belonging to static pipelines */
+		if (!verify && (sroute->src_widget->dynamic_pipeline_widget ||
+				sroute->sink_widget->dynamic_pipeline_widget))
+			continue;
+
+		/*
+		 * For virtual routes, both sink and source are not buffer. IPC3 only supports
+		 * connections between a buffer and a component. Ignore the rest.
+		 */
+		if (sroute->src_widget->id != snd_soc_dapm_buffer &&
+		    sroute->sink_widget->id != snd_soc_dapm_buffer)
+			continue;
+
+		ret = sof_route_setup(sdev, sroute->src_widget->widget,
+				      sroute->sink_widget->widget);
+		if (ret < 0) {
+			dev_err(sdev->dev, "%s: route set up failed\n", __func__);
+			return ret;
+		}
+	}
+
+	/* complete pipeline */
+	list_for_each_entry(swidget, &sdev->widget_list, list) {
+		switch (swidget->id) {
+		case snd_soc_dapm_scheduler:
+			/* only complete static pipelines */
+			if (!verify && swidget->dynamic_pipeline_widget)
+				continue;
+
+			if (v->abi_version < SOF_ABI_VER(3, 19, 0)) {
+				ret = sof_widget_setup(sdev, swidget);
+				if (ret < 0)
+					return ret;
+			}
+
+			swidget->complete = sof_ipc3_complete_pipeline(sdev, swidget);
+			if (swidget->complete < 0)
+				return swidget->complete;
+			break;
+		default:
+			break;
+		}
+	}
+
+	return 0;
+}
+
+/*
+ * Free the PCM, its associated widgets and set the prepared flag to false for all PCMs that
+ * did not get suspended(ex: paused streams) so the widgets can be set up again during resume.
+ */
+static int sof_tear_down_left_over_pipelines(struct snd_sof_dev *sdev)
+{
+	struct snd_sof_widget *swidget;
+	struct snd_sof_pcm *spcm;
+	int dir, ret;
+
+	/*
+	 * free all PCMs and their associated DAPM widgets if their connected DAPM widget
+	 * list is not NULL. This should only be true for paused streams at this point.
+	 * This is equivalent to the handling of FE DAI suspend trigger for running streams.
+	 */
+	list_for_each_entry(spcm, &sdev->pcm_list, list) {
+		for_each_pcm_streams(dir) {
+			struct snd_pcm_substream *substream = spcm->stream[dir].substream;
+
+			if (!substream || !substream->runtime)
+				continue;
+
+			if (spcm->stream[dir].list) {
+				ret = sof_pcm_stream_free(sdev, substream, spcm, dir, true);
+				if (ret < 0)
+					return ret;
+			}
+		}
+	}
+
+	/*
+	 * free any left over DAI widgets. This is equivalent to the handling of suspend trigger
+	 * for the BE DAI for running streams.
+	 */
+	list_for_each_entry(swidget, &sdev->widget_list, list)
+		if (WIDGET_IS_DAI(swidget->id) && swidget->use_count == 1) {
+			ret = sof_widget_free(sdev, swidget);
+			if (ret < 0)
+				return ret;
+		}
+
+	return 0;
+}
+
+/*
+ * For older firmware, this function doesn't free widgets for static pipelines during suspend.
+ * It only resets use_count for all widgets.
+ */
+static int sof_ipc3_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verify)
+{
+	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
+	struct snd_sof_widget *swidget;
+	struct snd_sof_route *sroute;
+	int ret;
+
+	/*
+	 * This function is called during suspend and for one-time topology verification during
+	 * first boot. In both cases, there is no need to protect swidget->use_count and
+	 * sroute->setup because during suspend all running streams are suspended and during
+	 * topology loading the sound card unavailable to open PCMs.
+	 */
+	list_for_each_entry(swidget, &sdev->widget_list, list) {
+		if (swidget->dynamic_pipeline_widget)
+			continue;
+
+		/* Do not free widgets for static pipelines with FW ABI older than 3.19 */
+		if (!verify && !swidget->dynamic_pipeline_widget &&
+		    v->abi_version < SOF_ABI_VER(3, 19, 0)) {
+			swidget->use_count = 0;
+			swidget->complete = 0;
+			continue;
+		}
+
+		ret = sof_widget_free(sdev, swidget);
+		if (ret < 0)
+			return ret;
+	}
+
+	/*
+	 * Tear down all pipelines associated with PCMs that did not get suspended
+	 * and unset the prepare flag so that they can be set up again during resume.
+	 * Skip this step for older firmware.
+	 */
+	if (!verify && v->abi_version >= SOF_ABI_VER(3, 19, 0)) {
+		ret = sof_tear_down_left_over_pipelines(sdev);
+		if (ret < 0) {
+			dev_err(sdev->dev, "failed to tear down paused pipelines\n");
+			return ret;
+		}
+	}
+
+	list_for_each_entry(sroute, &sdev->route_list, list)
+		sroute->setup = false;
+
+	return 0;
+}
+
 /* token list for each topology object */
 static enum sof_tokens host_token_list[] = {
 	SOF_CORE_TOKENS,
@@ -2164,4 +2359,6 @@ const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
 	.widget_free = sof_ipc3_widget_free,
 	.widget_setup = sof_ipc3_widget_setup,
 	.dai_config = sof_ipc3_dai_config,
+	.set_up_all_pipelines = sof_ipc3_set_up_all_pipelines,
+	.tear_down_all_pipelines = sof_ipc3_tear_down_all_pipelines,
 };
sound/soc/sof/pm.c +10 -7
index 10adbbd0a9cd..1c319582ca6f 100644
@@ -71,6 +71,7 @@ static int sof_resume(struct device *dev, bool runtime_resume)
 {
 	struct snd_sof_dev *sdev = dev_get_drvdata(dev);
 	const struct sof_ipc_pm_ops *pm_ops = sdev->ipc->ops->pm;
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 	u32 old_state = sdev->dsp_power_state.state;
 	int ret;
 
@@ -144,12 +145,12 @@ static int sof_resume(struct device *dev, bool runtime_resume)
 	}
 
 	/* restore pipelines */
-	ret = sof_set_up_pipelines(sdev, false);
-	if (ret < 0) {
-		dev_err(sdev->dev,
-			"error: failed to restore pipeline after resume %d\n",
-			ret);
-		return ret;
+	if (tplg_ops->set_up_all_pipelines) {
+		ret = tplg_ops->set_up_all_pipelines(sdev, false);
+		if (ret < 0) {
+			dev_err(sdev->dev, "Failed to restore pipeline after resume %d\n", ret);
+			return ret;
+		}
 	}
 
 	/* Notify clients not managed by pm framework about core resume */
@@ -169,6 +170,7 @@ static int sof_suspend(struct device *dev, bool runtime_suspend)
 {
 	struct snd_sof_dev *sdev = dev_get_drvdata(dev);
 	const struct sof_ipc_pm_ops *pm_ops = sdev->ipc->ops->pm;
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 	pm_message_t pm_state;
 	u32 target_state = 0;
 	int ret;
@@ -204,7 +206,8 @@ static int sof_suspend(struct device *dev, bool runtime_suspend)
 		goto suspend;
 	}
 
-	sof_tear_down_pipelines(sdev, false);
+	if (tplg_ops->tear_down_all_pipelines)
+		tplg_ops->tear_down_all_pipelines(sdev, false);
 
 	/* release trace */
 	snd_sof_release_trace(sdev);
sound/soc/sof/sof-audio.c +0 -186

198 lines not on this page · raw message

sound/soc/sof/sof-audio.h +4 -2
index 777da321e2aa..b9a9956b5baa 100644
@@ -117,6 +117,8 @@ struct sof_ipc_tplg_widget_ops {
  * @widget_setup: Function pointer for setting up setup in the DSP
  * @widget_free: Function pointer for freeing widget in the DSP
  * @dai_config: Function pointer for sending DAI config IPC to the DSP
+ * @set_up_all_pipelines: Function pointer for setting up all topology pipelines
+ * @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
  */
 struct sof_ipc_tplg_ops {
 	const struct sof_ipc_tplg_widget_ops *widget;
@@ -130,6 +132,8 @@ struct sof_ipc_tplg_ops {
 	int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
 	int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
 			  unsigned int flags, struct snd_sof_dai_config_data *data);
+	int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
+	int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
 };
 
 /** struct snd_sof_tuple - Tuple info
@@ -429,8 +433,6 @@ int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, bool set);
 int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
 
 /* PM */
-int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify);
-int sof_tear_down_pipelines(struct snd_sof_dev *sdev, bool verify);
 int sof_set_hw_params_upon_resume(struct device *dev);
 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
sound/soc/sof/topology.c +24 -31

74 lines not on this page · raw message

Signature · 1 line
2.25.1
#19 lore raw

PATCH 19/19 ASoC: SOF: Add a new dai_get_clk topology IPC op

In reply to Ranjani Sridharan

This will help make the code for getting the mclk and bclk IPC specific. Add the implementation for IPC3 as well.

---
 sound/soc/sof/ipc3-topology.c | 29 +++++++++++++++++++++++++++++
 sound/soc/sof/sof-audio.c     | 31 +++++++------------------------
 sound/soc/sof/sof-audio.h     |  6 ++++++
 3 files changed, 42 insertions(+), 24 deletions(-)
sound/soc/sof/ipc3-topology.c +29 -0
index 3ac65dacc7b9..2f8450a8c0a1 100644
@@ -2252,6 +2252,34 @@ static int sof_ipc3_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verif
 	return 0;
 }
 
+static int sof_ipc3_dai_get_clk(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type)
+{
+	struct sof_dai_private_data *private = dai->private;
+
+	if (!private || !private->dai_config)
+		return 0;
+
+	switch (private->dai_config->type) {
+	case SOF_DAI_INTEL_SSP:
+		switch (clk_type) {
+		case SOF_DAI_CLK_INTEL_SSP_MCLK:
+			return private->dai_config->ssp.mclk_rate;
+		case SOF_DAI_CLK_INTEL_SSP_BCLK:
+			return private->dai_config->ssp.bclk_rate;
+		default:
+			break;
+		}
+		dev_err(sdev->dev, "fail to get SSP clk %d rate\n", clk_type);
+		break;
+	default:
+		/* not yet implemented for platforms other than the above */
+		dev_err(sdev->dev, "DAI type %d not supported yet!\n", private->dai_config->type);
+		break;
+	}
+
+	return -EINVAL;
+}
+
 /* token list for each topology object */
 static enum sof_tokens host_token_list[] = {
 	SOF_CORE_TOKENS,
@@ -2359,6 +2387,7 @@ const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
 	.widget_free = sof_ipc3_widget_free,
 	.widget_setup = sof_ipc3_widget_setup,
 	.dai_config = sof_ipc3_dai_config,
+	.dai_get_clk = sof_ipc3_dai_get_clk,
 	.set_up_all_pipelines = sof_ipc3_set_up_all_pipelines,
 	.tear_down_all_pipelines = sof_ipc3_tear_down_all_pipelines,
 };
sound/soc/sof/sof-audio.c +7 -24
index b4ee65cf9841..b2f009a0c5b7 100644
@@ -628,40 +628,23 @@ struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
 	return NULL;
 }
 
-#define SOF_DAI_CLK_INTEL_SSP_MCLK	0
-#define SOF_DAI_CLK_INTEL_SSP_BCLK	1
-
 static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
 {
 	struct snd_soc_component *component =
 		snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
 	struct snd_sof_dai *dai =
 		snd_sof_find_dai(component, (char *)rtd->dai_link->name);
-	struct sof_dai_private_data *private = dai->private;
+	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
 
 	/* use the tplg configured mclk if existed */
-	if (!dai || !private || !private->dai_config)
+	if (!dai)
 		return 0;
 
-	switch (private->dai_config->type) {
-	case SOF_DAI_INTEL_SSP:
-		switch (clk_type) {
-		case SOF_DAI_CLK_INTEL_SSP_MCLK:
-			return private->dai_config->ssp.mclk_rate;
-		case SOF_DAI_CLK_INTEL_SSP_BCLK:
-			return private->dai_config->ssp.bclk_rate;
-		default:
-			dev_err(rtd->dev, "fail to get SSP clk %d rate\n",
-				clk_type);
-			return -EINVAL;
-		}
-		break;
-	default:
-		/* not yet implemented for platforms other than the above */
-		dev_err(rtd->dev, "DAI type %d not supported yet!\n",
-			private->dai_config->type);
-		return -EINVAL;
-	}
+	if (tplg_ops->dai_get_clk)
+		return tplg_ops->dai_get_clk(sdev, dai, clk_type);
+
+	return 0;
 }
 
 /*
sound/soc/sof/sof-audio.h +6 -0
index b9a9956b5baa..7f15b3bc8196 100644
@@ -30,6 +30,9 @@
 
 #define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
 
+#define SOF_DAI_CLK_INTEL_SSP_MCLK	0
+#define SOF_DAI_CLK_INTEL_SSP_BCLK	1
+
 /*
  * Volume fractional word length define to 16 sets
  * the volume linear gain value to use Qx.16 format
@@ -39,6 +42,7 @@
 struct snd_sof_widget;
 struct snd_sof_route;
 struct snd_sof_control;
+struct snd_sof_dai;
 
 struct snd_sof_dai_config_data {
 	int dai_index;
@@ -117,6 +121,7 @@ struct sof_ipc_tplg_widget_ops {
  * @widget_setup: Function pointer for setting up setup in the DSP
  * @widget_free: Function pointer for freeing widget in the DSP
  * @dai_config: Function pointer for sending DAI config IPC to the DSP
+ * @dai_get_clk: Function pointer for getting the DAI clock setting
  * @set_up_all_pipelines: Function pointer for setting up all topology pipelines
  * @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
  */
@@ -132,6 +137,7 @@ struct sof_ipc_tplg_ops {
 	int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
 	int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
 			  unsigned int flags, struct snd_sof_dai_config_data *data);
+	int (*dai_get_clk)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type);
 	int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
 	int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
 };
Signature · 1 line
2.25.1
maintainer
#20 lore raw
In reply to Ranjani Sridharan
Quoted 28 lines · Ranjani Sridharan

This series is a continuation to the SOF IPC abstraction work to support the new IPC version introduced in the SOF firmware. It makes the top-level control IO, PCM and PM code IPC-agnostic. Other than the first patch, the rest are purely for abstraction and include no changes in functionality.

Ranjani Sridharan (19):
ASoC: SOF: set up scheduler widget before all other widgets in the
pipeline
ASoC: SOF: Make sof_widget_setup/free IPC agnostic
ASoC: SOF: Make sof_suspend/resume IPC agnostic
ASoC: SOF: Introduce IPC ops for kcontrol IO
ASoC: SOF: Add IPC3 topology control ops
ASoC: SOF: Add volume_get/put IPC3 ops
ASoC: SOF: Add switch get/put IPC3 ops
ASoC: SOF: Add enum_get/put control ops for IPC3
ASoC: SOF: Add bytes_get/put control IPC ops for IPC3
ASoC: SOF: Add bytes_ext control IPC ops for IPC3
ASoC: SOF: Introduce IPC-specific PCM ops
ASoC: SOF: pcm: expose the sof_pcm_setup_connected_widgets() function
ASoC: SOF: Introduce IPC3 PCM hw_free op
ASoC: SOF: Define hw_params PCM op for IPC3
ASoC: SOF: Add trigger PCM op for IPC3
ASoC: SOF: Add dai_link_fixup PCM op for IPC3
ASoC: SOF: expose sof_route_setup()
ASoC: SOF: topology: Add ops for setting up and tearing down pipelines
ASoC: SOF: Add a new dai_get_clk topology IPC op

Quoted 1 line

[...]

Applied to

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

Thanks!

[01/19] ASoC: SOF: set up scheduler widget before all other widgets in the pipeline

        commit: 40c2c63ac40d26bb0b8e17ada32e84541363f1b0
[02/19] ASoC: SOF: Make sof_widget_setup/free IPC agnostic
        commit: 051744b1bf0b13f63af5de3c296d04ab0cc6117c
[03/19] ASoC: SOF: Make sof_suspend/resume IPC agnostic
        commit: 657774acd00f3d63ebae06e5d15a74e013cee0ed
[04/19] ASoC: SOF: Introduce IPC ops for kcontrol IO
        commit: a0149a6bf0b4969a7f732528b2fb6ce32c309dfc
[05/19] ASoC: SOF: Add IPC3 topology control ops
        commit: 10f461d79c2d1afb22344986cc1b4631169cf25e
[06/19] ASoC: SOF: Add volume_get/put IPC3 ops
        commit: 838d04f3e232c3fb8c421959e8ff09e3a918011e
[07/19] ASoC: SOF: Add switch get/put IPC3 ops
        commit: a6668746436824c46b54b3f7fd72523f05f089eb
[08/19] ASoC: SOF: Add enum_get/put control ops for IPC3
        commit: 049307aad2a355f7b44736eeb5795d6d4499fd12
[09/19] ASoC: SOF: Add bytes_get/put control IPC ops for IPC3
        commit: 544ac8858f249950b4d99c68e538cdc07300528f
[10/19] ASoC: SOF: Add bytes_ext control IPC ops for IPC3
        commit: 67ec2a091630c28ea8d05db2bd7178a05b04b7e6
[11/19] ASoC: SOF: Introduce IPC-specific PCM ops
        commit: 967885ee45e48b669e0904a38f6aeb1a09b0d9a1
[12/19] ASoC: SOF: pcm: expose the sof_pcm_setup_connected_widgets() function
        commit: 442c7128219b1769af5685c5453b13711f6b84e2
[13/19] ASoC: SOF: Introduce IPC3 PCM hw_free op
        commit: 4123c24bd13caa8ff633d9e17fa2089d53b1f766
[14/19] ASoC: SOF: Define hw_params PCM op for IPC3
        commit: 621fd48c8cc8d77101a3ac69f7f058d3f8afdbcc
[15/19] ASoC: SOF: Add trigger PCM op for IPC3
        commit: beac3f4cb66fa05e902768ae75ea691c4a2c0911
[16/19] ASoC: SOF: Add dai_link_fixup PCM op for IPC3
        commit: b243b437f4c46b09ec26fc02bea610ace4b45aa2
[17/19] ASoC: SOF: expose sof_route_setup()
        commit: 3816bbea644202fd0a8410e54dbc30bd93f3292c
[18/19] ASoC: SOF: topology: Add ops for setting up and tearing down pipelines
        commit: 31cd6e469364c42c9c929750991c51e83a95e80b
[19/19] ASoC: SOF: Add a new dai_get_clk topology IPC op
        commit: 85f7a8b6e1bea0ad494fb786a5dd7d9715a976d2

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