1 #include <linux/init.h>
2 #include <linux/ioport.h>
3 #include <linux/interrupt.h>
7 static volatile unsigned char *pci_intack; /* RO, gives us the irq vector */
9 unsigned char cached_8259[2] = { 0xff, 0xff };
10 #define cached_A1 (cached_8259[0])
11 #define cached_21 (cached_8259[1])
13 static DEFINE_SPINLOCK(i8259_lock);
15 int i8259_pic_irq_offset;
18 * Acknowledge the IRQ using either the PCI host bridge's interrupt
19 * acknowledge feature or poll. How i8259_init() is called determines
20 * which is called. It should be noted that polling is broken on some
21 * IBM and Motorola PReP boxes so we must use the int-ack feature on them.
24 i8259_irq(struct pt_regs *regs)
28 spin_lock(&i8259_lock);
30 /* Either int-ack or poll for the IRQ */
34 /* Perform an interrupt acknowledge cycle on controller 1. */
35 outb(0x0C, 0x20); /* prepare for poll */
39 * Interrupt is cascaded so perform interrupt
40 * acknowledge on controller 2.
42 outb(0x0C, 0xA0); /* prepare for poll */
43 irq = (inb(0xA0) & 7) + 8;
49 * This may be a spurious interrupt.
51 * Read the interrupt status register (ISR). If the most
52 * significant bit is not set then there is no valid
56 outb(0x0B, 0x20); /* ISR register */
61 spin_unlock(&i8259_lock);
65 static void i8259_mask_and_ack_irq(unsigned int irq_nr)
69 spin_lock_irqsave(&i8259_lock, flags);
70 if ( irq_nr >= i8259_pic_irq_offset )
71 irq_nr -= i8259_pic_irq_offset;
74 cached_A1 |= 1 << (irq_nr-8);
75 inb(0xA1); /* DUMMY */
77 outb(0x20,0xA0); /* Non-specific EOI */
78 outb(0x20,0x20); /* Non-specific EOI to cascade */
80 cached_21 |= 1 << irq_nr;
81 inb(0x21); /* DUMMY */
83 outb(0x20,0x20); /* Non-specific EOI */
85 spin_unlock_irqrestore(&i8259_lock, flags);
88 static void i8259_set_irq_mask(int irq_nr)
94 static void i8259_mask_irq(unsigned int irq_nr)
98 spin_lock_irqsave(&i8259_lock, flags);
99 if ( irq_nr >= i8259_pic_irq_offset )
100 irq_nr -= i8259_pic_irq_offset;
102 cached_21 |= 1 << irq_nr;
104 cached_A1 |= 1 << (irq_nr-8);
105 i8259_set_irq_mask(irq_nr);
106 spin_unlock_irqrestore(&i8259_lock, flags);
109 static void i8259_unmask_irq(unsigned int irq_nr)
113 spin_lock_irqsave(&i8259_lock, flags);
114 if ( irq_nr >= i8259_pic_irq_offset )
115 irq_nr -= i8259_pic_irq_offset;
117 cached_21 &= ~(1 << irq_nr);
119 cached_A1 &= ~(1 << (irq_nr-8));
120 i8259_set_irq_mask(irq_nr);
121 spin_unlock_irqrestore(&i8259_lock, flags);
124 static void i8259_end_irq(unsigned int irq)
126 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))
127 && irq_desc[irq].action)
128 i8259_unmask_irq(irq);
131 struct hw_interrupt_type i8259_pic = {
137 i8259_mask_and_ack_irq,
142 static struct resource pic1_iores = {
143 .name = "8259 (master)",
146 .flags = IORESOURCE_BUSY,
149 static struct resource pic2_iores = {
150 .name = "8259 (slave)",
153 .flags = IORESOURCE_BUSY,
156 static struct resource pic_edgectrl_iores = {
157 .name = "8259 edge control",
160 .flags = IORESOURCE_BUSY,
163 static struct irqaction i8259_irqaction = {
164 .handler = no_action,
165 .flags = SA_INTERRUPT,
166 .mask = CPU_MASK_NONE,
167 .name = "82c59 secondary cascade",
172 * intack_addr - PCI interrupt acknowledge (real) address which will return
173 * the active irq from the 8259
176 i8259_init(long intack_addr)
180 spin_lock_irqsave(&i8259_lock, flags);
181 /* init master interrupt controller */
182 outb(0x11, 0x20); /* Start init sequence */
183 outb(0x00, 0x21); /* Vector base */
184 outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
185 outb(0x01, 0x21); /* Select 8086 mode */
187 /* init slave interrupt controller */
188 outb(0x11, 0xA0); /* Start init sequence */
189 outb(0x08, 0xA1); /* Vector base */
190 outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
191 outb(0x01, 0xA1); /* Select 8086 mode */
193 /* always read ISR */
197 /* Mask all interrupts */
198 outb(cached_A1, 0xA1);
199 outb(cached_21, 0x21);
201 spin_unlock_irqrestore(&i8259_lock, flags);
203 /* reserve our resources */
204 setup_irq( i8259_pic_irq_offset + 2, &i8259_irqaction);
205 request_resource(&ioport_resource, &pic1_iores);
206 request_resource(&ioport_resource, &pic2_iores);
207 request_resource(&ioport_resource, &pic_edgectrl_iores);
209 if (intack_addr != 0)
210 pci_intack = ioremap(intack_addr, 1);