From: Bo Gan <ganboing@gmail.com>
To: Samuel Holland <samuel.holland@sifive.com>,
Lucas Zampieri <lzampier@redhat.com>
Cc: Charles Mirabile <cmirabil@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Vivian Wang <dramforever@live.com>,
linux-riscv@lists.infradead.org,
Zhang Xincheng <zhangxincheng@ultrarisc.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC
Date: Mon, 13 Oct 2025 14:24:49 -0700 [thread overview]
Message-ID: <65122c79-7497-4b40-8112-a8ccaeeb16ab@gmail.com> (raw)
In-Reply-To: <1ecbd61e-6b3f-42e8-86cd-e1c589a45262@sifive.com>
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
next prev parent reply other threads:[~2025-10-13 21:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-10-13 22:04 ` Samuel Holland
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=65122c79-7497-4b40-8112-a8ccaeeb16ab@gmail.com \
--to=ganboing@gmail.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=cmirabil@redhat.com \
--cc=dramforever@live.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lzampier@redhat.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=samuel.holland@sifive.com \
--cc=tglx@linutronix.de \
--cc=zhangxincheng@ultrarisc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox