linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHES] Generalize PCI <-> OF node matching
@ 2011-04-07  3:26 Benjamin Herrenschmidt
  2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
                   ` (6 more replies)
  0 siblings, 7 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  3:26 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy

This series generalize the PCI <-> OF node matching, moves it to the
PCI core and make our archs use it. I also rip out while at it a whole
bunch of useless stuff from microblaze PCI code which was copied from
ppc32 and is essentially useless there (old workarounds for PowerMac
and ancient X servers).

Compile tested on x86_64, microblaze, sparc64 and powerpc.

How do you guys want to proceed with this series ? It will quickly
become a pre-req for other things on powerpc, so I can carry it in
powerpc in a separate branch that I also pull into powerpc-next or
we can have it somewhere on tip...


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
@ 2011-04-07  3:26 ` Benjamin Herrenschmidt
  2011-04-07  4:20   ` Benjamin Herrenschmidt
                     ` (2 more replies)
  2011-04-07  3:26 ` [PATCH 2/5] microblaze/pci: Remove powermac originated cruft Benjamin Herrenschmidt
                   ` (5 subsequent siblings)
  6 siblings, 3 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  3:26 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy,
	Benjamin Herrenschmidt

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>
---
 arch/microblaze/include/asm/pci-bridge.h |   14 ++--
 arch/microblaze/include/asm/prom.h       |   15 ---
 arch/microblaze/pci/pci_32.c             |   40 ++-------
 arch/powerpc/include/asm/pci-bridge.h    |   35 ++-----
 arch/powerpc/include/asm/pci.h           |    3 +-
 arch/powerpc/include/asm/prom.h          |   14 ---
 arch/powerpc/kernel/pci-common.c         |   11 ++-
 arch/powerpc/kernel/pci_32.c             |  148 +++---------------------------
 arch/powerpc/kernel/pci_dn.c             |   47 ----------
 arch/powerpc/kernel/pci_of_scan.c        |    9 +-
 arch/powerpc/platforms/powermac/pci.c    |    3 +-
 arch/sparc/kernel/pci.c                  |    2 +-
 drivers/of/of_pci.c                      |   36 +++++++
 drivers/pci/Makefile                     |    2 +
 drivers/pci/hotplug/rpadlpar_core.c      |    2 +-
 drivers/pci/of.c                         |   61 ++++++++++++
 drivers/pci/probe.c                      |    7 +-
 include/linux/of_pci.h                   |    5 +
 include/linux/pci.h                      |   18 ++++
 19 files changed, 180 insertions(+), 292 deletions(-)
 create mode 100644 drivers/pci/of.c

diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
index 1071766..4fa5508 100644
--- a/arch/microblaze/include/asm/pci-bridge.h
+++ b/arch/microblaze/include/asm/pci-bridge.h
@@ -105,19 +105,19 @@ struct pci_controller {
 };
 
 #ifdef CONFIG_PCI
-static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
+static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
 {
-	return bus->sysdata;
+	return dev->dev.of_node;
 }
 
 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
 {
-	struct pci_controller *host;
+	return bus->dev.of_node;
+}
 
-	if (bus->self)
-		return pci_device_to_OF_node(bus->self);
-	host = pci_bus_to_host(bus);
-	return host ? host->dn : NULL;
+static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
+{
+	return bus->sysdata;
 }
 
 static 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 d0890d3..9bd01ec 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -29,21 +29,6 @@
 extern int early_uartlite_console(void);
 extern int early_uart16550_console(void);
 
-#ifdef CONFIG_PCI
-/*
- * PCI <-> OF matching functions
- * (XXX should these be here?)
- */
-struct pci_bus;
-struct pci_dev;
-extern int pci_device_from_OF_node(struct device_node *node,
-					u8 *bus, u8 *devfn);
-extern struct device_node *pci_busdev_to_OF_node(struct pci_bus *bus,
-							int devfn);
-extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev);
-extern void pci_create_OF_bus_map(void);
-#endif
-
 /*
  * OF address retreival & translation
  */
diff --git a/arch/microblaze/pci/pci_32.c b/arch/microblaze/pci/pci_32.c
index 92728a6..b383a5a 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)
 	return np;
 }
 
-/*
- * Scans the OF tree for a device node matching a PCI device
- */
-struct device_node *
-pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
-{
-	struct device_node *parent, *np;
-
-	pr_debug("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn);
-	parent = scan_OF_for_pci_bus(bus);
-	if (parent == NULL)
-		return NULL;
-	pr_debug(" parent is %s\n", parent ? parent->full_name : "<NULL>");
-	np = scan_OF_for_pci_dev(parent, devfn);
-	of_node_put(parent);
-	pr_debug(" result is %s\n", np ? np->full_name : "<NULL>");
-
-	/* XXX most callers don't release the returned node
-	 * mostly because ppc64 doesn't increase the refcount,
-	 * we need to fix that.
-	 */
-	return np;
-}
-EXPORT_SYMBOL(pci_busdev_to_OF_node);
-
-struct device_node*
-pci_device_to_OF_node(struct pci_dev *dev)
-{
-	return pci_busdev_to_OF_node(dev->bus, dev->devfn);
-}
-EXPORT_SYMBOL(pci_device_to_OF_node);
-
 static int
 find_OF_pci_device_filter(struct device_node *node, void *data)
 {
@@ -315,6 +283,13 @@ pci_create_OF_bus_map(void)
 	}
 }
 
+struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
+{
+	struct pci_controller *hose = bus->sysdata;
+
+	return of_node_get(hose->dn);
+}
+
 static void __devinit pcibios_scan_phb(struct pci_controller *hose)
 {
 	struct pci_bus *bus;
@@ -332,7 +307,6 @@ static void __devinit pcibios_scan_phb(struct pci_controller *hose)
 		       hose->global_number);
 		return;
 	}
-	bus.dev->of_node = of_node_get(node);
 	bus->secondary = hose->first_busno;
 	hose->bus = bus;
 
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index 5e156e0..6912c45 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)
 	return bus->sysdata;
 }
 
-#ifndef CONFIG_PPC64
+static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
+{
+	return dev->dev.of_node;
+}
 
 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
 {
-	struct pci_controller *host;
-
-	if (bus->self)
-		return pci_device_to_OF_node(bus->self);
-	host = pci_bus_to_host(bus);
-	return host ? host->dn : NULL;
+	return bus->dev.of_node;
 }
 
+#ifndef CONFIG_PPC64
+
+extern int pci_device_from_OF_node(struct device_node *node,
+				   u8* bus, u8* devfn);
+extern void pci_create_OF_bus_map(void);
+
 static inline int isa_vaddr_is_ioport(void __iomem *address)
 {
 	/* No specific ISA handling on ppc32 at this stage, it
@@ -223,17 +227,8 @@ struct pci_dn {
 /* Get the pointer to a device_node's pci_dn */
 #define PCI_DN(dn)	((struct pci_dn *) (dn)->data)
 
-extern struct device_node *fetch_dev_dn(struct pci_dev *dev);
 extern void * update_dn_pci_info(struct device_node *dn, void *data);
 
-/* Get a device_node from a pci_dev.  This code must be fast except
- * in the case where the sysdata is incorrect and needs to be fixed
- * up (this will only happen once). */
-static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
-{
-	return dev->dev.of_node ? dev->dev.of_node : fetch_dev_dn(dev);
-}
-
 static inline int pci_device_from_OF_node(struct device_node *np,
 					  u8 *bus, u8 *devfn)
 {
@@ -244,14 +239,6 @@ static inline int pci_device_from_OF_node(struct device_node *np,
 	return 0;
 }
 
-static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
-{
-	if (bus->self)
-		return pci_device_to_OF_node(bus->self);
-	else
-		return bus->dev.of_node; /* Must be root bus (PHB) */
-}
-
 /** Find the bus corresponding to the indicated device node */
 extern struct pci_bus *pcibios_find_pci_bus(struct device_node *dn);
 
diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
index 7d77909..1f52268 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);
 extern struct pci_dev *of_create_pci_dev(struct device_node *node,
 					struct pci_bus *bus, int devfn);
 
-extern void of_scan_pci_bridge(struct device_node *node,
-				struct pci_dev *dev);
+extern void of_scan_pci_bridge(struct pci_dev *dev);
 
 extern void of_scan_bus(struct device_node *node, struct pci_bus *bus);
 extern 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 c189aa5..b823536 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -22,20 +22,6 @@
 
 #define HAVE_ARCH_DEVTREE_FIXUPS
 
-#ifdef CONFIG_PPC32
-/*
- * PCI <-> OF matching functions
- * (XXX should these be here?)
- */
-struct pci_bus;
-struct pci_dev;
-extern int pci_device_from_OF_node(struct device_node *node,
-				   u8* bus, u8* devfn);
-extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
-extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
-extern void pci_create_OF_bus_map(void);
-#endif
-
 /*
  * OF address retreival & translation
  */
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 893af2a..47c516b 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)
 		if (dev->is_added)
 			continue;
 
-		/* Setup OF node pointer in the device */
-		dev->dev.of_node = pci_device_to_OF_node(dev);
-
 		/* Fixup NUMA node as it may not be setup yet by the generic
 		 * code and is needed by the DMA init
 		 */
@@ -1685,6 +1682,13 @@ int early_find_capability(struct pci_controller *hose, int bus, int devfn,
 	return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap);
 }
 
+struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
+{
+	struct pci_controller *hose = bus->sysdata;
+
+	return of_node_get(hose->dn);
+}
+
 /**
  * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus
  * @hose: Pointer to the PCI host controller instance structure
@@ -1705,7 +1709,6 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose)
 			hose->global_number);
 		return;
 	}
-	bus->dev.of_node = of_node_get(node);
 	bus->secondary = hose->first_busno;
 	hose->bus = bus;
 
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c
index bedb370..ca6bcb7 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)
 #endif
 }
 
-typedef int (*pci_OF_scan_iterator)(struct device_node* node, void* data);
-
-static struct device_node*
-scan_OF_pci_childs(struct device_node *parent, pci_OF_scan_iterator filter, void* data)
-{
-	struct device_node *node;
-	struct device_node* sub_node;
-
-	for_each_child_of_node(parent, node) {
-		const unsigned int *class_code;
-	
-		if (filter(node, data)) {
-			of_node_put(node);
-			return node;
-		}
-
-		/* For PCI<->PCI bridges or CardBus bridges, we go down
-		 * Note: some OFs create a parent node "multifunc-device" as
-		 * a fake root for all functions of a multi-function device,
-		 * we go down them as well.
-		 */
-		class_code = of_get_property(node, "class-code", NULL);
-		if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
-			(*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
-			strcmp(node->name, "multifunc-device"))
-			continue;
-		sub_node = scan_OF_pci_childs(node, filter, data);
-		if (sub_node) {
-			of_node_put(node);
-			return sub_node;
-		}
-	}
-	return NULL;
-}
-
-static struct device_node *scan_OF_for_pci_dev(struct device_node *parent,
-					       unsigned int devfn)
-{
-	struct device_node *np, *cnp;
-	const u32 *reg;
-	unsigned int psize;
-
-	for_each_child_of_node(parent, np) {
-		reg = of_get_property(np, "reg", &psize);
-                if (reg && psize >= 4 && ((reg[0] >> 8) & 0xff) == devfn)
-			return np;
-
-		/* Note: some OFs create a parent node "multifunc-device" as
-		 * a fake root for all functions of a multi-function device,
-		 * we go down them as well. */
-                if (!strcmp(np->name, "multifunc-device")) {
-                        cnp = scan_OF_for_pci_dev(np, devfn);
-                        if (cnp)
-                                return cnp;
-                }
-	}
-	return NULL;
-}
-
-
-static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
-{
-	struct device_node *parent, *np;
-
-	/* Are we a root bus ? */
-	if (bus->self == NULL || bus->parent == NULL) {
-		struct pci_controller *hose = pci_bus_to_host(bus);
-		if (hose == NULL)
-			return NULL;
-		return of_node_get(hose->dn);
-	}
-
-	/* not a root bus, we need to get our parent */
-	parent = scan_OF_for_pci_bus(bus->parent);
-	if (parent == NULL)
-		return NULL;
-
-	/* now iterate for children for a match */
-	np = scan_OF_for_pci_dev(parent, bus->self->devfn);
-	of_node_put(parent);
-
-	return np;
-}
-
-/*
- * Scans the OF tree for a device node matching a PCI device
- */
-struct device_node *
-pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
-{
-	struct device_node *parent, *np;
-
-	pr_debug("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn);
-	parent = scan_OF_for_pci_bus(bus);
-	if (parent == NULL)
-		return NULL;
-	pr_debug(" parent is %s\n", parent ? parent->full_name : "<NULL>");
-	np = scan_OF_for_pci_dev(parent, devfn);
-	of_node_put(parent);
-	pr_debug(" result is %s\n", np ? np->full_name : "<NULL>");
-
-	/* XXX most callers don't release the returned node
-	 * mostly because ppc64 doesn't increase the refcount,
-	 * we need to fix that.
-	 */
-	return np;
-}
-EXPORT_SYMBOL(pci_busdev_to_OF_node);
-
-struct device_node*
-pci_device_to_OF_node(struct pci_dev *dev)
-{
-	return pci_busdev_to_OF_node(dev->bus, dev->devfn);
-}
-EXPORT_SYMBOL(pci_device_to_OF_node);
-
-static int
-find_OF_pci_device_filter(struct device_node* node, void* data)
-{
-	return ((void *)node == data);
-}
 
 /*
  * Returns the PCI device matching a given OF node
  */
-int
-pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
+int pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
 {
-	const unsigned int *reg;
-	struct pci_controller* hose;
 	struct pci_dev* dev = NULL;
-	
-	/* Make sure it's really a PCI device */
-	hose = pci_find_hose_for_OF_device(node);
-	if (!hose || !hose->dn)
-		return -ENODEV;
-	if (!scan_OF_pci_childs(hose->dn,
-			find_OF_pci_device_filter, (void *)node))
+	const __be32 *reg;
+	int size;
+
+	/* Check if it might have a chance to be a PCI device */
+	if (!pci_find_hose_for_OF_device(node))
 		return -ENODEV;
-	reg = of_get_property(node, "reg", NULL);
-	if (!reg)
+
+	reg = of_get_property(node, "reg", &size);
+	if (!reg || size < 5 * sizeof(u32))
 		return -ENODEV;
-	*bus = (reg[0] >> 16) & 0xff;
-	*devfn = ((reg[0] >> 8) & 0xff);
+	
+	*bus = (be32_to_cpup(&reg[0]) >> 16) & 0xff;
+	*devfn = (be32_to_cpup(&reg[0]) >> 8) & 0xff;
 
 	/* Ok, here we need some tweak. If we have already renumbered
 	 * 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 d225d99..8cb66a2 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -143,53 +143,6 @@ void __devinit pci_devs_phb_init_dynamic(struct pci_controller *phb)
 	traverse_pci_devices(dn, update_dn_pci_info, phb);
 }
 
-/*
- * Traversal func that looks for a <busno,devfcn> value.
- * If found, the pci_dn is returned (thus terminating the traversal).
- */
-static void *is_devfn_node(struct device_node *dn, void *data)
-{
-	int busno = ((unsigned long)data >> 8) & 0xff;
-	int devfn = ((unsigned long)data) & 0xff;
-	struct pci_dn *pci = dn->data;
-
-	if (pci && (devfn == pci->devfn) && (busno == pci->busno))
-		return dn;
-	return NULL;
-}
-
-/*
- * This is the "slow" path for looking up a device_node from a
- * pci_dev.  It will hunt for the device under its parent's
- * phb and then update of_node pointer.
- *
- * It may also do fixups on the actual device since this happens
- * on the first read/write.
- *
- * Note that it also must deal with devices that don't exist.
- * In this case it may probe for real hardware ("just in case")
- * and add a device_node to the device tree if necessary.
- *
- * Is this function necessary anymore now that dev->dev.of_node is
- * used to store the node pointer?
- *
- */
-struct device_node *fetch_dev_dn(struct pci_dev *dev)
-{
-	struct pci_controller *phb = dev->sysdata;
-	struct device_node *dn;
-	unsigned long searchval = (dev->bus->number << 8) | dev->devfn;
-
-	if (WARN_ON(!phb))
-		return NULL;
-
-	dn = traverse_pci_devices(phb->dn, is_devfn_node, (void *)searchval);
-	if (dn)
-		dev->dev.of_node = dn;
-	return dn;
-}
-EXPORT_SYMBOL(fetch_dev_dn);
-
 /** 
  * pci_devs_phb_init - Initialize phbs and pci devs under them.
  * 
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index 1e89a72..fe0a5ad 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);
  * this routine in turn call of_scan_bus() recusively to scan for more child
  * devices.
  */
-void __devinit of_scan_pci_bridge(struct device_node *node,
-				  struct pci_dev *dev)
+void __devinit of_scan_pci_bridge(struct pci_dev *dev)
 {
+	struct device_node *node = dev->dev.of_node;
 	struct pci_bus *bus;
 	const u32 *busrange, *ranges;
 	int len, i, mode;
@@ -238,7 +238,6 @@ void __devinit of_scan_pci_bridge(struct device_node *node,
 	bus->primary = dev->bus->number;
 	bus->subordinate = busrange[1];
 	bus->bridge_ctl = 0;
-	bus->dev.of_node = of_node_get(node);
 
 	/* parse ranges property */
 	/* PCI #address-cells == 3 and #size-cells == 2 always */
@@ -335,9 +334,7 @@ static void __devinit __of_scan_bus(struct device_node *node,
 	list_for_each_entry(dev, &bus->devices, bus_list) {
 		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
 		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
-			struct device_node *child = pci_device_to_OF_node(dev);
-			if (child)
-				of_scan_pci_bridge(child, dev);
+			of_scan_pci_bridge(dev);
 		}
 	}
 }
diff --git a/arch/powerpc/platforms/powermac/pci.c b/arch/powerpc/platforms/powermac/pci.c
index ab68989..68a18da 100644
--- a/arch/powerpc/platforms/powermac/pci.c
+++ b/arch/powerpc/platforms/powermac/pci.c
@@ -17,6 +17,7 @@
 #include <linux/init.h>
 #include <linux/bootmem.h>
 #include <linux/irq.h>
+#include <linux/of_pci.h>
 
 #include <asm/sections.h>
 #include <asm/io.h>
@@ -235,7 +236,7 @@ static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset)
 
 	if (offset >= 0x100)
 		return  PCIBIOS_BAD_REGISTER_NUMBER;
-	np = pci_busdev_to_OF_node(bus, devfn);
+	np = of_pci_find_child_device(bus->dev.of_node, devfn);
 	if (np == NULL)
 		return PCIBIOS_DEVICE_NOT_FOUND;
 
diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index 713dc91..e539d23 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,
 	dev->sysdata = node;
 	dev->dev.parent = bus->bridge;
 	dev->dev.bus = &pci_bus_type;
-	dev->dev.of_node = node;
+	dev->dev.of_node = of_node_get(node);
 	dev->devfn = devfn;
 	dev->multifunction = 0;		/* maybe a lie? */
 	set_pcie_port_type(dev);
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index ac1ec54..9d179c4 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -90,3 +90,39 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
 	return of_irq_map_raw(ppnode, &lspec_be, 1, laddr, out_irq);
 }
 EXPORT_SYMBOL_GPL(of_irq_map_pci);
+
+
+static inline int __of_pci_pci_compare(struct device_node *node, unsigned int devfn)
+{
+	unsigned int size;
+	const __be32 *reg = of_get_property(node, "reg", &size);
+
+	if (!reg || size < 5 * sizeof(__be32))
+		return 0;
+	return ((be32_to_cpup(&reg[0]) >> 8) & 0xff) == devfn;
+}
+
+struct device_node *of_pci_find_child_device(struct device_node *parent,
+					     unsigned int devfn)
+{
+	struct device_node *node, *node2;
+	
+	for_each_child_of_node(parent, node) {
+		if (__of_pci_pci_compare(node, devfn))
+			return node;
+		/*
+		 * Some OFs create a parent node "multifunc-device" as
+		 * a fake root for all functions of a multi-function
+		 * device we go down them as well.
+		 */
+                if (!strcmp(node->name, "multifunc-device")) {
+			for_each_child_of_node(node, node2) {
+				if (__of_pci_pci_compare(node2, devfn)) {
+					of_node_put(node);
+					return node2;
+				}
+			}
+                }
+	}
+	return NULL;
+}
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 98d61c8..d5c3cb9 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -70,4 +70,6 @@ obj-$(CONFIG_PCI_STUB) += pci-stub.o
 
 obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
 
+obj-$(CONFIG_OF) += of.o
+
 ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 0830347..1d002b1 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)
 	/* Scan below the new bridge */
 	if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
 	    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
-		of_scan_pci_bridge(dn, dev);
+		of_scan_pci_bridge(dev);
 
 	/* Map IO space for child bus, which may or may not succeed */
 	pcibios_map_io_space(dev->subordinate);
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
new file mode 100644
index 0000000..c94d37e
--- /dev/null
+++ b/drivers/pci/of.c
@@ -0,0 +1,61 @@
+/*
+ * PCI <-> OF mapping helpers
+ *
+ * Copyright 2011 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/of.h>
+#include <linux/of_pci.h>
+#include "pci.h"
+
+void pci_set_of_node(struct pci_dev *dev)
+{
+	if (!dev->bus->dev.of_node)
+		return;
+	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
+						    dev->devfn);
+}
+
+void pci_release_of_node(struct pci_dev *dev)
+{
+	of_node_put(dev->dev.of_node);
+	dev->dev.of_node = NULL;
+}
+
+void pci_set_bus_of_node(struct pci_bus *bus)
+{
+	if (bus->self == NULL)
+		bus->dev.of_node = pcibios_get_phb_of_node(bus);
+	else
+		bus->dev.of_node = of_node_get(bus->self->dev.of_node);
+}
+
+void pci_release_bus_of_node(struct pci_bus *bus)
+{
+	of_node_put(bus->dev.of_node);
+	bus->dev.of_node = NULL;
+}
+
+struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
+{
+	/* This should only be called for PHBs */
+	if (WARN_ON(bus->self || bus->parent))
+		return NULL;
+
+	/* Look for a node pointer in either the intermediary device we
+	 * create above the root bus or it's own parent. Normally only
+	 * the later is populated.
+	 */
+	if (bus->bridge->of_node)
+		return of_node_get(bus->bridge->of_node);
+	if (bus->bridge->parent->of_node)
+		return of_node_get(bus->bridge->parent->of_node);
+	return NULL;
+}
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 44cbbba..7964474 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -89,6 +89,7 @@ static void release_pcibus_dev(struct device *dev)
 	if (pci_bus->bridge)
 		put_device(pci_bus->bridge);
 	pci_bus_remove_resources(pci_bus);
+	pci_release_bus_of_node(pci_bus);
 	kfree(pci_bus);
 }
 
@@ -624,7 +625,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
 
 	child->self = bridge;
 	child->bridge = get_device(&bridge->dev);
-
+	pci_set_bus_of_node(child);
 	pci_set_bus_speed(child);
 
 	/* Set up default resource pointers and names.. */
@@ -1074,6 +1075,7 @@ static void pci_release_dev(struct device *dev)
 
 	pci_dev = to_pci_dev(dev);
 	pci_release_capabilities(pci_dev);
+	pci_release_of_node(pci_dev);
 	kfree(pci_dev);
 }
 
@@ -1193,6 +1195,8 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
 	dev->vendor = l & 0xffff;
 	dev->device = (l >> 16) & 0xffff;
 
+	pci_set_of_node(dev);
+
 	if (pci_setup_device(dev)) {
 		kfree(dev);
 		return NULL;
@@ -1445,6 +1449,7 @@ struct pci_bus * pci_create_bus(struct device *parent,
 		goto dev_reg_err;
 	b->bridge = get_device(dev);
 	device_enable_async_suspend(b->bridge);
+	pci_set_bus_of_node(b);
 
 	if (!parent)
 		set_dev_node(b->bridge, pcibus_to_node(b));
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 85a27b6..f93e217 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -6,4 +6,9 @@
 struct pci_dev;
 struct of_irq;
 int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
+
+struct device_node;
+struct device_node *of_pci_find_child_device(struct device_node *parent,
+					     unsigned int devfn);
+
 #endif
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 96f70d7..a1f90f0 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1543,5 +1543,23 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
 int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
 			      unsigned int len, const char *kw);
 
+/* PCI <-> OF binding helpers */
+#ifdef  CONFIG_OF
+struct device_node;
+extern void pci_set_of_node(struct pci_dev *dev);
+extern void pci_release_of_node(struct pci_dev *dev);
+extern void pci_set_bus_of_node(struct pci_bus *bus);
+extern void pci_release_bus_of_node(struct pci_bus *bus);
+
+/* Arch may override this (weak) */
+extern struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus);
+
+#else /* CONFIG_OF */
+static inline void pci_set_of_node(struct pci_dev *dev) { }
+static inline void pci_release_of_node(struct pci_dev *dev) { }
+static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
+static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
+#endif  /* CONFIG_OF */
+
 #endif /* __KERNEL__ */
 #endif /* LINUX_PCI_H */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 2/5] microblaze/pci: Remove powermac originated cruft
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
  2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
@ 2011-04-07  3:26 ` Benjamin Herrenschmidt
  2011-04-07  3:26 ` [PATCH 3/5] microblaze/pci: Move the remains of pci_32.c to pci-common.c Benjamin Herrenschmidt
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  3:26 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy,
	Benjamin Herrenschmidt

The whole business with re-assigning all bus numbers, creating
an OF bus "map" etc... is ancient powermac stuff that you really
don't care about on microblaze.

Similarly pci_device_from_OF_node() is unused and by getting rid
of it we can get rid of a whole lot of code otherwise unused on
this architecture

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 arch/microblaze/include/asm/pci-bridge.h |    3 -
 arch/microblaze/include/asm/pci.h        |    3 +-
 arch/microblaze/pci/pci_32.c             |  272 +-----------------------------
 3 files changed, 3 insertions(+), 275 deletions(-)

diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
index 4fa5508..da1e287 100644
--- a/arch/microblaze/include/asm/pci-bridge.h
+++ b/arch/microblaze/include/asm/pci-bridge.h
@@ -19,9 +19,6 @@ enum {
 	 */
 	PCI_REASSIGN_ALL_RSRC	= 0x00000001,
 
-	/* Re-assign all bus numbers */
-	PCI_REASSIGN_ALL_BUS	= 0x00000002,
-
 	/* Do not try to assign, just use existing setup */
 	PCI_PROBE_ONLY		= 0x00000004,
 
diff --git a/arch/microblaze/include/asm/pci.h b/arch/microblaze/include/asm/pci.h
index 2232ff9..f96c41d 100644
--- a/arch/microblaze/include/asm/pci.h
+++ b/arch/microblaze/include/asm/pci.h
@@ -40,8 +40,7 @@ struct pci_dev;
  * Set this to 1 if you want the kernel to re-assign all PCI
  * bus numbers (don't do that on ppc64 yet !)
  */
-#define pcibios_assign_all_busses() \
-	(pci_has_flag(PCI_REASSIGN_ALL_BUS))
+#define pcibios_assign_all_busses() 	0
 
 static inline void pcibios_set_master(struct pci_dev *dev)
 {
diff --git a/arch/microblaze/pci/pci_32.c b/arch/microblaze/pci/pci_32.c
index b383a5a..9128f15 100644
--- a/arch/microblaze/pci/pci_32.c
+++ b/arch/microblaze/pci/pci_32.c
@@ -28,261 +28,8 @@
 
 unsigned long isa_io_base;
 unsigned long pci_dram_offset;
-int pcibios_assign_bus_offset = 1;
-
-static u8 *pci_to_OF_bus_map;
-
-/* By default, we don't re-assign bus numbers. We do this only on
- * some pmacs
- */
-static int pci_assign_all_buses;
-
 static int pci_bus_count;
 
-/*
- * Functions below are used on OpenFirmware machines.
- */
-static void
-make_one_node_map(struct device_node *node, u8 pci_bus)
-{
-	const int *bus_range;
-	int len;
-
-	if (pci_bus >= pci_bus_count)
-		return;
-	bus_range = of_get_property(node, "bus-range", &len);
-	if (bus_range == NULL || len < 2 * sizeof(int)) {
-		printk(KERN_WARNING "Can't get bus-range for %s, "
-		       "assuming it starts at 0\n", node->full_name);
-		pci_to_OF_bus_map[pci_bus] = 0;
-	} else
-		pci_to_OF_bus_map[pci_bus] = bus_range[0];
-
-	for_each_child_of_node(node, node) {
-		struct pci_dev *dev;
-		const unsigned int *class_code, *reg;
-
-		class_code = of_get_property(node, "class-code", NULL);
-		if (!class_code ||
-			((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
-			(*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
-			continue;
-		reg = of_get_property(node, "reg", NULL);
-		if (!reg)
-			continue;
-		dev = pci_get_bus_and_slot(pci_bus, ((reg[0] >> 8) & 0xff));
-		if (!dev || !dev->subordinate) {
-			pci_dev_put(dev);
-			continue;
-		}
-		make_one_node_map(node, dev->subordinate->number);
-		pci_dev_put(dev);
-	}
-}
-
-void
-pcibios_make_OF_bus_map(void)
-{
-	int i;
-	struct pci_controller *hose, *tmp;
-	struct property *map_prop;
-	struct device_node *dn;
-
-	pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL);
-	if (!pci_to_OF_bus_map) {
-		printk(KERN_ERR "Can't allocate OF bus map !\n");
-		return;
-	}
-
-	/* We fill the bus map with invalid values, that helps
-	 * debugging.
-	 */
-	for (i = 0; i < pci_bus_count; i++)
-		pci_to_OF_bus_map[i] = 0xff;
-
-	/* For each hose, we begin searching bridges */
-	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
-		struct device_node *node = hose->dn;
-
-		if (!node)
-			continue;
-		make_one_node_map(node, hose->first_busno);
-	}
-	dn = of_find_node_by_path("/");
-	map_prop = of_find_property(dn, "pci-OF-bus-map", NULL);
-	if (map_prop) {
-		BUG_ON(pci_bus_count > map_prop->length);
-		memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
-	}
-	of_node_put(dn);
-#ifdef DEBUG
-	printk(KERN_INFO "PCI->OF bus map:\n");
-	for (i = 0; i < pci_bus_count; i++) {
-		if (pci_to_OF_bus_map[i] == 0xff)
-			continue;
-		printk(KERN_INFO "%d -> %d\n", i, pci_to_OF_bus_map[i]);
-	}
-#endif
-}
-
-typedef int (*pci_OF_scan_iterator)(struct device_node *node, void *data);
-
-static struct device_node *scan_OF_pci_childs(struct device_node *parent,
-					pci_OF_scan_iterator filter, void *data)
-{
-	struct device_node *node;
-	struct device_node *sub_node;
-
-	for_each_child_of_node(parent, node) {
-		const unsigned int *class_code;
-
-		if (filter(node, data)) {
-			of_node_put(node);
-			return node;
-		}
-
-		/* For PCI<->PCI bridges or CardBus bridges, we go down
-		 * Note: some OFs create a parent node "multifunc-device" as
-		 * a fake root for all functions of a multi-function device,
-		 * we go down them as well.
-		 */
-		class_code = of_get_property(node, "class-code", NULL);
-		if ((!class_code ||
-			((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
-			(*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
-			strcmp(node->name, "multifunc-device"))
-			continue;
-		sub_node = scan_OF_pci_childs(node, filter, data);
-		if (sub_node) {
-			of_node_put(node);
-			return sub_node;
-		}
-	}
-	return NULL;
-}
-
-static struct device_node *scan_OF_for_pci_dev(struct device_node *parent,
-					       unsigned int devfn)
-{
-	struct device_node *np, *cnp;
-	const u32 *reg;
-	unsigned int psize;
-
-	for_each_child_of_node(parent, np) {
-		reg = of_get_property(np, "reg", &psize);
-		if (reg && psize >= 4 && ((reg[0] >> 8) & 0xff) == devfn)
-			return np;
-
-		/* Note: some OFs create a parent node "multifunc-device" as
-		 * a fake root for all functions of a multi-function device,
-		 * we go down them as well. */
-		if (!strcmp(np->name, "multifunc-device")) {
-			cnp = scan_OF_for_pci_dev(np, devfn);
-			if (cnp)
-				return cnp;
-		}
-	}
-	return NULL;
-}
-
-
-static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
-{
-	struct device_node *parent, *np;
-
-	/* Are we a root bus ? */
-	if (bus->self == NULL || bus->parent == NULL) {
-		struct pci_controller *hose = pci_bus_to_host(bus);
-		if (hose == NULL)
-			return NULL;
-		return of_node_get(hose->dn);
-	}
-
-	/* not a root bus, we need to get our parent */
-	parent = scan_OF_for_pci_bus(bus->parent);
-	if (parent == NULL)
-		return NULL;
-
-	/* now iterate for children for a match */
-	np = scan_OF_for_pci_dev(parent, bus->self->devfn);
-	of_node_put(parent);
-
-	return np;
-}
-
-static int
-find_OF_pci_device_filter(struct device_node *node, void *data)
-{
-	return ((void *)node == data);
-}
-
-/*
- * Returns the PCI device matching a given OF node
- */
-int
-pci_device_from_OF_node(struct device_node *node, u8 *bus, u8 *devfn)
-{
-	const unsigned int *reg;
-	struct pci_controller *hose;
-	struct pci_dev *dev = NULL;
-
-	/* Make sure it's really a PCI device */
-	hose = pci_find_hose_for_OF_device(node);
-	if (!hose || !hose->dn)
-		return -ENODEV;
-	if (!scan_OF_pci_childs(hose->dn,
-			find_OF_pci_device_filter, (void *)node))
-		return -ENODEV;
-	reg = of_get_property(node, "reg", NULL);
-	if (!reg)
-		return -ENODEV;
-	*bus = (reg[0] >> 16) & 0xff;
-	*devfn = ((reg[0] >> 8) & 0xff);
-
-	/* Ok, here we need some tweak. If we have already renumbered
-	 * all busses, we can't rely on the OF bus number any more.
-	 * the pci_to_OF_bus_map is not enough as several PCI busses
-	 * may match the same OF bus number.
-	 */
-	if (!pci_to_OF_bus_map)
-		return 0;
-
-	for_each_pci_dev(dev)
-		if (pci_to_OF_bus_map[dev->bus->number] == *bus &&
-				dev->devfn == *devfn) {
-			*bus = dev->bus->number;
-			pci_dev_put(dev);
-			return 0;
-		}
-
-	return -ENODEV;
-}
-EXPORT_SYMBOL(pci_device_from_OF_node);
-
-/* We create the "pci-OF-bus-map" property now so it appears in the
- * /proc device tree
- */
-void __init
-pci_create_OF_bus_map(void)
-{
-	struct property *of_prop;
-	struct device_node *dn;
-
-	of_prop = (struct property *) alloc_bootmem(sizeof(struct property) + \
-									 256);
-	if (!of_prop)
-		return;
-	dn = of_find_node_by_path("/");
-	if (dn) {
-		memset(of_prop, -1, sizeof(struct property) + 256);
-		of_prop->name = "pci-OF-bus-map";
-		of_prop->length = 256;
-		of_prop->value = &of_prop[1];
-		prom_add_property(dn, of_prop);
-		of_node_put(dn);
-	}
-}
-
 struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
 {
 	struct pci_controller *hose = bus->sysdata;
@@ -329,32 +76,17 @@ static int __init pcibios_init(void)
 
 	printk(KERN_INFO "PCI: Probing PCI hardware\n");
 
-	if (pci_flags & PCI_REASSIGN_ALL_BUS) {
-		printk(KERN_INFO "setting pci_asign_all_busses\n");
-		pci_assign_all_buses = 1;
-	}
-
 	/* Scan all of the recorded PCI controllers.  */
 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
-		if (pci_assign_all_buses)
-			hose->first_busno = next_busno;
 		hose->last_busno = 0xff;
 		pcibios_scan_phb(hose);
 		printk(KERN_INFO "calling pci_bus_add_devices()\n");
 		pci_bus_add_devices(hose->bus);
-		if (pci_assign_all_buses || next_busno <= hose->last_busno)
-			next_busno = hose->last_busno + \
-					pcibios_assign_bus_offset;
+		if (next_busno <= hose->last_busno)
+			next_busno = hose->last_busno + 1;
 	}
 	pci_bus_count = next_busno;
 
-	/* OpenFirmware based machines need a map of OF bus
-	 * numbers vs. kernel bus numbers since we may have to
-	 * remap them.
-	 */
-	if (pci_assign_all_buses)
-		pcibios_make_OF_bus_map();
-
 	/* Call common code to handle resource allocation */
 	pcibios_resource_survey();
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 3/5] microblaze/pci: Move the remains of pci_32.c to pci-common.c
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
  2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
  2011-04-07  3:26 ` [PATCH 2/5] microblaze/pci: Remove powermac originated cruft Benjamin Herrenschmidt
@ 2011-04-07  3:26 ` Benjamin Herrenschmidt
  2011-04-07  3:26 ` [PATCH 4/5] x86/devicetree: Use generic PCI <-> OF matching Benjamin Herrenschmidt
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  3:26 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy,
	Benjamin Herrenschmidt

There's no point in keeping this separate. Even if microblaze grows
a 64-bit variant, it will probably be able to re-use that code as-is

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 arch/microblaze/pci/Makefile     |    2 +-
 arch/microblaze/pci/pci-common.c |  113 +++++++++++++++++++++++++++++++
 arch/microblaze/pci/pci_32.c     |  138 --------------------------------------
 3 files changed, 114 insertions(+), 139 deletions(-)
 delete mode 100644 arch/microblaze/pci/pci_32.c

diff --git a/arch/microblaze/pci/Makefile b/arch/microblaze/pci/Makefile
index 9889cc2..d1114fb 100644
--- a/arch/microblaze/pci/Makefile
+++ b/arch/microblaze/pci/Makefile
@@ -2,5 +2,5 @@
 # Makefile
 #
 
-obj-$(CONFIG_PCI)		+= pci_32.o pci-common.o indirect_pci.o iomap.o
+obj-$(CONFIG_PCI)		+= pci-common.o indirect_pci.o iomap.o
 obj-$(CONFIG_PCI_XILINX)	+= xilinx_pci.o
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c
index 5359906..b908378 100644
--- a/arch/microblaze/pci/pci-common.c
+++ b/arch/microblaze/pci/pci-common.c
@@ -50,6 +50,11 @@ unsigned int pci_flags;
 
 static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
 
+unsigned long isa_io_base;
+unsigned long pci_dram_offset;
+static int pci_bus_count;
+
+
 void set_pci_dma_ops(struct dma_map_ops *dma_ops)
 {
 	pci_dma_ops = dma_ops;
@@ -1558,6 +1563,113 @@ void __devinit pcibios_setup_phb_resources(struct pci_controller *hose)
 		 (unsigned long)hose->io_base_virt - _IO_BASE);
 }
 
+struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
+{
+	struct pci_controller *hose = bus->sysdata;
+
+	return of_node_get(hose->dn);
+}
+
+static void __devinit pcibios_scan_phb(struct pci_controller *hose)
+{
+	struct pci_bus *bus;
+	struct device_node *node = hose->dn;
+	unsigned long io_offset;
+	struct resource *res = &hose->io_resource;
+
+	pr_debug("PCI: Scanning PHB %s\n",
+		 node ? node->full_name : "<NO NAME>");
+
+	/* Create an empty bus for the toplevel */
+	bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, hose);
+	if (bus == NULL) {
+		printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
+		       hose->global_number);
+		return;
+	}
+	bus->secondary = hose->first_busno;
+	hose->bus = bus;
+
+	/* Fixup IO space offset */
+	io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
+	res->start = (res->start + io_offset) & 0xffffffffu;
+	res->end = (res->end + io_offset) & 0xffffffffu;
+
+	/* Wire up PHB bus resources */
+	pcibios_setup_phb_resources(hose);
+
+	/* Scan children */
+	hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
+}
+
+static int __init pcibios_init(void)
+{
+	struct pci_controller *hose, *tmp;
+	int next_busno = 0;
+
+	printk(KERN_INFO "PCI: Probing PCI hardware\n");
+
+	/* Scan all of the recorded PCI controllers.  */
+	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
+		hose->last_busno = 0xff;
+		pcibios_scan_phb(hose);
+		printk(KERN_INFO "calling pci_bus_add_devices()\n");
+		pci_bus_add_devices(hose->bus);
+		if (next_busno <= hose->last_busno)
+			next_busno = hose->last_busno + 1;
+	}
+	pci_bus_count = next_busno;
+
+	/* Call common code to handle resource allocation */
+	pcibios_resource_survey();
+
+	return 0;
+}
+
+subsys_initcall(pcibios_init);
+
+static struct pci_controller*
+pci_bus_to_hose(int bus)
+{
+	struct pci_controller *hose, *tmp;
+
+	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
+		if (bus >= hose->first_busno && bus <= hose->last_busno)
+			return hose;
+	return NULL;
+}
+
+/* Provide information on locations of various I/O regions in physical
+ * memory.  Do this on a per-card basis so that we choose the right
+ * root bridge.
+ * Note that the returned IO or memory base is a physical address
+ */
+
+long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
+{
+	struct pci_controller *hose;
+	long result = -EOPNOTSUPP;
+
+	hose = pci_bus_to_hose(bus);
+	if (!hose)
+		return -ENODEV;
+
+	switch (which) {
+	case IOBASE_BRIDGE_NUMBER:
+		return (long)hose->first_busno;
+	case IOBASE_MEMORY:
+		return (long)hose->pci_mem_offset;
+	case IOBASE_IO:
+		return (long)hose->io_base_phys;
+	case IOBASE_ISA_IO:
+		return (long)isa_io_base;
+	case IOBASE_ISA_MEM:
+		return (long)isa_mem_base;
+	}
+
+	return result;
+}
+
 /*
  * Null PCI config access functions, for the case when we can't
  * find a hose.
@@ -1626,3 +1738,4 @@ int early_find_capability(struct pci_controller *hose, int bus, int devfn,
 {
 	return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap);
 }
+
diff --git a/arch/microblaze/pci/pci_32.c b/arch/microblaze/pci/pci_32.c
deleted file mode 100644
index 9128f15..0000000
--- a/arch/microblaze/pci/pci_32.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Common pmac/prep/chrp pci routines. -- Cort
- */
-
-#include <linux/kernel.h>
-#include <linux/pci.h>
-#include <linux/delay.h>
-#include <linux/string.h>
-#include <linux/init.h>
-#include <linux/capability.h>
-#include <linux/sched.h>
-#include <linux/errno.h>
-#include <linux/bootmem.h>
-#include <linux/irq.h>
-#include <linux/list.h>
-#include <linux/of.h>
-#include <linux/slab.h>
-
-#include <asm/processor.h>
-#include <asm/io.h>
-#include <asm/prom.h>
-#include <asm/sections.h>
-#include <asm/pci-bridge.h>
-#include <asm/byteorder.h>
-#include <asm/uaccess.h>
-
-#undef DEBUG
-
-unsigned long isa_io_base;
-unsigned long pci_dram_offset;
-static int pci_bus_count;
-
-struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
-{
-	struct pci_controller *hose = bus->sysdata;
-
-	return of_node_get(hose->dn);
-}
-
-static void __devinit pcibios_scan_phb(struct pci_controller *hose)
-{
-	struct pci_bus *bus;
-	struct device_node *node = hose->dn;
-	unsigned long io_offset;
-	struct resource *res = &hose->io_resource;
-
-	pr_debug("PCI: Scanning PHB %s\n",
-		 node ? node->full_name : "<NO NAME>");
-
-	/* Create an empty bus for the toplevel */
-	bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, hose);
-	if (bus == NULL) {
-		printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
-		       hose->global_number);
-		return;
-	}
-	bus->secondary = hose->first_busno;
-	hose->bus = bus;
-
-	/* Fixup IO space offset */
-	io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
-	res->start = (res->start + io_offset) & 0xffffffffu;
-	res->end = (res->end + io_offset) & 0xffffffffu;
-
-	/* Wire up PHB bus resources */
-	pcibios_setup_phb_resources(hose);
-
-	/* Scan children */
-	hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
-}
-
-static int __init pcibios_init(void)
-{
-	struct pci_controller *hose, *tmp;
-	int next_busno = 0;
-
-	printk(KERN_INFO "PCI: Probing PCI hardware\n");
-
-	/* Scan all of the recorded PCI controllers.  */
-	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
-		hose->last_busno = 0xff;
-		pcibios_scan_phb(hose);
-		printk(KERN_INFO "calling pci_bus_add_devices()\n");
-		pci_bus_add_devices(hose->bus);
-		if (next_busno <= hose->last_busno)
-			next_busno = hose->last_busno + 1;
-	}
-	pci_bus_count = next_busno;
-
-	/* Call common code to handle resource allocation */
-	pcibios_resource_survey();
-
-	return 0;
-}
-
-subsys_initcall(pcibios_init);
-
-static struct pci_controller*
-pci_bus_to_hose(int bus)
-{
-	struct pci_controller *hose, *tmp;
-
-	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
-		if (bus >= hose->first_busno && bus <= hose->last_busno)
-			return hose;
-	return NULL;
-}
-
-/* Provide information on locations of various I/O regions in physical
- * memory.  Do this on a per-card basis so that we choose the right
- * root bridge.
- * Note that the returned IO or memory base is a physical address
- */
-
-long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
-{
-	struct pci_controller *hose;
-	long result = -EOPNOTSUPP;
-
-	hose = pci_bus_to_hose(bus);
-	if (!hose)
-		return -ENODEV;
-
-	switch (which) {
-	case IOBASE_BRIDGE_NUMBER:
-		return (long)hose->first_busno;
-	case IOBASE_MEMORY:
-		return (long)hose->pci_mem_offset;
-	case IOBASE_IO:
-		return (long)hose->io_base_phys;
-	case IOBASE_ISA_IO:
-		return (long)isa_io_base;
-	case IOBASE_ISA_MEM:
-		return (long)isa_mem_base;
-	}
-
-	return result;
-}
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 4/5] x86/devicetree: Use generic PCI <-> OF matching
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
                   ` (2 preceding siblings ...)
  2011-04-07  3:26 ` [PATCH 3/5] microblaze/pci: Move the remains of pci_32.c to pci-common.c Benjamin Herrenschmidt
@ 2011-04-07  3:26 ` Benjamin Herrenschmidt
  2011-04-07 10:30   ` Sebastian Andrzej Siewior
  2011-04-07  3:26 ` [PATCH 5/5] pci/of: Consolidate pci_device_to_OF_node() Benjamin Herrenschmidt
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  3:26 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy,
	Benjamin Herrenschmidt

Instead of walking the whole PCI tree to update the of_node's for
PCI busses and devices after the fact, enable the new generic core
code for doing so by providing the proper device nodes for the
PCI host bridges

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 arch/x86/kernel/devicetree.c |   62 +++++++++++++----------------------------
 1 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index 706a9fb..f6c9d67 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -123,6 +123,26 @@ static int __init add_bus_probe(void)
 module_init(add_bus_probe);
 
 #ifdef CONFIG_PCI
+struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
+{
+	struct device_node *np;
+	unsigned int bus_min;
+
+	for_each_node_by_type(np, "pci") {
+		const void *prop;
+		struct pci_bus *bus;
+		unsigned int bus_min;
+		struct device_node *child;
+
+		prop = of_get_property(np, "bus-range", NULL);
+		if (!prop)
+			continue;
+		bus_min = be32_to_cpup(prop);
+		if (bus->number == bus_min)
+			return np;
+	}
+}
+
 static int x86_of_pci_irq_enable(struct pci_dev *dev)
 {
 	struct of_irq oirq;
@@ -154,50 +174,8 @@ static void x86_of_pci_irq_disable(struct pci_dev *dev)
 
 void __cpuinit x86_of_pci_init(void)
 {
-	struct device_node *np;
-
 	pcibios_enable_irq = x86_of_pci_irq_enable;
 	pcibios_disable_irq = x86_of_pci_irq_disable;
-
-	for_each_node_by_type(np, "pci") {
-		const void *prop;
-		struct pci_bus *bus;
-		unsigned int bus_min;
-		struct device_node *child;
-
-		prop = of_get_property(np, "bus-range", NULL);
-		if (!prop)
-			continue;
-		bus_min = be32_to_cpup(prop);
-
-		bus = pci_find_bus(0, bus_min);
-		if (!bus) {
-			printk(KERN_ERR "Can't find a node for bus %s.\n",
-					np->full_name);
-			continue;
-		}
-
-		if (bus->self)
-			bus->self->dev.of_node = np;
-		else
-			bus->dev.of_node = np;
-
-		for_each_child_of_node(np, child) {
-			struct pci_dev *dev;
-			u32 devfn;
-
-			prop = of_get_property(child, "reg", NULL);
-			if (!prop)
-				continue;
-
-			devfn = (be32_to_cpup(prop) >> 8) & 0xff;
-			dev = pci_get_slot(bus, devfn);
-			if (!dev)
-				continue;
-			dev->dev.of_node = child;
-			pci_dev_put(dev);
-		}
-	}
 }
 #endif
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 5/5] pci/of: Consolidate pci_device_to_OF_node()
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
                   ` (3 preceding siblings ...)
  2011-04-07  3:26 ` [PATCH 4/5] x86/devicetree: Use generic PCI <-> OF matching Benjamin Herrenschmidt
@ 2011-04-07  3:26 ` Benjamin Herrenschmidt
  2011-04-07 11:54 ` [PATCHES] Generalize PCI <-> OF node matching Michal Simek
  2011-04-07 22:16 ` David Miller
  6 siblings, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  3:26 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy,
	Benjamin Herrenschmidt

All archs do more or less the same thing now, move it into
a single generic place.

I chose pci.h rather than of_pci.h to avoid having to change
all call-sites to include the later.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 arch/microblaze/include/asm/pci-bridge.h |    5 -----
 arch/powerpc/include/asm/pci-bridge.h    |    5 -----
 arch/sparc/include/asm/pci_32.h          |    3 ---
 arch/sparc/include/asm/pci_64.h          |    3 ---
 arch/sparc/kernel/pci.c                  |    6 ------
 arch/sparc/kernel/pcic.c                 |    8 --------
 arch/x86/include/asm/prom.h              |    5 -----
 include/linux/pci.h                      |    5 +++++
 8 files changed, 5 insertions(+), 35 deletions(-)

diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
index da1e287..eefc152 100644
--- a/arch/microblaze/include/asm/pci-bridge.h
+++ b/arch/microblaze/include/asm/pci-bridge.h
@@ -102,11 +102,6 @@ struct pci_controller {
 };
 
 #ifdef CONFIG_PCI
-static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
-{
-	return dev->dev.of_node;
-}
-
 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
 {
 	return bus->dev.of_node;
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index 6912c45..381f1ad 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -169,11 +169,6 @@ static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
 	return bus->sysdata;
 }
 
-static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
-{
-	return dev->dev.of_node;
-}
-
 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
 {
 	return bus->dev.of_node;
diff --git a/arch/sparc/include/asm/pci_32.h b/arch/sparc/include/asm/pci_32.h
index 332ac9a..4d0c39a 100644
--- a/arch/sparc/include/asm/pci_32.h
+++ b/arch/sparc/include/asm/pci_32.h
@@ -42,9 +42,6 @@ static inline void pci_dma_burst_advice(struct pci_dev *pdev,
 }
 #endif
 
-struct device_node;
-extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
-
 #endif /* __KERNEL__ */
 
 /* generic pci stuff */
diff --git a/arch/sparc/include/asm/pci_64.h b/arch/sparc/include/asm/pci_64.h
index 948b686..2614d96 100644
--- a/arch/sparc/include/asm/pci_64.h
+++ b/arch/sparc/include/asm/pci_64.h
@@ -91,9 +91,6 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
 	return PCI_IRQ_NONE;
 }
 
-struct device_node;
-extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
-
 #define HAVE_ARCH_PCI_RESOURCE_TO_USER
 extern void pci_resource_to_user(const struct pci_dev *dev, int bar,
 				 const struct resource *rsrc,
diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index e539d23..80a87e2 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -1021,12 +1021,6 @@ void arch_teardown_msi_irq(unsigned int irq)
 }
 #endif /* !(CONFIG_PCI_MSI) */
 
-struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
-{
-	return pdev->dev.of_node;
-}
-EXPORT_SYMBOL(pci_device_to_OF_node);
-
 static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit)
 {
 	struct pci_dev *ali_isa_bridge;
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c
index 2cdc131..7558b6e 100644
--- a/arch/sparc/kernel/pcic.c
+++ b/arch/sparc/kernel/pcic.c
@@ -856,14 +856,6 @@ int pcibios_assign_resource(struct pci_dev *pdev, int resource)
 	return -ENXIO;
 }
 
-struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
-{
-	struct pcidev_cookie *pc = pdev->sysdata;
-
-	return pc->prom_node;
-}
-EXPORT_SYMBOL(pci_device_to_OF_node);
-
 /*
  * This probably belongs here rather than ioport.c because
  * we do not want this crud linked into SBus kernels.
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
index 971e0b4..dd6066a 100644
--- a/arch/x86/include/asm/prom.h
+++ b/arch/x86/include/asm/prom.h
@@ -31,11 +31,6 @@ extern void x86_add_irq_domains(void);
 void __cpuinit x86_of_pci_init(void);
 void x86_dtb_init(void);
 
-static inline struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
-{
-	return pdev ? pdev->dev.of_node : NULL;
-}
-
 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
 {
 	return pci_device_to_OF_node(bus->self);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a1f90f0..44809d3 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1554,6 +1554,11 @@ extern void pci_release_bus_of_node(struct pci_bus *bus);
 /* Arch may override this (weak) */
 extern struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus);
 
+static inline struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
+{
+	return pdev ? pdev->dev.of_node : NULL;
+}
+
 #else /* CONFIG_OF */
 static inline void pci_set_of_node(struct pci_dev *dev) { }
 static inline void pci_release_of_node(struct pci_dev *dev) { }
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
@ 2011-04-07  4:20   ` Benjamin Herrenschmidt
  2011-04-07  7:56     ` Sebastian Andrzej Siewior
  2011-04-07 12:13   ` [PATCH] x86/ce4100: add reg property to bridges Sebastian Andrzej Siewior
  2011-04-07 22:27   ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically David Miller
  2 siblings, 1 reply; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  4:20 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arch, linux-kernel, davem, bheglaas, monstr, tglx, bigeasy

On Thu, 2011-04-07 at 13:26 +1000, Benjamin Herrenschmidt wrote:
> 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).

Crap ! I got the Linutronix guys email wrong oops ... If you reply,
please beware of the CC list, s/linuxtronix.de/linutronix.de.

Thomas, Sebastian, I suppose I don't need to re-send a private copy, you
should be able to find the patches ? :-)

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07  4:20   ` Benjamin Herrenschmidt
@ 2011-04-07  7:56     ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 25+ messages in thread
From: Sebastian Andrzej Siewior @ 2011-04-07  7:56 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linux-pci, linux-arch, linux-kernel, davem, bheglaas, monstr, tglx

Benjamin Herrenschmidt wrote:
> Thomas, Sebastian, I suppose I don't need to re-send a private copy, you
> should be able to find the patches ? :-)

No worries Ben, I got them. Thanks for the ping :)

> Cheers,
> Ben.
> 
> 

Sebastian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 4/5] x86/devicetree: Use generic PCI <-> OF matching
  2011-04-07  3:26 ` [PATCH 4/5] x86/devicetree: Use generic PCI <-> OF matching Benjamin Herrenschmidt
@ 2011-04-07 10:30   ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 25+ messages in thread
From: Sebastian Andrzej Siewior @ 2011-04-07 10:30 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linux-pci, linux-arch, linux-kernel, davem, bheglaas, monstr, tglx

* Benjamin Herrenschmidt | 2011-04-07 13:26:35 [+1000]:

>Instead of walking the whole PCI tree to update the of_node's for
>PCI busses and devices after the fact, enable the new generic core
>code for doing so by providing the proper device nodes for the
>PCI host bridges
>
>Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Ben, please add this to the series or melt into this patch :)

>From 1460c529a53a393dd3b41cdcd72ecc6ff1d3646e Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Thu, 7 Apr 2011 10:47:51 +0200
Subject: [PATCH] x86: dt: remove unused and/or shadowed variables

|arch/x86/kernel/devicetree.c: In function 'pcibios_get_phb_of_node':
|arch/x86/kernel/devicetree.c:135:23: warning: unused variable 'child'
|arch/x86/kernel/devicetree.c:129:15: warning: unused variable 'bus_min'
|arch/x86/kernel/devicetree.c:144:1: warning: control reaches end of non-void function
|arch/x86/kernel/devicetree.c:141:10: warning: 'bus' may be used uninitialized in this function

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/kernel/devicetree.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index f6c9d67..3568496 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -123,16 +123,13 @@ static int __init add_bus_probe(void)
 module_init(add_bus_probe);
 
 #ifdef CONFIG_PCI
-struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
+struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
 {
 	struct device_node *np;
-	unsigned int bus_min;
 
 	for_each_node_by_type(np, "pci") {
 		const void *prop;
-		struct pci_bus *bus;
 		unsigned int bus_min;
-		struct device_node *child;
 
 		prop = of_get_property(np, "bus-range", NULL);
 		if (!prop)
@@ -141,6 +138,7 @@ struct device_node * pcibios_get_phb_of_node(struct pci_bus *bus)
 		if (bus->number == bus_min)
 			return np;
 	}
+	return NULL;
 }
 
 static int x86_of_pci_irq_enable(struct pci_dev *dev)
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCHES] Generalize PCI <-> OF node matching
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
                   ` (4 preceding siblings ...)
  2011-04-07  3:26 ` [PATCH 5/5] pci/of: Consolidate pci_device_to_OF_node() Benjamin Herrenschmidt
@ 2011-04-07 11:54 ` Michal Simek
  2011-04-07 21:50   ` Benjamin Herrenschmidt
  2011-04-07 22:16 ` David Miller
  6 siblings, 1 reply; 25+ messages in thread
From: Michal Simek @ 2011-04-07 11:54 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linux-pci, linux-arch, linux-kernel, davem, bheglaas, tglx, bigeasy

Benjamin Herrenschmidt wrote:
> This series generalize the PCI <-> OF node matching, moves it to the
> PCI core and make our archs use it. I also rip out while at it a whole
> bunch of useless stuff from microblaze PCI code which was copied from
> ppc32 and is essentially useless there (old workarounds for PowerMac
> and ancient X servers).
> 
> Compile tested on x86_64, microblaze, sparc64 and powerpc.
> 
> How do you guys want to proceed with this series ? It will quickly
> become a pre-req for other things on powerpc, so I can carry it in
> powerpc in a separate branch that I also pull into powerpc-next or
> we can have it somewhere on tip...

There are several coding style issues.
Please look at it through checkpatch.pl.

Compilation is fine for Microblaze as you surely saw.
I am not able to test it on real hw right now but I will ask for remote 
connection to the board.

Thanks,
Michal


-- 
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/
Microblaze U-BOOT custodian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH] x86/ce4100: add reg property to bridges
  2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
  2011-04-07  4:20   ` Benjamin Herrenschmidt
@ 2011-04-07 12:13   ` Sebastian Andrzej Siewior
  2011-04-07 21:52     ` Benjamin Herrenschmidt
  2011-04-11 15:40     ` [tip:x86/urgent] x86/ce4100: Add " tip-bot for Sebastian Andrzej Siewior
  2011-04-07 22:27   ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically David Miller
  2 siblings, 2 replies; 25+ messages in thread
From: Sebastian Andrzej Siewior @ 2011-04-07 12:13 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linux-pci, linux-arch, linux-kernel, davem, monstr, tglx, bigeasy

without the reg property Ben's new code won't find the PCI & ISA bridge
and the devices won't get the DT-node attached.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---

This patch can be applied independently of Ben's series but without it
we have almost no devices :).

 arch/x86/platform/ce4100/falconfalls.dts |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/x86/platform/ce4100/falconfalls.dts b/arch/x86/platform/ce4100/falconfalls.dts
index dc701ea..2d6d226 100644
--- a/arch/x86/platform/ce4100/falconfalls.dts
+++ b/arch/x86/platform/ce4100/falconfalls.dts
@@ -74,6 +74,7 @@
 				compatible = "intel,ce4100-pci", "pci";
 				device_type = "pci";
 				bus-range = <1 1>;
+				reg = <0x0800 0x0 0x0 0x0 0x0>;
 				ranges = <0x2000000 0 0xdffe0000 0x2000000 0 0xdffe0000 0 0x1000>;
 
 				interrupt-parent = <&ioapic2>;
@@ -412,6 +413,7 @@
 				#address-cells = <2>;
 				#size-cells = <1>;
 				compatible = "isa";
+				reg = <0xf800 0x0 0x0 0x0 0x0>;
 				ranges = <1 0 0 0 0 0x100>;
 
 				rtc@70 {
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCHES] Generalize PCI <-> OF node matching
  2011-04-07 11:54 ` [PATCHES] Generalize PCI <-> OF node matching Michal Simek
@ 2011-04-07 21:50   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07 21:50 UTC (permalink / raw)
  To: monstr
  Cc: linux-pci, linux-arch, linux-kernel, davem, bheglaas, tglx, bigeasy

On Thu, 2011-04-07 at 13:54 +0200, Michal Simek wrote:
> There are several coding style issues.
> Please look at it through checkpatch.pl.

I tend to generally ignore checkpatch :-) I have my reasons... I'll have
a quick look see if there's anything really worthwhile in there but in
general I dislike "absolute" rules such as what checkpatch imposes.

> Compilation is fine for Microblaze as you surely saw.
> I am not able to test it on real hw right now but I will ask for
> remote connection to the board.

Thanks.

Cheers,
Ben.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] x86/ce4100: add reg property to bridges
  2011-04-07 12:13   ` [PATCH] x86/ce4100: add reg property to bridges Sebastian Andrzej Siewior
@ 2011-04-07 21:52     ` Benjamin Herrenschmidt
  2011-04-11  7:23       ` Sebastian Andrzej Siewior
  2011-04-11 15:40     ` [tip:x86/urgent] x86/ce4100: Add " tip-bot for Sebastian Andrzej Siewior
  1 sibling, 1 reply; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07 21:52 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-pci, linux-arch, linux-kernel, davem, monstr, tglx

On Thu, 2011-04-07 at 14:13 +0200, Sebastian Andrzej Siewior wrote:
> without the reg property Ben's new code won't find the PCI & ISA bridge
> and the devices won't get the DT-node attached.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> 
> This patch can be applied independently of Ben's series but without it
> we have almost no devices :).

Thanks. Are you sending that independently or do you want me to put it
in my series before the patch that would "break" it ?

Cheers,
Ben.

>  arch/x86/platform/ce4100/falconfalls.dts |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/platform/ce4100/falconfalls.dts b/arch/x86/platform/ce4100/falconfalls.dts
> index dc701ea..2d6d226 100644
> --- a/arch/x86/platform/ce4100/falconfalls.dts
> +++ b/arch/x86/platform/ce4100/falconfalls.dts
> @@ -74,6 +74,7 @@
>  				compatible = "intel,ce4100-pci", "pci";
>  				device_type = "pci";
>  				bus-range = <1 1>;
> +				reg = <0x0800 0x0 0x0 0x0 0x0>;
>  				ranges = <0x2000000 0 0xdffe0000 0x2000000 0 0xdffe0000 0 0x1000>;
>  
>  				interrupt-parent = <&ioapic2>;
> @@ -412,6 +413,7 @@
>  				#address-cells = <2>;
>  				#size-cells = <1>;
>  				compatible = "isa";
> +				reg = <0xf800 0x0 0x0 0x0 0x0>;
>  				ranges = <1 0 0 0 0 0x100>;
>  
>  				rtc@70 {



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCHES] Generalize PCI <-> OF node matching
  2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
                   ` (5 preceding siblings ...)
  2011-04-07 11:54 ` [PATCHES] Generalize PCI <-> OF node matching Michal Simek
@ 2011-04-07 22:16 ` David Miller
  2011-04-07 22:30   ` Benjamin Herrenschmidt
  6 siblings, 1 reply; 25+ messages in thread
From: David Miller @ 2011-04-07 22:16 UTC (permalink / raw)
  To: benh; +Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Thu,  7 Apr 2011 13:26:31 +1000

> This series generalize the PCI <-> OF node matching, moves it to the
> PCI core and make our archs use it. I also rip out while at it a whole
> bunch of useless stuff from microblaze PCI code which was copied from
> ppc32 and is essentially useless there (old workarounds for PowerMac
> and ancient X servers).
> 
> Compile tested on x86_64, microblaze, sparc64 and powerpc.

What tree is this against?  None of the microblaze and x86 bits
apply without rejects against Linus's tree, which is where I'm
trying to test this.

I'll trudge through it, but a heads up about what your patches
are against in the future would be heavily appreciated.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
  2011-04-07  4:20   ` Benjamin Herrenschmidt
  2011-04-07 12:13   ` [PATCH] x86/ce4100: add reg property to bridges Sebastian Andrzej Siewior
@ 2011-04-07 22:27   ` David Miller
  2011-04-07 22:29     ` David Miller
  2 siblings, 1 reply; 25+ messages in thread
From: David Miller @ 2011-04-07 22:27 UTC (permalink / raw)
  To: benh; +Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Thu,  7 Apr 2011 13:26:32 +1000

> 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>

This patch breaks the build on sparc:

> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> new file mode 100644
> index 0000000..c94d37e
> --- /dev/null
> +++ b/drivers/pci/of.c

This gets compiled in on all CONFIG_OF platforms, and:

> +void pci_set_of_node(struct pci_dev *dev)
> +{
> +	if (!dev->bus->dev.of_node)
> +		return;
> +	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
> +						    dev->devfn);
> +}

it references of_pci_find_child_device().

However, of_pci_find_child_device() lives in drivers/of/of_pci.c which is not
built into the tree because you haven't provided the necessary changes to
drivers/of/Makefile in this patch.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07 22:27   ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically David Miller
@ 2011-04-07 22:29     ` David Miller
  2011-04-07 22:31       ` David Miller
  0 siblings, 1 reply; 25+ messages in thread
From: David Miller @ 2011-04-07 22:29 UTC (permalink / raw)
  To: benh; +Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

From: David Miller <davem@davemloft.net>
Date: Thu, 07 Apr 2011 15:27:07 -0700 (PDT)

> However, of_pci_find_child_device() lives in drivers/of/of_pci.c which is not
> built into the tree because you haven't provided the necessary changes to
> drivers/of/Makefile in this patch.

Oh I see, it exists already but it's only built into the tree for
microblaze, x86, and ppc.

There's a lot of stuff in there which is superfluous and will never
be used on sparc.

Everything in there except the new of_pci_find_child_device() function
will be never ever used on sparc and therefore dead code.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCHES] Generalize PCI <-> OF node matching
  2011-04-07 22:16 ` David Miller
@ 2011-04-07 22:30   ` Benjamin Herrenschmidt
  2011-04-07 22:31     ` David Miller
  0 siblings, 1 reply; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07 22:30 UTC (permalink / raw)
  To: David Miller
  Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

On Thu, 2011-04-07 at 15:16 -0700, David Miller wrote:
> > This series generalize the PCI <-> OF node matching, moves it to the
> > PCI core and make our archs use it. I also rip out while at it a whole
> > bunch of useless stuff from microblaze PCI code which was copied from
> > ppc32 and is essentially useless there (old workarounds for PowerMac
> > and ancient X servers).
> > 
> > Compile tested on x86_64, microblaze, sparc64 and powerpc.
> 
> What tree is this against?  None of the microblaze and x86 bits
> apply without rejects against Linus's tree, which is where I'm
> trying to test this.
> 
> I'll trudge through it, but a heads up about what your patches
> are against in the future would be heavily appreciated. 

Sorry about that, it's Linus as of 3 days ago or so, commit
44148a667d3715f3a1c37eeff7e954c946cc1efe.

I'm surprised it would have changed that significantly since then but
I'll check & fixup, I can send a new one later today. I'll make sure to
specify the "anchor" commit next time.

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07 22:29     ` David Miller
@ 2011-04-07 22:31       ` David Miller
  2011-04-07 22:52         ` David Miller
  2011-04-07 23:21         ` Benjamin Herrenschmidt
  0 siblings, 2 replies; 25+ messages in thread
From: David Miller @ 2011-04-07 22:31 UTC (permalink / raw)
  To: benh; +Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: Text/Plain; charset=iso-8859-7, Size: 1761 bytes --]

From: David Miller <davem@davemloft.net>
Date: Thu, 07 Apr 2011 15:29:37 -0700 (PDT)

> From: David Miller <davem@davemloft.net>
> Date: Thu, 07 Apr 2011 15:27:07 -0700 (PDT)
> 
>> However, of_pci_find_child_device() lives in drivers/of/of_pci.c which is not
>> built into the tree because you haven't provided the necessary changes to
>> drivers/of/Makefile in this patch.
> 
> Oh I see, it exists already but it's only built into the tree for
> microblaze, x86, and ppc.
> 
> There's a lot of stuff in there which is superfluous and will never
> be used on sparc.
> 
> Everything in there except the new of_pci_find_child_device() function
> will be never ever used on sparc and therefore dead code.

Furthermore it will never build on sparc even if we wanted to do so
temporarily because it references interfaces sparc doesn't provide:

drivers/of/of_pci.c: In function ¡of_irq_map_pci¢:
drivers/of/of_pci.c:32:3: error: implicit declaration of function ¡of_irq_map_one¢ [-Werror=implicit-function-declaration]
drivers/of/of_pci.c:56:4: error: implicit declaration of function ¡pci_bus_to_OF_node¢ [-Werror=implicit-function-declaration]
drivers/of/of_pci.c:56:11: warning: assignment makes pointer from integer without a cast [enabled by default]
drivers/of/of_pci.c:90:2: error: implicit declaration of function ¡of_irq_map_raw¢ [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors

I don't think it's a good idea to mix the things you're trying to do
with all of the existing stuff in of_pci.c, why not create a new file
for the stuff you're trying to consolidate?
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCHES] Generalize PCI <-> OF node matching
  2011-04-07 22:30   ` Benjamin Herrenschmidt
@ 2011-04-07 22:31     ` David Miller
  0 siblings, 0 replies; 25+ messages in thread
From: David Miller @ 2011-04-07 22:31 UTC (permalink / raw)
  To: benh; +Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Fri, 08 Apr 2011 08:30:55 +1000

> I'm surprised it would have changed that significantly since then but
> I'll check & fixup, I can send a new one later today. I'll make sure to
> specify the "anchor" commit next time.

It's the spelling fixes bomb that went into Linus's tree eariler
today.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07 22:31       ` David Miller
@ 2011-04-07 22:52         ` David Miller
  2011-04-07 23:22           ` Benjamin Herrenschmidt
  2011-04-07 23:21         ` Benjamin Herrenschmidt
  1 sibling, 1 reply; 25+ messages in thread
From: David Miller @ 2011-04-07 22:52 UTC (permalink / raw)
  To: benh; +Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

From: David Miller <davem@davemloft.net>
Date: Thu, 07 Apr 2011 15:31:21 -0700 (PDT)

> I don't think it's a good idea to mix the things you're trying to do
> with all of the existing stuff in of_pci.c, why not create a new file
> for the stuff you're trying to consolidate?

Something like the following could be done to your first patch.

My sparc64 machine boots up properly with this change added to your
patch series:

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index f7861ed..ceb340e 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_OF_NET)	+= of_net.o
 obj-$(CONFIG_OF_SPI)	+= of_spi.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
+obj-$(CONFIG_PCI)	+= of_pci_base.o
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 9d179c4..ac1ec54 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -90,39 +90,3 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
 	return of_irq_map_raw(ppnode, &lspec_be, 1, laddr, out_irq);
 }
 EXPORT_SYMBOL_GPL(of_irq_map_pci);
-
-
-static inline int __of_pci_pci_compare(struct device_node *node, unsigned int devfn)
-{
-	unsigned int size;
-	const __be32 *reg = of_get_property(node, "reg", &size);
-
-	if (!reg || size < 5 * sizeof(__be32))
-		return 0;
-	return ((be32_to_cpup(&reg[0]) >> 8) & 0xff) == devfn;
-}
-
-struct device_node *of_pci_find_child_device(struct device_node *parent,
-					     unsigned int devfn)
-{
-	struct device_node *node, *node2;
-	
-	for_each_child_of_node(parent, node) {
-		if (__of_pci_pci_compare(node, devfn))
-			return node;
-		/*
-		 * Some OFs create a parent node "multifunc-device" as
-		 * a fake root for all functions of a multi-function
-		 * device we go down them as well.
-		 */
-                if (!strcmp(node->name, "multifunc-device")) {
-			for_each_child_of_node(node, node2) {
-				if (__of_pci_pci_compare(node2, devfn)) {
-					of_node_put(node);
-					return node2;
-				}
-			}
-                }
-	}
-	return NULL;
-}
diff --git a/drivers/of/of_pci_base.c b/drivers/of/of_pci_base.c
new file mode 100644
index 0000000..c5a2d96
--- /dev/null
+++ b/drivers/of/of_pci_base.c
@@ -0,0 +1,39 @@
+#include <linux/kernel.h>
+#include <linux/of_pci.h>
+#include <linux/of_irq.h>
+#include <asm/prom.h>
+
+static inline int __of_pci_pci_compare(struct device_node *node, unsigned int devfn)
+{
+	unsigned int size;
+	const __be32 *reg = of_get_property(node, "reg", &size);
+
+	if (!reg || size < 5 * sizeof(__be32))
+		return 0;
+	return ((be32_to_cpup(&reg[0]) >> 8) & 0xff) == devfn;
+}
+
+struct device_node *of_pci_find_child_device(struct device_node *parent,
+					     unsigned int devfn)
+{
+	struct device_node *node, *node2;
+	
+	for_each_child_of_node(parent, node) {
+		if (__of_pci_pci_compare(node, devfn))
+			return node;
+		/*
+		 * Some OFs create a parent node "multifunc-device" as
+		 * a fake root for all functions of a multi-function
+		 * device we go down them as well.
+		 */
+                if (!strcmp(node->name, "multifunc-device")) {
+			for_each_child_of_node(node, node2) {
+				if (__of_pci_pci_compare(node2, devfn)) {
+					of_node_put(node);
+					return node2;
+				}
+			}
+                }
+	}
+	return NULL;
+}
-- 
1.7.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07 22:31       ` David Miller
  2011-04-07 22:52         ` David Miller
@ 2011-04-07 23:21         ` Benjamin Herrenschmidt
  1 sibling, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07 23:21 UTC (permalink / raw)
  To: David Miller
  Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

On Thu, 2011-04-07 at 15:31 -0700, David Miller wrote:
> I don't think it's a good idea to mix the things you're trying to do
> with all of the existing stuff in of_pci.c, why not create a new file
> for the stuff you're trying to consolidate? 

I can move that new function to pci/of.c then. 

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically
  2011-04-07 22:52         ` David Miller
@ 2011-04-07 23:22           ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07 23:22 UTC (permalink / raw)
  To: David Miller
  Cc: linux-pci, linux-arch, linux-kernel, bheglaas, monstr, tglx, bigeasy

On Thu, 2011-04-07 at 15:52 -0700, David Miller wrote:
> > I don't think it's a good idea to mix the things you're trying to do
> > with all of the existing stuff in of_pci.c, why not create a new
> file
> > for the stuff you're trying to consolidate?
> 
> Something like the following could be done to your first patch.
> 
> My sparc64 machine boots up properly with this change added to your
> patch series:

Ok, thanks for testing !

Grant, do you prefer this or that I move the function to
drivers/pci/of.c ?

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] x86/ce4100: add reg property to bridges
  2011-04-07 21:52     ` Benjamin Herrenschmidt
@ 2011-04-11  7:23       ` Sebastian Andrzej Siewior
  2011-04-11  9:38         ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 25+ messages in thread
From: Sebastian Andrzej Siewior @ 2011-04-11  7:23 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linux-pci, linux-arch, linux-kernel, davem, monstr, tglx

* Benjamin Herrenschmidt | 2011-04-08 07:52:39 [+1000]:

>Thanks. Are you sending that independently or do you want me to put it
>in my series before the patch that would "break" it ?

I would prefer to get it into 39 so I don't have a device tree which
does not work on a later kernel version.

>Cheers,
>Ben.

Sebastian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] x86/ce4100: add reg property to bridges
  2011-04-11  7:23       ` Sebastian Andrzej Siewior
@ 2011-04-11  9:38         ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-11  9:38 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-pci, linux-arch, linux-kernel, davem, monstr, tglx

On Mon, 2011-04-11 at 09:23 +0200, Sebastian Andrzej Siewior wrote:
> * Benjamin Herrenschmidt | 2011-04-08 07:52:39 [+1000]:
> 
> >Thanks. Are you sending that independently or do you want me to put it
> >in my series before the patch that would "break" it ?
> 
> I would prefer to get it into 39 so I don't have a device tree which
> does not work on a later kernel version.

I've put merged the patch in my series. That's easier for testing.

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [tip:x86/urgent] x86/ce4100: Add reg property to bridges
  2011-04-07 12:13   ` [PATCH] x86/ce4100: add reg property to bridges Sebastian Andrzej Siewior
  2011-04-07 21:52     ` Benjamin Herrenschmidt
@ 2011-04-11 15:40     ` tip-bot for Sebastian Andrzej Siewior
  1 sibling, 0 replies; 25+ messages in thread
From: tip-bot for Sebastian Andrzej Siewior @ 2011-04-11 15:40 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, benh, bigeasy, tglx, mingo

Commit-ID:  30d746c68025ee69ac17219aacc9b1614d951f01
Gitweb:     http://git.kernel.org/tip/30d746c68025ee69ac17219aacc9b1614d951f01
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Thu, 7 Apr 2011 14:13:15 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 11 Apr 2011 17:37:02 +0200

x86/ce4100: Add reg property to bridges

without the reg property Ben's new code won't find the PCI & ISA
bridge and the devices won't get the DT-node attached.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: monstr@monstr.eu
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Link: http://lkml.kernel.org/r/20110407121315.GA9204@linutronix.de
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/platform/ce4100/falconfalls.dts |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/x86/platform/ce4100/falconfalls.dts b/arch/x86/platform/ce4100/falconfalls.dts
index dc701ea..2d6d226 100644
--- a/arch/x86/platform/ce4100/falconfalls.dts
+++ b/arch/x86/platform/ce4100/falconfalls.dts
@@ -74,6 +74,7 @@
 				compatible = "intel,ce4100-pci", "pci";
 				device_type = "pci";
 				bus-range = <1 1>;
+				reg = <0x0800 0x0 0x0 0x0 0x0>;
 				ranges = <0x2000000 0 0xdffe0000 0x2000000 0 0xdffe0000 0 0x1000>;
 
 				interrupt-parent = <&ioapic2>;
@@ -412,6 +413,7 @@
 				#address-cells = <2>;
 				#size-cells = <1>;
 				compatible = "isa";
+				reg = <0xf800 0x0 0x0 0x0 0x0>;
 				ranges = <1 0 0 0 0 0x100>;
 
 				rtc@70 {

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2011-04-11 15:40 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07  3:26 [PATCHES] Generalize PCI <-> OF node matching Benjamin Herrenschmidt
2011-04-07  3:26 ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically Benjamin Herrenschmidt
2011-04-07  4:20   ` Benjamin Herrenschmidt
2011-04-07  7:56     ` Sebastian Andrzej Siewior
2011-04-07 12:13   ` [PATCH] x86/ce4100: add reg property to bridges Sebastian Andrzej Siewior
2011-04-07 21:52     ` Benjamin Herrenschmidt
2011-04-11  7:23       ` Sebastian Andrzej Siewior
2011-04-11  9:38         ` Benjamin Herrenschmidt
2011-04-11 15:40     ` [tip:x86/urgent] x86/ce4100: Add " tip-bot for Sebastian Andrzej Siewior
2011-04-07 22:27   ` [PATCH 1/5] pci/of: Match PCI devices to OF nodes dynamically David Miller
2011-04-07 22:29     ` David Miller
2011-04-07 22:31       ` David Miller
2011-04-07 22:52         ` David Miller
2011-04-07 23:22           ` Benjamin Herrenschmidt
2011-04-07 23:21         ` Benjamin Herrenschmidt
2011-04-07  3:26 ` [PATCH 2/5] microblaze/pci: Remove powermac originated cruft Benjamin Herrenschmidt
2011-04-07  3:26 ` [PATCH 3/5] microblaze/pci: Move the remains of pci_32.c to pci-common.c Benjamin Herrenschmidt
2011-04-07  3:26 ` [PATCH 4/5] x86/devicetree: Use generic PCI <-> OF matching Benjamin Herrenschmidt
2011-04-07 10:30   ` Sebastian Andrzej Siewior
2011-04-07  3:26 ` [PATCH 5/5] pci/of: Consolidate pci_device_to_OF_node() Benjamin Herrenschmidt
2011-04-07 11:54 ` [PATCHES] Generalize PCI <-> OF node matching Michal Simek
2011-04-07 21:50   ` Benjamin Herrenschmidt
2011-04-07 22:16 ` David Miller
2011-04-07 22:30   ` Benjamin Herrenschmidt
2011-04-07 22:31     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).