Skip to contentSkip to conversation

arm: Use gic_enable/disable_irq() macro to clean up code

PATCH Applied Shaoqin Huang 3 participants 6 messages Mar 3, 2023 – Mar 21, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover arm: Use gic_enable/disable_irq() macro to clean up code

Some tests still use their own code to enable/disable irq, use gic_enable/disable_irq() to clean up them.

The first patch fixes a problem which will disable all irq when use gic_disable_irq().

The patch 2-3 clean up the code by using the macro.

Changelog:
----------
v3:
- s/diretly/directly.
- Refer Gic Spec to make comments more clear.
v2:
- tweak the comments in patch 1. (Eric)
- Reviewed by Eric.

Shaoqin Huang (3):
arm: gic: Write one bit per time in gic_irq_set_clr_enable()
arm64: timer: Use gic_enable/disable_irq() macro in timer test
arm64: microbench: Use gic_enable_irq() macro in microbench test

 arm/micro-bench.c | 15 +--------------
 arm/timer.c       | 20 +++-----------------
 lib/arm/gic.c     |  4 +---
 3 files changed, 5 insertions(+), 34 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH v3 1/3 arm: gic: Write one bit per time in gic_irq_set_clr_enable()

When use gic_irq_set_clr_enable() to disable an interrupt, it will disable all interrupt since it first read from Interrupt Clear-Enable Registers where '1' indicates that forwarding of the corresponding interrupt is enabled and then write this value with a mask into Interrupt Clear-Enable Registers where '1' indicates disable the forwarding of the corresponding interrupt.

So directly write one bit per time to enable or disable interrupt.

Fixes cb573c2 ("arm: gic: Introduce gic_irq_set_clr_enable() helper")
---
 lib/arm/gic.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/arm/gic.c +1 -3
index 1bfcfcf..89a15fe 100644
@@ -176,7 +176,6 @@ void gic_ipi_send_mask(int irq, const cpumask_t *dest)
 void gic_irq_set_clr_enable(int irq, bool enable)
 {
 	u32 offset, split = 32, shift = (irq % 32);
-	u32 reg, mask = BIT(shift);
 	void *base;
 
 	assert(irq < 1020);
@@ -199,8 +198,7 @@ void gic_irq_set_clr_enable(int irq, bool enable)
 		assert(0);
 	}
 	base += offset + (irq / split) * 4;
-	reg = readl(base);
-	writel(reg | mask, base);
+	writel(BIT(shift), base);
 }
 
 enum gic_irq_state gic_irq_state(int irq)
Signature · 1 line
2.39.1
#2 lore raw

PATCH v3 2/3 arm64: timer: Use gic_enable/disable_irq() macro in timer test

In reply to Shaoqin Huang

Use gic_enable/disable_irq() to clean up the code.

---
 arm/timer.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
arm/timer.c +3 -17
index c4e7b10..c0a8388 100644
@@ -14,9 +14,6 @@
 #include <asm/gic.h>
 #include <asm/io.h>
 
-static void *gic_isenabler;
-static void *gic_icenabler;
-
 static bool ptimer_unsupported;
 
 static void ptimer_unsupported_handler(struct pt_regs *regs, unsigned int esr)
@@ -139,12 +136,12 @@ static struct timer_info ptimer_info = {
 
 static void set_timer_irq_enabled(struct timer_info *info, bool enabled)
 {
-	u32 val = 1 << PPI(info->irq);
+	u32 irq = PPI(info->irq);
 
 	if (enabled)
-		writel(val, gic_isenabler);
+		gic_enable_irq(irq);
 	else
-		writel(val, gic_icenabler);
+		gic_disable_irq(irq);
 }
 
 static void irq_handler(struct pt_regs *regs)
@@ -366,17 +363,6 @@ static void test_init(void)
 
 	gic_enable_defaults();
 
-	switch (gic_version()) {
-	case 2:
-		gic_isenabler = gicv2_dist_base() + GICD_ISENABLER;
-		gic_icenabler = gicv2_dist_base() + GICD_ICENABLER;
-		break;
-	case 3:
-		gic_isenabler = gicv3_sgi_base() + GICR_ISENABLER0;
-		gic_icenabler = gicv3_sgi_base() + GICR_ICENABLER0;
-		break;
-	}
-
 	install_irq_handler(EL1H_IRQ, irq_handler);
 	set_timer_irq_enabled(&ptimer_info, true);
 	set_timer_irq_enabled(&vtimer_info, true);
Signature · 1 line
2.39.1
#3 lore raw

PATCH v3 3/3 arm64: microbench: Use gic_enable_irq() macro in microbench test

In reply to Shaoqin Huang

Use gic_enable_irq() to clean up code.

---
 arm/micro-bench.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
arm/micro-bench.c +1 -14
index 8436612..090fda6 100644
@@ -212,24 +212,11 @@ static void lpi_exec(void)
 
 static bool timer_prep(void)
 {
-	void *gic_isenabler;
-
 	gic_enable_defaults();
 	install_irq_handler(EL1H_IRQ, gic_irq_handler);
 	local_irq_enable();
 
-	switch (gic_version()) {
-	case 2:
-		gic_isenabler = gicv2_dist_base() + GICD_ISENABLER;
-		break;
-	case 3:
-		gic_isenabler = gicv3_sgi_base() + GICR_ISENABLER0;
-		break;
-	default:
-		assert_msg(0, "Unreachable");
-	}
-
-	writel(1 << PPI(TIMER_VTIMER_IRQ), gic_isenabler);
+	gic_enable_irq(PPI(TIMER_VTIMER_IRQ));
 	write_sysreg(ARCH_TIMER_CTL_IMASK | ARCH_TIMER_CTL_ENABLE, cntv_ctl_el0);
 	isb();
 
Signature · 1 line
2.39.1
reviewer Reviewed-by on the v3 series
#4 lore raw
In reply to Shaoqin Huang
Quoted 7 lines · Shaoqin Huang

Some tests still use their own code to enable/disable irq, use gic_enable/disable_irq() to clean up them.

The first patch fixes a problem which will disable all irq when use gic_disable_irq().

The patch 2-3 clean up the code by using the macro.

Series,

and seems that gic_irq_unmask() in arm/pl031.c can also be replaced by gic_enable_irq(pl031_irq).