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>
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 struct hw_interrupt_type cobalt_irq_type
= {
105 * Not an initfunc, needed by the reboot code
107 void init_pic_mode(void)
113 * Cobalt (IO)-APIC functions to handle PCI devices.
116 static void disable_cobalt_irq(unsigned int irq
)
118 /* XXX undo the APIC entry here? */
121 * definitely, we do not want to have IRQ storms from
122 * unused devices --mingo
126 static void enable_cobalt_irq(unsigned int irq
)
131 * Set the given Cobalt APIC Redirection Table entry to point
132 * to the given IDT vector/index.
134 static void co_apic_set(int entry
, int idtvec
)
136 co_apic_write(CO_APIC_LO(entry
), CO_APIC_LEVEL
| (CO_IRQ_BASE
+idtvec
));
137 co_apic_write(CO_APIC_HI(entry
), 0);
139 printk("Cobalt APIC Entry %d IDT Vector %d\n", entry
, idtvec
);
143 * "irq" really just serves to identify the device. Here is where we
144 * map this to the Cobalt APIC entry where it's physically wired.
145 * This is called via request_irq -> setup_x86_irq -> irq_desc->startup()
147 static void startup_cobalt_irq(unsigned int irq
)
150 * These "irq"'s are wired to the same Cobalt APIC entries
151 * for all (known) motherboard types/revs
154 case CO_IRQ_TIMER
: co_apic_set(CO_APIC_CPU
, CO_IRQ_TIMER
);
157 case CO_IRQ_ENET
: co_apic_set(CO_APIC_ENET
, CO_IRQ_ENET
);
160 case CO_IRQ_SERIAL
: return; /* XXX move to piix4-8259 "virtual" */
162 case CO_IRQ_8259
: co_apic_set(CO_APIC_8259
, CO_IRQ_8259
);
166 switch (visws_board_type
) {
168 switch (visws_board_rev
) {
170 co_apic_set(CO_APIC_0_5_IDE0
, CO_IRQ_IDE
);
171 co_apic_set(CO_APIC_0_5_IDE1
, CO_IRQ_IDE
);
174 co_apic_set(CO_APIC_0_6_IDE0
, CO_IRQ_IDE
);
175 co_apic_set(CO_APIC_0_6_IDE1
, CO_IRQ_IDE
);
179 switch (visws_board_rev
) {
181 co_apic_set(CO_APIC_1_2_IDE0
, CO_IRQ_IDE
);
192 * This is the handle() op in do_IRQ()
194 static void do_cobalt_IRQ(unsigned int irq
, struct pt_regs
* regs
)
196 struct irqaction
* action
;
197 irq_desc_t
*desc
= irq_desc
+ irq
;
199 spin_lock(&irq_controller_lock
);
203 status
= desc
->status
& ~(IRQ_REPLAY
| IRQ_WAITING
);
205 if (!(status
& (IRQ_DISABLED
| IRQ_INPROGRESS
))) {
206 action
= desc
->action
;
207 status
|= IRQ_INPROGRESS
;
209 desc
->status
= status
;
211 spin_unlock(&irq_controller_lock
);
213 /* Exit early if we had no action or it was disabled */
217 handle_IRQ_event(irq
, regs
, action
);
219 (void)co_cpu_read(CO_CPU_REV
); /* Sync driver ack to its h/w */
220 apic_write(APIC_EOI
, APIC_EIO_ACK
); /* Send EOI to Cobalt APIC */
222 spin_lock(&irq_controller_lock
);
224 unsigned int status
= desc
->status
& ~IRQ_INPROGRESS
;
225 desc
->status
= status
;
226 if (!(status
& IRQ_DISABLED
))
227 enable_cobalt_irq(irq
);
229 spin_unlock(&irq_controller_lock
);
233 * PIIX4-8259 master/virtual functions to handle:
240 * None of these get Cobalt APIC entries, neither do they have IDT
241 * entries. These interrupts are purely virtual and distributed from
242 * the 'master' interrupt source: CO_IRQ_8259.
244 * When the 8259 interrupts its handler figures out which of these
245 * devices is interrupting and dispatches to it's handler.
247 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
248 * enable_irq gets the right irq. This 'master' irq is never directly
249 * manipulated by any driver.
252 static void startup_piix4_master_irq(unsigned int irq
)
270 /* OCW1 - disable all interrupts in both 8259's */
274 startup_cobalt_irq(irq
);
277 static void shutdown_piix4_master_irq(unsigned int irq
)
280 * [we skip the 8259 magic here, not strictly necessary]
283 shutdown_cobalt_irq(irq
);
286 static void do_piix4_master_IRQ(unsigned int irq
, struct pt_regs
* regs
)
290 /* Find out what's interrupting in the PIIX4 8259 */
292 spin_lock(&irq_controller_lock
);
293 outb(0x0c, 0x20); /* OCW3 Poll command */
296 if (!(realirq
& 0x80)) {
298 * Bit 7 == 0 means invalid/spurious
305 * mask and ack the 8259
308 if ((mask
>> realirq
) & 0x01)
310 * This IRQ is masked... ignore
314 outb(mask
| (1<<realirq
), 0x21);
316 * OCW2 - non-specific EOI
320 spin_unlock(&irq_controller_lock
);
323 * handle this 'virtual interrupt' as a Cobalt one now.
325 kstat
.irqs
[smp_processor_id()][irq
]++;
326 do_cobalt_IRQ(realirq
, regs
);
328 spin_lock(&irq_controller_lock
);
330 irq_desc_t
*desc
= irq_desc
+ realirq
;
332 if (!(desc
->status
& IRQ_DISABLED
))
333 enable_piix4_virtual_irq(realirq
);
335 spin_unlock(&irq_controller_lock
);
339 spin_unlock(&irq_controller_lock
);
343 static void enable_piix4_virtual_irq(unsigned int irq
)
346 * assumes this irq is one of the legacy devices
349 unsigned int mask
= inb(0x21);
352 enable_cobalt_irq(irq
);
356 * assumes this irq is one of the legacy devices
358 static void disable_piix4_virtual_irq(unsigned int irq
)
362 disable_cobalt_irq(irq
);
369 static struct irqaction master_action
=
370 { no_action
, 0, 0, "PIIX4-8259", NULL
, NULL
};
372 void init_VISWS_APIC_irqs(void)
376 for (i
= 0; i
< 16; i
++) {
377 irq_desc
[i
].status
= IRQ_DISABLED
;
378 irq_desc
[i
].action
= 0;
379 irq_desc
[i
].depth
= 0;
382 * Cobalt IRQs are mapped to standard ISA
387 * Only CO_IRQ_8259 will be raised
391 irq_desc
[i
].handler
= &piix4_master_irq_type
;
395 irq_desc
[i
].handler
= &piix4_virtual_irq_type
;
398 irq_desc
[i
].handler
= &cobalt_irq_type
;
404 * The master interrupt is always present:
406 setup_x86_irq(CO_IRQ_8259
, &master_action
);