mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dawei Li <dawei.li@shingroup.cn>
To: tglx@linutronix.de, maz@kernel.org
Cc: sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dawei.li@shingroup.cn,
	set_pte_at@outlook.com
Subject: [PATCH v2 1/5] irqchip/gic-v3: Implement read polling with dedicated API
Date: Mon, 22 Jan 2024 16:57:12 +0800	[thread overview]
Message-ID: <20240122085716.2999875-2-dawei.li@shingroup.cn> (raw)
In-Reply-To: <20240122085716.2999875-1-dawei.li@shingroup.cn>

Kernel provide read*_poll_* API family to support looping based polling
code pattern like below:

while (...)
{
	val = op(addr);
	condition = cond(val);
	if (condition)
		break;

	/* Maybe some timeout handling stuff */

	cpu_relax();
	udelay();
}

As such, use readl_relaxed_poll_timeout_atomic() to implement atomic
register polling logic in gic-v3.

It's worth noting that this conversion would be impossilbe without
support of commit 7349a69cf312 ("iopoll: Do not use timekeeping in
read_poll_timeout_atomic()"), which remove time keeping code from
read_poll_timeout_atomic(), reason below:

Compared to other 'ordinary' device driver, IRQ chip driver is kinda
special, whose initialization(via init_IRQ()) happens pretty early,
even before timekeeping_init(). As a result, calling time keeping code
in irq chip init code is bogus.

Signed-off-by: Dawei Li <dawei.li@shingroup.cn>
---
 drivers/irqchip/irq-gic-v3.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index 98b0329b7154..020a67195b16 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -19,6 +19,7 @@
 #include <linux/percpu.h>
 #include <linux/refcount.h>
 #include <linux/slab.h>
+#include <linux/iopoll.h>
 
 #include <linux/irqchip.h>
 #include <linux/irqchip/arm-gic-common.h>
@@ -251,17 +252,16 @@ static inline void __iomem *gic_dist_base(struct irq_data *d)
 
 static void gic_do_wait_for_rwp(void __iomem *base, u32 bit)
 {
-	u32 count = 1000000;	/* 1s! */
+	u32 val;
+	int ret;
 
-	while (readl_relaxed(base + GICD_CTLR) & bit) {
-		count--;
-		if (!count) {
-			pr_err_ratelimited("RWP timeout, gone fishing\n");
-			return;
-		}
-		cpu_relax();
-		udelay(1);
-	}
+	ret = readl_relaxed_poll_timeout_atomic(base + GICD_CTLR,
+						val,
+						!(val & bit),
+						1,
+						USEC_PER_SEC);
+	if (ret == -ETIMEDOUT)
+		pr_err_ratelimited("RWP timeout, gone fishing\n");
 }
 
 /* Wait for completion of a distributor change */
@@ -279,8 +279,8 @@ static void gic_redist_wait_for_rwp(void)
 static void gic_enable_redist(bool enable)
 {
 	void __iomem *rbase;
-	u32 count = 1000000;	/* 1s! */
 	u32 val;
+	int ret;
 
 	if (gic_data.flags & FLAGS_WORKAROUND_GICR_WAKER_MSM8996)
 		return;
@@ -301,14 +301,12 @@ static void gic_enable_redist(bool enable)
 			return;	/* No PM support in this redistributor */
 	}
 
-	while (--count) {
-		val = readl_relaxed(rbase + GICR_WAKER);
-		if (enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep))
-			break;
-		cpu_relax();
-		udelay(1);
-	}
-	if (!count)
+	ret = readl_relaxed_poll_timeout_atomic(rbase + GICR_WAKER,
+						val,
+						enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep),
+						1,
+						USEC_PER_SEC);
+	if (ret == -ETIMEDOUT)
 		pr_err_ratelimited("redistributor failed to %s...\n",
 				   enable ? "wakeup" : "sleep");
 }
-- 
2.27.0


  reply	other threads:[~2024-01-22  8:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22  8:57 [PATCH v2 0/5] Minor cleanup on gic(v3) and genirq Dawei Li
2024-01-22  8:57 ` Dawei Li [this message]
2024-01-24 18:35   ` [tip: irq/core] irqchip/gic-v3: Use readl_relaxed_poll_timeout_atomic() tip-bot2 for Dawei Li
2024-01-22  8:57 ` [PATCH v2 2/5] irqchip/gic(v3): Replace gic_irq() with irqd_to_hwirq() Dawei Li
2024-01-24 18:35   ` [tip: irq/core] " tip-bot2 for Dawei Li
2024-01-22  8:57 ` [PATCH v2 3/5] genirq: Remove unneeded forward declaration Dawei Li
2024-01-24 18:35   ` [tip: irq/core] " tip-bot2 for Dawei Li
2024-01-22  8:57 ` [PATCH v2 4/5] genirq: Initialize resend_node hlist for all irq_desc Dawei Li
2024-01-24 18:35   ` [tip: irq/core] genirq: Initialize resend_node hlist for all interrupt descriptors tip-bot2 for Dawei Li
2024-01-22  8:57 ` [PATCH v2 5/5] genirq: Introduce generic init_desc() Dawei Li
2024-01-24 18:35   ` [tip: irq/core] genirq: Deduplicate interrupt descriptor initialization tip-bot2 for Dawei Li

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=20240122085716.2999875-2-dawei.li@shingroup.cn \
    --to=dawei.li@shingroup.cn \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=sdonthineni@nvidia.com \
    --cc=set_pte_at@outlook.com \
    --cc=tglx@linutronix.de \
    /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®