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