13 #include <linux/kernel.h>
14 #include <linux/pci.h>
16 #include <linux/string.h>
21 #include <asm/sections.h>
24 #include <asm/pci-bridge.h>
25 #include <asm/machdep.h>
26 #include <asm/iommu.h>
32 #define DBG(x...) printk(x)
41 for (; node != 0;node = node->
sibling) {
43 const unsigned int *class_code;
52 if (bus_range !=
NULL && len > 2 *
sizeof(
int)) {
53 if (bus_range[1] > higher)
54 higher = bus_range[1];
56 higher = fixup_one_level_bus_range(node->
child, higher);
75 if (prop ==
NULL || prop->
value ==
NULL || len < 2 *
sizeof(
int)) {
80 bus_range = prop->
value;
81 bus_range[1] = fixup_one_level_bus_range(bridge->
child, bus_range[1]);
85 static unsigned long u3_agp_cfa0(
u8 devfn,
u8 off)
87 return (1 << (
unsigned long)
PCI_SLOT(devfn)) |
89 ((
unsigned long)off & 0xFC
UL);
92 static unsigned long u3_agp_cfa1(
u8 bus,
u8 devfn,
u8 off)
94 return ((
unsigned long)bus << 16) |
95 ((
unsigned long)devfn << 8) |
96 ((
unsigned long)off & 0xFCUL) |
106 if (dev_fn < (11 << 3))
108 caddr = u3_agp_cfa0(dev_fn, offset);
110 caddr = u3_agp_cfa1(bus, dev_fn, offset);
115 }
while (
in_le32(hose->cfg_addr) != caddr);
118 return hose->cfg_data +
offset;
121 static int u3_agp_read_config(
struct pci_bus *bus,
unsigned int devfn,
122 int offset,
int len,
u32 *
val)
127 hose = pci_bus_to_host(bus);
131 addr = u3_agp_cfg_access(hose, bus->
number, devfn, offset);
152 static int u3_agp_write_config(
struct pci_bus *bus,
unsigned int devfn,
153 int offset,
int len,
u32 val)
158 hose = pci_bus_to_host(bus);
162 addr = u3_agp_cfg_access(hose, bus->
number, devfn, offset);
183 static struct pci_ops u3_agp_pci_ops =
185 .read = u3_agp_read_config,
186 .write = u3_agp_write_config,
189 static unsigned long u3_ht_cfa0(
u8 devfn,
u8 off)
191 return (devfn << 8) | off;
194 static unsigned long u3_ht_cfa1(
u8 bus,
u8 devfn,
u8 off)
196 return u3_ht_cfa0(devfn, off) + (bus << 16) + 0x01000000UL;
200 u8 bus,
u8 devfn,
u8 offset)
205 return hose->cfg_data + u3_ht_cfa0(devfn, offset);
207 return hose->cfg_data + u3_ht_cfa1(bus, devfn, offset);
215 addr = hose->cfg_addr;
216 addr += ((offset & ~3) << 2) + (4 - len - (offset & 3));
238 addr = hose->cfg_addr + ((offset & ~3) << 2) + (4 - len - (offset & 3));
258 static int u3_ht_read_config(
struct pci_bus *bus,
unsigned int devfn,
259 int offset,
int len,
u32 *val)
264 hose = pci_bus_to_host(bus);
269 return u3_ht_root_read_config(hose, offset, len, val);
274 addr = u3_ht_cfg_access(hose, bus->
number, devfn, offset);
296 static int u3_ht_write_config(
struct pci_bus *bus,
unsigned int devfn,
297 int offset,
int len,
u32 val)
302 hose = pci_bus_to_host(bus);
307 return u3_ht_root_write_config(hose, offset, len, val);
312 addr = u3_ht_cfg_access(hose, bus->
number, devfn, offset);
333 static struct pci_ops u3_ht_pci_ops =
335 .read = u3_ht_read_config,
336 .write = u3_ht_write_config,
339 static unsigned int u4_pcie_cfa0(
unsigned int devfn,
unsigned int off)
347 static unsigned int u4_pcie_cfa1(
unsigned int bus,
unsigned int devfn,
357 u8 bus,
u8 dev_fn,
int offset)
362 caddr = u4_pcie_cfa0(dev_fn, offset);
364 caddr = u4_pcie_cfa1(bus, dev_fn, offset);
369 }
while (
in_le32(hose->cfg_addr) != caddr);
372 return hose->cfg_data +
offset;
375 static int u4_pcie_read_config(
struct pci_bus *bus,
unsigned int devfn,
376 int offset,
int len,
u32 *val)
381 hose = pci_bus_to_host(bus);
384 if (offset >= 0x1000)
386 addr = u4_pcie_cfg_access(hose, bus->
number, devfn, offset);
406 static int u4_pcie_write_config(
struct pci_bus *bus,
unsigned int devfn,
407 int offset,
int len,
u32 val)
412 hose = pci_bus_to_host(bus);
415 if (offset >= 0x1000)
417 addr = u4_pcie_cfg_access(hose, bus->
number, devfn, offset);
438 static struct pci_ops u4_pcie_pci_ops =
440 .read = u4_pcie_read_config,
441 .write = u4_pcie_write_config,
457 hose->
ops = &u3_agp_pci_ops;
458 hose->cfg_addr =
ioremap(0xf0000000 + 0x800000, 0x1000);
459 hose->cfg_data =
ioremap(0xf0000000 + 0xc00000, 0x1000);
469 hose->
ops = &u4_pcie_pci_ops;
470 hose->cfg_addr =
ioremap(0xf0000000 + 0x800000, 0x1000);
471 hose->cfg_data =
ioremap(0xf0000000 + 0xc00000, 0x1000);
478 hose->
ops = &u3_ht_pci_ops;
484 hose->cfg_data =
ioremap(0xf2000000, 0x02000000);
485 hose->cfg_addr =
ioremap(0xf8070000, 0x1000);
498 const int *bus_range;
504 if (bus_range ==
NULL || len < 2 *
sizeof(
int)) {
513 hose->
last_busno = bus_range ? bus_range[1] : 0xff;
518 disp_name =
"U3-AGP";
526 disp_name =
"U4-PCIE";
529 printk(
KERN_INFO "Found %s PCI host bridge. Firmware bus number: %d->%d\n",
537 fixup_bus_range(dev);
548 DBG(
" -> maple_pci_irq_fixup\n");
551 if (u4_pcie !=
NULL && dev->
bus->number == 0 &&
552 pci_bus_to_host(dev->
bus) == u4_pcie) {
564 (dev->
class & 5) != 5) {
568 DBG(
" <- maple_pci_irq_fixup\n");
583 printk(
KERN_CRIT "maple_find_bridges: can't find root of device tree\n");
593 maple_add_bridge(np) == 0)
605 if (ht && maple_add_bridge(ht) != 0)
617 PCI_DN(np)->busno = 0xf0;
619 PCI_DN(np)->busno = 0xf0;
623 pci_add_flags(PCI_PROBE_ONLY);
629 unsigned int defirq = channel ? 15 : 14;
636 np = pci_device_to_OF_node(pdev);
638 printk(
"Failed to locate OF node for IDE %s\n",
644 printk(
"Failed to map onboard IDE interrupt for channel %d\n",
657 if (machine_is(maple)) {