visws_apic.c 7.2 KB

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