Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 2 | /* |
| 3 | * CHRP pci routines. |
| 4 | */ |
| 5 | |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 6 | #include <linux/kernel.h> |
| 7 | #include <linux/pci.h> |
| 8 | #include <linux/delay.h> |
| 9 | #include <linux/string.h> |
| 10 | #include <linux/init.h> |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 11 | |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/pgtable.h> |
| 14 | #include <asm/irq.h> |
| 15 | #include <asm/hydra.h> |
| 16 | #include <asm/prom.h> |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 17 | #include <asm/machdep.h> |
| 18 | #include <asm/sections.h> |
| 19 | #include <asm/pci-bridge.h> |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 20 | #include <asm/grackle.h> |
| 21 | #include <asm/rtas.h> |
| 22 | |
Paul Mackerras | b86756a | 2006-04-03 16:37:23 +1000 | [diff] [blame] | 23 | #include "chrp.h" |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 24 | #include "gg2.h" |
Paul Mackerras | b86756a | 2006-04-03 16:37:23 +1000 | [diff] [blame] | 25 | |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 26 | /* LongTrail */ |
| 27 | void __iomem *gg2_pci_config_base; |
| 28 | |
| 29 | /* |
| 30 | * The VLSI Golden Gate II has only 512K of PCI configuration space, so we |
| 31 | * limit the bus number to 3 bits |
| 32 | */ |
| 33 | |
Mathieu Malaterre | 910be6b | 2018-04-04 22:15:03 +0200 | [diff] [blame] | 34 | static int gg2_read_config(struct pci_bus *bus, unsigned int devfn, int off, |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 35 | int len, u32 *val) |
| 36 | { |
| 37 | volatile void __iomem *cfg_data; |
Kumar Gala | 8456993 | 2009-04-30 03:10:11 +0000 | [diff] [blame] | 38 | struct pci_controller *hose = pci_bus_to_host(bus); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 39 | |
| 40 | if (bus->number > 7) |
| 41 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 42 | /* |
| 43 | * Note: the caller has already checked that off is |
| 44 | * suitably aligned and that len is 1, 2 or 4. |
| 45 | */ |
| 46 | cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off); |
| 47 | switch (len) { |
| 48 | case 1: |
| 49 | *val = in_8(cfg_data); |
| 50 | break; |
| 51 | case 2: |
| 52 | *val = in_le16(cfg_data); |
| 53 | break; |
| 54 | default: |
| 55 | *val = in_le32(cfg_data); |
| 56 | break; |
| 57 | } |
| 58 | return PCIBIOS_SUCCESSFUL; |
| 59 | } |
| 60 | |
Mathieu Malaterre | 910be6b | 2018-04-04 22:15:03 +0200 | [diff] [blame] | 61 | static int gg2_write_config(struct pci_bus *bus, unsigned int devfn, int off, |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 62 | int len, u32 val) |
| 63 | { |
| 64 | volatile void __iomem *cfg_data; |
Kumar Gala | 8456993 | 2009-04-30 03:10:11 +0000 | [diff] [blame] | 65 | struct pci_controller *hose = pci_bus_to_host(bus); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 66 | |
| 67 | if (bus->number > 7) |
| 68 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 69 | /* |
| 70 | * Note: the caller has already checked that off is |
| 71 | * suitably aligned and that len is 1, 2 or 4. |
| 72 | */ |
| 73 | cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off); |
| 74 | switch (len) { |
| 75 | case 1: |
| 76 | out_8(cfg_data, val); |
| 77 | break; |
| 78 | case 2: |
| 79 | out_le16(cfg_data, val); |
| 80 | break; |
| 81 | default: |
| 82 | out_le32(cfg_data, val); |
| 83 | break; |
| 84 | } |
| 85 | return PCIBIOS_SUCCESSFUL; |
| 86 | } |
| 87 | |
| 88 | static struct pci_ops gg2_pci_ops = |
| 89 | { |
Nathan Lynch | f1d645f | 2007-08-10 05:18:44 +1000 | [diff] [blame] | 90 | .read = gg2_read_config, |
| 91 | .write = gg2_write_config, |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | /* |
| 95 | * Access functions for PCI config space using RTAS calls. |
| 96 | */ |
Mathieu Malaterre | 910be6b | 2018-04-04 22:15:03 +0200 | [diff] [blame] | 97 | static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset, |
| 98 | int len, u32 *val) |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 99 | { |
Kumar Gala | 8456993 | 2009-04-30 03:10:11 +0000 | [diff] [blame] | 100 | struct pci_controller *hose = pci_bus_to_host(bus); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 101 | unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8) |
| 102 | | (((bus->number - hose->first_busno) & 0xff) << 16) |
Kumar Gala | 5516b54 | 2007-06-27 01:17:57 -0500 | [diff] [blame] | 103 | | (hose->global_number << 24); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 104 | int ret = -1; |
| 105 | int rval; |
| 106 | |
| 107 | rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len); |
| 108 | *val = ret; |
| 109 | return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL; |
| 110 | } |
| 111 | |
Mathieu Malaterre | 910be6b | 2018-04-04 22:15:03 +0200 | [diff] [blame] | 112 | static int rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset, |
| 113 | int len, u32 val) |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 114 | { |
Kumar Gala | 8456993 | 2009-04-30 03:10:11 +0000 | [diff] [blame] | 115 | struct pci_controller *hose = pci_bus_to_host(bus); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 116 | unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8) |
| 117 | | (((bus->number - hose->first_busno) & 0xff) << 16) |
Kumar Gala | 5516b54 | 2007-06-27 01:17:57 -0500 | [diff] [blame] | 118 | | (hose->global_number << 24); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 119 | int rval; |
| 120 | |
| 121 | rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL, |
| 122 | addr, len, val); |
| 123 | return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL; |
| 124 | } |
| 125 | |
| 126 | static struct pci_ops rtas_pci_ops = |
| 127 | { |
Nathan Lynch | f1d645f | 2007-08-10 05:18:44 +1000 | [diff] [blame] | 128 | .read = rtas_read_config, |
| 129 | .write = rtas_write_config, |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | volatile struct Hydra __iomem *Hydra = NULL; |
| 133 | |
| 134 | int __init |
| 135 | hydra_init(void) |
| 136 | { |
| 137 | struct device_node *np; |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 138 | struct resource r; |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 139 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 140 | np = of_find_node_by_name(NULL, "mac-io"); |
| 141 | if (np == NULL || of_address_to_resource(np, 0, &r)) { |
| 142 | of_node_put(np); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 143 | return 0; |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 144 | } |
Nicolas Palix | 29e931c | 2008-12-02 03:34:46 +0000 | [diff] [blame] | 145 | of_node_put(np); |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 146 | Hydra = ioremap(r.start, resource_size(&r)); |
Greg Kroah-Hartman | 685143ac | 2006-06-12 15:18:31 -0700 | [diff] [blame] | 147 | printk("Hydra Mac I/O at %llx\n", (unsigned long long)r.start); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 148 | printk("Hydra Feature_Control was %x", |
| 149 | in_le32(&Hydra->Feature_Control)); |
| 150 | out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN | |
| 151 | HYDRA_FC_SCSI_CELL_EN | |
| 152 | HYDRA_FC_SCCA_ENABLE | |
| 153 | HYDRA_FC_SCCB_ENABLE | |
| 154 | HYDRA_FC_ARB_BYPASS | |
| 155 | HYDRA_FC_MPIC_ENABLE | |
| 156 | HYDRA_FC_SLOW_SCC_PCLK | |
| 157 | HYDRA_FC_MPIC_IS_MASTER)); |
| 158 | printk(", now %x\n", in_le32(&Hydra->Feature_Control)); |
| 159 | return 1; |
| 160 | } |
| 161 | |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 162 | #define PRG_CL_RESET_VALID 0x00010000 |
| 163 | |
| 164 | static void __init |
| 165 | setup_python(struct pci_controller *hose, struct device_node *dev) |
| 166 | { |
| 167 | u32 __iomem *reg; |
| 168 | u32 val; |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 169 | struct resource r; |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 170 | |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 171 | if (of_address_to_resource(dev, 0, &r)) { |
| 172 | printk(KERN_ERR "No address for Python PCI controller\n"); |
| 173 | return; |
| 174 | } |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 175 | |
| 176 | /* Clear the magic go-slow bit */ |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 177 | reg = ioremap(r.start + 0xf6000, 0x40); |
| 178 | BUG_ON(!reg); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 179 | val = in_be32(®[12]); |
| 180 | if (val & PRG_CL_RESET_VALID) { |
| 181 | out_be32(®[12], val & ~PRG_CL_RESET_VALID); |
| 182 | in_be32(®[12]); |
| 183 | } |
| 184 | iounmap(reg); |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 185 | |
Kumar Gala | 2e56ff2 | 2007-07-19 16:07:35 -0500 | [diff] [blame] | 186 | setup_indirect_pci(hose, r.start + 0xf8000, r.start + 0xf8010, 0); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* Marvell Discovery II based Pegasos 2 */ |
| 190 | static void __init setup_peg2(struct pci_controller *hose, struct device_node *dev) |
| 191 | { |
Stephen Rothwell | 8c8dc32 | 2007-04-24 13:50:55 +1000 | [diff] [blame] | 192 | struct device_node *root = of_find_node_by_path("/"); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 193 | struct device_node *rtas; |
| 194 | |
| 195 | rtas = of_find_node_by_name (root, "rtas"); |
| 196 | if (rtas) { |
| 197 | hose->ops = &rtas_pci_ops; |
Olaf Hering | d60dcd9 | 2006-02-04 12:55:41 +0100 | [diff] [blame] | 198 | of_node_put(rtas); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 199 | } else { |
| 200 | printk ("RTAS supporting Pegasos OF not found, please upgrade" |
| 201 | " your firmware\n"); |
| 202 | } |
Rob Herring | 0e47ff1 | 2011-07-12 09:25:51 -0500 | [diff] [blame] | 203 | pci_add_flags(PCI_REASSIGN_ALL_BUS); |
Stephen Rothwell | 8c8dc32 | 2007-04-24 13:50:55 +1000 | [diff] [blame] | 204 | /* keep the reference to the root node */ |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void __init |
| 208 | chrp_find_bridges(void) |
| 209 | { |
| 210 | struct device_node *dev; |
Jeremy Kerr | ae6b410 | 2006-07-12 15:40:05 +1000 | [diff] [blame] | 211 | const int *bus_range; |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 212 | int len, index = -1; |
| 213 | struct pci_controller *hose; |
Jeremy Kerr | ae6b410 | 2006-07-12 15:40:05 +1000 | [diff] [blame] | 214 | const unsigned int *dma; |
| 215 | const char *model, *machine; |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 216 | int is_longtrail = 0, is_mot = 0, is_pegasos = 0; |
Stephen Rothwell | 8c8dc32 | 2007-04-24 13:50:55 +1000 | [diff] [blame] | 217 | struct device_node *root = of_find_node_by_path("/"); |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 218 | struct resource r; |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 219 | /* |
| 220 | * The PCI host bridge nodes on some machines don't have |
| 221 | * properties to adequately identify them, so we have to |
| 222 | * look at what sort of machine this is as well. |
| 223 | */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 224 | machine = of_get_property(root, "model", NULL); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 225 | if (machine != NULL) { |
| 226 | is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0; |
| 227 | is_mot = strncmp(machine, "MOT", 3) == 0; |
| 228 | if (strncmp(machine, "Pegasos2", 8) == 0) |
| 229 | is_pegasos = 2; |
| 230 | else if (strncmp(machine, "Pegasos", 7) == 0) |
| 231 | is_pegasos = 1; |
| 232 | } |
Rob Herring | e5480bd | 2018-11-16 16:11:00 -0600 | [diff] [blame] | 233 | for_each_child_of_node(root, dev) { |
| 234 | if (!of_node_is_type(dev, "pci")) |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 235 | continue; |
| 236 | ++index; |
| 237 | /* The GG2 bridge on the LongTrail doesn't have an address */ |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 238 | if (of_address_to_resource(dev, 0, &r) && !is_longtrail) { |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 239 | printk(KERN_WARNING "Can't use %pOF: no address\n", |
| 240 | dev); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 241 | continue; |
| 242 | } |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 243 | bus_range = of_get_property(dev, "bus-range", &len); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 244 | if (bus_range == NULL || len < 2 * sizeof(int)) { |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 245 | printk(KERN_WARNING "Can't get bus-range for %pOF\n", |
| 246 | dev); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 247 | continue; |
| 248 | } |
| 249 | if (bus_range[1] == bus_range[0]) |
| 250 | printk(KERN_INFO "PCI bus %d", bus_range[0]); |
| 251 | else |
| 252 | printk(KERN_INFO "PCI buses %d..%d", |
| 253 | bus_range[0], bus_range[1]); |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 254 | printk(" controlled by %pOF", dev); |
David Woodhouse | 575e321 | 2006-01-14 00:13:49 +0000 | [diff] [blame] | 255 | if (!is_longtrail) |
Greg Kroah-Hartman | 685143ac | 2006-06-12 15:18:31 -0700 | [diff] [blame] | 256 | printk(" at %llx", (unsigned long long)r.start); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 257 | printk("\n"); |
| 258 | |
Kumar Gala | dbf8471 | 2007-06-27 01:56:50 -0500 | [diff] [blame] | 259 | hose = pcibios_alloc_controller(dev); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 260 | if (!hose) { |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 261 | printk("Can't allocate PCI controller structure for %pOF\n", |
| 262 | dev); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 263 | continue; |
| 264 | } |
Benjamin Herrenschmidt | ee673ea | 2008-10-13 20:49:47 +0000 | [diff] [blame] | 265 | hose->first_busno = hose->self_busno = bus_range[0]; |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 266 | hose->last_busno = bus_range[1]; |
| 267 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 268 | model = of_get_property(dev, "model", NULL); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 269 | if (model == NULL) |
| 270 | model = "<none>"; |
Benjamin Herrenschmidt | 22007a1 | 2008-10-13 20:14:09 +0000 | [diff] [blame] | 271 | if (strncmp(model, "IBM, Python", 11) == 0) { |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 272 | setup_python(hose, dev); |
| 273 | } else if (is_mot |
| 274 | || strncmp(model, "Motorola, Grackle", 17) == 0) { |
| 275 | setup_grackle(hose); |
| 276 | } else if (is_longtrail) { |
| 277 | void __iomem *p = ioremap(GG2_PCI_CONFIG_BASE, 0x80000); |
| 278 | hose->ops = &gg2_pci_ops; |
| 279 | hose->cfg_data = p; |
| 280 | gg2_pci_config_base = p; |
| 281 | } else if (is_pegasos == 1) { |
Kumar Gala | 2e56ff2 | 2007-07-19 16:07:35 -0500 | [diff] [blame] | 282 | setup_indirect_pci(hose, 0xfec00cf8, 0xfee00cfc, 0); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 283 | } else if (is_pegasos == 2) { |
| 284 | setup_peg2(hose, dev); |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 285 | } else if (!strncmp(model, "IBM,CPC710", 10)) { |
| 286 | setup_indirect_pci(hose, |
| 287 | r.start + 0x000f8000, |
Kumar Gala | 2e56ff2 | 2007-07-19 16:07:35 -0500 | [diff] [blame] | 288 | r.start + 0x000f8010, |
| 289 | 0); |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 290 | if (index == 0) { |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 291 | dma = of_get_property(dev, "system-dma-base", |
| 292 | &len); |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 293 | if (dma && len >= sizeof(*dma)) { |
| 294 | dma = (unsigned int *) |
| 295 | (((unsigned long)dma) + |
| 296 | len - sizeof(*dma)); |
| 297 | pci_dram_offset = *dma; |
| 298 | } |
| 299 | } |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 300 | } else { |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 301 | printk("No methods for %pOF (model %s), using RTAS\n", |
| 302 | dev, model); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 303 | hose->ops = &rtas_pci_ops; |
| 304 | } |
| 305 | |
| 306 | pci_process_bridge_OF_ranges(hose, dev, index == 0); |
| 307 | |
| 308 | /* check the first bridge for a property that we can |
| 309 | use to set pci_dram_offset */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 310 | dma = of_get_property(dev, "ibm,dma-ranges", &len); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 311 | if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) { |
| 312 | pci_dram_offset = dma[2] - dma[3]; |
| 313 | printk("pci_dram_offset = %lx\n", pci_dram_offset); |
| 314 | } |
| 315 | } |
Stephen Rothwell | 8c8dc32 | 2007-04-24 13:50:55 +1000 | [diff] [blame] | 316 | of_node_put(root); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 317 | } |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 318 | |
| 319 | /* SL82C105 IDE Control/Status Register */ |
| 320 | #define SL82C105_IDECSR 0x40 |
| 321 | |
Benjamin Herrenschmidt | 6d98bda | 2007-12-10 15:29:22 +1100 | [diff] [blame] | 322 | /* Fixup for Winbond ATA quirk, required for briq mostly because the |
| 323 | * 8259 is configured for level sensitive IRQ 14 and so wants the |
| 324 | * ATA controller to be set to fully native mode or bad things |
| 325 | * will happen. |
| 326 | */ |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 327 | static void chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105) |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 328 | { |
| 329 | u8 progif; |
| 330 | |
| 331 | /* If non-briq machines need that fixup too, please speak up */ |
| 332 | if (!machine_is(chrp) || _chrp_type != _CHRP_briq) |
| 333 | return; |
| 334 | |
| 335 | if ((sl82c105->class & 5) != 5) { |
| 336 | printk("W83C553: Switching SL82C105 IDE to PCI native mode\n"); |
| 337 | /* Enable SL82C105 PCI native IDE mode */ |
| 338 | pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif); |
| 339 | pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05); |
| 340 | sl82c105->class |= 0x05; |
| 341 | /* Disable SL82C105 second port */ |
| 342 | pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0003); |
Benjamin Herrenschmidt | 6d98bda | 2007-12-10 15:29:22 +1100 | [diff] [blame] | 343 | /* Clear IO BARs, they will be reassigned */ |
| 344 | pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_0, 0); |
| 345 | pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_1, 0); |
| 346 | pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_2, 0); |
| 347 | pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_3, 0); |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 348 | } |
| 349 | } |
Benjamin Herrenschmidt | 6d98bda | 2007-12-10 15:29:22 +1100 | [diff] [blame] | 350 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105, |
| 351 | chrp_pci_fixup_winbond_ata); |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 352 | |
| 353 | /* Pegasos2 firmware version 20040810 configures the built-in IDE controller |
| 354 | * in legacy mode, but sets the PCI registers to PCI native mode. |
| 355 | * The chip can only operate in legacy mode, so force the PCI class into legacy |
| 356 | * mode as well. The same fixup must be done to the class-code property in |
| 357 | * the IDE node /pci@80000000/ide@C,1 |
| 358 | */ |
Olaf Hering | 092ca5b | 2008-01-21 20:39:30 +1100 | [diff] [blame] | 359 | static void chrp_pci_fixup_vt8231_ata(struct pci_dev *viaide) |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 360 | { |
| 361 | u8 progif; |
| 362 | struct pci_dev *viaisa; |
| 363 | |
| 364 | if (!machine_is(chrp) || _chrp_type != _CHRP_Pegasos) |
| 365 | return; |
| 366 | if (viaide->irq != 14) |
| 367 | return; |
| 368 | |
| 369 | viaisa = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL); |
| 370 | if (!viaisa) |
| 371 | return; |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 372 | dev_info(&viaide->dev, "Fixing VIA IDE, force legacy mode on\n"); |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 373 | |
| 374 | pci_read_config_byte(viaide, PCI_CLASS_PROG, &progif); |
| 375 | pci_write_config_byte(viaide, PCI_CLASS_PROG, progif & ~0x5); |
| 376 | viaide->class &= ~0x5; |
| 377 | |
| 378 | pci_dev_put(viaisa); |
| 379 | } |
Olaf Hering | 092ca5b | 2008-01-21 20:39:30 +1100 | [diff] [blame] | 380 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, chrp_pci_fixup_vt8231_ata); |