ALSA: hda: Compilation and firmware-loading fixes
Subsystems (3)
Cezary Rojewski
maintainerv2 cover ALSA: hda: Compilation and firmware-loading fixes
Small set of fixes, one of which addresses the compilation issues with snd_hdac_adsp_xxx() macros utilized currently by the avs-driver alone.
The more 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 BDL entries) when performing any data transfer.
Changes in v2:
- removed the type-mismatch fixing patch as suggested by Takashi
- relocated snd_hdac_adsp_xxx() macros to avs/ space as suggested by Jaroslav and Takashi
Cezary Rojewski (2):
ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
ALSA: hda: Transfer firmware in two chunks
include/sound/hdaudio_ext.h | 45 --------------------------------- sound/hda/hdac_stream.c | 3 ++- sound/soc/intel/avs/apl.c | 1 + sound/soc/intel/avs/cnl.c | 1 + sound/soc/intel/avs/registers.h | 45 +++++++++++++++++++++++++++++++++ sound/soc/intel/avs/skl.c | 1 + 6 files changed, 50 insertions(+), 46 deletions(-)
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH v2 1/2 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 the macros are utilized by the avs-driver alone, relocate the code introduced with commit c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices") into the avs/ directory and update it to operate on 'adev' i.e.: the avs-driver-context directly to fix the issue.
--- include/sound/hdaudio_ext.h | 45 --------------------------------- sound/soc/intel/avs/apl.c | 1 + sound/soc/intel/avs/cnl.c | 1 + sound/soc/intel/avs/registers.h | 45 +++++++++++++++++++++++++++++++++ sound/soc/intel/avs/skl.c | 1 + 5 files changed, 48 insertions(+), 45 deletions(-)
include/sound/hdaudio_ext.h +0 -45
@@ -2,8 +2,6 @@#ifndef __SOUND_HDAUDIO_EXT_H#define __SOUND_HDAUDIO_EXT_H -#include <linux/io-64-nonatomic-lo-hi.h> -#include <linux/iopoll.h> #include <sound/hdaudio.h> int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
@@ -119,49 +117,6 @@ 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) -#define snd_hdac_adsp_readb (chip, reg) \ - snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg)) -#define snd_hdac_adsp_writew (chip, reg, value) \ - snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value) -#define snd_hdac_adsp_readw (chip, reg) \ - snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg)) -#define snd_hdac_adsp_writel (chip, reg, value) \ - snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value) -#define snd_hdac_adsp_readl (chip, reg) \ - snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg)) -#define snd_hdac_adsp_writeq (chip, reg, value) \ - snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value) -#define snd_hdac_adsp_readq (chip, reg) \ - snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg)) - -#define snd_hdac_adsp_updateb (chip, reg, mask, val) \ - snd_hdac_adsp_writeb(chip, reg, \ - (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val)) -#define snd_hdac_adsp_updatew (chip, reg, mask, val) \ - snd_hdac_adsp_writew(chip, reg, \ - (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val)) -#define snd_hdac_adsp_updatel (chip, reg, mask, val) \ - snd_hdac_adsp_writel(chip, reg, \ - (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val)) -#define snd_hdac_adsp_updateq (chip, reg, mask, val) \ - snd_hdac_adsp_writeq(chip, reg, \ - (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val)) - -#define snd_hdac_adsp_readb_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -#define snd_hdac_adsp_readw_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -#define snd_hdac_adsp_readl_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -#define snd_hdac_adsp_readq_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -struct hdac_ext_device ;/* ops common to all codec drivers */
sound/soc/intel/avs/apl.c +1 -0
@@ -12,6 +12,7 @@#include "avs.h" #include "messages.h" #include "path.h" +#include "registers.h" #include "topology.h" static irqreturn_t avs_apl_dsp_interrupt (struct avs_dev *adev)
sound/soc/intel/avs/cnl.c +1 -0
@@ -9,6 +9,7 @@#include <sound/hdaudio_ext.h> #include "avs.h" #include "messages.h" +#include "registers.h" static void avs_cnl_ipc_interrupt (struct avs_dev *adev) {
sound/soc/intel/avs/registers.h +45 -0
55 lines not on this page · raw message
sound/soc/intel/avs/skl.c +1 -0
@@ -12,6 +12,7 @@#include "avs.h" #include "cldma.h" #include "messages.h" +#include "registers.h" void avs_skl_ipc_interrupt (struct avs_dev *adev) {
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
Quoted 12 lines · Cezary Rojewski
The
snd_hdac_adsp_xxx()wrapsnd_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 the macros are utilized by the avs-driver alone, relocate the code introduced with commit
c19bd02e9029("ALSA: hda: Add helper macros for DSP capable devices") into the avs/ directory and update it to operate on 'adev' i.e.: the avs-driver-context directly to fix the issue.
Quoted 8 lines
Fixes c19bd02e9029 ("ALSA: hda: Add helper macros for DSP capable devices")Signed-off-by Cezary Rojewski <[email protected]>--- include/sound/hdaudio_ext.h | 45 --------------------------------- sound/soc/intel/avs/apl.c | 1 + sound/soc/intel/avs/cnl.c | 1 + sound/soc/intel/avs/registers.h | 45 +++++++++++++++++++++++++++++++++ sound/soc/intel/avs/skl.c | 1 +
I can take this, but as it touches ASoC stuff, need an ack from Mark.
thanks,
Takashi
Quoted 165 lines
5 files changed, 48 insertions(+), 45 deletions(-)include/sound/hdaudio_ext.h +0
-45@@ -2,8 +2,6 @@#ifndef __SOUND_HDAUDIO_EXT_H#define __SOUND_HDAUDIO_EXT_H -#include <linux/io-64-nonatomic-lo-hi.h> -#include <linux/iopoll.h> #include <sound/hdaudio.h> int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,@@ -119,49 +117,6 @@ 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) -#define snd_hdac_adsp_readb (chip, reg) \ - snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg)) -#define snd_hdac_adsp_writew (chip, reg, value) \ - snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value) -#define snd_hdac_adsp_readw (chip, reg) \ - snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg)) -#define snd_hdac_adsp_writel (chip, reg, value) \ - snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value) -#define snd_hdac_adsp_readl (chip, reg) \ - snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg)) -#define snd_hdac_adsp_writeq (chip, reg, value) \ - snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value) -#define snd_hdac_adsp_readq (chip, reg) \ - snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg)) - -#define snd_hdac_adsp_updateb (chip, reg, mask, val) \ - snd_hdac_adsp_writeb(chip, reg, \ - (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val)) -#define snd_hdac_adsp_updatew (chip, reg, mask, val) \ - snd_hdac_adsp_writew(chip, reg, \ - (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val)) -#define snd_hdac_adsp_updatel (chip, reg, mask, val) \ - snd_hdac_adsp_writel(chip, reg, \ - (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val)) -#define snd_hdac_adsp_updateq (chip, reg, mask, val) \ - snd_hdac_adsp_writeq(chip, reg, \ - (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val)) - -#define snd_hdac_adsp_readb_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -#define snd_hdac_adsp_readw_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -#define snd_hdac_adsp_readl_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -#define snd_hdac_adsp_readq_poll (chip, reg, val, cond, delay_us, timeout_us) \ - readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ - delay_us, timeout_us) -struct hdac_ext_device ;/* ops common to all codec drivers */ sound/soc/intel/avs/apl.c +1
-0@@ -12,6 +12,7 @@#include "avs.h" #include "messages.h" #include "path.h" +#include "registers.h" #include "topology.h" static irqreturn_t avs_apl_dsp_interrupt (struct avs_dev *adev)sound/soc/intel/avs/cnl.c +1
-0@@ -9,6 +9,7 @@#include <sound/hdaudio_ext.h> #include "avs.h" #include "messages.h" +#include "registers.h" static void avs_cnl_ipc_interrupt (struct avs_dev *adev) {sound/soc/intel/avs/registers.h +45
-0@@ -9,6 +9,8 @@#ifndef __SOUND_SOC_INTEL_AVS_REGS_H#define __SOUND_SOC_INTEL_AVS_REGS_H +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/iopoll.h> #include <linux/sizes.h> #define AZX_PCIREG_PGCTL 0x44@@ -98,4 +100,47 @@#define avs_downlink_addr (adev) \ avs_sram_addr(adev, AVS_DOWNLINK_WINDOW) +#define snd_hdac_adsp_writeb (adev, reg, value) \ + snd_hdac_reg_writeb(&(adev)->base.core, (adev)->dsp_ba + (reg), value) +#define snd_hdac_adsp_readb (adev, reg) \ + snd_hdac_reg_readb(&(adev)->base.core, (adev)->dsp_ba + (reg)) +#define snd_hdac_adsp_writew (adev, reg, value) \ + snd_hdac_reg_writew(&(adev)->base.core, (adev)->dsp_ba + (reg), value) +#define snd_hdac_adsp_readw (adev, reg) \ + snd_hdac_reg_readw(&(adev)->base.core, (adev)->dsp_ba + (reg)) +#define snd_hdac_adsp_writel (adev, reg, value) \ + snd_hdac_reg_writel(&(adev)->base.core, (adev)->dsp_ba + (reg), value) +#define snd_hdac_adsp_readl (adev, reg) \ + snd_hdac_reg_readl(&(adev)->base.core, (adev)->dsp_ba + (reg)) +#define snd_hdac_adsp_writeq (adev, reg, value) \ + snd_hdac_reg_writeq(&(adev)->base.core, (adev)->dsp_ba + (reg), value) +#define snd_hdac_adsp_readq (adev, reg) \ + snd_hdac_reg_readq(&(adev)->base.core, (adev)->dsp_ba + (reg)) + +#define snd_hdac_adsp_updateb (adev, reg, mask, val) \ + snd_hdac_adsp_writeb(adev, reg, \ + (snd_hdac_adsp_readb(adev, reg) & ~(mask)) | (val)) +#define snd_hdac_adsp_updatew (adev, reg, mask, val) \ + snd_hdac_adsp_writew(adev, reg, \ + (snd_hdac_adsp_readw(adev, reg) & ~(mask)) | (val)) +#define snd_hdac_adsp_updatel (adev, reg, mask, val) \ + snd_hdac_adsp_writel(adev, reg, \ + (snd_hdac_adsp_readl(adev, reg) & ~(mask)) | (val)) +#define snd_hdac_adsp_updateq (adev, reg, mask, val) \ + snd_hdac_adsp_writeq(adev, reg, \ + (snd_hdac_adsp_readq(adev, reg) & ~(mask)) | (val)) + +#define snd_hdac_adsp_readb_poll (adev, reg, val, cond, delay_us, timeout_us) \ + readb_poll_timeout((adev)->dsp_ba + (reg), val, cond, \ + delay_us, timeout_us) +#define snd_hdac_adsp_readw_poll (adev, reg, val, cond, delay_us, timeout_us) \ + readw_poll_timeout((adev)->dsp_ba + (reg), val, cond, \ + delay_us, timeout_us) +#define snd_hdac_adsp_readl_poll (adev, reg, val, cond, delay_us, timeout_us) \ + readl_poll_timeout((adev)->dsp_ba + (reg), val, cond, \ + delay_us, timeout_us) +#define snd_hdac_adsp_readq_poll (adev, reg, val, cond, delay_us, timeout_us) \ + readq_poll_timeout((adev)->dsp_ba + (reg), val, cond, \ + delay_us, timeout_us) +#endif /* __SOUND_SOC_INTEL_AVS_REGS_H */ sound/soc/intel/avs/skl.c +1
-0@@ -12,6 +12,7 @@#include "avs.h" #include "cldma.h" #include "messages.h" +#include "registers.h" void avs_skl_ipc_interrupt (struct avs_dev *adev) {Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
Quoted 1 line · Takashi Iwai
I can take this, but as it touches ASoC stuff, need an ack from Mark.
I tend to just not look at stuff with ALSA: on it since I get copied on lots of HDA patches.
Re: [PATCH v2 1/2] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
Quoted 9 lines · Mark Brown
Quoted 1 line · Takashi Iwai
I can take this, but as it touches ASoC stuff, need an ack from Mark.
Acked-by Mark Brown <[email protected]>I tend to just not look at stuff with ALSA: on it since I get copied on lots of HDA patches.
Heh, that's why I asked explicitly at this time ;)
Now applied the patch 1 to for-next branch.
I leave patch 2 for further discussion.
thanks,
Takashi
Mark Brown
maintainerRe: [PATCH v2 1/2] ALSA: hda: Fix compilation of snd_hdac_adsp_xxx() helpers
Quoted 6 lines · Takashi Iwai
Quoted 2 lines · Mark Brown
I tend to just not look at stuff with ALSA: on it since I get copied on lots of HDA patches.
Heh, that's why I asked explicitly at this time ;)
I do tend to do it on subject line so it's a bit random if I'll see a query in a thread (depends a bit on how quiet my inbox is and if it's the next mail after something I read).
Cezary Rojewski
maintainerPATCH v2 2/2 ALSA: hda: Transfer firmware in two chunks
In reply to Cezary RojewskiAs 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
@@ -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
Re: [PATCH v2 2/2] 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.
Signed-off-by Cezary Rojewski <[email protected]>--- sound/hda/hdac_stream.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)sound/hda/hdac_stream.c +1
-0@@ -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 );
I still think that it's not best place to change.
For PCM, this workaround isn't needed in most cases, because setup_bdle() is called per period, and periods_min = 2 for snd-hda-intel. Doing extra splitting is superfluous for PCM.
That said, if we need a workaround of the split, it should be done conditionally for the firmware stream.
thanks,
Takashi
Cezary Rojewski
maintainerRe: [PATCH v2 2/2] ALSA: hda: Transfer firmware in two chunks
Quoted 45 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.
Signed-off-by Cezary Rojewski <[email protected]>--- sound/hda/hdac_stream.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)sound/hda/hdac_stream.c +1
-0@@ -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 );I still think that it's not best place to change.
Quoted 6 lines
For PCM, this workaround isn't needed in most cases, because
setup_bdle()is called per period, andperiods_min= 2 for snd-hda-intel. Doing extra splitting is superfluous for PCM.That said, if we need a workaround of the split, it should be done conditionally for the firmware stream.
Somehow I did not understand your initial point. Now I do. Indeed, I should not have altered setup_bdle() in such fashion as it's used by _everyone_. Will review the change and come back with something better.
Kind regards,
Czarek