[NETLINK]: w1_int.c: fix default netlink group
[linux-2.6/verdex.git] / arch / ppc64 / kernel / i8259.c
blob74dcfd68fc75cc6f509dbc4f92179305e7f3df64
1 /*
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.
8 */
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>
16 #include <asm/io.h>
17 #include <asm/ppcdebug.h>
18 #include "i8259.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)
31 int irq;
33 spin_lock/*_irqsave*/(&i8259_lock/*, flags*/);
35 * Perform an interrupt acknowledge cycle on controller 1
36 */
37 outb(0x0C, 0x20);
38 irq = inb(0x20) & 7;
39 if (irq == 2)
41 /*
42 * Interrupt is cascaded so perform interrupt
43 * acknowledge on controller 2
45 outb(0x0C, 0xA0);
46 irq = (inb(0xA0) & 7) + 8;
48 else if (irq==7)
50 /*
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
55 * interrupt
57 outb(0x0b, 0x20);
58 if(~inb(0x20)&0x80) {
59 spin_unlock/*_irqrestore*/(&i8259_lock/*, flags*/);
60 return -1;
63 spin_unlock/*_irqrestore*/(&i8259_lock/*, flags*/);
64 return irq;
67 static void i8259_mask_and_ack_irq(unsigned int irq_nr)
69 unsigned long flags;
71 spin_lock_irqsave(&i8259_lock, flags);
72 if ( irq_nr >= i8259_pic_irq_offset )
73 irq_nr -= i8259_pic_irq_offset;
75 if (irq_nr > 7) {
76 cached_A1 |= 1 << (irq_nr-8);
77 inb(0xA1); /* DUMMY */
78 outb(cached_A1,0xA1);
79 outb(0x20,0xA0); /* Non-specific EOI */
80 outb(0x20,0x20); /* Non-specific EOI to cascade */
81 } else {
82 cached_21 |= 1 << irq_nr;
83 inb(0x21); /* DUMMY */
84 outb(cached_21,0x21);
85 outb(0x20,0x20); /* Non-specific EOI */
87 spin_unlock_irqrestore(&i8259_lock, flags);
90 static void i8259_set_irq_mask(int irq_nr)
92 outb(cached_A1,0xA1);
93 outb(cached_21,0x21);
96 static void i8259_mask_irq(unsigned int irq_nr)
98 unsigned long flags;
100 spin_lock_irqsave(&i8259_lock, flags);
101 if ( irq_nr >= i8259_pic_irq_offset )
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);
111 static void i8259_unmask_irq(unsigned int irq_nr)
113 unsigned long flags;
115 spin_lock_irqsave(&i8259_lock, flags);
116 if ( irq_nr >= i8259_pic_irq_offset )
117 irq_nr -= i8259_pic_irq_offset;
118 if ( irq_nr < 8 )
119 cached_21 &= ~(1 << irq_nr);
120 else
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)
143 unsigned long flags;
145 spin_lock_irqsave(&i8259_lock, flags);
146 i8259_pic_irq_offset = offset;
147 i8259_present = 1;
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)
168 if (!i8259_present)
169 return -ENODEV;
171 request_irq( i8259_pic_irq_offset + 2, no_action, SA_INTERRUPT,
172 "82c59 secondary cascade", NULL );
174 return 0;
177 arch_initcall(i8259_request_cascade);