11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/arch/alpha/kernel/sys_ruffian.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, 2000 Richard Henderson 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Code supporting the RUFFIAN. 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <linux/kernel.h> 121da177e4SLinus Torvalds #include <linux/types.h> 131da177e4SLinus Torvalds #include <linux/mm.h> 141da177e4SLinus Torvalds #include <linux/sched.h> 151da177e4SLinus Torvalds #include <linux/pci.h> 161da177e4SLinus Torvalds #include <linux/ioport.h> 171da177e4SLinus Torvalds #include <linux/init.h> 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <asm/ptrace.h> 201da177e4SLinus Torvalds #include <asm/system.h> 211da177e4SLinus Torvalds #include <asm/dma.h> 221da177e4SLinus Torvalds #include <asm/irq.h> 231da177e4SLinus Torvalds #include <asm/mmu_context.h> 241da177e4SLinus Torvalds #include <asm/io.h> 251da177e4SLinus Torvalds #include <asm/pgtable.h> 261da177e4SLinus Torvalds #include <asm/core_cia.h> 271da177e4SLinus Torvalds #include <asm/tlbflush.h> 281da177e4SLinus Torvalds #include <asm/8253pit.h> 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds #include "proto.h" 311da177e4SLinus Torvalds #include "irq_impl.h" 321da177e4SLinus Torvalds #include "pci_impl.h" 331da177e4SLinus Torvalds #include "machvec_impl.h" 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds static void __init 371da177e4SLinus Torvalds ruffian_init_irq(void) 381da177e4SLinus Torvalds { 391da177e4SLinus Torvalds /* Invert 6&7 for i82371 */ 401da177e4SLinus Torvalds *(vulp)PYXIS_INT_HILO = 0x000000c0UL; mb(); 411da177e4SLinus Torvalds *(vulp)PYXIS_INT_CNFG = 0x00002064UL; mb(); /* all clear */ 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds outb(0x11,0xA0); 441da177e4SLinus Torvalds outb(0x08,0xA1); 451da177e4SLinus Torvalds outb(0x02,0xA1); 461da177e4SLinus Torvalds outb(0x01,0xA1); 471da177e4SLinus Torvalds outb(0xFF,0xA1); 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds outb(0x11,0x20); 501da177e4SLinus Torvalds outb(0x00,0x21); 511da177e4SLinus Torvalds outb(0x04,0x21); 521da177e4SLinus Torvalds outb(0x01,0x21); 531da177e4SLinus Torvalds outb(0xFF,0x21); 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds /* Finish writing the 82C59A PIC Operation Control Words */ 561da177e4SLinus Torvalds outb(0x20,0xA0); 571da177e4SLinus Torvalds outb(0x20,0x20); 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds init_i8259a_irqs(); 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds /* Not interested in the bogus interrupts (0,3,6), 621da177e4SLinus Torvalds NMI (1), HALT (2), flash (5), or 21142 (8). */ 631da177e4SLinus Torvalds init_pyxis_irqs(0x16f0000); 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds common_init_isa_dma(); 661da177e4SLinus Torvalds } 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds #define RUFFIAN_LATCH ((PIT_TICK_RATE + HZ / 2) / HZ) 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds static void __init 711da177e4SLinus Torvalds ruffian_init_rtc(void) 721da177e4SLinus Torvalds { 731da177e4SLinus Torvalds /* Ruffian does not have the RTC connected to the CPU timer 741da177e4SLinus Torvalds interrupt. Instead, it uses the PIT connected to IRQ 0. */ 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds /* Setup interval timer. */ 771da177e4SLinus Torvalds outb(0x34, 0x43); /* binary, mode 2, LSB/MSB, ch 0 */ 781da177e4SLinus Torvalds outb(RUFFIAN_LATCH & 0xff, 0x40); /* LSB */ 791da177e4SLinus Torvalds outb(RUFFIAN_LATCH >> 8, 0x40); /* MSB */ 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds outb(0xb6, 0x43); /* pit counter 2: speaker */ 821da177e4SLinus Torvalds outb(0x31, 0x42); 831da177e4SLinus Torvalds outb(0x13, 0x42); 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds setup_irq(0, &timer_irqaction); 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds static void 891da177e4SLinus Torvalds ruffian_kill_arch (int mode) 901da177e4SLinus Torvalds { 911da177e4SLinus Torvalds cia_kill_arch(mode); 921da177e4SLinus Torvalds #if 0 931da177e4SLinus Torvalds /* This only causes re-entry to ARCSBIOS */ 941da177e4SLinus Torvalds /* Perhaps this works for other PYXIS as well? */ 951da177e4SLinus Torvalds *(vuip) PYXIS_RESET = 0x0000dead; 961da177e4SLinus Torvalds mb(); 971da177e4SLinus Torvalds #endif 981da177e4SLinus Torvalds } 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds /* 1011da177e4SLinus Torvalds * Interrupt routing: 1021da177e4SLinus Torvalds * 1031da177e4SLinus Torvalds * Primary bus 1041da177e4SLinus Torvalds * IdSel INTA INTB INTC INTD 1051da177e4SLinus Torvalds * 21052 13 - - - - 1061da177e4SLinus Torvalds * SIO 14 23 - - - 1071da177e4SLinus Torvalds * 21143 15 44 - - - 1081da177e4SLinus Torvalds * Slot 0 17 43 42 41 40 1091da177e4SLinus Torvalds * 1101da177e4SLinus Torvalds * Secondary bus 1111da177e4SLinus Torvalds * IdSel INTA INTB INTC INTD 1121da177e4SLinus Torvalds * Slot 0 8 (18) 19 18 17 16 1131da177e4SLinus Torvalds * Slot 1 9 (19) 31 30 29 28 1141da177e4SLinus Torvalds * Slot 2 10 (20) 27 26 25 24 1151da177e4SLinus Torvalds * Slot 3 11 (21) 39 38 37 36 1161da177e4SLinus Torvalds * Slot 4 12 (22) 35 34 33 32 1171da177e4SLinus Torvalds * 53c875 13 (23) 20 - - - 1181da177e4SLinus Torvalds * 1191da177e4SLinus Torvalds */ 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds static int __init 1221da177e4SLinus Torvalds ruffian_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 1231da177e4SLinus Torvalds { 1241da177e4SLinus Torvalds static char irq_tab[11][5] __initdata = { 1251da177e4SLinus Torvalds /*INT INTA INTB INTC INTD */ 1261da177e4SLinus Torvalds {-1, -1, -1, -1, -1}, /* IdSel 13, 21052 */ 1271da177e4SLinus Torvalds {-1, -1, -1, -1, -1}, /* IdSel 14, SIO */ 1281da177e4SLinus Torvalds {44, 44, 44, 44, 44}, /* IdSel 15, 21143 */ 1291da177e4SLinus Torvalds {-1, -1, -1, -1, -1}, /* IdSel 16, none */ 1301da177e4SLinus Torvalds {43, 43, 42, 41, 40}, /* IdSel 17, 64-bit slot */ 1311da177e4SLinus Torvalds /* the next 6 are actually on PCI bus 1, across the bridge */ 1321da177e4SLinus Torvalds {19, 19, 18, 17, 16}, /* IdSel 8, slot 0 */ 1331da177e4SLinus Torvalds {31, 31, 30, 29, 28}, /* IdSel 9, slot 1 */ 1341da177e4SLinus Torvalds {27, 27, 26, 25, 24}, /* IdSel 10, slot 2 */ 1351da177e4SLinus Torvalds {39, 39, 38, 37, 36}, /* IdSel 11, slot 3 */ 1361da177e4SLinus Torvalds {35, 35, 34, 33, 32}, /* IdSel 12, slot 4 */ 1371da177e4SLinus Torvalds {20, 20, 20, 20, 20}, /* IdSel 13, 53c875 */ 1381da177e4SLinus Torvalds }; 1391da177e4SLinus Torvalds const long min_idsel = 13, max_idsel = 23, irqs_per_slot = 5; 1401da177e4SLinus Torvalds return COMMON_TABLE_LOOKUP; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds static u8 __init 1441da177e4SLinus Torvalds ruffian_swizzle(struct pci_dev *dev, u8 *pinp) 1451da177e4SLinus Torvalds { 1461da177e4SLinus Torvalds int slot, pin = *pinp; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds if (dev->bus->number == 0) { 1491da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds /* Check for the built-in bridge. */ 1521da177e4SLinus Torvalds else if (PCI_SLOT(dev->bus->self->devfn) == 13) { 1531da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn) + 10; 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds else 1561da177e4SLinus Torvalds { 1571da177e4SLinus Torvalds /* Must be a card-based bridge. */ 1581da177e4SLinus Torvalds do { 1591da177e4SLinus Torvalds if (PCI_SLOT(dev->bus->self->devfn) == 13) { 1601da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn) + 10; 1611da177e4SLinus Torvalds break; 1621da177e4SLinus Torvalds } 163*1be9baa0SBjorn Helgaas pin = pci_swizzle_interrupt_pin(dev, pin); 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds /* Move up the chain of bridges. */ 1661da177e4SLinus Torvalds dev = dev->bus->self; 1671da177e4SLinus Torvalds /* Slot of the next bridge. */ 1681da177e4SLinus Torvalds slot = PCI_SLOT(dev->devfn); 1691da177e4SLinus Torvalds } while (dev->bus->self); 1701da177e4SLinus Torvalds } 1711da177e4SLinus Torvalds *pinp = pin; 1721da177e4SLinus Torvalds return slot; 1731da177e4SLinus Torvalds } 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds #ifdef BUILDING_FOR_MILO 1761da177e4SLinus Torvalds /* 1771da177e4SLinus Torvalds * The DeskStation Ruffian motherboard firmware does not place 1781da177e4SLinus Torvalds * the memory size in the PALimpure area. Therefore, we use 1791da177e4SLinus Torvalds * the Bank Configuration Registers in PYXIS to obtain the size. 1801da177e4SLinus Torvalds */ 1811da177e4SLinus Torvalds static unsigned long __init 1821da177e4SLinus Torvalds ruffian_get_bank_size(unsigned long offset) 1831da177e4SLinus Torvalds { 1841da177e4SLinus Torvalds unsigned long bank_addr, bank, ret = 0; 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds /* Valid offsets are: 0x800, 0x840 and 0x880 1871da177e4SLinus Torvalds since Ruffian only uses three banks. */ 1881da177e4SLinus Torvalds bank_addr = (unsigned long)PYXIS_MCR + offset; 1891da177e4SLinus Torvalds bank = *(vulp)bank_addr; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds /* Check BANK_ENABLE */ 1921da177e4SLinus Torvalds if (bank & 0x01) { 1931da177e4SLinus Torvalds static unsigned long size[] __initdata = { 1941da177e4SLinus Torvalds 0x40000000UL, /* 0x00, 1G */ 1951da177e4SLinus Torvalds 0x20000000UL, /* 0x02, 512M */ 1961da177e4SLinus Torvalds 0x10000000UL, /* 0x04, 256M */ 1971da177e4SLinus Torvalds 0x08000000UL, /* 0x06, 128M */ 1981da177e4SLinus Torvalds 0x04000000UL, /* 0x08, 64M */ 1991da177e4SLinus Torvalds 0x02000000UL, /* 0x0a, 32M */ 2001da177e4SLinus Torvalds 0x01000000UL, /* 0x0c, 16M */ 2011da177e4SLinus Torvalds 0x00800000UL, /* 0x0e, 8M */ 2021da177e4SLinus Torvalds 0x80000000UL, /* 0x10, 2G */ 2031da177e4SLinus Torvalds }; 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds bank = (bank & 0x1e) >> 1; 20625c8716cSTobias Klauser if (bank < ARRAY_SIZE(size)) 2071da177e4SLinus Torvalds ret = size[bank]; 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds return ret; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds #endif /* BUILDING_FOR_MILO */ 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds /* 2151da177e4SLinus Torvalds * The System Vector 2161da177e4SLinus Torvalds */ 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds struct alpha_machine_vector ruffian_mv __initmv = { 2191da177e4SLinus Torvalds .vector_name = "Ruffian", 2201da177e4SLinus Torvalds DO_EV5_MMU, 2211da177e4SLinus Torvalds DO_DEFAULT_RTC, 2221da177e4SLinus Torvalds DO_PYXIS_IO, 2231da177e4SLinus Torvalds .machine_check = cia_machine_check, 2241da177e4SLinus Torvalds .max_isa_dma_address = ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS, 2251da177e4SLinus Torvalds .min_io_address = DEFAULT_IO_BASE, 2261da177e4SLinus Torvalds .min_mem_address = DEFAULT_MEM_BASE, 2271da177e4SLinus Torvalds .pci_dac_offset = PYXIS_DAC_OFFSET, 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds .nr_irqs = 48, 2301da177e4SLinus Torvalds .device_interrupt = pyxis_device_interrupt, 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds .init_arch = pyxis_init_arch, 2331da177e4SLinus Torvalds .init_irq = ruffian_init_irq, 2341da177e4SLinus Torvalds .init_rtc = ruffian_init_rtc, 2351da177e4SLinus Torvalds .init_pci = cia_init_pci, 2361da177e4SLinus Torvalds .kill_arch = ruffian_kill_arch, 2371da177e4SLinus Torvalds .pci_map_irq = ruffian_map_irq, 2381da177e4SLinus Torvalds .pci_swizzle = ruffian_swizzle, 2391da177e4SLinus Torvalds }; 2401da177e4SLinus Torvalds ALIAS_MV(ruffian) 241