Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Support for PCI bridges found on Power Macintoshes. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 3 | * |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 4 | * Copyright (C) 2003-2005 Benjamin Herrenschmuidt (benh@kernel.crashing.org) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 5 | * Copyright (C) 1997 Paul Mackerras (paulus@samba.org) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/bootmem.h> |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 19 | #include <linux/irq.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 20 | |
| 21 | #include <asm/sections.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/prom.h> |
| 24 | #include <asm/pci-bridge.h> |
| 25 | #include <asm/machdep.h> |
| 26 | #include <asm/pmac_feature.h> |
Paul Mackerras | 830825d | 2005-10-26 17:16:38 +1000 | [diff] [blame] | 27 | #include <asm/grackle.h> |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 28 | #include <asm/ppc-pci.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 29 | |
| 30 | #undef DEBUG |
| 31 | |
| 32 | #ifdef DEBUG |
| 33 | #define DBG(x...) printk(x) |
| 34 | #else |
| 35 | #define DBG(x...) |
| 36 | #endif |
| 37 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 38 | /* XXX Could be per-controller, but I don't think we risk anything by |
| 39 | * assuming we won't have both UniNorth and Bandit */ |
| 40 | static int has_uninorth; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 41 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 42 | static struct pci_controller *u3_agp; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 43 | static struct pci_controller *u4_pcie; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 44 | static struct pci_controller *u3_ht; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 45 | #else |
| 46 | static int has_second_ohare; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 47 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 48 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 49 | extern int pcibios_assign_bus_offset; |
| 50 | |
| 51 | struct device_node *k2_skiplist[2]; |
| 52 | |
| 53 | /* |
| 54 | * Magic constants for enabling cache coherency in the bandit/PSX bridge. |
| 55 | */ |
| 56 | #define BANDIT_DEVID_2 8 |
| 57 | #define BANDIT_REVID 3 |
| 58 | |
| 59 | #define BANDIT_DEVNUM 11 |
| 60 | #define BANDIT_MAGIC 0x50 |
| 61 | #define BANDIT_COHERENT 0x40 |
| 62 | |
| 63 | static int __init fixup_one_level_bus_range(struct device_node *node, int higher) |
| 64 | { |
| 65 | for (; node != 0;node = node->sibling) { |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 66 | const int * bus_range; |
| 67 | const unsigned int *class_code; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 68 | int len; |
| 69 | |
| 70 | /* For PCI<->PCI bridges or CardBus bridges, we go down */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 71 | class_code = of_get_property(node, "class-code", NULL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 72 | if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI && |
| 73 | (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) |
| 74 | continue; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 75 | bus_range = of_get_property(node, "bus-range", &len); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 76 | if (bus_range != NULL && len > 2 * sizeof(int)) { |
| 77 | if (bus_range[1] > higher) |
| 78 | higher = bus_range[1]; |
| 79 | } |
| 80 | higher = fixup_one_level_bus_range(node->child, higher); |
| 81 | } |
| 82 | return higher; |
| 83 | } |
| 84 | |
| 85 | /* This routine fixes the "bus-range" property of all bridges in the |
| 86 | * system since they tend to have their "last" member wrong on macs |
| 87 | * |
| 88 | * Note that the bus numbers manipulated here are OF bus numbers, they |
| 89 | * are not Linux bus numbers. |
| 90 | */ |
| 91 | static void __init fixup_bus_range(struct device_node *bridge) |
| 92 | { |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 93 | int *bus_range, len; |
| 94 | struct property *prop; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 95 | |
| 96 | /* Lookup the "bus-range" property for the hose */ |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 97 | prop = of_find_property(bridge, "bus-range", &len); |
| 98 | if (prop == NULL || prop->length < 2 * sizeof(int)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 99 | return; |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 100 | |
Stephen Rothwell | 1a38147 | 2007-04-03 10:58:52 +1000 | [diff] [blame] | 101 | bus_range = prop->value; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 102 | bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]); |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers. |
| 107 | * |
| 108 | * The "Bandit" version is present in all early PCI PowerMacs, |
| 109 | * and up to the first ones using Grackle. Some machines may |
| 110 | * have 2 bandit controllers (2 PCI busses). |
| 111 | * |
| 112 | * "Chaos" is used in some "Bandit"-type machines as a bridge |
| 113 | * for the separate display bus. It is accessed the same |
| 114 | * way as bandit, but cannot be probed for devices. It therefore |
| 115 | * has its own config access functions. |
| 116 | * |
| 117 | * The "UniNorth" version is present in all Core99 machines |
| 118 | * (iBook, G4, new IMacs, and all the recent Apple machines). |
| 119 | * It contains 3 controllers in one ASIC. |
| 120 | * |
| 121 | * The U3 is the bridge used on G5 machines. It contains an |
| 122 | * AGP bus which is dealt with the old UniNorth access routines |
| 123 | * and a HyperTransport bus which uses its own set of access |
| 124 | * functions. |
| 125 | */ |
| 126 | |
| 127 | #define MACRISC_CFA0(devfn, off) \ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 128 | ((1 << (unsigned int)PCI_SLOT(dev_fn)) \ |
| 129 | | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \ |
| 130 | | (((unsigned int)(off)) & 0xFCUL)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 131 | |
| 132 | #define MACRISC_CFA1(bus, devfn, off) \ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 133 | ((((unsigned int)(bus)) << 16) \ |
| 134 | |(((unsigned int)(devfn)) << 8) \ |
| 135 | |(((unsigned int)(off)) & 0xFCUL) \ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 136 | |1UL) |
| 137 | |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 138 | static volatile void __iomem *macrisc_cfg_access(struct pci_controller* hose, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 139 | u8 bus, u8 dev_fn, u8 offset) |
| 140 | { |
| 141 | unsigned int caddr; |
| 142 | |
| 143 | if (bus == hose->first_busno) { |
| 144 | if (dev_fn < (11 << 3)) |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 145 | return NULL; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 146 | caddr = MACRISC_CFA0(dev_fn, offset); |
| 147 | } else |
| 148 | caddr = MACRISC_CFA1(bus, dev_fn, offset); |
| 149 | |
| 150 | /* Uninorth will return garbage if we don't read back the value ! */ |
| 151 | do { |
| 152 | out_le32(hose->cfg_addr, caddr); |
| 153 | } while (in_le32(hose->cfg_addr) != caddr); |
| 154 | |
| 155 | offset &= has_uninorth ? 0x07 : 0x03; |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 156 | return hose->cfg_data + offset; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static int macrisc_read_config(struct pci_bus *bus, unsigned int devfn, |
| 160 | int offset, int len, u32 *val) |
| 161 | { |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 162 | struct pci_controller *hose; |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 163 | volatile void __iomem *addr; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 164 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 165 | hose = pci_bus_to_host(bus); |
| 166 | if (hose == NULL) |
| 167 | return PCIBIOS_DEVICE_NOT_FOUND; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 168 | if (offset >= 0x100) |
| 169 | return PCIBIOS_BAD_REGISTER_NUMBER; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 170 | addr = macrisc_cfg_access(hose, bus->number, devfn, offset); |
| 171 | if (!addr) |
| 172 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 173 | /* |
| 174 | * Note: the caller has already checked that offset is |
| 175 | * suitably aligned and that len is 1, 2 or 4. |
| 176 | */ |
| 177 | switch (len) { |
| 178 | case 1: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 179 | *val = in_8(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 180 | break; |
| 181 | case 2: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 182 | *val = in_le16(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 183 | break; |
| 184 | default: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 185 | *val = in_le32(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 186 | break; |
| 187 | } |
| 188 | return PCIBIOS_SUCCESSFUL; |
| 189 | } |
| 190 | |
| 191 | static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn, |
| 192 | int offset, int len, u32 val) |
| 193 | { |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 194 | struct pci_controller *hose; |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 195 | volatile void __iomem *addr; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 196 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 197 | hose = pci_bus_to_host(bus); |
| 198 | if (hose == NULL) |
| 199 | return PCIBIOS_DEVICE_NOT_FOUND; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 200 | if (offset >= 0x100) |
| 201 | return PCIBIOS_BAD_REGISTER_NUMBER; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 202 | addr = macrisc_cfg_access(hose, bus->number, devfn, offset); |
| 203 | if (!addr) |
| 204 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 205 | /* |
| 206 | * Note: the caller has already checked that offset is |
| 207 | * suitably aligned and that len is 1, 2 or 4. |
| 208 | */ |
| 209 | switch (len) { |
| 210 | case 1: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 211 | out_8(addr, val); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 212 | break; |
| 213 | case 2: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 214 | out_le16(addr, val); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 215 | break; |
| 216 | default: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 217 | out_le32(addr, val); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | return PCIBIOS_SUCCESSFUL; |
| 221 | } |
| 222 | |
| 223 | static struct pci_ops macrisc_pci_ops = |
| 224 | { |
Nathan Lynch | 3fac10e | 2007-08-10 05:18:41 +1000 | [diff] [blame] | 225 | .read = macrisc_read_config, |
| 226 | .write = macrisc_write_config, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 227 | }; |
| 228 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 229 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 230 | /* |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 231 | * Verify that a specific (bus, dev_fn) exists on chaos |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 232 | */ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 233 | static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 234 | { |
| 235 | struct device_node *np; |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 236 | const u32 *vendor, *device; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 237 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 238 | if (offset >= 0x100) |
| 239 | return PCIBIOS_BAD_REGISTER_NUMBER; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 240 | np = pci_busdev_to_OF_node(bus, devfn); |
| 241 | if (np == NULL) |
| 242 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 243 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 244 | vendor = of_get_property(np, "vendor-id", NULL); |
| 245 | device = of_get_property(np, "device-id", NULL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 246 | if (vendor == NULL || device == NULL) |
| 247 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 248 | |
| 249 | if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10) |
| 250 | && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24)) |
| 251 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 252 | |
| 253 | return PCIBIOS_SUCCESSFUL; |
| 254 | } |
| 255 | |
| 256 | static int |
| 257 | chaos_read_config(struct pci_bus *bus, unsigned int devfn, int offset, |
| 258 | int len, u32 *val) |
| 259 | { |
| 260 | int result = chaos_validate_dev(bus, devfn, offset); |
| 261 | if (result == PCIBIOS_BAD_REGISTER_NUMBER) |
| 262 | *val = ~0U; |
| 263 | if (result != PCIBIOS_SUCCESSFUL) |
| 264 | return result; |
| 265 | return macrisc_read_config(bus, devfn, offset, len, val); |
| 266 | } |
| 267 | |
| 268 | static int |
| 269 | chaos_write_config(struct pci_bus *bus, unsigned int devfn, int offset, |
| 270 | int len, u32 val) |
| 271 | { |
| 272 | int result = chaos_validate_dev(bus, devfn, offset); |
| 273 | if (result != PCIBIOS_SUCCESSFUL) |
| 274 | return result; |
| 275 | return macrisc_write_config(bus, devfn, offset, len, val); |
| 276 | } |
| 277 | |
| 278 | static struct pci_ops chaos_pci_ops = |
| 279 | { |
Nathan Lynch | 3fac10e | 2007-08-10 05:18:41 +1000 | [diff] [blame] | 280 | .read = chaos_read_config, |
| 281 | .write = chaos_write_config, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 282 | }; |
| 283 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 284 | static void __init setup_chaos(struct pci_controller *hose, |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 285 | struct resource *addr) |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 286 | { |
| 287 | /* assume a `chaos' bridge */ |
| 288 | hose->ops = &chaos_pci_ops; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 289 | hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000); |
| 290 | hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 291 | } |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 292 | #endif /* CONFIG_PPC32 */ |
| 293 | |
| 294 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 295 | /* |
| 296 | * These versions of U3 HyperTransport config space access ops do not |
| 297 | * implement self-view of the HT host yet |
| 298 | */ |
| 299 | |
| 300 | /* |
| 301 | * This function deals with some "special cases" devices. |
| 302 | * |
| 303 | * 0 -> No special case |
| 304 | * 1 -> Skip the device but act as if the access was successfull |
| 305 | * (return 0xff's on reads, eventually, cache config space |
| 306 | * accesses in a later version) |
| 307 | * -1 -> Hide the device (unsuccessful acess) |
| 308 | */ |
| 309 | static int u3_ht_skip_device(struct pci_controller *hose, |
| 310 | struct pci_bus *bus, unsigned int devfn) |
| 311 | { |
| 312 | struct device_node *busdn, *dn; |
| 313 | int i; |
| 314 | |
| 315 | /* We only allow config cycles to devices that are in OF device-tree |
| 316 | * as we are apparently having some weird things going on with some |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 317 | * revs of K2 on recent G5s, except for the host bridge itself, which |
| 318 | * is missing from the tree but we know we can probe. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 319 | */ |
| 320 | if (bus->self) |
| 321 | busdn = pci_device_to_OF_node(bus->self); |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 322 | else if (devfn == 0) |
| 323 | return 0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 324 | else |
Stephen Rothwell | 44ef339 | 2007-12-10 14:33:21 +1100 | [diff] [blame] | 325 | busdn = hose->dn; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 326 | for (dn = busdn->child; dn; dn = dn->sibling) |
linas | e07102d | 2005-12-05 19:37:35 -0600 | [diff] [blame] | 327 | if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 328 | break; |
| 329 | if (dn == NULL) |
| 330 | return -1; |
| 331 | |
| 332 | /* |
| 333 | * When a device in K2 is powered down, we die on config |
| 334 | * cycle accesses. Fix that here. |
| 335 | */ |
| 336 | for (i=0; i<2; i++) |
| 337 | if (k2_skiplist[i] == dn) |
| 338 | return 1; |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | #define U3_HT_CFA0(devfn, off) \ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 344 | ((((unsigned int)devfn) << 8) | offset) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 345 | #define U3_HT_CFA1(bus, devfn, off) \ |
| 346 | (U3_HT_CFA0(devfn, off) \ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 347 | + (((unsigned int)bus) << 16) \ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 348 | + 0x01000000UL) |
| 349 | |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 350 | static void __iomem *u3_ht_cfg_access(struct pci_controller *hose, u8 bus, |
| 351 | u8 devfn, u8 offset, int *swap) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 352 | { |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 353 | *swap = 1; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 354 | if (bus == hose->first_busno) { |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 355 | if (devfn != 0) |
| 356 | return hose->cfg_data + U3_HT_CFA0(devfn, offset); |
| 357 | *swap = 0; |
| 358 | return ((void __iomem *)hose->cfg_addr) + (offset << 2); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 359 | } else |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 360 | return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn, |
| 364 | int offset, int len, u32 *val) |
| 365 | { |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 366 | struct pci_controller *hose; |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 367 | void __iomem *addr; |
| 368 | int swap; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 369 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 370 | hose = pci_bus_to_host(bus); |
| 371 | if (hose == NULL) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 372 | return PCIBIOS_DEVICE_NOT_FOUND; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 373 | if (offset >= 0x100) |
| 374 | return PCIBIOS_BAD_REGISTER_NUMBER; |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 375 | addr = u3_ht_cfg_access(hose, bus->number, devfn, offset, &swap); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 376 | if (!addr) |
| 377 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 378 | |
| 379 | switch (u3_ht_skip_device(hose, bus, devfn)) { |
| 380 | case 0: |
| 381 | break; |
| 382 | case 1: |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 383 | switch (len) { |
| 384 | case 1: |
| 385 | *val = 0xff; break; |
| 386 | case 2: |
| 387 | *val = 0xffff; break; |
| 388 | default: |
| 389 | *val = 0xfffffffful; break; |
| 390 | } |
| 391 | return PCIBIOS_SUCCESSFUL; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 392 | default: |
| 393 | return PCIBIOS_DEVICE_NOT_FOUND; |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 394 | } |
| 395 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 396 | /* |
| 397 | * Note: the caller has already checked that offset is |
| 398 | * suitably aligned and that len is 1, 2 or 4. |
| 399 | */ |
| 400 | switch (len) { |
| 401 | case 1: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 402 | *val = in_8(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 403 | break; |
| 404 | case 2: |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 405 | *val = swap ? in_le16(addr) : in_be16(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 406 | break; |
| 407 | default: |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 408 | *val = swap ? in_le32(addr) : in_be32(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 409 | break; |
| 410 | } |
| 411 | return PCIBIOS_SUCCESSFUL; |
| 412 | } |
| 413 | |
| 414 | static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn, |
| 415 | int offset, int len, u32 val) |
| 416 | { |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 417 | struct pci_controller *hose; |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 418 | void __iomem *addr; |
| 419 | int swap; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 420 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 421 | hose = pci_bus_to_host(bus); |
| 422 | if (hose == NULL) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 423 | return PCIBIOS_DEVICE_NOT_FOUND; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 424 | if (offset >= 0x100) |
| 425 | return PCIBIOS_BAD_REGISTER_NUMBER; |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 426 | addr = u3_ht_cfg_access(hose, bus->number, devfn, offset, &swap); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 427 | if (!addr) |
| 428 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 429 | |
| 430 | switch (u3_ht_skip_device(hose, bus, devfn)) { |
| 431 | case 0: |
| 432 | break; |
| 433 | case 1: |
| 434 | return PCIBIOS_SUCCESSFUL; |
| 435 | default: |
| 436 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Note: the caller has already checked that offset is |
| 441 | * suitably aligned and that len is 1, 2 or 4. |
| 442 | */ |
| 443 | switch (len) { |
| 444 | case 1: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 445 | out_8(addr, val); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 446 | break; |
| 447 | case 2: |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 448 | swap ? out_le16(addr, val) : out_be16(addr, val); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 449 | break; |
| 450 | default: |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 451 | swap ? out_le32(addr, val) : out_be32(addr, val); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 452 | break; |
| 453 | } |
| 454 | return PCIBIOS_SUCCESSFUL; |
| 455 | } |
| 456 | |
| 457 | static struct pci_ops u3_ht_pci_ops = |
| 458 | { |
Nathan Lynch | 3fac10e | 2007-08-10 05:18:41 +1000 | [diff] [blame] | 459 | .read = u3_ht_read_config, |
| 460 | .write = u3_ht_write_config, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 461 | }; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 462 | |
| 463 | #define U4_PCIE_CFA0(devfn, off) \ |
| 464 | ((1 << ((unsigned int)PCI_SLOT(dev_fn))) \ |
| 465 | | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \ |
| 466 | | ((((unsigned int)(off)) >> 8) << 28) \ |
| 467 | | (((unsigned int)(off)) & 0xfcU)) |
| 468 | |
| 469 | #define U4_PCIE_CFA1(bus, devfn, off) \ |
| 470 | ((((unsigned int)(bus)) << 16) \ |
| 471 | |(((unsigned int)(devfn)) << 8) \ |
| 472 | | ((((unsigned int)(off)) >> 8) << 28) \ |
| 473 | |(((unsigned int)(off)) & 0xfcU) \ |
| 474 | |1UL) |
| 475 | |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 476 | static volatile void __iomem *u4_pcie_cfg_access(struct pci_controller* hose, |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 477 | u8 bus, u8 dev_fn, int offset) |
| 478 | { |
| 479 | unsigned int caddr; |
| 480 | |
| 481 | if (bus == hose->first_busno) { |
| 482 | caddr = U4_PCIE_CFA0(dev_fn, offset); |
| 483 | } else |
| 484 | caddr = U4_PCIE_CFA1(bus, dev_fn, offset); |
| 485 | |
| 486 | /* Uninorth will return garbage if we don't read back the value ! */ |
| 487 | do { |
| 488 | out_le32(hose->cfg_addr, caddr); |
| 489 | } while (in_le32(hose->cfg_addr) != caddr); |
| 490 | |
| 491 | offset &= 0x03; |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 492 | return hose->cfg_data + offset; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static int u4_pcie_read_config(struct pci_bus *bus, unsigned int devfn, |
| 496 | int offset, int len, u32 *val) |
| 497 | { |
| 498 | struct pci_controller *hose; |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 499 | volatile void __iomem *addr; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 500 | |
| 501 | hose = pci_bus_to_host(bus); |
| 502 | if (hose == NULL) |
| 503 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 504 | if (offset >= 0x1000) |
| 505 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 506 | addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset); |
| 507 | if (!addr) |
| 508 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 509 | /* |
| 510 | * Note: the caller has already checked that offset is |
| 511 | * suitably aligned and that len is 1, 2 or 4. |
| 512 | */ |
| 513 | switch (len) { |
| 514 | case 1: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 515 | *val = in_8(addr); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 516 | break; |
| 517 | case 2: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 518 | *val = in_le16(addr); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 519 | break; |
| 520 | default: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 521 | *val = in_le32(addr); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 522 | break; |
| 523 | } |
| 524 | return PCIBIOS_SUCCESSFUL; |
| 525 | } |
| 526 | |
| 527 | static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn, |
| 528 | int offset, int len, u32 val) |
| 529 | { |
| 530 | struct pci_controller *hose; |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 531 | volatile void __iomem *addr; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 532 | |
| 533 | hose = pci_bus_to_host(bus); |
| 534 | if (hose == NULL) |
| 535 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 536 | if (offset >= 0x1000) |
| 537 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 538 | addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset); |
| 539 | if (!addr) |
| 540 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 541 | /* |
| 542 | * Note: the caller has already checked that offset is |
| 543 | * suitably aligned and that len is 1, 2 or 4. |
| 544 | */ |
| 545 | switch (len) { |
| 546 | case 1: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 547 | out_8(addr, val); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 548 | break; |
| 549 | case 2: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 550 | out_le16(addr, val); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 551 | break; |
| 552 | default: |
Al Viro | de125bf | 2006-02-01 05:18:43 -0500 | [diff] [blame] | 553 | out_le32(addr, val); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | return PCIBIOS_SUCCESSFUL; |
| 557 | } |
| 558 | |
| 559 | static struct pci_ops u4_pcie_pci_ops = |
| 560 | { |
Nathan Lynch | 3fac10e | 2007-08-10 05:18:41 +1000 | [diff] [blame] | 561 | .read = u4_pcie_read_config, |
| 562 | .write = u4_pcie_write_config, |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 563 | }; |
| 564 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 565 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 566 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 567 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 568 | /* |
| 569 | * For a bandit bridge, turn on cache coherency if necessary. |
| 570 | * N.B. we could clean this up using the hose ops directly. |
| 571 | */ |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 572 | static void __init init_bandit(struct pci_controller *bp) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 573 | { |
| 574 | unsigned int vendev, magic; |
| 575 | int rev; |
| 576 | |
| 577 | /* read the word at offset 0 in config space for device 11 */ |
| 578 | out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + PCI_VENDOR_ID); |
| 579 | udelay(2); |
| 580 | vendev = in_le32(bp->cfg_data); |
| 581 | if (vendev == (PCI_DEVICE_ID_APPLE_BANDIT << 16) + |
| 582 | PCI_VENDOR_ID_APPLE) { |
| 583 | /* read the revision id */ |
| 584 | out_le32(bp->cfg_addr, |
| 585 | (1UL << BANDIT_DEVNUM) + PCI_REVISION_ID); |
| 586 | udelay(2); |
| 587 | rev = in_8(bp->cfg_data); |
| 588 | if (rev != BANDIT_REVID) |
| 589 | printk(KERN_WARNING |
| 590 | "Unknown revision %d for bandit\n", rev); |
| 591 | } else if (vendev != (BANDIT_DEVID_2 << 16) + PCI_VENDOR_ID_APPLE) { |
| 592 | printk(KERN_WARNING "bandit isn't? (%x)\n", vendev); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | /* read the word at offset 0x50 */ |
| 597 | out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + BANDIT_MAGIC); |
| 598 | udelay(2); |
| 599 | magic = in_le32(bp->cfg_data); |
| 600 | if ((magic & BANDIT_COHERENT) != 0) |
| 601 | return; |
| 602 | magic |= BANDIT_COHERENT; |
| 603 | udelay(2); |
| 604 | out_le32(bp->cfg_data, magic); |
| 605 | printk(KERN_INFO "Cache coherency enabled for bandit/PSX\n"); |
| 606 | } |
| 607 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 608 | /* |
| 609 | * Tweak the PCI-PCI bridge chip on the blue & white G3s. |
| 610 | */ |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 611 | static void __init init_p2pbridge(void) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 612 | { |
| 613 | struct device_node *p2pbridge; |
| 614 | struct pci_controller* hose; |
| 615 | u8 bus, devfn; |
| 616 | u16 val; |
| 617 | |
| 618 | /* XXX it would be better here to identify the specific |
| 619 | PCI-PCI bridge chip we have. */ |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 620 | p2pbridge = of_find_node_by_name(NULL, "pci-bridge"); |
| 621 | if (p2pbridge == NULL |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 622 | || p2pbridge->parent == NULL |
| 623 | || strcmp(p2pbridge->parent->name, "pci") != 0) |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 624 | goto done; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 625 | if (pci_device_from_OF_node(p2pbridge, &bus, &devfn) < 0) { |
| 626 | DBG("Can't find PCI infos for PCI<->PCI bridge\n"); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 627 | goto done; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 628 | } |
| 629 | /* Warning: At this point, we have not yet renumbered all busses. |
| 630 | * So we must use OF walking to find out hose |
| 631 | */ |
| 632 | hose = pci_find_hose_for_OF_device(p2pbridge); |
| 633 | if (!hose) { |
| 634 | DBG("Can't find hose for PCI<->PCI bridge\n"); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 635 | goto done; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 636 | } |
| 637 | if (early_read_config_word(hose, bus, devfn, |
| 638 | PCI_BRIDGE_CONTROL, &val) < 0) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 639 | printk(KERN_ERR "init_p2pbridge: couldn't read bridge" |
| 640 | " control\n"); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 641 | goto done; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 642 | } |
| 643 | val &= ~PCI_BRIDGE_CTL_MASTER_ABORT; |
| 644 | early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 645 | done: |
| 646 | of_node_put(p2pbridge); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 647 | } |
| 648 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 649 | static void __init init_second_ohare(void) |
| 650 | { |
| 651 | struct device_node *np = of_find_node_by_name(NULL, "pci106b,7"); |
| 652 | unsigned char bus, devfn; |
| 653 | unsigned short cmd; |
| 654 | |
| 655 | if (np == NULL) |
| 656 | return; |
| 657 | |
| 658 | /* This must run before we initialize the PICs since the second |
| 659 | * ohare hosts a PIC that will be accessed there. |
| 660 | */ |
| 661 | if (pci_device_from_OF_node(np, &bus, &devfn) == 0) { |
| 662 | struct pci_controller* hose = |
| 663 | pci_find_hose_for_OF_device(np); |
| 664 | if (!hose) { |
| 665 | printk(KERN_ERR "Can't find PCI hose for OHare2 !\n"); |
| 666 | return; |
| 667 | } |
| 668 | early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd); |
| 669 | cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 670 | cmd &= ~PCI_COMMAND_IO; |
| 671 | early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd); |
| 672 | } |
| 673 | has_second_ohare = 1; |
| 674 | } |
| 675 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 676 | /* |
| 677 | * Some Apple desktop machines have a NEC PD720100A USB2 controller |
| 678 | * on the motherboard. Open Firmware, on these, will disable the |
| 679 | * EHCI part of it so it behaves like a pair of OHCI's. This fixup |
| 680 | * code re-enables it ;) |
| 681 | */ |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 682 | static void __init fixup_nec_usb2(void) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 683 | { |
| 684 | struct device_node *nec; |
| 685 | |
| 686 | for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) { |
| 687 | struct pci_controller *hose; |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 688 | u32 data; |
| 689 | const u32 *prop; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 690 | u8 bus, devfn; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 691 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 692 | prop = of_get_property(nec, "vendor-id", NULL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 693 | if (prop == NULL) |
| 694 | continue; |
| 695 | if (0x1033 != *prop) |
| 696 | continue; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 697 | prop = of_get_property(nec, "device-id", NULL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 698 | if (prop == NULL) |
| 699 | continue; |
| 700 | if (0x0035 != *prop) |
| 701 | continue; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 702 | prop = of_get_property(nec, "reg", NULL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 703 | if (prop == NULL) |
| 704 | continue; |
| 705 | devfn = (prop[0] >> 8) & 0xff; |
| 706 | bus = (prop[0] >> 16) & 0xff; |
| 707 | if (PCI_FUNC(devfn) != 0) |
| 708 | continue; |
| 709 | hose = pci_find_hose_for_OF_device(nec); |
| 710 | if (!hose) |
| 711 | continue; |
| 712 | early_read_config_dword(hose, bus, devfn, 0xe4, &data); |
| 713 | if (data & 1UL) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 714 | printk("Found NEC PD720100A USB2 chip with disabled" |
| 715 | " EHCI, fixing up...\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 716 | data &= ~1UL; |
| 717 | early_write_config_dword(hose, bus, devfn, 0xe4, data); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 722 | static void __init setup_bandit(struct pci_controller *hose, |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 723 | struct resource *addr) |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 724 | { |
| 725 | hose->ops = ¯isc_pci_ops; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 726 | hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000); |
| 727 | hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 728 | init_bandit(hose); |
| 729 | } |
| 730 | |
| 731 | static int __init setup_uninorth(struct pci_controller *hose, |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 732 | struct resource *addr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 733 | { |
Benjamin Herrenschmidt | fc3fb71 | 2007-12-20 14:54:46 +1100 | [diff] [blame] | 734 | ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 735 | has_uninorth = 1; |
| 736 | hose->ops = ¯isc_pci_ops; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 737 | hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000); |
| 738 | hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 739 | /* We "know" that the bridge at f2000000 has the PCI slots. */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 740 | return addr->start == 0xf2000000; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 741 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 742 | #endif /* CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 743 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 744 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 745 | static void __init setup_u3_agp(struct pci_controller* hose) |
| 746 | { |
| 747 | /* On G5, we move AGP up to high bus number so we don't need |
| 748 | * to reassign bus numbers for HT. If we ever have P2P bridges |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 749 | * on AGP, we'll have to move pci_assign_all_busses to the |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 750 | * pci_controller structure so we enable it for AGP and not for |
| 751 | * HT childs. |
| 752 | * We hard code the address because of the different size of |
| 753 | * the reg address cell, we shall fix that by killing struct |
| 754 | * reg_property and using some accessor functions instead |
| 755 | */ |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 756 | hose->first_busno = 0xf0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 757 | hose->last_busno = 0xff; |
| 758 | has_uninorth = 1; |
| 759 | hose->ops = ¯isc_pci_ops; |
| 760 | hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000); |
| 761 | hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 762 | u3_agp = hose; |
| 763 | } |
| 764 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 765 | static void __init setup_u4_pcie(struct pci_controller* hose) |
| 766 | { |
| 767 | /* We currently only implement the "non-atomic" config space, to |
| 768 | * be optimised later. |
| 769 | */ |
| 770 | hose->ops = &u4_pcie_pci_ops; |
| 771 | hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000); |
| 772 | hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000); |
| 773 | |
| 774 | /* The bus contains a bridge from root -> device, we need to |
| 775 | * make it visible on bus 0 so that we pick the right type |
| 776 | * of config cycles. If we didn't, we would have to force all |
| 777 | * config cycles to be type 1. So we override the "bus-range" |
| 778 | * property here |
| 779 | */ |
| 780 | hose->first_busno = 0x00; |
| 781 | hose->last_busno = 0xff; |
| 782 | u4_pcie = hose; |
| 783 | } |
| 784 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 785 | static void __init setup_u3_ht(struct pci_controller* hose) |
| 786 | { |
Stephen Rothwell | 44ef339 | 2007-12-10 14:33:21 +1100 | [diff] [blame] | 787 | struct device_node *np = hose->dn; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 788 | struct pci_controller *other = NULL; |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 789 | struct resource cfg_res, self_res; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 790 | int i, cur; |
| 791 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 792 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 793 | hose->ops = &u3_ht_pci_ops; |
| 794 | |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 795 | /* Get base addresses from OF tree |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 796 | */ |
Benjamin Herrenschmidt | 444532d | 2007-12-20 14:55:01 +1100 | [diff] [blame^] | 797 | if (of_address_to_resource(np, 0, &cfg_res) || |
| 798 | of_address_to_resource(np, 1, &self_res)) { |
| 799 | printk(KERN_ERR "PCI: Failed to get U3/U4 HT resources !\n"); |
| 800 | return; |
| 801 | } |
| 802 | |
| 803 | /* Map external cfg space access into cfg_data and self registers |
| 804 | * into cfg_addr |
| 805 | */ |
| 806 | hose->cfg_data = ioremap(cfg_res.start, 0x02000000); |
| 807 | hose->cfg_addr = ioremap(self_res.start, |
| 808 | self_res.end - self_res.start + 1); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 809 | |
| 810 | /* |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 811 | * /ht node doesn't expose a "ranges" property, so we "remove" |
| 812 | * regions that have been allocated to AGP. So far, this version of |
| 813 | * the code doesn't assign any of the 0xfxxxxxxx "fine" memory regions |
| 814 | * to /ht. We need to fix that sooner or later by either parsing all |
| 815 | * child "ranges" properties or figuring out the U3 address space |
| 816 | * decoding logic and then read its configuration register (if any). |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 817 | */ |
| 818 | hose->io_base_phys = 0xf4000000; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 819 | hose->pci_io_size = 0x00400000; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 820 | hose->io_resource.name = np->full_name; |
| 821 | hose->io_resource.start = 0; |
| 822 | hose->io_resource.end = 0x003fffff; |
| 823 | hose->io_resource.flags = IORESOURCE_IO; |
| 824 | hose->pci_mem_offset = 0; |
| 825 | hose->first_busno = 0; |
| 826 | hose->last_busno = 0xef; |
| 827 | hose->mem_resources[0].name = np->full_name; |
| 828 | hose->mem_resources[0].start = 0x80000000; |
| 829 | hose->mem_resources[0].end = 0xefffffff; |
| 830 | hose->mem_resources[0].flags = IORESOURCE_MEM; |
| 831 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 832 | u3_ht = hose; |
| 833 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 834 | if (u3_agp != NULL) |
| 835 | other = u3_agp; |
| 836 | else if (u4_pcie != NULL) |
| 837 | other = u4_pcie; |
| 838 | |
| 839 | if (other == NULL) { |
| 840 | DBG("U3/4 has no AGP/PCIE, using full resource range\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 844 | /* Fixup bus range vs. PCIE */ |
| 845 | if (u4_pcie) |
| 846 | hose->last_busno = u4_pcie->first_busno - 1; |
| 847 | |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 848 | /* We "remove" the AGP resources from the resources allocated to HT, |
| 849 | * that is we create "holes". However, that code does assumptions |
| 850 | * that so far happen to be true (cross fingers...), typically that |
| 851 | * resources in the AGP node are properly ordered |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 852 | */ |
| 853 | cur = 0; |
| 854 | for (i=0; i<3; i++) { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 855 | struct resource *res = &other->mem_resources[i]; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 856 | if (res->flags != IORESOURCE_MEM) |
| 857 | continue; |
| 858 | /* We don't care about "fine" resources */ |
| 859 | if (res->start >= 0xf0000000) |
| 860 | continue; |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 861 | /* Check if it's just a matter of "shrinking" us in one |
| 862 | * direction |
| 863 | */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 864 | if (hose->mem_resources[cur].start == res->start) { |
| 865 | DBG("U3/HT: shrink start of %d, %08lx -> %08lx\n", |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 866 | cur, hose->mem_resources[cur].start, |
| 867 | res->end + 1); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 868 | hose->mem_resources[cur].start = res->end + 1; |
| 869 | continue; |
| 870 | } |
| 871 | if (hose->mem_resources[cur].end == res->end) { |
| 872 | DBG("U3/HT: shrink end of %d, %08lx -> %08lx\n", |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 873 | cur, hose->mem_resources[cur].end, |
| 874 | res->start - 1); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 875 | hose->mem_resources[cur].end = res->start - 1; |
| 876 | continue; |
| 877 | } |
| 878 | /* No, it's not the case, we need a hole */ |
| 879 | if (cur == 2) { |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 880 | /* not enough resources for a hole, we drop part |
| 881 | * of the range |
| 882 | */ |
| 883 | printk(KERN_WARNING "Running out of resources" |
| 884 | " for /ht host !\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 885 | hose->mem_resources[cur].end = res->start - 1; |
| 886 | continue; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 887 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 888 | cur++; |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 889 | DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n", |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 890 | cur-1, res->start - 1, cur, res->end + 1); |
| 891 | hose->mem_resources[cur].name = np->full_name; |
| 892 | hose->mem_resources[cur].flags = IORESOURCE_MEM; |
| 893 | hose->mem_resources[cur].start = res->end + 1; |
| 894 | hose->mem_resources[cur].end = hose->mem_resources[cur-1].end; |
| 895 | hose->mem_resources[cur-1].end = res->start - 1; |
| 896 | } |
| 897 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 898 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 899 | |
| 900 | /* |
| 901 | * We assume that if we have a G3 powermac, we have one bridge called |
| 902 | * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise, |
| 903 | * if we have one or more bandit or chaos bridges, we don't have a MPC106. |
| 904 | */ |
Arnd Bergmann | 09b55f7 | 2007-06-18 01:06:54 +0200 | [diff] [blame] | 905 | static int __init pmac_add_bridge(struct device_node *dev) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 906 | { |
| 907 | int len; |
| 908 | struct pci_controller *hose; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 909 | struct resource rsrc; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 910 | char *disp_name; |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 911 | const int *bus_range; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 912 | int primary = 1, has_address = 0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 913 | |
| 914 | DBG("Adding PCI host bridge %s\n", dev->full_name); |
| 915 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 916 | /* Fetch host bridge registers address */ |
| 917 | has_address = (of_address_to_resource(dev, 0, &rsrc) == 0); |
| 918 | |
| 919 | /* Get bus range if any */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 920 | bus_range = of_get_property(dev, "bus-range", &len); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 921 | if (bus_range == NULL || len < 2 * sizeof(int)) { |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 922 | printk(KERN_WARNING "Can't get bus-range for %s, assume" |
| 923 | " bus 0\n", dev->full_name); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 924 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 925 | |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 926 | hose = pcibios_alloc_controller(dev); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 927 | if (!hose) |
| 928 | return -ENOMEM; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 929 | hose->first_busno = bus_range ? bus_range[0] : 0; |
| 930 | hose->last_busno = bus_range ? bus_range[1] : 0xff; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 931 | |
| 932 | disp_name = NULL; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 933 | |
| 934 | /* 64 bits only bridges */ |
Benjamin Herrenschmidt | b5166cc | 2005-11-15 16:05:33 +1100 | [diff] [blame] | 935 | #ifdef CONFIG_PPC64 |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 936 | if (of_device_is_compatible(dev, "u3-agp")) { |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 937 | setup_u3_agp(hose); |
| 938 | disp_name = "U3-AGP"; |
| 939 | primary = 0; |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 940 | } else if (of_device_is_compatible(dev, "u3-ht")) { |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 941 | setup_u3_ht(hose); |
| 942 | disp_name = "U3-HT"; |
| 943 | primary = 1; |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 944 | } else if (of_device_is_compatible(dev, "u4-pcie")) { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 945 | setup_u4_pcie(hose); |
| 946 | disp_name = "U4-PCIE"; |
| 947 | primary = 0; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 948 | } |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 949 | printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number:" |
| 950 | " %d->%d\n", disp_name, hose->first_busno, hose->last_busno); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 951 | #endif /* CONFIG_PPC64 */ |
| 952 | |
| 953 | /* 32 bits only bridges */ |
| 954 | #ifdef CONFIG_PPC32 |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 955 | if (of_device_is_compatible(dev, "uni-north")) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 956 | primary = setup_uninorth(hose, &rsrc); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 957 | disp_name = "UniNorth"; |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 958 | } else if (strcmp(dev->name, "pci") == 0) { |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 959 | /* XXX assume this is a mpc106 (grackle) */ |
| 960 | setup_grackle(hose); |
| 961 | disp_name = "Grackle (MPC106)"; |
| 962 | } else if (strcmp(dev->name, "bandit") == 0) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 963 | setup_bandit(hose, &rsrc); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 964 | disp_name = "Bandit"; |
| 965 | } else if (strcmp(dev->name, "chaos") == 0) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 966 | setup_chaos(hose, &rsrc); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 967 | disp_name = "Chaos"; |
| 968 | primary = 0; |
| 969 | } |
Greg Kroah-Hartman | 685143a | 2006-06-12 15:18:31 -0700 | [diff] [blame] | 970 | printk(KERN_INFO "Found %s PCI host bridge at 0x%016llx. " |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 971 | "Firmware bus number: %d->%d\n", |
Greg Kroah-Hartman | 685143a | 2006-06-12 15:18:31 -0700 | [diff] [blame] | 972 | disp_name, (unsigned long long)rsrc.start, hose->first_busno, |
| 973 | hose->last_busno); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 974 | #endif /* CONFIG_PPC32 */ |
| 975 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 976 | DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n", |
| 977 | hose, hose->cfg_addr, hose->cfg_data); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 978 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 979 | /* Interpret the "ranges" property */ |
| 980 | /* This also maps the I/O region and sets isa_io/mem_base */ |
| 981 | pci_process_bridge_OF_ranges(hose, dev, primary); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 982 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 983 | /* Fixup "bus-range" OF property */ |
| 984 | fixup_bus_range(dev); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
Benjamin Herrenschmidt | f90bb15 | 2006-11-11 17:24:51 +1100 | [diff] [blame] | 989 | void __devinit pmac_pci_irq_fixup(struct pci_dev *dev) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 990 | { |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 991 | #ifdef CONFIG_PPC32 |
Benjamin Herrenschmidt | f90bb15 | 2006-11-11 17:24:51 +1100 | [diff] [blame] | 992 | /* Fixup interrupt for the modem/ethernet combo controller. |
| 993 | * on machines with a second ohare chip. |
| 994 | * The number in the device tree (27) is bogus (correct for |
| 995 | * the ethernet-only board but not the combo ethernet/modem |
| 996 | * board). The real interrupt is 28 on the second controller |
| 997 | * -> 28+32 = 60. |
| 998 | */ |
| 999 | if (has_second_ohare && |
| 1000 | dev->vendor == PCI_VENDOR_ID_DEC && |
| 1001 | dev->device == PCI_DEVICE_ID_DEC_TULIP_PLUS) { |
| 1002 | dev->irq = irq_create_mapping(NULL, 60); |
| 1003 | set_irq_type(dev->irq, IRQ_TYPE_LEVEL_LOW); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1004 | } |
Benjamin Herrenschmidt | f90bb15 | 2006-11-11 17:24:51 +1100 | [diff] [blame] | 1005 | #endif /* CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1006 | } |
| 1007 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1008 | void __init pmac_pci_init(void) |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1009 | { |
| 1010 | struct device_node *np, *root; |
| 1011 | struct device_node *ht = NULL; |
| 1012 | |
Benjamin Herrenschmidt | fc3fb71 | 2007-12-20 14:54:46 +1100 | [diff] [blame] | 1013 | ppc_pci_flags = PPC_PCI_CAN_SKIP_ISA_ALIGN; |
Benjamin Herrenschmidt | 3fd94c6 | 2007-12-20 14:54:53 +1100 | [diff] [blame] | 1014 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1015 | root = of_find_node_by_path("/"); |
| 1016 | if (root == NULL) { |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1017 | printk(KERN_CRIT "pmac_pci_init: can't find root " |
| 1018 | "of device tree\n"); |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1019 | return; |
| 1020 | } |
| 1021 | for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) { |
| 1022 | if (np->name == NULL) |
| 1023 | continue; |
| 1024 | if (strcmp(np->name, "bandit") == 0 |
| 1025 | || strcmp(np->name, "chaos") == 0 |
| 1026 | || strcmp(np->name, "pci") == 0) { |
Arnd Bergmann | 09b55f7 | 2007-06-18 01:06:54 +0200 | [diff] [blame] | 1027 | if (pmac_add_bridge(np) == 0) |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1028 | of_node_get(np); |
| 1029 | } |
| 1030 | if (strcmp(np->name, "ht") == 0) { |
| 1031 | of_node_get(np); |
| 1032 | ht = np; |
| 1033 | } |
| 1034 | } |
| 1035 | of_node_put(root); |
| 1036 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1037 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1038 | /* Probe HT last as it relies on the agp resources to be already |
| 1039 | * setup |
| 1040 | */ |
Arnd Bergmann | 09b55f7 | 2007-06-18 01:06:54 +0200 | [diff] [blame] | 1041 | if (ht && pmac_add_bridge(ht) != 0) |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1042 | of_node_put(ht); |
| 1043 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1044 | /* Setup the linkage between OF nodes and PHBs */ |
| 1045 | pci_devs_phb_init(); |
| 1046 | |
| 1047 | /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We |
| 1048 | * assume there is no P2P bridge on the AGP bus, which should be a |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1049 | * safe assumptions for now. We should do something better in the |
| 1050 | * future though |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1051 | */ |
| 1052 | if (u3_agp) { |
Stephen Rothwell | 44ef339 | 2007-12-10 14:33:21 +1100 | [diff] [blame] | 1053 | struct device_node *np = u3_agp->dn; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1054 | PCI_DN(np)->busno = 0xf0; |
| 1055 | for (np = np->child; np; np = np->sibling) |
| 1056 | PCI_DN(np)->busno = 0xf0; |
| 1057 | } |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1058 | /* pmac_check_ht_link(); */ |
| 1059 | |
Benjamin Herrenschmidt | 295f83e | 2007-12-20 14:54:58 +1100 | [diff] [blame] | 1060 | /* We can allocate missing resources if any */ |
| 1061 | pci_probe_only = 0; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1062 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1063 | #else /* CONFIG_PPC64 */ |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1064 | init_p2pbridge(); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1065 | init_second_ohare(); |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1066 | fixup_nec_usb2(); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1067 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1068 | /* We are still having some issues with the Xserve G4, enabling |
| 1069 | * some offset between bus number and domains for now when we |
| 1070 | * assign all busses should help for now |
| 1071 | */ |
Benjamin Herrenschmidt | fc3fb71 | 2007-12-20 14:54:46 +1100 | [diff] [blame] | 1072 | if (ppc_pci_flags & PPC_PCI_REASSIGN_ALL_BUS) |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1073 | pcibios_assign_bus_offset = 0x10; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1074 | #endif |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 1075 | } |
| 1076 | |
Benjamin Herrenschmidt | bc0826c | 2007-12-20 14:54:57 +1100 | [diff] [blame] | 1077 | #ifdef CONFIG_PPC32 |
Benjamin Herrenschmidt | 549beb9 | 2007-12-20 14:54:57 +1100 | [diff] [blame] | 1078 | int pmac_pci_enable_device_hook(struct pci_dev *dev) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1079 | { |
| 1080 | struct device_node* node; |
| 1081 | int updatecfg = 0; |
| 1082 | int uninorth_child; |
| 1083 | |
| 1084 | node = pci_device_to_OF_node(dev); |
| 1085 | |
| 1086 | /* We don't want to enable USB controllers absent from the OF tree |
| 1087 | * (iBook second controller) |
| 1088 | */ |
| 1089 | if (dev->vendor == PCI_VENDOR_ID_APPLE |
Jean Delvare | c67808e | 2006-04-09 20:07:35 +0200 | [diff] [blame] | 1090 | && dev->class == PCI_CLASS_SERIAL_USB_OHCI |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1091 | && !node) { |
| 1092 | printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n", |
| 1093 | pci_name(dev)); |
| 1094 | return -EINVAL; |
| 1095 | } |
| 1096 | |
| 1097 | if (!node) |
| 1098 | return 0; |
| 1099 | |
| 1100 | uninorth_child = node->parent && |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1101 | of_device_is_compatible(node->parent, "uni-north"); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1102 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1103 | /* Firewire & GMAC were disabled after PCI probe, the driver is |
| 1104 | * claiming them, we must re-enable them now. |
| 1105 | */ |
| 1106 | if (uninorth_child && !strcmp(node->name, "firewire") && |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1107 | (of_device_is_compatible(node, "pci106b,18") || |
| 1108 | of_device_is_compatible(node, "pci106b,30") || |
| 1109 | of_device_is_compatible(node, "pci11c1,5811"))) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1110 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1); |
| 1111 | pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1); |
| 1112 | updatecfg = 1; |
| 1113 | } |
| 1114 | if (uninorth_child && !strcmp(node->name, "ethernet") && |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1115 | of_device_is_compatible(node, "gmac")) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1116 | pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1); |
| 1117 | updatecfg = 1; |
| 1118 | } |
| 1119 | |
Benjamin Herrenschmidt | 549beb9 | 2007-12-20 14:54:57 +1100 | [diff] [blame] | 1120 | /* |
| 1121 | * Fixup various header fields on 32 bits. We don't do that on |
| 1122 | * 64 bits as some of these have strange values behind the HT |
| 1123 | * bridge and we must not, for example, enable MWI or set the |
| 1124 | * cache line size on them. |
| 1125 | */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1126 | if (updatecfg) { |
| 1127 | u16 cmd; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1128 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1129 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1130 | cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
| 1131 | | PCI_COMMAND_INVALIDATE; |
| 1132 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
| 1133 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16); |
Benjamin Herrenschmidt | 549beb9 | 2007-12-20 14:54:57 +1100 | [diff] [blame] | 1134 | |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1135 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, |
| 1136 | L1_CACHE_BYTES >> 2); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
Benjamin Herrenschmidt | bc0826c | 2007-12-20 14:54:57 +1100 | [diff] [blame] | 1142 | void __devinit pmac_pci_fixup_ohci(struct pci_dev *dev) |
| 1143 | { |
| 1144 | struct device_node *node = pci_device_to_OF_node(dev); |
| 1145 | |
| 1146 | /* We don't want to assign resources to USB controllers |
| 1147 | * absent from the OF tree (iBook second controller) |
| 1148 | */ |
| 1149 | if (dev->class == PCI_CLASS_SERIAL_USB_OHCI && !node) |
| 1150 | dev->resource[0].flags = 0; |
| 1151 | } |
| 1152 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, PCI_ANY_ID, pmac_pci_fixup_ohci); |
| 1153 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1154 | /* We power down some devices after they have been probed. They'll |
| 1155 | * be powered back on later on |
| 1156 | */ |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1157 | void __init pmac_pcibios_after_init(void) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1158 | { |
| 1159 | struct device_node* nd; |
| 1160 | |
| 1161 | #ifdef CONFIG_BLK_DEV_IDE |
| 1162 | struct pci_dev *dev = NULL; |
| 1163 | |
| 1164 | /* OF fails to initialize IDE controllers on macs |
| 1165 | * (and maybe other machines) |
| 1166 | * |
| 1167 | * Ideally, this should be moved to the IDE layer, but we need |
| 1168 | * to check specifically with Andre Hedrick how to do it cleanly |
| 1169 | * since the common IDE code seem to care about the fact that the |
| 1170 | * BIOS may have disabled a controller. |
| 1171 | * |
| 1172 | * -- BenH |
| 1173 | */ |
| 1174 | for_each_pci_dev(dev) { |
Benjamin Herrenschmidt | b5d99e6 | 2007-03-07 11:27:55 +0100 | [diff] [blame] | 1175 | if ((dev->class >> 16) != PCI_BASE_CLASS_STORAGE) |
| 1176 | continue; |
| 1177 | if (pci_enable_device(dev)) |
| 1178 | printk(KERN_WARNING |
| 1179 | "pci: Failed to enable %s\n", pci_name(dev)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1180 | } |
| 1181 | #endif /* CONFIG_BLK_DEV_IDE */ |
| 1182 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1183 | for_each_node_by_name(nd, "firewire") { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1184 | if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") || |
| 1185 | of_device_is_compatible(nd, "pci106b,30") || |
| 1186 | of_device_is_compatible(nd, "pci11c1,5811")) |
| 1187 | && of_device_is_compatible(nd->parent, "uni-north")) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1188 | pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0); |
| 1189 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0); |
| 1190 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1191 | } |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1192 | of_node_put(nd); |
| 1193 | for_each_node_by_name(nd, "ethernet") { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1194 | if (nd->parent && of_device_is_compatible(nd, "gmac") |
| 1195 | && of_device_is_compatible(nd->parent, "uni-north")) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1196 | pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1197 | } |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1198 | of_node_put(nd); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1199 | } |
| 1200 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1201 | void pmac_pci_fixup_cardbus(struct pci_dev* dev) |
| 1202 | { |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 1203 | if (!machine_is(powermac)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1204 | return; |
| 1205 | /* |
| 1206 | * Fix the interrupt routing on the various cardbus bridges |
| 1207 | * used on powerbooks |
| 1208 | */ |
| 1209 | if (dev->vendor != PCI_VENDOR_ID_TI) |
| 1210 | return; |
| 1211 | if (dev->device == PCI_DEVICE_ID_TI_1130 || |
| 1212 | dev->device == PCI_DEVICE_ID_TI_1131) { |
| 1213 | u8 val; |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1214 | /* Enable PCI interrupt */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1215 | if (pci_read_config_byte(dev, 0x91, &val) == 0) |
| 1216 | pci_write_config_byte(dev, 0x91, val | 0x30); |
| 1217 | /* Disable ISA interrupt mode */ |
| 1218 | if (pci_read_config_byte(dev, 0x92, &val) == 0) |
| 1219 | pci_write_config_byte(dev, 0x92, val & ~0x06); |
| 1220 | } |
| 1221 | if (dev->device == PCI_DEVICE_ID_TI_1210 || |
| 1222 | dev->device == PCI_DEVICE_ID_TI_1211 || |
| 1223 | dev->device == PCI_DEVICE_ID_TI_1410 || |
| 1224 | dev->device == PCI_DEVICE_ID_TI_1510) { |
| 1225 | u8 val; |
| 1226 | /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA |
| 1227 | signal out the MFUNC0 pin */ |
| 1228 | if (pci_read_config_byte(dev, 0x8c, &val) == 0) |
| 1229 | pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2); |
| 1230 | /* Disable ISA interrupt mode */ |
| 1231 | if (pci_read_config_byte(dev, 0x92, &val) == 0) |
| 1232 | pci_write_config_byte(dev, 0x92, val & ~0x06); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus); |
| 1237 | |
| 1238 | void pmac_pci_fixup_pciata(struct pci_dev* dev) |
| 1239 | { |
| 1240 | u8 progif = 0; |
| 1241 | |
| 1242 | /* |
| 1243 | * On PowerMacs, we try to switch any PCI ATA controller to |
| 1244 | * fully native mode |
| 1245 | */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 1246 | if (!machine_is(powermac)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1247 | return; |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 1248 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1249 | /* Some controllers don't have the class IDE */ |
| 1250 | if (dev->vendor == PCI_VENDOR_ID_PROMISE) |
| 1251 | switch(dev->device) { |
| 1252 | case PCI_DEVICE_ID_PROMISE_20246: |
| 1253 | case PCI_DEVICE_ID_PROMISE_20262: |
| 1254 | case PCI_DEVICE_ID_PROMISE_20263: |
| 1255 | case PCI_DEVICE_ID_PROMISE_20265: |
| 1256 | case PCI_DEVICE_ID_PROMISE_20267: |
| 1257 | case PCI_DEVICE_ID_PROMISE_20268: |
| 1258 | case PCI_DEVICE_ID_PROMISE_20269: |
| 1259 | case PCI_DEVICE_ID_PROMISE_20270: |
| 1260 | case PCI_DEVICE_ID_PROMISE_20271: |
| 1261 | case PCI_DEVICE_ID_PROMISE_20275: |
| 1262 | case PCI_DEVICE_ID_PROMISE_20276: |
| 1263 | case PCI_DEVICE_ID_PROMISE_20277: |
| 1264 | goto good; |
| 1265 | } |
| 1266 | /* Others, check PCI class */ |
| 1267 | if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) |
| 1268 | return; |
| 1269 | good: |
| 1270 | pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); |
| 1271 | if ((progif & 5) != 5) { |
Benjamin Herrenschmidt | 6d98bda | 2007-12-10 15:29:22 +1100 | [diff] [blame] | 1272 | printk(KERN_INFO "PCI: %s Forcing PCI IDE into native mode\n", |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1273 | pci_name(dev)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1274 | (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5); |
| 1275 | if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || |
| 1276 | (progif & 5) != 5) |
| 1277 | printk(KERN_ERR "Rewrite of PROGIF failed !\n"); |
Benjamin Herrenschmidt | 6d98bda | 2007-12-10 15:29:22 +1100 | [diff] [blame] | 1278 | else { |
| 1279 | /* Clear IO BARs, they will be reassigned */ |
| 1280 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0); |
| 1281 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0); |
| 1282 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, 0); |
| 1283 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_3, 0); |
| 1284 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1285 | } |
| 1286 | } |
Benjamin Herrenschmidt | 6d98bda | 2007-12-10 15:29:22 +1100 | [diff] [blame] | 1287 | DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata); |
Benjamin Herrenschmidt | bc0826c | 2007-12-20 14:54:57 +1100 | [diff] [blame] | 1288 | #endif /* CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1289 | |
| 1290 | /* |
| 1291 | * Disable second function on K2-SATA, it's broken |
| 1292 | * and disable IO BARs on first one |
| 1293 | */ |
| 1294 | static void fixup_k2_sata(struct pci_dev* dev) |
| 1295 | { |
| 1296 | int i; |
| 1297 | u16 cmd; |
| 1298 | |
| 1299 | if (PCI_FUNC(dev->devfn) > 0) { |
| 1300 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
| 1301 | cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
| 1302 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
| 1303 | for (i = 0; i < 6; i++) { |
| 1304 | dev->resource[i].start = dev->resource[i].end = 0; |
| 1305 | dev->resource[i].flags = 0; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1306 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, |
| 1307 | 0); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1308 | } |
| 1309 | } else { |
| 1310 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
| 1311 | cmd &= ~PCI_COMMAND_IO; |
| 1312 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
| 1313 | for (i = 0; i < 5; i++) { |
| 1314 | dev->resource[i].start = dev->resource[i].end = 0; |
| 1315 | dev->resource[i].flags = 0; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1316 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, |
| 1317 | 0); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata); |
| 1322 | |