blob: f852ae3e0ee42a016adc6155b2f5c37942f6dbc5 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
2 * Support for PCI bridges found on Power Macintoshes.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10003 *
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +11004 * Copyright (C) 2003-2005 Benjamin Herrenschmuidt (benh@kernel.crashing.org)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10005 * 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 Herrenschmidt6e99e452006-07-10 04:44:42 -070019#include <linux/irq.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100020
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 Mackerras830825d2005-10-26 17:16:38 +100027#include <asm/grackle.h>
Paul Mackerras3c3f42d2005-10-10 22:58:41 +100028#include <asm/ppc-pci.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100029
30#undef DEBUG
31
32#ifdef DEBUG
33#define DBG(x...) printk(x)
34#else
35#define DBG(x...)
36#endif
37
Paul Mackerras14cf11a2005-09-26 16:04:21 +100038/* XXX Could be per-controller, but I don't think we risk anything by
39 * assuming we won't have both UniNorth and Bandit */
40static int has_uninorth;
Paul Mackerras35499c02005-10-22 16:02:39 +100041#ifdef CONFIG_PPC64
Paul Mackerras14cf11a2005-09-26 16:04:21 +100042static struct pci_controller *u3_agp;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +110043static struct pci_controller *u4_pcie;
Paul Mackerras35499c02005-10-22 16:02:39 +100044static struct pci_controller *u3_ht;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100045#else
46static int has_second_ohare;
Paul Mackerras35499c02005-10-22 16:02:39 +100047#endif /* CONFIG_PPC64 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100048
Paul Mackerras14cf11a2005-09-26 16:04:21 +100049extern int pcibios_assign_bus_offset;
50
51struct 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
63static int __init fixup_one_level_bus_range(struct device_node *node, int higher)
64{
65 for (; node != 0;node = node->sibling) {
Jeremy Kerr018a3d12006-07-12 15:40:29 +100066 const int * bus_range;
67 const unsigned int *class_code;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100068 int len;
69
70 /* For PCI<->PCI bridges or CardBus bridges, we go down */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100071 class_code = of_get_property(node, "class-code", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +100072 if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
73 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
74 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100075 bus_range = of_get_property(node, "bus-range", &len);
Paul Mackerras14cf11a2005-09-26 16:04:21 +100076 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 */
91static void __init fixup_bus_range(struct device_node *bridge)
92{
Jeremy Kerr018a3d12006-07-12 15:40:29 +100093 int *bus_range, len;
94 struct property *prop;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100095
96 /* Lookup the "bus-range" property for the hose */
Jeremy Kerr018a3d12006-07-12 15:40:29 +100097 prop = of_find_property(bridge, "bus-range", &len);
98 if (prop == NULL || prop->length < 2 * sizeof(int))
Paul Mackerras14cf11a2005-09-26 16:04:21 +100099 return;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000100
Stephen Rothwell1a381472007-04-03 10:58:52 +1000101 bus_range = prop->value;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000102 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 Herrenschmidt1beb6a72005-12-14 13:10:10 +1100128 ((1 << (unsigned int)PCI_SLOT(dev_fn)) \
129 | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
130 | (((unsigned int)(off)) & 0xFCUL))
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000131
132#define MACRISC_CFA1(bus, devfn, off) \
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100133 ((((unsigned int)(bus)) << 16) \
134 |(((unsigned int)(devfn)) << 8) \
135 |(((unsigned int)(off)) & 0xFCUL) \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000136 |1UL)
137
Al Virode125bf2006-02-01 05:18:43 -0500138static volatile void __iomem *macrisc_cfg_access(struct pci_controller* hose,
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000139 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 Virode125bf2006-02-01 05:18:43 -0500145 return NULL;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000146 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 Virode125bf2006-02-01 05:18:43 -0500156 return hose->cfg_data + offset;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000157}
158
159static int macrisc_read_config(struct pci_bus *bus, unsigned int devfn,
160 int offset, int len, u32 *val)
161{
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000162 struct pci_controller *hose;
Al Virode125bf2006-02-01 05:18:43 -0500163 volatile void __iomem *addr;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000164
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000165 hose = pci_bus_to_host(bus);
166 if (hose == NULL)
167 return PCIBIOS_DEVICE_NOT_FOUND;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100168 if (offset >= 0x100)
169 return PCIBIOS_BAD_REGISTER_NUMBER;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000170 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 Virode125bf2006-02-01 05:18:43 -0500179 *val = in_8(addr);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000180 break;
181 case 2:
Al Virode125bf2006-02-01 05:18:43 -0500182 *val = in_le16(addr);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000183 break;
184 default:
Al Virode125bf2006-02-01 05:18:43 -0500185 *val = in_le32(addr);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000186 break;
187 }
188 return PCIBIOS_SUCCESSFUL;
189}
190
191static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn,
192 int offset, int len, u32 val)
193{
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000194 struct pci_controller *hose;
Al Virode125bf2006-02-01 05:18:43 -0500195 volatile void __iomem *addr;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000196
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000197 hose = pci_bus_to_host(bus);
198 if (hose == NULL)
199 return PCIBIOS_DEVICE_NOT_FOUND;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100200 if (offset >= 0x100)
201 return PCIBIOS_BAD_REGISTER_NUMBER;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000202 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 Virode125bf2006-02-01 05:18:43 -0500211 out_8(addr, val);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000212 break;
213 case 2:
Al Virode125bf2006-02-01 05:18:43 -0500214 out_le16(addr, val);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000215 break;
216 default:
Al Virode125bf2006-02-01 05:18:43 -0500217 out_le32(addr, val);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000218 break;
219 }
220 return PCIBIOS_SUCCESSFUL;
221}
222
223static struct pci_ops macrisc_pci_ops =
224{
Nathan Lynch3fac10e2007-08-10 05:18:41 +1000225 .read = macrisc_read_config,
226 .write = macrisc_write_config,
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000227};
228
Paul Mackerras35499c02005-10-22 16:02:39 +1000229#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000230/*
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000231 * Verify that a specific (bus, dev_fn) exists on chaos
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000232 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100233static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000234{
235 struct device_node *np;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000236 const u32 *vendor, *device;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000237
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100238 if (offset >= 0x100)
239 return PCIBIOS_BAD_REGISTER_NUMBER;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000240 np = pci_busdev_to_OF_node(bus, devfn);
241 if (np == NULL)
242 return PCIBIOS_DEVICE_NOT_FOUND;
243
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000244 vendor = of_get_property(np, "vendor-id", NULL);
245 device = of_get_property(np, "device-id", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000246 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
256static int
257chaos_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
268static int
269chaos_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
278static struct pci_ops chaos_pci_ops =
279{
Nathan Lynch3fac10e2007-08-10 05:18:41 +1000280 .read = chaos_read_config,
281 .write = chaos_write_config,
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000282};
283
Paul Mackerras35499c02005-10-22 16:02:39 +1000284static void __init setup_chaos(struct pci_controller *hose,
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100285 struct resource *addr)
Paul Mackerras35499c02005-10-22 16:02:39 +1000286{
287 /* assume a `chaos' bridge */
288 hose->ops = &chaos_pci_ops;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100289 hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
290 hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
Paul Mackerras35499c02005-10-22 16:02:39 +1000291}
Paul Mackerras35499c02005-10-22 16:02:39 +1000292#endif /* CONFIG_PPC32 */
293
294#ifdef CONFIG_PPC64
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000295/*
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 */
309static 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
317 * revs of K2 on recent G5s
318 */
319 if (bus->self)
320 busdn = pci_device_to_OF_node(bus->self);
321 else
322 busdn = hose->arch_data;
323 for (dn = busdn->child; dn; dn = dn->sibling)
linase07102d2005-12-05 19:37:35 -0600324 if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000325 break;
326 if (dn == NULL)
327 return -1;
328
329 /*
330 * When a device in K2 is powered down, we die on config
331 * cycle accesses. Fix that here.
332 */
333 for (i=0; i<2; i++)
334 if (k2_skiplist[i] == dn)
335 return 1;
336
337 return 0;
338}
339
340#define U3_HT_CFA0(devfn, off) \
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100341 ((((unsigned int)devfn) << 8) | offset)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000342#define U3_HT_CFA1(bus, devfn, off) \
343 (U3_HT_CFA0(devfn, off) \
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100344 + (((unsigned int)bus) << 16) \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000345 + 0x01000000UL)
346
Al Virode125bf2006-02-01 05:18:43 -0500347static volatile void __iomem *u3_ht_cfg_access(struct pci_controller* hose,
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000348 u8 bus, u8 devfn, u8 offset)
349{
350 if (bus == hose->first_busno) {
351 /* For now, we don't self probe U3 HT bridge */
352 if (PCI_SLOT(devfn) == 0)
Al Virode125bf2006-02-01 05:18:43 -0500353 return NULL;
354 return hose->cfg_data + U3_HT_CFA0(devfn, offset);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000355 } else
Al Virode125bf2006-02-01 05:18:43 -0500356 return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000357}
358
359static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn,
360 int offset, int len, u32 *val)
361{
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000362 struct pci_controller *hose;
Al Virode125bf2006-02-01 05:18:43 -0500363 volatile void __iomem *addr;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000364
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000365 hose = pci_bus_to_host(bus);
366 if (hose == NULL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000367 return PCIBIOS_DEVICE_NOT_FOUND;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100368 if (offset >= 0x100)
369 return PCIBIOS_BAD_REGISTER_NUMBER;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000370 addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);
371 if (!addr)
372 return PCIBIOS_DEVICE_NOT_FOUND;
373
374 switch (u3_ht_skip_device(hose, bus, devfn)) {
375 case 0:
376 break;
377 case 1:
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000378 switch (len) {
379 case 1:
380 *val = 0xff; break;
381 case 2:
382 *val = 0xffff; break;
383 default:
384 *val = 0xfffffffful; break;
385 }
386 return PCIBIOS_SUCCESSFUL;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000387 default:
388 return PCIBIOS_DEVICE_NOT_FOUND;
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000389 }
390
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000391 /*
392 * Note: the caller has already checked that offset is
393 * suitably aligned and that len is 1, 2 or 4.
394 */
395 switch (len) {
396 case 1:
Al Virode125bf2006-02-01 05:18:43 -0500397 *val = in_8(addr);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000398 break;
399 case 2:
Al Virode125bf2006-02-01 05:18:43 -0500400 *val = in_le16(addr);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000401 break;
402 default:
Al Virode125bf2006-02-01 05:18:43 -0500403 *val = in_le32(addr);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000404 break;
405 }
406 return PCIBIOS_SUCCESSFUL;
407}
408
409static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
410 int offset, int len, u32 val)
411{
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000412 struct pci_controller *hose;
Al Virode125bf2006-02-01 05:18:43 -0500413 volatile void __iomem *addr;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000414
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000415 hose = pci_bus_to_host(bus);
416 if (hose == NULL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000417 return PCIBIOS_DEVICE_NOT_FOUND;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100418 if (offset >= 0x100)
419 return PCIBIOS_BAD_REGISTER_NUMBER;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000420 addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);
421 if (!addr)
422 return PCIBIOS_DEVICE_NOT_FOUND;
423
424 switch (u3_ht_skip_device(hose, bus, devfn)) {
425 case 0:
426 break;
427 case 1:
428 return PCIBIOS_SUCCESSFUL;
429 default:
430 return PCIBIOS_DEVICE_NOT_FOUND;
431 }
432
433 /*
434 * Note: the caller has already checked that offset is
435 * suitably aligned and that len is 1, 2 or 4.
436 */
437 switch (len) {
438 case 1:
Al Virode125bf2006-02-01 05:18:43 -0500439 out_8(addr, val);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000440 break;
441 case 2:
Al Virode125bf2006-02-01 05:18:43 -0500442 out_le16(addr, val);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000443 break;
444 default:
Al Virode125bf2006-02-01 05:18:43 -0500445 out_le32((u32 __iomem *)addr, val);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000446 break;
447 }
448 return PCIBIOS_SUCCESSFUL;
449}
450
451static struct pci_ops u3_ht_pci_ops =
452{
Nathan Lynch3fac10e2007-08-10 05:18:41 +1000453 .read = u3_ht_read_config,
454 .write = u3_ht_write_config,
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000455};
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100456
457#define U4_PCIE_CFA0(devfn, off) \
458 ((1 << ((unsigned int)PCI_SLOT(dev_fn))) \
459 | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
460 | ((((unsigned int)(off)) >> 8) << 28) \
461 | (((unsigned int)(off)) & 0xfcU))
462
463#define U4_PCIE_CFA1(bus, devfn, off) \
464 ((((unsigned int)(bus)) << 16) \
465 |(((unsigned int)(devfn)) << 8) \
466 | ((((unsigned int)(off)) >> 8) << 28) \
467 |(((unsigned int)(off)) & 0xfcU) \
468 |1UL)
469
Al Virode125bf2006-02-01 05:18:43 -0500470static volatile void __iomem *u4_pcie_cfg_access(struct pci_controller* hose,
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100471 u8 bus, u8 dev_fn, int offset)
472{
473 unsigned int caddr;
474
475 if (bus == hose->first_busno) {
476 caddr = U4_PCIE_CFA0(dev_fn, offset);
477 } else
478 caddr = U4_PCIE_CFA1(bus, dev_fn, offset);
479
480 /* Uninorth will return garbage if we don't read back the value ! */
481 do {
482 out_le32(hose->cfg_addr, caddr);
483 } while (in_le32(hose->cfg_addr) != caddr);
484
485 offset &= 0x03;
Al Virode125bf2006-02-01 05:18:43 -0500486 return hose->cfg_data + offset;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100487}
488
489static int u4_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
490 int offset, int len, u32 *val)
491{
492 struct pci_controller *hose;
Al Virode125bf2006-02-01 05:18:43 -0500493 volatile void __iomem *addr;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100494
495 hose = pci_bus_to_host(bus);
496 if (hose == NULL)
497 return PCIBIOS_DEVICE_NOT_FOUND;
498 if (offset >= 0x1000)
499 return PCIBIOS_BAD_REGISTER_NUMBER;
500 addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
501 if (!addr)
502 return PCIBIOS_DEVICE_NOT_FOUND;
503 /*
504 * Note: the caller has already checked that offset is
505 * suitably aligned and that len is 1, 2 or 4.
506 */
507 switch (len) {
508 case 1:
Al Virode125bf2006-02-01 05:18:43 -0500509 *val = in_8(addr);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100510 break;
511 case 2:
Al Virode125bf2006-02-01 05:18:43 -0500512 *val = in_le16(addr);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100513 break;
514 default:
Al Virode125bf2006-02-01 05:18:43 -0500515 *val = in_le32(addr);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100516 break;
517 }
518 return PCIBIOS_SUCCESSFUL;
519}
520
521static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
522 int offset, int len, u32 val)
523{
524 struct pci_controller *hose;
Al Virode125bf2006-02-01 05:18:43 -0500525 volatile void __iomem *addr;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100526
527 hose = pci_bus_to_host(bus);
528 if (hose == NULL)
529 return PCIBIOS_DEVICE_NOT_FOUND;
530 if (offset >= 0x1000)
531 return PCIBIOS_BAD_REGISTER_NUMBER;
532 addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
533 if (!addr)
534 return PCIBIOS_DEVICE_NOT_FOUND;
535 /*
536 * Note: the caller has already checked that offset is
537 * suitably aligned and that len is 1, 2 or 4.
538 */
539 switch (len) {
540 case 1:
Al Virode125bf2006-02-01 05:18:43 -0500541 out_8(addr, val);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100542 break;
543 case 2:
Al Virode125bf2006-02-01 05:18:43 -0500544 out_le16(addr, val);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100545 break;
546 default:
Al Virode125bf2006-02-01 05:18:43 -0500547 out_le32(addr, val);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100548 break;
549 }
550 return PCIBIOS_SUCCESSFUL;
551}
552
553static struct pci_ops u4_pcie_pci_ops =
554{
Nathan Lynch3fac10e2007-08-10 05:18:41 +1000555 .read = u4_pcie_read_config,
556 .write = u4_pcie_write_config,
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100557};
558
Paul Mackerras35499c02005-10-22 16:02:39 +1000559#endif /* CONFIG_PPC64 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000560
Paul Mackerras35499c02005-10-22 16:02:39 +1000561#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000562/*
563 * For a bandit bridge, turn on cache coherency if necessary.
564 * N.B. we could clean this up using the hose ops directly.
565 */
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000566static void __init init_bandit(struct pci_controller *bp)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000567{
568 unsigned int vendev, magic;
569 int rev;
570
571 /* read the word at offset 0 in config space for device 11 */
572 out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + PCI_VENDOR_ID);
573 udelay(2);
574 vendev = in_le32(bp->cfg_data);
575 if (vendev == (PCI_DEVICE_ID_APPLE_BANDIT << 16) +
576 PCI_VENDOR_ID_APPLE) {
577 /* read the revision id */
578 out_le32(bp->cfg_addr,
579 (1UL << BANDIT_DEVNUM) + PCI_REVISION_ID);
580 udelay(2);
581 rev = in_8(bp->cfg_data);
582 if (rev != BANDIT_REVID)
583 printk(KERN_WARNING
584 "Unknown revision %d for bandit\n", rev);
585 } else if (vendev != (BANDIT_DEVID_2 << 16) + PCI_VENDOR_ID_APPLE) {
586 printk(KERN_WARNING "bandit isn't? (%x)\n", vendev);
587 return;
588 }
589
590 /* read the word at offset 0x50 */
591 out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + BANDIT_MAGIC);
592 udelay(2);
593 magic = in_le32(bp->cfg_data);
594 if ((magic & BANDIT_COHERENT) != 0)
595 return;
596 magic |= BANDIT_COHERENT;
597 udelay(2);
598 out_le32(bp->cfg_data, magic);
599 printk(KERN_INFO "Cache coherency enabled for bandit/PSX\n");
600}
601
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000602/*
603 * Tweak the PCI-PCI bridge chip on the blue & white G3s.
604 */
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000605static void __init init_p2pbridge(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000606{
607 struct device_node *p2pbridge;
608 struct pci_controller* hose;
609 u8 bus, devfn;
610 u16 val;
611
612 /* XXX it would be better here to identify the specific
613 PCI-PCI bridge chip we have. */
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000614 p2pbridge = of_find_node_by_name(NULL, "pci-bridge");
615 if (p2pbridge == NULL
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000616 || p2pbridge->parent == NULL
617 || strcmp(p2pbridge->parent->name, "pci") != 0)
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000618 goto done;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000619 if (pci_device_from_OF_node(p2pbridge, &bus, &devfn) < 0) {
620 DBG("Can't find PCI infos for PCI<->PCI bridge\n");
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000621 goto done;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000622 }
623 /* Warning: At this point, we have not yet renumbered all busses.
624 * So we must use OF walking to find out hose
625 */
626 hose = pci_find_hose_for_OF_device(p2pbridge);
627 if (!hose) {
628 DBG("Can't find hose for PCI<->PCI bridge\n");
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000629 goto done;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000630 }
631 if (early_read_config_word(hose, bus, devfn,
632 PCI_BRIDGE_CONTROL, &val) < 0) {
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100633 printk(KERN_ERR "init_p2pbridge: couldn't read bridge"
634 " control\n");
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000635 goto done;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000636 }
637 val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
638 early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val);
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000639done:
640 of_node_put(p2pbridge);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000641}
642
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000643static void __init init_second_ohare(void)
644{
645 struct device_node *np = of_find_node_by_name(NULL, "pci106b,7");
646 unsigned char bus, devfn;
647 unsigned short cmd;
648
649 if (np == NULL)
650 return;
651
652 /* This must run before we initialize the PICs since the second
653 * ohare hosts a PIC that will be accessed there.
654 */
655 if (pci_device_from_OF_node(np, &bus, &devfn) == 0) {
656 struct pci_controller* hose =
657 pci_find_hose_for_OF_device(np);
658 if (!hose) {
659 printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
660 return;
661 }
662 early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
663 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
664 cmd &= ~PCI_COMMAND_IO;
665 early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
666 }
667 has_second_ohare = 1;
668}
669
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000670/*
671 * Some Apple desktop machines have a NEC PD720100A USB2 controller
672 * on the motherboard. Open Firmware, on these, will disable the
673 * EHCI part of it so it behaves like a pair of OHCI's. This fixup
674 * code re-enables it ;)
675 */
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000676static void __init fixup_nec_usb2(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000677{
678 struct device_node *nec;
679
680 for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) {
681 struct pci_controller *hose;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000682 u32 data;
683 const u32 *prop;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000684 u8 bus, devfn;
Paul Mackerras35499c02005-10-22 16:02:39 +1000685
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000686 prop = of_get_property(nec, "vendor-id", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000687 if (prop == NULL)
688 continue;
689 if (0x1033 != *prop)
690 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000691 prop = of_get_property(nec, "device-id", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000692 if (prop == NULL)
693 continue;
694 if (0x0035 != *prop)
695 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000696 prop = of_get_property(nec, "reg", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000697 if (prop == NULL)
698 continue;
699 devfn = (prop[0] >> 8) & 0xff;
700 bus = (prop[0] >> 16) & 0xff;
701 if (PCI_FUNC(devfn) != 0)
702 continue;
703 hose = pci_find_hose_for_OF_device(nec);
704 if (!hose)
705 continue;
706 early_read_config_dword(hose, bus, devfn, 0xe4, &data);
707 if (data & 1UL) {
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100708 printk("Found NEC PD720100A USB2 chip with disabled"
709 " EHCI, fixing up...\n");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000710 data &= ~1UL;
711 early_write_config_dword(hose, bus, devfn, 0xe4, data);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000712 }
713 }
714}
715
Paul Mackerras35499c02005-10-22 16:02:39 +1000716static void __init setup_bandit(struct pci_controller *hose,
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100717 struct resource *addr)
Paul Mackerras35499c02005-10-22 16:02:39 +1000718{
719 hose->ops = &macrisc_pci_ops;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100720 hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
721 hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
Paul Mackerras35499c02005-10-22 16:02:39 +1000722 init_bandit(hose);
723}
724
725static int __init setup_uninorth(struct pci_controller *hose,
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100726 struct resource *addr)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000727{
Paul Mackerras399fe2b2005-10-20 20:57:05 +1000728 pci_assign_all_buses = 1;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000729 has_uninorth = 1;
730 hose->ops = &macrisc_pci_ops;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100731 hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
732 hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000733 /* We "know" that the bridge at f2000000 has the PCI slots. */
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100734 return addr->start == 0xf2000000;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000735}
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100736#endif /* CONFIG_PPC32 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000737
Paul Mackerras35499c02005-10-22 16:02:39 +1000738#ifdef CONFIG_PPC64
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000739static void __init setup_u3_agp(struct pci_controller* hose)
740{
741 /* On G5, we move AGP up to high bus number so we don't need
742 * to reassign bus numbers for HT. If we ever have P2P bridges
Paul Mackerras35499c02005-10-22 16:02:39 +1000743 * on AGP, we'll have to move pci_assign_all_busses to the
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000744 * pci_controller structure so we enable it for AGP and not for
745 * HT childs.
746 * We hard code the address because of the different size of
747 * the reg address cell, we shall fix that by killing struct
748 * reg_property and using some accessor functions instead
749 */
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000750 hose->first_busno = 0xf0;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000751 hose->last_busno = 0xff;
752 has_uninorth = 1;
753 hose->ops = &macrisc_pci_ops;
754 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
755 hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000756 u3_agp = hose;
757}
758
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100759static void __init setup_u4_pcie(struct pci_controller* hose)
760{
761 /* We currently only implement the "non-atomic" config space, to
762 * be optimised later.
763 */
764 hose->ops = &u4_pcie_pci_ops;
765 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
766 hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
767
768 /* The bus contains a bridge from root -> device, we need to
769 * make it visible on bus 0 so that we pick the right type
770 * of config cycles. If we didn't, we would have to force all
771 * config cycles to be type 1. So we override the "bus-range"
772 * property here
773 */
774 hose->first_busno = 0x00;
775 hose->last_busno = 0xff;
776 u4_pcie = hose;
777}
778
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000779static void __init setup_u3_ht(struct pci_controller* hose)
780{
781 struct device_node *np = (struct device_node *)hose->arch_data;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100782 struct pci_controller *other = NULL;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000783 int i, cur;
784
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100785
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000786 hose->ops = &u3_ht_pci_ops;
787
788 /* We hard code the address because of the different size of
789 * the reg address cell, we shall fix that by killing struct
790 * reg_property and using some accessor functions instead
791 */
Al Virode125bf2006-02-01 05:18:43 -0500792 hose->cfg_data = ioremap(0xf2000000, 0x02000000);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000793
794 /*
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100795 * /ht node doesn't expose a "ranges" property, so we "remove"
796 * regions that have been allocated to AGP. So far, this version of
797 * the code doesn't assign any of the 0xfxxxxxxx "fine" memory regions
798 * to /ht. We need to fix that sooner or later by either parsing all
799 * child "ranges" properties or figuring out the U3 address space
800 * decoding logic and then read its configuration register (if any).
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000801 */
802 hose->io_base_phys = 0xf4000000;
Paul Mackerras35499c02005-10-22 16:02:39 +1000803 hose->pci_io_size = 0x00400000;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000804 hose->io_resource.name = np->full_name;
805 hose->io_resource.start = 0;
806 hose->io_resource.end = 0x003fffff;
807 hose->io_resource.flags = IORESOURCE_IO;
808 hose->pci_mem_offset = 0;
809 hose->first_busno = 0;
810 hose->last_busno = 0xef;
811 hose->mem_resources[0].name = np->full_name;
812 hose->mem_resources[0].start = 0x80000000;
813 hose->mem_resources[0].end = 0xefffffff;
814 hose->mem_resources[0].flags = IORESOURCE_MEM;
815
Paul Mackerras35499c02005-10-22 16:02:39 +1000816 u3_ht = hose;
817
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100818 if (u3_agp != NULL)
819 other = u3_agp;
820 else if (u4_pcie != NULL)
821 other = u4_pcie;
822
823 if (other == NULL) {
824 DBG("U3/4 has no AGP/PCIE, using full resource range\n");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000825 return;
826 }
827
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100828 /* Fixup bus range vs. PCIE */
829 if (u4_pcie)
830 hose->last_busno = u4_pcie->first_busno - 1;
831
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100832 /* We "remove" the AGP resources from the resources allocated to HT,
833 * that is we create "holes". However, that code does assumptions
834 * that so far happen to be true (cross fingers...), typically that
835 * resources in the AGP node are properly ordered
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000836 */
837 cur = 0;
838 for (i=0; i<3; i++) {
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100839 struct resource *res = &other->mem_resources[i];
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000840 if (res->flags != IORESOURCE_MEM)
841 continue;
842 /* We don't care about "fine" resources */
843 if (res->start >= 0xf0000000)
844 continue;
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100845 /* Check if it's just a matter of "shrinking" us in one
846 * direction
847 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000848 if (hose->mem_resources[cur].start == res->start) {
849 DBG("U3/HT: shrink start of %d, %08lx -> %08lx\n",
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100850 cur, hose->mem_resources[cur].start,
851 res->end + 1);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000852 hose->mem_resources[cur].start = res->end + 1;
853 continue;
854 }
855 if (hose->mem_resources[cur].end == res->end) {
856 DBG("U3/HT: shrink end of %d, %08lx -> %08lx\n",
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100857 cur, hose->mem_resources[cur].end,
858 res->start - 1);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000859 hose->mem_resources[cur].end = res->start - 1;
860 continue;
861 }
862 /* No, it's not the case, we need a hole */
863 if (cur == 2) {
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100864 /* not enough resources for a hole, we drop part
865 * of the range
866 */
867 printk(KERN_WARNING "Running out of resources"
868 " for /ht host !\n");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000869 hose->mem_resources[cur].end = res->start - 1;
870 continue;
Paul Mackerras35499c02005-10-22 16:02:39 +1000871 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000872 cur++;
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000873 DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n",
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000874 cur-1, res->start - 1, cur, res->end + 1);
875 hose->mem_resources[cur].name = np->full_name;
876 hose->mem_resources[cur].flags = IORESOURCE_MEM;
877 hose->mem_resources[cur].start = res->end + 1;
878 hose->mem_resources[cur].end = hose->mem_resources[cur-1].end;
879 hose->mem_resources[cur-1].end = res->start - 1;
880 }
881}
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100882#endif /* CONFIG_PPC64 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000883
884/*
885 * We assume that if we have a G3 powermac, we have one bridge called
886 * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise,
887 * if we have one or more bandit or chaos bridges, we don't have a MPC106.
888 */
Arnd Bergmann09b55f72007-06-18 01:06:54 +0200889static int __init pmac_add_bridge(struct device_node *dev)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000890{
891 int len;
892 struct pci_controller *hose;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100893 struct resource rsrc;
Paul Mackerras35499c02005-10-22 16:02:39 +1000894 char *disp_name;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000895 const int *bus_range;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100896 int primary = 1, has_address = 0;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000897
898 DBG("Adding PCI host bridge %s\n", dev->full_name);
899
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100900 /* Fetch host bridge registers address */
901 has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
902
903 /* Get bus range if any */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000904 bus_range = of_get_property(dev, "bus-range", &len);
Paul Mackerras35499c02005-10-22 16:02:39 +1000905 if (bus_range == NULL || len < 2 * sizeof(int)) {
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100906 printk(KERN_WARNING "Can't get bus-range for %s, assume"
907 " bus 0\n", dev->full_name);
Paul Mackerras35499c02005-10-22 16:02:39 +1000908 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000909
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100910 hose = pcibios_alloc_controller(dev);
Paul Mackerras35499c02005-10-22 16:02:39 +1000911 if (!hose)
912 return -ENOMEM;
Paul Mackerras35499c02005-10-22 16:02:39 +1000913 hose->first_busno = bus_range ? bus_range[0] : 0;
914 hose->last_busno = bus_range ? bus_range[1] : 0xff;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000915
916 disp_name = NULL;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100917
918 /* 64 bits only bridges */
Benjamin Herrenschmidtb5166cc2005-11-15 16:05:33 +1100919#ifdef CONFIG_PPC64
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000920 if (of_device_is_compatible(dev, "u3-agp")) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000921 setup_u3_agp(hose);
922 disp_name = "U3-AGP";
923 primary = 0;
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000924 } else if (of_device_is_compatible(dev, "u3-ht")) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000925 setup_u3_ht(hose);
926 disp_name = "U3-HT";
927 primary = 1;
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000928 } else if (of_device_is_compatible(dev, "u4-pcie")) {
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100929 setup_u4_pcie(hose);
930 disp_name = "U4-PCIE";
931 primary = 0;
Paul Mackerras35499c02005-10-22 16:02:39 +1000932 }
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100933 printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number:"
934 " %d->%d\n", disp_name, hose->first_busno, hose->last_busno);
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100935#endif /* CONFIG_PPC64 */
936
937 /* 32 bits only bridges */
938#ifdef CONFIG_PPC32
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000939 if (of_device_is_compatible(dev, "uni-north")) {
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100940 primary = setup_uninorth(hose, &rsrc);
Paul Mackerras35499c02005-10-22 16:02:39 +1000941 disp_name = "UniNorth";
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000942 } else if (strcmp(dev->name, "pci") == 0) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000943 /* XXX assume this is a mpc106 (grackle) */
944 setup_grackle(hose);
945 disp_name = "Grackle (MPC106)";
946 } else if (strcmp(dev->name, "bandit") == 0) {
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100947 setup_bandit(hose, &rsrc);
Paul Mackerras35499c02005-10-22 16:02:39 +1000948 disp_name = "Bandit";
949 } else if (strcmp(dev->name, "chaos") == 0) {
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100950 setup_chaos(hose, &rsrc);
Paul Mackerras35499c02005-10-22 16:02:39 +1000951 disp_name = "Chaos";
952 primary = 0;
953 }
Greg Kroah-Hartman685143ac2006-06-12 15:18:31 -0700954 printk(KERN_INFO "Found %s PCI host bridge at 0x%016llx. "
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100955 "Firmware bus number: %d->%d\n",
Greg Kroah-Hartman685143ac2006-06-12 15:18:31 -0700956 disp_name, (unsigned long long)rsrc.start, hose->first_busno,
957 hose->last_busno);
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100958#endif /* CONFIG_PPC32 */
959
Paul Mackerras35499c02005-10-22 16:02:39 +1000960 DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
961 hose, hose->cfg_addr, hose->cfg_data);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000962
Paul Mackerras35499c02005-10-22 16:02:39 +1000963 /* Interpret the "ranges" property */
964 /* This also maps the I/O region and sets isa_io/mem_base */
965 pci_process_bridge_OF_ranges(hose, dev, primary);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000966
Paul Mackerras35499c02005-10-22 16:02:39 +1000967 /* Fixup "bus-range" OF property */
968 fixup_bus_range(dev);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000969
970 return 0;
971}
972
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100973void __devinit pmac_pci_irq_fixup(struct pci_dev *dev)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000974{
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700975#ifdef CONFIG_PPC32
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100976 /* Fixup interrupt for the modem/ethernet combo controller.
977 * on machines with a second ohare chip.
978 * The number in the device tree (27) is bogus (correct for
979 * the ethernet-only board but not the combo ethernet/modem
980 * board). The real interrupt is 28 on the second controller
981 * -> 28+32 = 60.
982 */
983 if (has_second_ohare &&
984 dev->vendor == PCI_VENDOR_ID_DEC &&
985 dev->device == PCI_DEVICE_ID_DEC_TULIP_PLUS) {
986 dev->irq = irq_create_mapping(NULL, 60);
987 set_irq_type(dev->irq, IRQ_TYPE_LEVEL_LOW);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000988 }
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100989#endif /* CONFIG_PPC32 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000990}
991
Paul Mackerras35499c02005-10-22 16:02:39 +1000992void __init pmac_pci_init(void)
Paul Mackerras3c3f42d2005-10-10 22:58:41 +1000993{
994 struct device_node *np, *root;
995 struct device_node *ht = NULL;
996
997 root = of_find_node_by_path("/");
998 if (root == NULL) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000999 printk(KERN_CRIT "pmac_pci_init: can't find root "
1000 "of device tree\n");
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001001 return;
1002 }
1003 for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
1004 if (np->name == NULL)
1005 continue;
1006 if (strcmp(np->name, "bandit") == 0
1007 || strcmp(np->name, "chaos") == 0
1008 || strcmp(np->name, "pci") == 0) {
Arnd Bergmann09b55f72007-06-18 01:06:54 +02001009 if (pmac_add_bridge(np) == 0)
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001010 of_node_get(np);
1011 }
1012 if (strcmp(np->name, "ht") == 0) {
1013 of_node_get(np);
1014 ht = np;
1015 }
1016 }
1017 of_node_put(root);
1018
Paul Mackerras35499c02005-10-22 16:02:39 +10001019#ifdef CONFIG_PPC64
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001020 /* Probe HT last as it relies on the agp resources to be already
1021 * setup
1022 */
Arnd Bergmann09b55f72007-06-18 01:06:54 +02001023 if (ht && pmac_add_bridge(ht) != 0)
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001024 of_node_put(ht);
1025
Paul Mackerras35499c02005-10-22 16:02:39 +10001026 /* Setup the linkage between OF nodes and PHBs */
1027 pci_devs_phb_init();
1028
1029 /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We
1030 * assume there is no P2P bridge on the AGP bus, which should be a
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +11001031 * safe assumptions for now. We should do something better in the
1032 * future though
Paul Mackerras35499c02005-10-22 16:02:39 +10001033 */
1034 if (u3_agp) {
1035 struct device_node *np = u3_agp->arch_data;
1036 PCI_DN(np)->busno = 0xf0;
1037 for (np = np->child; np; np = np->sibling)
1038 PCI_DN(np)->busno = 0xf0;
1039 }
Paul Mackerras35499c02005-10-22 16:02:39 +10001040 /* pmac_check_ht_link(); */
1041
1042 /* Tell pci.c to not use the common resource allocation mechanism */
1043 pci_probe_only = 1;
1044
Paul Mackerras35499c02005-10-22 16:02:39 +10001045#else /* CONFIG_PPC64 */
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001046 init_p2pbridge();
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +10001047 init_second_ohare();
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001048 fixup_nec_usb2();
Paul Mackerras35499c02005-10-22 16:02:39 +10001049
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001050 /* We are still having some issues with the Xserve G4, enabling
1051 * some offset between bus number and domains for now when we
1052 * assign all busses should help for now
1053 */
Paul Mackerras399fe2b2005-10-20 20:57:05 +10001054 if (pci_assign_all_buses)
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001055 pcibios_assign_bus_offset = 0x10;
Paul Mackerras35499c02005-10-22 16:02:39 +10001056#endif
Paul Mackerras3c3f42d2005-10-10 22:58:41 +10001057}
1058
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001059int
1060pmac_pci_enable_device_hook(struct pci_dev *dev, int initial)
1061{
1062 struct device_node* node;
1063 int updatecfg = 0;
1064 int uninorth_child;
1065
1066 node = pci_device_to_OF_node(dev);
1067
1068 /* We don't want to enable USB controllers absent from the OF tree
1069 * (iBook second controller)
1070 */
1071 if (dev->vendor == PCI_VENDOR_ID_APPLE
Jean Delvarec67808e2006-04-09 20:07:35 +02001072 && dev->class == PCI_CLASS_SERIAL_USB_OHCI
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001073 && !node) {
1074 printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",
1075 pci_name(dev));
1076 return -EINVAL;
1077 }
1078
1079 if (!node)
1080 return 0;
1081
1082 uninorth_child = node->parent &&
Stephen Rothwell55b61fe2007-05-03 17:26:52 +10001083 of_device_is_compatible(node->parent, "uni-north");
Paul Mackerras35499c02005-10-22 16:02:39 +10001084
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001085 /* Firewire & GMAC were disabled after PCI probe, the driver is
1086 * claiming them, we must re-enable them now.
1087 */
1088 if (uninorth_child && !strcmp(node->name, "firewire") &&
Stephen Rothwell55b61fe2007-05-03 17:26:52 +10001089 (of_device_is_compatible(node, "pci106b,18") ||
1090 of_device_is_compatible(node, "pci106b,30") ||
1091 of_device_is_compatible(node, "pci11c1,5811"))) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001092 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
1093 pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
1094 updatecfg = 1;
1095 }
1096 if (uninorth_child && !strcmp(node->name, "ethernet") &&
Stephen Rothwell55b61fe2007-05-03 17:26:52 +10001097 of_device_is_compatible(node, "gmac")) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001098 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
1099 updatecfg = 1;
1100 }
1101
1102 if (updatecfg) {
1103 u16 cmd;
Paul Mackerras35499c02005-10-22 16:02:39 +10001104
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001105 /*
1106 * Make sure PCI is correctly configured
1107 *
1108 * We use old pci_bios versions of the function since, by
1109 * default, gmac is not powered up, and so will be absent
1110 * from the kernel initial PCI lookup.
1111 *
1112 * Should be replaced by 2.4 new PCI mechanisms and really
1113 * register the device.
1114 */
1115 pci_read_config_word(dev, PCI_COMMAND, &cmd);
Paul Mackerras35499c02005-10-22 16:02:39 +10001116 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
1117 | PCI_COMMAND_INVALIDATE;
1118 pci_write_config_word(dev, PCI_COMMAND, cmd);
1119 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);
1120 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
1121 L1_CACHE_BYTES >> 2);
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001122 }
1123
1124 return 0;
1125}
1126
1127/* We power down some devices after they have been probed. They'll
1128 * be powered back on later on
1129 */
Paul Mackerras35499c02005-10-22 16:02:39 +10001130void __init pmac_pcibios_after_init(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001131{
1132 struct device_node* nd;
1133
1134#ifdef CONFIG_BLK_DEV_IDE
1135 struct pci_dev *dev = NULL;
1136
1137 /* OF fails to initialize IDE controllers on macs
1138 * (and maybe other machines)
1139 *
1140 * Ideally, this should be moved to the IDE layer, but we need
1141 * to check specifically with Andre Hedrick how to do it cleanly
1142 * since the common IDE code seem to care about the fact that the
1143 * BIOS may have disabled a controller.
1144 *
1145 * -- BenH
1146 */
1147 for_each_pci_dev(dev) {
Benjamin Herrenschmidtb5d99e62007-03-07 11:27:55 +01001148 if ((dev->class >> 16) != PCI_BASE_CLASS_STORAGE)
1149 continue;
1150 if (pci_enable_device(dev))
1151 printk(KERN_WARNING
1152 "pci: Failed to enable %s\n", pci_name(dev));
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001153 }
1154#endif /* CONFIG_BLK_DEV_IDE */
1155
Stephen Rothwell30686ba2007-04-24 13:53:04 +10001156 for_each_node_by_name(nd, "firewire") {
Stephen Rothwell55b61fe2007-05-03 17:26:52 +10001157 if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") ||
1158 of_device_is_compatible(nd, "pci106b,30") ||
1159 of_device_is_compatible(nd, "pci11c1,5811"))
1160 && of_device_is_compatible(nd->parent, "uni-north")) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001161 pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
1162 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
1163 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001164 }
Stephen Rothwell30686ba2007-04-24 13:53:04 +10001165 of_node_put(nd);
1166 for_each_node_by_name(nd, "ethernet") {
Stephen Rothwell55b61fe2007-05-03 17:26:52 +10001167 if (nd->parent && of_device_is_compatible(nd, "gmac")
1168 && of_device_is_compatible(nd->parent, "uni-north"))
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001169 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001170 }
Stephen Rothwell30686ba2007-04-24 13:53:04 +10001171 of_node_put(nd);
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001172}
1173
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001174#ifdef CONFIG_PPC32
1175void pmac_pci_fixup_cardbus(struct pci_dev* dev)
1176{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +11001177 if (!machine_is(powermac))
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001178 return;
1179 /*
1180 * Fix the interrupt routing on the various cardbus bridges
1181 * used on powerbooks
1182 */
1183 if (dev->vendor != PCI_VENDOR_ID_TI)
1184 return;
1185 if (dev->device == PCI_DEVICE_ID_TI_1130 ||
1186 dev->device == PCI_DEVICE_ID_TI_1131) {
1187 u8 val;
Paul Mackerras35499c02005-10-22 16:02:39 +10001188 /* Enable PCI interrupt */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001189 if (pci_read_config_byte(dev, 0x91, &val) == 0)
1190 pci_write_config_byte(dev, 0x91, val | 0x30);
1191 /* Disable ISA interrupt mode */
1192 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1193 pci_write_config_byte(dev, 0x92, val & ~0x06);
1194 }
1195 if (dev->device == PCI_DEVICE_ID_TI_1210 ||
1196 dev->device == PCI_DEVICE_ID_TI_1211 ||
1197 dev->device == PCI_DEVICE_ID_TI_1410 ||
1198 dev->device == PCI_DEVICE_ID_TI_1510) {
1199 u8 val;
1200 /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA
1201 signal out the MFUNC0 pin */
1202 if (pci_read_config_byte(dev, 0x8c, &val) == 0)
1203 pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
1204 /* Disable ISA interrupt mode */
1205 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1206 pci_write_config_byte(dev, 0x92, val & ~0x06);
1207 }
1208}
1209
1210DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);
1211
1212void pmac_pci_fixup_pciata(struct pci_dev* dev)
1213{
1214 u8 progif = 0;
1215
1216 /*
1217 * On PowerMacs, we try to switch any PCI ATA controller to
1218 * fully native mode
1219 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +11001220 if (!machine_is(powermac))
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001221 return;
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +11001222
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001223 /* Some controllers don't have the class IDE */
1224 if (dev->vendor == PCI_VENDOR_ID_PROMISE)
1225 switch(dev->device) {
1226 case PCI_DEVICE_ID_PROMISE_20246:
1227 case PCI_DEVICE_ID_PROMISE_20262:
1228 case PCI_DEVICE_ID_PROMISE_20263:
1229 case PCI_DEVICE_ID_PROMISE_20265:
1230 case PCI_DEVICE_ID_PROMISE_20267:
1231 case PCI_DEVICE_ID_PROMISE_20268:
1232 case PCI_DEVICE_ID_PROMISE_20269:
1233 case PCI_DEVICE_ID_PROMISE_20270:
1234 case PCI_DEVICE_ID_PROMISE_20271:
1235 case PCI_DEVICE_ID_PROMISE_20275:
1236 case PCI_DEVICE_ID_PROMISE_20276:
1237 case PCI_DEVICE_ID_PROMISE_20277:
1238 goto good;
1239 }
1240 /* Others, check PCI class */
1241 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
1242 return;
1243 good:
1244 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
1245 if ((progif & 5) != 5) {
Benjamin Herrenschmidt6d98bda2007-12-10 15:29:22 +11001246 printk(KERN_INFO "PCI: %s Forcing PCI IDE into native mode\n",
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +11001247 pci_name(dev));
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001248 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
1249 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
1250 (progif & 5) != 5)
1251 printk(KERN_ERR "Rewrite of PROGIF failed !\n");
Benjamin Herrenschmidt6d98bda2007-12-10 15:29:22 +11001252 else {
1253 /* Clear IO BARs, they will be reassigned */
1254 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);
1255 pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);
1256 pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, 0);
1257 pci_write_config_dword(dev, PCI_BASE_ADDRESS_3, 0);
1258 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001259 }
1260}
Benjamin Herrenschmidt6d98bda2007-12-10 15:29:22 +11001261DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001262#endif
1263
1264/*
1265 * Disable second function on K2-SATA, it's broken
1266 * and disable IO BARs on first one
1267 */
1268static void fixup_k2_sata(struct pci_dev* dev)
1269{
1270 int i;
1271 u16 cmd;
1272
1273 if (PCI_FUNC(dev->devfn) > 0) {
1274 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1275 cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
1276 pci_write_config_word(dev, PCI_COMMAND, cmd);
1277 for (i = 0; i < 6; i++) {
1278 dev->resource[i].start = dev->resource[i].end = 0;
1279 dev->resource[i].flags = 0;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +11001280 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
1281 0);
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001282 }
1283 } else {
1284 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1285 cmd &= ~PCI_COMMAND_IO;
1286 pci_write_config_word(dev, PCI_COMMAND, cmd);
1287 for (i = 0; i < 5; i++) {
1288 dev->resource[i].start = dev->resource[i].end = 0;
1289 dev->resource[i].flags = 0;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +11001290 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
1291 0);
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001292 }
1293 }
1294}
1295DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata);
1296