18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci** DINO manager 48c2ecf20Sopenharmony_ci** 58c2ecf20Sopenharmony_ci** (c) Copyright 1999 Red Hat Software 68c2ecf20Sopenharmony_ci** (c) Copyright 1999 SuSE GmbH 78c2ecf20Sopenharmony_ci** (c) Copyright 1999,2000 Hewlett-Packard Company 88c2ecf20Sopenharmony_ci** (c) Copyright 2000 Grant Grundler 98c2ecf20Sopenharmony_ci** (c) Copyright 2006-2019 Helge Deller 108c2ecf20Sopenharmony_ci** 118c2ecf20Sopenharmony_ci** 128c2ecf20Sopenharmony_ci** This module provides access to Dino PCI bus (config/IOport spaces) 138c2ecf20Sopenharmony_ci** and helps manage Dino IRQ lines. 148c2ecf20Sopenharmony_ci** 158c2ecf20Sopenharmony_ci** Dino interrupt handling is a bit complicated. 168c2ecf20Sopenharmony_ci** Dino always writes to the broadcast EIR via irr0 for now. 178c2ecf20Sopenharmony_ci** (BIG WARNING: using broadcast EIR is a really bad thing for SMP!) 188c2ecf20Sopenharmony_ci** Only one processor interrupt is used for the 11 IRQ line 198c2ecf20Sopenharmony_ci** inputs to dino. 208c2ecf20Sopenharmony_ci** 218c2ecf20Sopenharmony_ci** The different between Built-in Dino and Card-Mode 228c2ecf20Sopenharmony_ci** dino is in chip initialization and pci device initialization. 238c2ecf20Sopenharmony_ci** 248c2ecf20Sopenharmony_ci** Linux drivers can only use Card-Mode Dino if pci devices I/O port 258c2ecf20Sopenharmony_ci** BARs are configured and used by the driver. Programming MMIO address 268c2ecf20Sopenharmony_ci** requires substantial knowledge of available Host I/O address ranges 278c2ecf20Sopenharmony_ci** is currently not supported. Port/Config accessor functions are the 288c2ecf20Sopenharmony_ci** same. "BIOS" differences are handled within the existing routines. 298c2ecf20Sopenharmony_ci*/ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* Changes : 328c2ecf20Sopenharmony_ci** 2001-06-14 : Clement Moyroud (moyroudc@esiee.fr) 338c2ecf20Sopenharmony_ci** - added support for the integrated RS232. 348c2ecf20Sopenharmony_ci*/ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* 378c2ecf20Sopenharmony_ci** TODO: create a virtual address for each Dino HPA. 388c2ecf20Sopenharmony_ci** GSC code might be able to do this since IODC data tells us 398c2ecf20Sopenharmony_ci** how many pages are used. PCI subsystem could (must?) do this 408c2ecf20Sopenharmony_ci** for PCI drivers devices which implement/use MMIO registers. 418c2ecf20Sopenharmony_ci*/ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#include <linux/delay.h> 448c2ecf20Sopenharmony_ci#include <linux/types.h> 458c2ecf20Sopenharmony_ci#include <linux/kernel.h> 468c2ecf20Sopenharmony_ci#include <linux/pci.h> 478c2ecf20Sopenharmony_ci#include <linux/init.h> 488c2ecf20Sopenharmony_ci#include <linux/ioport.h> 498c2ecf20Sopenharmony_ci#include <linux/slab.h> 508c2ecf20Sopenharmony_ci#include <linux/interrupt.h> /* for struct irqaction */ 518c2ecf20Sopenharmony_ci#include <linux/spinlock.h> /* for spinlock_t and prototypes */ 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#include <asm/pdc.h> 548c2ecf20Sopenharmony_ci#include <asm/page.h> 558c2ecf20Sopenharmony_ci#include <asm/io.h> 568c2ecf20Sopenharmony_ci#include <asm/hardware.h> 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#include "gsc.h" 598c2ecf20Sopenharmony_ci#include "iommu.h" 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#undef DINO_DEBUG 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#ifdef DINO_DEBUG 648c2ecf20Sopenharmony_ci#define DBG(x...) printk(x) 658c2ecf20Sopenharmony_ci#else 668c2ecf20Sopenharmony_ci#define DBG(x...) 678c2ecf20Sopenharmony_ci#endif 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* 708c2ecf20Sopenharmony_ci** Config accessor functions only pass in the 8-bit bus number 718c2ecf20Sopenharmony_ci** and not the 8-bit "PCI Segment" number. Each Dino will be 728c2ecf20Sopenharmony_ci** assigned a PCI bus number based on "when" it's discovered. 738c2ecf20Sopenharmony_ci** 748c2ecf20Sopenharmony_ci** The "secondary" bus number is set to this before calling 758c2ecf20Sopenharmony_ci** pci_scan_bus(). If any PPB's are present, the scan will 768c2ecf20Sopenharmony_ci** discover them and update the "secondary" and "subordinate" 778c2ecf20Sopenharmony_ci** fields in Dino's pci_bus structure. 788c2ecf20Sopenharmony_ci** 798c2ecf20Sopenharmony_ci** Changes in the configuration *will* result in a different 808c2ecf20Sopenharmony_ci** bus number for each dino. 818c2ecf20Sopenharmony_ci*/ 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define is_card_dino(id) ((id)->hw_type == HPHW_A_DMA) 848c2ecf20Sopenharmony_ci#define is_cujo(id) ((id)->hversion == 0x682) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define DINO_IAR0 0x004 878c2ecf20Sopenharmony_ci#define DINO_IODC_ADDR 0x008 888c2ecf20Sopenharmony_ci#define DINO_IODC_DATA_0 0x008 898c2ecf20Sopenharmony_ci#define DINO_IODC_DATA_1 0x008 908c2ecf20Sopenharmony_ci#define DINO_IRR0 0x00C 918c2ecf20Sopenharmony_ci#define DINO_IAR1 0x010 928c2ecf20Sopenharmony_ci#define DINO_IRR1 0x014 938c2ecf20Sopenharmony_ci#define DINO_IMR 0x018 948c2ecf20Sopenharmony_ci#define DINO_IPR 0x01C 958c2ecf20Sopenharmony_ci#define DINO_TOC_ADDR 0x020 968c2ecf20Sopenharmony_ci#define DINO_ICR 0x024 978c2ecf20Sopenharmony_ci#define DINO_ILR 0x028 988c2ecf20Sopenharmony_ci#define DINO_IO_COMMAND 0x030 998c2ecf20Sopenharmony_ci#define DINO_IO_STATUS 0x034 1008c2ecf20Sopenharmony_ci#define DINO_IO_CONTROL 0x038 1018c2ecf20Sopenharmony_ci#define DINO_IO_GSC_ERR_RESP 0x040 1028c2ecf20Sopenharmony_ci#define DINO_IO_ERR_INFO 0x044 1038c2ecf20Sopenharmony_ci#define DINO_IO_PCI_ERR_RESP 0x048 1048c2ecf20Sopenharmony_ci#define DINO_IO_FBB_EN 0x05c 1058c2ecf20Sopenharmony_ci#define DINO_IO_ADDR_EN 0x060 1068c2ecf20Sopenharmony_ci#define DINO_PCI_ADDR 0x064 1078c2ecf20Sopenharmony_ci#define DINO_CONFIG_DATA 0x068 1088c2ecf20Sopenharmony_ci#define DINO_IO_DATA 0x06c 1098c2ecf20Sopenharmony_ci#define DINO_MEM_DATA 0x070 /* Dino 3.x only */ 1108c2ecf20Sopenharmony_ci#define DINO_GSC2X_CONFIG 0x7b4 1118c2ecf20Sopenharmony_ci#define DINO_GMASK 0x800 1128c2ecf20Sopenharmony_ci#define DINO_PAMR 0x804 1138c2ecf20Sopenharmony_ci#define DINO_PAPR 0x808 1148c2ecf20Sopenharmony_ci#define DINO_DAMODE 0x80c 1158c2ecf20Sopenharmony_ci#define DINO_PCICMD 0x810 1168c2ecf20Sopenharmony_ci#define DINO_PCISTS 0x814 1178c2ecf20Sopenharmony_ci#define DINO_MLTIM 0x81c 1188c2ecf20Sopenharmony_ci#define DINO_BRDG_FEAT 0x820 1198c2ecf20Sopenharmony_ci#define DINO_PCIROR 0x824 1208c2ecf20Sopenharmony_ci#define DINO_PCIWOR 0x828 1218c2ecf20Sopenharmony_ci#define DINO_TLTIM 0x830 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define DINO_IRQS 11 /* bits 0-10 are architected */ 1248c2ecf20Sopenharmony_ci#define DINO_IRR_MASK 0x5ff /* only 10 bits are implemented */ 1258c2ecf20Sopenharmony_ci#define DINO_LOCAL_IRQS (DINO_IRQS+1) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define DINO_MASK_IRQ(x) (1<<(x)) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define PCIINTA 0x001 1308c2ecf20Sopenharmony_ci#define PCIINTB 0x002 1318c2ecf20Sopenharmony_ci#define PCIINTC 0x004 1328c2ecf20Sopenharmony_ci#define PCIINTD 0x008 1338c2ecf20Sopenharmony_ci#define PCIINTE 0x010 1348c2ecf20Sopenharmony_ci#define PCIINTF 0x020 1358c2ecf20Sopenharmony_ci#define GSCEXTINT 0x040 1368c2ecf20Sopenharmony_ci/* #define xxx 0x080 - bit 7 is "default" */ 1378c2ecf20Sopenharmony_ci/* #define xxx 0x100 - bit 8 not used */ 1388c2ecf20Sopenharmony_ci/* #define xxx 0x200 - bit 9 not used */ 1398c2ecf20Sopenharmony_ci#define RS232INT 0x400 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistruct dino_device 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci struct pci_hba_data hba; /* 'C' inheritance - must be first */ 1448c2ecf20Sopenharmony_ci spinlock_t dinosaur_pen; 1458c2ecf20Sopenharmony_ci u32 imr; /* IRQ's which are enabled */ 1468c2ecf20Sopenharmony_ci struct gsc_irq gsc_irq; 1478c2ecf20Sopenharmony_ci int global_irq[DINO_LOCAL_IRQS]; /* map IMR bit to global irq */ 1488c2ecf20Sopenharmony_ci#ifdef DINO_DEBUG 1498c2ecf20Sopenharmony_ci unsigned int dino_irr0; /* save most recent IRQ line stat */ 1508c2ecf20Sopenharmony_ci#endif 1518c2ecf20Sopenharmony_ci}; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic inline struct dino_device *DINO_DEV(struct pci_hba_data *hba) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci return container_of(hba, struct dino_device, hba); 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci/* 1598c2ecf20Sopenharmony_ci * Dino Configuration Space Accessor Functions 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#define DINO_CFG_TOK(bus,dfn,pos) ((u32) ((bus)<<16 | (dfn)<<8 | (pos))) 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/* 1658c2ecf20Sopenharmony_ci * keep the current highest bus count to assist in allocating busses. This 1668c2ecf20Sopenharmony_ci * tries to keep a global bus count total so that when we discover an 1678c2ecf20Sopenharmony_ci * entirely new bus, it can be given a unique bus number. 1688c2ecf20Sopenharmony_ci */ 1698c2ecf20Sopenharmony_cistatic int dino_current_bus = 0; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic int dino_cfg_read(struct pci_bus *bus, unsigned int devfn, int where, 1728c2ecf20Sopenharmony_ci int size, u32 *val) 1738c2ecf20Sopenharmony_ci{ 1748c2ecf20Sopenharmony_ci struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge)); 1758c2ecf20Sopenharmony_ci u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start; 1768c2ecf20Sopenharmony_ci u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3); 1778c2ecf20Sopenharmony_ci void __iomem *base_addr = d->hba.base_addr; 1788c2ecf20Sopenharmony_ci unsigned long flags; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci DBG("%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where, 1818c2ecf20Sopenharmony_ci size); 1828c2ecf20Sopenharmony_ci spin_lock_irqsave(&d->dinosaur_pen, flags); 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci /* tell HW which CFG address */ 1858c2ecf20Sopenharmony_ci __raw_writel(v, base_addr + DINO_PCI_ADDR); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* generate cfg read cycle */ 1888c2ecf20Sopenharmony_ci if (size == 1) { 1898c2ecf20Sopenharmony_ci *val = readb(base_addr + DINO_CONFIG_DATA + (where & 3)); 1908c2ecf20Sopenharmony_ci } else if (size == 2) { 1918c2ecf20Sopenharmony_ci *val = readw(base_addr + DINO_CONFIG_DATA + (where & 2)); 1928c2ecf20Sopenharmony_ci } else if (size == 4) { 1938c2ecf20Sopenharmony_ci *val = readl(base_addr + DINO_CONFIG_DATA); 1948c2ecf20Sopenharmony_ci } 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&d->dinosaur_pen, flags); 1978c2ecf20Sopenharmony_ci return 0; 1988c2ecf20Sopenharmony_ci} 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* 2018c2ecf20Sopenharmony_ci * Dino address stepping "feature": 2028c2ecf20Sopenharmony_ci * When address stepping, Dino attempts to drive the bus one cycle too soon 2038c2ecf20Sopenharmony_ci * even though the type of cycle (config vs. MMIO) might be different. 2048c2ecf20Sopenharmony_ci * The read of Ven/Prod ID is harmless and avoids Dino's address stepping. 2058c2ecf20Sopenharmony_ci */ 2068c2ecf20Sopenharmony_cistatic int dino_cfg_write(struct pci_bus *bus, unsigned int devfn, int where, 2078c2ecf20Sopenharmony_ci int size, u32 val) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge)); 2108c2ecf20Sopenharmony_ci u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start; 2118c2ecf20Sopenharmony_ci u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3); 2128c2ecf20Sopenharmony_ci void __iomem *base_addr = d->hba.base_addr; 2138c2ecf20Sopenharmony_ci unsigned long flags; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci DBG("%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where, 2168c2ecf20Sopenharmony_ci size); 2178c2ecf20Sopenharmony_ci spin_lock_irqsave(&d->dinosaur_pen, flags); 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci /* avoid address stepping feature */ 2208c2ecf20Sopenharmony_ci __raw_writel(v & 0xffffff00, base_addr + DINO_PCI_ADDR); 2218c2ecf20Sopenharmony_ci __raw_readl(base_addr + DINO_CONFIG_DATA); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci /* tell HW which CFG address */ 2248c2ecf20Sopenharmony_ci __raw_writel(v, base_addr + DINO_PCI_ADDR); 2258c2ecf20Sopenharmony_ci /* generate cfg read cycle */ 2268c2ecf20Sopenharmony_ci if (size == 1) { 2278c2ecf20Sopenharmony_ci writeb(val, base_addr + DINO_CONFIG_DATA + (where & 3)); 2288c2ecf20Sopenharmony_ci } else if (size == 2) { 2298c2ecf20Sopenharmony_ci writew(val, base_addr + DINO_CONFIG_DATA + (where & 2)); 2308c2ecf20Sopenharmony_ci } else if (size == 4) { 2318c2ecf20Sopenharmony_ci writel(val, base_addr + DINO_CONFIG_DATA); 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&d->dinosaur_pen, flags); 2358c2ecf20Sopenharmony_ci return 0; 2368c2ecf20Sopenharmony_ci} 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_cistatic struct pci_ops dino_cfg_ops = { 2398c2ecf20Sopenharmony_ci .read = dino_cfg_read, 2408c2ecf20Sopenharmony_ci .write = dino_cfg_write, 2418c2ecf20Sopenharmony_ci}; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/* 2458c2ecf20Sopenharmony_ci * Dino "I/O Port" Space Accessor Functions 2468c2ecf20Sopenharmony_ci * 2478c2ecf20Sopenharmony_ci * Many PCI devices don't require use of I/O port space (eg Tulip, 2488c2ecf20Sopenharmony_ci * NCR720) since they export the same registers to both MMIO and 2498c2ecf20Sopenharmony_ci * I/O port space. Performance is going to stink if drivers use 2508c2ecf20Sopenharmony_ci * I/O port instead of MMIO. 2518c2ecf20Sopenharmony_ci */ 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci#define DINO_PORT_IN(type, size, mask) \ 2548c2ecf20Sopenharmony_cistatic u##size dino_in##size (struct pci_hba_data *d, u16 addr) \ 2558c2ecf20Sopenharmony_ci{ \ 2568c2ecf20Sopenharmony_ci u##size v; \ 2578c2ecf20Sopenharmony_ci unsigned long flags; \ 2588c2ecf20Sopenharmony_ci spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \ 2598c2ecf20Sopenharmony_ci /* tell HW which IO Port address */ \ 2608c2ecf20Sopenharmony_ci __raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \ 2618c2ecf20Sopenharmony_ci /* generate I/O PORT read cycle */ \ 2628c2ecf20Sopenharmony_ci v = read##type(d->base_addr+DINO_IO_DATA+(addr&mask)); \ 2638c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \ 2648c2ecf20Sopenharmony_ci return v; \ 2658c2ecf20Sopenharmony_ci} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ciDINO_PORT_IN(b, 8, 3) 2688c2ecf20Sopenharmony_ciDINO_PORT_IN(w, 16, 2) 2698c2ecf20Sopenharmony_ciDINO_PORT_IN(l, 32, 0) 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci#define DINO_PORT_OUT(type, size, mask) \ 2728c2ecf20Sopenharmony_cistatic void dino_out##size (struct pci_hba_data *d, u16 addr, u##size val) \ 2738c2ecf20Sopenharmony_ci{ \ 2748c2ecf20Sopenharmony_ci unsigned long flags; \ 2758c2ecf20Sopenharmony_ci spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \ 2768c2ecf20Sopenharmony_ci /* tell HW which IO port address */ \ 2778c2ecf20Sopenharmony_ci __raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \ 2788c2ecf20Sopenharmony_ci /* generate cfg write cycle */ \ 2798c2ecf20Sopenharmony_ci write##type(val, d->base_addr+DINO_IO_DATA+(addr&mask)); \ 2808c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \ 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ciDINO_PORT_OUT(b, 8, 3) 2848c2ecf20Sopenharmony_ciDINO_PORT_OUT(w, 16, 2) 2858c2ecf20Sopenharmony_ciDINO_PORT_OUT(l, 32, 0) 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cistatic struct pci_port_ops dino_port_ops = { 2888c2ecf20Sopenharmony_ci .inb = dino_in8, 2898c2ecf20Sopenharmony_ci .inw = dino_in16, 2908c2ecf20Sopenharmony_ci .inl = dino_in32, 2918c2ecf20Sopenharmony_ci .outb = dino_out8, 2928c2ecf20Sopenharmony_ci .outw = dino_out16, 2938c2ecf20Sopenharmony_ci .outl = dino_out32 2948c2ecf20Sopenharmony_ci}; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistatic void dino_mask_irq(struct irq_data *d) 2978c2ecf20Sopenharmony_ci{ 2988c2ecf20Sopenharmony_ci struct dino_device *dino_dev = irq_data_get_irq_chip_data(d); 2998c2ecf20Sopenharmony_ci int local_irq = gsc_find_local_irq(d->irq, dino_dev->global_irq, DINO_LOCAL_IRQS); 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci DBG(KERN_WARNING "%s(0x%px, %d)\n", __func__, dino_dev, d->irq); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci /* Clear the matching bit in the IMR register */ 3048c2ecf20Sopenharmony_ci dino_dev->imr &= ~(DINO_MASK_IRQ(local_irq)); 3058c2ecf20Sopenharmony_ci __raw_writel(dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR); 3068c2ecf20Sopenharmony_ci} 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistatic void dino_unmask_irq(struct irq_data *d) 3098c2ecf20Sopenharmony_ci{ 3108c2ecf20Sopenharmony_ci struct dino_device *dino_dev = irq_data_get_irq_chip_data(d); 3118c2ecf20Sopenharmony_ci int local_irq = gsc_find_local_irq(d->irq, dino_dev->global_irq, DINO_LOCAL_IRQS); 3128c2ecf20Sopenharmony_ci u32 tmp; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci DBG(KERN_WARNING "%s(0x%px, %d)\n", __func__, dino_dev, d->irq); 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci /* 3178c2ecf20Sopenharmony_ci ** clear pending IRQ bits 3188c2ecf20Sopenharmony_ci ** 3198c2ecf20Sopenharmony_ci ** This does NOT change ILR state! 3208c2ecf20Sopenharmony_ci ** See comment below for ILR usage. 3218c2ecf20Sopenharmony_ci */ 3228c2ecf20Sopenharmony_ci __raw_readl(dino_dev->hba.base_addr+DINO_IPR); 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci /* set the matching bit in the IMR register */ 3258c2ecf20Sopenharmony_ci dino_dev->imr |= DINO_MASK_IRQ(local_irq); /* used in dino_isr() */ 3268c2ecf20Sopenharmony_ci __raw_writel( dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR); 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci /* Emulate "Level Triggered" Interrupt 3298c2ecf20Sopenharmony_ci ** Basically, a driver is blowing it if the IRQ line is asserted 3308c2ecf20Sopenharmony_ci ** while the IRQ is disabled. But tulip.c seems to do that.... 3318c2ecf20Sopenharmony_ci ** Give 'em a kluge award and a nice round of applause! 3328c2ecf20Sopenharmony_ci ** 3338c2ecf20Sopenharmony_ci ** The gsc_write will generate an interrupt which invokes dino_isr(). 3348c2ecf20Sopenharmony_ci ** dino_isr() will read IPR and find nothing. But then catch this 3358c2ecf20Sopenharmony_ci ** when it also checks ILR. 3368c2ecf20Sopenharmony_ci */ 3378c2ecf20Sopenharmony_ci tmp = __raw_readl(dino_dev->hba.base_addr+DINO_ILR); 3388c2ecf20Sopenharmony_ci if (tmp & DINO_MASK_IRQ(local_irq)) { 3398c2ecf20Sopenharmony_ci DBG(KERN_WARNING "%s(): IRQ asserted! (ILR 0x%x)\n", 3408c2ecf20Sopenharmony_ci __func__, tmp); 3418c2ecf20Sopenharmony_ci gsc_writel(dino_dev->gsc_irq.txn_data, dino_dev->gsc_irq.txn_addr); 3428c2ecf20Sopenharmony_ci } 3438c2ecf20Sopenharmony_ci} 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 3468c2ecf20Sopenharmony_cistatic int dino_set_affinity_irq(struct irq_data *d, const struct cpumask *dest, 3478c2ecf20Sopenharmony_ci bool force) 3488c2ecf20Sopenharmony_ci{ 3498c2ecf20Sopenharmony_ci struct dino_device *dino_dev = irq_data_get_irq_chip_data(d); 3508c2ecf20Sopenharmony_ci struct cpumask tmask; 3518c2ecf20Sopenharmony_ci int cpu_irq; 3528c2ecf20Sopenharmony_ci u32 eim; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci if (!cpumask_and(&tmask, dest, cpu_online_mask)) 3558c2ecf20Sopenharmony_ci return -EINVAL; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci cpu_irq = cpu_check_affinity(d, &tmask); 3588c2ecf20Sopenharmony_ci if (cpu_irq < 0) 3598c2ecf20Sopenharmony_ci return cpu_irq; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci dino_dev->gsc_irq.txn_addr = txn_affinity_addr(d->irq, cpu_irq); 3628c2ecf20Sopenharmony_ci eim = ((u32) dino_dev->gsc_irq.txn_addr) | dino_dev->gsc_irq.txn_data; 3638c2ecf20Sopenharmony_ci __raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci irq_data_update_effective_affinity(d, &tmask); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci return IRQ_SET_MASK_OK; 3688c2ecf20Sopenharmony_ci} 3698c2ecf20Sopenharmony_ci#endif 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_cistatic struct irq_chip dino_interrupt_type = { 3728c2ecf20Sopenharmony_ci .name = "GSC-PCI", 3738c2ecf20Sopenharmony_ci .irq_unmask = dino_unmask_irq, 3748c2ecf20Sopenharmony_ci .irq_mask = dino_mask_irq, 3758c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 3768c2ecf20Sopenharmony_ci .irq_set_affinity = dino_set_affinity_irq, 3778c2ecf20Sopenharmony_ci#endif 3788c2ecf20Sopenharmony_ci}; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci/* 3828c2ecf20Sopenharmony_ci * Handle a Processor interrupt generated by Dino. 3838c2ecf20Sopenharmony_ci * 3848c2ecf20Sopenharmony_ci * ilr_loop counter is a kluge to prevent a "stuck" IRQ line from 3858c2ecf20Sopenharmony_ci * wedging the CPU. Could be removed or made optional at some point. 3868c2ecf20Sopenharmony_ci */ 3878c2ecf20Sopenharmony_cistatic irqreturn_t dino_isr(int irq, void *intr_dev) 3888c2ecf20Sopenharmony_ci{ 3898c2ecf20Sopenharmony_ci struct dino_device *dino_dev = intr_dev; 3908c2ecf20Sopenharmony_ci u32 mask; 3918c2ecf20Sopenharmony_ci int ilr_loop = 100; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci /* read and acknowledge pending interrupts */ 3948c2ecf20Sopenharmony_ci#ifdef DINO_DEBUG 3958c2ecf20Sopenharmony_ci dino_dev->dino_irr0 = 3968c2ecf20Sopenharmony_ci#endif 3978c2ecf20Sopenharmony_ci mask = __raw_readl(dino_dev->hba.base_addr+DINO_IRR0) & DINO_IRR_MASK; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci if (mask == 0) 4008c2ecf20Sopenharmony_ci return IRQ_NONE; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ciilr_again: 4038c2ecf20Sopenharmony_ci do { 4048c2ecf20Sopenharmony_ci int local_irq = __ffs(mask); 4058c2ecf20Sopenharmony_ci int irq = dino_dev->global_irq[local_irq]; 4068c2ecf20Sopenharmony_ci DBG(KERN_DEBUG "%s(%d, %p) mask 0x%x\n", 4078c2ecf20Sopenharmony_ci __func__, irq, intr_dev, mask); 4088c2ecf20Sopenharmony_ci generic_handle_irq(irq); 4098c2ecf20Sopenharmony_ci mask &= ~DINO_MASK_IRQ(local_irq); 4108c2ecf20Sopenharmony_ci } while (mask); 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci /* Support for level triggered IRQ lines. 4138c2ecf20Sopenharmony_ci ** 4148c2ecf20Sopenharmony_ci ** Dropping this support would make this routine *much* faster. 4158c2ecf20Sopenharmony_ci ** But since PCI requires level triggered IRQ line to share lines... 4168c2ecf20Sopenharmony_ci ** device drivers may assume lines are level triggered (and not 4178c2ecf20Sopenharmony_ci ** edge triggered like EISA/ISA can be). 4188c2ecf20Sopenharmony_ci */ 4198c2ecf20Sopenharmony_ci mask = __raw_readl(dino_dev->hba.base_addr+DINO_ILR) & dino_dev->imr; 4208c2ecf20Sopenharmony_ci if (mask) { 4218c2ecf20Sopenharmony_ci if (--ilr_loop > 0) 4228c2ecf20Sopenharmony_ci goto ilr_again; 4238c2ecf20Sopenharmony_ci pr_warn_ratelimited("Dino 0x%px: stuck interrupt %d\n", 4248c2ecf20Sopenharmony_ci dino_dev->hba.base_addr, mask); 4258c2ecf20Sopenharmony_ci } 4268c2ecf20Sopenharmony_ci return IRQ_HANDLED; 4278c2ecf20Sopenharmony_ci} 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic void dino_assign_irq(struct dino_device *dino, int local_irq, int *irqp) 4308c2ecf20Sopenharmony_ci{ 4318c2ecf20Sopenharmony_ci int irq = gsc_assign_irq(&dino_interrupt_type, dino); 4328c2ecf20Sopenharmony_ci if (irq == NO_IRQ) 4338c2ecf20Sopenharmony_ci return; 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci *irqp = irq; 4368c2ecf20Sopenharmony_ci dino->global_irq[local_irq] = irq; 4378c2ecf20Sopenharmony_ci} 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_cistatic void dino_choose_irq(struct parisc_device *dev, void *ctrl) 4408c2ecf20Sopenharmony_ci{ 4418c2ecf20Sopenharmony_ci int irq; 4428c2ecf20Sopenharmony_ci struct dino_device *dino = ctrl; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci switch (dev->id.sversion) { 4458c2ecf20Sopenharmony_ci case 0x00084: irq = 8; break; /* PS/2 */ 4468c2ecf20Sopenharmony_ci case 0x0008c: irq = 10; break; /* RS232 */ 4478c2ecf20Sopenharmony_ci case 0x00096: irq = 8; break; /* PS/2 */ 4488c2ecf20Sopenharmony_ci default: return; /* Unknown */ 4498c2ecf20Sopenharmony_ci } 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci dino_assign_irq(dino, irq, &dev->irq); 4528c2ecf20Sopenharmony_ci} 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci/* 4568c2ecf20Sopenharmony_ci * Cirrus 6832 Cardbus reports wrong irq on RDI Tadpole PARISC Laptop (deller@gmx.de) 4578c2ecf20Sopenharmony_ci * (the irqs are off-by-one, not sure yet if this is a cirrus, dino-hardware or dino-driver problem...) 4588c2ecf20Sopenharmony_ci */ 4598c2ecf20Sopenharmony_cistatic void quirk_cirrus_cardbus(struct pci_dev *dev) 4608c2ecf20Sopenharmony_ci{ 4618c2ecf20Sopenharmony_ci u8 new_irq = dev->irq - 1; 4628c2ecf20Sopenharmony_ci printk(KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d\n", 4638c2ecf20Sopenharmony_ci pci_name(dev), dev->irq, new_irq); 4648c2ecf20Sopenharmony_ci dev->irq = new_irq; 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ciDECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6832, quirk_cirrus_cardbus ); 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci#ifdef CONFIG_TULIP 4698c2ecf20Sopenharmony_ci/* Check if PCI device is behind a Card-mode Dino. */ 4708c2ecf20Sopenharmony_cistatic int pci_dev_is_behind_card_dino(struct pci_dev *dev) 4718c2ecf20Sopenharmony_ci{ 4728c2ecf20Sopenharmony_ci struct dino_device *dino_dev; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci dino_dev = DINO_DEV(parisc_walk_tree(dev->bus->bridge)); 4758c2ecf20Sopenharmony_ci return is_card_dino(&dino_dev->hba.dev->id); 4768c2ecf20Sopenharmony_ci} 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_cistatic void pci_fixup_tulip(struct pci_dev *dev) 4798c2ecf20Sopenharmony_ci{ 4808c2ecf20Sopenharmony_ci if (!pci_dev_is_behind_card_dino(dev)) 4818c2ecf20Sopenharmony_ci return; 4828c2ecf20Sopenharmony_ci if (!(pci_resource_flags(dev, 1) & IORESOURCE_MEM)) 4838c2ecf20Sopenharmony_ci return; 4848c2ecf20Sopenharmony_ci pr_warn("%s: HP HSC-PCI Cards with card-mode Dino not yet supported.\n", 4858c2ecf20Sopenharmony_ci pci_name(dev)); 4868c2ecf20Sopenharmony_ci /* Disable this card by zeroing the PCI resources */ 4878c2ecf20Sopenharmony_ci memset(&dev->resource[0], 0, sizeof(dev->resource[0])); 4888c2ecf20Sopenharmony_ci memset(&dev->resource[1], 0, sizeof(dev->resource[1])); 4898c2ecf20Sopenharmony_ci} 4908c2ecf20Sopenharmony_ciDECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_DEC, PCI_ANY_ID, pci_fixup_tulip); 4918c2ecf20Sopenharmony_ci#endif /* CONFIG_TULIP */ 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_cistatic void __init 4948c2ecf20Sopenharmony_cidino_bios_init(void) 4958c2ecf20Sopenharmony_ci{ 4968c2ecf20Sopenharmony_ci DBG("dino_bios_init\n"); 4978c2ecf20Sopenharmony_ci} 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci/* 5008c2ecf20Sopenharmony_ci * dino_card_setup - Set up the memory space for a Dino in card mode. 5018c2ecf20Sopenharmony_ci * @bus: the bus under this dino 5028c2ecf20Sopenharmony_ci * 5038c2ecf20Sopenharmony_ci * Claim an 8MB chunk of unused IO space and call the generic PCI routines 5048c2ecf20Sopenharmony_ci * to set up the addresses of the devices on this bus. 5058c2ecf20Sopenharmony_ci */ 5068c2ecf20Sopenharmony_ci#define _8MB 0x00800000UL 5078c2ecf20Sopenharmony_cistatic void __init 5088c2ecf20Sopenharmony_cidino_card_setup(struct pci_bus *bus, void __iomem *base_addr) 5098c2ecf20Sopenharmony_ci{ 5108c2ecf20Sopenharmony_ci int i; 5118c2ecf20Sopenharmony_ci struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge)); 5128c2ecf20Sopenharmony_ci struct resource *res; 5138c2ecf20Sopenharmony_ci char name[128]; 5148c2ecf20Sopenharmony_ci int size; 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci res = &dino_dev->hba.lmmio_space; 5178c2ecf20Sopenharmony_ci res->flags = IORESOURCE_MEM; 5188c2ecf20Sopenharmony_ci size = scnprintf(name, sizeof(name), "Dino LMMIO (%s)", 5198c2ecf20Sopenharmony_ci dev_name(bus->bridge)); 5208c2ecf20Sopenharmony_ci res->name = kmalloc(size+1, GFP_KERNEL); 5218c2ecf20Sopenharmony_ci if(res->name) 5228c2ecf20Sopenharmony_ci strcpy((char *)res->name, name); 5238c2ecf20Sopenharmony_ci else 5248c2ecf20Sopenharmony_ci res->name = dino_dev->hba.lmmio_space.name; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB, 5288c2ecf20Sopenharmony_ci F_EXTEND(0xf0000000UL) | _8MB, 5298c2ecf20Sopenharmony_ci F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) { 5308c2ecf20Sopenharmony_ci struct pci_dev *dev, *tmp; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci printk(KERN_ERR "Dino: cannot attach bus %s\n", 5338c2ecf20Sopenharmony_ci dev_name(bus->bridge)); 5348c2ecf20Sopenharmony_ci /* kill the bus, we can't do anything with it */ 5358c2ecf20Sopenharmony_ci list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { 5368c2ecf20Sopenharmony_ci list_del(&dev->bus_list); 5378c2ecf20Sopenharmony_ci } 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci return; 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci bus->resource[1] = res; 5428c2ecf20Sopenharmony_ci bus->resource[0] = &(dino_dev->hba.io_space); 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci /* Now tell dino what range it has */ 5458c2ecf20Sopenharmony_ci for (i = 1; i < 31; i++) { 5468c2ecf20Sopenharmony_ci if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB))) 5478c2ecf20Sopenharmony_ci break; 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %p\n", 5508c2ecf20Sopenharmony_ci i, res->start, base_addr + DINO_IO_ADDR_EN); 5518c2ecf20Sopenharmony_ci __raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN); 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_cistatic void __init 5558c2ecf20Sopenharmony_cidino_card_fixup(struct pci_dev *dev) 5568c2ecf20Sopenharmony_ci{ 5578c2ecf20Sopenharmony_ci u32 irq_pin; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci /* 5608c2ecf20Sopenharmony_ci ** REVISIT: card-mode PCI-PCI expansion chassis do exist. 5618c2ecf20Sopenharmony_ci ** Not sure they were ever productized. 5628c2ecf20Sopenharmony_ci ** Die here since we'll die later in dino_inb() anyway. 5638c2ecf20Sopenharmony_ci */ 5648c2ecf20Sopenharmony_ci if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { 5658c2ecf20Sopenharmony_ci panic("Card-Mode Dino: PCI-PCI Bridge not supported\n"); 5668c2ecf20Sopenharmony_ci } 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci /* 5698c2ecf20Sopenharmony_ci ** Set Latency Timer to 0xff (not a shared bus) 5708c2ecf20Sopenharmony_ci ** Set CACHELINE_SIZE. 5718c2ecf20Sopenharmony_ci */ 5728c2ecf20Sopenharmony_ci dino_cfg_write(dev->bus, dev->devfn, 5738c2ecf20Sopenharmony_ci PCI_CACHE_LINE_SIZE, 2, 0xff00 | L1_CACHE_BYTES/4); 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci /* 5768c2ecf20Sopenharmony_ci ** Program INT_LINE for card-mode devices. 5778c2ecf20Sopenharmony_ci ** The cards are hardwired according to this algorithm. 5788c2ecf20Sopenharmony_ci ** And it doesn't matter if PPB's are present or not since 5798c2ecf20Sopenharmony_ci ** the IRQ lines bypass the PPB. 5808c2ecf20Sopenharmony_ci ** 5818c2ecf20Sopenharmony_ci ** "-1" converts INTA-D (1-4) to PCIINTA-D (0-3) range. 5828c2ecf20Sopenharmony_ci ** The additional "-1" adjusts for skewing the IRQ<->slot. 5838c2ecf20Sopenharmony_ci */ 5848c2ecf20Sopenharmony_ci dino_cfg_read(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 1, &irq_pin); 5858c2ecf20Sopenharmony_ci dev->irq = pci_swizzle_interrupt_pin(dev, irq_pin) - 1; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci /* Shouldn't really need to do this but it's in case someone tries 5888c2ecf20Sopenharmony_ci ** to bypass PCI services and look at the card themselves. 5898c2ecf20Sopenharmony_ci */ 5908c2ecf20Sopenharmony_ci dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, dev->irq); 5918c2ecf20Sopenharmony_ci} 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci/* The alignment contraints for PCI bridges under dino */ 5948c2ecf20Sopenharmony_ci#define DINO_BRIDGE_ALIGN 0x100000 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_cistatic void __init 5988c2ecf20Sopenharmony_cidino_fixup_bus(struct pci_bus *bus) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci struct pci_dev *dev; 6018c2ecf20Sopenharmony_ci struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge)); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci DBG(KERN_WARNING "%s(0x%px) bus %d platform_data 0x%px\n", 6048c2ecf20Sopenharmony_ci __func__, bus, bus->busn_res.start, 6058c2ecf20Sopenharmony_ci bus->bridge->platform_data); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci /* Firmware doesn't set up card-mode dino, so we have to */ 6088c2ecf20Sopenharmony_ci if (is_card_dino(&dino_dev->hba.dev->id)) { 6098c2ecf20Sopenharmony_ci dino_card_setup(bus, dino_dev->hba.base_addr); 6108c2ecf20Sopenharmony_ci } else if (bus->parent) { 6118c2ecf20Sopenharmony_ci int i; 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci pci_read_bridge_bases(bus); 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci for(i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) { 6178c2ecf20Sopenharmony_ci if((bus->self->resource[i].flags & 6188c2ecf20Sopenharmony_ci (IORESOURCE_IO | IORESOURCE_MEM)) == 0) 6198c2ecf20Sopenharmony_ci continue; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci if(bus->self->resource[i].flags & IORESOURCE_MEM) { 6228c2ecf20Sopenharmony_ci /* There's a quirk to alignment of 6238c2ecf20Sopenharmony_ci * bridge memory resources: the start 6248c2ecf20Sopenharmony_ci * is the alignment and start-end is 6258c2ecf20Sopenharmony_ci * the size. However, firmware will 6268c2ecf20Sopenharmony_ci * have assigned start and end, so we 6278c2ecf20Sopenharmony_ci * need to take this into account */ 6288c2ecf20Sopenharmony_ci bus->self->resource[i].end = bus->self->resource[i].end - bus->self->resource[i].start + DINO_BRIDGE_ALIGN; 6298c2ecf20Sopenharmony_ci bus->self->resource[i].start = DINO_BRIDGE_ALIGN; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci } 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci DBG("DEBUG %s assigning %d [%pR]\n", 6348c2ecf20Sopenharmony_ci dev_name(&bus->self->dev), i, 6358c2ecf20Sopenharmony_ci &bus->self->resource[i]); 6368c2ecf20Sopenharmony_ci WARN_ON(pci_assign_resource(bus->self, i)); 6378c2ecf20Sopenharmony_ci DBG("DEBUG %s after assign %d [%pR]\n", 6388c2ecf20Sopenharmony_ci dev_name(&bus->self->dev), i, 6398c2ecf20Sopenharmony_ci &bus->self->resource[i]); 6408c2ecf20Sopenharmony_ci } 6418c2ecf20Sopenharmony_ci } 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci list_for_each_entry(dev, &bus->devices, bus_list) { 6458c2ecf20Sopenharmony_ci if (is_card_dino(&dino_dev->hba.dev->id)) 6468c2ecf20Sopenharmony_ci dino_card_fixup(dev); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci /* 6498c2ecf20Sopenharmony_ci ** P2PB's only have 2 BARs, no IRQs. 6508c2ecf20Sopenharmony_ci ** I'd like to just ignore them for now. 6518c2ecf20Sopenharmony_ci */ 6528c2ecf20Sopenharmony_ci if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { 6538c2ecf20Sopenharmony_ci pcibios_init_bridge(dev); 6548c2ecf20Sopenharmony_ci continue; 6558c2ecf20Sopenharmony_ci } 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci /* null out the ROM resource if there is one (we don't 6588c2ecf20Sopenharmony_ci * care about an expansion rom on parisc, since it 6598c2ecf20Sopenharmony_ci * usually contains (x86) bios code) */ 6608c2ecf20Sopenharmony_ci dev->resource[PCI_ROM_RESOURCE].flags = 0; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci if(dev->irq == 255) { 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci#define DINO_FIX_UNASSIGNED_INTERRUPTS 6658c2ecf20Sopenharmony_ci#ifdef DINO_FIX_UNASSIGNED_INTERRUPTS 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci /* This code tries to assign an unassigned 6688c2ecf20Sopenharmony_ci * interrupt. Leave it disabled unless you 6698c2ecf20Sopenharmony_ci * *really* know what you're doing since the 6708c2ecf20Sopenharmony_ci * pin<->interrupt line mapping varies by bus 6718c2ecf20Sopenharmony_ci * and machine */ 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci u32 irq_pin; 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci dino_cfg_read(dev->bus, dev->devfn, 6768c2ecf20Sopenharmony_ci PCI_INTERRUPT_PIN, 1, &irq_pin); 6778c2ecf20Sopenharmony_ci irq_pin = pci_swizzle_interrupt_pin(dev, irq_pin) - 1; 6788c2ecf20Sopenharmony_ci printk(KERN_WARNING "Device %s has undefined IRQ, " 6798c2ecf20Sopenharmony_ci "setting to %d\n", pci_name(dev), irq_pin); 6808c2ecf20Sopenharmony_ci dino_cfg_write(dev->bus, dev->devfn, 6818c2ecf20Sopenharmony_ci PCI_INTERRUPT_LINE, 1, irq_pin); 6828c2ecf20Sopenharmony_ci dino_assign_irq(dino_dev, irq_pin, &dev->irq); 6838c2ecf20Sopenharmony_ci#else 6848c2ecf20Sopenharmony_ci dev->irq = 65535; 6858c2ecf20Sopenharmony_ci printk(KERN_WARNING "Device %s has unassigned IRQ\n", pci_name(dev)); 6868c2ecf20Sopenharmony_ci#endif 6878c2ecf20Sopenharmony_ci } else { 6888c2ecf20Sopenharmony_ci /* Adjust INT_LINE for that busses region */ 6898c2ecf20Sopenharmony_ci dino_assign_irq(dino_dev, dev->irq, &dev->irq); 6908c2ecf20Sopenharmony_ci } 6918c2ecf20Sopenharmony_ci } 6928c2ecf20Sopenharmony_ci} 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_cistatic struct pci_bios_ops dino_bios_ops = { 6968c2ecf20Sopenharmony_ci .init = dino_bios_init, 6978c2ecf20Sopenharmony_ci .fixup_bus = dino_fixup_bus 6988c2ecf20Sopenharmony_ci}; 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci/* 7028c2ecf20Sopenharmony_ci * Initialise a DINO controller chip 7038c2ecf20Sopenharmony_ci */ 7048c2ecf20Sopenharmony_cistatic void __init 7058c2ecf20Sopenharmony_cidino_card_init(struct dino_device *dino_dev) 7068c2ecf20Sopenharmony_ci{ 7078c2ecf20Sopenharmony_ci u32 brdg_feat = 0x00784e05; 7088c2ecf20Sopenharmony_ci unsigned long status; 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci status = __raw_readl(dino_dev->hba.base_addr+DINO_IO_STATUS); 7118c2ecf20Sopenharmony_ci if (status & 0x0000ff80) { 7128c2ecf20Sopenharmony_ci __raw_writel(0x00000005, 7138c2ecf20Sopenharmony_ci dino_dev->hba.base_addr+DINO_IO_COMMAND); 7148c2ecf20Sopenharmony_ci udelay(1); 7158c2ecf20Sopenharmony_ci } 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK); 7188c2ecf20Sopenharmony_ci __raw_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN); 7198c2ecf20Sopenharmony_ci __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_ICR); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci#if 1 7228c2ecf20Sopenharmony_ci/* REVISIT - should be a runtime check (eg if (CPU_IS_PCX_L) ...) */ 7238c2ecf20Sopenharmony_ci /* 7248c2ecf20Sopenharmony_ci ** PCX-L processors don't support XQL like Dino wants it. 7258c2ecf20Sopenharmony_ci ** PCX-L2 ignore XQL signal and it doesn't matter. 7268c2ecf20Sopenharmony_ci */ 7278c2ecf20Sopenharmony_ci brdg_feat &= ~0x4; /* UXQL */ 7288c2ecf20Sopenharmony_ci#endif 7298c2ecf20Sopenharmony_ci __raw_writel( brdg_feat, dino_dev->hba.base_addr+DINO_BRDG_FEAT); 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci /* 7328c2ecf20Sopenharmony_ci ** Don't enable address decoding until we know which I/O range 7338c2ecf20Sopenharmony_ci ** currently is available from the host. Only affects MMIO 7348c2ecf20Sopenharmony_ci ** and not I/O port space. 7358c2ecf20Sopenharmony_ci */ 7368c2ecf20Sopenharmony_ci __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_IO_ADDR_EN); 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_DAMODE); 7398c2ecf20Sopenharmony_ci __raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIROR); 7408c2ecf20Sopenharmony_ci __raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIWOR); 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci __raw_writel(0x00000040, dino_dev->hba.base_addr+DINO_MLTIM); 7438c2ecf20Sopenharmony_ci __raw_writel(0x00000080, dino_dev->hba.base_addr+DINO_IO_CONTROL); 7448c2ecf20Sopenharmony_ci __raw_writel(0x0000008c, dino_dev->hba.base_addr+DINO_TLTIM); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci /* Disable PAMR before writing PAPR */ 7478c2ecf20Sopenharmony_ci __raw_writel(0x0000007e, dino_dev->hba.base_addr+DINO_PAMR); 7488c2ecf20Sopenharmony_ci __raw_writel(0x0000007f, dino_dev->hba.base_addr+DINO_PAPR); 7498c2ecf20Sopenharmony_ci __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_PAMR); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci /* 7528c2ecf20Sopenharmony_ci ** Dino ERS encourages enabling FBB (0x6f). 7538c2ecf20Sopenharmony_ci ** We can't until we know *all* devices below us can support it. 7548c2ecf20Sopenharmony_ci ** (Something in device configuration header tells us). 7558c2ecf20Sopenharmony_ci */ 7568c2ecf20Sopenharmony_ci __raw_writel(0x0000004f, dino_dev->hba.base_addr+DINO_PCICMD); 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci /* Somewhere, the PCI spec says give devices 1 second 7598c2ecf20Sopenharmony_ci ** to recover from the #RESET being de-asserted. 7608c2ecf20Sopenharmony_ci ** Experience shows most devices only need 10ms. 7618c2ecf20Sopenharmony_ci ** This short-cut speeds up booting significantly. 7628c2ecf20Sopenharmony_ci */ 7638c2ecf20Sopenharmony_ci mdelay(pci_post_reset_delay); 7648c2ecf20Sopenharmony_ci} 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_cistatic int __init 7678c2ecf20Sopenharmony_cidino_bridge_init(struct dino_device *dino_dev, const char *name) 7688c2ecf20Sopenharmony_ci{ 7698c2ecf20Sopenharmony_ci unsigned long io_addr; 7708c2ecf20Sopenharmony_ci int result, i, count=0; 7718c2ecf20Sopenharmony_ci struct resource *res, *prevres = NULL; 7728c2ecf20Sopenharmony_ci /* 7738c2ecf20Sopenharmony_ci * Decoding IO_ADDR_EN only works for Built-in Dino 7748c2ecf20Sopenharmony_ci * since PDC has already initialized this. 7758c2ecf20Sopenharmony_ci */ 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci io_addr = __raw_readl(dino_dev->hba.base_addr + DINO_IO_ADDR_EN); 7788c2ecf20Sopenharmony_ci if (io_addr == 0) { 7798c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: No PCI devices enabled.\n", name); 7808c2ecf20Sopenharmony_ci return -ENODEV; 7818c2ecf20Sopenharmony_ci } 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci res = &dino_dev->hba.lmmio_space; 7848c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) { 7858c2ecf20Sopenharmony_ci unsigned long start, end; 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci if((io_addr & (1 << i)) == 0) 7888c2ecf20Sopenharmony_ci continue; 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci start = F_EXTEND(0xf0000000UL) | (i << 23); 7918c2ecf20Sopenharmony_ci end = start + 8 * 1024 * 1024 - 1; 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci DBG("DINO RANGE %d is at 0x%lx-0x%lx\n", count, 7948c2ecf20Sopenharmony_ci start, end); 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci if(prevres && prevres->end + 1 == start) { 7978c2ecf20Sopenharmony_ci prevres->end = end; 7988c2ecf20Sopenharmony_ci } else { 7998c2ecf20Sopenharmony_ci if(count >= DINO_MAX_LMMIO_RESOURCES) { 8008c2ecf20Sopenharmony_ci printk(KERN_ERR "%s is out of resource windows for range %d (0x%lx-0x%lx)\n", name, count, start, end); 8018c2ecf20Sopenharmony_ci break; 8028c2ecf20Sopenharmony_ci } 8038c2ecf20Sopenharmony_ci prevres = res; 8048c2ecf20Sopenharmony_ci res->start = start; 8058c2ecf20Sopenharmony_ci res->end = end; 8068c2ecf20Sopenharmony_ci res->flags = IORESOURCE_MEM; 8078c2ecf20Sopenharmony_ci res->name = kmalloc(64, GFP_KERNEL); 8088c2ecf20Sopenharmony_ci if(res->name) 8098c2ecf20Sopenharmony_ci snprintf((char *)res->name, 64, "%s LMMIO %d", 8108c2ecf20Sopenharmony_ci name, count); 8118c2ecf20Sopenharmony_ci res++; 8128c2ecf20Sopenharmony_ci count++; 8138c2ecf20Sopenharmony_ci } 8148c2ecf20Sopenharmony_ci } 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci res = &dino_dev->hba.lmmio_space; 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci for(i = 0; i < DINO_MAX_LMMIO_RESOURCES; i++) { 8198c2ecf20Sopenharmony_ci if(res[i].flags == 0) 8208c2ecf20Sopenharmony_ci break; 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci result = ccio_request_resource(dino_dev->hba.dev, &res[i]); 8238c2ecf20Sopenharmony_ci if (result < 0) { 8248c2ecf20Sopenharmony_ci printk(KERN_ERR "%s: failed to claim PCI Bus address " 8258c2ecf20Sopenharmony_ci "space %d (%pR)!\n", name, i, &res[i]); 8268c2ecf20Sopenharmony_ci return result; 8278c2ecf20Sopenharmony_ci } 8288c2ecf20Sopenharmony_ci } 8298c2ecf20Sopenharmony_ci return 0; 8308c2ecf20Sopenharmony_ci} 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_cistatic int __init dino_common_init(struct parisc_device *dev, 8338c2ecf20Sopenharmony_ci struct dino_device *dino_dev, const char *name) 8348c2ecf20Sopenharmony_ci{ 8358c2ecf20Sopenharmony_ci int status; 8368c2ecf20Sopenharmony_ci u32 eim; 8378c2ecf20Sopenharmony_ci struct resource *res; 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci pcibios_register_hba(&dino_dev->hba); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci pci_bios = &dino_bios_ops; /* used by pci_scan_bus() */ 8428c2ecf20Sopenharmony_ci pci_port = &dino_port_ops; 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci /* 8458c2ecf20Sopenharmony_ci ** Note: SMP systems can make use of IRR1/IAR1 registers 8468c2ecf20Sopenharmony_ci ** But it won't buy much performance except in very 8478c2ecf20Sopenharmony_ci ** specific applications/configurations. Note Dino 8488c2ecf20Sopenharmony_ci ** still only has 11 IRQ input lines - just map some of them 8498c2ecf20Sopenharmony_ci ** to a different processor. 8508c2ecf20Sopenharmony_ci */ 8518c2ecf20Sopenharmony_ci dev->irq = gsc_alloc_irq(&dino_dev->gsc_irq); 8528c2ecf20Sopenharmony_ci eim = ((u32) dino_dev->gsc_irq.txn_addr) | dino_dev->gsc_irq.txn_data; 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci /* 8558c2ecf20Sopenharmony_ci ** Dino needs a PA "IRQ" to get a processor's attention. 8568c2ecf20Sopenharmony_ci ** arch/parisc/kernel/irq.c returns an EIRR bit. 8578c2ecf20Sopenharmony_ci */ 8588c2ecf20Sopenharmony_ci if (dev->irq < 0) { 8598c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: gsc_alloc_irq() failed\n", name); 8608c2ecf20Sopenharmony_ci return 1; 8618c2ecf20Sopenharmony_ci } 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci status = request_irq(dev->irq, dino_isr, 0, name, dino_dev); 8648c2ecf20Sopenharmony_ci if (status) { 8658c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: request_irq() failed with %d\n", 8668c2ecf20Sopenharmony_ci name, status); 8678c2ecf20Sopenharmony_ci return 1; 8688c2ecf20Sopenharmony_ci } 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci /* Support the serial port which is sometimes attached on built-in 8718c2ecf20Sopenharmony_ci * Dino / Cujo chips. 8728c2ecf20Sopenharmony_ci */ 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci gsc_fixup_irqs(dev, dino_dev, dino_choose_irq); 8758c2ecf20Sopenharmony_ci 8768c2ecf20Sopenharmony_ci /* 8778c2ecf20Sopenharmony_ci ** This enables DINO to generate interrupts when it sees 8788c2ecf20Sopenharmony_ci ** any of its inputs *change*. Just asserting an IRQ 8798c2ecf20Sopenharmony_ci ** before it's enabled (ie unmasked) isn't good enough. 8808c2ecf20Sopenharmony_ci */ 8818c2ecf20Sopenharmony_ci __raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0); 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci /* 8848c2ecf20Sopenharmony_ci ** Some platforms don't clear Dino's IRR0 register at boot time. 8858c2ecf20Sopenharmony_ci ** Reading will clear it now. 8868c2ecf20Sopenharmony_ci */ 8878c2ecf20Sopenharmony_ci __raw_readl(dino_dev->hba.base_addr+DINO_IRR0); 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci /* allocate I/O Port resource region */ 8908c2ecf20Sopenharmony_ci res = &dino_dev->hba.io_space; 8918c2ecf20Sopenharmony_ci if (!is_cujo(&dev->id)) { 8928c2ecf20Sopenharmony_ci res->name = "Dino I/O Port"; 8938c2ecf20Sopenharmony_ci } else { 8948c2ecf20Sopenharmony_ci res->name = "Cujo I/O Port"; 8958c2ecf20Sopenharmony_ci } 8968c2ecf20Sopenharmony_ci res->start = HBA_PORT_BASE(dino_dev->hba.hba_num); 8978c2ecf20Sopenharmony_ci res->end = res->start + (HBA_PORT_SPACE_SIZE - 1); 8988c2ecf20Sopenharmony_ci res->flags = IORESOURCE_IO; /* do not mark it busy ! */ 8998c2ecf20Sopenharmony_ci if (request_resource(&ioport_resource, res) < 0) { 9008c2ecf20Sopenharmony_ci printk(KERN_ERR "%s: request I/O Port region failed " 9018c2ecf20Sopenharmony_ci "0x%lx/%lx (hpa 0x%px)\n", 9028c2ecf20Sopenharmony_ci name, (unsigned long)res->start, (unsigned long)res->end, 9038c2ecf20Sopenharmony_ci dino_dev->hba.base_addr); 9048c2ecf20Sopenharmony_ci return 1; 9058c2ecf20Sopenharmony_ci } 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci return 0; 9088c2ecf20Sopenharmony_ci} 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_ci#define CUJO_RAVEN_ADDR F_EXTEND(0xf1000000UL) 9118c2ecf20Sopenharmony_ci#define CUJO_FIREHAWK_ADDR F_EXTEND(0xf1604000UL) 9128c2ecf20Sopenharmony_ci#define CUJO_RAVEN_BADPAGE 0x01003000UL 9138c2ecf20Sopenharmony_ci#define CUJO_FIREHAWK_BADPAGE 0x01607000UL 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_cistatic const char dino_vers[][4] = { 9168c2ecf20Sopenharmony_ci "2.0", 9178c2ecf20Sopenharmony_ci "2.1", 9188c2ecf20Sopenharmony_ci "3.0", 9198c2ecf20Sopenharmony_ci "3.1" 9208c2ecf20Sopenharmony_ci}; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_cistatic const char cujo_vers[][4] = { 9238c2ecf20Sopenharmony_ci "1.0", 9248c2ecf20Sopenharmony_ci "2.0" 9258c2ecf20Sopenharmony_ci}; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_civoid ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci/* 9308c2ecf20Sopenharmony_ci** Determine if dino should claim this chip (return 0) or not (return 1). 9318c2ecf20Sopenharmony_ci** If so, initialize the chip appropriately (card-mode vs bridge mode). 9328c2ecf20Sopenharmony_ci** Much of the initialization is common though. 9338c2ecf20Sopenharmony_ci*/ 9348c2ecf20Sopenharmony_cistatic int __init dino_probe(struct parisc_device *dev) 9358c2ecf20Sopenharmony_ci{ 9368c2ecf20Sopenharmony_ci struct dino_device *dino_dev; // Dino specific control struct 9378c2ecf20Sopenharmony_ci const char *version = "unknown"; 9388c2ecf20Sopenharmony_ci char *name; 9398c2ecf20Sopenharmony_ci int is_cujo = 0; 9408c2ecf20Sopenharmony_ci LIST_HEAD(resources); 9418c2ecf20Sopenharmony_ci struct pci_bus *bus; 9428c2ecf20Sopenharmony_ci unsigned long hpa = dev->hpa.start; 9438c2ecf20Sopenharmony_ci int max; 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci name = "Dino"; 9468c2ecf20Sopenharmony_ci if (is_card_dino(&dev->id)) { 9478c2ecf20Sopenharmony_ci version = "3.x (card mode)"; 9488c2ecf20Sopenharmony_ci } else { 9498c2ecf20Sopenharmony_ci if (!is_cujo(&dev->id)) { 9508c2ecf20Sopenharmony_ci if (dev->id.hversion_rev < 4) { 9518c2ecf20Sopenharmony_ci version = dino_vers[dev->id.hversion_rev]; 9528c2ecf20Sopenharmony_ci } 9538c2ecf20Sopenharmony_ci } else { 9548c2ecf20Sopenharmony_ci name = "Cujo"; 9558c2ecf20Sopenharmony_ci is_cujo = 1; 9568c2ecf20Sopenharmony_ci if (dev->id.hversion_rev < 2) { 9578c2ecf20Sopenharmony_ci version = cujo_vers[dev->id.hversion_rev]; 9588c2ecf20Sopenharmony_ci } 9598c2ecf20Sopenharmony_ci } 9608c2ecf20Sopenharmony_ci } 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci printk("%s version %s found at 0x%lx\n", name, version, hpa); 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci if (!request_mem_region(hpa, PAGE_SIZE, name)) { 9658c2ecf20Sopenharmony_ci printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%lx)!\n", 9668c2ecf20Sopenharmony_ci hpa); 9678c2ecf20Sopenharmony_ci return 1; 9688c2ecf20Sopenharmony_ci } 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci /* Check for bugs */ 9718c2ecf20Sopenharmony_ci if (is_cujo && dev->id.hversion_rev == 1) { 9728c2ecf20Sopenharmony_ci#ifdef CONFIG_IOMMU_CCIO 9738c2ecf20Sopenharmony_ci printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround\n"); 9748c2ecf20Sopenharmony_ci if (hpa == (unsigned long)CUJO_RAVEN_ADDR) { 9758c2ecf20Sopenharmony_ci ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE); 9768c2ecf20Sopenharmony_ci } else if (hpa == (unsigned long)CUJO_FIREHAWK_ADDR) { 9778c2ecf20Sopenharmony_ci ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE); 9788c2ecf20Sopenharmony_ci } else { 9798c2ecf20Sopenharmony_ci printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", hpa); 9808c2ecf20Sopenharmony_ci } 9818c2ecf20Sopenharmony_ci#endif 9828c2ecf20Sopenharmony_ci } else if (!is_cujo && !is_card_dino(&dev->id) && 9838c2ecf20Sopenharmony_ci dev->id.hversion_rev < 3) { 9848c2ecf20Sopenharmony_ci printk(KERN_WARNING 9858c2ecf20Sopenharmony_ci"The GSCtoPCI (Dino hrev %d) bus converter found may exhibit\n" 9868c2ecf20Sopenharmony_ci"data corruption. See Service Note Numbers: A4190A-01, A4191A-01.\n" 9878c2ecf20Sopenharmony_ci"Systems shipped after Aug 20, 1997 will not exhibit this problem.\n" 9888c2ecf20Sopenharmony_ci"Models affected: C180, C160, C160L, B160L, and B132L workstations.\n\n", 9898c2ecf20Sopenharmony_ci dev->id.hversion_rev); 9908c2ecf20Sopenharmony_ci/* REVISIT: why are C200/C240 listed in the README table but not 9918c2ecf20Sopenharmony_ci** "Models affected"? Could be an omission in the original literature. 9928c2ecf20Sopenharmony_ci*/ 9938c2ecf20Sopenharmony_ci } 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci dino_dev = kzalloc(sizeof(struct dino_device), GFP_KERNEL); 9968c2ecf20Sopenharmony_ci if (!dino_dev) { 9978c2ecf20Sopenharmony_ci printk("dino_init_chip - couldn't alloc dino_device\n"); 9988c2ecf20Sopenharmony_ci return 1; 9998c2ecf20Sopenharmony_ci } 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci dino_dev->hba.dev = dev; 10028c2ecf20Sopenharmony_ci dino_dev->hba.base_addr = ioremap(hpa, 4096); 10038c2ecf20Sopenharmony_ci dino_dev->hba.lmmio_space_offset = PCI_F_EXTEND; 10048c2ecf20Sopenharmony_ci spin_lock_init(&dino_dev->dinosaur_pen); 10058c2ecf20Sopenharmony_ci dino_dev->hba.iommu = ccio_get_iommu(dev); 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci if (is_card_dino(&dev->id)) { 10088c2ecf20Sopenharmony_ci dino_card_init(dino_dev); 10098c2ecf20Sopenharmony_ci } else { 10108c2ecf20Sopenharmony_ci dino_bridge_init(dino_dev, name); 10118c2ecf20Sopenharmony_ci } 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci if (dino_common_init(dev, dino_dev, name)) 10148c2ecf20Sopenharmony_ci return 1; 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci dev->dev.platform_data = dino_dev; 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_ci pci_add_resource_offset(&resources, &dino_dev->hba.io_space, 10198c2ecf20Sopenharmony_ci HBA_PORT_BASE(dino_dev->hba.hba_num)); 10208c2ecf20Sopenharmony_ci if (dino_dev->hba.lmmio_space.flags) 10218c2ecf20Sopenharmony_ci pci_add_resource_offset(&resources, &dino_dev->hba.lmmio_space, 10228c2ecf20Sopenharmony_ci dino_dev->hba.lmmio_space_offset); 10238c2ecf20Sopenharmony_ci if (dino_dev->hba.elmmio_space.flags) 10248c2ecf20Sopenharmony_ci pci_add_resource_offset(&resources, &dino_dev->hba.elmmio_space, 10258c2ecf20Sopenharmony_ci dino_dev->hba.lmmio_space_offset); 10268c2ecf20Sopenharmony_ci if (dino_dev->hba.gmmio_space.flags) 10278c2ecf20Sopenharmony_ci pci_add_resource(&resources, &dino_dev->hba.gmmio_space); 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci dino_dev->hba.bus_num.start = dino_current_bus; 10308c2ecf20Sopenharmony_ci dino_dev->hba.bus_num.end = 255; 10318c2ecf20Sopenharmony_ci dino_dev->hba.bus_num.flags = IORESOURCE_BUS; 10328c2ecf20Sopenharmony_ci pci_add_resource(&resources, &dino_dev->hba.bus_num); 10338c2ecf20Sopenharmony_ci /* 10348c2ecf20Sopenharmony_ci ** It's not used to avoid chicken/egg problems 10358c2ecf20Sopenharmony_ci ** with configuration accessor functions. 10368c2ecf20Sopenharmony_ci */ 10378c2ecf20Sopenharmony_ci dino_dev->hba.hba_bus = bus = pci_create_root_bus(&dev->dev, 10388c2ecf20Sopenharmony_ci dino_current_bus, &dino_cfg_ops, NULL, &resources); 10398c2ecf20Sopenharmony_ci if (!bus) { 10408c2ecf20Sopenharmony_ci printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)\n", 10418c2ecf20Sopenharmony_ci dev_name(&dev->dev), dino_current_bus); 10428c2ecf20Sopenharmony_ci pci_free_resource_list(&resources); 10438c2ecf20Sopenharmony_ci /* increment the bus number in case of duplicates */ 10448c2ecf20Sopenharmony_ci dino_current_bus++; 10458c2ecf20Sopenharmony_ci return 0; 10468c2ecf20Sopenharmony_ci } 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci max = pci_scan_child_bus(bus); 10498c2ecf20Sopenharmony_ci pci_bus_update_busn_res_end(bus, max); 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_ci /* This code *depends* on scanning being single threaded 10528c2ecf20Sopenharmony_ci * if it isn't, this global bus number count will fail 10538c2ecf20Sopenharmony_ci */ 10548c2ecf20Sopenharmony_ci dino_current_bus = max + 1; 10558c2ecf20Sopenharmony_ci pci_bus_assign_resources(bus); 10568c2ecf20Sopenharmony_ci pci_bus_add_devices(bus); 10578c2ecf20Sopenharmony_ci return 0; 10588c2ecf20Sopenharmony_ci} 10598c2ecf20Sopenharmony_ci 10608c2ecf20Sopenharmony_ci/* 10618c2ecf20Sopenharmony_ci * Normally, we would just test sversion. But the Elroy PCI adapter has 10628c2ecf20Sopenharmony_ci * the same sversion as Dino, so we have to check hversion as well. 10638c2ecf20Sopenharmony_ci * Unfortunately, the J2240 PDC reports the wrong hversion for the first 10648c2ecf20Sopenharmony_ci * Dino, so we have to test for Dino, Cujo and Dino-in-a-J2240. 10658c2ecf20Sopenharmony_ci * For card-mode Dino, most machines report an sversion of 9D. But 715 10668c2ecf20Sopenharmony_ci * and 725 firmware misreport it as 0x08080 for no adequately explained 10678c2ecf20Sopenharmony_ci * reason. 10688c2ecf20Sopenharmony_ci */ 10698c2ecf20Sopenharmony_cistatic const struct parisc_device_id dino_tbl[] __initconst = { 10708c2ecf20Sopenharmony_ci { HPHW_A_DMA, HVERSION_REV_ANY_ID, 0x004, 0x0009D },/* Card-mode Dino */ 10718c2ecf20Sopenharmony_ci { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x08080 }, /* XXX */ 10728c2ecf20Sopenharmony_ci { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x680, 0xa }, /* Bridge-mode Dino */ 10738c2ecf20Sopenharmony_ci { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x682, 0xa }, /* Bridge-mode Cujo */ 10748c2ecf20Sopenharmony_ci { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x05d, 0xa }, /* Dino in a J2240 */ 10758c2ecf20Sopenharmony_ci { 0, } 10768c2ecf20Sopenharmony_ci}; 10778c2ecf20Sopenharmony_ci 10788c2ecf20Sopenharmony_cistatic struct parisc_driver dino_driver __refdata = { 10798c2ecf20Sopenharmony_ci .name = "dino", 10808c2ecf20Sopenharmony_ci .id_table = dino_tbl, 10818c2ecf20Sopenharmony_ci .probe = dino_probe, 10828c2ecf20Sopenharmony_ci}; 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci/* 10858c2ecf20Sopenharmony_ci * One time initialization to let the world know Dino is here. 10868c2ecf20Sopenharmony_ci * This is the only routine which is NOT static. 10878c2ecf20Sopenharmony_ci * Must be called exactly once before pci_init(). 10888c2ecf20Sopenharmony_ci */ 10898c2ecf20Sopenharmony_ciint __init dino_init(void) 10908c2ecf20Sopenharmony_ci{ 10918c2ecf20Sopenharmony_ci register_parisc_driver(&dino_driver); 10928c2ecf20Sopenharmony_ci return 0; 10938c2ecf20Sopenharmony_ci} 10948c2ecf20Sopenharmony_ci 1095