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 54c0497664SThomas Gleixner eiger_enable_irq(struct irq_data *d) 551da177e4SLinus Torvalds { 56c0497664SThomas Gleixner unsigned int irq = d->irq; 571da177e4SLinus Torvalds unsigned long mask; 581da177e4SLinus Torvalds mask = (cached_irq_mask[irq >= 64] &= ~(1UL << (irq & 63))); 591da177e4SLinus Torvalds eiger_update_irq_hw(irq, mask); 601da177e4SLinus Torvalds } 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static void 63c0497664SThomas Gleixner eiger_disable_irq(struct irq_data *d) 641da177e4SLinus Torvalds { 65c0497664SThomas Gleixner unsigned int irq = d->irq; 661da177e4SLinus Torvalds unsigned long mask; 671da177e4SLinus Torvalds mask = (cached_irq_mask[irq >= 64] |= 1UL << (irq & 63)); 681da177e4SLinus Torvalds eiger_update_irq_hw(irq, mask); 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds 7144377f62SThomas Gleixner static struct irq_chip eiger_irq_type = { 728ab1221cSThomas Gleixner .name = "EIGER", 73c0497664SThomas Gleixner .irq_unmask = eiger_enable_irq, 74c0497664SThomas Gleixner .irq_mask = eiger_disable_irq, 75c0497664SThomas Gleixner .irq_mask_ack = eiger_disable_irq, 761da177e4SLinus Torvalds }; 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds static void 797ca56053SAl Viro eiger_device_interrupt(unsigned long vector) 801da177e4SLinus Torvalds { 811da177e4SLinus Torvalds unsigned intstatus; 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds /* 841da177e4SLinus Torvalds * The PALcode will have passed us vectors 0x800 or 0x810, 851da177e4SLinus Torvalds * which are fairly arbitrary values and serve only to tell 861da177e4SLinus Torvalds * us whether an interrupt has come in on IRQ0 or IRQ1. If 871da177e4SLinus Torvalds * it's IRQ1 it's a PCI interrupt; if it's IRQ0, it's 881da177e4SLinus Torvalds * probably ISA, but PCI interrupts can come through IRQ0 891da177e4SLinus Torvalds * as well if the interrupt controller isn't in accelerated 901da177e4SLinus Torvalds * mode. 911da177e4SLinus Torvalds * 921da177e4SLinus Torvalds * OTOH, the accelerator thing doesn't seem to be working 931da177e4SLinus Torvalds * overly well, so what we'll do instead is try directly 941da177e4SLinus Torvalds * examining the Master Interrupt Register to see if it's a 951da177e4SLinus Torvalds * PCI interrupt, and if _not_ then we'll pass it on to the 961da177e4SLinus Torvalds * ISA handler. 971da177e4SLinus Torvalds */ 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds intstatus = inw(0x500) & 15; 1001da177e4SLinus Torvalds if (intstatus) { 1011da177e4SLinus Torvalds /* 1021da177e4SLinus Torvalds * This is a PCI interrupt. Check each bit and 1031da177e4SLinus Torvalds * despatch an interrupt if it's set. 1041da177e4SLinus Torvalds */ 1051da177e4SLinus Torvalds 1063dbb8c62SAl Viro if (intstatus & 8) handle_irq(16+3); 1073dbb8c62SAl Viro if (intstatus & 4) handle_irq(16+2); 1083dbb8c62SAl Viro if (intstatus & 2) handle_irq(16+1); 1093dbb8c62SAl Viro if (intstatus & 1) handle_irq(16+0); 1101da177e4SLinus Torvalds } else { 1117ca56053SAl Viro isa_device_interrupt(vector); 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds static void 1167ca56053SAl Viro eiger_srm_device_interrupt(unsigned long vector) 1171da177e4SLinus Torvalds { 1181da177e4SLinus Torvalds int irq = (vector - 0x800) >> 4; 1193dbb8c62SAl Viro handle_irq(irq); 1201da177e4SLinus Torvalds } 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds static void __init 1231da177e4SLinus Torvalds eiger_init_irq(void) 1241da177e4SLinus Torvalds { 1251da177e4SLinus Torvalds long i; 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds outb(0, DMA1_RESET_REG); 1281da177e4SLinus Torvalds outb(0, DMA2_RESET_REG); 1291da177e4SLinus Torvalds outb(DMA_MODE_CASCADE, DMA2_MODE_REG); 1301da177e4SLinus Torvalds outb(0, DMA2_MASK_REG); 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds if (alpha_using_srm) 1331da177e4SLinus Torvalds alpha_mv.device_interrupt = eiger_srm_device_interrupt; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds for (i = 16; i < 128; i += 16) 1361da177e4SLinus Torvalds eiger_update_irq_hw(i, -1); 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds init_i8259a_irqs(); 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds for (i = 16; i < 128; ++i) { 1417d209c81SKyle McMartin set_irq_chip_and_handler(i, &eiger_irq_type, handle_level_irq); 142c0497664SThomas Gleixner irq_set_status_flags(i, IRQ_LEVEL); 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds } 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds static int __init 1471da177e4SLinus Torvalds eiger_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 1481da177e4SLinus Torvalds { 1491da177e4SLinus Torvalds u8 irq_orig; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds /* The SRM console has already calculated out the IRQ value's for 1521da177e4SLinus Torvalds option cards. As this works lets just read in the value already 1531da177e4SLinus Torvalds set and change it to a useable value by Linux. 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds All the IRQ values generated by the console are greater than 90, 1561da177e4SLinus Torvalds so we subtract 80 because it is (90 - allocated ISA IRQ's). */ 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq_orig); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds return irq_orig - 0x80; 1611da177e4SLinus Torvalds } 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds static u8 __init 1641da177e4SLinus Torvalds eiger_swizzle(struct pci_dev *dev, u8 *pinp) 1651da177e4SLinus Torvalds { 1661da177e4SLinus Torvalds struct pci_controller *hose = dev->sysdata; 1671da177e4SLinus Torvalds int slot, pin = *pinp; 1681da177e4SLinus Torvalds int bridge_count = 0; 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds /* Find the number of backplane bridges. */ 1711da177e4SLinus Torvalds int backplane = inw(0x502) & 0x0f; 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds switch (backplane) 1741da177e4SLinus Torvalds { 1751da177e4SLinus Torvalds case 0x00: bridge_count = 0; break; /* No bridges */ 1761da177e4SLinus Torvalds case 0x01: bridge_count = 1; break; /* 1 */ 1771da177e4SLinus Torvalds case 0x03: bridge_count = 2; break; /* 2 */ 1781da177e4SLinus Torvalds case 0x07: bridge_count = 3; break; /* 3 */ 1791da177e4SLinus Torvalds case 0x0f: bridge_count = 4; break; /* 4 */ 1801da177e4SLinus Torvalds }; 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 1831da177e4SLinus Torvalds while (dev->bus->self) { 1841da177e4SLinus Torvalds /* Check for built-in bridges on hose 0. */ 1851da177e4SLinus Torvalds if (hose->index == 0 1861da177e4SLinus Torvalds && (PCI_SLOT(dev->bus->self->devfn) 1871da177e4SLinus Torvalds > 20 - bridge_count)) { 1881da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 1891da177e4SLinus Torvalds break; 1901da177e4SLinus Torvalds } 1911da177e4SLinus Torvalds /* Must be a card-based bridge. */ 1921be9baa0SBjorn Helgaas pin = pci_swizzle_interrupt_pin(dev, pin); 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds /* Move up the chain of bridges. */ 1951da177e4SLinus Torvalds dev = dev->bus->self; 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds *pinp = pin; 1981da177e4SLinus Torvalds return slot; 1991da177e4SLinus Torvalds } 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds /* 2021da177e4SLinus Torvalds * The System Vectors 2031da177e4SLinus Torvalds */ 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds struct alpha_machine_vector eiger_mv __initmv = { 2061da177e4SLinus Torvalds .vector_name = "Eiger", 2071da177e4SLinus Torvalds DO_EV6_MMU, 2081da177e4SLinus Torvalds DO_DEFAULT_RTC, 2091da177e4SLinus Torvalds DO_TSUNAMI_IO, 2101da177e4SLinus Torvalds .machine_check = tsunami_machine_check, 2111da177e4SLinus Torvalds .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS, 2121da177e4SLinus Torvalds .min_io_address = DEFAULT_IO_BASE, 2131da177e4SLinus Torvalds .min_mem_address = DEFAULT_MEM_BASE, 2141da177e4SLinus Torvalds .pci_dac_offset = TSUNAMI_DAC_OFFSET, 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds .nr_irqs = 128, 2171da177e4SLinus Torvalds .device_interrupt = eiger_device_interrupt, 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds .init_arch = tsunami_init_arch, 2201da177e4SLinus Torvalds .init_irq = eiger_init_irq, 2211da177e4SLinus Torvalds .init_rtc = common_init_rtc, 2221da177e4SLinus Torvalds .init_pci = common_init_pci, 2231da177e4SLinus Torvalds .kill_arch = tsunami_kill_arch, 2241da177e4SLinus Torvalds .pci_map_irq = eiger_map_irq, 2251da177e4SLinus Torvalds .pci_swizzle = eiger_swizzle, 2261da177e4SLinus Torvalds }; 2271da177e4SLinus Torvalds ALIAS_MV(eiger) 228