visws_apic.c 7.0 KB

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