@@ -510,6 +510,60 @@ static int __init imsic_matrix_init(void)
510
510
return 0 ;
511
511
}
512
512
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
+
513
567
static int __init imsic_get_parent_hartid (struct fwnode_handle * fwnode ,
514
568
u32 index , unsigned long * hartid )
515
569
{
@@ -578,50 +632,9 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
578
632
return - EINVAL ;
579
633
}
580
634
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 );
609
636
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 );
617
637
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 ;
625
638
626
639
/* Sanity check guest index bits */
627
640
i = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT ;
0 commit comments