11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/arch/alpha/kernel/sys_eiger.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1995 David A Rusling 51da177e4SLinus Torvalds * Copyright (C) 1996, 1999 Jay A Estabrook 61da177e4SLinus Torvalds * Copyright (C) 1998, 1999 Richard Henderson 71da177e4SLinus Torvalds * Copyright (C) 1999 Iain Grant 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Code supporting the EIGER (EV6+TSUNAMI). 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/pci.h> 271da177e4SLinus Torvalds #include <asm/pgtable.h> 281da177e4SLinus Torvalds #include <asm/core_tsunami.h> 291da177e4SLinus Torvalds #include <asm/hwrpb.h> 301da177e4SLinus Torvalds #include <asm/tlbflush.h> 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #include "proto.h" 331da177e4SLinus Torvalds #include "irq_impl.h" 341da177e4SLinus Torvalds #include "pci_impl.h" 351da177e4SLinus Torvalds #include "machvec_impl.h" 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds /* Note that this interrupt code is identical to TAKARA. */ 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds /* Note mask bit is true for DISABLED irqs. */ 411da177e4SLinus Torvalds static unsigned long cached_irq_mask[2] = { -1, -1 }; 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds static inline void 441da177e4SLinus Torvalds eiger_update_irq_hw(unsigned long irq, unsigned long mask) 451da177e4SLinus Torvalds { 461da177e4SLinus Torvalds int regaddr; 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds mask = (irq >= 64 ? mask << 16 : mask >> ((irq - 16) & 0x30)); 491da177e4SLinus Torvalds regaddr = 0x510 + (((irq - 16) >> 2) & 0x0c); 501da177e4SLinus Torvalds outl(mask & 0xffff0000UL, regaddr); 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds static inline void 541da177e4SLinus Torvalds eiger_enable_irq(unsigned int irq) 551da177e4SLinus Torvalds { 561da177e4SLinus Torvalds unsigned long mask; 571da177e4SLinus Torvalds mask = (cached_irq_mask[irq >= 64] &= ~(1UL << (irq & 63))); 581da177e4SLinus Torvalds eiger_update_irq_hw(irq, mask); 591da177e4SLinus Torvalds } 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds static void 621da177e4SLinus Torvalds eiger_disable_irq(unsigned int irq) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds unsigned long mask; 651da177e4SLinus Torvalds mask = (cached_irq_mask[irq >= 64] |= 1UL << (irq & 63)); 661da177e4SLinus Torvalds eiger_update_irq_hw(irq, mask); 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds static unsigned int 701da177e4SLinus Torvalds eiger_startup_irq(unsigned int irq) 711da177e4SLinus Torvalds { 721da177e4SLinus Torvalds eiger_enable_irq(irq); 731da177e4SLinus Torvalds return 0; /* never anything pending */ 741da177e4SLinus Torvalds } 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds static void 771da177e4SLinus Torvalds eiger_end_irq(unsigned int irq) 781da177e4SLinus Torvalds { 791da177e4SLinus Torvalds if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) 801da177e4SLinus Torvalds eiger_enable_irq(irq); 811da177e4SLinus Torvalds } 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds static struct hw_interrupt_type eiger_irq_type = { 841da177e4SLinus Torvalds .typename = "EIGER", 851da177e4SLinus Torvalds .startup = eiger_startup_irq, 861da177e4SLinus Torvalds .shutdown = eiger_disable_irq, 871da177e4SLinus Torvalds .enable = eiger_enable_irq, 881da177e4SLinus Torvalds .disable = eiger_disable_irq, 891da177e4SLinus Torvalds .ack = eiger_disable_irq, 901da177e4SLinus Torvalds .end = eiger_end_irq, 911da177e4SLinus Torvalds }; 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds static void 947ca56053SAl Viro eiger_device_interrupt(unsigned long vector) 951da177e4SLinus Torvalds { 961da177e4SLinus Torvalds unsigned intstatus; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds /* 991da177e4SLinus Torvalds * The PALcode will have passed us vectors 0x800 or 0x810, 1001da177e4SLinus Torvalds * which are fairly arbitrary values and serve only to tell 1011da177e4SLinus Torvalds * us whether an interrupt has come in on IRQ0 or IRQ1. If 1021da177e4SLinus Torvalds * it's IRQ1 it's a PCI interrupt; if it's IRQ0, it's 1031da177e4SLinus Torvalds * probably ISA, but PCI interrupts can come through IRQ0 1041da177e4SLinus Torvalds * as well if the interrupt controller isn't in accelerated 1051da177e4SLinus Torvalds * mode. 1061da177e4SLinus Torvalds * 1071da177e4SLinus Torvalds * OTOH, the accelerator thing doesn't seem to be working 1081da177e4SLinus Torvalds * overly well, so what we'll do instead is try directly 1091da177e4SLinus Torvalds * examining the Master Interrupt Register to see if it's a 1101da177e4SLinus Torvalds * PCI interrupt, and if _not_ then we'll pass it on to the 1111da177e4SLinus Torvalds * ISA handler. 1121da177e4SLinus Torvalds */ 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds intstatus = inw(0x500) & 15; 1151da177e4SLinus Torvalds if (intstatus) { 1161da177e4SLinus Torvalds /* 1171da177e4SLinus Torvalds * This is a PCI interrupt. Check each bit and 1181da177e4SLinus Torvalds * despatch an interrupt if it's set. 1191da177e4SLinus Torvalds */ 1201da177e4SLinus Torvalds 1213dbb8c62SAl Viro if (intstatus & 8) handle_irq(16+3); 1223dbb8c62SAl Viro if (intstatus & 4) handle_irq(16+2); 1233dbb8c62SAl Viro if (intstatus & 2) handle_irq(16+1); 1243dbb8c62SAl Viro if (intstatus & 1) handle_irq(16+0); 1251da177e4SLinus Torvalds } else { 1267ca56053SAl Viro isa_device_interrupt(vector); 1271da177e4SLinus Torvalds } 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds static void 1317ca56053SAl Viro eiger_srm_device_interrupt(unsigned long vector) 1321da177e4SLinus Torvalds { 1331da177e4SLinus Torvalds int irq = (vector - 0x800) >> 4; 1343dbb8c62SAl Viro handle_irq(irq); 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds static void __init 1381da177e4SLinus Torvalds eiger_init_irq(void) 1391da177e4SLinus Torvalds { 1401da177e4SLinus Torvalds long i; 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds outb(0, DMA1_RESET_REG); 1431da177e4SLinus Torvalds outb(0, DMA2_RESET_REG); 1441da177e4SLinus Torvalds outb(DMA_MODE_CASCADE, DMA2_MODE_REG); 1451da177e4SLinus Torvalds outb(0, DMA2_MASK_REG); 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds if (alpha_using_srm) 1481da177e4SLinus Torvalds alpha_mv.device_interrupt = eiger_srm_device_interrupt; 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds for (i = 16; i < 128; i += 16) 1511da177e4SLinus Torvalds eiger_update_irq_hw(i, -1); 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds init_i8259a_irqs(); 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds for (i = 16; i < 128; ++i) { 1561da177e4SLinus Torvalds irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL; 157d1bef4edSIngo Molnar irq_desc[i].chip = &eiger_irq_type; 1581da177e4SLinus Torvalds } 1591da177e4SLinus Torvalds } 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds static int __init 1621da177e4SLinus Torvalds eiger_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 1631da177e4SLinus Torvalds { 1641da177e4SLinus Torvalds u8 irq_orig; 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds /* The SRM console has already calculated out the IRQ value's for 1671da177e4SLinus Torvalds option cards. As this works lets just read in the value already 1681da177e4SLinus Torvalds set and change it to a useable value by Linux. 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds All the IRQ values generated by the console are greater than 90, 1711da177e4SLinus Torvalds so we subtract 80 because it is (90 - allocated ISA IRQ's). */ 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq_orig); 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds return irq_orig - 0x80; 1761da177e4SLinus Torvalds } 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds static u8 __init 1791da177e4SLinus Torvalds eiger_swizzle(struct pci_dev *dev, u8 *pinp) 1801da177e4SLinus Torvalds { 1811da177e4SLinus Torvalds struct pci_controller *hose = dev->sysdata; 1821da177e4SLinus Torvalds int slot, pin = *pinp; 1831da177e4SLinus Torvalds int bridge_count = 0; 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds /* Find the number of backplane bridges. */ 1861da177e4SLinus Torvalds int backplane = inw(0x502) & 0x0f; 1871da177e4SLinus Torvalds 1881da177e4SLinus Torvalds switch (backplane) 1891da177e4SLinus Torvalds { 1901da177e4SLinus Torvalds case 0x00: bridge_count = 0; break; /* No bridges */ 1911da177e4SLinus Torvalds case 0x01: bridge_count = 1; break; /* 1 */ 1921da177e4SLinus Torvalds case 0x03: bridge_count = 2; break; /* 2 */ 1931da177e4SLinus Torvalds case 0x07: bridge_count = 3; break; /* 3 */ 1941da177e4SLinus Torvalds case 0x0f: bridge_count = 4; break; /* 4 */ 1951da177e4SLinus Torvalds }; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 1981da177e4SLinus Torvalds while (dev->bus->self) { 1991da177e4SLinus Torvalds /* Check for built-in bridges on hose 0. */ 2001da177e4SLinus Torvalds if (hose->index == 0 2011da177e4SLinus Torvalds && (PCI_SLOT(dev->bus->self->devfn) 2021da177e4SLinus Torvalds > 20 - bridge_count)) { 2031da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 2041da177e4SLinus Torvalds break; 2051da177e4SLinus Torvalds } 2061da177e4SLinus Torvalds /* Must be a card-based bridge. */ 2071be9baa0SBjorn Helgaas pin = pci_swizzle_interrupt_pin(dev, pin); 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds /* Move up the chain of bridges. */ 2101da177e4SLinus Torvalds dev = dev->bus->self; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds *pinp = pin; 2131da177e4SLinus Torvalds return slot; 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds /* 2171da177e4SLinus Torvalds * The System Vectors 2181da177e4SLinus Torvalds */ 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds struct alpha_machine_vector eiger_mv __initmv = { 2211da177e4SLinus Torvalds .vector_name = "Eiger", 2221da177e4SLinus Torvalds DO_EV6_MMU, 2231da177e4SLinus Torvalds DO_DEFAULT_RTC, 2241da177e4SLinus Torvalds DO_TSUNAMI_IO, 2251da177e4SLinus Torvalds .machine_check = tsunami_machine_check, 2261da177e4SLinus Torvalds .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS, 2271da177e4SLinus Torvalds .min_io_address = DEFAULT_IO_BASE, 2281da177e4SLinus Torvalds .min_mem_address = DEFAULT_MEM_BASE, 2291da177e4SLinus Torvalds .pci_dac_offset = TSUNAMI_DAC_OFFSET, 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds .nr_irqs = 128, 2321da177e4SLinus Torvalds .device_interrupt = eiger_device_interrupt, 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds .init_arch = tsunami_init_arch, 2351da177e4SLinus Torvalds .init_irq = eiger_init_irq, 2361da177e4SLinus Torvalds .init_rtc = common_init_rtc, 2371da177e4SLinus Torvalds .init_pci = common_init_pci, 2381da177e4SLinus Torvalds .kill_arch = tsunami_kill_arch, 2391da177e4SLinus Torvalds .pci_map_irq = eiger_map_irq, 2401da177e4SLinus Torvalds .pci_swizzle = eiger_swizzle, 2411da177e4SLinus Torvalds }; 2421da177e4SLinus Torvalds ALIAS_MV(eiger) 243