Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 1 | /* |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 2 | * MPC83xx/85xx/86xx PCI/PCIE support routing. |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 3 | * |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 4 | * Copyright 2007,2008 Freescale Semiconductor, Inc |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 5 | * |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 6 | * Initial author: Xianghua Xiao <x.xiao@freescale.com> |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 7 | * Recode: ZHANG WEI <wei.zhang@freescale.com> |
| 8 | * Rewrite the routing for Frescale PCI and PCI Express |
| 9 | * Roy Zang <tie-fei.zang@freescale.com> |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | */ |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 17 | #include <linux/pci.h> |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 18 | #include <linux/delay.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/bootmem.h> |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 22 | |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <asm/prom.h> |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 25 | #include <asm/pci-bridge.h> |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 26 | #include <asm/machdep.h> |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 27 | #include <sysdev/fsl_soc.h> |
Roy Zang | 55c4499 | 2007-07-10 18:44:34 +0800 | [diff] [blame] | 28 | #include <sysdev/fsl_pci.h> |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 29 | |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 30 | #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx) |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 31 | static int __init setup_one_atmu(struct ccsr_pci __iomem *pci, |
| 32 | unsigned int index, const struct resource *res, |
| 33 | resource_size_t offset) |
| 34 | { |
| 35 | resource_size_t pci_addr = res->start - offset; |
| 36 | resource_size_t phys_addr = res->start; |
| 37 | resource_size_t size = res->end - res->start + 1; |
| 38 | u32 flags = 0x80044000; /* enable & mem R/W */ |
| 39 | unsigned int i; |
| 40 | |
| 41 | pr_debug("PCI MEM resource start 0x%016llx, size 0x%016llx.\n", |
| 42 | (u64)res->start, (u64)size); |
| 43 | |
| 44 | for (i = 0; size > 0; i++) { |
| 45 | unsigned int bits = min(__ilog2(size), |
| 46 | __ffs(pci_addr | phys_addr)); |
| 47 | |
| 48 | if (index + i >= 5) |
| 49 | return -1; |
| 50 | |
| 51 | out_be32(&pci->pow[index + i].potar, pci_addr >> 12); |
| 52 | out_be32(&pci->pow[index + i].potear, (u64)pci_addr >> 44); |
| 53 | out_be32(&pci->pow[index + i].powbar, phys_addr >> 12); |
| 54 | out_be32(&pci->pow[index + i].powar, flags | (bits - 1)); |
| 55 | |
| 56 | pci_addr += (resource_size_t)1U << bits; |
| 57 | phys_addr += (resource_size_t)1U << bits; |
| 58 | size -= (resource_size_t)1U << bits; |
| 59 | } |
| 60 | |
| 61 | return i; |
| 62 | } |
| 63 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 64 | /* atmu setup for fsl pci/pcie controller */ |
Anton Vorontsov | c9dadff | 2008-12-29 19:40:32 +0300 | [diff] [blame] | 65 | static void __init setup_pci_atmu(struct pci_controller *hose, |
| 66 | struct resource *rsrc) |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 67 | { |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 68 | struct ccsr_pci __iomem *pci; |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 69 | int i, j, n; |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 70 | |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 71 | pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n", |
| 72 | (u64)rsrc->start, (u64)rsrc->end - (u64)rsrc->start + 1); |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 73 | pci = ioremap(rsrc->start, rsrc->end - rsrc->start + 1); |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 74 | if (!pci) { |
| 75 | dev_err(hose->parent, "Unable to map ATMU registers\n"); |
| 76 | return; |
| 77 | } |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 78 | |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 79 | /* Disable all windows (except powar0 since it's ignored) */ |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 80 | for(i = 1; i < 5; i++) |
| 81 | out_be32(&pci->pow[i].powar, 0); |
| 82 | for(i = 0; i < 3; i++) |
| 83 | out_be32(&pci->piw[i].piwar, 0); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 84 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 85 | /* Setup outbound MEM window */ |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 86 | for(i = 0, j = 1; i < 3; i++) { |
| 87 | if (!(hose->mem_resources[i].flags & IORESOURCE_MEM)) |
| 88 | continue; |
| 89 | |
| 90 | n = setup_one_atmu(pci, j, &hose->mem_resources[i], |
| 91 | hose->pci_mem_offset); |
| 92 | |
| 93 | if (n < 0 || j >= 5) { |
| 94 | pr_err("Ran out of outbound PCI ATMUs for resource %d!\n", i); |
| 95 | hose->mem_resources[i].flags |= IORESOURCE_DISABLED; |
| 96 | } else |
| 97 | j += n; |
| 98 | } |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 99 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 100 | /* Setup outbound IO window */ |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 101 | if (hose->io_resource.flags & IORESOURCE_IO) { |
| 102 | if (j >= 5) { |
| 103 | pr_err("Ran out of outbound PCI ATMUs for IO resource\n"); |
| 104 | } else { |
| 105 | pr_debug("PCI IO resource start 0x%016llx, size 0x%016llx, " |
| 106 | "phy base 0x%016llx.\n", |
| 107 | (u64)hose->io_resource.start, |
| 108 | (u64)hose->io_resource.end - (u64)hose->io_resource.start + 1, |
| 109 | (u64)hose->io_base_phys); |
| 110 | out_be32(&pci->pow[j].potar, (hose->io_resource.start >> 12)); |
| 111 | out_be32(&pci->pow[j].potear, 0); |
| 112 | out_be32(&pci->pow[j].powbar, (hose->io_base_phys >> 12)); |
| 113 | /* Enable, IO R/W */ |
| 114 | out_be32(&pci->pow[j].powar, 0x80088000 |
| 115 | | (__ilog2(hose->io_resource.end |
| 116 | - hose->io_resource.start + 1) - 1)); |
| 117 | } |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 118 | } |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 119 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 120 | /* Setup 2G inbound Memory Window @ 1 */ |
| 121 | out_be32(&pci->piw[2].pitar, 0x00000000); |
| 122 | out_be32(&pci->piw[2].piwbar,0x00000000); |
| 123 | out_be32(&pci->piw[2].piwar, PIWAR_2G); |
Trent Piepho | a097a78 | 2009-01-06 22:37:53 -0600 | [diff] [blame^] | 124 | |
| 125 | iounmap(pci); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Anton Vorontsov | c9dadff | 2008-12-29 19:40:32 +0300 | [diff] [blame] | 128 | static void __init setup_pci_cmd(struct pci_controller *hose) |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 129 | { |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 130 | u16 cmd; |
Kumar Gala | eb12af4 | 2007-07-20 16:29:09 -0500 | [diff] [blame] | 131 | int cap_x; |
| 132 | |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 133 | early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd); |
| 134 | cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 135 | | PCI_COMMAND_IO; |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 136 | early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd); |
Kumar Gala | eb12af4 | 2007-07-20 16:29:09 -0500 | [diff] [blame] | 137 | |
| 138 | cap_x = early_find_capability(hose, 0, 0, PCI_CAP_ID_PCIX); |
| 139 | if (cap_x) { |
| 140 | int pci_x_cmd = cap_x + PCI_X_CMD; |
| 141 | cmd = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ |
| 142 | | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E; |
| 143 | early_write_config_word(hose, 0, 0, pci_x_cmd, cmd); |
| 144 | } else { |
| 145 | early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80); |
| 146 | } |
Kumar Gala | 9ad494f | 2006-06-28 00:37:45 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 149 | static void __init setup_pci_pcsrbar(struct pci_controller *hose) |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 150 | { |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 151 | #ifdef CONFIG_PCI_MSI |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 152 | phys_addr_t immr_base; |
| 153 | |
| 154 | immr_base = get_immrbase(); |
| 155 | early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 156 | #endif |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 157 | } |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 158 | |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 159 | static int fsl_pcie_bus_fixup; |
Zhang Wei | 20243c7 | 2007-06-26 18:22:40 -0500 | [diff] [blame] | 160 | |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 161 | static void __init quirk_fsl_pcie_header(struct pci_dev *dev) |
| 162 | { |
Kumar Gala | 957ecff | 2007-07-11 13:31:58 -0500 | [diff] [blame] | 163 | /* if we aren't a PCIe don't bother */ |
| 164 | if (!pci_find_capability(dev, PCI_CAP_ID_EXP)) |
| 165 | return ; |
| 166 | |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 167 | dev->class = PCI_CLASS_BRIDGE_PCI << 8; |
| 168 | fsl_pcie_bus_fixup = 1; |
| 169 | return ; |
Zhang Wei | 20243c7 | 2007-06-26 18:22:40 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Anton Vorontsov | c9dadff | 2008-12-29 19:40:32 +0300 | [diff] [blame] | 172 | static int __init fsl_pcie_check_link(struct pci_controller *hose) |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 173 | { |
Kumar Gala | 2fce1225 | 2007-10-03 23:37:33 -0500 | [diff] [blame] | 174 | u32 val; |
| 175 | early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val); |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 176 | if (val < PCIE_LTSSM_L0) |
| 177 | return 1; |
| 178 | return 0; |
| 179 | } |
Zhang Wei | 20243c7 | 2007-06-26 18:22:40 -0500 | [diff] [blame] | 180 | |
Kumar Gala | 6c0a11c | 2007-07-19 15:29:53 -0500 | [diff] [blame] | 181 | void fsl_pcibios_fixup_bus(struct pci_bus *bus) |
| 182 | { |
| 183 | struct pci_controller *hose = (struct pci_controller *) bus->sysdata; |
| 184 | int i; |
| 185 | |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 186 | if ((bus->parent == hose->bus) && |
| 187 | ((fsl_pcie_bus_fixup && |
| 188 | early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) || |
| 189 | (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK))) |
| 190 | { |
| 191 | for (i = 0; i < 4; ++i) { |
| 192 | struct resource *res = bus->resource[i]; |
| 193 | struct resource *par = bus->parent->resource[i]; |
| 194 | if (res) { |
| 195 | res->start = 0; |
| 196 | res->end = 0; |
| 197 | res->flags = 0; |
| 198 | } |
| 199 | if (res && par) { |
| 200 | res->start = par->start; |
| 201 | res->end = par->end; |
| 202 | res->flags = par->flags; |
| 203 | } |
Kumar Gala | 6c0a11c | 2007-07-19 15:29:53 -0500 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 208 | int __init fsl_add_bridge(struct device_node *dev, int is_primary) |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 209 | { |
| 210 | int len; |
| 211 | struct pci_controller *hose; |
| 212 | struct resource rsrc; |
Jeremy Kerr | 8efca49 | 2006-07-12 15:39:42 +1000 | [diff] [blame] | 213 | const int *bus_range; |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 214 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 215 | pr_debug("Adding PCI host bridge %s\n", dev->full_name); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 216 | |
| 217 | /* Fetch host bridge registers address */ |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 218 | if (of_address_to_resource(dev, 0, &rsrc)) { |
| 219 | printk(KERN_WARNING "Can't get pci register base!"); |
| 220 | return -ENOMEM; |
| 221 | } |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 222 | |
| 223 | /* Get bus range if any */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 224 | bus_range = of_get_property(dev, "bus-range", &len); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 225 | if (bus_range == NULL || len < 2 * sizeof(int)) |
| 226 | printk(KERN_WARNING "Can't get bus-range for %s, assume" |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 227 | " bus 0\n", dev->full_name); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 228 | |
Josh Boyer | 7fe519c | 2008-12-11 09:46:44 +0000 | [diff] [blame] | 229 | ppc_pci_add_flags(PPC_PCI_REASSIGN_ALL_BUS); |
Kumar Gala | dbf8471 | 2007-06-27 01:56:50 -0500 | [diff] [blame] | 230 | hose = pcibios_alloc_controller(dev); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 231 | if (!hose) |
| 232 | return -ENOMEM; |
Kumar Gala | dbf8471 | 2007-06-27 01:56:50 -0500 | [diff] [blame] | 233 | |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 234 | hose->first_busno = bus_range ? bus_range[0] : 0x0; |
Zhang Wei | bf7c036 | 2007-05-22 11:38:26 +0800 | [diff] [blame] | 235 | hose->last_busno = bus_range ? bus_range[1] : 0xff; |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 236 | |
Kumar Gala | 2e56ff2 | 2007-07-19 16:07:35 -0500 | [diff] [blame] | 237 | setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4, |
| 238 | PPC_INDIRECT_TYPE_BIG_ENDIAN); |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 239 | setup_pci_cmd(hose); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 240 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 241 | /* check PCI express link status */ |
Kumar Gala | 957ecff | 2007-07-11 13:31:58 -0500 | [diff] [blame] | 242 | if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) { |
Kumar Gala | 7659c03 | 2007-07-25 00:29:53 -0500 | [diff] [blame] | 243 | hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG | |
Kumar Gala | 957ecff | 2007-07-11 13:31:58 -0500 | [diff] [blame] | 244 | PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS; |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 245 | if (fsl_pcie_check_link(hose)) |
Kumar Gala | 957ecff | 2007-07-11 13:31:58 -0500 | [diff] [blame] | 246 | hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK; |
| 247 | } |
Zhang Wei | e4725c2 | 2007-06-25 15:21:10 -0500 | [diff] [blame] | 248 | |
joe@perches.com | df3c901 | 2007-11-20 12:47:55 +1100 | [diff] [blame] | 249 | printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. " |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 250 | "Firmware bus number: %d->%d\n", |
| 251 | (unsigned long long)rsrc.start, hose->first_busno, |
| 252 | hose->last_busno); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 253 | |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 254 | pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n", |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 255 | hose, hose->cfg_addr, hose->cfg_data); |
| 256 | |
| 257 | /* Interpret the "ranges" property */ |
| 258 | /* This also maps the I/O region and sets isa_io/mem_base */ |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 259 | pci_process_bridge_OF_ranges(hose, dev, is_primary); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 260 | |
| 261 | /* Setup PEX window registers */ |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 262 | setup_pci_atmu(hose, &rsrc); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 263 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 264 | /* Setup PEXCSRBAR */ |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 265 | setup_pci_pcsrbar(hose); |
Jon Loeliger | b809b3e | 2006-06-17 17:52:48 -0500 | [diff] [blame] | 266 | return 0; |
| 267 | } |
Zang Roy-r61911 | 9ac4dd3 | 2007-07-10 18:46:35 +0800 | [diff] [blame] | 268 | |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 269 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548E, quirk_fsl_pcie_header); |
| 270 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548, quirk_fsl_pcie_header); |
| 271 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543E, quirk_fsl_pcie_header); |
| 272 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543, quirk_fsl_pcie_header); |
| 273 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8547E, quirk_fsl_pcie_header); |
| 274 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545E, quirk_fsl_pcie_header); |
| 275 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545, quirk_fsl_pcie_header); |
| 276 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568E, quirk_fsl_pcie_header); |
| 277 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568, quirk_fsl_pcie_header); |
| 278 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567E, quirk_fsl_pcie_header); |
| 279 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567, quirk_fsl_pcie_header); |
| 280 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533E, quirk_fsl_pcie_header); |
| 281 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533, quirk_fsl_pcie_header); |
| 282 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544E, quirk_fsl_pcie_header); |
| 283 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544, quirk_fsl_pcie_header); |
| 284 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572E, quirk_fsl_pcie_header); |
| 285 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572, quirk_fsl_pcie_header); |
Kumar Gala | 2f3804e | 2008-07-02 01:36:15 -0500 | [diff] [blame] | 286 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536E, quirk_fsl_pcie_header); |
| 287 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536, quirk_fsl_pcie_header); |
Kumar Gala | 72b122c | 2008-01-14 17:02:19 -0600 | [diff] [blame] | 288 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_header); |
| 289 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_header); |
| 290 | DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8610, quirk_fsl_pcie_header); |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 291 | #endif /* CONFIG_PPC_85xx || CONFIG_PPC_86xx */ |
| 292 | |
John Rigby | 3522580 | 2008-10-07 15:13:18 -0600 | [diff] [blame] | 293 | #if defined(CONFIG_PPC_83xx) || defined(CONFIG_PPC_MPC512x) |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 294 | int __init mpc83xx_add_bridge(struct device_node *dev) |
| 295 | { |
| 296 | int len; |
| 297 | struct pci_controller *hose; |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 298 | struct resource rsrc_reg; |
| 299 | struct resource rsrc_cfg; |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 300 | const int *bus_range; |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 301 | int primary; |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 302 | |
| 303 | pr_debug("Adding PCI host bridge %s\n", dev->full_name); |
| 304 | |
| 305 | /* Fetch host bridge registers address */ |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 306 | if (of_address_to_resource(dev, 0, &rsrc_reg)) { |
| 307 | printk(KERN_WARNING "Can't get pci register base!\n"); |
| 308 | return -ENOMEM; |
| 309 | } |
| 310 | |
| 311 | memset(&rsrc_cfg, 0, sizeof(rsrc_cfg)); |
| 312 | |
| 313 | if (of_address_to_resource(dev, 1, &rsrc_cfg)) { |
| 314 | printk(KERN_WARNING |
| 315 | "No pci config register base in dev tree, " |
| 316 | "using default\n"); |
| 317 | /* |
| 318 | * MPC83xx supports up to two host controllers |
| 319 | * one at 0x8500 has config space registers at 0x8300 |
| 320 | * one at 0x8600 has config space registers at 0x8380 |
| 321 | */ |
| 322 | if ((rsrc_reg.start & 0xfffff) == 0x8500) |
| 323 | rsrc_cfg.start = (rsrc_reg.start & 0xfff00000) + 0x8300; |
| 324 | else if ((rsrc_reg.start & 0xfffff) == 0x8600) |
| 325 | rsrc_cfg.start = (rsrc_reg.start & 0xfff00000) + 0x8380; |
| 326 | } |
| 327 | /* |
| 328 | * Controller at offset 0x8500 is primary |
| 329 | */ |
| 330 | if ((rsrc_reg.start & 0xfffff) == 0x8500) |
| 331 | primary = 1; |
| 332 | else |
| 333 | primary = 0; |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 334 | |
| 335 | /* Get bus range if any */ |
| 336 | bus_range = of_get_property(dev, "bus-range", &len); |
| 337 | if (bus_range == NULL || len < 2 * sizeof(int)) { |
| 338 | printk(KERN_WARNING "Can't get bus-range for %s, assume" |
| 339 | " bus 0\n", dev->full_name); |
| 340 | } |
| 341 | |
Josh Boyer | 7fe519c | 2008-12-11 09:46:44 +0000 | [diff] [blame] | 342 | ppc_pci_add_flags(PPC_PCI_REASSIGN_ALL_BUS); |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 343 | hose = pcibios_alloc_controller(dev); |
| 344 | if (!hose) |
| 345 | return -ENOMEM; |
| 346 | |
| 347 | hose->first_busno = bus_range ? bus_range[0] : 0; |
| 348 | hose->last_busno = bus_range ? bus_range[1] : 0xff; |
| 349 | |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 350 | setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 4, 0); |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 351 | |
John Rigby | 3522580 | 2008-10-07 15:13:18 -0600 | [diff] [blame] | 352 | printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. " |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 353 | "Firmware bus number: %d->%d\n", |
John Rigby | 5b70a09 | 2008-10-07 13:00:18 -0600 | [diff] [blame] | 354 | (unsigned long long)rsrc_reg.start, hose->first_busno, |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 355 | hose->last_busno); |
| 356 | |
| 357 | pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n", |
| 358 | hose, hose->cfg_addr, hose->cfg_data); |
| 359 | |
| 360 | /* Interpret the "ranges" property */ |
| 361 | /* This also maps the I/O region and sets isa_io/mem_base */ |
| 362 | pci_process_bridge_OF_ranges(hose, dev, primary); |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | #endif /* CONFIG_PPC_83xx */ |