From nobody Tue Feb 10 04:15:12 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73C5C4219F6; Wed, 4 Feb 2026 15:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770217442; cv=none; b=fJZRganu1d/EFxu7ciyYCimeS4jwDKxFYpfAdB7IMBNJR2MeAlgz+1Ozwvz1jGvAuS4Lw+MFPpHkuFMDW/3BG4zt1EEcSUrKm8FhadBGVPUzF7yshhtCEO/yMx99G/b0YU1xmlpTF2Lk7sBdk0uhdL/sTQRYbKpFYDmjy9f7M8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770217442; c=relaxed/simple; bh=IVlaZyxTbDvAUzq2zYKRtHWEEQHA5MUwmc9r7odreew=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W4CIOGMjy/vC2JspleK1uuuW9G87yRC7vdkmNObIJzinTNPbKaaX3GZjX09C0OCbK8yczRFX6e7zXl8HTLRCoNhdFiIlcIGmZfAwK3qCseZ5NGlavfB6xT7phpPFJJlNtYtAv0N65GT8/tSLWfX6II/DrQgOEDfZTxntY/gslsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=e3TfmBRo; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="e3TfmBRo" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 328541A2BEB; Wed, 4 Feb 2026 15:04:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 032D560705; Wed, 4 Feb 2026 15:04:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F0B90119A8891; Wed, 4 Feb 2026 16:03:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1770217440; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=G4UNSy88KQWm8WOMSSIMqsO1f4If8xoX3YXDKQyUN9o=; b=e3TfmBRo14ruyhe7FEggc0w2r3fTPV5ON3fWyNeEJQw3dxSuoRhVY41a7RwABTW6Vb+Yqh exrghVodzNmbPYcfDj4phUFTj6STThZhDwwSwyGgDpmXO+4NzksbLBBXjfvCk4ByBnogJn kLgh2hq0MC12ngo5FkuYdrc1UqEcdOlUVvpgxKwX0pJc1GY81yTG9+EKx5c47EVzMDfb+s 66XWaI3IlmMYD7toRju9pUiOTReDpUORgBuz2fIjTcsCAcraqXuTV3ZfI3X5YGReITbjDF nfHo0inD5u4O0jKba5QvblxFjRi4YLZ5qyl7ZF3O7eL5dxztqplHuIYQS4d+vg== From: "Thomas Richard (TI)" Date: Wed, 04 Feb 2026 16:03:39 +0100 Subject: [PATCH v4 2/4] firmware: ti_sci: add support for restoring IRQs during resume Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-ti-sci-jacinto-s2r-restore-irq-v4-2-67820af39eac@bootlin.com> References: <20260204-ti-sci-jacinto-s2r-restore-irq-v4-0-67820af39eac@bootlin.com> In-Reply-To: <20260204-ti-sci-jacinto-s2r-restore-irq-v4-0-67820af39eac@bootlin.com> To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Michael Turquette , Stephen Boyd Cc: Gregory CLEMENT , richard.genoud@bootlin.com, Udit Kumar , Prasanth Mantena , Abhash Kumar , Thomas Petazzoni , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, "Thomas Richard (TI)" X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 Some DM-Firmware are not able to restore the IRQ context after a suspend-resume. The IRQ_CONTEXT_LOST firmware capability has been introduced to identify this characteristic. In this case the responsibility is delegated to the ti_sci driver, which maintains an internal list of all requested IRQs. This list is updated on each set()/free() operation, and all IRQs are restored during the resume_noirq() phase. Signed-off-by: Thomas Richard (TI) --- drivers/firmware/ti_sci.c | 153 ++++++++++++++++++++++++++++++++++++++++++= ---- drivers/firmware/ti_sci.h | 2 + 2 files changed, 144 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index eaeaaae94142..8e43e69ef7c4 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,16 @@ struct ti_sci_desc { int max_msg_size; }; =20 +/** + * struct ti_sci_irq - Description of allocated irqs + * @node: Link to hash table + * @desc: Description of the irq + */ +struct ti_sci_irq { + struct hlist_node node; + struct ti_sci_msg_req_manage_irq desc; +}; + /** * struct ti_sci_info - Structure representing a TI SCI instance * @dev: Device pointer @@ -101,6 +112,7 @@ struct ti_sci_desc { * @chan_rx: Receive mailbox channel * @minfo: Message info * @node: list head + * @irqs: List of allocated irqs * @host_id: Host ID * @fw_caps: FW/SoC low power capabilities * @users: Number of users of this instance @@ -117,6 +129,7 @@ struct ti_sci_info { struct mbox_chan *chan_tx; struct mbox_chan *chan_rx; struct ti_sci_xfers_info minfo; + DECLARE_HASHTABLE(irqs, 8); struct list_head node; u8 host_id; u64 fw_caps; @@ -2301,6 +2314,32 @@ static int ti_sci_manage_irq(const struct ti_sci_han= dle *handle, return ret; } =20 +/** + * ti_sci_irq_hash() - Helper API to compute irq hash for the hash table. + * @irq: irq to hash + * + * Return: the computed hash value. + */ +static int ti_sci_irq_hash(struct ti_sci_msg_req_manage_irq *irq) +{ + return irq->src_id ^ irq->src_index; +} + +/** + * ti_sci_irq_equal() - Helper API to compare two irqs (generic headers ar= e not + * compared) + * @irq_a: irq_a to compare + * @irq_b: irq_b to compare + * + * Return: true if the two irqs are equal, else false. + */ +static bool ti_sci_irq_equal(struct ti_sci_msg_req_manage_irq *irq_a, + struct ti_sci_msg_req_manage_irq *irq_b) +{ + return !memcmp(&irq_a->valid_params, &irq_b->valid_params, + sizeof(*irq_a) - sizeof(irq_a->hdr)); +} + /** * ti_sci_set_irq() - Helper api to configure the irq route between the * requested source and destination @@ -2324,15 +2363,43 @@ static int ti_sci_set_irq(const struct ti_sci_handl= e *handle, u32 valid_params, u16 dst_host_irq, u16 ia_id, u16 vint, u16 global_event, u8 vint_status_bit, u8 s_host) { + struct ti_sci_info *info =3D handle_to_ti_sci_info(handle); + struct ti_sci_msg_req_manage_irq *desc; + struct ti_sci_irq *irq; + int ret; + pr_debug("%s: IRQ set with valid_params =3D 0x%x from src =3D %d, index = =3D %d, to dst =3D %d, irq =3D %d,via ia_id =3D %d, vint =3D %d, global eve= nt =3D %d,status_bit =3D %d\n", __func__, valid_params, src_id, src_index, dst_id, dst_host_irq, ia_id, vint, global_event, vint_status_bit); =20 - return ti_sci_manage_irq(handle, valid_params, src_id, src_index, - dst_id, dst_host_irq, ia_id, vint, - global_event, vint_status_bit, s_host, - TI_SCI_MSG_SET_IRQ); + ret =3D ti_sci_manage_irq(handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit, s_host, + TI_SCI_MSG_SET_IRQ); + + if (ret || !(info->fw_caps & MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST)) + return ret; + + irq =3D kzalloc(sizeof(*irq), GFP_KERNEL); + if (!irq) + return -ENOMEM; + + desc =3D &irq->desc; + desc->valid_params =3D valid_params; + desc->src_id =3D src_id; + desc->src_index =3D src_index; + desc->dst_id =3D dst_id; + desc->dst_host_irq =3D dst_host_irq; + desc->ia_id =3D ia_id; + desc->vint =3D vint; + desc->global_event =3D global_event; + desc->vint_status_bit =3D vint_status_bit; + desc->secondary_host =3D s_host; + + hash_add(info->irqs, &irq->node, ti_sci_irq_hash(desc)); + + return 0; } =20 /** @@ -2358,15 +2425,46 @@ static int ti_sci_free_irq(const struct ti_sci_hand= le *handle, u32 valid_params, u16 dst_host_irq, u16 ia_id, u16 vint, u16 global_event, u8 vint_status_bit, u8 s_host) { + struct ti_sci_info *info =3D handle_to_ti_sci_info(handle); + struct ti_sci_msg_req_manage_irq irq_desc; + struct ti_sci_irq *this_irq; + struct hlist_node *tmp_node; + int ret; + pr_debug("%s: IRQ release with valid_params =3D 0x%x from src =3D %d, ind= ex =3D %d, to dst =3D %d, irq =3D %d,via ia_id =3D %d, vint =3D %d, global = event =3D %d,status_bit =3D %d\n", __func__, valid_params, src_id, src_index, dst_id, dst_host_irq, ia_id, vint, global_event, vint_status_bit); =20 - return ti_sci_manage_irq(handle, valid_params, src_id, src_index, - dst_id, dst_host_irq, ia_id, vint, - global_event, vint_status_bit, s_host, - TI_SCI_MSG_FREE_IRQ); + ret =3D ti_sci_manage_irq(handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit, s_host, + TI_SCI_MSG_FREE_IRQ); + + if (ret || !(info->fw_caps & MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST)) + return ret; + + irq_desc.valid_params =3D valid_params; + irq_desc.src_id =3D src_id; + irq_desc.src_index =3D src_index; + irq_desc.dst_id =3D dst_id; + irq_desc.dst_host_irq =3D dst_host_irq; + irq_desc.ia_id =3D ia_id; + irq_desc.vint =3D vint; + irq_desc.global_event =3D global_event; + irq_desc.vint_status_bit =3D vint_status_bit; + irq_desc.secondary_host =3D s_host; + + hash_for_each_possible_safe(info->irqs, this_irq, tmp_node, node, + ti_sci_irq_hash(&irq_desc)) { + if (ti_sci_irq_equal(&irq_desc, &this_irq->desc)) { + hlist_del(&this_irq->node); + kfree(this_irq); + return 0; + } + } + + return 0; } =20 /** @@ -3847,7 +3945,10 @@ static int ti_sci_suspend_noirq(struct device *dev) static int ti_sci_resume_noirq(struct device *dev) { struct ti_sci_info *info =3D dev_get_drvdata(dev); - int ret =3D 0; + struct ti_sci_msg_req_manage_irq *irq_desc; + struct ti_sci_irq *irq; + struct hlist_node *tmp_node; + int ret =3D 0, i; u32 source; u64 time; u8 pin; @@ -3859,6 +3960,32 @@ static int ti_sci_resume_noirq(struct device *dev) return ret; } =20 + switch (pm_suspend_target_state) { + case PM_SUSPEND_MEM: + if (info->fw_caps & MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST) { + hash_for_each_safe(info->irqs, i, tmp_node, irq, node) { + irq_desc =3D &irq->desc; + ret =3D ti_sci_manage_irq(&info->handle, + irq_desc->valid_params, + irq_desc->src_id, + irq_desc->src_index, + irq_desc->dst_id, + irq_desc->dst_host_irq, + irq_desc->ia_id, + irq_desc->vint, + irq_desc->global_event, + irq_desc->vint_status_bit, + irq_desc->secondary_host, + TI_SCI_MSG_SET_IRQ); + if (ret) + return ret; + } + } + break; + default: + break; + } + ret =3D ti_sci_msg_cmd_lpm_wake_reason(&info->handle, &source, &time, &pi= n, &mode); /* Do not fail to resume on error as the wake reason is not critical */ if (!ret) @@ -4014,13 +4141,14 @@ static int ti_sci_probe(struct platform_device *pde= v) } =20 ti_sci_msg_cmd_query_fw_caps(&info->handle, &info->fw_caps); - dev_dbg(dev, "Detected firmware capabilities: %s%s%s%s%s%s\n", + dev_dbg(dev, "Detected firmware capabilities: %s%s%s%s%s%s%s\n", info->fw_caps & MSG_FLAG_CAPS_GENERIC ? "Generic" : "", info->fw_caps & MSG_FLAG_CAPS_LPM_PARTIAL_IO ? " Partial-IO" : "", info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED ? " DM-Managed" : "", info->fw_caps & MSG_FLAG_CAPS_LPM_ABORT ? " LPM-Abort" : "", info->fw_caps & MSG_FLAG_CAPS_IO_ISOLATION ? " IO-Isolation" : "", - info->fw_caps & MSG_FLAG_CAPS_LPM_BOARDCFG_MANAGED ? " BoardConfig-Manag= ed" : "" + info->fw_caps & MSG_FLAG_CAPS_LPM_BOARDCFG_MANAGED ? " BoardConfig-Manag= ed" : "", + info->fw_caps & MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST ? " IRQ-Context-Lost"= : "" ); =20 ti_sci_setup_ops(info); @@ -4053,6 +4181,9 @@ static int ti_sci_probe(struct platform_device *pdev) list_add_tail(&info->node, &ti_sci_list); mutex_unlock(&ti_sci_list_mutex); =20 + if (info->fw_caps & MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST) + hash_init(info->irqs); + ret =3D of_platform_populate(dev->of_node, NULL, NULL, dev); if (ret) { dev_err(dev, "platform_populate failed %pe\n", ERR_PTR(ret)); diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index d90de59e29eb..67f16e8c69a1 100644 --- a/drivers/firmware/ti_sci.h +++ b/drivers/firmware/ti_sci.h @@ -151,6 +151,7 @@ struct ti_sci_msg_req_reboot { * MSG_FLAG_CAPS_LPM_ABORT: Abort entry to LPM * MSG_FLAG_CAPS_IO_ISOLATION: IO Isolation support * MSG_FLAG_CAPS_LPM_BOARDCFG_MANAGED: LPM config done statically for the= DM via boardcfg + * MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST: DM is not able to restore IRQ cont= ext * * Response to a generic message with message type TI_SCI_MSG_QUERY_FW_CAPS * providing currently available SOC/firmware capabilities. SoC that don't @@ -164,6 +165,7 @@ struct ti_sci_msg_resp_query_fw_caps { #define MSG_FLAG_CAPS_LPM_ABORT TI_SCI_MSG_FLAG(9) #define MSG_FLAG_CAPS_IO_ISOLATION TI_SCI_MSG_FLAG(7) #define MSG_FLAG_CAPS_LPM_BOARDCFG_MANAGED TI_SCI_MSG_FLAG(12) +#define MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST TI_SCI_MSG_FLAG(14) #define MSG_MASK_CAPS_LPM GENMASK_ULL(4, 1) u64 fw_caps; } __packed; --=20 2.51.0