aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/microblaze/include/asm/pci-bridge.h14
-rw-r--r--arch/microblaze/include/asm/prom.h15
-rw-r--r--arch/microblaze/pci/pci_32.c40
-rw-r--r--arch/powerpc/include/asm/pci-bridge.h35
-rw-r--r--arch/powerpc/include/asm/pci.h3
-rw-r--r--arch/powerpc/include/asm/prom.h14
-rw-r--r--arch/powerpc/kernel/pci-common.c11
-rw-r--r--arch/powerpc/kernel/pci_32.c150
-rw-r--r--arch/powerpc/kernel/pci_dn.c47
-rw-r--r--arch/powerpc/kernel/pci_of_scan.c9
-rw-r--r--arch/powerpc/platforms/powermac/pci.c3
-rw-r--r--arch/sparc/kernel/pci.c2
-rw-r--r--drivers/of/Kconfig8
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/of_pci.c112
-rw-r--r--drivers/of/of_pci_irq.c92
-rw-r--r--drivers/pci/Makefile2
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c2
-rw-r--r--drivers/pci/of.c61
-rw-r--r--drivers/pci/probe.c7
-rw-r--r--include/linux/of_pci.h5
-rw-r--r--include/linux/pci.h18
22 files changed, 275 insertions, 376 deletions
diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
index 746df91e5796..728f8d6a59a4 100644
--- a/arch/microblaze/include/asm/pci-bridge.h
+++ b/arch/microblaze/include/asm/pci-bridge.h
@@ -105,19 +105,19 @@ struct pci_controller {
105}; 105};
106 106
107#ifdef CONFIG_PCI 107#ifdef CONFIG_PCI
108static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) 108static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
109{ 109{
110 return bus->sysdata; 110 return dev->dev.of_node;
111} 111}
112 112
113static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) 113static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
114{ 114{
115 struct pci_controller *host; 115 return bus->dev.of_node;
116}
116 117
117 if (bus->self) 118static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
118 return pci_device_to_OF_node(bus->self); 119{
119 host = pci_bus_to_host(bus); 120 return bus->sysdata;
120 return host ? host->dn : NULL;
121} 121}
122 122
123static inline int isa_vaddr_is_ioport(void __iomem *address) 123static inline int isa_vaddr_is_ioport(void __iomem *address)
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 @@
29extern int early_uartlite_console(void); 29extern int early_uartlite_console(void);
30extern int early_uart16550_console(void); 30extern int early_uart16550_console(void);
31 31
32#ifdef CONFIG_PCI
33/*
34 * PCI <-> OF matching functions
35 * (XXX should these be here?)
36 */
37struct pci_bus;
38struct pci_dev;
39extern int pci_device_from_OF_node(struct device_node *node,
40 u8 *bus, u8 *devfn);
41extern struct device_node *pci_busdev_to_OF_node(struct pci_bus *bus,
42 int devfn);
43extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev);
44extern 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/pci_32.c b/arch/microblaze/pci/pci_32.c
index 92728a6cfd80..2fa95069e6ba 100644
--- a/arch/microblaze/pci/pci_32.c
+++ b/arch/microblaze/pci/pci_32.c
@@ -210,38 +210,6 @@ static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
210 return np; 210 return np;
211} 211}
212 212
213/*
214 * Scans the OF tree for a device node matching a PCI device
215 */
216struct device_node *
217pci_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}
236EXPORT_SYMBOL(pci_busdev_to_OF_node);
237
238struct device_node*
239pci_device_to_OF_node(struct pci_dev *dev)
240{
241 return pci_busdev_to_OF_node(dev->bus, dev->devfn);
242}
243EXPORT_SYMBOL(pci_device_to_OF_node);
244
245static int 213static int
246find_OF_pci_device_filter(struct device_node *node, void *data) 214find_OF_pci_device_filter(struct device_node *node, void *data)
247{ 215{
@@ -315,6 +283,13 @@ pci_create_OF_bus_map(void)
315 } 283 }
316} 284}
317 285
286struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
287{
288 struct pci_controller *hose = bus->sysdata;
289
290 return of_node_get(hose->dn);
291}
292
318static void __devinit pcibios_scan_phb(struct pci_controller *hose) 293static void __devinit pcibios_scan_phb(struct pci_controller *hose)
319{ 294{
320 struct pci_bus *bus; 295 struct pci_bus *bus;
@@ -332,7 +307,6 @@ static void __devinit pcibios_scan_phb(struct pci_controller *hose)
332 hose->global_number); 307 hose->global_number);
333 return; 308 return;
334 } 309 }
335 bus.dev->of_node = of_node_get(node);
336 bus->secondary = hose->first_busno; 310 bus->secondary = hose->first_busno;
337 hose->bus = bus; 311 hose->bus = bus;
338 312
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index b90dbf8e5cd9..3e6869476e55 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -169,18 +169,22 @@ static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
169 return bus->sysdata; 169 return bus->sysdata;
170} 170}
171 171
172#ifndef CONFIG_PPC64 172static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
173{
174 return dev->dev.of_node;
175}
173 176
174static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) 177static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
175{ 178{
176 struct pci_controller *host; 179 return bus->dev.of_node;
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} 180}
183 181
182#ifndef CONFIG_PPC64
183
184extern int pci_device_from_OF_node(struct device_node *node,
185 u8 *bus, u8 *devfn);
186extern void pci_create_OF_bus_map(void);
187
184static inline int isa_vaddr_is_ioport(void __iomem *address) 188static inline int isa_vaddr_is_ioport(void __iomem *address)
185{ 189{
186 /* No specific ISA handling on ppc32 at this stage, it 190 /* No specific ISA handling on ppc32 at this stage, it
@@ -223,17 +227,8 @@ struct pci_dn {
223/* Get the pointer to a device_node's pci_dn */ 227/* Get the pointer to a device_node's pci_dn */
224#define PCI_DN(dn) ((struct pci_dn *) (dn)->data) 228#define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
225 229
226extern struct device_node *fetch_dev_dn(struct pci_dev *dev);
227extern void * update_dn_pci_info(struct device_node *dn, void *data); 230extern void * update_dn_pci_info(struct device_node *dn, void *data);
228 231
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). */
232static 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
237static inline int pci_device_from_OF_node(struct device_node *np, 232static inline int pci_device_from_OF_node(struct device_node *np,
238 u8 *bus, u8 *devfn) 233 u8 *bus, u8 *devfn)
239{ 234{
@@ -244,14 +239,6 @@ static inline int pci_device_from_OF_node(struct device_node *np,
244 return 0; 239 return 0;
245} 240}
246 241
247static 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 */ 242/** Find the bus corresponding to the indicated device node */
256extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn); 243extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn);
257 244
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);
179extern struct pci_dev *of_create_pci_dev(struct device_node *node, 179extern 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
182extern void of_scan_pci_bridge(struct device_node *node, 182extern void of_scan_pci_bridge(struct pci_dev *dev);
183 struct pci_dev *dev);
184 183
185extern void of_scan_bus(struct device_node *node, struct pci_bus *bus); 184extern void of_scan_bus(struct device_node *node, struct pci_bus *bus);
186extern void of_rescan_bus(struct device_node *node, struct pci_bus *bus); 185extern 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 */
30struct pci_bus;
31struct pci_dev;
32extern int pci_device_from_OF_node(struct device_node *node,
33 u8* bus, u8* devfn);
34extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
35extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
36extern 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
1685struct 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
170typedef int (*pci_OF_scan_iterator)(struct device_node* node, void* data);
171
172static struct device_node*
173scan_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
205static 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
230static 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 */
257struct device_node *
258pci_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}
277EXPORT_SYMBOL(pci_busdev_to_OF_node);
278
279struct device_node*
280pci_device_to_OF_node(struct pci_dev *dev)
281{
282 return pci_busdev_to_OF_node(dev->bus, dev->devfn);
283}
284EXPORT_SYMBOL(pci_device_to_OF_node);
285
286static int
287find_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 */
295int 174int pci_device_from_OF_node(struct device_node *node, u8 *bus, u8 *devfn)
296pci_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(&reg[0]) >> 16) & 0xff;
189 *devfn = (be32_to_cpup(&reg[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 */
149static 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 */
176struct 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}
190EXPORT_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 */
205void __devinit of_scan_pci_bridge(struct device_node *node, 205void __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/kernel/pci.c b/arch/sparc/kernel/pci.c
index 713dc91020a6..e539d23dec9d 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);
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index d06a6374ed6c..cac63c9f49ae 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -71,8 +71,14 @@ config OF_MDIO
71 71
72config OF_PCI 72config OF_PCI
73 def_tristate PCI 73 def_tristate PCI
74 depends on PCI && (PPC || MICROBLAZE || X86) 74 depends on PCI
75 help 75 help
76 OpenFirmware PCI bus accessors 76 OpenFirmware PCI bus accessors
77 77
78config OF_PCI_IRQ
79 def_tristate PCI
80 depends on OF_PCI && OF_IRQ
81 help
82 OpenFirmware PCI IRQ routing helpers
83
78endmenu # OF 84endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index f7861ed2f287..dccb1176be57 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_OF_NET) += of_net.o
10obj-$(CONFIG_OF_SPI) += of_spi.o 10obj-$(CONFIG_OF_SPI) += of_spi.o
11obj-$(CONFIG_OF_MDIO) += of_mdio.o 11obj-$(CONFIG_OF_MDIO) += of_mdio.o
12obj-$(CONFIG_OF_PCI) += of_pci.o 12obj-$(CONFIG_OF_PCI) += of_pci.o
13obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index ac1ec54e4fd5..ec7b060ae952 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -1,92 +1,40 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/of_pci.h> 2#include <linux/of_pci.h>
3#include <linux/of_irq.h>
4#include <asm/prom.h> 3#include <asm/prom.h>
5 4
6/** 5static inline int __of_pci_pci_compare(struct device_node *node,
7 * of_irq_map_pci - Resolve the interrupt for a PCI device 6 unsigned int devfn)
8 * @pdev: the device whose interrupt is to be resolved
9 * @out_irq: structure of_irq filled by this function
10 *
11 * This function resolves the PCI interrupt for a given PCI device. If a
12 * device-node exists for a given pci_dev, it will use normal OF tree
13 * walking. If not, it will implement standard swizzling and walk up the
14 * PCI tree until an device-node is found, at which point it will finish
15 * resolving using the OF tree walking.
16 */
17int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
18{ 7{
19 struct device_node *dn, *ppnode; 8 unsigned int size;
20 struct pci_dev *ppdev; 9 const __be32 *reg = of_get_property(node, "reg", &size);
21 u32 lspec;
22 __be32 lspec_be;
23 __be32 laddr[3];
24 u8 pin;
25 int rc;
26 10
27 /* Check if we have a device node, if yes, fallback to standard 11 if (!reg || size < 5 * sizeof(__be32))
28 * device tree parsing 12 return 0;
29 */ 13 return ((be32_to_cpup(&reg[0]) >> 8) & 0xff) == devfn;
30 dn = pci_device_to_OF_node(pdev); 14}
31 if (dn) {
32 rc = of_irq_map_one(dn, 0, out_irq);
33 if (!rc)
34 return rc;
35 }
36
37 /* Ok, we don't, time to have fun. Let's start by building up an
38 * interrupt spec. we assume #interrupt-cells is 1, which is standard
39 * for PCI. If you do different, then don't use that routine.
40 */
41 rc = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin);
42 if (rc != 0)
43 return rc;
44 /* No pin, exit */
45 if (pin == 0)
46 return -ENODEV;
47
48 /* Now we walk up the PCI tree */
49 lspec = pin;
50 for (;;) {
51 /* Get the pci_dev of our parent */
52 ppdev = pdev->bus->self;
53
54 /* Ouch, it's a host bridge... */
55 if (ppdev == NULL) {
56 ppnode = pci_bus_to_OF_node(pdev->bus);
57
58 /* No node for host bridge ? give up */
59 if (ppnode == NULL)
60 return -EINVAL;
61 } else {
62 /* We found a P2P bridge, check if it has a node */
63 ppnode = pci_device_to_OF_node(ppdev);
64 }
65
66 /* Ok, we have found a parent with a device-node, hand over to
67 * the OF parsing code.
68 * We build a unit address from the linux device to be used for
69 * resolution. Note that we use the linux bus number which may
70 * not match your firmware bus numbering.
71 * Fortunately, in most cases, interrupt-map-mask doesn't
72 * include the bus number as part of the matching.
73 * You should still be careful about that though if you intend
74 * to rely on this function (you ship a firmware that doesn't
75 * create device nodes for all PCI devices).
76 */
77 if (ppnode)
78 break;
79 15
80 /* We can only get here if we hit a P2P bridge with no node, 16struct device_node *of_pci_find_child_device(struct device_node *parent,
81 * let's do standard swizzling and try again 17 unsigned int devfn)
18{
19 struct device_node *node, *node2;
20
21 for_each_child_of_node(parent, node) {
22 if (__of_pci_pci_compare(node, devfn))
23 return node;
24 /*
25 * Some OFs create a parent node "multifunc-device" as
26 * a fake root for all functions of a multi-function
27 * device we go down them as well.
82 */ 28 */
83 lspec = pci_swizzle_interrupt_pin(pdev, lspec); 29 if (!strcmp(node->name, "multifunc-device")) {
84 pdev = ppdev; 30 for_each_child_of_node(node, node2) {
31 if (__of_pci_pci_compare(node2, devfn)) {
32 of_node_put(node);
33 return node2;
34 }
35 }
36 }
85 } 37 }
86 38 return NULL;
87 lspec_be = cpu_to_be32(lspec);
88 laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8));
89 laddr[1] = laddr[2] = cpu_to_be32(0);
90 return of_irq_map_raw(ppnode, &lspec_be, 1, laddr, out_irq);
91} 39}
92EXPORT_SYMBOL_GPL(of_irq_map_pci); 40EXPORT_SYMBOL_GPL(of_pci_find_child_device);
diff --git a/drivers/of/of_pci_irq.c b/drivers/of/of_pci_irq.c
new file mode 100644
index 000000000000..ac1ec54e4fd5
--- /dev/null
+++ b/drivers/of/of_pci_irq.c
@@ -0,0 +1,92 @@
1#include <linux/kernel.h>
2#include <linux/of_pci.h>
3#include <linux/of_irq.h>
4#include <asm/prom.h>
5
6/**
7 * of_irq_map_pci - Resolve the interrupt for a PCI device
8 * @pdev: the device whose interrupt is to be resolved
9 * @out_irq: structure of_irq filled by this function
10 *
11 * This function resolves the PCI interrupt for a given PCI device. If a
12 * device-node exists for a given pci_dev, it will use normal OF tree
13 * walking. If not, it will implement standard swizzling and walk up the
14 * PCI tree until an device-node is found, at which point it will finish
15 * resolving using the OF tree walking.
16 */
17int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
18{
19 struct device_node *dn, *ppnode;
20 struct pci_dev *ppdev;
21 u32 lspec;
22 __be32 lspec_be;
23 __be32 laddr[3];
24 u8 pin;
25 int rc;
26
27 /* Check if we have a device node, if yes, fallback to standard
28 * device tree parsing
29 */
30 dn = pci_device_to_OF_node(pdev);
31 if (dn) {
32 rc = of_irq_map_one(dn, 0, out_irq);
33 if (!rc)
34 return rc;
35 }
36
37 /* Ok, we don't, time to have fun. Let's start by building up an
38 * interrupt spec. we assume #interrupt-cells is 1, which is standard
39 * for PCI. If you do different, then don't use that routine.
40 */
41 rc = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin);
42 if (rc != 0)
43 return rc;
44 /* No pin, exit */
45 if (pin == 0)
46 return -ENODEV;
47
48 /* Now we walk up the PCI tree */
49 lspec = pin;
50 for (;;) {
51 /* Get the pci_dev of our parent */
52 ppdev = pdev->bus->self;
53
54 /* Ouch, it's a host bridge... */
55 if (ppdev == NULL) {
56 ppnode = pci_bus_to_OF_node(pdev->bus);
57
58 /* No node for host bridge ? give up */
59 if (ppnode == NULL)
60 return -EINVAL;
61 } else {
62 /* We found a P2P bridge, check if it has a node */
63 ppnode = pci_device_to_OF_node(ppdev);
64 }
65
66 /* Ok, we have found a parent with a device-node, hand over to
67 * the OF parsing code.
68 * We build a unit address from the linux device to be used for
69 * resolution. Note that we use the linux bus number which may
70 * not match your firmware bus numbering.
71 * Fortunately, in most cases, interrupt-map-mask doesn't
72 * include the bus number as part of the matching.
73 * You should still be careful about that though if you intend
74 * to rely on this function (you ship a firmware that doesn't
75 * create device nodes for all PCI devices).
76 */
77 if (ppnode)
78 break;
79
80 /* We can only get here if we hit a P2P bridge with no node,
81 * let's do standard swizzling and try again
82 */
83 lspec = pci_swizzle_interrupt_pin(pdev, lspec);
84 pdev = ppdev;
85 }
86
87 lspec_be = cpu_to_be32(lspec);
88 laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8));
89 laddr[1] = laddr[2] = cpu_to_be32(0);
90 return of_irq_map_raw(ppnode, &lspec_be, 1, laddr, out_irq);
91}
92EXPORT_SYMBOL_GPL(of_irq_map_pci);
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index c85f744270a5..f27f4a1488a1 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -70,4 +70,6 @@ obj-$(CONFIG_PCI_STUB) += pci-stub.o
70 70
71obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o 71obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
72 72
73obj-$(CONFIG_OF) += of.o
74
73ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG 75ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 083034710fa6..1d002b1c2bf4 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -158,7 +158,7 @@ static void dlpar_pci_add_bus(struct device_node *dn)
158 /* Scan below the new bridge */ 158 /* Scan below the new bridge */
159 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 159 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
160 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 160 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
161 of_scan_pci_bridge(dn, dev); 161 of_scan_pci_bridge(dev);
162 162
163 /* Map IO space for child bus, which may or may not succeed */ 163 /* Map IO space for child bus, which may or may not succeed */
164 pcibios_map_io_space(dev->subordinate); 164 pcibios_map_io_space(dev->subordinate);
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
new file mode 100644
index 000000000000..c94d37ec55c8
--- /dev/null
+++ b/drivers/pci/of.c
@@ -0,0 +1,61 @@
1/*
2 * PCI <-> OF mapping helpers
3 *
4 * Copyright 2011 IBM Corp.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/pci.h>
14#include <linux/of.h>
15#include <linux/of_pci.h>
16#include "pci.h"
17
18void pci_set_of_node(struct pci_dev *dev)
19{
20 if (!dev->bus->dev.of_node)
21 return;
22 dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
23 dev->devfn);
24}
25
26void pci_release_of_node(struct pci_dev *dev)
27{
28 of_node_put(dev->dev.of_node);
29 dev->dev.of_node = NULL;
30}
31
32void pci_set_bus_of_node(struct pci_bus *bus)
33{
34 if (bus->self == NULL)
35 bus->dev.of_node = pcibios_get_phb_of_node(bus);
36 else
37 bus->dev.of_node = of_node_get(bus->self->dev.of_node);
38}
39
40void pci_release_bus_of_node(struct pci_bus *bus)
41{
42 of_node_put(bus->dev.of_node);
43 bus->dev.of_node = NULL;
44}
45
46struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
47{
48 /* This should only be called for PHBs */
49 if (WARN_ON(bus->self || bus->parent))
50 return NULL;
51
52 /* Look for a node pointer in either the intermediary device we
53 * create above the root bus or it's own parent. Normally only
54 * the later is populated.
55 */
56 if (bus->bridge->of_node)
57 return of_node_get(bus->bridge->of_node);
58 if (bus->bridge->parent->of_node)
59 return of_node_get(bus->bridge->parent->of_node);
60 return NULL;
61}
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 48849ffdd672..c28c7b91910e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -52,6 +52,7 @@ static void release_pcibus_dev(struct device *dev)
52 if (pci_bus->bridge) 52 if (pci_bus->bridge)
53 put_device(pci_bus->bridge); 53 put_device(pci_bus->bridge);
54 pci_bus_remove_resources(pci_bus); 54 pci_bus_remove_resources(pci_bus);
55 pci_release_bus_of_node(pci_bus);
55 kfree(pci_bus); 56 kfree(pci_bus);
56} 57}
57 58
@@ -588,7 +589,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
588 589
589 child->self = bridge; 590 child->self = bridge;
590 child->bridge = get_device(&bridge->dev); 591 child->bridge = get_device(&bridge->dev);
591 592 pci_set_bus_of_node(child);
592 pci_set_bus_speed(child); 593 pci_set_bus_speed(child);
593 594
594 /* Set up default resource pointers and names.. */ 595 /* Set up default resource pointers and names.. */
@@ -1038,6 +1039,7 @@ static void pci_release_dev(struct device *dev)
1038 1039
1039 pci_dev = to_pci_dev(dev); 1040 pci_dev = to_pci_dev(dev);
1040 pci_release_capabilities(pci_dev); 1041 pci_release_capabilities(pci_dev);
1042 pci_release_of_node(pci_dev);
1041 kfree(pci_dev); 1043 kfree(pci_dev);
1042} 1044}
1043 1045
@@ -1157,6 +1159,8 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
1157 dev->vendor = l & 0xffff; 1159 dev->vendor = l & 0xffff;
1158 dev->device = (l >> 16) & 0xffff; 1160 dev->device = (l >> 16) & 0xffff;
1159 1161
1162 pci_set_of_node(dev);
1163
1160 if (pci_setup_device(dev)) { 1164 if (pci_setup_device(dev)) {
1161 kfree(dev); 1165 kfree(dev);
1162 return NULL; 1166 return NULL;
@@ -1409,6 +1413,7 @@ struct pci_bus * pci_create_bus(struct device *parent,
1409 goto dev_reg_err; 1413 goto dev_reg_err;
1410 b->bridge = get_device(dev); 1414 b->bridge = get_device(dev);
1411 device_enable_async_suspend(b->bridge); 1415 device_enable_async_suspend(b->bridge);
1416 pci_set_bus_of_node(b);
1412 1417
1413 if (!parent) 1418 if (!parent)
1414 set_dev_node(b->bridge, pcibus_to_node(b)); 1419 set_dev_node(b->bridge, pcibus_to_node(b));
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 85a27b650d76..f93e21700d3e 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -6,4 +6,9 @@
6struct pci_dev; 6struct pci_dev;
7struct of_irq; 7struct of_irq;
8int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq); 8int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
9
10struct device_node;
11struct device_node *of_pci_find_child_device(struct device_node *parent,
12 unsigned int devfn);
13
9#endif 14#endif
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c446b5ca2d38..e5086e9a9bf7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1589,5 +1589,23 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
1589int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off, 1589int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
1590 unsigned int len, const char *kw); 1590 unsigned int len, const char *kw);
1591 1591
1592/* PCI <-> OF binding helpers */
1593#ifdef CONFIG_OF
1594struct device_node;
1595extern void pci_set_of_node(struct pci_dev *dev);
1596extern void pci_release_of_node(struct pci_dev *dev);
1597extern void pci_set_bus_of_node(struct pci_bus *bus);
1598extern void pci_release_bus_of_node(struct pci_bus *bus);
1599
1600/* Arch may override this (weak) */
1601extern struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus);
1602
1603#else /* CONFIG_OF */
1604static inline void pci_set_of_node(struct pci_dev *dev) { }
1605static inline void pci_release_of_node(struct pci_dev *dev) { }
1606static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
1607static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
1608#endif /* CONFIG_OF */
1609
1592#endif /* __KERNEL__ */ 1610#endif /* __KERNEL__ */
1593#endif /* LINUX_PCI_H */ 1611#endif /* LINUX_PCI_H */