blob: 31e828118f8e8d722cd58caa25681479ab69a486 [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>
Ingo Molnar3964cd32008-07-26 19:35:20 +020027#include <asm/io_apic.h>
Ingo Molnar65253632008-07-10 15:50:37 +020028#include <asm/fixmap.h>
29#include <asm/reboot.h>
30#include <asm/setup.h>
Ingo Molnare641f5f2009-02-17 14:02:01 +010031#include <asm/apic.h>
Ingo Molnar65253632008-07-10 15:50:37 +020032#include <asm/e820.h>
Ingo Molnar65253632008-07-10 15:50:37 +020033#include <asm/io.h>
34
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020035#include <linux/kernel_stat.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020036
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020037#include <asm/i8259.h>
38#include <asm/irq_vectors.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020039#include <asm/visws/lithium.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020040
41#include <linux/sched.h>
42#include <linux/kernel.h>
Ingo Molnar26dd9fc2008-07-10 16:21:38 +020043#include <linux/pci.h>
44#include <linux/pci_ids.h>
45
Ingo Molnarf78cb9b2008-07-10 19:39:55 +020046extern int no_broadcast;
47
Ingo Molnar65253632008-07-10 15:50:37 +020048char visws_board_type = -1;
49char visws_board_rev = -1;
50
51int is_visws_box(void)
52{
53 return visws_board_type >= 0;
54}
55
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070056static int __init visws_time_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020057{
58 printk(KERN_INFO "Starting Cobalt Timer system clock\n");
59
60 /* Set the countdown value */
61 co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
62
63 /* Start the timer */
64 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
65
66 /* Enable (unmask) the timer interrupt */
67 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
68
69 /*
70 * Zero return means the generic timer setup code will set up
71 * the standard vector:
72 */
73 return 0;
74}
75
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070076static int __init visws_pre_intr_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020077{
78 init_VISWS_APIC_irqs();
79
80 /*
81 * We dont want ISA irqs to be set up by the generic code:
82 */
83 return 1;
84}
85
86/* Quirk for machine specific memory setup. */
87
88#define MB (1024 * 1024)
89
90unsigned long sgivwfb_mem_phys;
91unsigned long sgivwfb_mem_size;
92EXPORT_SYMBOL(sgivwfb_mem_phys);
93EXPORT_SYMBOL(sgivwfb_mem_size);
94
95long long mem_size __initdata = 0;
96
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070097static char * __init visws_memory_setup(void)
Ingo Molnar65253632008-07-10 15:50:37 +020098{
99 long long gfx_mem_size = 8 * MB;
100
101 mem_size = boot_params.alt_mem_k;
102
103 if (!mem_size) {
104 printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
105 mem_size = 128 * MB;
106 }
107
108 /*
109 * this hardcodes the graphics memory to 8 MB
110 * it really should be sized dynamically (or at least
111 * set as a boot param)
112 */
113 if (!sgivwfb_mem_size) {
114 printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
115 sgivwfb_mem_size = 8 * MB;
116 }
117
118 /*
119 * Trim to nearest MB
120 */
121 sgivwfb_mem_size &= ~((1 << 20) - 1);
122 sgivwfb_mem_phys = mem_size - gfx_mem_size;
123
124 e820_add_region(0, LOWMEMSIZE(), E820_RAM);
125 e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
126 e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
127
128 return "PROM";
129}
130
131static void visws_machine_emergency_restart(void)
132{
133 /*
134 * Visual Workstations restart after this
135 * register is poked on the PIIX4
136 */
137 outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
138}
139
140static void visws_machine_power_off(void)
141{
142 unsigned short pm_status;
143/* extern unsigned int pci_bus0; */
144
145 while ((pm_status = inw(PMSTS_PORT)) & 0x100)
146 outw(pm_status, PMSTS_PORT);
147
148 outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
149
150 mdelay(10);
151
152#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
153 (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
154
155/* outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
156 outl(PIIX_SPECIAL_STOP, 0xCFC);
157}
158
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200159static void __init visws_get_smp_config(unsigned int early)
Ingo Molnar65253632008-07-10 15:50:37 +0200160{
Ingo Molnar65253632008-07-10 15:50:37 +0200161}
162
Ingo Molnar65253632008-07-10 15:50:37 +0200163/*
164 * The Visual Workstation is Intel MP compliant in the hardware
165 * sense, but it doesn't have a BIOS(-configuration table).
166 * No problem for Linux.
167 */
168
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530169static void __init MP_processor_info(struct mpc_cpu *m)
Ingo Molnar65253632008-07-10 15:50:37 +0200170{
171 int ver, logical_apicid;
172 physid_mask_t apic_cpus;
173
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530174 if (!(m->cpuflag & CPU_ENABLED))
Ingo Molnar65253632008-07-10 15:50:37 +0200175 return;
176
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530177 logical_apicid = m->apicid;
Ingo Molnar65253632008-07-10 15:50:37 +0200178 printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530179 m->cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
180 m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8,
181 (m->cpufeature & CPU_MODEL_MASK) >> 4, m->apicver);
Ingo Molnar65253632008-07-10 15:50:37 +0200182
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530183 if (m->cpuflag & CPU_BOOTPROCESSOR)
184 boot_cpu_physical_apicid = m->apicid;
Ingo Molnar65253632008-07-10 15:50:37 +0200185
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530186 ver = m->apicver;
187 if ((ver >= 0x14 && m->apicid >= 0xff) || m->apicid >= 0xf) {
Ingo Molnar65253632008-07-10 15:50:37 +0200188 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530189 m->apicid, MAX_APICS);
Ingo Molnar65253632008-07-10 15:50:37 +0200190 return;
191 }
192
Ingo Molnar80587142009-01-28 06:50:47 +0100193 apic_cpus = apic->apicid_to_cpu_present(m->apicid);
Ingo Molnar65253632008-07-10 15:50:37 +0200194 physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
195 /*
196 * Validate version
197 */
198 if (ver == 0x0) {
199 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
200 "fixing up to 0x10. (tell your hw vendor)\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530201 m->apicid);
Ingo Molnar65253632008-07-10 15:50:37 +0200202 ver = 0x10;
203 }
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530204 apic_version[m->apicid] = ver;
Ingo Molnar65253632008-07-10 15:50:37 +0200205}
206
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200207static void __init visws_find_smp_config(unsigned int reserve)
Ingo Molnar65253632008-07-10 15:50:37 +0200208{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530209 struct mpc_cpu *mp = phys_to_virt(CO_CPU_TAB_PHYS);
Ingo Molnar65253632008-07-10 15:50:37 +0200210 unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
211
212 if (ncpus > CO_CPU_MAX) {
213 printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
214 ncpus, mp);
215
216 ncpus = CO_CPU_MAX;
217 }
218
Max Krasnyansky23b49c192008-08-11 14:55:31 -0700219 if (ncpus > setup_max_cpus)
220 ncpus = setup_max_cpus;
Ingo Molnar65253632008-07-10 15:50:37 +0200221
222#ifdef CONFIG_X86_LOCAL_APIC
223 smp_found_config = 1;
224#endif
225 while (ncpus--)
226 MP_processor_info(mp++);
227
228 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
Ingo Molnar65253632008-07-10 15:50:37 +0200229}
230
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700231static int visws_trap_init(void);
232
233static struct x86_quirks visws_x86_quirks __initdata = {
234 .arch_time_init = visws_time_init,
235 .arch_pre_intr_init = visws_pre_intr_init,
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700236 .arch_intr_init = NULL,
237 .arch_trap_init = visws_trap_init,
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700238};
Ingo Molnar65253632008-07-10 15:50:37 +0200239
240void __init visws_early_detect(void)
241{
242 int raw;
243
244 visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
245 >> PIIX_GPI_BD_SHIFT;
246
247 if (visws_board_type < 0)
248 return;
249
250 /*
251 * Install special quirks for timer, interrupt and memory setup:
Ingo Molnar65253632008-07-10 15:50:37 +0200252 * Fall back to generic behavior for traps:
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700253 * Override generic MP-table parsing:
Ingo Molnar65253632008-07-10 15:50:37 +0200254 */
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700255 x86_quirks = &visws_x86_quirks;
Ingo Molnar65253632008-07-10 15:50:37 +0200256
Thomas Gleixner6b18ae32009-08-20 10:19:54 +0200257 x86_init.resources.memory_setup = visws_memory_setup;
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200258 x86_init.mpparse.get_smp_config = visws_get_smp_config;
259 x86_init.mpparse.find_smp_config = visws_find_smp_config;
Thomas Gleixner6b18ae32009-08-20 10:19:54 +0200260
Ingo Molnar65253632008-07-10 15:50:37 +0200261 /*
262 * Install reboot quirks:
263 */
264 pm_power_off = visws_machine_power_off;
265 machine_ops.emergency_restart = visws_machine_emergency_restart;
266
267 /*
268 * Do not use broadcast IPIs:
269 */
270 no_broadcast = 0;
271
Ingo Molnar54ce7f92008-07-10 16:14:56 +0200272#ifdef CONFIG_X86_IO_APIC
273 /*
274 * Turn off IO-APIC detection and initialization:
275 */
276 skip_ioapic_setup = 1;
277#endif
278
Ingo Molnar65253632008-07-10 15:50:37 +0200279 /*
280 * Get Board rev.
281 * First, we have to initialize the 307 part to allow us access
282 * to the GPIO registers. Let's map them at 0x0fc0 which is right
283 * after the PIIX4 PM section.
284 */
285 outb_p(SIO_DEV_SEL, SIO_INDEX);
286 outb_p(SIO_GP_DEV, SIO_DATA); /* Talk to GPIO regs. */
287
288 outb_p(SIO_DEV_MSB, SIO_INDEX);
289 outb_p(SIO_GP_MSB, SIO_DATA); /* MSB of GPIO base address */
290
291 outb_p(SIO_DEV_LSB, SIO_INDEX);
292 outb_p(SIO_GP_LSB, SIO_DATA); /* LSB of GPIO base address */
293
294 outb_p(SIO_DEV_ENB, SIO_INDEX);
295 outb_p(1, SIO_DATA); /* Enable GPIO registers. */
296
297 /*
298 * Now, we have to map the power management section to write
299 * a bit which enables access to the GPIO registers.
300 * What lunatic came up with this shit?
301 */
302 outb_p(SIO_DEV_SEL, SIO_INDEX);
303 outb_p(SIO_PM_DEV, SIO_DATA); /* Talk to GPIO regs. */
304
305 outb_p(SIO_DEV_MSB, SIO_INDEX);
306 outb_p(SIO_PM_MSB, SIO_DATA); /* MSB of PM base address */
307
308 outb_p(SIO_DEV_LSB, SIO_INDEX);
309 outb_p(SIO_PM_LSB, SIO_DATA); /* LSB of PM base address */
310
311 outb_p(SIO_DEV_ENB, SIO_INDEX);
312 outb_p(1, SIO_DATA); /* Enable PM registers. */
313
314 /*
315 * Now, write the PM register which enables the GPIO registers.
316 */
317 outb_p(SIO_PM_FER2, SIO_PM_INDEX);
318 outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
319
320 /*
321 * Now, initialize the GPIO registers.
322 * We want them all to be inputs which is the
323 * power on default, so let's leave them alone.
324 * So, let's just read the board rev!
325 */
326 raw = inb_p(SIO_GP_DATA1);
327 raw &= 0x7f; /* 7 bits of valid board revision ID. */
328
329 if (visws_board_type == VISWS_320) {
330 if (raw < 0x6) {
331 visws_board_rev = 4;
332 } else if (raw < 0xc) {
333 visws_board_rev = 5;
334 } else {
335 visws_board_rev = 6;
336 }
337 } else if (visws_board_type == VISWS_540) {
338 visws_board_rev = 2;
339 } else {
340 visws_board_rev = raw;
341 }
342
343 printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
344 (visws_board_type == VISWS_320 ? "320" :
345 (visws_board_type == VISWS_540 ? "540" :
346 "unknown")), visws_board_rev);
347}
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200348
349#define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
350#define BCD (LI_INTB | LI_INTC | LI_INTD)
351#define ALLDEVS (A01234 | BCD)
352
353static __init void lithium_init(void)
354{
355 set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
356 set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
357
358 if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
359 (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
360 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
361/* panic("This machine is not SGI Visual Workstation 320/540"); */
362 }
363
364 if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
365 (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
366 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
367/* panic("This machine is not SGI Visual Workstation 320/540"); */
368 }
369
370 li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
371 li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
372}
373
374static __init void cobalt_init(void)
375{
376 /*
377 * On normal SMP PC this is used only with SMP, but we have to
378 * use it and set it up here to start the Cobalt clock
379 */
380 set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
381 setup_local_APIC();
382 printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
383 (unsigned int)apic_read(APIC_LVR),
384 (unsigned int)apic_read(APIC_ID));
385
386 set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
387 set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
388 printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
389 co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
390
391 /* Enable Cobalt APIC being careful to NOT change the ID! */
392 co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
393
394 printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
395 co_apic_read(CO_APIC_ID));
396}
397
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700398static int __init visws_trap_init(void)
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200399{
400 lithium_init();
401 cobalt_init();
402
403 return 1;
404}
405
406/*
407 * IRQ controller / APIC support:
408 */
409
410static DEFINE_SPINLOCK(cobalt_lock);
411
412/*
413 * Set the given Cobalt APIC Redirection Table entry to point
414 * to the given IDT vector/index.
415 */
416static inline void co_apic_set(int entry, int irq)
417{
418 co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
419 co_apic_write(CO_APIC_HI(entry), 0);
420}
421
422/*
423 * Cobalt (IO)-APIC functions to handle PCI devices.
424 */
425static inline int co_apic_ide0_hack(void)
426{
427 extern char visws_board_type;
428 extern char visws_board_rev;
429
430 if (visws_board_type == VISWS_320 && visws_board_rev == 5)
431 return 5;
432 return CO_APIC_IDE0;
433}
434
435static int is_co_apic(unsigned int irq)
436{
437 if (IS_CO_APIC(irq))
438 return CO_APIC(irq);
439
440 switch (irq) {
441 case 0: return CO_APIC_CPU;
442 case CO_IRQ_IDE0: return co_apic_ide0_hack();
443 case CO_IRQ_IDE1: return CO_APIC_IDE1;
444 default: return -1;
445 }
446}
447
448
449/*
450 * This is the SGI Cobalt (IO-)APIC:
451 */
452
453static void enable_cobalt_irq(unsigned int irq)
454{
455 co_apic_set(is_co_apic(irq), irq);
456}
457
458static void disable_cobalt_irq(unsigned int irq)
459{
460 int entry = is_co_apic(irq);
461
462 co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
463 co_apic_read(CO_APIC_LO(entry));
464}
465
466/*
467 * "irq" really just serves to identify the device. Here is where we
468 * map this to the Cobalt APIC entry where it's physically wired.
469 * This is called via request_irq -> setup_irq -> irq_desc->startup()
470 */
471static unsigned int startup_cobalt_irq(unsigned int irq)
472{
473 unsigned long flags;
Yinghai Lu08678b02008-08-19 20:50:05 -0700474 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200475
476 spin_lock_irqsave(&cobalt_lock, flags);
Yinghai Lu08678b02008-08-19 20:50:05 -0700477 if ((desc->status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
478 desc->status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200479 enable_cobalt_irq(irq);
480 spin_unlock_irqrestore(&cobalt_lock, flags);
481 return 0;
482}
483
484static void ack_cobalt_irq(unsigned int irq)
485{
486 unsigned long flags;
487
488 spin_lock_irqsave(&cobalt_lock, flags);
489 disable_cobalt_irq(irq);
490 apic_write(APIC_EOI, APIC_EIO_ACK);
491 spin_unlock_irqrestore(&cobalt_lock, flags);
492}
493
494static void end_cobalt_irq(unsigned int irq)
495{
496 unsigned long flags;
Yinghai Lu08678b02008-08-19 20:50:05 -0700497 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200498
499 spin_lock_irqsave(&cobalt_lock, flags);
Yinghai Lu08678b02008-08-19 20:50:05 -0700500 if (!(desc->status & (IRQ_DISABLED | IRQ_INPROGRESS)))
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200501 enable_cobalt_irq(irq);
502 spin_unlock_irqrestore(&cobalt_lock, flags);
503}
504
505static struct irq_chip cobalt_irq_type = {
506 .typename = "Cobalt-APIC",
507 .startup = startup_cobalt_irq,
508 .shutdown = disable_cobalt_irq,
509 .enable = enable_cobalt_irq,
510 .disable = disable_cobalt_irq,
511 .ack = ack_cobalt_irq,
512 .end = end_cobalt_irq,
513};
514
515
516/*
517 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
518 * -- not the manner expected by the code in i8259.c.
519 *
520 * there is a 'master' physical interrupt source that gets sent to
521 * the CPU. But in the chipset there are various 'virtual' interrupts
522 * waiting to be handled. We represent this to Linux through a 'master'
523 * interrupt controller type, and through a special virtual interrupt-
524 * controller. Device drivers only see the virtual interrupt sources.
525 */
526static unsigned int startup_piix4_master_irq(unsigned int irq)
527{
528 init_8259A(0);
529
530 return startup_cobalt_irq(irq);
531}
532
533static void end_piix4_master_irq(unsigned int irq)
534{
535 unsigned long flags;
536
537 spin_lock_irqsave(&cobalt_lock, flags);
538 enable_cobalt_irq(irq);
539 spin_unlock_irqrestore(&cobalt_lock, flags);
540}
541
542static struct irq_chip piix4_master_irq_type = {
543 .typename = "PIIX4-master",
544 .startup = startup_piix4_master_irq,
545 .ack = ack_cobalt_irq,
546 .end = end_piix4_master_irq,
547};
548
549
550static struct irq_chip piix4_virtual_irq_type = {
551 .typename = "PIIX4-virtual",
552 .shutdown = disable_8259A_irq,
553 .enable = enable_8259A_irq,
554 .disable = disable_8259A_irq,
555};
556
557
558/*
559 * PIIX4-8259 master/virtual functions to handle interrupt requests
560 * from legacy devices: floppy, parallel, serial, rtc.
561 *
562 * None of these get Cobalt APIC entries, neither do they have IDT
563 * entries. These interrupts are purely virtual and distributed from
564 * the 'master' interrupt source: CO_IRQ_8259.
565 *
566 * When the 8259 interrupts its handler figures out which of these
567 * devices is interrupting and dispatches to its handler.
568 *
569 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
570 * enable_irq gets the right irq. This 'master' irq is never directly
571 * manipulated by any driver.
572 */
573static irqreturn_t piix4_master_intr(int irq, void *dev_id)
574{
575 int realirq;
Thomas Gleixnerbf5172d2009-03-09 22:04:45 +0100576 struct irq_desc *desc;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200577 unsigned long flags;
578
579 spin_lock_irqsave(&i8259A_lock, flags);
580
581 /* Find out what's interrupting in the PIIX4 master 8259 */
582 outb(0x0c, 0x20); /* OCW3 Poll command */
583 realirq = inb(0x20);
584
585 /*
586 * Bit 7 == 0 means invalid/spurious
587 */
588 if (unlikely(!(realirq & 0x80)))
589 goto out_unlock;
590
591 realirq &= 7;
592
593 if (unlikely(realirq == 2)) {
594 outb(0x0c, 0xa0);
595 realirq = inb(0xa0);
596
597 if (unlikely(!(realirq & 0x80)))
598 goto out_unlock;
599
600 realirq = (realirq & 7) + 8;
601 }
602
603 /* mask and ack interrupt */
604 cached_irq_mask |= 1 << realirq;
605 if (unlikely(realirq > 7)) {
606 inb(0xa1);
607 outb(cached_slave_mask, 0xa1);
608 outb(0x60 + (realirq & 7), 0xa0);
609 outb(0x60 + 2, 0x20);
610 } else {
611 inb(0x21);
612 outb(cached_master_mask, 0x21);
613 outb(0x60 + realirq, 0x20);
614 }
615
616 spin_unlock_irqrestore(&i8259A_lock, flags);
617
Yinghai Lu08678b02008-08-19 20:50:05 -0700618 desc = irq_to_desc(realirq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200619
620 /*
621 * handle this 'virtual interrupt' as a Cobalt one now.
622 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200623 kstat_incr_irqs_this_cpu(realirq, desc);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200624
625 if (likely(desc->action != NULL))
626 handle_IRQ_event(realirq, desc->action);
627
628 if (!(desc->status & IRQ_DISABLED))
629 enable_8259A_irq(realirq);
630
631 return IRQ_HANDLED;
632
633out_unlock:
634 spin_unlock_irqrestore(&i8259A_lock, flags);
635 return IRQ_NONE;
636}
637
638static struct irqaction master_action = {
639 .handler = piix4_master_intr,
640 .name = "PIIX4-8259",
641};
642
643static struct irqaction cascade_action = {
644 .handler = no_action,
645 .name = "cascade",
646};
647
648
649void init_VISWS_APIC_irqs(void)
650{
651 int i;
652
653 for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700654 struct irq_desc *desc = irq_to_desc(i);
655
656 desc->status = IRQ_DISABLED;
657 desc->action = 0;
658 desc->depth = 1;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200659
660 if (i == 0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700661 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200662 }
663 else if (i == CO_IRQ_IDE0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700664 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200665 }
666 else if (i == CO_IRQ_IDE1) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700667 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200668 }
669 else if (i == CO_IRQ_8259) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700670 desc->chip = &piix4_master_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200671 }
672 else if (i < CO_IRQ_APIC0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700673 desc->chip = &piix4_virtual_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200674 }
675 else if (IS_CO_APIC(i)) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700676 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200677 }
678 }
679
680 setup_irq(CO_IRQ_8259, &master_action);
681 setup_irq(2, &cascade_action);
682}