irq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <loongson.h>
  3. #include <irq.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/init.h>
  6. #include <asm/irq_cpu.h>
  7. #include <asm/i8259.h>
  8. #include <asm/mipsregs.h>
  9. #include "smp.h"
  10. extern void loongson3_send_irq_by_ipi(int cpu, int irqs);
  11. unsigned int irq_cpu[16] = {[0 ... 15] = -1};
  12. unsigned int ht_irq[] = {0, 1, 3, 4, 5, 6, 7, 8, 12, 14, 15};
  13. unsigned int local_irq = 1<<0 | 1<<1 | 1<<2 | 1<<7 | 1<<8 | 1<<12;
  14. int plat_set_irq_affinity(struct irq_data *d, const struct cpumask *affinity,
  15. bool force)
  16. {
  17. unsigned int cpu;
  18. struct cpumask new_affinity;
  19. /* I/O devices are connected on package-0 */
  20. cpumask_copy(&new_affinity, affinity);
  21. for_each_cpu(cpu, affinity)
  22. if (cpu_data[cpu].package > 0)
  23. cpumask_clear_cpu(cpu, &new_affinity);
  24. if (cpumask_empty(&new_affinity))
  25. return -EINVAL;
  26. cpumask_copy(d->common->affinity, &new_affinity);
  27. return IRQ_SET_MASK_OK_NOCOPY;
  28. }
  29. static void ht_irqdispatch(void)
  30. {
  31. unsigned int i, irq;
  32. struct irq_data *irqd;
  33. struct cpumask affinity;
  34. irq = LOONGSON_HT1_INT_VECTOR(0);
  35. LOONGSON_HT1_INT_VECTOR(0) = irq; /* Acknowledge the IRQs */
  36. for (i = 0; i < ARRAY_SIZE(ht_irq); i++) {
  37. if (!(irq & (0x1 << ht_irq[i])))
  38. continue;
  39. /* handled by local core */
  40. if (local_irq & (0x1 << ht_irq[i])) {
  41. do_IRQ(ht_irq[i]);
  42. continue;
  43. }
  44. irqd = irq_get_irq_data(ht_irq[i]);
  45. cpumask_and(&affinity, irqd->common->affinity, cpu_active_mask);
  46. if (cpumask_empty(&affinity)) {
  47. do_IRQ(ht_irq[i]);
  48. continue;
  49. }
  50. irq_cpu[ht_irq[i]] = cpumask_next(irq_cpu[ht_irq[i]], &affinity);
  51. if (irq_cpu[ht_irq[i]] >= nr_cpu_ids)
  52. irq_cpu[ht_irq[i]] = cpumask_first(&affinity);
  53. if (irq_cpu[ht_irq[i]] == 0) {
  54. do_IRQ(ht_irq[i]);
  55. continue;
  56. }
  57. /* balanced by other cores */
  58. loongson3_send_irq_by_ipi(irq_cpu[ht_irq[i]], (0x1 << ht_irq[i]));
  59. }
  60. }
  61. #define UNUSED_IPS (CAUSEF_IP5 | CAUSEF_IP4 | CAUSEF_IP1 | CAUSEF_IP0)
  62. void mach_irq_dispatch(unsigned int pending)
  63. {
  64. if (pending & CAUSEF_IP7)
  65. do_IRQ(LOONGSON_TIMER_IRQ);
  66. #if defined(CONFIG_SMP)
  67. if (pending & CAUSEF_IP6)
  68. loongson3_ipi_interrupt(NULL);
  69. #endif
  70. if (pending & CAUSEF_IP3)
  71. ht_irqdispatch();
  72. if (pending & CAUSEF_IP2)
  73. do_IRQ(LOONGSON_UART_IRQ);
  74. if (pending & UNUSED_IPS) {
  75. pr_err("%s : spurious interrupt\n", __func__);
  76. spurious_interrupt();
  77. }
  78. }
  79. static inline void mask_loongson_irq(struct irq_data *d) { }
  80. static inline void unmask_loongson_irq(struct irq_data *d) { }
  81. /* For MIPS IRQs which shared by all cores */
  82. static struct irq_chip loongson_irq_chip = {
  83. .name = "Loongson",
  84. .irq_ack = mask_loongson_irq,
  85. .irq_mask = mask_loongson_irq,
  86. .irq_mask_ack = mask_loongson_irq,
  87. .irq_unmask = unmask_loongson_irq,
  88. .irq_eoi = unmask_loongson_irq,
  89. };
  90. void irq_router_init(void)
  91. {
  92. int i;
  93. /* route LPC int to cpu core0 int 0 */
  94. LOONGSON_INT_ROUTER_LPC =
  95. LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 0);
  96. /* route HT1 int0 ~ int7 to cpu core0 INT1*/
  97. for (i = 0; i < 8; i++)
  98. LOONGSON_INT_ROUTER_HT1(i) =
  99. LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 1);
  100. /* enable HT1 interrupt */
  101. LOONGSON_HT1_INTN_EN(0) = 0xffffffff;
  102. /* enable router interrupt intenset */
  103. LOONGSON_INT_ROUTER_INTENSET =
  104. LOONGSON_INT_ROUTER_INTEN | (0xffff << 16) | 0x1 << 10;
  105. }
  106. void __init mach_init_irq(void)
  107. {
  108. struct irq_chip *chip;
  109. clear_c0_status(ST0_IM | ST0_BEV);
  110. irq_router_init();
  111. mips_cpu_irq_init();
  112. init_i8259_irqs();
  113. chip = irq_get_chip(I8259A_IRQ_BASE);
  114. chip->irq_set_affinity = plat_set_irq_affinity;
  115. irq_set_chip_and_handler(LOONGSON_UART_IRQ,
  116. &loongson_irq_chip, handle_percpu_irq);
  117. irq_set_chip_and_handler(LOONGSON_BRIDGE_IRQ,
  118. &loongson_irq_chip, handle_percpu_irq);
  119. set_c0_status(STATUSF_IP2 | STATUSF_IP3 | STATUSF_IP6);
  120. }
  121. #ifdef CONFIG_HOTPLUG_CPU
  122. void fixup_irqs(void)
  123. {
  124. irq_cpu_offline();
  125. clear_c0_status(ST0_IM);
  126. }
  127. #endif