2 * Support for PCI bridges found on Power Macintoshes.
3 * At present the "bandit" and "chaos" bridges are supported.
4 * Fortunately you access configuration space in the same
5 * way with either bridge.
7 * Copyright (C) 1997 Paul Mackerras (paulus@cs.anu.edu.au)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/pci.h>
17 #include <linux/delay.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
21 #include <asm/sections.h>
24 #include <asm/pci-bridge.h>
25 #include <asm/machdep.h>
26 #include <asm/pmac_feature.h>
32 extern void xmon_printf(const char *fmt, ...);
33 #define DBG(x...) xmon_printf(x)
35 #define DBG(x...) printk(x)
41 static int add_bridge(struct device_node *dev);
42 extern void pmac_check_ht_link(void);
44 /* XXX Could be per-controller, but I don't think we risk anything by
45 * assuming we won't have both UniNorth and Bandit */
46 static int has_uninorth;
48 static struct pci_controller *u3_agp;
49 #endif /* CONFIG_POWER4 */
51 extern u8 pci_cache_line_size;
52 extern int pcibios_assign_bus_offset;
54 struct device_node *k2_skiplist[2];
57 * Magic constants for enabling cache coherency in the bandit/PSX bridge.
59 #define BANDIT_DEVID_2 8
60 #define BANDIT_REVID 3
62 #define BANDIT_DEVNUM 11
63 #define BANDIT_MAGIC 0x50
64 #define BANDIT_COHERENT 0x40
67 fixup_one_level_bus_range(struct device_node *node, int higher)
69 for (; node != 0;node = node->sibling) {
71 unsigned int *class_code;
74 /* For PCI<->PCI bridges or CardBus bridges, we go down */
75 class_code = (unsigned int *) get_property(node, "class-code", NULL);
76 if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
77 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
79 bus_range = (int *) get_property(node, "bus-range", &len);
80 if (bus_range != NULL && len > 2 * sizeof(int)) {
81 if (bus_range[1] > higher)
82 higher = bus_range[1];
84 higher = fixup_one_level_bus_range(node->child, higher);
89 /* This routine fixes the "bus-range" property of all bridges in the
90 * system since they tend to have their "last" member wrong on macs
92 * Note that the bus numbers manipulated here are OF bus numbers, they
93 * are not Linux bus numbers.
96 fixup_bus_range(struct device_node *bridge)
101 /* Lookup the "bus-range" property for the hose */
102 bus_range = (int *) get_property(bridge, "bus-range", &len);
103 if (bus_range == NULL || len < 2 * sizeof(int)) {
104 printk(KERN_WARNING "Can't get bus-range for %s\n",
108 bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);
112 * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers.
114 * The "Bandit" version is present in all early PCI PowerMacs,
115 * and up to the first ones using Grackle. Some machines may
116 * have 2 bandit controllers (2 PCI busses).
118 * "Chaos" is used in some "Bandit"-type machines as a bridge
119 * for the separate display bus. It is accessed the same
120 * way as bandit, but cannot be probed for devices. It therefore
121 * has its own config access functions.
123 * The "UniNorth" version is present in all Core99 machines
124 * (iBook, G4, new IMacs, and all the recent Apple machines).
125 * It contains 3 controllers in one ASIC.
127 * The U3 is the bridge used on G5 machines. It contains an
128 * AGP bus which is dealt with the old UniNorth access routines
129 * and a HyperTransport bus which uses its own set of access
133 #define MACRISC_CFA0(devfn, off) \
134 ((1 << (unsigned long)PCI_SLOT(dev_fn)) \
135 | (((unsigned long)PCI_FUNC(dev_fn)) << 8) \
136 | (((unsigned long)(off)) & 0xFCUL))
138 #define MACRISC_CFA1(bus, devfn, off) \
139 ((((unsigned long)(bus)) << 16) \
140 |(((unsigned long)(devfn)) << 8) \
141 |(((unsigned long)(off)) & 0xFCUL) \
144 static void volatile __iomem * __pmac
145 macrisc_cfg_access(struct pci_controller* hose, u8 bus, u8 dev_fn, u8 offset)
149 if (bus == hose->first_busno) {
150 if (dev_fn < (11 << 3))
152 caddr = MACRISC_CFA0(dev_fn, offset);
154 caddr = MACRISC_CFA1(bus, dev_fn, offset);
156 /* Uninorth will return garbage if we don't read back the value ! */
158 out_le32(hose->cfg_addr, caddr);
159 } while (in_le32(hose->cfg_addr) != caddr);
161 offset &= has_uninorth ? 0x07 : 0x03;
162 return hose->cfg_data + offset;
166 macrisc_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
169 struct pci_controller *hose = bus->sysdata;
170 void volatile __iomem *addr;
172 addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
174 return PCIBIOS_DEVICE_NOT_FOUND;
176 * Note: the caller has already checked that offset is
177 * suitably aligned and that len is 1, 2 or 4.
184 *val = in_le16(addr);
187 *val = in_le32(addr);
190 return PCIBIOS_SUCCESSFUL;
194 macrisc_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
197 struct pci_controller *hose = bus->sysdata;
198 void volatile __iomem *addr;
200 addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
202 return PCIBIOS_DEVICE_NOT_FOUND;
204 * Note: the caller has already checked that offset is
205 * suitably aligned and that len is 1, 2 or 4.
214 (void) in_le16(addr);
218 (void) in_le32(addr);
221 return PCIBIOS_SUCCESSFUL;
224 static struct pci_ops macrisc_pci_ops =
231 * Verifiy that a specific (bus, dev_fn) exists on chaos
234 chaos_validate_dev(struct pci_bus *bus, int devfn, int offset)
236 struct device_node *np;
237 u32 *vendor, *device;
239 np = pci_busdev_to_OF_node(bus, devfn);
241 return PCIBIOS_DEVICE_NOT_FOUND;
243 vendor = (u32 *)get_property(np, "vendor-id", NULL);
244 device = (u32 *)get_property(np, "device-id", NULL);
245 if (vendor == NULL || device == NULL)
246 return PCIBIOS_DEVICE_NOT_FOUND;
248 if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10)
249 && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24))
250 return PCIBIOS_BAD_REGISTER_NUMBER;
252 return PCIBIOS_SUCCESSFUL;
256 chaos_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
259 int result = chaos_validate_dev(bus, devfn, offset);
260 if (result == PCIBIOS_BAD_REGISTER_NUMBER)
262 if (result != PCIBIOS_SUCCESSFUL)
264 return macrisc_read_config(bus, devfn, offset, len, val);
268 chaos_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
271 int result = chaos_validate_dev(bus, devfn, offset);
272 if (result != PCIBIOS_SUCCESSFUL)
274 return macrisc_write_config(bus, devfn, offset, len, val);
277 static struct pci_ops chaos_pci_ops =
286 * These versions of U3 HyperTransport config space access ops do not
287 * implement self-view of the HT host yet
290 #define U3_HT_CFA0(devfn, off) \
291 ((((unsigned long)devfn) << 8) | offset)
292 #define U3_HT_CFA1(bus, devfn, off) \
293 (U3_HT_CFA0(devfn, off) \
294 + (((unsigned long)bus) << 16) \
297 static void volatile __iomem * __pmac
298 u3_ht_cfg_access(struct pci_controller* hose, u8 bus, u8 devfn, u8 offset)
300 if (bus == hose->first_busno) {
301 /* For now, we don't self probe U3 HT bridge */
302 if (PCI_FUNC(devfn) != 0 || PCI_SLOT(devfn) > 7 ||
305 return hose->cfg_data + U3_HT_CFA0(devfn, offset);
307 return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);
311 u3_ht_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
314 struct pci_controller *hose = bus->sysdata;
315 void volatile __iomem *addr;
318 struct device_node *np = pci_busdev_to_OF_node(bus, devfn);
320 return PCIBIOS_DEVICE_NOT_FOUND;
323 * When a device in K2 is powered down, we die on config
324 * cycle accesses. Fix that here.
327 if (k2_skiplist[i] == np) {
332 *val = 0xffff; break;
334 *val = 0xfffffffful; break;
336 return PCIBIOS_SUCCESSFUL;
339 addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);
341 return PCIBIOS_DEVICE_NOT_FOUND;
343 * Note: the caller has already checked that offset is
344 * suitably aligned and that len is 1, 2 or 4.
351 *val = in_le16(addr);
354 *val = in_le32(addr);
357 return PCIBIOS_SUCCESSFUL;
361 u3_ht_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
364 struct pci_controller *hose = bus->sysdata;
365 void volatile __iomem *addr;
368 struct device_node *np = pci_busdev_to_OF_node(bus, devfn);
370 return PCIBIOS_DEVICE_NOT_FOUND;
372 * When a device in K2 is powered down, we die on config
373 * cycle accesses. Fix that here.
376 if (k2_skiplist[i] == np)
377 return PCIBIOS_SUCCESSFUL;
379 addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);
381 return PCIBIOS_DEVICE_NOT_FOUND;
383 * Note: the caller has already checked that offset is
384 * suitably aligned and that len is 1, 2 or 4.
393 (void) in_le16(addr);
397 (void) in_le32(addr);
400 return PCIBIOS_SUCCESSFUL;
403 static struct pci_ops u3_ht_pci_ops =
409 #endif /* CONFIG_POWER4 */
412 * For a bandit bridge, turn on cache coherency if necessary.
413 * N.B. we could clean this up using the hose ops directly.
416 init_bandit(struct pci_controller *bp)
418 unsigned int vendev, magic;
421 /* read the word at offset 0 in config space for device 11 */
422 out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + PCI_VENDOR_ID);
424 vendev = in_le32(bp->cfg_data);
425 if (vendev == (PCI_DEVICE_ID_APPLE_BANDIT << 16) +
426 PCI_VENDOR_ID_APPLE) {
427 /* read the revision id */
428 out_le32(bp->cfg_addr,
429 (1UL << BANDIT_DEVNUM) + PCI_REVISION_ID);
431 rev = in_8(bp->cfg_data);
432 if (rev != BANDIT_REVID)
434 "Unknown revision %d for bandit\n", rev);
435 } else if (vendev != (BANDIT_DEVID_2 << 16) + PCI_VENDOR_ID_APPLE) {
436 printk(KERN_WARNING "bandit isn't? (%x)\n", vendev);
440 /* read the word at offset 0x50 */
441 out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + BANDIT_MAGIC);
443 magic = in_le32(bp->cfg_data);
444 if ((magic & BANDIT_COHERENT) != 0)
446 magic |= BANDIT_COHERENT;
448 out_le32(bp->cfg_data, magic);
449 printk(KERN_INFO "Cache coherency enabled for bandit/PSX\n");
454 * Tweak the PCI-PCI bridge chip on the blue & white G3s.
459 struct device_node *p2pbridge;
460 struct pci_controller* hose;
464 /* XXX it would be better here to identify the specific
465 PCI-PCI bridge chip we have. */
466 if ((p2pbridge = find_devices("pci-bridge")) == 0
467 || p2pbridge->parent == NULL
468 || strcmp(p2pbridge->parent->name, "pci") != 0)
470 if (pci_device_from_OF_node(p2pbridge, &bus, &devfn) < 0) {
471 DBG("Can't find PCI infos for PCI<->PCI bridge\n");
474 /* Warning: At this point, we have not yet renumbered all busses.
475 * So we must use OF walking to find out hose
477 hose = pci_find_hose_for_OF_device(p2pbridge);
479 DBG("Can't find hose for PCI<->PCI bridge\n");
482 if (early_read_config_word(hose, bus, devfn,
483 PCI_BRIDGE_CONTROL, &val) < 0) {
484 printk(KERN_ERR "init_p2pbridge: couldn't read bridge control\n");
487 val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
488 early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val);
492 * Some Apple desktop machines have a NEC PD720100A USB2 controller
493 * on the motherboard. Open Firmware, on these, will disable the
494 * EHCI part of it so it behaves like a pair of OHCI's. This fixup
495 * code re-enables it ;)
500 struct device_node *nec;
502 for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) {
503 struct pci_controller *hose;
507 prop = (u32 *)get_property(nec, "vendor-id", NULL);
512 prop = (u32 *)get_property(nec, "device-id", NULL);
517 prop = (u32 *)get_property(nec, "reg", NULL);
520 devfn = (prop[0] >> 8) & 0xff;
521 bus = (prop[0] >> 16) & 0xff;
522 if (PCI_FUNC(devfn) != 0)
524 hose = pci_find_hose_for_OF_device(nec);
527 early_read_config_dword(hose, bus, devfn, 0xe4, &data);
529 printk("Found NEC PD720100A USB2 chip with disabled EHCI, fixing up...\n");
531 early_write_config_dword(hose, bus, devfn, 0xe4, data);
532 early_write_config_byte(hose, bus, devfn | 2, PCI_INTERRUPT_LINE,
539 pmac_find_bridges(void)
541 struct device_node *np, *root;
542 struct device_node *ht = NULL;
544 root = of_find_node_by_path("/");
546 printk(KERN_CRIT "pmac_find_bridges: can't find root of device tree\n");
549 for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
550 if (np->name == NULL)
552 if (strcmp(np->name, "bandit") == 0
553 || strcmp(np->name, "chaos") == 0
554 || strcmp(np->name, "pci") == 0) {
555 if (add_bridge(np) == 0)
558 if (strcmp(np->name, "ht") == 0) {
565 /* Probe HT last as it relies on the agp resources to be already
568 if (ht && add_bridge(ht) != 0)
574 /* We are still having some issues with the Xserve G4, enabling
575 * some offset between bus number and domains for now when we
576 * assign all busses should help for now
578 if (pci_assign_all_busses)
579 pcibios_assign_bus_offset = 0x10;
582 /* There is something wrong with DMA on U3/HT. I haven't figured out
583 * the details yet, but if I set the cache line size to 128 bytes like
584 * it should, I'm getting memory corruption caused by devices like
585 * sungem (even without the MWI bit set, but maybe sungem doesn't
586 * care). Right now, it appears that setting up a 64 bytes line size
587 * works properly, 64 bytes beeing the max transfer size of HT, I
588 * suppose this is related the way HT/PCI are hooked together. I still
589 * need to dive into more specs though to be really sure of what's
592 * Ok, apparently, it's just that HT can't do more than 64 bytes
593 * transactions. MWI seem to be meaningless there as well, it may
594 * be worth nop'ing out pci_set_mwi too though I haven't done that
597 * Note that it's a bit different for whatever is in the AGP slot.
598 * For now, I don't care, but this can become a real issue, we
599 * should probably hook pci_set_mwi anyway to make sure it sets
600 * the real cache line size in there.
602 if (machine_is_compatible("MacRISC4"))
603 pci_cache_line_size = 16; /* 64 bytes */
605 pmac_check_ht_link();
606 #endif /* CONFIG_POWER4 */
609 #define GRACKLE_CFA(b, d, o) (0x80 | ((b) << 8) | ((d) << 16) \
610 | (((o) & ~3) << 24))
612 #define GRACKLE_PICR1_STG 0x00000040
613 #define GRACKLE_PICR1_LOOPSNOOP 0x00000010
615 /* N.B. this is called before bridges is initialized, so we can't
616 use grackle_pcibios_{read,write}_config_dword. */
617 static inline void grackle_set_stg(struct pci_controller* bp, int enable)
621 out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
622 val = in_le32(bp->cfg_data);
623 val = enable? (val | GRACKLE_PICR1_STG) :
624 (val & ~GRACKLE_PICR1_STG);
625 out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
626 out_le32(bp->cfg_data, val);
627 (void)in_le32(bp->cfg_data);
630 static inline void grackle_set_loop_snoop(struct pci_controller *bp, int enable)
634 out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
635 val = in_le32(bp->cfg_data);
636 val = enable? (val | GRACKLE_PICR1_LOOPSNOOP) :
637 (val & ~GRACKLE_PICR1_LOOPSNOOP);
638 out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
639 out_le32(bp->cfg_data, val);
640 (void)in_le32(bp->cfg_data);
644 setup_uninorth(struct pci_controller* hose, struct reg_property* addr)
646 pci_assign_all_busses = 1;
648 hose->ops = ¯isc_pci_ops;
649 hose->cfg_addr = ioremap(addr->address + 0x800000, 0x1000);
650 hose->cfg_data = ioremap(addr->address + 0xc00000, 0x1000);
651 /* We "know" that the bridge at f2000000 has the PCI slots. */
652 return addr->address == 0xf2000000;
656 setup_bandit(struct pci_controller* hose, struct reg_property* addr)
658 hose->ops = ¯isc_pci_ops;
659 hose->cfg_addr = ioremap(addr->address + 0x800000, 0x1000);
660 hose->cfg_data = ioremap(addr->address + 0xc00000, 0x1000);
665 setup_chaos(struct pci_controller* hose, struct reg_property* addr)
667 /* assume a `chaos' bridge */
668 hose->ops = &chaos_pci_ops;
669 hose->cfg_addr = ioremap(addr->address + 0x800000, 0x1000);
670 hose->cfg_data = ioremap(addr->address + 0xc00000, 0x1000);
676 setup_u3_agp(struct pci_controller* hose, struct reg_property* addr)
678 /* On G5, we move AGP up to high bus number so we don't need
679 * to reassign bus numbers for HT. If we ever have P2P bridges
680 * on AGP, we'll have to move pci_assign_all_busses to the
681 * pci_controller structure so we enable it for AGP and not for
683 * We hard code the address because of the different size of
684 * the reg address cell, we shall fix that by killing struct
685 * reg_property and using some accessor functions instead
687 hose->first_busno = 0xf0;
688 hose->last_busno = 0xff;
690 hose->ops = ¯isc_pci_ops;
691 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
692 hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
698 setup_u3_ht(struct pci_controller* hose, struct reg_property *addr)
700 struct device_node *np = (struct device_node *)hose->arch_data;
703 hose->ops = &u3_ht_pci_ops;
705 /* We hard code the address because of the different size of
706 * the reg address cell, we shall fix that by killing struct
707 * reg_property and using some accessor functions instead
709 hose->cfg_data = ioremap(0xf2000000, 0x02000000);
712 * /ht node doesn't expose a "ranges" property, so we "remove" regions that
713 * have been allocated to AGP. So far, this version of the code doesn't assign
714 * any of the 0xfxxxxxxx "fine" memory regions to /ht.
715 * We need to fix that sooner or later by either parsing all child "ranges"
716 * properties or figuring out the U3 address space decoding logic and
717 * then read its configuration register (if any).
719 hose->io_base_phys = 0xf4000000;
720 hose->io_base_virt = ioremap(hose->io_base_phys, 0x00400000);
721 isa_io_base = (unsigned long) hose->io_base_virt;
722 hose->io_resource.name = np->full_name;
723 hose->io_resource.start = 0;
724 hose->io_resource.end = 0x003fffff;
725 hose->io_resource.flags = IORESOURCE_IO;
726 hose->pci_mem_offset = 0;
727 hose->first_busno = 0;
728 hose->last_busno = 0xef;
729 hose->mem_resources[0].name = np->full_name;
730 hose->mem_resources[0].start = 0x80000000;
731 hose->mem_resources[0].end = 0xefffffff;
732 hose->mem_resources[0].flags = IORESOURCE_MEM;
734 if (u3_agp == NULL) {
735 DBG("U3 has no AGP, using full resource range\n");
739 /* We "remove" the AGP resources from the resources allocated to HT, that
740 * is we create "holes". However, that code does assumptions that so far
741 * happen to be true (cross fingers...), typically that resources in the
742 * AGP node are properly ordered
745 for (i=0; i<3; i++) {
746 struct resource *res = &u3_agp->mem_resources[i];
747 if (res->flags != IORESOURCE_MEM)
749 /* We don't care about "fine" resources */
750 if (res->start >= 0xf0000000)
752 /* Check if it's just a matter of "shrinking" us in one direction */
753 if (hose->mem_resources[cur].start == res->start) {
754 DBG("U3/HT: shrink start of %d, %08lx -> %08lx\n",
755 cur, hose->mem_resources[cur].start, res->end + 1);
756 hose->mem_resources[cur].start = res->end + 1;
759 if (hose->mem_resources[cur].end == res->end) {
760 DBG("U3/HT: shrink end of %d, %08lx -> %08lx\n",
761 cur, hose->mem_resources[cur].end, res->start - 1);
762 hose->mem_resources[cur].end = res->start - 1;
765 /* No, it's not the case, we need a hole */
767 /* not enough resources to make a hole, we drop part of the range */
768 printk(KERN_WARNING "Running out of resources for /ht host !\n");
769 hose->mem_resources[cur].end = res->start - 1;
773 DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n",
774 cur-1, res->start - 1, cur, res->end + 1);
775 hose->mem_resources[cur].name = np->full_name;
776 hose->mem_resources[cur].flags = IORESOURCE_MEM;
777 hose->mem_resources[cur].start = res->end + 1;
778 hose->mem_resources[cur].end = hose->mem_resources[cur-1].end;
779 hose->mem_resources[cur-1].end = res->start - 1;
783 #endif /* CONFIG_POWER4 */
786 setup_grackle(struct pci_controller *hose)
788 setup_indirect_pci(hose, 0xfec00000, 0xfee00000);
789 if (machine_is_compatible("AAPL,PowerBook1998"))
790 grackle_set_loop_snoop(hose, 1);
791 #if 0 /* Disabled for now, HW problems ??? */
792 grackle_set_stg(hose, 1);
797 * We assume that if we have a G3 powermac, we have one bridge called
798 * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise,
799 * if we have one or more bandit or chaos bridges, we don't have a MPC106.
802 add_bridge(struct device_node *dev)
805 struct pci_controller *hose;
806 struct reg_property *addr;
811 DBG("Adding PCI host bridge %s\n", dev->full_name);
813 addr = (struct reg_property *) get_property(dev, "reg", &len);
814 if (addr == NULL || len < sizeof(*addr)) {
815 printk(KERN_WARNING "Can't use %s: no address\n",
819 bus_range = (int *) get_property(dev, "bus-range", &len);
820 if (bus_range == NULL || len < 2 * sizeof(int)) {
821 printk(KERN_WARNING "Can't get bus-range for %s, assume bus 0\n",
825 hose = pcibios_alloc_controller();
828 hose->arch_data = dev;
829 hose->first_busno = bus_range ? bus_range[0] : 0;
830 hose->last_busno = bus_range ? bus_range[1] : 0xff;
834 if (device_is_compatible(dev, "u3-agp")) {
835 setup_u3_agp(hose, addr);
836 disp_name = "U3-AGP";
838 } else if (device_is_compatible(dev, "u3-ht")) {
839 setup_u3_ht(hose, addr);
843 #endif /* CONFIG_POWER4 */
844 if (device_is_compatible(dev, "uni-north")) {
845 primary = setup_uninorth(hose, addr);
846 disp_name = "UniNorth";
847 } else if (strcmp(dev->name, "pci") == 0) {
848 /* XXX assume this is a mpc106 (grackle) */
850 disp_name = "Grackle (MPC106)";
851 } else if (strcmp(dev->name, "bandit") == 0) {
852 setup_bandit(hose, addr);
853 disp_name = "Bandit";
854 } else if (strcmp(dev->name, "chaos") == 0) {
855 setup_chaos(hose, addr);
859 printk(KERN_INFO "Found %s PCI host bridge at 0x%08x. Firmware bus number: %d->%d\n",
860 disp_name, addr->address, hose->first_busno, hose->last_busno);
861 DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
862 hose, hose->cfg_addr, hose->cfg_data);
864 /* Interpret the "ranges" property */
865 /* This also maps the I/O region and sets isa_io/mem_base */
866 pci_process_bridge_OF_ranges(hose, dev, primary);
868 /* Fixup "bus-range" OF property */
869 fixup_bus_range(dev);
875 pcibios_fixup_OF_interrupts(void)
877 struct pci_dev* dev = NULL;
880 * Open Firmware often doesn't initialize the
881 * PCI_INTERRUPT_LINE config register properly, so we
882 * should find the device node and apply the interrupt
883 * obtained from the OF device-tree
885 for_each_pci_dev(dev) {
886 struct device_node *node;
887 node = pci_device_to_OF_node(dev);
888 /* this is the node, see if it has interrupts */
889 if (node && node->n_intrs > 0)
890 dev->irq = node->intrs[0].line;
891 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
896 pmac_pcibios_fixup(void)
898 /* Fixup interrupts according to OF tree */
899 pcibios_fixup_OF_interrupts();
903 pmac_pci_enable_device_hook(struct pci_dev *dev, int initial)
905 struct device_node* node;
909 node = pci_device_to_OF_node(dev);
911 /* We don't want to enable USB controllers absent from the OF tree
912 * (iBook second controller)
914 if (dev->vendor == PCI_VENDOR_ID_APPLE
915 && (dev->class == ((PCI_CLASS_SERIAL_USB << 8) | 0x10))
917 printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",
925 uninorth_child = node->parent &&
926 device_is_compatible(node->parent, "uni-north");
928 /* Firewire & GMAC were disabled after PCI probe, the driver is
929 * claiming them, we must re-enable them now.
931 if (uninorth_child && !strcmp(node->name, "firewire") &&
932 (device_is_compatible(node, "pci106b,18") ||
933 device_is_compatible(node, "pci106b,30") ||
934 device_is_compatible(node, "pci11c1,5811"))) {
935 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
936 pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
939 if (uninorth_child && !strcmp(node->name, "ethernet") &&
940 device_is_compatible(node, "gmac")) {
941 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
949 * Make sure PCI is correctly configured
951 * We use old pci_bios versions of the function since, by
952 * default, gmac is not powered up, and so will be absent
953 * from the kernel initial PCI lookup.
955 * Should be replaced by 2.4 new PCI mechanisms and really
956 * register the device.
958 pci_read_config_word(dev, PCI_COMMAND, &cmd);
959 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE;
960 pci_write_config_word(dev, PCI_COMMAND, cmd);
961 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);
962 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cache_line_size);
968 /* We power down some devices after they have been probed. They'll
969 * be powered back on later on
972 pmac_pcibios_after_init(void)
974 struct device_node* nd;
976 #ifdef CONFIG_BLK_DEV_IDE
977 struct pci_dev *dev = NULL;
979 /* OF fails to initialize IDE controllers on macs
980 * (and maybe other machines)
982 * Ideally, this should be moved to the IDE layer, but we need
983 * to check specifically with Andre Hedrick how to do it cleanly
984 * since the common IDE code seem to care about the fact that the
985 * BIOS may have disabled a controller.
989 for_each_pci_dev(dev) {
990 if ((dev->class >> 16) == PCI_BASE_CLASS_STORAGE)
991 pci_enable_device(dev);
993 #endif /* CONFIG_BLK_DEV_IDE */
995 nd = find_devices("firewire");
997 if (nd->parent && (device_is_compatible(nd, "pci106b,18") ||
998 device_is_compatible(nd, "pci106b,30") ||
999 device_is_compatible(nd, "pci11c1,5811"))
1000 && device_is_compatible(nd->parent, "uni-north")) {
1001 pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
1002 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
1006 nd = find_devices("ethernet");
1008 if (nd->parent && device_is_compatible(nd, "gmac")
1009 && device_is_compatible(nd->parent, "uni-north"))
1010 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
1015 void pmac_pci_fixup_cardbus(struct pci_dev* dev)
1017 if (_machine != _MACH_Pmac)
1020 * Fix the interrupt routing on the various cardbus bridges
1021 * used on powerbooks
1023 if (dev->vendor != PCI_VENDOR_ID_TI)
1025 if (dev->device == PCI_DEVICE_ID_TI_1130 ||
1026 dev->device == PCI_DEVICE_ID_TI_1131) {
1028 /* Enable PCI interrupt */
1029 if (pci_read_config_byte(dev, 0x91, &val) == 0)
1030 pci_write_config_byte(dev, 0x91, val | 0x30);
1031 /* Disable ISA interrupt mode */
1032 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1033 pci_write_config_byte(dev, 0x92, val & ~0x06);
1035 if (dev->device == PCI_DEVICE_ID_TI_1210 ||
1036 dev->device == PCI_DEVICE_ID_TI_1211 ||
1037 dev->device == PCI_DEVICE_ID_TI_1410 ||
1038 dev->device == PCI_DEVICE_ID_TI_1510) {
1040 /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA
1041 signal out the MFUNC0 pin */
1042 if (pci_read_config_byte(dev, 0x8c, &val) == 0)
1043 pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
1044 /* Disable ISA interrupt mode */
1045 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1046 pci_write_config_byte(dev, 0x92, val & ~0x06);
1050 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);
1052 void pmac_pci_fixup_pciata(struct pci_dev* dev)
1057 * On PowerMacs, we try to switch any PCI ATA controller to
1060 if (_machine != _MACH_Pmac)
1062 /* Some controllers don't have the class IDE */
1063 if (dev->vendor == PCI_VENDOR_ID_PROMISE)
1064 switch(dev->device) {
1065 case PCI_DEVICE_ID_PROMISE_20246:
1066 case PCI_DEVICE_ID_PROMISE_20262:
1067 case PCI_DEVICE_ID_PROMISE_20263:
1068 case PCI_DEVICE_ID_PROMISE_20265:
1069 case PCI_DEVICE_ID_PROMISE_20267:
1070 case PCI_DEVICE_ID_PROMISE_20268:
1071 case PCI_DEVICE_ID_PROMISE_20269:
1072 case PCI_DEVICE_ID_PROMISE_20270:
1073 case PCI_DEVICE_ID_PROMISE_20271:
1074 case PCI_DEVICE_ID_PROMISE_20275:
1075 case PCI_DEVICE_ID_PROMISE_20276:
1076 case PCI_DEVICE_ID_PROMISE_20277:
1079 /* Others, check PCI class */
1080 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
1083 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
1084 if ((progif & 5) != 5) {
1085 printk(KERN_INFO "Forcing PCI IDE into native mode: %s\n", pci_name(dev));
1086 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
1087 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
1089 printk(KERN_ERR "Rewrite of PROGIF failed !\n");
1092 DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);
1096 * Disable second function on K2-SATA, it's broken
1097 * and disable IO BARs on first one
1099 void __pmac pmac_pci_fixup_k2_sata(struct pci_dev* dev)
1104 if (PCI_FUNC(dev->devfn) > 0) {
1105 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1106 cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
1107 pci_write_config_word(dev, PCI_COMMAND, cmd);
1108 for (i = 0; i < 6; i++) {
1109 dev->resource[i].start = dev->resource[i].end = 0;
1110 dev->resource[i].flags = 0;
1111 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, 0);
1114 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1115 cmd &= ~PCI_COMMAND_IO;
1116 pci_write_config_word(dev, PCI_COMMAND, cmd);
1117 for (i = 0; i < 5; i++) {
1118 dev->resource[i].start = dev->resource[i].end = 0;
1119 dev->resource[i].flags = 0;
1120 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, 0);
1124 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, pmac_pci_fixup_k2_sata);