All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
To: cip-dev@lists.cip-project.org,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>,
	Pavel Machek <pavel@denx.de>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Subject: [PATCH 5.10.y-cip 23/48] irqchip/sifive-plic: Separate the enable and mask operations
Date: Mon,  5 Feb 2024 12:41:10 +0000	[thread overview]
Message-ID: <20240205124135.14779-24-prabhakar.mahadev-lad.rj@bp.renesas.com> (raw)
In-Reply-To: <20240205124135.14779-1-prabhakar.mahadev-lad.rj@bp.renesas.com>

From: Samuel Holland <samuel@sholland.org>

commit a1706a1c5062e0908528170f853601ed53f428c8 upstream.

The PLIC has two per-IRQ checks before sending an IRQ to a hart context.
First, it checks that the IRQ's priority is nonzero. Then, it checks
that the enable bit is set for that combination of IRQ and context.

Currently, the PLIC driver sets both the priority value and the enable
bit in its (un)mask operations. However, modifying the enable bit is
problematic for two reasons:
  1) The enable bits are packed, so changes are not atomic and require
     taking a spinlock.
  2) The following requirement from the PLIC spec, which explains the
     racy (un)mask operations in plic_irq_eoi():

       If the completion ID does not match an interrupt source
       that is currently enabled for the target, the completion
       is silently ignored.

Both of these problems are solved by using the priority value to mask
IRQs. Each IRQ has a separate priority register, so writing the priority
value is atomic. And since the enable bit remains set while an IRQ is
masked, the EOI operation works normally. The enable bits are still used
to control the IRQ's affinity.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220701202440.59059-3-samuel@sholland.org
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/irqchip/irq-sifive-plic.c | 55 +++++++++++++++++++------------
 1 file changed, 34 insertions(+), 21 deletions(-)

diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c
index 364023c776d4..2673f726f85d 100644
--- a/drivers/irqchip/irq-sifive-plic.c
+++ b/drivers/irqchip/irq-sifive-plic.c
@@ -108,9 +108,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask,
 				   struct irq_data *d, int enable)
 {
 	int cpu;
-	struct plic_priv *priv = irq_data_get_irq_chip_data(d);
 
-	writel(enable, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID);
 	for_each_cpu(cpu, mask) {
 		struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu);
 
@@ -118,16 +116,37 @@ static inline void plic_irq_toggle(const struct cpumask *mask,
 	}
 }
 
-static void plic_irq_unmask(struct irq_data *d)
+static void plic_irq_enable(struct irq_data *d)
 {
 	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 1);
 }
 
-static void plic_irq_mask(struct irq_data *d)
+static void plic_irq_disable(struct irq_data *d)
 {
 	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);
 }
 
+static void plic_irq_unmask(struct irq_data *d)
+{
+	struct plic_priv *priv = irq_data_get_irq_chip_data(d);
+
+	writel(1, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID);
+}
+
+static void plic_irq_mask(struct irq_data *d)
+{
+	struct plic_priv *priv = irq_data_get_irq_chip_data(d);
+
+	writel(0, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID);
+}
+
+static void plic_irq_eoi(struct irq_data *d)
+{
+	struct plic_handler *handler = this_cpu_ptr(&plic_handlers);
+
+	writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM);
+}
+
 #ifdef CONFIG_SMP
 static int plic_set_affinity(struct irq_data *d,
 			     const struct cpumask *mask_val, bool force)
@@ -146,32 +165,21 @@ static int plic_set_affinity(struct irq_data *d,
 	if (cpu >= nr_cpu_ids)
 		return -EINVAL;
 
-	plic_irq_mask(d);
+	plic_irq_disable(d);
 
 	irq_data_update_effective_affinity(d, cpumask_of(cpu));
 
-	if (!irqd_irq_masked(d))
-		plic_irq_unmask(d);
+	if (!irqd_irq_disabled(d))
+		plic_irq_enable(d);
 
 	return IRQ_SET_MASK_OK_DONE;
 }
 #endif
 
-static void plic_irq_eoi(struct irq_data *d)
-{
-	struct plic_handler *handler = this_cpu_ptr(&plic_handlers);
-
-	if (irqd_irq_masked(d)) {
-		plic_irq_unmask(d);
-		writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM);
-		plic_irq_mask(d);
-	} else {
-		writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM);
-	}
-}
-
 static struct irq_chip plic_edge_chip = {
 	.name		= "SiFive PLIC",
+	.irq_enable	= plic_irq_enable,
+	.irq_disable	= plic_irq_disable,
 	.irq_ack	= plic_irq_eoi,
 	.irq_mask	= plic_irq_mask,
 	.irq_unmask	= plic_irq_unmask,
@@ -184,6 +192,8 @@ static struct irq_chip plic_edge_chip = {
 
 static struct irq_chip plic_chip = {
 	.name		= "SiFive PLIC",
+	.irq_enable	= plic_irq_enable,
+	.irq_disable	= plic_irq_disable,
 	.irq_mask	= plic_irq_mask,
 	.irq_unmask	= plic_irq_unmask,
 	.irq_eoi	= plic_irq_eoi,
@@ -431,8 +441,11 @@ static int __init __plic_init(struct device_node *node,
 			i * CONTEXT_ENABLE_SIZE;
 		handler->priv = priv;
 done:
-		for (hwirq = 1; hwirq <= nr_irqs; hwirq++)
+		for (hwirq = 1; hwirq <= nr_irqs; hwirq++) {
 			plic_toggle(handler, hwirq, 0);
+			writel(1, priv->regs + PRIORITY_BASE +
+				  hwirq * PRIORITY_PER_ID);
+		}
 		nr_handlers++;
 	}
 
-- 
2.34.1



  parent reply	other threads:[~2024-02-05 12:42 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 12:40 [PATCH 5.10.y-cip 00/48] Add support for Renesas RZ/Five RISC-V SoC Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 01/48] ASoC: dt-bindings: renesas,rz-ssi: Update interrupts and interrupt-names properties Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 02/48] ASoC: sh: rz-ssi: Update interrupt handling for half duplex channels Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 03/48] arm64: dts: renesas: r9a07g054: Update IRQ numbers for SSI channels Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 04/48] arm64: dts: renesas: r9a07g044: " Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 05/48] arm64: dts: renesas: rzg2ul-smarc: Move selecting PMOD_SCI0_EN to board DTS Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 06/48] arm64: dts: renesas: rzg2ul-smarc: Include SoM DTSI into " Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 07/48] arm64: dts: renesas: r9a07g043: Introduce SOC_PERIPHERAL_IRQ() macro to specify interrupt property Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 08/48] arm64: dts: renesas: r9a07g043: Update IRQ numbers for SSI channels Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 09/48] arm64: dts: renesas: r9a07g043: Split out RZ/G2UL SoC specific parts Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 10/48] cacheinfo: clear cache_leaves(cpu) in free_cache_attributes() Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 11/48] riscv: Kconfig: Enable cpufreq kconfig menu Lad Prabhakar
2024-02-05 12:40 ` [PATCH 5.10.y-cip 12/48] dma-direct: add support for dma_coherent_default_memory Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 13/48] dma-mapping: allow using the global coherent pool for !ARM Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 14/48] dma-mapping: simplify dma_init_coherent_memory Lad Prabhakar
2024-02-06  9:18   ` nobuhiro1.iwamatsu
2024-02-06  9:52     ` Prabhakar Mahadev Lad
2024-02-06 10:12       ` Pavel Machek
2024-02-06 11:42         ` Prabhakar Mahadev Lad
2024-02-05 12:41 ` [PATCH 5.10.y-cip 15/48] dma-mapping: add a dma_init_global_coherent helper Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 16/48] dma-mapping: make the global coherent pool conditional Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 17/48] of: also handle dma-noncoherent in of_dma_is_coherent() Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 18/48] of/irq: Use interrupts-extended to find parent Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 19/48] irqchip/sifive-plic: Improve naming scheme for per context offsets Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 20/48] irqchip/sifive-plic: Disable S-mode IRQs if running in M-mode Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 21/48] irqchip/sifive-plic: Add support for Renesas RZ/Five SoC Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 22/48] irqchip/sifive-plic: Make better use of the effective affinity mask Lad Prabhakar
2024-02-05 12:41 ` Lad Prabhakar [this message]
2024-02-05 12:41 ` [PATCH 5.10.y-cip 24/48] clocksource/drivers/renesas-ostm: Add support for RZ/V2L SoC Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 25/48] clocksource/drivers/riscv: Increase the clock source rating Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 26/48] clocksource/drivers/riscv: Get rid of clocksource_arch_init() callback Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 27/48] mmc: host: Kconfig: Make MMC_SDHI_INTERNAL_DMAC config option dependant on ARCH_RENESAS Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 28/48] dt-bindings: riscv: Sort the CPU core list alphabetically Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 29/48] dt-bindings: riscv: Add Andes AX45MP core to the list Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 30/48] dt-bindings: clock: r9a07g043-cpg: Add Renesas RZ/Five CPG Clock and Reset Definitions Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 31/48] dt-bindings: cache: andestech,ax45mp-cache: Add DT binding documentation for L2 cache controller Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 32/48] soc: renesas: Identify RZ/Five SoC Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 33/48] clk: renesas: r9a07g043: Add support for " Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 34/48] cache: Add L2 cache management for Andes AX45MP RISC-V core Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 35/48] cache: ax45mp_cache: Add non coherent support Lad Prabhakar
2024-02-05 19:36   ` Pavel Machek
2024-02-05 12:41 ` [PATCH 5.10.y-cip 36/48] soc: renesas: Kconfig: Select the required configs for RZ/Five SoC Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 37/48] riscv: Kconfig.socs: Add ARCH_RENESAS kconfig option Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 38/48] riscv: dts: renesas: Add initial devicetree for Renesas RZ/Five SoC Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 39/48] riscv: dts: renesas: Add minimal DTS for Renesas RZ/Five SMARC EVK Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 40/48] riscv: dts: renesas: r9a07g043f/rzfive-smarc-som: Enable ADC/OPP/Thermal Zones/TSU Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 41/48] riscv: dts: renesas: rzfive-smarc: Enable CANFD/I2C Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 42/48] riscv: dts: renesas: rzfive-smarc-som: Enable WDT Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 43/48] riscv: dts: renesas: rzfive-smarc-som: Enable OSTM nodes Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 44/48] riscv: dts: renesas: rzfive-smarc-som: Drop PHY interrupt support for ETH{0,1} Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 45/48] riscv: dts: renesas: Clean up dtbs_check W=1 warning due to empty phy node Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 46/48] riscv: dts: renesas: r9a07g043f: Add L2 cache node Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 47/48] riscv: dts: renesas: r9a07g043f: Add dma-noncoherent property Lad Prabhakar
2024-02-05 12:41 ` [PATCH 5.10.y-cip 48/48] riscv: dts: renesas: rzfive-smarc: Enable the blocks which were explicitly disabled Lad Prabhakar
2024-02-05 19:33 ` [PATCH 5.10.y-cip 00/48] Add support for Renesas RZ/Five RISC-V SoC Pavel Machek
2024-02-06  8:20 ` nobuhiro1.iwamatsu
2024-02-06  8:29 ` Pavel Machek
2024-02-06  9:02   ` Prabhakar Mahadev Lad
2024-02-06  9:08     ` Pavel Machek

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=20240205124135.14779-24-prabhakar.mahadev-lad.rj@bp.renesas.com \
    --to=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=pavel@denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.