irq_i8259.c 4.2 KB

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