mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Kumar, Udit" <u-kumar1@ti.com>
To: "Thomas Richard (TI.com)" <thomas.richard@bootlin.com>,
	Nishanth Menon <nm@ti.com>, Tero Kristo <kristo@kernel.org>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Michael Turquette <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>, Dhruva Gole <d-gole@ti.com>
Cc: Gregory CLEMENT <gregory.clement@bootlin.com>,
	<richard.genoud@bootlin.com>, Prasanth Mantena <p-mantena@ti.com>,
	"Abhash Kumar" <a-kumar2@ti.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-clk@vger.kernel.org>,
	<u-kumar1@ti.com>
Subject: Re: [PATCH v3 2/4] firmware: ti_sci: handle IRQ restore in BOARDCFG_MANAGED mode during resume
Date: Tue, 16 Dec 2025 08:17:24 +0530	[thread overview]
Message-ID: <bcc7a3da-3cb5-451b-98eb-4f7896c615a1@ti.com> (raw)
In-Reply-To: <20251205-ti-sci-jacinto-s2r-restore-irq-v3-2-d06963974ad4@bootlin.com>


On 12/5/2025 7:58 PM, Thomas Richard (TI.com) wrote:
> In BOARDCFG_MANAGED mode, the firmware cannot restore IRQs during
> resume. This 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.com) <thomas.richard@bootlin.com>
> ---
>   drivers/firmware/ti_sci.c | 147 +++++++++++++++++++++++++++++++++++++++++++---
>   1 file changed, 138 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
> index d77b631d9c855..8d94745376e2a 100644
> --- a/drivers/firmware/ti_sci.c
> +++ b/drivers/firmware/ti_sci.c
> @@ -12,6 +12,7 @@
>   #include <linux/cpu.h>
>   #include <linux/debugfs.h>
>   #include <linux/export.h>
> +#include <linux/hashtable.h>
>   #include <linux/io.h>
>   #include <linux/iopoll.h>
>   #include <linux/kernel.h>
> @@ -87,6 +88,16 @@ struct ti_sci_desc {
>   	int max_msg_size;
>   };
>   
> +/**
> + * 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_handle *handle,
>   	return ret;
>   }
>   
> +/**
> + * 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 are 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_handle *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 = 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 = 0x%x from src = %d, index = %d, to dst = %d, irq = %d,via ia_id = %d, vint = %d, global event = %d,status_bit = %d\n",
>   		 __func__, valid_params, src_id, src_index,
>   		 dst_id, dst_host_irq, ia_id, vint, global_event,
>   		 vint_status_bit);
>   
> -	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 = 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)
> +		return ret;
> +
> +	irq = kzalloc(sizeof(*irq), GFP_KERNEL);
> +	if (!irq)
> +		return -ENOMEM;
> +
> +	desc = &irq->desc;
> +	desc->valid_params = valid_params;
> +	desc->src_id = src_id;
> +	desc->src_index = src_index;
> +	desc->dst_id = dst_id;
> +	desc->dst_host_irq = dst_host_irq;
> +	desc->ia_id = ia_id;
> +	desc->vint = vint;
> +	desc->global_event = global_event;
> +	desc->vint_status_bit = vint_status_bit;
> +	desc->secondary_host = s_host;
> +
> +	hash_add(info->irqs, &irq->node, ti_sci_irq_hash(desc));
> +
> +	return 0;
>   }
>   
>   /**
> @@ -2358,15 +2425,46 @@ static int ti_sci_free_irq(const struct ti_sci_handle *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 = 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 = 0x%x from src = %d, index = %d, to dst = %d, irq = %d,via ia_id = %d, vint = %d, global event = %d,status_bit = %d\n",
>   		 __func__, valid_params, src_id, src_index,
>   		 dst_id, dst_host_irq, ia_id, vint, global_event,
>   		 vint_status_bit);
>   
> -	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 = 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)
> +		return ret;
> +
> +	irq_desc.valid_params = valid_params;
> +	irq_desc.src_id = src_id;
> +	irq_desc.src_index = src_index;
> +	irq_desc.dst_id = dst_id;
> +	irq_desc.dst_host_irq = dst_host_irq;
> +	irq_desc.ia_id = ia_id;
> +	irq_desc.vint = vint;
> +	irq_desc.global_event = global_event;
> +	irq_desc.vint_status_bit = vint_status_bit;
> +	irq_desc.secondary_host = 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;


IMO,  you can restrict saving of irq and list management to fw having

BOARDCFG_MANAGED capability.

Dhurva ?


> +		}
> +	}
> +
> +	return 0;
>   }
>   
>   /**
> [..]

  reply	other threads:[~2025-12-16  2:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 14:28 [PATCH v3 0/4] firmware: ti_sci: Introduce BOARDCFG_MANAGED mode for Jacinto family Thomas Richard (TI.com)
2025-12-05 14:28 ` [PATCH v3 1/4] firmware: ti_sci: add BOARDCFG_MANAGED mode support Thomas Richard (TI.com)
2025-12-16  2:43   ` Kumar, Udit
2025-12-05 14:28 ` [PATCH v3 2/4] firmware: ti_sci: handle IRQ restore in BOARDCFG_MANAGED mode during resume Thomas Richard (TI.com)
2025-12-16  2:47   ` Kumar, Udit [this message]
2025-12-17  5:29     ` Dhruva Gole
2025-12-18 10:17       ` Thomas Richard
2025-12-05 14:28 ` [PATCH v3 3/4] clk: keystone: sci-clk: add restore_context() operation Thomas Richard (TI.com)
2025-12-16  2:55   ` Kumar, Udit
2025-12-05 14:28 ` [PATCH v3 4/4] firmware: ti_sci: restore clock context during resume in BOARDCFG_MANAGED mode Thomas Richard (TI.com)
2025-12-17  6:07   ` Dhruva Gole
2025-12-18 10:19     ` Thomas Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bcc7a3da-3cb5-451b-98eb-4f7896c615a1@ti.com \
    --to=u-kumar1@ti.com \
    --cc=a-kumar2@ti.com \
    --cc=d-gole@ti.com \
    --cc=gregory.clement@bootlin.com \
    --cc=kristo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nm@ti.com \
    --cc=p-mantena@ti.com \
    --cc=richard.genoud@bootlin.com \
    --cc=sboyd@kernel.org \
    --cc=ssantosh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=thomas.richard@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®