Commit | Line | Data |
---|---|---|
04bea68b SAS |
1 | #include <linux/kernel.h> |
2 | #include <linux/of_pci.h> | |
3 | #include <asm/prom.h> | |
4 | ||
98d9f30c BH |
5 | static inline int __of_pci_pci_compare(struct device_node *node, |
6 | unsigned int devfn) | |
04bea68b | 7 | { |
98d9f30c BH |
8 | unsigned int size; |
9 | const __be32 *reg = of_get_property(node, "reg", &size); | |
04bea68b | 10 | |
98d9f30c BH |
11 | if (!reg || size < 5 * sizeof(__be32)) |
12 | return 0; | |
13 | return ((be32_to_cpup(®[0]) >> 8) & 0xff) == devfn; | |
14 | } | |
04bea68b | 15 | |
98d9f30c BH |
16 | struct device_node *of_pci_find_child_device(struct device_node *parent, |
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. | |
04bea68b | 28 | */ |
98d9f30c BH |
29 | if (!strcmp(node->name, "multifunc-device")) { |
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 | } | |
04bea68b | 37 | } |
98d9f30c | 38 | return NULL; |
04bea68b | 39 | } |
98d9f30c | 40 | EXPORT_SYMBOL_GPL(of_pci_find_child_device); |