blob: 3059eb45a9158c4d272c94a0af6fcc553c94e9ce [file] [log] [blame]
Ingo Molnar65253632008-07-10 15:50:37 +02001/*
Ingo Molnar26dd9fc2008-07-10 16:21:38 +02002 * SGI Visual Workstation support and quirks, unmaintained.
3 *
Ingo Molnar65253632008-07-10 15:50:37 +02004 * Split out from setup.c by davej@suse.de
Ingo Molnar26dd9fc2008-07-10 16:21:38 +02005 *
6 * Copyright (C) 1999 Bent Hagemark, Ingo Molnar
7 *
8 * SGI Visual Workstation interrupt controller
9 *
10 * The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
11 * which serves as the main interrupt controller in the system. Non-legacy
12 * hardware in the system uses this controller directly. Legacy devices
13 * are connected to the PIIX4 which in turn has its 8259(s) connected to
14 * a of the Cobalt APIC entry.
15 *
16 * 09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
17 *
18 * 25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
Ingo Molnar65253632008-07-10 15:50:37 +020019 */
Ingo Molnar65253632008-07-10 15:50:37 +020020#include <linux/interrupt.h>
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/smp.h>
24
25#include <asm/visws/cobalt.h>
26#include <asm/visws/piix4.h>
27#include <asm/arch_hooks.h>
Ingo Molnar3964cd32008-07-26 19:35:20 +020028#include <asm/io_apic.h>
Ingo Molnar65253632008-07-10 15:50:37 +020029#include <asm/fixmap.h>
30#include <asm/reboot.h>
31#include <asm/setup.h>
32#include <asm/e820.h>
Ingo Molnar65253632008-07-10 15:50:37 +020033#include <asm/io.h>
34
35#include <mach_ipi.h>
36
37#include "mach_apic.h"
38
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020039#include <linux/kernel_stat.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020040
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020041#include <asm/i8259.h>
42#include <asm/irq_vectors.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020043#include <asm/visws/lithium.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020044
45#include <linux/sched.h>
46#include <linux/kernel.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020047#include <linux/pci.h>
48#include <linux/pci_ids.h>
49
Ingo Molnarf78cb9b2008-07-10 19:39:55 +020050extern int no_broadcast;
51
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020052#include <asm/apic.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020053
Ingo Molnar65253632008-07-10 15:50:37 +020054char visws_board_type = -1;
55char visws_board_rev = -1;
56
57int is_visws_box(void)
58{
59 return visws_board_type >= 0;
60}
61
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070062static int __init visws_time_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020063{
64 printk(KERN_INFO "Starting Cobalt Timer system clock\n");
65
66 /* Set the countdown value */
67 co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
68
69 /* Start the timer */
70 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
71
72 /* Enable (unmask) the timer interrupt */
73 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
74
75 /*
76 * Zero return means the generic timer setup code will set up
77 * the standard vector:
78 */
79 return 0;
80}
81
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070082static int __init visws_pre_intr_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020083{
84 init_VISWS_APIC_irqs();
85
86 /*
87 * We dont want ISA irqs to be set up by the generic code:
88 */
89 return 1;
90}
91
92/* Quirk for machine specific memory setup. */
93
94#define MB (1024 * 1024)
95
96unsigned long sgivwfb_mem_phys;
97unsigned long sgivwfb_mem_size;
98EXPORT_SYMBOL(sgivwfb_mem_phys);
99EXPORT_SYMBOL(sgivwfb_mem_size);
100
101long long mem_size __initdata = 0;
102
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700103static char * __init visws_memory_setup(void)
Ingo Molnar65253632008-07-10 15:50:37 +0200104{
105 long long gfx_mem_size = 8 * MB;
106
107 mem_size = boot_params.alt_mem_k;
108
109 if (!mem_size) {
110 printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
111 mem_size = 128 * MB;
112 }
113
114 /*
115 * this hardcodes the graphics memory to 8 MB
116 * it really should be sized dynamically (or at least
117 * set as a boot param)
118 */
119 if (!sgivwfb_mem_size) {
120 printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
121 sgivwfb_mem_size = 8 * MB;
122 }
123
124 /*
125 * Trim to nearest MB
126 */
127 sgivwfb_mem_size &= ~((1 << 20) - 1);
128 sgivwfb_mem_phys = mem_size - gfx_mem_size;
129
130 e820_add_region(0, LOWMEMSIZE(), E820_RAM);
131 e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
132 e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
133
134 return "PROM";
135}
136
137static void visws_machine_emergency_restart(void)
138{
139 /*
140 * Visual Workstations restart after this
141 * register is poked on the PIIX4
142 */
143 outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
144}
145
146static void visws_machine_power_off(void)
147{
148 unsigned short pm_status;
149/* extern unsigned int pci_bus0; */
150
151 while ((pm_status = inw(PMSTS_PORT)) & 0x100)
152 outw(pm_status, PMSTS_PORT);
153
154 outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
155
156 mdelay(10);
157
158#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
159 (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
160
161/* outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
162 outl(PIIX_SPECIAL_STOP, 0xCFC);
163}
164
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700165static int __init visws_get_smp_config(unsigned int early)
Ingo Molnar65253632008-07-10 15:50:37 +0200166{
167 /*
168 * Prevent MP-table parsing by the generic code:
169 */
170 return 1;
171}
172
173extern unsigned int __cpuinitdata maxcpus;
174
175/*
176 * The Visual Workstation is Intel MP compliant in the hardware
177 * sense, but it doesn't have a BIOS(-configuration table).
178 * No problem for Linux.
179 */
180
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700181static void __init MP_processor_info(struct mpc_config_processor *m)
Ingo Molnar65253632008-07-10 15:50:37 +0200182{
183 int ver, logical_apicid;
184 physid_mask_t apic_cpus;
185
186 if (!(m->mpc_cpuflag & CPU_ENABLED))
187 return;
188
189 logical_apicid = m->mpc_apicid;
190 printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
191 m->mpc_cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
192 m->mpc_apicid,
193 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
194 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
195 m->mpc_apicver);
196
197 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR)
198 boot_cpu_physical_apicid = m->mpc_apicid;
199
200 ver = m->mpc_apicver;
201 if ((ver >= 0x14 && m->mpc_apicid >= 0xff) || m->mpc_apicid >= 0xf) {
202 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
203 m->mpc_apicid, MAX_APICS);
204 return;
205 }
206
207 apic_cpus = apicid_to_cpu_present(m->mpc_apicid);
208 physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
209 /*
210 * Validate version
211 */
212 if (ver == 0x0) {
213 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
214 "fixing up to 0x10. (tell your hw vendor)\n",
215 m->mpc_apicid);
216 ver = 0x10;
217 }
218 apic_version[m->mpc_apicid] = ver;
219}
220
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700221static int __init visws_find_smp_config(unsigned int reserve)
Ingo Molnar65253632008-07-10 15:50:37 +0200222{
223 struct mpc_config_processor *mp = phys_to_virt(CO_CPU_TAB_PHYS);
224 unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
225
226 if (ncpus > CO_CPU_MAX) {
227 printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
228 ncpus, mp);
229
230 ncpus = CO_CPU_MAX;
231 }
232
233 if (ncpus > maxcpus)
234 ncpus = maxcpus;
235
236#ifdef CONFIG_X86_LOCAL_APIC
237 smp_found_config = 1;
238#endif
239 while (ncpus--)
240 MP_processor_info(mp++);
241
242 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
243
244 return 1;
245}
246
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700247static int visws_trap_init(void);
248
249static struct x86_quirks visws_x86_quirks __initdata = {
250 .arch_time_init = visws_time_init,
251 .arch_pre_intr_init = visws_pre_intr_init,
252 .arch_memory_setup = visws_memory_setup,
253 .arch_intr_init = NULL,
254 .arch_trap_init = visws_trap_init,
255 .mach_get_smp_config = visws_get_smp_config,
256 .mach_find_smp_config = visws_find_smp_config,
257};
Ingo Molnar65253632008-07-10 15:50:37 +0200258
259void __init visws_early_detect(void)
260{
261 int raw;
262
263 visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
264 >> PIIX_GPI_BD_SHIFT;
265
266 if (visws_board_type < 0)
267 return;
268
269 /*
270 * Install special quirks for timer, interrupt and memory setup:
Ingo Molnar65253632008-07-10 15:50:37 +0200271 * Fall back to generic behavior for traps:
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700272 * Override generic MP-table parsing:
Ingo Molnar65253632008-07-10 15:50:37 +0200273 */
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700274 x86_quirks = &visws_x86_quirks;
Ingo Molnar65253632008-07-10 15:50:37 +0200275
276 /*
277 * Install reboot quirks:
278 */
279 pm_power_off = visws_machine_power_off;
280 machine_ops.emergency_restart = visws_machine_emergency_restart;
281
282 /*
283 * Do not use broadcast IPIs:
284 */
285 no_broadcast = 0;
286
Ingo Molnar54ce7f92008-07-10 16:14:56 +0200287#ifdef CONFIG_X86_IO_APIC
288 /*
289 * Turn off IO-APIC detection and initialization:
290 */
291 skip_ioapic_setup = 1;
292#endif
293
Ingo Molnar65253632008-07-10 15:50:37 +0200294 /*
295 * Get Board rev.
296 * First, we have to initialize the 307 part to allow us access
297 * to the GPIO registers. Let's map them at 0x0fc0 which is right
298 * after the PIIX4 PM section.
299 */
300 outb_p(SIO_DEV_SEL, SIO_INDEX);
301 outb_p(SIO_GP_DEV, SIO_DATA); /* Talk to GPIO regs. */
302
303 outb_p(SIO_DEV_MSB, SIO_INDEX);
304 outb_p(SIO_GP_MSB, SIO_DATA); /* MSB of GPIO base address */
305
306 outb_p(SIO_DEV_LSB, SIO_INDEX);
307 outb_p(SIO_GP_LSB, SIO_DATA); /* LSB of GPIO base address */
308
309 outb_p(SIO_DEV_ENB, SIO_INDEX);
310 outb_p(1, SIO_DATA); /* Enable GPIO registers. */
311
312 /*
313 * Now, we have to map the power management section to write
314 * a bit which enables access to the GPIO registers.
315 * What lunatic came up with this shit?
316 */
317 outb_p(SIO_DEV_SEL, SIO_INDEX);
318 outb_p(SIO_PM_DEV, SIO_DATA); /* Talk to GPIO regs. */
319
320 outb_p(SIO_DEV_MSB, SIO_INDEX);
321 outb_p(SIO_PM_MSB, SIO_DATA); /* MSB of PM base address */
322
323 outb_p(SIO_DEV_LSB, SIO_INDEX);
324 outb_p(SIO_PM_LSB, SIO_DATA); /* LSB of PM base address */
325
326 outb_p(SIO_DEV_ENB, SIO_INDEX);
327 outb_p(1, SIO_DATA); /* Enable PM registers. */
328
329 /*
330 * Now, write the PM register which enables the GPIO registers.
331 */
332 outb_p(SIO_PM_FER2, SIO_PM_INDEX);
333 outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
334
335 /*
336 * Now, initialize the GPIO registers.
337 * We want them all to be inputs which is the
338 * power on default, so let's leave them alone.
339 * So, let's just read the board rev!
340 */
341 raw = inb_p(SIO_GP_DATA1);
342 raw &= 0x7f; /* 7 bits of valid board revision ID. */
343
344 if (visws_board_type == VISWS_320) {
345 if (raw < 0x6) {
346 visws_board_rev = 4;
347 } else if (raw < 0xc) {
348 visws_board_rev = 5;
349 } else {
350 visws_board_rev = 6;
351 }
352 } else if (visws_board_type == VISWS_540) {
353 visws_board_rev = 2;
354 } else {
355 visws_board_rev = raw;
356 }
357
358 printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
359 (visws_board_type == VISWS_320 ? "320" :
360 (visws_board_type == VISWS_540 ? "540" :
361 "unknown")), visws_board_rev);
362}
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200363
364#define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
365#define BCD (LI_INTB | LI_INTC | LI_INTD)
366#define ALLDEVS (A01234 | BCD)
367
368static __init void lithium_init(void)
369{
370 set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
371 set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
372
373 if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
374 (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
375 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
376/* panic("This machine is not SGI Visual Workstation 320/540"); */
377 }
378
379 if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
380 (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
381 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
382/* panic("This machine is not SGI Visual Workstation 320/540"); */
383 }
384
385 li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
386 li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
387}
388
389static __init void cobalt_init(void)
390{
391 /*
392 * On normal SMP PC this is used only with SMP, but we have to
393 * use it and set it up here to start the Cobalt clock
394 */
395 set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
396 setup_local_APIC();
397 printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
398 (unsigned int)apic_read(APIC_LVR),
399 (unsigned int)apic_read(APIC_ID));
400
401 set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
402 set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
403 printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
404 co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
405
406 /* Enable Cobalt APIC being careful to NOT change the ID! */
407 co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
408
409 printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
410 co_apic_read(CO_APIC_ID));
411}
412
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700413static int __init visws_trap_init(void)
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200414{
415 lithium_init();
416 cobalt_init();
417
418 return 1;
419}
420
421/*
422 * IRQ controller / APIC support:
423 */
424
425static DEFINE_SPINLOCK(cobalt_lock);
426
427/*
428 * Set the given Cobalt APIC Redirection Table entry to point
429 * to the given IDT vector/index.
430 */
431static inline void co_apic_set(int entry, int irq)
432{
433 co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
434 co_apic_write(CO_APIC_HI(entry), 0);
435}
436
437/*
438 * Cobalt (IO)-APIC functions to handle PCI devices.
439 */
440static inline int co_apic_ide0_hack(void)
441{
442 extern char visws_board_type;
443 extern char visws_board_rev;
444
445 if (visws_board_type == VISWS_320 && visws_board_rev == 5)
446 return 5;
447 return CO_APIC_IDE0;
448}
449
450static int is_co_apic(unsigned int irq)
451{
452 if (IS_CO_APIC(irq))
453 return CO_APIC(irq);
454
455 switch (irq) {
456 case 0: return CO_APIC_CPU;
457 case CO_IRQ_IDE0: return co_apic_ide0_hack();
458 case CO_IRQ_IDE1: return CO_APIC_IDE1;
459 default: return -1;
460 }
461}
462
463
464/*
465 * This is the SGI Cobalt (IO-)APIC:
466 */
467
468static void enable_cobalt_irq(unsigned int irq)
469{
470 co_apic_set(is_co_apic(irq), irq);
471}
472
473static void disable_cobalt_irq(unsigned int irq)
474{
475 int entry = is_co_apic(irq);
476
477 co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
478 co_apic_read(CO_APIC_LO(entry));
479}
480
481/*
482 * "irq" really just serves to identify the device. Here is where we
483 * map this to the Cobalt APIC entry where it's physically wired.
484 * This is called via request_irq -> setup_irq -> irq_desc->startup()
485 */
486static unsigned int startup_cobalt_irq(unsigned int irq)
487{
488 unsigned long flags;
489
490 spin_lock_irqsave(&cobalt_lock, flags);
491 if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
492 irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
493 enable_cobalt_irq(irq);
494 spin_unlock_irqrestore(&cobalt_lock, flags);
495 return 0;
496}
497
498static void ack_cobalt_irq(unsigned int irq)
499{
500 unsigned long flags;
501
502 spin_lock_irqsave(&cobalt_lock, flags);
503 disable_cobalt_irq(irq);
504 apic_write(APIC_EOI, APIC_EIO_ACK);
505 spin_unlock_irqrestore(&cobalt_lock, flags);
506}
507
508static void end_cobalt_irq(unsigned int irq)
509{
510 unsigned long flags;
511
512 spin_lock_irqsave(&cobalt_lock, flags);
513 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
514 enable_cobalt_irq(irq);
515 spin_unlock_irqrestore(&cobalt_lock, flags);
516}
517
518static struct irq_chip cobalt_irq_type = {
519 .typename = "Cobalt-APIC",
520 .startup = startup_cobalt_irq,
521 .shutdown = disable_cobalt_irq,
522 .enable = enable_cobalt_irq,
523 .disable = disable_cobalt_irq,
524 .ack = ack_cobalt_irq,
525 .end = end_cobalt_irq,
526};
527
528
529/*
530 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
531 * -- not the manner expected by the code in i8259.c.
532 *
533 * there is a 'master' physical interrupt source that gets sent to
534 * the CPU. But in the chipset there are various 'virtual' interrupts
535 * waiting to be handled. We represent this to Linux through a 'master'
536 * interrupt controller type, and through a special virtual interrupt-
537 * controller. Device drivers only see the virtual interrupt sources.
538 */
539static unsigned int startup_piix4_master_irq(unsigned int irq)
540{
541 init_8259A(0);
542
543 return startup_cobalt_irq(irq);
544}
545
546static void end_piix4_master_irq(unsigned int irq)
547{
548 unsigned long flags;
549
550 spin_lock_irqsave(&cobalt_lock, flags);
551 enable_cobalt_irq(irq);
552 spin_unlock_irqrestore(&cobalt_lock, flags);
553}
554
555static struct irq_chip piix4_master_irq_type = {
556 .typename = "PIIX4-master",
557 .startup = startup_piix4_master_irq,
558 .ack = ack_cobalt_irq,
559 .end = end_piix4_master_irq,
560};
561
562
563static struct irq_chip piix4_virtual_irq_type = {
564 .typename = "PIIX4-virtual",
565 .shutdown = disable_8259A_irq,
566 .enable = enable_8259A_irq,
567 .disable = disable_8259A_irq,
568};
569
570
571/*
572 * PIIX4-8259 master/virtual functions to handle interrupt requests
573 * from legacy devices: floppy, parallel, serial, rtc.
574 *
575 * None of these get Cobalt APIC entries, neither do they have IDT
576 * entries. These interrupts are purely virtual and distributed from
577 * the 'master' interrupt source: CO_IRQ_8259.
578 *
579 * When the 8259 interrupts its handler figures out which of these
580 * devices is interrupting and dispatches to its handler.
581 *
582 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
583 * enable_irq gets the right irq. This 'master' irq is never directly
584 * manipulated by any driver.
585 */
586static irqreturn_t piix4_master_intr(int irq, void *dev_id)
587{
588 int realirq;
589 irq_desc_t *desc;
590 unsigned long flags;
591
592 spin_lock_irqsave(&i8259A_lock, flags);
593
594 /* Find out what's interrupting in the PIIX4 master 8259 */
595 outb(0x0c, 0x20); /* OCW3 Poll command */
596 realirq = inb(0x20);
597
598 /*
599 * Bit 7 == 0 means invalid/spurious
600 */
601 if (unlikely(!(realirq & 0x80)))
602 goto out_unlock;
603
604 realirq &= 7;
605
606 if (unlikely(realirq == 2)) {
607 outb(0x0c, 0xa0);
608 realirq = inb(0xa0);
609
610 if (unlikely(!(realirq & 0x80)))
611 goto out_unlock;
612
613 realirq = (realirq & 7) + 8;
614 }
615
616 /* mask and ack interrupt */
617 cached_irq_mask |= 1 << realirq;
618 if (unlikely(realirq > 7)) {
619 inb(0xa1);
620 outb(cached_slave_mask, 0xa1);
621 outb(0x60 + (realirq & 7), 0xa0);
622 outb(0x60 + 2, 0x20);
623 } else {
624 inb(0x21);
625 outb(cached_master_mask, 0x21);
626 outb(0x60 + realirq, 0x20);
627 }
628
629 spin_unlock_irqrestore(&i8259A_lock, flags);
630
631 desc = irq_desc + realirq;
632
633 /*
634 * handle this 'virtual interrupt' as a Cobalt one now.
635 */
636 kstat_cpu(smp_processor_id()).irqs[realirq]++;
637
638 if (likely(desc->action != NULL))
639 handle_IRQ_event(realirq, desc->action);
640
641 if (!(desc->status & IRQ_DISABLED))
642 enable_8259A_irq(realirq);
643
644 return IRQ_HANDLED;
645
646out_unlock:
647 spin_unlock_irqrestore(&i8259A_lock, flags);
648 return IRQ_NONE;
649}
650
651static struct irqaction master_action = {
652 .handler = piix4_master_intr,
653 .name = "PIIX4-8259",
654};
655
656static struct irqaction cascade_action = {
657 .handler = no_action,
658 .name = "cascade",
659};
660
661
662void init_VISWS_APIC_irqs(void)
663{
664 int i;
665
666 for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
667 irq_desc[i].status = IRQ_DISABLED;
668 irq_desc[i].action = 0;
669 irq_desc[i].depth = 1;
670
671 if (i == 0) {
672 irq_desc[i].chip = &cobalt_irq_type;
673 }
674 else if (i == CO_IRQ_IDE0) {
675 irq_desc[i].chip = &cobalt_irq_type;
676 }
677 else if (i == CO_IRQ_IDE1) {
678 irq_desc[i].chip = &cobalt_irq_type;
679 }
680 else if (i == CO_IRQ_8259) {
681 irq_desc[i].chip = &piix4_master_irq_type;
682 }
683 else if (i < CO_IRQ_APIC0) {
684 irq_desc[i].chip = &piix4_virtual_irq_type;
685 }
686 else if (IS_CO_APIC(i)) {
687 irq_desc[i].chip = &cobalt_irq_type;
688 }
689 }
690
691 setup_irq(CO_IRQ_8259, &master_action);
692 setup_irq(2, &cascade_action);
693}