From: Thomas Gleixner <tglx@linutronix.de>
To: Lucas Zampieri <lzampier@redhat.com>, linux-kernel@vger.kernel.org
Cc: Charles Mirabile <cmirabil@redhat.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Samuel Holland <samuel.holland@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Vivian Wang <dramforever@live.com>,
devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
Zhang Xincheng <zhangxincheng@ultrarisc.com>,
Lucas Zampieri <lzampier@redhat.com>
Subject: Re: [PATCH v4 3/3] irqchip/plic: add support for UltraRISC DP1000 PLIC
Date: Wed, 15 Oct 2025 20:40:47 +0200 [thread overview]
Message-ID: <87y0pc100g.ffs@tglx> (raw)
In-Reply-To: <20251015143108.441291-4-lzampier@redhat.com>
On Wed, Oct 15 2025 at 15:31, Lucas Zampieri wrote:
> +static bool cp100_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_relaxed(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);
Please add brackets around the conditional as it's not a true single
line.
> +static irq_hw_number_t cp100_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;
> + irq_hw_number_t hwirq = 0;
Please use reverse fir tree ordering:
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#variable-declarations
> +
> + raw_spin_lock(&handler->enable_lock);
Please use
guard(raw_spinlock)(&handler->....);
which gets rid of the goto and you can just return instead.
> + /* Save current interrupt enable state */
> + for (i = 0; i < nr_irq_groups; i++)
> + handler->enable_save[i] = readl_relaxed(enable + i * sizeof(u32));
> +
> + if (!cp100_isolate_pending_irq(nr_irq_groups, handler->enable_save, pending, enable))
> + goto out;
> +
> + hwirq = readl(claim);
> +
> + /* Restore previous state */
> + for (i = 0; i < nr_irq_groups; i++)
> + writel_relaxed(handler->enable_save[i], enable + i * sizeof(u32));
> +out:
> + raw_spin_unlock(&handler->enable_lock);
> + return hwirq;
> +}
> +
> +static void plic_handle_irq_cp100(struct irq_desc *desc)
> +{
> + struct plic_handler *handler = this_cpu_ptr(&plic_handlers);
> + struct irq_chip *chip = irq_desc_get_chip(desc);
> + void __iomem *claim = handler->hart_base + CONTEXT_CLAIM;
> + irq_hw_number_t hwirq;
> +
> + WARN_ON_ONCE(!handler->present);
> +
> + chained_irq_enter(chip, desc);
> +
> + while ((hwirq = cp100_get_hwirq(handler, claim))) {
> + int err = generic_handle_domain_irq(handler->priv->irqdomain,
> + hwirq);
Let it stick out, you have 100 characters
> + if (unlikely(err)) {
> + pr_warn_ratelimited("%pfwP: can't find mapping for hwirq %lu\n",
> + handler->priv->fwnode, hwirq);
> + }
> + }
> +
> + chained_irq_exit(chip, desc);
> +}
> +
> static void plic_set_threshold(struct plic_handler *handler, u32 threshold)
> {
> /* priority must be > threshold to trigger an interrupt */
> @@ -430,6 +516,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_CP100_CLAIM_REGISTER_ERRATUM) },
> {}
> };
>
> @@ -664,12 +752,16 @@ static int plic_probe(struct fwnode_handle *fwnode)
> }
>
> if (global_setup) {
> + void (*handler_fn)(struct irq_desc *) = plic_handle_irq;
Lacks a newline between variable declaration and code.
> + if (test_bit(PLIC_QUIRK_CP100_CLAIM_REGISTER_ERRATUM, &handler->priv->plic_quirks))
> + handler_fn = plic_handle_irq_cp100;
> +
> /* 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",
Thanks,
tglx
prev parent reply other threads:[~2025-10-15 18:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 14:31 [PATCH v4 0/3] Add UltraRISC DP1000 PLIC support Lucas Zampieri
2025-10-15 14:31 ` [PATCH v4 1/3] dt-bindings: vendor-prefixes: add UltraRISC Lucas Zampieri
2025-10-15 14:31 ` [PATCH v4 2/3] dt-bindings: interrupt-controller: add UltraRISC DP1000 PLIC Lucas Zampieri
2025-10-15 14:31 ` [PATCH v4 3/3] irqchip/plic: add support for " Lucas Zampieri
2025-10-15 18:40 ` Thomas Gleixner [this message]
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=87y0pc100g.ffs@tglx \
--to=tglx@linutronix.de \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=cmirabil@redhat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dramforever@live.com \
--cc=krzk+dt@kernel.org \
--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=robh@kernel.org \
--cc=samuel.holland@sifive.com \
--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