2 * linux/arch/i386/kernel/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.
15 #include <linux/ptrace.h>
16 #include <linux/errno.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/signal.h>
19 #include <linux/sched.h>
20 #include <linux/ioport.h>
21 #include <linux/interrupt.h>
22 #include <linux/timex.h>
23 #include <linux/malloc.h>
24 #include <linux/random.h>
25 #include <linux/smp.h>
26 #include <linux/smp_lock.h>
27 #include <linux/init.h>
29 #include <asm/system.h>
32 #include <asm/bitops.h>
34 #include <asm/pgtable.h>
35 #include <asm/delay.h>
38 #include <asm/cobalt.h>
40 #include <linux/irq.h>
43 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
44 * -- not the manner expected by the normal 8259 code in irq.c.
46 * there is a 'master' physical interrupt source that gets sent to
47 * the CPU. But in the chipset there are various 'virtual' interrupts
48 * waiting to be handled. We represent this to Linux through a 'master'
49 * interrupt controller type, and through a special virtual interrupt-
50 * controller. Device drivers only see the virtual interrupt sources.
53 #define CO_IRQ_BASE 0x20 /* This is the 0x20 in init_IRQ()! */
55 static void startup_piix4_master_irq(unsigned int irq
);
56 static void shutdown_piix4_master_irq(unsigned int irq
);
57 static void do_piix4_master_IRQ(unsigned int irq
, struct pt_regs
* regs
);
58 #define enable_piix4_master_irq startup_piix4_master_irq
59 #define disable_piix4_master_irq shutdown_piix4_master_irq
61 static struct hw_interrupt_type piix4_master_irq_type
= {
63 startup_piix4_master_irq
,
64 shutdown_piix4_master_irq
,
66 enable_piix4_master_irq
,
67 disable_piix4_master_irq
70 static void enable_piix4_virtual_irq(unsigned int irq
);
71 static void disable_piix4_virtual_irq(unsigned int irq
);
72 #define startup_piix4_virtual_irq enable_piix4_virtual_irq
73 #define shutdown_piix4_virtual_irq disable_piix4_virtual_irq
75 static struct hw_interrupt_type piix4_virtual_irq_type
= {
77 startup_piix4_virtual_irq
,
78 shutdown_piix4_virtual_irq
,
79 0, /* no handler, it's never called physically */
80 enable_piix4_virtual_irq
,
81 disable_piix4_virtual_irq
85 * This is the SGI Cobalt (IO-)APIC:
88 static void do_cobalt_IRQ(unsigned int irq
, struct pt_regs
* regs
);
89 static void enable_cobalt_irq(unsigned int irq
);
90 static void disable_cobalt_irq(unsigned int irq
);
91 static void startup_cobalt_irq(unsigned int irq
);
92 #define shutdown_cobalt_irq disable_cobalt_irq
94 static spinlock_t irq_controller_lock
= SPIN_LOCK_UNLOCKED
;
96 static struct hw_interrupt_type cobalt_irq_type
= {
107 * Not an __init, needed by the reboot code
109 void disable_IO_APIC(void)
115 * Cobalt (IO)-APIC functions to handle PCI devices.
118 static void disable_cobalt_irq(unsigned int irq
)
120 /* XXX undo the APIC entry here? */
123 * definitely, we do not want to have IRQ storms from
124 * unused devices --mingo
128 static void enable_cobalt_irq(unsigned int irq
)
133 * Set the given Cobalt APIC Redirection Table entry to point
134 * to the given IDT vector/index.
136 static void co_apic_set(int entry
, int idtvec
)
138 co_apic_write(CO_APIC_LO(entry
), CO_APIC_LEVEL
| (CO_IRQ_BASE
+idtvec
));
139 co_apic_write(CO_APIC_HI(entry
), 0);
141 printk("Cobalt APIC Entry %d IDT Vector %d\n", entry
, idtvec
);
145 * "irq" really just serves to identify the device. Here is where we
146 * map this to the Cobalt APIC entry where it's physically wired.
147 * This is called via request_irq -> setup_x86_irq -> irq_desc->startup()
149 static void startup_cobalt_irq(unsigned int irq
)
152 * These "irq"'s are wired to the same Cobalt APIC entries
153 * for all (known) motherboard types/revs
156 case CO_IRQ_TIMER
: co_apic_set(CO_APIC_CPU
, CO_IRQ_TIMER
);
159 case CO_IRQ_ENET
: co_apic_set(CO_APIC_ENET
, CO_IRQ_ENET
);
162 case CO_IRQ_SERIAL
: return; /* XXX move to piix4-8259 "virtual" */
164 case CO_IRQ_8259
: co_apic_set(CO_APIC_8259
, CO_IRQ_8259
);
168 switch (visws_board_type
) {
170 switch (visws_board_rev
) {
172 co_apic_set(CO_APIC_0_5_IDE0
, CO_IRQ_IDE
);
173 co_apic_set(CO_APIC_0_5_IDE1
, CO_IRQ_IDE
);
176 co_apic_set(CO_APIC_0_6_IDE0
, CO_IRQ_IDE
);
177 co_apic_set(CO_APIC_0_6_IDE1
, CO_IRQ_IDE
);
181 switch (visws_board_rev
) {
183 co_apic_set(CO_APIC_1_2_IDE0
, CO_IRQ_IDE
);
194 * This is the handle() op in do_IRQ()
196 static void do_cobalt_IRQ(unsigned int irq
, struct pt_regs
* regs
)
198 struct irqaction
* action
;
199 irq_desc_t
*desc
= irq_desc
+ irq
;
201 spin_lock(&irq_controller_lock
);
205 status
= desc
->status
& ~(IRQ_REPLAY
| IRQ_WAITING
);
207 if (!(status
& (IRQ_DISABLED
| IRQ_INPROGRESS
))) {
208 action
= desc
->action
;
209 status
|= IRQ_INPROGRESS
;
211 desc
->status
= status
;
213 spin_unlock(&irq_controller_lock
);
215 /* Exit early if we had no action or it was disabled */
219 handle_IRQ_event(irq
, regs
, action
);
221 (void)co_cpu_read(CO_CPU_REV
); /* Sync driver ack to its h/w */
222 apic_write(APIC_EOI
, APIC_EIO_ACK
); /* Send EOI to Cobalt APIC */
224 spin_lock(&irq_controller_lock
);
226 unsigned int status
= desc
->status
& ~IRQ_INPROGRESS
;
227 desc
->status
= status
;
228 if (!(status
& IRQ_DISABLED
))
229 enable_cobalt_irq(irq
);
231 spin_unlock(&irq_controller_lock
);
235 * PIIX4-8259 master/virtual functions to handle:
242 * None of these get Cobalt APIC entries, neither do they have IDT
243 * entries. These interrupts are purely virtual and distributed from
244 * the 'master' interrupt source: CO_IRQ_8259.
246 * When the 8259 interrupts its handler figures out which of these
247 * devices is interrupting and dispatches to it's handler.
249 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
250 * enable_irq gets the right irq. This 'master' irq is never directly
251 * manipulated by any driver.
254 static void startup_piix4_master_irq(unsigned int irq
)
272 /* OCW1 - disable all interrupts in both 8259's */
276 startup_cobalt_irq(irq
);
279 static void shutdown_piix4_master_irq(unsigned int irq
)
282 * [we skip the 8259 magic here, not strictly necessary]
285 shutdown_cobalt_irq(irq
);
288 static void do_piix4_master_IRQ(unsigned int irq
, struct pt_regs
* regs
)
292 /* Find out what's interrupting in the PIIX4 8259 */
294 spin_lock(&irq_controller_lock
);
295 outb(0x0c, 0x20); /* OCW3 Poll command */
298 if (!(realirq
& 0x80)) {
300 * Bit 7 == 0 means invalid/spurious
307 * mask and ack the 8259
310 if ((mask
>> realirq
) & 0x01)
312 * This IRQ is masked... ignore
316 outb(mask
| (1<<realirq
), 0x21);
318 * OCW2 - non-specific EOI
322 spin_unlock(&irq_controller_lock
);
325 * handle this 'virtual interrupt' as a Cobalt one now.
327 kstat
.irqs
[smp_processor_id()][irq
]++;
328 do_cobalt_IRQ(realirq
, regs
);
330 spin_lock(&irq_controller_lock
);
332 irq_desc_t
*desc
= irq_desc
+ realirq
;
334 if (!(desc
->status
& IRQ_DISABLED
))
335 enable_piix4_virtual_irq(realirq
);
337 spin_unlock(&irq_controller_lock
);
341 spin_unlock(&irq_controller_lock
);
345 static void enable_piix4_virtual_irq(unsigned int irq
)
348 * assumes this irq is one of the legacy devices
351 unsigned int mask
= inb(0x21);
354 enable_cobalt_irq(irq
);
358 * assumes this irq is one of the legacy devices
360 static void disable_piix4_virtual_irq(unsigned int irq
)
364 disable_cobalt_irq(irq
);
371 static struct irqaction master_action
=
372 { no_action
, 0, 0, "PIIX4-8259", NULL
, NULL
};
374 void init_VISWS_APIC_irqs(void)
378 for (i
= 0; i
< 16; i
++) {
379 irq_desc
[i
].status
= IRQ_DISABLED
;
380 irq_desc
[i
].action
= 0;
381 irq_desc
[i
].depth
= 1;
384 * Cobalt IRQs are mapped to standard ISA
389 * Only CO_IRQ_8259 will be raised
393 irq_desc
[i
].handler
= &piix4_master_irq_type
;
397 irq_desc
[i
].handler
= &piix4_virtual_irq_type
;
400 irq_desc
[i
].handler
= &cobalt_irq_type
;
406 * The master interrupt is always present:
408 setup_x86_irq(CO_IRQ_8259
, &master_action
);