1
2
3
4
5
6
7
8
9
10
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>
19#include <linux/irq.h>
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>
27#include <asm/grackle.h>
28#include <asm/ppc-pci.h>
29
30#undef DEBUG
31
32#ifdef DEBUG
33#define DBG(x...) printk(x)
34#else
35#define DBG(x...)
36#endif
37
38
39
40static int has_uninorth;
41#ifdef CONFIG_PPC64
42static struct pci_controller *u3_agp;
43#else
44static int has_second_ohare;
45#endif
46
47extern int pcibios_assign_bus_offset;
48
49struct device_node *k2_skiplist[2];
50
51
52
53
54#define BANDIT_DEVID_2 8
55#define BANDIT_REVID 3
56
57#define BANDIT_DEVNUM 11
58#define BANDIT_MAGIC 0x50
59#define BANDIT_COHERENT 0x40
60
61static int __init fixup_one_level_bus_range(struct device_node *node, int higher)
62{
63 for (; node != 0;node = node->sibling) {
64 const int * bus_range;
65 const unsigned int *class_code;
66 int len;
67
68
69 class_code = of_get_property(node, "class-code", NULL);
70 if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
71 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
72 continue;
73 bus_range = of_get_property(node, "bus-range", &len);
74 if (bus_range != NULL && len > 2 * sizeof(int)) {
75 if (bus_range[1] > higher)
76 higher = bus_range[1];
77 }
78 higher = fixup_one_level_bus_range(node->child, higher);
79 }
80 return higher;
81}
82
83
84
85
86
87
88
89static void __init fixup_bus_range(struct device_node *bridge)
90{
91 int *bus_range, len;
92 struct property *prop;
93
94
95 prop = of_find_property(bridge, "bus-range", &len);
96 if (prop == NULL || prop->length < 2 * sizeof(int))
97 return;
98
99 bus_range = prop->value;
100 bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);
101}
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125#define MACRISC_CFA0(devfn, off) \
126 ((1 << (unsigned int)PCI_SLOT(dev_fn)) \
127 | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
128 | (((unsigned int)(off)) & 0xFCUL))
129
130#define MACRISC_CFA1(bus, devfn, off) \
131 ((((unsigned int)(bus)) << 16) \
132 |(((unsigned int)(devfn)) << 8) \
133 |(((unsigned int)(off)) & 0xFCUL) \
134 |1UL)
135
136static volatile void __iomem *macrisc_cfg_access(struct pci_controller* hose,
137 u8 bus, u8 dev_fn, u8 offset)
138{
139 unsigned int caddr;
140
141 if (bus == hose->first_busno) {
142 if (dev_fn < (11 << 3))
143 return NULL;
144 caddr = MACRISC_CFA0(dev_fn, offset);
145 } else
146 caddr = MACRISC_CFA1(bus, dev_fn, offset);
147
148
149 do {
150 out_le32(hose->cfg_addr, caddr);
151 } while (in_le32(hose->cfg_addr) != caddr);
152
153 offset &= has_uninorth ? 0x07 : 0x03;
154 return hose->cfg_data + offset;
155}
156
157static int macrisc_read_config(struct pci_bus *bus, unsigned int devfn,
158 int offset, int len, u32 *val)
159{
160 struct pci_controller *hose;
161 volatile void __iomem *addr;
162
163 hose = pci_bus_to_host(bus);
164 if (hose == NULL)
165 return PCIBIOS_DEVICE_NOT_FOUND;
166 if (offset >= 0x100)
167 return PCIBIOS_BAD_REGISTER_NUMBER;
168 addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
169 if (!addr)
170 return PCIBIOS_DEVICE_NOT_FOUND;
171
172
173
174
175 switch (len) {
176 case 1:
177 *val = in_8(addr);
178 break;
179 case 2:
180 *val = in_le16(addr);
181 break;
182 default:
183 *val = in_le32(addr);
184 break;
185 }
186 return PCIBIOS_SUCCESSFUL;
187}
188
189static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn,
190 int offset, int len, u32 val)
191{
192 struct pci_controller *hose;
193 volatile void __iomem *addr;
194
195 hose = pci_bus_to_host(bus);
196 if (hose == NULL)
197 return PCIBIOS_DEVICE_NOT_FOUND;
198 if (offset >= 0x100)
199 return PCIBIOS_BAD_REGISTER_NUMBER;
200 addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
201 if (!addr)
202 return PCIBIOS_DEVICE_NOT_FOUND;
203
204
205
206
207 switch (len) {
208 case 1:
209 out_8(addr, val);
210 break;
211 case 2:
212 out_le16(addr, val);
213 break;
214 default:
215 out_le32(addr, val);
216 break;
217 }
218 return PCIBIOS_SUCCESSFUL;
219}
220
221static struct pci_ops macrisc_pci_ops =
222{
223 .read = macrisc_read_config,
224 .write = macrisc_write_config,
225};
226
227#ifdef CONFIG_PPC32
228
229
230
231static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset)
232{
233 struct device_node *np;
234 const u32 *vendor, *device;
235
236 if (offset >= 0x100)
237 return PCIBIOS_BAD_REGISTER_NUMBER;
238 np = pci_busdev_to_OF_node(bus, devfn);
239 if (np == NULL)
240 return PCIBIOS_DEVICE_NOT_FOUND;
241
242 vendor = of_get_property(np, "vendor-id", NULL);
243 device = of_get_property(np, "device-id", NULL);
244 if (vendor == NULL || device == NULL)
245 return PCIBIOS_DEVICE_NOT_FOUND;
246
247 if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10)
248 && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24))
249 return PCIBIOS_BAD_REGISTER_NUMBER;
250
251 return PCIBIOS_SUCCESSFUL;
252}
253
254static int
255chaos_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
256 int len, u32 *val)
257{
258 int result = chaos_validate_dev(bus, devfn, offset);
259 if (result == PCIBIOS_BAD_REGISTER_NUMBER)
260 *val = ~0U;
261 if (result != PCIBIOS_SUCCESSFUL)
262 return result;
263 return macrisc_read_config(bus, devfn, offset, len, val);
264}
265
266static int
267chaos_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
268 int len, u32 val)
269{
270 int result = chaos_validate_dev(bus, devfn, offset);
271 if (result != PCIBIOS_SUCCESSFUL)
272 return result;
273 return macrisc_write_config(bus, devfn, offset, len, val);
274}
275
276static struct pci_ops chaos_pci_ops =
277{
278 .read = chaos_read_config,
279 .write = chaos_write_config,
280};
281
282static void __init setup_chaos(struct pci_controller *hose,
283 struct resource *addr)
284{
285
286 hose->ops = &chaos_pci_ops;
287 hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
288 hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
289}
290#endif
291
292#ifdef CONFIG_PPC64
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307static int u3_ht_skip_device(struct pci_controller *hose,
308 struct pci_bus *bus, unsigned int devfn)
309{
310 struct device_node *busdn, *dn;
311 int i;
312
313
314
315
316
317
318 if (bus->self)
319 busdn = pci_device_to_OF_node(bus->self);
320 else if (devfn == 0)
321 return 0;
322 else
323 busdn = hose->dn;
324 for (dn = busdn->child; dn; dn = dn->sibling)
325 if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn)
326 break;
327 if (dn == NULL)
328 return -1;
329
330
331
332
333
334 for (i=0; i<2; i++)
335 if (k2_skiplist[i] == dn)
336 return 1;
337
338 return 0;
339}
340
341#define U3_HT_CFA0(devfn, off) \
342 ((((unsigned int)devfn) << 8) | offset)
343#define U3_HT_CFA1(bus, devfn, off) \
344 (U3_HT_CFA0(devfn, off) \
345 + (((unsigned int)bus) << 16) \
346 + 0x01000000UL)
347
348static void __iomem *u3_ht_cfg_access(struct pci_controller *hose, u8 bus,
349 u8 devfn, u8 offset, int *swap)
350{
351 *swap = 1;
352 if (bus == hose->first_busno) {
353 if (devfn != 0)
354 return hose->cfg_data + U3_HT_CFA0(devfn, offset);
355 *swap = 0;
356 return ((void __iomem *)hose->cfg_addr) + (offset << 2);
357 } else
358 return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);
359}
360
361static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn,
362 int offset, int len, u32 *val)
363{
364 struct pci_controller *hose;
365 void __iomem *addr;
366 int swap;
367
368 hose = pci_bus_to_host(bus);
369 if (hose == NULL)
370 return PCIBIOS_DEVICE_NOT_FOUND;
371 if (offset >= 0x100)
372 return PCIBIOS_BAD_REGISTER_NUMBER;
373 addr = u3_ht_cfg_access(hose, bus->number, devfn, offset, &swap);
374 if (!addr)
375 return PCIBIOS_DEVICE_NOT_FOUND;
376
377 switch (u3_ht_skip_device(hose, bus, devfn)) {
378 case 0:
379 break;
380 case 1:
381 switch (len) {
382 case 1:
383 *val = 0xff; break;
384 case 2:
385 *val = 0xffff; break;
386 default:
387 *val = 0xfffffffful; break;
388 }
389 return PCIBIOS_SUCCESSFUL;
390 default:
391 return PCIBIOS_DEVICE_NOT_FOUND;
392 }
393
394
395
396
397
398 switch (len) {
399 case 1:
400 *val = in_8(addr);
401 break;
402 case 2:
403 *val = swap ? in_le16(addr) : in_be16(addr);
404 break;
405 default:
406 *val = swap ? in_le32(addr) : in_be32(addr);
407 break;
408 }
409 return PCIBIOS_SUCCESSFUL;
410}
411
412static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
413 int offset, int len, u32 val)
414{
415 struct pci_controller *hose;
416 void __iomem *addr;
417 int swap;
418
419 hose = pci_bus_to_host(bus);
420 if (hose == NULL)
421 return PCIBIOS_DEVICE_NOT_FOUND;
422 if (offset >= 0x100)
423 return PCIBIOS_BAD_REGISTER_NUMBER;
424 addr = u3_ht_cfg_access(hose, bus->number, devfn, offset, &swap);
425 if (!addr)
426 return PCIBIOS_DEVICE_NOT_FOUND;
427
428 switch (u3_ht_skip_device(hose, bus, devfn)) {
429 case 0:
430 break;
431 case 1:
432 return PCIBIOS_SUCCESSFUL;
433 default:
434 return PCIBIOS_DEVICE_NOT_FOUND;
435 }
436
437
438
439
440
441 switch (len) {
442 case 1:
443 out_8(addr, val);
444 break;
445 case 2:
446 swap ? out_le16(addr, val) : out_be16(addr, val);
447 break;
448 default:
449 swap ? out_le32(addr, val) : out_be32(addr, val);
450 break;
451 }
452 return PCIBIOS_SUCCESSFUL;
453}
454
455static struct pci_ops u3_ht_pci_ops =
456{
457 .read = u3_ht_read_config,
458 .write = u3_ht_write_config,
459};
460
461#define U4_PCIE_CFA0(devfn, off) \
462 ((1 << ((unsigned int)PCI_SLOT(dev_fn))) \
463 | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
464 | ((((unsigned int)(off)) >> 8) << 28) \
465 | (((unsigned int)(off)) & 0xfcU))
466
467#define U4_PCIE_CFA1(bus, devfn, off) \
468 ((((unsigned int)(bus)) << 16) \
469 |(((unsigned int)(devfn)) << 8) \
470 | ((((unsigned int)(off)) >> 8) << 28) \
471 |(((unsigned int)(off)) & 0xfcU) \
472 |1UL)
473
474static volatile void __iomem *u4_pcie_cfg_access(struct pci_controller* hose,
475 u8 bus, u8 dev_fn, int offset)
476{
477 unsigned int caddr;
478
479 if (bus == hose->first_busno) {
480 caddr = U4_PCIE_CFA0(dev_fn, offset);
481 } else
482 caddr = U4_PCIE_CFA1(bus, dev_fn, offset);
483
484
485 do {
486 out_le32(hose->cfg_addr, caddr);
487 } while (in_le32(hose->cfg_addr) != caddr);
488
489 offset &= 0x03;
490 return hose->cfg_data + offset;
491}
492
493static int u4_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
494 int offset, int len, u32 *val)
495{
496 struct pci_controller *hose;
497 volatile void __iomem *addr;
498
499 hose = pci_bus_to_host(bus);
500 if (hose == NULL)
501 return PCIBIOS_DEVICE_NOT_FOUND;
502 if (offset >= 0x1000)
503 return PCIBIOS_BAD_REGISTER_NUMBER;
504 addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
505 if (!addr)
506 return PCIBIOS_DEVICE_NOT_FOUND;
507
508
509
510
511 switch (len) {
512 case 1:
513 *val = in_8(addr);
514 break;
515 case 2:
516 *val = in_le16(addr);
517 break;
518 default:
519 *val = in_le32(addr);
520 break;
521 }
522 return PCIBIOS_SUCCESSFUL;
523}
524
525static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
526 int offset, int len, u32 val)
527{
528 struct pci_controller *hose;
529 volatile void __iomem *addr;
530
531 hose = pci_bus_to_host(bus);
532 if (hose == NULL)
533 return PCIBIOS_DEVICE_NOT_FOUND;
534 if (offset >= 0x1000)
535 return PCIBIOS_BAD_REGISTER_NUMBER;
536 addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
537 if (!addr)
538 return PCIBIOS_DEVICE_NOT_FOUND;
539
540
541
542
543 switch (len) {
544 case 1:
545 out_8(addr, val);
546 break;
547 case 2:
548 out_le16(addr, val);
549 break;
550 default:
551 out_le32(addr, val);
552 break;
553 }
554 return PCIBIOS_SUCCESSFUL;
555}
556
557static struct pci_ops u4_pcie_pci_ops =
558{
559 .read = u4_pcie_read_config,
560 .write = u4_pcie_write_config,
561};
562
563#endif
564
565#ifdef CONFIG_PPC32
566
567
568
569
570static void __init init_bandit(struct pci_controller *bp)
571{
572 unsigned int vendev, magic;
573 int rev;
574
575
576 out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + PCI_VENDOR_ID);
577 udelay(2);
578 vendev = in_le32(bp->cfg_data);
579 if (vendev == (PCI_DEVICE_ID_APPLE_BANDIT << 16) +
580 PCI_VENDOR_ID_APPLE) {
581
582 out_le32(bp->cfg_addr,
583 (1UL << BANDIT_DEVNUM) + PCI_REVISION_ID);
584 udelay(2);
585 rev = in_8(bp->cfg_data);
586 if (rev != BANDIT_REVID)
587 printk(KERN_WARNING
588 "Unknown revision %d for bandit\n", rev);
589 } else if (vendev != (BANDIT_DEVID_2 << 16) + PCI_VENDOR_ID_APPLE) {
590 printk(KERN_WARNING "bandit isn't? (%x)\n", vendev);
591 return;
592 }
593
594
595 out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + BANDIT_MAGIC);
596 udelay(2);
597 magic = in_le32(bp->cfg_data);
598 if ((magic & BANDIT_COHERENT) != 0)
599 return;
600 magic |= BANDIT_COHERENT;
601 udelay(2);
602 out_le32(bp->cfg_data, magic);
603 printk(KERN_INFO "Cache coherency enabled for bandit/PSX\n");
604}
605
606
607
608
609static void __init init_p2pbridge(void)
610{
611 struct device_node *p2pbridge;
612 struct pci_controller* hose;
613 u8 bus, devfn;
614 u16 val;
615
616
617
618 p2pbridge = of_find_node_by_name(NULL, "pci-bridge");
619 if (p2pbridge == NULL
620 || p2pbridge->parent == NULL
621 || strcmp(p2pbridge->parent->name, "pci") != 0)
622 goto done;
623 if (pci_device_from_OF_node(p2pbridge, &bus, &devfn) < 0) {
624 DBG("Can't find PCI infos for PCI<->PCI bridge\n");
625 goto done;
626 }
627
628
629
630 hose = pci_find_hose_for_OF_device(p2pbridge);
631 if (!hose) {
632 DBG("Can't find hose for PCI<->PCI bridge\n");
633 goto done;
634 }
635 if (early_read_config_word(hose, bus, devfn,
636 PCI_BRIDGE_CONTROL, &val) < 0) {
637 printk(KERN_ERR "init_p2pbridge: couldn't read bridge"
638 " control\n");
639 goto done;
640 }
641 val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
642 early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val);
643done:
644 of_node_put(p2pbridge);
645}
646
647static void __init init_second_ohare(void)
648{
649 struct device_node *np = of_find_node_by_name(NULL, "pci106b,7");
650 unsigned char bus, devfn;
651 unsigned short cmd;
652
653 if (np == NULL)
654 return;
655
656
657
658
659 if (pci_device_from_OF_node(np, &bus, &devfn) == 0) {
660 struct pci_controller* hose =
661 pci_find_hose_for_OF_device(np);
662 if (!hose) {
663 printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
664 return;
665 }
666 early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
667 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
668 cmd &= ~PCI_COMMAND_IO;
669 early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
670 }
671 has_second_ohare = 1;
672}
673
674
675
676
677
678
679
680static void __init fixup_nec_usb2(void)
681{
682 struct device_node *nec;
683
684 for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) {
685 struct pci_controller *hose;
686 u32 data;
687 const u32 *prop;
688 u8 bus, devfn;
689
690 prop = of_get_property(nec, "vendor-id", NULL);
691 if (prop == NULL)
692 continue;
693 if (0x1033 != *prop)
694 continue;
695 prop = of_get_property(nec, "device-id", NULL);
696 if (prop == NULL)
697 continue;
698 if (0x0035 != *prop)
699 continue;
700 prop = of_get_property(nec, "reg", NULL);
701 if (prop == NULL)
702 continue;
703 devfn = (prop[0] >> 8) & 0xff;
704 bus = (prop[0] >> 16) & 0xff;
705 if (PCI_FUNC(devfn) != 0)
706 continue;
707 hose = pci_find_hose_for_OF_device(nec);
708 if (!hose)
709 continue;
710 early_read_config_dword(hose, bus, devfn, 0xe4, &data);
711 if (data & 1UL) {
712 printk("Found NEC PD720100A USB2 chip with disabled"
713 " EHCI, fixing up...\n");
714 data &= ~1UL;
715 early_write_config_dword(hose, bus, devfn, 0xe4, data);
716 }
717 }
718}
719
720static void __init setup_bandit(struct pci_controller *hose,
721 struct resource *addr)
722{
723 hose->ops = ¯isc_pci_ops;
724 hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
725 hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
726 init_bandit(hose);
727}
728
729static int __init setup_uninorth(struct pci_controller *hose,
730 struct resource *addr)
731{
732 ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
733 has_uninorth = 1;
734 hose->ops = ¯isc_pci_ops;
735 hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
736 hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
737
738 return addr->start == 0xf2000000;
739}
740#endif
741
742#ifdef CONFIG_PPC64
743static void __init setup_u3_agp(struct pci_controller* hose)
744{
745
746
747
748
749
750
751
752
753
754 hose->first_busno = 0xf0;
755 hose->last_busno = 0xff;
756 has_uninorth = 1;
757 hose->ops = ¯isc_pci_ops;
758 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
759 hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
760 u3_agp = hose;
761}
762
763static void __init setup_u4_pcie(struct pci_controller* hose)
764{
765
766
767
768 hose->ops = &u4_pcie_pci_ops;
769 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
770 hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
771
772
773
774
775
776
777
778 hose->first_busno = 0x00;
779 hose->last_busno = 0xff;
780}
781
782static void __init parse_region_decode(struct pci_controller *hose,
783 u32 decode)
784{
785 unsigned long base, end, next = -1;
786 int i, cur = -1;
787
788
789
790
791 for (i = 0; i < 31; i++) {
792 if ((decode & (0x80000000 >> i)) == 0)
793 continue;
794 if (i < 16) {
795 base = 0xf0000000 | (((u32)i) << 24);
796 end = base + 0x00ffffff;
797 } else {
798 base = ((u32)i-16) << 28;
799 end = base + 0x0fffffff;
800 }
801 if (base != next) {
802 if (++cur >= 3) {
803 printk(KERN_WARNING "PCI: Too many ranges !\n");
804 break;
805 }
806 hose->mem_resources[cur].flags = IORESOURCE_MEM;
807 hose->mem_resources[cur].name = hose->dn->full_name;
808 hose->mem_resources[cur].start = base;
809 hose->mem_resources[cur].end = end;
810 DBG(" %d: 0x%08lx-0x%08lx\n", cur, base, end);
811 } else {
812 DBG(" : -0x%08lx\n", end);
813 hose->mem_resources[cur].end = end;
814 }
815 next = end + 1;
816 }
817}
818
819static void __init setup_u3_ht(struct pci_controller* hose)
820{
821 struct device_node *np = hose->dn;
822 struct resource cfg_res, self_res;
823 u32 decode;
824
825 hose->ops = &u3_ht_pci_ops;
826
827
828
829 if (of_address_to_resource(np, 0, &cfg_res) ||
830 of_address_to_resource(np, 1, &self_res)) {
831 printk(KERN_ERR "PCI: Failed to get U3/U4 HT resources !\n");
832 return;
833 }
834
835
836
837
838 hose->cfg_data = ioremap(cfg_res.start, 0x02000000);
839 hose->cfg_addr = ioremap(self_res.start,
840 self_res.end - self_res.start + 1);
841
842
843
844
845
846
847 hose->io_base_phys = 0xf4000000;
848 hose->pci_io_size = 0x00400000;
849 hose->io_resource.name = np->full_name;
850 hose->io_resource.start = 0;
851 hose->io_resource.end = 0x003fffff;
852 hose->io_resource.flags = IORESOURCE_IO;
853 hose->pci_mem_offset = 0;
854 hose->first_busno = 0;
855 hose->last_busno = 0xef;
856
857
858 decode = in_be32(hose->cfg_addr + 0x80);
859
860 DBG("PCI: Apple HT bridge decode register: 0x%08x\n", decode);
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879 decode &= 0x003fffff;
880
881
882 parse_region_decode(hose, decode);
883}
884#endif
885
886
887
888
889
890
891static int __init pmac_add_bridge(struct device_node *dev)
892{
893 int len;
894 struct pci_controller *hose;
895 struct resource rsrc;
896 char *disp_name;
897 const int *bus_range;
898 int primary = 1, has_address = 0;
899
900 DBG("Adding PCI host bridge %s\n", dev->full_name);
901
902
903 has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
904
905
906 bus_range = of_get_property(dev, "bus-range", &len);
907 if (bus_range == NULL || len < 2 * sizeof(int)) {
908 printk(KERN_WARNING "Can't get bus-range for %s, assume"
909 " bus 0\n", dev->full_name);
910 }
911
912 hose = pcibios_alloc_controller(dev);
913 if (!hose)
914 return -ENOMEM;
915 hose->first_busno = bus_range ? bus_range[0] : 0;
916 hose->last_busno = bus_range ? bus_range[1] : 0xff;
917
918 disp_name = NULL;
919
920
921#ifdef CONFIG_PPC64
922 if (of_device_is_compatible(dev, "u3-agp")) {
923 setup_u3_agp(hose);
924 disp_name = "U3-AGP";
925 primary = 0;
926 } else if (of_device_is_compatible(dev, "u3-ht")) {
927 setup_u3_ht(hose);
928 disp_name = "U3-HT";
929 primary = 1;
930 } else if (of_device_is_compatible(dev, "u4-pcie")) {
931 setup_u4_pcie(hose);
932 disp_name = "U4-PCIE";
933 primary = 0;
934 }
935 printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number:"
936 " %d->%d\n", disp_name, hose->first_busno, hose->last_busno);
937#endif
938
939
940#ifdef CONFIG_PPC32
941 if (of_device_is_compatible(dev, "uni-north")) {
942 primary = setup_uninorth(hose, &rsrc);
943 disp_name = "UniNorth";
944 } else if (strcmp(dev->name, "pci") == 0) {
945
946 setup_grackle(hose);
947 disp_name = "Grackle (MPC106)";
948 } else if (strcmp(dev->name, "bandit") == 0) {
949 setup_bandit(hose, &rsrc);
950 disp_name = "Bandit";
951 } else if (strcmp(dev->name, "chaos") == 0) {
952 setup_chaos(hose, &rsrc);
953 disp_name = "Chaos";
954 primary = 0;
955 }
956 printk(KERN_INFO "Found %s PCI host bridge at 0x%016llx. "
957 "Firmware bus number: %d->%d\n",
958 disp_name, (unsigned long long)rsrc.start, hose->first_busno,
959 hose->last_busno);
960#endif
961
962 DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
963 hose, hose->cfg_addr, hose->cfg_data);
964
965
966
967 pci_process_bridge_OF_ranges(hose, dev, primary);
968
969
970 fixup_bus_range(dev);
971
972 return 0;
973}
974
975void __devinit pmac_pci_irq_fixup(struct pci_dev *dev)
976{
977#ifdef CONFIG_PPC32
978
979
980
981
982
983
984
985 if (has_second_ohare &&
986 dev->vendor == PCI_VENDOR_ID_DEC &&
987 dev->device == PCI_DEVICE_ID_DEC_TULIP_PLUS) {
988 dev->irq = irq_create_mapping(NULL, 60);
989 set_irq_type(dev->irq, IRQ_TYPE_LEVEL_LOW);
990 }
991#endif
992}
993
994void __init pmac_pci_init(void)
995{
996 struct device_node *np, *root;
997 struct device_node *ht = NULL;
998
999 ppc_pci_flags = PPC_PCI_CAN_SKIP_ISA_ALIGN;
1000
1001 root = of_find_node_by_path("/");
1002 if (root == NULL) {
1003 printk(KERN_CRIT "pmac_pci_init: can't find root "
1004 "of device tree\n");
1005 return;
1006 }
1007 for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
1008 if (np->name == NULL)
1009 continue;
1010 if (strcmp(np->name, "bandit") == 0
1011 || strcmp(np->name, "chaos") == 0
1012 || strcmp(np->name, "pci") == 0) {
1013 if (pmac_add_bridge(np) == 0)
1014 of_node_get(np);
1015 }
1016 if (strcmp(np->name, "ht") == 0) {
1017 of_node_get(np);
1018 ht = np;
1019 }
1020 }
1021 of_node_put(root);
1022
1023#ifdef CONFIG_PPC64
1024
1025
1026
1027 if (ht && pmac_add_bridge(ht) != 0)
1028 of_node_put(ht);
1029
1030
1031 pci_devs_phb_init();
1032
1033
1034
1035
1036
1037
1038 if (u3_agp) {
1039 struct device_node *np = u3_agp->dn;
1040 PCI_DN(np)->busno = 0xf0;
1041 for (np = np->child; np; np = np->sibling)
1042 PCI_DN(np)->busno = 0xf0;
1043 }
1044
1045
1046
1047 pci_probe_only = 0;
1048
1049#else
1050 init_p2pbridge();
1051 init_second_ohare();
1052 fixup_nec_usb2();
1053
1054
1055
1056
1057
1058 if (ppc_pci_flags & PPC_PCI_REASSIGN_ALL_BUS)
1059 pcibios_assign_bus_offset = 0x10;
1060#endif
1061}
1062
1063#ifdef CONFIG_PPC32
1064int pmac_pci_enable_device_hook(struct pci_dev *dev)
1065{
1066 struct device_node* node;
1067 int updatecfg = 0;
1068 int uninorth_child;
1069
1070 node = pci_device_to_OF_node(dev);
1071
1072
1073
1074
1075 if (dev->vendor == PCI_VENDOR_ID_APPLE
1076 && dev->class == PCI_CLASS_SERIAL_USB_OHCI
1077 && !node) {
1078 printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",
1079 pci_name(dev));
1080 return -EINVAL;
1081 }
1082
1083 if (!node)
1084 return 0;
1085
1086 uninorth_child = node->parent &&
1087 of_device_is_compatible(node->parent, "uni-north");
1088
1089
1090
1091
1092 if (uninorth_child && !strcmp(node->name, "firewire") &&
1093 (of_device_is_compatible(node, "pci106b,18") ||
1094 of_device_is_compatible(node, "pci106b,30") ||
1095 of_device_is_compatible(node, "pci11c1,5811"))) {
1096 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
1097 pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
1098 updatecfg = 1;
1099 }
1100 if (uninorth_child && !strcmp(node->name, "ethernet") &&
1101 of_device_is_compatible(node, "gmac")) {
1102 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
1103 updatecfg = 1;
1104 }
1105
1106
1107
1108
1109
1110
1111
1112 if (updatecfg) {
1113 u16 cmd;
1114
1115 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1116 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
1117 | PCI_COMMAND_INVALIDATE;
1118 pci_write_config_word(dev, PCI_COMMAND, cmd);
1119 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);
1120
1121 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
1122 L1_CACHE_BYTES >> 2);
1123 }
1124
1125 return 0;
1126}
1127
1128void __devinit pmac_pci_fixup_ohci(struct pci_dev *dev)
1129{
1130 struct device_node *node = pci_device_to_OF_node(dev);
1131
1132
1133
1134
1135 if (dev->class == PCI_CLASS_SERIAL_USB_OHCI && !node)
1136 dev->resource[0].flags = 0;
1137}
1138DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, PCI_ANY_ID, pmac_pci_fixup_ohci);
1139
1140
1141
1142
1143void __init pmac_pcibios_after_init(void)
1144{
1145 struct device_node* nd;
1146
1147 for_each_node_by_name(nd, "firewire") {
1148 if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") ||
1149 of_device_is_compatible(nd, "pci106b,30") ||
1150 of_device_is_compatible(nd, "pci11c1,5811"))
1151 && of_device_is_compatible(nd->parent, "uni-north")) {
1152 pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
1153 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
1154 }
1155 }
1156 of_node_put(nd);
1157 for_each_node_by_name(nd, "ethernet") {
1158 if (nd->parent && of_device_is_compatible(nd, "gmac")
1159 && of_device_is_compatible(nd->parent, "uni-north"))
1160 pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
1161 }
1162 of_node_put(nd);
1163}
1164
1165void pmac_pci_fixup_cardbus(struct pci_dev* dev)
1166{
1167 if (!machine_is(powermac))
1168 return;
1169
1170
1171
1172
1173 if (dev->vendor != PCI_VENDOR_ID_TI)
1174 return;
1175 if (dev->device == PCI_DEVICE_ID_TI_1130 ||
1176 dev->device == PCI_DEVICE_ID_TI_1131) {
1177 u8 val;
1178
1179 if (pci_read_config_byte(dev, 0x91, &val) == 0)
1180 pci_write_config_byte(dev, 0x91, val | 0x30);
1181
1182 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1183 pci_write_config_byte(dev, 0x92, val & ~0x06);
1184 }
1185 if (dev->device == PCI_DEVICE_ID_TI_1210 ||
1186 dev->device == PCI_DEVICE_ID_TI_1211 ||
1187 dev->device == PCI_DEVICE_ID_TI_1410 ||
1188 dev->device == PCI_DEVICE_ID_TI_1510) {
1189 u8 val;
1190
1191
1192 if (pci_read_config_byte(dev, 0x8c, &val) == 0)
1193 pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
1194
1195 if (pci_read_config_byte(dev, 0x92, &val) == 0)
1196 pci_write_config_byte(dev, 0x92, val & ~0x06);
1197 }
1198}
1199
1200DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);
1201
1202void pmac_pci_fixup_pciata(struct pci_dev* dev)
1203{
1204 u8 progif = 0;
1205
1206
1207
1208
1209
1210 if (!machine_is(powermac))
1211 return;
1212
1213
1214 if (dev->vendor == PCI_VENDOR_ID_PROMISE)
1215 switch(dev->device) {
1216 case PCI_DEVICE_ID_PROMISE_20246:
1217 case PCI_DEVICE_ID_PROMISE_20262:
1218 case PCI_DEVICE_ID_PROMISE_20263:
1219 case PCI_DEVICE_ID_PROMISE_20265:
1220 case PCI_DEVICE_ID_PROMISE_20267:
1221 case PCI_DEVICE_ID_PROMISE_20268:
1222 case PCI_DEVICE_ID_PROMISE_20269:
1223 case PCI_DEVICE_ID_PROMISE_20270:
1224 case PCI_DEVICE_ID_PROMISE_20271:
1225 case PCI_DEVICE_ID_PROMISE_20275:
1226 case PCI_DEVICE_ID_PROMISE_20276:
1227 case PCI_DEVICE_ID_PROMISE_20277:
1228 goto good;
1229 }
1230
1231 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
1232 return;
1233 good:
1234 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
1235 if ((progif & 5) != 5) {
1236 printk(KERN_INFO "PCI: %s Forcing PCI IDE into native mode\n",
1237 pci_name(dev));
1238 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
1239 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
1240 (progif & 5) != 5)
1241 printk(KERN_ERR "Rewrite of PROGIF failed !\n");
1242 else {
1243
1244 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);
1245 pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);
1246 pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, 0);
1247 pci_write_config_dword(dev, PCI_BASE_ADDRESS_3, 0);
1248 }
1249 }
1250}
1251DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);
1252#endif
1253
1254
1255
1256
1257
1258static void fixup_k2_sata(struct pci_dev* dev)
1259{
1260 int i;
1261 u16 cmd;
1262
1263 if (PCI_FUNC(dev->devfn) > 0) {
1264 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1265 cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
1266 pci_write_config_word(dev, PCI_COMMAND, cmd);
1267 for (i = 0; i < 6; i++) {
1268 dev->resource[i].start = dev->resource[i].end = 0;
1269 dev->resource[i].flags = 0;
1270 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
1271 0);
1272 }
1273 } else {
1274 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1275 cmd &= ~PCI_COMMAND_IO;
1276 pci_write_config_word(dev, PCI_COMMAND, cmd);
1277 for (i = 0; i < 5; i++) {
1278 dev->resource[i].start = dev->resource[i].end = 0;
1279 dev->resource[i].flags = 0;
1280 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
1281 0);
1282 }
1283 }
1284}
1285DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata);
1286
1287