Skip to contentSkip to conversation

ASoC: Intel: AVS - Audio DSP for cAVS

PATCH Superseded Cezary Rojewski 4 participants 35 messages Mar 9, 2022 – Mar 14, 2022

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

v4 cover ASoC: Intel: AVS - Audio DSP for cAVS

A continuation of cleanup work of Intel SST solutions found in sound/soc/intel/. With two major chapters released last year catpt [1] and removal of haswell solution [2], time has come for Skylake-driver.

Througout 2019, 2020 and 2021 Skylake-driver has had many fixes applied and even attempts of refactors as seen in fundamental overhaul [3], IPC flow adjustments [4] and LARGE_CONFIG overhaul [5] series. Unfortunately, story repeats itself - problems are found within the core of a driver. Painting it with different colors does not change the fact that is it still a house of cards. As changes needed to address those issues would make Skylake solution incompatible with its previous revisions, a decision has been made to provide a new solution instead. In time it would deprecate and replace Skylake-driver.

That solution has been called AVS - from AudioDSP architecture name:
Audio-Voice-Speech. It is meant to provide support for the exact same range of platforms as its predecessor: SKL, KBL, AML and APL.

Note: this series is dependent upon HDA-series [6] which exposes several codec-organization functions allowing for reduced code size on avs-driver side.

Note: this series does not add fully functional driver as its size would get out of control. Here, focus is put on adding IPC protocol and code loading code.

Changes v3 -> v4:
- noted the limitations of LARGE_CONFIG_GET handler and dropped non-inclusive wording as requested by Pierre and Ranjani
- code loading flow now verifies if power downing non-MAIN_CORE fails
- commented kfree() usage in FW_CONFIG and HW_CONFIG getters

Changes v2 -> v3:
- fixed variable initialization errors mentioned by sparse

Changes v1 -> v2:
Almost all updates here are thanks to feedback from Pierre.

- several comments and few kernel-docs have been added in areas which felt more or less unclear
- avs_ipc_wait_busy_completion() now spins up to 'repeats_left' number of times before giving up
- 'adsp_ba' field of struct avs_dev has been renamed to 'dsp_ba'
- 'dops' field of struct avs_spec has been renamed to 'dsp_ops'
- IPC abstraction has been simplified: SKL_ADSP_REG_HIP* regs are used directly
- fixed allnoconfig with AVS enabled compilation issues
- fixed code loading error paths: previously requested firmware is now released before function return to the caller
- code and function arguments tied to D0IX support have been removed from this patchset and will be part of followup series adding that feature instead
- enriched dev_err() messages in avs_dsp_get_core() and avs_dsp_put_core()
- numerous wording fixes used in power/reset/stall DSP operations

Changes RFC v1 [7]: -> v1:
- separated HDA codec-organization patches, path and topology handling, PCM and complementary features such as recovery from this series to ease the review process
- fixed EXPORT_SYMBOL_GPL for exported members of ASoC framework
- result of stall() is now checked when sending ROM message
- result of snd_hdac_ext_stream_set_spib() is now checked when loading basefw
- if basefw is not ready, notification processing is now skipped
- documented several topology parsing helpers

Changes [internal] RFC v2 -> [public] RFC v1:
- dropped any sysfs related changes from this series, moved to follow up one
- dropped entire subscription-mechanism found in ipc.c. Handlers that are delegated to service certain firmware notifications are now called directly
- fixed kernel doc for snd_soc_dapm_new_dai_widgets() as reported by ikp
- prefixed snd_hda_codec_device_init() as suggested by Amadeo
- improved comments for d0ix transitions for APL-based platforms as suggested by Pierre
- a ton of spelling related fixes in most of the commit messages
- fixed remaining warnings pointed by scan-build (variable assigned but not used)
- replaced most of 'cAVS X.Y' expression usages with 'platform-based' equivalents as suggested by Pierre e.g.: cAVS 1.5 -> SKL-based

Changes [internal] RFC v1 -> [internal] RFC v2:
- fixed memleak caused by lack of kfree(vols) if memory allocation fails in avs_peakvol_create() as reported by Curtis
- fixed missing 'i' iterator incrementation in avs_widget_ready() causing reference loss as reported by Curtis
- replace hardcode: 0x40 usage with snd_hdac_calc_stream_format as suggested by Curtis.
In consequence, readability for all code loading (CL) procedues has increased and such approach auto-documents the CL stream preparation

- updated behavior of all index-fetching functions found in utils.c:
avs_module_entry_index(), avs_module_id_entry_index() and follow ups:
avs_get_module_entry(), avs_get_module_id_entry() to better conform to linux-kernel standard when no entry is found (return -ENOENT) rather than C++ standard (return -1, what in kernel case translated to -EPERM) as suggested by Curtis and Peter
- several suggestions have been made regarding spacing, and so far, I've agreed and applied with all of them. None proposed seemed out of place or redundant

- avs_path_stop() renamed to avs_path_pause() pipeline states are represented by RESET/PAUSED/RUNNING. avs_path_reset() and avs_path_run() were already there and avs_path_stop() just didn't look cohesive
- added missing parsers for num_output_pin and num_input_pin which are required for custom modules such as WAVES or DSM
- dropped 'priv_param_length' from custom module descriptor as this field is obsolete in firmware

- parse_dictionary() has been split into parse_dictionary_header() and parse_dictionary_entries() to drop code duplication present in several parsing function which could not re-use entire parse_dictionary()
- added avs_tplg_vendor_array_lookup_next() and avs_tplg_vendor_entry_next() to drop code duplicated present in several parsing functions. This change greatly impacted readability of all parsers
- parsing helpers such avs_tplg_vendor_array_lookup() now return offset by updating specified in function argument list u32 *offset variable. This is to address problem when u32 offset would be greater than max int, which is the return type for these functions
- AVS_DEFINE_PTR_PARSER() macro has been introduced to drop code duplication for all ptr-parsing users

- all struct avs_path_module creators have had their declaration
updated: function argument *owner ceased to exist as it could already be accessed by mod->owner

- fixed the order of operation for conditional paths (e.g.: echo reference) so these are no longer controlled by "source" path and instead are impacted by state changes of source and sink paths both. Previously only source path e.g. playback sourcing echo reference would trigger RUNNING status for conditional path. Equivalent RUNNING on WoV path which is in this case sink path, would not do so, leading to order-of-operation problems. Behavior has been changed to: both source and sink need to be RUNNING for conditional path to be set to RUNNING too. PAUSED for either source or sink will cause PAUSED transition for conditional path.
- to achieve the above, path states are now saved in 'state' i.e. new u32 field for struct avs_path

- resigned from fw_filename field usage in favour of newly added tplg_filename for machine board descriptors as suggested by Pierre
- platform descriptor fields have had their names update better reflect their purpose as suggested by Pierre
- fixed comp_list missing locking when manipulated
- all message senders now accept request as pointer as suggeseted by Peter
- resigned of AZX_ usage for all ADSP-related registers, leaving them only for HOST memory space related operations
- fixed disable path for core DSP operations: power/reset/stall as reported by Peter

- safety when locking between received responses (reply vs notification) has been lowered as suggested by Pierre. Most usages are not performed in IRQ context and none is done in hard-IRQ one
- s/master/main/ plus AVS_MAIN_CORE_MASK has replaced ->master_mask
- several functions have had their logging updated - logs have been moved to lower level functions as suggested by Pierre
- hdac_ext_stream usage has been streamlined to estream, hdac_streams are represented by hstream instead
- hw_params() are resilient to scenarios when they are called mutliple times as reported by Pierre
- avs_dsp_enable() now collapses if any of its steps fails as reported by Pierre and Peter
- avs_module_ida_empty() now returns value of type bool as suggested by Bard

[1]: https://www.spinics.net/lists/alsa-devel/msg116440.html
[2]: https://www.spinics.net/lists/alsa-devel/msg116901.html
[3]: https://www.spinics.net/lists/alsa-devel/msg94199.html
[4]: https://www.spinics.net/lists/alsa-devel/msg92588.html
[5]: https://lore.kernel.org/all/[email protected]/
[6]: https://lore.kernel.org/alsa-devel/[email protected]/T/#t
[7]: https://lore.kernel.org/all/[email protected]/

Cezary Rojewski (17):
ALSA: hda: Add helper macros for DSP capable devices
ASoC: Export DAI register and widget ctor and dctor functions
ASoC: Intel: Introduce AVS driver
ASoC: Intel: avs: Inter process communication
ASoC: Intel: avs: Add code loading requests
ASoC: Intel: avs: Add pipeline management requests
ASoC: Intel: avs: Add module management requests
ASoC: Intel: avs: Add power management requests
ASoC: Intel: avs: Add ROM requests
ASoC: Intel: avs: Add basefw runtime-parameter requests
ASoC: Intel: avs: Firmware resources management utilities
ASoC: Intel: avs: Declare module configuration types
ASoC: Intel: avs: Dynamic firmware resources management
ASoC: Intel: avs: General code loading flow
ASoC: Intel: avs: Implement CLDMA transfer
ASoC: Intel: avs: Code loading over CLDMA
ASoC: Intel: avs: Code loading over HDA

 include/sound/hdaudio.h         |   2 +
 include/sound/hdaudio_ext.h     |  50 +++
 include/sound/soc-dapm.h        |   1 +
 sound/soc/intel/Kconfig         |  12 +
 sound/soc/intel/Makefile        |   1 +
 sound/soc/intel/avs/Makefile    |   6 +
 sound/soc/intel/avs/avs.h       | 248 +++++++++++
 sound/soc/intel/avs/cldma.c     | 317 ++++++++++++++
 sound/soc/intel/avs/cldma.h     |  29 ++
 sound/soc/intel/avs/core.c      |  62 +++
 sound/soc/intel/avs/dsp.c       | 303 +++++++++++++
 sound/soc/intel/avs/ipc.c       | 393 +++++++++++++++++
 sound/soc/intel/avs/loader.c    | 610 ++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.c  | 699 +++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h  | 753 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/registers.h |  75 ++++
 sound/soc/intel/avs/utils.c     | 301 +++++++++++++
 sound/soc/soc-core.c            |   1 +
 sound/soc/soc-dapm.c            |  15 +
 19 files changed, 3878 insertions(+)
 create mode 100644 sound/soc/intel/avs/Makefile
 create mode 100644 sound/soc/intel/avs/avs.h
 create mode 100644 sound/soc/intel/avs/cldma.c
 create mode 100644 sound/soc/intel/avs/cldma.h
 create mode 100644 sound/soc/intel/avs/core.c
 create mode 100644 sound/soc/intel/avs/dsp.c
 create mode 100644 sound/soc/intel/avs/ipc.c
 create mode 100644 sound/soc/intel/avs/loader.c
 create mode 100644 sound/soc/intel/avs/messages.c
 create mode 100644 sound/soc/intel/avs/messages.h
 create mode 100644 sound/soc/intel/avs/registers.h
 create mode 100644 sound/soc/intel/avs/utils.c
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v4 1/17 ALSA: hda: Add helper macros for DSP capable devices

HDAudio drivers make heavy use of I/O operations. Declare a range of update, read and write helpers similar to those available for HDAudio legacy driver. These macros are used by AVS driver to improve code readability.

---
 include/sound/hdaudio.h     |  2 ++
 include/sound/hdaudio_ext.h | 50 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
include/sound/hdaudio.h +2 -0
index 6a90ce405e60..69907260b9ce 100644
@@ -448,6 +448,8 @@ static inline u16 snd_hdac_reg_readw(struct hdac_bus *bus, void __iomem *addr)
 
 #define snd_hdac_reg_writel(bus, addr, val)	writel(val, addr)
 #define snd_hdac_reg_readl(bus, addr)	readl(addr)
+#define snd_hdac_reg_writeq(bus, addr, val)	writeq(val, addr)
+#define snd_hdac_reg_readq(bus, addr)		readq(addr)
 
 /*
  * macros for easy use
include/sound/hdaudio_ext.h +50 -0

62 lines not on this page · raw message

Signature · 1 line
2.25.1
Acked-by on v4 1/17
#2 lore raw

Re: [PATCH v4 01/17] ALSA: hda: Add helper macros for DSP capable devices

Quoted 7 lines · Cezary Rojewski

HDAudio drivers make heavy use of I/O operations. Declare a range of update, read and write helpers similar to those available for HDAudio legacy driver. These macros are used by AVS driver to improve code readability.

thanks,

Takashi

Quoted 89 lines
---
 include/sound/hdaudio.h     |  2 ++
 include/sound/hdaudio_ext.h | 50 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
include/sound/hdaudio.h +2 -0
index 6a90ce405e60..69907260b9ce 100644
@@ -448,6 +448,8 @@ static inline u16 snd_hdac_reg_readw(struct hdac_bus *bus, void __iomem *addr)
 
 #define snd_hdac_reg_writel(bus, addr, val)	writel(val, addr)
 #define snd_hdac_reg_readl(bus, addr)	readl(addr)
+#define snd_hdac_reg_writeq(bus, addr, val)	writeq(val, addr)
+#define snd_hdac_reg_readq(bus, addr)		readq(addr)
 
 /*
  * macros for easy use
include/sound/hdaudio_ext.h +50 -0
index b0c8e4936168..d26234f9ee46 100644
@@ -2,6 +2,8 @@
 #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,
@@ -144,6 +146,54 @@ void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
 	writew(((readw(addr + reg) & ~(mask)) | (val)), \
 		addr + reg)
 
+#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)
+#define snd_hdac_stream_readb_poll(strm, reg, val, cond, delay_us, timeout_us) \
+	readb_poll_timeout((strm)->sd_addr + AZX_REG_ ## reg, val, cond, \
+			   delay_us, timeout_us)
+#define snd_hdac_stream_readl_poll(strm, reg, val, cond, delay_us, timeout_us) \
+	readl_poll_timeout((strm)->sd_addr + AZX_REG_ ## reg, val, cond, \
+			   delay_us, timeout_us)
 
 struct hdac_ext_device;
 
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH v4 2/17 ASoC: Export DAI register and widget ctor and dctor functions

In reply to Cezary Rojewski

To allow for more flexibility i.e. populating component DAIs dynamically during its initialization, without being limited to topology loading procedure, expose snd_soc_register(), snd_soc_dapm_new_dai_widgets() and snd_soc_dapm_free_widget() functions.

Allows users to first check available resources e.g. number of PCMs supported by HDAudio codec before allocating the number of DAPM widgets needed. This prevents superfluous objects from being created or allows driver to adjust to situation when resources are limited.

---
 include/sound/soc-dapm.h |  1 +
 sound/soc/soc-core.c     |  1 +
 sound/soc/soc-dapm.c     | 15 +++++++++++++++
 3 files changed, 17 insertions(+)
include/sound/soc-dapm.h +1 -0
index c3039e97929a..ebb8e7a7fc29 100644
@@ -429,6 +429,7 @@ struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(
 		const struct snd_soc_dapm_widget *widget);
 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
 				 struct snd_soc_dai *dai);
+void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
 
sound/soc/soc-core.c +1 -0
index 259429526c84..1f0564ed3a75 100644
@@ -2465,6 +2465,7 @@ struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
 	dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
 	return dai;
 }
+EXPORT_SYMBOL_GPL(snd_soc_register_dai);
 
 /**
  * snd_soc_unregister_dais - Unregister DAIs from the ASoC core
sound/soc/soc-dapm.c +15 -0
index b06c5682445c..b435b5c4cfb7 100644
@@ -2484,6 +2484,12 @@ static void dapm_free_path(struct snd_soc_dapm_path *path)
 	kfree(path);
 }
 
+/**
+ * snd_soc_dapm_free_widget - Free specified widget
+ * @w: widget to free
+ *
+ * Removes widget from all paths and frees memory occupied by it.
+ */
 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
 {
 	struct snd_soc_dapm_path *p, *next_p;
@@ -2506,6 +2512,7 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
 	kfree_const(w->sname);
 	kfree(w);
 }
+EXPORT_SYMBOL_GPL(snd_soc_dapm_free_widget);
 
 void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm)
 {
@@ -4208,6 +4215,13 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card,
 	return ERR_PTR(ret);
 }
 
+/**
+ * snd_soc_dapm_new_dai_widgets - Create new DAPM widgets
+ * @dapm: DAPM context
+ * @dai: parent DAI
+ *
+ * Returns 0 on success, error code otherwise.
+ */
 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
 				 struct snd_soc_dai *dai)
 {
@@ -4253,6 +4267,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(snd_soc_dapm_new_dai_widgets);
 
 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
 {
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH v4 3/17 ASoC: Intel: Introduce AVS driver

In reply to Cezary Rojewski

Declare base structures and core DSP operations for the avs solution. The base structures describe PCI HDAudio bus device and platform-type differentiations. First set of operations added controls the lifecycle of any Audio DSP core: (un)powering, (un)resetting and (un)stalling.

---
 sound/soc/intel/Kconfig         |  11 ++++
 sound/soc/intel/Makefile        |   1 +
 sound/soc/intel/avs/Makefile    |   5 ++
 sound/soc/intel/avs/avs.h       |  71 +++++++++++++++++++++
 sound/soc/intel/avs/dsp.c       | 107 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/registers.h |  22 +++++++
 6 files changed, 217 insertions(+)
 create mode 100644 sound/soc/intel/avs/Makefile
 create mode 100644 sound/soc/intel/avs/avs.h
 create mode 100644 sound/soc/intel/avs/dsp.c
 create mode 100644 sound/soc/intel/avs/registers.h
sound/soc/intel/Kconfig +11 -0
index f3a4a907b29d..e9768c4aa1a9 100644
@@ -209,5 +209,16 @@ config SND_SOC_INTEL_KEEMBAY
 	  If you have a Intel Keembay platform then enable this option
 	  by saying Y or m.
 
+config SND_SOC_INTEL_AVS
+	tristate "Intel AVS driver"
+	depends on PCI && ACPI
+	depends on COMMON_CLK
+	select SND_SOC_ACPI
+	select SND_HDA_EXT_CORE
+	help
+	  Enable support for Intel(R) cAVS 1.5 platforms with DSP
+	  capabilities. This includes Skylake, Kabylake, Amberlake and
+	  Apollolake.
+
 # ASoC codec drivers
 source "sound/soc/intel/boards/Kconfig"
sound/soc/intel/Makefile +1 -0
index 7c5038803be7..d44b2652c707 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM) += atom/
 obj-$(CONFIG_SND_SOC_INTEL_CATPT) += catpt/
 obj-$(CONFIG_SND_SOC_INTEL_SKYLAKE_COMMON) += skylake/
 obj-$(CONFIG_SND_SOC_INTEL_KEEMBAY) += keembay/
+obj-$(CONFIG_SND_SOC_INTEL_AVS) += avs/
 
 # Machine support
 obj-$(CONFIG_SND_SOC) += boards/
sound/soc/intel/avs/Makefile new file +5 -0
new file mode 100644
index 000000000000..5f7976a95fe2
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+snd-soc-avs-objs := dsp.o
+
+obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/avs.h new file +71 -0

71 lines not on this page · raw message

sound/soc/intel/avs/dsp.c new file +107 -0

107 lines not on this page · raw message

sound/soc/intel/avs/registers.h new file +22 -0
new file mode 100644
index 000000000000..e0b6c8ffe633
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright(c) 2021 Intel Corporation. All rights reserved.
+ *
+ * Authors: Cezary Rojewski <[email protected]>
+ *          Amadeusz Slawinski <[email protected]>
+ */
+
+#ifndef __SOUND_SOC_INTEL_AVS_REGS_H
+#define __SOUND_SOC_INTEL_AVS_REGS_H
+
+/* Intel HD Audio General DSP Registers */
+#define AVS_ADSP_GEN_BASE		0x0
+#define AVS_ADSP_REG_ADSPCS		(AVS_ADSP_GEN_BASE + 0x04)
+
+#define AVS_ADSPCS_CRST_MASK(cm)	(cm)
+#define AVS_ADSPCS_CSTALL_MASK(cm)	((cm) << 8)
+#define AVS_ADSPCS_SPA_MASK(cm)		((cm) << 16)
+#define AVS_ADSPCS_CPA_MASK(cm)		((cm) << 24)
+#define AVS_MAIN_CORE_MASK		BIT(0)
+
+#endif /* __SOUND_SOC_INTEL_AVS_REGS_H */
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v4 03/17] ASoC: Intel: Introduce AVS driver

sound/soc/intel/avs/Makefile line 5

Quoted 13 lines
sound/soc/intel/avs/Makefile new file +5 -0
new file mode 100644
index 000000000000..5f7976a95fe2
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+snd-soc-avs-objs := dsp.o
+
+obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o

nit-pick: snd-soc-intel-avs?

avs is not a clear mapping to Intel platforms

Quoted 5 lines

+/*
+ * struct avs_dev - Intel HD-Audio driver data
+ *
+ * @dev: PCI device
+ * @dsp_ba: DSP bar address

not sure it's only limited to DSP, is it?

Quoted 17 lines

+ * @spec: platform-specific descriptor
+ */

sound/soc/intel/avs/Makefile new file +14 -0
+struct avs_dev {
+	struct hda_bus base;
+	struct device *dev;
+
+	void __iomem *dsp_ba;
+	const struct avs_spec *spec;
+};
 
+int avs_dsp_core_reset(struct avs_dev *adev, u32 core_mask, bool reset)
+{
+	u32 value, mask, reg;
+	int ret;
+
+	mask = AVS_ADSPCS_CRST_MASK(core_mask);
+	value = reset ? mask : 0;

sound/soc/intel/avs/Makefile

Quoted 10 lines
sound/soc/intel/avs/Makefile new file +10 -0
+
+	snd_hdac_adsp_updatel(adev, AVS_ADSP_REG_ADSPCS, mask, value);
+
+	ret = snd_hdac_adsp_readl_poll(adev, AVS_ADSP_REG_ADSPCS,
+				       reg, (reg & mask) == value,
+				       AVS_ADSPCS_INTERVAL_US,
+				       AVS_ADSPCS_TIMEOUT_US);
+	if (ret)
+		dev_err(adev->dev, "core_mask %d %s reset failed: %d\n",
+			core_mask, reset ? "enter" : "exit", ret);

nit-pick: reset %s "entry" "exit"

Quoted 4 lines
sound/soc/intel/avs/Makefile new file +4 -0
+
+	return ret;
+}
+
author maintainer
#6 lore raw

Re: [PATCH v4 03/17] ASoC: Intel: Introduce AVS driver

Quoted 14 lines · Pierre-Louis Bossart

sound/soc/intel/avs/Makefile line 5

Quoted 11 lines
sound/soc/intel/avs/Makefile new file +5 -0
new file mode 100644
index 000000000000..5f7976a95fe2
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+snd-soc-avs-objs := dsp.o
+
+obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o

nit-pick: snd-soc-intel-avs?

Quoted 1 line

avs is not a clear mapping to Intel platforms

We already have snd_soc_catpt : (

Quoted 7 lines
Quoted 5 lines

+/*
+ * struct avs_dev - Intel HD-Audio driver data
+ *
+ * @dev: PCI device
+ * @dsp_ba: DSP bar address

not sure it's only limited to DSP, is it?

Well, this space is classified as: "Host Device Memory Space (Audio DSP)".

Quoted 21 lines
Quoted 21 lines

+ * @spec: platform-specific descriptor
+ */

sound/soc/intel/avs/Makefile new file +18 -0
+struct avs_dev {
+    struct hda_bus base;
+    struct device *dev;
+
+    void __iomem *dsp_ba;
+    const struct avs_spec *spec;
+};
 
+int avs_dsp_core_reset(struct avs_dev *adev, u32 core_mask, bool reset)
+{
+    u32 value, mask, reg;
+    int ret;
+
+    mask = AVS_ADSPCS_CRST_MASK(core_mask);
+    value = reset ? mask : 0;
+
+    snd_hdac_adsp_updatel(adev, AVS_ADSP_REG_ADSPCS, mask, value);
+
+    ret = snd_hdac_adsp_readl_poll(adev, AVS_ADSP_REG_ADSPCS,
Quoted 8 lines
Quoted 6 lines

+                       reg, (reg & mask) == value,
+                       AVS_ADSPCS_INTERVAL_US,
+                       AVS_ADSPCS_TIMEOUT_US);
+    if (ret)
+        dev_err(adev->dev, "core_mask %d %s reset failed: %d\n", +            core_mask, reset ? "enter" : "exit", ret);

nit-pick: reset %s "entry" "exit"

I did align with what's already present in sound/hda/hdac_controller.c. It's done the other way around there. My personal opinion is: it sounds more logically the way it is currently - but I'm not a native English speaker.

Quoted 5 lines
Quoted 4 lines
sound/soc/intel/avs/Makefile new file +4 -0
+
+    return ret;
+}
+
author maintainer
#7 lore raw

PATCH v4 4/17 ASoC: Intel: avs: Inter process communication

In reply to Cezary Rojewski

Implement the IPC between Intel audio firmware and kernel driver. The IPC allows transmission of requests, handling of responses as well as unsolicited (i.e. firmware-generated) notifications.

A subscription mechanism is added to enable different parts of the driver to register for specific notifications.

The part of the DSP boot process that involves sending ROM message requires an extra step - must be followed by unstall operation of MAIN_CORE. All other types of messages do not require such specific handling, so separate set of functions is provided for sending these.

---
 sound/soc/intel/avs/Makefile    |   2 +-
 sound/soc/intel/avs/avs.h       | 100 +++++++++
 sound/soc/intel/avs/ipc.c       | 387 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h  | 170 ++++++++++++++
 sound/soc/intel/avs/registers.h |  45 ++++
 5 files changed, 703 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/intel/avs/ipc.c
 create mode 100644 sound/soc/intel/avs/messages.h
sound/soc/intel/avs/Makefile +1 -1
index 5f7976a95fe2..e243806dd38a 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-snd-soc-avs-objs := dsp.o
+snd-soc-avs-objs := dsp.o ipc.o
 
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/avs.h +100 -0

129 lines not on this page · raw message

sound/soc/intel/avs/ipc.c new file +387 -0

387 lines not on this page · raw message

sound/soc/intel/avs/messages.h new file +170 -0

170 lines not on this page · raw message

sound/soc/intel/avs/registers.h +45 -0

55 lines not on this page · raw message

Signature · 1 line
2.25.1
#8 lore raw

Re: [PATCH v4 04/17] ASoC: Intel: avs: Inter process communication

Quoted 7 lines

+/*
+ * struct avs_dsp_ops - Platform-specific DSP operations
+ *
+ * @power: Power on or off DSP cores
+ * @reset: Enter or exit reset state on DSP cores
+ * @stall: Stall or run DSP cores

nit-pick: the description sounds like boolean states. add "callback to"

Quoted 3 lines

+ * @irq_handler: Top half of IPC servicing
+ * @irq_thread: Bottom half of IPC servicing
+ * @int_control: Enable or disable IPC interrupts

callback to ...

Quoted 5 lines

+ */
struct avs_dsp_ops {
int (* const power)(struct avs_dev *, u32, bool); int (* const reset)(struct avs_dev *, u32, bool); int (* const stall)(struct avs_dev *, u32, bool);

sound/soc/intel/avs/avs.h int avs_dsp_core_stall(struct avs_dev *adev, u32 core_mask, bool stall); · line 107

Quoted 10 lines
sound/soc/intel/avs/avs.h +8 -0
+	irqreturn_t (* const irq_handler)(int, void *);
+	irqreturn_t (* const irq_thread)(int, void *);
+	void (* const int_control)(struct avs_dev *, bool);
  };
 
+/*
+ * struct avs_ipc - DSP IPC context
+ *
+ * @dev: PCI device
+ * @rx: Reply message cache

cache? I find this confusing, what are you trying to say here?

Quoted 4 lines

+ * @default_timeout_ms: default message timeout in MS
+ * @ready: whether firmware is ready and communication is open
+ * @rx_completed: whether RX for previously sent TX has been received
+ * @rx_lock: for serializating manipulation of rx_* fields

typo: serializing

Quoted 9 lines

+ * @msg_lock: for synchronizing request handling
+ * @done_completion: DONE-part of IPC i.e. ROM and ACKs from FW
+ * @busy_completion: BUSY-part of IPC i.e. receiving responses from FW
+ */

sound/soc/intel/avs/avs.h +5 -0
+struct avs_ipc {
+	struct device *dev;
+
+	struct avs_ipc_msg rx;
+	u32 default_timeout_ms;

sound/soc/intel/avs/avs.h int avs_dsp_core_stall(struct avs_dev *adev, u32 core_mask, bool stall); · line 130

Quoted 10 lines
sound/soc/intel/avs/avs.h +10 -0
+	bool ready;
+
+	bool rx_completed;
+	spinlock_t rx_lock;
+	struct mutex msg_mutex;
+	struct completion done_completion;
+	struct completion busy_completion;
+};
+
+#define AVS_EIPC	EREMOTEIO

I don't recall if I already mentioned this but I don't see the need for an intermediate redefinition of a Linux error code.

Quoted 9 lines
sound/soc/intel/avs/avs.h +9 -0
+/*
+ * IPC handlers may return positive value (firmware error code) what denotes
+ * successful HOST <-> DSP communication yet failure to process specific request.
+ *
+ * Below macro converts returned value to linux kernel error code.
+ * All IPC callers MUST use it as soon as firmware error code is consumed.
+ */
+#define AVS_IPC_RET(ret) \
+	(((ret) <= 0) ? (ret) : -AVS_EIPC)

sound/soc/intel/avs/avs.h int avs_dsp_core_stall(struct avs_dev *adev, u32 core_mask, bool stall); · line 149

Quoted 10 lines
sound/soc/intel/avs/avs.h +10 -0
+
+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.
+	 */
+	if (error == -EPERM)
+		dev_dbg(adev->dev, "%s 0x%08x 0x%08x failed: %d\n", name,

%# adds the 0x for you.

Quoted 4 lines
sound/soc/intel/avs/ipc.c new file +4 -0
+			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);

sound/soc/intel/avs/ipc.c line 36

Quoted 10 lines
sound/soc/intel/avs/ipc.c new file +9 -0
+}
 
+static void avs_dsp_process_notification(struct avs_dev *adev, u64 header)
+{
+	struct avs_notify_mod_data mod_data;
+	union avs_notify_msg msg = AVS_MSG(header);
+	size_t data_size = 0;
+	void *data = NULL;
+
+	/* Ignore spurious notifications until handshake is established. */

there's no handshake here, just an initial notification after which the IPC protocol can start?

Quoted 53 lines
sound/soc/intel/avs/ipc.c new file +53 -0
+	if (!adev->ipc->ready && msg.notify_msg_type != AVS_NOTIFY_FW_READY) {
+		dev_dbg(adev->dev, "FW not ready, skip notification: 0x%08x\n",
+			msg.primary);
+		return;
+	}
+
+	/* Calculate notification payload size. */
+	switch (msg.notify_msg_type) {
+	case AVS_NOTIFY_FW_READY:
+		break;
+
+	case AVS_NOTIFY_PHRASE_DETECTED:
+		data_size = sizeof(struct avs_notify_voice_data);
+		break;
+
+	case AVS_NOTIFY_RESOURCE_EVENT:
+		data_size = sizeof(struct avs_notify_res_data);
+		break;
+
+	case AVS_NOTIFY_MODULE_EVENT:
+		/* To know the total payload size, header needs to be read first. */
+		memcpy_fromio(&mod_data, avs_uplink_addr(adev), sizeof(mod_data));
+		data_size = sizeof(mod_data) + mod_data.data_size;
+		break;
+
+	default:
+		dev_info(adev->dev, "unknown notification: 0x%08x\n",
+			 msg.primary);
+		break;
+	}
+
+	if (data_size) {
+		data = kmalloc(data_size, GFP_KERNEL);
+		if (!data)
+			return;
+
+		memcpy_fromio(data, avs_uplink_addr(adev), data_size);
+	}
+
+	/* Perform notification-specific operations. */
+	switch (msg.notify_msg_type) {
+	case AVS_NOTIFY_FW_READY:
+		dev_dbg(adev->dev, "FW READY 0x%08x\n", msg.primary);
+		adev->ipc->ready = true;
+		complete(&adev->fw_ready);
+		break;
+
+	default:
+		break;
+	}
+
+	kfree(data);
+}
author maintainer
#9 lore raw

Re: [PATCH v4 04/17] ASoC: Intel: avs: Inter process communication

Quoted 9 lines · Pierre-Louis Bossart
Quoted 7 lines

+/*
+ * struct avs_dsp_ops - Platform-specific DSP operations
+ *
+ * @power: Power on or off DSP cores
+ * @reset: Enter or exit reset state on DSP cores
+ * @stall: Stall or run DSP cores

nit-pick: the description sounds like boolean states. add "callback to"

The title i.e. struct's description reads: *DSP operations*. And thus I believe the *DSP operation* prefix applies to everything below implicitly. Otherwise we have spam of: "A callback to do <this and that>".

Quoted 5 lines
Quoted 3 lines

+ * @irq_handler: Top half of IPC servicing
+ * @irq_thread: Bottom half of IPC servicing
+ * @int_control: Enable or disable IPC interrupts

callback to ...

Ditto.

Quoted 10 lines
Quoted 9 lines

+ */
  struct avs_dsp_ops {
      int (* const power)(struct avs_dev *, u32, bool); int (* const reset)(struct avs_dev *, u32, bool); int (* const stall)(struct avs_dev *, u32, bool); +    irqreturn_t (* const irq_handler)(int, void *); +    irqreturn_t (* const irq_thread)(int, void *); +    void (* const int_control)(struct avs_dev *, bool); };

Quoted 7 lines
Quoted 5 lines

+/*
+ * struct avs_ipc - DSP IPC context
+ *
+ * @dev: PCI device
+ * @rx: Reply message cache

cache? I find this confusing, what are you trying to say here?

The goal of that member is to reduce amount of memory allocations needed during message processing. That's why it's called cache.

Quoted 6 lines
Quoted 4 lines

+ * @default_timeout_ms: default message timeout in MS
+ * @ready: whether firmware is ready and communication is open
+ * @rx_completed: whether RX for previously sent TX has been received
+ * @rx_lock: for serializating manipulation of rx_* fields

typo: serializing

Ack.

Quoted 13 lines
Quoted 13 lines

+ * @msg_lock: for synchronizing request handling
+ * @done_completion: DONE-part of IPC i.e. ROM and ACKs from FW
+ * @busy_completion: BUSY-part of IPC i.e. receiving responses from FW
+ */

sound/soc/intel/avs/avs.h +9 -0
+struct avs_ipc {
+    struct device *dev;
+
+    struct avs_ipc_msg rx;
+    u32 default_timeout_ms;
+    bool ready;
+
+    bool rx_completed;
+    spinlock_t rx_lock;
Quoted 8 lines

sound/soc/intel/avs/avs.h int avs_dsp_core_stall(struct avs_dev *adev, u32 core_mask, bool stall); · line 130

Quoted 6 lines

+    struct mutex msg_mutex;
+    struct completion done_completion;
+    struct completion busy_completion;

sound/soc/intel/avs/avs.h +3 -0
+};
+
+#define AVS_EIPC    EREMOTEIO

I don't recall if I already mentioned this but I don't see the need for an intermediate redefinition of a Linux error code.

Hmm.. I've already explained that code makes use of this macro to differentiate between IPC protocol errors and *other* errors. Otherwise, if code gets changed, every single usage -EREMOTEIO will need to be addressed, not just AVS_EIPC declaration.

Quoted 32 lines
Quoted 15 lines

+/*
+ * IPC handlers may return positive value (firmware error code) what denotes
+ * successful HOST <-> DSP communication yet failure to process specific request.
+ *
+ * Below macro converts returned value to linux kernel error code.
+ * All IPC callers MUST use it as soon as firmware error code is consumed.
+ */

sound/soc/intel/avs/avs.h +4 -0
+#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,

Quoted 8 lines

+                   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. +     */
+    if (error == -EPERM)
+        dev_dbg(adev->dev, "%s 0x%08x 0x%08x failed: %d\n", name,

%# adds the 0x for you.

Quoted 5 lines

+            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); +}

Quoted 11 lines

sound/soc/intel/avs/ipc.c line 36

Quoted 9 lines

+static void avs_dsp_process_notification(struct avs_dev *adev, u64 header)

sound/soc/intel/avs/ipc.c new file +7 -0
+{
+    struct avs_notify_mod_data mod_data;
+    union avs_notify_msg msg = AVS_MSG(header);
+    size_t data_size = 0;
+    void *data = NULL;
+
+    /* Ignore spurious notifications until handshake is established. */

there's no handshake here, just an initial notification after which the IPC protocol can start?

There is no *real* handshake yes, but the FW_READY is sent as a response to us (the driver) programming ADSP cores and loading firmware.

Regards,
Czarek

author maintainer
#10 lore raw

PATCH v4 5/17 ASoC: Intel: avs: Add code loading requests

In reply to Cezary Rojewski

Before firmware and its modules can be used, they have to be loaded. Code loading process is complex and is a combination of DMA and IPC operations. Here, IPC part is being added and accounts for CLDMA and HDA mechanisms both.

---
 sound/soc/intel/avs/Makefile   |  2 +-
 sound/soc/intel/avs/messages.c | 65 ++++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h | 22 ++++++++++++
 3 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/intel/avs/messages.c
sound/soc/intel/avs/Makefile +1 -1
index e243806dd38a..c0824f30fd3b 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-snd-soc-avs-objs := dsp.o ipc.o
+snd-soc-avs-objs := dsp.o ipc.o messages.o
 
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/messages.c new file +65 -0

65 lines not on this page · raw message

sound/soc/intel/avs/messages.h +22 -0
index 003e634f5547..b9ec1c64179b 100644
@@ -24,6 +24,9 @@ enum avs_msg_direction {
 };
 
 enum avs_global_msg_type {
+	AVS_GLB_LOAD_MULTIPLE_MODULES = 15,
+	AVS_GLB_UNLOAD_MULTIPLE_MODULES = 16,
+	AVS_GLB_LOAD_LIBRARY = 24,
 	AVS_GLB_NOTIFICATION = 27,
 };
 
@@ -38,6 +41,16 @@ union avs_global_msg {
 				u32 msg_direction:1;
 				u32 msg_target:1;
 			};
+			/* module loading */
+			struct {
+				u32 mod_cnt:8;
+			} load_multi_mods;
+			/* library loading */
+			struct {
+				u32 dma_id:5;
+				u32 rsvd:11;
+				u32 lib_id:4;
+			} load_lib;
 		};
 		union {
 			u32 val;
@@ -84,6 +97,10 @@ union avs_reply_msg {
 		};
 		union {
 			u32 val;
+			/* module loading */
+			struct {
+				u32 err_mod_id:16;
+			} load_multi_mods;
 		} ext;
 	};
 } __packed;
@@ -167,4 +184,9 @@ struct avs_notify_mod_data {
 	u32 data[];
 } __packed;
 
+/* Code loading messages */
+int avs_ipc_load_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids);
+int avs_ipc_unload_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids);
+int avs_ipc_load_library(struct avs_dev *adev, u32 dma_id, u32 lib_id);
+
 #endif /* __SOUND_SOC_INTEL_AVS_MSGS_H */
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH v4 6/17 ASoC: Intel: avs: Add pipeline management requests

In reply to Cezary Rojewski

Pipeline represents a scheduling entity. Their existence as well as their state machine is controlled through CREATE_PIPELINE, DELETE_PIPELINE and SET_PIPELINE_STATE IPCs.

---
 sound/soc/intel/avs/messages.c | 76 ++++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h | 48 +++++++++++++++++++++
 2 files changed, 124 insertions(+)
sound/soc/intel/avs/messages.c +76 -0
index d568338b0737..de2d50f8c6b4 100644
@@ -63,3 +63,79 @@ int avs_ipc_load_library(struct avs_dev *adev, u32 dma_id, u32 lib_id)
 
 	return ret;
 }
+
+int avs_ipc_create_pipeline(struct avs_dev *adev, u16 req_size, u8 priority,
+			    u8 instance_id, bool lp, u16 attributes)
+{
+	union avs_global_msg msg = AVS_GLOBAL_REQUEST(CREATE_PIPELINE);
+	struct avs_ipc_msg request = {{0}};
+	int ret;
+
+	msg.create_ppl.ppl_mem_size = req_size;
+	msg.create_ppl.ppl_priority = priority;
+	msg.create_ppl.instance_id = instance_id;
+	msg.ext.create_ppl.lp = lp;
+	msg.ext.create_ppl.attributes = attributes;
+	request.header = msg.val;
+
+	ret = avs_dsp_send_msg(adev, &request, NULL);
+	if (ret)
+		avs_ipc_err(adev, &request, "create pipeline", ret);
+
+	return ret;
+}
+
+int avs_ipc_delete_pipeline(struct avs_dev *adev, u8 instance_id)
+{
+	union avs_global_msg msg = AVS_GLOBAL_REQUEST(DELETE_PIPELINE);
+	struct avs_ipc_msg request = {{0}};
+	int ret;
+
+	msg.ppl.instance_id = instance_id;
+	request.header = msg.val;
+
+	ret = avs_dsp_send_msg(adev, &request, NULL);
+	if (ret)
+		avs_ipc_err(adev, &request, "delete pipeline", ret);
+
+	return ret;
+}
+
+int avs_ipc_set_pipeline_state(struct avs_dev *adev, u8 instance_id,
+			       enum avs_pipeline_state state)
+{
+	union avs_global_msg msg = AVS_GLOBAL_REQUEST(SET_PIPELINE_STATE);
+	struct avs_ipc_msg request = {{0}};
+	int ret;
+
+	msg.set_ppl_state.ppl_id = instance_id;
+	msg.set_ppl_state.state = state;
+	request.header = msg.val;
+
+	ret = avs_dsp_send_msg(adev, &request, NULL);
+	if (ret)
+		avs_ipc_err(adev, &request, "set pipeline state", ret);
+
+	return ret;
+}
+
+int avs_ipc_get_pipeline_state(struct avs_dev *adev, u8 instance_id,
+			       enum avs_pipeline_state *state)
+{
+	union avs_global_msg msg = AVS_GLOBAL_REQUEST(GET_PIPELINE_STATE);
+	struct avs_ipc_msg request = {{0}};
+	struct avs_ipc_msg reply = {{0}};
+	int ret;
+
+	msg.get_ppl_state.ppl_id = instance_id;
+	request.header = msg.val;
+
+	ret = avs_dsp_send_msg(adev, &request, &reply);
+	if (ret) {
+		avs_ipc_err(adev, &request, "get pipeline state", ret);
+		return ret;
+	}
+
+	*state = reply.rsp.ext.get_ppl_state.state;
+	return ret;
+}
sound/soc/intel/avs/messages.h +48 -0

76 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#12 lore raw

PATCH v4 7/17 ASoC: Intel: avs: Add module management requests

In reply to Cezary Rojewski

Firmware modules implement processing algorithms. Their lifecycle, similarly to pipelines is being controlled by IPCs: initialization, deletion and (un)binding.

Modules can be configured at runtime - runtime parameters. This is done with help of LARGE_CONFIG IPCs: getter and setter.

Due to firmware limitations, LARGE_CONFIG_GET handler implementation does not support retrieving payload with size larger than IPC inbox window size.

---
 sound/soc/intel/avs/ipc.c      |   8 +-
 sound/soc/intel/avs/messages.c | 262 +++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h |  53 +++++++
 3 files changed, 322 insertions(+), 1 deletion(-)
sound/soc/intel/avs/ipc.c +7 -1
index c0722f8b195f..9770368a898e 100644
@@ -21,9 +21,15 @@ static void avs_dsp_receive_rx(struct avs_dev *adev, u64 header)
 
 	ipc->rx.header = header;
 	/* Abort copying payload if request processing was unsuccessful. */
-	if (!msg.status)
+	if (!msg.status) {
+		/* update size in case of LARGE_CONFIG_GET */
+		if (msg.msg_target == AVS_MOD_MSG &&
+		    msg.global_msg_type == AVS_MOD_LARGE_CONFIG_GET)
+			ipc->rx.size = msg.ext.large_config.data_off_size;
+
 		memcpy_fromio(ipc->rx.data, avs_uplink_addr(adev),
 			      ipc->rx.size);
+	}
 }
 
 static void avs_dsp_process_notification(struct avs_dev *adev, u64 header)
sound/soc/intel/avs/messages.c +262 -0

271 lines not on this page · raw message

sound/soc/intel/avs/messages.h +53 -0

75 lines not on this page · raw message

Signature · 1 line
2.25.1
#13 lore raw

Re: [PATCH v4 07/17] ASoC: Intel: avs: Add module management requests

Quoted 14 lines

+/*
+ * avs_ipc_delete_instance - Delete module instance
+ *
+ * @adev: Driver context
+ * @module_id: Module-type id
+ * @instance_id: Unique module instance id
+ *
+ * Argument verification, as well as pipeline state checks are done by the
+ * firmware.
+ *
+ * Note: only standalone modules i.e. without a parent pipeline shall be
+ * deleted using this IPC message. In all other cases, pipeline owning the
+ * modules peforms cleanup automatically when it is deleted.

typo: performs

checkpatch.pl --strict --codespell would detect all this for you.

Quoted 17 lines

+ */

sound/soc/intel/avs/messages.c +16 -0
+int avs_ipc_delete_instance(struct avs_dev *adev, u16 module_id, u8 instance_id)
+{
+	union avs_module_msg msg = AVS_MODULE_REQUEST(DELETE_INSTANCE);
+	struct avs_ipc_msg request = {{0}};
+	int ret;
+
+	msg.module_id = module_id;
+	msg.instance_id = instance_id;
+	request.header = msg.val;
+
+	ret = avs_dsp_send_msg(adev, &request, NULL);
+	if (ret)
+		avs_ipc_err(adev, &request, "delete instance", ret);
+
+	return ret;
+}
author maintainer
#14 lore raw

Re: [PATCH v4 07/17] ASoC: Intel: avs: Add module management requests

Quoted 17 lines · Pierre-Louis Bossart
Quoted 16 lines

+/*
+ * avs_ipc_delete_instance - Delete module instance
+ *
+ * @adev: Driver context
+ * @module_id: Module-type id
+ * @instance_id: Unique module instance id
+ *
+ * Argument verification, as well as pipeline state checks are done by the
+ * firmware.
+ *
+ * Note: only standalone modules i.e. without a parent pipeline shall be
+ * deleted using this IPC message. In all other cases, pipeline owning the
+ * modules peforms cleanup automatically when it is deleted.

Quoted 3 lines

typo: performs

checkpatch.pl --strict --codespell would detect all this for you.

Ack.

author maintainer
#15 lore raw

PATCH v4 8/17 ASoC: Intel: avs: Add power management requests

In reply to Cezary Rojewski

Audio DSP supports low power states i.e.: transitions between D0 and D3 and D0-substates in form of D0i0 and D0i3. That process is a combination of core and IPC operations. Here, Dx and D0ix IPC handlers are added.

---
 sound/soc/intel/avs/messages.c | 44 ++++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h | 15 ++++++++++++
 2 files changed, 59 insertions(+)
sound/soc/intel/avs/messages.c +44 -0
index 613c9452226d..e8f441b28d71 100644
@@ -401,3 +401,47 @@ int avs_ipc_get_large_config(struct avs_dev *adev, u16 module_id, u8 instance_id
 
 	return 0;
 }
+
+int avs_ipc_set_dx(struct avs_dev *adev, u32 core_mask, bool powerup)
+{
+	union avs_module_msg msg = AVS_MODULE_REQUEST(SET_DX);
+	struct avs_ipc_msg request;
+	struct avs_dxstate_info dx;
+	int ret;
+
+	dx.core_mask = core_mask;
+	dx.dx_mask = powerup ? core_mask : 0;
+	request.header = msg.val;
+	request.data = &dx;
+	request.size = sizeof(dx);
+
+	ret = avs_dsp_send_msg(adev, &request, NULL);
+	if (ret)
+		avs_ipc_err(adev, &request, "set dx", ret);
+
+	return ret;
+}
+
+/*
+ * avs_ipc_set_d0ix - Set power gating policy (entering D0IX substates)
+ *
+ * @enable_pg: Whether to enable or disable power gating
+ * @streaming: Whether a stream is running when transitioning
+ */
+int avs_ipc_set_d0ix(struct avs_dev *adev, bool enable_pg, bool streaming)
+{
+	union avs_module_msg msg = AVS_MODULE_REQUEST(SET_D0IX);
+	struct avs_ipc_msg request = {{0}};
+	int ret;
+
+	msg.ext.set_d0ix.wake = enable_pg;
+	msg.ext.set_d0ix.streaming = streaming;
+
+	request.header = msg.val;
+
+	ret = avs_dsp_send_msg(adev, &request, NULL);
+	if (ret)
+		avs_ipc_err(adev, &request, "set d0ix", ret);
+
+	return ret;
+}
sound/soc/intel/avs/messages.h +15 -0
index e4b95b066d70..69920f5e802b 100644
@@ -97,6 +97,8 @@ enum avs_module_msg_type {
 	AVS_MOD_LARGE_CONFIG_SET = 4,
 	AVS_MOD_BIND = 5,
 	AVS_MOD_UNBIND = 6,
+	AVS_MOD_SET_DX = 7,
+	AVS_MOD_SET_D0IX = 8,
 	AVS_MOD_DELETE_INSTANCE = 11,
 };
 
@@ -133,6 +135,10 @@ union avs_module_msg {
 				u32 dst_queue:3;
 				u32 src_queue:3;
 			} bind_unbind;
+			struct {
+				u32 wake:1;
+				u32 streaming:1;
+			} set_d0ix;
 		} ext;
 	};
 } __packed;
@@ -290,4 +296,13 @@ int avs_ipc_get_large_config(struct avs_dev *adev, u16 module_id, u8 instance_id
 			     u8 param_id, u8 *request_data, size_t request_size,
 			     u8 **reply_data, size_t *reply_size);
 
+/* DSP cores and domains power management messages */
+struct avs_dxstate_info {
+	u32 core_mask;	/* which cores are subject for power transition */
+	u32 dx_mask;	/* bit[n]=1 core n goes to D0, bit[n]=0 it goes to D3 */
+} __packed;
+
+int avs_ipc_set_dx(struct avs_dev *adev, u32 core_mask, bool powerup);
+int avs_ipc_set_d0ix(struct avs_dev *adev, bool enable_pg, bool streaming);
+
 #endif /* __SOUND_SOC_INTEL_AVS_MSGS_H */
Signature · 1 line
2.25.1
author maintainer
#16 lore raw

PATCH v4 9/17 ASoC: Intel: avs: Add ROM requests

In reply to Cezary Rojewski

ROM requests are messages initiated by Host to alter firmware early boot process. They specify whether the next boot should be a fresh start or if IMR can be used to speed things up.

---
 sound/soc/intel/avs/messages.c | 18 ++++++++++++++++++
 sound/soc/intel/avs/messages.h | 14 ++++++++++++++
 2 files changed, 32 insertions(+)
sound/soc/intel/avs/messages.c +18 -0
index e8f441b28d71..f7d00e541323 100644
@@ -12,6 +12,24 @@
 
 #define AVS_CL_TIMEOUT_MS	5000
 
+int avs_ipc_set_boot_config(struct avs_dev *adev, u32 dma_id, u32 purge)
+{
+	union avs_global_msg msg = AVS_GLOBAL_REQUEST(ROM_CONTROL);
+	struct avs_ipc_msg request = {{0}};
+	int ret;
+
+	msg.boot_cfg.rom_ctrl_msg_type = AVS_ROM_SET_BOOT_CONFIG;
+	msg.boot_cfg.dma_id = dma_id;
+	msg.boot_cfg.purge_request = purge;
+	request.header = msg.val;
+
+	ret = avs_dsp_send_rom_msg(adev, &request);
+	if (ret)
+		avs_ipc_err(adev, &request, "set boot config", ret);
+
+	return ret;
+}
+
 int avs_ipc_load_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids)
 {
 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(LOAD_MULTIPLE_MODULES);
sound/soc/intel/avs/messages.h +14 -0
index 69920f5e802b..615a61cef4f6 100644
@@ -24,6 +24,7 @@ enum avs_msg_direction {
 };
 
 enum avs_global_msg_type {
+	AVS_GLB_ROM_CONTROL = 1,
 	AVS_GLB_LOAD_MULTIPLE_MODULES = 15,
 	AVS_GLB_UNLOAD_MULTIPLE_MODULES = 16,
 	AVS_GLB_CREATE_PIPELINE = 17,
@@ -45,6 +46,12 @@ union avs_global_msg {
 				u32 msg_direction:1;
 				u32 msg_target:1;
 			};
+			/* set boot config */
+			struct {
+				u32 rom_ctrl_msg_type:9;
+				u32 dma_id:5;
+				u32 purge_request:1;
+			} boot_cfg;
 			/* module loading */
 			struct {
 				u32 mod_cnt:8;
@@ -255,6 +262,13 @@ struct avs_notify_mod_data {
 	u32 data[];
 } __packed;
 
+/* ROM messages */
+enum avs_rom_control_msg_type {
+	AVS_ROM_SET_BOOT_CONFIG = 0,
+};
+
+int avs_ipc_set_boot_config(struct avs_dev *adev, u32 dma_id, u32 purge);
+
 /* Code loading messages */
 int avs_ipc_load_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids);
 int avs_ipc_unload_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids);
Signature · 1 line
2.25.1
author maintainer
#17 lore raw

PATCH v4 10/17 ASoC: Intel: avs: Add basefw runtime-parameter requests

In reply to Cezary Rojewski

Each module may expose a range of runtime parameters. For basefw, implement handlers for: FIRMWARE_CONFIG, HARDWARE_CONFIG and MODULES_INFO. These are used by driver to dynamically allocate resources in respect to platform details, reducing number of hardcodes and code duplications that would otherwise be needed to be defined within the driver code.

---
 sound/soc/intel/avs/messages.c | 217 +++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/messages.h | 179 +++++++++++++++++++++++++++
 2 files changed, 396 insertions(+)
sound/soc/intel/avs/messages.c +217 -0
index f7d00e541323..4e7a2972da6d 100644
@@ -463,3 +463,220 @@ int avs_ipc_set_d0ix(struct avs_dev *adev, bool enable_pg, bool streaming)
 
 	return ret;
 }
+
+int avs_ipc_get_fw_config(struct avs_dev *adev, struct avs_fw_cfg *cfg)
+{
+	struct avs_tlv *tlv;
+	size_t payload_size;
+	size_t offset = 0;
+	u8 *payload;
+	int ret;
+
+	ret = avs_ipc_get_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
+				       AVS_BASEFW_FIRMWARE_CONFIG, NULL, 0,
+				       &payload, &payload_size);
+	if (ret)
+		return ret;
+
+	while (offset < payload_size) {
+		tlv = (struct avs_tlv *)(payload + offset);
+
+		switch (tlv->type) {
+		case AVS_FW_CFG_FW_VERSION:
+			memcpy(&cfg->fw_version, tlv->value,
+				sizeof(cfg->fw_version));
+			break;
+
+		case AVS_FW_CFG_MEMORY_RECLAIMED:
+			cfg->memory_reclaimed = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_SLOW_CLOCK_FREQ_HZ:
+			cfg->slow_clock_freq_hz = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_FAST_CLOCK_FREQ_HZ:
+			cfg->fast_clock_freq_hz = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_ALH_SUPPORT_LEVEL:
+			cfg->alh_support = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_IPC_DL_MAILBOX_BYTES:
+			cfg->ipc_dl_mailbox_bytes = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_IPC_UL_MAILBOX_BYTES:
+			cfg->ipc_ul_mailbox_bytes = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_TRACE_LOG_BYTES:
+			cfg->trace_log_bytes = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_PPL_COUNT:
+			cfg->max_ppl_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_ASTATE_COUNT:
+			cfg->max_astate_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_MODULE_PIN_COUNT:
+			cfg->max_module_pin_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MODULES_COUNT:
+			cfg->modules_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_MOD_INST_COUNT:
+			cfg->max_mod_inst_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_LL_TASKS_PER_PRI_COUNT:
+			cfg->max_ll_tasks_per_pri_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_LL_PRI_COUNT:
+			cfg->ll_pri_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_DP_TASKS_COUNT:
+			cfg->max_dp_tasks_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_MAX_LIBS_COUNT:
+			cfg->max_libs_count = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_XTAL_FREQ_HZ:
+			cfg->xtal_freq_hz = *tlv->value;
+			break;
+
+		case AVS_FW_CFG_POWER_GATING_POLICY:
+			cfg->power_gating_policy = *tlv->value;
+			break;
+
+		/* Known but not useful to us. */
+		case AVS_FW_CFG_DMA_BUFFER_CONFIG:
+		case AVS_FW_CFG_SCHEDULER_CONFIG:
+		case AVS_FW_CFG_CLOCKS_CONFIG:
+			break;
+
+		default:
+			dev_info(adev->dev, "Unrecognized fw param: %d\n",
+				 tlv->type);
+			break;
+		}
+
+		offset += sizeof(*tlv) + tlv->length;
+	}
+
+	/* No longer needed, free it as it's owned by the get_large_config() caller. */
+	kfree(payload);
+	return ret;
+}
+
+int avs_ipc_get_hw_config(struct avs_dev *adev, struct avs_hw_cfg *cfg)
+{
+	struct avs_tlv *tlv;
+	size_t payload_size;
+	size_t size, offset = 0;
+	u8 *payload;
+	int ret;
+
+	ret = avs_ipc_get_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
+				       AVS_BASEFW_HARDWARE_CONFIG, NULL, 0,
+				       &payload, &payload_size);
+	if (ret)
+		return ret;
+
+	while (offset < payload_size) {
+		tlv = (struct avs_tlv *)(payload + offset);
+
+		switch (tlv->type) {
+		case AVS_HW_CFG_AVS_VER:
+			cfg->avs_version = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_DSP_CORES:
+			cfg->dsp_cores = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_MEM_PAGE_BYTES:
+			cfg->mem_page_bytes = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_TOTAL_PHYS_MEM_PAGES:
+			cfg->total_phys_mem_pages = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_I2S_CAPS:
+			cfg->i2s_caps.i2s_version = tlv->value[0];
+			size = tlv->value[1];
+			cfg->i2s_caps.ctrl_count = size;
+			if (!size)
+				break;
+
+			/* Multiply to get entire array size. */
+			size *= sizeof(*cfg->i2s_caps.ctrl_base_addr);
+			cfg->i2s_caps.ctrl_base_addr = devm_kmemdup(adev->dev,
+								    &tlv->value[2],
+								    size, GFP_KERNEL);
+			if (!cfg->i2s_caps.ctrl_base_addr) {
+				ret = -ENOMEM;
+				goto exit;
+			}
+			break;
+
+		case AVS_HW_CFG_GATEWAY_COUNT:
+			cfg->gateway_count = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_HP_EBB_COUNT:
+			cfg->hp_ebb_count = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_LP_EBB_COUNT:
+			cfg->lp_ebb_count = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_EBB_SIZE_BYTES:
+			cfg->ebb_size_bytes = *tlv->value;
+			break;
+
+		case AVS_HW_CFG_GPDMA_CAPS:
+			break;
+
+		default:
+			dev_info(adev->dev, "Unrecognized hw config: %d\n",
+				 tlv->type);
+			break;
+		}
+
+		offset += sizeof(*tlv) + tlv->length;
+	}
+
+exit:
+	/* No longer needed, free it as it's owned by the get_large_config() caller. */
+	kfree(payload);
+	return ret;
+}
+
+int avs_ipc_get_modules_info(struct avs_dev *adev, struct avs_mods_info **info)
+{
+	size_t payload_size;
+	u8 *payload;
+	int ret;
+
+	ret = avs_ipc_get_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
+				       AVS_BASEFW_MODULES_INFO, NULL, 0,
+				       &payload, &payload_size);
+	if (ret)
+		return ret;
+
+	*info = (struct avs_mods_info *)payload;
+	return 0;
+}
sound/soc/intel/avs/messages.h +179 -0

183 lines not on this page · raw message

Signature · 1 line
2.25.1
#18 lore raw

Re: [PATCH v4 10/17] ASoC: Intel: avs: Add basefw runtime-parameter requests

sound/soc/intel/avs/messages.h struct avs_dxstate_info { · line 412

Quoted 5 lines
sound/soc/intel/avs/messages.h +3 -0
+enum avs_i2s_version {
+	AVS_I2S_VER_15_SKYLAKE   = 0x00000,
+	AVS_I2S_VER_15_BROXTON   = 0x10000,

I would add a comment that this is added for completeness but not tested/supported.

Quoted 3 lines
sound/soc/intel/avs/messages.h +3 -0
+	AVS_I2S_VER_15_BROXTON_P = 0x20000,
+	AVS_I2S_VER_18_KBL_CNL   = 0x30000,
+};
author maintainer
#19 lore raw

PATCH v4 11/17 ASoC: Intel: avs: Firmware resources management utilities

In reply to Cezary Rojewski

With basefw runtime parameter handlers added, implement utility functions to ease pipelines and modules allocation. IDA is enlisted to help with that.

As firmware is modular and multiple binaries can be loaded on-demand depending on the streaming scenario, custom firmware caching mechanism is added.

---
 sound/soc/intel/avs/Makefile |   2 +-
 sound/soc/intel/avs/avs.h    |  37 +++++
 sound/soc/intel/avs/utils.c  | 301 +++++++++++++++++++++++++++++++++++
 3 files changed, 339 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/intel/avs/utils.c
sound/soc/intel/avs/Makefile +1 -1
index c0824f30fd3b..d9f92c5f5407 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-snd-soc-avs-objs := dsp.o ipc.o messages.o
+snd-soc-avs-objs := dsp.o ipc.o messages.o utils.o
 
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/avs.h +37 -0
index 841b8541b101..02d7591d0eac 100644
@@ -53,12 +53,26 @@ struct avs_spec {
 	const u32 rom_status;
 };
 
+struct avs_fw_entry {
+	char *name;
+	const struct firmware *fw;
+
+	struct list_head node;
+};
+
 /*
  * struct avs_dev - Intel HD-Audio driver data
  *
  * @dev: PCI device
  * @dsp_ba: DSP bar address
  * @spec: platform-specific descriptor
+ * @fw_cfg: Firmware configuration, obtained through FW_CONFIG message
+ * @hw_cfg: Hardware configuration, obtained through HW_CONFIG message
+ * @mods_info: Available module-types, obtained through MODULES_INFO message
+ * @mod_idas: Module instance ID pool, one per module-type
+ * @modres_mutex: For synchronizing any @mods_info updates
+ * @ppl_ida: Pipeline instance ID pool
+ * @fw_list: List of libraries loaded, including base firmware
  */
 struct avs_dev {
 	struct hda_bus base;
@@ -68,6 +82,14 @@ struct avs_dev {
 	const struct avs_spec *spec;
 	struct avs_ipc *ipc;
 
+	struct avs_fw_cfg fw_cfg;
+	struct avs_hw_cfg hw_cfg;
+	struct avs_mods_info *mods_info;
+	struct ida **mod_idas;
+	struct mutex modres_mutex;
+	struct ida ppl_ida;
+	struct list_head fw_list;
+
 	struct completion fw_ready;
 };
 
@@ -168,4 +190,19 @@ 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);
 
+/* Firmware resources management */
+
+int avs_get_module_entry(struct avs_dev *adev, const guid_t *uuid, struct avs_module_entry *entry);
+int avs_get_module_id_entry(struct avs_dev *adev, u32 module_id, struct avs_module_entry *entry);
+int avs_get_module_id(struct avs_dev *adev, const guid_t *uuid);
+bool avs_is_module_ida_empty(struct avs_dev *adev, u32 module_id);
+
+int avs_module_info_init(struct avs_dev *adev, bool purge);
+void avs_module_info_free(struct avs_dev *adev);
+int avs_module_id_alloc(struct avs_dev *adev, u16 module_id);
+void avs_module_id_free(struct avs_dev *adev, u16 module_id, u8 instance_id);
+int avs_request_firmware(struct avs_dev *adev, const struct firmware **fw_p, const char *name);
+void avs_release_last_firmware(struct avs_dev *adev);
+void avs_release_firmwares(struct avs_dev *adev);
+
 #endif /* __SOUND_SOC_INTEL_AVS_H */
sound/soc/intel/avs/utils.c new file +301 -0

301 lines not on this page · raw message

Signature · 1 line
2.25.1
#20 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 10 lines

/*
* struct avs_dev - Intel HD-Audio driver data
*
* @dev: PCI device
* @dsp_ba: DSP bar address
* @spec: platform-specific descriptor
+ * @fw_cfg: Firmware configuration, obtained through FW_CONFIG message
+ * @hw_cfg: Hardware configuration, obtained through HW_CONFIG message
+ * @mods_info: Available module-types, obtained through MODULES_INFO message

is this just for the base firmware? If this includes the extensions, how are the module types defined?

Quoted 40 lines

+ * @mod_idas: Module instance ID pool, one per module-type
+ * @modres_mutex: For synchronizing any @mods_info updates
+ * @ppl_ida: Pipeline instance ID pool
+ * @fw_list: List of libraries loaded, including base firmware */
struct avs_dev {
struct hda_bus base;

(quoted diff) +26 -0
@@ -68,6 +82,14 @@ struct avs_dev {
  	const struct avs_spec *spec;
  	struct avs_ipc *ipc;
 
+	struct avs_fw_cfg fw_cfg;
+	struct avs_hw_cfg hw_cfg;
+	struct avs_mods_info *mods_info;
+	struct ida **mod_idas;
+	struct mutex modres_mutex;
+	struct ida ppl_ida;
+	struct list_head fw_list;
+
  	struct completion fw_ready;
  };
 
+/* Caller responsible for holding adev->modres_mutex. */
+static int
+avs_module_ida_alloc(struct avs_dev *adev, struct avs_mods_info *newinfo, bool purge)
+{
+	struct avs_mods_info *oldinfo = adev->mods_info;
+	struct ida **ida_ptrs;
+	u32 tocopy_count = 0;
+	int i;
+
+	if (!purge && oldinfo) {
+		if (oldinfo->count >= newinfo->count)
+			dev_warn(adev->dev, "refreshing %d modules info with %d\n",
+				 oldinfo->count, newinfo->count);
+		tocopy_count = oldinfo->count;
+	}
+
+	ida_ptrs = kcalloc(newinfo->count, sizeof(*ida_ptrs), GFP_KERNEL);
+	if (!ida_ptrs)

Review struct avs_dev {

Quoted 10 lines
(quoted diff) +10 -0
+		return -ENOMEM;
+
+	if (tocopy_count)
+		memcpy(ida_ptrs, adev->mod_idas, tocopy_count * sizeof(*ida_ptrs));
+
+	for (i = tocopy_count; i < newinfo->count; i++) {
+		ida_ptrs[i] = kzalloc(sizeof(**ida_ptrs), GFP_KERNEL);
+		if (!ida_ptrs[i]) {
+			while (i--)
+				kfree(ida_ptrs[i]);

it's a bit hairy to play with the loop counter, I would jump to an error handling label to make it clearer.

sound/soc/intel/avs/utils.c line 146

Quoted 9 lines
sound/soc/intel/avs/utils.c new file +9 -0
+
+			kfree(ida_ptrs);
+			return -ENOMEM;
+		}
+
+		ida_init(ida_ptrs[i]);
+	}
+
+	/* If old elements have been reused, don't wipe them. */

the comment is very odd, there's either a free() or a destroy() happening below...

Quoted 8 lines
sound/soc/intel/avs/utils.c new file +8 -0
+	if (tocopy_count)
+		kfree(adev->mod_idas);
+	else
+		avs_module_ida_destroy(adev);
+
+	adev->mod_idas = ida_ptrs;
+	return 0;
+}

sound/soc/intel/avs/utils.c line 201

Quoted 10 lines
sound/soc/intel/avs/utils.c new file +9 -0
 
+int avs_module_id_alloc(struct avs_dev *adev, u16 module_id)
+{
+	int ret, idx, max_id;
+
+	mutex_lock(&adev->modres_mutex);
+
+	idx = avs_module_id_entry_index(adev, module_id);
+	if (idx == -ENOENT) {
+		WARN(1, "invalid module id: %d", module_id);

dev_err() seems to be more than enough, why would you add a complete call trace?

Quoted 9 lines
sound/soc/intel/avs/utils.c new file +9 -0
+		ret = -EINVAL;
+		goto exit;
+	}
+	max_id = adev->mods_info->entries[idx].instance_max_count - 1;
+	ret = ida_alloc_max(adev->mod_idas[idx], max_id, GFP_KERNEL);
+exit:
+	mutex_unlock(&adev->modres_mutex);
+	return ret;
+}

sound/soc/intel/avs/utils.c line 220

Quoted 10 lines
sound/soc/intel/avs/utils.c new file +10 -0
+
+void avs_module_id_free(struct avs_dev *adev, u16 module_id, u8 instance_id)
+{
+	int idx;
+
+	mutex_lock(&adev->modres_mutex);
+
+	idx = avs_module_id_entry_index(adev, module_id);
+	if (idx == -ENOENT) {
+		WARN(1, "invalid module id: %d", module_id);

same WARN is over-engineered.

sound/soc/intel/avs/utils.c line 229

Quoted 9 lines
sound/soc/intel/avs/utils.c new file +9 -0
+		goto exit;
+	}
+
+	ida_free(adev->mod_idas[idx], instance_id);
+exit:
+	mutex_unlock(&adev->modres_mutex);
+}
+
+/*

I am running out of time and will resume this review next week.

author maintainer
#21 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 1 line · Pierre-Louis Bossart

I am running out of time and will resume this review next week.

Hello,

I don't believe any of the comments provided are a strong reason for re-send. Given that last revisions were mostly related to addressing comments, rewords and explaining stuff, series is in good shape and ready for merge. As I already stated, team continues to work on the subject and there are more patch-series to come.

Regards,
Czarek

maintainer
#22 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 5 lines · Cezary Rojewski

I don't believe any of the comments provided are a strong reason for re-send. Given that last revisions were mostly related to addressing comments, rewords and explaining stuff, series is in good shape and ready for merge. As I already stated, team continues to work on the subject and there are more patch-series to come.

It'd be good to get the WARN()s fixed.

author maintainer
#23 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 9 lines · Mark Brown
Quoted 5 lines · Cezary Rojewski

I don't believe any of the comments provided are a strong reason for re-send. Given that last revisions were mostly related to addressing comments, rewords and explaining stuff, series is in good shape and ready for merge. As I already stated, team continues to work on the subject and there are more patch-series to come.

It'd be good to get the WARN()s fixed.

Ack. Addressed in v5.

author maintainer
#24 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

In reply to Pierre-Louis Bossart
Quoted 12 lines · Pierre-Louis Bossart
Quoted 11 lines

  /*
   * struct avs_dev - Intel HD-Audio driver data
   *
   * @dev: PCI device
   * @dsp_ba: DSP bar address
   * @spec: platform-specific descriptor
+ * @fw_cfg: Firmware configuration, obtained through FW_CONFIG message
+ * @hw_cfg: Hardware configuration, obtained through HW_CONFIG message
+ * @mods_info: Available module-types, obtained through MODULES_INFO message

Quoted 1 line

is this just for the base firmware? If this includes the extensions, how are the module types defined?

Only base firmware is able to process MODULE_INFO getter. So, every time driver loads a library, this info gets updated internally on the firmware side. We make use of said getter to retrieve up-to-date information and cache in ->mods_info for later use. ->mods_info is a member of type struct avs_mods_info with each enter represented by struct avs_module_info. These are introduced with all the basefw runtime parameters.

Quoted 20 lines
Quoted 20 lines

+ * @mod_idas: Module instance ID pool, one per module-type
+ * @modres_mutex: For synchronizing any @mods_info updates
+ * @ppl_ida: Pipeline instance ID pool
+ * @fw_list: List of libraries loaded, including base firmware */
  struct avs_dev {
      struct hda_bus base;

sound/soc/intel/avs/avs.h +8 -0
@@ -68,6 +82,14 @@ struct avs_dev {
       const struct avs_spec *spec;
       struct avs_ipc *ipc;
+    struct avs_fw_cfg fw_cfg;
+    struct avs_hw_cfg hw_cfg;
+    struct avs_mods_info *mods_info;
+    struct ida **mod_idas;
+    struct mutex modres_mutex;
+    struct ida ppl_ida;
+    struct list_head fw_list;
+
       struct completion fw_ready;
   };

...

Quoted 35 lines
Quoted 8 lines

+    if (tocopy_count)
+        kfree(adev->mod_idas);
+    else
+        avs_module_ida_destroy(adev);

sound/soc/intel/avs/utils.c new file +4 -0
+
+    adev->mod_idas = ida_ptrs;
+    return 0;
+}

sound/soc/intel/avs/utils.c line 201

Quoted 10 lines
sound/soc/intel/avs/utils.c new file +9 -0
 
+int avs_module_id_alloc(struct avs_dev *adev, u16 module_id)
+{
+    int ret, idx, max_id;
+
+    mutex_lock(&adev->modres_mutex);
+
+    idx = avs_module_id_entry_index(adev, module_id);
+    if (idx == -ENOENT) {
+        WARN(1, "invalid module id: %d", module_id);

dev_err() seems to be more than enough, why would you add a complete call trace?

Quoted 14 lines

+        ret = -EINVAL;
+        goto exit;
+    }
+    max_id = adev->mods_info->entries[idx].instance_max_count - 1; +    ret = ida_alloc_max(adev->mod_idas[idx], max_id, GFP_KERNEL);

sound/soc/intel/avs/utils.c new file +6 -0
+exit:
+    mutex_unlock(&adev->modres_mutex);
+    return ret;
+}
+
+void avs_module_id_free(struct avs_dev *adev, u16 module_id, u8 

instance_id)
+{
+    int idx;

Quoted 8 lines

sound/soc/intel/avs/utils.c line 201

Quoted 6 lines
sound/soc/intel/avs/utils.c new file +6 -0
+
+    mutex_lock(&adev->modres_mutex);
+
+    idx = avs_module_id_entry_index(adev, module_id);
+    if (idx == -ENOENT) {
+        WARN(1, "invalid module id: %d", module_id);

same WARN is over-engineered.

Ack for both.

Regards,
Czarek

#25 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 13 lines · Cezary Rojewski
Quoted 12 lines · Pierre-Louis Bossart
Quoted 11 lines

  /*
   * struct avs_dev - Intel HD-Audio driver data
   *
   * @dev: PCI device
   * @dsp_ba: DSP bar address
   * @spec: platform-specific descriptor
+ * @fw_cfg: Firmware configuration, obtained through FW_CONFIG message
+ * @hw_cfg: Hardware configuration, obtained through HW_CONFIG message
+ * @mods_info: Available module-types, obtained through MODULES_INFO message

Quoted 4 lines
Quoted 1 line

is this just for the base firmware? If this includes the extensions, how are the module types defined?

Only base firmware is able to process MODULE_INFO getter. So, every time driver loads a library, this info gets updated internally on the firmware side. We make use of said getter to retrieve up-to-date information and cache in ->mods_info for later use. ->mods_info is a member of type struct avs_mods_info with each enter represented by struct avs_module_info. These are introduced with all the basefw runtime parameters.

you clarified the mechanism but not the definition of 'module-type'?

the definition doesn't really help.

struct avs_module_type {
	u32 load_type:4;
	u32 auto_start:1;
	u32 domain_ll:1;
	u32 domain_dp:1;
	u32 lib_code:1;
	u32 rsvd:24;
} __packed;

I see nothing that would e.g. identify a mixer from a gain. The definition of 'type' seems to refer to low-level properties, not what the module actually does?

author maintainer
#26 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 14 lines · Pierre-Louis Bossart
Quoted 13 lines · Cezary Rojewski
Quoted 12 lines · Pierre-Louis Bossart
Quoted 11 lines

  /*
   * struct avs_dev - Intel HD-Audio driver data
   *
   * @dev: PCI device
   * @dsp_ba: DSP bar address
   * @spec: platform-specific descriptor
+ * @fw_cfg: Firmware configuration, obtained through FW_CONFIG message
+ * @hw_cfg: Hardware configuration, obtained through HW_CONFIG message
+ * @mods_info: Available module-types, obtained through MODULES_INFO message

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

is this just for the base firmware? If this includes the extensions, how are the module types defined?

Only base firmware is able to process MODULE_INFO getter. So, every time driver loads a library, this info gets updated internally on the firmware side. We make use of said getter to retrieve up-to-date information and cache in ->mods_info for later use. ->mods_info is a member of type struct avs_mods_info with each enter represented by struct avs_module_info. These are introduced with all the basefw

Sorry for the typo: s/avs_module_info/avs_module_entry/.

Quoted 15 lines
Quoted 1 line

runtime parameters.

you clarified the mechanism but not the definition of 'module-type'?

the definition doesn't really help.

struct avs_module_type {
    u32 load_type:4;
    u32 auto_start:1;
    u32 domain_ll:1;
    u32 domain_dp:1;
    u32 lib_code:1;
    u32 rsvd:24;
} __packed;

Quoted 1 line

I see nothing that would e.g. identify a mixer from a gain. The definition of 'type' seems to refer to low-level properties, not what the module actually does?

There is no "module-type" enum that software can rely on. We rely on hardcoded GUIDs instead. "module-type" is represented by struct avs_module_entry (per type) in context of MODULE_INFO IPC. All these names are indented to match firmware equivalents to make it easier to switch between the two worlds.

Regards,
Czarek

#27 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 39 lines · Cezary Rojewski
Quoted 16 lines · Pierre-Louis Bossart
Quoted 15 lines · Cezary Rojewski
Quoted 14 lines · Pierre-Louis Bossart
Quoted 13 lines

  /*
   * struct avs_dev - Intel HD-Audio driver data
   *
   * @dev: PCI device
   * @dsp_ba: DSP bar address
   * @spec: platform-specific descriptor
+ * @fw_cfg: Firmware configuration, obtained through FW_CONFIG message
+ * @hw_cfg: Hardware configuration, obtained through HW_CONFIG message
+ * @mods_info: Available module-types, obtained through MODULES_INFO message

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

is this just for the base firmware? If this includes the extensions, how are the module types defined?

Only base firmware is able to process MODULE_INFO getter. So, every time driver loads a library, this info gets updated internally on the firmware side. We make use of said getter to retrieve up-to-date information and cache in ->mods_info for later use. ->mods_info is a member of type struct avs_mods_info with each enter represented by struct avs_module_info. These are introduced with all the basefw

Sorry for the typo: s/avs_module_info/avs_module_entry/.

Quoted 15 lines
Quoted 1 line

runtime parameters.

you clarified the mechanism but not the definition of 'module-type'?

the definition doesn't really help.

struct avs_module_type {
     u32 load_type:4;
     u32 auto_start:1;
     u32 domain_ll:1;
     u32 domain_dp:1;
     u32 lib_code:1;
     u32 rsvd:24;
} __packed;

Quoted 4 lines
Quoted 1 line

I see nothing that would e.g. identify a mixer from a gain. The definition of 'type' seems to refer to low-level properties, not what the module actually does?

There is no "module-type" enum that software can rely on. We rely on hardcoded GUIDs instead. "module-type" is represented by struct avs_module_entry (per type) in context of MODULE_INFO IPC. All these names are indented to match firmware equivalents to make it easier to switch between the two worlds.

So the initial kernel-doc I commented on is still quite convoluted, you are referring to a 'module-type' that's not really well defined or useful for a driver.

Given the definition:

struct avs_mods_info {
	u32 count;
	struct avs_module_entry entries[];
} __packed;

wouldn't this be simpler/less confusing:

"
@mods_info: Available array of module entries, obtained through MODULES_INFO message
"

?

author maintainer
#28 lore raw

Re: [PATCH v4 11/17] ASoC: Intel: avs: Firmware resources management utilities

Quoted 1 line · Pierre-Louis Bossart

On 3/11/22 11:20, Cezary Rojewski wrote:

...

Quoted 32 lines
Quoted 17 lines

Sorry for the typo: s/avs_module_info/avs_module_entry/.

Quoted 15 lines
Quoted 1 line

runtime parameters.

you clarified the mechanism but not the definition of 'module-type'?

the definition doesn't really help.

struct avs_module_type {
     u32 load_type:4;
     u32 auto_start:1;
     u32 domain_ll:1;
     u32 domain_dp:1;
     u32 lib_code:1;
     u32 rsvd:24;
} __packed;

Quoted 4 lines
Quoted 1 line

I see nothing that would e.g. identify a mixer from a gain. The definition of 'type' seems to refer to low-level properties, not what the module actually does?

There is no "module-type" enum that software can rely on. We rely on hardcoded GUIDs instead. "module-type" is represented by struct avs_module_entry (per type) in context of MODULE_INFO IPC. All these names are indented to match firmware equivalents to make it easier to switch between the two worlds.

So the initial kernel-doc I commented on is still quite convoluted, you are referring to a 'module-type' that's not really well defined or useful for a driver.

Given the definition:

struct avs_mods_info {
    u32 count;
    struct avs_module_entry entries[];
} __packed;

Quoted 6 lines

wouldn't this be simpler/less confusing:

"
@mods_info: Available array of module entries, obtained through MODULES_INFO message
"

The major problem is the convoluted naming within the firmware itself.

The decision for the naming all the members as they are is dictated by the fact that there is much, much higher chance for Intel audio software or firmware developer to do some major/meaningful changes to the avs-driver as the kernel grows than a person outside that circle. Not everyone might agree, but that's the democratic decision made by the team in the early days of this driver. And thus, having close name-matching between the driver and the firmware makes it easier for given developer to switch between the two projects.

Agree on the rewording. There are probably more of such wordings within the code so this might span more than 1 file.

Regards,
Czarek

author maintainer
#29 lore raw

PATCH v4 12/17 ASoC: Intel: avs: Declare module configuration types

In reply to Cezary Rojewski

Declare structures and constants for all modules being part of basefw binary. These are used in streaming operations to communicate the needs of software to firmware side.

While adding module types, append handler for SET_SINK_FORMAT runtime for COPIER module which allows for configuration of output pin other than the default one (0).

---
 sound/soc/intel/avs/messages.c |  17 +++
 sound/soc/intel/avs/messages.h | 252 +++++++++++++++++++++++++++++++++
 2 files changed, 269 insertions(+)
sound/soc/intel/avs/messages.c +17 -0
index 4e7a2972da6d..9eaaf717cb54 100644
@@ -680,3 +680,20 @@ int avs_ipc_get_modules_info(struct avs_dev *adev, struct avs_mods_info **info)
 	*info = (struct avs_mods_info *)payload;
 	return 0;
 }
+
+int avs_ipc_copier_set_sink_format(struct avs_dev *adev, u16 module_id,
+				   u8 instance_id, u32 sink_id,
+				   const struct avs_audio_format *src_fmt,
+				   const struct avs_audio_format *sink_fmt)
+{
+	struct avs_copier_sink_format cpr_fmt;
+
+	cpr_fmt.sink_id = sink_id;
+	/* Firmware expects driver to resend copier's input format. */
+	cpr_fmt.src_fmt = *src_fmt;
+	cpr_fmt.sink_fmt = *sink_fmt;
+
+	return avs_ipc_set_large_config(adev, module_id, instance_id,
+					AVS_COPIER_SET_SINK_FORMAT,
+					(u8 *)&cpr_fmt, sizeof(cpr_fmt));
+}
sound/soc/intel/avs/messages.h +252 -0

256 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#30 lore raw

PATCH v4 13/17 ASoC: Intel: avs: Dynamic firmware resources management

In reply to Cezary Rojewski

Wrap elementary DSP-core operations and resource control into more complex handlers. This is done to reduce the number of invocations of wrapped operations throughout the driver as order of operations matters - most flows involve register manipulation and IPCs combined.

---
 sound/soc/intel/avs/avs.h |  10 +++
 sound/soc/intel/avs/dsp.c | 170 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
sound/soc/intel/avs/avs.h +10 -0
index 02d7591d0eac..2f9d6347ab0f 100644
@@ -89,6 +89,7 @@ struct avs_dev {
 	struct mutex modres_mutex;
 	struct ida ppl_ida;
 	struct list_head fw_list;
+	int *core_refs;		/* reference count per core */
 
 	struct completion fw_ready;
 };
@@ -205,4 +206,13 @@ int avs_request_firmware(struct avs_dev *adev, const struct firmware **fw_p, con
 void avs_release_last_firmware(struct avs_dev *adev);
 void avs_release_firmwares(struct avs_dev *adev);
 
+int avs_dsp_init_module(struct avs_dev *adev, u16 module_id, u8 ppl_instance_id,
+			u8 core_id, u8 domain, void *param, u32 param_size,
+			u16 *instance_id);
+void avs_dsp_delete_module(struct avs_dev *adev, u16 module_id, u16 instance_id,
+			   u8 ppl_instance_id, u8 core_id);
+int avs_dsp_create_pipeline(struct avs_dev *adev, u16 req_size, u8 priority,
+			    bool lp, u16 attributes, u8 *instance_id);
+int avs_dsp_delete_pipeline(struct avs_dev *adev, u8 instance_id);
+
 #endif /* __SOUND_SOC_INTEL_AVS_H */
sound/soc/intel/avs/dsp.c +170 -0

174 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#31 lore raw

PATCH v4 14/17 ASoC: Intel: avs: General code loading flow

In reply to Cezary Rojewski

Code loading is a complex procedure and requires combined effort of DMA and IPCs. With IPCs already in place, lay out ground for specific DMA transfer operations.

---
 sound/soc/intel/avs/Makefile    |   2 +-
 sound/soc/intel/avs/avs.h       |  18 +++
 sound/soc/intel/avs/core.c      |  62 +++++++++
 sound/soc/intel/avs/dsp.c       |  26 ++++
 sound/soc/intel/avs/loader.c    | 237 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/registers.h |   6 +
 6 files changed, 350 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/intel/avs/core.c
 create mode 100644 sound/soc/intel/avs/loader.c
sound/soc/intel/avs/Makefile +1 -1
index d9f92c5f5407..d9c793160612 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-snd-soc-avs-objs := dsp.o ipc.o messages.o utils.o
+snd-soc-avs-objs := dsp.o ipc.o messages.o utils.o core.o loader.o
 
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/avs.h +18 -0
index 2f9d6347ab0f..21a161c2443d 100644
@@ -10,8 +10,11 @@
 #define __SOUND_SOC_INTEL_AVS_H
 
 #include <linux/device.h>
+#include <linux/firmware.h>
 #include <sound/hda_codec.h>
+#include <sound/hda_register.h>
 #include "messages.h"
+#include "registers.h"
 
 struct avs_dev;
 
@@ -32,6 +35,10 @@ struct avs_dsp_ops {
 	irqreturn_t (* const irq_handler)(int, void *);
 	irqreturn_t (* const irq_thread)(int, void *);
 	void (* const int_control)(struct avs_dev *, bool);
+	int (* const load_basefw)(struct avs_dev *, struct firmware *);
+	int (* const load_lib)(struct avs_dev *, struct firmware *, u32);
+	int (* const transfer_mods)(struct avs_dev *, bool,
+				    struct avs_module_entry *, u32);
 };
 
 #define avs_dsp_op(adev, op, ...) \
@@ -45,6 +52,7 @@ struct avs_spec {
 	const char *name;
 
 	const struct avs_dsp_ops *const dsp_ops;
+	struct avs_fw_version min_fw_version; /* anything below is rejected */
 
 	const u32 core_init_mask;	/* used during DSP boot */
 	const u64 attributes;		/* bitmask of AVS_PLATATTR_* */
@@ -90,6 +98,7 @@ struct avs_dev {
 	struct ida ppl_ida;
 	struct list_head fw_list;
 	int *core_refs;		/* reference count per core */
+	char **lib_names;
 
 	struct completion fw_ready;
 };
@@ -215,4 +224,13 @@ int avs_dsp_create_pipeline(struct avs_dev *adev, u16 req_size, u8 priority,
 			    bool lp, u16 attributes, u8 *instance_id);
 int avs_dsp_delete_pipeline(struct avs_dev *adev, u8 instance_id);
 
+/* Firmware loading */
+
+void avs_hda_clock_gating_enable(struct avs_dev *adev, bool enable);
+void avs_hda_power_gating_enable(struct avs_dev *adev, bool enable);
+void avs_hda_l1sen_enable(struct avs_dev *adev, bool enable);
+
+int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge);
+int avs_dsp_first_boot_firmware(struct avs_dev *adev);
+
 #endif /* __SOUND_SOC_INTEL_AVS_H */
sound/soc/intel/avs/core.c new file +62 -0

62 lines not on this page · raw message

sound/soc/intel/avs/dsp.c +26 -0
index 5994d64d2468..a434e9918c51 100644
@@ -198,6 +198,7 @@ int avs_dsp_init_module(struct avs_dev *adev, u16 module_id, u8 ppl_instance_id,
 			u16 *instance_id)
 {
 	struct avs_module_entry mentry;
+	bool was_loaded = false;
 	int ret, id;
 
 	id = avs_module_id_alloc(adev, module_id);
@@ -212,6 +213,16 @@ int avs_dsp_init_module(struct avs_dev *adev, u16 module_id, u8 ppl_instance_id,
 	if (ret)
 		goto err_mod_entry;
 
+	/* Load code into memory if this is the first instance. */
+	if (!id && !avs_module_entry_is_loaded(&mentry)) {
+		ret = avs_dsp_op(adev, transfer_mods, true, &mentry, 1);
+		if (ret) {
+			dev_err(adev->dev, "load modules failed: %d\n", ret);
+			goto err_mod_entry;
+		}
+		was_loaded = true;
+	}
+
 	ret = avs_ipc_init_instance(adev, module_id, id, ppl_instance_id,
 				    core_id, domain, param, param_size);
 	if (ret) {
@@ -223,6 +234,8 @@ int avs_dsp_init_module(struct avs_dev *adev, u16 module_id, u8 ppl_instance_id,
 	return 0;
 
 err_ipc:
+	if (was_loaded)
+		avs_dsp_op(adev, transfer_mods, false, &mentry, 1);
 	avs_dsp_put_core(adev, core_id);
 err_mod_entry:
 	avs_module_id_free(adev, module_id, id);
@@ -232,12 +245,25 @@ int avs_dsp_init_module(struct avs_dev *adev, u16 module_id, u8 ppl_instance_id,
 void avs_dsp_delete_module(struct avs_dev *adev, u16 module_id, u16 instance_id,
 			   u8 ppl_instance_id, u8 core_id)
 {
+	struct avs_module_entry mentry;
+	int ret;
+
 	/* Modules not owned by any pipeline need to be freed explicitly. */
 	if (ppl_instance_id == INVALID_PIPELINE_ID)
 		avs_ipc_delete_instance(adev, module_id, instance_id);
 
 	avs_module_id_free(adev, module_id, instance_id);
 
+	ret = avs_get_module_id_entry(adev, module_id, &mentry);
+	/* Unload occupied memory if this was the last instance. */
+	if (!ret && mentry.type.load_type == AVS_MODULE_LOAD_TYPE_LOADABLE) {
+		if (avs_is_module_ida_empty(adev, module_id)) {
+			ret = avs_dsp_op(adev, transfer_mods, false, &mentry, 1);
+			if (ret)
+				dev_err(adev->dev, "unload modules failed: %d\n", ret);
+		}
+	}
+
 	avs_dsp_put_core(adev, core_id);
 }
 
sound/soc/intel/avs/loader.c new file +237 -0

237 lines not on this page · raw message

sound/soc/intel/avs/registers.h +6 -0
index 4bb10ca46a1e..a05465bac6d0 100644
@@ -9,6 +9,12 @@
 #ifndef __SOUND_SOC_INTEL_AVS_REGS_H
 #define __SOUND_SOC_INTEL_AVS_REGS_H
 
+#define AZX_PCIREG_PGCTL		0x44
+#define AZX_PCIREG_CGCTL		0x48
+#define AZX_PGCTL_LSRMD_MASK		BIT(4)
+#define AZX_CGCTL_MISCBDCGE_MASK	BIT(6)
+#define AZX_VS_EM2_L1SEN		BIT(13)
+
 /* Intel HD Audio General DSP Registers */
 #define AVS_ADSP_GEN_BASE		0x0
 #define AVS_ADSP_REG_ADSPCS		(AVS_ADSP_GEN_BASE + 0x04)
Signature · 1 line
2.25.1
author maintainer
#32 lore raw

PATCH v4 15/17 ASoC: Intel: avs: Implement CLDMA transfer

In reply to Cezary Rojewski

SKL and KBL rely on a dedicated HDAudio DMA stream for code loading and authentication. The implementation of this specific mechanism for SKL-based platforms re-uses HDAudio DMA (streaming) functions found in HDA library to avoid duplication of functionality.

---
 sound/soc/intel/avs/Makefile    |   1 +
 sound/soc/intel/avs/cldma.c     | 317 ++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/cldma.h     |  29 +++
 sound/soc/intel/avs/registers.h |   2 +
 4 files changed, 349 insertions(+)
 create mode 100644 sound/soc/intel/avs/cldma.c
 create mode 100644 sound/soc/intel/avs/cldma.h
sound/soc/intel/avs/Makefile +1 -0
index d9c793160612..f842bfc5e97e 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 snd-soc-avs-objs := dsp.o ipc.o messages.o utils.o core.o loader.o
+snd-soc-avs-objs += cldma.o
 
 obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
sound/soc/intel/avs/cldma.c new file +317 -0

317 lines not on this page · raw message

sound/soc/intel/avs/cldma.h new file +29 -0
new file mode 100644
index 000000000000..cad81f03095a
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright(c) 2021 Intel Corporation. All rights reserved.
+ *
+ * Author: Cezary Rojewski <[email protected]>
+ */
+
+#ifndef __SOUND_SOC_INTEL_AVS_CLDMA_H
+#define __SOUND_SOC_INTEL_AVS_CLDMA_H
+
+#define AVS_CL_DEFAULT_BUFFER_SIZE	(32 * PAGE_SIZE)
+
+struct hda_cldma;
+extern struct hda_cldma code_loader;
+
+void hda_cldma_fill(struct hda_cldma *cl);
+void hda_cldma_transfer(struct hda_cldma *cl, unsigned long start_delay);
+
+int hda_cldma_start(struct hda_cldma *cl);
+int hda_cldma_stop(struct hda_cldma *cl);
+int hda_cldma_reset(struct hda_cldma *cl);
+
+void hda_cldma_set_data(struct hda_cldma *cl, void *data, unsigned int size);
+void hda_cldma_setup(struct hda_cldma *cl);
+int hda_cldma_init(struct hda_cldma *cl, struct hdac_bus *bus, void __iomem *dsp_ba,
+		   unsigned int buffer_size);
+void hda_cldma_free(struct hda_cldma *cl);
+
+#endif
sound/soc/intel/avs/registers.h +2 -0
index a05465bac6d0..0f55f526d962 100644
@@ -22,7 +22,9 @@
 #define AVS_ADSP_REG_ADSPIS		(AVS_ADSP_GEN_BASE + 0x0C)
 
 #define AVS_ADSP_ADSPIC_IPC		BIT(0)
+#define AVS_ADSP_ADSPIC_CLDMA		BIT(1)
 #define AVS_ADSP_ADSPIS_IPC		BIT(0)
+#define AVS_ADSP_ADSPIS_CLDMA		BIT(1)
 
 #define AVS_ADSPCS_CRST_MASK(cm)	(cm)
 #define AVS_ADSPCS_CSTALL_MASK(cm)	((cm) << 8)
Signature · 1 line
2.25.1
author maintainer
#33 lore raw

PATCH v4 16/17 ASoC: Intel: avs: Code loading over CLDMA

In reply to Cezary Rojewski

With CLDMA transfer implemented, make use of it to shape firmware, library and module loading routines for SKL and KBL platforms.

---
 sound/soc/intel/avs/avs.h    |   7 ++
 sound/soc/intel/avs/loader.c | 159 +++++++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+)
sound/soc/intel/avs/avs.h +7 -0
index 21a161c2443d..2531b383e1e7 100644
@@ -44,6 +44,8 @@ struct avs_dsp_ops {
 #define avs_dsp_op(adev, op, ...) \
 	((adev)->spec->dsp_ops->op(adev, ## __VA_ARGS__))
 
+#define AVS_PLATATTR_CLDMA		BIT_ULL(0)
+
 #define avs_platattr_test(adev, attr) \
 	((adev)->spec->attributes & AVS_PLATATTR_##attr)
 
@@ -233,4 +235,9 @@ void avs_hda_l1sen_enable(struct avs_dev *adev, bool enable);
 int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge);
 int avs_dsp_first_boot_firmware(struct avs_dev *adev);
 
+int avs_cldma_load_basefw(struct avs_dev *adev, struct firmware *fw);
+int avs_cldma_load_library(struct avs_dev *adev, struct firmware *lib, u32 id);
+int avs_cldma_transfer_modules(struct avs_dev *adev, bool load,
+			       struct avs_module_entry *mods, u32 num_mods);
+
 #endif /* __SOUND_SOC_INTEL_AVS_H */
sound/soc/intel/avs/loader.c +159 -0

183 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#34 lore raw

PATCH v4 17/17 ASoC: Intel: avs: Code loading over HDA

In reply to Cezary Rojewski

Compared to SKL and KBL, more recent cAVS platforms are meant to re-use one of HDAudio streams during boot procedure causing CLDMA to become obsolete. Once transferred, given stream is returned to pool available for audio streaming.

Module loading handler is stub as library and module code became inseparable in later firmware generations.

---
 sound/soc/intel/Kconfig      |   1 +
 sound/soc/intel/avs/avs.h    |   5 +
 sound/soc/intel/avs/loader.c | 214 +++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
sound/soc/intel/Kconfig +1 -0
index e9768c4aa1a9..d025ca0c77fa 100644
@@ -215,6 +215,7 @@ config SND_SOC_INTEL_AVS
 	depends on COMMON_CLK
 	select SND_SOC_ACPI
 	select SND_HDA_EXT_CORE
+	select SND_HDA_DSP_LOADER
 	help
 	  Enable support for Intel(R) cAVS 1.5 platforms with DSP
 	  capabilities. This includes Skylake, Kabylake, Amberlake and
sound/soc/intel/avs/avs.h +5 -0
index 2531b383e1e7..2451b676704c 100644
@@ -45,6 +45,7 @@ struct avs_dsp_ops {
 	((adev)->spec->dsp_ops->op(adev, ## __VA_ARGS__))
 
 #define AVS_PLATATTR_CLDMA		BIT_ULL(0)
+#define AVS_PLATATTR_IMR		BIT_ULL(1)
 
 #define avs_platattr_test(adev, attr) \
 	((adev)->spec->attributes & AVS_PLATATTR_##attr)
@@ -239,5 +240,9 @@ int avs_cldma_load_basefw(struct avs_dev *adev, struct firmware *fw);
 int avs_cldma_load_library(struct avs_dev *adev, struct firmware *lib, u32 id);
 int avs_cldma_transfer_modules(struct avs_dev *adev, bool load,
 			       struct avs_module_entry *mods, u32 num_mods);
+int avs_hda_load_basefw(struct avs_dev *adev, struct firmware *fw);
+int avs_hda_load_library(struct avs_dev *adev, struct firmware *lib, u32 id);
+int avs_hda_transfer_modules(struct avs_dev *adev, bool load,
+			     struct avs_module_entry *mods, u32 num_mods);
 
 #endif /* __SOUND_SOC_INTEL_AVS_H */
sound/soc/intel/avs/loader.c +214 -0

240 lines not on this page · raw message

Signature · 1 line
2.25.1