13 #include <linux/kernel.h>
14 #include <linux/pci.h>
16 #include <linux/string.h>
22 #include <asm/sections.h>
25 #include <asm/pci-bridge.h>
26 #include <asm/machdep.h>
34 #define DBG(x...) printk(x)
41 static int has_uninorth;
45 static int has_second_ohare;
55 #define BANDIT_DEVID_2 8
56 #define BANDIT_REVID 3
58 #define BANDIT_DEVNUM 11
59 #define BANDIT_MAGIC 0x50
60 #define BANDIT_COHERENT 0x40
64 for (; node != 0;node = node->
sibling) {
65 const int * bus_range;
66 const unsigned int *class_code;
75 if (bus_range !=
NULL && len > 2 *
sizeof(
int)) {
76 if (bus_range[1] > higher)
77 higher = bus_range[1];
79 higher = fixup_one_level_bus_range(node->
child, higher);
97 if (prop ==
NULL || prop->
length < 2 *
sizeof(
int))
100 bus_range = prop->
value;
101 bus_range[1] = fixup_one_level_bus_range(bridge->
child, bus_range[1]);
126 #define MACRISC_CFA0(devfn, off) \
127 ((1 << (unsigned int)PCI_SLOT(dev_fn)) \
128 | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
129 | (((unsigned int)(off)) & 0xFCUL))
131 #define MACRISC_CFA1(bus, devfn, off) \
132 ((((unsigned int)(bus)) << 16) \
133 |(((unsigned int)(devfn)) << 8) \
134 |(((unsigned int)(off)) & 0xFCUL) \
143 if (dev_fn < (11 << 3))
152 }
while (
in_le32(hose->cfg_addr) != caddr);
154 offset &= has_uninorth ? 0x07 : 0x03;
155 return hose->cfg_data +
offset;
158 static int macrisc_read_config(
struct pci_bus *
bus,
unsigned int devfn,
164 hose = pci_bus_to_host(bus);
169 addr = macrisc_cfg_access(hose, bus->
number, devfn, offset);
190 static int macrisc_write_config(
struct pci_bus *bus,
unsigned int devfn,
191 int offset,
int len,
u32 val)
196 hose = pci_bus_to_host(bus);
201 addr = macrisc_cfg_access(hose, bus->
number, devfn, offset);
222 static struct pci_ops macrisc_pci_ops =
224 .read = macrisc_read_config,
225 .write = macrisc_write_config,
232 static int chaos_validate_dev(
struct pci_bus *bus,
int devfn,
int offset)
245 if (vendor ==
NULL || device ==
NULL)
248 if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10)
249 && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24))
256 chaos_read_config(
struct pci_bus *bus,
unsigned int devfn,
int offset,
259 int result = chaos_validate_dev(bus, devfn, offset);
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);
274 return macrisc_write_config(bus, devfn, offset, len, val);
277 static struct pci_ops chaos_pci_ops =
279 .
read = chaos_read_config,
280 .write = chaos_write_config,
287 hose->
ops = &chaos_pci_ops;
288 hose->cfg_addr =
ioremap(addr->
start + 0x800000, 0x1000);
289 hose->cfg_data =
ioremap(addr->
start + 0xc00000, 0x1000);
309 struct pci_bus *bus,
unsigned int devfn)
320 busdn = pci_device_to_OF_node(bus->
self);
326 if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn)
336 if (k2_skiplist[i] == dn)
342 #define U3_HT_CFA0(devfn, off) \
343 ((((unsigned int)devfn) << 8) | offset)
344 #define U3_HT_CFA1(bus, devfn, off) \
345 (U3_HT_CFA0(devfn, off) \
346 + (((unsigned int)bus) << 16) \
355 return hose->cfg_data + U3_HT_CFA0(devfn, offset);
357 return ((
void __iomem *)hose->cfg_addr) + (offset << 2);
359 return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);
362 static int u3_ht_read_config(
struct pci_bus *bus,
unsigned int devfn,
363 int offset,
int len,
u32 *val)
369 hose = pci_bus_to_host(bus);
374 addr = u3_ht_cfg_access(hose, bus->
number, devfn, offset, &swap);
378 switch (u3_ht_skip_device(hose, bus, devfn)) {
386 *val = 0xffff;
break;
388 *val = 0xfffffffful;
break;
413 static int u3_ht_write_config(
struct pci_bus *bus,
unsigned int devfn,
414 int offset,
int len,
u32 val)
420 hose = pci_bus_to_host(bus);
425 addr = u3_ht_cfg_access(hose, bus->
number, devfn, offset, &swap);
429 switch (u3_ht_skip_device(hose, bus, devfn)) {
456 static struct pci_ops u3_ht_pci_ops =
458 .
read = u3_ht_read_config,
459 .write = u3_ht_write_config,
462 #define U4_PCIE_CFA0(devfn, off) \
463 ((1 << ((unsigned int)PCI_SLOT(dev_fn))) \
464 | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
465 | ((((unsigned int)(off)) >> 8) << 28) \
466 | (((unsigned int)(off)) & 0xfcU))
468 #define U4_PCIE_CFA1(bus, devfn, off) \
469 ((((unsigned int)(bus)) << 16) \
470 |(((unsigned int)(devfn)) << 8) \
471 | ((((unsigned int)(off)) >> 8) << 28) \
472 |(((unsigned int)(off)) & 0xfcU) \
476 u8 bus,
u8 dev_fn,
int offset)
481 caddr = U4_PCIE_CFA0(dev_fn, offset);
483 caddr = U4_PCIE_CFA1(bus, dev_fn, offset);
488 }
while (
in_le32(hose->cfg_addr) != caddr);
491 return hose->cfg_data +
offset;
494 static int u4_pcie_read_config(
struct pci_bus *bus,
unsigned int devfn,
495 int offset,
int len,
u32 *val)
500 hose = pci_bus_to_host(bus);
503 if (offset >= 0x1000)
505 addr = u4_pcie_cfg_access(hose, bus->
number, devfn, offset);
526 static int u4_pcie_write_config(
struct pci_bus *bus,
unsigned int devfn,
527 int offset,
int len,
u32 val)
532 hose = pci_bus_to_host(bus);
535 if (offset >= 0x1000)
537 addr = u4_pcie_cfg_access(hose, bus->
number, devfn, offset);
558 static struct pci_ops u4_pcie_pci_ops =
560 .
read = u4_pcie_read_config,
561 .write = u4_pcie_write_config,
587 unsigned int vendev,
magic;
593 vendev =
in_le32(bp->cfg_data);
600 rev =
in_8(bp->cfg_data);
603 "Unknown revision %d for bandit\n", rev);
624 static void __init init_p2pbridge(
void)
634 if (p2pbridge ==
NULL
639 DBG(
"Can't find PCI infos for PCI<->PCI bridge\n");
647 DBG(
"Can't find hose for PCI<->PCI bridge\n");
650 if (early_read_config_word(hose, bus, devfn,
659 of_node_put(p2pbridge);
662 static void __init init_second_ohare(
void)
682 early_read_config_word(hose, bus, devfn,
PCI_COMMAND, &cmd);
685 early_write_config_word(hose, bus, devfn,
PCI_COMMAND, cmd);
687 has_second_ohare = 1;
697 static void __init fixup_nec_usb2(
void)
720 devfn = (prop[0] >> 8) & 0xff;
721 bus = (prop[0] >> 16) & 0xff;
727 early_read_config_dword(hose, bus, devfn, 0xe4, &data);
729 printk(
"Found NEC PD720100A USB2 chip with disabled"
730 " EHCI, fixing up...\n");
732 early_write_config_dword(hose, bus, devfn, 0xe4, data);
740 hose->
ops = ¯isc_pci_ops;
741 hose->cfg_addr =
ioremap(addr->
start + 0x800000, 0x1000);
742 hose->cfg_data =
ioremap(addr->
start + 0xc00000, 0x1000);
749 pci_add_flags(PCI_REASSIGN_ALL_BUS);
751 hose->
ops = ¯isc_pci_ops;
752 hose->cfg_addr =
ioremap(addr->
start + 0x800000, 0x1000);
753 hose->cfg_data =
ioremap(addr->
start + 0xc00000, 0x1000);
755 return addr->
start == 0xf2000000;
774 hose->
ops = ¯isc_pci_ops;
775 hose->cfg_addr =
ioremap(0xf0000000 + 0x800000, 0x1000);
776 hose->cfg_data =
ioremap(0xf0000000 + 0xc00000, 0x1000);
785 hose->
ops = &u4_pcie_pci_ops;
786 hose->cfg_addr =
ioremap(0xf0000000 + 0x800000, 0x1000);
787 hose->cfg_data =
ioremap(0xf0000000 + 0xc00000, 0x1000);
808 for (i = 0; i < 31; i++) {
809 if ((decode & (0x80000000 >> i)) == 0)
812 base = 0xf0000000 | (((
u32)i) << 24);
813 end = base + 0x00ffffff;
815 base = ((
u32)i-16) << 28;
816 end = base + 0x0fffffff;
827 DBG(
" %d: 0x%08lx-0x%08lx\n", cur, base, end);
829 DBG(
" : -0x%08lx\n", end);
842 hose->
ops = &u3_ht_pci_ops;
855 hose->cfg_data =
ioremap(cfg_res.start, 0x02000000);
856 hose->cfg_addr =
ioremap(self_res.start, resource_size(&self_res));
863 hose->io_base_phys = 0xf4000000;
864 hose->pci_io_size = 0x00400000;
866 hose->io_resource.start = 0;
867 hose->io_resource.end = 0x003fffff;
869 hose->pci_mem_offset = 0;
874 decode =
in_be32(hose->cfg_addr + 0x80);
876 DBG(
"PCI: Apple HT bridge decode register: 0x%08x\n", decode);
895 decode &= 0x003fffff;
898 parse_region_decode(hose, decode);
913 const int *bus_range;
914 int primary = 1, has_address = 0;
923 if (bus_range ==
NULL || len < 2 *
sizeof(
int)) {
932 hose->
last_busno = bus_range ? bus_range[1] : 0xff;
940 disp_name =
"U3-AGP";
948 disp_name =
"U4-PCIE";
958 primary = setup_uninorth(hose, &rsrc);
959 disp_name =
"UniNorth";
963 disp_name =
"Grackle (MPC106)";
964 }
else if (
strcmp(dev->
name,
"bandit") == 0) {
965 setup_bandit(hose, &rsrc);
966 disp_name =
"Bandit";
968 setup_chaos(hose, &rsrc);
973 "Firmware bus number: %d->%d\n",
974 disp_name, (
unsigned long long)rsrc.start, hose->
first_busno,
978 DBG(
" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
979 hose, hose->cfg_addr, hose->cfg_data);
986 fixup_bus_range(dev);
1001 if (has_second_ohare &&
1020 "of device tree\n");
1029 if (pmac_add_bridge(np) == 0)
1043 if (ht && pmac_add_bridge(ht) != 0)
1056 PCI_DN(np)->busno = 0xf0;
1058 PCI_DN(np)->busno = 0xf0;
1064 init_second_ohare();
1071 if (pci_has_flag(PCI_REASSIGN_ALL_BUS))
1083 node = pci_device_to_OF_node(dev);
1099 uninorth_child = node->
parent &&
1105 if (uninorth_child && !
strcmp(node->
name,
"firewire") &&
1109 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
1110 pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
1113 if (uninorth_child && !
strcmp(node->
name,
"ethernet") &&
1115 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
1143 struct device_node *node = pci_device_to_OF_node(dev);
1160 for_each_node_by_name(nd,
"firewire") {
1165 pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
1166 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
1169 for_each_node_by_name(nd,
"ethernet") {
1172 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
1176 void pmac_pci_fixup_cardbus(
struct pci_dev* dev)
1178 if (!machine_is(powermac))
1190 if (pci_read_config_byte(dev, 0x91, &val) == 0)
1191 pci_write_config_byte(dev, 0x91, val | 0x30);
1193 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1194 pci_write_config_byte(dev, 0x92, val & ~0x06);
1203 if (pci_read_config_byte(dev, 0x8c, &val) == 0)
1204 pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
1206 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1207 pci_write_config_byte(dev, 0x92, val & ~0x06);
1213 void pmac_pci_fixup_pciata(
struct pci_dev* dev)
1221 if (!machine_is(powermac))
1246 if ((progif & 5) != 5) {
1269 static void fixup_k2_sata(
struct pci_dev* dev)
1278 for (i = 0; i < 6; i++) {
1288 for (i = 0; i < 5; i++) {
1316 static void fixup_u4_pcie(
struct pci_dev* dev)
1324 if (!machine_is(powermac))
1328 for (i = 0; i < 3; i++) {
1335 if (r->
start >= 0xf0000000 && r->
start < 0xf3000000)
1337 if (!region || resource_size(r) > resource_size(region))
1351 reg = ((region->
start >> 16) & 0xfff0) | (region->
end & 0xfff00000);