2 * linux/arch/arm/kernel/dec21285.c: PCI functions for DC21285
4 * Copyright (C) 1998-2001 Russell King
5 * Copyright (C) 1998-2000 Phil Blundell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <linux/ptrace.h>
14 #include <linux/interrupt.h>
16 #include <linux/slab.h>
17 #include <linux/init.h>
18 #include <linux/ioport.h>
22 #include <asm/system.h>
23 #include <asm/mach/pci.h>
24 #include <asm/hardware/dec21285.h>
28 #define PCICMD_ABORT ((PCI_STATUS_REC_MASTER_ABORT| \
29 PCI_STATUS_REC_TARGET_ABORT)<<16)
31 #define PCICMD_ERROR_BITS ((PCI_STATUS_DETECTED_PARITY | \
32 PCI_STATUS_REC_MASTER_ABORT | \
33 PCI_STATUS_REC_TARGET_ABORT | \
34 PCI_STATUS_PARITY) << 16)
36 extern int setup_arm_irq(int, struct irqaction *);
37 extern void pcibios_report_status(u_int status_mask, int warn);
38 extern void register_isa_ports(unsigned int, unsigned int, unsigned int);
41 dc21285_base_address(struct pci_bus *bus, unsigned int devfn)
43 unsigned long addr = 0;
45 if (bus->number == 0) {
46 if (PCI_SLOT(devfn) == 0)
48 * For devfn 0, point at the 21285
54 if (devfn < PCI_DEVFN(MAX_SLOTS, 0))
55 addr = PCICFG0_BASE | 0xc00000 | (devfn << 8);
58 addr = PCICFG1_BASE | (bus->number << 16) | (devfn << 8);
64 dc21285_read_config(struct pci_bus *bus, unsigned int devfn, int where,
67 unsigned long addr = dc21285_base_address(bus, devfn);
73 asm("ldr%?b %0, [%1, %2]"
74 : "=r" (v) : "r" (addr), "r" (where));
77 asm("ldr%?h %0, [%1, %2]"
78 : "=r" (v) : "r" (addr), "r" (where));
81 asm("ldr%? %0, [%1, %2]"
82 : "=r" (v) : "r" (addr), "r" (where));
89 if (v & PCICMD_ABORT) {
90 *CSR_PCICMD = v & (0xffff|PCICMD_ABORT);
94 return PCIBIOS_SUCCESSFUL;
98 dc21285_write_config(struct pci_bus *bus, unsigned int devfn, int where,
101 unsigned long addr = dc21285_base_address(bus, devfn);
107 asm("str%?b %0, [%1, %2]"
108 : : "r" (value), "r" (addr), "r" (where));
111 asm("str%?h %0, [%1, %2]"
112 : : "r" (value), "r" (addr), "r" (where));
115 asm("str%? %0, [%1, %2]"
116 : : "r" (value), "r" (addr), "r" (where));
121 if (v & PCICMD_ABORT) {
122 *CSR_PCICMD = v & (0xffff|PCICMD_ABORT);
126 return PCIBIOS_SUCCESSFUL;
129 static struct pci_ops dc21285_ops = {
130 .read = dc21285_read_config,
131 .write = dc21285_write_config,
134 static struct timer_list serr_timer;
135 static struct timer_list perr_timer;
137 static void dc21285_enable_error(unsigned long __data)
141 del_timer(&serr_timer);
145 del_timer(&perr_timer);
153 * Warn on PCI errors.
155 static irqreturn_t dc21285_abort_irq(int irq, void *dev_id, struct pt_regs *regs)
164 if (status & PCI_STATUS_REC_MASTER_ABORT) {
165 printk(KERN_DEBUG "PCI: master abort, pc=0x%08lx\n",
166 instruction_pointer(regs));
167 cmd |= PCI_STATUS_REC_MASTER_ABORT << 16;
170 if (status & PCI_STATUS_REC_TARGET_ABORT) {
171 printk(KERN_DEBUG "PCI: target abort: ");
172 pcibios_report_status(PCI_STATUS_REC_MASTER_ABORT |
173 PCI_STATUS_SIG_TARGET_ABORT |
174 PCI_STATUS_REC_TARGET_ABORT, 1);
177 cmd |= PCI_STATUS_REC_TARGET_ABORT << 16;
185 static irqreturn_t dc21285_serr_irq(int irq, void *dev_id, struct pt_regs *regs)
187 struct timer_list *timer = dev_id;
190 printk(KERN_DEBUG "PCI: system error received: ");
191 pcibios_report_status(PCI_STATUS_SIG_SYSTEM_ERROR, 1);
194 cntl = *CSR_SA110_CNTL & 0xffffdf07;
195 *CSR_SA110_CNTL = cntl | SA110_CNTL_RXSERR;
198 * back off this interrupt
201 timer->expires = jiffies + HZ;
207 static irqreturn_t dc21285_discard_irq(int irq, void *dev_id, struct pt_regs *regs)
209 printk(KERN_DEBUG "PCI: discard timer expired\n");
210 *CSR_SA110_CNTL &= 0xffffde07;
215 static irqreturn_t dc21285_dparity_irq(int irq, void *dev_id, struct pt_regs *regs)
219 printk(KERN_DEBUG "PCI: data parity error detected: ");
220 pcibios_report_status(PCI_STATUS_PARITY | PCI_STATUS_DETECTED_PARITY, 1);
223 cmd = *CSR_PCICMD & 0xffff;
224 *CSR_PCICMD = cmd | 1 << 24;
229 static irqreturn_t dc21285_parity_irq(int irq, void *dev_id, struct pt_regs *regs)
231 struct timer_list *timer = dev_id;
234 printk(KERN_DEBUG "PCI: parity error detected: ");
235 pcibios_report_status(PCI_STATUS_PARITY | PCI_STATUS_DETECTED_PARITY, 1);
238 cmd = *CSR_PCICMD & 0xffff;
239 *CSR_PCICMD = cmd | 1 << 31;
242 * back off this interrupt
245 timer->expires = jiffies + HZ;
251 int __init dc21285_setup(int nr, struct pci_sys_data *sys)
253 struct resource *res;
255 if (nr || !footbridge_cfn_mode())
258 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
260 printk("out of memory for root bus resources");
264 res[0].flags = IORESOURCE_MEM;
265 res[0].name = "Footbridge non-prefetch";
266 res[1].flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
267 res[1].name = "Footbridge prefetch";
269 allocate_resource(&iomem_resource, &res[1], 0x20000000,
270 0xa0000000, 0xffffffff, 0x20000000, NULL, NULL);
271 allocate_resource(&iomem_resource, &res[0], 0x40000000,
272 0x80000000, 0xffffffff, 0x40000000, NULL, NULL);
274 sys->resource[0] = &ioport_resource;
275 sys->resource[1] = &res[0];
276 sys->resource[2] = &res[1];
277 sys->mem_offset = DC21285_PCI_MEM;
282 struct pci_bus * __init dc21285_scan_bus(int nr, struct pci_sys_data *sys)
284 return pci_scan_bus(0, &dc21285_ops, sys);
287 void __init dc21285_preinit(void)
289 unsigned int mem_size, mem_mask;
292 mem_size = (unsigned int)high_memory - PAGE_OFFSET;
293 for (mem_mask = 0x00100000; mem_mask < 0x10000000; mem_mask <<= 1)
294 if (mem_mask >= mem_size)
298 * These registers need to be set up whether we're the
299 * central function or not.
301 *CSR_SDRAMBASEMASK = (mem_mask - 1) & 0x0ffc0000;
302 *CSR_SDRAMBASEOFFSET = 0;
303 *CSR_ROMBASEMASK = 0x80000000;
304 *CSR_CSRBASEMASK = 0;
305 *CSR_CSRBASEOFFSET = 0;
306 *CSR_PCIADDR_EXTN = 0;
308 cfn_mode = __footbridge_cfn_mode();
310 printk(KERN_INFO "PCI: DC21285 footbridge, revision %02lX, in "
311 "%s mode\n", *CSR_CLASSREV & 0xff, cfn_mode ?
312 "central function" : "addin");
314 if (footbridge_cfn_mode()) {
316 * Clear any existing errors - we aren't
317 * interested in historical data...
319 *CSR_SA110_CNTL = (*CSR_SA110_CNTL & 0xffffde07) |
321 *CSR_PCICMD = (*CSR_PCICMD & 0xffff) | PCICMD_ERROR_BITS;
324 init_timer(&serr_timer);
325 init_timer(&perr_timer);
327 serr_timer.data = IRQ_PCI_SERR;
328 serr_timer.function = dc21285_enable_error;
329 perr_timer.data = IRQ_PCI_PERR;
330 perr_timer.function = dc21285_enable_error;
333 * We don't care if these fail.
335 request_irq(IRQ_PCI_SERR, dc21285_serr_irq, IRQF_DISABLED,
336 "PCI system error", &serr_timer);
337 request_irq(IRQ_PCI_PERR, dc21285_parity_irq, IRQF_DISABLED,
338 "PCI parity error", &perr_timer);
339 request_irq(IRQ_PCI_ABORT, dc21285_abort_irq, IRQF_DISABLED,
341 request_irq(IRQ_DISCARD_TIMER, dc21285_discard_irq, IRQF_DISABLED,
342 "Discard timer", NULL);
343 request_irq(IRQ_PCI_DPERR, dc21285_dparity_irq, IRQF_DISABLED,
344 "PCI data parity", NULL);
347 static struct resource csrio;
349 csrio.flags = IORESOURCE_IO;
350 csrio.name = "Footbridge";
352 allocate_resource(&ioport_resource, &csrio, 128,
353 0xff00, 0xffff, 128, NULL, NULL);
356 * Map our SDRAM at a known address in PCI space, just in case
357 * the firmware had other ideas. Using a nonzero base is
358 * necessary, since some VGA cards forcefully use PCI addresses
359 * in the range 0x000a0000 to 0x000c0000. (eg, S3 cards).
361 *CSR_PCICSRBASE = 0xf4000000;
362 *CSR_PCICSRIOBASE = csrio.start;
363 *CSR_PCISDRAMBASE = __virt_to_bus(PAGE_OFFSET);
365 *CSR_PCICMD = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
366 PCI_COMMAND_INVALIDATE | PCICMD_ERROR_BITS;
367 } else if (footbridge_cfn_mode() != 0) {
369 * If we are not compiled to accept "add-in" mode, then
370 * we are using a constant virt_to_bus translation which
371 * can not hope to cater for the way the host BIOS has
372 * set up the machine.
374 panic("PCI: this kernel is compiled for central "
375 "function mode only");
379 void __init dc21285_postinit(void)
381 register_isa_ports(DC21285_PCI_MEM, DC21285_PCI_IO, 0);