* [PATCH v2 0/3] Add UltraRISC DP1000 PLIC support
@ 2025-10-13 11:15 Lucas Zampieri
2025-10-13 11:15 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: add UltraRISC Lucas Zampieri
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Lucas Zampieri @ 2025-10-13 11:15 UTC (permalink / raw)
To: linux-kernel
Cc: Lucas Zampieri, Thomas Gleixner, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Paul Walmsley, Samuel Holland, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Vivian Wang, devicetree, linux-riscv
This series adds support for the PLIC implementation in the UltraRISC
DP1000 SoC. The DP1000 PLIC claim register has a hardware bug where
reading it while multiple interrupts are pending can return the wrong
interrupt ID. The workaround temporarily disables all interrupts except
the first pending one before reading the claim register, then restores
the previous state.
The driver matches on "ultrarisc,cp100-plic" (CPU core compatible), allowing
the quirk to apply to all SoCs using UR-CP100 cores (currently DP1000,
potentially future SoCs).
Charles Mirabile (2):
dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC
irqchip/plic: add support for UltraRISC DP1000 PLIC
Lucas Zampieri (1):
dt-bindings: vendor-prefixes: add UltraRISC
Changes in v2:
- 0002: Changed compatible string pattern to SoC+core: ultrarisc,dp1000-plic
with ultrarisc,cp100-plic fallback (suggested by Krzysztof and Vivian)
- 0003: Driver now matches on ultrarisc,cp100-plic (core) instead of dp1000 (SoC)
- All patches: Added submitter Signed-off-by to complete DCO chain
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
.../interrupt-controller/sifive,plic-1.0.0.yaml | 3 +
drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++-
3 files changed, 87 insertions(+), 1 deletion(-)
--
2.51.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v2 1/3] dt-bindings: vendor-prefixes: add UltraRISC 2025-10-13 11:15 [PATCH v2 0/3] Add UltraRISC DP1000 PLIC support Lucas Zampieri @ 2025-10-13 11:15 ` Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 3/3] irqchip/plic: add support for " Lucas Zampieri 2 siblings, 0 replies; 14+ messages in thread From: Lucas Zampieri @ 2025-10-13 11:15 UTC (permalink / raw) To: devicetree Cc: Lucas Zampieri, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Vivian Wang, linux-kernel Add vendor prefix for UltraRISC Technology Co., Ltd. Signed-off-by: Lucas Zampieri <lzampier@redhat.com> Acked-by: Rob Herring (Arm) <robh@kernel.org> --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 123456789abc..234567890def 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -1642,6 +1642,8 @@ patternProperties: description: Universal Scientific Industrial Co., Ltd. "^usr,.*": description: U.S. Robotics Corporation + "^ultrarisc,.*": + description: UltraRISC Technology Co., Ltd. "^ultratronik,.*": description: Ultratronik GmbH "^utoo,.*": -- 2.51.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC 2025-10-13 11:15 [PATCH v2 0/3] Add UltraRISC DP1000 PLIC support Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: add UltraRISC Lucas Zampieri @ 2025-10-13 11:15 ` Lucas Zampieri 2025-10-13 18:25 ` Conor Dooley 2025-10-13 11:15 ` [PATCH v2 3/3] irqchip/plic: add support for " Lucas Zampieri 2 siblings, 1 reply; 14+ messages in thread From: Lucas Zampieri @ 2025-10-13 11:15 UTC (permalink / raw) To: devicetree Cc: Charles Mirabile, Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, linux-kernel, Lucas Zampieri From: Charles Mirabile <cmirabil@redhat.com> Add a new compatible string for UltraRISC DP1000 PLIC. Signed-off-by: Charles Mirabile <cmirabil@redhat.com> Signed-off-by: Lucas Zampieri <lzampier@redhat.com> --- .../bindings/interrupt-controller/sifive,plic-1.0.0.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml b/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml index 5b827bc24301..a419de50f5a8 100644 --- a/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml +++ b/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml @@ -74,6 +74,8 @@ properties: - sophgo,sg2044-plic - thead,th1520-plic - const: thead,c900-plic + - items: + - const: ultrarisc,dp1000-plic + - const: ultrarisc,cp100-plic - items: - const: sifive,plic-1.0.0 - const: riscv,plic0 -- 2.51.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC 2025-10-13 11:15 ` [PATCH v2 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC Lucas Zampieri @ 2025-10-13 18:25 ` Conor Dooley 0 siblings, 0 replies; 14+ messages in thread From: Conor Dooley @ 2025-10-13 18:25 UTC (permalink / raw) To: Lucas Zampieri Cc: devicetree, Charles Mirabile, Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1413 bytes --] On Mon, Oct 13, 2025 at 12:15:37PM +0100, Lucas Zampieri wrote: > From: Charles Mirabile <cmirabil@redhat.com> > > Add a new compatible string for UltraRISC DP1000 PLIC. > > Signed-off-by: Charles Mirabile <cmirabil@redhat.com> > Signed-off-by: Lucas Zampieri <lzampier@redhat.com> > --- > .../bindings/interrupt-controller/sifive,plic-1.0.0.yaml | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml b/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml > index 5b827bc24301..a419de50f5a8 100644 > --- a/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml > +++ b/Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml > @@ -74,6 +74,8 @@ properties: > - sophgo,sg2044-plic > - thead,th1520-plic > - const: thead,c900-plic > + - items: > + - const: ultrarisc,dp1000-plic > + - const: ultrarisc,cp100-plic Based on your cover letter, this is problem not incorrect, but this fails the eye test and looks wrong. Please mention in your commit message that dp1000 is an soc and cp100 is a purchasable IP core. pw-bot: changes-requested > - items: > - const: sifive,plic-1.0.0 > - const: riscv,plic0 > -- > 2.51.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 11:15 [PATCH v2 0/3] Add UltraRISC DP1000 PLIC support Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: add UltraRISC Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC Lucas Zampieri @ 2025-10-13 11:15 ` Lucas Zampieri 2025-10-13 18:30 ` Conor Dooley 2025-10-13 19:00 ` Samuel Holland 2 siblings, 2 replies; 14+ messages in thread From: Lucas Zampieri @ 2025-10-13 11:15 UTC (permalink / raw) To: linux-kernel Cc: Charles Mirabile, Thomas Gleixner, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng, Lucas Zampieri From: Charles Mirabile <cmirabil@redhat.com> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to work around a known hardware bug with IRQ claiming. When claiming an interrupt on the DP1000 PLIC all other interrupts must be disabled before the claim register is accessed to prevent incorrect handling of the interrupt. When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq the enable state of all interrupts is saved and then all interrupts except for the first pending one are disabled before reading the claim register. The interrupts are then restored before further processing of the claimed interrupt continues. The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all SoCs using UR-CP100 cores, regardless of the specific SoC implementation. This has no impact on other platforms. Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> Signed-off-by: Charles Mirabile <cmirabil@redhat.com> Signed-off-by: Lucas Zampieri <lzampier@redhat.com> --- drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 9c4af7d58846..a7b51a925e96 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -49,6 +49,8 @@ #define CONTEXT_ENABLE_BASE 0x2000 #define CONTEXT_ENABLE_SIZE 0x80 +#define PENDING_BASE 0x1000 + /* * Each hart context has a set of control registers associated with it. Right * now there's only two: a source priority threshold over which the hart will @@ -63,6 +65,7 @@ #define PLIC_ENABLE_THRESHOLD 0 #define PLIC_QUIRK_EDGE_INTERRUPT 0 +#define PLIC_QUIRK_CLAIM_REGISTER 1 struct plic_priv { struct fwnode_handle *fwnode; @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { .free = irq_domain_free_irqs_top, }; +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], + void __iomem *pending, + void __iomem *enable) +{ + u32 pending_irqs = 0; + int i, j; + + /* Look for first pending interrupt */ + for (i = 0; i < nr_irq_groups; i++) { + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); + if (pending_irqs) + break; + } + + if (!pending_irqs) + return false; + + /* Disable all interrupts but the first pending one */ + for (j = 0; j < nr_irq_groups; j++) { + u32 new_mask = 0; + + if (j == i) + /* Extract mask with lowest set bit */ + new_mask = (pending_irqs & -pending_irqs); + + writel(new_mask, enable + j * sizeof(u32)); + } + + return true; +} + +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, + void __iomem *claim) +{ + void __iomem *enable = handler->enable_base; + void __iomem *pending = handler->priv->regs + PENDING_BASE; + int nr_irqs = handler->priv->nr_irqs; + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); + int i; + u32 ie[32] = { 0 }; + irq_hw_number_t hwirq = 0; + + raw_spin_lock(&handler->enable_lock); + + /* Save current interrupt enable state */ + for (i = 0; i < nr_irq_groups; i++) + ie[i] = readl(enable + i * sizeof(u32)); + + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) + goto out; + + hwirq = readl(claim); + + /* Restore previous state */ + for (i = 0; i < nr_irq_groups; i++) + writel(ie[i], enable + i * sizeof(u32)); +out: + raw_spin_unlock(&handler->enable_lock); + return hwirq; +} + +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, + void __iomem *claim) +{ + /* + * Due to a hardware bug in the implementation of the claim register + * in the UltraRISC DP1000 platform, other interrupts must be disabled + * before reading the claim register and restored afterwards. + */ + + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) + return dp1000_get_hwirq(handler, claim); + + return readl(claim); +} + /* * Handling an interrupt is a two-step process: first you claim the interrupt * by reading the claim register, then you complete the interrupt by writing @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) chained_irq_enter(chip, desc); - while ((hwirq = readl(claim))) { + while ((hwirq = plic_get_hwirq(handler, claim))) { int err = generic_handle_domain_irq(handler->priv->irqdomain, hwirq); if (unlikely(err)) { @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, { .compatible = "thead,c900-plic", .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, + { .compatible = "ultrarisc,cp100-plic", + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, {} }; -- 2.51.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 11:15 ` [PATCH v2 3/3] irqchip/plic: add support for " Lucas Zampieri @ 2025-10-13 18:30 ` Conor Dooley 2025-10-14 9:14 ` Vivian Wang 2025-10-13 19:00 ` Samuel Holland 1 sibling, 1 reply; 14+ messages in thread From: Conor Dooley @ 2025-10-13 18:30 UTC (permalink / raw) To: Lucas Zampieri Cc: linux-kernel, Charles Mirabile, Thomas Gleixner, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng [-- Attachment #1: Type: text/plain, Size: 5729 bytes --] On Mon, Oct 13, 2025 at 12:15:38PM +0100, Lucas Zampieri wrote: > From: Charles Mirabile <cmirabil@redhat.com> > > Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to > work around a known hardware bug with IRQ claiming. > > When claiming an interrupt on the DP1000 PLIC all other interrupts must be > disabled before the claim register is accessed to prevent incorrect > handling of the interrupt. > > When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq > the enable state of all interrupts is saved and then all interrupts > except for the first pending one are disabled before reading the claim > register. The interrupts are then restored before further processing of > the claimed interrupt continues. > > The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all > SoCs using UR-CP100 cores, regardless of the specific SoC implementation. Why is that? I expect that you're doing that intentionally given the ultrarisc employee listed as a co-developer, but with only one SoC using this IP core it seems possible that this bug in the hardware could be fixed for other SoCs that are built using this IP core. Is there a plan to, for example, change the core version to UR-CP101 when the bug is fixed? Thanks, Conor. > This has no impact on other platforms. > > Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> > Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> > Signed-off-by: Charles Mirabile <cmirabil@redhat.com> > Signed-off-by: Lucas Zampieri <lzampier@redhat.com> > --- > drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- > 1 file changed, 82 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > index 9c4af7d58846..a7b51a925e96 100644 > --- a/drivers/irqchip/irq-sifive-plic.c > +++ b/drivers/irqchip/irq-sifive-plic.c > @@ -49,6 +49,8 @@ > #define CONTEXT_ENABLE_BASE 0x2000 > #define CONTEXT_ENABLE_SIZE 0x80 > > +#define PENDING_BASE 0x1000 > + > /* > * Each hart context has a set of control registers associated with it. Right > * now there's only two: a source priority threshold over which the hart will > @@ -63,6 +65,7 @@ > #define PLIC_ENABLE_THRESHOLD 0 > > #define PLIC_QUIRK_EDGE_INTERRUPT 0 > +#define PLIC_QUIRK_CLAIM_REGISTER 1 > > struct plic_priv { > struct fwnode_handle *fwnode; > @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { > .free = irq_domain_free_irqs_top, > }; > > +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], > + void __iomem *pending, > + void __iomem *enable) > +{ > + u32 pending_irqs = 0; > + int i, j; > + > + /* Look for first pending interrupt */ > + for (i = 0; i < nr_irq_groups; i++) { > + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); > + if (pending_irqs) > + break; > + } > + > + if (!pending_irqs) > + return false; > + > + /* Disable all interrupts but the first pending one */ > + for (j = 0; j < nr_irq_groups; j++) { > + u32 new_mask = 0; > + > + if (j == i) > + /* Extract mask with lowest set bit */ > + new_mask = (pending_irqs & -pending_irqs); > + > + writel(new_mask, enable + j * sizeof(u32)); > + } > + > + return true; > +} > + > +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, > + void __iomem *claim) > +{ > + void __iomem *enable = handler->enable_base; > + void __iomem *pending = handler->priv->regs + PENDING_BASE; > + int nr_irqs = handler->priv->nr_irqs; > + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); > + int i; > + u32 ie[32] = { 0 }; > + irq_hw_number_t hwirq = 0; > + > + raw_spin_lock(&handler->enable_lock); > + > + /* Save current interrupt enable state */ > + for (i = 0; i < nr_irq_groups; i++) > + ie[i] = readl(enable + i * sizeof(u32)); > + > + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) > + goto out; > + > + hwirq = readl(claim); > + > + /* Restore previous state */ > + for (i = 0; i < nr_irq_groups; i++) > + writel(ie[i], enable + i * sizeof(u32)); > +out: > + raw_spin_unlock(&handler->enable_lock); > + return hwirq; > +} > + > +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, > + void __iomem *claim) > +{ > + /* > + * Due to a hardware bug in the implementation of the claim register > + * in the UltraRISC DP1000 platform, other interrupts must be disabled > + * before reading the claim register and restored afterwards. > + */ > + > + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) > + return dp1000_get_hwirq(handler, claim); > + > + return readl(claim); > +} > + > /* > * Handling an interrupt is a two-step process: first you claim the interrupt > * by reading the claim register, then you complete the interrupt by writing > @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) > > chained_irq_enter(chip, desc); > > - while ((hwirq = readl(claim))) { > + while ((hwirq = plic_get_hwirq(handler, claim))) { > int err = generic_handle_domain_irq(handler->priv->irqdomain, > hwirq); > if (unlikely(err)) { > @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > { .compatible = "thead,c900-plic", > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > + { .compatible = "ultrarisc,cp100-plic", > + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, > {} > }; > > -- > 2.51.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 18:30 ` Conor Dooley @ 2025-10-14 9:14 ` Vivian Wang 2025-10-14 14:35 ` Lucas Zampieri 2025-10-14 17:47 ` Conor Dooley 0 siblings, 2 replies; 14+ messages in thread From: Vivian Wang @ 2025-10-14 9:14 UTC (permalink / raw) To: Conor Dooley, Lucas Zampieri Cc: linux-kernel, Charles Mirabile, Thomas Gleixner, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng Hi Conor, On 10/14/25 02:30, Conor Dooley wrote: > On Mon, Oct 13, 2025 at 12:15:38PM +0100, Lucas Zampieri wrote: >> From: Charles Mirabile <cmirabil@redhat.com> >> >> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to >> work around a known hardware bug with IRQ claiming. >> >> When claiming an interrupt on the DP1000 PLIC all other interrupts must be >> disabled before the claim register is accessed to prevent incorrect >> handling of the interrupt. >> >> When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq >> the enable state of all interrupts is saved and then all interrupts >> except for the first pending one are disabled before reading the claim >> register. The interrupts are then restored before further processing of >> the claimed interrupt continues. >> >> The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all >> SoCs using UR-CP100 cores, regardless of the specific SoC implementation. > Why is that? I expect that you're doing that intentionally given the > ultrarisc employee listed as a co-developer, but with only one SoC using > this IP core it seems possible that this bug in the hardware could be > fixed for other SoCs that are built using this IP core. > Is there a plan to, for example, change the core version to UR-CP101 > when the bug is fixed? I originally proposed to match on ultrarisc,cp100-plic under the assumption that it would be the case. Furthermore, it is my understanding that if the bug is fixed in, say, UR-DP1001, then the PLIC node can simply be compatible = "ultrarisc,dp1001-plic", "sifive,plic-1.0.0"; I meant my reply that I had assumed this bug was associated with the UR-CP100 core, but I should have stated so more clearly. Vivian "dramforever" Wang ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-14 9:14 ` Vivian Wang @ 2025-10-14 14:35 ` Lucas Zampieri 2025-10-14 17:47 ` Conor Dooley 1 sibling, 0 replies; 14+ messages in thread From: Lucas Zampieri @ 2025-10-14 14:35 UTC (permalink / raw) To: Vivian Wang Cc: Conor Dooley, linux-kernel, Charles Mirabile, Thomas Gleixner, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng Hi Conor and Vivian, On Tue, Oct 14, 2025 at 10:15 AM Vivian Wang <wangruikang@iscas.ac.cn> wrote: > > Hi Conor, > > On 10/14/25 02:30, Conor Dooley wrote: > > On Mon, Oct 13, 2025 at 12:15:38PM +0100, Lucas Zampieri wrote: > >> From: Charles Mirabile <cmirabil@redhat.com> > >> > >> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to > >> work around a known hardware bug with IRQ claiming. > >> > >> When claiming an interrupt on the DP1000 PLIC all other interrupts must be > >> disabled before the claim register is accessed to prevent incorrect > >> handling of the interrupt. > >> > >> When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq > >> the enable state of all interrupts is saved and then all interrupts > >> except for the first pending one are disabled before reading the claim > >> register. The interrupts are then restored before further processing of > >> the claimed interrupt continues. > >> > >> The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all > >> SoCs using UR-CP100 cores, regardless of the specific SoC implementation. > > Why is that? I expect that you're doing that intentionally given the > > ultrarisc employee listed as a co-developer, but with only one SoC using > > this IP core it seems possible that this bug in the hardware could be > > fixed for other SoCs that are built using this IP core. > > Is there a plan to, for example, change the core version to UR-CP101 > > when the bug is fixed? > > I originally proposed to match on ultrarisc,cp100-plic under the > assumption that it would be the case. > As far as I was able to verify with UltraRisc, this is a bug with the cp100 cores and not the DP-1000 SoC, what that means is that any other board using those cp100 cores should have the same bug. And I agree that the function naming in this patch makes it confusing and seem like this is an issue to the dp1000, I'll reword those in a v3. > Furthermore, it is my understanding that if the bug is fixed in, say, > UR-DP1001, then the PLIC node can simply be > > compatible = "ultrarisc,dp1001-plic", "sifive,plic-1.0.0"; > > I meant my reply that I had assumed this bug was associated with the > UR-CP100 core, but I should have stated so more clearly. > > Vivian "dramforever" Wang > Lucas Zampieri ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-14 9:14 ` Vivian Wang 2025-10-14 14:35 ` Lucas Zampieri @ 2025-10-14 17:47 ` Conor Dooley 1 sibling, 0 replies; 14+ messages in thread From: Conor Dooley @ 2025-10-14 17:47 UTC (permalink / raw) To: Vivian Wang Cc: Lucas Zampieri, linux-kernel, Charles Mirabile, Thomas Gleixner, Paul Walmsley, Samuel Holland, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng [-- Attachment #1: Type: text/plain, Size: 2020 bytes --] On Tue, Oct 14, 2025 at 05:14:17PM +0800, Vivian Wang wrote: > Hi Conor, > > On 10/14/25 02:30, Conor Dooley wrote: > > On Mon, Oct 13, 2025 at 12:15:38PM +0100, Lucas Zampieri wrote: > >> From: Charles Mirabile <cmirabil@redhat.com> > >> > >> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to > >> work around a known hardware bug with IRQ claiming. > >> > >> When claiming an interrupt on the DP1000 PLIC all other interrupts must be > >> disabled before the claim register is accessed to prevent incorrect > >> handling of the interrupt. > >> > >> When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq > >> the enable state of all interrupts is saved and then all interrupts > >> except for the first pending one are disabled before reading the claim > >> register. The interrupts are then restored before further processing of > >> the claimed interrupt continues. > >> > >> The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all > >> SoCs using UR-CP100 cores, regardless of the specific SoC implementation. > > Why is that? I expect that you're doing that intentionally given the > > ultrarisc employee listed as a co-developer, but with only one SoC using > > this IP core it seems possible that this bug in the hardware could be > > fixed for other SoCs that are built using this IP core. > > Is there a plan to, for example, change the core version to UR-CP101 > > when the bug is fixed? > > I originally proposed to match on ultrarisc,cp100-plic under the > assumption that it would be the case. > > Furthermore, it is my understanding that if the bug is fixed in, say, > UR-DP1001, then the PLIC node can simply be > > compatible = "ultrarisc,dp1001-plic", "sifive,plic-1.0.0"; > > I meant my reply that I had assumed this bug was associated with the > UR-CP100 core, but I should have stated so more clearly. Ah ye, very true, could be done that way if there's a changed version that's compliant. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 11:15 ` [PATCH v2 3/3] irqchip/plic: add support for " Lucas Zampieri 2025-10-13 18:30 ` Conor Dooley @ 2025-10-13 19:00 ` Samuel Holland 2025-10-13 21:03 ` Charles Mirabile 2025-10-13 21:24 ` Bo Gan 1 sibling, 2 replies; 14+ messages in thread From: Samuel Holland @ 2025-10-13 19:00 UTC (permalink / raw) To: Lucas Zampieri Cc: Charles Mirabile, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng, linux-kernel Hi Lucas, On 2025-10-13 6:15 AM, Lucas Zampieri wrote: > From: Charles Mirabile <cmirabil@redhat.com> > > Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to > work around a known hardware bug with IRQ claiming. > > When claiming an interrupt on the DP1000 PLIC all other interrupts must be > disabled before the claim register is accessed to prevent incorrect > handling of the interrupt. > > When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq > the enable state of all interrupts is saved and then all interrupts > except for the first pending one are disabled before reading the claim > register. The interrupts are then restored before further processing of > the claimed interrupt continues. Since the workaround requires scanning the pending bits for each interrupt anyway, it would be simpler and more efficient to ignore the claim register entirely. Call generic_handle_domain_irq() for each interrupt that is (enabled AND pending), then clear the pending bit. Then you would not need to save and restore the enable registers. > The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all > SoCs using UR-CP100 cores, regardless of the specific SoC implementation. > This has no impact on other platforms. > > Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> > Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> > Signed-off-by: Charles Mirabile <cmirabil@redhat.com> > Signed-off-by: Lucas Zampieri <lzampier@redhat.com> > --- > drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- > 1 file changed, 82 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > index 9c4af7d58846..a7b51a925e96 100644 > --- a/drivers/irqchip/irq-sifive-plic.c > +++ b/drivers/irqchip/irq-sifive-plic.c > @@ -49,6 +49,8 @@ > #define CONTEXT_ENABLE_BASE 0x2000 > #define CONTEXT_ENABLE_SIZE 0x80 > > +#define PENDING_BASE 0x1000 > + > /* > * Each hart context has a set of control registers associated with it. Right > * now there's only two: a source priority threshold over which the hart will > @@ -63,6 +65,7 @@ > #define PLIC_ENABLE_THRESHOLD 0 > > #define PLIC_QUIRK_EDGE_INTERRUPT 0 > +#define PLIC_QUIRK_CLAIM_REGISTER 1 > > struct plic_priv { > struct fwnode_handle *fwnode; > @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { > .free = irq_domain_free_irqs_top, > }; > > +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], > + void __iomem *pending, > + void __iomem *enable) > +{ > + u32 pending_irqs = 0; > + int i, j; > + > + /* Look for first pending interrupt */ > + for (i = 0; i < nr_irq_groups; i++) { > + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); > + if (pending_irqs) > + break; > + } > + > + if (!pending_irqs) > + return false; > + > + /* Disable all interrupts but the first pending one */ > + for (j = 0; j < nr_irq_groups; j++) { > + u32 new_mask = 0; > + > + if (j == i) > + /* Extract mask with lowest set bit */ > + new_mask = (pending_irqs & -pending_irqs); > + > + writel(new_mask, enable + j * sizeof(u32)); > + } > + > + return true; > +} > + > +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, > + void __iomem *claim) > +{ > + void __iomem *enable = handler->enable_base; > + void __iomem *pending = handler->priv->regs + PENDING_BASE; > + int nr_irqs = handler->priv->nr_irqs; > + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); > + int i; > + u32 ie[32] = { 0 }; > + irq_hw_number_t hwirq = 0; > + > + raw_spin_lock(&handler->enable_lock); > + > + /* Save current interrupt enable state */ > + for (i = 0; i < nr_irq_groups; i++) > + ie[i] = readl(enable + i * sizeof(u32)); > + > + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) > + goto out; > + > + hwirq = readl(claim); > + > + /* Restore previous state */ > + for (i = 0; i < nr_irq_groups; i++) > + writel(ie[i], enable + i * sizeof(u32)); > +out: > + raw_spin_unlock(&handler->enable_lock); > + return hwirq; > +} > + > +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, > + void __iomem *claim) > +{ > + /* > + * Due to a hardware bug in the implementation of the claim register > + * in the UltraRISC DP1000 platform, other interrupts must be disabled > + * before reading the claim register and restored afterwards. > + */ > + > + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) > + return dp1000_get_hwirq(handler, claim); > + > + return readl(claim); > +} > + > /* > * Handling an interrupt is a two-step process: first you claim the interrupt > * by reading the claim register, then you complete the interrupt by writing > @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) > > chained_irq_enter(chip, desc); > > - while ((hwirq = readl(claim))) { > + while ((hwirq = plic_get_hwirq(handler, claim))) { This is the hot path for interrupt handling. Instead of checking for the quirk on every interrupt, please create a new function that you conditionally pass to irq_set_chained_handler(), so the quirk check only happens once at boot. Regards, Samuel > int err = generic_handle_domain_irq(handler->priv->irqdomain, > hwirq); > if (unlikely(err)) { > @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > { .compatible = "thead,c900-plic", > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > + { .compatible = "ultrarisc,cp100-plic", > + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, > {} > }; > > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 19:00 ` Samuel Holland @ 2025-10-13 21:03 ` Charles Mirabile 2025-10-13 21:58 ` Samuel Holland 2025-10-13 21:24 ` Bo Gan 1 sibling, 1 reply; 14+ messages in thread From: Charles Mirabile @ 2025-10-13 21:03 UTC (permalink / raw) To: samuel.holland Cc: alex, aou, cmirabil, dramforever, linux-kernel, linux-riscv, lzampier, palmer, paul.walmsley, tglx, zhangxincheng Hi Samuel - On Mon, Oct 13, 2025 at 02:00:29PM -0500, Samuel Holland wrote: > Hi Lucas, > > On 2025-10-13 6:15 AM, Lucas Zampieri wrote: > > From: Charles Mirabile <cmirabil@redhat.com> > > > > Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to > > work around a known hardware bug with IRQ claiming. > > > > When claiming an interrupt on the DP1000 PLIC all other interrupts must be > > disabled before the claim register is accessed to prevent incorrect > > handling of the interrupt. > > > > When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq > > the enable state of all interrupts is saved and then all interrupts > > except for the first pending one are disabled before reading the claim > > register. The interrupts are then restored before further processing of > > the claimed interrupt continues. > > Since the workaround requires scanning the pending bits for each interrupt > anyway, it would be simpler and more efficient to ignore the claim register > entirely. Call generic_handle_domain_irq() for each interrupt that is (enabled > AND pending), then clear the pending bit. Then you would not need to save and > restore the enable registers. > > > The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all > > SoCs using UR-CP100 cores, regardless of the specific SoC implementation. > > This has no impact on other platforms. > > > > Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> > > Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> > > Signed-off-by: Charles Mirabile <cmirabil@redhat.com> > > Signed-off-by: Lucas Zampieri <lzampier@redhat.com> > > --- > > drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- > > 1 file changed, 82 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > > index 9c4af7d58846..a7b51a925e96 100644 > > --- a/drivers/irqchip/irq-sifive-plic.c > > +++ b/drivers/irqchip/irq-sifive-plic.c > > @@ -49,6 +49,8 @@ > > #define CONTEXT_ENABLE_BASE 0x2000 > > #define CONTEXT_ENABLE_SIZE 0x80 > > > > +#define PENDING_BASE 0x1000 > > + > > /* > > * Each hart context has a set of control registers associated with it. Right > > * now there's only two: a source priority threshold over which the hart will > > @@ -63,6 +65,7 @@ > > #define PLIC_ENABLE_THRESHOLD 0 > > > > #define PLIC_QUIRK_EDGE_INTERRUPT 0 > > +#define PLIC_QUIRK_CLAIM_REGISTER 1 > > > > struct plic_priv { > > struct fwnode_handle *fwnode; > > @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { > > .free = irq_domain_free_irqs_top, > > }; > > > > +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], > > + void __iomem *pending, > > + void __iomem *enable) > > +{ > > + u32 pending_irqs = 0; > > + int i, j; > > + > > + /* Look for first pending interrupt */ > > + for (i = 0; i < nr_irq_groups; i++) { > > + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); > > + if (pending_irqs) > > + break; > > + } > > + > > + if (!pending_irqs) > > + return false; > > + > > + /* Disable all interrupts but the first pending one */ > > + for (j = 0; j < nr_irq_groups; j++) { > > + u32 new_mask = 0; > > + > > + if (j == i) > > + /* Extract mask with lowest set bit */ > > + new_mask = (pending_irqs & -pending_irqs); > > + > > + writel(new_mask, enable + j * sizeof(u32)); > > + } > > + > > + return true; > > +} > > + > > +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, > > + void __iomem *claim) > > +{ > > + void __iomem *enable = handler->enable_base; > > + void __iomem *pending = handler->priv->regs + PENDING_BASE; > > + int nr_irqs = handler->priv->nr_irqs; > > + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); > > + int i; > > + u32 ie[32] = { 0 }; > > + irq_hw_number_t hwirq = 0; > > + > > + raw_spin_lock(&handler->enable_lock); > > + > > + /* Save current interrupt enable state */ > > + for (i = 0; i < nr_irq_groups; i++) > > + ie[i] = readl(enable + i * sizeof(u32)); > > + > > + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) > > + goto out; > > + > > + hwirq = readl(claim); > > + > > + /* Restore previous state */ > > + for (i = 0; i < nr_irq_groups; i++) > > + writel(ie[i], enable + i * sizeof(u32)); > > +out: > > + raw_spin_unlock(&handler->enable_lock); > > + return hwirq; > > +} > > + > > +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, > > + void __iomem *claim) > > +{ > > + /* > > + * Due to a hardware bug in the implementation of the claim register > > + * in the UltraRISC DP1000 platform, other interrupts must be disabled > > + * before reading the claim register and restored afterwards. > > + */ > > + > > + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) > > + return dp1000_get_hwirq(handler, claim); > > + > > + return readl(claim); > > +} > > + > > /* > > * Handling an interrupt is a two-step process: first you claim the interrupt > > * by reading the claim register, then you complete the interrupt by writing > > @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) > > > > chained_irq_enter(chip, desc); > > > > - while ((hwirq = readl(claim))) { > > + while ((hwirq = plic_get_hwirq(handler, claim))) { > > This is the hot path for interrupt handling. Instead of checking for the quirk > on every interrupt, please create a new function that you conditionally pass to > irq_set_chained_handler(), so the quirk check only happens once at boot. > > Regards, > Samuel > > > int err = generic_handle_domain_irq(handler->priv->irqdomain, > > hwirq); > > if (unlikely(err)) { > > @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { > > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > > { .compatible = "thead,c900-plic", > > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > > + { .compatible = "ultrarisc,cp100-plic", > > + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, > > {} > > }; > > > > -- > > 2.51.0 > > > Is something like this closer to what you had in mind? I tried it on the dp1000 and it doesn't work. Obviously it is concievable that I messed up the logic here, but it also might be the case that reading the claim register is integral to the proper functioning of the pending bits. I can confirm that a more minimal change that just moves the quirk check out of the hot path is fine. Would that be acceptable even if it is not the most efficient? (in essense take the hunk with new functions from the original patch but revert the change to `plic_handle_irq` and then add the hunk that changes probe from this proposed patch and then create the `plic_handle_irq_dp1000` function as a copy of `plic_handle_irq` where `dp1000_get_hwirq` is in the loop instead of `readl(claim)`). Best - Charlie --- diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 9c4af7d58846..fcf520ed33fd 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -49,6 +49,8 @@ #define CONTEXT_ENABLE_BASE 0x2000 #define CONTEXT_ENABLE_SIZE 0x80 +#define PENDING_BASE 0x1000 + /* * Each hart context has a set of control registers associated with it. Right * now there's only two: a source priority threshold over which the hart will @@ -63,6 +65,7 @@ #define PLIC_ENABLE_THRESHOLD 0 #define PLIC_QUIRK_EDGE_INTERRUPT 0 +#define PLIC_QUIRK_CLAIM_REGISTER 1 struct plic_priv { struct fwnode_handle *fwnode; @@ -367,6 +370,53 @@ static const struct irq_domain_ops plic_irqdomain_ops = { .free = irq_domain_free_irqs_top, }; +static int dp1000_find_pending_irq(struct plic_handler *handler, void __iomem *pending) +{ + void __iomem *enable = handler->enable_base; + int nr_irqs = handler->priv->nr_irqs; + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); + u32 pending_irqs = 0; + int i; + + raw_spin_lock(&handler->enable_lock); + for (i = 0; i < nr_irq_groups; i++) { + u32 enable_mask = readl(enable + i * sizeof(u32)); + u32 pending_mask = readl(pending + i * sizeof(u32)); + if ((pending_irqs = enable_mask & pending_mask)) + break; + } + raw_spin_unlock(&handler->enable_lock); + + if (!pending_irqs) + return 0; + + return 32 * i + __ffs(pending_irqs); +} + +static void plic_handle_irq_dp1000(struct irq_desc *desc) +{ + struct plic_handler *handler = this_cpu_ptr(&plic_handlers); + void __iomem *pending = handler->priv->regs + PENDING_BASE; + struct irq_chip *chip = irq_desc_get_chip(desc); + irq_hw_number_t hwirq; + + WARN_ON_ONCE(!handler->present); + + chained_irq_enter(chip, desc); + + while ((hwirq = dp1000_find_pending_irq(handler, pending))) { + int err = generic_handle_domain_irq(handler->priv->irqdomain, + hwirq); + __plic_toggle(pending, hwirq, 0); + if (unlikely(err)) { + pr_warn_ratelimited("%pfwP: can't find mapping for hwirq %lu\n", + handler->priv->fwnode, hwirq); + } + } + + chained_irq_exit(chip, desc); +} + /* * Handling an interrupt is a two-step process: first you claim the interrupt * by reading the claim register, then you complete the interrupt by writing @@ -432,6 +482,8 @@ static const struct of_device_id plic_match[] = { .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, { .compatible = "thead,c900-plic", .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, + { .compatible = "ultrarisc,dp1000-plic", + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, {} }; @@ -666,12 +718,16 @@ static int plic_probe(struct fwnode_handle *fwnode) } if (global_setup) { + void (*handler_fn)(struct irq_desc *) = plic_handle_irq; + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) + handler_fn = plic_handle_irq_dp1000; + /* Find parent domain and register chained handler */ domain = irq_find_matching_fwnode(riscv_get_intc_hwnode(), DOMAIN_BUS_ANY); if (domain) plic_parent_irq = irq_create_mapping(domain, RV_IRQ_EXT); if (plic_parent_irq) - irq_set_chained_handler(plic_parent_irq, plic_handle_irq); + irq_set_chained_handler(plic_parent_irq, handler_fn); cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING, "irqchip/sifive/plic:starting", -- 2.43.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 21:03 ` Charles Mirabile @ 2025-10-13 21:58 ` Samuel Holland 0 siblings, 0 replies; 14+ messages in thread From: Samuel Holland @ 2025-10-13 21:58 UTC (permalink / raw) To: Charles Mirabile Cc: alex, aou, dramforever, linux-kernel, linux-riscv, lzampier, palmer, paul.walmsley, tglx, zhangxincheng Hi Charles, On 2025-10-13 4:03 PM, Charles Mirabile wrote: > Hi Samuel - > > On Mon, Oct 13, 2025 at 02:00:29PM -0500, Samuel Holland wrote: >> Hi Lucas, >> >> On 2025-10-13 6:15 AM, Lucas Zampieri wrote: >>> From: Charles Mirabile <cmirabil@redhat.com> >>> >>> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to >>> work around a known hardware bug with IRQ claiming. >>> >>> When claiming an interrupt on the DP1000 PLIC all other interrupts must be >>> disabled before the claim register is accessed to prevent incorrect >>> handling of the interrupt. >>> >>> When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq >>> the enable state of all interrupts is saved and then all interrupts >>> except for the first pending one are disabled before reading the claim >>> register. The interrupts are then restored before further processing of >>> the claimed interrupt continues. >> >> Since the workaround requires scanning the pending bits for each interrupt >> anyway, it would be simpler and more efficient to ignore the claim register >> entirely. Call generic_handle_domain_irq() for each interrupt that is (enabled >> AND pending), then clear the pending bit. Then you would not need to save and >> restore the enable registers. >> >>> The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all >>> SoCs using UR-CP100 cores, regardless of the specific SoC implementation. >>> This has no impact on other platforms. >>> >>> Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> >>> Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> >>> Signed-off-by: Charles Mirabile <cmirabil@redhat.com> >>> Signed-off-by: Lucas Zampieri <lzampier@redhat.com> >>> --- >>> drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- >>> 1 file changed, 82 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c >>> index 9c4af7d58846..a7b51a925e96 100644 >>> --- a/drivers/irqchip/irq-sifive-plic.c >>> +++ b/drivers/irqchip/irq-sifive-plic.c >>> @@ -49,6 +49,8 @@ >>> #define CONTEXT_ENABLE_BASE 0x2000 >>> #define CONTEXT_ENABLE_SIZE 0x80 >>> >>> +#define PENDING_BASE 0x1000 >>> + >>> /* >>> * Each hart context has a set of control registers associated with it. Right >>> * now there's only two: a source priority threshold over which the hart will >>> @@ -63,6 +65,7 @@ >>> #define PLIC_ENABLE_THRESHOLD 0 >>> >>> #define PLIC_QUIRK_EDGE_INTERRUPT 0 >>> +#define PLIC_QUIRK_CLAIM_REGISTER 1 >>> >>> struct plic_priv { >>> struct fwnode_handle *fwnode; >>> @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { >>> .free = irq_domain_free_irqs_top, >>> }; >>> >>> +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], >>> + void __iomem *pending, >>> + void __iomem *enable) >>> +{ >>> + u32 pending_irqs = 0; >>> + int i, j; >>> + >>> + /* Look for first pending interrupt */ >>> + for (i = 0; i < nr_irq_groups; i++) { >>> + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); >>> + if (pending_irqs) >>> + break; >>> + } >>> + >>> + if (!pending_irqs) >>> + return false; >>> + >>> + /* Disable all interrupts but the first pending one */ >>> + for (j = 0; j < nr_irq_groups; j++) { >>> + u32 new_mask = 0; >>> + >>> + if (j == i) >>> + /* Extract mask with lowest set bit */ >>> + new_mask = (pending_irqs & -pending_irqs); >>> + >>> + writel(new_mask, enable + j * sizeof(u32)); >>> + } >>> + >>> + return true; >>> +} >>> + >>> +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, >>> + void __iomem *claim) >>> +{ >>> + void __iomem *enable = handler->enable_base; >>> + void __iomem *pending = handler->priv->regs + PENDING_BASE; >>> + int nr_irqs = handler->priv->nr_irqs; >>> + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); >>> + int i; >>> + u32 ie[32] = { 0 }; A couple of comments since we're keeping this algorithm: There's already an appropriately-sized handler->enable_save array that can be reused here. >>> + irq_hw_number_t hwirq = 0; >>> + >>> + raw_spin_lock(&handler->enable_lock); >>> + >>> + /* Save current interrupt enable state */ >>> + for (i = 0; i < nr_irq_groups; i++) >>> + ie[i] = readl(enable + i * sizeof(u32)); >>> + >>> + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) >>> + goto out; >>> + >>> + hwirq = readl(claim); >>> + >>> + /* Restore previous state */ >>> + for (i = 0; i < nr_irq_groups; i++) >>> + writel(ie[i], enable + i * sizeof(u32)); All of the I/O in these new functions, except the readl(claim), can use the {readl,writel}_relaxed I/O accessors. They don't have any ordering requirement with respect to main memory, just other I/O. >>> +out: >>> + raw_spin_unlock(&handler->enable_lock); >>> + return hwirq; >>> +} >>> + >>> +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, >>> + void __iomem *claim) >>> +{ >>> + /* >>> + * Due to a hardware bug in the implementation of the claim register >>> + * in the UltraRISC DP1000 platform, other interrupts must be disabled >>> + * before reading the claim register and restored afterwards. >>> + */ >>> + >>> + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) >>> + return dp1000_get_hwirq(handler, claim); >>> + >>> + return readl(claim); >>> +} >>> + >>> /* >>> * Handling an interrupt is a two-step process: first you claim the interrupt >>> * by reading the claim register, then you complete the interrupt by writing >>> @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) >>> >>> chained_irq_enter(chip, desc); >>> >>> - while ((hwirq = readl(claim))) { >>> + while ((hwirq = plic_get_hwirq(handler, claim))) { >> >> This is the hot path for interrupt handling. Instead of checking for the quirk >> on every interrupt, please create a new function that you conditionally pass to >> irq_set_chained_handler(), so the quirk check only happens once at boot. >> >> Regards, >> Samuel >> >>> int err = generic_handle_domain_irq(handler->priv->irqdomain, >>> hwirq); >>> if (unlikely(err)) { >>> @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { >>> .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, >>> { .compatible = "thead,c900-plic", >>> .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, >>> + { .compatible = "ultrarisc,cp100-plic", >>> + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, >>> {} >>> }; >>> >>> -- >>> 2.51.0 >>> >> > > Is something like this closer to what you had in mind? I tried it on the > dp1000 and it doesn't work. Obviously it is concievable that I messed up > the logic here, but it also might be the case that reading the claim > register is integral to the proper functioning of the pending bits. It's also possible that the pending bits are read only. There are existing implementations with both RO and RW pending bits. So the claim register might be the only way to clear the pending bits for edge-triggered interrupts. (For level interrupts, the pending bits should clear themselves, so it should be fine if the write is ignored.) I don't see anything wrong with the code below, but we're working with known-buggy hardware, so who knows. > I can confirm that a more minimal change that just moves the quirk check > out of the hot path is fine. Would that be acceptable even if it is not > the most efficient? (in essense take the hunk with new functions from > the original patch but revert the change to `plic_handle_irq` and then add > the hunk that changes probe from this proposed patch and then create > the `plic_handle_irq_dp1000` function as a copy of `plic_handle_irq` where > `dp1000_get_hwirq` is in the loop instead of `readl(claim)`). Yes, this is acceptable. Even if the workaround isn't the most efficient, it's at least isolated to the affected hardware. So we'll get the hardware working now, and the efficiency can always be revisited later. Regards, Samuel > Best - Charlie > > --- > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > index 9c4af7d58846..fcf520ed33fd 100644 > --- a/drivers/irqchip/irq-sifive-plic.c > +++ b/drivers/irqchip/irq-sifive-plic.c > @@ -49,6 +49,8 @@ > #define CONTEXT_ENABLE_BASE 0x2000 > #define CONTEXT_ENABLE_SIZE 0x80 > > +#define PENDING_BASE 0x1000 > + > /* > * Each hart context has a set of control registers associated with it. Right > * now there's only two: a source priority threshold over which the hart will > @@ -63,6 +65,7 @@ > #define PLIC_ENABLE_THRESHOLD 0 > > #define PLIC_QUIRK_EDGE_INTERRUPT 0 > +#define PLIC_QUIRK_CLAIM_REGISTER 1 > > struct plic_priv { > struct fwnode_handle *fwnode; > @@ -367,6 +370,53 @@ static const struct irq_domain_ops plic_irqdomain_ops = { > .free = irq_domain_free_irqs_top, > }; > > +static int dp1000_find_pending_irq(struct plic_handler *handler, void __iomem *pending) > +{ > + void __iomem *enable = handler->enable_base; > + int nr_irqs = handler->priv->nr_irqs; > + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); > + u32 pending_irqs = 0; > + int i; > + > + raw_spin_lock(&handler->enable_lock); > + for (i = 0; i < nr_irq_groups; i++) { > + u32 enable_mask = readl(enable + i * sizeof(u32)); > + u32 pending_mask = readl(pending + i * sizeof(u32)); > + if ((pending_irqs = enable_mask & pending_mask)) > + break; > + } > + raw_spin_unlock(&handler->enable_lock); > + > + if (!pending_irqs) > + return 0; > + > + return 32 * i + __ffs(pending_irqs); > +} > + > +static void plic_handle_irq_dp1000(struct irq_desc *desc) > +{ > + struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > + void __iomem *pending = handler->priv->regs + PENDING_BASE; > + struct irq_chip *chip = irq_desc_get_chip(desc); > + irq_hw_number_t hwirq; > + > + WARN_ON_ONCE(!handler->present); > + > + chained_irq_enter(chip, desc); > + > + while ((hwirq = dp1000_find_pending_irq(handler, pending))) { > + int err = generic_handle_domain_irq(handler->priv->irqdomain, > + hwirq); > + __plic_toggle(pending, hwirq, 0); > + if (unlikely(err)) { > + pr_warn_ratelimited("%pfwP: can't find mapping for hwirq %lu\n", > + handler->priv->fwnode, hwirq); > + } > + } > + > + chained_irq_exit(chip, desc); > +} > + > /* > * Handling an interrupt is a two-step process: first you claim the interrupt > * by reading the claim register, then you complete the interrupt by writing > @@ -432,6 +482,8 @@ static const struct of_device_id plic_match[] = { > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > { .compatible = "thead,c900-plic", > .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, > + { .compatible = "ultrarisc,dp1000-plic", > + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, > {} > }; > > @@ -666,12 +718,16 @@ static int plic_probe(struct fwnode_handle *fwnode) > } > > if (global_setup) { > + void (*handler_fn)(struct irq_desc *) = plic_handle_irq; > + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) > + handler_fn = plic_handle_irq_dp1000; > + > /* Find parent domain and register chained handler */ > domain = irq_find_matching_fwnode(riscv_get_intc_hwnode(), DOMAIN_BUS_ANY); > if (domain) > plic_parent_irq = irq_create_mapping(domain, RV_IRQ_EXT); > if (plic_parent_irq) > - irq_set_chained_handler(plic_parent_irq, plic_handle_irq); > + irq_set_chained_handler(plic_parent_irq, handler_fn); > > cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING, > "irqchip/sifive/plic:starting", ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 19:00 ` Samuel Holland 2025-10-13 21:03 ` Charles Mirabile @ 2025-10-13 21:24 ` Bo Gan 2025-10-13 22:04 ` Samuel Holland 1 sibling, 1 reply; 14+ messages in thread From: Bo Gan @ 2025-10-13 21:24 UTC (permalink / raw) To: Samuel Holland, Lucas Zampieri Cc: Charles Mirabile, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng, linux-kernel On 10/13/25 12:00, Samuel Holland wrote: > Hi Lucas, > > On 2025-10-13 6:15 AM, Lucas Zampieri wrote: >> From: Charles Mirabile <cmirabil@redhat.com> >> >> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to >> work around a known hardware bug with IRQ claiming. >> >> When claiming an interrupt on the DP1000 PLIC all other interrupts must be >> disabled before the claim register is accessed to prevent incorrect >> handling of the interrupt. >> >> When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq >> the enable state of all interrupts is saved and then all interrupts >> except for the first pending one are disabled before reading the claim >> register. The interrupts are then restored before further processing of >> the claimed interrupt continues. > > Since the workaround requires scanning the pending bits for each interrupt > anyway, it would be simpler and more efficient to ignore the claim register > entirely. Call generic_handle_domain_irq() for each interrupt that is (enabled > AND pending), then clear the pending bit. Then you would not need to save and > restore the enable registers. > Is that safe and race-free? Can we guarantee that the enable bits for different contexts (harts) are disjoint at any given time? I'm a little bit worried about the scenario where 2+ harts having the same irq enabled and competing for the same irq claim. Without using the HW claim register, we may get spurious interrupt, and then wrongly claimed the spurious interrupt causing the next real one to be delayed indefinitely. >> The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all >> SoCs using UR-CP100 cores, regardless of the specific SoC implementation. >> This has no impact on other platforms. >> >> Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> >> Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> >> Signed-off-by: Charles Mirabile <cmirabil@redhat.com> >> Signed-off-by: Lucas Zampieri <lzampier@redhat.com> >> --- >> drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- >> 1 file changed, 82 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c >> index 9c4af7d58846..a7b51a925e96 100644 >> --- a/drivers/irqchip/irq-sifive-plic.c >> +++ b/drivers/irqchip/irq-sifive-plic.c >> @@ -49,6 +49,8 @@ >> #define CONTEXT_ENABLE_BASE 0x2000 >> #define CONTEXT_ENABLE_SIZE 0x80 >> >> +#define PENDING_BASE 0x1000 >> + >> /* >> * Each hart context has a set of control registers associated with it. Right >> * now there's only two: a source priority threshold over which the hart will >> @@ -63,6 +65,7 @@ >> #define PLIC_ENABLE_THRESHOLD 0 >> >> #define PLIC_QUIRK_EDGE_INTERRUPT 0 >> +#define PLIC_QUIRK_CLAIM_REGISTER 1 >> >> struct plic_priv { >> struct fwnode_handle *fwnode; >> @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { >> .free = irq_domain_free_irqs_top, >> }; >> >> +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], >> + void __iomem *pending, >> + void __iomem *enable) >> +{ >> + u32 pending_irqs = 0; >> + int i, j; >> + >> + /* Look for first pending interrupt */ >> + for (i = 0; i < nr_irq_groups; i++) { >> + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); >> + if (pending_irqs) >> + break; >> + } >> + >> + if (!pending_irqs) >> + return false; >> + >> + /* Disable all interrupts but the first pending one */ >> + for (j = 0; j < nr_irq_groups; j++) { >> + u32 new_mask = 0; >> + >> + if (j == i) >> + /* Extract mask with lowest set bit */ >> + new_mask = (pending_irqs & -pending_irqs); >> + >> + writel(new_mask, enable + j * sizeof(u32)); >> + } >> + >> + return true; >> +} >> + >> +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, >> + void __iomem *claim) >> +{ >> + void __iomem *enable = handler->enable_base; >> + void __iomem *pending = handler->priv->regs + PENDING_BASE; >> + int nr_irqs = handler->priv->nr_irqs; >> + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); >> + int i; >> + u32 ie[32] = { 0 }; >> + irq_hw_number_t hwirq = 0; >> + >> + raw_spin_lock(&handler->enable_lock); >> + >> + /* Save current interrupt enable state */ >> + for (i = 0; i < nr_irq_groups; i++) >> + ie[i] = readl(enable + i * sizeof(u32)); >> + >> + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) >> + goto out; >> + >> + hwirq = readl(claim); >> + >> + /* Restore previous state */ >> + for (i = 0; i < nr_irq_groups; i++) >> + writel(ie[i], enable + i * sizeof(u32)); >> +out: >> + raw_spin_unlock(&handler->enable_lock); >> + return hwirq; >> +} >> + >> +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, >> + void __iomem *claim) >> +{ >> + /* >> + * Due to a hardware bug in the implementation of the claim register >> + * in the UltraRISC DP1000 platform, other interrupts must be disabled >> + * before reading the claim register and restored afterwards. >> + */ >> + >> + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) >> + return dp1000_get_hwirq(handler, claim); >> + >> + return readl(claim); >> +} >> + >> /* >> * Handling an interrupt is a two-step process: first you claim the interrupt >> * by reading the claim register, then you complete the interrupt by writing >> @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) >> >> chained_irq_enter(chip, desc); >> >> - while ((hwirq = readl(claim))) { >> + while ((hwirq = plic_get_hwirq(handler, claim))) { > > This is the hot path for interrupt handling. Instead of checking for the quirk > on every interrupt, please create a new function that you conditionally pass to > irq_set_chained_handler(), so the quirk check only happens once at boot. > > Regards, > Samuel > >> int err = generic_handle_domain_irq(handler->priv->irqdomain, >> hwirq); >> if (unlikely(err)) { >> @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { >> .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, >> { .compatible = "thead,c900-plic", >> .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, >> + { .compatible = "ultrarisc,cp100-plic", >> + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, >> {} >> }; >> >> -- >> 2.51.0 >> > Bo ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC 2025-10-13 21:24 ` Bo Gan @ 2025-10-13 22:04 ` Samuel Holland 0 siblings, 0 replies; 14+ messages in thread From: Samuel Holland @ 2025-10-13 22:04 UTC (permalink / raw) To: Bo Gan Cc: Charles Mirabile, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Vivian Wang, linux-riscv, Zhang Xincheng, linux-kernel, Lucas Zampieri Hi Bo, On 2025-10-13 4:24 PM, Bo Gan wrote: > On 10/13/25 12:00, Samuel Holland wrote: >> Hi Lucas, >> >> On 2025-10-13 6:15 AM, Lucas Zampieri wrote: >>> From: Charles Mirabile <cmirabil@redhat.com> >>> >>> Add a new compatible for the plic found in UltraRISC DP1000 with a quirk to >>> work around a known hardware bug with IRQ claiming. >>> >>> When claiming an interrupt on the DP1000 PLIC all other interrupts must be >>> disabled before the claim register is accessed to prevent incorrect >>> handling of the interrupt. >>> >>> When the PLIC_QUIRK_CLAIM_REGISTER is present, during plic_handle_irq >>> the enable state of all interrupts is saved and then all interrupts >>> except for the first pending one are disabled before reading the claim >>> register. The interrupts are then restored before further processing of >>> the claimed interrupt continues. >> >> Since the workaround requires scanning the pending bits for each interrupt >> anyway, it would be simpler and more efficient to ignore the claim register >> entirely. Call generic_handle_domain_irq() for each interrupt that is (enabled >> AND pending), then clear the pending bit. Then you would not need to save and >> restore the enable registers. >> > > Is that safe and race-free? Can we guarantee that the enable bits for > different contexts (harts) are disjoint at any given time? I'm a little > bit worried about the scenario where 2+ harts having the same irq enabled > and competing for the same irq claim. Without using the HW claim register, > we may get spurious interrupt, and then wrongly claimed the spurious > interrupt causing the next real one to be delayed indefinitely. Yes, we can guarantee each interrupt is enabled on only one hart at a time. plic_set_affinity() always chooses a single CPU and gets called from irq_startup() before the first time the interrupt is enabled. There are other races to consider (e.g. clearing one pending bit while the hardware sets an adjacent one), but it looks like this strategy may not work on the hardware anyway. Regards, Samuel >>> The driver matches on "ultrarisc,cp100-plic" to apply the quirk to all >>> SoCs using UR-CP100 cores, regardless of the specific SoC implementation. >>> This has no impact on other platforms. >>> >>> Co-developed-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> >>> Signed-off-by: Zhang Xincheng <zhangxincheng@ultrarisc.com> >>> Signed-off-by: Charles Mirabile <cmirabil@redhat.com> >>> Signed-off-by: Lucas Zampieri <lzampier@redhat.com> >>> --- >>> drivers/irqchip/irq-sifive-plic.c | 83 ++++++++++++++++++++++++++++++- >>> 1 file changed, 82 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive- >>> plic.c >>> index 9c4af7d58846..a7b51a925e96 100644 >>> --- a/drivers/irqchip/irq-sifive-plic.c >>> +++ b/drivers/irqchip/irq-sifive-plic.c >>> @@ -49,6 +49,8 @@ >>> #define CONTEXT_ENABLE_BASE 0x2000 >>> #define CONTEXT_ENABLE_SIZE 0x80 >>> >>> +#define PENDING_BASE 0x1000 >>> + >>> /* >>> * Each hart context has a set of control registers associated with it. Right >>> * now there's only two: a source priority threshold over which the hart will >>> @@ -63,6 +65,7 @@ >>> #define PLIC_ENABLE_THRESHOLD 0 >>> >>> #define PLIC_QUIRK_EDGE_INTERRUPT 0 >>> +#define PLIC_QUIRK_CLAIM_REGISTER 1 >>> >>> struct plic_priv { >>> struct fwnode_handle *fwnode; >>> @@ -367,6 +370,82 @@ static const struct irq_domain_ops plic_irqdomain_ops = { >>> .free = irq_domain_free_irqs_top, >>> }; >>> >>> +static bool dp1000_isolate_pending_irq(int nr_irq_groups, u32 ie[], >>> + void __iomem *pending, >>> + void __iomem *enable) >>> +{ >>> + u32 pending_irqs = 0; >>> + int i, j; >>> + >>> + /* Look for first pending interrupt */ >>> + for (i = 0; i < nr_irq_groups; i++) { >>> + pending_irqs = ie[i] & readl(pending + i * sizeof(u32)); >>> + if (pending_irqs) >>> + break; >>> + } >>> + >>> + if (!pending_irqs) >>> + return false; >>> + >>> + /* Disable all interrupts but the first pending one */ >>> + for (j = 0; j < nr_irq_groups; j++) { >>> + u32 new_mask = 0; >>> + >>> + if (j == i) >>> + /* Extract mask with lowest set bit */ >>> + new_mask = (pending_irqs & -pending_irqs); >>> + >>> + writel(new_mask, enable + j * sizeof(u32)); >>> + } >>> + >>> + return true; >>> +} >>> + >>> +static irq_hw_number_t dp1000_get_hwirq(struct plic_handler *handler, >>> + void __iomem *claim) >>> +{ >>> + void __iomem *enable = handler->enable_base; >>> + void __iomem *pending = handler->priv->regs + PENDING_BASE; >>> + int nr_irqs = handler->priv->nr_irqs; >>> + int nr_irq_groups = DIV_ROUND_UP(nr_irqs, 32); >>> + int i; >>> + u32 ie[32] = { 0 }; >>> + irq_hw_number_t hwirq = 0; >>> + >>> + raw_spin_lock(&handler->enable_lock); >>> + >>> + /* Save current interrupt enable state */ >>> + for (i = 0; i < nr_irq_groups; i++) >>> + ie[i] = readl(enable + i * sizeof(u32)); >>> + >>> + if (!dp1000_isolate_pending_irq(nr_irq_groups, ie, pending, enable)) >>> + goto out; >>> + >>> + hwirq = readl(claim); >>> + >>> + /* Restore previous state */ >>> + for (i = 0; i < nr_irq_groups; i++) >>> + writel(ie[i], enable + i * sizeof(u32)); >>> +out: >>> + raw_spin_unlock(&handler->enable_lock); >>> + return hwirq; >>> +} >>> + >>> +static irq_hw_number_t plic_get_hwirq(struct plic_handler *handler, >>> + void __iomem *claim) >>> +{ >>> + /* >>> + * Due to a hardware bug in the implementation of the claim register >>> + * in the UltraRISC DP1000 platform, other interrupts must be disabled >>> + * before reading the claim register and restored afterwards. >>> + */ >>> + >>> + if (test_bit(PLIC_QUIRK_CLAIM_REGISTER, &handler->priv->plic_quirks)) >>> + return dp1000_get_hwirq(handler, claim); >>> + >>> + return readl(claim); >>> +} >>> + >>> /* >>> * Handling an interrupt is a two-step process: first you claim the interrupt >>> * by reading the claim register, then you complete the interrupt by writing >>> @@ -384,7 +463,7 @@ static void plic_handle_irq(struct irq_desc *desc) >>> >>> chained_irq_enter(chip, desc); >>> >>> - while ((hwirq = readl(claim))) { >>> + while ((hwirq = plic_get_hwirq(handler, claim))) { >> >> This is the hot path for interrupt handling. Instead of checking for the quirk >> on every interrupt, please create a new function that you conditionally pass to >> irq_set_chained_handler(), so the quirk check only happens once at boot. >> >> Regards, >> Samuel >> >>> int err = generic_handle_domain_irq(handler->priv->irqdomain, >>> hwirq); >>> if (unlikely(err)) { >>> @@ -432,6 +511,8 @@ static const struct of_device_id plic_match[] = { >>> .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, >>> { .compatible = "thead,c900-plic", >>> .data = (const void *)BIT(PLIC_QUIRK_EDGE_INTERRUPT) }, >>> + { .compatible = "ultrarisc,cp100-plic", >>> + .data = (const void *)BIT(PLIC_QUIRK_CLAIM_REGISTER) }, >>> {} >>> }; >>> >>> -- >>> 2.51.0 >>> >> > > Bo ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2025-10-14 17:47 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-13 11:15 [PATCH v2 0/3] Add UltraRISC DP1000 PLIC support Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: add UltraRISC Lucas Zampieri 2025-10-13 11:15 ` [PATCH v2 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC Lucas Zampieri 2025-10-13 18:25 ` Conor Dooley 2025-10-13 11:15 ` [PATCH v2 3/3] irqchip/plic: add support for " Lucas Zampieri 2025-10-13 18:30 ` Conor Dooley 2025-10-14 9:14 ` Vivian Wang 2025-10-14 14:35 ` Lucas Zampieri 2025-10-14 17:47 ` Conor Dooley 2025-10-13 19:00 ` Samuel Holland 2025-10-13 21:03 ` Charles Mirabile 2025-10-13 21:58 ` Samuel Holland 2025-10-13 21:24 ` Bo Gan 2025-10-13 22:04 ` Samuel Holland
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox