hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
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
51
-static DEFINE_SPINLOCK(gic_lock);
51
+static DEFINE_RAW_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;
....@@ -207,7 +209,7 @@
207209
208210 irq = GIC_HWIRQ_TO_SHARED(d->hwirq);
209211
210
- spin_lock_irqsave(&gic_lock, flags);
212
+ raw_spin_lock_irqsave(&gic_lock, flags);
211213 switch (type & IRQ_TYPE_SENSE_MASK) {
212214 case IRQ_TYPE_EDGE_FALLING:
213215 pol = GIC_POL_FALLING_EDGE;
....@@ -247,7 +249,7 @@
247249 else
248250 irq_set_chip_handler_name_locked(d, &gic_level_irq_controller,
249251 handle_level_irq, NULL);
250
- spin_unlock_irqrestore(&gic_lock, flags);
252
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
251253
252254 return 0;
253255 }
....@@ -265,7 +267,7 @@
265267 return -EINVAL;
266268
267269 /* Assumption : cpumask refers to a single CPU */
268
- spin_lock_irqsave(&gic_lock, flags);
270
+ raw_spin_lock_irqsave(&gic_lock, flags);
269271
270272 /* Re-route this IRQ */
271273 write_gic_map_vp(irq, BIT(mips_cm_vp_id(cpu)));
....@@ -276,7 +278,7 @@
276278 set_bit(irq, per_cpu_ptr(pcpu_masks, cpu));
277279
278280 irq_data_update_effective_affinity(d, cpumask_of(cpu));
279
- spin_unlock_irqrestore(&gic_lock, flags);
281
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
280282
281283 return IRQ_SET_MASK_OK;
282284 }
....@@ -354,12 +356,12 @@
354356 cd = irq_data_get_irq_chip_data(d);
355357 cd->mask = false;
356358
357
- spin_lock_irqsave(&gic_lock, flags);
359
+ raw_spin_lock_irqsave(&gic_lock, flags);
358360 for_each_online_cpu(cpu) {
359361 write_gic_vl_other(mips_cm_vp_id(cpu));
360362 write_gic_vo_rmask(BIT(intr));
361363 }
362
- spin_unlock_irqrestore(&gic_lock, flags);
364
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
363365 }
364366
365367 static void gic_unmask_local_irq_all_vpes(struct irq_data *d)
....@@ -372,32 +374,43 @@
372374 cd = irq_data_get_irq_chip_data(d);
373375 cd->mask = true;
374376
375
- spin_lock_irqsave(&gic_lock, flags);
377
+ raw_spin_lock_irqsave(&gic_lock, flags);
376378 for_each_online_cpu(cpu) {
377379 write_gic_vl_other(mips_cm_vp_id(cpu));
378380 write_gic_vo_smask(BIT(intr));
379381 }
380
- spin_unlock_irqrestore(&gic_lock, flags);
382
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
381383 }
382384
383
-static void gic_all_vpes_irq_cpu_online(struct irq_data *d)
385
+static void gic_all_vpes_irq_cpu_online(void)
384386 {
385
- struct gic_all_vpes_chip_data *cd;
386
- unsigned int intr;
387
+ static const unsigned int local_intrs[] = {
388
+ GIC_LOCAL_INT_TIMER,
389
+ GIC_LOCAL_INT_PERFCTR,
390
+ GIC_LOCAL_INT_FDC,
391
+ };
392
+ unsigned long flags;
393
+ int i;
387394
388
- intr = GIC_HWIRQ_TO_LOCAL(d->hwirq);
389
- cd = irq_data_get_irq_chip_data(d);
395
+ raw_spin_lock_irqsave(&gic_lock, flags);
390396
391
- write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
392
- if (cd->mask)
393
- write_gic_vl_smask(BIT(intr));
397
+ for (i = 0; i < ARRAY_SIZE(local_intrs); i++) {
398
+ unsigned int intr = local_intrs[i];
399
+ struct gic_all_vpes_chip_data *cd;
400
+
401
+ cd = &gic_all_vpes_chip_data[intr];
402
+ write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
403
+ if (cd->mask)
404
+ write_gic_vl_smask(BIT(intr));
405
+ }
406
+
407
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
394408 }
395409
396410 static struct irq_chip gic_all_vpes_local_irq_controller = {
397411 .name = "MIPS GIC Local",
398412 .irq_mask = gic_mask_local_irq_all_vpes,
399413 .irq_unmask = gic_unmask_local_irq_all_vpes,
400
- .irq_cpu_online = gic_all_vpes_irq_cpu_online,
401414 };
402415
403416 static void __gic_irq_dispatch(void)
....@@ -421,11 +434,11 @@
421434
422435 data = irq_get_irq_data(virq);
423436
424
- spin_lock_irqsave(&gic_lock, flags);
437
+ raw_spin_lock_irqsave(&gic_lock, flags);
425438 write_gic_map_pin(intr, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin);
426439 write_gic_map_vp(intr, BIT(mips_cm_vp_id(cpu)));
427440 irq_data_update_effective_affinity(data, cpumask_of(cpu));
428
- spin_unlock_irqrestore(&gic_lock, flags);
441
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
429442
430443 return 0;
431444 }
....@@ -459,9 +472,11 @@
459472 u32 map;
460473
461474 if (hwirq >= GIC_SHARED_HWIRQ_BASE) {
475
+#ifdef CONFIG_GENERIC_IRQ_IPI
462476 /* verify that shared irqs don't conflict with an IPI irq */
463477 if (test_bit(GIC_HWIRQ_TO_SHARED(hwirq), ipi_resrv))
464478 return -EBUSY;
479
+#endif /* CONFIG_GENERIC_IRQ_IPI */
465480
466481 err = irq_domain_set_hwirq_and_chip(d, virq, hwirq,
467482 &gic_level_irq_controller,
....@@ -476,11 +491,15 @@
476491 intr = GIC_HWIRQ_TO_LOCAL(hwirq);
477492 map = GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin;
478493
494
+ /*
495
+ * If adding support for more per-cpu interrupts, keep the the
496
+ * array in gic_all_vpes_irq_cpu_online() in sync.
497
+ */
479498 switch (intr) {
480499 case GIC_LOCAL_INT_TIMER:
481500 /* CONFIG_MIPS_CMP workaround (see __gic_init) */
482501 map = GIC_MAP_PIN_MAP_TO_PIN | timer_cpu_pin;
483
- /* fall-through */
502
+ fallthrough;
484503 case GIC_LOCAL_INT_PERFCTR:
485504 case GIC_LOCAL_INT_FDC:
486505 /*
....@@ -514,12 +533,12 @@
514533 if (!gic_local_irq_is_routable(intr))
515534 return -EPERM;
516535
517
- spin_lock_irqsave(&gic_lock, flags);
536
+ raw_spin_lock_irqsave(&gic_lock, flags);
518537 for_each_online_cpu(cpu) {
519538 write_gic_vl_other(mips_cm_vp_id(cpu));
520539 write_gic_vo_map(mips_gic_vx_map_reg(intr), map);
521540 }
522
- spin_unlock_irqrestore(&gic_lock, flags);
541
+ raw_spin_unlock_irqrestore(&gic_lock, flags);
523542
524543 return 0;
525544 }
....@@ -549,6 +568,8 @@
549568 .free = gic_irq_domain_free,
550569 .map = gic_irq_domain_map,
551570 };
571
+
572
+#ifdef CONFIG_GENERIC_IRQ_IPI
552573
553574 static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
554575 const u32 *intspec, unsigned int intsize,
....@@ -617,8 +638,8 @@
617638 return ret;
618639 }
619640
620
-void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq,
621
- unsigned int nr_irqs)
641
+static void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq,
642
+ unsigned int nr_irqs)
622643 {
623644 irq_hw_number_t base_hwirq;
624645 struct irq_data *data;
....@@ -631,8 +652,8 @@
631652 bitmap_set(ipi_available, base_hwirq, nr_irqs);
632653 }
633654
634
-int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node,
635
- enum irq_domain_bus_token bus_token)
655
+static int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node,
656
+ enum irq_domain_bus_token bus_token)
636657 {
637658 bool is_ipi;
638659
....@@ -653,6 +674,48 @@
653674 .match = gic_ipi_domain_match,
654675 };
655676
677
+static int gic_register_ipi_domain(struct device_node *node)
678
+{
679
+ struct irq_domain *gic_ipi_domain;
680
+ unsigned int v[2], num_ipis;
681
+
682
+ gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain,
683
+ IRQ_DOMAIN_FLAG_IPI_PER_CPU,
684
+ GIC_NUM_LOCAL_INTRS + gic_shared_intrs,
685
+ node, &gic_ipi_domain_ops, NULL);
686
+ if (!gic_ipi_domain) {
687
+ pr_err("Failed to add IPI domain");
688
+ return -ENXIO;
689
+ }
690
+
691
+ irq_domain_update_bus_token(gic_ipi_domain, DOMAIN_BUS_IPI);
692
+
693
+ if (node &&
694
+ !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", v, 2)) {
695
+ bitmap_set(ipi_resrv, v[0], v[1]);
696
+ } else {
697
+ /*
698
+ * Reserve 2 interrupts per possible CPU/VP for use as IPIs,
699
+ * meeting the requirements of arch/mips SMP.
700
+ */
701
+ num_ipis = 2 * num_possible_cpus();
702
+ bitmap_set(ipi_resrv, gic_shared_intrs - num_ipis, num_ipis);
703
+ }
704
+
705
+ bitmap_copy(ipi_available, ipi_resrv, GIC_MAX_INTRS);
706
+
707
+ return 0;
708
+}
709
+
710
+#else /* !CONFIG_GENERIC_IRQ_IPI */
711
+
712
+static inline int gic_register_ipi_domain(struct device_node *node)
713
+{
714
+ return 0;
715
+}
716
+
717
+#endif /* !CONFIG_GENERIC_IRQ_IPI */
718
+
656719 static int gic_cpu_startup(unsigned int cpu)
657720 {
658721 /* Enable or disable EIC */
....@@ -662,8 +725,8 @@
662725 /* Clear all local IRQ masks (ie. disable all local interrupts) */
663726 write_gic_vl_rmask(~0);
664727
665
- /* Invoke irq_cpu_online callbacks to enable desired interrupts */
666
- irq_cpu_online();
728
+ /* Enable desired interrupts */
729
+ gic_all_vpes_irq_cpu_online();
667730
668731 return 0;
669732 }
....@@ -671,11 +734,12 @@
671734 static int __init gic_of_init(struct device_node *node,
672735 struct device_node *parent)
673736 {
674
- unsigned int cpu_vec, i, gicconfig, v[2], num_ipis;
737
+ unsigned int cpu_vec, i, gicconfig;
675738 unsigned long reserved;
676739 phys_addr_t gic_base;
677740 struct resource res;
678741 size_t gic_len;
742
+ int ret;
679743
680744 /* Find the first available CPU vector. */
681745 i = 0;
....@@ -716,7 +780,11 @@
716780 __sync();
717781 }
718782
719
- mips_gic_base = ioremap_nocache(gic_base, gic_len);
783
+ mips_gic_base = ioremap(gic_base, gic_len);
784
+ if (!mips_gic_base) {
785
+ pr_err("Failed to ioremap gic_base\n");
786
+ return -ENOMEM;
787
+ }
720788
721789 gicconfig = read_gic_config();
722790 gic_shared_intrs = gicconfig & GIC_CONFIG_NUMINTERRUPTS;
....@@ -764,30 +832,9 @@
764832 return -ENXIO;
765833 }
766834
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);
835
+ ret = gic_register_ipi_domain(node);
836
+ if (ret)
837
+ return ret;
791838
792839 board_bind_eic_interrupt = &gic_bind_eic_interrupt;
793840