visws_apic.c 7.2 KB

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