Skip to content

Commit aa143df

Browse files
vlsunilrafaeljw
authored andcommitted
irqchip/riscv-imsic-state: Create separate function for DT
While populating IMSIC global structure, many fields are initialized using DT properties. Make the code which uses DT properties as separate function so that it is easier to add ACPI support later. No functionality added/changed. Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Sunil V L <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Björn Töpel <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent f8619b6 commit aa143df

File tree

1 file changed

+55
-42
lines changed

1 file changed

+55
-42
lines changed

drivers/irqchip/irq-riscv-imsic-state.c

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,60 @@ static int __init imsic_matrix_init(void)
510510
return 0;
511511
}
512512

513+
static int __init imsic_populate_global_dt(struct fwnode_handle *fwnode,
514+
struct imsic_global_config *global,
515+
u32 *nr_parent_irqs)
516+
{
517+
int rc;
518+
519+
/* Find number of guest index bits in MSI address */
520+
rc = of_property_read_u32(to_of_node(fwnode), "riscv,guest-index-bits",
521+
&global->guest_index_bits);
522+
if (rc)
523+
global->guest_index_bits = 0;
524+
525+
/* Find number of HART index bits */
526+
rc = of_property_read_u32(to_of_node(fwnode), "riscv,hart-index-bits",
527+
&global->hart_index_bits);
528+
if (rc) {
529+
/* Assume default value */
530+
global->hart_index_bits = __fls(*nr_parent_irqs);
531+
if (BIT(global->hart_index_bits) < *nr_parent_irqs)
532+
global->hart_index_bits++;
533+
}
534+
535+
/* Find number of group index bits */
536+
rc = of_property_read_u32(to_of_node(fwnode), "riscv,group-index-bits",
537+
&global->group_index_bits);
538+
if (rc)
539+
global->group_index_bits = 0;
540+
541+
/*
542+
* Find first bit position of group index.
543+
* If not specified assumed the default APLIC-IMSIC configuration.
544+
*/
545+
rc = of_property_read_u32(to_of_node(fwnode), "riscv,group-index-shift",
546+
&global->group_index_shift);
547+
if (rc)
548+
global->group_index_shift = IMSIC_MMIO_PAGE_SHIFT * 2;
549+
550+
/* Find number of interrupt identities */
551+
rc = of_property_read_u32(to_of_node(fwnode), "riscv,num-ids",
552+
&global->nr_ids);
553+
if (rc) {
554+
pr_err("%pfwP: number of interrupt identities not found\n", fwnode);
555+
return rc;
556+
}
557+
558+
/* Find number of guest interrupt identities */
559+
rc = of_property_read_u32(to_of_node(fwnode), "riscv,num-guest-ids",
560+
&global->nr_guest_ids);
561+
if (rc)
562+
global->nr_guest_ids = global->nr_ids;
563+
564+
return 0;
565+
}
566+
513567
static int __init imsic_get_parent_hartid(struct fwnode_handle *fwnode,
514568
u32 index, unsigned long *hartid)
515569
{
@@ -578,50 +632,9 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
578632
return -EINVAL;
579633
}
580634

581-
/* Find number of guest index bits in MSI address */
582-
rc = of_property_read_u32(to_of_node(fwnode), "riscv,guest-index-bits",
583-
&global->guest_index_bits);
584-
if (rc)
585-
global->guest_index_bits = 0;
586-
587-
/* Find number of HART index bits */
588-
rc = of_property_read_u32(to_of_node(fwnode), "riscv,hart-index-bits",
589-
&global->hart_index_bits);
590-
if (rc) {
591-
/* Assume default value */
592-
global->hart_index_bits = __fls(*nr_parent_irqs);
593-
if (BIT(global->hart_index_bits) < *nr_parent_irqs)
594-
global->hart_index_bits++;
595-
}
596-
597-
/* Find number of group index bits */
598-
rc = of_property_read_u32(to_of_node(fwnode), "riscv,group-index-bits",
599-
&global->group_index_bits);
600-
if (rc)
601-
global->group_index_bits = 0;
602-
603-
/*
604-
* Find first bit position of group index.
605-
* If not specified assumed the default APLIC-IMSIC configuration.
606-
*/
607-
rc = of_property_read_u32(to_of_node(fwnode), "riscv,group-index-shift",
608-
&global->group_index_shift);
635+
rc = imsic_populate_global_dt(fwnode, global, nr_parent_irqs);
609636
if (rc)
610-
global->group_index_shift = IMSIC_MMIO_PAGE_SHIFT * 2;
611-
612-
/* Find number of interrupt identities */
613-
rc = of_property_read_u32(to_of_node(fwnode), "riscv,num-ids",
614-
&global->nr_ids);
615-
if (rc) {
616-
pr_err("%pfwP: number of interrupt identities not found\n", fwnode);
617637
return rc;
618-
}
619-
620-
/* Find number of guest interrupt identities */
621-
rc = of_property_read_u32(to_of_node(fwnode), "riscv,num-guest-ids",
622-
&global->nr_guest_ids);
623-
if (rc)
624-
global->nr_guest_ids = global->nr_ids;
625638

626639
/* Sanity check guest index bits */
627640
i = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT;

0 commit comments

Comments
 (0)