ip27-irq.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ip27-irq.c: Highlevel interrupt handling for IP27 architecture.
  4. *
  5. * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org)
  6. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  7. * Copyright (C) 1999 - 2001 Kanoj Sarcar
  8. */
  9. #undef DEBUG
  10. #include <linux/init.h>
  11. #include <linux/irq.h>
  12. #include <linux/errno.h>
  13. #include <linux/signal.h>
  14. #include <linux/sched.h>
  15. #include <linux/types.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/ioport.h>
  18. #include <linux/timex.h>
  19. #include <linux/smp.h>
  20. #include <linux/random.h>
  21. #include <linux/kernel.h>
  22. #include <linux/kernel_stat.h>
  23. #include <linux/delay.h>
  24. #include <linux/bitops.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/io.h>
  27. #include <asm/mipsregs.h>
  28. #include <asm/processor.h>
  29. #include <asm/sn/addrs.h>
  30. #include <asm/sn/agent.h>
  31. #include <asm/sn/arch.h>
  32. #include <asm/sn/hub.h>
  33. #include <asm/sn/intr.h>
  34. /*
  35. * Linux has a controller-independent x86 interrupt architecture.
  36. * every controller has a 'controller-template', that is used
  37. * by the main code to do the right thing. Each driver-visible
  38. * interrupt source is transparently wired to the appropriate
  39. * controller. Thus drivers need not be aware of the
  40. * interrupt-controller.
  41. *
  42. * Various interrupt controllers we handle: 8259 PIC, SMP IO-APIC,
  43. * PIIX4's internal 8259 PIC and SGI's Visual Workstation Cobalt (IO-)APIC.
  44. * (IO-APICs assumed to be messaging to Pentium local-APICs)
  45. *
  46. * the code is designed to be easily extended with new/different
  47. * interrupt controllers, without having to do assembly magic.
  48. */
  49. extern asmlinkage void ip27_irq(void);
  50. /*
  51. * Find first bit set
  52. */
  53. static int ms1bit(unsigned long x)
  54. {
  55. int b = 0, s;
  56. s = 16; if (x >> 16 == 0) s = 0; b += s; x >>= s;
  57. s = 8; if (x >> 8 == 0) s = 0; b += s; x >>= s;
  58. s = 4; if (x >> 4 == 0) s = 0; b += s; x >>= s;
  59. s = 2; if (x >> 2 == 0) s = 0; b += s; x >>= s;
  60. s = 1; if (x >> 1 == 0) s = 0; b += s;
  61. return b;
  62. }
  63. /*
  64. * This code is unnecessarily complex, because we do
  65. * intr enabling. Basically, once we grab the set of intrs we need
  66. * to service, we must mask _all_ these interrupts; firstly, to make
  67. * sure the same intr does not intr again, causing recursion that
  68. * can lead to stack overflow. Secondly, we can not just mask the
  69. * one intr we are do_IRQing, because the non-masked intrs in the
  70. * first set might intr again, causing multiple servicings of the
  71. * same intr. This effect is mostly seen for intercpu intrs.
  72. * Kanoj 05.13.00
  73. */
  74. static void ip27_do_irq_mask0(void)
  75. {
  76. int irq, swlevel;
  77. hubreg_t pend0, mask0;
  78. cpuid_t cpu = smp_processor_id();
  79. int pi_int_mask0 =
  80. (cputoslice(cpu) == 0) ? PI_INT_MASK0_A : PI_INT_MASK0_B;
  81. /* copied from Irix intpend0() */
  82. pend0 = LOCAL_HUB_L(PI_INT_PEND0);
  83. mask0 = LOCAL_HUB_L(pi_int_mask0);
  84. pend0 &= mask0; /* Pick intrs we should look at */
  85. if (!pend0)
  86. return;
  87. swlevel = ms1bit(pend0);
  88. #ifdef CONFIG_SMP
  89. if (pend0 & (1UL << CPU_RESCHED_A_IRQ)) {
  90. LOCAL_HUB_CLR_INTR(CPU_RESCHED_A_IRQ);
  91. scheduler_ipi();
  92. } else if (pend0 & (1UL << CPU_RESCHED_B_IRQ)) {
  93. LOCAL_HUB_CLR_INTR(CPU_RESCHED_B_IRQ);
  94. scheduler_ipi();
  95. } else if (pend0 & (1UL << CPU_CALL_A_IRQ)) {
  96. LOCAL_HUB_CLR_INTR(CPU_CALL_A_IRQ);
  97. irq_enter();
  98. generic_smp_call_function_interrupt();
  99. irq_exit();
  100. } else if (pend0 & (1UL << CPU_CALL_B_IRQ)) {
  101. LOCAL_HUB_CLR_INTR(CPU_CALL_B_IRQ);
  102. irq_enter();
  103. generic_smp_call_function_interrupt();
  104. irq_exit();
  105. } else
  106. #endif
  107. {
  108. /* "map" swlevel to irq */
  109. struct slice_data *si = cpu_data[cpu].data;
  110. irq = si->level_to_irq[swlevel];
  111. do_IRQ(irq);
  112. }
  113. LOCAL_HUB_L(PI_INT_PEND0);
  114. }
  115. static void ip27_do_irq_mask1(void)
  116. {
  117. int irq, swlevel;
  118. hubreg_t pend1, mask1;
  119. cpuid_t cpu = smp_processor_id();
  120. int pi_int_mask1 = (cputoslice(cpu) == 0) ? PI_INT_MASK1_A : PI_INT_MASK1_B;
  121. struct slice_data *si = cpu_data[cpu].data;
  122. /* copied from Irix intpend0() */
  123. pend1 = LOCAL_HUB_L(PI_INT_PEND1);
  124. mask1 = LOCAL_HUB_L(pi_int_mask1);
  125. pend1 &= mask1; /* Pick intrs we should look at */
  126. if (!pend1)
  127. return;
  128. swlevel = ms1bit(pend1);
  129. /* "map" swlevel to irq */
  130. irq = si->level_to_irq[swlevel];
  131. LOCAL_HUB_CLR_INTR(swlevel);
  132. do_IRQ(irq);
  133. LOCAL_HUB_L(PI_INT_PEND1);
  134. }
  135. static void ip27_prof_timer(void)
  136. {
  137. panic("CPU %d got a profiling interrupt", smp_processor_id());
  138. }
  139. static void ip27_hub_error(void)
  140. {
  141. panic("CPU %d got a hub error interrupt", smp_processor_id());
  142. }
  143. asmlinkage void plat_irq_dispatch(void)
  144. {
  145. unsigned long pending = read_c0_cause() & read_c0_status();
  146. extern unsigned int rt_timer_irq;
  147. if (pending & CAUSEF_IP4)
  148. do_IRQ(rt_timer_irq);
  149. else if (pending & CAUSEF_IP2) /* PI_INT_PEND_0 or CC_PEND_{A|B} */
  150. ip27_do_irq_mask0();
  151. else if (pending & CAUSEF_IP3) /* PI_INT_PEND_1 */
  152. ip27_do_irq_mask1();
  153. else if (pending & CAUSEF_IP5)
  154. ip27_prof_timer();
  155. else if (pending & CAUSEF_IP6)
  156. ip27_hub_error();
  157. }
  158. void __init arch_init_irq(void)
  159. {
  160. }
  161. void install_ipi(void)
  162. {
  163. int slice = LOCAL_HUB_L(PI_CPU_NUM);
  164. int cpu = smp_processor_id();
  165. struct slice_data *si = cpu_data[cpu].data;
  166. struct hub_data *hub = hub_data(cpu_to_node(cpu));
  167. int resched, call;
  168. resched = CPU_RESCHED_A_IRQ + slice;
  169. __set_bit(resched, hub->irq_alloc_mask);
  170. __set_bit(resched, si->irq_enable_mask);
  171. LOCAL_HUB_CLR_INTR(resched);
  172. call = CPU_CALL_A_IRQ + slice;
  173. __set_bit(call, hub->irq_alloc_mask);
  174. __set_bit(call, si->irq_enable_mask);
  175. LOCAL_HUB_CLR_INTR(call);
  176. if (slice == 0) {
  177. LOCAL_HUB_S(PI_INT_MASK0_A, si->irq_enable_mask[0]);
  178. LOCAL_HUB_S(PI_INT_MASK1_A, si->irq_enable_mask[1]);
  179. } else {
  180. LOCAL_HUB_S(PI_INT_MASK0_B, si->irq_enable_mask[0]);
  181. LOCAL_HUB_S(PI_INT_MASK1_B, si->irq_enable_mask[1]);
  182. }
  183. }