ASoC: Intel: avs: QoL fixes
Subsystems (3)
cover ASoC: Intel: avs: QoL fixes
Set of fixes mainly cleaning up code, but also correcting some minor HW assumptions.
Amadeusz Sławiński (2):
ASoC: Intel: avs: Use generic size defines
ASoC: Intel: avs: Preallocate memory for module configuration
Cezary Rojewski (3):
ASoC: Intel: avs: Move IPC error messages one level down
ASoC: Intel: avs: Keep module refcount up when gathering traces
ASoC: Intel: avs: Drop superfluous stream decoupling
Wu Zhou (1):
ASoC: Intel: avs: Disable DSP before loading basefw
sound/soc/intel/avs/avs.h | 38 ++++------- sound/soc/intel/avs/cldma.h | 4 +- sound/soc/intel/avs/core.c | 5 ++ sound/soc/intel/avs/debugfs.c | 4 ++ sound/soc/intel/avs/ipc.c | 52 ++++++++++----- sound/soc/intel/avs/loader.c | 4 ++ sound/soc/intel/avs/messages.c | 112 ++++++-------------------------- sound/soc/intel/avs/messages.h | 4 +- sound/soc/intel/avs/path.c | 31 +++++---- sound/soc/intel/avs/pcm.c | 2 - sound/soc/intel/avs/registers.h | 4 +- 11 files changed, 103 insertions(+), 157 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/6 ASoC: Intel: avs: Move IPC error messages one level down
From: Cezary Rojewski <[email protected]>
Code size can be reduced if avs_dsp_send_xxx_msg()s take responsibility for dumping logs in case of an IPC message failure. In consequence, avs_ipc_err() helper is removed.
--- sound/soc/intel/avs/avs.h | 37 +++-------- sound/soc/intel/avs/ipc.c | 52 ++++++++++----- sound/soc/intel/avs/messages.c | 112 ++++++--------------------------- 3 files changed, 65 insertions(+), 136 deletions(-)
sound/soc/intel/avs/avs.h +10 -27
@@ -224,39 +224,22 @@ struct avs_ipc {#define AVS_IPC_RET (ret) \ (((ret) <= 0) ? (ret) : -AVS_EIPC) -static inline void avs_ipc_err (struct avs_dev *adev,struct avs_ipc_msg *tx, -const char *name,int error) -{ -/* -* If IPC channel is blocked e.g.: due to ongoing recovery, -* -EPERM error code is expected and thus it's not an actual error. -* -* Unsupported IPCs are of no harm either. -*/ -if (error == -EPERM || error ==AVS_IPC_NOT_SUPPORTED ) -dev_dbg (adev->dev,"%s 0x%08x 0x%08x failed: %d\n" , name, - tx->glb.primary, tx->glb.ext.val, error); -else -dev_err (adev->dev,"%s 0x%08x 0x%08x failed: %d\n" , name, - tx->glb.primary, tx->glb.ext.val, error); -} -irqreturn_t avs_dsp_irq_handler (int irq,void *dev_id);irqreturn_t avs_dsp_irq_thread (int irq,void *dev_id);void avs_dsp_process_response (struct avs_dev *adev,u64 header); -int avs_dsp_send_msg_timeout (struct avs_dev *adev, -struct avs_ipc_msg *request, -struct avs_ipc_msg *reply,int timeout); -int avs_dsp_send_msg (struct avs_dev *adev, -struct avs_ipc_msg *request,struct avs_ipc_msg *reply); +int avs_dsp_send_msg_timeout (struct avs_dev *adev,struct avs_ipc_msg *request, +struct avs_ipc_msg *reply,int timeout,const char *name); +int avs_dsp_send_msg (struct avs_dev *adev,struct avs_ipc_msg *request, +struct avs_ipc_msg *reply,const char *name);/* Two variants below are for messages that control DSP power states. */ int avs_dsp_send_pm_msg_timeout (struct avs_dev *adev,struct avs_ipc_msg *request, -struct avs_ipc_msg *reply,int timeout,bool wake_d0i0); +struct avs_ipc_msg *reply,int timeout,bool wake_d0i0, +const char *name);int avs_dsp_send_pm_msg (struct avs_dev *adev,struct avs_ipc_msg *request, -struct avs_ipc_msg *reply,bool wake_d0i0); -int avs_dsp_send_rom_msg_timeout (struct avs_dev *adev, -struct avs_ipc_msg *request,int timeout); -int avs_dsp_send_rom_msg (struct avs_dev *adev,struct avs_ipc_msg *request); +struct avs_ipc_msg *reply,bool wake_d0i0,const char *name); +int avs_dsp_send_rom_msg_timeout (struct avs_dev *adev,struct avs_ipc_msg *request,int timeout, +const char *name); +int avs_dsp_send_rom_msg (struct avs_dev *adev,struct avs_ipc_msg *request,const char *name);void avs_dsp_interrupt_control (struct avs_dev *adev,bool enable);int avs_ipc_init (struct avs_ipc *ipc,struct device *dev);void avs_ipc_block (struct avs_ipc *ipc);
sound/soc/intel/avs/ipc.c +36 -16
117 lines not on this page · raw message
sound/soc/intel/avs/messages.c +19 -93
288 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 2/6 ASoC: Intel: avs: Use generic size defines
In reply to Amadeusz SławińskiInstead of using PAGE_SIZE as base of definitions in headers, use generic size defines. While x86 platforms use 4096 as page size, there are platforms which use different page sizes. Two of changed defines are for memory windows on DSP side, which have fixed size independent of host side page size. Another one is for CLDMA buffer which also doesn't need to change with page size.
--- sound/soc/intel/avs/cldma.h | 4 +++- sound/soc/intel/avs/messages.h | 4 +++- sound/soc/intel/avs/registers.h | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)
sound/soc/intel/avs/cldma.h +3 -1
@@ -8,7 +8,9 @@#ifndef __SOUND_SOC_INTEL_AVS_CLDMA_H#define __SOUND_SOC_INTEL_AVS_CLDMA_H -#define AVS_CL_DEFAULT_BUFFER_SIZE (32 * PAGE_SIZE) +#include <linux/sizes.h> + +#define AVS_CL_DEFAULT_BUFFER_SIZE SZ_128Kstruct hda_cldma ;extern struct hda_cldma code_loader;
sound/soc/intel/avs/messages.h +3 -1
@@ -9,9 +9,11 @@#ifndef __SOUND_SOC_INTEL_AVS_MSGS_H#define __SOUND_SOC_INTEL_AVS_MSGS_H +#include <linux/sizes.h> +struct avs_dev ; -#define AVS_MAILBOX_SIZE 4096 +#define AVS_MAILBOX_SIZE SZ_4Kenum avs_msg_target { AVS_FW_GEN_MSG = 0,
sound/soc/intel/avs/registers.h +3 -1
@@ -9,6 +9,8 @@#ifndef __SOUND_SOC_INTEL_AVS_REGS_H#define __SOUND_SOC_INTEL_AVS_REGS_H +#include <linux/sizes.h> +#define AZX_PCIREG_PGCTL 0x44#define AZX_PCIREG_CGCTL 0x48#define AZX_PGCTL_LSRMD_MASK BIT(4)
@@ -59,7 +61,7 @@#define AVS_FW_REG_STATUS (adev) (AVS_FW_REG_BASE(adev) + 0x0)#define AVS_FW_REG_ERROR_CODE (adev) (AVS_FW_REG_BASE(adev) + 0x4) -#define AVS_WINDOW_CHUNK_SIZE PAGE_SIZE +#define AVS_WINDOW_CHUNK_SIZE SZ_4K#define AVS_FW_REGS_SIZE AVS_WINDOW_CHUNK_SIZE#define AVS_FW_REGS_WINDOW 0/* DSP -> HOST communication window */
Signature · 1 line
2.34.1
PATCH 3/6 ASoC: Intel: avs: Preallocate memory for module configuration
In reply to Amadeusz SławińskiIn order to instantiate modules on the firmware side, the driver sends payload with module configuration. In some case size of this information is not known before hand, so driver allocates temporary memory during module creation and frees it after use. Optimize the flow a bit, by preallocating maximum buffer. This removes the time spend on allocating memory, as well as potential OOM errors during module initialization.
Handlers for modules, where configuration data fits on stack, are left as is.
--- sound/soc/intel/avs/avs.h | 1 + sound/soc/intel/avs/core.c | 5 +++++ sound/soc/intel/avs/path.c | 31 +++++++++++++++---------------- 3 files changed, 21 insertions(+), 16 deletions(-)
sound/soc/intel/avs/avs.h +1 -0
@@ -121,6 +121,7 @@ struct avs_dev {struct avs_mods_info *mods_info;struct ida **mod_idas;struct mutex modres_mutex; +void *modcfg_buf;/* module configuration buffer */ struct ida ppl_ida;struct list_head fw_list;int *core_refs;/* reference count per core */
sound/soc/intel/avs/core.c +5 -0
@@ -26,6 +26,7 @@#include "../../codecs/hda.h" #include "avs.h" #include "cldma.h" +#include "messages.h" static u32 pgctl_mask =AZX_PGCTL_LSRMD_MASK ;module_param (pgctl_mask, uint,0444 );
@@ -380,6 +381,10 @@ static int avs_bus_init(struct avs_dev *adev, struct pci_dev *pci, const structif (ret <0 )return ret; + adev->modcfg_buf =devm_kzalloc (dev,AVS_MAILBOX_SIZE ,GFP_KERNEL ); +if (!adev->modcfg_buf) +return -ENOMEM ; + adev->dev = dev; adev->spec = (const struct avs_spec *)id->driver_data; adev->ipc = ipc;
sound/soc/intel/avs/path.c +15 -16
@@ -237,11 +237,11 @@ static int avs_copier_create(struct avs_dev *adev, struct avs_path_module *mod)/* Every config-BLOB contains gateway attributes. */ if (data_size) cfg_size -=sizeof (cfg->gtw_cfg.config.attrs); +if (cfg_size >AVS_MAILBOX_SIZE ) +return -EINVAL ; - cfg =kzalloc (cfg_size,GFP_KERNEL ); -if (!cfg) -return -ENOMEM ; - + cfg = adev->modcfg_buf; +memset (cfg,0 , cfg_size); cfg->base.cpc = t->cfg_base->cpc; cfg->base.ibs = t->cfg_base->ibs; cfg->base.obs = t->cfg_base->obs;
@@ -261,7 +261,6 @@ static int avs_copier_create(struct avs_dev *adev, struct avs_path_module *mod) ret =avs_dsp_init_module (adev, mod->module_id, mod->owner->instance_id, t->core_id, t->domain, cfg, cfg_size, &mod->instance_id); -kfree (cfg);return ret; }
@@ -294,7 +293,7 @@ static int avs_peakvol_create(struct avs_dev *adev, struct avs_path_module *mod)struct avs_control_data *ctl_data;struct avs_peakvol_cfg *cfg;int volume =S32_MAX ; -size_t size; +size_t cfg_size;int ret; ctl_data =avs_get_module_control (mod);
@@ -302,11 +301,12 @@ static int avs_peakvol_create(struct avs_dev *adev, struct avs_path_module *mod) volume = ctl_data->volume;/* As 2+ channels controls are unsupported, have a single block for all channels. */ - size =struct_size (cfg, vols,1 ); - cfg =kzalloc (size,GFP_KERNEL ); -if (!cfg) -return -ENOMEM ; + cfg_size =struct_size (cfg, vols,1 ); +if (cfg_size >AVS_MAILBOX_SIZE ) +return -EINVAL ; + cfg = adev->modcfg_buf; +memset (cfg,0 , cfg_size); cfg->base.cpc = t->cfg_base->cpc; cfg->base.ibs = t->cfg_base->ibs; cfg->base.obs = t->cfg_base->obs;
@@ -318,9 +318,8 @@ static int avs_peakvol_create(struct avs_dev *adev, struct avs_path_module *mod) cfg->vols[0 ].curve_duration =0 ; ret =avs_dsp_init_module (adev, mod->module_id, mod->owner->instance_id, t->core_id, - t->domain, cfg, size, &mod->instance_id); + t->domain, cfg, cfg_size, &mod->instance_id); -kfree (cfg);return ret; }
@@ -480,10 +479,11 @@ static int avs_modext_create(struct avs_dev *adev, struct avs_path_module *mod) num_pins = tcfg->generic.num_input_pins + tcfg->generic.num_output_pins; cfg_size =struct_size (cfg, pin_fmts, num_pins); - cfg =kzalloc (cfg_size,GFP_KERNEL ); -if (!cfg) -return -ENOMEM ; +if (cfg_size >AVS_MAILBOX_SIZE ) +return -EINVAL ; + cfg = adev->modcfg_buf; +memset (cfg,0 , cfg_size); cfg->base.cpc = t->cfg_base->cpc; cfg->base.ibs = t->cfg_base->ibs; cfg->base.obs = t->cfg_base->obs;
@@ -505,7 +505,6 @@ static int avs_modext_create(struct avs_dev *adev, struct avs_path_module *mod) ret =avs_dsp_init_module (adev, mod->module_id, mod->owner->instance_id, t->core_id, t->domain, cfg, cfg_size, &mod->instance_id); -kfree (cfg);return ret; }
Signature · 1 line
2.34.1
PATCH 4/6 ASoC: Intel: avs: Keep module refcount up when gathering traces
In reply to Amadeusz SławińskiFrom: Cezary Rojewski <[email protected]>
To prevent rmmod and similar behave unexpectedly when invoked on snd_soc_avs module while the AudioDSP firmware tracing is ongoing, increase the module refcount until the tracing is stopped.
--- sound/soc/intel/avs/debugfs.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/soc/intel/avs/debugfs.c +4 -0
@@ -236,6 +236,9 @@ static int strace_open(struct inode *inode, struct file *file)struct avs_dev *adev = inode->i_private;int ret; +if (!try_module_get (adev->dev->driver->owner)) +return -ENODEV ; +if (kfifo_initialized (&adev->trace_fifo))return -EBUSY ;
@@ -270,6 +273,7 @@ static int strace_release(struct inode *inode, struct file *file)spin_unlock_irqrestore (&adev->trace_lock, flags); +module_put (adev->dev->driver->owner);return 0 ; }
Signature · 1 line
2.34.1
PATCH 5/6 ASoC: Intel: avs: Disable DSP before loading basefw
In reply to Amadeusz SławińskiFrom: Wu Zhou <[email protected]>
When audio controller is passed-through to the guest machine in virtualized environment, the basefw load will fail the next time guest OS reboots. Disable the DSP main core before loading the base firmware to sanitize the environment.
--- sound/soc/intel/avs/loader.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/soc/intel/avs/loader.c +4 -0
@@ -662,6 +662,10 @@ int avs_dsp_first_boot_firmware(struct avs_dev *adev) } } + ret =avs_dsp_core_disable (adev,AVS_MAIN_CORE_MASK ); +if (ret <0 ) +return ret; + ret =avs_dsp_boot_firmware (adev, true);if (ret <0 ) {dev_err (adev->dev,"firmware boot failed: %d\n" , ret);
Signature · 1 line
2.34.1
PATCH 6/6 ASoC: Intel: avs: Drop superfluous stream decoupling
In reply to Amadeusz SławińskiFrom: Cezary Rojewski <[email protected]>
HDAudio streams are decoupled on startup() and, decoupling them again on prepare() is redundant.
--- sound/soc/intel/avs/pcm.c | 2 -- 1 file changed, 2 deletions(-)
sound/soc/intel/avs/pcm.c +0 -2
@@ -350,7 +350,6 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct sn format_val =snd_hdac_calc_stream_format (runtime->rate, runtime->channels, runtime->format, runtime->sample_bits,0 ); -snd_hdac_ext_stream_decouple (bus, link_stream, true);snd_hdac_ext_stream_reset (link_stream);snd_hdac_ext_stream_setup (link_stream, format_val);
@@ -615,7 +614,6 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_soreturn 0 ; bus =hdac_stream (host_stream)->bus; -snd_hdac_ext_stream_decouple (bus, data->host_stream, true);snd_hdac_stream_reset (hdac_stream (host_stream)); format_val = snd_hdac_calc_stream_format(runtime->rate, runtime->channels, runtime->format,
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH 6/6] ASoC: Intel: avs: Drop superfluous stream decoupling
kernel test robot noticed the following build warnings:
Hi Amadeusz,
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 v6.6-rc3 next-20230929] [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/Amadeusz-S-awi-ski/ASoC-Intel-avs-Move-IPC-error-messages-one-level-down/20230929-192935 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next patch link: https://lore.kernel.org/r/20230929112436.787058-7-amadeuszx.slawinski%40linux.intel.com patch subject: [PATCH 6/6] ASoC: Intel: avs: Drop superfluous stream decoupling config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230929/[email protected]/config) compiler: alpha-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230929/[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 >>):
sound/soc/intel/avs/pcm.c: In function 'avs_dai_fe_prepare':
>> sound/soc/intel/avs/pcm.c:606:26: warning: variable 'bus' set but not used [-Wunused-but-set-variable]
606 | struct hdac_bus *bus;
| ^~~vim +/bus +606 sound/soc/intel/avs/pcm.c
9114700b496c6c Cezary Rojewski 2022-05-16 599
9114700b496c6c Cezary Rojewski 2022-05-16 600 static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
9114700b496c6c Cezary Rojewski 2022-05-16 601 {
9114700b496c6c Cezary Rojewski 2022-05-16 602 struct snd_pcm_runtime *runtime = substream->runtime;
9114700b496c6c Cezary Rojewski 2022-05-16 603 struct avs_dma_data *data;
9114700b496c6c Cezary Rojewski 2022-05-16 604 struct avs_dev *adev = to_avs_dev(dai->dev);
9114700b496c6c Cezary Rojewski 2022-05-16 605 struct hdac_ext_stream *host_stream;
9114700b496c6c Cezary Rojewski 2022-05-16 @606 struct hdac_bus *bus;
9114700b496c6c Cezary Rojewski 2022-05-16 607 unsigned int format_val;
9114700b496c6c Cezary Rojewski 2022-05-16 608 int ret;
9114700b496c6c Cezary Rojewski 2022-05-16 609
9114700b496c6c Cezary Rojewski 2022-05-16 610 data = snd_soc_dai_get_dma_data(dai, substream);
9114700b496c6c Cezary Rojewski 2022-05-16 611 host_stream = data->host_stream;
9114700b496c6c Cezary Rojewski 2022-05-16 612
9114700b496c6c Cezary Rojewski 2022-05-16 613 if (hdac_stream(host_stream)->prepared)
9114700b496c6c Cezary Rojewski 2022-05-16 614 return 0;
9114700b496c6c Cezary Rojewski 2022-05-16 615
9114700b496c6c Cezary Rojewski 2022-05-16 616 bus = hdac_stream(host_stream)->bus;
9114700b496c6c Cezary Rojewski 2022-05-16 617 snd_hdac_stream_reset(hdac_stream(host_stream));
9114700b496c6c Cezary Rojewski 2022-05-16 618
9114700b496c6c Cezary Rojewski 2022-05-16 619 format_val = snd_hdac_calc_stream_format(runtime->rate, runtime->channels, runtime->format,
9114700b496c6c Cezary Rojewski 2022-05-16 620 runtime->sample_bits, 0);
9114700b496c6c Cezary Rojewski 2022-05-16 621
9114700b496c6c Cezary Rojewski 2022-05-16 622 ret = snd_hdac_stream_set_params(hdac_stream(host_stream), format_val);
9114700b496c6c Cezary Rojewski 2022-05-16 623 if (ret < 0)
9114700b496c6c Cezary Rojewski 2022-05-16 624 return ret;
9114700b496c6c Cezary Rojewski 2022-05-16 625
9114700b496c6c Cezary Rojewski 2022-05-16 626 ret = snd_hdac_stream_setup(hdac_stream(host_stream));
9114700b496c6c Cezary Rojewski 2022-05-16 627 if (ret < 0)
9114700b496c6c Cezary Rojewski 2022-05-16 628 return ret;
9114700b496c6c Cezary Rojewski 2022-05-16 629
9114700b496c6c Cezary Rojewski 2022-05-16 630 ret = avs_dai_prepare(adev, substream, dai);
9114700b496c6c Cezary Rojewski 2022-05-16 631 if (ret)
9114700b496c6c Cezary Rojewski 2022-05-16 632 return ret;
9114700b496c6c Cezary Rojewski 2022-05-16 633
9114700b496c6c Cezary Rojewski 2022-05-16 634 hdac_stream(host_stream)->prepared = true;
9114700b496c6c Cezary Rojewski 2022-05-16 635 return 0;
9114700b496c6c Cezary Rojewski 2022-05-16 636 }
9114700b496c6c Cezary Rojewski 2022-05-16 637 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Mark Brown
maintainerQuoted 8 lines · Amadeusz Sławiński
Set of fixes mainly cleaning up code, but also correcting some minor HW assumptions.
Amadeusz Sławiński (2):
ASoC: Intel: avs: Use generic size defines
ASoC: Intel: avs: Preallocate memory for module configuration[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/6] ASoC: Intel: avs: Move IPC error messages one level down
commit: 26033ae6bd896d89aac4a3194ceb5dc673ce9214
[2/6] ASoC: Intel: avs: Use generic size defines
commit: 7eb878e768fd952739a03bf4bbd021496a818eb9
[3/6] ASoC: Intel: avs: Preallocate memory for module configuration
commit: 28a21cb26425797910b4d7ab0cad0d377d4a004c
[4/6] ASoC: Intel: avs: Keep module refcount up when gathering traces
commit: 0a5fb3cc28fda52c761775db2ccb7ccb954aee2a
[5/6] ASoC: Intel: avs: Disable DSP before loading basefw
commit: a5e6ea01265e9ed9ab8511907ebbc82552cd2e9e
[6/6] ASoC: Intel: avs: Drop superfluous stream decoupling
commit: b87b8f43afd5f7afd3920532942f5e9ea028d955All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark