i8259.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * i8259 interrupt controller driver.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/ioport.h>
  11. #include <linux/interrupt.h>
  12. #include <asm/io.h>
  13. #include <asm/i8259.h>
  14. static volatile void __iomem *pci_intack; /* RO, gives us the irq vector */
  15. static unsigned char cached_8259[2] = { 0xff, 0xff };
  16. #define cached_A1 (cached_8259[0])
  17. #define cached_21 (cached_8259[1])
  18. static DEFINE_SPINLOCK(i8259_lock);
  19. static int i8259_pic_irq_offset;
  20. /*
  21. * Acknowledge the IRQ using either the PCI host bridge's interrupt
  22. * acknowledge feature or poll. How i8259_init() is called determines
  23. * which is called. It should be noted that polling is broken on some
  24. * IBM and Motorola PReP boxes so we must use the int-ack feature on them.
  25. */
  26. int i8259_irq(void)
  27. {
  28. int irq;
  29. spin_lock(&i8259_lock);
  30. /* Either int-ack or poll for the IRQ */
  31. if (pci_intack)
  32. irq = readb(pci_intack);
  33. else {
  34. /* Perform an interrupt acknowledge cycle on controller 1. */
  35. outb(0x0C, 0x20); /* prepare for poll */
  36. irq = inb(0x20) & 7;
  37. if (irq == 2 ) {
  38. /*
  39. * Interrupt is cascaded so perform interrupt
  40. * acknowledge on controller 2.
  41. */
  42. outb(0x0C, 0xA0); /* prepare for poll */
  43. irq = (inb(0xA0) & 7) + 8;
  44. }
  45. }
  46. if (irq == 7) {
  47. /*
  48. * This may be a spurious interrupt.
  49. *
  50. * Read the interrupt status register (ISR). If the most
  51. * significant bit is not set then there is no valid
  52. * interrupt.
  53. */
  54. if (!pci_intack)
  55. outb(0x0B, 0x20); /* ISR register */
  56. if(~inb(0x20) & 0x80)
  57. irq = -1;
  58. }
  59. spin_unlock(&i8259_lock);
  60. return irq + i8259_pic_irq_offset;
  61. }
  62. static void i8259_mask_and_ack_irq(unsigned int irq_nr)
  63. {
  64. unsigned long flags;
  65. spin_lock_irqsave(&i8259_lock, flags);
  66. irq_nr -= i8259_pic_irq_offset;
  67. if (irq_nr > 7) {
  68. cached_A1 |= 1 << (irq_nr-8);
  69. inb(0xA1); /* DUMMY */
  70. outb(cached_A1, 0xA1);
  71. outb(0x20, 0xA0); /* Non-specific EOI */
  72. outb(0x20, 0x20); /* Non-specific EOI to cascade */
  73. } else {
  74. cached_21 |= 1 << irq_nr;
  75. inb(0x21); /* DUMMY */
  76. outb(cached_21, 0x21);
  77. outb(0x20, 0x20); /* Non-specific EOI */
  78. }
  79. spin_unlock_irqrestore(&i8259_lock, flags);
  80. }
  81. static void i8259_set_irq_mask(int irq_nr)
  82. {
  83. outb(cached_A1,0xA1);
  84. outb(cached_21,0x21);
  85. }
  86. static void i8259_mask_irq(unsigned int irq_nr)
  87. {
  88. unsigned long flags;
  89. spin_lock_irqsave(&i8259_lock, flags);
  90. irq_nr -= i8259_pic_irq_offset;
  91. if (irq_nr < 8)
  92. cached_21 |= 1 << irq_nr;
  93. else
  94. cached_A1 |= 1 << (irq_nr-8);
  95. i8259_set_irq_mask(irq_nr);
  96. spin_unlock_irqrestore(&i8259_lock, flags);
  97. }
  98. static void i8259_unmask_irq(unsigned int irq_nr)
  99. {
  100. unsigned long flags;
  101. spin_lock_irqsave(&i8259_lock, flags);
  102. irq_nr -= i8259_pic_irq_offset;
  103. if (irq_nr < 8)
  104. cached_21 &= ~(1 << irq_nr);
  105. else
  106. cached_A1 &= ~(1 << (irq_nr-8));
  107. i8259_set_irq_mask(irq_nr);
  108. spin_unlock_irqrestore(&i8259_lock, flags);
  109. }
  110. static struct irq_chip i8259_pic = {
  111. .typename = " i8259 ",
  112. .mask = i8259_mask_irq,
  113. .unmask = i8259_unmask_irq,
  114. .mask_ack = i8259_mask_and_ack_irq,
  115. };
  116. static struct resource pic1_iores = {
  117. .name = "8259 (master)",
  118. .start = 0x20,
  119. .end = 0x21,
  120. .flags = IORESOURCE_BUSY,
  121. };
  122. static struct resource pic2_iores = {
  123. .name = "8259 (slave)",
  124. .start = 0xa0,
  125. .end = 0xa1,
  126. .flags = IORESOURCE_BUSY,
  127. };
  128. static struct resource pic_edgectrl_iores = {
  129. .name = "8259 edge control",
  130. .start = 0x4d0,
  131. .end = 0x4d1,
  132. .flags = IORESOURCE_BUSY,
  133. };
  134. static struct irqaction i8259_irqaction = {
  135. .handler = no_action,
  136. .flags = SA_INTERRUPT,
  137. .mask = CPU_MASK_NONE,
  138. .name = "82c59 secondary cascade",
  139. };
  140. /*
  141. * i8259_init()
  142. * intack_addr - PCI interrupt acknowledge (real) address which will return
  143. * the active irq from the 8259
  144. */
  145. void __init i8259_init(unsigned long intack_addr, int offset)
  146. {
  147. unsigned long flags;
  148. int i;
  149. spin_lock_irqsave(&i8259_lock, flags);
  150. i8259_pic_irq_offset = offset;
  151. /* init master interrupt controller */
  152. outb(0x11, 0x20); /* Start init sequence */
  153. outb(0x00, 0x21); /* Vector base */
  154. outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
  155. outb(0x01, 0x21); /* Select 8086 mode */
  156. /* init slave interrupt controller */
  157. outb(0x11, 0xA0); /* Start init sequence */
  158. outb(0x08, 0xA1); /* Vector base */
  159. outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
  160. outb(0x01, 0xA1); /* Select 8086 mode */
  161. /* always read ISR */
  162. outb(0x0B, 0x20);
  163. outb(0x0B, 0xA0);
  164. /* Mask all interrupts */
  165. outb(cached_A1, 0xA1);
  166. outb(cached_21, 0x21);
  167. spin_unlock_irqrestore(&i8259_lock, flags);
  168. for (i = 0; i < NUM_ISA_INTERRUPTS; ++i) {
  169. set_irq_chip_and_handler(offset + i, &i8259_pic,
  170. handle_level_irq);
  171. irq_desc[offset + i].status |= IRQ_LEVEL;
  172. }
  173. /* reserve our resources */
  174. setup_irq(offset + 2, &i8259_irqaction);
  175. request_resource(&ioport_resource, &pic1_iores);
  176. request_resource(&ioport_resource, &pic2_iores);
  177. request_resource(&ioport_resource, &pic_edgectrl_iores);
  178. if (intack_addr != 0)
  179. pci_intack = ioremap(intack_addr, 1);
  180. }