2 * c 2001 PPC64 Team, IBM Corp
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.
9 #include <linux/stddef.h>
10 #include <linux/init.h>
11 #include <linux/sched.h>
12 #include <linux/signal.h>
13 #include <linux/cache.h>
14 #include <linux/irq.h>
15 #include <linux/interrupt.h>
17 #include <asm/ppcdebug.h>
20 unsigned char cached_8259
[2] = { 0xff, 0xff };
21 #define cached_A1 (cached_8259[0])
22 #define cached_21 (cached_8259[1])
24 static __cacheline_aligned_in_smp
DEFINE_SPINLOCK(i8259_lock
);
26 static int i8259_pic_irq_offset
;
27 static int i8259_present
;
29 int i8259_irq(int cpu
)
33 spin_lock
/*_irqsave*/(&i8259_lock
/*, flags*/);
35 * Perform an interrupt acknowledge cycle on controller 1
42 * Interrupt is cascaded so perform interrupt
43 * acknowledge on controller 2
46 irq
= (inb(0xA0) & 7) + 8;
51 * This may be a spurious interrupt
53 * Read the interrupt status register. If the most
54 * significant bit is not set then there is no valid
59 spin_unlock
/*_irqrestore*/(&i8259_lock
/*, flags*/);
63 spin_unlock
/*_irqrestore*/(&i8259_lock
/*, flags*/);
67 static void i8259_mask_and_ack_irq(unsigned int irq_nr
)
71 spin_lock_irqsave(&i8259_lock
, flags
);
72 if ( irq_nr
>= i8259_pic_irq_offset
)
73 irq_nr
-= i8259_pic_irq_offset
;
76 cached_A1
|= 1 << (irq_nr
-8);
77 inb(0xA1); /* DUMMY */
79 outb(0x20,0xA0); /* Non-specific EOI */
80 outb(0x20,0x20); /* Non-specific EOI to cascade */
82 cached_21
|= 1 << irq_nr
;
83 inb(0x21); /* DUMMY */
85 outb(0x20,0x20); /* Non-specific EOI */
87 spin_unlock_irqrestore(&i8259_lock
, flags
);
90 static void i8259_set_irq_mask(int irq_nr
)
96 static void i8259_mask_irq(unsigned int irq_nr
)
100 spin_lock_irqsave(&i8259_lock
, flags
);
101 if ( irq_nr
>= i8259_pic_irq_offset
)
102 irq_nr
-= i8259_pic_irq_offset
;
104 cached_21
|= 1 << irq_nr
;
106 cached_A1
|= 1 << (irq_nr
-8);
107 i8259_set_irq_mask(irq_nr
);
108 spin_unlock_irqrestore(&i8259_lock
, flags
);
111 static void i8259_unmask_irq(unsigned int irq_nr
)
115 spin_lock_irqsave(&i8259_lock
, flags
);
116 if ( irq_nr
>= i8259_pic_irq_offset
)
117 irq_nr
-= i8259_pic_irq_offset
;
119 cached_21
&= ~(1 << irq_nr
);
121 cached_A1
&= ~(1 << (irq_nr
-8));
122 i8259_set_irq_mask(irq_nr
);
123 spin_unlock_irqrestore(&i8259_lock
, flags
);
126 static void i8259_end_irq(unsigned int irq
)
128 if (!(get_irq_desc(irq
)->status
& (IRQ_DISABLED
|IRQ_INPROGRESS
)) &&
129 get_irq_desc(irq
)->action
)
130 i8259_unmask_irq(irq
);
133 struct hw_interrupt_type i8259_pic
= {
134 .typename
= " i8259 ",
135 .enable
= i8259_unmask_irq
,
136 .disable
= i8259_mask_irq
,
137 .ack
= i8259_mask_and_ack_irq
,
138 .end
= i8259_end_irq
,
141 void __init
i8259_init(int offset
)
145 spin_lock_irqsave(&i8259_lock
, flags
);
146 i8259_pic_irq_offset
= offset
;
148 /* init master interrupt controller */
149 outb(0x11, 0x20); /* Start init sequence */
150 outb(0x00, 0x21); /* Vector base */
151 outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
152 outb(0x01, 0x21); /* Select 8086 mode */
153 outb(0xFF, 0x21); /* Mask all */
154 /* init slave interrupt controller */
155 outb(0x11, 0xA0); /* Start init sequence */
156 outb(0x08, 0xA1); /* Vector base */
157 outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
158 outb(0x01, 0xA1); /* Select 8086 mode */
159 outb(0xFF, 0xA1); /* Mask all */
160 outb(cached_A1
, 0xA1);
161 outb(cached_21
, 0x21);
162 spin_unlock_irqrestore(&i8259_lock
, flags
);
166 static int i8259_request_cascade(void)
171 request_irq( i8259_pic_irq_offset
+ 2, no_action
, SA_INTERRUPT
,
172 "82c59 secondary cascade", NULL
);
177 arch_initcall(i8259_request_cascade
);