aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/of.c
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2011-04-10 21:37:07 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2011-06-07 19:08:17 -0400
commit98d9f30c820d509145757e6ecbc36013aa02f7bc (patch)
treedd5da915d991352ced56ed849612029339f64198 /drivers/pci/of.c
parent1fa7b6a29c61358cc2ca6f64cef4aa0e1a7ca74c (diff)
pci/of: Match PCI devices to OF nodes dynamically
powerpc has two different ways of matching PCI devices to their corresponding OF node (if any) for historical reasons. The ppc64 one does a scan looking for matching bus/dev/fn, while the ppc32 one does a scan looking only for matching dev/fn on each level in order to be agnostic to busses being renumbered (which Linux does on some platforms). This removes both and instead moves the matching code to the PCI core itself. It's the most logical place to do it: when a pci_dev is created, we know the parent and thus can do a single level scan for the matching device_node (if any). The benefit is that all archs now get the matching for free. There's one hook the arch might want to provide to match a PHB bus to its device node. A default weak implementation is provided that looks for the parent device device node, but it's not entirely reliable on powerpc for various reasons so powerpc provides its own. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Michal Simek <monstr@monstr.eu> Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci/of.c')
-rw-r--r--drivers/pci/of.c61
1 files changed, 61 insertions, 0 deletions
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}