aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/pci_32.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/kernel/pci_32.c')
-rw-r--r--arch/powerpc/kernel/pci_32.c237
1 files changed, 112 insertions, 125 deletions
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c
index 0d9ff72e2852..2847cd51a2d7 100644
--- a/arch/powerpc/kernel/pci_32.c
+++ b/arch/powerpc/kernel/pci_32.c
@@ -12,6 +12,7 @@
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/bootmem.h> 13#include <linux/bootmem.h>
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/list.h>
15 16
16#include <asm/processor.h> 17#include <asm/processor.h>
17#include <asm/io.h> 18#include <asm/io.h>
@@ -99,7 +100,7 @@ pcibios_fixup_resources(struct pci_dev *dev)
99 continue; 100 continue;
100 if (res->end == 0xffffffff) { 101 if (res->end == 0xffffffff) {
101 DBG("PCI:%s Resource %d [%016llx-%016llx] is unassigned\n", 102 DBG("PCI:%s Resource %d [%016llx-%016llx] is unassigned\n",
102 pci_name(dev), i, res->start, res->end); 103 pci_name(dev), i, (u64)res->start, (u64)res->end);
103 res->end -= res->start; 104 res->end -= res->start;
104 res->start = 0; 105 res->start = 0;
105 res->flags |= IORESOURCE_UNSET; 106 res->flags |= IORESOURCE_UNSET;
@@ -115,11 +116,9 @@ pcibios_fixup_resources(struct pci_dev *dev)
115 if (offset != 0) { 116 if (offset != 0) {
116 res->start += offset; 117 res->start += offset;
117 res->end += offset; 118 res->end += offset;
118#ifdef DEBUG 119 DBG("Fixup res %d (%lx) of dev %s: %llx -> %llx\n",
119 printk("Fixup res %d (%lx) of dev %s: %llx -> %llx\n", 120 i, res->flags, pci_name(dev),
120 i, res->flags, pci_name(dev), 121 (u64)res->start - offset, (u64)res->start);
121 res->start - offset, res->start);
122#endif
123 } 122 }
124 } 123 }
125 124
@@ -255,7 +254,7 @@ pcibios_allocate_bus_resources(struct list_head *bus_list)
255 } 254 }
256 255
257 DBG("PCI: bridge rsrc %llx..%llx (%lx), parent %p\n", 256 DBG("PCI: bridge rsrc %llx..%llx (%lx), parent %p\n",
258 res->start, res->end, res->flags, pr); 257 (u64)res->start, (u64)res->end, res->flags, pr);
259 if (pr) { 258 if (pr) {
260 if (request_resource(pr, res) == 0) 259 if (request_resource(pr, res) == 0)
261 continue; 260 continue;
@@ -306,7 +305,7 @@ reparent_resources(struct resource *parent, struct resource *res)
306 for (p = res->child; p != NULL; p = p->sibling) { 305 for (p = res->child; p != NULL; p = p->sibling) {
307 p->parent = res; 306 p->parent = res;
308 DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n", 307 DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n",
309 p->name, p->start, p->end, res->name); 308 p->name, (u64)p->start, (u64)p->end, res->name);
310 } 309 }
311 return 0; 310 return 0;
312} 311}
@@ -362,7 +361,7 @@ pci_relocate_bridge_resource(struct pci_bus *bus, int i)
362 } 361 }
363 if (request_resource(pr, res)) { 362 if (request_resource(pr, res)) {
364 DBG(KERN_ERR "PCI: huh? couldn't move to %llx..%llx\n", 363 DBG(KERN_ERR "PCI: huh? couldn't move to %llx..%llx\n",
365 res->start, res->end); 364 (u64)res->start, (u64)res->end);
366 return -1; /* "can't happen" */ 365 return -1; /* "can't happen" */
367 } 366 }
368 update_bridge_base(bus, i); 367 update_bridge_base(bus, i);
@@ -480,14 +479,14 @@ static inline void alloc_resource(struct pci_dev *dev, int idx)
480 struct resource *pr, *r = &dev->resource[idx]; 479 struct resource *pr, *r = &dev->resource[idx];
481 480
482 DBG("PCI:%s: Resource %d: %016llx-%016llx (f=%lx)\n", 481 DBG("PCI:%s: Resource %d: %016llx-%016llx (f=%lx)\n",
483 pci_name(dev), idx, r->start, r->end, r->flags); 482 pci_name(dev), idx, (u64)r->start, (u64)r->end, r->flags);
484 pr = pci_find_parent_resource(dev, r); 483 pr = pci_find_parent_resource(dev, r);
485 if (!pr || request_resource(pr, r) < 0) { 484 if (!pr || request_resource(pr, r) < 0) {
486 printk(KERN_ERR "PCI: Cannot allocate resource region %d" 485 printk(KERN_ERR "PCI: Cannot allocate resource region %d"
487 " of device %s\n", idx, pci_name(dev)); 486 " of device %s\n", idx, pci_name(dev));
488 if (pr) 487 if (pr)
489 DBG("PCI: parent is %p: %016llx-%016llx (f=%lx)\n", 488 DBG("PCI: parent is %p: %016llx-%016llx (f=%lx)\n",
490 pr, pr->start, pr->end, pr->flags); 489 pr, (u64)pr->start, (u64)pr->end, pr->flags);
491 /* We'll assign a new address later */ 490 /* We'll assign a new address later */
492 r->flags |= IORESOURCE_UNSET; 491 r->flags |= IORESOURCE_UNSET;
493 r->end -= r->start; 492 r->end -= r->start;
@@ -671,7 +670,7 @@ pcibios_make_OF_bus_map(void)
671 struct pci_controller* hose; 670 struct pci_controller* hose;
672 struct property *map_prop; 671 struct property *map_prop;
673 672
674 pci_to_OF_bus_map = (u8*)kmalloc(pci_bus_count, GFP_KERNEL); 673 pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL);
675 if (!pci_to_OF_bus_map) { 674 if (!pci_to_OF_bus_map) {
676 printk(KERN_ERR "Can't allocate OF bus map !\n"); 675 printk(KERN_ERR "Can't allocate OF bus map !\n");
677 return; 676 return;
@@ -737,25 +736,51 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
737 return NULL; 736 return NULL;
738} 737}
739 738
740static int 739static struct device_node *scan_OF_for_pci_dev(struct device_node *parent,
741scan_OF_pci_childs_iterator(struct device_node* node, void* data) 740 unsigned int devfn)
742{ 741{
743 const unsigned int *reg; 742 struct device_node *np = NULL;
744 u8* fdata = (u8*)data; 743 const u32 *reg;
745 744 unsigned int psize;
746 reg = get_property(node, "reg", NULL); 745
747 if (reg && ((reg[0] >> 8) & 0xff) == fdata[1] 746 while ((np = of_get_next_child(parent, np)) != NULL) {
748 && ((reg[0] >> 16) & 0xff) == fdata[0]) 747 reg = get_property(np, "reg", &psize);
749 return 1; 748 if (reg == NULL || psize < 4)
750 return 0; 749 continue;
750 if (((reg[0] >> 8) & 0xff) == devfn)
751 return np;
752 }
753 return NULL;
751} 754}
752 755
753static struct device_node* 756
754scan_OF_childs_for_device(struct device_node* node, u8 bus, u8 dev_fn) 757static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
755{ 758{
756 u8 filter_data[2] = {bus, dev_fn}; 759 struct device_node *parent, *np;
760
761 /* Are we a root bus ? */
762 if (bus->self == NULL || bus->parent == NULL) {
763 struct pci_controller *hose = pci_bus_to_hose(bus->number);
764 if (hose == NULL)
765 return NULL;
766 return of_node_get(hose->arch_data);
767 }
757 768
758 return scan_OF_pci_childs(node, scan_OF_pci_childs_iterator, filter_data); 769 /* not a root bus, we need to get our parent */
770 parent = scan_OF_for_pci_bus(bus->parent);
771 if (parent == NULL)
772 return NULL;
773
774 /* now iterate for children for a match */
775 np = scan_OF_for_pci_dev(parent, bus->self->devfn);
776 of_node_put(parent);
777
778 /* sanity check */
779 if (strcmp(np->type, "pci") != 0)
780 printk(KERN_WARNING "pci: wrong type \"%s\" for bridge %s\n",
781 np->type, np->full_name);
782
783 return np;
759} 784}
760 785
761/* 786/*
@@ -764,43 +789,25 @@ scan_OF_childs_for_device(struct device_node* node, u8 bus, u8 dev_fn)
764struct device_node * 789struct device_node *
765pci_busdev_to_OF_node(struct pci_bus *bus, int devfn) 790pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
766{ 791{
767 struct pci_controller *hose; 792 struct device_node *parent, *np;
768 struct device_node *node;
769 int busnr;
770 793
771 if (!have_of) 794 if (!have_of)
772 return NULL; 795 return NULL;
773
774 /* Lookup the hose */
775 busnr = bus->number;
776 hose = pci_bus_to_hose(busnr);
777 if (!hose)
778 return NULL;
779 796
780 /* Check it has an OF node associated */ 797 DBG("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn);
781 node = (struct device_node *) hose->arch_data; 798 parent = scan_OF_for_pci_bus(bus);
782 if (!node) 799 if (parent == NULL)
783 return NULL; 800 return NULL;
784 801 DBG(" parent is %s\n", parent ? parent->full_name : "<NULL>");
785 /* Fixup bus number according to what OF think it is. */ 802 np = scan_OF_for_pci_dev(parent, devfn);
786#ifdef CONFIG_PPC_PMAC 803 of_node_put(parent);
787 /* The G5 need a special case here. Basically, we don't remap all 804 DBG(" result is %s\n", np ? np->full_name : "<NULL>");
788 * busses on it so we don't create the pci-OF-map. However, we do 805
789 * remap the AGP bus and so have to deal with it. A future better 806 /* XXX most callers don't release the returned node
790 * fix has to be done by making the remapping per-host and always 807 * mostly because ppc64 doesn't increase the refcount,
791 * filling the pci_to_OF map. --BenH 808 * we need to fix that.
792 */ 809 */
793 if (machine_is(powermac) && busnr >= 0xf0) 810 return np;
794 busnr -= 0xf0;
795 else
796#endif
797 if (pci_to_OF_bus_map)
798 busnr = pci_to_OF_bus_map[busnr];
799 if (busnr == 0xff)
800 return NULL;
801
802 /* Now, lookup childs of the hose */
803 return scan_OF_childs_for_device(node->child, busnr, devfn);
804} 811}
805EXPORT_SYMBOL(pci_busdev_to_OF_node); 812EXPORT_SYMBOL(pci_busdev_to_OF_node);
806 813
@@ -960,7 +967,7 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
960 res->flags = IORESOURCE_IO; 967 res->flags = IORESOURCE_IO;
961 res->start = ranges[2]; 968 res->start = ranges[2];
962 DBG("PCI: IO 0x%llx -> 0x%llx\n", 969 DBG("PCI: IO 0x%llx -> 0x%llx\n",
963 res->start, res->start + size - 1); 970 (u64)res->start, (u64)res->start + size - 1);
964 break; 971 break;
965 case 2: /* memory space */ 972 case 2: /* memory space */
966 memno = 0; 973 memno = 0;
@@ -982,7 +989,7 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
982 res->flags |= IORESOURCE_PREFETCH; 989 res->flags |= IORESOURCE_PREFETCH;
983 res->start = ranges[na+2]; 990 res->start = ranges[na+2];
984 DBG("PCI: MEM[%d] 0x%llx -> 0x%llx\n", memno, 991 DBG("PCI: MEM[%d] 0x%llx -> 0x%llx\n", memno,
985 res->start, res->start + size - 1); 992 (u64)res->start, (u64)res->start + size - 1);
986 } 993 }
987 break; 994 break;
988 } 995 }
@@ -1268,7 +1275,10 @@ pcibios_init(void)
1268 if (pci_assign_all_buses) 1275 if (pci_assign_all_buses)
1269 hose->first_busno = next_busno; 1276 hose->first_busno = next_busno;
1270 hose->last_busno = 0xff; 1277 hose->last_busno = 0xff;
1271 bus = pci_scan_bus(hose->first_busno, hose->ops, hose); 1278 bus = pci_scan_bus_parented(hose->parent, hose->first_busno,
1279 hose->ops, hose);
1280 if (bus)
1281 pci_bus_add_devices(bus);
1272 hose->last_busno = bus->subordinate; 1282 hose->last_busno = bus->subordinate;
1273 if (pci_assign_all_buses || next_busno <= hose->last_busno) 1283 if (pci_assign_all_buses || next_busno <= hose->last_busno)
1274 next_busno = hose->last_busno + pcibios_assign_bus_offset; 1284 next_busno = hose->last_busno + pcibios_assign_bus_offset;
@@ -1282,10 +1292,6 @@ pcibios_init(void)
1282 if (pci_assign_all_buses && have_of) 1292 if (pci_assign_all_buses && have_of)
1283 pcibios_make_OF_bus_map(); 1293 pcibios_make_OF_bus_map();
1284 1294
1285 /* Do machine dependent PCI interrupt routing */
1286 if (ppc_md.pci_swizzle && ppc_md.pci_map_irq)
1287 pci_fixup_irqs(ppc_md.pci_swizzle, ppc_md.pci_map_irq);
1288
1289 /* Call machine dependent fixup */ 1295 /* Call machine dependent fixup */
1290 if (ppc_md.pcibios_fixup) 1296 if (ppc_md.pcibios_fixup)
1291 ppc_md.pcibios_fixup(); 1297 ppc_md.pcibios_fixup();
@@ -1308,25 +1314,6 @@ pcibios_init(void)
1308 1314
1309subsys_initcall(pcibios_init); 1315subsys_initcall(pcibios_init);
1310 1316
1311unsigned char __init
1312common_swizzle(struct pci_dev *dev, unsigned char *pinp)
1313{
1314 struct pci_controller *hose = dev->sysdata;
1315
1316 if (dev->bus->number != hose->first_busno) {
1317 u8 pin = *pinp;
1318 do {
1319 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
1320 /* Move up the chain of bridges. */
1321 dev = dev->bus->self;
1322 } while (dev->bus->self);
1323 *pinp = pin;
1324
1325 /* The slot is the idsel of the last bridge. */
1326 }
1327 return PCI_SLOT(dev->devfn);
1328}
1329
1330unsigned long resource_fixup(struct pci_dev * dev, struct resource * res, 1317unsigned long resource_fixup(struct pci_dev * dev, struct resource * res,
1331 unsigned long start, unsigned long size) 1318 unsigned long start, unsigned long size)
1332{ 1319{
@@ -1338,6 +1325,7 @@ void __init pcibios_fixup_bus(struct pci_bus *bus)
1338 struct pci_controller *hose = (struct pci_controller *) bus->sysdata; 1325 struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
1339 unsigned long io_offset; 1326 unsigned long io_offset;
1340 struct resource *res; 1327 struct resource *res;
1328 struct pci_dev *dev;
1341 int i; 1329 int i;
1342 1330
1343 io_offset = (unsigned long)hose->io_base_virt - isa_io_base; 1331 io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
@@ -1390,8 +1378,16 @@ void __init pcibios_fixup_bus(struct pci_bus *bus)
1390 } 1378 }
1391 } 1379 }
1392 1380
1381 /* Platform specific bus fixups */
1393 if (ppc_md.pcibios_fixup_bus) 1382 if (ppc_md.pcibios_fixup_bus)
1394 ppc_md.pcibios_fixup_bus(bus); 1383 ppc_md.pcibios_fixup_bus(bus);
1384
1385 /* Read default IRQs and fixup if necessary */
1386 list_for_each_entry(dev, &bus->devices, bus_list) {
1387 pci_read_irq_line(dev);
1388 if (ppc_md.pci_irq_fixup)
1389 ppc_md.pci_irq_fixup(dev);
1390 }
1395} 1391}
1396 1392
1397char __init *pcibios_setup(char *str) 1393char __init *pcibios_setup(char *str)
@@ -1556,7 +1552,7 @@ pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
1556 1552
1557 1553
1558static struct resource *__pci_mmap_make_offset(struct pci_dev *dev, 1554static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
1559 unsigned long *offset, 1555 resource_size_t *offset,
1560 enum pci_mmap_state mmap_state) 1556 enum pci_mmap_state mmap_state)
1561{ 1557{
1562 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number); 1558 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
@@ -1568,10 +1564,12 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
1568 1564
1569 /* If memory, add on the PCI bridge address offset */ 1565 /* If memory, add on the PCI bridge address offset */
1570 if (mmap_state == pci_mmap_mem) { 1566 if (mmap_state == pci_mmap_mem) {
1567#if 0 /* See comment in pci_resource_to_user() for why this is disabled */
1571 *offset += hose->pci_mem_offset; 1568 *offset += hose->pci_mem_offset;
1569#endif
1572 res_bit = IORESOURCE_MEM; 1570 res_bit = IORESOURCE_MEM;
1573 } else { 1571 } else {
1574 io_offset = hose->io_base_virt - ___IO_BASE; 1572 io_offset = hose->io_base_virt - (void __iomem *)_IO_BASE;
1575 *offset += io_offset; 1573 *offset += io_offset;
1576 res_bit = IORESOURCE_IO; 1574 res_bit = IORESOURCE_IO;
1577 } 1575 }
@@ -1636,9 +1634,6 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
1636 else 1634 else
1637 prot |= _PAGE_GUARDED; 1635 prot |= _PAGE_GUARDED;
1638 1636
1639 printk("PCI map for %s:%llx, prot: %lx\n", pci_name(dev),
1640 (unsigned long long)rp->start, prot);
1641
1642 return __pgprot(prot); 1637 return __pgprot(prot);
1643} 1638}
1644 1639
@@ -1707,7 +1702,7 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1707 enum pci_mmap_state mmap_state, 1702 enum pci_mmap_state mmap_state,
1708 int write_combine) 1703 int write_combine)
1709{ 1704{
1710 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 1705 resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
1711 struct resource *rp; 1706 struct resource *rp;
1712 int ret; 1707 int ret;
1713 1708
@@ -1820,21 +1815,42 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar,
1820 resource_size_t *start, resource_size_t *end) 1815 resource_size_t *start, resource_size_t *end)
1821{ 1816{
1822 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number); 1817 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
1823 unsigned long offset = 0; 1818 resource_size_t offset = 0;
1824 1819
1825 if (hose == NULL) 1820 if (hose == NULL)
1826 return; 1821 return;
1827 1822
1828 if (rsrc->flags & IORESOURCE_IO) 1823 if (rsrc->flags & IORESOURCE_IO)
1829 offset = ___IO_BASE - hose->io_base_virt + hose->io_base_phys; 1824 offset = (unsigned long)hose->io_base_virt - _IO_BASE;
1825
1826 /* We pass a fully fixed up address to userland for MMIO instead of
1827 * a BAR value because X is lame and expects to be able to use that
1828 * to pass to /dev/mem !
1829 *
1830 * That means that we'll have potentially 64 bits values where some
1831 * userland apps only expect 32 (like X itself since it thinks only
1832 * Sparc has 64 bits MMIO) but if we don't do that, we break it on
1833 * 32 bits CHRPs :-(
1834 *
1835 * Hopefully, the sysfs insterface is immune to that gunk. Once X
1836 * has been fixed (and the fix spread enough), we can re-enable the
1837 * 2 lines below and pass down a BAR value to userland. In that case
1838 * we'll also have to re-enable the matching code in
1839 * __pci_mmap_make_offset().
1840 *
1841 * BenH.
1842 */
1843#if 0
1844 else if (rsrc->flags & IORESOURCE_MEM)
1845 offset = hose->pci_mem_offset;
1846#endif
1830 1847
1831 *start = rsrc->start + offset; 1848 *start = rsrc->start - offset;
1832 *end = rsrc->end + offset; 1849 *end = rsrc->end - offset;
1833} 1850}
1834 1851
1835void __init 1852void __init pci_init_resource(struct resource *res, resource_size_t start,
1836pci_init_resource(struct resource *res, unsigned long start, unsigned long end, 1853 resource_size_t end, int flags, char *name)
1837 int flags, char *name)
1838{ 1854{
1839 res->start = start; 1855 res->start = start;
1840 res->end = end; 1856 res->end = end;
@@ -1845,35 +1861,6 @@ pci_init_resource(struct resource *res, unsigned long start, unsigned long end,
1845 res->child = NULL; 1861 res->child = NULL;
1846} 1862}
1847 1863
1848void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
1849{
1850 unsigned long start = pci_resource_start(dev, bar);
1851 unsigned long len = pci_resource_len(dev, bar);
1852 unsigned long flags = pci_resource_flags(dev, bar);
1853
1854 if (!len)
1855 return NULL;
1856 if (max && len > max)
1857 len = max;
1858 if (flags & IORESOURCE_IO)
1859 return ioport_map(start, len);
1860 if (flags & IORESOURCE_MEM)
1861 /* Not checking IORESOURCE_CACHEABLE because PPC does
1862 * not currently distinguish between ioremap and
1863 * ioremap_nocache.
1864 */
1865 return ioremap(start, len);
1866 /* What? */
1867 return NULL;
1868}
1869
1870void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
1871{
1872 /* Nothing to do */
1873}
1874EXPORT_SYMBOL(pci_iomap);
1875EXPORT_SYMBOL(pci_iounmap);
1876
1877unsigned long pci_address_to_pio(phys_addr_t address) 1864unsigned long pci_address_to_pio(phys_addr_t address)
1878{ 1865{
1879 struct pci_controller* hose = hose_head; 1866 struct pci_controller* hose = hose_head;