Merge tag 'stable/for-linus-3.7-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / drivers / of / of_pci.c
CommitLineData
04bea68b 1#include <linux/kernel.h>
9775913f 2#include <linux/export.h>
a6422850 3#include <linux/of.h>
04bea68b
SAS
4#include <linux/of_pci.h>
5#include <asm/prom.h>
6
98d9f30c
BH
7static inline int __of_pci_pci_compare(struct device_node *node,
8 unsigned int devfn)
04bea68b 9{
98d9f30c
BH
10 unsigned int size;
11 const __be32 *reg = of_get_property(node, "reg", &size);
04bea68b 12
98d9f30c
BH
13 if (!reg || size < 5 * sizeof(__be32))
14 return 0;
15 return ((be32_to_cpup(&reg[0]) >> 8) & 0xff) == devfn;
16}
04bea68b 17
98d9f30c
BH
18struct device_node *of_pci_find_child_device(struct device_node *parent,
19 unsigned int devfn)
20{
21 struct device_node *node, *node2;
22
23 for_each_child_of_node(parent, node) {
24 if (__of_pci_pci_compare(node, devfn))
25 return node;
26 /*
27 * Some OFs create a parent node "multifunc-device" as
28 * a fake root for all functions of a multi-function
29 * device we go down them as well.
04bea68b 30 */
98d9f30c
BH
31 if (!strcmp(node->name, "multifunc-device")) {
32 for_each_child_of_node(node, node2) {
33 if (__of_pci_pci_compare(node2, devfn)) {
34 of_node_put(node);
35 return node2;
36 }
37 }
38 }
04bea68b 39 }
98d9f30c 40 return NULL;
04bea68b 41}
98d9f30c 42EXPORT_SYMBOL_GPL(of_pci_find_child_device);
This page took 0.129752 seconds and 5 git commands to generate.