2 * Copyright (C) 2006 PA Semi, Inc
4 * Authors: Kip Walker, PA Semi
5 * Olof Johansson, PA Semi
7 * Maintained by: Olof Johansson <olof@lixom.net>
9 * Based on arch/powerpc/platforms/maple/pci.c
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/kernel.h>
27 #include <linux/pci.h>
29 #include <asm/pci-bridge.h>
30 #include <asm/machdep.h>
32 #include <asm/ppc-pci.h>
34 #define PA_PXP_CFA(bus, devfn, off) (((bus) << 20) | ((devfn) << 12) | (off))
36 #define CONFIG_OFFSET_VALID(off) ((off) < 4096)
38 static void volatile __iomem *pa_pxp_cfg_addr(struct pci_controller *hose,
39 u8 bus, u8 devfn, int offset)
41 return hose->cfg_data + PA_PXP_CFA(bus, devfn, offset);
44 static int pa_pxp_read_config(struct pci_bus *bus, unsigned int devfn,
45 int offset, int len, u32 *val)
47 struct pci_controller *hose;
48 void volatile __iomem *addr;
50 hose = pci_bus_to_host(bus);
52 return PCIBIOS_DEVICE_NOT_FOUND;
54 if (!CONFIG_OFFSET_VALID(offset))
55 return PCIBIOS_BAD_REGISTER_NUMBER;
57 addr = pa_pxp_cfg_addr(hose, bus->number, devfn, offset);
60 * Note: the caller has already checked that offset is
61 * suitably aligned and that len is 1, 2 or 4.
75 return PCIBIOS_SUCCESSFUL;
78 static int pa_pxp_write_config(struct pci_bus *bus, unsigned int devfn,
79 int offset, int len, u32 val)
81 struct pci_controller *hose;
82 void volatile __iomem *addr;
84 hose = pci_bus_to_host(bus);
86 return PCIBIOS_DEVICE_NOT_FOUND;
88 if (!CONFIG_OFFSET_VALID(offset))
89 return PCIBIOS_BAD_REGISTER_NUMBER;
91 addr = pa_pxp_cfg_addr(hose, bus->number, devfn, offset);
94 * Note: the caller has already checked that offset is
95 * suitably aligned and that len is 1, 2 or 4.
104 (void) in_le16(addr);
108 (void) in_le32(addr);
111 return PCIBIOS_SUCCESSFUL;
114 static struct pci_ops pa_pxp_ops = {
119 static void __init setup_pa_pxp(struct pci_controller *hose)
121 hose->ops = &pa_pxp_ops;
122 hose->cfg_data = ioremap(0xe0000000, 0x10000000);
125 static int __init add_bridge(struct device_node *dev)
127 struct pci_controller *hose;
129 pr_debug("Adding PCI host bridge %s\n", dev->full_name);
131 hose = pcibios_alloc_controller(dev);
135 hose->first_busno = 0;
136 hose->last_busno = 0xff;
140 printk(KERN_INFO "Found PA-PXP PCI host bridge.\n");
142 /* Interpret the "ranges" property */
143 /* This also maps the I/O region and sets isa_io/mem_base */
144 pci_process_bridge_OF_ranges(hose, dev, 1);
145 pci_setup_phb_io(hose, 1);
151 static void __init pas_fixup_phb_resources(void)
153 struct pci_controller *hose, *tmp;
155 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
156 unsigned long offset = (unsigned long)hose->io_base_virt - pci_io_base;
157 hose->io_resource.start += offset;
158 hose->io_resource.end += offset;
159 printk(KERN_INFO "PCI Host %d, io start: %lx; io end: %lx\n",
161 hose->io_resource.start, hose->io_resource.end);
166 void __init pas_pci_init(void)
168 struct device_node *np, *root;
170 root = of_find_node_by_path("/");
172 printk(KERN_CRIT "pas_pci_init: can't find root "
177 for (np = NULL; (np = of_get_next_child(root, np)) != NULL;)
178 if (np->name && !strcmp(np->name, "pxp") && !add_bridge(np))
183 pas_fixup_phb_resources();
185 /* Setup the linkage between OF nodes and PHBs */
188 /* Use the common resource allocation mechanism */