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