blob: 1d6309d70dfa836759e807dec81d6fb384909eee [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
Thomas Gleixnerd9112f42009-08-20 09:41:38 +020076/* Replaces the default init_ISA_irqs in the generic setup */
77static void __init visws_pre_intr_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020078{
79 init_VISWS_APIC_irqs();
Ingo Molnar65253632008-07-10 15:50:37 +020080}
81
82/* Quirk for machine specific memory setup. */
83
84#define MB (1024 * 1024)
85
86unsigned long sgivwfb_mem_phys;
87unsigned long sgivwfb_mem_size;
88EXPORT_SYMBOL(sgivwfb_mem_phys);
89EXPORT_SYMBOL(sgivwfb_mem_size);
90
91long long mem_size __initdata = 0;
92
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070093static char * __init visws_memory_setup(void)
Ingo Molnar65253632008-07-10 15:50:37 +020094{
95 long long gfx_mem_size = 8 * MB;
96
97 mem_size = boot_params.alt_mem_k;
98
99 if (!mem_size) {
100 printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
101 mem_size = 128 * MB;
102 }
103
104 /*
105 * this hardcodes the graphics memory to 8 MB
106 * it really should be sized dynamically (or at least
107 * set as a boot param)
108 */
109 if (!sgivwfb_mem_size) {
110 printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
111 sgivwfb_mem_size = 8 * MB;
112 }
113
114 /*
115 * Trim to nearest MB
116 */
117 sgivwfb_mem_size &= ~((1 << 20) - 1);
118 sgivwfb_mem_phys = mem_size - gfx_mem_size;
119
120 e820_add_region(0, LOWMEMSIZE(), E820_RAM);
121 e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
122 e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
123
124 return "PROM";
125}
126
127static void visws_machine_emergency_restart(void)
128{
129 /*
130 * Visual Workstations restart after this
131 * register is poked on the PIIX4
132 */
133 outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
134}
135
136static void visws_machine_power_off(void)
137{
138 unsigned short pm_status;
139/* extern unsigned int pci_bus0; */
140
141 while ((pm_status = inw(PMSTS_PORT)) & 0x100)
142 outw(pm_status, PMSTS_PORT);
143
144 outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
145
146 mdelay(10);
147
148#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
149 (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
150
151/* outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
152 outl(PIIX_SPECIAL_STOP, 0xCFC);
153}
154
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200155static void __init visws_get_smp_config(unsigned int early)
Ingo Molnar65253632008-07-10 15:50:37 +0200156{
Ingo Molnar65253632008-07-10 15:50:37 +0200157}
158
Ingo Molnar65253632008-07-10 15:50:37 +0200159/*
160 * The Visual Workstation is Intel MP compliant in the hardware
161 * sense, but it doesn't have a BIOS(-configuration table).
162 * No problem for Linux.
163 */
164
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530165static void __init MP_processor_info(struct mpc_cpu *m)
Ingo Molnar65253632008-07-10 15:50:37 +0200166{
167 int ver, logical_apicid;
168 physid_mask_t apic_cpus;
169
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530170 if (!(m->cpuflag & CPU_ENABLED))
Ingo Molnar65253632008-07-10 15:50:37 +0200171 return;
172
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530173 logical_apicid = m->apicid;
Ingo Molnar65253632008-07-10 15:50:37 +0200174 printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530175 m->cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
176 m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8,
177 (m->cpufeature & CPU_MODEL_MASK) >> 4, m->apicver);
Ingo Molnar65253632008-07-10 15:50:37 +0200178
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530179 if (m->cpuflag & CPU_BOOTPROCESSOR)
180 boot_cpu_physical_apicid = m->apicid;
Ingo Molnar65253632008-07-10 15:50:37 +0200181
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530182 ver = m->apicver;
183 if ((ver >= 0x14 && m->apicid >= 0xff) || m->apicid >= 0xf) {
Ingo Molnar65253632008-07-10 15:50:37 +0200184 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530185 m->apicid, MAX_APICS);
Ingo Molnar65253632008-07-10 15:50:37 +0200186 return;
187 }
188
Ingo Molnar80587142009-01-28 06:50:47 +0100189 apic_cpus = apic->apicid_to_cpu_present(m->apicid);
Ingo Molnar65253632008-07-10 15:50:37 +0200190 physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
191 /*
192 * Validate version
193 */
194 if (ver == 0x0) {
195 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
196 "fixing up to 0x10. (tell your hw vendor)\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530197 m->apicid);
Ingo Molnar65253632008-07-10 15:50:37 +0200198 ver = 0x10;
199 }
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530200 apic_version[m->apicid] = ver;
Ingo Molnar65253632008-07-10 15:50:37 +0200201}
202
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200203static void __init visws_find_smp_config(unsigned int reserve)
Ingo Molnar65253632008-07-10 15:50:37 +0200204{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530205 struct mpc_cpu *mp = phys_to_virt(CO_CPU_TAB_PHYS);
Ingo Molnar65253632008-07-10 15:50:37 +0200206 unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
207
208 if (ncpus > CO_CPU_MAX) {
209 printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
210 ncpus, mp);
211
212 ncpus = CO_CPU_MAX;
213 }
214
Max Krasnyansky23b49c192008-08-11 14:55:31 -0700215 if (ncpus > setup_max_cpus)
216 ncpus = setup_max_cpus;
Ingo Molnar65253632008-07-10 15:50:37 +0200217
218#ifdef CONFIG_X86_LOCAL_APIC
219 smp_found_config = 1;
220#endif
221 while (ncpus--)
222 MP_processor_info(mp++);
223
224 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
Ingo Molnar65253632008-07-10 15:50:37 +0200225}
226
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700227static int visws_trap_init(void);
228
229static struct x86_quirks visws_x86_quirks __initdata = {
230 .arch_time_init = visws_time_init,
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700231 .arch_intr_init = NULL,
232 .arch_trap_init = visws_trap_init,
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700233};
Ingo Molnar65253632008-07-10 15:50:37 +0200234
235void __init visws_early_detect(void)
236{
237 int raw;
238
239 visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
240 >> PIIX_GPI_BD_SHIFT;
241
242 if (visws_board_type < 0)
243 return;
244
245 /*
246 * Install special quirks for timer, interrupt and memory setup:
Ingo Molnar65253632008-07-10 15:50:37 +0200247 * Fall back to generic behavior for traps:
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700248 * Override generic MP-table parsing:
Ingo Molnar65253632008-07-10 15:50:37 +0200249 */
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700250 x86_quirks = &visws_x86_quirks;
Ingo Molnar65253632008-07-10 15:50:37 +0200251
Thomas Gleixner6b18ae32009-08-20 10:19:54 +0200252 x86_init.resources.memory_setup = visws_memory_setup;
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200253 x86_init.mpparse.get_smp_config = visws_get_smp_config;
254 x86_init.mpparse.find_smp_config = visws_find_smp_config;
Thomas Gleixnerd9112f42009-08-20 09:41:38 +0200255 x86_init.irqs.pre_vector_init = visws_pre_intr_init;
Thomas Gleixner6b18ae32009-08-20 10:19:54 +0200256
Ingo Molnar65253632008-07-10 15:50:37 +0200257 /*
258 * Install reboot quirks:
259 */
260 pm_power_off = visws_machine_power_off;
261 machine_ops.emergency_restart = visws_machine_emergency_restart;
262
263 /*
264 * Do not use broadcast IPIs:
265 */
266 no_broadcast = 0;
267
Ingo Molnar54ce7f92008-07-10 16:14:56 +0200268#ifdef CONFIG_X86_IO_APIC
269 /*
270 * Turn off IO-APIC detection and initialization:
271 */
272 skip_ioapic_setup = 1;
273#endif
274
Ingo Molnar65253632008-07-10 15:50:37 +0200275 /*
276 * Get Board rev.
277 * First, we have to initialize the 307 part to allow us access
278 * to the GPIO registers. Let's map them at 0x0fc0 which is right
279 * after the PIIX4 PM section.
280 */
281 outb_p(SIO_DEV_SEL, SIO_INDEX);
282 outb_p(SIO_GP_DEV, SIO_DATA); /* Talk to GPIO regs. */
283
284 outb_p(SIO_DEV_MSB, SIO_INDEX);
285 outb_p(SIO_GP_MSB, SIO_DATA); /* MSB of GPIO base address */
286
287 outb_p(SIO_DEV_LSB, SIO_INDEX);
288 outb_p(SIO_GP_LSB, SIO_DATA); /* LSB of GPIO base address */
289
290 outb_p(SIO_DEV_ENB, SIO_INDEX);
291 outb_p(1, SIO_DATA); /* Enable GPIO registers. */
292
293 /*
294 * Now, we have to map the power management section to write
295 * a bit which enables access to the GPIO registers.
296 * What lunatic came up with this shit?
297 */
298 outb_p(SIO_DEV_SEL, SIO_INDEX);
299 outb_p(SIO_PM_DEV, SIO_DATA); /* Talk to GPIO regs. */
300
301 outb_p(SIO_DEV_MSB, SIO_INDEX);
302 outb_p(SIO_PM_MSB, SIO_DATA); /* MSB of PM base address */
303
304 outb_p(SIO_DEV_LSB, SIO_INDEX);
305 outb_p(SIO_PM_LSB, SIO_DATA); /* LSB of PM base address */
306
307 outb_p(SIO_DEV_ENB, SIO_INDEX);
308 outb_p(1, SIO_DATA); /* Enable PM registers. */
309
310 /*
311 * Now, write the PM register which enables the GPIO registers.
312 */
313 outb_p(SIO_PM_FER2, SIO_PM_INDEX);
314 outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
315
316 /*
317 * Now, initialize the GPIO registers.
318 * We want them all to be inputs which is the
319 * power on default, so let's leave them alone.
320 * So, let's just read the board rev!
321 */
322 raw = inb_p(SIO_GP_DATA1);
323 raw &= 0x7f; /* 7 bits of valid board revision ID. */
324
325 if (visws_board_type == VISWS_320) {
326 if (raw < 0x6) {
327 visws_board_rev = 4;
328 } else if (raw < 0xc) {
329 visws_board_rev = 5;
330 } else {
331 visws_board_rev = 6;
332 }
333 } else if (visws_board_type == VISWS_540) {
334 visws_board_rev = 2;
335 } else {
336 visws_board_rev = raw;
337 }
338
339 printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
340 (visws_board_type == VISWS_320 ? "320" :
341 (visws_board_type == VISWS_540 ? "540" :
342 "unknown")), visws_board_rev);
343}
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200344
345#define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
346#define BCD (LI_INTB | LI_INTC | LI_INTD)
347#define ALLDEVS (A01234 | BCD)
348
349static __init void lithium_init(void)
350{
351 set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
352 set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
353
354 if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
355 (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
356 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
357/* panic("This machine is not SGI Visual Workstation 320/540"); */
358 }
359
360 if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
361 (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
362 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
363/* panic("This machine is not SGI Visual Workstation 320/540"); */
364 }
365
366 li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
367 li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
368}
369
370static __init void cobalt_init(void)
371{
372 /*
373 * On normal SMP PC this is used only with SMP, but we have to
374 * use it and set it up here to start the Cobalt clock
375 */
376 set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
377 setup_local_APIC();
378 printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
379 (unsigned int)apic_read(APIC_LVR),
380 (unsigned int)apic_read(APIC_ID));
381
382 set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
383 set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
384 printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
385 co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
386
387 /* Enable Cobalt APIC being careful to NOT change the ID! */
388 co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
389
390 printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
391 co_apic_read(CO_APIC_ID));
392}
393
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700394static int __init visws_trap_init(void)
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200395{
396 lithium_init();
397 cobalt_init();
398
399 return 1;
400}
401
402/*
403 * IRQ controller / APIC support:
404 */
405
406static DEFINE_SPINLOCK(cobalt_lock);
407
408/*
409 * Set the given Cobalt APIC Redirection Table entry to point
410 * to the given IDT vector/index.
411 */
412static inline void co_apic_set(int entry, int irq)
413{
414 co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
415 co_apic_write(CO_APIC_HI(entry), 0);
416}
417
418/*
419 * Cobalt (IO)-APIC functions to handle PCI devices.
420 */
421static inline int co_apic_ide0_hack(void)
422{
423 extern char visws_board_type;
424 extern char visws_board_rev;
425
426 if (visws_board_type == VISWS_320 && visws_board_rev == 5)
427 return 5;
428 return CO_APIC_IDE0;
429}
430
431static int is_co_apic(unsigned int irq)
432{
433 if (IS_CO_APIC(irq))
434 return CO_APIC(irq);
435
436 switch (irq) {
437 case 0: return CO_APIC_CPU;
438 case CO_IRQ_IDE0: return co_apic_ide0_hack();
439 case CO_IRQ_IDE1: return CO_APIC_IDE1;
440 default: return -1;
441 }
442}
443
444
445/*
446 * This is the SGI Cobalt (IO-)APIC:
447 */
448
449static void enable_cobalt_irq(unsigned int irq)
450{
451 co_apic_set(is_co_apic(irq), irq);
452}
453
454static void disable_cobalt_irq(unsigned int irq)
455{
456 int entry = is_co_apic(irq);
457
458 co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
459 co_apic_read(CO_APIC_LO(entry));
460}
461
462/*
463 * "irq" really just serves to identify the device. Here is where we
464 * map this to the Cobalt APIC entry where it's physically wired.
465 * This is called via request_irq -> setup_irq -> irq_desc->startup()
466 */
467static unsigned int startup_cobalt_irq(unsigned int irq)
468{
469 unsigned long flags;
Yinghai Lu08678b02008-08-19 20:50:05 -0700470 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200471
472 spin_lock_irqsave(&cobalt_lock, flags);
Yinghai Lu08678b02008-08-19 20:50:05 -0700473 if ((desc->status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
474 desc->status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200475 enable_cobalt_irq(irq);
476 spin_unlock_irqrestore(&cobalt_lock, flags);
477 return 0;
478}
479
480static void ack_cobalt_irq(unsigned int irq)
481{
482 unsigned long flags;
483
484 spin_lock_irqsave(&cobalt_lock, flags);
485 disable_cobalt_irq(irq);
486 apic_write(APIC_EOI, APIC_EIO_ACK);
487 spin_unlock_irqrestore(&cobalt_lock, flags);
488}
489
490static void end_cobalt_irq(unsigned int irq)
491{
492 unsigned long flags;
Yinghai Lu08678b02008-08-19 20:50:05 -0700493 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200494
495 spin_lock_irqsave(&cobalt_lock, flags);
Yinghai Lu08678b02008-08-19 20:50:05 -0700496 if (!(desc->status & (IRQ_DISABLED | IRQ_INPROGRESS)))
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200497 enable_cobalt_irq(irq);
498 spin_unlock_irqrestore(&cobalt_lock, flags);
499}
500
501static struct irq_chip cobalt_irq_type = {
502 .typename = "Cobalt-APIC",
503 .startup = startup_cobalt_irq,
504 .shutdown = disable_cobalt_irq,
505 .enable = enable_cobalt_irq,
506 .disable = disable_cobalt_irq,
507 .ack = ack_cobalt_irq,
508 .end = end_cobalt_irq,
509};
510
511
512/*
513 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
514 * -- not the manner expected by the code in i8259.c.
515 *
516 * there is a 'master' physical interrupt source that gets sent to
517 * the CPU. But in the chipset there are various 'virtual' interrupts
518 * waiting to be handled. We represent this to Linux through a 'master'
519 * interrupt controller type, and through a special virtual interrupt-
520 * controller. Device drivers only see the virtual interrupt sources.
521 */
522static unsigned int startup_piix4_master_irq(unsigned int irq)
523{
524 init_8259A(0);
525
526 return startup_cobalt_irq(irq);
527}
528
529static void end_piix4_master_irq(unsigned int irq)
530{
531 unsigned long flags;
532
533 spin_lock_irqsave(&cobalt_lock, flags);
534 enable_cobalt_irq(irq);
535 spin_unlock_irqrestore(&cobalt_lock, flags);
536}
537
538static struct irq_chip piix4_master_irq_type = {
539 .typename = "PIIX4-master",
540 .startup = startup_piix4_master_irq,
541 .ack = ack_cobalt_irq,
542 .end = end_piix4_master_irq,
543};
544
545
546static struct irq_chip piix4_virtual_irq_type = {
547 .typename = "PIIX4-virtual",
548 .shutdown = disable_8259A_irq,
549 .enable = enable_8259A_irq,
550 .disable = disable_8259A_irq,
551};
552
553
554/*
555 * PIIX4-8259 master/virtual functions to handle interrupt requests
556 * from legacy devices: floppy, parallel, serial, rtc.
557 *
558 * None of these get Cobalt APIC entries, neither do they have IDT
559 * entries. These interrupts are purely virtual and distributed from
560 * the 'master' interrupt source: CO_IRQ_8259.
561 *
562 * When the 8259 interrupts its handler figures out which of these
563 * devices is interrupting and dispatches to its handler.
564 *
565 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
566 * enable_irq gets the right irq. This 'master' irq is never directly
567 * manipulated by any driver.
568 */
569static irqreturn_t piix4_master_intr(int irq, void *dev_id)
570{
571 int realirq;
Thomas Gleixnerbf5172d2009-03-09 22:04:45 +0100572 struct irq_desc *desc;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200573 unsigned long flags;
574
575 spin_lock_irqsave(&i8259A_lock, flags);
576
577 /* Find out what's interrupting in the PIIX4 master 8259 */
578 outb(0x0c, 0x20); /* OCW3 Poll command */
579 realirq = inb(0x20);
580
581 /*
582 * Bit 7 == 0 means invalid/spurious
583 */
584 if (unlikely(!(realirq & 0x80)))
585 goto out_unlock;
586
587 realirq &= 7;
588
589 if (unlikely(realirq == 2)) {
590 outb(0x0c, 0xa0);
591 realirq = inb(0xa0);
592
593 if (unlikely(!(realirq & 0x80)))
594 goto out_unlock;
595
596 realirq = (realirq & 7) + 8;
597 }
598
599 /* mask and ack interrupt */
600 cached_irq_mask |= 1 << realirq;
601 if (unlikely(realirq > 7)) {
602 inb(0xa1);
603 outb(cached_slave_mask, 0xa1);
604 outb(0x60 + (realirq & 7), 0xa0);
605 outb(0x60 + 2, 0x20);
606 } else {
607 inb(0x21);
608 outb(cached_master_mask, 0x21);
609 outb(0x60 + realirq, 0x20);
610 }
611
612 spin_unlock_irqrestore(&i8259A_lock, flags);
613
Yinghai Lu08678b02008-08-19 20:50:05 -0700614 desc = irq_to_desc(realirq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200615
616 /*
617 * handle this 'virtual interrupt' as a Cobalt one now.
618 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200619 kstat_incr_irqs_this_cpu(realirq, desc);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200620
621 if (likely(desc->action != NULL))
622 handle_IRQ_event(realirq, desc->action);
623
624 if (!(desc->status & IRQ_DISABLED))
625 enable_8259A_irq(realirq);
626
627 return IRQ_HANDLED;
628
629out_unlock:
630 spin_unlock_irqrestore(&i8259A_lock, flags);
631 return IRQ_NONE;
632}
633
634static struct irqaction master_action = {
635 .handler = piix4_master_intr,
636 .name = "PIIX4-8259",
637};
638
639static struct irqaction cascade_action = {
640 .handler = no_action,
641 .name = "cascade",
642};
643
644
645void init_VISWS_APIC_irqs(void)
646{
647 int i;
648
649 for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700650 struct irq_desc *desc = irq_to_desc(i);
651
652 desc->status = IRQ_DISABLED;
653 desc->action = 0;
654 desc->depth = 1;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200655
656 if (i == 0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700657 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200658 }
659 else if (i == CO_IRQ_IDE0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700660 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200661 }
662 else if (i == CO_IRQ_IDE1) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700663 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200664 }
665 else if (i == CO_IRQ_8259) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700666 desc->chip = &piix4_master_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200667 }
668 else if (i < CO_IRQ_APIC0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700669 desc->chip = &piix4_virtual_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200670 }
671 else if (IS_CO_APIC(i)) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700672 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200673 }
674 }
675
676 setup_irq(CO_IRQ_8259, &master_action);
677 setup_irq(2, &cascade_action);
678}