forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/irqchip/irq-mips-gic.c
....@@ -46,17 +46,19 @@
4646
4747 void __iomem *mips_gic_base;
4848
49
-DEFINE_PER_CPU_READ_MOSTLY(unsigned long[GIC_MAX_LONGS], pcpu_masks);
49
+static DEFINE_PER_CPU_READ_MOSTLY(unsigned long[GIC_MAX_LONGS], pcpu_masks);
5050
5151 static DEFINE_SPINLOCK(gic_lock);
5252 static struct irq_domain *gic_irq_domain;
53
-static struct irq_domain *gic_ipi_domain;
5453 static int gic_shared_intrs;
5554 static unsigned int gic_cpu_pin;
5655 static unsigned int timer_cpu_pin;
5756 static struct irq_chip gic_level_irq_controller, gic_edge_irq_controller;
57
+
58
+#ifdef CONFIG_GENERIC_IRQ_IPI
5859 static DECLARE_BITMAP(ipi_resrv, GIC_MAX_INTRS);
5960 static DECLARE_BITMAP(ipi_available, GIC_MAX_INTRS);
61
+#endif /* CONFIG_GENERIC_IRQ_IPI */
6062
6163 static struct gic_all_vpes_chip_data {
6264 u32 map;
....@@ -459,9 +461,11 @@
459461 u32 map;
460462
461463 if (hwirq >= GIC_SHARED_HWIRQ_BASE) {
464
+#ifdef CONFIG_GENERIC_IRQ_IPI
462465 /* verify that shared irqs don't conflict with an IPI irq */
463466 if (test_bit(GIC_HWIRQ_TO_SHARED(hwirq), ipi_resrv))
464467 return -EBUSY;
468
+#endif /* CONFIG_GENERIC_IRQ_IPI */
465469
466470 err = irq_domain_set_hwirq_and_chip(d, virq, hwirq,
467471 &gic_level_irq_controller,
....@@ -480,7 +484,7 @@
480484 case GIC_LOCAL_INT_TIMER:
481485 /* CONFIG_MIPS_CMP workaround (see __gic_init) */
482486 map = GIC_MAP_PIN_MAP_TO_PIN | timer_cpu_pin;
483
- /* fall-through */
487
+ fallthrough;
484488 case GIC_LOCAL_INT_PERFCTR:
485489 case GIC_LOCAL_INT_FDC:
486490 /*
....@@ -550,6 +554,8 @@
550554 .map = gic_irq_domain_map,
551555 };
552556
557
+#ifdef CONFIG_GENERIC_IRQ_IPI
558
+
553559 static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
554560 const u32 *intspec, unsigned int intsize,
555561 irq_hw_number_t *out_hwirq,
....@@ -617,8 +623,8 @@
617623 return ret;
618624 }
619625
620
-void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq,
621
- unsigned int nr_irqs)
626
+static void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq,
627
+ unsigned int nr_irqs)
622628 {
623629 irq_hw_number_t base_hwirq;
624630 struct irq_data *data;
....@@ -631,8 +637,8 @@
631637 bitmap_set(ipi_available, base_hwirq, nr_irqs);
632638 }
633639
634
-int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node,
635
- enum irq_domain_bus_token bus_token)
640
+static int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node,
641
+ enum irq_domain_bus_token bus_token)
636642 {
637643 bool is_ipi;
638644
....@@ -653,6 +659,48 @@
653659 .match = gic_ipi_domain_match,
654660 };
655661
662
+static int gic_register_ipi_domain(struct device_node *node)
663
+{
664
+ struct irq_domain *gic_ipi_domain;
665
+ unsigned int v[2], num_ipis;
666
+
667
+ gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain,
668
+ IRQ_DOMAIN_FLAG_IPI_PER_CPU,
669
+ GIC_NUM_LOCAL_INTRS + gic_shared_intrs,
670
+ node, &gic_ipi_domain_ops, NULL);
671
+ if (!gic_ipi_domain) {
672
+ pr_err("Failed to add IPI domain");
673
+ return -ENXIO;
674
+ }
675
+
676
+ irq_domain_update_bus_token(gic_ipi_domain, DOMAIN_BUS_IPI);
677
+
678
+ if (node &&
679
+ !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", v, 2)) {
680
+ bitmap_set(ipi_resrv, v[0], v[1]);
681
+ } else {
682
+ /*
683
+ * Reserve 2 interrupts per possible CPU/VP for use as IPIs,
684
+ * meeting the requirements of arch/mips SMP.
685
+ */
686
+ num_ipis = 2 * num_possible_cpus();
687
+ bitmap_set(ipi_resrv, gic_shared_intrs - num_ipis, num_ipis);
688
+ }
689
+
690
+ bitmap_copy(ipi_available, ipi_resrv, GIC_MAX_INTRS);
691
+
692
+ return 0;
693
+}
694
+
695
+#else /* !CONFIG_GENERIC_IRQ_IPI */
696
+
697
+static inline int gic_register_ipi_domain(struct device_node *node)
698
+{
699
+ return 0;
700
+}
701
+
702
+#endif /* !CONFIG_GENERIC_IRQ_IPI */
703
+
656704 static int gic_cpu_startup(unsigned int cpu)
657705 {
658706 /* Enable or disable EIC */
....@@ -671,11 +719,12 @@
671719 static int __init gic_of_init(struct device_node *node,
672720 struct device_node *parent)
673721 {
674
- unsigned int cpu_vec, i, gicconfig, v[2], num_ipis;
722
+ unsigned int cpu_vec, i, gicconfig;
675723 unsigned long reserved;
676724 phys_addr_t gic_base;
677725 struct resource res;
678726 size_t gic_len;
727
+ int ret;
679728
680729 /* Find the first available CPU vector. */
681730 i = 0;
....@@ -716,7 +765,11 @@
716765 __sync();
717766 }
718767
719
- mips_gic_base = ioremap_nocache(gic_base, gic_len);
768
+ mips_gic_base = ioremap(gic_base, gic_len);
769
+ if (!mips_gic_base) {
770
+ pr_err("Failed to ioremap gic_base\n");
771
+ return -ENOMEM;
772
+ }
720773
721774 gicconfig = read_gic_config();
722775 gic_shared_intrs = gicconfig & GIC_CONFIG_NUMINTERRUPTS;
....@@ -764,30 +817,9 @@
764817 return -ENXIO;
765818 }
766819
767
- gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain,
768
- IRQ_DOMAIN_FLAG_IPI_PER_CPU,
769
- GIC_NUM_LOCAL_INTRS + gic_shared_intrs,
770
- node, &gic_ipi_domain_ops, NULL);
771
- if (!gic_ipi_domain) {
772
- pr_err("Failed to add IPI domain");
773
- return -ENXIO;
774
- }
775
-
776
- irq_domain_update_bus_token(gic_ipi_domain, DOMAIN_BUS_IPI);
777
-
778
- if (node &&
779
- !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", v, 2)) {
780
- bitmap_set(ipi_resrv, v[0], v[1]);
781
- } else {
782
- /*
783
- * Reserve 2 interrupts per possible CPU/VP for use as IPIs,
784
- * meeting the requirements of arch/mips SMP.
785
- */
786
- num_ipis = 2 * num_possible_cpus();
787
- bitmap_set(ipi_resrv, gic_shared_intrs - num_ipis, num_ipis);
788
- }
789
-
790
- bitmap_copy(ipi_available, ipi_resrv, GIC_MAX_INTRS);
820
+ ret = gic_register_ipi_domain(node);
821
+ if (ret)
822
+ return ret;
791823
792824 board_bind_eic_interrupt = &gic_bind_eic_interrupt;
793825