1 #include <linux/stddef.h>
2 #include <linux/init.h>
4 #include <linux/ioport.h>
5 #include <linux/sched.h>
6 #include <linux/signal.h>
10 static volatile unsigned char *pci_intack; /* RO, gives us the irq vector */
12 unsigned char cached_8259[2] = { 0xff, 0xff };
13 #define cached_A1 (cached_8259[0])
14 #define cached_21 (cached_8259[1])
16 static spinlock_t i8259_lock = SPIN_LOCK_UNLOCKED;
18 int i8259_pic_irq_offset;
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.
27 i8259_irq(struct pt_regs *regs)
31 spin_lock(&i8259_lock);
33 /* Either int-ack or poll for the IRQ */
37 /* Perform an interrupt acknowledge cycle on controller 1. */
38 outb(0x0C, 0x20); /* prepare for poll */
42 * Interrupt is cascaded so perform interrupt
43 * acknowledge on controller 2.
45 outb(0x0C, 0xA0); /* prepare for poll */
46 irq = (inb(0xA0) & 7) + 8;
52 * This may be a spurious interrupt.
54 * Read the interrupt status register (ISR). If the most
55 * significant bit is not set then there is no valid
59 outb(0x0B, 0x20); /* ISR register */
64 spin_unlock(&i8259_lock);
68 static void i8259_mask_and_ack_irq(unsigned int irq_nr)
72 spin_lock_irqsave(&i8259_lock, flags);
73 if ( irq_nr >= i8259_pic_irq_offset )
74 irq_nr -= i8259_pic_irq_offset;
77 cached_A1 |= 1 << (irq_nr-8);
78 inb(0xA1); /* DUMMY */
80 outb(0x20,0xA0); /* Non-specific EOI */
81 outb(0x20,0x20); /* Non-specific EOI to cascade */
83 cached_21 |= 1 << irq_nr;
84 inb(0x21); /* DUMMY */
86 outb(0x20,0x20); /* Non-specific EOI */
88 spin_unlock_irqrestore(&i8259_lock, flags);
91 static void i8259_set_irq_mask(int irq_nr)
97 static void i8259_mask_irq(unsigned int irq_nr)
101 spin_lock_irqsave(&i8259_lock, flags);
102 if ( irq_nr >= i8259_pic_irq_offset )
103 irq_nr -= i8259_pic_irq_offset;
105 cached_21 |= 1 << irq_nr;
107 cached_A1 |= 1 << (irq_nr-8);
108 i8259_set_irq_mask(irq_nr);
109 spin_unlock_irqrestore(&i8259_lock, flags);
112 static void i8259_unmask_irq(unsigned int irq_nr)
116 spin_lock_irqsave(&i8259_lock, flags);
117 if ( irq_nr >= i8259_pic_irq_offset )
118 irq_nr -= i8259_pic_irq_offset;
120 cached_21 &= ~(1 << irq_nr);
122 cached_A1 &= ~(1 << (irq_nr-8));
123 i8259_set_irq_mask(irq_nr);
124 spin_unlock_irqrestore(&i8259_lock, flags);
127 static void i8259_end_irq(unsigned int irq)
129 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
130 i8259_unmask_irq(irq);
133 struct hw_interrupt_type i8259_pic = {
139 i8259_mask_and_ack_irq,
144 #if 0 /* Do not request these before the host bridge resource have been setup */
145 static struct resource pic1_iores = {
146 "8259 (master)", 0x20, 0x21, IORESOURCE_BUSY
149 static struct resource pic2_iores = {
150 "8259 (slave)", 0xa0, 0xa1, IORESOURCE_BUSY
153 static struct resource pic_edgectrl_iores = {
154 "8259 edge control", 0x4d0, 0x4d1, IORESOURCE_BUSY
158 void __init i8259_init(unsigned long intack_addr)
162 spin_lock_irqsave(&i8259_lock, flags);
163 /* init master interrupt controller */
164 outb(0x11, 0x20); /* Start init sequence */
165 outb(0x00, 0x21); /* Vector base */
166 outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
167 outb(0x01, 0x21); /* Select 8086 mode */
169 /* init slave interrupt controller */
170 outb(0x11, 0xA0); /* Start init sequence */
171 outb(0x08, 0xA1); /* Vector base */
172 outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
173 outb(0x01, 0xA1); /* Select 8086 mode */
175 /* always read ISR */
179 /* Mask all interrupts */
180 outb(cached_A1, 0xA1);
181 outb(cached_21, 0x21);
183 spin_unlock_irqrestore(&i8259_lock, flags);
185 /* reserve our resources */
186 request_irq( i8259_pic_irq_offset + 2, no_action, SA_INTERRUPT,
187 "82c59 secondary cascade", NULL );
188 #if 0 /* Do not request these before the host bridge resource have been setup */
189 request_resource(&ioport_resource, &pic1_iores);
190 request_resource(&ioport_resource, &pic2_iores);
191 request_resource(&ioport_resource, &pic_edgectrl_iores);
194 pci_intack = ioremap(intack_addr, 1);