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>
20 #include <linux/bootmem.h>
22 #include <asm/sections.h>
25 #include <asm/pci-bridge.h>
26 #include <asm/machdep.h>
27 #include <asm/pmac_feature.h>
33 extern void xmon_printf(const char *fmt
, ...);
34 #define DBG(x...) xmon_printf(x)
36 #define DBG(x...) printk(x)
42 static int add_bridge(struct device_node
*dev
);
43 extern void pmac_check_ht_link(void);
45 /* XXX Could be per-controller, but I don't think we risk anything by
46 * assuming we won't have both UniNorth and Bandit */
47 static int has_uninorth
;
49 static struct pci_controller
*u3_agp
;
50 #endif /* CONFIG_POWER4 */
52 extern u8 pci_cache_line_size
;
53 extern int pcibios_assign_bus_offset
;
55 struct device_node
*k2_skiplist
[2];
58 * Magic constants for enabling cache coherency in the bandit/PSX bridge.
60 #define BANDIT_DEVID_2 8
61 #define BANDIT_REVID 3
63 #define BANDIT_DEVNUM 11
64 #define BANDIT_MAGIC 0x50
65 #define BANDIT_COHERENT 0x40
68 fixup_one_level_bus_range(struct device_node
*node
, int higher
)
70 for (; node
!= 0;node
= node
->sibling
) {
72 unsigned int *class_code
;
75 /* For PCI<->PCI bridges or CardBus bridges, we go down */
76 class_code
= (unsigned int *) get_property(node
, "class-code", NULL
);
77 if (!class_code
|| ((*class_code
>> 8) != PCI_CLASS_BRIDGE_PCI
&&
78 (*class_code
>> 8) != PCI_CLASS_BRIDGE_CARDBUS
))
80 bus_range
= (int *) get_property(node
, "bus-range", &len
);
81 if (bus_range
!= NULL
&& len
> 2 * sizeof(int)) {
82 if (bus_range
[1] > higher
)
83 higher
= bus_range
[1];
85 higher
= fixup_one_level_bus_range(node
->child
, higher
);
90 /* This routine fixes the "bus-range" property of all bridges in the
91 * system since they tend to have their "last" member wrong on macs
93 * Note that the bus numbers manipulated here are OF bus numbers, they
94 * are not Linux bus numbers.
97 fixup_bus_range(struct device_node
*bridge
)
102 /* Lookup the "bus-range" property for the hose */
103 bus_range
= (int *) get_property(bridge
, "bus-range", &len
);
104 if (bus_range
== NULL
|| len
< 2 * sizeof(int)) {
105 printk(KERN_WARNING
"Can't get bus-range for %s\n",
109 bus_range
[1] = fixup_one_level_bus_range(bridge
->child
, bus_range
[1]);
113 * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers.
115 * The "Bandit" version is present in all early PCI PowerMacs,
116 * and up to the first ones using Grackle. Some machines may
117 * have 2 bandit controllers (2 PCI busses).
119 * "Chaos" is used in some "Bandit"-type machines as a bridge
120 * for the separate display bus. It is accessed the same
121 * way as bandit, but cannot be probed for devices. It therefore
122 * has its own config access functions.
124 * The "UniNorth" version is present in all Core99 machines
125 * (iBook, G4, new IMacs, and all the recent Apple machines).
126 * It contains 3 controllers in one ASIC.
128 * The U3 is the bridge used on G5 machines. It contains an
129 * AGP bus which is dealt with the old UniNorth access routines
130 * and a HyperTransport bus which uses its own set of access
134 #define MACRISC_CFA0(devfn, off) \
135 ((1 << (unsigned long)PCI_SLOT(dev_fn)) \
136 | (((unsigned long)PCI_FUNC(dev_fn)) << 8) \
137 | (((unsigned long)(off)) & 0xFCUL))
139 #define MACRISC_CFA1(bus, devfn, off) \
140 ((((unsigned long)(bus)) << 16) \
141 |(((unsigned long)(devfn)) << 8) \
142 |(((unsigned long)(off)) & 0xFCUL) \
145 static void volatile __iomem
* __pmac
146 macrisc_cfg_access(struct pci_controller
* hose
, u8 bus
, u8 dev_fn
, u8 offset
)
150 if (bus
== hose
->first_busno
) {
151 if (dev_fn
< (11 << 3))
153 caddr
= MACRISC_CFA0(dev_fn
, offset
);
155 caddr
= MACRISC_CFA1(bus
, dev_fn
, offset
);
157 /* Uninorth will return garbage if we don't read back the value ! */
159 out_le32(hose
->cfg_addr
, caddr
);
160 } while (in_le32(hose
->cfg_addr
) != caddr
);
162 offset
&= has_uninorth
? 0x07 : 0x03;
163 return hose
->cfg_data
+ offset
;
167 macrisc_read_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
170 struct pci_controller
*hose
= bus
->sysdata
;
171 void volatile __iomem
*addr
;
173 addr
= macrisc_cfg_access(hose
, bus
->number
, devfn
, offset
);
175 return PCIBIOS_DEVICE_NOT_FOUND
;
177 * Note: the caller has already checked that offset is
178 * suitably aligned and that len is 1, 2 or 4.
185 *val
= in_le16(addr
);
188 *val
= in_le32(addr
);
191 return PCIBIOS_SUCCESSFUL
;
195 macrisc_write_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
198 struct pci_controller
*hose
= bus
->sysdata
;
199 void volatile __iomem
*addr
;
201 addr
= macrisc_cfg_access(hose
, bus
->number
, devfn
, offset
);
203 return PCIBIOS_DEVICE_NOT_FOUND
;
205 * Note: the caller has already checked that offset is
206 * suitably aligned and that len is 1, 2 or 4.
215 (void) in_le16(addr
);
219 (void) in_le32(addr
);
222 return PCIBIOS_SUCCESSFUL
;
225 static struct pci_ops macrisc_pci_ops
=
232 * Verifiy that a specific (bus, dev_fn) exists on chaos
235 chaos_validate_dev(struct pci_bus
*bus
, int devfn
, int offset
)
237 struct device_node
*np
;
238 u32
*vendor
, *device
;
240 np
= pci_busdev_to_OF_node(bus
, devfn
);
242 return PCIBIOS_DEVICE_NOT_FOUND
;
244 vendor
= (u32
*)get_property(np
, "vendor-id", NULL
);
245 device
= (u32
*)get_property(np
, "device-id", NULL
);
246 if (vendor
== NULL
|| device
== NULL
)
247 return PCIBIOS_DEVICE_NOT_FOUND
;
249 if ((*vendor
== 0x106b) && (*device
== 3) && (offset
>= 0x10)
250 && (offset
!= 0x14) && (offset
!= 0x18) && (offset
<= 0x24))
251 return PCIBIOS_BAD_REGISTER_NUMBER
;
253 return PCIBIOS_SUCCESSFUL
;
257 chaos_read_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
260 int result
= chaos_validate_dev(bus
, devfn
, offset
);
261 if (result
== PCIBIOS_BAD_REGISTER_NUMBER
)
263 if (result
!= PCIBIOS_SUCCESSFUL
)
265 return macrisc_read_config(bus
, devfn
, offset
, len
, val
);
269 chaos_write_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
272 int result
= chaos_validate_dev(bus
, devfn
, offset
);
273 if (result
!= PCIBIOS_SUCCESSFUL
)
275 return macrisc_write_config(bus
, devfn
, offset
, len
, val
);
278 static struct pci_ops chaos_pci_ops
=
287 * These versions of U3 HyperTransport config space access ops do not
288 * implement self-view of the HT host yet
291 #define U3_HT_CFA0(devfn, off) \
292 ((((unsigned long)devfn) << 8) | offset)
293 #define U3_HT_CFA1(bus, devfn, off) \
294 (U3_HT_CFA0(devfn, off) \
295 + (((unsigned long)bus) << 16) \
298 static void volatile __iomem
* __pmac
299 u3_ht_cfg_access(struct pci_controller
* hose
, u8 bus
, u8 devfn
, u8 offset
)
301 if (bus
== hose
->first_busno
) {
302 /* For now, we don't self probe U3 HT bridge */
303 if (PCI_FUNC(devfn
) != 0 || PCI_SLOT(devfn
) > 7 ||
306 return hose
->cfg_data
+ U3_HT_CFA0(devfn
, offset
);
308 return hose
->cfg_data
+ U3_HT_CFA1(bus
, devfn
, offset
);
312 u3_ht_read_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
315 struct pci_controller
*hose
= bus
->sysdata
;
316 void volatile __iomem
*addr
;
319 struct device_node
*np
= pci_busdev_to_OF_node(bus
, devfn
);
321 return PCIBIOS_DEVICE_NOT_FOUND
;
324 * When a device in K2 is powered down, we die on config
325 * cycle accesses. Fix that here.
328 if (k2_skiplist
[i
] == np
) {
333 *val
= 0xffff; break;
335 *val
= 0xfffffffful
; break;
337 return PCIBIOS_SUCCESSFUL
;
340 addr
= u3_ht_cfg_access(hose
, bus
->number
, devfn
, offset
);
342 return PCIBIOS_DEVICE_NOT_FOUND
;
344 * Note: the caller has already checked that offset is
345 * suitably aligned and that len is 1, 2 or 4.
352 *val
= in_le16(addr
);
355 *val
= in_le32(addr
);
358 return PCIBIOS_SUCCESSFUL
;
362 u3_ht_write_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
365 struct pci_controller
*hose
= bus
->sysdata
;
366 void volatile __iomem
*addr
;
369 struct device_node
*np
= pci_busdev_to_OF_node(bus
, devfn
);
371 return PCIBIOS_DEVICE_NOT_FOUND
;
373 * When a device in K2 is powered down, we die on config
374 * cycle accesses. Fix that here.
377 if (k2_skiplist
[i
] == np
)
378 return PCIBIOS_SUCCESSFUL
;
380 addr
= u3_ht_cfg_access(hose
, bus
->number
, devfn
, offset
);
382 return PCIBIOS_DEVICE_NOT_FOUND
;
384 * Note: the caller has already checked that offset is
385 * suitably aligned and that len is 1, 2 or 4.
394 (void) in_le16(addr
);
398 (void) in_le32(addr
);
401 return PCIBIOS_SUCCESSFUL
;
404 static struct pci_ops u3_ht_pci_ops
=
410 #endif /* CONFIG_POWER4 */
413 * For a bandit bridge, turn on cache coherency if necessary.
414 * N.B. we could clean this up using the hose ops directly.
417 init_bandit(struct pci_controller
*bp
)
419 unsigned int vendev
, magic
;
422 /* read the word at offset 0 in config space for device 11 */
423 out_le32(bp
->cfg_addr
, (1UL << BANDIT_DEVNUM
) + PCI_VENDOR_ID
);
425 vendev
= in_le32(bp
->cfg_data
);
426 if (vendev
== (PCI_DEVICE_ID_APPLE_BANDIT
<< 16) +
427 PCI_VENDOR_ID_APPLE
) {
428 /* read the revision id */
429 out_le32(bp
->cfg_addr
,
430 (1UL << BANDIT_DEVNUM
) + PCI_REVISION_ID
);
432 rev
= in_8(bp
->cfg_data
);
433 if (rev
!= BANDIT_REVID
)
435 "Unknown revision %d for bandit\n", rev
);
436 } else if (vendev
!= (BANDIT_DEVID_2
<< 16) + PCI_VENDOR_ID_APPLE
) {
437 printk(KERN_WARNING
"bandit isn't? (%x)\n", vendev
);
441 /* read the word at offset 0x50 */
442 out_le32(bp
->cfg_addr
, (1UL << BANDIT_DEVNUM
) + BANDIT_MAGIC
);
444 magic
= in_le32(bp
->cfg_data
);
445 if ((magic
& BANDIT_COHERENT
) != 0)
447 magic
|= BANDIT_COHERENT
;
449 out_le32(bp
->cfg_data
, magic
);
450 printk(KERN_INFO
"Cache coherency enabled for bandit/PSX\n");
455 * Tweak the PCI-PCI bridge chip on the blue & white G3s.
460 struct device_node
*p2pbridge
;
461 struct pci_controller
* hose
;
465 /* XXX it would be better here to identify the specific
466 PCI-PCI bridge chip we have. */
467 if ((p2pbridge
= find_devices("pci-bridge")) == 0
468 || p2pbridge
->parent
== NULL
469 || strcmp(p2pbridge
->parent
->name
, "pci") != 0)
471 if (pci_device_from_OF_node(p2pbridge
, &bus
, &devfn
) < 0) {
472 DBG("Can't find PCI infos for PCI<->PCI bridge\n");
475 /* Warning: At this point, we have not yet renumbered all busses.
476 * So we must use OF walking to find out hose
478 hose
= pci_find_hose_for_OF_device(p2pbridge
);
480 DBG("Can't find hose for PCI<->PCI bridge\n");
483 if (early_read_config_word(hose
, bus
, devfn
,
484 PCI_BRIDGE_CONTROL
, &val
) < 0) {
485 printk(KERN_ERR
"init_p2pbridge: couldn't read bridge control\n");
488 val
&= ~PCI_BRIDGE_CTL_MASTER_ABORT
;
489 early_write_config_word(hose
, bus
, devfn
, PCI_BRIDGE_CONTROL
, val
);
493 * Some Apple desktop machines have a NEC PD720100A USB2 controller
494 * on the motherboard. Open Firmware, on these, will disable the
495 * EHCI part of it so it behaves like a pair of OHCI's. This fixup
496 * code re-enables it ;)
501 struct device_node
*nec
;
503 for (nec
= NULL
; (nec
= of_find_node_by_name(nec
, "usb")) != NULL
;) {
504 struct pci_controller
*hose
;
508 prop
= (u32
*)get_property(nec
, "vendor-id", NULL
);
513 prop
= (u32
*)get_property(nec
, "device-id", NULL
);
518 prop
= (u32
*)get_property(nec
, "reg", NULL
);
521 devfn
= (prop
[0] >> 8) & 0xff;
522 bus
= (prop
[0] >> 16) & 0xff;
523 if (PCI_FUNC(devfn
) != 0)
525 hose
= pci_find_hose_for_OF_device(nec
);
528 early_read_config_dword(hose
, bus
, devfn
, 0xe4, &data
);
530 printk("Found NEC PD720100A USB2 chip with disabled EHCI, fixing up...\n");
532 early_write_config_dword(hose
, bus
, devfn
, 0xe4, data
);
533 early_write_config_byte(hose
, bus
, devfn
| 2, PCI_INTERRUPT_LINE
,
540 pmac_find_bridges(void)
542 struct device_node
*np
, *root
;
543 struct device_node
*ht
= NULL
;
545 root
= of_find_node_by_path("/");
547 printk(KERN_CRIT
"pmac_find_bridges: can't find root of device tree\n");
550 for (np
= NULL
; (np
= of_get_next_child(root
, np
)) != NULL
;) {
551 if (np
->name
== NULL
)
553 if (strcmp(np
->name
, "bandit") == 0
554 || strcmp(np
->name
, "chaos") == 0
555 || strcmp(np
->name
, "pci") == 0) {
556 if (add_bridge(np
) == 0)
559 if (strcmp(np
->name
, "ht") == 0) {
566 /* Probe HT last as it relies on the agp resources to be already
569 if (ht
&& add_bridge(ht
) != 0)
575 /* We are still having some issues with the Xserve G4, enabling
576 * some offset between bus number and domains for now when we
577 * assign all busses should help for now
579 if (pci_assign_all_busses
)
580 pcibios_assign_bus_offset
= 0x10;
583 /* There is something wrong with DMA on U3/HT. I haven't figured out
584 * the details yet, but if I set the cache line size to 128 bytes like
585 * it should, I'm getting memory corruption caused by devices like
586 * sungem (even without the MWI bit set, but maybe sungem doesn't
587 * care). Right now, it appears that setting up a 64 bytes line size
588 * works properly, 64 bytes beeing the max transfer size of HT, I
589 * suppose this is related the way HT/PCI are hooked together. I still
590 * need to dive into more specs though to be really sure of what's
593 * Ok, apparently, it's just that HT can't do more than 64 bytes
594 * transactions. MWI seem to be meaningless there as well, it may
595 * be worth nop'ing out pci_set_mwi too though I haven't done that
598 * Note that it's a bit different for whatever is in the AGP slot.
599 * For now, I don't care, but this can become a real issue, we
600 * should probably hook pci_set_mwi anyway to make sure it sets
601 * the real cache line size in there.
603 if (machine_is_compatible("MacRISC4"))
604 pci_cache_line_size
= 16; /* 64 bytes */
606 pmac_check_ht_link();
607 #endif /* CONFIG_POWER4 */
610 #define GRACKLE_CFA(b, d, o) (0x80 | ((b) << 8) | ((d) << 16) \
611 | (((o) & ~3) << 24))
613 #define GRACKLE_PICR1_STG 0x00000040
614 #define GRACKLE_PICR1_LOOPSNOOP 0x00000010
616 /* N.B. this is called before bridges is initialized, so we can't
617 use grackle_pcibios_{read,write}_config_dword. */
618 static inline void grackle_set_stg(struct pci_controller
* bp
, int enable
)
622 out_be32(bp
->cfg_addr
, GRACKLE_CFA(0, 0, 0xa8));
623 val
= in_le32(bp
->cfg_data
);
624 val
= enable
? (val
| GRACKLE_PICR1_STG
) :
625 (val
& ~GRACKLE_PICR1_STG
);
626 out_be32(bp
->cfg_addr
, GRACKLE_CFA(0, 0, 0xa8));
627 out_le32(bp
->cfg_data
, val
);
628 (void)in_le32(bp
->cfg_data
);
631 static inline void grackle_set_loop_snoop(struct pci_controller
*bp
, int enable
)
635 out_be32(bp
->cfg_addr
, GRACKLE_CFA(0, 0, 0xa8));
636 val
= in_le32(bp
->cfg_data
);
637 val
= enable
? (val
| GRACKLE_PICR1_LOOPSNOOP
) :
638 (val
& ~GRACKLE_PICR1_LOOPSNOOP
);
639 out_be32(bp
->cfg_addr
, GRACKLE_CFA(0, 0, 0xa8));
640 out_le32(bp
->cfg_data
, val
);
641 (void)in_le32(bp
->cfg_data
);
645 setup_uninorth(struct pci_controller
* hose
, struct reg_property
* addr
)
647 pci_assign_all_busses
= 1;
649 hose
->ops
= ¯isc_pci_ops
;
650 hose
->cfg_addr
= ioremap(addr
->address
+ 0x800000, 0x1000);
651 hose
->cfg_data
= ioremap(addr
->address
+ 0xc00000, 0x1000);
652 /* We "know" that the bridge at f2000000 has the PCI slots. */
653 return addr
->address
== 0xf2000000;
657 setup_bandit(struct pci_controller
* hose
, struct reg_property
* addr
)
659 hose
->ops
= ¯isc_pci_ops
;
660 hose
->cfg_addr
= ioremap(addr
->address
+ 0x800000, 0x1000);
661 hose
->cfg_data
= ioremap(addr
->address
+ 0xc00000, 0x1000);
666 setup_chaos(struct pci_controller
* hose
, struct reg_property
* addr
)
668 /* assume a `chaos' bridge */
669 hose
->ops
= &chaos_pci_ops
;
670 hose
->cfg_addr
= ioremap(addr
->address
+ 0x800000, 0x1000);
671 hose
->cfg_data
= ioremap(addr
->address
+ 0xc00000, 0x1000);
677 setup_u3_agp(struct pci_controller
* hose
, struct reg_property
* addr
)
679 /* On G5, we move AGP up to high bus number so we don't need
680 * to reassign bus numbers for HT. If we ever have P2P bridges
681 * on AGP, we'll have to move pci_assign_all_busses to the
682 * pci_controller structure so we enable it for AGP and not for
684 * We hard code the address because of the different size of
685 * the reg address cell, we shall fix that by killing struct
686 * reg_property and using some accessor functions instead
688 hose
->first_busno
= 0xf0;
689 hose
->last_busno
= 0xff;
691 hose
->ops
= ¯isc_pci_ops
;
692 hose
->cfg_addr
= ioremap(0xf0000000 + 0x800000, 0x1000);
693 hose
->cfg_data
= ioremap(0xf0000000 + 0xc00000, 0x1000);
699 setup_u3_ht(struct pci_controller
* hose
, struct reg_property
*addr
)
701 struct device_node
*np
= (struct device_node
*)hose
->arch_data
;
704 hose
->ops
= &u3_ht_pci_ops
;
706 /* We hard code the address because of the different size of
707 * the reg address cell, we shall fix that by killing struct
708 * reg_property and using some accessor functions instead
710 hose
->cfg_data
= ioremap(0xf2000000, 0x02000000);
713 * /ht node doesn't expose a "ranges" property, so we "remove" regions that
714 * have been allocated to AGP. So far, this version of the code doesn't assign
715 * any of the 0xfxxxxxxx "fine" memory regions to /ht.
716 * We need to fix that sooner or later by either parsing all child "ranges"
717 * properties or figuring out the U3 address space decoding logic and
718 * then read its configuration register (if any).
720 hose
->io_base_phys
= 0xf4000000;
721 hose
->io_base_virt
= ioremap(hose
->io_base_phys
, 0x00400000);
722 isa_io_base
= (unsigned long) hose
->io_base_virt
;
723 hose
->io_resource
.name
= np
->full_name
;
724 hose
->io_resource
.start
= 0;
725 hose
->io_resource
.end
= 0x003fffff;
726 hose
->io_resource
.flags
= IORESOURCE_IO
;
727 hose
->pci_mem_offset
= 0;
728 hose
->first_busno
= 0;
729 hose
->last_busno
= 0xef;
730 hose
->mem_resources
[0].name
= np
->full_name
;
731 hose
->mem_resources
[0].start
= 0x80000000;
732 hose
->mem_resources
[0].end
= 0xefffffff;
733 hose
->mem_resources
[0].flags
= IORESOURCE_MEM
;
735 if (u3_agp
== NULL
) {
736 DBG("U3 has no AGP, using full resource range\n");
740 /* We "remove" the AGP resources from the resources allocated to HT, that
741 * is we create "holes". However, that code does assumptions that so far
742 * happen to be true (cross fingers...), typically that resources in the
743 * AGP node are properly ordered
746 for (i
=0; i
<3; i
++) {
747 struct resource
*res
= &u3_agp
->mem_resources
[i
];
748 if (res
->flags
!= IORESOURCE_MEM
)
750 /* We don't care about "fine" resources */
751 if (res
->start
>= 0xf0000000)
753 /* Check if it's just a matter of "shrinking" us in one direction */
754 if (hose
->mem_resources
[cur
].start
== res
->start
) {
755 DBG("U3/HT: shrink start of %d, %08lx -> %08lx\n",
756 cur
, hose
->mem_resources
[cur
].start
, res
->end
+ 1);
757 hose
->mem_resources
[cur
].start
= res
->end
+ 1;
760 if (hose
->mem_resources
[cur
].end
== res
->end
) {
761 DBG("U3/HT: shrink end of %d, %08lx -> %08lx\n",
762 cur
, hose
->mem_resources
[cur
].end
, res
->start
- 1);
763 hose
->mem_resources
[cur
].end
= res
->start
- 1;
766 /* No, it's not the case, we need a hole */
768 /* not enough resources to make a hole, we drop part of the range */
769 printk(KERN_WARNING
"Running out of resources for /ht host !\n");
770 hose
->mem_resources
[cur
].end
= res
->start
- 1;
774 DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n",
775 cur
-1, res
->start
- 1, cur
, res
->end
+ 1);
776 hose
->mem_resources
[cur
].name
= np
->full_name
;
777 hose
->mem_resources
[cur
].flags
= IORESOURCE_MEM
;
778 hose
->mem_resources
[cur
].start
= res
->end
+ 1;
779 hose
->mem_resources
[cur
].end
= hose
->mem_resources
[cur
-1].end
;
780 hose
->mem_resources
[cur
-1].end
= res
->start
- 1;
784 #endif /* CONFIG_POWER4 */
787 setup_grackle(struct pci_controller
*hose
)
789 setup_indirect_pci(hose
, 0xfec00000, 0xfee00000);
790 if (machine_is_compatible("AAPL,PowerBook1998"))
791 grackle_set_loop_snoop(hose
, 1);
792 #if 0 /* Disabled for now, HW problems ??? */
793 grackle_set_stg(hose
, 1);
798 * We assume that if we have a G3 powermac, we have one bridge called
799 * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise,
800 * if we have one or more bandit or chaos bridges, we don't have a MPC106.
803 add_bridge(struct device_node
*dev
)
806 struct pci_controller
*hose
;
807 struct reg_property
*addr
;
812 DBG("Adding PCI host bridge %s\n", dev
->full_name
);
814 addr
= (struct reg_property
*) get_property(dev
, "reg", &len
);
815 if (addr
== NULL
|| len
< sizeof(*addr
)) {
816 printk(KERN_WARNING
"Can't use %s: no address\n",
820 bus_range
= (int *) get_property(dev
, "bus-range", &len
);
821 if (bus_range
== NULL
|| len
< 2 * sizeof(int)) {
822 printk(KERN_WARNING
"Can't get bus-range for %s, assume bus 0\n",
826 hose
= pcibios_alloc_controller();
829 hose
->arch_data
= dev
;
830 hose
->first_busno
= bus_range
? bus_range
[0] : 0;
831 hose
->last_busno
= bus_range
? bus_range
[1] : 0xff;
835 if (device_is_compatible(dev
, "u3-agp")) {
836 setup_u3_agp(hose
, addr
);
837 disp_name
= "U3-AGP";
839 } else if (device_is_compatible(dev
, "u3-ht")) {
840 setup_u3_ht(hose
, addr
);
844 #endif /* CONFIG_POWER4 */
845 if (device_is_compatible(dev
, "uni-north")) {
846 primary
= setup_uninorth(hose
, addr
);
847 disp_name
= "UniNorth";
848 } else if (strcmp(dev
->name
, "pci") == 0) {
849 /* XXX assume this is a mpc106 (grackle) */
851 disp_name
= "Grackle (MPC106)";
852 } else if (strcmp(dev
->name
, "bandit") == 0) {
853 setup_bandit(hose
, addr
);
854 disp_name
= "Bandit";
855 } else if (strcmp(dev
->name
, "chaos") == 0) {
856 setup_chaos(hose
, addr
);
860 printk(KERN_INFO
"Found %s PCI host bridge at 0x%08x. Firmware bus number: %d->%d\n",
861 disp_name
, addr
->address
, hose
->first_busno
, hose
->last_busno
);
862 DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
863 hose
, hose
->cfg_addr
, hose
->cfg_data
);
865 /* Interpret the "ranges" property */
866 /* This also maps the I/O region and sets isa_io/mem_base */
867 pci_process_bridge_OF_ranges(hose
, dev
, primary
);
869 /* Fixup "bus-range" OF property */
870 fixup_bus_range(dev
);
876 pcibios_fixup_OF_interrupts(void)
878 struct pci_dev
* dev
= NULL
;
881 * Open Firmware often doesn't initialize the
882 * PCI_INTERRUPT_LINE config register properly, so we
883 * should find the device node and apply the interrupt
884 * obtained from the OF device-tree
886 for_each_pci_dev(dev
) {
887 struct device_node
*node
;
888 node
= pci_device_to_OF_node(dev
);
889 /* this is the node, see if it has interrupts */
890 if (node
&& node
->n_intrs
> 0)
891 dev
->irq
= node
->intrs
[0].line
;
892 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, dev
->irq
);
897 pmac_pcibios_fixup(void)
899 /* Fixup interrupts according to OF tree */
900 pcibios_fixup_OF_interrupts();
904 pmac_pci_enable_device_hook(struct pci_dev
*dev
, int initial
)
906 struct device_node
* node
;
910 node
= pci_device_to_OF_node(dev
);
912 /* We don't want to enable USB controllers absent from the OF tree
913 * (iBook second controller)
915 if (dev
->vendor
== PCI_VENDOR_ID_APPLE
916 && (dev
->class == ((PCI_CLASS_SERIAL_USB
<< 8) | 0x10))
918 printk(KERN_INFO
"Apple USB OHCI %s disabled by firmware\n",
926 uninorth_child
= node
->parent
&&
927 device_is_compatible(node
->parent
, "uni-north");
929 /* Firewire & GMAC were disabled after PCI probe, the driver is
930 * claiming them, we must re-enable them now.
932 if (uninorth_child
&& !strcmp(node
->name
, "firewire") &&
933 (device_is_compatible(node
, "pci106b,18") ||
934 device_is_compatible(node
, "pci106b,30") ||
935 device_is_compatible(node
, "pci11c1,5811"))) {
936 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER
, node
, 0, 1);
937 pmac_call_feature(PMAC_FTR_1394_ENABLE
, node
, 0, 1);
940 if (uninorth_child
&& !strcmp(node
->name
, "ethernet") &&
941 device_is_compatible(node
, "gmac")) {
942 pmac_call_feature(PMAC_FTR_GMAC_ENABLE
, node
, 0, 1);
950 * Make sure PCI is correctly configured
952 * We use old pci_bios versions of the function since, by
953 * default, gmac is not powered up, and so will be absent
954 * from the kernel initial PCI lookup.
956 * Should be replaced by 2.4 new PCI mechanisms and really
957 * register the device.
959 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
960 cmd
|= PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
| PCI_COMMAND_INVALIDATE
;
961 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
962 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, 16);
963 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
, pci_cache_line_size
);
969 /* We power down some devices after they have been probed. They'll
970 * be powered back on later on
973 pmac_pcibios_after_init(void)
975 struct device_node
* nd
;
977 #ifdef CONFIG_BLK_DEV_IDE
978 struct pci_dev
*dev
= NULL
;
980 /* OF fails to initialize IDE controllers on macs
981 * (and maybe other machines)
983 * Ideally, this should be moved to the IDE layer, but we need
984 * to check specifically with Andre Hedrick how to do it cleanly
985 * since the common IDE code seem to care about the fact that the
986 * BIOS may have disabled a controller.
990 for_each_pci_dev(dev
) {
991 if ((dev
->class >> 16) == PCI_BASE_CLASS_STORAGE
)
992 pci_enable_device(dev
);
994 #endif /* CONFIG_BLK_DEV_IDE */
996 nd
= find_devices("firewire");
998 if (nd
->parent
&& (device_is_compatible(nd
, "pci106b,18") ||
999 device_is_compatible(nd
, "pci106b,30") ||
1000 device_is_compatible(nd
, "pci11c1,5811"))
1001 && device_is_compatible(nd
->parent
, "uni-north")) {
1002 pmac_call_feature(PMAC_FTR_1394_ENABLE
, nd
, 0, 0);
1003 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER
, nd
, 0, 0);
1007 nd
= find_devices("ethernet");
1009 if (nd
->parent
&& device_is_compatible(nd
, "gmac")
1010 && device_is_compatible(nd
->parent
, "uni-north"))
1011 pmac_call_feature(PMAC_FTR_GMAC_ENABLE
, nd
, 0, 0);
1016 void pmac_pci_fixup_cardbus(struct pci_dev
* dev
)
1018 if (_machine
!= _MACH_Pmac
)
1021 * Fix the interrupt routing on the various cardbus bridges
1022 * used on powerbooks
1024 if (dev
->vendor
!= PCI_VENDOR_ID_TI
)
1026 if (dev
->device
== PCI_DEVICE_ID_TI_1130
||
1027 dev
->device
== PCI_DEVICE_ID_TI_1131
) {
1029 /* Enable PCI interrupt */
1030 if (pci_read_config_byte(dev
, 0x91, &val
) == 0)
1031 pci_write_config_byte(dev
, 0x91, val
| 0x30);
1032 /* Disable ISA interrupt mode */
1033 if (pci_read_config_byte(dev
, 0x92, &val
) == 0)
1034 pci_write_config_byte(dev
, 0x92, val
& ~0x06);
1036 if (dev
->device
== PCI_DEVICE_ID_TI_1210
||
1037 dev
->device
== PCI_DEVICE_ID_TI_1211
||
1038 dev
->device
== PCI_DEVICE_ID_TI_1410
||
1039 dev
->device
== PCI_DEVICE_ID_TI_1510
) {
1041 /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA
1042 signal out the MFUNC0 pin */
1043 if (pci_read_config_byte(dev
, 0x8c, &val
) == 0)
1044 pci_write_config_byte(dev
, 0x8c, (val
& ~0x0f) | 2);
1045 /* Disable ISA interrupt mode */
1046 if (pci_read_config_byte(dev
, 0x92, &val
) == 0)
1047 pci_write_config_byte(dev
, 0x92, val
& ~0x06);
1051 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI
, PCI_ANY_ID
, pmac_pci_fixup_cardbus
);
1053 void pmac_pci_fixup_pciata(struct pci_dev
* dev
)
1058 * On PowerMacs, we try to switch any PCI ATA controller to
1061 if (_machine
!= _MACH_Pmac
)
1063 /* Some controllers don't have the class IDE */
1064 if (dev
->vendor
== PCI_VENDOR_ID_PROMISE
)
1065 switch(dev
->device
) {
1066 case PCI_DEVICE_ID_PROMISE_20246
:
1067 case PCI_DEVICE_ID_PROMISE_20262
:
1068 case PCI_DEVICE_ID_PROMISE_20263
:
1069 case PCI_DEVICE_ID_PROMISE_20265
:
1070 case PCI_DEVICE_ID_PROMISE_20267
:
1071 case PCI_DEVICE_ID_PROMISE_20268
:
1072 case PCI_DEVICE_ID_PROMISE_20269
:
1073 case PCI_DEVICE_ID_PROMISE_20270
:
1074 case PCI_DEVICE_ID_PROMISE_20271
:
1075 case PCI_DEVICE_ID_PROMISE_20275
:
1076 case PCI_DEVICE_ID_PROMISE_20276
:
1077 case PCI_DEVICE_ID_PROMISE_20277
:
1080 /* Others, check PCI class */
1081 if ((dev
->class >> 8) != PCI_CLASS_STORAGE_IDE
)
1084 pci_read_config_byte(dev
, PCI_CLASS_PROG
, &progif
);
1085 if ((progif
& 5) != 5) {
1086 printk(KERN_INFO
"Forcing PCI IDE into native mode: %s\n", pci_name(dev
));
1087 (void) pci_write_config_byte(dev
, PCI_CLASS_PROG
, progif
|5);
1088 if (pci_read_config_byte(dev
, PCI_CLASS_PROG
, &progif
) ||
1090 printk(KERN_ERR
"Rewrite of PROGIF failed !\n");
1093 DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID
, PCI_ANY_ID
, pmac_pci_fixup_pciata
);
1097 * Disable second function on K2-SATA, it's broken
1098 * and disable IO BARs on first one
1100 void __pmac
pmac_pci_fixup_k2_sata(struct pci_dev
* dev
)
1105 if (PCI_FUNC(dev
->devfn
) > 0) {
1106 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
1107 cmd
&= ~(PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
1108 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
1109 for (i
= 0; i
< 6; i
++) {
1110 dev
->resource
[i
].start
= dev
->resource
[i
].end
= 0;
1111 dev
->resource
[i
].flags
= 0;
1112 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
+ 4 * i
, 0);
1115 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
1116 cmd
&= ~PCI_COMMAND_IO
;
1117 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
1118 for (i
= 0; i
< 5; i
++) {
1119 dev
->resource
[i
].start
= dev
->resource
[i
].end
= 0;
1120 dev
->resource
[i
].flags
= 0;
1121 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
+ 4 * i
, 0);
1125 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS
, 0x0240, pmac_pci_fixup_k2_sata
);