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 = {
132 .typename = " i8259 ",
133 .enable = i8259_unmask_irq,
134 .disable = i8259_mask_irq,
135 .ack = i8259_mask_and_ack_irq,
136 .end = i8259_end_irq,
139 static struct resource pic1_iores = {
140 .name = "8259 (master)",
143 .flags = IORESOURCE_BUSY,
146 static struct resource pic2_iores = {
147 .name = "8259 (slave)",
150 .flags = IORESOURCE_BUSY,
153 static struct resource pic_edgectrl_iores = {
154 .name = "8259 edge control",
157 .flags = IORESOURCE_BUSY,
160 static struct irqaction i8259_irqaction = {
161 .handler = no_action,
162 .flags = SA_INTERRUPT,
163 .mask = CPU_MASK_NONE,
164 .name = "82c59 secondary cascade",
169 * intack_addr - PCI interrupt acknowledge (real) address which will return
170 * the active irq from the 8259
173 i8259_init(long intack_addr)
177 spin_lock_irqsave(&i8259_lock, flags);
178 /* init master interrupt controller */
179 outb(0x11, 0x20); /* Start init sequence */
180 outb(0x00, 0x21); /* Vector base */
181 outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
182 outb(0x01, 0x21); /* Select 8086 mode */
184 /* init slave interrupt controller */
185 outb(0x11, 0xA0); /* Start init sequence */
186 outb(0x08, 0xA1); /* Vector base */
187 outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
188 outb(0x01, 0xA1); /* Select 8086 mode */
190 /* always read ISR */
194 /* Mask all interrupts */
195 outb(cached_A1, 0xA1);
196 outb(cached_21, 0x21);
198 spin_unlock_irqrestore(&i8259_lock, flags);
200 /* reserve our resources */
201 setup_irq( i8259_pic_irq_offset + 2, &i8259_irqaction);
202 request_resource(&ioport_resource, &pic1_iores);
203 request_resource(&ioport_resource, &pic2_iores);
204 request_resource(&ioport_resource, &pic_edgectrl_iores);
206 if (intack_addr != 0)
207 pci_intack = ioremap(intack_addr, 1);