Sebastian Andrzej Siewior | 04bea68 | 2011-01-24 09:58:55 +0530 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/of_pci.h> |
Sebastian Andrzej Siewior | 04bea68 | 2011-01-24 09:58:55 +0530 | [diff] [blame] | 3 | #include <asm/prom.h> |
| 4 | |
Benjamin Herrenschmidt | 98d9f30c8 | 2011-04-11 11:37:07 +1000 | [diff] [blame] | 5 | static inline int __of_pci_pci_compare(struct device_node *node, |
| 6 | unsigned int devfn) |
Sebastian Andrzej Siewior | 04bea68 | 2011-01-24 09:58:55 +0530 | [diff] [blame] | 7 | { |
Benjamin Herrenschmidt | 98d9f30c8 | 2011-04-11 11:37:07 +1000 | [diff] [blame] | 8 | unsigned int size; |
| 9 | const __be32 *reg = of_get_property(node, "reg", &size); |
Sebastian Andrzej Siewior | 04bea68 | 2011-01-24 09:58:55 +0530 | [diff] [blame] | 10 | |
Benjamin Herrenschmidt | 98d9f30c8 | 2011-04-11 11:37:07 +1000 | [diff] [blame] | 11 | if (!reg || size < 5 * sizeof(__be32)) |
| 12 | return 0; |
| 13 | return ((be32_to_cpup(®[0]) >> 8) & 0xff) == devfn; |
Sebastian Andrzej Siewior | 04bea68 | 2011-01-24 09:58:55 +0530 | [diff] [blame] | 14 | } |
Benjamin Herrenschmidt | 98d9f30c8 | 2011-04-11 11:37:07 +1000 | [diff] [blame] | 15 | |
| 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. |
| 28 | */ |
| 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 | } |
| 37 | } |
| 38 | return NULL; |
| 39 | } |
| 40 | EXPORT_SYMBOL_GPL(of_pci_find_child_device); |