irq_i8259.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/alpha/kernel/irq_i8259.c
  4. *
  5. * This is the 'legacy' 8259A Programmable Interrupt Controller,
  6. * present in the majority of PC/AT boxes.
  7. *
  8. * Started hacking from linux-2.3.30pre6/arch/i386/kernel/i8259.c.
  9. */
  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(struct irq_data *d)
  31. {
  32. spin_lock(&i8259_irq_lock);
  33. i8259_update_irq_hw(d->irq, cached_irq_mask &= ~(1 << d->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(struct irq_data *d)
  43. {
  44. spin_lock(&i8259_irq_lock);
  45. __i8259a_disable_irq(d->irq);
  46. spin_unlock(&i8259_irq_lock);
  47. }
  48. void
  49. i8259a_mask_and_ack_irq(struct irq_data *d)
  50. {
  51. unsigned int irq = d->irq;
  52. spin_lock(&i8259_irq_lock);
  53. __i8259a_disable_irq(irq);
  54. /* Ack the interrupt making it the lowest priority. */
  55. if (irq >= 8) {
  56. outb(0xE0 | (irq - 8), 0xa0); /* ack the slave */
  57. irq = 2;
  58. }
  59. outb(0xE0 | irq, 0x20); /* ack the master */
  60. spin_unlock(&i8259_irq_lock);
  61. }
  62. struct irq_chip i8259a_irq_type = {
  63. .name = "XT-PIC",
  64. .irq_unmask = i8259a_enable_irq,
  65. .irq_mask = i8259a_disable_irq,
  66. .irq_mask_ack = i8259a_mask_and_ack_irq,
  67. };
  68. void __init
  69. init_i8259a_irqs(void)
  70. {
  71. static struct irqaction cascade = {
  72. .handler = no_action,
  73. .name = "cascade",
  74. };
  75. long i;
  76. outb(0xff, 0x21); /* mask all of 8259A-1 */
  77. outb(0xff, 0xA1); /* mask all of 8259A-2 */
  78. for (i = 0; i < 16; i++) {
  79. irq_set_chip_and_handler(i, &i8259a_irq_type, handle_level_irq);
  80. }
  81. setup_irq(2, &cascade);
  82. }
  83. #if defined(CONFIG_ALPHA_GENERIC)
  84. # define IACK_SC alpha_mv.iack_sc
  85. #elif defined(CONFIG_ALPHA_APECS)
  86. # define IACK_SC APECS_IACK_SC
  87. #elif defined(CONFIG_ALPHA_LCA)
  88. # define IACK_SC LCA_IACK_SC
  89. #elif defined(CONFIG_ALPHA_CIA)
  90. # define IACK_SC CIA_IACK_SC
  91. #elif defined(CONFIG_ALPHA_PYXIS)
  92. # define IACK_SC PYXIS_IACK_SC
  93. #elif defined(CONFIG_ALPHA_TITAN)
  94. # define IACK_SC TITAN_IACK_SC
  95. #elif defined(CONFIG_ALPHA_TSUNAMI)
  96. # define IACK_SC TSUNAMI_IACK_SC
  97. #elif defined(CONFIG_ALPHA_IRONGATE)
  98. # define IACK_SC IRONGATE_IACK_SC
  99. #endif
  100. /* Note that CONFIG_ALPHA_POLARIS is intentionally left out here, since
  101. sys_rx164 wants to use isa_no_iack_sc_device_interrupt for some reason. */
  102. #if defined(IACK_SC)
  103. void
  104. isa_device_interrupt(unsigned long vector)
  105. {
  106. /*
  107. * Generate a PCI interrupt acknowledge cycle. The PIC will
  108. * respond with the interrupt vector of the highest priority
  109. * interrupt that is pending. The PALcode sets up the
  110. * interrupts vectors such that irq level L generates vector L.
  111. */
  112. int j = *(vuip) IACK_SC;
  113. j &= 0xff;
  114. handle_irq(j);
  115. }
  116. #endif
  117. #if defined(CONFIG_ALPHA_GENERIC) || !defined(IACK_SC)
  118. void
  119. isa_no_iack_sc_device_interrupt(unsigned long vector)
  120. {
  121. unsigned long pic;
  122. /*
  123. * It seems to me that the probability of two or more *device*
  124. * interrupts occurring at almost exactly the same time is
  125. * pretty low. So why pay the price of checking for
  126. * additional interrupts here if the common case can be
  127. * handled so much easier?
  128. */
  129. /*
  130. * The first read of gives you *all* interrupting lines.
  131. * Therefore, read the mask register and and out those lines
  132. * not enabled. Note that some documentation has 21 and a1
  133. * write only. This is not true.
  134. */
  135. pic = inb(0x20) | (inb(0xA0) << 8); /* read isr */
  136. pic &= 0xFFFB; /* mask out cascade & hibits */
  137. while (pic) {
  138. int j = ffz(~pic);
  139. pic &= pic - 1;
  140. handle_irq(j);
  141. }
  142. }
  143. #endif