ip27-irq-pci.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/pci/bridge.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 struct bridge_controller *irq_to_bridge[];
  50. extern int irq_to_slot[];
  51. /*
  52. * use these macros to get the encoded nasid and widget id
  53. * from the irq value
  54. */
  55. #define IRQ_TO_BRIDGE(i) irq_to_bridge[(i)]
  56. #define SLOT_FROM_PCI_IRQ(i) irq_to_slot[i]
  57. static inline int alloc_level(int cpu, int irq)
  58. {
  59. struct hub_data *hub = hub_data(cpu_to_node(cpu));
  60. struct slice_data *si = cpu_data[cpu].data;
  61. int level;
  62. level = find_first_zero_bit(hub->irq_alloc_mask, LEVELS_PER_SLICE);
  63. if (level >= LEVELS_PER_SLICE)
  64. panic("Cpu %d flooded with devices", cpu);
  65. __set_bit(level, hub->irq_alloc_mask);
  66. si->level_to_irq[level] = irq;
  67. return level;
  68. }
  69. static inline int find_level(cpuid_t *cpunum, int irq)
  70. {
  71. int cpu, i;
  72. for_each_online_cpu(cpu) {
  73. struct slice_data *si = cpu_data[cpu].data;
  74. for (i = BASE_PCI_IRQ; i < LEVELS_PER_SLICE; i++)
  75. if (si->level_to_irq[i] == irq) {
  76. *cpunum = cpu;
  77. return i;
  78. }
  79. }
  80. panic("Could not identify cpu/level for irq %d", irq);
  81. }
  82. static int intr_connect_level(int cpu, int bit)
  83. {
  84. nasid_t nasid = COMPACT_TO_NASID_NODEID(cpu_to_node(cpu));
  85. struct slice_data *si = cpu_data[cpu].data;
  86. set_bit(bit, si->irq_enable_mask);
  87. if (!cputoslice(cpu)) {
  88. REMOTE_HUB_S(nasid, PI_INT_MASK0_A, si->irq_enable_mask[0]);
  89. REMOTE_HUB_S(nasid, PI_INT_MASK1_A, si->irq_enable_mask[1]);
  90. } else {
  91. REMOTE_HUB_S(nasid, PI_INT_MASK0_B, si->irq_enable_mask[0]);
  92. REMOTE_HUB_S(nasid, PI_INT_MASK1_B, si->irq_enable_mask[1]);
  93. }
  94. return 0;
  95. }
  96. static int intr_disconnect_level(int cpu, int bit)
  97. {
  98. nasid_t nasid = COMPACT_TO_NASID_NODEID(cpu_to_node(cpu));
  99. struct slice_data *si = cpu_data[cpu].data;
  100. clear_bit(bit, si->irq_enable_mask);
  101. if (!cputoslice(cpu)) {
  102. REMOTE_HUB_S(nasid, PI_INT_MASK0_A, si->irq_enable_mask[0]);
  103. REMOTE_HUB_S(nasid, PI_INT_MASK1_A, si->irq_enable_mask[1]);
  104. } else {
  105. REMOTE_HUB_S(nasid, PI_INT_MASK0_B, si->irq_enable_mask[0]);
  106. REMOTE_HUB_S(nasid, PI_INT_MASK1_B, si->irq_enable_mask[1]);
  107. }
  108. return 0;
  109. }
  110. /* Startup one of the (PCI ...) IRQs routes over a bridge. */
  111. static unsigned int startup_bridge_irq(struct irq_data *d)
  112. {
  113. struct bridge_controller *bc;
  114. bridgereg_t device;
  115. bridge_t *bridge;
  116. int pin, swlevel;
  117. cpuid_t cpu;
  118. pin = SLOT_FROM_PCI_IRQ(d->irq);
  119. bc = IRQ_TO_BRIDGE(d->irq);
  120. bridge = bc->base;
  121. pr_debug("bridge_startup(): irq= 0x%x pin=%d\n", d->irq, pin);
  122. /*
  123. * "map" irq to a swlevel greater than 6 since the first 6 bits
  124. * of INT_PEND0 are taken
  125. */
  126. swlevel = find_level(&cpu, d->irq);
  127. bridge->b_int_addr[pin].addr = (0x20000 | swlevel | (bc->nasid << 8));
  128. bridge->b_int_enable |= (1 << pin);
  129. bridge->b_int_enable |= 0x7ffffe00; /* more stuff in int_enable */
  130. /*
  131. * Enable sending of an interrupt clear packt to the hub on a high to
  132. * low transition of the interrupt pin.
  133. *
  134. * IRIX sets additional bits in the address which are documented as
  135. * reserved in the bridge docs.
  136. */
  137. bridge->b_int_mode |= (1UL << pin);
  138. /*
  139. * We assume the bridge to have a 1:1 mapping between devices
  140. * (slots) and intr pins.
  141. */
  142. device = bridge->b_int_device;
  143. device &= ~(7 << (pin*3));
  144. device |= (pin << (pin*3));
  145. bridge->b_int_device = device;
  146. bridge->b_wid_tflush;
  147. intr_connect_level(cpu, swlevel);
  148. return 0; /* Never anything pending. */
  149. }
  150. /* Shutdown one of the (PCI ...) IRQs routes over a bridge. */
  151. static void shutdown_bridge_irq(struct irq_data *d)
  152. {
  153. struct bridge_controller *bc = IRQ_TO_BRIDGE(d->irq);
  154. bridge_t *bridge = bc->base;
  155. int pin, swlevel;
  156. cpuid_t cpu;
  157. pr_debug("bridge_shutdown: irq 0x%x\n", d->irq);
  158. pin = SLOT_FROM_PCI_IRQ(d->irq);
  159. /*
  160. * map irq to a swlevel greater than 6 since the first 6 bits
  161. * of INT_PEND0 are taken
  162. */
  163. swlevel = find_level(&cpu, d->irq);
  164. intr_disconnect_level(cpu, swlevel);
  165. bridge->b_int_enable &= ~(1 << pin);
  166. bridge->b_wid_tflush;
  167. }
  168. static inline void enable_bridge_irq(struct irq_data *d)
  169. {
  170. cpuid_t cpu;
  171. int swlevel;
  172. swlevel = find_level(&cpu, d->irq); /* Criminal offence */
  173. intr_connect_level(cpu, swlevel);
  174. }
  175. static inline void disable_bridge_irq(struct irq_data *d)
  176. {
  177. cpuid_t cpu;
  178. int swlevel;
  179. swlevel = find_level(&cpu, d->irq); /* Criminal offence */
  180. intr_disconnect_level(cpu, swlevel);
  181. }
  182. static struct irq_chip bridge_irq_type = {
  183. .name = "bridge",
  184. .irq_startup = startup_bridge_irq,
  185. .irq_shutdown = shutdown_bridge_irq,
  186. .irq_mask = disable_bridge_irq,
  187. .irq_unmask = enable_bridge_irq,
  188. };
  189. void register_bridge_irq(unsigned int irq)
  190. {
  191. irq_set_chip_and_handler(irq, &bridge_irq_type, handle_level_irq);
  192. }
  193. int request_bridge_irq(struct bridge_controller *bc)
  194. {
  195. int irq = allocate_irqno();
  196. int swlevel, cpu;
  197. nasid_t nasid;
  198. if (irq < 0)
  199. return irq;
  200. /*
  201. * "map" irq to a swlevel greater than 6 since the first 6 bits
  202. * of INT_PEND0 are taken
  203. */
  204. cpu = bc->irq_cpu;
  205. swlevel = alloc_level(cpu, irq);
  206. if (unlikely(swlevel < 0)) {
  207. free_irqno(irq);
  208. return -EAGAIN;
  209. }
  210. /* Make sure it's not already pending when we connect it. */
  211. nasid = COMPACT_TO_NASID_NODEID(cpu_to_node(cpu));
  212. REMOTE_HUB_CLR_INTR(nasid, swlevel);
  213. intr_connect_level(cpu, swlevel);
  214. register_bridge_irq(irq);
  215. return irq;
  216. }