Linux Sound subsystem development
 help / color / mirror / Atom feed
* Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
  2025-01-09 12:52 ` [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers Cezary Rojewski
@ 2025-01-09 12:42   ` Jaroslav Kysela
  2025-01-09 14:20     ` Takashi Iwai
  0 siblings, 1 reply; 12+ messages in thread
From: Jaroslav Kysela @ 2025-01-09 12:42 UTC (permalink / raw)
  To: Cezary Rojewski, tiwai; +Cc: linux-sound, broonie, amadeuszx.slawinski

On 09. 01. 25 13:52, Cezary Rojewski wrote:
> The snd_hdac_adsp_xxx() wrap snd_hdac_reg_xxx() helpers to simplify
> register access for AudioDSP drivers e.g.: the avs-driver. Byte- and
> word-variants of said helps do not expand to bare readx/writex()
> operations but functions instead and, due to pointer type
> incompatibility, cause compilation to fail.
> 
> As AudioDSP drivers e.g.: the avs-driver utilize struct hda_bus (and
> thus struct hdac_bus) as the base structure, add casts to address the
> problem.
> 
> Fixes: c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices")
> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
> ---
>   include/sound/hdaudio_ext.h | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/include/sound/hdaudio_ext.h b/include/sound/hdaudio_ext.h
> index 957295364a5e..79a010dd0062 100644
> --- a/include/sound/hdaudio_ext.h
> +++ b/include/sound/hdaudio_ext.h
> @@ -120,21 +120,21 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink)
>   void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
>   
>   #define snd_hdac_adsp_writeb(chip, reg, value) \
> -	snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
> +	snd_hdac_reg_writeb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>   #define snd_hdac_adsp_readb(chip, reg) \
> -	snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
> +	snd_hdac_reg_readb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>   #define snd_hdac_adsp_writew(chip, reg, value) \
> -	snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
> +	snd_hdac_reg_writew((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>   #define snd_hdac_adsp_readw(chip, reg) \
> -	snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
> +	snd_hdac_reg_readw((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>   #define snd_hdac_adsp_writel(chip, reg, value) \
> -	snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
> +	snd_hdac_reg_writel((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>   #define snd_hdac_adsp_readl(chip, reg) \
> -	snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
> +	snd_hdac_reg_readl((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>   #define snd_hdac_adsp_writeq(chip, reg, value) \
> -	snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
> +	snd_hdac_reg_writeq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>   #define snd_hdac_adsp_readq(chip, reg) \
> -	snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
> +	snd_hdac_reg_readq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>   
>   #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
>   	snd_hdac_adsp_writeb(chip, reg, \


I'm not sure, if this change is wanted. The passed pointer validation from the 
compiler side is lost with retyping.

Perhaps, it would be better to create another set of defines for other 
structure pointers.

					Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 0/3] ALSA: hda: Compilation and firmware-loading fixes
@ 2025-01-09 12:52 Cezary Rojewski
  2025-01-09 12:52 ` [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers Cezary Rojewski
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 12:52 UTC (permalink / raw)
  To: tiwai; +Cc: linux-sound, broonie, perex, amadeuszx.slawinski, Cezary Rojewski

Small set of fixes, two of which are self-explanatory: address
compilation or static analysis problems.

The most impactful change updates the firmware loading flow so that the
binary is loaded in two chunks rather than just one. This is to follow
recommendation from the hardware team: SDxLVI is expected to be at least
1 (0-index based so 1+1=2 BDLEs) when performing any data transfer.

Cezary Rojewski (3):
  ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
  ALSA: hda: Transfer firmware in two chunks
  ALSA: control: Fix argument type mismatch

 include/sound/control.h     |  2 +-
 include/sound/hdaudio_ext.h | 16 ++++++++--------
 sound/hda/hdac_stream.c     |  3 ++-
 3 files changed, 11 insertions(+), 10 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
  2025-01-09 12:52 [PATCH 0/3] ALSA: hda: Compilation and firmware-loading fixes Cezary Rojewski
@ 2025-01-09 12:52 ` Cezary Rojewski
  2025-01-09 12:42   ` Jaroslav Kysela
  2025-01-09 12:52 ` [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks Cezary Rojewski
  2025-01-09 12:52 ` [PATCH 3/3] ALSA: control: Fix argument type mismatch Cezary Rojewski
  2 siblings, 1 reply; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 12:52 UTC (permalink / raw)
  To: tiwai; +Cc: linux-sound, broonie, perex, amadeuszx.slawinski, Cezary Rojewski

The snd_hdac_adsp_xxx() wrap snd_hdac_reg_xxx() helpers to simplify
register access for AudioDSP drivers e.g.: the avs-driver. Byte- and
word-variants of said helps do not expand to bare readx/writex()
operations but functions instead and, due to pointer type
incompatibility, cause compilation to fail.

As AudioDSP drivers e.g.: the avs-driver utilize struct hda_bus (and
thus struct hdac_bus) as the base structure, add casts to address the
problem.

Fixes: c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices")
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
 include/sound/hdaudio_ext.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/sound/hdaudio_ext.h b/include/sound/hdaudio_ext.h
index 957295364a5e..79a010dd0062 100644
--- a/include/sound/hdaudio_ext.h
+++ b/include/sound/hdaudio_ext.h
@@ -120,21 +120,21 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink)
 void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
 
 #define snd_hdac_adsp_writeb(chip, reg, value) \
-	snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
+	snd_hdac_reg_writeb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
 #define snd_hdac_adsp_readb(chip, reg) \
-	snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
+	snd_hdac_reg_readb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
 #define snd_hdac_adsp_writew(chip, reg, value) \
-	snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
+	snd_hdac_reg_writew((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
 #define snd_hdac_adsp_readw(chip, reg) \
-	snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
+	snd_hdac_reg_readw((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
 #define snd_hdac_adsp_writel(chip, reg, value) \
-	snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
+	snd_hdac_reg_writel((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
 #define snd_hdac_adsp_readl(chip, reg) \
-	snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
+	snd_hdac_reg_readl((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
 #define snd_hdac_adsp_writeq(chip, reg, value) \
-	snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
+	snd_hdac_reg_writeq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
 #define snd_hdac_adsp_readq(chip, reg) \
-	snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
+	snd_hdac_reg_readq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
 
 #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
 	snd_hdac_adsp_writeb(chip, reg, \
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks
  2025-01-09 12:52 [PATCH 0/3] ALSA: hda: Compilation and firmware-loading fixes Cezary Rojewski
  2025-01-09 12:52 ` [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers Cezary Rojewski
@ 2025-01-09 12:52 ` Cezary Rojewski
  2025-01-09 14:29   ` Takashi Iwai
  2025-01-09 12:52 ` [PATCH 3/3] ALSA: control: Fix argument type mismatch Cezary Rojewski
  2 siblings, 1 reply; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 12:52 UTC (permalink / raw)
  To: tiwai; +Cc: linux-sound, broonie, perex, amadeuszx.slawinski, Cezary Rojewski

As per specification, SDxLVI shall be at least 1 i.e.: two chunks to
perform a valid transfer. This is true for the PCM transfer code but
not firmware-transfer one.

Technical background:
- the LVI > 0 rule shall be obeyed in PCM transfer
- HW permits LVI == 0 when transfer is SW-controlled (SPIB)
- FW download is not a PCM transfer and is SW-controlled (SPIB)

The above is the fundament which AudioDSP firmware loading functions
have been built upon and worked since 2016. The presented changes are to
align the loading flows and avoid rising more questions in the future.

Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
 sound/hda/hdac_stream.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
index 2670792f43b4..18d74a28a246 100644
--- a/sound/hda/hdac_stream.c
+++ b/sound/hda/hdac_stream.c
@@ -455,6 +455,7 @@ static int setup_bdle(struct hdac_bus *bus,
 		      struct hdac_stream *azx_dev, __le32 **bdlp,
 		      int ofs, int size, int with_ioc)
 {
+	u32 bdle_size = size / 2;
 	__le32 *bdl = *bdlp;
 
 	while (size > 0) {
@@ -469,7 +470,7 @@ static int setup_bdle(struct hdac_bus *bus,
 		bdl[0] = cpu_to_le32((u32)addr);
 		bdl[1] = cpu_to_le32(upper_32_bits(addr));
 		/* program the size field of the BDL entry */
-		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
+		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, bdle_size);
 		/* one BDLE cannot cross 4K boundary on CTHDA chips */
 		if (bus->align_bdle_4k) {
 			u32 remain = 0x1000 - (ofs & 0xfff);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/3] ALSA: control: Fix argument type mismatch
  2025-01-09 12:52 [PATCH 0/3] ALSA: hda: Compilation and firmware-loading fixes Cezary Rojewski
  2025-01-09 12:52 ` [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers Cezary Rojewski
  2025-01-09 12:52 ` [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks Cezary Rojewski
@ 2025-01-09 12:52 ` Cezary Rojewski
  2025-01-09 14:31   ` Takashi Iwai
  2 siblings, 1 reply; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 12:52 UTC (permalink / raw)
  To: tiwai; +Cc: linux-sound, broonie, perex, amadeuszx.slawinski, Cezary Rojewski

strscpy() expects argument of type "char *", not "unsigned char *".
Found out by Coverity static analyzer.

Fixes: 68fa05d4a82b ("ALSA: control: Introduce snd_ctl_find_id_mixer()")
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
 include/sound/control.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/sound/control.h b/include/sound/control.h
index e07f6b960641..f7e18a1d144f 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -161,7 +161,7 @@ snd_ctl_find_id_mixer(struct snd_card *card, const char *name)
 	struct snd_ctl_elem_id id = {};
 
 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
-	strscpy(id.name, name, sizeof(id.name));
+	strscpy((char *)id.name, name, sizeof(id.name));
 	return snd_ctl_find_id(card, &id);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
  2025-01-09 12:42   ` Jaroslav Kysela
@ 2025-01-09 14:20     ` Takashi Iwai
  2025-01-09 14:41       ` Cezary Rojewski
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2025-01-09 14:20 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: Cezary Rojewski, tiwai, linux-sound, broonie, amadeuszx.slawinski

On Thu, 09 Jan 2025 13:42:18 +0100,
Jaroslav Kysela wrote:
> 
> On 09. 01. 25 13:52, Cezary Rojewski wrote:
> > The snd_hdac_adsp_xxx() wrap snd_hdac_reg_xxx() helpers to simplify
> > register access for AudioDSP drivers e.g.: the avs-driver. Byte- and
> > word-variants of said helps do not expand to bare readx/writex()
> > operations but functions instead and, due to pointer type
> > incompatibility, cause compilation to fail.
> > 
> > As AudioDSP drivers e.g.: the avs-driver utilize struct hda_bus (and
> > thus struct hdac_bus) as the base structure, add casts to address the
> > problem.
> > 
> > Fixes: c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices")
> > Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
> > ---
> >   include/sound/hdaudio_ext.h | 16 ++++++++--------
> >   1 file changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/include/sound/hdaudio_ext.h b/include/sound/hdaudio_ext.h
> > index 957295364a5e..79a010dd0062 100644
> > --- a/include/sound/hdaudio_ext.h
> > +++ b/include/sound/hdaudio_ext.h
> > @@ -120,21 +120,21 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink)
> >   void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
> >     #define snd_hdac_adsp_writeb(chip, reg, value) \
> > -	snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
> > +	snd_hdac_reg_writeb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >   #define snd_hdac_adsp_readb(chip, reg) \
> > -	snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
> > +	snd_hdac_reg_readb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >   #define snd_hdac_adsp_writew(chip, reg, value) \
> > -	snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
> > +	snd_hdac_reg_writew((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >   #define snd_hdac_adsp_readw(chip, reg) \
> > -	snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
> > +	snd_hdac_reg_readw((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >   #define snd_hdac_adsp_writel(chip, reg, value) \
> > -	snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
> > +	snd_hdac_reg_writel((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >   #define snd_hdac_adsp_readl(chip, reg) \
> > -	snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
> > +	snd_hdac_reg_readl((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >   #define snd_hdac_adsp_writeq(chip, reg, value) \
> > -	snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
> > +	snd_hdac_reg_writeq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >   #define snd_hdac_adsp_readq(chip, reg) \
> > -	snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
> > +	snd_hdac_reg_readq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >     #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
> >   	snd_hdac_adsp_writeb(chip, reg, \
> 
> 
> I'm not sure, if this change is wanted. The passed pointer validation
> from the compiler side is lost with retyping.
> 
> Perhaps, it would be better to create another set of defines for other
> structure pointers.

Agreed.  The cast there secretly assumes the type punning and it hides
potential bugs.

As those macros are used only by AVS for now, you can move to AVS
locally and redefine for the more appropriate types, too.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks
  2025-01-09 12:52 ` [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks Cezary Rojewski
@ 2025-01-09 14:29   ` Takashi Iwai
  2025-01-09 17:13     ` Cezary Rojewski
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2025-01-09 14:29 UTC (permalink / raw)
  To: Cezary Rojewski; +Cc: tiwai, linux-sound, broonie, perex, amadeuszx.slawinski

On Thu, 09 Jan 2025 13:52:03 +0100,
Cezary Rojewski wrote:
> 
> As per specification, SDxLVI shall be at least 1 i.e.: two chunks to
> perform a valid transfer. This is true for the PCM transfer code but
> not firmware-transfer one.
> 
> Technical background:
> - the LVI > 0 rule shall be obeyed in PCM transfer
> - HW permits LVI == 0 when transfer is SW-controlled (SPIB)
> - FW download is not a PCM transfer and is SW-controlled (SPIB)
> 
> The above is the fundament which AudioDSP firmware loading functions
> have been built upon and worked since 2016. The presented changes are to
> align the loading flows and avoid rising more questions in the future.
> 
> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
> ---
>  sound/hda/hdac_stream.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
> index 2670792f43b4..18d74a28a246 100644
> --- a/sound/hda/hdac_stream.c
> +++ b/sound/hda/hdac_stream.c
> @@ -455,6 +455,7 @@ static int setup_bdle(struct hdac_bus *bus,
>  		      struct hdac_stream *azx_dev, __le32 **bdlp,
>  		      int ofs, int size, int with_ioc)
>  {
> +	u32 bdle_size = size / 2;
>  	__le32 *bdl = *bdlp;
>  
>  	while (size > 0) {
> @@ -469,7 +470,7 @@ static int setup_bdle(struct hdac_bus *bus,
>  		bdl[0] = cpu_to_le32((u32)addr);
>  		bdl[1] = cpu_to_le32(upper_32_bits(addr));
>  		/* program the size field of the BDL entry */
> -		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
> +		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, bdle_size);
>  		/* one BDLE cannot cross 4K boundary on CTHDA chips */
>  		if (bus->align_bdle_4k) {
>  			u32 remain = 0x1000 - (ofs & 0xfff);

Note that we set up BDLE also for the fragment for pos_adj correction
at the beginning of the buffer.  With your patch, this small BDLE
would be split again.  I don't think it's the desired outcome.

The requirement is to have at least two BDL entries?


thanks,

Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/3] ALSA: control: Fix argument type mismatch
  2025-01-09 12:52 ` [PATCH 3/3] ALSA: control: Fix argument type mismatch Cezary Rojewski
@ 2025-01-09 14:31   ` Takashi Iwai
  2025-01-09 14:47     ` Cezary Rojewski
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2025-01-09 14:31 UTC (permalink / raw)
  To: Cezary Rojewski; +Cc: tiwai, linux-sound, broonie, perex, amadeuszx.slawinski

On Thu, 09 Jan 2025 13:52:04 +0100,
Cezary Rojewski wrote:
> 
> strscpy() expects argument of type "char *", not "unsigned char *".
> Found out by Coverity static analyzer.
> 
> Fixes: 68fa05d4a82b ("ALSA: control: Introduce snd_ctl_find_id_mixer()")
> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>

The conversion between char and unsigned char pointers isn't taken
seriously in the kernel code.  The compiler warning was disabled
intentionally, too.  In general, such an unnecessary cast is more
harmful.


thanks,

Takashi

> ---
>  include/sound/control.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/sound/control.h b/include/sound/control.h
> index e07f6b960641..f7e18a1d144f 100644
> --- a/include/sound/control.h
> +++ b/include/sound/control.h
> @@ -161,7 +161,7 @@ snd_ctl_find_id_mixer(struct snd_card *card, const char *name)
>  	struct snd_ctl_elem_id id = {};
>  
>  	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
> -	strscpy(id.name, name, sizeof(id.name));
> +	strscpy((char *)id.name, name, sizeof(id.name));
>  	return snd_ctl_find_id(card, &id);
>  }
>  
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
  2025-01-09 14:20     ` Takashi Iwai
@ 2025-01-09 14:41       ` Cezary Rojewski
  2025-01-09 14:52         ` Takashi Iwai
  0 siblings, 1 reply; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 14:41 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela
  Cc: tiwai, linux-sound, broonie, amadeuszx.slawinski

On 2025-01-09 3:20 PM, Takashi Iwai wrote:
> On Thu, 09 Jan 2025 13:42:18 +0100,
> Jaroslav Kysela wrote:
>>
>> On 09. 01. 25 13:52, Cezary Rojewski wrote:
>>> The snd_hdac_adsp_xxx() wrap snd_hdac_reg_xxx() helpers to simplify
>>> register access for AudioDSP drivers e.g.: the avs-driver. Byte- and
>>> word-variants of said helps do not expand to bare readx/writex()
>>> operations but functions instead and, due to pointer type
>>> incompatibility, cause compilation to fail.
>>>
>>> As AudioDSP drivers e.g.: the avs-driver utilize struct hda_bus (and
>>> thus struct hdac_bus) as the base structure, add casts to address the
>>> problem.
>>>
>>> Fixes: c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices")
>>> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
>>> ---
>>>    include/sound/hdaudio_ext.h | 16 ++++++++--------
>>>    1 file changed, 8 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/include/sound/hdaudio_ext.h b/include/sound/hdaudio_ext.h
>>> index 957295364a5e..79a010dd0062 100644
>>> --- a/include/sound/hdaudio_ext.h
>>> +++ b/include/sound/hdaudio_ext.h
>>> @@ -120,21 +120,21 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink)
>>>    void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
>>>      #define snd_hdac_adsp_writeb(chip, reg, value) \
>>> -	snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
>>> +	snd_hdac_reg_writeb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>>>    #define snd_hdac_adsp_readb(chip, reg) \
>>> -	snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
>>> +	snd_hdac_reg_readb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>>>    #define snd_hdac_adsp_writew(chip, reg, value) \
>>> -	snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
>>> +	snd_hdac_reg_writew((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>>>    #define snd_hdac_adsp_readw(chip, reg) \
>>> -	snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
>>> +	snd_hdac_reg_readw((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>>>    #define snd_hdac_adsp_writel(chip, reg, value) \
>>> -	snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
>>> +	snd_hdac_reg_writel((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>>>    #define snd_hdac_adsp_readl(chip, reg) \
>>> -	snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
>>> +	snd_hdac_reg_readl((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>>>    #define snd_hdac_adsp_writeq(chip, reg, value) \
>>> -	snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
>>> +	snd_hdac_reg_writeq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
>>>    #define snd_hdac_adsp_readq(chip, reg) \
>>> -	snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
>>> +	snd_hdac_reg_readq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
>>>      #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
>>>    	snd_hdac_adsp_writeb(chip, reg, \
>>
>>
>> I'm not sure, if this change is wanted. The passed pointer validation
>> from the compiler side is lost with retyping.
>>
>> Perhaps, it would be better to create another set of defines for other
>> structure pointers.
> 
> Agreed.  The cast there secretly assumes the type punning and it hides
> potential bugs.
> 
> As those macros are used only by AVS for now, you can move to AVS
> locally and redefine for the more appropriate types, too.

Hi,

Thank you both for the constructive feedback. From what I understand, to 
fix the compilation issue, it is best to move the macros into local, 
sound/soc/intel/avs/ location, perhaps into the existing registers.h file?

Kind regards,
Czarek

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/3] ALSA: control: Fix argument type mismatch
  2025-01-09 14:31   ` Takashi Iwai
@ 2025-01-09 14:47     ` Cezary Rojewski
  0 siblings, 0 replies; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 14:47 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: tiwai, linux-sound, broonie, perex, amadeuszx.slawinski



On 2025-01-09 3:31 PM, Takashi Iwai wrote:
> On Thu, 09 Jan 2025 13:52:04 +0100,
> Cezary Rojewski wrote:
>>
>> strscpy() expects argument of type "char *", not "unsigned char *".
>> Found out by Coverity static analyzer.
>>
>> Fixes: 68fa05d4a82b ("ALSA: control: Introduce snd_ctl_find_id_mixer()")
>> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
> 
> The conversion between char and unsigned char pointers isn't taken
> seriously in the kernel code.  The compiler warning was disabled
> intentionally, too.  In general, such an unnecessary cast is more
> harmful.

Understood, will remove in v2 and squelch the analyzers on the intel side.

>> ---
>>   include/sound/control.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/sound/control.h b/include/sound/control.h
>> index e07f6b960641..f7e18a1d144f 100644
>> --- a/include/sound/control.h
>> +++ b/include/sound/control.h
>> @@ -161,7 +161,7 @@ snd_ctl_find_id_mixer(struct snd_card *card, const char *name)
>>   	struct snd_ctl_elem_id id = {};
>>   
>>   	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
>> -	strscpy(id.name, name, sizeof(id.name));
>> +	strscpy((char *)id.name, name, sizeof(id.name));
>>   	return snd_ctl_find_id(card, &id);
>>   }
>>   
>> -- 
>> 2.25.1
>>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
  2025-01-09 14:41       ` Cezary Rojewski
@ 2025-01-09 14:52         ` Takashi Iwai
  0 siblings, 0 replies; 12+ messages in thread
From: Takashi Iwai @ 2025-01-09 14:52 UTC (permalink / raw)
  To: Cezary Rojewski
  Cc: Takashi Iwai, Jaroslav Kysela, tiwai, linux-sound, broonie,
	amadeuszx.slawinski

On Thu, 09 Jan 2025 15:41:59 +0100,
Cezary Rojewski wrote:
> 
> On 2025-01-09 3:20 PM, Takashi Iwai wrote:
> > On Thu, 09 Jan 2025 13:42:18 +0100,
> > Jaroslav Kysela wrote:
> >> 
> >> On 09. 01. 25 13:52, Cezary Rojewski wrote:
> >>> The snd_hdac_adsp_xxx() wrap snd_hdac_reg_xxx() helpers to simplify
> >>> register access for AudioDSP drivers e.g.: the avs-driver. Byte- and
> >>> word-variants of said helps do not expand to bare readx/writex()
> >>> operations but functions instead and, due to pointer type
> >>> incompatibility, cause compilation to fail.
> >>> 
> >>> As AudioDSP drivers e.g.: the avs-driver utilize struct hda_bus (and
> >>> thus struct hdac_bus) as the base structure, add casts to address the
> >>> problem.
> >>> 
> >>> Fixes: c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices")
> >>> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
> >>> ---
> >>>    include/sound/hdaudio_ext.h | 16 ++++++++--------
> >>>    1 file changed, 8 insertions(+), 8 deletions(-)
> >>> 
> >>> diff --git a/include/sound/hdaudio_ext.h b/include/sound/hdaudio_ext.h
> >>> index 957295364a5e..79a010dd0062 100644
> >>> --- a/include/sound/hdaudio_ext.h
> >>> +++ b/include/sound/hdaudio_ext.h
> >>> @@ -120,21 +120,21 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink)
> >>>    void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
> >>>      #define snd_hdac_adsp_writeb(chip, reg, value) \
> >>> -	snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
> >>> +	snd_hdac_reg_writeb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >>>    #define snd_hdac_adsp_readb(chip, reg) \
> >>> -	snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
> >>> +	snd_hdac_reg_readb((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >>>    #define snd_hdac_adsp_writew(chip, reg, value) \
> >>> -	snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
> >>> +	snd_hdac_reg_writew((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >>>    #define snd_hdac_adsp_readw(chip, reg) \
> >>> -	snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
> >>> +	snd_hdac_reg_readw((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >>>    #define snd_hdac_adsp_writel(chip, reg, value) \
> >>> -	snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
> >>> +	snd_hdac_reg_writel((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >>>    #define snd_hdac_adsp_readl(chip, reg) \
> >>> -	snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
> >>> +	snd_hdac_reg_readl((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >>>    #define snd_hdac_adsp_writeq(chip, reg, value) \
> >>> -	snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
> >>> +	snd_hdac_reg_writeq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg), value)
> >>>    #define snd_hdac_adsp_readq(chip, reg) \
> >>> -	snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
> >>> +	snd_hdac_reg_readq((struct hdac_bus *)(chip), (chip)->dsp_ba + (reg))
> >>>      #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
> >>>    	snd_hdac_adsp_writeb(chip, reg, \
> >> 
> >> 
> >> I'm not sure, if this change is wanted. The passed pointer validation
> >> from the compiler side is lost with retyping.
> >> 
> >> Perhaps, it would be better to create another set of defines for other
> >> structure pointers.
> > 
> > Agreed.  The cast there secretly assumes the type punning and it hides
> > potential bugs.
> > 
> > As those macros are used only by AVS for now, you can move to AVS
> > locally and redefine for the more appropriate types, too.
> 
> Hi,
> 
> Thank you both for the constructive feedback. From what I understand,
> to fix the compilation issue, it is best to move the macros into
> local, sound/soc/intel/avs/ location, perhaps into the existing
> registers.h file?

Yes, it sounds reasonable.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks
  2025-01-09 14:29   ` Takashi Iwai
@ 2025-01-09 17:13     ` Cezary Rojewski
  0 siblings, 0 replies; 12+ messages in thread
From: Cezary Rojewski @ 2025-01-09 17:13 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: tiwai, linux-sound, broonie, perex, amadeuszx.slawinski

On 2025-01-09 3:29 PM, Takashi Iwai wrote:
> On Thu, 09 Jan 2025 13:52:03 +0100,
> Cezary Rojewski wrote:
>>
>> As per specification, SDxLVI shall be at least 1 i.e.: two chunks to
>> perform a valid transfer. This is true for the PCM transfer code but
>> not firmware-transfer one.
>>
>> Technical background:
>> - the LVI > 0 rule shall be obeyed in PCM transfer
>> - HW permits LVI == 0 when transfer is SW-controlled (SPIB)
>> - FW download is not a PCM transfer and is SW-controlled (SPIB)
>>
>> The above is the fundament which AudioDSP firmware loading functions
>> have been built upon and worked since 2016. The presented changes are to
>> align the loading flows and avoid rising more questions in the future.
>>
>> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
>> ---
>>   sound/hda/hdac_stream.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
>> index 2670792f43b4..18d74a28a246 100644
>> --- a/sound/hda/hdac_stream.c
>> +++ b/sound/hda/hdac_stream.c
>> @@ -455,6 +455,7 @@ static int setup_bdle(struct hdac_bus *bus,
>>   		      struct hdac_stream *azx_dev, __le32 **bdlp,
>>   		      int ofs, int size, int with_ioc)
>>   {
>> +	u32 bdle_size = size / 2;
>>   	__le32 *bdl = *bdlp;
>>   
>>   	while (size > 0) {
>> @@ -469,7 +470,7 @@ static int setup_bdle(struct hdac_bus *bus,
>>   		bdl[0] = cpu_to_le32((u32)addr);
>>   		bdl[1] = cpu_to_le32(upper_32_bits(addr));
>>   		/* program the size field of the BDL entry */
>> -		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
>> +		chunk = snd_sgbuf_get_chunk_size(dmab, ofs, bdle_size);
>>   		/* one BDLE cannot cross 4K boundary on CTHDA chips */
>>   		if (bus->align_bdle_4k) {
>>   			u32 remain = 0x1000 - (ofs & 0xfff);
> 
> Note that we set up BDLE also for the fragment for pos_adj correction
> at the beginning of the buffer.  With your patch, this small BDLE
> would be split again.  I don't think it's the desired outcome.
> 
> The requirement is to have at least two BDL entries?

Indeed, that's the requirement.

SDxLVI of 0 translates to 1x BDL entry (BDLE), SDxLVI of 1 translates to 
2x BDLEs.  As the commit message explains, the existing code causes no 
known issues for the platforms available on the market but we want to be 
forward-compatible and avoid revisiting the subject in future.  To 
address this, the hardware team recommends to update the 
firmware-loading code to follow similar rules the PCM-transfer does.

In regard to pos_adj, the DSP-capable drivers e.g.: the avs-driver, do 
not utilize the bus->bdl_pos_adj field. To the best of my knowledge, 
it's always set to zero so all the conditional code that takes pos_adj 
into account is ignored.


Kind regards,
Czarek

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-01-09 17:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 12:52 [PATCH 0/3] ALSA: hda: Compilation and firmware-loading fixes Cezary Rojewski
2025-01-09 12:52 ` [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers Cezary Rojewski
2025-01-09 12:42   ` Jaroslav Kysela
2025-01-09 14:20     ` Takashi Iwai
2025-01-09 14:41       ` Cezary Rojewski
2025-01-09 14:52         ` Takashi Iwai
2025-01-09 12:52 ` [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks Cezary Rojewski
2025-01-09 14:29   ` Takashi Iwai
2025-01-09 17:13     ` Cezary Rojewski
2025-01-09 12:52 ` [PATCH 3/3] ALSA: control: Fix argument type mismatch Cezary Rojewski
2025-01-09 14:31   ` Takashi Iwai
2025-01-09 14:47     ` Cezary Rojewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox