visws_apic.c 7.1 KB

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