Path: blob/master/arch/arm/mach-footbridge/dc21285.c
10817 views
/*1* linux/arch/arm/kernel/dec21285.c: PCI functions for DC212852*3* Copyright (C) 1998-2001 Russell King4* Copyright (C) 1998-2000 Phil Blundell5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License version 2 as8* published by the Free Software Foundation.9*/10#include <linux/kernel.h>11#include <linux/pci.h>12#include <linux/interrupt.h>13#include <linux/mm.h>14#include <linux/slab.h>15#include <linux/init.h>16#include <linux/ioport.h>17#include <linux/irq.h>18#include <linux/io.h>19#include <linux/spinlock.h>2021#include <asm/irq.h>22#include <asm/system.h>23#include <asm/mach/pci.h>24#include <asm/hardware/dec21285.h>2526#define MAX_SLOTS 212728#define PCICMD_ABORT ((PCI_STATUS_REC_MASTER_ABORT| \29PCI_STATUS_REC_TARGET_ABORT)<<16)3031#define PCICMD_ERROR_BITS ((PCI_STATUS_DETECTED_PARITY | \32PCI_STATUS_REC_MASTER_ABORT | \33PCI_STATUS_REC_TARGET_ABORT | \34PCI_STATUS_PARITY) << 16)3536extern int setup_arm_irq(int, struct irqaction *);37extern void pcibios_report_status(u_int status_mask, int warn);3839static unsigned long40dc21285_base_address(struct pci_bus *bus, unsigned int devfn)41{42unsigned long addr = 0;4344if (bus->number == 0) {45if (PCI_SLOT(devfn) == 0)46/*47* For devfn 0, point at the 2128548*/49addr = ARMCSR_BASE;50else {51devfn -= 1 << 3;5253if (devfn < PCI_DEVFN(MAX_SLOTS, 0))54addr = PCICFG0_BASE | 0xc00000 | (devfn << 8);55}56} else57addr = PCICFG1_BASE | (bus->number << 16) | (devfn << 8);5859return addr;60}6162static int63dc21285_read_config(struct pci_bus *bus, unsigned int devfn, int where,64int size, u32 *value)65{66unsigned long addr = dc21285_base_address(bus, devfn);67u32 v = 0xffffffff;6869if (addr)70switch (size) {71case 1:72asm("ldrb %0, [%1, %2]"73: "=r" (v) : "r" (addr), "r" (where) : "cc");74break;75case 2:76asm("ldrh %0, [%1, %2]"77: "=r" (v) : "r" (addr), "r" (where) : "cc");78break;79case 4:80asm("ldr %0, [%1, %2]"81: "=r" (v) : "r" (addr), "r" (where) : "cc");82break;83}8485*value = v;8687v = *CSR_PCICMD;88if (v & PCICMD_ABORT) {89*CSR_PCICMD = v & (0xffff|PCICMD_ABORT);90return -1;91}9293return PCIBIOS_SUCCESSFUL;94}9596static int97dc21285_write_config(struct pci_bus *bus, unsigned int devfn, int where,98int size, u32 value)99{100unsigned long addr = dc21285_base_address(bus, devfn);101u32 v;102103if (addr)104switch (size) {105case 1:106asm("strb %0, [%1, %2]"107: : "r" (value), "r" (addr), "r" (where)108: "cc");109break;110case 2:111asm("strh %0, [%1, %2]"112: : "r" (value), "r" (addr), "r" (where)113: "cc");114break;115case 4:116asm("str %0, [%1, %2]"117: : "r" (value), "r" (addr), "r" (where)118: "cc");119break;120}121122v = *CSR_PCICMD;123if (v & PCICMD_ABORT) {124*CSR_PCICMD = v & (0xffff|PCICMD_ABORT);125return -1;126}127128return PCIBIOS_SUCCESSFUL;129}130131static struct pci_ops dc21285_ops = {132.read = dc21285_read_config,133.write = dc21285_write_config,134};135136static struct timer_list serr_timer;137static struct timer_list perr_timer;138139static void dc21285_enable_error(unsigned long __data)140{141switch (__data) {142case IRQ_PCI_SERR:143del_timer(&serr_timer);144break;145146case IRQ_PCI_PERR:147del_timer(&perr_timer);148break;149}150151enable_irq(__data);152}153154/*155* Warn on PCI errors.156*/157static irqreturn_t dc21285_abort_irq(int irq, void *dev_id)158{159unsigned int cmd;160unsigned int status;161162cmd = *CSR_PCICMD;163status = cmd >> 16;164cmd = cmd & 0xffff;165166if (status & PCI_STATUS_REC_MASTER_ABORT) {167printk(KERN_DEBUG "PCI: master abort, pc=0x%08lx\n",168instruction_pointer(get_irq_regs()));169cmd |= PCI_STATUS_REC_MASTER_ABORT << 16;170}171172if (status & PCI_STATUS_REC_TARGET_ABORT) {173printk(KERN_DEBUG "PCI: target abort: ");174pcibios_report_status(PCI_STATUS_REC_MASTER_ABORT |175PCI_STATUS_SIG_TARGET_ABORT |176PCI_STATUS_REC_TARGET_ABORT, 1);177printk("\n");178179cmd |= PCI_STATUS_REC_TARGET_ABORT << 16;180}181182*CSR_PCICMD = cmd;183184return IRQ_HANDLED;185}186187static irqreturn_t dc21285_serr_irq(int irq, void *dev_id)188{189struct timer_list *timer = dev_id;190unsigned int cntl;191192printk(KERN_DEBUG "PCI: system error received: ");193pcibios_report_status(PCI_STATUS_SIG_SYSTEM_ERROR, 1);194printk("\n");195196cntl = *CSR_SA110_CNTL & 0xffffdf07;197*CSR_SA110_CNTL = cntl | SA110_CNTL_RXSERR;198199/*200* back off this interrupt201*/202disable_irq(irq);203timer->expires = jiffies + HZ;204add_timer(timer);205206return IRQ_HANDLED;207}208209static irqreturn_t dc21285_discard_irq(int irq, void *dev_id)210{211printk(KERN_DEBUG "PCI: discard timer expired\n");212*CSR_SA110_CNTL &= 0xffffde07;213214return IRQ_HANDLED;215}216217static irqreturn_t dc21285_dparity_irq(int irq, void *dev_id)218{219unsigned int cmd;220221printk(KERN_DEBUG "PCI: data parity error detected: ");222pcibios_report_status(PCI_STATUS_PARITY | PCI_STATUS_DETECTED_PARITY, 1);223printk("\n");224225cmd = *CSR_PCICMD & 0xffff;226*CSR_PCICMD = cmd | 1 << 24;227228return IRQ_HANDLED;229}230231static irqreturn_t dc21285_parity_irq(int irq, void *dev_id)232{233struct timer_list *timer = dev_id;234unsigned int cmd;235236printk(KERN_DEBUG "PCI: parity error detected: ");237pcibios_report_status(PCI_STATUS_PARITY | PCI_STATUS_DETECTED_PARITY, 1);238printk("\n");239240cmd = *CSR_PCICMD & 0xffff;241*CSR_PCICMD = cmd | 1 << 31;242243/*244* back off this interrupt245*/246disable_irq(irq);247timer->expires = jiffies + HZ;248add_timer(timer);249250return IRQ_HANDLED;251}252253int __init dc21285_setup(int nr, struct pci_sys_data *sys)254{255struct resource *res;256257if (nr || !footbridge_cfn_mode())258return 0;259260res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);261if (!res) {262printk("out of memory for root bus resources");263return 0;264}265266res[0].flags = IORESOURCE_MEM;267res[0].name = "Footbridge non-prefetch";268res[1].flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;269res[1].name = "Footbridge prefetch";270271allocate_resource(&iomem_resource, &res[1], 0x20000000,2720xa0000000, 0xffffffff, 0x20000000, NULL, NULL);273allocate_resource(&iomem_resource, &res[0], 0x40000000,2740x80000000, 0xffffffff, 0x40000000, NULL, NULL);275276sys->resource[0] = &ioport_resource;277sys->resource[1] = &res[0];278sys->resource[2] = &res[1];279sys->mem_offset = DC21285_PCI_MEM;280281return 1;282}283284struct pci_bus * __init dc21285_scan_bus(int nr, struct pci_sys_data *sys)285{286return pci_scan_bus(0, &dc21285_ops, sys);287}288289#define dc21285_request_irq(_a, _b, _c, _d, _e) \290WARN_ON(request_irq(_a, _b, _c, _d, _e) < 0)291292void __init dc21285_preinit(void)293{294unsigned int mem_size, mem_mask;295int cfn_mode;296297mem_size = (unsigned int)high_memory - PAGE_OFFSET;298for (mem_mask = 0x00100000; mem_mask < 0x10000000; mem_mask <<= 1)299if (mem_mask >= mem_size)300break;301302/*303* These registers need to be set up whether we're the304* central function or not.305*/306*CSR_SDRAMBASEMASK = (mem_mask - 1) & 0x0ffc0000;307*CSR_SDRAMBASEOFFSET = 0;308*CSR_ROMBASEMASK = 0x80000000;309*CSR_CSRBASEMASK = 0;310*CSR_CSRBASEOFFSET = 0;311*CSR_PCIADDR_EXTN = 0;312313cfn_mode = __footbridge_cfn_mode();314315printk(KERN_INFO "PCI: DC21285 footbridge, revision %02lX, in "316"%s mode\n", *CSR_CLASSREV & 0xff, cfn_mode ?317"central function" : "addin");318319if (footbridge_cfn_mode()) {320/*321* Clear any existing errors - we aren't322* interested in historical data...323*/324*CSR_SA110_CNTL = (*CSR_SA110_CNTL & 0xffffde07) |325SA110_CNTL_RXSERR;326*CSR_PCICMD = (*CSR_PCICMD & 0xffff) | PCICMD_ERROR_BITS;327}328329init_timer(&serr_timer);330init_timer(&perr_timer);331332serr_timer.data = IRQ_PCI_SERR;333serr_timer.function = dc21285_enable_error;334perr_timer.data = IRQ_PCI_PERR;335perr_timer.function = dc21285_enable_error;336337/*338* We don't care if these fail.339*/340dc21285_request_irq(IRQ_PCI_SERR, dc21285_serr_irq, IRQF_DISABLED,341"PCI system error", &serr_timer);342dc21285_request_irq(IRQ_PCI_PERR, dc21285_parity_irq, IRQF_DISABLED,343"PCI parity error", &perr_timer);344dc21285_request_irq(IRQ_PCI_ABORT, dc21285_abort_irq, IRQF_DISABLED,345"PCI abort", NULL);346dc21285_request_irq(IRQ_DISCARD_TIMER, dc21285_discard_irq, IRQF_DISABLED,347"Discard timer", NULL);348dc21285_request_irq(IRQ_PCI_DPERR, dc21285_dparity_irq, IRQF_DISABLED,349"PCI data parity", NULL);350351if (cfn_mode) {352static struct resource csrio;353354csrio.flags = IORESOURCE_IO;355csrio.name = "Footbridge";356357allocate_resource(&ioport_resource, &csrio, 128,3580xff00, 0xffff, 128, NULL, NULL);359360/*361* Map our SDRAM at a known address in PCI space, just in case362* the firmware had other ideas. Using a nonzero base is363* necessary, since some VGA cards forcefully use PCI addresses364* in the range 0x000a0000 to 0x000c0000. (eg, S3 cards).365*/366*CSR_PCICSRBASE = 0xf4000000;367*CSR_PCICSRIOBASE = csrio.start;368*CSR_PCISDRAMBASE = __virt_to_bus(PAGE_OFFSET);369*CSR_PCIROMBASE = 0;370*CSR_PCICMD = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |371PCI_COMMAND_INVALIDATE | PCICMD_ERROR_BITS;372} else if (footbridge_cfn_mode() != 0) {373/*374* If we are not compiled to accept "add-in" mode, then375* we are using a constant virt_to_bus translation which376* can not hope to cater for the way the host BIOS has377* set up the machine.378*/379panic("PCI: this kernel is compiled for central "380"function mode only");381}382}383384void __init dc21285_postinit(void)385{386register_isa_ports(DC21285_PCI_MEM, DC21285_PCI_IO, 0);387}388389390