2 * Copyright (C) 1999 Bent Hagemark, Ingo Molnar
4 * SGI Visual Workstation interrupt controller
6 * The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
7 * which serves as the main interrupt controller in the system. Non-legacy
8 * hardware in the system uses this controller directly. Legacy devices
9 * are connected to the PIIX4 which in turn has its 8259(s) connected to
10 * a of the Cobalt APIC entry.
12 * 09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
14 * 25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
17 #include <linux/kernel_stat.h>
18 #include <linux/interrupt.h>
19 #include <linux/init.h>
23 #include <asm/i8259.h>
24 #include <asm/irq_vectors.h>
28 static DEFINE_SPINLOCK(cobalt_lock);
31 * Set the given Cobalt APIC Redirection Table entry to point
32 * to the given IDT vector/index.
34 static inline void co_apic_set(int entry, int irq)
36 co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
37 co_apic_write(CO_APIC_HI(entry), 0);
41 * Cobalt (IO)-APIC functions to handle PCI devices.
43 static inline int co_apic_ide0_hack(void)
45 extern char visws_board_type;
46 extern char visws_board_rev;
48 if (visws_board_type == VISWS_320 && visws_board_rev == 5)
53 static int is_co_apic(unsigned int irq)
59 case 0: return CO_APIC_CPU;
60 case CO_IRQ_IDE0: return co_apic_ide0_hack();
61 case CO_IRQ_IDE1: return CO_APIC_IDE1;
68 * This is the SGI Cobalt (IO-)APIC:
71 static void enable_cobalt_irq(unsigned int irq)
73 co_apic_set(is_co_apic(irq), irq);
76 static void disable_cobalt_irq(unsigned int irq)
78 int entry = is_co_apic(irq);
80 co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
81 co_apic_read(CO_APIC_LO(entry));
85 * "irq" really just serves to identify the device. Here is where we
86 * map this to the Cobalt APIC entry where it's physically wired.
87 * This is called via request_irq -> setup_irq -> irq_desc->startup()
89 static unsigned int startup_cobalt_irq(unsigned int irq)
93 spin_lock_irqsave(&cobalt_lock, flags);
94 if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
95 irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
96 enable_cobalt_irq(irq);
97 spin_unlock_irqrestore(&cobalt_lock, flags);
101 static void ack_cobalt_irq(unsigned int irq)
105 spin_lock_irqsave(&cobalt_lock, flags);
106 disable_cobalt_irq(irq);
107 apic_write(APIC_EOI, APIC_EIO_ACK);
108 spin_unlock_irqrestore(&cobalt_lock, flags);
111 static void end_cobalt_irq(unsigned int irq)
115 spin_lock_irqsave(&cobalt_lock, flags);
116 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
117 enable_cobalt_irq(irq);
118 spin_unlock_irqrestore(&cobalt_lock, flags);
121 static struct irq_chip cobalt_irq_type = {
122 .typename = "Cobalt-APIC",
123 .startup = startup_cobalt_irq,
124 .shutdown = disable_cobalt_irq,
125 .enable = enable_cobalt_irq,
126 .disable = disable_cobalt_irq,
127 .ack = ack_cobalt_irq,
128 .end = end_cobalt_irq,
133 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
134 * -- not the manner expected by the code in i8259.c.
136 * there is a 'master' physical interrupt source that gets sent to
137 * the CPU. But in the chipset there are various 'virtual' interrupts
138 * waiting to be handled. We represent this to Linux through a 'master'
139 * interrupt controller type, and through a special virtual interrupt-
140 * controller. Device drivers only see the virtual interrupt sources.
142 static unsigned int startup_piix4_master_irq(unsigned int irq)
146 return startup_cobalt_irq(irq);
149 static void end_piix4_master_irq(unsigned int irq)
153 spin_lock_irqsave(&cobalt_lock, flags);
154 enable_cobalt_irq(irq);
155 spin_unlock_irqrestore(&cobalt_lock, flags);
158 static struct irq_chip piix4_master_irq_type = {
159 .typename = "PIIX4-master",
160 .startup = startup_piix4_master_irq,
161 .ack = ack_cobalt_irq,
162 .end = end_piix4_master_irq,
166 static struct irq_chip piix4_virtual_irq_type = {
167 .typename = "PIIX4-virtual",
168 .shutdown = disable_8259A_irq,
169 .enable = enable_8259A_irq,
170 .disable = disable_8259A_irq,
175 * PIIX4-8259 master/virtual functions to handle interrupt requests
176 * from legacy devices: floppy, parallel, serial, rtc.
178 * None of these get Cobalt APIC entries, neither do they have IDT
179 * entries. These interrupts are purely virtual and distributed from
180 * the 'master' interrupt source: CO_IRQ_8259.
182 * When the 8259 interrupts its handler figures out which of these
183 * devices is interrupting and dispatches to its handler.
185 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
186 * enable_irq gets the right irq. This 'master' irq is never directly
187 * manipulated by any driver.
189 static irqreturn_t piix4_master_intr(int irq, void *dev_id)
195 spin_lock_irqsave(&i8259A_lock, flags);
197 /* Find out what's interrupting in the PIIX4 master 8259 */
198 outb(0x0c, 0x20); /* OCW3 Poll command */
202 * Bit 7 == 0 means invalid/spurious
204 if (unlikely(!(realirq & 0x80)))
209 if (unlikely(realirq == 2)) {
213 if (unlikely(!(realirq & 0x80)))
216 realirq = (realirq & 7) + 8;
219 /* mask and ack interrupt */
220 cached_irq_mask |= 1 << realirq;
221 if (unlikely(realirq > 7)) {
223 outb(cached_slave_mask, 0xa1);
224 outb(0x60 + (realirq & 7), 0xa0);
225 outb(0x60 + 2, 0x20);
228 outb(cached_master_mask, 0x21);
229 outb(0x60 + realirq, 0x20);
232 spin_unlock_irqrestore(&i8259A_lock, flags);
234 desc = irq_desc + realirq;
237 * handle this 'virtual interrupt' as a Cobalt one now.
239 kstat_cpu(smp_processor_id()).irqs[realirq]++;
241 if (likely(desc->action != NULL))
242 handle_IRQ_event(realirq, desc->action);
244 if (!(desc->status & IRQ_DISABLED))
245 enable_8259A_irq(realirq);
250 spin_unlock_irqrestore(&i8259A_lock, flags);
254 static struct irqaction master_action = {
255 .handler = piix4_master_intr,
256 .name = "PIIX4-8259",
259 static struct irqaction cascade_action = {
260 .handler = no_action,
265 void init_VISWS_APIC_irqs(void)
269 for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
270 irq_desc[i].status = IRQ_DISABLED;
271 irq_desc[i].action = 0;
272 irq_desc[i].depth = 1;
275 irq_desc[i].chip = &cobalt_irq_type;
277 else if (i == CO_IRQ_IDE0) {
278 irq_desc[i].chip = &cobalt_irq_type;
280 else if (i == CO_IRQ_IDE1) {
281 irq_desc[i].chip = &cobalt_irq_type;
283 else if (i == CO_IRQ_8259) {
284 irq_desc[i].chip = &piix4_master_irq_type;
286 else if (i < CO_IRQ_APIC0) {
287 irq_desc[i].chip = &piix4_virtual_irq_type;
289 else if (IS_CO_APIC(i)) {
290 irq_desc[i].chip = &cobalt_irq_type;
294 setup_irq(CO_IRQ_8259, &master_action);
295 setup_irq(2, &cascade_action);