Skip to contentSkip to conversation

ASoC: Intel: avs: Soundwire support

PATCH Superseded Cezary Rojewski 4 participants 21 messages Nov 3 – Nov 5

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

v2 cover ASoC: Intel: avs: Soundwire support

The RaptorLake-P and RaptorLake-M based platform used in Automotive area do utilize SoundWire for streaming audio. This patchset brings such support to the public domain.

If possible, I'd like the changes to go through Mark's tree.

As the patchset updates drivers/soundwire, I've decided to strip it off any machine-boards and have here just the changes done to the main soundwire driver and their user/usage. Machine boards for RPL-P/M will follow in a separate set and do not touch drivers/soundwire stuff.

The reasoning behind modyfing the soundwire code:

Typically dai->startup() is responsible for checking if all the required resources are available whereas dai->hw_params() is responsible for configuring such resources. Existing code does the PDI assignment and its configuration within one function - intel_hw_params(). The logical split is not possible. The change provides functions that represent such logical blocks: assign, release and config. Such division exists already for the HDAudio interface, see sound/hda/core/stream.c

For the user i.e.: avs-driver (sound/soc/intel/avs) it also makes the code very cohesive - aligns with that's done on the HDAudio side as all the HDAudio streams are assignment during dai->startup() and configured with dai->hw_params().

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

avs-driver -only patches follow the three soundwire ones. First, they extend the existing code so it can accommodate SDW interface. With that done, laverage existing PCM code (sound/soc/intel/avs/pcm.c) and soundwire-intel to implement DAI operations.

Changes in v2:
- dropped duplicate headers as pointed by Amadeusz
- fixed PDI initialization for ace2x as pointed by Bard. This is done by introducing ->init_pdis() ops and calling it just before ->register_dais(). The body of the ops is 1:1 with the existing PDI initialization code
- fixed the error path if init_pdis() fails, as pointed by Bard
- fixed Amadeusz' email for all the headers

A number of changes pointed by Sashiko:
- fixed compilation when CONFIG_SND_SOC_INTEL_AVS=y and CONFIG_SOUNDWIRE_INTEL=m. This is done with help of new kconfig:
SND_SOC_INTEL_AVS_SOUNDWIRE
- added missing kernel docs
- avs_sdw_dai_trigger()/prepare() now rollback sdw_stream state if DSP operations fail
- avs_sdw_dai_shutdown() now NULLs the sdw_stream context
- wanted to reserve this for later but since the bot pointed this out, updated hw_params(), hw_free() and prepare() to accommodate for suspend/resume scenario with a SDW stream
- sdw_intel_acpi_scan() now returns -ENODEV if the library is disabled (previously returned 0)
- avs_sdw_probe() now exits early if the link_mask is 0
- disabled SDW probing for avs-driver on ACE2+ platforms

Cezary Rojewski (7):
soundwire: intel: Define stubs when library is disabled
soundwire: intel: Allow for dynamic assignment of PDIs
soundwire: intel: Split PDIs and DAIs initialization
ASoC: Intel: avs: Pass irq to dsp_interrupt callback
ASoC: Intel: avs: SoundWire support
ASoC: Intel: avs: Expose common PCM functions
ASoC: Intel: avs: SoundWire PCM BE operations

 drivers/soundwire/cadence_master.c    |  65 ++++++
 drivers/soundwire/cadence_master.h    |  25 +--
 drivers/soundwire/intel.c             |  41 +++-
 drivers/soundwire/intel.h             |  10 +-
 drivers/soundwire/intel_ace2x.c       |  25 ++-
 drivers/soundwire/intel_auxdevice.c   |   4 +
 include/linux/soundwire/sdw_cadence.h |  35 ++++
 include/linux/soundwire/sdw_intel.h   |  45 +++-
 sound/hda/core/Kconfig                |   2 +-
 sound/hda/core/Makefile               |   3 +
 sound/soc/intel/Kconfig               |   8 +
 sound/soc/intel/avs/Makefile          |   4 +
 sound/soc/intel/avs/apl.c             |   2 +-
 sound/soc/intel/avs/avs.h             |  15 +-
 sound/soc/intel/avs/cnl.c             |  25 ++-
 sound/soc/intel/avs/core.c            |  22 +-
 sound/soc/intel/avs/loader.c          |   3 +
 sound/soc/intel/avs/messages.h        |   2 +
 sound/soc/intel/avs/mtl.c             |   2 +-
 sound/soc/intel/avs/path.c            |   2 +
 sound/soc/intel/avs/pcm.c             |  42 +---
 sound/soc/intel/avs/pcm.h             |  50 +++++
 sound/soc/intel/avs/pcm_sdw.c         | 289 ++++++++++++++++++++++++++
 sound/soc/intel/avs/registers.h       |   4 +
 sound/soc/intel/avs/skl.c             |   2 +-
 sound/soc/intel/avs/soundwire.c       | 117 +++++++++++
 sound/soc/intel/avs/soundwire.h       |  63 ++++++
 27 files changed, 816 insertions(+), 91 deletions(-)
 create mode 100644 include/linux/soundwire/sdw_cadence.h
 create mode 100644 sound/soc/intel/avs/pcm_sdw.c
 create mode 100644 sound/soc/intel/avs/soundwire.c
 create mode 100644 sound/soc/intel/avs/soundwire.h
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 1/7 soundwire: intel: Define stubs when library is disabled

The library defines no stubs when it is disabled so the actual users have to do it locally to allow the code to compilte or, guard the code that does interact with soundwire with #if(s). Define simple wrappers to make the life of soundwire-code users easier.

The change allows for a driver to build against SOUNDWIRE_INTEL=n whilst still calling the stubs in its common code without compilation failing. The driver needs not to flank its soundwire-code with #if(s) either.

Not all sdw_intel_xxx()s are part of drivers/soundwire. Some definitions are located within sound/hda/core instead. With the wrappers done, update Kconfig for sound/hda/core as currently the ACPI-related function are compiled regardless if SOUNDWIRE_INTEL is selected or not. By being dependent on SOUNDWIRE_INTEL those functions are compiled only if the SoundWire was actually requested.

---
 include/linux/soundwire/sdw_intel.h | 34 +++++++++++++++++++++++++++++
 sound/hda/core/Kconfig              |  2 +-
 sound/hda/core/Makefile             |  3 +++
 3 files changed, 38 insertions(+), 1 deletion(-)
include/linux/soundwire/sdw_intel.h +34 -0
index 9710f2dc04e2..4547dcc710e5 100644
@@ -358,6 +358,8 @@ struct sdw_intel_res {
 	struct mutex *eml_lock;
 };
 
+#if IS_ENABLED(CONFIG_SOUNDWIRE_INTEL)
+
 /*
  * On Intel platforms, the SoundWire IP has dependencies on power
  * rails shared with the DSP, and the initialization steps are split
@@ -384,6 +386,38 @@ void sdw_intel_exit(struct sdw_intel_ctx *ctx);
 
 irqreturn_t sdw_intel_thread(int irq, void *dev_id);
 
+#else
+
+static inline int sdw_intel_acpi_scan(acpi_handle parent_handle, struct sdw_intel_acpi_info *info)
+{
+	return -ENODEV;
+}
+
+static inline void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx)
+{
+}
+
+static inline struct sdw_intel_ctx *sdw_intel_probe(struct sdw_intel_res *res)
+{
+	return NULL;
+}
+
+static inline int sdw_intel_startup(struct sdw_intel_ctx *ctx)
+{
+	return 0;
+}
+
+static inline void sdw_intel_exit(struct sdw_intel_ctx *ctx)
+{
+}
+
+static inline irqreturn_t sdw_intel_thread(int irq, void *dev_id)
+{
+	return 0;
+}
+
+#endif
+
 #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE      BIT(1)
 
 struct sdw_intel;
sound/hda/core/Kconfig +1 -1
index bfdcf6384c52..6cbcd9e26420 100644
@@ -29,7 +29,7 @@ config SND_INTEL_DSP_CONFIG
 	tristate
 	select ACPI_NHLT if ACPI
 	select SND_INTEL_NHLT if ACPI
-	select SND_INTEL_SOUNDWIRE_ACPI if ACPI
+	select SND_INTEL_SOUNDWIRE_ACPI if SOUNDWIRE_INTEL != n
 	# this config should be selected only for Intel DSP platforms.
 	# A fallback is provided so that the code compiles in all cases.
 
sound/hda/core/Makefile +3 -0
index 89cb46143050..28032ac7bc61 100644
@@ -18,5 +18,8 @@ snd-intel-dspcfg-y := intel-dsp-config.o
 snd-intel-dspcfg-$(CONFIG_SND_INTEL_NHLT) += intel-nhlt.o
 obj-$(CONFIG_SND_INTEL_DSP_CONFIG) += snd-intel-dspcfg.o
 
+ifneq ($(CONFIG_SND_INTEL_SOUNDWIRE_ACPI),)
 snd-intel-sdw-acpi-y := intel-sdw-acpi.o
+endif
+
 obj-$(CONFIG_SND_INTEL_SOUNDWIRE_ACPI) += snd-intel-sdw-acpi.o
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v2 2/7 soundwire: intel: Allow for dynamic assignment of PDIs

In reply to Cezary Rojewski

Currently, PDIs are assigned upfront based on the DAI IDs. Some drivers do not assign anything upfront and request a free PDI when streaming is about to start.

Provide assign/release() functions to allow them to be assigned dynamically. This also streamlines the process of assigning/releasing PDIs with what is done in HDAudio library (sound/hda) for HDAudio streams, see snd_hdac_stream_assign/release().

As resource availability-check is typically done during dai->startup() whilst hardware/firmware configuration occurs on dai->hw_params(), add sdw_intel_pdi_config() to maintain this logical split - assign on start(), configure on hw_params(). Existing code does all of that in intel_hw_params() so the logical split is not possible.

---
 drivers/soundwire/cadence_master.c    | 65 +++++++++++++++++++++++++++
 drivers/soundwire/cadence_master.h    | 25 ++---------
 drivers/soundwire/intel.c             | 16 +++++++
 include/linux/soundwire/sdw_cadence.h | 35 +++++++++++++++
 include/linux/soundwire/sdw_intel.h   |  7 +++
 5 files changed, 127 insertions(+), 21 deletions(-)
 create mode 100644 include/linux/soundwire/sdw_cadence.h
drivers/soundwire/cadence_master.c +65 -0
index a0a63b76793e..3eb3ac428d87 100644
@@ -17,6 +17,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/soundwire/sdw_registers.h>
 #include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_cadence.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 #include <linux/workqueue.h>
@@ -1835,6 +1836,7 @@ int sdw_cdns_probe(struct sdw_cdns *cdns)
 
 	mutex_init(&cdns->status_update_lock);
 
+	spin_lock_init(&cdns->pdi_lock);
 	INIT_WORK(&cdns->work, cdns_update_slave_status_work);
 	INIT_DELAYED_WORK(&cdns->attach_dwork, cdns_check_attached_status_dwork);
 
@@ -1991,6 +1993,69 @@ struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
 }
 EXPORT_SYMBOL(sdw_cdns_alloc_pdi);
 
+/**
+ * sdw_cdns_assign_pdi - Assign a PDI
+ * @bus: SoundWire bus instance
+ * @dir: Data direction
+ *
+ * Return: A valid PDI instance or %NULL if none available.
+ */
+struct sdw_cdns_pdi *sdw_cdns_assign_pdi(struct sdw_bus *bus, u32 dir)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+	struct sdw_cdns_streams *stream = &cdns->pcm;
+	struct sdw_cdns_pdi *pdis, *pdi;
+	size_t num_pdis;
+	int i;
+
+	if (dir == SDW_DATA_DIR_RX) {
+		num_pdis = stream->num_in;
+		pdis = stream->in;
+	} else {
+		num_pdis = stream->num_out;
+		pdis = stream->out;
+	}
+
+	spin_lock(&cdns->pdi_lock);
+	for (i = 0; i < num_pdis; i++) {
+		if (!pdis[i].assigned) {
+			pdi = &pdis[i];
+			goto found;
+		}
+	}
+
+	/* Indexes 0/1 are reserved for the Bulk transfer. */
+	for (i = 2; i < stream->num_bd; i++) {
+		if (!stream->bd[i].assigned) {
+			pdi = &stream->bd[i];
+			goto found;
+		}
+	}
+
+	spin_unlock(&cdns->pdi_lock);
+	return NULL;
+found:
+	pdi->dir = dir;
+	pdi->assigned = true;
+	spin_unlock(&cdns->pdi_lock);
+	return pdi;
+}
+EXPORT_SYMBOL(sdw_cdns_assign_pdi);
+
+/**
+ * sdw_cdns_release_pdi() - Release a PDI
+ * @bus: SoundWire bus instance
+ * @pdi: PDI instance
+ */
+void sdw_cdns_release_pdi(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+
+	guard(spinlock)(&cdns->pdi_lock);
+	pdi->assigned = false;
+}
+EXPORT_SYMBOL(sdw_cdns_release_pdi);
+
 /*
  * the MIPI SoundWire CRC8 polynomial is X^8 + X^6 + X^3 + X^2 + 1, MSB first
  * The value is (1)01001101 = 0x4D
drivers/soundwire/cadence_master.h +4 -21
index f4e41a9ab165..c3339c1e98ff 100644
@@ -6,6 +6,8 @@
 #ifndef __SDW_CADENCE_H
 #define __SDW_CADENCE_H
 
+#include <linux/soundwire/sdw_cadence.h>
+
 #define SDW_CADENCE_GSYNC_KHZ		4 /* 4 kHz */
 #define SDW_CADENCE_GSYNC_HZ		(SDW_CADENCE_GSYNC_KHZ * 1000)
 
@@ -17,27 +19,6 @@
 
 #define SDW_CADENCE_MCP_IP_OFFSET	0x4000
 
-/**
- * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
- *
- * @num: pdi number
- * @intel_alh_id: link identifier
- * @l_ch_num: low channel for PDI
- * @h_ch_num: high channel for PDI
- * @ch_count: total channel count for PDI
- * @dir: data direction
- * @type: stream type, (only PCM supported)
- */
-struct sdw_cdns_pdi {
-	int num;
-	int intel_alh_id;
-	int l_ch_num;
-	int h_ch_num;
-	int ch_count;
-	enum sdw_data_direction dir;
-	enum sdw_stream_type type;
-};
-
 /**
  * struct sdw_cdns_streams: Cadence stream data structure
  *
@@ -114,6 +95,7 @@ struct sdw_cdns_dai_runtime {
  * @ports: Data ports
  * @num_ports: Total number of data ports
  * @pcm: PCM streams
+ * @pdi_lock: synchronizes assignment of PDIs found in PCM streams
  * @registers: Cadence registers
  * @link_up: Link status
  * @msg_count: Messages sent on bus
@@ -140,6 +122,7 @@ struct sdw_cdns {
 	int num_ports;
 
 	struct sdw_cdns_streams pcm;
+	spinlock_t pdi_lock;
 
 	int pdi_loopback_source;
 	int pdi_loopback_target;
drivers/soundwire/intel.c +16 -0
index af65214836b4..d53fa3d299bc 100644
@@ -674,6 +674,22 @@ intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi)
 	intel_writel(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id), conf);
 }
 
+/**
+ * sdw_intel_pdi_config - Configure specified PDI
+ * @bus: SoundWire bus instance
+ * @pdi: PDI instance to configure
+ */
+void sdw_intel_pdi_config(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+	struct sdw_intel *sdw = cdns_to_intel(cdns);
+
+	intel_pdi_shim_configure(sdw, pdi);
+	intel_pdi_alh_configure(sdw, pdi);
+	sdw_cdns_config_stream(cdns, pdi->ch_count, pdi->dir, pdi);
+}
+EXPORT_SYMBOL(sdw_intel_pdi_config);
+
 static int intel_params_stream(struct sdw_intel *sdw,
 			       struct snd_pcm_substream *substream,
 			       struct snd_soc_dai *dai,
include/linux/soundwire/sdw_cadence.h new file +35 -0
new file mode 100644
index 000000000000..331b21adafc4
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
+/* Copyright(c) 2024-2026 Intel Corporation */
+
+#ifndef ___SDW_CADENCE_H
+#define ___SDW_CADENCE_H
+
+#include <linux/soundwire/sdw.h>
+
+/**
+ * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
+ *
+ * @num: pdi number
+ * @intel_alh_id: link identifier
+ * @l_ch_num: low channel for PDI
+ * @h_ch_num: high channel for PDI
+ * @ch_count: total channel count for PDI
+ * @dir: data direction
+ * @type: stream type, (only PCM supported)
+ * @assigned: whether PDI is in use
+ */
+struct sdw_cdns_pdi {
+	int num;
+	int intel_alh_id;
+	int l_ch_num;
+	int h_ch_num;
+	int ch_count;
+	enum sdw_data_direction dir;
+	enum sdw_stream_type type;
+	bool assigned;
+};
+
+struct sdw_cdns_pdi *sdw_cdns_assign_pdi(struct sdw_bus *bus, u32 dir);
+void sdw_cdns_release_pdi(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi);
+
+#endif
include/linux/soundwire/sdw_intel.h +7 -0
index 4547dcc710e5..fbfb216bd90c 100644
@@ -7,6 +7,7 @@
 #include <linux/acpi.h>
 #include <linux/irqreturn.h>
 #include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_cadence.h>
 
 /*********************************************************************
  * cAVS and ACE1.x definitions
@@ -386,6 +387,8 @@ void sdw_intel_exit(struct sdw_intel_ctx *ctx);
 
 irqreturn_t sdw_intel_thread(int irq, void *dev_id);
 
+void sdw_intel_pdi_config(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi);
+
 #else
 
 static inline int sdw_intel_acpi_scan(acpi_handle parent_handle, struct sdw_intel_acpi_info *info)
@@ -416,6 +419,10 @@ static inline irqreturn_t sdw_intel_thread(int irq, void *dev_id)
 	return 0;
 }
 
+static inline void sdw_intel_pdi_config(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi)
+{
+}
+
 #endif
 
 #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE      BIT(1)
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v2 2/7] soundwire: intel: Allow for dynamic assignment of PDIs

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] soundwire: intel: sdw_intel_pdi_config() adds separate layer over DAI ops --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] soundwire: intel: sdw_intel_pdi_config() adds separate layer over DAI ops --

commit e83fbc567de1bac187beea3bd11c5b0304d25e97
Author: Cezary Rojewski <[email protected]>

soundwire: intel: Allow for dynamic assignment of PDIs

This commit introduces sdw_cdns_assign_pdi() and sdw_cdns_release_pdi() for dynamic PDI assignment, along with sdw_intel_pdi_config() to configure PDIs separately from assignment.

Quoted 13 lines
drivers/soundwire/intel.c +5 -0
index af65214836b4d..d53fa3d299bc7 100644
@@ -674,6 +674,22 @@ intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi)
 	intel_writel(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id), conf);
 }
 
+/**
+ * sdw_intel_pdi_config - Configure specified PDI
+ * @bus: SoundWire bus instance
+ * @pdi: PDI instance to configure
+ */

drivers/soundwire/intel.c intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi) · line 691

Quoted 10 lines
drivers/soundwire/intel.c +10 -0
+void sdw_intel_pdi_config(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+	struct sdw_intel *sdw = cdns_to_intel(cdns);
+
+	intel_pdi_shim_configure(sdw, pdi);
+	intel_pdi_alh_configure(sdw, pdi);
+	sdw_cdns_config_stream(cdns, pdi->ch_count, pdi->dir, pdi);
+}
+EXPORT_SYMBOL(sdw_intel_pdi_config);

[Severity: Medium]
As reported by Vinod Koul on v1 [1], exporting sdw_intel_pdi_config() adds a separate layer in drivers/soundwire/intel.c for external driver-specific DAI handling while leaving the existing DAI operations in intel_hw_params() unchanged:

drivers/soundwire/intel.c:intel_hw_params() {
    ...
	pdi = sdw_cdns_alloc_pdi(cdns, &cdns->pcm, ch, dir, dai->id);

	if (!pdi)
		return -EINVAL;

	/* do run-time configurations for SHIM, ALH and PDI/PORT */
	intel_pdi_shim_configure(sdw, pdi);
	intel_pdi_alh_configure(sdw, pdi);
	sdw_cdns_config_stream(cdns, ch, dir, pdi);
    ...
}

Instead of exporting sdw_intel_pdi_config() for external callers while intel_hw_params() continues to allocate PDIs statically by DAI ID and call intel_pdi_shim_configure(), intel_pdi_alh_configure(), and sdw_cdns_config_stream() directly, could the SoundWire Intel driver itself be updated to handle both startup and hw_params uniformly across SOF and AVS drivers?

[1] https://lore.kernel.org/r/aulzN9MCl5CJB1Al@parshuram

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#4 lore raw

PATCH v2 3/7 soundwire: intel: Split PDIs and DAIs initialization

In reply to Cezary Rojewski

Not every client of the soundwire-driver needs the secondary soc-component and full range of DAIs immediately when initializing the device. As function intel_register_dai() does all of that on top of initializing PDIs, split it into two logical blocks to accommodate for both approaches. In consequence, register_dai() callback becomes optional.

To keep things in status quo for existing users, update intel_link_startup() to call sdw_intel_init_pdis().

---
 drivers/soundwire/intel.c           | 25 ++++++++++++++++---------
 drivers/soundwire/intel.h           | 10 +++++++++-
 drivers/soundwire/intel_ace2x.c     | 25 ++++++++++++++++---------
 drivers/soundwire/intel_auxdevice.c |  4 ++++
 include/linux/soundwire/sdw_intel.h |  4 +++-
 5 files changed, 48 insertions(+), 20 deletions(-)
drivers/soundwire/intel.c +16 -9
index d53fa3d299bc..7807d24ff050 100644
@@ -1027,23 +1027,29 @@ static int intel_create_dai(struct sdw_cdns *cdns,
 	return 0;
 }
 
+static int intel_init_pdis(struct sdw_intel *sdw)
+{
+	struct sdw_cdns_stream_config config;
+	int ret;
+
+	/* Read the PDI config and initialize cadence PDI */
+	intel_pdi_init(sdw, &config);
+	ret = sdw_cdns_pdi_init(&sdw->cdns, config);
+	if (ret)
+		return ret;
+
+	intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm);
+	return 0;
+}
+
 static int intel_register_dai(struct sdw_intel *sdw)
 {
 	struct sdw_cdns_dai_runtime **dai_runtime_array;
-	struct sdw_cdns_stream_config config;
 	struct sdw_cdns *cdns = &sdw->cdns;
 	struct sdw_cdns_streams *stream;
 	struct snd_soc_dai_driver *dais;
 	int num_dai, ret, off = 0;
 
-	/* Read the PDI config and initialize cadence PDI */
-	intel_pdi_init(sdw, &config);
-	ret = sdw_cdns_pdi_init(cdns, config);
-	if (ret)
-		return ret;
-
-	intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm);
-
 	/* DAIs are created based on total number of PDIs supported */
 	num_dai = cdns->pcm.num_pdi;
 
@@ -1087,6 +1093,7 @@ const struct sdw_intel_hw_ops sdw_intel_cnl_hw_ops = {
 	.debugfs_init = intel_debugfs_init,
 	.debugfs_exit = intel_debugfs_exit,
 
+	.init_pdis = intel_init_pdis,
 	.register_dai = intel_register_dai,
 
 	.check_clock_stop = intel_check_clock_stop,
drivers/soundwire/intel.h +9 -1
index 7a2e7e73ad63..f2372749f08d 100644
@@ -154,11 +154,18 @@ static inline void sdw_intel_debugfs_exit(struct sdw_intel *sdw)
 		SDW_INTEL_OPS(sdw, debugfs_exit)(sdw);
 }
 
+static inline int sdw_intel_init_pdis(struct sdw_intel *sdw)
+{
+	if (SDW_INTEL_CHECK_OPS(sdw, init_pdis))
+		return SDW_INTEL_OPS(sdw, init_pdis)(sdw);
+	return -ENOTSUPP;
+}
+
 static inline int sdw_intel_register_dai(struct sdw_intel *sdw)
 {
 	if (SDW_INTEL_CHECK_OPS(sdw, register_dai))
 		return SDW_INTEL_OPS(sdw, register_dai)(sdw);
-	return -ENOTSUPP;
+	return 0;
 }
 
 static inline void sdw_intel_check_clock_stop(struct sdw_intel *sdw)
@@ -262,6 +269,7 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw);
 void intel_check_clock_stop(struct sdw_intel *sdw);
 int intel_start_bus_after_clock_stop(struct sdw_intel *sdw);
 int intel_stop_bus(struct sdw_intel *sdw, bool clock_stop, bool wake_enable);
+int sdw_intel_init_pdis(struct sdw_intel *sdw);
 
 /* common bank switch routines */
 int intel_pre_bank_switch(struct sdw_intel *sdw);
drivers/soundwire/intel_ace2x.c +16 -9
index 642b33ab5526..67b5d54bb2a7 100644
@@ -1058,10 +1058,24 @@ static int intel_create_dai(struct sdw_cdns *cdns,
 	return 0;
 }
 
+static int intel_init_pdis(struct sdw_intel *sdw)
+{
+	struct sdw_cdns_stream_config config;
+	int ret;
+
+	/* Read the PDI config and initialize cadence PDI */
+	intel_pdi_init(sdw, &config);
+	ret = sdw_cdns_pdi_init(&sdw->cdns, config);
+	if (ret)
+		return ret;
+
+	intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm);
+	return 0;
+}
+
 static int intel_register_dai(struct sdw_intel *sdw)
 {
 	struct sdw_cdns_dai_runtime **dai_runtime_array;
-	struct sdw_cdns_stream_config config;
 	struct sdw_cdns *cdns = &sdw->cdns;
 	struct sdw_cdns_streams *stream;
 	struct snd_soc_dai_driver *dais;
@@ -1069,14 +1083,6 @@ static int intel_register_dai(struct sdw_intel *sdw)
 	int ret;
 	int off = 0;
 
-	/* Read the PDI config and initialize cadence PDI */
-	intel_pdi_init(sdw, &config);
-	ret = sdw_cdns_pdi_init(cdns, config);
-	if (ret)
-		return ret;
-
-	intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm);
-
 	/* DAIs are created based on total number of PDIs supported */
 	num_dai = cdns->pcm.num_pdi;
 
@@ -1149,6 +1155,7 @@ const struct sdw_intel_hw_ops sdw_intel_lnl_hw_ops = {
 
 	.get_link_count = intel_get_link_count,
 
+	.init_pdis = intel_init_pdis,
 	.register_dai = intel_register_dai,
 
 	.check_clock_stop = intel_check_clock_stop,
drivers/soundwire/intel_auxdevice.c +4 -0
index 5983fbc5725a..9031c96f7e9d 100644
@@ -423,6 +423,10 @@ int intel_link_startup(struct auxiliary_device *auxdev)
 	if (ret)
 		goto err_init;
 
+	ret = sdw_intel_init_pdis(sdw);
+	if (ret)
+		goto err_power_up;
+
 	/* Register DAIs */
 	ret = sdw_intel_register_dai(sdw);
 	if (ret) {
include/linux/soundwire/sdw_intel.h +3 -1
index fbfb216bd90c..0efb05a25d12 100644
@@ -433,7 +433,8 @@ struct sdw_intel;
  * @debugfs_init: initialize all debugfs capabilities
  * @debugfs_exit: close and cleanup debugfs capabilities
  * @get_link_count: fetch link count from hardware registers
- * @register_dai: read all PDI information and register DAIs
+ * @init_pdis: read all PDI information
+ * @register_dai: register DAIs
  * @check_clock_stop: throw error message if clock is not stopped.
  * @start_bus: normal start
  * @start_bus_after_reset: start after reset
@@ -459,6 +460,7 @@ struct sdw_intel_hw_ops {
 
 	int (*get_link_count)(struct sdw_intel *sdw);
 
+	int (*init_pdis)(struct sdw_intel *sdw);
 	int (*register_dai)(struct sdw_intel *sdw);
 
 	void (*check_clock_stop)(struct sdw_intel *sdw);
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v2 3/7] soundwire: intel: Split PDIs and DAIs initialization

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] soundwire: intel: redundant declaration of sdw_intel_init_pdis() in intel.h --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] soundwire: intel: redundant declaration of sdw_intel_init_pdis() in intel.h --

commit b93a84bb66dfc11183e5241bb65db4b0c4fcaaef
Author: Cezary Rojewski <[email protected]>

soundwire: intel: Split PDIs and DAIs initialization

This commit splits PDI initialization out of intel_register_dai() into a separate init_pdis callback in struct sdw_intel_hw_ops so that register_dai() can be optional. It also updates intel_link_startup() to call sdw_intel_init_pdis() before registering DAIs.

Quoted 25 lines
drivers/soundwire/intel.h +8 -1
index 7a2e7e73ad632..f2372749f08db 100644
@@ -154,11 +154,18 @@ static inline void sdw_intel_debugfs_exit(struct sdw_intel *sdw)
 		SDW_INTEL_OPS(sdw, debugfs_exit)(sdw);
 }
 
+static inline int sdw_intel_init_pdis(struct sdw_intel *sdw)
+{
+	if (SDW_INTEL_CHECK_OPS(sdw, init_pdis))
+		return SDW_INTEL_OPS(sdw, init_pdis)(sdw);
+	return -ENOTSUPP;
+}
+
 static inline int sdw_intel_register_dai(struct sdw_intel *sdw)
 {
 	if (SDW_INTEL_CHECK_OPS(sdw, register_dai))
 		return SDW_INTEL_OPS(sdw, register_dai)(sdw);
-	return -ENOTSUPP;
+	return 0;
 }
 
 static inline void sdw_intel_check_clock_stop(struct sdw_intel *sdw)

drivers/soundwire/intel.h int intel_start_bus_after_reset(struct sdw_intel *sdw); · line 272

Quoted 4 lines
drivers/soundwire/intel.h +1 -0
@@ -262,6 +269,7 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw);
 void intel_check_clock_stop(struct sdw_intel *sdw);
 int intel_start_bus_after_clock_stop(struct sdw_intel *sdw);
 int intel_stop_bus(struct sdw_intel *sdw, bool clock_stop, bool wake_enable);
+int sdw_intel_init_pdis(struct sdw_intel *sdw);

[Severity: Low]
sdw_intel_init_pdis() is already defined earlier in drivers/soundwire/intel.h as a static inline wrapper for the init_pdis callback. Should this redundant non-static prototype under the common bus management declarations be dropped?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author maintainer
#6 lore raw

PATCH v2 4/7 ASoC: Intel: avs: Pass irq to dsp_interrupt callback

In reply to Cezary Rojewski

Soundwire IRQ thread function requires passing irq as one of the arguments, as we will want to call it in dsp_interrupt callback, it needs to be passed throguh.

---
 sound/soc/intel/avs/apl.c  | 2 +-
 sound/soc/intel/avs/avs.h  | 6 +++---
 sound/soc/intel/avs/cnl.c  | 2 +-
 sound/soc/intel/avs/core.c | 2 +-
 sound/soc/intel/avs/mtl.c  | 2 +-
 sound/soc/intel/avs/skl.c  | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)
sound/soc/intel/avs/apl.c +1 -1
index cf600e1c986e..3abcdf062035 100644
@@ -17,7 +17,7 @@
 #include "registers.h"
 #include "topology.h"
 
-static irqreturn_t avs_apl_dsp_interrupt(struct avs_dev *adev)
+static irqreturn_t avs_apl_dsp_interrupt(struct avs_dev *adev, int irq)
 {
 	u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
 	irqreturn_t ret = IRQ_NONE;
sound/soc/intel/avs/avs.h +3 -3
index b4f9d66d55ad..b3af2c4126be 100644
@@ -45,7 +45,7 @@ struct avs_dsp_ops {
 	int (* const power)(struct avs_dev *, u32, bool);
 	int (* const reset)(struct avs_dev *, u32, bool);
 	int (* const stall)(struct avs_dev *, u32, bool);
-	irqreturn_t (* const dsp_interrupt)(struct avs_dev *);
+	irqreturn_t (* const dsp_interrupt)(struct avs_dev *, int irq);
 	void (* const int_control)(struct avs_dev *, bool);
 	int (* const load_basefw)(struct avs_dev *, struct firmware *);
 	int (* const load_lib)(struct avs_dev *, struct firmware *, u32);
@@ -273,8 +273,8 @@ int avs_mtl_core_stall(struct avs_dev *adev, u32 core_mask, bool stall);
 int avs_lnl_core_stall(struct avs_dev *adev, u32 core_mask, bool stall);
 void avs_mtl_interrupt_control(struct avs_dev *adev, bool enable);
 void avs_skl_ipc_interrupt(struct avs_dev *adev);
-irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev);
-irqreturn_t avs_mtl_dsp_interrupt(struct avs_dev *adev);
+irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev, int irq);
+irqreturn_t avs_mtl_dsp_interrupt(struct avs_dev *adev, int irq);
 int avs_apl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
 			u32 fifo_full_period, unsigned long resource_mask, u32 *priorities);
 int avs_icl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
sound/soc/intel/avs/cnl.c +1 -1
index 5b5359e9128b..31fd9f251d6c 100644
@@ -58,7 +58,7 @@ static void avs_cnl_ipc_interrupt(struct avs_dev *adev)
 			      AVS_ADSP_HIPCCTL_DONE | AVS_ADSP_HIPCCTL_BUSY);
 }
 
-irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev)
+irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev, int irq)
 {
 	u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
 	irqreturn_t ret = IRQ_NONE;
sound/soc/intel/avs/core.c +1 -1
index 611ae9f034d4..9413027e1e32 100644
@@ -344,7 +344,7 @@ static irqreturn_t avs_dsp_irq_thread(int irq, void *dev_id)
 
 	status = readl(bus->ppcap + AZX_REG_PP_PPSTS);
 	if (status & AZX_PPCTL_PIE)
-		avs_dsp_op(adev, dsp_interrupt);
+		avs_dsp_op(adev, dsp_interrupt, irq);
 
 	/* Unmask GIE, masked in irq_handler(). */
 	snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_GLOBAL_EN, AZX_INT_GLOBAL_EN);
sound/soc/intel/avs/mtl.c +1 -1
index d8bdd03275d7..29f79d6ff0d4 100644
@@ -166,7 +166,7 @@ static void avs_mtl_ipc_interrupt(struct avs_dev *adev)
 			      AVS_ADSP_HIPCCTL_DONE | AVS_ADSP_HIPCCTL_BUSY);
 }
 
-irqreturn_t avs_mtl_dsp_interrupt(struct avs_dev *adev)
+irqreturn_t avs_mtl_dsp_interrupt(struct avs_dev *adev, int irq)
 {
 	u32 adspis = snd_hdac_adsp_readl(adev, MTL_DWICTL_REG_FINALSTATUSL);
 	irqreturn_t ret = IRQ_NONE;
sound/soc/intel/avs/skl.c +1 -1
index 8fb86f364ff3..54c883658cca 100644
@@ -54,7 +54,7 @@ void avs_skl_ipc_interrupt(struct avs_dev *adev)
 			      AVS_ADSP_HIPCCTL_DONE | AVS_ADSP_HIPCCTL_BUSY);
 }
 
-static irqreturn_t avs_skl_dsp_interrupt(struct avs_dev *adev)
+static irqreturn_t avs_skl_dsp_interrupt(struct avs_dev *adev, int irq)
 {
 	u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
 	irqreturn_t ret = IRQ_NONE;
Signature · 1 line
2.34.1
author maintainer
#7 lore raw

PATCH v2 5/7 ASoC: Intel: avs: SoundWire support

In reply to Cezary Rojewski

The SoundWire device is part of the Intel HDAudio PCI device. To support transfer over SoundWire interface it has to be accounted for when probing the parent device.

Most of the actual job is done by the SoundWire library which is already part of the kernel. Utilize it in the core functions of the driver to enumerate SoundWire component and service its interrupts.

---
 sound/soc/intel/Kconfig         |   8 +++
 sound/soc/intel/avs/Makefile    |   4 ++
 sound/soc/intel/avs/avs.h       |   1 +
 sound/soc/intel/avs/cnl.c       |  23 ++++++-
 sound/soc/intel/avs/core.c      |  20 ++++++
 sound/soc/intel/avs/loader.c    |   3 +
 sound/soc/intel/avs/registers.h |   4 ++
 sound/soc/intel/avs/soundwire.c | 117 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/soundwire.h |  56 +++++++++++++++
 9 files changed, 234 insertions(+), 2 deletions(-)
 create mode 100644 sound/soc/intel/avs/soundwire.c
 create mode 100644 sound/soc/intel/avs/soundwire.h
sound/soc/intel/Kconfig +8 -0
index 63367364916a..c765eee25763 100644
@@ -106,12 +106,20 @@ config SND_SOC_INTEL_AVS
 	select SND_HDA_EXT_CORE
 	select SND_HDA_DSP_LOADER
 	select SND_INTEL_DSP_CONFIG
+	select SND_INTEL_SOUNDWIRE_ACPI if SOUNDWIRE_INTEL != n
 	select WANT_DEV_COREDUMP
 	help
 	  Enable support for Intel(R) cAVS 1.5 platforms with DSP
 	  capabilities. This includes Skylake, Kabylake, Amberlake and
 	  Apollolake.
 
+config SND_SOC_INTEL_AVS_SOUNDWIRE
+	tristate
+	default SND_SOC_INTEL_AVS
+	depends on SND_SOC_INTEL_AVS
+	depends on SOUNDWIRE_INTEL
+	depends on !(SOUNDWIRE_INTEL=m && SND_SOC_INTEL_AVS=y)
+
 # Machine board drivers
 source "sound/soc/intel/avs/boards/Kconfig"
 
sound/soc/intel/avs/Makefile +4 -0
index 576dc0da381d..042e8dd232f8 100644
@@ -14,6 +14,10 @@ ifneq ($(CONFIG_DEBUG_FS),)
 snd-soc-avs-y += probes.o debugfs.o
 endif
 
+ifneq ($(CONFIG_SND_SOC_INTEL_AVS_SOUNDWIRE),)
+snd-soc-avs-y += soundwire.o
+endif
+
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
 
 # Machine support
sound/soc/intel/avs/avs.h +1 -0
index b3af2c4126be..40e65639adb2 100644
@@ -136,6 +136,7 @@ struct avs_dev {
 	void __iomem *dsp_ba;
 	const struct avs_spec *spec;
 	struct avs_ipc *ipc;
+	struct sdw_intel_ctx *sdw;
 
 	struct avs_fw_cfg fw_cfg;
 	struct avs_hw_cfg hw_cfg;
sound/soc/intel/avs/cnl.c +21 -2
index 31fd9f251d6c..7090b91572d8 100644
@@ -6,11 +6,16 @@
 //          Amadeusz Slawinski <[email protected]>
 //
 
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_intel.h>
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
 #include "debug.h"
 #include "messages.h"
 #include "registers.h"
+#include "soundwire.h"
 
 static void avs_cnl_ipc_interrupt(struct avs_dev *adev)
 {
@@ -61,16 +66,30 @@ static void avs_cnl_ipc_interrupt(struct avs_dev *adev)
 irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev, int irq)
 {
 	u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
+	u32 adspis2 = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS2);
 	irqreturn_t ret = IRQ_NONE;
 
-	if (adspis == UINT_MAX)
+	if (adspis == UINT_MAX && adspis2 == UINT_MAX)
 		return ret;
 
-	if (adspis & AVS_ADSP_ADSPIS_IPC) {
+	if (adspis != UINT_MAX && (adspis & AVS_ADSP_ADSPIS_IPC)) {
 		avs_cnl_ipc_interrupt(adev);
 		ret = IRQ_HANDLED;
 	}
 
+	if (adev->sdw) {
+		u32 wakests;
+
+		if (adspis2 != UINT_MAX && (adspis2 & AVS_ADSP_ADSPIS2_SNDW))
+			ret = avs_sdw_thread(irq, adev);
+
+		wakests = snd_hdac_adsp_readl(adev, adev->sdw->shim_base + SDW_SHIM_WAKESTS);
+		if (wakests) {
+			avs_sdw_process_wakeen_event(adev);
+			ret = IRQ_HANDLED;
+		}
+	}
+
 	return ret;
 }
 
sound/soc/intel/avs/core.c +20 -0
index 9413027e1e32..3cabe9a2d104 100644
@@ -31,6 +31,7 @@
 #include "debug.h"
 #include "messages.h"
 #include "pcm.h"
+#include "soundwire.h"
 
 static u32 pgctl_mask = AZX_PGCTL_LSRMD_MASK;
 module_param(pgctl_mask, uint, 0444);
@@ -230,6 +231,11 @@ static void avs_hda_probe_work(struct work_struct *work)
 	list_for_each_entry(hlink, &bus->hlink_list, list)
 		snd_hdac_ext_bus_link_put(bus, hlink);
 
+	/* Soundwire component is optional */
+	ret = avs_sdw_probe(adev);
+	if (ret && ret != -ENODEV)
+		dev_err(adev->dev, "failed to probe sdw: %d\n", ret);
+
 	snd_hdac_ext_bus_ppcap_enable(bus, true);
 	snd_hdac_ext_bus_ppcap_int_enable(bus, true);
 	avs_debugfs_init(adev);
@@ -240,6 +246,14 @@ static void avs_hda_probe_work(struct work_struct *work)
 
 	acpi_nhlt_get_gbl_table();
 
+	ret = avs_sdw_startup(adev);
+	if (ret) {
+		dev_err(adev->dev, "failed to startup sdw: %d\n", ret);
+		return;
+	}
+
+	avs_sdw_enable_irq(adev, true);
+
 	avs_register_all_boards(adev);
 
 	/* configure PM */
@@ -561,6 +575,8 @@ static void avs_pci_shutdown(struct pci_dev *pci)
 	snd_hdac_bus_stop_chip(bus);
 	snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
 
+	avs_sdw_enable_irq(adev, false);
+
 	pci_free_irq(pci, 0, adev);
 	pci_free_irq(pci, 0, bus);
 	pci_free_irq_vectors(pci);
@@ -579,6 +595,7 @@ static void avs_pci_remove(struct pci_dev *pci)
 
 	acpi_nhlt_put_gbl_table();
 	avs_debugfs_exit(adev);
+	avs_sdw_exit(adev);
 
 	if (avs_platattr_test(adev, CLDMA))
 		hda_cldma_free(&code_loader);
@@ -661,6 +678,7 @@ static int avs_suspend_common(struct avs_dev *adev, bool low_power)
 	}
 
 	avs_ipc_block(adev->ipc);
+	avs_sdw_enable_irq(adev, false);
 	avs_dsp_op(adev, int_control, false);
 	snd_hdac_ext_bus_ppcap_int_enable(bus, false);
 
@@ -720,6 +738,8 @@ static int avs_resume_common(struct avs_dev *adev, bool low_power, bool purge)
 		return ret;
 	}
 
+	avs_sdw_enable_irq(adev, true);
+
 	return 0;
 }
 
sound/soc/intel/avs/loader.c +3 -0
index bebdc79ec88e..27d09a3bb5ef 100644
@@ -18,6 +18,7 @@
 #include "messages.h"
 #include "registers.h"
 #include "topology.h"
+#include "soundwire.h"
 
 #define AVS_ROM_STS_MASK		0xFF
 #define AVS_ROM_INIT_DONE		0x1
@@ -345,6 +346,8 @@ static int avs_imr_load_basefw(struct avs_dev *adev)
 	if (ret < 0)
 		return ret;
 
+	avs_sdw_process_wakeen_event(adev);
+
 	ret = wait_for_completion_timeout(&adev->fw_ready,
 					  msecs_to_jiffies(AVS_FW_INIT_TIMEOUT_MS));
 	if (!ret) {
sound/soc/intel/avs/registers.h +4 -0
index 97767882ffa1..9e403cfb04fa 100644
@@ -25,11 +25,15 @@
 #define AVS_ADSP_REG_ADSPCS		(AVS_ADSP_GEN_BASE + 0x04)
 #define AVS_ADSP_REG_ADSPIC		(AVS_ADSP_GEN_BASE + 0x08)
 #define AVS_ADSP_REG_ADSPIS		(AVS_ADSP_GEN_BASE + 0x0C)
+#define AVS_ADSP_REG_ADSPIC2		(AVS_ADSP_GEN_BASE + 0x10)
+#define AVS_ADSP_REG_ADSPIS2		(AVS_ADSP_GEN_BASE + 0x14)
 
 #define AVS_ADSP_ADSPIC_IPC		BIT(0)
 #define AVS_ADSP_ADSPIC_CLDMA		BIT(1)
 #define AVS_ADSP_ADSPIS_IPC		BIT(0)
 #define AVS_ADSP_ADSPIS_CLDMA		BIT(1)
+#define AVS_ADSP_ADSPIC2_SNDW		BIT(5)
+#define AVS_ADSP_ADSPIS2_SNDW		BIT(5)
 
 #define AVS_ADSPCS_CRST_MASK(cm)	(cm)
 #define AVS_ADSPCS_CSTALL_MASK(cm)	((cm) << 8)
sound/soc/intel/avs/soundwire.c new file +117 -0

117 lines not on this page · raw message

sound/soc/intel/avs/soundwire.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v2 5/7] ASoC: Intel: avs: SoundWire support

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ASoC: Intel: avs: premature sdw clear, IRQ race, and unmasked IRQ in teardown - [Medium] ASoC…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ASoC: Intel: avs: premature sdw clear, IRQ race, and unmasked IRQ in teardown
- [Medium] ASoC: Intel: avs: 32-bit unaligned read and missing all-ones check on WAKESTS --

commit 8ccf2c90780786f5e6483aeba7422e7c31a54429
Author: Cezary Rojewski <[email protected]>

ASoC: Intel: avs: SoundWire support

This commit adds SoundWire support to the Intel AVS driver by utilizing the existing SoundWire library to probe, start up, tear down, and handle interrupts for the SoundWire component.

Quoted 4 lines
sound/soc/intel/avs/cnl.c +0 -0
index 31fd9f251d6c9..7090b91572d88 100644

[ ... ]

Quoted 19 lines
sound/soc/intel/avs/cnl.c +5 -2
@@ -61,16 +66,30 @@ static void avs_cnl_ipc_interrupt(struct avs_dev *adev)
 irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev, int irq)
 {
 	u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
+	u32 adspis2 = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS2);
 	irqreturn_t ret = IRQ_NONE;
 
-	if (adspis == UINT_MAX)
+	if (adspis == UINT_MAX && adspis2 == UINT_MAX)
 		return ret;
 
-	if (adspis != UINT_MAX && (adspis & AVS_ADSP_ADSPIS_IPC)) {
+	if (adspis != UINT_MAX && (adspis & AVS_ADSP_ADSPIS_IPC)) {
 		avs_cnl_ipc_interrupt(adev);
 		ret = IRQ_HANDLED;
 	}
 
+	if (adev->sdw) {
+		u32 wakests;

sound/soc/intel/avs/cnl.c static void avs_cnl_ipc_interrupt(struct avs_dev *adev) · line 91

Quoted 10 lines
sound/soc/intel/avs/cnl.c +10 -0
+
+		if (adspis2 != UINT_MAX && (adspis2 & AVS_ADSP_ADSPIS2_SNDW))
+			ret = avs_sdw_thread(irq, adev);
+
+		wakests = snd_hdac_adsp_readl(adev, adev->sdw->shim_base + SDW_SHIM_WAKESTS);
+		if (wakests) {
+			avs_sdw_process_wakeen_event(adev);
+			ret = IRQ_HANDLED;
+		}
+	}

[Severity: Medium]
In avs_cnl_dsp_interrupt() in sound/soc/intel/avs/cnl.c, should SDW_SHIM_WAKESTS be read with the 16-bit helper snd_hdac_adsp_readw() and checked against U16_MAX?

In include/linux/soundwire/sdw_intel.h, SDW_SHIM_WAKESTS is defined at 2-byte-aligned offset 0x192 immediately after SDW_SHIM_WAKEEN at 0x190, and drivers/soundwire/intel.c accesses it as a 16-bit register via intel_readw() in intel_shim_check_wake(). Using snd_hdac_adsp_readl() performs an unaligned 32-bit MMIO read across offsets 0x192..0x195.

Additionally, in avs_hda_probe_work() in sound/soc/intel/avs/core.c, avs_sdw_probe() populates adev->sdw before avs_dsp_first_boot_firmware() and avs_sdw_startup() run. When an IPC interrupt fires while the SoundWire SHIM power domain is still unpowered (or powered down at runtime), the MMIO read can return all-ones. Without filtering out U16_MAX (like the UINT_MAX checks on adspis and adspis2 above), could wakests evaluate to non-zero and spuriously trigger avs_sdw_process_wakeen_event()?

Quoted 5 lines
sound/soc/intel/avs/soundwire.c new file +0 -0
new file mode 100644
index 0000000000000..284a00ea794e7

[ ... ]

sound/soc/intel/avs/soundwire.c line 79

Quoted 9 lines
sound/soc/intel/avs/soundwire.c new file +9 -0
+void avs_sdw_exit(struct avs_dev *adev)
+{
+	struct sdw_intel_ctx *ctx = adev->sdw;
+
+	if (ctx) {
+		adev->sdw = NULL;
+		sdw_intel_exit(ctx);
+	}
+}

[Severity: High]
As reported by Sashiko on v1 [1], in avs_sdw_exit() in sound/soc/intel/avs/soundwire.c (called from avs_pci_remove() in sound/soc/intel/avs/core.c), does setting adev->sdw to NULL before calling sdw_intel_exit(ctx) while interrupts are still active cause several issues during driver removal?

1. Inside sdw_intel_exit() in drivers/soundwire/intel_init.c, each link synchronously runtime-resumes its child peripheral devices:

drivers/soundwire/intel_init.c:sdw_intel_exit() {
	list_for_each_entry(link, &ctx->link_list, list) {
		struct sdw_bus *bus = &link->cdns->bus;
		int ret;

		ret = device_for_each_child(bus->dev, NULL, intel_resume_child_device);
		...
	}
}

Because avs_sdw_probe() sets SDW_INTEL_CLK_STOP_BUS_RESET, resuming a suspended link powers it up, enables Cadence MCP interrupts, restarts the SoundWire bus, and performs register transfers waiting on completion. However, since adev->sdw was already cleared to NULL, avs_cnl_dsp_interrupt() skips avs_sdw_thread(), so SoundWire interrupts are never serviced during sdw_intel_exit(), causing child device resume and bus transfers to time out while the unacknowledged level-triggered interrupt remains asserted.

2. Neither avs_pci_remove() nor avs_sdw_exit() calls avs_sdw_enable_irq(adev, false) to clear AVS_ADSP_ADSPIC2_SNDW in AVS_ADSP_REG_ADSPIC2.

3. In avs_pci_remove(), avs_sdw_exit() runs before pci_free_irq() without synchronization against the IRQ thread. In avs_cnl_dsp_interrupt(), adev->sdw is checked at the start of the block and then dereferenced again for adev->sdw->shim_base:

sound/soc/intel/avs/cnl.c:avs_cnl_dsp_interrupt() {
	if (adev->sdw) {
		u32 wakests;

		if (adspis2 != UINT_MAX && (adspis2 & AVS_ADSP_ADSPIS2_SNDW))
			ret = avs_sdw_thread(irq, adev);

		wakests = snd_hdac_adsp_readl(adev, adev->sdw->shim_base + SDW_SHIM_WAKESTS);
		...
	}
}

If avs_sdw_exit() clears adev->sdw and calls sdw_intel_exit(ctx) concurrently, can avs_cnl_dsp_interrupt() hit a NULL pointer dereference on adev->sdw->shim_base or a use-after-free on ctx in sdw_intel_thread() and sdw_intel_process_wakeen_event()?

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
author maintainer
#9 lore raw

PATCH v2 6/7 ASoC: Intel: avs: Expose common PCM functions

In reply to Cezary Rojewski

All the PCM operations are currently bundled together within the pcm.c file regardless of which transfer type they cover. To allow for splitting them, provide a header that exposes the common operations outside.

---
 sound/soc/intel/avs/avs.h |  8 -------
 sound/soc/intel/avs/pcm.c | 42 +++++++++-------------------------
 sound/soc/intel/avs/pcm.h | 47 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 39 deletions(-)
sound/soc/intel/avs/avs.h +0 -8
index 40e65639adb2..1b2f1e7d0556 100644
@@ -347,14 +347,6 @@ struct avs_soc_component {
 
 extern const struct snd_soc_dai_ops avs_dai_fe_ops;
 
-int avs_register_dmic_component(struct avs_dev *adev, const char *name);
-int avs_register_i2s_component(struct avs_dev *adev, const char *name, unsigned long port_mask,
-			       unsigned long *tdms);
-int avs_register_hda_component(struct avs_dev *adev, const char *name);
-int avs_register_component(struct device *dev, const char *name,
-			   struct snd_soc_component_driver *drv,
-			   struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais);
-
 int avs_register_all_boards(struct avs_dev *adev);
 void avs_unregister_all_boards(struct avs_dev *adev);
 
sound/soc/intel/avs/pcm.c +11 -31

84 lines not on this page · raw message

sound/soc/intel/avs/pcm.h +47 -0

55 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#10 lore raw

PATCH v2 7/7 ASoC: Intel: avs: SoundWire PCM BE operations

In reply to Cezary Rojewski

Implement the back-end PCM operations for the SoundWire Link to support data transfer over SoundWire interface. Most of the actual job is done by the SoundWire library, thus code added here just invokes them in correct order.

---
 sound/soc/intel/avs/Makefile    |   2 +-
 sound/soc/intel/avs/messages.h  |   2 +
 sound/soc/intel/avs/path.c      |   2 +
 sound/soc/intel/avs/pcm.h       |   3 +
 sound/soc/intel/avs/pcm_sdw.c   | 289 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/soundwire.h |   7 +
 6 files changed, 304 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/intel/avs/pcm_sdw.c
sound/soc/intel/avs/Makefile +1 -1
index 042e8dd232f8..fab7e1ba622d 100644
@@ -15,7 +15,7 @@ snd-soc-avs-y += probes.o debugfs.o
 endif
 
 ifneq ($(CONFIG_SND_SOC_INTEL_AVS_SOUNDWIRE),)
-snd-soc-avs-y += soundwire.o
+snd-soc-avs-y += soundwire.o pcm_sdw.o
 endif
 
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/messages.h +2 -0
index 55c04b0142ae..d1ffc640dda2 100644
@@ -750,6 +750,8 @@ enum avs_dma_type {
 	AVS_DMA_DMIC_LINK_INPUT = 11,
 	AVS_DMA_I2S_LINK_OUTPUT = 12,
 	AVS_DMA_I2S_LINK_INPUT = 13,
+	AVS_DMA_SDW_LINK_OUTPUT = 16,
+	AVS_DMA_SDW_LINK_INPUT = 17,
 };
 
 union avs_virtual_index {
sound/soc/intel/avs/path.c +2 -0
index a8a2b3484338..60d9245894e7 100644
@@ -260,6 +260,8 @@ static void avs_init_node_id(union avs_connector_node_id *node_id,
 
 	case AVS_DMA_HDA_LINK_OUTPUT:
 	case AVS_DMA_HDA_LINK_INPUT:
+	case AVS_DMA_SDW_LINK_OUTPUT:
+	case AVS_DMA_SDW_LINK_INPUT:
 		node_id->vindex = te->copier.vindex.val | dma_id;
 		break;
 
sound/soc/intel/avs/pcm.h +3 -0
index a5093e62da26..f2620d6f3479 100644
@@ -35,6 +35,9 @@ struct avs_dma_data {
 
 	struct work_struct period_elapsed_work;
 	struct hdac_ext_link *link;
+	struct sdw_stream_runtime *sdw_stream;
+	struct sdw_cdns_pdi *pdi;
+	bool sdw_suspended;
 	struct snd_pcm_substream *substream;
 };
 
sound/soc/intel/avs/pcm_sdw.c new file +289 -0

289 lines not on this page · raw message

sound/soc/intel/avs/soundwire.h +7 -0
index e57e29ed16bf..b2279613a326 100644
@@ -22,6 +22,8 @@ void avs_sdw_enable_irq(struct avs_dev *adev, bool enable);
 void avs_sdw_process_wakeen_event(struct avs_dev *adev);
 irqreturn_t avs_sdw_thread(int irq, struct avs_dev *adev);
 
+int avs_register_sdw_component(struct avs_dev *adev, const char *name, u32 link_id);
+
 #else
 
 static inline int avs_sdw_probe(struct avs_dev *adev)
@@ -51,6 +53,11 @@ static inline irqreturn_t avs_sdw_thread(int irq, struct avs_dev *adev)
 	return IRQ_HANDLED;
 }
 
+static inline int avs_register_sdw_component(struct avs_dev *adev, const char *name, u32 link_id)
+{
+	return 0;
+}
+
 #endif
 
 #endif /* __SOUND_SOC_INTEL_AVS_SOUNDWIRE_H */
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH v2 7/7] ASoC: Intel: avs: SoundWire PCM BE operations

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ASoC: Intel: avs: broken sdw_suspended tracking in pcm_sdw.c - [High] ASoC: Intel: avs: m_rt leak…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ASoC: Intel: avs: broken sdw_suspended tracking in pcm_sdw.c
- [High] ASoC: Intel: avs: m_rt leak and UAF in avs_sdw_dai_hw_params()
--

commit 74a0d17712722615078fab6499f5e8443f22cefa
Author: Cezary Rojewski <[email protected]>

ASoC: Intel: avs: SoundWire PCM BE operations

This commit implements the back-end PCM operations for SoundWire links in the Intel AVS driver to support audio data transfer over the SoundWire interface.

Quoted 5 lines
sound/soc/intel/avs/pcm_sdw.c new file +0 -0
new file mode 100644
index 0000000000000..54caa84fbd75f

[ ... ]

Quoted 47 lines
sound/soc/intel/avs/pcm_sdw.c new file +47 -0
+static void avs_sdw_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct snd_soc_acpi_mach *mach;
+	struct snd_soc_dai *codec_dai;
+	struct avs_dma_data *data;
+	struct sdw_slave *codec;
+
+	codec_dai = snd_soc_rtd_to_codec(rtd, 0);
+	data = snd_soc_dai_get_dma_data(dai, substream);
+	mach = dev_get_platdata(dai->component->card->dev);
+	codec = mach->pdata;
+
+	snd_soc_dai_set_stream(codec_dai, NULL, substream->stream);
+	sdw_cdns_release_pdi(codec->bus, data->pdi);
+	sdw_release_stream(data->sdw_stream);
+	avs_dai_shutdown(substream, dai);
+}
+
+static int avs_sdw_dai_hw_params(struct snd_pcm_substream *substream,
+				 struct snd_pcm_hw_params *hw_params,
+				 struct snd_soc_dai *dai)
+{
+	struct sdw_stream_config sconfig = {0};
+	struct sdw_port_config pconfig = {0};
+	struct snd_soc_acpi_mach *mach;
+	struct avs_dma_data *data;
+	struct sdw_cdns_pdi *pdi;
+	struct sdw_slave *codec;
+	int ret;
+
+	data = snd_soc_dai_get_dma_data(dai, substream);
+	if (data->path)
+		return 0;
+
+	mach = dev_get_platdata(dai->component->card->dev);
+	codec = mach->pdata;
+	pdi = data->pdi;
+	pdi->ch_count = params_channels(hw_params);
+	pdi->h_ch_num = pdi->ch_count - 1;
+	pdi->l_ch_num = 0;
+	sdw_intel_pdi_config(codec->bus, pdi);
+
+	if (data->sdw_suspended)
+		return avs_dai_be_hw_params(substream, hw_params, dai, pdi->intel_alh_id);
+
+	sconfig.direction = pdi->dir;

sound/soc/intel/avs/pcm_sdw.c line 129

Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10 -0
+	sconfig.ch_count = pdi->ch_count;
+	sconfig.frame_rate = params_rate(hw_params);
+	sconfig.type = SDW_STREAM_PCM;
+	sconfig.bps = snd_pcm_format_width(params_format(hw_params));
+	pconfig.num = pdi->num;
+	pconfig.ch_mask = (1 << pdi->ch_count) - 1;
+
+	ret = sdw_stream_add_master(codec->bus, &sconfig, &pconfig, 1, data->sdw_stream);
+	if (ret)
+		return ret;

[Severity: High]
As reported by Sashiko on v1 [1], can a failure in sdw_stream_add_master() here leak the struct sdw_master_runtime (m_rt) and leave a dangling pointer to data->sdw_stream on codec->bus->m_rt_list?

In __soc_pcm_hw_params(), codec DAI hw_params callbacks run before CPU DAI hw_params callbacks:

__soc_pcm_hw_params()
-> snd_soc_dai_hw_params(codec_dai)

       -> sdw_stream_add_slave()
            -> sdw_master_rt_alloc()
  -> snd_soc_dai_hw_params(cpu_dai)
       -> avs_sdw_dai_hw_params()
            -> sdw_stream_add_master()

Because sdw_stream_add_slave() already allocated m_rt and linked it onto data->sdw_stream->master_list and codec->bus->m_rt_list, sdw_stream_add_master() finds the existing m_rt via sdw_master_rt_find() and leaves alloc_master_rt as false.

If sdw_master_port_alloc(), sdw_master_rt_config(), sdw_config_stream(), or sdw_master_port_config() then fails inside sdw_stream_add_master(), m_rt (and any allocated master ports) is not freed by sdw_stream_add_master(), and avs_sdw_dai_hw_params() returns early without calling sdw_stream_remove_master() and with data->path still NULL.

During __soc_pcm_hw_params() error rollback, soc_pcm_hw_clean() calls the codec DAI hw_free callback (which calls sdw_stream_remove_slave(), freeing only s_rt and slave ports), while avs_sdw_dai_hw_free() is either skipped or returns early because data->path is NULL. When avs_sdw_dai_shutdown() later calls sdw_release_stream(data->sdw_stream), data->sdw_stream is freed while m_rt remains on codec->bus->m_rt_list with m_rt->stream pointing to freed memory.

Should avs_sdw_dai_hw_params() call sdw_stream_remove_master() when sdw_stream_add_master() fails, or should sdw_stream_remove_master() be guaranteed on teardown even when data->path is NULL?

Quoted 75 lines
sound/soc/intel/avs/pcm_sdw.c new file +75 -0
+
+	ret = avs_dai_be_hw_params(substream, hw_params, dai, pdi->intel_alh_id);
+	if (ret)
+		sdw_stream_remove_master(codec->bus, data->sdw_stream);
+	return ret;
+}
+
+static int avs_sdw_dai_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
+{
+	struct snd_soc_acpi_mach *mach;
+	struct avs_dma_data *data;
+	struct sdw_slave *codec;
+
+	data = snd_soc_dai_get_dma_data(dai, substream);
+	if (!data->path)
+		return 0;
+
+	mach = dev_get_platdata(dai->component->card->dev);
+	codec = mach->pdata;
+
+	avs_path_reset(data->path);
+	avs_path_free(data->path);
+	data->path = NULL;
+	sdw_deprepare_stream(data->sdw_stream);
+	if (!data->sdw_suspended)
+		sdw_stream_remove_master(codec->bus, data->sdw_stream);
+
+	return 0;
+}
+
+static int avs_sdw_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
+{
+	struct avs_dma_data *data;
+	int ret;
+
+	data = snd_soc_dai_get_dma_data(dai, substream);
+
+	/*
+	 * There is no guarantee trigger(RESUME) fires, so reset the flag here.
+	 * Ensures there is no sdw_master leak should hw_free() occur without resuming.
+	 */
+	data->sdw_suspended = false;
+
+	ret = sdw_prepare_stream(data->sdw_stream);
+	if (ret) {
+		dev_err(dai->dev, "sdw stream prepare failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = avs_dai_prepare(substream, dai);
+	if (ret)
+		sdw_deprepare_stream(data->sdw_stream);
+	return ret;
+}
+
+static int avs_sdw_dai_trigger(struct snd_pcm_substream *substream, int cmd,
+			       struct snd_soc_dai *dai)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct avs_dma_data *data;
+	int ret = 0;
+
+	data = snd_soc_dai_get_dma_data(dai, substream);
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_RESUME:
+		if (rtd->dai_link->ignore_suspend)
+			break;
+		fallthrough;
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		ret = sdw_enable_stream(data->sdw_stream);
+		if (ret)
+			break;
+

sound/soc/intel/avs/pcm_sdw.c line 214

Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10 -0
+		ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
+		if (ret)
+			sdw_disable_stream(data->sdw_stream);
+		break;
+
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		if (rtd->dai_link->ignore_suspend)
+			break;
+		data->sdw_suspended = true;
+		fallthrough;

[Severity: High]
As reported by Sashiko on v1 [2], does tracking suspend state via data->sdw_suspended in avs_sdw_dai_trigger() and clearing it only in avs_sdw_dai_prepare() break suspend/resume for non-running streams and risk a use-after-free if resume hw_params fails?

First, during system suspend, snd_pcm_do_suspend() only triggers SNDRV_PCM_TRIGGER_SUSPEND when snd_pcm_running(substream) is true, and dpcm_be_dai_trigger() only forwards SNDRV_PCM_TRIGGER_SUSPEND when the BE is in SND_SOC_DPCM_STATE_START. If an open, configured stream (data->path != NULL) is in SNDRV_PCM_STATE_PAUSED, SNDRV_PCM_STATE_PREPARED, SNDRV_PCM_STATE_SETUP, or SNDRV_PCM_STATE_XRUN at suspend time, avs_sdw_dai_trigger() is never called and data->sdw_suspended stays false.

When avs_component_suspend() then runs:

avs_component_suspend()
-> avs_component_suspend_hw_free()

       -> avs_dai_suspend_be_hw_free()
            -> avs_sdw_dai_hw_free()
                 -> sdw_stream_remove_master()

Because data->sdw_suspended is false, avs_sdw_dai_hw_free() calls sdw_stream_remove_master(), which invokes sdw_master_rt_free() to free both m_rt and all attached codec slave runtimes (s_rt) and sets data->sdw_stream->state to SDW_STREAM_RELEASED. On resume, avs_component_resume() only invokes CPU DAI callbacks (avs_sdw_dai_hw_params() and avs_sdw_dai_prepare()) without calling the codec DAI hw_params callback. sdw_stream_add_master() allocates a new m_rt with no slave runtime and leaves data->sdw_stream->state as SDW_STREAM_RELEASED, causing sdw_prepare_stream() in avs_sdw_dai_prepare() to fail with -EINVAL and disconnecting the substream.

Second, for a stream that was running at suspend (data->sdw_suspended == true), avs_sdw_dai_hw_free() sets data->path = NULL while keeping m_rt on codec->bus->m_rt_list. On resume, avs_component_resume() runs avs_component_resume_hw_params() for all BE and FE links before calling avs_component_resume_prepare(). If avs_dai_be_hw_params() fails in avs_sdw_dai_hw_params() (leaving data->path NULL) or if FE hw_params fails before avs_sdw_dai_prepare() is reached (leaving data->sdw_suspended true), closing the substream causes avs_sdw_dai_hw_free() to skip sdw_stream_remove_master(), and avs_sdw_dai_shutdown() then frees data->sdw_stream via sdw_release_stream() while m_rt is still linked on codec->bus->m_rt_list.

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#12 lore raw
In reply to Cezary Rojewski
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

author maintainer
#13 lore raw
Quoted 8 lines · Pierre-Louis Bossart
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

Quoted 6 lines

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

Kind disagree on the debugging part. Having SDW streaming follow closely to what is done for HDAudio from the beginning (no hardcodes) makes it easier for a developer to debug stuff. OTOH if one of these two follows a completely different path, the developer has to have such hardcodes in mind when debugging the PCM code or even when looking at the topology.

At the same time, I'm not going anywhere and I do intend to work with Peter and Kai to update the common code. Simply put, such a refactor would be routed through SOF GH first.

Kind regards,
Czarek

#14 lore raw
Quoted 23 lines · Cezary Rojewski
Quoted 8 lines · Pierre-Louis Bossart
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

Quoted 6 lines

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

Kind disagree on the debugging part. Having SDW streaming follow closely to what is done for HDAudio from the beginning (no hardcodes) makes it easier for a developer to debug stuff. OTOH if one of these two follows a completely different path, the developer has to have such hardcodes in mind when debugging the PCM code or even when looking at the topology.

Quoted 3 lines

At the same time, I'm not going anywhere and I do intend to work with Peter and Kai to update the common code. Simply put, such a refactor would be routed through SOF GH first.

The machine driver selects the first available cpu_dai when creating a dailink. It doesn't really add much value to add a second level of freedom to select PDIs, since in practice it'll select the first as well. PDIs have no moral equivalent in HDaudio, it's a Cadence-specific IP.

Also there is already a degree of freedom in the allocation of stream_tag, which is used for DMA support. That one makes sense since DMAs may be used for non-SoundWire things (HDMI, trace, probe, etc).

That's 2 degrees of freedom on 3 levels, do you really need full configurability?

maintainer
#15 lore raw
Quoted 32 lines · Pierre-Louis Bossart
Quoted 23 lines · Cezary Rojewski
Quoted 8 lines · Pierre-Louis Bossart
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

Quoted 6 lines

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

Kind disagree on the debugging part. Having SDW streaming follow closely to what is done for HDAudio from the beginning (no hardcodes) makes it easier for a developer to debug stuff. OTOH if one of these two follows a completely different path, the developer has to have such hardcodes in mind when debugging the PCM code or even when looking at the topology.

Quoted 3 lines

At the same time, I'm not going anywhere and I do intend to work with Peter and Kai to update the common code. Simply put, such a refactor would be routed through SOF GH first.

The machine driver selects the first available cpu_dai when creating a dailink. It doesn't really add much value to add a second level of freedom to select PDIs, since in practice it'll select the first as well. PDIs have no moral equivalent in HDaudio, it's a Cadence-specific IP.

Quoted 6 lines

Also there is already a degree of freedom in the allocation of stream_tag, which is used for DMA support. That one makes sense since DMAs may be used for non-SoundWire things (HDMI, trace, probe, etc).

That's 2 degrees of freedom on 3 levels, do you really need full configurability?

I dont see any gain from this approach. I would reconsider and see if we can reuse things

Signature · 1 line
~Vinod
author maintainer
#16 lore raw
Quoted 33 lines · Vinod Koul
Quoted 32 lines · Pierre-Louis Bossart
Quoted 23 lines · Cezary Rojewski
Quoted 8 lines · Pierre-Louis Bossart
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

Quoted 6 lines

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

Kind disagree on the debugging part. Having SDW streaming follow closely to what is done for HDAudio from the beginning (no hardcodes) makes it easier for a developer to debug stuff. OTOH if one of these two follows a completely different path, the developer has to have such hardcodes in mind when debugging the PCM code or even when looking at the topology.

Quoted 3 lines

At the same time, I'm not going anywhere and I do intend to work with Peter and Kai to update the common code. Simply put, such a refactor would be routed through SOF GH first.

The machine driver selects the first available cpu_dai when creating a dailink. It doesn't really add much value to add a second level of freedom to select PDIs, since in practice it'll select the first as well. PDIs have no moral equivalent in HDaudio, it's a Cadence-specific IP.

Quoted 6 lines
Quoted 6 lines

Also there is already a degree of freedom in the allocation of stream_tag, which is used for DMA support. That one makes sense since DMAs may be used for non-SoundWire things (HDMI, trace, probe, etc).

That's 2 degrees of freedom on 3 levels, do you really need full configurability?

I'm not following this "level of freedom" notion. What's part of this set is a basic allocation - driver (a user of the soundwire-lib) comes and ask for a free resource (PDI). If there is one, it gets assigned. Very standard, how many expect resources are redistributed.

Quoted 3 lines

I dont see any gain from this approach. I would reconsider and see if we can reuse things

I'm not sure which way the last message goes.

However, I find it easier to move from hardcodes to the basic allocation approach (seen here, in this very patchset) than the other way around. The change would consist of updating intel_hw_params() so the PDI allocation is no longer done there.

#17 lore raw
Quoted 38 lines · Cezary Rojewski
Quoted 37 lines · Vinod Koul
Quoted 36 lines · Pierre-Louis Bossart
Quoted 23 lines · Cezary Rojewski
Quoted 8 lines · Pierre-Louis Bossart
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

Quoted 6 lines

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

Kind disagree on the debugging part. Having SDW streaming follow closely to what is done for HDAudio from the beginning (no hardcodes) makes it easier for a developer to debug stuff. OTOH if one of these two follows a completely different path, the developer has to have such hardcodes in mind when debugging the PCM code or even when looking at the topology.

Quoted 3 lines

At the same time, I'm not going anywhere and I do intend to work with Peter and Kai to update the common code. Simply put, such a refactor would be routed through SOF GH first.

The machine driver selects the first available cpu_dai when creating a dailink. It doesn't really add much value to add a second level of freedom to select PDIs, since in practice it'll select the first as well. PDIs have no moral equivalent in HDaudio, it's a Cadence-specific IP.

Also there is already a degree of freedom in the allocation of stream_tag, which is used for DMA support. That one makes sense since DMAs may be used for non-SoundWire things (HDMI, trace, probe, etc).

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

That's 2 degrees of freedom on 3 levels, do you really need full configurability?

I'm not following this "level of freedom" notion. What's part of this set is a basic allocation - driver (a user of the soundwire-lib) comes and ask for a free resource (PDI). If there is one, it gets assigned. Very standard, how many expect resources are redistributed.

You're missing a level. The platform driver exposes a set of DAIs, and then the machine driver will decide which dai it needs for a specific dailink/stream. That's the part that really matters IMHO.

The choice of the PDI is done only internally in the Intel platform driver, and it really doesn't matter how you map cpu_dais to PDIs. A fixed mapping is just as good as a dynamic approach - same results, maybe less elegant but the performance is identical.

Quoted 10 lines
Quoted 3 lines

I dont see any gain from this approach. I would reconsider and see if we can reuse things

I'm not sure which way the last message goes.

However, I find it easier to move from hardcodes to the basic allocation approach (seen here, in this very patchset) than the other way around. The change would consist of updating intel_hw_params() so the PDI allocation is no longer done there.

Change is risky, especially when this touches platforms all the way to CNL across at least 3 generations of Intel hardware since 2018, for no tangible benefit.

author maintainer
#18 lore raw
Quoted 47 lines · Pierre-Louis Bossart
Quoted 38 lines · Cezary Rojewski
Quoted 37 lines · Vinod Koul
Quoted 36 lines · Pierre-Louis Bossart
Quoted 23 lines · Cezary Rojewski
Quoted 8 lines · Pierre-Louis Bossart
Quoted 5 lines

Also, the existing code fetches the PDIs based on pre-defined "dai_id". That's not the case for the avs-driver. It simply asks: "is any PDI free?" and assigns it for the substream if one is found.
No predefining. Again, this aligns with how HDAudio streaming is done.

Yeah but at the end of the day there's a 1:1 mapping between cpu_dai and PDI, no?

Quoted 6 lines

All PDIs are created equal, a dynamic mapping doesn't make things more efficient. It just makes things more complex to debug since you don't have a fixed mapping between dailinks/stream/cpu_dai/PDI.

Put differently, couldn't the AVS driver work around that fixed mapping to avoid changes to legacy platforms that have shipped many moons ago?

Kind disagree on the debugging part. Having SDW streaming follow closely to what is done for HDAudio from the beginning (no hardcodes) makes it easier for a developer to debug stuff. OTOH if one of these two follows a completely different path, the developer has to have such hardcodes in mind when debugging the PCM code or even when looking at the topology.

Quoted 3 lines

At the same time, I'm not going anywhere and I do intend to work with Peter and Kai to update the common code. Simply put, such a refactor would be routed through SOF GH first.

The machine driver selects the first available cpu_dai when creating a dailink. It doesn't really add much value to add a second level of freedom to select PDIs, since in practice it'll select the first as well. PDIs have no moral equivalent in HDaudio, it's a Cadence-specific IP.

Also there is already a degree of freedom in the allocation of stream_tag, which is used for DMA support. That one makes sense since DMAs may be used for non-SoundWire things (HDMI, trace, probe, etc).

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

That's 2 degrees of freedom on 3 levels, do you really need full configurability?

I'm not following this "level of freedom" notion. What's part of this set is a basic allocation - driver (a user of the soundwire-lib) comes and ask for a free resource (PDI). If there is one, it gets assigned. Very standard, how many expect resources are redistributed.

Quoted 8 lines

You're missing a level. The platform driver exposes a set of DAIs, and then the machine driver will decide which dai it needs for a specific dailink/stream. That's the part that really matters IMHO.

The choice of the PDI is done only internally in the Intel platform driver, and it really doesn't matter how you map cpu_dais to PDIs. A fixed mapping is just as good as a dynamic approach - same results, maybe less elegant but the performance is identical.

While I'm still missing why the machine driver layer is mentioned here, I guess we agree on the fact that basic allocation approach is more elegant. Never claimed performance is better.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I dont see any gain from this approach. I would reconsider and see if we can reuse things

I'm not sure which way the last message goes.

Quoted 8 lines
Quoted 4 lines

However, I find it easier to move from hardcodes to the basic allocation approach (seen here, in this very patchset) than the other way around. The change would consist of updating intel_hw_params() so the PDI allocation is no longer done there.

Change is risky, especially when this touches platforms all the way to CNL across at least 3 generations of Intel hardware since 2018, for no tangible benefit.

Well, that's why I don't want to mix the 2 patchsets. However, I'm of those who is not afraid of editing code that touches older platform - my intention wouldn't be to level the code, obviously. From functional perspective it should reach status quo. And both teams have their CIs.

Now, I assume most of the discussion touches on patch 2/7, the one with sdw_cdns_assign_pdi()/release_pdi(). The main suspect:

intel_hw_params(dai)

	alloc_pdi()
	config_pdi()
	params_hook()

is a DAI operation, represents dai->hw_params(). The params hook is there to give SOF some location to send IPC from. If intel_hw_params() is split, there is no need for hooks. Such hooks are certainly not elegant.

I believe the way forward is to convert DAI ops present in intel.c to library-type functions. Let platform components call these. Frankly, except for our friend, intel_hw_params(), one could say they already are
- perhaps the whole intel_pcm_dai_ops could be dropped.

Kind regards,
Czarek

#19 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

However, I find it easier to move from hardcodes to the basic allocation approach (seen here, in this very patchset) than the other way around. The change would consist of updating intel_hw_params() so the PDI allocation is no longer done there.

Quoted 8 lines
Quoted 3 lines

Change is risky, especially when this touches platforms all the way to CNL across at least 3 generations of Intel hardware since 2018, for no tangible benefit.

Well, that's why I don't want to mix the 2 patchsets. However, I'm of those who is not afraid of editing code that touches older platform - my intention wouldn't be to level the code, obviously. From functional perspective it should reach status quo. And both teams have their CIs.

CI resources are limited, lab space and maintenance costs result in older generation moved to 'community support', you'd be lucky if there is one device per generation...

"If it ain't broke don't fix it" applies here.

There are many other topics to work on with the on-going change from HDaudio to SoundWire in the PC space, Linux is way way behind Windows as measured by all the recent bug reports on configurations with new vendors/new chips - not to mention that there are very few reviewers for SoundWire...

Quoted 11 lines

Now, I assume most of the discussion touches on patch 2/7, the one with sdw_cdns_assign_pdi()/release_pdi(). The main suspect:

intel_hw_params(dai)

	alloc_pdi()
	config_pdi()
	params_hook()

is a DAI operation, represents dai->hw_params(). The params hook is there to give SOF some location to send IPC from. If intel_hw_params() is split, there is no need for hooks. Such hooks are certainly not elegant.

The reason for those hooks is not technical, it's due to the split in the code between the Soundwire code in drivers/soundwire and the controller in sound/soc/sof/intel. There's no real other way to send an IPC from the SoundWire side, it is what it is now.

Quoted 4 lines

I believe the way forward is to convert DAI ops present in intel.c to library-type functions. Let platform components call these. Frankly, except for our friend, intel_hw_params(), one could say they already are
- perhaps the whole intel_pcm_dai_ops could be dropped.

No, the intel_pcm_dai_ops was introduced to have intel-bus-common define a generic behavior for a stream and the ops hide hardware-specific implementations between CNL and LNL. This has nothing to do with the PDI really.

There's a second level of indirection to send an IPC with the dai->hw_params, again the implementation is done differently depending on generations. Note that in theory on ACE2.x SoundWire could have been managed without any dependency on the DSP firmware and thus no IPC, unfortunately decisions made by firmware folks result in the need for this IPC. It is also what it is now.

author maintainer
#20 lore raw
Quoted 19 lines · Pierre-Louis Bossart
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

However, I find it easier to move from hardcodes to the basic allocation approach (seen here, in this very patchset) than the other way around. The change would consist of updating intel_hw_params() so the PDI allocation is no longer done there.

Quoted 8 lines
Quoted 3 lines

Change is risky, especially when this touches platforms all the way to CNL across at least 3 generations of Intel hardware since 2018, for no tangible benefit.

Well, that's why I don't want to mix the 2 patchsets. However, I'm of those who is not afraid of editing code that touches older platform - my intention wouldn't be to level the code, obviously. From functional perspective it should reach status quo. And both teams have their CIs.

CI resources are limited, lab space and maintenance costs result in older generation moved to 'community support', you'd be lucky if there is one device per generation...

Quoted 7 lines

"If it ain't broke don't fix it" applies here.

There are many other topics to work on with the on-going change from HDaudio to SoundWire in the PC space, Linux is way way behind Windows as measured by all the recent bug reports on configurations with new vendors/new chips - not to mention that there are very few reviewers for SoundWire...

There is a chance you've just gained one :)

In regard to CI - have to object. Our CI hosts setups from Haswell onwards. And each generation has more than 1 setup available. Perhaps that's not something developers and maintainers are used to, though that doesn't sound good.

Ah, the Windows side topic. Let me add something positive then to the mix. This year decided to finish ~14 year _recommended sequence_ issue from Broadwell era. That _was_ the last thing left on the list for that project. Both SW [1] and FW received fixes.

ADL, CNL or similar sounds like a yesterday when compared to BDW. And Windows is not using DSP on BDW. Which one has more configurations now!

[1]:
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines
Quoted 8 lines

Now, I assume most of the discussion touches on patch 2/7, the one with sdw_cdns_assign_pdi()/release_pdi(). The main suspect:

intel_hw_params(dai)

	alloc_pdi()
	config_pdi()
	params_hook()
Quoted 8 lines
Quoted 3 lines

is a DAI operation, represents dai->hw_params(). The params hook is there to give SOF some location to send IPC from. If intel_hw_params() is split, there is no need for hooks. Such hooks are certainly not elegant.

The reason for those hooks is not technical, it's due to the split in the code between the Soundwire code in drivers/soundwire and the controller in sound/soc/sof/intel. There's no real other way to send an IPC from the SoundWire side, it is what it is now.

There is a way - let platform DSP component (ASoC component) do that instead.

Quoted 10 lines
Quoted 4 lines

I believe the way forward is to convert DAI ops present in intel.c to library-type functions. Let platform components call these. Frankly, except for our friend, intel_hw_params(), one could say they already are
- perhaps the whole intel_pcm_dai_ops could be dropped.

No, the intel_pcm_dai_ops was introduced to have intel-bus-common define a generic behavior for a stream and the ops hide hardware-specific implementations between CNL and LNL. This has nothing to do with the PDI really.

Quoted 6 lines

There's a second level of indirection to send an IPC with the dai->hw_params, again the implementation is done differently depending on generations. Note that in theory on ACE2.x SoundWire could have been managed without any dependency on the DSP firmware and thus no IPC, unfortunately decisions made by firmware folks result in the need for this IPC. It is also what it is now.

These ops pair nicely with SOF. Other soundwire lib users do not use them at all. If the intention is to share, the "library" approach is what's going to make this happen.

Yes, there are differences with ACE2.x, I'm aware of them but all in due time. One step at a time. Library approach makes this much easier though. The DSP component is aware of its own (HW) differences.

Once again, I believe all below sound very reasonable:

	basic allocation in form of assign/release()
	dai->startup() as lone resource-availability check
	dai->hw_params() as lone resource configurator

Hope we can settle on that.