blob: 843e9d30a1e3c64a169a5e9993369d10419d55e8 [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>
Thomas Gleixner845b3942009-08-19 15:37:03 +020033#include <asm/time.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
Thomas Gleixner845b3942009-08-19 15:37:03 +020052static void __init visws_time_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020053{
54 printk(KERN_INFO "Starting Cobalt Timer system clock\n");
55
56 /* Set the countdown value */
57 co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
58
59 /* Start the timer */
60 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
61
62 /* Enable (unmask) the timer interrupt */
63 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
64
Thomas Gleixner845b3942009-08-19 15:37:03 +020065 setup_default_timer_irq();
Ingo Molnar65253632008-07-10 15:50:37 +020066}
67
Thomas Gleixnerd9112f42009-08-20 09:41:38 +020068/* Replaces the default init_ISA_irqs in the generic setup */
69static void __init visws_pre_intr_init(void)
Ingo Molnar65253632008-07-10 15:50:37 +020070{
71 init_VISWS_APIC_irqs();
Ingo Molnar65253632008-07-10 15:50:37 +020072}
73
74/* Quirk for machine specific memory setup. */
75
76#define MB (1024 * 1024)
77
78unsigned long sgivwfb_mem_phys;
79unsigned long sgivwfb_mem_size;
80EXPORT_SYMBOL(sgivwfb_mem_phys);
81EXPORT_SYMBOL(sgivwfb_mem_size);
82
83long long mem_size __initdata = 0;
84
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070085static char * __init visws_memory_setup(void)
Ingo Molnar65253632008-07-10 15:50:37 +020086{
87 long long gfx_mem_size = 8 * MB;
88
89 mem_size = boot_params.alt_mem_k;
90
91 if (!mem_size) {
92 printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
93 mem_size = 128 * MB;
94 }
95
96 /*
97 * this hardcodes the graphics memory to 8 MB
98 * it really should be sized dynamically (or at least
99 * set as a boot param)
100 */
101 if (!sgivwfb_mem_size) {
102 printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
103 sgivwfb_mem_size = 8 * MB;
104 }
105
106 /*
107 * Trim to nearest MB
108 */
109 sgivwfb_mem_size &= ~((1 << 20) - 1);
110 sgivwfb_mem_phys = mem_size - gfx_mem_size;
111
112 e820_add_region(0, LOWMEMSIZE(), E820_RAM);
113 e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
114 e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
115
116 return "PROM";
117}
118
119static void visws_machine_emergency_restart(void)
120{
121 /*
122 * Visual Workstations restart after this
123 * register is poked on the PIIX4
124 */
125 outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
126}
127
128static void visws_machine_power_off(void)
129{
130 unsigned short pm_status;
131/* extern unsigned int pci_bus0; */
132
133 while ((pm_status = inw(PMSTS_PORT)) & 0x100)
134 outw(pm_status, PMSTS_PORT);
135
136 outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
137
138 mdelay(10);
139
140#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
141 (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
142
143/* outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
144 outl(PIIX_SPECIAL_STOP, 0xCFC);
145}
146
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200147static void __init visws_get_smp_config(unsigned int early)
Ingo Molnar65253632008-07-10 15:50:37 +0200148{
Ingo Molnar65253632008-07-10 15:50:37 +0200149}
150
Ingo Molnar65253632008-07-10 15:50:37 +0200151/*
152 * The Visual Workstation is Intel MP compliant in the hardware
153 * sense, but it doesn't have a BIOS(-configuration table).
154 * No problem for Linux.
155 */
156
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530157static void __init MP_processor_info(struct mpc_cpu *m)
Ingo Molnar65253632008-07-10 15:50:37 +0200158{
159 int ver, logical_apicid;
160 physid_mask_t apic_cpus;
161
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530162 if (!(m->cpuflag & CPU_ENABLED))
Ingo Molnar65253632008-07-10 15:50:37 +0200163 return;
164
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530165 logical_apicid = m->apicid;
Ingo Molnar65253632008-07-10 15:50:37 +0200166 printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530167 m->cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
168 m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8,
169 (m->cpufeature & CPU_MODEL_MASK) >> 4, m->apicver);
Ingo Molnar65253632008-07-10 15:50:37 +0200170
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530171 if (m->cpuflag & CPU_BOOTPROCESSOR)
172 boot_cpu_physical_apicid = m->apicid;
Ingo Molnar65253632008-07-10 15:50:37 +0200173
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530174 ver = m->apicver;
175 if ((ver >= 0x14 && m->apicid >= 0xff) || m->apicid >= 0xf) {
Ingo Molnar65253632008-07-10 15:50:37 +0200176 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530177 m->apicid, MAX_APICS);
Ingo Molnar65253632008-07-10 15:50:37 +0200178 return;
179 }
180
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300181 apic->apicid_to_cpu_present(m->apicid, &apic_cpus);
Ingo Molnar65253632008-07-10 15:50:37 +0200182 physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
183 /*
184 * Validate version
185 */
186 if (ver == 0x0) {
187 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
188 "fixing up to 0x10. (tell your hw vendor)\n",
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530189 m->apicid);
Ingo Molnar65253632008-07-10 15:50:37 +0200190 ver = 0x10;
191 }
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530192 apic_version[m->apicid] = ver;
Ingo Molnar65253632008-07-10 15:50:37 +0200193}
194
Yinghai Lub24c2a92009-11-24 02:48:18 -0800195static void __init visws_find_smp_config(void)
Ingo Molnar65253632008-07-10 15:50:37 +0200196{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530197 struct mpc_cpu *mp = phys_to_virt(CO_CPU_TAB_PHYS);
Ingo Molnar65253632008-07-10 15:50:37 +0200198 unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
199
200 if (ncpus > CO_CPU_MAX) {
201 printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
202 ncpus, mp);
203
204 ncpus = CO_CPU_MAX;
205 }
206
Max Krasnyansky23b49c192008-08-11 14:55:31 -0700207 if (ncpus > setup_max_cpus)
208 ncpus = setup_max_cpus;
Ingo Molnar65253632008-07-10 15:50:37 +0200209
210#ifdef CONFIG_X86_LOCAL_APIC
211 smp_found_config = 1;
212#endif
213 while (ncpus--)
214 MP_processor_info(mp++);
215
216 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
Ingo Molnar65253632008-07-10 15:50:37 +0200217}
218
Thomas Gleixner428cf902009-08-20 10:35:46 +0200219static void visws_trap_init(void);
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700220
Ingo Molnar65253632008-07-10 15:50:37 +0200221void __init visws_early_detect(void)
222{
223 int raw;
224
225 visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
226 >> PIIX_GPI_BD_SHIFT;
227
228 if (visws_board_type < 0)
229 return;
230
231 /*
Thomas Gleixner845b3942009-08-19 15:37:03 +0200232 * Override the default platform setup functions
Ingo Molnar65253632008-07-10 15:50:37 +0200233 */
Thomas Gleixner6b18ae32009-08-20 10:19:54 +0200234 x86_init.resources.memory_setup = visws_memory_setup;
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200235 x86_init.mpparse.get_smp_config = visws_get_smp_config;
236 x86_init.mpparse.find_smp_config = visws_find_smp_config;
Thomas Gleixnerd9112f42009-08-20 09:41:38 +0200237 x86_init.irqs.pre_vector_init = visws_pre_intr_init;
Thomas Gleixner428cf902009-08-20 10:35:46 +0200238 x86_init.irqs.trap_init = visws_trap_init;
Thomas Gleixner845b3942009-08-19 15:37:03 +0200239 x86_init.timers.timer_init = visws_time_init;
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +0200240 x86_init.pci.init = pci_visws_init;
Thomas Gleixner6b18ae32009-08-20 10:19:54 +0200241
Ingo Molnar65253632008-07-10 15:50:37 +0200242 /*
243 * Install reboot quirks:
244 */
245 pm_power_off = visws_machine_power_off;
246 machine_ops.emergency_restart = visws_machine_emergency_restart;
247
248 /*
249 * Do not use broadcast IPIs:
250 */
251 no_broadcast = 0;
252
Ingo Molnar54ce7f92008-07-10 16:14:56 +0200253#ifdef CONFIG_X86_IO_APIC
254 /*
255 * Turn off IO-APIC detection and initialization:
256 */
257 skip_ioapic_setup = 1;
258#endif
259
Ingo Molnar65253632008-07-10 15:50:37 +0200260 /*
261 * Get Board rev.
262 * First, we have to initialize the 307 part to allow us access
263 * to the GPIO registers. Let's map them at 0x0fc0 which is right
264 * after the PIIX4 PM section.
265 */
266 outb_p(SIO_DEV_SEL, SIO_INDEX);
267 outb_p(SIO_GP_DEV, SIO_DATA); /* Talk to GPIO regs. */
268
269 outb_p(SIO_DEV_MSB, SIO_INDEX);
270 outb_p(SIO_GP_MSB, SIO_DATA); /* MSB of GPIO base address */
271
272 outb_p(SIO_DEV_LSB, SIO_INDEX);
273 outb_p(SIO_GP_LSB, SIO_DATA); /* LSB of GPIO base address */
274
275 outb_p(SIO_DEV_ENB, SIO_INDEX);
276 outb_p(1, SIO_DATA); /* Enable GPIO registers. */
277
278 /*
279 * Now, we have to map the power management section to write
280 * a bit which enables access to the GPIO registers.
281 * What lunatic came up with this shit?
282 */
283 outb_p(SIO_DEV_SEL, SIO_INDEX);
284 outb_p(SIO_PM_DEV, SIO_DATA); /* Talk to GPIO regs. */
285
286 outb_p(SIO_DEV_MSB, SIO_INDEX);
287 outb_p(SIO_PM_MSB, SIO_DATA); /* MSB of PM base address */
288
289 outb_p(SIO_DEV_LSB, SIO_INDEX);
290 outb_p(SIO_PM_LSB, SIO_DATA); /* LSB of PM base address */
291
292 outb_p(SIO_DEV_ENB, SIO_INDEX);
293 outb_p(1, SIO_DATA); /* Enable PM registers. */
294
295 /*
296 * Now, write the PM register which enables the GPIO registers.
297 */
298 outb_p(SIO_PM_FER2, SIO_PM_INDEX);
299 outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
300
301 /*
302 * Now, initialize the GPIO registers.
303 * We want them all to be inputs which is the
304 * power on default, so let's leave them alone.
305 * So, let's just read the board rev!
306 */
307 raw = inb_p(SIO_GP_DATA1);
308 raw &= 0x7f; /* 7 bits of valid board revision ID. */
309
310 if (visws_board_type == VISWS_320) {
311 if (raw < 0x6) {
312 visws_board_rev = 4;
313 } else if (raw < 0xc) {
314 visws_board_rev = 5;
315 } else {
316 visws_board_rev = 6;
317 }
318 } else if (visws_board_type == VISWS_540) {
319 visws_board_rev = 2;
320 } else {
321 visws_board_rev = raw;
322 }
323
324 printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
325 (visws_board_type == VISWS_320 ? "320" :
326 (visws_board_type == VISWS_540 ? "540" :
327 "unknown")), visws_board_rev);
328}
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200329
330#define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
331#define BCD (LI_INTB | LI_INTC | LI_INTD)
332#define ALLDEVS (A01234 | BCD)
333
334static __init void lithium_init(void)
335{
336 set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
337 set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
338
339 if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
340 (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
341 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
342/* panic("This machine is not SGI Visual Workstation 320/540"); */
343 }
344
345 if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
346 (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
347 printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
348/* panic("This machine is not SGI Visual Workstation 320/540"); */
349 }
350
351 li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
352 li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
353}
354
355static __init void cobalt_init(void)
356{
357 /*
358 * On normal SMP PC this is used only with SMP, but we have to
359 * use it and set it up here to start the Cobalt clock
360 */
361 set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
362 setup_local_APIC();
363 printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
364 (unsigned int)apic_read(APIC_LVR),
365 (unsigned int)apic_read(APIC_ID));
366
367 set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
368 set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
369 printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
370 co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
371
372 /* Enable Cobalt APIC being careful to NOT change the ID! */
373 co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
374
375 printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
376 co_apic_read(CO_APIC_ID));
377}
378
Thomas Gleixner428cf902009-08-20 10:35:46 +0200379static void __init visws_trap_init(void)
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200380{
381 lithium_init();
382 cobalt_init();
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200383}
384
385/*
386 * IRQ controller / APIC support:
387 */
388
389static DEFINE_SPINLOCK(cobalt_lock);
390
391/*
392 * Set the given Cobalt APIC Redirection Table entry to point
393 * to the given IDT vector/index.
394 */
395static inline void co_apic_set(int entry, int irq)
396{
397 co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
398 co_apic_write(CO_APIC_HI(entry), 0);
399}
400
401/*
402 * Cobalt (IO)-APIC functions to handle PCI devices.
403 */
404static inline int co_apic_ide0_hack(void)
405{
406 extern char visws_board_type;
407 extern char visws_board_rev;
408
409 if (visws_board_type == VISWS_320 && visws_board_rev == 5)
410 return 5;
411 return CO_APIC_IDE0;
412}
413
414static int is_co_apic(unsigned int irq)
415{
416 if (IS_CO_APIC(irq))
417 return CO_APIC(irq);
418
419 switch (irq) {
420 case 0: return CO_APIC_CPU;
421 case CO_IRQ_IDE0: return co_apic_ide0_hack();
422 case CO_IRQ_IDE1: return CO_APIC_IDE1;
423 default: return -1;
424 }
425}
426
427
428/*
429 * This is the SGI Cobalt (IO-)APIC:
430 */
431
432static void enable_cobalt_irq(unsigned int irq)
433{
434 co_apic_set(is_co_apic(irq), irq);
435}
436
437static void disable_cobalt_irq(unsigned int irq)
438{
439 int entry = is_co_apic(irq);
440
441 co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
442 co_apic_read(CO_APIC_LO(entry));
443}
444
445/*
446 * "irq" really just serves to identify the device. Here is where we
447 * map this to the Cobalt APIC entry where it's physically wired.
448 * This is called via request_irq -> setup_irq -> irq_desc->startup()
449 */
450static unsigned int startup_cobalt_irq(unsigned int irq)
451{
452 unsigned long flags;
Yinghai Lu08678b02008-08-19 20:50:05 -0700453 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200454
455 spin_lock_irqsave(&cobalt_lock, flags);
Yinghai Lu08678b02008-08-19 20:50:05 -0700456 if ((desc->status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
457 desc->status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200458 enable_cobalt_irq(irq);
459 spin_unlock_irqrestore(&cobalt_lock, flags);
460 return 0;
461}
462
463static void ack_cobalt_irq(unsigned int irq)
464{
465 unsigned long flags;
466
467 spin_lock_irqsave(&cobalt_lock, flags);
468 disable_cobalt_irq(irq);
469 apic_write(APIC_EOI, APIC_EIO_ACK);
470 spin_unlock_irqrestore(&cobalt_lock, flags);
471}
472
473static void end_cobalt_irq(unsigned int irq)
474{
475 unsigned long flags;
Yinghai Lu08678b02008-08-19 20:50:05 -0700476 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200477
478 spin_lock_irqsave(&cobalt_lock, flags);
Yinghai Lu08678b02008-08-19 20:50:05 -0700479 if (!(desc->status & (IRQ_DISABLED | IRQ_INPROGRESS)))
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200480 enable_cobalt_irq(irq);
481 spin_unlock_irqrestore(&cobalt_lock, flags);
482}
483
484static struct irq_chip cobalt_irq_type = {
Thomas Gleixner6dbfe5a2009-11-17 18:27:18 +0100485 .name = "Cobalt-APIC",
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200486 .startup = startup_cobalt_irq,
487 .shutdown = disable_cobalt_irq,
488 .enable = enable_cobalt_irq,
489 .disable = disable_cobalt_irq,
490 .ack = ack_cobalt_irq,
491 .end = end_cobalt_irq,
492};
493
494
495/*
496 * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
497 * -- not the manner expected by the code in i8259.c.
498 *
499 * there is a 'master' physical interrupt source that gets sent to
500 * the CPU. But in the chipset there are various 'virtual' interrupts
501 * waiting to be handled. We represent this to Linux through a 'master'
502 * interrupt controller type, and through a special virtual interrupt-
503 * controller. Device drivers only see the virtual interrupt sources.
504 */
505static unsigned int startup_piix4_master_irq(unsigned int irq)
506{
507 init_8259A(0);
508
509 return startup_cobalt_irq(irq);
510}
511
512static void end_piix4_master_irq(unsigned int irq)
513{
514 unsigned long flags;
515
516 spin_lock_irqsave(&cobalt_lock, flags);
517 enable_cobalt_irq(irq);
518 spin_unlock_irqrestore(&cobalt_lock, flags);
519}
520
521static struct irq_chip piix4_master_irq_type = {
Thomas Gleixner6dbfe5a2009-11-17 18:27:18 +0100522 .name = "PIIX4-master",
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200523 .startup = startup_piix4_master_irq,
524 .ack = ack_cobalt_irq,
525 .end = end_piix4_master_irq,
526};
527
528
529static struct irq_chip piix4_virtual_irq_type = {
Thomas Gleixner6dbfe5a2009-11-17 18:27:18 +0100530 .name = "PIIX4-virtual",
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200531 .shutdown = disable_8259A_irq,
532 .enable = enable_8259A_irq,
533 .disable = disable_8259A_irq,
534};
535
536
537/*
538 * PIIX4-8259 master/virtual functions to handle interrupt requests
539 * from legacy devices: floppy, parallel, serial, rtc.
540 *
541 * None of these get Cobalt APIC entries, neither do they have IDT
542 * entries. These interrupts are purely virtual and distributed from
543 * the 'master' interrupt source: CO_IRQ_8259.
544 *
545 * When the 8259 interrupts its handler figures out which of these
546 * devices is interrupting and dispatches to its handler.
547 *
548 * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
549 * enable_irq gets the right irq. This 'master' irq is never directly
550 * manipulated by any driver.
551 */
552static irqreturn_t piix4_master_intr(int irq, void *dev_id)
553{
554 int realirq;
Thomas Gleixnerbf5172d2009-03-09 22:04:45 +0100555 struct irq_desc *desc;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200556 unsigned long flags;
557
558 spin_lock_irqsave(&i8259A_lock, flags);
559
560 /* Find out what's interrupting in the PIIX4 master 8259 */
561 outb(0x0c, 0x20); /* OCW3 Poll command */
562 realirq = inb(0x20);
563
564 /*
565 * Bit 7 == 0 means invalid/spurious
566 */
567 if (unlikely(!(realirq & 0x80)))
568 goto out_unlock;
569
570 realirq &= 7;
571
572 if (unlikely(realirq == 2)) {
573 outb(0x0c, 0xa0);
574 realirq = inb(0xa0);
575
576 if (unlikely(!(realirq & 0x80)))
577 goto out_unlock;
578
579 realirq = (realirq & 7) + 8;
580 }
581
582 /* mask and ack interrupt */
583 cached_irq_mask |= 1 << realirq;
584 if (unlikely(realirq > 7)) {
585 inb(0xa1);
586 outb(cached_slave_mask, 0xa1);
587 outb(0x60 + (realirq & 7), 0xa0);
588 outb(0x60 + 2, 0x20);
589 } else {
590 inb(0x21);
591 outb(cached_master_mask, 0x21);
592 outb(0x60 + realirq, 0x20);
593 }
594
595 spin_unlock_irqrestore(&i8259A_lock, flags);
596
Yinghai Lu08678b02008-08-19 20:50:05 -0700597 desc = irq_to_desc(realirq);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200598
599 /*
600 * handle this 'virtual interrupt' as a Cobalt one now.
601 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200602 kstat_incr_irqs_this_cpu(realirq, desc);
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200603
604 if (likely(desc->action != NULL))
605 handle_IRQ_event(realirq, desc->action);
606
607 if (!(desc->status & IRQ_DISABLED))
608 enable_8259A_irq(realirq);
609
610 return IRQ_HANDLED;
611
612out_unlock:
613 spin_unlock_irqrestore(&i8259A_lock, flags);
614 return IRQ_NONE;
615}
616
617static struct irqaction master_action = {
618 .handler = piix4_master_intr,
619 .name = "PIIX4-8259",
620};
621
622static struct irqaction cascade_action = {
623 .handler = no_action,
624 .name = "cascade",
625};
626
627
628void init_VISWS_APIC_irqs(void)
629{
630 int i;
631
632 for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700633 struct irq_desc *desc = irq_to_desc(i);
634
635 desc->status = IRQ_DISABLED;
636 desc->action = 0;
637 desc->depth = 1;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200638
639 if (i == 0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700640 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200641 }
642 else if (i == CO_IRQ_IDE0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700643 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200644 }
645 else if (i == CO_IRQ_IDE1) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700646 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200647 }
648 else if (i == CO_IRQ_8259) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700649 desc->chip = &piix4_master_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200650 }
651 else if (i < CO_IRQ_APIC0) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700652 desc->chip = &piix4_virtual_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200653 }
654 else if (IS_CO_APIC(i)) {
Yinghai Lu08678b02008-08-19 20:50:05 -0700655 desc->chip = &cobalt_irq_type;
Ingo Molnar26dd9fc2008-07-10 16:21:38 +0200656 }
657 }
658
659 setup_irq(CO_IRQ_8259, &master_action);
660 setup_irq(2, &cascade_action);
661}