Skip to contentSkip to conversation

ALSA: hda: Compilation and firmware-loading fixes

PATCH Superseded Cezary Rojewski 3 participants 12 messages Jan 9, 2025 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ALSA: hda: Compilation and firmware-loading fixes

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(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers

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")
---
 include/sound/hdaudio_ext.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
include/sound/hdaudio_ext.h +8 -8
index 957295364a5e..79a010dd0062 100644
@@ -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, \
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers

Quoted 40 lines · 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")
---
  include/sound/hdaudio_ext.h | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
include/sound/hdaudio_ext.h +5 -6
index 957295364a5e..79a010dd0062 100644
@@ -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))

include/sound/hdaudio_ext.h int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink) · line 140

Quoted 10 lines
include/sound/hdaudio_ext.h +3 -2
+	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

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#3 lore raw

Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers

Quoted 55 lines · Jaroslav Kysela
Quoted 38 lines · 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")
---
  include/sound/hdaudio_ext.h | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
include/sound/hdaudio_ext.h +5 -5
index 957295364a5e..79a010dd0062 100644
@@ -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) \

include/sound/hdaudio_ext.h int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink) · line 138

Quoted 10 lines
include/sound/hdaudio_ext.h +3 -3
-	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.

Quoted 2 lines

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

#4 lore raw

Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers

Quoted 57 lines · Takashi Iwai
Quoted 55 lines · Jaroslav Kysela
Quoted 38 lines · 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")
---
   include/sound/hdaudio_ext.h | 16 ++++++++--------
   1 file changed, 8 insertions(+), 8 deletions(-)
include/sound/hdaudio_ext.h +5 -5
index 957295364a5e..79a010dd0062 100644
@@ -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) \

include/sound/hdaudio_ext.h int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink) · line 138

Quoted 10 lines
include/sound/hdaudio_ext.h +3 -3
-	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.

Quoted 8 lines
Quoted 2 lines

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

#5 lore raw

Re: [PATCH 1/3] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers

Quoted 68 lines · Cezary Rojewski
Quoted 57 lines · Takashi Iwai
Quoted 55 lines · Jaroslav Kysela
Quoted 38 lines · 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")
---
   include/sound/hdaudio_ext.h | 16 ++++++++--------
   1 file changed, 8 insertions(+), 8 deletions(-)
include/sound/hdaudio_ext.h +5 -5
index 957295364a5e..79a010dd0062 100644
@@ -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) \

include/sound/hdaudio_ext.h int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink) · line 138

Quoted 10 lines
include/sound/hdaudio_ext.h +3 -3
-	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.

Quoted 8 lines
Quoted 2 lines

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.

Quoted 6 lines

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

#6 lore raw

PATCH 2/3 ALSA: hda: Transfer firmware in two chunks

In reply to 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.

---
 sound/hda/hdac_stream.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/hda/hdac_stream.c +2 -1
index 2670792f43b4..18d74a28a246 100644
@@ -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);
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks

Quoted 32 lines · 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.

---
 sound/hda/hdac_stream.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/hda/hdac_stream.c +1 -0
index 2670792f43b4..18d74a28a246 100644
@@ -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) {

sound/hda/hdac_stream.c static int setup_bdle(struct hdac_bus *bus, · line 476

Quoted 8 lines
sound/hda/hdac_stream.c +1 -1
@@ -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

#8 lore raw

Re: [PATCH 2/3] ALSA: hda: Transfer firmware in two chunks

Quoted 47 lines · Takashi Iwai
Quoted 32 lines · 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.

---
  sound/hda/hdac_stream.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
sound/hda/hdac_stream.c +1 -0
index 2670792f43b4..18d74a28a246 100644
@@ -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) {

sound/hda/hdac_stream.c static int setup_bdle(struct hdac_bus *bus, · line 476

Quoted 8 lines
sound/hda/hdac_stream.c +1 -1
@@ -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.

Quoted 1 line

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

#9 lore raw

PATCH 3/3 ALSA: control: Fix argument type mismatch

In reply to 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()")
---
 include/sound/control.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/sound/control.h +1 -1
index e07f6b960641..f7e18a1d144f 100644
@@ -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);
 }
 
Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH 3/3] ALSA: control: Fix argument type mismatch

Quoted 6 lines · 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()")

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

Quoted 20 lines
---
 include/sound/control.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/sound/control.h +1 -1
index e07f6b960641..f7e18a1d144f 100644
@@ -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);
 }
 
Signature · 1 line
2.25.1
#11 lore raw

Re: [PATCH 3/3] ALSA: control: Fix argument type mismatch

Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Cezary Rojewski

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

Quoted 7 lines
Quoted 2 lines
Fixes 68fa05d4a82b ("ALSA: control: Introduce snd_ctl_find_id_mixer()")

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.

Quoted 20 lines
Quoted 20 lines
---
  include/sound/control.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/sound/control.h +1 -1
index e07f6b960641..f7e18a1d144f 100644
@@ -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);
  }
 
Signature · 1 line
2.25.1