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