visws_apic.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright (C) 1999 Bent Hagemark, Ingo Molnar
  3. *
  4. * SGI Visual Workstation interrupt controller
  5. *
  6. * The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
  7. * which serves as the main interrupt controller in the system. Non-legacy
  8. * hardware in the system uses this controller directly. Legacy devices
  9. * are connected to the PIIX4 which in turn has its 8259(s) connected to
  10. * a of the Cobalt APIC entry.
  11. *
  12. * 09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
  13. *
  14. * 25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
  15. */
  16. #include <linux/kernel_stat.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/init.h>
  19. #include <asm/io.h>
  20. #include <asm/apic.h>
  21. #include <asm/i8259.h>
  22. #include "cobalt.h"
  23. #include "irq_vectors.h"
  24. static DEFINE_SPINLOCK(cobalt_lock);
  25. /*
  26. * Set the given Cobalt APIC Redirection Table entry to point
  27. * to the given IDT vector/index.
  28. */
  29. static inline void co_apic_set(int entry, int irq)
  30. {
  31. co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
  32. co_apic_write(CO_APIC_HI(entry), 0);
  33. }
  34. /*
  35. * Cobalt (IO)-APIC functions to handle PCI devices.
  36. */
  37. static inline int co_apic_ide0_hack(void)
  38. {
  39. extern char visws_board_type;
  40. extern char visws_board_rev;
  41. if (visws_board_type == VISWS_320 && visws_board_rev == 5)
  42. return 5;
  43. return CO_APIC_IDE0;
  44. }
  45. static int is_co_apic(unsigned int irq)
  46. {
  47. if (IS_CO_APIC(irq))
  48. return CO_APIC(irq);
  49. switch (irq) {
  50. case 0: return CO_APIC_CPU;
  51. case CO_IRQ_IDE0: return co_apic_ide0_hack();
  52. case CO_IRQ_IDE1: return CO_APIC_IDE1;
  53. default: return -1;
  54. }
  55. }
  56. /*
  57. * This is the SGI Cobalt (IO-)APIC:
  58. */
  59. static void enable_cobalt_irq(unsigned int irq)
  60. {
  61. co_apic_set(is_co_apic(irq), irq);
  62. }
  63. static void disable_cobalt_irq(unsigned int irq)
  64. {
  65. int entry = is_co_apic(irq);
  66. co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
  67. co_apic_read(CO_APIC_LO(entry));
  68. }
  69. /*
  70. * "irq" really just serves to identify the device. Here is where we
  71. * map this to the Cobalt APIC entry where it's physically wired.
  72. * This is called via request_irq -> setup_irq -> irq_desc->startup()
  73. */
  74. static unsigned int startup_cobalt_irq(unsigned int irq)
  75. {
  76. unsigned long flags;
  77. spin_lock_irqsave(&cobalt_lock, flags);
  78. if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
  79. irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
  80. enable_cobalt_irq(irq);
  81. spin_unlock_irqrestore(&cobalt_lock, flags);
  82. return 0;
  83. }
  84. static void ack_cobalt_irq(unsigned int irq)
  85. {
  86. unsigned long flags;
  87. spin_lock_irqsave(&cobalt_lock, flags);
  88. disable_cobalt_irq(irq);
  89. apic_write(APIC_EOI, APIC_EIO_ACK);
  90. spin_unlock_irqrestore(&cobalt_lock, flags);
  91. }
  92. static void end_cobalt_irq(unsigned int irq)
  93. {
  94. unsigned long flags;
  95. spin_lock_irqsave(&cobalt_lock, flags);
  96. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  97. enable_cobalt_irq(irq);
  98. spin_unlock_irqrestore(&cobalt_lock, flags);
  99. }
  100. static struct irq_chip cobalt_irq_type = {
  101. .typename = "Cobalt-APIC",
  102. .startup = startup_cobalt_irq,
  103. .shutdown = disable_cobalt_irq,
  104. .enable = enable_cobalt_irq,
  105. .disable = disable_cobalt_irq,
  106. .ack = ack_cobalt_irq,
  107. .end = end_cobalt_irq,
  108. };
  109. /*
  110. * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
  111. * -- not the manner expected by the code in i8259.c.
  112. *
  113. * there is a 'master' physical interrupt source that gets sent to
  114. * the CPU. But in the chipset there are various 'virtual' interrupts
  115. * waiting to be handled. We represent this to Linux through a 'master'
  116. * interrupt controller type, and through a special virtual interrupt-
  117. * controller. Device drivers only see the virtual interrupt sources.
  118. */
  119. static unsigned int startup_piix4_master_irq(unsigned int irq)
  120. {
  121. init_8259A(0);
  122. return startup_cobalt_irq(irq);
  123. }
  124. static void end_piix4_master_irq(unsigned int irq)
  125. {
  126. unsigned long flags;
  127. spin_lock_irqsave(&cobalt_lock, flags);
  128. enable_cobalt_irq(irq);
  129. spin_unlock_irqrestore(&cobalt_lock, flags);
  130. }
  131. static struct irq_chip piix4_master_irq_type = {
  132. .typename = "PIIX4-master",
  133. .startup = startup_piix4_master_irq,
  134. .ack = ack_cobalt_irq,
  135. .end = end_piix4_master_irq,
  136. };
  137. static struct irq_chip piix4_virtual_irq_type = {
  138. .typename = "PIIX4-virtual",
  139. .shutdown = disable_8259A_irq,
  140. .enable = enable_8259A_irq,
  141. .disable = disable_8259A_irq,
  142. };
  143. /*
  144. * PIIX4-8259 master/virtual functions to handle interrupt requests
  145. * from legacy devices: floppy, parallel, serial, rtc.
  146. *
  147. * None of these get Cobalt APIC entries, neither do they have IDT
  148. * entries. These interrupts are purely virtual and distributed from
  149. * the 'master' interrupt source: CO_IRQ_8259.
  150. *
  151. * When the 8259 interrupts its handler figures out which of these
  152. * devices is interrupting and dispatches to its handler.
  153. *
  154. * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
  155. * enable_irq gets the right irq. This 'master' irq is never directly
  156. * manipulated by any driver.
  157. */
  158. static irqreturn_t piix4_master_intr(int irq, void *dev_id)
  159. {
  160. int realirq;
  161. irq_desc_t *desc;
  162. unsigned long flags;
  163. spin_lock_irqsave(&i8259A_lock, flags);
  164. /* Find out what's interrupting in the PIIX4 master 8259 */
  165. outb(0x0c, 0x20); /* OCW3 Poll command */
  166. realirq = inb(0x20);
  167. /*
  168. * Bit 7 == 0 means invalid/spurious
  169. */
  170. if (unlikely(!(realirq & 0x80)))
  171. goto out_unlock;
  172. realirq &= 7;
  173. if (unlikely(realirq == 2)) {
  174. outb(0x0c, 0xa0);
  175. realirq = inb(0xa0);
  176. if (unlikely(!(realirq & 0x80)))
  177. goto out_unlock;
  178. realirq = (realirq & 7) + 8;
  179. }
  180. /* mask and ack interrupt */
  181. cached_irq_mask |= 1 << realirq;
  182. if (unlikely(realirq > 7)) {
  183. inb(0xa1);
  184. outb(cached_slave_mask, 0xa1);
  185. outb(0x60 + (realirq & 7), 0xa0);
  186. outb(0x60 + 2, 0x20);
  187. } else {
  188. inb(0x21);
  189. outb(cached_master_mask, 0x21);
  190. outb(0x60 + realirq, 0x20);
  191. }
  192. spin_unlock_irqrestore(&i8259A_lock, flags);
  193. desc = irq_desc + realirq;
  194. /*
  195. * handle this 'virtual interrupt' as a Cobalt one now.
  196. */
  197. kstat_cpu(smp_processor_id()).irqs[realirq]++;
  198. if (likely(desc->action != NULL))
  199. handle_IRQ_event(realirq, desc->action);
  200. if (!(desc->status & IRQ_DISABLED))
  201. enable_8259A_irq(realirq);
  202. return IRQ_HANDLED;
  203. out_unlock:
  204. spin_unlock_irqrestore(&i8259A_lock, flags);
  205. return IRQ_NONE;
  206. }
  207. static struct irqaction master_action = {
  208. .handler = piix4_master_intr,
  209. .name = "PIIX4-8259",
  210. };
  211. static struct irqaction cascade_action = {
  212. .handler = no_action,
  213. .name = "cascade",
  214. };
  215. void init_VISWS_APIC_irqs(void)
  216. {
  217. int i;
  218. for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
  219. irq_desc[i].status = IRQ_DISABLED;
  220. irq_desc[i].action = 0;
  221. irq_desc[i].depth = 1;
  222. if (i == 0) {
  223. irq_desc[i].chip = &cobalt_irq_type;
  224. }
  225. else if (i == CO_IRQ_IDE0) {
  226. irq_desc[i].chip = &cobalt_irq_type;
  227. }
  228. else if (i == CO_IRQ_IDE1) {
  229. irq_desc[i].chip = &cobalt_irq_type;
  230. }
  231. else if (i == CO_IRQ_8259) {
  232. irq_desc[i].chip = &piix4_master_irq_type;
  233. }
  234. else if (i < CO_IRQ_APIC0) {
  235. irq_desc[i].chip = &piix4_virtual_irq_type;
  236. }
  237. else if (IS_CO_APIC(i)) {
  238. irq_desc[i].chip = &cobalt_irq_type;
  239. }
  240. }
  241. setup_irq(CO_IRQ_8259, &master_action);
  242. setup_irq(2, &cascade_action);
  243. }