[POWERPC] Fix warning on UP
[linux-ginger.git] / arch / i386 / mach-visws / visws_apic.c
blob710faf71a650b11a991cdbc034cb21e31f0a98f1
1 /*
2 * linux/arch/i386/mach-visws/visws_apic.c
4 * Copyright (C) 1999 Bent Hagemark, Ingo Molnar
6 * SGI Visual Workstation interrupt controller
8 * The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
9 * which serves as the main interrupt controller in the system. Non-legacy
10 * hardware in the system uses this controller directly. Legacy devices
11 * are connected to the PIIX4 which in turn has its 8259(s) connected to
12 * a of the Cobalt APIC entry.
14 * 09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
16 * 25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
19 #include <linux/kernel_stat.h>
20 #include <linux/interrupt.h>
21 #include <linux/init.h>
23 #include <asm/io.h>
24 #include <asm/apic.h>
25 #include <asm/i8259.h>
27 #include "cobalt.h"
28 #include "irq_vectors.h"
31 static DEFINE_SPINLOCK(cobalt_lock);
34 * Set the given Cobalt APIC Redirection Table entry to point
35 * to the given IDT vector/index.
37 static inline void co_apic_set(int entry, int irq)
39 co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
40 co_apic_write(CO_APIC_HI(entry), 0);
44 * Cobalt (IO)-APIC functions to handle PCI devices.
46 static inline int co_apic_ide0_hack(void)
48 extern char visws_board_type;
49 extern char visws_board_rev;
51 if (visws_board_type == VISWS_320 && visws_board_rev == 5)
52 return 5;
53 return CO_APIC_IDE0;
56 static int is_co_apic(unsigned int irq)
58 if (IS_CO_APIC(irq))
59 return CO_APIC(irq);
61 switch (irq) {
62 case 0: return CO_APIC_CPU;
63 case CO_IRQ_IDE0: return co_apic_ide0_hack();
64 case CO_IRQ_IDE1: return CO_APIC_IDE1;
65 default: return -1;
71 * This is the SGI Cobalt (IO-)APIC:
74 static void enable_cobalt_irq(unsigned int irq)
76 co_apic_set(is_co_apic(irq), irq);
79 static void disable_cobalt_irq(unsigned int irq)
81 int entry = is_co_apic(irq);
83 co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
84 co_apic_read(CO_APIC_LO(entry));
88 * "irq" really just serves to identify the device. Here is where we
89 * map this to the Cobalt APIC entry where it's physically wired.
90 * This is called via request_irq -> setup_irq -> irq_desc->startup()
92 static unsigned int startup_cobalt_irq(unsigned int irq)
94 unsigned long flags;
96 spin_lock_irqsave(&cobalt_lock, flags);
97 if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
98 irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
99 enable_cobalt_irq(irq);
100 spin_unlock_irqrestore(&cobalt_lock, flags);
101 return 0;
104 static void ack_cobalt_irq(unsigned int irq)
106 unsigned long flags;
108 spin_lock_irqsave(&cobalt_lock, flags);
109 disable_cobalt_irq(irq);
110 apic_write(APIC_EOI, APIC_EIO_ACK);
111 spin_unlock_irqrestore(&cobalt_lock, flags);
114 static void end_cobalt_irq(unsigned int irq)
116 unsigned long flags;
118 spin_lock_irqsave(&cobalt_lock, flags);
119 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
120 enable_cobalt_irq(irq);
121 spin_unlock_irqrestore(&cobalt_lock, flags);
124 static struct irq_chip cobalt_irq_type = {
125 .typename = "Cobalt-APIC",
126 .startup = startup_cobalt_irq,
127 .shutdown = disable_cobalt_irq,
128 .enable = enable_cobalt_irq,
129 .disable = disable_cobalt_irq,
130 .ack = ack_cobalt_irq,
131 .end = end_cobalt_irq,
136 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
137 * -- not the manner expected by the code in i8259.c.
139 * there is a 'master' physical interrupt source that gets sent to
140 * the CPU. But in the chipset there are various 'virtual' interrupts
141 * waiting to be handled. We represent this to Linux through a 'master'
142 * interrupt controller type, and through a special virtual interrupt-
143 * controller. Device drivers only see the virtual interrupt sources.
145 static unsigned int startup_piix4_master_irq(unsigned int irq)
147 init_8259A(0);
149 return startup_cobalt_irq(irq);
152 static void end_piix4_master_irq(unsigned int irq)
154 unsigned long flags;
156 spin_lock_irqsave(&cobalt_lock, flags);
157 enable_cobalt_irq(irq);
158 spin_unlock_irqrestore(&cobalt_lock, flags);
161 static struct irq_chip piix4_master_irq_type = {
162 .typename = "PIIX4-master",
163 .startup = startup_piix4_master_irq,
164 .ack = ack_cobalt_irq,
165 .end = end_piix4_master_irq,
169 static struct irq_chip piix4_virtual_irq_type = {
170 .typename = "PIIX4-virtual",
171 .shutdown = disable_8259A_irq,
172 .enable = enable_8259A_irq,
173 .disable = disable_8259A_irq,
178 * PIIX4-8259 master/virtual functions to handle interrupt requests
179 * from legacy devices: floppy, parallel, serial, rtc.
181 * None of these get Cobalt APIC entries, neither do they have IDT
182 * entries. These interrupts are purely virtual and distributed from
183 * the 'master' interrupt source: CO_IRQ_8259.
185 * When the 8259 interrupts its handler figures out which of these
186 * devices is interrupting and dispatches to its handler.
188 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
189 * enable_irq gets the right irq. This 'master' irq is never directly
190 * manipulated by any driver.
192 static irqreturn_t piix4_master_intr(int irq, void *dev_id)
194 int realirq;
195 irq_desc_t *desc;
196 unsigned long flags;
198 spin_lock_irqsave(&i8259A_lock, flags);
200 /* Find out what's interrupting in the PIIX4 master 8259 */
201 outb(0x0c, 0x20); /* OCW3 Poll command */
202 realirq = inb(0x20);
205 * Bit 7 == 0 means invalid/spurious
207 if (unlikely(!(realirq & 0x80)))
208 goto out_unlock;
210 realirq &= 7;
212 if (unlikely(realirq == 2)) {
213 outb(0x0c, 0xa0);
214 realirq = inb(0xa0);
216 if (unlikely(!(realirq & 0x80)))
217 goto out_unlock;
219 realirq = (realirq & 7) + 8;
222 /* mask and ack interrupt */
223 cached_irq_mask |= 1 << realirq;
224 if (unlikely(realirq > 7)) {
225 inb(0xa1);
226 outb(cached_slave_mask, 0xa1);
227 outb(0x60 + (realirq & 7), 0xa0);
228 outb(0x60 + 2, 0x20);
229 } else {
230 inb(0x21);
231 outb(cached_master_mask, 0x21);
232 outb(0x60 + realirq, 0x20);
235 spin_unlock_irqrestore(&i8259A_lock, flags);
237 desc = irq_desc + realirq;
240 * handle this 'virtual interrupt' as a Cobalt one now.
242 kstat_cpu(smp_processor_id()).irqs[realirq]++;
244 if (likely(desc->action != NULL))
245 handle_IRQ_event(realirq, desc->action);
247 if (!(desc->status & IRQ_DISABLED))
248 enable_8259A_irq(realirq);
250 return IRQ_HANDLED;
252 out_unlock:
253 spin_unlock_irqrestore(&i8259A_lock, flags);
254 return IRQ_NONE;
257 static struct irqaction master_action = {
258 .handler = piix4_master_intr,
259 .name = "PIIX4-8259",
262 static struct irqaction cascade_action = {
263 .handler = no_action,
264 .name = "cascade",
268 void init_VISWS_APIC_irqs(void)
270 int i;
272 for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
273 irq_desc[i].status = IRQ_DISABLED;
274 irq_desc[i].action = 0;
275 irq_desc[i].depth = 1;
277 if (i == 0) {
278 irq_desc[i].chip = &cobalt_irq_type;
280 else if (i == CO_IRQ_IDE0) {
281 irq_desc[i].chip = &cobalt_irq_type;
283 else if (i == CO_IRQ_IDE1) {
284 irq_desc[i].chip = &cobalt_irq_type;
286 else if (i == CO_IRQ_8259) {
287 irq_desc[i].chip = &piix4_master_irq_type;
289 else if (i < CO_IRQ_APIC0) {
290 irq_desc[i].chip = &piix4_virtual_irq_type;
292 else if (IS_CO_APIC(i)) {
293 irq_desc[i].chip = &cobalt_irq_type;
297 setup_irq(CO_IRQ_8259, &master_action);
298 setup_irq(2, &cascade_action);