irq_i8259.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * linux/arch/alpha/kernel/irq_i8259.c
  3. *
  4. * This is the 'legacy' 8259A Programmable Interrupt Controller,
  5. * present in the majority of PC/AT boxes.
  6. *
  7. * Started hacking from linux-2.3.30pre6/arch/i386/kernel/i8259.c.
  8. */
  9. #include <linux/config.h>
  10. #include <linux/init.h>
  11. #include <linux/cache.h>
  12. #include <linux/sched.h>
  13. #include <linux/irq.h>
  14. #include <linux/interrupt.h>
  15. #include <asm/io.h>
  16. #include "proto.h"
  17. #include "irq_impl.h"
  18. /* Note mask bit is true for DISABLED irqs. */
  19. static unsigned int cached_irq_mask = 0xffff;
  20. static DEFINE_SPINLOCK(i8259_irq_lock);
  21. static inline void
  22. i8259_update_irq_hw(unsigned int irq, unsigned long mask)
  23. {
  24. int port = 0x21;
  25. if (irq & 8) mask >>= 8;
  26. if (irq & 8) port = 0xA1;
  27. outb(mask, port);
  28. }
  29. inline void
  30. i8259a_enable_irq(unsigned int irq)
  31. {
  32. spin_lock(&i8259_irq_lock);
  33. i8259_update_irq_hw(irq, cached_irq_mask &= ~(1 << irq));
  34. spin_unlock(&i8259_irq_lock);
  35. }
  36. static inline void
  37. __i8259a_disable_irq(unsigned int irq)
  38. {
  39. i8259_update_irq_hw(irq, cached_irq_mask |= 1 << irq);
  40. }
  41. void
  42. i8259a_disable_irq(unsigned int irq)
  43. {
  44. spin_lock(&i8259_irq_lock);
  45. __i8259a_disable_irq(irq);
  46. spin_unlock(&i8259_irq_lock);
  47. }
  48. void
  49. i8259a_mask_and_ack_irq(unsigned int irq)
  50. {
  51. spin_lock(&i8259_irq_lock);
  52. __i8259a_disable_irq(irq);
  53. /* Ack the interrupt making it the lowest priority. */
  54. if (irq >= 8) {
  55. outb(0xE0 | (irq - 8), 0xa0); /* ack the slave */
  56. irq = 2;
  57. }
  58. outb(0xE0 | irq, 0x20); /* ack the master */
  59. spin_unlock(&i8259_irq_lock);
  60. }
  61. unsigned int
  62. i8259a_startup_irq(unsigned int irq)
  63. {
  64. i8259a_enable_irq(irq);
  65. return 0; /* never anything pending */
  66. }
  67. void
  68. i8259a_end_irq(unsigned int irq)
  69. {
  70. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  71. i8259a_enable_irq(irq);
  72. }
  73. struct hw_interrupt_type i8259a_irq_type = {
  74. .typename = "XT-PIC",
  75. .startup = i8259a_startup_irq,
  76. .shutdown = i8259a_disable_irq,
  77. .enable = i8259a_enable_irq,
  78. .disable = i8259a_disable_irq,
  79. .ack = i8259a_mask_and_ack_irq,
  80. .end = i8259a_end_irq,
  81. };
  82. void __init
  83. init_i8259a_irqs(void)
  84. {
  85. static struct irqaction cascade = {
  86. .handler = no_action,
  87. .name = "cascade",
  88. };
  89. long i;
  90. outb(0xff, 0x21); /* mask all of 8259A-1 */
  91. outb(0xff, 0xA1); /* mask all of 8259A-2 */
  92. for (i = 0; i < 16; i++) {
  93. irq_desc[i].status = IRQ_DISABLED;
  94. irq_desc[i].handler = &i8259a_irq_type;
  95. }
  96. setup_irq(2, &cascade);
  97. }
  98. #if defined(CONFIG_ALPHA_GENERIC)
  99. # define IACK_SC alpha_mv.iack_sc
  100. #elif defined(CONFIG_ALPHA_APECS)
  101. # define IACK_SC APECS_IACK_SC
  102. #elif defined(CONFIG_ALPHA_LCA)
  103. # define IACK_SC LCA_IACK_SC
  104. #elif defined(CONFIG_ALPHA_CIA)
  105. # define IACK_SC CIA_IACK_SC
  106. #elif defined(CONFIG_ALPHA_PYXIS)
  107. # define IACK_SC PYXIS_IACK_SC
  108. #elif defined(CONFIG_ALPHA_TITAN)
  109. # define IACK_SC TITAN_IACK_SC
  110. #elif defined(CONFIG_ALPHA_TSUNAMI)
  111. # define IACK_SC TSUNAMI_IACK_SC
  112. #elif defined(CONFIG_ALPHA_IRONGATE)
  113. # define IACK_SC IRONGATE_IACK_SC
  114. #endif
  115. /* Note that CONFIG_ALPHA_POLARIS is intentionally left out here, since
  116. sys_rx164 wants to use isa_no_iack_sc_device_interrupt for some reason. */
  117. #if defined(IACK_SC)
  118. void
  119. isa_device_interrupt(unsigned long vector, struct pt_regs *regs)
  120. {
  121. /*
  122. * Generate a PCI interrupt acknowledge cycle. The PIC will
  123. * respond with the interrupt vector of the highest priority
  124. * interrupt that is pending. The PALcode sets up the
  125. * interrupts vectors such that irq level L generates vector L.
  126. */
  127. int j = *(vuip) IACK_SC;
  128. j &= 0xff;
  129. handle_irq(j, regs);
  130. }
  131. #endif
  132. #if defined(CONFIG_ALPHA_GENERIC) || !defined(IACK_SC)
  133. void
  134. isa_no_iack_sc_device_interrupt(unsigned long vector, struct pt_regs *regs)
  135. {
  136. unsigned long pic;
  137. /*
  138. * It seems to me that the probability of two or more *device*
  139. * interrupts occurring at almost exactly the same time is
  140. * pretty low. So why pay the price of checking for
  141. * additional interrupts here if the common case can be
  142. * handled so much easier?
  143. */
  144. /*
  145. * The first read of gives you *all* interrupting lines.
  146. * Therefore, read the mask register and and out those lines
  147. * not enabled. Note that some documentation has 21 and a1
  148. * write only. This is not true.
  149. */
  150. pic = inb(0x20) | (inb(0xA0) << 8); /* read isr */
  151. pic &= 0xFFFB; /* mask out cascade & hibits */
  152. while (pic) {
  153. int j = ffz(~pic);
  154. pic &= pic - 1;
  155. handle_irq(j, regs);
  156. }
  157. }
  158. #endif