11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/arch/alpha/kernel/sys_noritake.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1995 David A Rusling 51da177e4SLinus Torvalds * Copyright (C) 1996 Jay A Estabrook 61da177e4SLinus Torvalds * Copyright (C) 1998, 1999 Richard Henderson 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Code supporting the NORITAKE (AlphaServer 1000A), 91da177e4SLinus Torvalds * CORELLE (AlphaServer 800), and ALCOR Primo (AlphaStation 600A). 101da177e4SLinus Torvalds */ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <linux/kernel.h> 131da177e4SLinus Torvalds #include <linux/types.h> 141da177e4SLinus Torvalds #include <linux/mm.h> 151da177e4SLinus Torvalds #include <linux/sched.h> 161da177e4SLinus Torvalds #include <linux/pci.h> 171da177e4SLinus Torvalds #include <linux/init.h> 181da177e4SLinus Torvalds #include <linux/bitops.h> 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds #include <asm/ptrace.h> 211da177e4SLinus Torvalds #include <asm/system.h> 221da177e4SLinus Torvalds #include <asm/dma.h> 231da177e4SLinus Torvalds #include <asm/irq.h> 241da177e4SLinus Torvalds #include <asm/mmu_context.h> 251da177e4SLinus Torvalds #include <asm/io.h> 261da177e4SLinus Torvalds #include <asm/pgtable.h> 271da177e4SLinus Torvalds #include <asm/core_apecs.h> 281da177e4SLinus Torvalds #include <asm/core_cia.h> 291da177e4SLinus Torvalds #include <asm/tlbflush.h> 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #include "proto.h" 321da177e4SLinus Torvalds #include "irq_impl.h" 331da177e4SLinus Torvalds #include "pci_impl.h" 341da177e4SLinus Torvalds #include "machvec_impl.h" 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds /* Note mask bit is true for ENABLED irqs. */ 371da177e4SLinus Torvalds static int cached_irq_mask; 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds static inline void 401da177e4SLinus Torvalds noritake_update_irq_hw(int irq, int mask) 411da177e4SLinus Torvalds { 421da177e4SLinus Torvalds int port = 0x54a; 431da177e4SLinus Torvalds if (irq >= 32) { 441da177e4SLinus Torvalds mask >>= 16; 451da177e4SLinus Torvalds port = 0x54c; 461da177e4SLinus Torvalds } 471da177e4SLinus Torvalds outw(mask, port); 481da177e4SLinus Torvalds } 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds static void 511da177e4SLinus Torvalds noritake_enable_irq(unsigned int irq) 521da177e4SLinus Torvalds { 531da177e4SLinus Torvalds noritake_update_irq_hw(irq, cached_irq_mask |= 1 << (irq - 16)); 541da177e4SLinus Torvalds } 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds static void 571da177e4SLinus Torvalds noritake_disable_irq(unsigned int irq) 581da177e4SLinus Torvalds { 591da177e4SLinus Torvalds noritake_update_irq_hw(irq, cached_irq_mask &= ~(1 << (irq - 16))); 601da177e4SLinus Torvalds } 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static unsigned int 631da177e4SLinus Torvalds noritake_startup_irq(unsigned int irq) 641da177e4SLinus Torvalds { 651da177e4SLinus Torvalds noritake_enable_irq(irq); 661da177e4SLinus Torvalds return 0; 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds static struct hw_interrupt_type noritake_irq_type = { 701da177e4SLinus Torvalds .typename = "NORITAKE", 711da177e4SLinus Torvalds .startup = noritake_startup_irq, 721da177e4SLinus Torvalds .shutdown = noritake_disable_irq, 731da177e4SLinus Torvalds .enable = noritake_enable_irq, 741da177e4SLinus Torvalds .disable = noritake_disable_irq, 751da177e4SLinus Torvalds .ack = noritake_disable_irq, 761da177e4SLinus Torvalds .end = noritake_enable_irq, 771da177e4SLinus Torvalds }; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds static void 80*7ca56053SAl Viro noritake_device_interrupt(unsigned long vector) 811da177e4SLinus Torvalds { 821da177e4SLinus Torvalds unsigned long pld; 831da177e4SLinus Torvalds unsigned int i; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds /* Read the interrupt summary registers of NORITAKE */ 861da177e4SLinus Torvalds pld = (((unsigned long) inw(0x54c) << 32) 871da177e4SLinus Torvalds | ((unsigned long) inw(0x54a) << 16) 881da177e4SLinus Torvalds | ((unsigned long) inb(0xa0) << 8) 891da177e4SLinus Torvalds | inb(0x20)); 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds /* 921da177e4SLinus Torvalds * Now for every possible bit set, work through them and call 931da177e4SLinus Torvalds * the appropriate interrupt handler. 941da177e4SLinus Torvalds */ 951da177e4SLinus Torvalds while (pld) { 961da177e4SLinus Torvalds i = ffz(~pld); 971da177e4SLinus Torvalds pld &= pld - 1; /* clear least bit set */ 981da177e4SLinus Torvalds if (i < 16) { 99*7ca56053SAl Viro isa_device_interrupt(vector); 1001da177e4SLinus Torvalds } else { 101*7ca56053SAl Viro handle_irq(i, get_irq_regs()); 1021da177e4SLinus Torvalds } 1031da177e4SLinus Torvalds } 1041da177e4SLinus Torvalds } 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds static void 107*7ca56053SAl Viro noritake_srm_device_interrupt(unsigned long vector) 1081da177e4SLinus Torvalds { 1091da177e4SLinus Torvalds int irq; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds irq = (vector - 0x800) >> 4; 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds /* 1141da177e4SLinus Torvalds * I really hate to do this, too, but the NORITAKE SRM console also 1151da177e4SLinus Torvalds * reports PCI vectors *lower* than I expected from the bit numbers 1161da177e4SLinus Torvalds * in the documentation. 1171da177e4SLinus Torvalds * But I really don't want to change the fixup code for allocation 1181da177e4SLinus Torvalds * of IRQs, nor the alpha_irq_mask maintenance stuff, both of which 1191da177e4SLinus Torvalds * look nice and clean now. 1201da177e4SLinus Torvalds * So, here's this additional grotty hack... :-( 1211da177e4SLinus Torvalds */ 1221da177e4SLinus Torvalds if (irq >= 16) 1231da177e4SLinus Torvalds irq = irq + 1; 1241da177e4SLinus Torvalds 125*7ca56053SAl Viro handle_irq(irq, get_irq_regs()); 1261da177e4SLinus Torvalds } 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds static void __init 1291da177e4SLinus Torvalds noritake_init_irq(void) 1301da177e4SLinus Torvalds { 1311da177e4SLinus Torvalds long i; 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds if (alpha_using_srm) 1341da177e4SLinus Torvalds alpha_mv.device_interrupt = noritake_srm_device_interrupt; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds outw(0, 0x54a); 1371da177e4SLinus Torvalds outw(0, 0x54c); 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds for (i = 16; i < 48; ++i) { 1401da177e4SLinus Torvalds irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL; 141d1bef4edSIngo Molnar irq_desc[i].chip = &noritake_irq_type; 1421da177e4SLinus Torvalds } 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds init_i8259a_irqs(); 1451da177e4SLinus Torvalds common_init_isa_dma(); 1461da177e4SLinus Torvalds } 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds /* 1501da177e4SLinus Torvalds * PCI Fixup configuration. 1511da177e4SLinus Torvalds * 1521da177e4SLinus Torvalds * Summary @ 0x542, summary register #1: 1531da177e4SLinus Torvalds * Bit Meaning 1541da177e4SLinus Torvalds * 0 All valid ints from summary regs 2 & 3 1551da177e4SLinus Torvalds * 1 QLOGIC ISP1020A SCSI 1561da177e4SLinus Torvalds * 2 Interrupt Line A from slot 0 1571da177e4SLinus Torvalds * 3 Interrupt Line B from slot 0 1581da177e4SLinus Torvalds * 4 Interrupt Line A from slot 1 1591da177e4SLinus Torvalds * 5 Interrupt line B from slot 1 1601da177e4SLinus Torvalds * 6 Interrupt Line A from slot 2 1611da177e4SLinus Torvalds * 7 Interrupt Line B from slot 2 1621da177e4SLinus Torvalds * 8 Interrupt Line A from slot 3 1631da177e4SLinus Torvalds * 9 Interrupt Line B from slot 3 1641da177e4SLinus Torvalds *10 Interrupt Line A from slot 4 1651da177e4SLinus Torvalds *11 Interrupt Line B from slot 4 1661da177e4SLinus Torvalds *12 Interrupt Line A from slot 5 1671da177e4SLinus Torvalds *13 Interrupt Line B from slot 5 1681da177e4SLinus Torvalds *14 Interrupt Line A from slot 6 1691da177e4SLinus Torvalds *15 Interrupt Line B from slot 6 1701da177e4SLinus Torvalds * 1711da177e4SLinus Torvalds * Summary @ 0x544, summary register #2: 1721da177e4SLinus Torvalds * Bit Meaning 1731da177e4SLinus Torvalds * 0 OR of all unmasked ints in SR #2 1741da177e4SLinus Torvalds * 1 OR of secondary bus ints 1751da177e4SLinus Torvalds * 2 Interrupt Line C from slot 0 1761da177e4SLinus Torvalds * 3 Interrupt Line D from slot 0 1771da177e4SLinus Torvalds * 4 Interrupt Line C from slot 1 1781da177e4SLinus Torvalds * 5 Interrupt line D from slot 1 1791da177e4SLinus Torvalds * 6 Interrupt Line C from slot 2 1801da177e4SLinus Torvalds * 7 Interrupt Line D from slot 2 1811da177e4SLinus Torvalds * 8 Interrupt Line C from slot 3 1821da177e4SLinus Torvalds * 9 Interrupt Line D from slot 3 1831da177e4SLinus Torvalds *10 Interrupt Line C from slot 4 1841da177e4SLinus Torvalds *11 Interrupt Line D from slot 4 1851da177e4SLinus Torvalds *12 Interrupt Line C from slot 5 1861da177e4SLinus Torvalds *13 Interrupt Line D from slot 5 1871da177e4SLinus Torvalds *14 Interrupt Line C from slot 6 1881da177e4SLinus Torvalds *15 Interrupt Line D from slot 6 1891da177e4SLinus Torvalds * 1901da177e4SLinus Torvalds * The device to slot mapping looks like: 1911da177e4SLinus Torvalds * 1921da177e4SLinus Torvalds * Slot Device 1931da177e4SLinus Torvalds * 7 Intel PCI-EISA bridge chip 1941da177e4SLinus Torvalds * 8 DEC PCI-PCI bridge chip 1951da177e4SLinus Torvalds * 11 PCI on board slot 0 1961da177e4SLinus Torvalds * 12 PCI on board slot 1 1971da177e4SLinus Torvalds * 13 PCI on board slot 2 1981da177e4SLinus Torvalds * 1991da177e4SLinus Torvalds * 2001da177e4SLinus Torvalds * This two layered interrupt approach means that we allocate IRQ 16 and 2011da177e4SLinus Torvalds * above for PCI interrupts. The IRQ relates to which bit the interrupt 2021da177e4SLinus Torvalds * comes in on. This makes interrupt processing much easier. 2031da177e4SLinus Torvalds */ 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds static int __init 2061da177e4SLinus Torvalds noritake_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 2071da177e4SLinus Torvalds { 2081da177e4SLinus Torvalds static char irq_tab[15][5] __initdata = { 2091da177e4SLinus Torvalds /*INT INTA INTB INTC INTD */ 2101da177e4SLinus Torvalds /* note: IDSELs 16, 17, and 25 are CORELLE only */ 2111da177e4SLinus Torvalds { 16+1, 16+1, 16+1, 16+1, 16+1}, /* IdSel 16, QLOGIC */ 2121da177e4SLinus Torvalds { -1, -1, -1, -1, -1}, /* IdSel 17, S3 Trio64 */ 2131da177e4SLinus Torvalds { -1, -1, -1, -1, -1}, /* IdSel 18, PCEB */ 2141da177e4SLinus Torvalds { -1, -1, -1, -1, -1}, /* IdSel 19, PPB */ 2151da177e4SLinus Torvalds { -1, -1, -1, -1, -1}, /* IdSel 20, ???? */ 2161da177e4SLinus Torvalds { -1, -1, -1, -1, -1}, /* IdSel 21, ???? */ 2171da177e4SLinus Torvalds { 16+2, 16+2, 16+3, 32+2, 32+3}, /* IdSel 22, slot 0 */ 2181da177e4SLinus Torvalds { 16+4, 16+4, 16+5, 32+4, 32+5}, /* IdSel 23, slot 1 */ 2191da177e4SLinus Torvalds { 16+6, 16+6, 16+7, 32+6, 32+7}, /* IdSel 24, slot 2 */ 2201da177e4SLinus Torvalds { 16+8, 16+8, 16+9, 32+8, 32+9}, /* IdSel 25, slot 3 */ 2211da177e4SLinus Torvalds /* The following 5 are actually on PCI bus 1, which is 2221da177e4SLinus Torvalds across the built-in bridge of the NORITAKE only. */ 2231da177e4SLinus Torvalds { 16+1, 16+1, 16+1, 16+1, 16+1}, /* IdSel 16, QLOGIC */ 2241da177e4SLinus Torvalds { 16+8, 16+8, 16+9, 32+8, 32+9}, /* IdSel 17, slot 3 */ 2251da177e4SLinus Torvalds {16+10, 16+10, 16+11, 32+10, 32+11}, /* IdSel 18, slot 4 */ 2261da177e4SLinus Torvalds {16+12, 16+12, 16+13, 32+12, 32+13}, /* IdSel 19, slot 5 */ 2271da177e4SLinus Torvalds {16+14, 16+14, 16+15, 32+14, 32+15}, /* IdSel 20, slot 6 */ 2281da177e4SLinus Torvalds }; 2291da177e4SLinus Torvalds const long min_idsel = 5, max_idsel = 19, irqs_per_slot = 5; 2301da177e4SLinus Torvalds return COMMON_TABLE_LOOKUP; 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds static u8 __init 2341da177e4SLinus Torvalds noritake_swizzle(struct pci_dev *dev, u8 *pinp) 2351da177e4SLinus Torvalds { 2361da177e4SLinus Torvalds int slot, pin = *pinp; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds if (dev->bus->number == 0) { 2391da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 2401da177e4SLinus Torvalds } 2411da177e4SLinus Torvalds /* Check for the built-in bridge */ 2421da177e4SLinus Torvalds else if (PCI_SLOT(dev->bus->self->devfn) == 8) { 2431da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn) + 15; /* WAG! */ 2441da177e4SLinus Torvalds } 2451da177e4SLinus Torvalds else 2461da177e4SLinus Torvalds { 2471da177e4SLinus Torvalds /* Must be a card-based bridge. */ 2481da177e4SLinus Torvalds do { 2491da177e4SLinus Torvalds if (PCI_SLOT(dev->bus->self->devfn) == 8) { 2501da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn) + 15; 2511da177e4SLinus Torvalds break; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn)) ; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds /* Move up the chain of bridges. */ 2561da177e4SLinus Torvalds dev = dev->bus->self; 2571da177e4SLinus Torvalds /* Slot of the next bridge. */ 2581da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 2591da177e4SLinus Torvalds } while (dev->bus->self); 2601da177e4SLinus Torvalds } 2611da177e4SLinus Torvalds *pinp = pin; 2621da177e4SLinus Torvalds return slot; 2631da177e4SLinus Torvalds } 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds #if defined(CONFIG_ALPHA_GENERIC) || !defined(CONFIG_ALPHA_PRIMO) 2661da177e4SLinus Torvalds static void 2671da177e4SLinus Torvalds noritake_apecs_machine_check(unsigned long vector, unsigned long la_ptr, 2681da177e4SLinus Torvalds struct pt_regs * regs) 2691da177e4SLinus Torvalds { 2701da177e4SLinus Torvalds #define MCHK_NO_DEVSEL 0x205U 2711da177e4SLinus Torvalds #define MCHK_NO_TABT 0x204U 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds struct el_common *mchk_header; 2741da177e4SLinus Torvalds unsigned int code; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds mchk_header = (struct el_common *)la_ptr; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds /* Clear the error before any reporting. */ 2791da177e4SLinus Torvalds mb(); 2801da177e4SLinus Torvalds mb(); /* magic */ 2811da177e4SLinus Torvalds draina(); 2821da177e4SLinus Torvalds apecs_pci_clr_err(); 2831da177e4SLinus Torvalds wrmces(0x7); 2841da177e4SLinus Torvalds mb(); 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds code = mchk_header->code; 2871da177e4SLinus Torvalds process_mcheck_info(vector, la_ptr, regs, "NORITAKE APECS", 2881da177e4SLinus Torvalds (mcheck_expected(0) 2891da177e4SLinus Torvalds && (code == MCHK_NO_DEVSEL 2901da177e4SLinus Torvalds || code == MCHK_NO_TABT))); 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds #endif 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds /* 2961da177e4SLinus Torvalds * The System Vectors 2971da177e4SLinus Torvalds */ 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvalds #if defined(CONFIG_ALPHA_GENERIC) || !defined(CONFIG_ALPHA_PRIMO) 3001da177e4SLinus Torvalds struct alpha_machine_vector noritake_mv __initmv = { 3011da177e4SLinus Torvalds .vector_name = "Noritake", 3021da177e4SLinus Torvalds DO_EV4_MMU, 3031da177e4SLinus Torvalds DO_DEFAULT_RTC, 3041da177e4SLinus Torvalds DO_APECS_IO, 3051da177e4SLinus Torvalds .machine_check = noritake_apecs_machine_check, 3061da177e4SLinus Torvalds .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS, 3071da177e4SLinus Torvalds .min_io_address = EISA_DEFAULT_IO_BASE, 3081da177e4SLinus Torvalds .min_mem_address = APECS_AND_LCA_DEFAULT_MEM_BASE, 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds .nr_irqs = 48, 3111da177e4SLinus Torvalds .device_interrupt = noritake_device_interrupt, 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds .init_arch = apecs_init_arch, 3141da177e4SLinus Torvalds .init_irq = noritake_init_irq, 3151da177e4SLinus Torvalds .init_rtc = common_init_rtc, 3161da177e4SLinus Torvalds .init_pci = common_init_pci, 3171da177e4SLinus Torvalds .pci_map_irq = noritake_map_irq, 3181da177e4SLinus Torvalds .pci_swizzle = noritake_swizzle, 3191da177e4SLinus Torvalds }; 3201da177e4SLinus Torvalds ALIAS_MV(noritake) 3211da177e4SLinus Torvalds #endif 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_PRIMO) 3241da177e4SLinus Torvalds struct alpha_machine_vector noritake_primo_mv __initmv = { 3251da177e4SLinus Torvalds .vector_name = "Noritake-Primo", 3261da177e4SLinus Torvalds DO_EV5_MMU, 3271da177e4SLinus Torvalds DO_DEFAULT_RTC, 3281da177e4SLinus Torvalds DO_CIA_IO, 3291da177e4SLinus Torvalds .machine_check = cia_machine_check, 3301da177e4SLinus Torvalds .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS, 3311da177e4SLinus Torvalds .min_io_address = EISA_DEFAULT_IO_BASE, 3321da177e4SLinus Torvalds .min_mem_address = CIA_DEFAULT_MEM_BASE, 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds .nr_irqs = 48, 3351da177e4SLinus Torvalds .device_interrupt = noritake_device_interrupt, 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds .init_arch = cia_init_arch, 3381da177e4SLinus Torvalds .init_irq = noritake_init_irq, 3391da177e4SLinus Torvalds .init_rtc = common_init_rtc, 3401da177e4SLinus Torvalds .init_pci = cia_init_pci, 3411da177e4SLinus Torvalds .kill_arch = cia_kill_arch, 3421da177e4SLinus Torvalds .pci_map_irq = noritake_map_irq, 3431da177e4SLinus Torvalds .pci_swizzle = noritake_swizzle, 3441da177e4SLinus Torvalds }; 3451da177e4SLinus Torvalds ALIAS_MV(noritake_primo) 3461da177e4SLinus Torvalds #endif 347