ASoC: Intel: avs: Soundwire support
Subsystems (4)
Cezary Rojewski
maintainerv3 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 v3:
- sdw_intel_pdi_config() now re-used in the existing code
- wakests now read as u16 rather than u32
- dropped superfluous declaration of sdw_intel_init_pdis()
- avs_sdw_dai_hw_params() now calls sdw_stream_remove_master() when sdw_stream_add_master() fails
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 | 64 ++++++ drivers/soundwire/cadence_master.h | 25 +-- drivers/soundwire/intel.c | 49 +++-- drivers/soundwire/intel.h | 9 +- 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 | 23 +- 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 | 291 ++++++++++++++++++++++++++ sound/soc/intel/avs/registers.h | 4 + sound/soc/intel/avs/skl.c | 2 +- sound/soc/intel/avs/soundwire.c | 112 ++++++++++ sound/soc/intel/avs/soundwire.h | 63 ++++++ 27 files changed, 814 insertions(+), 97 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
Cezary Rojewski
maintainerPATCH v3 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
@@ -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
@@ -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
@@ -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
Cezary Rojewski
maintainerPATCH v3 2/7 soundwire: intel: Allow for dynamic assignment of PDIs
In reply to Cezary RojewskiCurrently, 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 | 64 +++++++++++++++++++++++++++ drivers/soundwire/cadence_master.h | 25 ++--------- drivers/soundwire/intel.c | 24 +++++++--- include/linux/soundwire/sdw_cadence.h | 35 +++++++++++++++ include/linux/soundwire/sdw_intel.h | 7 +++ 5 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 include/linux/soundwire/sdw_cadence.h
drivers/soundwire/cadence_master.c +64 -0
@@ -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,68 @@ 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; + } + } + +for (i =0 ; 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
@@ -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 +18 -6
@@ -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,
@@ -745,9 +761,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,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); +sdw_intel_pdi_config (&cdns->bus, dai_runtime->pdi);/* store pdi and hw_params, may be needed in prepare step */ dai_runtime->paused = false;
@@ -823,9 +837,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,else dir =SDW_DATA_DIR_TX ; -intel_pdi_shim_configure (sdw, dai_runtime->pdi); -intel_pdi_alh_configure (sdw, dai_runtime->pdi); -sdw_cdns_config_stream (cdns, ch, dir, dai_runtime->pdi); +sdw_intel_pdi_config (&cdns->bus, dai_runtime->pdi);/* Inform DSP about PDI stream number */ ret = intel_params_stream(sdw, substream, dai,
include/linux/soundwire/sdw_cadence.h new file +35 -0
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v3 2/7] soundwire: intel: Allow for dynamic assignment of PDIs
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] soundwire: intel: NULL deref in intel_hw_params() on dai_runtime->pdi - [High] soundwire: cadence…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] soundwire: intel: NULL deref in intel_hw_params() on dai_runtime->pdi
- [High] soundwire: cadence: sdw_cdns_assign_pdi() assigns Bulk PDIs 0 and 1
- [Medium] soundwire: intel: sdw_intel_pdi_config() adds separate layer over DAI ops
- [Low] soundwire: intel: unused variables ch and dir in intel_prepare() --
commit b476d294896c8b164f217d04d51fe678c5bc644e
Author: Cezary Rojewski <[email protected]>
soundwire: intel: Allow for dynamic assignment of PDIs
This commit adds sdw_cdns_assign_pdi() and sdw_cdns_release_pdi() for dynamic PDI allocation and exports sdw_intel_pdi_config() to configure SHIM, ALH, and stream registers for a PDI.
Quoted 4 lines
drivers/soundwire/cadence_master.c +0
-0
[ ... ]
Quoted 20 lines
drivers/soundwire/cadence_master.c +20
-0+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];
drivers/soundwire/cadence_master.c struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns, · line 2032
Quoted 10 lines
drivers/soundwire/cadence_master.c +10
-0+ goto found; + } + } + +for (i =0 ; i < stream->num_bd; i++) { +if (!stream->bd[i].assigned) { + pdi = &stream->bd[i]; + goto found; + } + }
[Severity: High]
Does searching stream->bd from index 0 hand out PDI 0 and PDI 1 to PCM streams?
In sdw_cdns_pdi_init(), stream->bd is allocated starting at PDI 0, and the first two entries (pdi->num 0 and 1) are reserved for Bulk transfers on DataPort 0. On Intel controllers where all PDIs are bidirectional (num_in == 0 and num_out == 0), the first two sdw_cdns_assign_pdi() calls return PDI 0 and PDI 1. When sdw_intel_pdi_config() then calls sdw_cdns_config_stream(), TX streams on PDI 0 or 1 set CDNS_PORTCTRL_BULK_ENABLE, PDI 1 is mapped onto DataPort 0 alongside PDI 0, and intel_pdi_shim_configure() / intel_pdi_alh_configure() omit the +2 PCM ALH stream offset applied when pdi->num >= 2.
Should the stream->bd loop start at i = 2 to skip the two Bulk PDIs?
[ ... ]
Quoted 13 lines
drivers/soundwire/intel.c +5
-0@@ -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], why add a separate layer exporting sdw_intel_pdi_config() and sdw_cdns_assign_pdi() / sdw_cdns_release_pdi() for driver-specific DAI ops instead of updating the SoundWire Intel DAI driver to handle both startup and hw_params uniformly across Intel drivers?
drivers/soundwire/intel.c static int intel_hw_params(struct snd_pcm_substream *substream, · line 764
Quoted 8 lines
drivers/soundwire/intel.c +1
-3@@ -745,9 +761,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,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); +sdw_intel_pdi_config (&cdns->bus, dai_runtime->pdi);
[Severity: High]
Does passing dai_runtime->pdi here cause a NULL pointer dereference?
dai_runtime->pdi is NULL until "dai_runtime->pdi = pdi;" a few lines below, and sdw_intel_pdi_config() -> intel_pdi_shim_configure() immediately dereferences pdi. Passing pdi (or assigning dai_runtime->pdi before calling sdw_intel_pdi_config()) avoids the crash.
drivers/soundwire/intel.c static int intel_prepare(struct snd_pcm_substream *substream, · line 840
Quoted 8 lines
drivers/soundwire/intel.c +1
-3@@ -823,9 +837,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,else dir =SDW_DATA_DIR_TX ; -intel_pdi_shim_configure (sdw, dai_runtime->pdi); -intel_pdi_alh_configure (sdw, dai_runtime->pdi); -sdw_cdns_config_stream (cdns, ch, dir, dai_runtime->pdi); +sdw_intel_pdi_config (&cdns->bus, dai_runtime->pdi);
[Severity: Low]
After replacing sdw_cdns_config_stream() with sdw_intel_pdi_config(), the local variables ch and dir in intel_prepare() are set but never used, triggering -Wunused-but-set-variable warnings.
[1] https://lore.kernel.org/r/aulzN9MCl5CJB1Al@parshuram
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Cezary Rojewski
maintainerRe: [PATCH v3 2/7] soundwire: intel: Allow for dynamic assignment of PDIs
In reply to Cezary RojewskiQuoted 9 lines · 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().
Quoted 8 lines
As resource availability-check is typically done during
dai->startup()whilst hardware/firmware configuration occurs ondai->hw_params(), addsdw_intel_pdi_config()to maintain this logical split - assign onstart(), configure onhw_params(). Existing code does all of that inintel_hw_params()so the logical split is not possible.Cc Vinod Koul <[email protected]>Signed-off-by Cezary Rojewski <[email protected]>
Scratch that, will send v4 soon. While rebasing messed up this commit.
kernel test robot
build botRe: [PATCH v3 2/7] soundwire: intel: Allow for dynamic assignment of PDIs
In reply to Cezary Rojewskikernel test robot noticed the following build warnings:
Hi Cezary,
kernel test robot noticed the following build warnings:
[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on tiwai-sound/for-next tiwai-sound/for-linus linus/master v7.4-rc1 next-20261105] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Cezary-Rojewski/soundwire-intel-Define-stubs-when-library-is-disabled/20261106-131551 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next patch link: https://lore.kernel.org/r/20261106121557.2338556-3-cezary.rojewski%40intel.com patch subject: [PATCH v3 2/7] soundwire: intel: Allow for dynamic assignment of PDIs config: x86_64-randconfig-1015-20261106 (https://download.01.org/0day-ci/archive/20261107/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261107/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/soundwire/intel.c: In function 'intel_prepare':
>> drivers/soundwire/intel.c:807:17: warning: variable 'dir' set but not used [-Wunused-but-set-variable]
807 | int ch, dir;
| ^~~
>> drivers/soundwire/intel.c:807:13: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
807 | int ch, dir;
| ^~vim +/dir +807 drivers/soundwire/intel.c
c46302ec554c57 Vinod Koul 2018-04-26 800
27b198f409d876 Rander Wang 2020-02-14 801 static int intel_prepare(struct snd_pcm_substream *substream,
27b198f409d876 Rander Wang 2020-02-14 802 struct snd_soc_dai *dai)
27b198f409d876 Rander Wang 2020-02-14 803 {
a5a0239c27fe11 Bard Liao 2020-08-17 804 struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
a5a0239c27fe11 Bard Liao 2020-08-17 805 struct sdw_intel *sdw = cdns_to_intel(cdns);
e0767e39107968 Pierre-Louis Bossart 2022-11-01 806 struct sdw_cdns_dai_runtime *dai_runtime;
a5a0239c27fe11 Bard Liao 2020-08-17 @807 int ch, dir;
244eb888f9ab86 Pierre-Louis Bossart 2020-09-04 808 int ret = 0;
27b198f409d876 Rander Wang 2020-02-14 809
7dddead766c082 Pierre-Louis Bossart 2022-11-01 810 dai_runtime = cdns->dai_runtime_array[dai->id];
e0767e39107968 Pierre-Louis Bossart 2022-11-01 811 if (!dai_runtime) {
e0767e39107968 Pierre-Louis Bossart 2022-11-01 812 dev_err(dai->dev, "failed to get dai runtime in %s\n",
27b198f409d876 Rander Wang 2020-02-14 813 __func__);
27b198f409d876 Rander Wang 2020-02-14 814 return -EIO;
27b198f409d876 Rander Wang 2020-02-14 815 }
27b198f409d876 Rander Wang 2020-02-14 816
e0767e39107968 Pierre-Louis Bossart 2022-11-01 817 if (dai_runtime->suspended) {
50cd92e0c8d35d Kuninori Morimoto 2023-09-11 818 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
0a0d1740bd8fd7 Pierre-Louis Bossart 2023-03-21 819 struct snd_pcm_hw_params *hw_params;
0a0d1740bd8fd7 Pierre-Louis Bossart 2023-03-21 820
0a0d1740bd8fd7 Pierre-Louis Bossart 2023-03-21 821 hw_params = &rtd->dpcm[substream->stream].hw_params;
0a0d1740bd8fd7 Pierre-Louis Bossart 2023-03-21 822
e0767e39107968 Pierre-Louis Bossart 2022-11-01 823 dai_runtime->suspended = false;
a5a0239c27fe11 Bard Liao 2020-08-17 824
a5a0239c27fe11 Bard Liao 2020-08-17 825 /*
a5a0239c27fe11 Bard Liao 2020-08-17 826 * .prepare() is called after system resume, where we
a5a0239c27fe11 Bard Liao 2020-08-17 827 * need to reinitialize the SHIM/ALH/Cadence IP.
a5a0239c27fe11 Bard Liao 2020-08-17 828 * .prepare() is also called to deal with underflows,
a5a0239c27fe11 Bard Liao 2020-08-17 829 * but in those cases we cannot touch ALH/SHIM
a5a0239c27fe11 Bard Liao 2020-08-17 830 * registers
a5a0239c27fe11 Bard Liao 2020-08-17 831 */
a5a0239c27fe11 Bard Liao 2020-08-17 832
a5a0239c27fe11 Bard Liao 2020-08-17 833 /* configure stream */
0a0d1740bd8fd7 Pierre-Louis Bossart 2023-03-21 834 ch = params_channels(hw_params);
a5a0239c27fe11 Bard Liao 2020-08-17 835 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
a5a0239c27fe11 Bard Liao 2020-08-17 836 dir = SDW_DATA_DIR_RX;
a5a0239c27fe11 Bard Liao 2020-08-17 837 else
a5a0239c27fe11 Bard Liao 2020-08-17 838 dir = SDW_DATA_DIR_TX;
a5a0239c27fe11 Bard Liao 2020-08-17 839
5977f02f8733d2 Cezary Rojewski 2026-11-06 840 sdw_intel_pdi_config(&cdns->bus, dai_runtime->pdi);
a5a0239c27fe11 Bard Liao 2020-08-17 841
a5a0239c27fe11 Bard Liao 2020-08-17 842 /* Inform DSP about PDI stream number */
1d905d355ef329 Pierre-Louis Bossart 2023-05-15 843 ret = intel_params_stream(sdw, substream, dai,
0a0d1740bd8fd7 Pierre-Louis Bossart 2023-03-21 844 hw_params,
a5a0239c27fe11 Bard Liao 2020-08-17 845 sdw->instance,
e0767e39107968 Pierre-Louis Bossart 2022-11-01 846 dai_runtime->pdi->intel_alh_id);
a5a0239c27fe11 Bard Liao 2020-08-17 847 }
a5a0239c27fe11 Bard Liao 2020-08-17 848
a5a0239c27fe11 Bard Liao 2020-08-17 849 return ret;
27b198f409d876 Rander Wang 2020-02-14 850 }
27b198f409d876 Rander Wang 2020-02-14 851 --
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Cezary Rojewski
maintainerPATCH v3 3/7 soundwire: intel: Split PDIs and DAIs initialization
In reply to Cezary RojewskiNot 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 | 9 ++++++++- drivers/soundwire/intel_ace2x.c | 25 ++++++++++++++++--------- drivers/soundwire/intel_auxdevice.c | 4 ++++ include/linux/soundwire/sdw_intel.h | 4 +++- 5 files changed, 47 insertions(+), 20 deletions(-)
drivers/soundwire/intel.c +16 -9
@@ -1023,23 +1023,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;
@@ -1083,6 +1089,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 +8 -1
@@ -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_ace2x.c +16 -9
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v3 3/7] soundwire: intel: Split PDIs and DAIs initialization
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] soundwire: intel: bypassing intel_register_dai() against maintainer direction --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: intel: bypassing intel_register_dai() against maintainer direction
--
commit fd70be11c65e2cabc3b8e75299a0c79a70299383
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 and makes the register_dai() callback optional during link startup.
Quoted 12 lines
drivers/soundwire/intel.h +4
-0@@ -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);
drivers/soundwire/intel.h static inline void sdw_intel_debugfs_exit(struct sdw_intel *sdw) · line 169
Quoted 10 lines
drivers/soundwire/intel.h +4
-1+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 ; }
[Severity: Medium]
As reported by Pierre-Louis Bossart on v2 [1], can the AVS driver reuse the existing SoundWire Intel DAI registration and intel_pcm_dai_ops rather than making register_dai() optional to bypass them?
Splitting intel_init_pdis() from intel_register_dai() and returning 0 when register_dai is NULL is only used so commit "ASoC: Intel: avs: SoundWire support" and commit "ASoC: Intel: avs: SoundWire PCM BE operations" can clear register_dai and implement a separate DAI registration and dynamic PDI assignment path, duplicating the existing SoundWire Intel DAI infrastructure.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Cezary Rojewski
maintainerPATCH v3 4/7 ASoC: Intel: avs: Pass irq to dsp_interrupt callback
In reply to Cezary RojewskiSoundwire 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Cezary Rojewski
maintainerPATCH v3 5/7 ASoC: Intel: avs: SoundWire support
In reply to Cezary RojewskiThe 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 | 21 ++++++ sound/soc/intel/avs/loader.c | 3 + sound/soc/intel/avs/registers.h | 4 ++ sound/soc/intel/avs/soundwire.c | 112 ++++++++++++++++++++++++++++++++ sound/soc/intel/avs/soundwire.h | 56 ++++++++++++++++ 9 files changed, 230 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
@@ -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
@@ -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
@@ -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
@@ -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) { +u16 wakests; + +if (adspis2 !=UINT_MAX && (adspis2 &AVS_ADSP_ADSPIS2_SNDW )) + ret =avs_sdw_thread (irq, adev); + + wakests =snd_hdac_adsp_readw (adev, adev->sdw->shim_base +SDW_SHIM_WAKESTS ); +if (wakests && wakests !=U16_MAX ) { +avs_sdw_process_wakeen_event (adev); + ret =IRQ_HANDLED ; + } + } +return ret; }
sound/soc/intel/avs/core.c +21 -0
@@ -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,11 +595,13 @@ 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);snd_hdac_stop_streams_and_chip (bus); +avs_sdw_enable_irq (adev, false);avs_dsp_op (adev, int_control, false);snd_hdac_ext_bus_ppcap_int_enable (bus, false);
@@ -661,6 +679,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 +739,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
@@ -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
@@ -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 +112 -0
112 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
[email protected]
AI reviewRe: [PATCH v3 5/7] ASoC: Intel: avs: SoundWire support
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] ASoC: Intel: avs: use-after-free of adev->sdw in avs_pci_remove() - [Medium] ASoC: Intel: avs…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] ASoC: Intel: avs: use-after-free of adev->sdw in avs_pci_remove()
- [Medium] ASoC: Intel: avs: uncleaned SoundWire links on avs_hda_probe_work() failure
--
commit 838bee43a4741d68e2f300d57b530a29e67bb205
Author: Cezary Rojewski <[email protected]>
ASoC: Intel: avs: SoundWire support
This commit adds SoundWire component enumeration, startup, teardown, and interrupt handling to the Intel AVS driver.
Quoted 17 lines
sound/soc/intel/avs/core.c +5
-0@@ -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);
sound/soc/intel/avs/core.c static void avs_hda_probe_work(struct work_struct *work) · line 253
Quoted 8 lines
sound/soc/intel/avs/core.c +5
-0@@ -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 ; + }
[Severity: Medium]
Does returning early when avs_dsp_first_boot_firmware() or avs_sdw_startup() fails leave the SoundWire auxiliary link devices registered while the DSP and links are powered down?
avs_sdw_probe() registers the soundwire_intel.link.* auxiliary devices and sets adev->sdw before firmware boot. If avs_dsp_first_boot_firmware() or avs_sdw_startup() fails, the links are never powered up via sdw_intel_startup() and runtime PM is not enabled. A later avs_pci_remove() then runs avs_sdw_exit() -> sdw_intel_exit() -> intel_link_remove(), which calls sdw_cdns_enable_interrupt(cdns, false) and writes to unpowered link MMIO registers.
[ ... ]
sound/soc/intel/avs/core.c static void avs_pci_remove(struct pci_dev *pci) · line 606
Quoted 13 lines
sound/soc/intel/avs/core.c +2
-0@@ -579,11 +595,13 @@ 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);snd_hdac_stop_streams_and_chip (bus); +avs_sdw_enable_irq (adev, false);avs_dsp_op (adev, int_control, false);snd_hdac_ext_bus_ppcap_int_enable (bus, false);
[Severity: High]
Can avs_cnl_dsp_interrupt() dereference adev->sdw after avs_sdw_exit() frees it?
avs_sdw_exit() calls sdw_intel_exit(adev->sdw), which frees the sdw_intel_ctx and its link structures, without clearing adev->sdw and before SoundWire and DSP interrupts are disabled or freed via pci_free_irq():
CPU0 CPU1avs_pci_remove()
avs_sdw_exit(adev)
sdw_intel_exit(adev->sdw)
...
kfree(ctx)
avs_dsp_irq_thread()
avs_cnl_dsp_interrupt()
if (adev->sdw)
avs_sdw_thread(irq, adev)
sdw_intel_thread(irq, adev->sdw)
<-- use-after-freeDisabling SoundWire and DSP interrupts (and synchronizing the IRQ or moving avs_sdw_exit() after pci_free_irq()) before tearing down adev->sdw, and clearing adev->sdw in avs_sdw_exit(), would avoid this.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Cezary Rojewski
maintainerPATCH v3 6/7 ASoC: Intel: avs: Expose common PCM functions
In reply to Cezary RojewskiAll 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
@@ -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
Cezary Rojewski
maintainerPATCH v3 7/7 ASoC: Intel: avs: SoundWire PCM BE operations
In reply to Cezary RojewskiImplement 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 | 291 ++++++++++++++++++++++++++++++++ sound/soc/intel/avs/soundwire.h | 7 + 6 files changed, 306 insertions(+), 1 deletion(-) create mode 100644 sound/soc/intel/avs/pcm_sdw.c
sound/soc/intel/avs/Makefile +1 -1
@@ -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
@@ -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
@@ -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
@@ -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 +291 -0
291 lines not on this page · raw message
sound/soc/intel/avs/soundwire.h +7 -0
@@ -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
[email protected]
AI reviewRe: [PATCH v3 7/7] ASoC: Intel: avs: SoundWire PCM BE operations
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] ASoC: Intel: avs: broken sdw_suspended state and m_rt lifecycle in pcm_sdw.c - [High] ASoC: Intel…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] ASoC: Intel: avs: broken sdw_suspended state and m_rt lifecycle in pcm_sdw.c
- [High] ASoC: Intel: avs: stream left in SDW_STREAM_DEPREPARED on resume in pcm_sdw.c
- [High] ASoC: Intel: avs: bulk PDIs 0 and 1 assigned to PCM streams in avs_sdw_dai_startup()
--
commit 18beef33b6f436db2bab29aa861b96311ce4d2f9
Author: Cezary Rojewski <[email protected]>
ASoC: Intel: avs: SoundWire PCM BE operations
This commit adds back-end DAI operations and component registration for SoundWire PCM streams in the Intel AVS driver.
Quoted 6 lines
sound/soc/intel/avs/pcm_sdw.c new file +0
-0@@ -0,0 +1,291 @@
[ ... ]
Quoted 23 lines
sound/soc/intel/avs/pcm_sdw.c new file +23
-0+static int avs_sdw_dai_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct sdw_stream_runtime *sdw_stream; +struct snd_soc_acpi_mach *mach; +struct snd_soc_dai *codec_dai; +struct avs_dma_data *data; +struct sdw_cdns_pdi *pdi; +struct sdw_slave *codec; +int dir, ret; + + mach =dev_get_platdata (dai->component->card->dev); + codec = mach->pdata; +if (substream->stream ==SNDRV_PCM_STREAM_CAPTURE ) + dir =SDW_DATA_DIR_RX ; +else + dir =SDW_DATA_DIR_TX ; + + ret =avs_dai_startup (substream, dai); +if (ret) +return ret; + + sdw_stream =sdw_alloc_stream (substream->name,SDW_STREAM_PCM );
sound/soc/intel/avs/pcm_sdw.c line 55
Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+if (!sdw_stream) { + ret = -ENOMEM ; + goto err_alloc_stream; + } + + pdi =sdw_cdns_assign_pdi (codec->bus, dir); +if (!pdi) { + ret = -EBUSY ; + goto err_assign_pdi; + }
[Severity: High]
Does sdw_cdns_assign_pdi() assign bulk PDIs 0 and 1 to the first two PCM substreams on a link?
On Intel cAVS SoundWire controllers, SDW_SHIM_PCMSCAP reports bidirectional streams in pcm_bd with pcm_in and pcm_out set to 0, where PDI 0 and PDI 1 are reserved for 1-channel bulk transfers and PCM PDIs start at index 2. Because sdw_cdns_assign_pdi() searches stream->bd starting from index 0, passing the resulting pdi to sdw_intel_pdi_config() and sdw_stream_add_master() in avs_sdw_dai_hw_params() enables CDNS_PORTCTRL_BULK_ENABLE on TX, maps PDI 1 to DataPort 0 in CDNS_PDI_CONFIG(1) while configuring DataPort 1 in pconfig.num, and computes bulk ALH stream IDs instead of PCM ALH stream IDs.
Quoted 94 lines
sound/soc/intel/avs/pcm_sdw.c new file +94
-0+/* Fulfill the codec needs by setting the sdw_stream. */ + codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +snd_soc_dai_set_stream (codec_dai, sdw_stream, substream->stream); + + data =snd_soc_dai_get_dma_data (dai, substream); + data->sdw_stream = sdw_stream; + data->pdi = pdi; +return 0 ; + +err_assign_pdi: +sdw_release_stream (sdw_stream); +err_alloc_stream: +avs_dai_shutdown (substream, dai); +return ret; +} + +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; + 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) { +sdw_stream_remove_master (codec->bus, data->sdw_stream); +return ret; + } + + 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;
sound/soc/intel/avs/pcm_sdw.c line 160
Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ +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 ; +}
[Severity: High]
When a suspended stream resumes, does leaving data->sdw_stream in SDW_STREAM_DEPREPARED cause sdw_prepare_stream() to skip computing its port and transport parameters?
During suspend, avs_sdw_dai_hw_free() calls sdw_deprepare_stream(), which sets data->sdw_stream->state to SDW_STREAM_DEPREPARED and subtracts the stream bandwidth from bus->params.bandwidth. On resume, avs_sdw_dai_hw_params() returns early when data->sdw_suspended is set without restoring the state to SDW_STREAM_CONFIGURED, so sdw_prepare_stream() runs with update_params set to true while sdw_compute_port_params() ignores streams in SDW_STREAM_DEPREPARED:
drivers/soundwire/generic_bandwidth_allocation.c:sdw_compute_group_params() {
...
if (m_rt->stream == stream) {
/* Only runtime during prepare should be added */
if (stream->state != SDW_STREAM_CONFIGURED)
continue;
} else {
/* Include streams withPrepared or Enabled seamlessly */
if (m_rt->stream->state != SDW_STREAM_PREPARED &&
m_rt->stream->state != SDW_STREAM_ENABLED)
continue;
}
...
}Quoted 46 lines
sound/soc/intel/avs/pcm_sdw.c new file +46
-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 216
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]
Can tracking suspend via data->sdw_suspended in avs_sdw_dai_trigger() break resume for non-running streams and leave a freed data->sdw_stream linked on codec->bus->m_rt_list if resume fails?
snd_pcm_do_suspend() only issues SNDRV_PCM_TRIGGER_SUSPEND when the substream is running, so a configured substream in PAUSED, PREPARED, SETUP, or XRUN state enters avs_component_suspend() with data->sdw_suspended still false. avs_sdw_dai_hw_free() then calls sdw_stream_remove_master(), which frees the master and codec slave runtimes and sets data->sdw_stream->state to SDW_STREAM_RELEASED, but avs_component_resume() only re-runs CPU DAI hw_params and never calls the codec DAI's hw_params (sdw_stream_add_slave()), causing sdw_prepare_stream() in avs_sdw_dai_prepare() to fail with -EINVAL and disconnect the substream.
Conversely, when a running stream suspends (setting data->sdw_suspended = true) and avs_component_resume_hw_params() fails before avs_sdw_dai_prepare() clears data->sdw_suspended, closing the substream skips sdw_stream_remove_master() in avs_sdw_dai_hw_free() (because !data->path or data->sdw_suspended is true) and frees data->sdw_stream in avs_sdw_dai_shutdown(), leaving m_rt on codec->bus->m_rt_list with a dangling m_rt->stream pointer (use-after-free on subsequent SoundWire bus operations). The same dangling m_rt occurs if codec DAI hw_params fails after sdw_stream_add_slave() allocates m_rt on codec->bus before avs_sdw_dai_hw_params() sets data->path.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Pierre-Louis Bossart
reviewerRe: [PATCH v3 7/7] ASoC: Intel: avs: SoundWire PCM BE operations
In reply to Cezary RojewskiI am afraid this patch needs to be completely re-visited. You mixed dai and dailink layers, and that explains most of the misunderstandings in the review of the PDI stuff where I mentioned that what matters is how the dailink is created.
Quoted 17 lines
sound/soc/intel/avs/pcm_sdw.c new file +17
-0+static int avs_sdw_dai_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct sdw_stream_runtime *sdw_stream; +struct snd_soc_acpi_mach *mach; +struct snd_soc_dai *codec_dai; +struct avs_dma_data *data; +struct sdw_cdns_pdi *pdi; +struct sdw_slave *codec; +int dir, ret; + + mach =dev_get_platdata (dai->component->card->dev); + codec = mach->pdata; +if (substream->stream ==SNDRV_PCM_STREAM_CAPTURE ) + dir =SDW_DATA_DIR_RX ; +else + dir =SDW_DATA_DIR_TX ;
sound/soc/intel/avs/pcm_sdw.c line 49
Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ + ret =avs_dai_startup (substream, dai); +if (ret) +return ret; + + sdw_stream =sdw_alloc_stream (substream->name,SDW_STREAM_PCM ); +if (!sdw_stream) { + ret = -ENOMEM ; + goto err_alloc_stream; + }
This isn't quite the intented use of the SoundWire stream API, which provides a sdw_startup_stream() that's supposed to be invoked during the dailink creation in the machine driver that binds cpu and codec dais
"
sdw_alloc_stream should be called only once per stream. Typically invoked from ALSA/ASoC machine/platform driver.
"
The dailink maps exactly 1:1 to the SoundWire stream concept, and that's what allows us to deal with aggregation - when multiple cpu_dais on multiple links are connected to multiple amps. That's the #1 reason why SoundWire exists and the #1 difference to other audio interfaces.
BPT/BRA support is the only case where sdw_alloc_stream() is used in the Intel platform driver, since there's clearly no concept of cpu_ or codec DAI.
sound/soc/intel/avs/pcm_sdw.c line 59
Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ + pdi =sdw_cdns_assign_pdi (codec->bus, dir); +if (!pdi) { + ret = -EBUSY ; + goto err_assign_pdi; + } + +/* Fulfill the codec needs by setting the sdw_stream. */ + codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +snd_soc_dai_set_stream (codec_dai, sdw_stream, substream->stream);
That absolutely does not scale to the case where you have multiple cpu_dais and multiple codec_dais.
Please take a look at the sof_sdw machine driver (same solution used by AMD), and please use the sdw_utils library to deal with all the stream management.
Quoted 11 lines
sound/soc/intel/avs/pcm_sdw.c new file +11
-0+ data =snd_soc_dai_get_dma_data (dai, substream); + data->sdw_stream = sdw_stream; + data->pdi = pdi; +return 0 ; + +err_assign_pdi: +sdw_release_stream (sdw_stream); +err_alloc_stream: +avs_dai_shutdown (substream, dai); +return ret; +}
Cezary Rojewski
maintainerRe: [PATCH v3 7/7] ASoC: Intel: avs: SoundWire PCM BE operations
Quoted 42 lines · Pierre-Louis Bossart
I am afraid this patch needs to be completely re-visited. You mixed dai and dailink layers, and that explains most of the misunderstandings in the review of the PDI stuff where I mentioned that what matters is how the dailink is created.
Quoted 17 lines
sound/soc/intel/avs/pcm_sdw.c new file +17
-0+static int avs_sdw_dai_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct sdw_stream_runtime *sdw_stream; +struct snd_soc_acpi_mach *mach; +struct snd_soc_dai *codec_dai; +struct avs_dma_data *data; +struct sdw_cdns_pdi *pdi; +struct sdw_slave *codec; +int dir, ret; + + mach =dev_get_platdata (dai->component->card->dev); + codec = mach->pdata; +if (substream->stream ==SNDRV_PCM_STREAM_CAPTURE ) + dir =SDW_DATA_DIR_RX ; +else + dir =SDW_DATA_DIR_TX ;sound/soc/intel/avs/pcm_sdw.c line 49
Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ + ret =avs_dai_startup (substream, dai); +if (ret) +return ret; + + sdw_stream =sdw_alloc_stream (substream->name,SDW_STREAM_PCM ); +if (!sdw_stream) { + ret = -ENOMEM ; + goto err_alloc_stream; + }This isn't quite the intented use of the SoundWire stream API, which provides a
sdw_startup_stream()that's supposed to be invoked during the dailink creation in the machine driver that binds cpu and codec dais"
sdw_alloc_streamshould be called only once per stream. Typically invoked from ALSA/ASoC machine/platform driver.
"
Quoted 4 lines
The dailink maps exactly 1:1 to the SoundWire stream concept, and that's what allows us to deal with aggregation - when multiple
cpu_daison multiple links are connected to multiple amps. That's the #1 reason why SoundWire exists and the #1 difference to other audio interfaces.
dai_link->startup() occurs at pcm->open(), directly before dai->startup(). The binding process relates to card-binding and FrontEnd exposition, at least that's my understanding of the subject.
Now, thank you for mentioning the intention. Did not understand the point before that. However, given the above, plus the fact dai->shutdown() frees the stream object, I see no difference from functional perspective - allocate a stream object once per runtime, free it when runtime is about to be destroyed. The exact same thing happens here. For avs-driver, the machine boards are minimal. Dai-link operations tend to be used to patch up stuff between codec <> platform expectations. The intention is to make populating the configurations easier _and_ have one location for the PCM operations - everything happens in pcm.c file -or- in case of SDW, pcm_sdw.c
Quoted 3 lines
BPT/BRA support is the only case where
sdw_alloc_stream()is used in the Intel platform driver, since there's clearly no concept ofcpu_or codec DAI.
No intention to support that (BRA) for automotive right now.
Quoted 14 lines
sound/soc/intel/avs/pcm_sdw.c line 59
Quoted 10 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ + pdi =sdw_cdns_assign_pdi (codec->bus, dir); +if (!pdi) { + ret = -EBUSY ; + goto err_assign_pdi; + } + +/* Fulfill the codec needs by setting the sdw_stream. */ + codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +snd_soc_dai_set_stream (codec_dai, sdw_stream, substream->stream);That absolutely does not scale to the case where you have multiple
cpu_daisand multiplecodec_dais.
Quoted 3 lines
Please take a look at the
sof_sdwmachine driver (same solution used by AMD), and please use thesdw_utilslibrary to deal with all the stream management.
I believe you are talking about aggregation. No intention to support that with this code.
After reading the read I have an impression that the expectation of this patchset is: full brown SoundWire support. I wish I could agree with you. The reality is: standard PCM over codecs with and without SDCA. If I get a user and an external release on top of that, I'll come back and revisit. The code present here provides simple implementation of the goal, basically mirroring what's done for HDA in pcm.c nicely making it easy to follow.
Quoted 12 lines
Quoted 11 lines
sound/soc/intel/avs/pcm_sdw.c new file +11
-0+ data =snd_soc_dai_get_dma_data (dai, substream); + data->sdw_stream = sdw_stream; + data->pdi = pdi; +return 0 ; + +err_assign_pdi: +sdw_release_stream (sdw_stream); +err_alloc_stream: +avs_dai_shutdown (substream, dai); +return ret; +}
Pierre-Louis Bossart
reviewerRe: [PATCH v3 7/7] ASoC: Intel: avs: SoundWire PCM BE operations
Quoted 23 lines
Quoted 15 lines
sound/soc/intel/avs/pcm_sdw.c line 59
Quoted 11 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ + pdi =sdw_cdns_assign_pdi (codec->bus, dir); +if (!pdi) { + ret = -EBUSY ; + goto err_assign_pdi; + } + +/* Fulfill the codec needs by setting the sdw_stream. */ + codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +snd_soc_dai_set_stream (codec_dai, sdw_stream, substream->stream);That absolutely does not scale to the case where you have multiple
cpu_daisand multiplecodec_dais.Quoted 3 lines
Please take a look at the
sof_sdwmachine driver (same solution used by AMD), and please use thesdw_utilslibrary to deal with all the stream management.I believe you are talking about aggregation. No intention to support that with this code.
Quoted 7 lines
After reading the read I have an impression that the expectation of this patchset is: full brown SoundWire support. I wish I could agree with you. The reality is: standard PCM over codecs with and without SDCA. If I get a user and an external release on top of that, I'll come back and revisit. The code present here provides simple implementation of the goal, basically mirroring what's done for HDA in
pcm.cnicely making it easy to follow.
well, I find it interesting that you are suggesting changes that impact existing to SoundWire *products* for what appears to be an experimental setup that will have to be changed *again* if and when there's a user.
It's ok to push background changes ahead of time to prepare the future. I am not sure what to think of your approach.
a) Mirroring HDaudio is not the goal, if that comes with a substandard way of using the SoundWire subsystem and capabilities does all this belong in the mainline? My take is that support for two amps is a standard feature, be they on the same link or not.
b) At the very least you should have disclosed your goals, limitations of your approach, and be mindful of reviewer time.
Cezary Rojewski
maintainerRe: [PATCH v3 7/7] ASoC: Intel: avs: SoundWire PCM BE operations
Quoted 30 lines · Pierre-Louis Bossart
Quoted 23 lines
Quoted 15 lines
sound/soc/intel/avs/pcm_sdw.c line 59
Quoted 11 lines
sound/soc/intel/avs/pcm_sdw.c new file +10
-0+ + pdi =sdw_cdns_assign_pdi (codec->bus, dir); +if (!pdi) { + ret = -EBUSY ; + goto err_assign_pdi; + } + +/* Fulfill the codec needs by setting the sdw_stream. */ + codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +snd_soc_dai_set_stream (codec_dai, sdw_stream, substream->stream);That absolutely does not scale to the case where you have multiple
cpu_daisand multiplecodec_dais.Quoted 3 lines
Please take a look at the
sof_sdwmachine driver (same solution used by AMD), and please use thesdw_utilslibrary to deal with all the stream management.I believe you are talking about aggregation. No intention to support that with this code.
Quoted 7 lines
After reading the read I have an impression that the expectation of this patchset is: full brown SoundWire support. I wish I could agree with you. The reality is: standard PCM over codecs with and without SDCA. If I get a user and an external release on top of that, I'll come back and revisit. The code present here provides simple implementation of the goal, basically mirroring what's done for HDA in
pcm.cnicely making it easy to follow.
Quoted 3 lines
well, I find it interesting that you are suggesting changes that impact existing to SoundWire *products* for what appears to be an experimental setup that will have to be changed *again* if and when there's a user.
The configurations are not experimental. The base of this code exists since 2021, shipping to upstream only now as the releases are external only this year. Is there a possibility for more configurations in the future? I guess the answer is yes. Though I believe it's OK to change stuff when the expectations/requirements change.
Quoted 9 lines
It's ok to push background changes ahead of time to prepare the future. I am not sure what to think of your approach.
a) Mirroring HDaudio is not the goal, if that comes with a substandard way of using the SoundWire subsystem and capabilities does all this belong in the mainline? My take is that support for two amps is a standard feature, be they on the same link or not.
b) At the very least you should have disclosed your goals, limitations of your approach, and be mindful of reviewer time.
You're correct, I should have listed the avs-pcm goals along the reasoning behind the soundwire changes. In regard to a), instead of sending v4 today I'll try to integrate amp/aggregation and see the scale of changes. If it's wide-beyond the scope of this patchset, I'll opt out. If the changes are manageable, I'll update the series.
There is a benefit already of this iterative review - the first patch is gone, the rest of them are not users of it and the code compiles just fine without it - avs-driver brings in its own set of stubs in 5/7.
Thank you, Pierre!