Skip to contentSkip to conversation

ASoC: Intel: avs: Refactor IRQ handling

PATCH In review Cezary Rojewski 2 participants 4 messages Apr 19, 2024 – Apr 21, 2024

Subsystems (3)
lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

cover ASoC: Intel: avs: Refactor IRQ handling

The existing code can be both improved and simplified. To make this change easier to manage, first add new implementation and then remove deadcode in a separate patch.

Simplification achieved with:

- reduce the amount of resources requested by the driver i.e.: IPC and CLDMA request_irq() merged into one
- reduce the number of DSP ops from 2 to 1:
irq_handler/thread() vs dsp_interrupt()
- drop ambiguity around CLDMA interrupt, let skl.c handle that explicitly as it is the only user

With that done, switch to the new implementation and remove unused members. While the change is non-trivial, from functional perspective status quo is achieved.

Cezary Rojewski (2):
ASoC: Intel: avs: New IRQ handling implementation
ASoC: Intel: avs: Remove unused IRQ-related code

 sound/soc/intel/avs/apl.c   | 20 +++++++-
 sound/soc/intel/avs/avs.h   |  8 ++--
 sound/soc/intel/avs/cldma.c | 42 ++++-------------
 sound/soc/intel/avs/cldma.h |  1 +
 sound/soc/intel/avs/cnl.c   | 91 ++++++++++++++++++++++++-------------
 sound/soc/intel/avs/core.c  | 85 ++++++++++++++++------------------
 sound/soc/intel/avs/icl.c   |  3 +-
 sound/soc/intel/avs/ipc.c   | 48 -------------------
 sound/soc/intel/avs/skl.c   | 73 +++++++++++++++++++++--------
 sound/soc/intel/avs/tgl.c   |  3 +-
 10 files changed, 186 insertions(+), 188 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/2 ASoC: Intel: avs: New IRQ handling implementation

The existing code can be both improved and simplified. To make this change easier to manage, first add new implementation and then remove deadcode in a separate patch.

Simplification achieved with:
- reduce the amount of resources requested by the driver i.e.: IPC and CLDMA request_irq() merged into one
- reduce the number of DSP ops from 2 to 1:
irq_handler/thread() vs dsp_interrupt()
- drop ambiguity around CLDMA interrupt, let skl.c handle that explicitly as it is the only user

---
 sound/soc/intel/avs/apl.c   | 18 +++++++++
 sound/soc/intel/avs/avs.h   |  3 ++
 sound/soc/intel/avs/cldma.c | 11 +++++
 sound/soc/intel/avs/cldma.h |  1 +
 sound/soc/intel/avs/cnl.c   | 63 +++++++++++++++++++++++++++++
 sound/soc/intel/avs/core.c  | 80 +++++++++++++++++++++++++++++++++++++
 sound/soc/intel/avs/icl.c   |  1 +
 sound/soc/intel/avs/skl.c   | 62 ++++++++++++++++++++++++++++
 sound/soc/intel/avs/tgl.c   |  1 +
 9 files changed, 240 insertions(+)
sound/soc/intel/avs/apl.c +18 -0
index c21ecaef9eba..a186d88430b9 100644
@@ -8,11 +8,28 @@
 
 #include <linux/devcoredump.h>
 #include <linux/slab.h>
+#include <sound/hdaudio_ext.h>
 #include "avs.h"
 #include "messages.h"
 #include "path.h"
 #include "topology.h"
 
+static irqreturn_t avs_apl_dsp_interrupt(struct avs_dev *adev)
+{
+	u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
+	irqreturn_t ret = IRQ_NONE;
+
+	if (adspis == UINT_MAX)
+		return ret;
+
+	if (adspis & AVS_ADSP_ADSPIS_IPC) {
+		avs_skl_ipc_interrupt(adev);
+		ret = IRQ_HANDLED;
+	}
+
+	return ret;
+}
+
 #ifdef CONFIG_DEBUG_FS
 int avs_apl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
 			u32 fifo_full_period, unsigned long resource_mask, u32 *priorities)
@@ -237,6 +254,7 @@ const struct avs_dsp_ops avs_apl_dsp_ops = {
 	.power = avs_dsp_core_power,
 	.reset = avs_dsp_core_reset,
 	.stall = avs_dsp_core_stall,
+	.dsp_interrupt = avs_apl_dsp_interrupt,
 	.irq_handler = avs_irq_handler,
 	.irq_thread = avs_skl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
sound/soc/intel/avs/avs.h +3 -0
index eb8c03afdd23..75ae8f3addb8 100644
@@ -46,6 +46,7 @@ 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 dsp_interrupt)(struct avs_dev *);
 	irqreturn_t (* const irq_handler)(struct avs_dev *);
 	irqreturn_t (* const irq_thread)(struct avs_dev *);
 	void (* const int_control)(struct avs_dev *, bool);
@@ -269,6 +270,8 @@ int avs_dsp_enable_d0ix(struct avs_dev *adev);
 
 irqreturn_t avs_skl_irq_thread(struct avs_dev *adev);
 irqreturn_t avs_cnl_irq_thread(struct avs_dev *adev);
+void avs_skl_ipc_interrupt(struct avs_dev *adev);
+irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev);
 int avs_apl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
 			u32 fifo_full_period, unsigned long resource_mask, u32 *priorities);
 int avs_icl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
sound/soc/intel/avs/cldma.c +11 -0
index 585579840b64..c79b126f376d 100644
@@ -270,6 +270,17 @@ static irqreturn_t cldma_irq_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+void hda_cldma_interrupt(struct hda_cldma *cl)
+{
+	/* disable CLDMA interrupt */
+	snd_hdac_adsp_updatel(cl, AVS_ADSP_REG_ADSPIC, AVS_ADSP_ADSPIC_CLDMA, 0);
+
+	cl->sd_status = snd_hdac_stream_readb(cl, SD_STS);
+	dev_dbg(cl->dev, "%s sd_status: 0x%08x\n", __func__, cl->sd_status);
+
+	complete(&cl->completion);
+}
+
 int hda_cldma_init(struct hda_cldma *cl, struct hdac_bus *bus, void __iomem *dsp_ba,
 		   unsigned int buffer_size)
 {
sound/soc/intel/avs/cldma.h +1 -0
index 223d3431ab81..7d95e2747f52 100644
@@ -24,6 +24,7 @@ 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);
+void hda_cldma_interrupt(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);
sound/soc/intel/avs/cnl.c +63 -0

73 lines not on this page · raw message

sound/soc/intel/avs/core.c +80 -0

86 lines not on this page · raw message

sound/soc/intel/avs/icl.c +1 -0
index 7a1ecf241856..004fe71505dd 100644
@@ -188,6 +188,7 @@ const struct avs_dsp_ops avs_icl_dsp_ops = {
 	.power = avs_dsp_core_power,
 	.reset = avs_dsp_core_reset,
 	.stall = avs_dsp_core_stall,
+	.dsp_interrupt = avs_cnl_dsp_interrupt,
 	.irq_handler = avs_irq_handler,
 	.irq_thread = avs_cnl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
sound/soc/intel/avs/skl.c +62 -0

80 lines not on this page · raw message

sound/soc/intel/avs/tgl.c +1 -0
index 0e052e7f6bac..e3723ef38a33 100644
@@ -39,6 +39,7 @@ const struct avs_dsp_ops avs_tgl_dsp_ops = {
 	.power = avs_tgl_dsp_core_power,
 	.reset = avs_tgl_dsp_core_reset,
 	.stall = avs_tgl_dsp_core_stall,
+	.dsp_interrupt = avs_cnl_dsp_interrupt,
 	.irq_handler = avs_irq_handler,
 	.irq_thread = avs_cnl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/2 ASoC: Intel: avs: Remove unused IRQ-related code

In reply to Cezary Rojewski

Most IRQ-related code is duplicated in the driver. Switch to the new implementation and remove unused members.

While the change is non-trivial, from functional perspective status quo is achieved.

---
 sound/soc/intel/avs/apl.c   |  2 -
 sound/soc/intel/avs/avs.h   |  5 --
 sound/soc/intel/avs/cldma.c | 45 ++----------------
 sound/soc/intel/avs/cnl.c   | 34 --------------
 sound/soc/intel/avs/core.c  | 91 ++-----------------------------------
 sound/soc/intel/avs/icl.c   |  2 -
 sound/soc/intel/avs/ipc.c   | 48 -------------------
 sound/soc/intel/avs/skl.c   | 27 -----------
 sound/soc/intel/avs/tgl.c   |  2 -
 9 files changed, 7 insertions(+), 249 deletions(-)
sound/soc/intel/avs/apl.c +0 -2
index a186d88430b9..bf97e4e428a4 100644
@@ -255,8 +255,6 @@ const struct avs_dsp_ops avs_apl_dsp_ops = {
 	.reset = avs_dsp_core_reset,
 	.stall = avs_dsp_core_stall,
 	.dsp_interrupt = avs_apl_dsp_interrupt,
-	.irq_handler = avs_irq_handler,
-	.irq_thread = avs_skl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
 	.load_basefw = avs_hda_load_basefw,
 	.load_lib = avs_hda_load_library,
sound/soc/intel/avs/avs.h +0 -5
index 75ae8f3addb8..c905ecd0a108 100644
@@ -47,8 +47,6 @@ struct avs_dsp_ops {
 	int (* const reset)(struct avs_dev *, u32, bool);
 	int (* const stall)(struct avs_dev *, u32, bool);
 	irqreturn_t (* const dsp_interrupt)(struct avs_dev *);
-	irqreturn_t (* const irq_handler)(struct avs_dev *);
-	irqreturn_t (* const irq_thread)(struct avs_dev *);
 	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);
@@ -246,7 +244,6 @@ struct avs_ipc {
 #define AVS_IPC_RET(ret) \
 	(((ret) <= 0) ? (ret) : -AVS_EIPC)
 
-irqreturn_t avs_irq_handler(struct avs_dev *adev);
 void avs_dsp_process_response(struct avs_dev *adev, u64 header);
 int avs_dsp_send_msg_timeout(struct avs_dev *adev, struct avs_ipc_msg *request,
 			     struct avs_ipc_msg *reply, int timeout, const char *name);
@@ -268,8 +265,6 @@ void avs_ipc_block(struct avs_ipc *ipc);
 int avs_dsp_disable_d0ix(struct avs_dev *adev);
 int avs_dsp_enable_d0ix(struct avs_dev *adev);
 
-irqreturn_t avs_skl_irq_thread(struct avs_dev *adev);
-irqreturn_t avs_cnl_irq_thread(struct avs_dev *adev);
 void avs_skl_ipc_interrupt(struct avs_dev *adev);
 irqreturn_t avs_cnl_dsp_interrupt(struct avs_dev *adev);
 int avs_apl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
sound/soc/intel/avs/cldma.c +4 -41

74 lines not on this page · raw message

sound/soc/intel/avs/cnl.c +0 -34
index c021c0f51a53..0d03e1e03c11 100644
@@ -10,38 +10,6 @@
 #include "avs.h"
 #include "messages.h"
 
-irqreturn_t avs_cnl_irq_thread(struct avs_dev *adev)
-{
-	union avs_reply_msg msg;
-	u32 hipctdr, hipctdd, hipctda;
-
-	hipctdr = snd_hdac_adsp_readl(adev, CNL_ADSP_REG_HIPCTDR);
-	hipctdd = snd_hdac_adsp_readl(adev, CNL_ADSP_REG_HIPCTDD);
-
-	/* Ensure DSP sent new response to process. */
-	if (!(hipctdr & CNL_ADSP_HIPCTDR_BUSY))
-		return IRQ_NONE;
-
-	msg.primary = hipctdr;
-	msg.ext.val = hipctdd;
-	avs_dsp_process_response(adev, msg.val);
-
-	/* Tell DSP we accepted its message. */
-	snd_hdac_adsp_updatel(adev, CNL_ADSP_REG_HIPCTDR,
-			      CNL_ADSP_HIPCTDR_BUSY, CNL_ADSP_HIPCTDR_BUSY);
-	/* Ack this response. */
-	snd_hdac_adsp_updatel(adev, CNL_ADSP_REG_HIPCTDA,
-			      CNL_ADSP_HIPCTDA_DONE, CNL_ADSP_HIPCTDA_DONE);
-	/* HW might have been clock gated, give some time for change to propagate. */
-	snd_hdac_adsp_readl_poll(adev, CNL_ADSP_REG_HIPCTDA, hipctda,
-				 !(hipctda & CNL_ADSP_HIPCTDA_DONE), 10, 1000);
-	/* Unmask busy interrupt. */
-	snd_hdac_adsp_updatel(adev, CNL_ADSP_REG_HIPCCTL,
-			      AVS_ADSP_HIPCCTL_BUSY, AVS_ADSP_HIPCCTL_BUSY);
-
-	return IRQ_HANDLED;
-}
-
 static void avs_cnl_ipc_interrupt(struct avs_dev *adev)
 {
 	const struct avs_spec *spec = adev->spec;
@@ -109,8 +77,6 @@ const struct avs_dsp_ops avs_cnl_dsp_ops = {
 	.reset = avs_dsp_core_reset,
 	.stall = avs_dsp_core_stall,
 	.dsp_interrupt = avs_cnl_dsp_interrupt,
-	.irq_handler = avs_irq_handler,
-	.irq_thread = avs_cnl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
 	.load_basefw = avs_hda_load_basefw,
 	.load_lib = avs_hda_load_library,
sound/soc/intel/avs/core.c +3 -88

133 lines not on this page · raw message

sound/soc/intel/avs/icl.c +0 -2
index 004fe71505dd..3a96c4304ca6 100644
@@ -189,8 +189,6 @@ const struct avs_dsp_ops avs_icl_dsp_ops = {
 	.reset = avs_dsp_core_reset,
 	.stall = avs_dsp_core_stall,
 	.dsp_interrupt = avs_cnl_dsp_interrupt,
-	.irq_handler = avs_irq_handler,
-	.irq_thread = avs_cnl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
 	.load_basefw = avs_icl_load_basefw,
 	.load_lib = avs_hda_load_library,
sound/soc/intel/avs/ipc.c +0 -48

54 lines not on this page · raw message

sound/soc/intel/avs/skl.c +0 -27
index 25abfead9f63..fceed353449a 100644
@@ -13,31 +13,6 @@
 #include "cldma.h"
 #include "messages.h"
 
-irqreturn_t avs_skl_irq_thread(struct avs_dev *adev)
-{
-	union avs_reply_msg msg;
-	u32 hipct, hipcte;
-
-	hipct = snd_hdac_adsp_readl(adev, SKL_ADSP_REG_HIPCT);
-	hipcte = snd_hdac_adsp_readl(adev, SKL_ADSP_REG_HIPCTE);
-
-	/* Ensure DSP sent new response to process. */
-	if (!(hipct & SKL_ADSP_HIPCT_BUSY))
-		return IRQ_NONE;
-
-	msg.primary = hipct;
-	msg.ext.val = hipcte;
-	avs_dsp_process_response(adev, msg.val);
-
-	/* Tell DSP we accepted its message. */
-	snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCT, SKL_ADSP_HIPCT_BUSY, SKL_ADSP_HIPCT_BUSY);
-	/* Unmask busy interrupt. */
-	snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCCTL, AVS_ADSP_HIPCCTL_BUSY,
-			      AVS_ADSP_HIPCCTL_BUSY);
-
-	return IRQ_HANDLED;
-}
-
 void avs_skl_ipc_interrupt(struct avs_dev *adev)
 {
 	const struct avs_spec *spec = adev->spec;
@@ -190,8 +165,6 @@ const struct avs_dsp_ops avs_skl_dsp_ops = {
 	.reset = avs_dsp_core_reset,
 	.stall = avs_dsp_core_stall,
 	.dsp_interrupt = avs_skl_dsp_interrupt,
-	.irq_handler = avs_irq_handler,
-	.irq_thread = avs_skl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
 	.load_basefw = avs_cldma_load_basefw,
 	.load_lib = avs_cldma_load_library,
sound/soc/intel/avs/tgl.c +0 -2
index e3723ef38a33..b985a8299b72 100644
@@ -40,8 +40,6 @@ const struct avs_dsp_ops avs_tgl_dsp_ops = {
 	.reset = avs_tgl_dsp_core_reset,
 	.stall = avs_tgl_dsp_core_stall,
 	.dsp_interrupt = avs_cnl_dsp_interrupt,
-	.irq_handler = avs_irq_handler,
-	.irq_thread = avs_cnl_irq_thread,
 	.int_control = avs_dsp_interrupt_control,
 	.load_basefw = avs_icl_load_basefw,
 	.load_lib = avs_hda_load_library,
Signature · 1 line
2.25.1
maintainer
#3 lore raw
In reply to Cezary Rojewski
Quoted 6 lines · Cezary Rojewski

The existing code can be both improved and simplified. To make this change easier to manage, first add new implementation and then remove deadcode in a separate patch.

Simplification achieved with:

Quoted 8 lines

- reduce the amount of resources requested by the driver i.e.: IPC and CLDMA request_irq() merged into one
- reduce the number of DSP ops from 2 to 1:
irq_handler/thread() vs dsp_interrupt()
- drop ambiguity around CLDMA interrupt, let skl.c handle that explicitly as it is the only user

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: Intel: avs: New IRQ handling implementation

      commit: 7ce6ceeb77bfd9fb0b22203190bd6f57fe917b51
[2/2] ASoC: Intel: avs: Remove unused IRQ-related code
      commit: 84049e2db59ad9b09461b6d7ec56bd3e8fe75eca

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark