1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/kernel/dec21285.c: PCI functions for DC21285
5 * Copyright (C) 1998-2001 Russell King
6 * Copyright (C) 1998-2000 Phil Blundell
8 #include <linux/kernel.h>
10 #include <linux/interrupt.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/irq.h>
17 #include <linux/spinlock.h>
20 #include <asm/mach/pci.h>
21 #include <asm/hardware/dec21285.h>
25 #define PCICMD_ABORT ((PCI_STATUS_REC_MASTER_ABORT| \
26 PCI_STATUS_REC_TARGET_ABORT)<<16)
28 #define PCICMD_ERROR_BITS ((PCI_STATUS_DETECTED_PARITY | \
29 PCI_STATUS_REC_MASTER_ABORT | \
30 PCI_STATUS_REC_TARGET_ABORT | \
31 PCI_STATUS_PARITY) << 16)
33 extern int setup_arm_irq(int, struct irqaction
*);
36 dc21285_base_address(struct pci_bus
*bus
, unsigned int devfn
)
38 unsigned long addr
= 0;
40 if (bus
->number
== 0) {
41 if (PCI_SLOT(devfn
) == 0)
43 * For devfn 0, point at the 21285
49 if (devfn
< PCI_DEVFN(MAX_SLOTS
, 0))
50 addr
= PCICFG0_BASE
| 0xc00000 | (devfn
<< 8);
53 addr
= PCICFG1_BASE
| (bus
->number
<< 16) | (devfn
<< 8);
59 dc21285_read_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
62 unsigned long addr
= dc21285_base_address(bus
, devfn
);
68 asm("ldrb %0, [%1, %2]"
69 : "=r" (v
) : "r" (addr
), "r" (where
) : "cc");
72 asm("ldrh %0, [%1, %2]"
73 : "=r" (v
) : "r" (addr
), "r" (where
) : "cc");
76 asm("ldr %0, [%1, %2]"
77 : "=r" (v
) : "r" (addr
), "r" (where
) : "cc");
84 if (v
& PCICMD_ABORT
) {
85 *CSR_PCICMD
= v
& (0xffff|PCICMD_ABORT
);
89 return PCIBIOS_SUCCESSFUL
;
93 dc21285_write_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
96 unsigned long addr
= dc21285_base_address(bus
, devfn
);
102 asm("strb %0, [%1, %2]"
103 : : "r" (value
), "r" (addr
), "r" (where
)
107 asm("strh %0, [%1, %2]"
108 : : "r" (value
), "r" (addr
), "r" (where
)
112 asm("str %0, [%1, %2]"
113 : : "r" (value
), "r" (addr
), "r" (where
)
119 if (v
& PCICMD_ABORT
) {
120 *CSR_PCICMD
= v
& (0xffff|PCICMD_ABORT
);
124 return PCIBIOS_SUCCESSFUL
;
127 struct pci_ops dc21285_ops
= {
128 .read
= dc21285_read_config
,
129 .write
= dc21285_write_config
,
132 static struct timer_list serr_timer
;
133 static struct timer_list perr_timer
;
135 static void dc21285_enable_error(struct timer_list
*timer
)
139 if (timer
== &serr_timer
)
140 enable_irq(IRQ_PCI_SERR
);
141 else if (timer
== &perr_timer
)
142 enable_irq(IRQ_PCI_PERR
);
146 * Warn on PCI errors.
148 static irqreturn_t
dc21285_abort_irq(int irq
, void *dev_id
)
157 if (status
& PCI_STATUS_REC_MASTER_ABORT
) {
158 printk(KERN_DEBUG
"PCI: master abort, pc=0x%08lx\n",
159 instruction_pointer(get_irq_regs()));
160 cmd
|= PCI_STATUS_REC_MASTER_ABORT
<< 16;
163 if (status
& PCI_STATUS_REC_TARGET_ABORT
) {
164 printk(KERN_DEBUG
"PCI: target abort: ");
165 pcibios_report_status(PCI_STATUS_REC_MASTER_ABORT
|
166 PCI_STATUS_SIG_TARGET_ABORT
|
167 PCI_STATUS_REC_TARGET_ABORT
, 1);
170 cmd
|= PCI_STATUS_REC_TARGET_ABORT
<< 16;
178 static irqreturn_t
dc21285_serr_irq(int irq
, void *dev_id
)
180 struct timer_list
*timer
= dev_id
;
183 printk(KERN_DEBUG
"PCI: system error received: ");
184 pcibios_report_status(PCI_STATUS_SIG_SYSTEM_ERROR
, 1);
187 cntl
= *CSR_SA110_CNTL
& 0xffffdf07;
188 *CSR_SA110_CNTL
= cntl
| SA110_CNTL_RXSERR
;
191 * back off this interrupt
194 timer
->expires
= jiffies
+ HZ
;
200 static irqreturn_t
dc21285_discard_irq(int irq
, void *dev_id
)
202 printk(KERN_DEBUG
"PCI: discard timer expired\n");
203 *CSR_SA110_CNTL
&= 0xffffde07;
208 static irqreturn_t
dc21285_dparity_irq(int irq
, void *dev_id
)
212 printk(KERN_DEBUG
"PCI: data parity error detected: ");
213 pcibios_report_status(PCI_STATUS_PARITY
| PCI_STATUS_DETECTED_PARITY
, 1);
216 cmd
= *CSR_PCICMD
& 0xffff;
217 *CSR_PCICMD
= cmd
| 1 << 24;
222 static irqreturn_t
dc21285_parity_irq(int irq
, void *dev_id
)
224 struct timer_list
*timer
= dev_id
;
227 printk(KERN_DEBUG
"PCI: parity error detected: ");
228 pcibios_report_status(PCI_STATUS_PARITY
| PCI_STATUS_DETECTED_PARITY
, 1);
231 cmd
= *CSR_PCICMD
& 0xffff;
232 *CSR_PCICMD
= cmd
| 1 << 31;
235 * back off this interrupt
238 timer
->expires
= jiffies
+ HZ
;
244 int __init
dc21285_setup(int nr
, struct pci_sys_data
*sys
)
246 struct resource
*res
;
248 if (nr
|| !footbridge_cfn_mode())
251 res
= kcalloc(2, sizeof(struct resource
), GFP_KERNEL
);
253 printk("out of memory for root bus resources");
257 res
[0].flags
= IORESOURCE_MEM
;
258 res
[0].name
= "Footbridge non-prefetch";
259 res
[1].flags
= IORESOURCE_MEM
| IORESOURCE_PREFETCH
;
260 res
[1].name
= "Footbridge prefetch";
262 allocate_resource(&iomem_resource
, &res
[1], 0x20000000,
263 0xa0000000, 0xffffffff, 0x20000000, NULL
, NULL
);
264 allocate_resource(&iomem_resource
, &res
[0], 0x40000000,
265 0x80000000, 0xffffffff, 0x40000000, NULL
, NULL
);
267 sys
->mem_offset
= DC21285_PCI_MEM
;
269 pci_add_resource_offset(&sys
->resources
, &res
[0], sys
->mem_offset
);
270 pci_add_resource_offset(&sys
->resources
, &res
[1], sys
->mem_offset
);
275 #define dc21285_request_irq(_a, _b, _c, _d, _e) \
276 WARN_ON(request_irq(_a, _b, _c, _d, _e) < 0)
278 void __init
dc21285_preinit(void)
280 unsigned int mem_size
, mem_mask
;
283 pcibios_min_mem
= 0x81000000;
285 mem_size
= (unsigned int)high_memory
- PAGE_OFFSET
;
286 for (mem_mask
= 0x00100000; mem_mask
< 0x10000000; mem_mask
<<= 1)
287 if (mem_mask
>= mem_size
)
291 * These registers need to be set up whether we're the
292 * central function or not.
294 *CSR_SDRAMBASEMASK
= (mem_mask
- 1) & 0x0ffc0000;
295 *CSR_SDRAMBASEOFFSET
= 0;
296 *CSR_ROMBASEMASK
= 0x80000000;
297 *CSR_CSRBASEMASK
= 0;
298 *CSR_CSRBASEOFFSET
= 0;
299 *CSR_PCIADDR_EXTN
= 0;
301 cfn_mode
= __footbridge_cfn_mode();
303 printk(KERN_INFO
"PCI: DC21285 footbridge, revision %02lX, in "
304 "%s mode\n", *CSR_CLASSREV
& 0xff, cfn_mode
?
305 "central function" : "addin");
307 if (footbridge_cfn_mode()) {
309 * Clear any existing errors - we aren't
310 * interested in historical data...
312 *CSR_SA110_CNTL
= (*CSR_SA110_CNTL
& 0xffffde07) |
314 *CSR_PCICMD
= (*CSR_PCICMD
& 0xffff) | PCICMD_ERROR_BITS
;
317 timer_setup(&serr_timer
, dc21285_enable_error
, 0);
318 timer_setup(&perr_timer
, dc21285_enable_error
, 0);
321 * We don't care if these fail.
323 dc21285_request_irq(IRQ_PCI_SERR
, dc21285_serr_irq
, 0,
324 "PCI system error", &serr_timer
);
325 dc21285_request_irq(IRQ_PCI_PERR
, dc21285_parity_irq
, 0,
326 "PCI parity error", &perr_timer
);
327 dc21285_request_irq(IRQ_PCI_ABORT
, dc21285_abort_irq
, 0,
329 dc21285_request_irq(IRQ_DISCARD_TIMER
, dc21285_discard_irq
, 0,
330 "Discard timer", NULL
);
331 dc21285_request_irq(IRQ_PCI_DPERR
, dc21285_dparity_irq
, 0,
332 "PCI data parity", NULL
);
336 * Map our SDRAM at a known address in PCI space, just in case
337 * the firmware had other ideas. Using a nonzero base is
338 * necessary, since some VGA cards forcefully use PCI addresses
339 * in the range 0x000a0000 to 0x000c0000. (eg, S3 cards).
341 *CSR_PCICSRBASE
= 0xf4000000;
342 *CSR_PCICSRIOBASE
= 0;
343 *CSR_PCISDRAMBASE
= __virt_to_bus(PAGE_OFFSET
);
345 *CSR_PCICMD
= PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
|
346 PCI_COMMAND_INVALIDATE
| PCICMD_ERROR_BITS
;
347 } else if (footbridge_cfn_mode() != 0) {
349 * If we are not compiled to accept "add-in" mode, then
350 * we are using a constant virt_to_bus translation which
351 * can not hope to cater for the way the host BIOS has
352 * set up the machine.
354 panic("PCI: this kernel is compiled for central "
355 "function mode only");
359 void __init
dc21285_postinit(void)
361 register_isa_ports(DC21285_PCI_MEM
, DC21285_PCI_IO
, 0);