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