ip27-irq.c 5.5 KB

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