ip27-irq.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. smp_call_function_interrupt();
  97. } else if (pend0 & (1UL << CPU_CALL_B_IRQ)) {
  98. LOCAL_HUB_CLR_INTR(CPU_CALL_B_IRQ);
  99. smp_call_function_interrupt();
  100. } else
  101. #endif
  102. {
  103. /* "map" swlevel to irq */
  104. struct slice_data *si = cpu_data[cpu].data;
  105. irq = si->level_to_irq[swlevel];
  106. do_IRQ(irq);
  107. }
  108. LOCAL_HUB_L(PI_INT_PEND0);
  109. }
  110. static void ip27_do_irq_mask1(void)
  111. {
  112. int irq, swlevel;
  113. hubreg_t pend1, mask1;
  114. cpuid_t cpu = smp_processor_id();
  115. int pi_int_mask1 = (cputoslice(cpu) == 0) ? PI_INT_MASK1_A : PI_INT_MASK1_B;
  116. struct slice_data *si = cpu_data[cpu].data;
  117. /* copied from Irix intpend0() */
  118. pend1 = LOCAL_HUB_L(PI_INT_PEND1);
  119. mask1 = LOCAL_HUB_L(pi_int_mask1);
  120. pend1 &= mask1; /* Pick intrs we should look at */
  121. if (!pend1)
  122. return;
  123. swlevel = ms1bit(pend1);
  124. /* "map" swlevel to irq */
  125. irq = si->level_to_irq[swlevel];
  126. LOCAL_HUB_CLR_INTR(swlevel);
  127. do_IRQ(irq);
  128. LOCAL_HUB_L(PI_INT_PEND1);
  129. }
  130. static void ip27_prof_timer(void)
  131. {
  132. panic("CPU %d got a profiling interrupt", smp_processor_id());
  133. }
  134. static void ip27_hub_error(void)
  135. {
  136. panic("CPU %d got a hub error interrupt", smp_processor_id());
  137. }
  138. asmlinkage void plat_irq_dispatch(void)
  139. {
  140. unsigned long pending = read_c0_cause() & read_c0_status();
  141. extern unsigned int rt_timer_irq;
  142. if (pending & CAUSEF_IP4)
  143. do_IRQ(rt_timer_irq);
  144. else if (pending & CAUSEF_IP2) /* PI_INT_PEND_0 or CC_PEND_{A|B} */
  145. ip27_do_irq_mask0();
  146. else if (pending & CAUSEF_IP3) /* PI_INT_PEND_1 */
  147. ip27_do_irq_mask1();
  148. else if (pending & CAUSEF_IP5)
  149. ip27_prof_timer();
  150. else if (pending & CAUSEF_IP6)
  151. ip27_hub_error();
  152. }
  153. void __init arch_init_irq(void)
  154. {
  155. }
  156. void install_ipi(void)
  157. {
  158. int slice = LOCAL_HUB_L(PI_CPU_NUM);
  159. int cpu = smp_processor_id();
  160. struct slice_data *si = cpu_data[cpu].data;
  161. struct hub_data *hub = hub_data(cpu_to_node(cpu));
  162. int resched, call;
  163. resched = CPU_RESCHED_A_IRQ + slice;
  164. __set_bit(resched, hub->irq_alloc_mask);
  165. __set_bit(resched, si->irq_enable_mask);
  166. LOCAL_HUB_CLR_INTR(resched);
  167. call = CPU_CALL_A_IRQ + slice;
  168. __set_bit(call, hub->irq_alloc_mask);
  169. __set_bit(call, si->irq_enable_mask);
  170. LOCAL_HUB_CLR_INTR(call);
  171. if (slice == 0) {
  172. LOCAL_HUB_S(PI_INT_MASK0_A, si->irq_enable_mask[0]);
  173. LOCAL_HUB_S(PI_INT_MASK1_A, si->irq_enable_mask[1]);
  174. } else {
  175. LOCAL_HUB_S(PI_INT_MASK0_B, si->irq_enable_mask[0]);
  176. LOCAL_HUB_S(PI_INT_MASK1_B, si->irq_enable_mask[1]);
  177. }
  178. }