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