Skip to content

Commit 9565210

Browse files
avpatelKAGA-KOKO
authored andcommitted
irqchip/sifive-plic: Parse number of interrupts and contexts early in plic_probe()
The SiFive PLIC driver needs to know the number of interrupts and contexts to complete initialization. Parse these details early in plic_probe() to avoid unnecessary memory allocations and register mappings if these details are not available. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240222094006.1030709-7-apatel@ventanamicro.com
1 parent a155872 commit 9565210

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

drivers/irqchip/irq-sifive-plic.c

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,34 @@ static const struct of_device_id plic_match[] = {
417417
{}
418418
};
419419

420+
static int plic_parse_nr_irqs_and_contexts(struct platform_device *pdev,
421+
u32 *nr_irqs, u32 *nr_contexts)
422+
{
423+
struct device *dev = &pdev->dev;
424+
int rc;
425+
426+
/*
427+
* Currently, only OF fwnode is supported so extend this
428+
* function for ACPI support.
429+
*/
430+
if (!is_of_node(dev->fwnode))
431+
return -EINVAL;
432+
433+
rc = of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", nr_irqs);
434+
if (rc) {
435+
dev_err(dev, "riscv,ndev property not available\n");
436+
return rc;
437+
}
438+
439+
*nr_contexts = of_irq_count(to_of_node(dev->fwnode));
440+
if (WARN_ON(!(*nr_contexts))) {
441+
dev_err(dev, "no PLIC context available\n");
442+
return -EINVAL;
443+
}
444+
445+
return 0;
446+
}
447+
420448
static int plic_parse_context_parent(struct platform_device *pdev, u32 context,
421449
u32 *parent_hwirq, int *parent_cpu)
422450
{
@@ -465,31 +493,26 @@ static int plic_probe(struct platform_device *pdev)
465493
plic_quirks = (unsigned long)id->data;
466494
}
467495

496+
error = plic_parse_nr_irqs_and_contexts(pdev, &nr_irqs, &nr_contexts);
497+
if (error)
498+
return error;
499+
468500
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
469501
if (!priv)
470502
return -ENOMEM;
471503

472504
priv->dev = dev;
473505
priv->plic_quirks = plic_quirks;
506+
priv->nr_irqs = nr_irqs;
474507

475508
priv->regs = devm_platform_ioremap_resource(pdev, 0);
476509
if (WARN_ON(!priv->regs))
477510
return -EIO;
478511

479-
of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", &nr_irqs);
480-
if (WARN_ON(!nr_irqs))
481-
return -EINVAL;
482-
483-
priv->nr_irqs = nr_irqs;
484-
485512
priv->prio_save = devm_bitmap_zalloc(dev, nr_irqs, GFP_KERNEL);
486513
if (!priv->prio_save)
487514
return -ENOMEM;
488515

489-
nr_contexts = of_irq_count(to_of_node(dev->fwnode));
490-
if (WARN_ON(!nr_contexts))
491-
return -EINVAL;
492-
493516
for (i = 0; i < nr_contexts; i++) {
494517
error = plic_parse_context_parent(pdev, i, &parent_hwirq, &cpu);
495518
if (error) {

0 commit comments

Comments
 (0)