2 * arch/arm/mach-ixp23xx/pci.c
4 * PCI routines for IXP23XX based systems
6 * Copyright (c) 2005 MontaVista Software, Inc.
8 * based on original code:
10 * Author: Naeem Afzal <naeem.m.afzal@intel.com>
11 * Copyright 2002-2005 Intel Corp.
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 #include <linux/config.h>
20 #include <linux/sched.h>
21 #include <linux/kernel.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
25 #include <linux/init.h>
26 #include <linux/ioport.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
32 #include <asm/sizes.h>
33 #include <asm/system.h>
34 #include <asm/mach/pci.h>
35 #include <asm/mach-types.h>
36 #include <asm/hardware.h>
38 extern int (*external_fault
) (unsigned long, struct pt_regs
*);
40 static int pci_master_aborts
= 0;
43 #define DBG(x...) printk(x)
48 int clear_master_aborts(void);
51 *ixp23xx_pci_config_addr(unsigned int bus_nr
, unsigned int devfn
, int where
)
56 * Must be dword aligned
61 * For top bus, generate type 0, else type 1
64 if (PCI_SLOT(devfn
) >= 8)
67 paddress
= (u32
*) (IXP23XX_PCI_CFG0_VIRT
68 | (1 << (PCI_SLOT(devfn
) + 16))
69 | (PCI_FUNC(devfn
) << 8) | where
);
71 paddress
= (u32
*) (IXP23XX_PCI_CFG1_VIRT
73 | (PCI_SLOT(devfn
) << 11)
74 | (PCI_FUNC(devfn
) << 8) | where
);
81 * Mask table, bits to mask for quantity of size 1, 2 or 4 bytes.
82 * 0 and 3 are not valid indexes...
84 static u32 bytemask
[] = {
92 static int ixp23xx_pci_read_config(struct pci_bus
*bus
, unsigned int devfn
,
93 int where
, int size
, u32
*value
)
100 DBG("In config_read(%d) %d from dev %d:%d:%d\n", size
, where
,
101 bus
->number
, PCI_SLOT(devfn
), PCI_FUNC(devfn
));
103 addr
= ixp23xx_pci_config_addr(bus
->number
, devfn
, where
);
105 return PCIBIOS_DEVICE_NOT_FOUND
;
107 pci_master_aborts
= 0;
108 *value
= (*addr
>> (8*n
)) & bytemask
[size
];
109 if (pci_master_aborts
) {
110 pci_master_aborts
= 0;
112 return PCIBIOS_DEVICE_NOT_FOUND
;
115 return PCIBIOS_SUCCESSFUL
;
119 * We don't do error checking on the address for writes.
120 * It's assumed that the user checked for the device existing first
121 * by doing a read first.
123 static int ixp23xx_pci_write_config(struct pci_bus
*bus
, unsigned int devfn
,
124 int where
, int size
, u32 value
)
130 mask
= ~(bytemask
[size
] << ((where
% 0x4) * 8));
131 addr
= ixp23xx_pci_config_addr(bus
->number
, devfn
, where
);
133 return PCIBIOS_DEVICE_NOT_FOUND
;
134 temp
= (u32
) (value
) << ((where
% 0x4) * 8);
135 *addr
= (*addr
& mask
) | temp
;
137 clear_master_aborts();
139 return PCIBIOS_SUCCESSFUL
;
142 struct pci_ops ixp23xx_pci_ops
= {
143 .read
= ixp23xx_pci_read_config
,
144 .write
= ixp23xx_pci_write_config
,
147 struct pci_bus
*ixp23xx_pci_scan_bus(int nr
, struct pci_sys_data
*sysdata
)
149 return pci_scan_bus(sysdata
->busnr
, &ixp23xx_pci_ops
, sysdata
);
152 int ixp23xx_pci_abort_handler(unsigned long addr
, unsigned int fsr
, struct pt_regs
*regs
)
154 volatile unsigned long temp
;
157 pci_master_aborts
= 1;
159 local_irq_save(flags
);
160 temp
= *IXP23XX_PCI_CONTROL
;
163 * master abort and cmd tgt err
165 if (temp
& ((1 << 8) | (1 << 5)))
166 *IXP23XX_PCI_CONTROL
= temp
;
168 temp
= *IXP23XX_PCI_CMDSTAT
;
170 if (temp
& (1 << 29))
171 *IXP23XX_PCI_CMDSTAT
= temp
;
172 local_irq_restore(flags
);
175 * If it was an imprecise abort, then we need to correct the
176 * return address to be _after_ the instruction.
184 int clear_master_aborts(void)
188 temp
= *IXP23XX_PCI_CONTROL
;
191 * master abort and cmd tgt err
193 if (temp
& ((1 << 8) | (1 << 5)))
194 *IXP23XX_PCI_CONTROL
= temp
;
196 temp
= *IXP23XX_PCI_CMDSTAT
;
198 if (temp
& (1 << 29))
199 *IXP23XX_PCI_CMDSTAT
= temp
;
204 static void __init
ixp23xx_pci_common_init(void)
207 *IXP23XX_PCI_CONTROL
|= 0x20000; /* set I/O swapping */
210 * ADDR_31 needs to be clear for PCI memory access to CPP memory
212 *IXP23XX_CPP2XSI_CURR_XFER_REG3
&= ~IXP23XX_CPP2XSI_ADDR_31
;
213 *IXP23XX_CPP2XSI_CURR_XFER_REG3
|= IXP23XX_CPP2XSI_PSH_OFF
;
216 * Select correct memory for PCI inbound transactions
218 if (ixp23xx_cpp_boot()) {
219 *IXP23XX_PCI_CPP_ADDR_BITS
&= ~(1 << 1);
221 *IXP23XX_PCI_CPP_ADDR_BITS
|= (1 << 1);
224 * Enable coherency on A2 silicon.
226 if (arch_is_coherent())
227 *IXP23XX_CPP2XSI_CURR_XFER_REG3
&= ~IXP23XX_CPP2XSI_COH_OFF
;
231 void __init
ixp23xx_pci_preinit(void)
233 ixp23xx_pci_common_init();
235 hook_fault_code(16+6, ixp23xx_pci_abort_handler
, SIGBUS
,
236 "PCI config cycle to non-existent device");
238 *IXP23XX_PCI_ADDR_EXT
= 0x0000e000;
242 * Prevent PCI layer from seeing the inbound host-bridge resources
244 static void __devinit
pci_fixup_ixp23xx(struct pci_dev
*dev
)
249 dev
->class |= PCI_CLASS_BRIDGE_HOST
<< 8;
250 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++) {
251 dev
->resource
[i
].start
= 0;
252 dev
->resource
[i
].end
= 0;
253 dev
->resource
[i
].flags
= 0;
256 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL
, 0x9002, pci_fixup_ixp23xx
);
259 * IXP2300 systems often have large resource requirements, so we just
260 * use our own resource space.
262 static struct resource ixp23xx_pci_mem_space
= {
263 .start
= IXP23XX_PCI_MEM_START
,
264 .end
= IXP23XX_PCI_MEM_START
+ IXP23XX_PCI_MEM_SIZE
- 1,
265 .flags
= IORESOURCE_MEM
,
266 .name
= "PCI Mem Space"
269 static struct resource ixp23xx_pci_io_space
= {
272 .flags
= IORESOURCE_IO
,
273 .name
= "PCI I/O Space"
276 int ixp23xx_pci_setup(int nr
, struct pci_sys_data
*sys
)
281 sys
->resource
[0] = &ixp23xx_pci_io_space
;
282 sys
->resource
[1] = &ixp23xx_pci_mem_space
;
283 sys
->resource
[2] = NULL
;
288 void ixp23xx_pci_slave_init(void)
290 ixp23xx_pci_common_init();