i8259.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. .disable = i8259_mask_irq,
  114. .unmask = i8259_unmask_irq,
  115. .mask_ack = i8259_mask_and_ack_irq,
  116. };
  117. static struct resource pic1_iores = {
  118. .name = "8259 (master)",
  119. .start = 0x20,
  120. .end = 0x21,
  121. .flags = IORESOURCE_BUSY,
  122. };
  123. static struct resource pic2_iores = {
  124. .name = "8259 (slave)",
  125. .start = 0xa0,
  126. .end = 0xa1,
  127. .flags = IORESOURCE_BUSY,
  128. };
  129. static struct resource pic_edgectrl_iores = {
  130. .name = "8259 edge control",
  131. .start = 0x4d0,
  132. .end = 0x4d1,
  133. .flags = IORESOURCE_BUSY,
  134. };
  135. static struct irqaction i8259_irqaction = {
  136. .handler = no_action,
  137. .flags = IRQF_DISABLED,
  138. .mask = CPU_MASK_NONE,
  139. .name = "82c59 secondary cascade",
  140. };
  141. /*
  142. * i8259_init()
  143. * intack_addr - PCI interrupt acknowledge (real) address which will return
  144. * the active irq from the 8259
  145. */
  146. void __init i8259_init(unsigned long intack_addr, int offset)
  147. {
  148. unsigned long flags;
  149. int i;
  150. spin_lock_irqsave(&i8259_lock, flags);
  151. i8259_pic_irq_offset = offset;
  152. /* init master interrupt controller */
  153. outb(0x11, 0x20); /* Start init sequence */
  154. outb(0x00, 0x21); /* Vector base */
  155. outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
  156. outb(0x01, 0x21); /* Select 8086 mode */
  157. /* init slave interrupt controller */
  158. outb(0x11, 0xA0); /* Start init sequence */
  159. outb(0x08, 0xA1); /* Vector base */
  160. outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
  161. outb(0x01, 0xA1); /* Select 8086 mode */
  162. /* always read ISR */
  163. outb(0x0B, 0x20);
  164. outb(0x0B, 0xA0);
  165. /* Mask all interrupts */
  166. outb(cached_A1, 0xA1);
  167. outb(cached_21, 0x21);
  168. spin_unlock_irqrestore(&i8259_lock, flags);
  169. for (i = 0; i < NUM_ISA_INTERRUPTS; ++i) {
  170. set_irq_chip_and_handler(offset + i, &i8259_pic,
  171. handle_level_irq);
  172. irq_desc[offset + i].status |= IRQ_LEVEL;
  173. }
  174. /* reserve our resources */
  175. setup_irq(offset + 2, &i8259_irqaction);
  176. request_resource(&ioport_resource, &pic1_iores);
  177. request_resource(&ioport_resource, &pic2_iores);
  178. request_resource(&ioport_resource, &pic_edgectrl_iores);
  179. if (intack_addr != 0)
  180. pci_intack = ioremap(intack_addr, 1);
  181. }