2 * arch/arm/plat-iop/pci.c
4 * PCI support for the Intel IOP32X and IOP33X processors
6 * Author: Rory Bolt <rorybolt@pacbell.net>
7 * Copyright (C) 2002 Rory Bolt
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/pci.h>
16 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <linux/ioport.h>
22 #include <asm/signal.h>
23 #include <asm/system.h>
24 #include <mach/hardware.h>
25 #include <asm/mach/pci.h>
26 #include <asm/hardware/iop3xx.h>
31 #define DBG(x...) printk(x)
33 #define DBG(x...) do { } while (0)
37 * This routine builds either a type0 or type1 configuration command. If the
38 * bus is on the 803xx then a type0 made, else a type1 is created.
40 static u32
iop3xx_cfg_address(struct pci_bus
*bus
, int devfn
, int where
)
42 struct pci_sys_data
*sys
= bus
->sysdata
;
45 if (sys
->busnr
== bus
->number
)
46 addr
= 1 << (PCI_SLOT(devfn
) + 16) | (PCI_SLOT(devfn
) << 11);
48 addr
= bus
->number
<< 16 | PCI_SLOT(devfn
) << 11 | 1;
50 addr
|= PCI_FUNC(devfn
) << 8 | (where
& ~3);
56 * This routine checks the status of the last configuration cycle. If an error
57 * was detected it returns a 1, else it returns a 0. The errors being checked
58 * are parity, master abort, target abort (master and target). These types of
59 * errors occur during a config cycle where there is no device, like during
60 * the discovery stage.
62 static int iop3xx_pci_status(void)
68 * Check the status registers.
70 status
= *IOP3XX_ATUSR
;
71 if (status
& 0xf900) {
72 DBG("\t\t\tPCI: P0 - status = 0x%08x\n", status
);
73 *IOP3XX_ATUSR
= status
& 0xf900;
77 status
= *IOP3XX_ATUISR
;
78 if (status
& 0x679f) {
79 DBG("\t\t\tPCI: P1 - status = 0x%08x\n", status
);
80 *IOP3XX_ATUISR
= status
& 0x679f;
88 * Simply write the address register and read the configuration
89 * data. Note that the 4 nops ensure that we are able to handle
90 * a delayed abort (in theory.)
92 static u32
iop3xx_read(unsigned long addr
)
104 : "r" (addr
), "r" (IOP3XX_OCCAR
), "r" (IOP3XX_OCCDR
));
110 * The read routines must check the error status of the last configuration
111 * cycle. If there was an error, the routine returns all hex f's.
114 iop3xx_read_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
115 int size
, u32
*value
)
117 unsigned long addr
= iop3xx_cfg_address(bus
, devfn
, where
);
118 u32 val
= iop3xx_read(addr
) >> ((where
& 3) * 8);
120 if (iop3xx_pci_status())
125 return PCIBIOS_SUCCESSFUL
;
129 iop3xx_write_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
132 unsigned long addr
= iop3xx_cfg_address(bus
, devfn
, where
);
136 val
= iop3xx_read(addr
);
137 if (iop3xx_pci_status())
138 return PCIBIOS_SUCCESSFUL
;
140 where
= (where
& 3) * 8;
143 val
&= ~(0xff << where
);
145 val
&= ~(0xffff << where
);
147 *IOP3XX_OCCDR
= val
| value
<< where
;
157 : "r" (value
), "r" (addr
),
158 "r" (IOP3XX_OCCAR
), "r" (IOP3XX_OCCDR
));
161 return PCIBIOS_SUCCESSFUL
;
164 static struct pci_ops iop3xx_ops
= {
165 .read
= iop3xx_read_config
,
166 .write
= iop3xx_write_config
,
170 * When a PCI device does not exist during config cycles, the 80200 gets a
171 * bus error instead of returning 0xffffffff. This handler simply returns.
174 iop3xx_pci_abort(unsigned long addr
, unsigned int fsr
, struct pt_regs
*regs
)
176 DBG("PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx\n",
177 addr
, fsr
, regs
->ARM_pc
, regs
->ARM_lr
);
180 * If it was an imprecise abort, then we need to correct the
181 * return address to be _after_ the instruction.
189 int iop3xx_pci_setup(int nr
, struct pci_sys_data
*sys
)
191 struct resource
*res
;
196 res
= kzalloc(2 * sizeof(struct resource
), GFP_KERNEL
);
198 panic("PCI: unable to alloc resources");
200 res
[0].start
= IOP3XX_PCI_LOWER_IO_PA
;
201 res
[0].end
= IOP3XX_PCI_LOWER_IO_PA
+ IOP3XX_PCI_IO_WINDOW_SIZE
- 1;
202 res
[0].name
= "IOP3XX PCI I/O Space";
203 res
[0].flags
= IORESOURCE_IO
;
204 request_resource(&ioport_resource
, &res
[0]);
206 res
[1].start
= IOP3XX_PCI_LOWER_MEM_PA
;
207 res
[1].end
= IOP3XX_PCI_LOWER_MEM_PA
+ IOP3XX_PCI_MEM_WINDOW_SIZE
- 1;
208 res
[1].name
= "IOP3XX PCI Memory Space";
209 res
[1].flags
= IORESOURCE_MEM
;
210 request_resource(&iomem_resource
, &res
[1]);
213 * Use whatever translation is already setup.
215 sys
->mem_offset
= IOP3XX_PCI_LOWER_MEM_PA
- *IOP3XX_OMWTVR0
;
216 sys
->io_offset
= IOP3XX_PCI_LOWER_IO_PA
- *IOP3XX_OIOWTVR
;
218 pci_add_resource(&sys
->resources
, &res
[0]);
219 pci_add_resource(&sys
->resources
, &res
[1]);
224 struct pci_bus
*iop3xx_pci_scan_bus(int nr
, struct pci_sys_data
*sys
)
226 return pci_scan_root_bus(NULL
, sys
->busnr
, &iop3xx_ops
, sys
,
230 void __init
iop3xx_atu_setup(void)
232 /* BAR 0 ( Disabled ) */
233 *IOP3XX_IAUBAR0
= 0x0;
234 *IOP3XX_IABAR0
= 0x0;
235 *IOP3XX_IATVR0
= 0x0;
238 /* BAR 1 ( Disabled ) */
239 *IOP3XX_IAUBAR1
= 0x0;
240 *IOP3XX_IABAR1
= 0x0;
243 /* BAR 2 (1:1 mapping with Physical RAM) */
244 /* Set limit and enable */
245 *IOP3XX_IALR2
= ~((u32
)IOP3XX_MAX_RAM_SIZE
- 1) & ~0x1;
246 *IOP3XX_IAUBAR2
= 0x0;
248 /* Align the inbound bar with the base of memory */
249 *IOP3XX_IABAR2
= PHYS_OFFSET
|
250 PCI_BASE_ADDRESS_MEM_TYPE_64
|
251 PCI_BASE_ADDRESS_MEM_PREFETCH
;
253 *IOP3XX_IATVR2
= PHYS_OFFSET
;
255 /* Outbound window 0 */
256 *IOP3XX_OMWTVR0
= IOP3XX_PCI_LOWER_MEM_BA
;
257 *IOP3XX_OUMWTVR0
= 0;
259 /* Outbound window 1 */
260 *IOP3XX_OMWTVR1
= IOP3XX_PCI_LOWER_MEM_BA
+
261 IOP3XX_PCI_MEM_WINDOW_SIZE
/ 2;
262 *IOP3XX_OUMWTVR1
= 0;
264 /* BAR 3 ( Disabled ) */
265 *IOP3XX_IAUBAR3
= 0x0;
266 *IOP3XX_IABAR3
= 0x0;
267 *IOP3XX_IATVR3
= 0x0;
272 *IOP3XX_OIOWTVR
= IOP3XX_PCI_LOWER_IO_BA
;
274 /* Enable inbound and outbound cycles
276 *IOP3XX_ATUCMD
|= PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
|
277 PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
278 *IOP3XX_ATUCR
|= IOP3XX_ATUCR_OUT_EN
;
281 void __init
iop3xx_atu_disable(void)
286 /* wait for cycles to quiesce */
287 while (*IOP3XX_PCSR
& (IOP3XX_PCSR_OUT_Q_BUSY
|
288 IOP3XX_PCSR_IN_Q_BUSY
))
291 /* BAR 0 ( Disabled ) */
292 *IOP3XX_IAUBAR0
= 0x0;
293 *IOP3XX_IABAR0
= 0x0;
294 *IOP3XX_IATVR0
= 0x0;
297 /* BAR 1 ( Disabled ) */
298 *IOP3XX_IAUBAR1
= 0x0;
299 *IOP3XX_IABAR1
= 0x0;
302 /* BAR 2 ( Disabled ) */
303 *IOP3XX_IAUBAR2
= 0x0;
304 *IOP3XX_IABAR2
= 0x0;
305 *IOP3XX_IATVR2
= 0x0;
308 /* BAR 3 ( Disabled ) */
309 *IOP3XX_IAUBAR3
= 0x0;
310 *IOP3XX_IABAR3
= 0x0;
311 *IOP3XX_IATVR3
= 0x0;
314 /* Clear the outbound windows */
317 /* Outbound window 0 */
319 *IOP3XX_OUMWTVR0
= 0;
321 /* Outbound window 1 */
323 *IOP3XX_OUMWTVR1
= 0;
326 /* Flag to determine whether the ATU is initialized and the PCI bus scanned */
329 int iop3xx_get_init_atu(void) {
330 /* check if default has been overridden */
331 if (init_atu
!= IOP3XX_INIT_ATU_DEFAULT
)
334 return IOP3XX_INIT_ATU_DISABLE
;
337 static void __init
iop3xx_atu_debug(void)
339 DBG("PCI: Intel IOP3xx PCI init.\n");
340 DBG("PCI: Outbound memory window 0: PCI 0x%08x%08x\n",
341 *IOP3XX_OUMWTVR0
, *IOP3XX_OMWTVR0
);
342 DBG("PCI: Outbound memory window 1: PCI 0x%08x%08x\n",
343 *IOP3XX_OUMWTVR1
, *IOP3XX_OMWTVR1
);
344 DBG("PCI: Outbound IO window: PCI 0x%08x\n",
347 DBG("PCI: Inbound memory window 0: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
348 *IOP3XX_IAUBAR0
, *IOP3XX_IABAR0
, *IOP3XX_IALR0
, *IOP3XX_IATVR0
);
349 DBG("PCI: Inbound memory window 1: PCI 0x%08x%08x 0x%08x\n",
350 *IOP3XX_IAUBAR1
, *IOP3XX_IABAR1
, *IOP3XX_IALR1
);
351 DBG("PCI: Inbound memory window 2: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
352 *IOP3XX_IAUBAR2
, *IOP3XX_IABAR2
, *IOP3XX_IALR2
, *IOP3XX_IATVR2
);
353 DBG("PCI: Inbound memory window 3: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
354 *IOP3XX_IAUBAR3
, *IOP3XX_IABAR3
, *IOP3XX_IALR3
, *IOP3XX_IATVR3
);
356 DBG("PCI: Expansion ROM window: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
357 0, *IOP3XX_ERBAR
, *IOP3XX_ERLR
, *IOP3XX_ERTVR
);
359 DBG("ATU: IOP3XX_ATUCMD=0x%04x\n", *IOP3XX_ATUCMD
);
360 DBG("ATU: IOP3XX_ATUCR=0x%08x\n", *IOP3XX_ATUCR
);
362 hook_fault_code(16+6, iop3xx_pci_abort
, SIGBUS
, 0, "imprecise external abort");
365 /* for platforms that might be host-bus-adapters */
366 void __init
iop3xx_pci_preinit_cond(void)
368 if (iop3xx_get_init_atu() == IOP3XX_INIT_ATU_ENABLE
) {
369 iop3xx_atu_disable();
375 void __init
iop3xx_pci_preinit(void)
380 iop3xx_atu_disable();
385 /* allow init_atu to be user overridden */
386 static int __init
iop3xx_init_atu_setup(char *str
)
388 init_atu
= IOP3XX_INIT_ATU_DEFAULT
;
390 while (*str
!= '\0') {
394 init_atu
= IOP3XX_INIT_ATU_ENABLE
;
398 init_atu
= IOP3XX_INIT_ATU_DISABLE
;
404 printk(KERN_DEBUG
"\"%s\" malformed at "
417 __setup("iop3xx_init_atu", iop3xx_init_atu_setup
);