From 6bceaea6b19eb8df89d285fb42f6094d4d8c74ff Mon Sep 17 00:00:00 2001 From: Abel Vesa Date: Fri, 12 Jun 2026 14:09:08 +0300 Subject: [PATCH 1/3] FROMGIT: remoteproc: qcom: q6v5: Make handover IRQ one-shot The handover interrupt is expected to be consumed once during each prepare cycle. If the remote processor keeps signalling handover after the first event, qcom_q6v5 currently logs the duplicate interrupt repeatedly while leaving the IRQ enabled. Track the handover IRQ enable state explicitly and route all handover IRQ enable/disable operations through idempotent helpers. Request the handover IRQ with IRQF_NO_AUTOEN so it is only enabled through the helper during prepare. The handover handler disables it after marking handover as issued, while unprepare disables and synchronizes it before checking whether handover was issued. Signed-off-by: Abel Vesa Link: https://lore.kernel.org/r/20260612-rproc-q6v5-handover-irq-one-shot-v1-1-bb688f4446b3@oss.qualcomm.com Signed-off-by: Bjorn Andersson --- drivers/remoteproc/qcom_q6v5.c | 54 +++++++++++++++++++++++++++------- drivers/remoteproc/qcom_q6v5.h | 4 +++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5.c b/drivers/remoteproc/qcom_q6v5.c index 52247c17c38ac..fc63e13bd909b 100644 --- a/drivers/remoteproc/qcom_q6v5.c +++ b/drivers/remoteproc/qcom_q6v5.c @@ -37,6 +37,40 @@ static int q6v5_load_state_toggle(struct qcom_q6v5 *q6v5, bool enable) return ret; } +static void q6v5_handover_irq_enable(struct qcom_q6v5 *q6v5) +{ + unsigned long flags; + bool enable = false; + + spin_lock_irqsave(&q6v5->handover_lock, flags); + if (!q6v5->handover_irq_enabled) { + q6v5->handover_irq_enabled = true; + enable = true; + } + spin_unlock_irqrestore(&q6v5->handover_lock, flags); + + if (enable) + enable_irq(q6v5->handover_irq); +} + +static void q6v5_handover_irq_disable(struct qcom_q6v5 *q6v5, bool sync) +{ + unsigned long flags; + bool disable = false; + + spin_lock_irqsave(&q6v5->handover_lock, flags); + if (q6v5->handover_irq_enabled) { + q6v5->handover_irq_enabled = false; + disable = true; + } + spin_unlock_irqrestore(&q6v5->handover_lock, flags); + + if (disable) + disable_irq_nosync(q6v5->handover_irq); + if (sync) + synchronize_irq(q6v5->handover_irq); +} + /** * qcom_q6v5_prepare() - reinitialize the qcom_q6v5 context before start * @q6v5: reference to qcom_q6v5 context to be reinitialized @@ -65,7 +99,7 @@ int qcom_q6v5_prepare(struct qcom_q6v5 *q6v5) q6v5->running = true; q6v5->handover_issued = false; - enable_irq(q6v5->handover_irq); + q6v5_handover_irq_enable(q6v5); return 0; } @@ -79,7 +113,8 @@ EXPORT_SYMBOL_GPL(qcom_q6v5_prepare); */ int qcom_q6v5_unprepare(struct qcom_q6v5 *q6v5) { - disable_irq(q6v5->handover_irq); + q6v5_handover_irq_disable(q6v5, true); + q6v5_load_state_toggle(q6v5, false); /* Disable interconnect vote, in case handover never happened */ @@ -165,18 +200,15 @@ static irqreturn_t q6v5_handover_interrupt(int irq, void *data) { struct qcom_q6v5 *q6v5 = data; - if (q6v5->handover_issued) { - dev_err(q6v5->dev, "Handover signaled, but it already happened\n"); - return IRQ_HANDLED; - } + q6v5->handover_issued = true; + + q6v5_handover_irq_disable(q6v5, false); if (q6v5->handover) q6v5->handover(q6v5); icc_set_bw(q6v5->path, 0, 0); - q6v5->handover_issued = true; - return IRQ_HANDLED; } @@ -325,6 +357,8 @@ int qcom_q6v5_init(struct qcom_q6v5 *q6v5, struct platform_device *pdev, q6v5->crash_reason = crash_reason; q6v5->handover = handover; + spin_lock_init(&q6v5->handover_lock); + init_completion(&q6v5->start_done); init_completion(&q6v5->stop_done); @@ -373,13 +407,13 @@ int qcom_q6v5_init(struct qcom_q6v5 *q6v5, struct platform_device *pdev, ret = devm_request_threaded_irq(&pdev->dev, q6v5->handover_irq, NULL, q6v5_handover_interrupt, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, + IRQF_TRIGGER_RISING | IRQF_ONESHOT | + IRQF_NO_AUTOEN, "q6v5 handover", q6v5); if (ret) { dev_err(&pdev->dev, "failed to acquire handover IRQ\n"); return ret; } - disable_irq(q6v5->handover_irq); q6v5->stop_irq = platform_get_irq_byname(pdev, "stop-ack"); if (q6v5->stop_irq < 0) diff --git a/drivers/remoteproc/qcom_q6v5.h b/drivers/remoteproc/qcom_q6v5.h index 5025ffc4dbe80..ad03f1907029a 100644 --- a/drivers/remoteproc/qcom_q6v5.h +++ b/drivers/remoteproc/qcom_q6v5.h @@ -5,6 +5,7 @@ #include #include +#include #include struct icc_path; @@ -32,6 +33,9 @@ struct qcom_q6v5 { int stop_irq; int pong_irq; + /* Protects handover_irq_enabled against stop/handover races. */ + spinlock_t handover_lock; + bool handover_irq_enabled; bool handover_issued; struct completion start_done; From cb14ffbe82be13ac21964a42952db302b1fa2478 Mon Sep 17 00:00:00 2001 From: Jingyi Wang Date: Tue, 23 Jun 2026 03:05:21 -0700 Subject: [PATCH 2/3] FROMGIT: remoteproc: qcom: pas: Add late attach support for subsystems Subsystems can be brought out of reset by entities such as bootloaders. As the irq enablement could be later than subsystem bring up, the state of subsystem should be checked by reading SMP2P bits. A new qcom_pas_attach() function is introduced. if crash state is detected for the subsystem, rproc_report_crash() is called. If the ready state is detected meanwhile stop state is not detected, it will be marked as "attached", otherwise it could be the early boot feature is not supported by other entities or it has already been stopped. In above cases, the state will be marked as RPROC_OFFLINE so that the PAS driver can load the firmware and start the remoteproc. Co-developed-by: Gokul Krishna Krishnakumar Signed-off-by: Gokul Krishna Krishnakumar Tested-by: Shawn Guo Signed-off-by: Jingyi Wang Tested-by: Mukesh Ojha Link: https://lore.kernel.org/r/20260623-knp-soccp-v7-5-1ec7bb5c9fec@oss.qualcomm.com Signed-off-by: Bjorn Andersson --- drivers/remoteproc/qcom_common.h | 6 +++++ drivers/remoteproc/qcom_q6v5.c | 3 ++- drivers/remoteproc/qcom_q6v5_pas.c | 38 +++++++++++++++++------------- drivers/remoteproc/qcom_sysmon.c | 19 +++++++++++++++ 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/drivers/remoteproc/qcom_common.h b/drivers/remoteproc/qcom_common.h index b07fbaa091a06..b0e7e336d363e 100644 --- a/drivers/remoteproc/qcom_common.h +++ b/drivers/remoteproc/qcom_common.h @@ -68,6 +68,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, int ssctl_instance); void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon); bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon); +bool qcom_sysmon_shutdown_irq_state(struct qcom_sysmon *sysmon); #else static inline struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, const char *name, @@ -84,6 +85,11 @@ static inline bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon) { return false; } + +static inline bool qcom_sysmon_shutdown_irq_state(struct qcom_sysmon *sysmon) +{ + return false; +} #endif #endif diff --git a/drivers/remoteproc/qcom_q6v5.c b/drivers/remoteproc/qcom_q6v5.c index fc63e13bd909b..99e4384f1b0e6 100644 --- a/drivers/remoteproc/qcom_q6v5.c +++ b/drivers/remoteproc/qcom_q6v5.c @@ -235,7 +235,8 @@ int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5, struct qcom_sysmon *sysmon) q6v5->running = false; /* Don't perform SMP2P dance if remote isn't running */ - if (q6v5->rproc->state != RPROC_RUNNING || qcom_sysmon_shutdown_acked(sysmon)) + if ((q6v5->rproc->state != RPROC_RUNNING && q6v5->rproc->state != RPROC_ATTACHED) || + qcom_sysmon_shutdown_acked(sysmon)) return 0; qcom_smem_state_update_bits(q6v5->state, diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index 3a30cbd3ce2b6..719e9f661bcca 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -561,15 +561,18 @@ static void qcom_pas_coredump(struct rproc *rproc) static int qcom_pas_attach(struct rproc *rproc) { - int ret; struct qcom_pas *pas = rproc->priv; bool ready_state; bool crash_state; + bool stop_state; + int ret; + + pas->q6v5.handover_issued = true; + enable_irq(pas->q6v5.handover_irq); pas->q6v5.running = true; ret = irq_get_irqchip_state(pas->q6v5.fatal_irq, IRQCHIP_STATE_LINE_LEVEL, &crash_state); - if (ret) goto disable_running; @@ -580,9 +583,18 @@ static int qcom_pas_attach(struct rproc *rproc) goto disable_running; } + ret = irq_get_irqchip_state(pas->q6v5.stop_irq, + IRQCHIP_STATE_LINE_LEVEL, &stop_state); + if (ret) + goto disable_running; + + if (stop_state || qcom_sysmon_shutdown_irq_state(pas->sysmon)) { + dev_info(pas->dev, "Subsystem found stop state set. Falling back to start.\n"); + goto unroll_attach; + } + ret = irq_get_irqchip_state(pas->q6v5.ready_irq, IRQCHIP_STATE_LINE_LEVEL, &ready_state); - if (ret) goto disable_running; @@ -593,24 +605,16 @@ static int qcom_pas_attach(struct rproc *rproc) * start the remoteproc. */ dev_err(pas->dev, "Failed to get subsystem ready interrupt\n"); - pas->rproc->state = RPROC_OFFLINE; - ret = -EINVAL; - goto disable_running; - } - - ret = qcom_q6v5_ping_subsystem(&pas->q6v5); - - if (ret) { - dev_err(pas->dev, "Failed to ping subsystem, assuming device crashed\n"); - rproc_report_crash(rproc, RPROC_FATAL_ERROR); - goto disable_running; + goto unroll_attach; } - pas->q6v5.handover_issued = true; - return 0; +unroll_attach: + pas->rproc->state = RPROC_OFFLINE; + ret = -EINVAL; disable_running: + disable_irq(pas->q6v5.handover_irq); pas->q6v5.running = false; return ret; @@ -637,6 +641,7 @@ static const struct rproc_ops qcom_pas_minidump_ops = { .load = qcom_pas_load, .panic = qcom_pas_panic, .coredump = qcom_pas_minidump, + .attach = qcom_pas_attach, }; static int qcom_pas_init_clock(struct qcom_pas *pas) @@ -1020,7 +1025,6 @@ static int qcom_pas_probe(struct platform_device *pdev) pas->rproc->state = RPROC_DETACHED; } - ret = qcom_pas_setup_tmd(pas); if (ret) goto remove_ssr_sysmon; diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c index 913e3b750a869..a0830a48b1f40 100644 --- a/drivers/remoteproc/qcom_sysmon.c +++ b/drivers/remoteproc/qcom_sysmon.c @@ -736,6 +736,25 @@ bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon) } EXPORT_SYMBOL_GPL(qcom_sysmon_shutdown_acked); +bool qcom_sysmon_shutdown_irq_state(struct qcom_sysmon *sysmon) +{ + bool shutdown_state; + int ret; + + if (!sysmon) + return false; + + ret = irq_get_irqchip_state(sysmon->shutdown_irq, + IRQCHIP_STATE_LINE_LEVEL, &shutdown_state); + if (ret) { + dev_warn(sysmon->dev, "failed to get shutdown_state: %d\n", ret); + return false; + } + + return shutdown_state; +} +EXPORT_SYMBOL_GPL(qcom_sysmon_shutdown_irq_state); + /** * sysmon_probe() - probe sys_mon channel * @rpdev: rpmsg device handle From dbfedf8578e6d125de30de21259f226ac800034e Mon Sep 17 00:00:00 2001 From: Shawn Guo Date: Sat, 1 Aug 2026 09:17:31 +0800 Subject: [PATCH 3/3] FROMLIST: remoteproc: qcom: q6v5_pas: Don't enable handover IRQ on attach qcom_pas_attach() unmasks the handover IRQ and marks handover_issued even though this driver instance never runs qcom_q6v5_prepare() for the boot it is attaching to. This was believed necessary to flush a stale interrupt latched at the interrupt controller while masked, but the handover IRQ is a Qualcomm SMP2P soft IRQ, not a real edge-latched hardware interrupt. The Linux SMP2P driver updates its cached value unconditionally on every notification and only delivers the nested IRQ for bits currently enabled in its own software bitmap, so a transition that happens while masked is simply dropped, never replayed on a later unmask. Since there is nothing to flush, and this driver instance never takes the proxy power-domain/clock/regulator votes that the handover callback would tear down, there is no need to unmask the IRQ in attach() at all. Drop the enable_irq()/disable_irq() pair; setting handover_issued = true is sufficient to keep the flag consistent for the eventual qcom_q6v5_unprepare()/qcom_q6v5_prepare() cycle. It fixes the following unbalanced runtime PM usage and IRQ enable warnings seen on Nord ADSP (probed as attached), after commit bb7c5d6f5b41 ("remoteproc: qcom: q6v5: Make handover IRQ one-shot") comes in place. root@iq10-rrd:~# cat /sys/class/remoteproc/remoteproc0/state attached root@iq10-rrd:~# echo stop > /sys/class/remoteproc/remoteproc0/state [ 40.004874] genpd genpd:0:4c00000.remoteproc: Runtime PM usage count underflow! [ 40.012409] genpd genpd:1:4c00000.remoteproc: Runtime PM usage count underflow! [ 40.050074] remoteproc remoteproc0: stopped remote processor adsp root@iq10-rrd:~# echo start > /sys/class/remoteproc/remoteproc0/state [ 44.350298] remoteproc remoteproc0: powering up adsp [ 44.375769] remoteproc remoteproc0: Booting fw image qcom/nord/adsp.mbn, size 8241816 [ 44.389850] PDM: no support for the platform, userspace daemon might be required. [ 44.397864] ------------[ cut here ]------------ [ 44.402633] Unbalanced enable for IRQ 363 [ 44.406779] WARNING: kernel/irq/manage.c:775 at __enable_irq+0x4c/0x7c, CPU#9: sh/791 ... Suggested-by: Stephan Gerhold Link: https://lore.kernel.org/r/20260801011731.1084591-1-shengchao.guo@oss.qualcomm.com Signed-off-by: Shawn Guo Reviewed-by: Abel Vesa --- drivers/remoteproc/qcom_q6v5_pas.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index 719e9f661bcca..0ca373a294625 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -568,7 +568,6 @@ static int qcom_pas_attach(struct rproc *rproc) int ret; pas->q6v5.handover_issued = true; - enable_irq(pas->q6v5.handover_irq); pas->q6v5.running = true; ret = irq_get_irqchip_state(pas->q6v5.fatal_irq, @@ -614,7 +613,6 @@ static int qcom_pas_attach(struct rproc *rproc) pas->rproc->state = RPROC_OFFLINE; ret = -EINVAL; disable_running: - disable_irq(pas->q6v5.handover_irq); pas->q6v5.running = false; return ret;