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