diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-22 17:54:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-22 17:54:02 -0400 |
commit | acb41c0f928fdb84a1c3753ac92c534a2a0f08d2 (patch) | |
tree | 4bf92f1c2b1f36fa68d3e77d646b04b863e1a7e4 /arch | |
parent | 8181780c163e7111f15619067cfa044172d532e1 (diff) | |
parent | ef3b4f8cc20e80c767e47b848fb7512770ab80d7 (diff) |
Merge branch 'of-pci' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
* 'of-pci' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc:
pci/of: Consolidate pci_bus_to_OF_node()
pci/of: Consolidate pci_device_to_OF_node()
x86/devicetree: Use generic PCI <-> OF matching
microblaze/pci: Move the remains of pci_32.c to pci-common.c
microblaze/pci: Remove powermac originated cruft
pci/of: Match PCI devices to OF nodes dynamically
Diffstat (limited to 'arch')
-rw-r--r-- | arch/microblaze/include/asm/pci-bridge.h | 13 | ||||
-rw-r--r-- | arch/microblaze/include/asm/pci.h | 3 | ||||
-rw-r--r-- | arch/microblaze/include/asm/prom.h | 15 | ||||
-rw-r--r-- | arch/microblaze/pci/Makefile | 2 | ||||
-rw-r--r-- | arch/microblaze/pci/pci-common.c | 112 | ||||
-rw-r--r-- | arch/microblaze/pci/pci_32.c | 432 | ||||
-rw-r--r-- | arch/powerpc/include/asm/pci-bridge.h | 29 | ||||
-rw-r--r-- | arch/powerpc/include/asm/pci.h | 3 | ||||
-rw-r--r-- | arch/powerpc/include/asm/prom.h | 14 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci-common.c | 11 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_32.c | 150 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_dn.c | 47 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_of_scan.c | 9 | ||||
-rw-r--r-- | arch/powerpc/platforms/powermac/pci.c | 3 | ||||
-rw-r--r-- | arch/sparc/include/asm/pci_32.h | 3 | ||||
-rw-r--r-- | arch/sparc/include/asm/pci_64.h | 3 | ||||
-rw-r--r-- | arch/sparc/kernel/pci.c | 8 | ||||
-rw-r--r-- | arch/sparc/kernel/pcic.c | 8 | ||||
-rw-r--r-- | arch/x86/include/asm/prom.h | 11 | ||||
-rw-r--r-- | arch/x86/kernel/devicetree.c | 60 |
20 files changed, 162 insertions, 774 deletions
diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h index 746df91e5796..242be57a319c 100644 --- a/arch/microblaze/include/asm/pci-bridge.h +++ b/arch/microblaze/include/asm/pci-bridge.h | |||
@@ -19,9 +19,6 @@ enum { | |||
19 | */ | 19 | */ |
20 | PCI_REASSIGN_ALL_RSRC = 0x00000001, | 20 | PCI_REASSIGN_ALL_RSRC = 0x00000001, |
21 | 21 | ||
22 | /* Re-assign all bus numbers */ | ||
23 | PCI_REASSIGN_ALL_BUS = 0x00000002, | ||
24 | |||
25 | /* Do not try to assign, just use existing setup */ | 22 | /* Do not try to assign, just use existing setup */ |
26 | PCI_PROBE_ONLY = 0x00000004, | 23 | PCI_PROBE_ONLY = 0x00000004, |
27 | 24 | ||
@@ -110,16 +107,6 @@ static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) | |||
110 | return bus->sysdata; | 107 | return bus->sysdata; |
111 | } | 108 | } |
112 | 109 | ||
113 | static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) | ||
114 | { | ||
115 | struct pci_controller *host; | ||
116 | |||
117 | if (bus->self) | ||
118 | return pci_device_to_OF_node(bus->self); | ||
119 | host = pci_bus_to_host(bus); | ||
120 | return host ? host->dn : NULL; | ||
121 | } | ||
122 | |||
123 | static inline int isa_vaddr_is_ioport(void __iomem *address) | 110 | static inline int isa_vaddr_is_ioport(void __iomem *address) |
124 | { | 111 | { |
125 | /* No specific ISA handling on ppc32 at this stage, it | 112 | /* No specific ISA handling on ppc32 at this stage, it |
diff --git a/arch/microblaze/include/asm/pci.h b/arch/microblaze/include/asm/pci.h index ba65cf472544..1dd9d6b1e275 100644 --- a/arch/microblaze/include/asm/pci.h +++ b/arch/microblaze/include/asm/pci.h | |||
@@ -40,8 +40,7 @@ struct pci_dev; | |||
40 | * Set this to 1 if you want the kernel to re-assign all PCI | 40 | * Set this to 1 if you want the kernel to re-assign all PCI |
41 | * bus numbers (don't do that on ppc64 yet !) | 41 | * bus numbers (don't do that on ppc64 yet !) |
42 | */ | 42 | */ |
43 | #define pcibios_assign_all_busses() \ | 43 | #define pcibios_assign_all_busses() 0 |
44 | (pci_has_flag(PCI_REASSIGN_ALL_BUS)) | ||
45 | 44 | ||
46 | static inline void pcibios_set_master(struct pci_dev *dev) | 45 | static inline void pcibios_set_master(struct pci_dev *dev) |
47 | { | 46 | { |
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h index d0890d36ef61..9bd01ecb00d6 100644 --- a/arch/microblaze/include/asm/prom.h +++ b/arch/microblaze/include/asm/prom.h | |||
@@ -29,21 +29,6 @@ | |||
29 | extern int early_uartlite_console(void); | 29 | extern int early_uartlite_console(void); |
30 | extern int early_uart16550_console(void); | 30 | extern int early_uart16550_console(void); |
31 | 31 | ||
32 | #ifdef CONFIG_PCI | ||
33 | /* | ||
34 | * PCI <-> OF matching functions | ||
35 | * (XXX should these be here?) | ||
36 | */ | ||
37 | struct pci_bus; | ||
38 | struct pci_dev; | ||
39 | extern int pci_device_from_OF_node(struct device_node *node, | ||
40 | u8 *bus, u8 *devfn); | ||
41 | extern struct device_node *pci_busdev_to_OF_node(struct pci_bus *bus, | ||
42 | int devfn); | ||
43 | extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev); | ||
44 | extern void pci_create_OF_bus_map(void); | ||
45 | #endif | ||
46 | |||
47 | /* | 32 | /* |
48 | * OF address retreival & translation | 33 | * OF address retreival & translation |
49 | */ | 34 | */ |
diff --git a/arch/microblaze/pci/Makefile b/arch/microblaze/pci/Makefile index 9889cc2e1294..d1114fbd4780 100644 --- a/arch/microblaze/pci/Makefile +++ b/arch/microblaze/pci/Makefile | |||
@@ -2,5 +2,5 @@ | |||
2 | # Makefile | 2 | # Makefile |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_PCI) += pci_32.o pci-common.o indirect_pci.o iomap.o | 5 | obj-$(CONFIG_PCI) += pci-common.o indirect_pci.o iomap.o |
6 | obj-$(CONFIG_PCI_XILINX) += xilinx_pci.o | 6 | obj-$(CONFIG_PCI_XILINX) += xilinx_pci.o |
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 53599067d2f9..041b1d86d75b 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c | |||
@@ -50,6 +50,11 @@ unsigned int pci_flags; | |||
50 | 50 | ||
51 | static struct dma_map_ops *pci_dma_ops = &dma_direct_ops; | 51 | static struct dma_map_ops *pci_dma_ops = &dma_direct_ops; |
52 | 52 | ||
53 | unsigned long isa_io_base; | ||
54 | unsigned long pci_dram_offset; | ||
55 | static int pci_bus_count; | ||
56 | |||
57 | |||
53 | void set_pci_dma_ops(struct dma_map_ops *dma_ops) | 58 | void set_pci_dma_ops(struct dma_map_ops *dma_ops) |
54 | { | 59 | { |
55 | pci_dma_ops = dma_ops; | 60 | pci_dma_ops = dma_ops; |
@@ -1558,6 +1563,112 @@ void __devinit pcibios_setup_phb_resources(struct pci_controller *hose) | |||
1558 | (unsigned long)hose->io_base_virt - _IO_BASE); | 1563 | (unsigned long)hose->io_base_virt - _IO_BASE); |
1559 | } | 1564 | } |
1560 | 1565 | ||
1566 | struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus) | ||
1567 | { | ||
1568 | struct pci_controller *hose = bus->sysdata; | ||
1569 | |||
1570 | return of_node_get(hose->dn); | ||
1571 | } | ||
1572 | |||
1573 | static void __devinit pcibios_scan_phb(struct pci_controller *hose) | ||
1574 | { | ||
1575 | struct pci_bus *bus; | ||
1576 | struct device_node *node = hose->dn; | ||
1577 | unsigned long io_offset; | ||
1578 | struct resource *res = &hose->io_resource; | ||
1579 | |||
1580 | pr_debug("PCI: Scanning PHB %s\n", | ||
1581 | node ? node->full_name : "<NO NAME>"); | ||
1582 | |||
1583 | /* Create an empty bus for the toplevel */ | ||
1584 | bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, hose); | ||
1585 | if (bus == NULL) { | ||
1586 | printk(KERN_ERR "Failed to create bus for PCI domain %04x\n", | ||
1587 | hose->global_number); | ||
1588 | return; | ||
1589 | } | ||
1590 | bus->secondary = hose->first_busno; | ||
1591 | hose->bus = bus; | ||
1592 | |||
1593 | /* Fixup IO space offset */ | ||
1594 | io_offset = (unsigned long)hose->io_base_virt - isa_io_base; | ||
1595 | res->start = (res->start + io_offset) & 0xffffffffu; | ||
1596 | res->end = (res->end + io_offset) & 0xffffffffu; | ||
1597 | |||
1598 | /* Wire up PHB bus resources */ | ||
1599 | pcibios_setup_phb_resources(hose); | ||
1600 | |||
1601 | /* Scan children */ | ||
1602 | hose->last_busno = bus->subordinate = pci_scan_child_bus(bus); | ||
1603 | } | ||
1604 | |||
1605 | static int __init pcibios_init(void) | ||
1606 | { | ||
1607 | struct pci_controller *hose, *tmp; | ||
1608 | int next_busno = 0; | ||
1609 | |||
1610 | printk(KERN_INFO "PCI: Probing PCI hardware\n"); | ||
1611 | |||
1612 | /* Scan all of the recorded PCI controllers. */ | ||
1613 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { | ||
1614 | hose->last_busno = 0xff; | ||
1615 | pcibios_scan_phb(hose); | ||
1616 | printk(KERN_INFO "calling pci_bus_add_devices()\n"); | ||
1617 | pci_bus_add_devices(hose->bus); | ||
1618 | if (next_busno <= hose->last_busno) | ||
1619 | next_busno = hose->last_busno + 1; | ||
1620 | } | ||
1621 | pci_bus_count = next_busno; | ||
1622 | |||
1623 | /* Call common code to handle resource allocation */ | ||
1624 | pcibios_resource_survey(); | ||
1625 | |||
1626 | return 0; | ||
1627 | } | ||
1628 | |||
1629 | subsys_initcall(pcibios_init); | ||
1630 | |||
1631 | static struct pci_controller *pci_bus_to_hose(int bus) | ||
1632 | { | ||
1633 | struct pci_controller *hose, *tmp; | ||
1634 | |||
1635 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) | ||
1636 | if (bus >= hose->first_busno && bus <= hose->last_busno) | ||
1637 | return hose; | ||
1638 | return NULL; | ||
1639 | } | ||
1640 | |||
1641 | /* Provide information on locations of various I/O regions in physical | ||
1642 | * memory. Do this on a per-card basis so that we choose the right | ||
1643 | * root bridge. | ||
1644 | * Note that the returned IO or memory base is a physical address | ||
1645 | */ | ||
1646 | |||
1647 | long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn) | ||
1648 | { | ||
1649 | struct pci_controller *hose; | ||
1650 | long result = -EOPNOTSUPP; | ||
1651 | |||
1652 | hose = pci_bus_to_hose(bus); | ||
1653 | if (!hose) | ||
1654 | return -ENODEV; | ||
1655 | |||
1656 | switch (which) { | ||
1657 | case IOBASE_BRIDGE_NUMBER: | ||
1658 | return (long)hose->first_busno; | ||
1659 | case IOBASE_MEMORY: | ||
1660 | return (long)hose->pci_mem_offset; | ||
1661 | case IOBASE_IO: | ||
1662 | return (long)hose->io_base_phys; | ||
1663 | case IOBASE_ISA_IO: | ||
1664 | return (long)isa_io_base; | ||
1665 | case IOBASE_ISA_MEM: | ||
1666 | return (long)isa_mem_base; | ||
1667 | } | ||
1668 | |||
1669 | return result; | ||
1670 | } | ||
1671 | |||
1561 | /* | 1672 | /* |
1562 | * Null PCI config access functions, for the case when we can't | 1673 | * Null PCI config access functions, for the case when we can't |
1563 | * find a hose. | 1674 | * find a hose. |
@@ -1626,3 +1737,4 @@ int early_find_capability(struct pci_controller *hose, int bus, int devfn, | |||
1626 | { | 1737 | { |
1627 | return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap); | 1738 | return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap); |
1628 | } | 1739 | } |
1740 | |||
diff --git a/arch/microblaze/pci/pci_32.c b/arch/microblaze/pci/pci_32.c deleted file mode 100644 index 92728a6cfd80..000000000000 --- a/arch/microblaze/pci/pci_32.c +++ /dev/null | |||
@@ -1,432 +0,0 @@ | |||
1 | /* | ||
2 | * Common pmac/prep/chrp pci routines. -- Cort | ||
3 | */ | ||
4 | |||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/pci.h> | ||
7 | #include <linux/delay.h> | ||
8 | #include <linux/string.h> | ||
9 | #include <linux/init.h> | ||
10 | #include <linux/capability.h> | ||
11 | #include <linux/sched.h> | ||
12 | #include <linux/errno.h> | ||
13 | #include <linux/bootmem.h> | ||
14 | #include <linux/irq.h> | ||
15 | #include <linux/list.h> | ||
16 | #include <linux/of.h> | ||
17 | #include <linux/slab.h> | ||
18 | |||
19 | #include <asm/processor.h> | ||
20 | #include <asm/io.h> | ||
21 | #include <asm/prom.h> | ||
22 | #include <asm/sections.h> | ||
23 | #include <asm/pci-bridge.h> | ||
24 | #include <asm/byteorder.h> | ||
25 | #include <asm/uaccess.h> | ||
26 | |||
27 | #undef DEBUG | ||
28 | |||
29 | unsigned long isa_io_base; | ||
30 | unsigned long pci_dram_offset; | ||
31 | int pcibios_assign_bus_offset = 1; | ||
32 | |||
33 | static u8 *pci_to_OF_bus_map; | ||
34 | |||
35 | /* By default, we don't re-assign bus numbers. We do this only on | ||
36 | * some pmacs | ||
37 | */ | ||
38 | static int pci_assign_all_buses; | ||
39 | |||
40 | static int pci_bus_count; | ||
41 | |||
42 | /* | ||
43 | * Functions below are used on OpenFirmware machines. | ||
44 | */ | ||
45 | static void | ||
46 | make_one_node_map(struct device_node *node, u8 pci_bus) | ||
47 | { | ||
48 | const int *bus_range; | ||
49 | int len; | ||
50 | |||
51 | if (pci_bus >= pci_bus_count) | ||
52 | return; | ||
53 | bus_range = of_get_property(node, "bus-range", &len); | ||
54 | if (bus_range == NULL || len < 2 * sizeof(int)) { | ||
55 | printk(KERN_WARNING "Can't get bus-range for %s, " | ||
56 | "assuming it starts at 0\n", node->full_name); | ||
57 | pci_to_OF_bus_map[pci_bus] = 0; | ||
58 | } else | ||
59 | pci_to_OF_bus_map[pci_bus] = bus_range[0]; | ||
60 | |||
61 | for_each_child_of_node(node, node) { | ||
62 | struct pci_dev *dev; | ||
63 | const unsigned int *class_code, *reg; | ||
64 | |||
65 | class_code = of_get_property(node, "class-code", NULL); | ||
66 | if (!class_code || | ||
67 | ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI && | ||
68 | (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) | ||
69 | continue; | ||
70 | reg = of_get_property(node, "reg", NULL); | ||
71 | if (!reg) | ||
72 | continue; | ||
73 | dev = pci_get_bus_and_slot(pci_bus, ((reg[0] >> 8) & 0xff)); | ||
74 | if (!dev || !dev->subordinate) { | ||
75 | pci_dev_put(dev); | ||
76 | continue; | ||
77 | } | ||
78 | make_one_node_map(node, dev->subordinate->number); | ||
79 | pci_dev_put(dev); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | void | ||
84 | pcibios_make_OF_bus_map(void) | ||
85 | { | ||
86 | int i; | ||
87 | struct pci_controller *hose, *tmp; | ||
88 | struct property *map_prop; | ||
89 | struct device_node *dn; | ||
90 | |||
91 | pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL); | ||
92 | if (!pci_to_OF_bus_map) { | ||
93 | printk(KERN_ERR "Can't allocate OF bus map !\n"); | ||
94 | return; | ||
95 | } | ||
96 | |||
97 | /* We fill the bus map with invalid values, that helps | ||
98 | * debugging. | ||
99 | */ | ||
100 | for (i = 0; i < pci_bus_count; i++) | ||
101 | pci_to_OF_bus_map[i] = 0xff; | ||
102 | |||
103 | /* For each hose, we begin searching bridges */ | ||
104 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { | ||
105 | struct device_node *node = hose->dn; | ||
106 | |||
107 | if (!node) | ||
108 | continue; | ||
109 | make_one_node_map(node, hose->first_busno); | ||
110 | } | ||
111 | dn = of_find_node_by_path("/"); | ||
112 | map_prop = of_find_property(dn, "pci-OF-bus-map", NULL); | ||
113 | if (map_prop) { | ||
114 | BUG_ON(pci_bus_count > map_prop->length); | ||
115 | memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count); | ||
116 | } | ||
117 | of_node_put(dn); | ||
118 | #ifdef DEBUG | ||
119 | printk(KERN_INFO "PCI->OF bus map:\n"); | ||
120 | for (i = 0; i < pci_bus_count; i++) { | ||
121 | if (pci_to_OF_bus_map[i] == 0xff) | ||
122 | continue; | ||
123 | printk(KERN_INFO "%d -> %d\n", i, pci_to_OF_bus_map[i]); | ||
124 | } | ||
125 | #endif | ||
126 | } | ||
127 | |||
128 | typedef int (*pci_OF_scan_iterator)(struct device_node *node, void *data); | ||
129 | |||
130 | static struct device_node *scan_OF_pci_childs(struct device_node *parent, | ||
131 | pci_OF_scan_iterator filter, void *data) | ||
132 | { | ||
133 | struct device_node *node; | ||
134 | struct device_node *sub_node; | ||
135 | |||
136 | for_each_child_of_node(parent, node) { | ||
137 | const unsigned int *class_code; | ||
138 | |||
139 | if (filter(node, data)) { | ||
140 | of_node_put(node); | ||
141 | return node; | ||
142 | } | ||
143 | |||
144 | /* For PCI<->PCI bridges or CardBus bridges, we go down | ||
145 | * Note: some OFs create a parent node "multifunc-device" as | ||
146 | * a fake root for all functions of a multi-function device, | ||
147 | * we go down them as well. | ||
148 | */ | ||
149 | class_code = of_get_property(node, "class-code", NULL); | ||
150 | if ((!class_code || | ||
151 | ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI && | ||
152 | (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) && | ||
153 | strcmp(node->name, "multifunc-device")) | ||
154 | continue; | ||
155 | sub_node = scan_OF_pci_childs(node, filter, data); | ||
156 | if (sub_node) { | ||
157 | of_node_put(node); | ||
158 | return sub_node; | ||
159 | } | ||
160 | } | ||
161 | return NULL; | ||
162 | } | ||
163 | |||
164 | static struct device_node *scan_OF_for_pci_dev(struct device_node *parent, | ||
165 | unsigned int devfn) | ||
166 | { | ||
167 | struct device_node *np, *cnp; | ||
168 | const u32 *reg; | ||
169 | unsigned int psize; | ||
170 | |||
171 | for_each_child_of_node(parent, np) { | ||
172 | reg = of_get_property(np, "reg", &psize); | ||
173 | if (reg && psize >= 4 && ((reg[0] >> 8) & 0xff) == devfn) | ||
174 | return np; | ||
175 | |||
176 | /* Note: some OFs create a parent node "multifunc-device" as | ||
177 | * a fake root for all functions of a multi-function device, | ||
178 | * we go down them as well. */ | ||
179 | if (!strcmp(np->name, "multifunc-device")) { | ||
180 | cnp = scan_OF_for_pci_dev(np, devfn); | ||
181 | if (cnp) | ||
182 | return cnp; | ||
183 | } | ||
184 | } | ||
185 | return NULL; | ||
186 | } | ||
187 | |||
188 | |||
189 | static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus) | ||
190 | { | ||
191 | struct device_node *parent, *np; | ||
192 | |||
193 | /* Are we a root bus ? */ | ||
194 | if (bus->self == NULL || bus->parent == NULL) { | ||
195 | struct pci_controller *hose = pci_bus_to_host(bus); | ||
196 | if (hose == NULL) | ||
197 | return NULL; | ||
198 | return of_node_get(hose->dn); | ||
199 | } | ||
200 | |||
201 | /* not a root bus, we need to get our parent */ | ||
202 | parent = scan_OF_for_pci_bus(bus->parent); | ||
203 | if (parent == NULL) | ||
204 | return NULL; | ||
205 | |||
206 | /* now iterate for children for a match */ | ||
207 | np = scan_OF_for_pci_dev(parent, bus->self->devfn); | ||
208 | of_node_put(parent); | ||
209 | |||
210 | return np; | ||
211 | } | ||
212 | |||
213 | /* | ||
214 | * Scans the OF tree for a device node matching a PCI device | ||
215 | */ | ||
216 | struct device_node * | ||
217 | pci_busdev_to_OF_node(struct pci_bus *bus, int devfn) | ||
218 | { | ||
219 | struct device_node *parent, *np; | ||
220 | |||
221 | pr_debug("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn); | ||
222 | parent = scan_OF_for_pci_bus(bus); | ||
223 | if (parent == NULL) | ||
224 | return NULL; | ||
225 | pr_debug(" parent is %s\n", parent ? parent->full_name : "<NULL>"); | ||
226 | np = scan_OF_for_pci_dev(parent, devfn); | ||
227 | of_node_put(parent); | ||
228 | pr_debug(" result is %s\n", np ? np->full_name : "<NULL>"); | ||
229 | |||
230 | /* XXX most callers don't release the returned node | ||
231 | * mostly because ppc64 doesn't increase the refcount, | ||
232 | * we need to fix that. | ||
233 | */ | ||
234 | return np; | ||
235 | } | ||
236 | EXPORT_SYMBOL(pci_busdev_to_OF_node); | ||
237 | |||
238 | struct device_node* | ||
239 | pci_device_to_OF_node(struct pci_dev *dev) | ||
240 | { | ||
241 | return pci_busdev_to_OF_node(dev->bus, dev->devfn); | ||
242 | } | ||
243 | EXPORT_SYMBOL(pci_device_to_OF_node); | ||
244 | |||
245 | static int | ||
246 | find_OF_pci_device_filter(struct device_node *node, void *data) | ||
247 | { | ||
248 | return ((void *)node == data); | ||
249 | } | ||
250 | |||
251 | /* | ||
252 | * Returns the PCI device matching a given OF node | ||
253 | */ | ||
254 | int | ||
255 | pci_device_from_OF_node(struct device_node *node, u8 *bus, u8 *devfn) | ||
256 | { | ||
257 | const unsigned int *reg; | ||
258 | struct pci_controller *hose; | ||
259 | struct pci_dev *dev = NULL; | ||
260 | |||
261 | /* Make sure it's really a PCI device */ | ||
262 | hose = pci_find_hose_for_OF_device(node); | ||
263 | if (!hose || !hose->dn) | ||
264 | return -ENODEV; | ||
265 | if (!scan_OF_pci_childs(hose->dn, | ||
266 | find_OF_pci_device_filter, (void *)node)) | ||
267 | return -ENODEV; | ||
268 | reg = of_get_property(node, "reg", NULL); | ||
269 | if (!reg) | ||
270 | return -ENODEV; | ||
271 | *bus = (reg[0] >> 16) & 0xff; | ||
272 | *devfn = ((reg[0] >> 8) & 0xff); | ||
273 | |||
274 | /* Ok, here we need some tweak. If we have already renumbered | ||
275 | * all busses, we can't rely on the OF bus number any more. | ||
276 | * the pci_to_OF_bus_map is not enough as several PCI busses | ||
277 | * may match the same OF bus number. | ||
278 | */ | ||
279 | if (!pci_to_OF_bus_map) | ||
280 | return 0; | ||
281 | |||
282 | for_each_pci_dev(dev) | ||
283 | if (pci_to_OF_bus_map[dev->bus->number] == *bus && | ||
284 | dev->devfn == *devfn) { | ||
285 | *bus = dev->bus->number; | ||
286 | pci_dev_put(dev); | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | return -ENODEV; | ||
291 | } | ||
292 | EXPORT_SYMBOL(pci_device_from_OF_node); | ||
293 | |||
294 | /* We create the "pci-OF-bus-map" property now so it appears in the | ||
295 | * /proc device tree | ||
296 | */ | ||
297 | void __init | ||
298 | pci_create_OF_bus_map(void) | ||
299 | { | ||
300 | struct property *of_prop; | ||
301 | struct device_node *dn; | ||
302 | |||
303 | of_prop = (struct property *) alloc_bootmem(sizeof(struct property) + \ | ||
304 | 256); | ||
305 | if (!of_prop) | ||
306 | return; | ||
307 | dn = of_find_node_by_path("/"); | ||
308 | if (dn) { | ||
309 | memset(of_prop, -1, sizeof(struct property) + 256); | ||
310 | of_prop->name = "pci-OF-bus-map"; | ||
311 | of_prop->length = 256; | ||
312 | of_prop->value = &of_prop[1]; | ||
313 | prom_add_property(dn, of_prop); | ||
314 | of_node_put(dn); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | static void __devinit pcibios_scan_phb(struct pci_controller *hose) | ||
319 | { | ||
320 | struct pci_bus *bus; | ||
321 | struct device_node *node = hose->dn; | ||
322 | unsigned long io_offset; | ||
323 | struct resource *res = &hose->io_resource; | ||
324 | |||
325 | pr_debug("PCI: Scanning PHB %s\n", | ||
326 | node ? node->full_name : "<NO NAME>"); | ||
327 | |||
328 | /* Create an empty bus for the toplevel */ | ||
329 | bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, hose); | ||
330 | if (bus == NULL) { | ||
331 | printk(KERN_ERR "Failed to create bus for PCI domain %04x\n", | ||
332 | hose->global_number); | ||
333 | return; | ||
334 | } | ||
335 | bus.dev->of_node = of_node_get(node); | ||
336 | bus->secondary = hose->first_busno; | ||
337 | hose->bus = bus; | ||
338 | |||
339 | /* Fixup IO space offset */ | ||
340 | io_offset = (unsigned long)hose->io_base_virt - isa_io_base; | ||
341 | res->start = (res->start + io_offset) & 0xffffffffu; | ||
342 | res->end = (res->end + io_offset) & 0xffffffffu; | ||
343 | |||
344 | /* Wire up PHB bus resources */ | ||
345 | pcibios_setup_phb_resources(hose); | ||
346 | |||
347 | /* Scan children */ | ||
348 | hose->last_busno = bus->subordinate = pci_scan_child_bus(bus); | ||
349 | } | ||
350 | |||
351 | static int __init pcibios_init(void) | ||
352 | { | ||
353 | struct pci_controller *hose, *tmp; | ||
354 | int next_busno = 0; | ||
355 | |||
356 | printk(KERN_INFO "PCI: Probing PCI hardware\n"); | ||
357 | |||
358 | if (pci_flags & PCI_REASSIGN_ALL_BUS) { | ||
359 | printk(KERN_INFO "setting pci_asign_all_busses\n"); | ||
360 | pci_assign_all_buses = 1; | ||
361 | } | ||
362 | |||
363 | /* Scan all of the recorded PCI controllers. */ | ||
364 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { | ||
365 | if (pci_assign_all_buses) | ||
366 | hose->first_busno = next_busno; | ||
367 | hose->last_busno = 0xff; | ||
368 | pcibios_scan_phb(hose); | ||
369 | printk(KERN_INFO "calling pci_bus_add_devices()\n"); | ||
370 | pci_bus_add_devices(hose->bus); | ||
371 | if (pci_assign_all_buses || next_busno <= hose->last_busno) | ||
372 | next_busno = hose->last_busno + \ | ||
373 | pcibios_assign_bus_offset; | ||
374 | } | ||
375 | pci_bus_count = next_busno; | ||
376 | |||
377 | /* OpenFirmware based machines need a map of OF bus | ||
378 | * numbers vs. kernel bus numbers since we may have to | ||
379 | * remap them. | ||
380 | */ | ||
381 | if (pci_assign_all_buses) | ||
382 | pcibios_make_OF_bus_map(); | ||
383 | |||
384 | /* Call common code to handle resource allocation */ | ||
385 | pcibios_resource_survey(); | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | subsys_initcall(pcibios_init); | ||
391 | |||
392 | static struct pci_controller* | ||
393 | pci_bus_to_hose(int bus) | ||
394 | { | ||
395 | struct pci_controller *hose, *tmp; | ||
396 | |||
397 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) | ||
398 | if (bus >= hose->first_busno && bus <= hose->last_busno) | ||
399 | return hose; | ||
400 | return NULL; | ||
401 | } | ||
402 | |||
403 | /* Provide information on locations of various I/O regions in physical | ||
404 | * memory. Do this on a per-card basis so that we choose the right | ||
405 | * root bridge. | ||
406 | * Note that the returned IO or memory base is a physical address | ||
407 | */ | ||
408 | |||
409 | long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn) | ||
410 | { | ||
411 | struct pci_controller *hose; | ||
412 | long result = -EOPNOTSUPP; | ||
413 | |||
414 | hose = pci_bus_to_hose(bus); | ||
415 | if (!hose) | ||
416 | return -ENODEV; | ||
417 | |||
418 | switch (which) { | ||
419 | case IOBASE_BRIDGE_NUMBER: | ||
420 | return (long)hose->first_busno; | ||
421 | case IOBASE_MEMORY: | ||
422 | return (long)hose->pci_mem_offset; | ||
423 | case IOBASE_IO: | ||
424 | return (long)hose->io_base_phys; | ||
425 | case IOBASE_ISA_IO: | ||
426 | return (long)isa_io_base; | ||
427 | case IOBASE_ISA_MEM: | ||
428 | return (long)isa_mem_base; | ||
429 | } | ||
430 | |||
431 | return result; | ||
432 | } | ||
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h index b90dbf8e5cd9..90bd3ed48165 100644 --- a/arch/powerpc/include/asm/pci-bridge.h +++ b/arch/powerpc/include/asm/pci-bridge.h | |||
@@ -171,15 +171,9 @@ static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) | |||
171 | 171 | ||
172 | #ifndef CONFIG_PPC64 | 172 | #ifndef CONFIG_PPC64 |
173 | 173 | ||
174 | static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) | 174 | extern int pci_device_from_OF_node(struct device_node *node, |
175 | { | 175 | u8 *bus, u8 *devfn); |
176 | struct pci_controller *host; | 176 | extern void pci_create_OF_bus_map(void); |
177 | |||
178 | if (bus->self) | ||
179 | return pci_device_to_OF_node(bus->self); | ||
180 | host = pci_bus_to_host(bus); | ||
181 | return host ? host->dn : NULL; | ||
182 | } | ||
183 | 177 | ||
184 | static inline int isa_vaddr_is_ioport(void __iomem *address) | 178 | static inline int isa_vaddr_is_ioport(void __iomem *address) |
185 | { | 179 | { |
@@ -223,17 +217,8 @@ struct pci_dn { | |||
223 | /* Get the pointer to a device_node's pci_dn */ | 217 | /* Get the pointer to a device_node's pci_dn */ |
224 | #define PCI_DN(dn) ((struct pci_dn *) (dn)->data) | 218 | #define PCI_DN(dn) ((struct pci_dn *) (dn)->data) |
225 | 219 | ||
226 | extern struct device_node *fetch_dev_dn(struct pci_dev *dev); | ||
227 | extern void * update_dn_pci_info(struct device_node *dn, void *data); | 220 | extern void * update_dn_pci_info(struct device_node *dn, void *data); |
228 | 221 | ||
229 | /* Get a device_node from a pci_dev. This code must be fast except | ||
230 | * in the case where the sysdata is incorrect and needs to be fixed | ||
231 | * up (this will only happen once). */ | ||
232 | static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev) | ||
233 | { | ||
234 | return dev->dev.of_node ? dev->dev.of_node : fetch_dev_dn(dev); | ||
235 | } | ||
236 | |||
237 | static inline int pci_device_from_OF_node(struct device_node *np, | 222 | static inline int pci_device_from_OF_node(struct device_node *np, |
238 | u8 *bus, u8 *devfn) | 223 | u8 *bus, u8 *devfn) |
239 | { | 224 | { |
@@ -244,14 +229,6 @@ static inline int pci_device_from_OF_node(struct device_node *np, | |||
244 | return 0; | 229 | return 0; |
245 | } | 230 | } |
246 | 231 | ||
247 | static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) | ||
248 | { | ||
249 | if (bus->self) | ||
250 | return pci_device_to_OF_node(bus->self); | ||
251 | else | ||
252 | return bus->dev.of_node; /* Must be root bus (PHB) */ | ||
253 | } | ||
254 | |||
255 | /** Find the bus corresponding to the indicated device node */ | 232 | /** Find the bus corresponding to the indicated device node */ |
256 | extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn); | 233 | extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn); |
257 | 234 | ||
diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h index 7d7790954e02..1f522680ea17 100644 --- a/arch/powerpc/include/asm/pci.h +++ b/arch/powerpc/include/asm/pci.h | |||
@@ -179,8 +179,7 @@ extern int remove_phb_dynamic(struct pci_controller *phb); | |||
179 | extern struct pci_dev *of_create_pci_dev(struct device_node *node, | 179 | extern struct pci_dev *of_create_pci_dev(struct device_node *node, |
180 | struct pci_bus *bus, int devfn); | 180 | struct pci_bus *bus, int devfn); |
181 | 181 | ||
182 | extern void of_scan_pci_bridge(struct device_node *node, | 182 | extern void of_scan_pci_bridge(struct pci_dev *dev); |
183 | struct pci_dev *dev); | ||
184 | 183 | ||
185 | extern void of_scan_bus(struct device_node *node, struct pci_bus *bus); | 184 | extern void of_scan_bus(struct device_node *node, struct pci_bus *bus); |
186 | extern void of_rescan_bus(struct device_node *node, struct pci_bus *bus); | 185 | extern void of_rescan_bus(struct device_node *node, struct pci_bus *bus); |
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h index c189aa5fe1f4..b823536375dc 100644 --- a/arch/powerpc/include/asm/prom.h +++ b/arch/powerpc/include/asm/prom.h | |||
@@ -22,20 +22,6 @@ | |||
22 | 22 | ||
23 | #define HAVE_ARCH_DEVTREE_FIXUPS | 23 | #define HAVE_ARCH_DEVTREE_FIXUPS |
24 | 24 | ||
25 | #ifdef CONFIG_PPC32 | ||
26 | /* | ||
27 | * PCI <-> OF matching functions | ||
28 | * (XXX should these be here?) | ||
29 | */ | ||
30 | struct pci_bus; | ||
31 | struct pci_dev; | ||
32 | extern int pci_device_from_OF_node(struct device_node *node, | ||
33 | u8* bus, u8* devfn); | ||
34 | extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int); | ||
35 | extern struct device_node* pci_device_to_OF_node(struct pci_dev *); | ||
36 | extern void pci_create_OF_bus_map(void); | ||
37 | #endif | ||
38 | |||
39 | /* | 25 | /* |
40 | * OF address retreival & translation | 26 | * OF address retreival & translation |
41 | */ | 27 | */ |
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index 893af2a9cd03..a3c92770e422 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c | |||
@@ -1097,9 +1097,6 @@ void __devinit pcibios_setup_bus_devices(struct pci_bus *bus) | |||
1097 | if (dev->is_added) | 1097 | if (dev->is_added) |
1098 | continue; | 1098 | continue; |
1099 | 1099 | ||
1100 | /* Setup OF node pointer in the device */ | ||
1101 | dev->dev.of_node = pci_device_to_OF_node(dev); | ||
1102 | |||
1103 | /* Fixup NUMA node as it may not be setup yet by the generic | 1100 | /* Fixup NUMA node as it may not be setup yet by the generic |
1104 | * code and is needed by the DMA init | 1101 | * code and is needed by the DMA init |
1105 | */ | 1102 | */ |
@@ -1685,6 +1682,13 @@ int early_find_capability(struct pci_controller *hose, int bus, int devfn, | |||
1685 | return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap); | 1682 | return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap); |
1686 | } | 1683 | } |
1687 | 1684 | ||
1685 | struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus) | ||
1686 | { | ||
1687 | struct pci_controller *hose = bus->sysdata; | ||
1688 | |||
1689 | return of_node_get(hose->dn); | ||
1690 | } | ||
1691 | |||
1688 | /** | 1692 | /** |
1689 | * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus | 1693 | * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus |
1690 | * @hose: Pointer to the PCI host controller instance structure | 1694 | * @hose: Pointer to the PCI host controller instance structure |
@@ -1705,7 +1709,6 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose) | |||
1705 | hose->global_number); | 1709 | hose->global_number); |
1706 | return; | 1710 | return; |
1707 | } | 1711 | } |
1708 | bus->dev.of_node = of_node_get(node); | ||
1709 | bus->secondary = hose->first_busno; | 1712 | bus->secondary = hose->first_busno; |
1710 | hose->bus = bus; | 1713 | hose->bus = bus; |
1711 | 1714 | ||
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c index bedb370459f2..86585508e9c1 100644 --- a/arch/powerpc/kernel/pci_32.c +++ b/arch/powerpc/kernel/pci_32.c | |||
@@ -167,150 +167,26 @@ pcibios_make_OF_bus_map(void) | |||
167 | #endif | 167 | #endif |
168 | } | 168 | } |
169 | 169 | ||
170 | typedef int (*pci_OF_scan_iterator)(struct device_node* node, void* data); | ||
171 | |||
172 | static struct device_node* | ||
173 | scan_OF_pci_childs(struct device_node *parent, pci_OF_scan_iterator filter, void* data) | ||
174 | { | ||
175 | struct device_node *node; | ||
176 | struct device_node* sub_node; | ||
177 | |||
178 | for_each_child_of_node(parent, node) { | ||
179 | const unsigned int *class_code; | ||
180 | |||
181 | if (filter(node, data)) { | ||
182 | of_node_put(node); | ||
183 | return node; | ||
184 | } | ||
185 | |||
186 | /* For PCI<->PCI bridges or CardBus bridges, we go down | ||
187 | * Note: some OFs create a parent node "multifunc-device" as | ||
188 | * a fake root for all functions of a multi-function device, | ||
189 | * we go down them as well. | ||
190 | */ | ||
191 | class_code = of_get_property(node, "class-code", NULL); | ||
192 | if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI && | ||
193 | (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) && | ||
194 | strcmp(node->name, "multifunc-device")) | ||
195 | continue; | ||
196 | sub_node = scan_OF_pci_childs(node, filter, data); | ||
197 | if (sub_node) { | ||
198 | of_node_put(node); | ||
199 | return sub_node; | ||
200 | } | ||
201 | } | ||
202 | return NULL; | ||
203 | } | ||
204 | |||
205 | static struct device_node *scan_OF_for_pci_dev(struct device_node *parent, | ||
206 | unsigned int devfn) | ||
207 | { | ||
208 | struct device_node *np, *cnp; | ||
209 | const u32 *reg; | ||
210 | unsigned int psize; | ||
211 | |||
212 | for_each_child_of_node(parent, np) { | ||
213 | reg = of_get_property(np, "reg", &psize); | ||
214 | if (reg && psize >= 4 && ((reg[0] >> 8) & 0xff) == devfn) | ||
215 | return np; | ||
216 | |||
217 | /* Note: some OFs create a parent node "multifunc-device" as | ||
218 | * a fake root for all functions of a multi-function device, | ||
219 | * we go down them as well. */ | ||
220 | if (!strcmp(np->name, "multifunc-device")) { | ||
221 | cnp = scan_OF_for_pci_dev(np, devfn); | ||
222 | if (cnp) | ||
223 | return cnp; | ||
224 | } | ||
225 | } | ||
226 | return NULL; | ||
227 | } | ||
228 | |||
229 | |||
230 | static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus) | ||
231 | { | ||
232 | struct device_node *parent, *np; | ||
233 | |||
234 | /* Are we a root bus ? */ | ||
235 | if (bus->self == NULL || bus->parent == NULL) { | ||
236 | struct pci_controller *hose = pci_bus_to_host(bus); | ||
237 | if (hose == NULL) | ||
238 | return NULL; | ||
239 | return of_node_get(hose->dn); | ||
240 | } | ||
241 | |||
242 | /* not a root bus, we need to get our parent */ | ||
243 | parent = scan_OF_for_pci_bus(bus->parent); | ||
244 | if (parent == NULL) | ||
245 | return NULL; | ||
246 | |||
247 | /* now iterate for children for a match */ | ||
248 | np = scan_OF_for_pci_dev(parent, bus->self->devfn); | ||
249 | of_node_put(parent); | ||
250 | |||
251 | return np; | ||
252 | } | ||
253 | |||
254 | /* | ||
255 | * Scans the OF tree for a device node matching a PCI device | ||
256 | */ | ||
257 | struct device_node * | ||
258 | pci_busdev_to_OF_node(struct pci_bus *bus, int devfn) | ||
259 | { | ||
260 | struct device_node *parent, *np; | ||
261 | |||
262 | pr_debug("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn); | ||
263 | parent = scan_OF_for_pci_bus(bus); | ||
264 | if (parent == NULL) | ||
265 | return NULL; | ||
266 | pr_debug(" parent is %s\n", parent ? parent->full_name : "<NULL>"); | ||
267 | np = scan_OF_for_pci_dev(parent, devfn); | ||
268 | of_node_put(parent); | ||
269 | pr_debug(" result is %s\n", np ? np->full_name : "<NULL>"); | ||
270 | |||
271 | /* XXX most callers don't release the returned node | ||
272 | * mostly because ppc64 doesn't increase the refcount, | ||
273 | * we need to fix that. | ||
274 | */ | ||
275 | return np; | ||
276 | } | ||
277 | EXPORT_SYMBOL(pci_busdev_to_OF_node); | ||
278 | |||
279 | struct device_node* | ||
280 | pci_device_to_OF_node(struct pci_dev *dev) | ||
281 | { | ||
282 | return pci_busdev_to_OF_node(dev->bus, dev->devfn); | ||
283 | } | ||
284 | EXPORT_SYMBOL(pci_device_to_OF_node); | ||
285 | |||
286 | static int | ||
287 | find_OF_pci_device_filter(struct device_node* node, void* data) | ||
288 | { | ||
289 | return ((void *)node == data); | ||
290 | } | ||
291 | 170 | ||
292 | /* | 171 | /* |
293 | * Returns the PCI device matching a given OF node | 172 | * Returns the PCI device matching a given OF node |
294 | */ | 173 | */ |
295 | int | 174 | int pci_device_from_OF_node(struct device_node *node, u8 *bus, u8 *devfn) |
296 | pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn) | ||
297 | { | 175 | { |
298 | const unsigned int *reg; | 176 | struct pci_dev *dev = NULL; |
299 | struct pci_controller* hose; | 177 | const __be32 *reg; |
300 | struct pci_dev* dev = NULL; | 178 | int size; |
301 | 179 | ||
302 | /* Make sure it's really a PCI device */ | 180 | /* Check if it might have a chance to be a PCI device */ |
303 | hose = pci_find_hose_for_OF_device(node); | 181 | if (!pci_find_hose_for_OF_device(node)) |
304 | if (!hose || !hose->dn) | ||
305 | return -ENODEV; | ||
306 | if (!scan_OF_pci_childs(hose->dn, | ||
307 | find_OF_pci_device_filter, (void *)node)) | ||
308 | return -ENODEV; | 182 | return -ENODEV; |
309 | reg = of_get_property(node, "reg", NULL); | 183 | |
310 | if (!reg) | 184 | reg = of_get_property(node, "reg", &size); |
185 | if (!reg || size < 5 * sizeof(u32)) | ||
311 | return -ENODEV; | 186 | return -ENODEV; |
312 | *bus = (reg[0] >> 16) & 0xff; | 187 | |
313 | *devfn = ((reg[0] >> 8) & 0xff); | 188 | *bus = (be32_to_cpup(®[0]) >> 16) & 0xff; |
189 | *devfn = (be32_to_cpup(®[0]) >> 8) & 0xff; | ||
314 | 190 | ||
315 | /* Ok, here we need some tweak. If we have already renumbered | 191 | /* Ok, here we need some tweak. If we have already renumbered |
316 | * all busses, we can't rely on the OF bus number any more. | 192 | * all busses, we can't rely on the OF bus number any more. |
diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c index 6baabc13306a..478f8d78716b 100644 --- a/arch/powerpc/kernel/pci_dn.c +++ b/arch/powerpc/kernel/pci_dn.c | |||
@@ -142,53 +142,6 @@ void __devinit pci_devs_phb_init_dynamic(struct pci_controller *phb) | |||
142 | traverse_pci_devices(dn, update_dn_pci_info, phb); | 142 | traverse_pci_devices(dn, update_dn_pci_info, phb); |
143 | } | 143 | } |
144 | 144 | ||
145 | /* | ||
146 | * Traversal func that looks for a <busno,devfcn> value. | ||
147 | * If found, the pci_dn is returned (thus terminating the traversal). | ||
148 | */ | ||
149 | static void *is_devfn_node(struct device_node *dn, void *data) | ||
150 | { | ||
151 | int busno = ((unsigned long)data >> 8) & 0xff; | ||
152 | int devfn = ((unsigned long)data) & 0xff; | ||
153 | struct pci_dn *pci = dn->data; | ||
154 | |||
155 | if (pci && (devfn == pci->devfn) && (busno == pci->busno)) | ||
156 | return dn; | ||
157 | return NULL; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * This is the "slow" path for looking up a device_node from a | ||
162 | * pci_dev. It will hunt for the device under its parent's | ||
163 | * phb and then update of_node pointer. | ||
164 | * | ||
165 | * It may also do fixups on the actual device since this happens | ||
166 | * on the first read/write. | ||
167 | * | ||
168 | * Note that it also must deal with devices that don't exist. | ||
169 | * In this case it may probe for real hardware ("just in case") | ||
170 | * and add a device_node to the device tree if necessary. | ||
171 | * | ||
172 | * Is this function necessary anymore now that dev->dev.of_node is | ||
173 | * used to store the node pointer? | ||
174 | * | ||
175 | */ | ||
176 | struct device_node *fetch_dev_dn(struct pci_dev *dev) | ||
177 | { | ||
178 | struct pci_controller *phb = dev->sysdata; | ||
179 | struct device_node *dn; | ||
180 | unsigned long searchval = (dev->bus->number << 8) | dev->devfn; | ||
181 | |||
182 | if (WARN_ON(!phb)) | ||
183 | return NULL; | ||
184 | |||
185 | dn = traverse_pci_devices(phb->dn, is_devfn_node, (void *)searchval); | ||
186 | if (dn) | ||
187 | dev->dev.of_node = dn; | ||
188 | return dn; | ||
189 | } | ||
190 | EXPORT_SYMBOL(fetch_dev_dn); | ||
191 | |||
192 | /** | 145 | /** |
193 | * pci_devs_phb_init - Initialize phbs and pci devs under them. | 146 | * pci_devs_phb_init - Initialize phbs and pci devs under them. |
194 | * | 147 | * |
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c index 1e89a72fd030..fe0a5ad6f73e 100644 --- a/arch/powerpc/kernel/pci_of_scan.c +++ b/arch/powerpc/kernel/pci_of_scan.c | |||
@@ -202,9 +202,9 @@ EXPORT_SYMBOL(of_create_pci_dev); | |||
202 | * this routine in turn call of_scan_bus() recusively to scan for more child | 202 | * this routine in turn call of_scan_bus() recusively to scan for more child |
203 | * devices. | 203 | * devices. |
204 | */ | 204 | */ |
205 | void __devinit of_scan_pci_bridge(struct device_node *node, | 205 | void __devinit of_scan_pci_bridge(struct pci_dev *dev) |
206 | struct pci_dev *dev) | ||
207 | { | 206 | { |
207 | struct device_node *node = dev->dev.of_node; | ||
208 | struct pci_bus *bus; | 208 | struct pci_bus *bus; |
209 | const u32 *busrange, *ranges; | 209 | const u32 *busrange, *ranges; |
210 | int len, i, mode; | 210 | int len, i, mode; |
@@ -238,7 +238,6 @@ void __devinit of_scan_pci_bridge(struct device_node *node, | |||
238 | bus->primary = dev->bus->number; | 238 | bus->primary = dev->bus->number; |
239 | bus->subordinate = busrange[1]; | 239 | bus->subordinate = busrange[1]; |
240 | bus->bridge_ctl = 0; | 240 | bus->bridge_ctl = 0; |
241 | bus->dev.of_node = of_node_get(node); | ||
242 | 241 | ||
243 | /* parse ranges property */ | 242 | /* parse ranges property */ |
244 | /* PCI #address-cells == 3 and #size-cells == 2 always */ | 243 | /* PCI #address-cells == 3 and #size-cells == 2 always */ |
@@ -335,9 +334,7 @@ static void __devinit __of_scan_bus(struct device_node *node, | |||
335 | list_for_each_entry(dev, &bus->devices, bus_list) { | 334 | list_for_each_entry(dev, &bus->devices, bus_list) { |
336 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || | 335 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
337 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { | 336 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
338 | struct device_node *child = pci_device_to_OF_node(dev); | 337 | of_scan_pci_bridge(dev); |
339 | if (child) | ||
340 | of_scan_pci_bridge(child, dev); | ||
341 | } | 338 | } |
342 | } | 339 | } |
343 | } | 340 | } |
diff --git a/arch/powerpc/platforms/powermac/pci.c b/arch/powerpc/platforms/powermac/pci.c index f33e08d573ce..abe8d7e2ebeb 100644 --- a/arch/powerpc/platforms/powermac/pci.c +++ b/arch/powerpc/platforms/powermac/pci.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/bootmem.h> | 18 | #include <linux/bootmem.h> |
19 | #include <linux/irq.h> | 19 | #include <linux/irq.h> |
20 | #include <linux/of_pci.h> | ||
20 | 21 | ||
21 | #include <asm/sections.h> | 22 | #include <asm/sections.h> |
22 | #include <asm/io.h> | 23 | #include <asm/io.h> |
@@ -235,7 +236,7 @@ static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset) | |||
235 | 236 | ||
236 | if (offset >= 0x100) | 237 | if (offset >= 0x100) |
237 | return PCIBIOS_BAD_REGISTER_NUMBER; | 238 | return PCIBIOS_BAD_REGISTER_NUMBER; |
238 | np = pci_busdev_to_OF_node(bus, devfn); | 239 | np = of_pci_find_child_device(bus->dev.of_node, devfn); |
239 | if (np == NULL) | 240 | if (np == NULL) |
240 | return PCIBIOS_DEVICE_NOT_FOUND; | 241 | return PCIBIOS_DEVICE_NOT_FOUND; |
241 | 242 | ||
diff --git a/arch/sparc/include/asm/pci_32.h b/arch/sparc/include/asm/pci_32.h index 862e3ce92b15..02939abd356c 100644 --- a/arch/sparc/include/asm/pci_32.h +++ b/arch/sparc/include/asm/pci_32.h | |||
@@ -42,9 +42,6 @@ static inline void pci_dma_burst_advice(struct pci_dev *pdev, | |||
42 | } | 42 | } |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | struct device_node; | ||
46 | extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev); | ||
47 | |||
48 | #endif /* __KERNEL__ */ | 45 | #endif /* __KERNEL__ */ |
49 | 46 | ||
50 | #ifndef CONFIG_LEON_PCI | 47 | #ifndef CONFIG_LEON_PCI |
diff --git a/arch/sparc/include/asm/pci_64.h b/arch/sparc/include/asm/pci_64.h index 948b686ec089..2614d96141c9 100644 --- a/arch/sparc/include/asm/pci_64.h +++ b/arch/sparc/include/asm/pci_64.h | |||
@@ -91,9 +91,6 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) | |||
91 | return PCI_IRQ_NONE; | 91 | return PCI_IRQ_NONE; |
92 | } | 92 | } |
93 | 93 | ||
94 | struct device_node; | ||
95 | extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev); | ||
96 | |||
97 | #define HAVE_ARCH_PCI_RESOURCE_TO_USER | 94 | #define HAVE_ARCH_PCI_RESOURCE_TO_USER |
98 | extern void pci_resource_to_user(const struct pci_dev *dev, int bar, | 95 | extern void pci_resource_to_user(const struct pci_dev *dev, int bar, |
99 | const struct resource *rsrc, | 96 | const struct resource *rsrc, |
diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c index 713dc91020a6..80a87e2a3e7c 100644 --- a/arch/sparc/kernel/pci.c +++ b/arch/sparc/kernel/pci.c | |||
@@ -284,7 +284,7 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, | |||
284 | dev->sysdata = node; | 284 | dev->sysdata = node; |
285 | dev->dev.parent = bus->bridge; | 285 | dev->dev.parent = bus->bridge; |
286 | dev->dev.bus = &pci_bus_type; | 286 | dev->dev.bus = &pci_bus_type; |
287 | dev->dev.of_node = node; | 287 | dev->dev.of_node = of_node_get(node); |
288 | dev->devfn = devfn; | 288 | dev->devfn = devfn; |
289 | dev->multifunction = 0; /* maybe a lie? */ | 289 | dev->multifunction = 0; /* maybe a lie? */ |
290 | set_pcie_port_type(dev); | 290 | set_pcie_port_type(dev); |
@@ -1021,12 +1021,6 @@ void arch_teardown_msi_irq(unsigned int irq) | |||
1021 | } | 1021 | } |
1022 | #endif /* !(CONFIG_PCI_MSI) */ | 1022 | #endif /* !(CONFIG_PCI_MSI) */ |
1023 | 1023 | ||
1024 | struct device_node *pci_device_to_OF_node(struct pci_dev *pdev) | ||
1025 | { | ||
1026 | return pdev->dev.of_node; | ||
1027 | } | ||
1028 | EXPORT_SYMBOL(pci_device_to_OF_node); | ||
1029 | |||
1030 | static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit) | 1024 | static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit) |
1031 | { | 1025 | { |
1032 | struct pci_dev *ali_isa_bridge; | 1026 | struct pci_dev *ali_isa_bridge; |
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c index 948601a066ff..a19f04195478 100644 --- a/arch/sparc/kernel/pcic.c +++ b/arch/sparc/kernel/pcic.c | |||
@@ -885,14 +885,6 @@ int pcibios_assign_resource(struct pci_dev *pdev, int resource) | |||
885 | return -ENXIO; | 885 | return -ENXIO; |
886 | } | 886 | } |
887 | 887 | ||
888 | struct device_node *pci_device_to_OF_node(struct pci_dev *pdev) | ||
889 | { | ||
890 | struct pcidev_cookie *pc = pdev->sysdata; | ||
891 | |||
892 | return pc->prom_node; | ||
893 | } | ||
894 | EXPORT_SYMBOL(pci_device_to_OF_node); | ||
895 | |||
896 | /* | 888 | /* |
897 | * This probably belongs here rather than ioport.c because | 889 | * This probably belongs here rather than ioport.c because |
898 | * we do not want this crud linked into SBus kernels. | 890 | * we do not want this crud linked into SBus kernels. |
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h index 971e0b46446e..df1287019e6d 100644 --- a/arch/x86/include/asm/prom.h +++ b/arch/x86/include/asm/prom.h | |||
@@ -30,17 +30,6 @@ extern void add_dtb(u64 data); | |||
30 | extern void x86_add_irq_domains(void); | 30 | extern void x86_add_irq_domains(void); |
31 | void __cpuinit x86_of_pci_init(void); | 31 | void __cpuinit x86_of_pci_init(void); |
32 | void x86_dtb_init(void); | 32 | void x86_dtb_init(void); |
33 | |||
34 | static inline struct device_node *pci_device_to_OF_node(struct pci_dev *pdev) | ||
35 | { | ||
36 | return pdev ? pdev->dev.of_node : NULL; | ||
37 | } | ||
38 | |||
39 | static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) | ||
40 | { | ||
41 | return pci_device_to_OF_node(bus->self); | ||
42 | } | ||
43 | |||
44 | #else | 33 | #else |
45 | static inline void add_dtb(u64 data) { } | 34 | static inline void add_dtb(u64 data) { } |
46 | static inline void x86_add_irq_domains(void) { } | 35 | static inline void x86_add_irq_domains(void) { } |
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c index 9aeb78a23de4..a621f3427685 100644 --- a/arch/x86/kernel/devicetree.c +++ b/arch/x86/kernel/devicetree.c | |||
@@ -134,6 +134,24 @@ static int __init add_bus_probe(void) | |||
134 | module_init(add_bus_probe); | 134 | module_init(add_bus_probe); |
135 | 135 | ||
136 | #ifdef CONFIG_PCI | 136 | #ifdef CONFIG_PCI |
137 | struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus) | ||
138 | { | ||
139 | struct device_node *np; | ||
140 | |||
141 | for_each_node_by_type(np, "pci") { | ||
142 | const void *prop; | ||
143 | unsigned int bus_min; | ||
144 | |||
145 | prop = of_get_property(np, "bus-range", NULL); | ||
146 | if (!prop) | ||
147 | continue; | ||
148 | bus_min = be32_to_cpup(prop); | ||
149 | if (bus->number == bus_min) | ||
150 | return np; | ||
151 | } | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
137 | static int x86_of_pci_irq_enable(struct pci_dev *dev) | 155 | static int x86_of_pci_irq_enable(struct pci_dev *dev) |
138 | { | 156 | { |
139 | struct of_irq oirq; | 157 | struct of_irq oirq; |
@@ -165,50 +183,8 @@ static void x86_of_pci_irq_disable(struct pci_dev *dev) | |||
165 | 183 | ||
166 | void __cpuinit x86_of_pci_init(void) | 184 | void __cpuinit x86_of_pci_init(void) |
167 | { | 185 | { |
168 | struct device_node *np; | ||
169 | |||
170 | pcibios_enable_irq = x86_of_pci_irq_enable; | 186 | pcibios_enable_irq = x86_of_pci_irq_enable; |
171 | pcibios_disable_irq = x86_of_pci_irq_disable; | 187 | pcibios_disable_irq = x86_of_pci_irq_disable; |
172 | |||
173 | for_each_node_by_type(np, "pci") { | ||
174 | const void *prop; | ||
175 | struct pci_bus *bus; | ||
176 | unsigned int bus_min; | ||
177 | struct device_node *child; | ||
178 | |||
179 | prop = of_get_property(np, "bus-range", NULL); | ||
180 | if (!prop) | ||
181 | continue; | ||
182 | bus_min = be32_to_cpup(prop); | ||
183 | |||
184 | bus = pci_find_bus(0, bus_min); | ||
185 | if (!bus) { | ||
186 | printk(KERN_ERR "Can't find a node for bus %s.\n", | ||
187 | np->full_name); | ||
188 | continue; | ||
189 | } | ||
190 | |||
191 | if (bus->self) | ||
192 | bus->self->dev.of_node = np; | ||
193 | else | ||
194 | bus->dev.of_node = np; | ||
195 | |||
196 | for_each_child_of_node(np, child) { | ||
197 | struct pci_dev *dev; | ||
198 | u32 devfn; | ||
199 | |||
200 | prop = of_get_property(child, "reg", NULL); | ||
201 | if (!prop) | ||
202 | continue; | ||
203 | |||
204 | devfn = (be32_to_cpup(prop) >> 8) & 0xff; | ||
205 | dev = pci_get_slot(bus, devfn); | ||
206 | if (!dev) | ||
207 | continue; | ||
208 | dev->dev.of_node = child; | ||
209 | pci_dev_put(dev); | ||
210 | } | ||
211 | } | ||
212 | } | 188 | } |
213 | #endif | 189 | #endif |
214 | 190 | ||