All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] of/address: merge of_iomap()
       [not found] <20100608140917.25879.67745.stgit@angua>
@ 2010-06-08 14:09 ` Grant Likely
  2010-06-10  6:40   ` Benjamin Herrenschmidt
  2010-06-08 14:10 ` [PATCH 2/5] of/address: merge of_address_to_resource() Grant Likely
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:09 UTC (permalink / raw)
  Cc: Stephen Rothwell, Michal Simek, linuxppc-dev, microblaze-uclinux

Merge common code between Microblaze and PowerPC.  This patch creates
new of_address.h and address.c files to containing address translation
and mapping routines.  First routine to be moved it of_iomap()

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
CC: Michal Simek <monstr@monstr.eu>
CC: Wolfram Sang <w.sang@pengutronix.de>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: microblaze-uclinux@itee.uq.edu.au
CC: linuxppc-dev@ozlabs.org
---
 arch/microblaze/include/asm/prom.h  |   10 +---------
 arch/microblaze/kernel/prom_parse.c |   11 -----------
 arch/powerpc/include/asm/prom.h     |   10 +---------
 arch/powerpc/kernel/prom_parse.c    |   11 -----------
 drivers/of/Kconfig                  |    4 ++++
 drivers/of/Makefile                 |    1 +
 drivers/of/address.c                |   22 ++++++++++++++++++++++
 include/linux/of_address.h          |    9 +++++++++
 8 files changed, 38 insertions(+), 40 deletions(-)
 create mode 100644 drivers/of/address.c
 create mode 100644 include/linux/of_address.h

diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
index 3659930..b6698ef 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -20,6 +20,7 @@
 #ifndef __ASSEMBLY__
 
 #include <linux/types.h>
+#include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/of_fdt.h>
 #include <linux/proc_fs.h>
@@ -107,15 +108,6 @@ extern const void *of_get_mac_address(struct device_node *np);
 struct pci_dev;
 extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
 
-/**
- * of_iomap - Maps the memory mapped IO for a given device_node
- * @device:	the device whose io range will be mapped
- * @index:	index of the io range
- *
- * Returns a pointer to the mapped memory
- */
-extern void __iomem *of_iomap(struct device_node *device, int index);
-
 #endif /* __ASSEMBLY__ */
 #endif /* __KERNEL__ */
 #endif /* _ASM_MICROBLAZE_PROM_H */
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
index 70c0471..5003ee8 100644
--- a/arch/microblaze/kernel/prom_parse.c
+++ b/arch/microblaze/kernel/prom_parse.c
@@ -697,14 +697,3 @@ const void *of_get_mac_address(struct device_node *np)
 	return NULL;
 }
 EXPORT_SYMBOL(of_get_mac_address);
-
-void __iomem *of_iomap(struct device_node *np, int index)
-{
-	struct resource res;
-
-	if (of_address_to_resource(np, index, &res))
-		return NULL;
-
-	return ioremap(res.start, 1 + res.end - res.start);
-}
-EXPORT_SYMBOL(of_iomap);
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index 2440984..e0bdbc6 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -18,6 +18,7 @@
  */
 #include <linux/types.h>
 #include <linux/of_fdt.h>
+#include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/proc_fs.h>
 #include <linux/platform_device.h>
@@ -136,14 +137,5 @@ extern void of_irq_map_init(unsigned int flags);
 struct pci_dev;
 extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
 
-/**
- * of_iomap - Maps the memory mapped IO for a given device_node
- * @device:	the device whose io range will be mapped
- * @index:	index of the io range
- *
- * Returns a pointer to the mapped memory
- */
-extern void __iomem *of_iomap(struct device_node *device, int index);
-
 #endif /* __KERNEL__ */
 #endif /* _POWERPC_PROM_H */
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index ef518e3..dfb73c4 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -822,14 +822,3 @@ const void *of_get_mac_address(struct device_node *np)
 	return NULL;
 }
 EXPORT_SYMBOL(of_get_mac_address);
-
-void __iomem *of_iomap(struct device_node *np, int index)
-{
-	struct resource res;
-
-	if (of_address_to_resource(np, index, &res))
-		return NULL;
-
-	return ioremap(res.start, 1 + res.end - res.start);
-}
-EXPORT_SYMBOL(of_iomap);
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index b87495e..097f42a 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -6,6 +6,10 @@ config OF_DYNAMIC
 	def_bool y
 	depends on OF && PPC_OF
 
+config OF_ADDRESS
+	def_bool y
+	depends on OF && !SPARC
+
 config OF_IRQ
 	def_bool y
 	depends on OF && !SPARC
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 3631a5e..0052c40 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,5 +1,6 @@
 obj-y = base.o
 obj-$(CONFIG_OF_FLATTREE) += fdt.o
+obj-$(CONFIG_OF_ADDRESS)  += address.o
 obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
diff --git a/drivers/of/address.c b/drivers/of/address.c
new file mode 100644
index 0000000..258528d
--- /dev/null
+++ b/drivers/of/address.c
@@ -0,0 +1,22 @@
+
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/of_address.h>
+
+/**
+ * of_iomap - Maps the memory mapped IO for a given device_node
+ * @device:	the device whose io range will be mapped
+ * @index:	index of the io range
+ *
+ * Returns a pointer to the mapped memory
+ */
+void __iomem *of_iomap(struct device_node *np, int index)
+{
+	struct resource res;
+
+	if (of_address_to_resource(np, index, &res))
+		return NULL;
+
+	return ioremap(res.start, 1 + res.end - res.start);
+}
+EXPORT_SYMBOL(of_iomap);
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
new file mode 100644
index 0000000..570831d
--- /dev/null
+++ b/include/linux/of_address.h
@@ -0,0 +1,9 @@
+#ifndef __OF_ADDRESS_H
+#define __OF_ADDRESS_H
+#include <linux/ioport.h>
+#include <linux/of.h>
+
+extern void __iomem *of_iomap(struct device_node *device, int index);
+
+#endif /* __OF_ADDRESS_H */
+

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

* [PATCH 2/5] of/address: merge of_address_to_resource()
       [not found] <20100608140917.25879.67745.stgit@angua>
  2010-06-08 14:09 ` [PATCH 1/5] of/address: merge of_iomap() Grant Likely
@ 2010-06-08 14:10 ` Grant Likely
  2010-06-10  6:41   ` Benjamin Herrenschmidt
  2010-06-08 14:10 ` [PATCH 3/5] of/address: Merge all of the bus translation code Grant Likely
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:10 UTC (permalink / raw)
  Cc: Stephen Rothwell, Michal Simek, linuxppc-dev, microblaze-uclinux

Merge common code between PowerPC and Microblaze.  This patch also
moves the prototype of pci_address_to_pio() out of pci-bridge.h and
into prom.h because the only user of pci_address_to_pio() is
of_address_to_resource().

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
CC: Michal Simek <monstr@monstr.eu>
CC: Grant Likely <grant.likely@secretlab.ca>
CC: Wolfram Sang <w.sang@pengutronix.de>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: microblaze-uclinux@itee.uq.edu.au
CC: linuxppc-dev@ozlabs.org
---
 arch/microblaze/include/asm/pci-bridge.h |    5 ---
 arch/microblaze/include/asm/prom.h       |   17 +++++-----
 arch/microblaze/kernel/prom_parse.c      |   46 +--------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 ---
 arch/powerpc/include/asm/prom.h          |   17 +++++-----
 arch/powerpc/kernel/prom_parse.c         |   47 +---------------------------
 drivers/of/address.c                     |   51 ++++++++++++++++++++++++++++++
 include/linux/of_address.h               |    5 +++
 8 files changed, 76 insertions(+), 117 deletions(-)

diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
index 0c77cda..0c68764 100644
--- a/arch/microblaze/include/asm/pci-bridge.h
+++ b/arch/microblaze/include/asm/pci-bridge.h
@@ -172,13 +172,8 @@ static inline int pci_has_flag(int flag)
 
 extern struct list_head hose_list;
 
-extern unsigned long pci_address_to_pio(phys_addr_t address);
 extern int pcibios_vaddr_is_ioport(void __iomem *address);
 #else
-static inline unsigned long pci_address_to_pio(phys_addr_t address)
-{
-	return (unsigned long)-1;
-}
 static inline int pcibios_vaddr_is_ioport(void __iomem *address)
 {
 	return 0;
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
index b6698ef..644fa32 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -65,17 +65,18 @@ extern const u32 *of_get_address(struct device_node *dev, int index,
 extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
 			u64 *size, unsigned int *flags);
 
-/* Get an address as a resource. Note that if your address is
- * a PIO address, the conversion will fail if the physical address
- * can't be internally converted to an IO token with
- * pci_address_to_pio(), that is because it's either called to early
- * or it can't be matched to any host bridge IO space
- */
-extern int of_address_to_resource(struct device_node *dev, int index,
-				struct resource *r);
 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
 				struct resource *r);
 
+#ifdef CONFIG_PCI
+extern unsigned long pci_address_to_pio(phys_addr_t address);
+#else
+static inline unsigned long pci_address_to_pio(phys_addr_t address)
+{
+	return (unsigned long)-1;
+}
+#endif	/* CONFIG_PCI */
+
 /* Parse the ibm,dma-window property of an OF node into the busno, phys and
  * size parameters.
  */
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
index 5003ee8..7cb5a98 100644
--- a/arch/microblaze/kernel/prom_parse.c
+++ b/arch/microblaze/kernel/prom_parse.c
@@ -6,6 +6,7 @@
 #include <linux/module.h>
 #include <linux/ioport.h>
 #include <linux/etherdevice.h>
+#include <linux/of_address.h>
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
 
@@ -17,9 +18,6 @@
 			(ns) > 0)
 
 static struct of_bus *of_match_bus(struct device_node *np);
-static int __of_address_to_resource(struct device_node *dev,
-		const u32 *addrp, u64 size, unsigned int flags,
-		struct resource *r);
 
 /* Debug utility */
 #ifdef DEBUG
@@ -576,48 +574,6 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
 }
 EXPORT_SYMBOL(of_get_address);
 
-static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
-				u64 size, unsigned int flags,
-				struct resource *r)
-{
-	u64 taddr;
-
-	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
-		return -EINVAL;
-	taddr = of_translate_address(dev, addrp);
-	if (taddr == OF_BAD_ADDR)
-		return -EINVAL;
-	memset(r, 0, sizeof(struct resource));
-	if (flags & IORESOURCE_IO) {
-		unsigned long port;
-		port = -1; /* pci_address_to_pio(taddr); */
-		if (port == (unsigned long)-1)
-			return -EINVAL;
-		r->start = port;
-		r->end = port + size - 1;
-	} else {
-		r->start = taddr;
-		r->end = taddr + size - 1;
-	}
-	r->flags = flags;
-	r->name = dev->name;
-	return 0;
-}
-
-int of_address_to_resource(struct device_node *dev, int index,
-			struct resource *r)
-{
-	const u32	*addrp;
-	u64		size;
-	unsigned int	flags;
-
-	addrp = of_get_address(dev, index, &size, &flags);
-	if (addrp == NULL)
-		return -EINVAL;
-	return __of_address_to_resource(dev, addrp, size, flags, r);
-}
-EXPORT_SYMBOL_GPL(of_address_to_resource);
-
 void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
 		unsigned long *busno, unsigned long *phys, unsigned long *size)
 {
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index 76e1f31..51e9e6f 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -303,13 +303,8 @@ extern void pcibios_free_controller(struct pci_controller *phb);
 extern void pcibios_setup_phb_resources(struct pci_controller *hose);
 
 #ifdef CONFIG_PCI
-extern unsigned long pci_address_to_pio(phys_addr_t address);
 extern int pcibios_vaddr_is_ioport(void __iomem *address);
 #else
-static inline unsigned long pci_address_to_pio(phys_addr_t address)
-{
-	return (unsigned long)-1;
-}
 static inline int pcibios_vaddr_is_ioport(void __iomem *address)
 {
 	return 0;
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index e0bdbc6..e1c1bdd 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -70,14 +70,6 @@ static inline const u32 *of_get_pci_address(struct device_node *dev,
 }
 #endif /* CONFIG_PCI */
 
-/* Get an address as a resource. Note that if your address is
- * a PIO address, the conversion will fail if the physical address
- * can't be internally converted to an IO token with
- * pci_address_to_pio(), that is because it's either called to early
- * or it can't be matched to any host bridge IO space
- */
-extern int of_address_to_resource(struct device_node *dev, int index,
-				  struct resource *r);
 #ifdef CONFIG_PCI
 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
 				      struct resource *r);
@@ -89,6 +81,15 @@ static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
 }
 #endif /* CONFIG_PCI */
 
+#ifdef CONFIG_PCI
+extern unsigned long pci_address_to_pio(phys_addr_t address);
+#else
+static inline unsigned long pci_address_to_pio(phys_addr_t address)
+{
+	return (unsigned long)-1;
+}
+#endif	/* CONFIG_PCI */
+
 /* Parse the ibm,dma-window property of an OF node into the busno, phys and
  * size parameters.
  */
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index dfb73c4..a2ef129 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -6,6 +6,7 @@
 #include <linux/module.h>
 #include <linux/ioport.h>
 #include <linux/etherdevice.h>
+#include <linux/of_address.h>
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
 
@@ -27,10 +28,6 @@
 			(ns) > 0)
 
 static struct of_bus *of_match_bus(struct device_node *np);
-static int __of_address_to_resource(struct device_node *dev,
-		const u32 *addrp, u64 size, unsigned int flags,
-		struct resource *r);
-
 
 /* Debug utility */
 #ifdef DEBUG
@@ -610,48 +607,6 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
 }
 EXPORT_SYMBOL(of_get_address);
 
-static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
-				    u64 size, unsigned int flags,
-				    struct resource *r)
-{
-	u64 taddr;
-
-	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
-		return -EINVAL;
-	taddr = of_translate_address(dev, addrp);
-	if (taddr == OF_BAD_ADDR)
-		return -EINVAL;
-	memset(r, 0, sizeof(struct resource));
-	if (flags & IORESOURCE_IO) {
-		unsigned long port;
-		port = pci_address_to_pio(taddr);
-		if (port == (unsigned long)-1)
-			return -EINVAL;
-		r->start = port;
-		r->end = port + size - 1;
-	} else {
-		r->start = taddr;
-		r->end = taddr + size - 1;
-	}
-	r->flags = flags;
-	r->name = dev->name;
-	return 0;
-}
-
-int of_address_to_resource(struct device_node *dev, int index,
-			   struct resource *r)
-{
-	const u32	*addrp;
-	u64		size;
-	unsigned int	flags;
-
-	addrp = of_get_address(dev, index, &size, &flags);
-	if (addrp == NULL)
-		return -EINVAL;
-	return __of_address_to_resource(dev, addrp, size, flags, r);
-}
-EXPORT_SYMBOL_GPL(of_address_to_resource);
-
 void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
 		unsigned long *busno, unsigned long *phys, unsigned long *size)
 {
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 258528d..c381955 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -3,6 +3,57 @@
 #include <linux/ioport.h>
 #include <linux/of_address.h>
 
+int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
+			     u64 size, unsigned int flags,
+			     struct resource *r)
+{
+	u64 taddr;
+
+	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
+		return -EINVAL;
+	taddr = of_translate_address(dev, addrp);
+	if (taddr == OF_BAD_ADDR)
+		return -EINVAL;
+	memset(r, 0, sizeof(struct resource));
+	if (flags & IORESOURCE_IO) {
+		unsigned long port;
+		port = pci_address_to_pio(taddr);
+		if (port == (unsigned long)-1)
+			return -EINVAL;
+		r->start = port;
+		r->end = port + size - 1;
+	} else {
+		r->start = taddr;
+		r->end = taddr + size - 1;
+	}
+	r->flags = flags;
+	r->name = dev->name;
+	return 0;
+}
+
+/**
+ * of_address_to_resource - Translate device tree address and return as resource
+ *
+ * Note that if your address is a PIO address, the conversion will fail if
+ * the physical address can't be internally converted to an IO token with
+ * pci_address_to_pio(), that is because it's either called to early or it
+ * can't be matched to any host bridge IO space
+ */
+int of_address_to_resource(struct device_node *dev, int index,
+			   struct resource *r)
+{
+	const u32	*addrp;
+	u64		size;
+	unsigned int	flags;
+
+	addrp = of_get_address(dev, index, &size, &flags);
+	if (addrp == NULL)
+		return -EINVAL;
+	return __of_address_to_resource(dev, addrp, size, flags, r);
+}
+EXPORT_SYMBOL_GPL(of_address_to_resource);
+
+
 /**
  * of_iomap - Maps the memory mapped IO for a given device_node
  * @device:	the device whose io range will be mapped
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 570831d..474b794 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -3,6 +3,11 @@
 #include <linux/ioport.h>
 #include <linux/of.h>
 
+extern int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
+				    u64 size, unsigned int flags,
+				    struct resource *r);
+extern int of_address_to_resource(struct device_node *dev, int index,
+				  struct resource *r);
 extern void __iomem *of_iomap(struct device_node *device, int index);
 
 #endif /* __OF_ADDRESS_H */

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

* [PATCH 3/5] of/address: Merge all of the bus translation code
       [not found] <20100608140917.25879.67745.stgit@angua>
  2010-06-08 14:09 ` [PATCH 1/5] of/address: merge of_iomap() Grant Likely
  2010-06-08 14:10 ` [PATCH 2/5] of/address: merge of_address_to_resource() Grant Likely
@ 2010-06-08 14:10 ` Grant Likely
  2010-06-10  6:43   ` Benjamin Herrenschmidt
  2010-06-08 14:10 ` [PATCH 4/5] of/address: little-endian fixes Grant Likely
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:10 UTC (permalink / raw)
  Cc: Stephen Rothwell, Michal Simek, linuxppc-dev, microblaze-uclinux

Microblaze and PowerPC share a large chunk of code for translating
OF device tree data into usable addresses.  There aren't many differences
between the two, so merge the codebase wholesale rather than trying to
work out the independent bits.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
CC: Michal Simek <monstr@monstr.eu>
CC: Wolfram Sang <w.sang@pengutronix.de>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: microblaze-uclinux@itee.uq.edu.au
CC: linuxppc-dev@ozlabs.org
---
 arch/microblaze/include/asm/prom.h  |    4 
 arch/microblaze/kernel/prom_parse.c |  489 ---------------------------------
 arch/powerpc/include/asm/prom.h     |    4 
 arch/powerpc/kernel/prom_parse.c    |  515 -----------------------------------
 drivers/of/address.c                |  517 +++++++++++++++++++++++++++++++++++
 include/linux/of_address.h          |    4 
 6 files changed, 515 insertions(+), 1018 deletions(-)

diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
index 644fa32..35cb3de 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -52,10 +52,6 @@ extern void pci_create_OF_bus_map(void);
  * OF address retreival & translation
  */
 
-/* Translate an OF address block into a CPU physical address
- */
-extern u64 of_translate_address(struct device_node *np, const u32 *addr);
-
 /* Extract an address from a device, returns the region size and
  * the address space flags too. The PCI version uses a BAR number
  * instead of an absolute index
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
index 7cb5a98..1d610e6 100644
--- a/arch/microblaze/kernel/prom_parse.c
+++ b/arch/microblaze/kernel/prom_parse.c
@@ -10,213 +10,7 @@
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
 
-#define PRu64	"%llx"
-
-/* Max address size we deal with */
-#define OF_MAX_ADDR_CELLS	4
-#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
-			(ns) > 0)
-
-static struct of_bus *of_match_bus(struct device_node *np);
-
-/* Debug utility */
-#ifdef DEBUG
-static void of_dump_addr(const char *s, const u32 *addr, int na)
-{
-	printk(KERN_INFO "%s", s);
-	while (na--)
-		printk(KERN_INFO " %08x", *(addr++));
-	printk(KERN_INFO "\n");
-}
-#else
-static void of_dump_addr(const char *s, const u32 *addr, int na) { }
-#endif
-
-/* Callbacks for bus specific translators */
-struct of_bus {
-	const char	*name;
-	const char	*addresses;
-	int		(*match)(struct device_node *parent);
-	void		(*count_cells)(struct device_node *child,
-					int *addrc, int *sizec);
-	u64		(*map)(u32 *addr, const u32 *range,
-				int na, int ns, int pna);
-	int		(*translate)(u32 *addr, u64 offset, int na);
-	unsigned int	(*get_flags)(const u32 *addr);
-};
-
-/*
- * Default translator (generic bus)
- */
-
-static void of_bus_default_count_cells(struct device_node *dev,
-					int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = of_n_addr_cells(dev);
-	if (sizec)
-		*sizec = of_n_size_cells(dev);
-}
-
-static u64 of_bus_default_map(u32 *addr, const u32 *range,
-		int na, int ns, int pna)
-{
-	u64 cp, s, da;
-
-	cp = of_read_number(range, na);
-	s  = of_read_number(range + na + pna, ns);
-	da = of_read_number(addr, na);
-
-	pr_debug("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
-		cp, s, da);
-
-	if (da < cp || da >= (cp + s))
-		return OF_BAD_ADDR;
-	return da - cp;
-}
-
-static int of_bus_default_translate(u32 *addr, u64 offset, int na)
-{
-	u64 a = of_read_number(addr, na);
-	memset(addr, 0, na * 4);
-	a += offset;
-	if (na > 1)
-		addr[na - 2] = a >> 32;
-	addr[na - 1] = a & 0xffffffffu;
-
-	return 0;
-}
-
-static unsigned int of_bus_default_get_flags(const u32 *addr)
-{
-	return IORESOURCE_MEM;
-}
-
 #ifdef CONFIG_PCI
-/*
- * PCI bus specific translator
- */
-
-static int of_bus_pci_match(struct device_node *np)
-{
-	/* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
-	return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
-}
-
-static void of_bus_pci_count_cells(struct device_node *np,
-				int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = 3;
-	if (sizec)
-		*sizec = 2;
-}
-
-static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
-{
-	u64 cp, s, da;
-
-	/* Check address type match */
-	if ((addr[0] ^ range[0]) & 0x03000000)
-		return OF_BAD_ADDR;
-
-	/* Read address values, skipping high cell */
-	cp = of_read_number(range + 1, na - 1);
-	s  = of_read_number(range + na + pna, ns);
-	da = of_read_number(addr + 1, na - 1);
-
-	pr_debug("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
-
-	if (da < cp || da >= (cp + s))
-		return OF_BAD_ADDR;
-	return da - cp;
-}
-
-static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
-{
-	return of_bus_default_translate(addr + 1, offset, na - 1);
-}
-
-static unsigned int of_bus_pci_get_flags(const u32 *addr)
-{
-	unsigned int flags = 0;
-	u32 w = addr[0];
-
-	switch ((w >> 24) & 0x03) {
-	case 0x01:
-		flags |= IORESOURCE_IO;
-		break;
-	case 0x02: /* 32 bits */
-	case 0x03: /* 64 bits */
-		flags |= IORESOURCE_MEM;
-		break;
-	}
-	if (w & 0x40000000)
-		flags |= IORESOURCE_PREFETCH;
-	return flags;
-}
-
-const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
-			unsigned int *flags)
-{
-	const u32 *prop;
-	unsigned int psize;
-	struct device_node *parent;
-	struct of_bus *bus;
-	int onesize, i, na, ns;
-
-	/* Get parent & match bus type */
-	parent = of_get_parent(dev);
-	if (parent == NULL)
-		return NULL;
-	bus = of_match_bus(parent);
-	if (strcmp(bus->name, "pci")) {
-		of_node_put(parent);
-		return NULL;
-	}
-	bus->count_cells(dev, &na, &ns);
-	of_node_put(parent);
-	if (!OF_CHECK_COUNTS(na, ns))
-		return NULL;
-
-	/* Get "reg" or "assigned-addresses" property */
-	prop = of_get_property(dev, bus->addresses, &psize);
-	if (prop == NULL)
-		return NULL;
-	psize /= 4;
-
-	onesize = na + ns;
-	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
-		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
-			if (size)
-				*size = of_read_number(prop + na, ns);
-			if (flags)
-				*flags = bus->get_flags(prop);
-			return prop;
-		}
-	return NULL;
-}
-EXPORT_SYMBOL(of_get_pci_address);
-
-int of_pci_address_to_resource(struct device_node *dev, int bar,
-				struct resource *r)
-{
-	const u32	*addrp;
-	u64		size;
-	unsigned int	flags;
-
-	addrp = of_get_pci_address(dev, bar, &size, &flags);
-	if (addrp == NULL)
-		return -EINVAL;
-	return __of_address_to_resource(dev, addrp, size, flags, r);
-}
-EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
-
-static u8 of_irq_pci_swizzle(u8 slot, u8 pin)
-{
-	return (((pin - 1) + slot) % 4) + 1;
-}
-
 int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
 {
 	struct device_node *dn, *ppnode;
@@ -291,289 +85,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
 EXPORT_SYMBOL_GPL(of_irq_map_pci);
 #endif /* CONFIG_PCI */
 
-/*
- * ISA bus specific translator
- */
-
-static int of_bus_isa_match(struct device_node *np)
-{
-	return !strcmp(np->name, "isa");
-}
-
-static void of_bus_isa_count_cells(struct device_node *child,
-				int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = 2;
-	if (sizec)
-		*sizec = 1;
-}
-
-static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
-{
-	u64 cp, s, da;
-
-	/* Check address type match */
-	if ((addr[0] ^ range[0]) & 0x00000001)
-		return OF_BAD_ADDR;
-
-	/* Read address values, skipping high cell */
-	cp = of_read_number(range + 1, na - 1);
-	s  = of_read_number(range + na + pna, ns);
-	da = of_read_number(addr + 1, na - 1);
-
-	pr_debug("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
-
-	if (da < cp || da >= (cp + s))
-		return OF_BAD_ADDR;
-	return da - cp;
-}
-
-static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
-{
-	return of_bus_default_translate(addr + 1, offset, na - 1);
-}
-
-static unsigned int of_bus_isa_get_flags(const u32 *addr)
-{
-	unsigned int flags = 0;
-	u32 w = addr[0];
-
-	if (w & 1)
-		flags |= IORESOURCE_IO;
-	else
-		flags |= IORESOURCE_MEM;
-	return flags;
-}
-
-/*
- * Array of bus specific translators
- */
-
-static struct of_bus of_busses[] = {
-#ifdef CONFIG_PCI
-	/* PCI */
-	{
-		.name = "pci",
-		.addresses = "assigned-addresses",
-		.match = of_bus_pci_match,
-		.count_cells = of_bus_pci_count_cells,
-		.map = of_bus_pci_map,
-		.translate = of_bus_pci_translate,
-		.get_flags = of_bus_pci_get_flags,
-	},
-#endif /* CONFIG_PCI */
-	/* ISA */
-	{
-		.name = "isa",
-		.addresses = "reg",
-		.match = of_bus_isa_match,
-		.count_cells = of_bus_isa_count_cells,
-		.map = of_bus_isa_map,
-		.translate = of_bus_isa_translate,
-		.get_flags = of_bus_isa_get_flags,
-	},
-	/* Default */
-	{
-		.name = "default",
-		.addresses = "reg",
-		.match = NULL,
-		.count_cells = of_bus_default_count_cells,
-		.map = of_bus_default_map,
-		.translate = of_bus_default_translate,
-		.get_flags = of_bus_default_get_flags,
-	},
-};
-
-static struct of_bus *of_match_bus(struct device_node *np)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(of_busses); i++)
-		if (!of_busses[i].match || of_busses[i].match(np))
-			return &of_busses[i];
-	BUG();
-	return NULL;
-}
-
-static int of_translate_one(struct device_node *parent, struct of_bus *bus,
-			struct of_bus *pbus, u32 *addr,
-			int na, int ns, int pna)
-{
-	const u32 *ranges;
-	unsigned int rlen;
-	int rone;
-	u64 offset = OF_BAD_ADDR;
-
-	/* Normally, an absence of a "ranges" property means we are
-	 * crossing a non-translatable boundary, and thus the addresses
-	 * below the current not cannot be converted to CPU physical ones.
-	 * Unfortunately, while this is very clear in the spec, it's not
-	 * what Apple understood, and they do have things like /uni-n or
-	 * /ht nodes with no "ranges" property and a lot of perfectly
-	 * useable mapped devices below them. Thus we treat the absence of
-	 * "ranges" as equivalent to an empty "ranges" property which means
-	 * a 1:1 translation at that level. It's up to the caller not to try
-	 * to translate addresses that aren't supposed to be translated in
-	 * the first place. --BenH.
-	 */
-	ranges = of_get_property(parent, "ranges", (int *) &rlen);
-	if (ranges == NULL || rlen == 0) {
-		offset = of_read_number(addr, na);
-		memset(addr, 0, pna * 4);
-		pr_debug("OF: no ranges, 1:1 translation\n");
-		goto finish;
-	}
-
-	pr_debug("OF: walking ranges...\n");
-
-	/* Now walk through the ranges */
-	rlen /= 4;
-	rone = na + pna + ns;
-	for (; rlen >= rone; rlen -= rone, ranges += rone) {
-		offset = bus->map(addr, ranges, na, ns, pna);
-		if (offset != OF_BAD_ADDR)
-			break;
-	}
-	if (offset == OF_BAD_ADDR) {
-		pr_debug("OF: not found !\n");
-		return 1;
-	}
-	memcpy(addr, ranges + na, 4 * pna);
-
- finish:
-	of_dump_addr("OF: parent translation for:", addr, pna);
-	pr_debug("OF: with offset: "PRu64"\n", offset);
-
-	/* Translate it into parent bus space */
-	return pbus->translate(addr, offset, pna);
-}
-
-/*
- * Translate an address from the device-tree into a CPU physical address,
- * this walks up the tree and applies the various bus mappings on the
- * way.
- *
- * Note: We consider that crossing any level with #size-cells == 0 to mean
- * that translation is impossible (that is we are not dealing with a value
- * that can be mapped to a cpu physical address). This is not really specified
- * that way, but this is traditionally the way IBM at least do things
- */
-u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
-{
-	struct device_node *parent = NULL;
-	struct of_bus *bus, *pbus;
-	u32 addr[OF_MAX_ADDR_CELLS];
-	int na, ns, pna, pns;
-	u64 result = OF_BAD_ADDR;
-
-	pr_debug("OF: ** translation for device %s **\n", dev->full_name);
-
-	/* Increase refcount at current level */
-	of_node_get(dev);
-
-	/* Get parent & match bus type */
-	parent = of_get_parent(dev);
-	if (parent == NULL)
-		goto bail;
-	bus = of_match_bus(parent);
-
-	/* Cound address cells & copy address locally */
-	bus->count_cells(dev, &na, &ns);
-	if (!OF_CHECK_COUNTS(na, ns)) {
-		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
-			dev->full_name);
-		goto bail;
-	}
-	memcpy(addr, in_addr, na * 4);
-
-	pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
-		bus->name, na, ns, parent->full_name);
-	of_dump_addr("OF: translating address:", addr, na);
-
-	/* Translate */
-	for (;;) {
-		/* Switch to parent bus */
-		of_node_put(dev);
-		dev = parent;
-		parent = of_get_parent(dev);
-
-		/* If root, we have finished */
-		if (parent == NULL) {
-			pr_debug("OF: reached root node\n");
-			result = of_read_number(addr, na);
-			break;
-		}
-
-		/* Get new parent bus and counts */
-		pbus = of_match_bus(parent);
-		pbus->count_cells(dev, &pna, &pns);
-		if (!OF_CHECK_COUNTS(pna, pns)) {
-			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
-				dev->full_name);
-			break;
-		}
-
-		pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
-			pbus->name, pna, pns, parent->full_name);
-
-		/* Apply bus translation */
-		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna))
-			break;
-
-		/* Complete the move up one level */
-		na = pna;
-		ns = pns;
-		bus = pbus;
-
-		of_dump_addr("OF: one level translation:", addr, na);
-	}
- bail:
-	of_node_put(parent);
-	of_node_put(dev);
-
-	return result;
-}
-EXPORT_SYMBOL(of_translate_address);
-
-const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
-			unsigned int *flags)
-{
-	const u32 *prop;
-	unsigned int psize;
-	struct device_node *parent;
-	struct of_bus *bus;
-	int onesize, i, na, ns;
-
-	/* Get parent & match bus type */
-	parent = of_get_parent(dev);
-	if (parent == NULL)
-		return NULL;
-	bus = of_match_bus(parent);
-	bus->count_cells(dev, &na, &ns);
-	of_node_put(parent);
-	if (!OF_CHECK_COUNTS(na, ns))
-		return NULL;
-
-	/* Get "reg" or "assigned-addresses" property */
-	prop = of_get_property(dev, bus->addresses, (int *) &psize);
-	if (prop == NULL)
-		return NULL;
-	psize /= 4;
-
-	onesize = na + ns;
-	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
-		if (i == index) {
-			if (size)
-				*size = of_read_number(prop + na, ns);
-			if (flags)
-				*flags = bus->get_flags(prop);
-			return prop;
-		}
-	return NULL;
-}
-EXPORT_SYMBOL(of_get_address);
-
 void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
 		unsigned long *busno, unsigned long *phys, unsigned long *size)
 {
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index e1c1bdd..8e1d0fe 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -45,10 +45,6 @@ extern void pci_create_OF_bus_map(void);
  * OF address retreival & translation
  */
 
-/* Translate an OF address block into a CPU physical address
- */
-extern u64 of_translate_address(struct device_node *np, const u32 *addr);
-
 /* Translate a DMA address from device space to CPU space */
 extern u64 of_translate_dma_address(struct device_node *dev,
 				    const u32 *in_addr);
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index a2ef129..64f2606 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -10,225 +10,7 @@
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
 
-#ifdef DEBUG
-#define DBG(fmt...) do { printk(fmt); } while(0)
-#else
-#define DBG(fmt...) do { } while(0)
-#endif
-
-#ifdef CONFIG_PPC64
-#define PRu64	"%lx"
-#else
-#define PRu64	"%llx"
-#endif
-
-/* Max address size we deal with */
-#define OF_MAX_ADDR_CELLS	4
-#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
-			(ns) > 0)
-
-static struct of_bus *of_match_bus(struct device_node *np);
-
-/* Debug utility */
-#ifdef DEBUG
-static void of_dump_addr(const char *s, const u32 *addr, int na)
-{
-	printk("%s", s);
-	while(na--)
-		printk(" %08x", *(addr++));
-	printk("\n");
-}
-#else
-static void of_dump_addr(const char *s, const u32 *addr, int na) { }
-#endif
-
-
-/* Callbacks for bus specific translators */
-struct of_bus {
-	const char	*name;
-	const char	*addresses;
-	int		(*match)(struct device_node *parent);
-	void		(*count_cells)(struct device_node *child,
-				       int *addrc, int *sizec);
-	u64		(*map)(u32 *addr, const u32 *range,
-				int na, int ns, int pna);
-	int		(*translate)(u32 *addr, u64 offset, int na);
-	unsigned int	(*get_flags)(const u32 *addr);
-};
-
-
-/*
- * Default translator (generic bus)
- */
-
-static void of_bus_default_count_cells(struct device_node *dev,
-				       int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = of_n_addr_cells(dev);
-	if (sizec)
-		*sizec = of_n_size_cells(dev);
-}
-
-static u64 of_bus_default_map(u32 *addr, const u32 *range,
-		int na, int ns, int pna)
-{
-	u64 cp, s, da;
-
-	cp = of_read_number(range, na);
-	s  = of_read_number(range + na + pna, ns);
-	da = of_read_number(addr, na);
-
-	DBG("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
-	    cp, s, da);
-
-	if (da < cp || da >= (cp + s))
-		return OF_BAD_ADDR;
-	return da - cp;
-}
-
-static int of_bus_default_translate(u32 *addr, u64 offset, int na)
-{
-	u64 a = of_read_number(addr, na);
-	memset(addr, 0, na * 4);
-	a += offset;
-	if (na > 1)
-		addr[na - 2] = a >> 32;
-	addr[na - 1] = a & 0xffffffffu;
-
-	return 0;
-}
-
-static unsigned int of_bus_default_get_flags(const u32 *addr)
-{
-	return IORESOURCE_MEM;
-}
-
-
 #ifdef CONFIG_PCI
-/*
- * PCI bus specific translator
- */
-
-static int of_bus_pci_match(struct device_node *np)
-{
-	/* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
-	return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
-}
-
-static void of_bus_pci_count_cells(struct device_node *np,
-				   int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = 3;
-	if (sizec)
-		*sizec = 2;
-}
-
-static unsigned int of_bus_pci_get_flags(const u32 *addr)
-{
-	unsigned int flags = 0;
-	u32 w = addr[0];
-
-	switch((w >> 24) & 0x03) {
-	case 0x01:
-		flags |= IORESOURCE_IO;
-		break;
-	case 0x02: /* 32 bits */
-	case 0x03: /* 64 bits */
-		flags |= IORESOURCE_MEM;
-		break;
-	}
-	if (w & 0x40000000)
-		flags |= IORESOURCE_PREFETCH;
-	return flags;
-}
-
-static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
-{
-	u64 cp, s, da;
-	unsigned int af, rf;
-
-	af = of_bus_pci_get_flags(addr);
-	rf = of_bus_pci_get_flags(range);
-
-	/* Check address type match */
-	if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
-		return OF_BAD_ADDR;
-
-	/* Read address values, skipping high cell */
-	cp = of_read_number(range + 1, na - 1);
-	s  = of_read_number(range + na + pna, ns);
-	da = of_read_number(addr + 1, na - 1);
-
-	DBG("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
-
-	if (da < cp || da >= (cp + s))
-		return OF_BAD_ADDR;
-	return da - cp;
-}
-
-static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
-{
-	return of_bus_default_translate(addr + 1, offset, na - 1);
-}
-
-const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
-			unsigned int *flags)
-{
-	const u32 *prop;
-	unsigned int psize;
-	struct device_node *parent;
-	struct of_bus *bus;
-	int onesize, i, na, ns;
-
-	/* Get parent & match bus type */
-	parent = of_get_parent(dev);
-	if (parent == NULL)
-		return NULL;
-	bus = of_match_bus(parent);
-	if (strcmp(bus->name, "pci")) {
-		of_node_put(parent);
-		return NULL;
-	}
-	bus->count_cells(dev, &na, &ns);
-	of_node_put(parent);
-	if (!OF_CHECK_COUNTS(na, ns))
-		return NULL;
-
-	/* Get "reg" or "assigned-addresses" property */
-	prop = of_get_property(dev, bus->addresses, &psize);
-	if (prop == NULL)
-		return NULL;
-	psize /= 4;
-
-	onesize = na + ns;
-	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
-		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
-			if (size)
-				*size = of_read_number(prop + na, ns);
-			if (flags)
-				*flags = bus->get_flags(prop);
-			return prop;
-		}
-	return NULL;
-}
-EXPORT_SYMBOL(of_get_pci_address);
-
-int of_pci_address_to_resource(struct device_node *dev, int bar,
-			       struct resource *r)
-{
-	const u32	*addrp;
-	u64		size;
-	unsigned int	flags;
-
-	addrp = of_get_pci_address(dev, bar, &size, &flags);
-	if (addrp == NULL)
-		return -EINVAL;
-	return __of_address_to_resource(dev, addrp, size, flags, r);
-}
-EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
-
 int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
 {
 	struct device_node *dn, *ppnode;
@@ -310,303 +92,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
 EXPORT_SYMBOL_GPL(of_irq_map_pci);
 #endif /* CONFIG_PCI */
 
-/*
- * ISA bus specific translator
- */
-
-static int of_bus_isa_match(struct device_node *np)
-{
-	return !strcmp(np->name, "isa");
-}
-
-static void of_bus_isa_count_cells(struct device_node *child,
-				   int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = 2;
-	if (sizec)
-		*sizec = 1;
-}
-
-static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
-{
-	u64 cp, s, da;
-
-	/* Check address type match */
-	if ((addr[0] ^ range[0]) & 0x00000001)
-		return OF_BAD_ADDR;
-
-	/* Read address values, skipping high cell */
-	cp = of_read_number(range + 1, na - 1);
-	s  = of_read_number(range + na + pna, ns);
-	da = of_read_number(addr + 1, na - 1);
-
-	DBG("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
-
-	if (da < cp || da >= (cp + s))
-		return OF_BAD_ADDR;
-	return da - cp;
-}
-
-static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
-{
-	return of_bus_default_translate(addr + 1, offset, na - 1);
-}
-
-static unsigned int of_bus_isa_get_flags(const u32 *addr)
-{
-	unsigned int flags = 0;
-	u32 w = addr[0];
-
-	if (w & 1)
-		flags |= IORESOURCE_IO;
-	else
-		flags |= IORESOURCE_MEM;
-	return flags;
-}
-
-
-/*
- * Array of bus specific translators
- */
-
-static struct of_bus of_busses[] = {
-#ifdef CONFIG_PCI
-	/* PCI */
-	{
-		.name = "pci",
-		.addresses = "assigned-addresses",
-		.match = of_bus_pci_match,
-		.count_cells = of_bus_pci_count_cells,
-		.map = of_bus_pci_map,
-		.translate = of_bus_pci_translate,
-		.get_flags = of_bus_pci_get_flags,
-	},
-#endif /* CONFIG_PCI */
-	/* ISA */
-	{
-		.name = "isa",
-		.addresses = "reg",
-		.match = of_bus_isa_match,
-		.count_cells = of_bus_isa_count_cells,
-		.map = of_bus_isa_map,
-		.translate = of_bus_isa_translate,
-		.get_flags = of_bus_isa_get_flags,
-	},
-	/* Default */
-	{
-		.name = "default",
-		.addresses = "reg",
-		.match = NULL,
-		.count_cells = of_bus_default_count_cells,
-		.map = of_bus_default_map,
-		.translate = of_bus_default_translate,
-		.get_flags = of_bus_default_get_flags,
-	},
-};
-
-static struct of_bus *of_match_bus(struct device_node *np)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(of_busses); i ++)
-		if (!of_busses[i].match || of_busses[i].match(np))
-			return &of_busses[i];
-	BUG();
-	return NULL;
-}
-
-static int of_translate_one(struct device_node *parent, struct of_bus *bus,
-			    struct of_bus *pbus, u32 *addr,
-			    int na, int ns, int pna, const char *rprop)
-{
-	const u32 *ranges;
-	unsigned int rlen;
-	int rone;
-	u64 offset = OF_BAD_ADDR;
-
-	/* Normally, an absence of a "ranges" property means we are
-	 * crossing a non-translatable boundary, and thus the addresses
-	 * below the current not cannot be converted to CPU physical ones.
-	 * Unfortunately, while this is very clear in the spec, it's not
-	 * what Apple understood, and they do have things like /uni-n or
-	 * /ht nodes with no "ranges" property and a lot of perfectly
-	 * useable mapped devices below them. Thus we treat the absence of
-	 * "ranges" as equivalent to an empty "ranges" property which means
-	 * a 1:1 translation at that level. It's up to the caller not to try
-	 * to translate addresses that aren't supposed to be translated in
-	 * the first place. --BenH.
-	 */
-	ranges = of_get_property(parent, rprop, &rlen);
-	if (ranges == NULL || rlen == 0) {
-		offset = of_read_number(addr, na);
-		memset(addr, 0, pna * 4);
-		DBG("OF: no ranges, 1:1 translation\n");
-		goto finish;
-	}
-
-	DBG("OF: walking ranges...\n");
-
-	/* Now walk through the ranges */
-	rlen /= 4;
-	rone = na + pna + ns;
-	for (; rlen >= rone; rlen -= rone, ranges += rone) {
-		offset = bus->map(addr, ranges, na, ns, pna);
-		if (offset != OF_BAD_ADDR)
-			break;
-	}
-	if (offset == OF_BAD_ADDR) {
-		DBG("OF: not found !\n");
-		return 1;
-	}
-	memcpy(addr, ranges + na, 4 * pna);
-
- finish:
-	of_dump_addr("OF: parent translation for:", addr, pna);
-	DBG("OF: with offset: "PRu64"\n", offset);
-
-	/* Translate it into parent bus space */
-	return pbus->translate(addr, offset, pna);
-}
-
-
-/*
- * Translate an address from the device-tree into a CPU physical address,
- * this walks up the tree and applies the various bus mappings on the
- * way.
- *
- * Note: We consider that crossing any level with #size-cells == 0 to mean
- * that translation is impossible (that is we are not dealing with a value
- * that can be mapped to a cpu physical address). This is not really specified
- * that way, but this is traditionally the way IBM at least do things
- */
-u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
-			   const char *rprop)
-{
-	struct device_node *parent = NULL;
-	struct of_bus *bus, *pbus;
-	u32 addr[OF_MAX_ADDR_CELLS];
-	int na, ns, pna, pns;
-	u64 result = OF_BAD_ADDR;
-
-	DBG("OF: ** translation for device %s **\n", dev->full_name);
-
-	/* Increase refcount at current level */
-	of_node_get(dev);
-
-	/* Get parent & match bus type */
-	parent = of_get_parent(dev);
-	if (parent == NULL)
-		goto bail;
-	bus = of_match_bus(parent);
-
-	/* Cound address cells & copy address locally */
-	bus->count_cells(dev, &na, &ns);
-	if (!OF_CHECK_COUNTS(na, ns)) {
-		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
-		       dev->full_name);
-		goto bail;
-	}
-	memcpy(addr, in_addr, na * 4);
-
-	DBG("OF: bus is %s (na=%d, ns=%d) on %s\n",
-	    bus->name, na, ns, parent->full_name);
-	of_dump_addr("OF: translating address:", addr, na);
-
-	/* Translate */
-	for (;;) {
-		/* Switch to parent bus */
-		of_node_put(dev);
-		dev = parent;
-		parent = of_get_parent(dev);
-
-		/* If root, we have finished */
-		if (parent == NULL) {
-			DBG("OF: reached root node\n");
-			result = of_read_number(addr, na);
-			break;
-		}
-
-		/* Get new parent bus and counts */
-		pbus = of_match_bus(parent);
-		pbus->count_cells(dev, &pna, &pns);
-		if (!OF_CHECK_COUNTS(pna, pns)) {
-			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
-			       dev->full_name);
-			break;
-		}
-
-		DBG("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
-		    pbus->name, pna, pns, parent->full_name);
-
-		/* Apply bus translation */
-		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
-			break;
-
-		/* Complete the move up one level */
-		na = pna;
-		ns = pns;
-		bus = pbus;
-
-		of_dump_addr("OF: one level translation:", addr, na);
-	}
- bail:
-	of_node_put(parent);
-	of_node_put(dev);
-
-	return result;
-}
-
-u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
-{
-	return __of_translate_address(dev, in_addr, "ranges");
-}
-EXPORT_SYMBOL(of_translate_address);
-
-u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr)
-{
-	return __of_translate_address(dev, in_addr, "dma-ranges");
-}
-EXPORT_SYMBOL(of_translate_dma_address);
-
-const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
-		    unsigned int *flags)
-{
-	const u32 *prop;
-	unsigned int psize;
-	struct device_node *parent;
-	struct of_bus *bus;
-	int onesize, i, na, ns;
-
-	/* Get parent & match bus type */
-	parent = of_get_parent(dev);
-	if (parent == NULL)
-		return NULL;
-	bus = of_match_bus(parent);
-	bus->count_cells(dev, &na, &ns);
-	of_node_put(parent);
-	if (!OF_CHECK_COUNTS(na, ns))
-		return NULL;
-
-	/* Get "reg" or "assigned-addresses" property */
-	prop = of_get_property(dev, bus->addresses, &psize);
-	if (prop == NULL)
-		return NULL;
-	psize /= 4;
-
-	onesize = na + ns;
-	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
-		if (i == index) {
-			if (size)
-				*size = of_read_number(prop + na, ns);
-			if (flags)
-				*flags = bus->get_flags(prop);
-			return prop;
-		}
-	return NULL;
-}
-EXPORT_SYMBOL(of_get_address);
-
 void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
 		unsigned long *busno, unsigned long *phys, unsigned long *size)
 {
diff --git a/drivers/of/address.c b/drivers/of/address.c
index c381955..2a905d5 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -1,11 +1,522 @@
 
 #include <linux/io.h>
 #include <linux/ioport.h>
+#include <linux/module.h>
 #include <linux/of_address.h>
+#include <linux/pci_regs.h>
+#include <linux/string.h>
 
-int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
-			     u64 size, unsigned int flags,
-			     struct resource *r)
+/* Max address size we deal with */
+#define OF_MAX_ADDR_CELLS	4
+#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
+			(ns) > 0)
+
+static struct of_bus *of_match_bus(struct device_node *np);
+static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
+				    u64 size, unsigned int flags,
+				    struct resource *r);
+
+/* Debug utility */
+#ifdef DEBUG
+static void of_dump_addr(const char *s, const u32 *addr, int na)
+{
+	printk(KERN_DEBUG "%s", s);
+	while (na--)
+		printk(" %08x", *(addr++));
+	printk("\n");
+}
+#else
+static void of_dump_addr(const char *s, const u32 *addr, int na) { }
+#endif
+
+/* Callbacks for bus specific translators */
+struct of_bus {
+	const char	*name;
+	const char	*addresses;
+	int		(*match)(struct device_node *parent);
+	void		(*count_cells)(struct device_node *child,
+				       int *addrc, int *sizec);
+	u64		(*map)(u32 *addr, const u32 *range,
+				int na, int ns, int pna);
+	int		(*translate)(u32 *addr, u64 offset, int na);
+	unsigned int	(*get_flags)(const u32 *addr);
+};
+
+/*
+ * Default translator (generic bus)
+ */
+
+static void of_bus_default_count_cells(struct device_node *dev,
+				       int *addrc, int *sizec)
+{
+	if (addrc)
+		*addrc = of_n_addr_cells(dev);
+	if (sizec)
+		*sizec = of_n_size_cells(dev);
+}
+
+static u64 of_bus_default_map(u32 *addr, const u32 *range,
+		int na, int ns, int pna)
+{
+	u64 cp, s, da;
+
+	cp = of_read_number(range, na);
+	s  = of_read_number(range + na + pna, ns);
+	da = of_read_number(addr, na);
+
+	pr_debug("OF: default map, cp=%llx, s=%llx, da=%llx\n",
+		 (unsigned long long)cp, (unsigned long long)s,
+		 (unsigned long long)da);
+
+	if (da < cp || da >= (cp + s))
+		return OF_BAD_ADDR;
+	return da - cp;
+}
+
+static int of_bus_default_translate(u32 *addr, u64 offset, int na)
+{
+	u64 a = of_read_number(addr, na);
+	memset(addr, 0, na * 4);
+	a += offset;
+	if (na > 1)
+		addr[na - 2] = a >> 32;
+	addr[na - 1] = a & 0xffffffffu;
+
+	return 0;
+}
+
+static unsigned int of_bus_default_get_flags(const u32 *addr)
+{
+	return IORESOURCE_MEM;
+}
+
+#ifdef CONFIG_PCI
+/*
+ * PCI bus specific translator
+ */
+
+static int of_bus_pci_match(struct device_node *np)
+{
+	/* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
+	return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
+}
+
+static void of_bus_pci_count_cells(struct device_node *np,
+				   int *addrc, int *sizec)
+{
+	if (addrc)
+		*addrc = 3;
+	if (sizec)
+		*sizec = 2;
+}
+
+static unsigned int of_bus_pci_get_flags(const u32 *addr)
+{
+	unsigned int flags = 0;
+	u32 w = addr[0];
+
+	switch((w >> 24) & 0x03) {
+	case 0x01:
+		flags |= IORESOURCE_IO;
+		break;
+	case 0x02: /* 32 bits */
+	case 0x03: /* 64 bits */
+		flags |= IORESOURCE_MEM;
+		break;
+	}
+	if (w & 0x40000000)
+		flags |= IORESOURCE_PREFETCH;
+	return flags;
+}
+
+static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
+{
+	u64 cp, s, da;
+	unsigned int af, rf;
+
+	af = of_bus_pci_get_flags(addr);
+	rf = of_bus_pci_get_flags(range);
+
+	/* Check address type match */
+	if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
+		return OF_BAD_ADDR;
+
+	/* Read address values, skipping high cell */
+	cp = of_read_number(range + 1, na - 1);
+	s  = of_read_number(range + na + pna, ns);
+	da = of_read_number(addr + 1, na - 1);
+
+	pr_debug("OF: PCI map, cp=%llx, s=%llx, da=%llx\n",
+		 (unsigned long long)cp, (unsigned long long)s,
+		 (unsigned long long)da);
+
+	if (da < cp || da >= (cp + s))
+		return OF_BAD_ADDR;
+	return da - cp;
+}
+
+static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
+{
+	return of_bus_default_translate(addr + 1, offset, na - 1);
+}
+
+const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
+			unsigned int *flags)
+{
+	const u32 *prop;
+	unsigned int psize;
+	struct device_node *parent;
+	struct of_bus *bus;
+	int onesize, i, na, ns;
+
+	/* Get parent & match bus type */
+	parent = of_get_parent(dev);
+	if (parent == NULL)
+		return NULL;
+	bus = of_match_bus(parent);
+	if (strcmp(bus->name, "pci")) {
+		of_node_put(parent);
+		return NULL;
+	}
+	bus->count_cells(dev, &na, &ns);
+	of_node_put(parent);
+	if (!OF_CHECK_COUNTS(na, ns))
+		return NULL;
+
+	/* Get "reg" or "assigned-addresses" property */
+	prop = of_get_property(dev, bus->addresses, &psize);
+	if (prop == NULL)
+		return NULL;
+	psize /= 4;
+
+	onesize = na + ns;
+	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
+		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
+			if (size)
+				*size = of_read_number(prop + na, ns);
+			if (flags)
+				*flags = bus->get_flags(prop);
+			return prop;
+		}
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_pci_address);
+
+int of_pci_address_to_resource(struct device_node *dev, int bar,
+			       struct resource *r)
+{
+	const u32	*addrp;
+	u64		size;
+	unsigned int	flags;
+
+	addrp = of_get_pci_address(dev, bar, &size, &flags);
+	if (addrp == NULL)
+		return -EINVAL;
+	return __of_address_to_resource(dev, addrp, size, flags, r);
+}
+EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
+#endif /* CONFIG_PCI */
+
+/*
+ * ISA bus specific translator
+ */
+
+static int of_bus_isa_match(struct device_node *np)
+{
+	return !strcmp(np->name, "isa");
+}
+
+static void of_bus_isa_count_cells(struct device_node *child,
+				   int *addrc, int *sizec)
+{
+	if (addrc)
+		*addrc = 2;
+	if (sizec)
+		*sizec = 1;
+}
+
+static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
+{
+	u64 cp, s, da;
+
+	/* Check address type match */
+	if ((addr[0] ^ range[0]) & 0x00000001)
+		return OF_BAD_ADDR;
+
+	/* Read address values, skipping high cell */
+	cp = of_read_number(range + 1, na - 1);
+	s  = of_read_number(range + na + pna, ns);
+	da = of_read_number(addr + 1, na - 1);
+
+	pr_debug("OF: ISA map, cp=%llx, s=%llx, da=%llx\n",
+		 (unsigned long long)cp, (unsigned long long)s,
+		 (unsigned long long)da);
+
+	if (da < cp || da >= (cp + s))
+		return OF_BAD_ADDR;
+	return da - cp;
+}
+
+static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
+{
+	return of_bus_default_translate(addr + 1, offset, na - 1);
+}
+
+static unsigned int of_bus_isa_get_flags(const u32 *addr)
+{
+	unsigned int flags = 0;
+	u32 w = addr[0];
+
+	if (w & 1)
+		flags |= IORESOURCE_IO;
+	else
+		flags |= IORESOURCE_MEM;
+	return flags;
+}
+
+/*
+ * Array of bus specific translators
+ */
+
+static struct of_bus of_busses[] = {
+#ifdef CONFIG_PCI
+	/* PCI */
+	{
+		.name = "pci",
+		.addresses = "assigned-addresses",
+		.match = of_bus_pci_match,
+		.count_cells = of_bus_pci_count_cells,
+		.map = of_bus_pci_map,
+		.translate = of_bus_pci_translate,
+		.get_flags = of_bus_pci_get_flags,
+	},
+#endif /* CONFIG_PCI */
+	/* ISA */
+	{
+		.name = "isa",
+		.addresses = "reg",
+		.match = of_bus_isa_match,
+		.count_cells = of_bus_isa_count_cells,
+		.map = of_bus_isa_map,
+		.translate = of_bus_isa_translate,
+		.get_flags = of_bus_isa_get_flags,
+	},
+	/* Default */
+	{
+		.name = "default",
+		.addresses = "reg",
+		.match = NULL,
+		.count_cells = of_bus_default_count_cells,
+		.map = of_bus_default_map,
+		.translate = of_bus_default_translate,
+		.get_flags = of_bus_default_get_flags,
+	},
+};
+
+static struct of_bus *of_match_bus(struct device_node *np)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(of_busses); i++)
+		if (!of_busses[i].match || of_busses[i].match(np))
+			return &of_busses[i];
+	BUG();
+	return NULL;
+}
+
+static int of_translate_one(struct device_node *parent, struct of_bus *bus,
+			    struct of_bus *pbus, u32 *addr,
+			    int na, int ns, int pna, const char *rprop)
+{
+	const u32 *ranges;
+	unsigned int rlen;
+	int rone;
+	u64 offset = OF_BAD_ADDR;
+
+	/* Normally, an absence of a "ranges" property means we are
+	 * crossing a non-translatable boundary, and thus the addresses
+	 * below the current not cannot be converted to CPU physical ones.
+	 * Unfortunately, while this is very clear in the spec, it's not
+	 * what Apple understood, and they do have things like /uni-n or
+	 * /ht nodes with no "ranges" property and a lot of perfectly
+	 * useable mapped devices below them. Thus we treat the absence of
+	 * "ranges" as equivalent to an empty "ranges" property which means
+	 * a 1:1 translation at that level. It's up to the caller not to try
+	 * to translate addresses that aren't supposed to be translated in
+	 * the first place. --BenH.
+	 */
+	ranges = of_get_property(parent, rprop, &rlen);
+	if (ranges == NULL || rlen == 0) {
+		offset = of_read_number(addr, na);
+		memset(addr, 0, pna * 4);
+		pr_debug("OF: no ranges, 1:1 translation\n");
+		goto finish;
+	}
+
+	pr_debug("OF: walking ranges...\n");
+
+	/* Now walk through the ranges */
+	rlen /= 4;
+	rone = na + pna + ns;
+	for (; rlen >= rone; rlen -= rone, ranges += rone) {
+		offset = bus->map(addr, ranges, na, ns, pna);
+		if (offset != OF_BAD_ADDR)
+			break;
+	}
+	if (offset == OF_BAD_ADDR) {
+		pr_debug("OF: not found !\n");
+		return 1;
+	}
+	memcpy(addr, ranges + na, 4 * pna);
+
+ finish:
+	of_dump_addr("OF: parent translation for:", addr, pna);
+	pr_debug("OF: with offset: %llx\n", (unsigned long long)offset);
+
+	/* Translate it into parent bus space */
+	return pbus->translate(addr, offset, pna);
+}
+
+/*
+ * Translate an address from the device-tree into a CPU physical address,
+ * this walks up the tree and applies the various bus mappings on the
+ * way.
+ *
+ * Note: We consider that crossing any level with #size-cells == 0 to mean
+ * that translation is impossible (that is we are not dealing with a value
+ * that can be mapped to a cpu physical address). This is not really specified
+ * that way, but this is traditionally the way IBM at least do things
+ */
+u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
+			   const char *rprop)
+{
+	struct device_node *parent = NULL;
+	struct of_bus *bus, *pbus;
+	u32 addr[OF_MAX_ADDR_CELLS];
+	int na, ns, pna, pns;
+	u64 result = OF_BAD_ADDR;
+
+	pr_debug("OF: ** translation for device %s **\n", dev->full_name);
+
+	/* Increase refcount at current level */
+	of_node_get(dev);
+
+	/* Get parent & match bus type */
+	parent = of_get_parent(dev);
+	if (parent == NULL)
+		goto bail;
+	bus = of_match_bus(parent);
+
+	/* Cound address cells & copy address locally */
+	bus->count_cells(dev, &na, &ns);
+	if (!OF_CHECK_COUNTS(na, ns)) {
+		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
+		       dev->full_name);
+		goto bail;
+	}
+	memcpy(addr, in_addr, na * 4);
+
+	pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
+	    bus->name, na, ns, parent->full_name);
+	of_dump_addr("OF: translating address:", addr, na);
+
+	/* Translate */
+	for (;;) {
+		/* Switch to parent bus */
+		of_node_put(dev);
+		dev = parent;
+		parent = of_get_parent(dev);
+
+		/* If root, we have finished */
+		if (parent == NULL) {
+			pr_debug("OF: reached root node\n");
+			result = of_read_number(addr, na);
+			break;
+		}
+
+		/* Get new parent bus and counts */
+		pbus = of_match_bus(parent);
+		pbus->count_cells(dev, &pna, &pns);
+		if (!OF_CHECK_COUNTS(pna, pns)) {
+			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
+			       dev->full_name);
+			break;
+		}
+
+		pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
+		    pbus->name, pna, pns, parent->full_name);
+
+		/* Apply bus translation */
+		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
+			break;
+
+		/* Complete the move up one level */
+		na = pna;
+		ns = pns;
+		bus = pbus;
+
+		of_dump_addr("OF: one level translation:", addr, na);
+	}
+ bail:
+	of_node_put(parent);
+	of_node_put(dev);
+
+	return result;
+}
+
+u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
+{
+	return __of_translate_address(dev, in_addr, "ranges");
+}
+EXPORT_SYMBOL(of_translate_address);
+
+u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr)
+{
+	return __of_translate_address(dev, in_addr, "dma-ranges");
+}
+EXPORT_SYMBOL(of_translate_dma_address);
+
+const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
+		    unsigned int *flags)
+{
+	const u32 *prop;
+	unsigned int psize;
+	struct device_node *parent;
+	struct of_bus *bus;
+	int onesize, i, na, ns;
+
+	/* Get parent & match bus type */
+	parent = of_get_parent(dev);
+	if (parent == NULL)
+		return NULL;
+	bus = of_match_bus(parent);
+	bus->count_cells(dev, &na, &ns);
+	of_node_put(parent);
+	if (!OF_CHECK_COUNTS(na, ns))
+		return NULL;
+
+	/* Get "reg" or "assigned-addresses" property */
+	prop = of_get_property(dev, bus->addresses, &psize);
+	if (prop == NULL)
+		return NULL;
+	psize /= 4;
+
+	onesize = na + ns;
+	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
+		if (i == index) {
+			if (size)
+				*size = of_read_number(prop + na, ns);
+			if (flags)
+				*flags = bus->get_flags(prop);
+			return prop;
+		}
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_address);
+
+static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
+				    u64 size, unsigned int flags,
+				    struct resource *r)
 {
 	u64 taddr;
 
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 474b794..cc567df 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -3,9 +3,7 @@
 #include <linux/ioport.h>
 #include <linux/of.h>
 
-extern int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
-				    u64 size, unsigned int flags,
-				    struct resource *r);
+extern u64 of_translate_address(struct device_node *np, const u32 *addr);
 extern int of_address_to_resource(struct device_node *dev, int index,
 				  struct resource *r);
 extern void __iomem *of_iomap(struct device_node *device, int index);

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

* [PATCH 4/5] of/address: little-endian fixes
       [not found] <20100608140917.25879.67745.stgit@angua>
                   ` (2 preceding siblings ...)
  2010-06-08 14:10 ` [PATCH 3/5] of/address: Merge all of the bus translation code Grant Likely
@ 2010-06-08 14:10 ` Grant Likely
  2010-06-10  6:43   ` Benjamin Herrenschmidt
  2010-06-08 14:10   ` Grant Likely
  2010-06-08 14:12 ` [PATCH 0/5] Merge common address translation code (ppc & mb) Grant Likely
  5 siblings, 1 reply; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:10 UTC (permalink / raw)
  Cc: Stephen Rothwell, Michal Simek, linuxppc-dev, microblaze-uclinux

Fix some endian issues in the OF address translation code.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
CC: Michal Simek <monstr@monstr.eu>
CC: Wolfram Sang <w.sang@pengutronix.de>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: microblaze-uclinux@itee.uq.edu.au
CC: linuxppc-dev@ozlabs.org
---
 drivers/of/address.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 2a905d5..0b04137 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -22,7 +22,7 @@ static void of_dump_addr(const char *s, const u32 *addr, int na)
 {
 	printk(KERN_DEBUG "%s", s);
 	while (na--)
-		printk(" %08x", *(addr++));
+		printk(" %08x", be32_to_cpu(*(addr++)));
 	printk("\n");
 }
 #else
@@ -79,8 +79,8 @@ static int of_bus_default_translate(u32 *addr, u64 offset, int na)
 	memset(addr, 0, na * 4);
 	a += offset;
 	if (na > 1)
-		addr[na - 2] = a >> 32;
-	addr[na - 1] = a & 0xffffffffu;
+		addr[na - 2] = cpu_to_be32(a >> 32);
+	addr[na - 1] = cpu_to_be32(a & 0xffffffffu);
 
 	return 0;
 }
@@ -190,14 +190,16 @@ const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
 	psize /= 4;
 
 	onesize = na + ns;
-	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
-		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
+	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {
+		u32 val = be32_to_cpu(prop[0]);
+		if ((val & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
 			if (size)
 				*size = of_read_number(prop + na, ns);
 			if (flags)
 				*flags = bus->get_flags(prop);
 			return prop;
 		}
+	}
 	return NULL;
 }
 EXPORT_SYMBOL(of_get_pci_address);

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

* [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
       [not found] <20100608140917.25879.67745.stgit@angua>
@ 2010-06-08 14:10   ` Grant Likely
  2010-06-08 14:10 ` [PATCH 2/5] of/address: merge of_address_to_resource() Grant Likely
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:10 UTC (permalink / raw)
  Cc: Stephen Rothwell, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

Certain Apple machines don't use the ranges property correctly, but the
workaround should not be applied on other architectures.  This patch
disables the workaround for non-powerpc architectures.

Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
CC: Stephen Rothwell <sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>
CC: Benjamin Herrenschmidt <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
CC: linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
CC: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
---
 drivers/of/address.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 0b04137..5c220c3 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
 	 * a 1:1 translation at that level. It's up to the caller not to try
 	 * to translate addresses that aren't supposed to be translated in
 	 * the first place. --BenH.
+	 *
+	 * As far as we know, this damage only exists on Apple machines, so
+	 * This code is only enabled on powerpc. --gcl
 	 */
 	ranges = of_get_property(parent, rprop, &rlen);
+#if !defined(CONFIG_PPC)
+	if (ranges == NULL) {
+		pr_err("OF: no ranges; cannot translate\n");
+		return 1;
+	}
+#endif /* !defined(CONFIG_PPC) */
 	if (ranges == NULL || rlen == 0) {
 		offset = of_read_number(addr, na);
 		memset(addr, 0, pna * 4);
-		pr_debug("OF: no ranges, 1:1 translation\n");
+		pr_debug("OF: empty ranges; 1:1 translation\n");
 		goto finish;
 	}

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

* [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
@ 2010-06-08 14:10   ` Grant Likely
  0 siblings, 0 replies; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:10 UTC (permalink / raw)
  Cc: Stephen Rothwell, devicetree-discuss, linuxppc-dev

Certain Apple machines don't use the ranges property correctly, but the
workaround should not be applied on other architectures.  This patch
disables the workaround for non-powerpc architectures.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: linuxppc-dev@lists.ozlabs.org
CC: devicetree-discuss@lists.ozlabs.org
---
 drivers/of/address.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 0b04137..5c220c3 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
 	 * a 1:1 translation at that level. It's up to the caller not to try
 	 * to translate addresses that aren't supposed to be translated in
 	 * the first place. --BenH.
+	 *
+	 * As far as we know, this damage only exists on Apple machines, so
+	 * This code is only enabled on powerpc. --gcl
 	 */
 	ranges = of_get_property(parent, rprop, &rlen);
+#if !defined(CONFIG_PPC)
+	if (ranges == NULL) {
+		pr_err("OF: no ranges; cannot translate\n");
+		return 1;
+	}
+#endif /* !defined(CONFIG_PPC) */
 	if (ranges == NULL || rlen == 0) {
 		offset = of_read_number(addr, na);
 		memset(addr, 0, pna * 4);
-		pr_debug("OF: no ranges, 1:1 translation\n");
+		pr_debug("OF: empty ranges; 1:1 translation\n");
 		goto finish;
 	}
 

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

* [PATCH 0/5] Merge common address translation code (ppc & mb)
       [not found] <20100608140917.25879.67745.stgit@angua>
                   ` (4 preceding siblings ...)
  2010-06-08 14:10   ` Grant Likely
@ 2010-06-08 14:12 ` Grant Likely
  5 siblings, 0 replies; 24+ messages in thread
From: Grant Likely @ 2010-06-08 14:12 UTC (permalink / raw)
  To: Stephen Rothwell, Michal Simek, microblaze-uclinux, Wolfram Sang,
	linuxppc-dev, Benjamin Herrenschmidt

These five patches merge common code for decoding address ranges from
the device tree. =A0Simple mechanical change. =A0There should be no functio=
nal
difference except for the last patch which restricts the no-ranges code
to be powerpc-only.

These patches are based on top of the IRQ merge which I posted earlier.
If you want to test them, I've pushed the commits out to the here:

git://git.secretlab.ca/git/linux-2.6 devicetree-test

Cheers,
g.

---

Grant Likely (5):
=A0 =A0 =A0of/address: merge of_iomap()
=A0 =A0 =A0of/address: merge of_address_to_resource()
=A0 =A0 =A0of/address: Merge all of the bus translation code
=A0 =A0 =A0of/address: little-endian fixes
=A0 =A0 =A0of/address: restrict 'no-ranges' kludge to powerpc


=A0arch/microblaze/include/asm/pci-bridge.h | =A0 =A05
=A0arch/microblaze/include/asm/prom.h =A0 =A0 =A0 | =A0 31 +-
=A0arch/microblaze/kernel/prom_parse.c =A0 =A0 =A0| =A0546 ----------------=
------------
=A0arch/powerpc/include/asm/pci-bridge.h =A0 =A0| =A0 =A05
=A0arch/powerpc/include/asm/prom.h =A0 =A0 =A0 =A0 =A0| =A0 31 +-
=A0arch/powerpc/kernel/prom_parse.c =A0 =A0 =A0 =A0 | =A0573 --------------=
---------------
=A0drivers/of/Kconfig =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A0=
4
=A0drivers/of/Makefile =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A0=
1
=A0drivers/of/address.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0595 ++=
++++++++++++++++++++++++++++
=A0include/linux/of_address.h =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 12 +
=A010 files changed, 634 insertions(+), 1169 deletions(-)
=A0create mode 100644 drivers/of/address.c
=A0create mode 100644 include/linux/of_address.h



--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: [PATCH 1/5] of/address: merge of_iomap()
  2010-06-08 14:09 ` [PATCH 1/5] of/address: merge of_iomap() Grant Likely
@ 2010-06-10  6:40   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-10  6:40 UTC (permalink / raw)
  To: Grant Likely
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Tue, 2010-06-08 at 08:09 -0600, Grant Likely wrote:
> Merge common code between Microblaze and PowerPC.  This patch creates
> new of_address.h and address.c files to containing address translation
> and mapping routines.  First routine to be moved it of_iomap()
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> CC: Michal Simek <monstr@monstr.eu>
> CC: Wolfram Sang <w.sang@pengutronix.de>
> CC: Stephen Rothwell <sfr@canb.auug.org.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> CC: microblaze-uclinux@itee.uq.edu.au
> CC: linuxppc-dev@ozlabs.org
> ---
>  arch/microblaze/include/asm/prom.h  |   10 +---------
>  arch/microblaze/kernel/prom_parse.c |   11 -----------
>  arch/powerpc/include/asm/prom.h     |   10 +---------
>  arch/powerpc/kernel/prom_parse.c    |   11 -----------
>  drivers/of/Kconfig                  |    4 ++++
>  drivers/of/Makefile                 |    1 +
>  drivers/of/address.c                |   22 ++++++++++++++++++++++
>  include/linux/of_address.h          |    9 +++++++++
>  8 files changed, 38 insertions(+), 40 deletions(-)
>  create mode 100644 drivers/of/address.c
>  create mode 100644 include/linux/of_address.h
> 
> diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
> index 3659930..b6698ef 100644
> --- a/arch/microblaze/include/asm/prom.h
> +++ b/arch/microblaze/include/asm/prom.h
> @@ -20,6 +20,7 @@
>  #ifndef __ASSEMBLY__
>  
>  #include <linux/types.h>
> +#include <linux/of_address.h>
>  #include <linux/of_irq.h>
>  #include <linux/of_fdt.h>
>  #include <linux/proc_fs.h>
> @@ -107,15 +108,6 @@ extern const void *of_get_mac_address(struct device_node *np);
>  struct pci_dev;
>  extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
>  
> -/**
> - * of_iomap - Maps the memory mapped IO for a given device_node
> - * @device:	the device whose io range will be mapped
> - * @index:	index of the io range
> - *
> - * Returns a pointer to the mapped memory
> - */
> -extern void __iomem *of_iomap(struct device_node *device, int index);
> -
>  #endif /* __ASSEMBLY__ */
>  #endif /* __KERNEL__ */
>  #endif /* _ASM_MICROBLAZE_PROM_H */
> diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
> index 70c0471..5003ee8 100644
> --- a/arch/microblaze/kernel/prom_parse.c
> +++ b/arch/microblaze/kernel/prom_parse.c
> @@ -697,14 +697,3 @@ const void *of_get_mac_address(struct device_node *np)
>  	return NULL;
>  }
>  EXPORT_SYMBOL(of_get_mac_address);
> -
> -void __iomem *of_iomap(struct device_node *np, int index)
> -{
> -	struct resource res;
> -
> -	if (of_address_to_resource(np, index, &res))
> -		return NULL;
> -
> -	return ioremap(res.start, 1 + res.end - res.start);
> -}
> -EXPORT_SYMBOL(of_iomap);
> diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
> index 2440984..e0bdbc6 100644
> --- a/arch/powerpc/include/asm/prom.h
> +++ b/arch/powerpc/include/asm/prom.h
> @@ -18,6 +18,7 @@
>   */
>  #include <linux/types.h>
>  #include <linux/of_fdt.h>
> +#include <linux/of_address.h>
>  #include <linux/of_irq.h>
>  #include <linux/proc_fs.h>
>  #include <linux/platform_device.h>
> @@ -136,14 +137,5 @@ extern void of_irq_map_init(unsigned int flags);
>  struct pci_dev;
>  extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
>  
> -/**
> - * of_iomap - Maps the memory mapped IO for a given device_node
> - * @device:	the device whose io range will be mapped
> - * @index:	index of the io range
> - *
> - * Returns a pointer to the mapped memory
> - */
> -extern void __iomem *of_iomap(struct device_node *device, int index);
> -
>  #endif /* __KERNEL__ */
>  #endif /* _POWERPC_PROM_H */
> diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
> index ef518e3..dfb73c4 100644
> --- a/arch/powerpc/kernel/prom_parse.c
> +++ b/arch/powerpc/kernel/prom_parse.c
> @@ -822,14 +822,3 @@ const void *of_get_mac_address(struct device_node *np)
>  	return NULL;
>  }
>  EXPORT_SYMBOL(of_get_mac_address);
> -
> -void __iomem *of_iomap(struct device_node *np, int index)
> -{
> -	struct resource res;
> -
> -	if (of_address_to_resource(np, index, &res))
> -		return NULL;
> -
> -	return ioremap(res.start, 1 + res.end - res.start);
> -}
> -EXPORT_SYMBOL(of_iomap);
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index b87495e..097f42a 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -6,6 +6,10 @@ config OF_DYNAMIC
>  	def_bool y
>  	depends on OF && PPC_OF
>  
> +config OF_ADDRESS
> +	def_bool y
> +	depends on OF && !SPARC
> +
>  config OF_IRQ
>  	def_bool y
>  	depends on OF && !SPARC
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index 3631a5e..0052c40 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -1,5 +1,6 @@
>  obj-y = base.o
>  obj-$(CONFIG_OF_FLATTREE) += fdt.o
> +obj-$(CONFIG_OF_ADDRESS)  += address.o
>  obj-$(CONFIG_OF_IRQ)    += irq.o
>  obj-$(CONFIG_OF_DEVICE) += device.o platform.o
>  obj-$(CONFIG_OF_GPIO)   += gpio.o
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> new file mode 100644
> index 0000000..258528d
> --- /dev/null
> +++ b/drivers/of/address.c
> @@ -0,0 +1,22 @@
> +
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/of_address.h>
> +
> +/**
> + * of_iomap - Maps the memory mapped IO for a given device_node
> + * @device:	the device whose io range will be mapped
> + * @index:	index of the io range
> + *
> + * Returns a pointer to the mapped memory
> + */
> +void __iomem *of_iomap(struct device_node *np, int index)
> +{
> +	struct resource res;
> +
> +	if (of_address_to_resource(np, index, &res))
> +		return NULL;
> +
> +	return ioremap(res.start, 1 + res.end - res.start);
> +}
> +EXPORT_SYMBOL(of_iomap);
> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
> new file mode 100644
> index 0000000..570831d
> --- /dev/null
> +++ b/include/linux/of_address.h
> @@ -0,0 +1,9 @@
> +#ifndef __OF_ADDRESS_H
> +#define __OF_ADDRESS_H
> +#include <linux/ioport.h>
> +#include <linux/of.h>
> +
> +extern void __iomem *of_iomap(struct device_node *device, int index);
> +
> +#endif /* __OF_ADDRESS_H */
> +

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

* Re: [PATCH 2/5] of/address: merge of_address_to_resource()
  2010-06-08 14:10 ` [PATCH 2/5] of/address: merge of_address_to_resource() Grant Likely
@ 2010-06-10  6:41   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-10  6:41 UTC (permalink / raw)
  To: Grant Likely
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> Merge common code between PowerPC and Microblaze.  This patch also
> moves the prototype of pci_address_to_pio() out of pci-bridge.h and
> into prom.h because the only user of pci_address_to_pio() is
> of_address_to_resource().
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> CC: Michal Simek <monstr@monstr.eu>
> CC: Grant Likely <grant.likely@secretlab.ca>
> CC: Wolfram Sang <w.sang@pengutronix.de>
> CC: Stephen Rothwell <sfr@canb.auug.org.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> CC: microblaze-uclinux@itee.uq.edu.au
> CC: linuxppc-dev@ozlabs.org
> ---
>  arch/microblaze/include/asm/pci-bridge.h |    5 ---
>  arch/microblaze/include/asm/prom.h       |   17 +++++-----
>  arch/microblaze/kernel/prom_parse.c      |   46 +--------------------------
>  arch/powerpc/include/asm/pci-bridge.h    |    5 ---
>  arch/powerpc/include/asm/prom.h          |   17 +++++-----
>  arch/powerpc/kernel/prom_parse.c         |   47 +---------------------------
>  drivers/of/address.c                     |   51 ++++++++++++++++++++++++++++++
>  include/linux/of_address.h               |    5 +++
>  8 files changed, 76 insertions(+), 117 deletions(-)
> 
> diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
> index 0c77cda..0c68764 100644
> --- a/arch/microblaze/include/asm/pci-bridge.h
> +++ b/arch/microblaze/include/asm/pci-bridge.h
> @@ -172,13 +172,8 @@ static inline int pci_has_flag(int flag)
>  
>  extern struct list_head hose_list;
>  
> -extern unsigned long pci_address_to_pio(phys_addr_t address);
>  extern int pcibios_vaddr_is_ioport(void __iomem *address);
>  #else
> -static inline unsigned long pci_address_to_pio(phys_addr_t address)
> -{
> -	return (unsigned long)-1;
> -}
>  static inline int pcibios_vaddr_is_ioport(void __iomem *address)
>  {
>  	return 0;
> diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
> index b6698ef..644fa32 100644
> --- a/arch/microblaze/include/asm/prom.h
> +++ b/arch/microblaze/include/asm/prom.h
> @@ -65,17 +65,18 @@ extern const u32 *of_get_address(struct device_node *dev, int index,
>  extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
>  			u64 *size, unsigned int *flags);
>  
> -/* Get an address as a resource. Note that if your address is
> - * a PIO address, the conversion will fail if the physical address
> - * can't be internally converted to an IO token with
> - * pci_address_to_pio(), that is because it's either called to early
> - * or it can't be matched to any host bridge IO space
> - */
> -extern int of_address_to_resource(struct device_node *dev, int index,
> -				struct resource *r);
>  extern int of_pci_address_to_resource(struct device_node *dev, int bar,
>  				struct resource *r);
>  
> +#ifdef CONFIG_PCI
> +extern unsigned long pci_address_to_pio(phys_addr_t address);
> +#else
> +static inline unsigned long pci_address_to_pio(phys_addr_t address)
> +{
> +	return (unsigned long)-1;
> +}
> +#endif	/* CONFIG_PCI */
> +
>  /* Parse the ibm,dma-window property of an OF node into the busno, phys and
>   * size parameters.
>   */
> diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
> index 5003ee8..7cb5a98 100644
> --- a/arch/microblaze/kernel/prom_parse.c
> +++ b/arch/microblaze/kernel/prom_parse.c
> @@ -6,6 +6,7 @@
>  #include <linux/module.h>
>  #include <linux/ioport.h>
>  #include <linux/etherdevice.h>
> +#include <linux/of_address.h>
>  #include <asm/prom.h>
>  #include <asm/pci-bridge.h>
>  
> @@ -17,9 +18,6 @@
>  			(ns) > 0)
>  
>  static struct of_bus *of_match_bus(struct device_node *np);
> -static int __of_address_to_resource(struct device_node *dev,
> -		const u32 *addrp, u64 size, unsigned int flags,
> -		struct resource *r);
>  
>  /* Debug utility */
>  #ifdef DEBUG
> @@ -576,48 +574,6 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
>  }
>  EXPORT_SYMBOL(of_get_address);
>  
> -static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> -				u64 size, unsigned int flags,
> -				struct resource *r)
> -{
> -	u64 taddr;
> -
> -	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
> -		return -EINVAL;
> -	taddr = of_translate_address(dev, addrp);
> -	if (taddr == OF_BAD_ADDR)
> -		return -EINVAL;
> -	memset(r, 0, sizeof(struct resource));
> -	if (flags & IORESOURCE_IO) {
> -		unsigned long port;
> -		port = -1; /* pci_address_to_pio(taddr); */
> -		if (port == (unsigned long)-1)
> -			return -EINVAL;
> -		r->start = port;
> -		r->end = port + size - 1;
> -	} else {
> -		r->start = taddr;
> -		r->end = taddr + size - 1;
> -	}
> -	r->flags = flags;
> -	r->name = dev->name;
> -	return 0;
> -}
> -
> -int of_address_to_resource(struct device_node *dev, int index,
> -			struct resource *r)
> -{
> -	const u32	*addrp;
> -	u64		size;
> -	unsigned int	flags;
> -
> -	addrp = of_get_address(dev, index, &size, &flags);
> -	if (addrp == NULL)
> -		return -EINVAL;
> -	return __of_address_to_resource(dev, addrp, size, flags, r);
> -}
> -EXPORT_SYMBOL_GPL(of_address_to_resource);
> -
>  void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
>  		unsigned long *busno, unsigned long *phys, unsigned long *size)
>  {
> diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
> index 76e1f31..51e9e6f 100644
> --- a/arch/powerpc/include/asm/pci-bridge.h
> +++ b/arch/powerpc/include/asm/pci-bridge.h
> @@ -303,13 +303,8 @@ extern void pcibios_free_controller(struct pci_controller *phb);
>  extern void pcibios_setup_phb_resources(struct pci_controller *hose);
>  
>  #ifdef CONFIG_PCI
> -extern unsigned long pci_address_to_pio(phys_addr_t address);
>  extern int pcibios_vaddr_is_ioport(void __iomem *address);
>  #else
> -static inline unsigned long pci_address_to_pio(phys_addr_t address)
> -{
> -	return (unsigned long)-1;
> -}
>  static inline int pcibios_vaddr_is_ioport(void __iomem *address)
>  {
>  	return 0;
> diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
> index e0bdbc6..e1c1bdd 100644
> --- a/arch/powerpc/include/asm/prom.h
> +++ b/arch/powerpc/include/asm/prom.h
> @@ -70,14 +70,6 @@ static inline const u32 *of_get_pci_address(struct device_node *dev,
>  }
>  #endif /* CONFIG_PCI */
>  
> -/* Get an address as a resource. Note that if your address is
> - * a PIO address, the conversion will fail if the physical address
> - * can't be internally converted to an IO token with
> - * pci_address_to_pio(), that is because it's either called to early
> - * or it can't be matched to any host bridge IO space
> - */
> -extern int of_address_to_resource(struct device_node *dev, int index,
> -				  struct resource *r);
>  #ifdef CONFIG_PCI
>  extern int of_pci_address_to_resource(struct device_node *dev, int bar,
>  				      struct resource *r);
> @@ -89,6 +81,15 @@ static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
>  }
>  #endif /* CONFIG_PCI */
>  
> +#ifdef CONFIG_PCI
> +extern unsigned long pci_address_to_pio(phys_addr_t address);
> +#else
> +static inline unsigned long pci_address_to_pio(phys_addr_t address)
> +{
> +	return (unsigned long)-1;
> +}
> +#endif	/* CONFIG_PCI */
> +
>  /* Parse the ibm,dma-window property of an OF node into the busno, phys and
>   * size parameters.
>   */
> diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
> index dfb73c4..a2ef129 100644
> --- a/arch/powerpc/kernel/prom_parse.c
> +++ b/arch/powerpc/kernel/prom_parse.c
> @@ -6,6 +6,7 @@
>  #include <linux/module.h>
>  #include <linux/ioport.h>
>  #include <linux/etherdevice.h>
> +#include <linux/of_address.h>
>  #include <asm/prom.h>
>  #include <asm/pci-bridge.h>
>  
> @@ -27,10 +28,6 @@
>  			(ns) > 0)
>  
>  static struct of_bus *of_match_bus(struct device_node *np);
> -static int __of_address_to_resource(struct device_node *dev,
> -		const u32 *addrp, u64 size, unsigned int flags,
> -		struct resource *r);
> -
>  
>  /* Debug utility */
>  #ifdef DEBUG
> @@ -610,48 +607,6 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
>  }
>  EXPORT_SYMBOL(of_get_address);
>  
> -static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> -				    u64 size, unsigned int flags,
> -				    struct resource *r)
> -{
> -	u64 taddr;
> -
> -	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
> -		return -EINVAL;
> -	taddr = of_translate_address(dev, addrp);
> -	if (taddr == OF_BAD_ADDR)
> -		return -EINVAL;
> -	memset(r, 0, sizeof(struct resource));
> -	if (flags & IORESOURCE_IO) {
> -		unsigned long port;
> -		port = pci_address_to_pio(taddr);
> -		if (port == (unsigned long)-1)
> -			return -EINVAL;
> -		r->start = port;
> -		r->end = port + size - 1;
> -	} else {
> -		r->start = taddr;
> -		r->end = taddr + size - 1;
> -	}
> -	r->flags = flags;
> -	r->name = dev->name;
> -	return 0;
> -}
> -
> -int of_address_to_resource(struct device_node *dev, int index,
> -			   struct resource *r)
> -{
> -	const u32	*addrp;
> -	u64		size;
> -	unsigned int	flags;
> -
> -	addrp = of_get_address(dev, index, &size, &flags);
> -	if (addrp == NULL)
> -		return -EINVAL;
> -	return __of_address_to_resource(dev, addrp, size, flags, r);
> -}
> -EXPORT_SYMBOL_GPL(of_address_to_resource);
> -
>  void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
>  		unsigned long *busno, unsigned long *phys, unsigned long *size)
>  {
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 258528d..c381955 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -3,6 +3,57 @@
>  #include <linux/ioport.h>
>  #include <linux/of_address.h>
>  
> +int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> +			     u64 size, unsigned int flags,
> +			     struct resource *r)
> +{
> +	u64 taddr;
> +
> +	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
> +		return -EINVAL;
> +	taddr = of_translate_address(dev, addrp);
> +	if (taddr == OF_BAD_ADDR)
> +		return -EINVAL;
> +	memset(r, 0, sizeof(struct resource));
> +	if (flags & IORESOURCE_IO) {
> +		unsigned long port;
> +		port = pci_address_to_pio(taddr);
> +		if (port == (unsigned long)-1)
> +			return -EINVAL;
> +		r->start = port;
> +		r->end = port + size - 1;
> +	} else {
> +		r->start = taddr;
> +		r->end = taddr + size - 1;
> +	}
> +	r->flags = flags;
> +	r->name = dev->name;
> +	return 0;
> +}
> +
> +/**
> + * of_address_to_resource - Translate device tree address and return as resource
> + *
> + * Note that if your address is a PIO address, the conversion will fail if
> + * the physical address can't be internally converted to an IO token with
> + * pci_address_to_pio(), that is because it's either called to early or it
> + * can't be matched to any host bridge IO space
> + */
> +int of_address_to_resource(struct device_node *dev, int index,
> +			   struct resource *r)
> +{
> +	const u32	*addrp;
> +	u64		size;
> +	unsigned int	flags;
> +
> +	addrp = of_get_address(dev, index, &size, &flags);
> +	if (addrp == NULL)
> +		return -EINVAL;
> +	return __of_address_to_resource(dev, addrp, size, flags, r);
> +}
> +EXPORT_SYMBOL_GPL(of_address_to_resource);
> +
> +
>  /**
>   * of_iomap - Maps the memory mapped IO for a given device_node
>   * @device:	the device whose io range will be mapped
> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
> index 570831d..474b794 100644
> --- a/include/linux/of_address.h
> +++ b/include/linux/of_address.h
> @@ -3,6 +3,11 @@
>  #include <linux/ioport.h>
>  #include <linux/of.h>
>  
> +extern int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> +				    u64 size, unsigned int flags,
> +				    struct resource *r);
> +extern int of_address_to_resource(struct device_node *dev, int index,
> +				  struct resource *r);
>  extern void __iomem *of_iomap(struct device_node *device, int index);
>  
>  #endif /* __OF_ADDRESS_H */

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

* Re: [PATCH 3/5] of/address: Merge all of the bus translation code
  2010-06-08 14:10 ` [PATCH 3/5] of/address: Merge all of the bus translation code Grant Likely
@ 2010-06-10  6:43   ` Benjamin Herrenschmidt
  2010-06-10 14:26     ` Grant Likely
  0 siblings, 1 reply; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-10  6:43 UTC (permalink / raw)
  To: Grant Likely
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> Microblaze and PowerPC share a large chunk of code for translating
> OF device tree data into usable addresses.  There aren't many differences
                                                           ^^^^
Care to comment on these differences ?

> between the two, so merge the codebase wholesale rather than trying to
> work out the independent bits.

Well, I don't see ifdef's in the resulting code (but I'm a bit blind),
so what did you do with the differences ?

This is complex and fragile code, so any change to it must be very
carefully scrutinized.

Cheers,
Ben.

> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> CC: Michal Simek <monstr@monstr.eu>
> CC: Wolfram Sang <w.sang@pengutronix.de>
> CC: Stephen Rothwell <sfr@canb.auug.org.au>
> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> CC: microblaze-uclinux@itee.uq.edu.au
> CC: linuxppc-dev@ozlabs.org
> ---
>  arch/microblaze/include/asm/prom.h  |    4 
>  arch/microblaze/kernel/prom_parse.c |  489 ---------------------------------
>  arch/powerpc/include/asm/prom.h     |    4 
>  arch/powerpc/kernel/prom_parse.c    |  515 -----------------------------------
>  drivers/of/address.c                |  517 +++++++++++++++++++++++++++++++++++
>  include/linux/of_address.h          |    4 
>  6 files changed, 515 insertions(+), 1018 deletions(-)
> 
> diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
> index 644fa32..35cb3de 100644
> --- a/arch/microblaze/include/asm/prom.h
> +++ b/arch/microblaze/include/asm/prom.h
> @@ -52,10 +52,6 @@ extern void pci_create_OF_bus_map(void);
>   * OF address retreival & translation
>   */
>  
> -/* Translate an OF address block into a CPU physical address
> - */
> -extern u64 of_translate_address(struct device_node *np, const u32 *addr);
> -
>  /* Extract an address from a device, returns the region size and
>   * the address space flags too. The PCI version uses a BAR number
>   * instead of an absolute index
> diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
> index 7cb5a98..1d610e6 100644
> --- a/arch/microblaze/kernel/prom_parse.c
> +++ b/arch/microblaze/kernel/prom_parse.c
> @@ -10,213 +10,7 @@
>  #include <asm/prom.h>
>  #include <asm/pci-bridge.h>
>  
> -#define PRu64	"%llx"
> -
> -/* Max address size we deal with */
> -#define OF_MAX_ADDR_CELLS	4
> -#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
> -			(ns) > 0)
> -
> -static struct of_bus *of_match_bus(struct device_node *np);
> -
> -/* Debug utility */
> -#ifdef DEBUG
> -static void of_dump_addr(const char *s, const u32 *addr, int na)
> -{
> -	printk(KERN_INFO "%s", s);
> -	while (na--)
> -		printk(KERN_INFO " %08x", *(addr++));
> -	printk(KERN_INFO "\n");
> -}
> -#else
> -static void of_dump_addr(const char *s, const u32 *addr, int na) { }
> -#endif
> -
> -/* Callbacks for bus specific translators */
> -struct of_bus {
> -	const char	*name;
> -	const char	*addresses;
> -	int		(*match)(struct device_node *parent);
> -	void		(*count_cells)(struct device_node *child,
> -					int *addrc, int *sizec);
> -	u64		(*map)(u32 *addr, const u32 *range,
> -				int na, int ns, int pna);
> -	int		(*translate)(u32 *addr, u64 offset, int na);
> -	unsigned int	(*get_flags)(const u32 *addr);
> -};
> -
> -/*
> - * Default translator (generic bus)
> - */
> -
> -static void of_bus_default_count_cells(struct device_node *dev,
> -					int *addrc, int *sizec)
> -{
> -	if (addrc)
> -		*addrc = of_n_addr_cells(dev);
> -	if (sizec)
> -		*sizec = of_n_size_cells(dev);
> -}
> -
> -static u64 of_bus_default_map(u32 *addr, const u32 *range,
> -		int na, int ns, int pna)
> -{
> -	u64 cp, s, da;
> -
> -	cp = of_read_number(range, na);
> -	s  = of_read_number(range + na + pna, ns);
> -	da = of_read_number(addr, na);
> -
> -	pr_debug("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
> -		cp, s, da);
> -
> -	if (da < cp || da >= (cp + s))
> -		return OF_BAD_ADDR;
> -	return da - cp;
> -}
> -
> -static int of_bus_default_translate(u32 *addr, u64 offset, int na)
> -{
> -	u64 a = of_read_number(addr, na);
> -	memset(addr, 0, na * 4);
> -	a += offset;
> -	if (na > 1)
> -		addr[na - 2] = a >> 32;
> -	addr[na - 1] = a & 0xffffffffu;
> -
> -	return 0;
> -}
> -
> -static unsigned int of_bus_default_get_flags(const u32 *addr)
> -{
> -	return IORESOURCE_MEM;
> -}
> -
>  #ifdef CONFIG_PCI
> -/*
> - * PCI bus specific translator
> - */
> -
> -static int of_bus_pci_match(struct device_node *np)
> -{
> -	/* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
> -	return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
> -}
> -
> -static void of_bus_pci_count_cells(struct device_node *np,
> -				int *addrc, int *sizec)
> -{
> -	if (addrc)
> -		*addrc = 3;
> -	if (sizec)
> -		*sizec = 2;
> -}
> -
> -static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
> -{
> -	u64 cp, s, da;
> -
> -	/* Check address type match */
> -	if ((addr[0] ^ range[0]) & 0x03000000)
> -		return OF_BAD_ADDR;
> -
> -	/* Read address values, skipping high cell */
> -	cp = of_read_number(range + 1, na - 1);
> -	s  = of_read_number(range + na + pna, ns);
> -	da = of_read_number(addr + 1, na - 1);
> -
> -	pr_debug("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
> -
> -	if (da < cp || da >= (cp + s))
> -		return OF_BAD_ADDR;
> -	return da - cp;
> -}
> -
> -static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
> -{
> -	return of_bus_default_translate(addr + 1, offset, na - 1);
> -}
> -
> -static unsigned int of_bus_pci_get_flags(const u32 *addr)
> -{
> -	unsigned int flags = 0;
> -	u32 w = addr[0];
> -
> -	switch ((w >> 24) & 0x03) {
> -	case 0x01:
> -		flags |= IORESOURCE_IO;
> -		break;
> -	case 0x02: /* 32 bits */
> -	case 0x03: /* 64 bits */
> -		flags |= IORESOURCE_MEM;
> -		break;
> -	}
> -	if (w & 0x40000000)
> -		flags |= IORESOURCE_PREFETCH;
> -	return flags;
> -}
> -
> -const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
> -			unsigned int *flags)
> -{
> -	const u32 *prop;
> -	unsigned int psize;
> -	struct device_node *parent;
> -	struct of_bus *bus;
> -	int onesize, i, na, ns;
> -
> -	/* Get parent & match bus type */
> -	parent = of_get_parent(dev);
> -	if (parent == NULL)
> -		return NULL;
> -	bus = of_match_bus(parent);
> -	if (strcmp(bus->name, "pci")) {
> -		of_node_put(parent);
> -		return NULL;
> -	}
> -	bus->count_cells(dev, &na, &ns);
> -	of_node_put(parent);
> -	if (!OF_CHECK_COUNTS(na, ns))
> -		return NULL;
> -
> -	/* Get "reg" or "assigned-addresses" property */
> -	prop = of_get_property(dev, bus->addresses, &psize);
> -	if (prop == NULL)
> -		return NULL;
> -	psize /= 4;
> -
> -	onesize = na + ns;
> -	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> -		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
> -			if (size)
> -				*size = of_read_number(prop + na, ns);
> -			if (flags)
> -				*flags = bus->get_flags(prop);
> -			return prop;
> -		}
> -	return NULL;
> -}
> -EXPORT_SYMBOL(of_get_pci_address);
> -
> -int of_pci_address_to_resource(struct device_node *dev, int bar,
> -				struct resource *r)
> -{
> -	const u32	*addrp;
> -	u64		size;
> -	unsigned int	flags;
> -
> -	addrp = of_get_pci_address(dev, bar, &size, &flags);
> -	if (addrp == NULL)
> -		return -EINVAL;
> -	return __of_address_to_resource(dev, addrp, size, flags, r);
> -}
> -EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
> -
> -static u8 of_irq_pci_swizzle(u8 slot, u8 pin)
> -{
> -	return (((pin - 1) + slot) % 4) + 1;
> -}
> -
>  int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
>  {
>  	struct device_node *dn, *ppnode;
> @@ -291,289 +85,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
>  EXPORT_SYMBOL_GPL(of_irq_map_pci);
>  #endif /* CONFIG_PCI */
>  
> -/*
> - * ISA bus specific translator
> - */
> -
> -static int of_bus_isa_match(struct device_node *np)
> -{
> -	return !strcmp(np->name, "isa");
> -}
> -
> -static void of_bus_isa_count_cells(struct device_node *child,
> -				int *addrc, int *sizec)
> -{
> -	if (addrc)
> -		*addrc = 2;
> -	if (sizec)
> -		*sizec = 1;
> -}
> -
> -static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
> -{
> -	u64 cp, s, da;
> -
> -	/* Check address type match */
> -	if ((addr[0] ^ range[0]) & 0x00000001)
> -		return OF_BAD_ADDR;
> -
> -	/* Read address values, skipping high cell */
> -	cp = of_read_number(range + 1, na - 1);
> -	s  = of_read_number(range + na + pna, ns);
> -	da = of_read_number(addr + 1, na - 1);
> -
> -	pr_debug("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
> -
> -	if (da < cp || da >= (cp + s))
> -		return OF_BAD_ADDR;
> -	return da - cp;
> -}
> -
> -static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
> -{
> -	return of_bus_default_translate(addr + 1, offset, na - 1);
> -}
> -
> -static unsigned int of_bus_isa_get_flags(const u32 *addr)
> -{
> -	unsigned int flags = 0;
> -	u32 w = addr[0];
> -
> -	if (w & 1)
> -		flags |= IORESOURCE_IO;
> -	else
> -		flags |= IORESOURCE_MEM;
> -	return flags;
> -}
> -
> -/*
> - * Array of bus specific translators
> - */
> -
> -static struct of_bus of_busses[] = {
> -#ifdef CONFIG_PCI
> -	/* PCI */
> -	{
> -		.name = "pci",
> -		.addresses = "assigned-addresses",
> -		.match = of_bus_pci_match,
> -		.count_cells = of_bus_pci_count_cells,
> -		.map = of_bus_pci_map,
> -		.translate = of_bus_pci_translate,
> -		.get_flags = of_bus_pci_get_flags,
> -	},
> -#endif /* CONFIG_PCI */
> -	/* ISA */
> -	{
> -		.name = "isa",
> -		.addresses = "reg",
> -		.match = of_bus_isa_match,
> -		.count_cells = of_bus_isa_count_cells,
> -		.map = of_bus_isa_map,
> -		.translate = of_bus_isa_translate,
> -		.get_flags = of_bus_isa_get_flags,
> -	},
> -	/* Default */
> -	{
> -		.name = "default",
> -		.addresses = "reg",
> -		.match = NULL,
> -		.count_cells = of_bus_default_count_cells,
> -		.map = of_bus_default_map,
> -		.translate = of_bus_default_translate,
> -		.get_flags = of_bus_default_get_flags,
> -	},
> -};
> -
> -static struct of_bus *of_match_bus(struct device_node *np)
> -{
> -	int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(of_busses); i++)
> -		if (!of_busses[i].match || of_busses[i].match(np))
> -			return &of_busses[i];
> -	BUG();
> -	return NULL;
> -}
> -
> -static int of_translate_one(struct device_node *parent, struct of_bus *bus,
> -			struct of_bus *pbus, u32 *addr,
> -			int na, int ns, int pna)
> -{
> -	const u32 *ranges;
> -	unsigned int rlen;
> -	int rone;
> -	u64 offset = OF_BAD_ADDR;
> -
> -	/* Normally, an absence of a "ranges" property means we are
> -	 * crossing a non-translatable boundary, and thus the addresses
> -	 * below the current not cannot be converted to CPU physical ones.
> -	 * Unfortunately, while this is very clear in the spec, it's not
> -	 * what Apple understood, and they do have things like /uni-n or
> -	 * /ht nodes with no "ranges" property and a lot of perfectly
> -	 * useable mapped devices below them. Thus we treat the absence of
> -	 * "ranges" as equivalent to an empty "ranges" property which means
> -	 * a 1:1 translation at that level. It's up to the caller not to try
> -	 * to translate addresses that aren't supposed to be translated in
> -	 * the first place. --BenH.
> -	 */
> -	ranges = of_get_property(parent, "ranges", (int *) &rlen);
> -	if (ranges == NULL || rlen == 0) {
> -		offset = of_read_number(addr, na);
> -		memset(addr, 0, pna * 4);
> -		pr_debug("OF: no ranges, 1:1 translation\n");
> -		goto finish;
> -	}
> -
> -	pr_debug("OF: walking ranges...\n");
> -
> -	/* Now walk through the ranges */
> -	rlen /= 4;
> -	rone = na + pna + ns;
> -	for (; rlen >= rone; rlen -= rone, ranges += rone) {
> -		offset = bus->map(addr, ranges, na, ns, pna);
> -		if (offset != OF_BAD_ADDR)
> -			break;
> -	}
> -	if (offset == OF_BAD_ADDR) {
> -		pr_debug("OF: not found !\n");
> -		return 1;
> -	}
> -	memcpy(addr, ranges + na, 4 * pna);
> -
> - finish:
> -	of_dump_addr("OF: parent translation for:", addr, pna);
> -	pr_debug("OF: with offset: "PRu64"\n", offset);
> -
> -	/* Translate it into parent bus space */
> -	return pbus->translate(addr, offset, pna);
> -}
> -
> -/*
> - * Translate an address from the device-tree into a CPU physical address,
> - * this walks up the tree and applies the various bus mappings on the
> - * way.
> - *
> - * Note: We consider that crossing any level with #size-cells == 0 to mean
> - * that translation is impossible (that is we are not dealing with a value
> - * that can be mapped to a cpu physical address). This is not really specified
> - * that way, but this is traditionally the way IBM at least do things
> - */
> -u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
> -{
> -	struct device_node *parent = NULL;
> -	struct of_bus *bus, *pbus;
> -	u32 addr[OF_MAX_ADDR_CELLS];
> -	int na, ns, pna, pns;
> -	u64 result = OF_BAD_ADDR;
> -
> -	pr_debug("OF: ** translation for device %s **\n", dev->full_name);
> -
> -	/* Increase refcount at current level */
> -	of_node_get(dev);
> -
> -	/* Get parent & match bus type */
> -	parent = of_get_parent(dev);
> -	if (parent == NULL)
> -		goto bail;
> -	bus = of_match_bus(parent);
> -
> -	/* Cound address cells & copy address locally */
> -	bus->count_cells(dev, &na, &ns);
> -	if (!OF_CHECK_COUNTS(na, ns)) {
> -		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
> -			dev->full_name);
> -		goto bail;
> -	}
> -	memcpy(addr, in_addr, na * 4);
> -
> -	pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
> -		bus->name, na, ns, parent->full_name);
> -	of_dump_addr("OF: translating address:", addr, na);
> -
> -	/* Translate */
> -	for (;;) {
> -		/* Switch to parent bus */
> -		of_node_put(dev);
> -		dev = parent;
> -		parent = of_get_parent(dev);
> -
> -		/* If root, we have finished */
> -		if (parent == NULL) {
> -			pr_debug("OF: reached root node\n");
> -			result = of_read_number(addr, na);
> -			break;
> -		}
> -
> -		/* Get new parent bus and counts */
> -		pbus = of_match_bus(parent);
> -		pbus->count_cells(dev, &pna, &pns);
> -		if (!OF_CHECK_COUNTS(pna, pns)) {
> -			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
> -				dev->full_name);
> -			break;
> -		}
> -
> -		pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
> -			pbus->name, pna, pns, parent->full_name);
> -
> -		/* Apply bus translation */
> -		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna))
> -			break;
> -
> -		/* Complete the move up one level */
> -		na = pna;
> -		ns = pns;
> -		bus = pbus;
> -
> -		of_dump_addr("OF: one level translation:", addr, na);
> -	}
> - bail:
> -	of_node_put(parent);
> -	of_node_put(dev);
> -
> -	return result;
> -}
> -EXPORT_SYMBOL(of_translate_address);
> -
> -const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
> -			unsigned int *flags)
> -{
> -	const u32 *prop;
> -	unsigned int psize;
> -	struct device_node *parent;
> -	struct of_bus *bus;
> -	int onesize, i, na, ns;
> -
> -	/* Get parent & match bus type */
> -	parent = of_get_parent(dev);
> -	if (parent == NULL)
> -		return NULL;
> -	bus = of_match_bus(parent);
> -	bus->count_cells(dev, &na, &ns);
> -	of_node_put(parent);
> -	if (!OF_CHECK_COUNTS(na, ns))
> -		return NULL;
> -
> -	/* Get "reg" or "assigned-addresses" property */
> -	prop = of_get_property(dev, bus->addresses, (int *) &psize);
> -	if (prop == NULL)
> -		return NULL;
> -	psize /= 4;
> -
> -	onesize = na + ns;
> -	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> -		if (i == index) {
> -			if (size)
> -				*size = of_read_number(prop + na, ns);
> -			if (flags)
> -				*flags = bus->get_flags(prop);
> -			return prop;
> -		}
> -	return NULL;
> -}
> -EXPORT_SYMBOL(of_get_address);
> -
>  void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
>  		unsigned long *busno, unsigned long *phys, unsigned long *size)
>  {
> diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
> index e1c1bdd..8e1d0fe 100644
> --- a/arch/powerpc/include/asm/prom.h
> +++ b/arch/powerpc/include/asm/prom.h
> @@ -45,10 +45,6 @@ extern void pci_create_OF_bus_map(void);
>   * OF address retreival & translation
>   */
>  
> -/* Translate an OF address block into a CPU physical address
> - */
> -extern u64 of_translate_address(struct device_node *np, const u32 *addr);
> -
>  /* Translate a DMA address from device space to CPU space */
>  extern u64 of_translate_dma_address(struct device_node *dev,
>  				    const u32 *in_addr);
> diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
> index a2ef129..64f2606 100644
> --- a/arch/powerpc/kernel/prom_parse.c
> +++ b/arch/powerpc/kernel/prom_parse.c
> @@ -10,225 +10,7 @@
>  #include <asm/prom.h>
>  #include <asm/pci-bridge.h>
>  
> -#ifdef DEBUG
> -#define DBG(fmt...) do { printk(fmt); } while(0)
> -#else
> -#define DBG(fmt...) do { } while(0)
> -#endif
> -
> -#ifdef CONFIG_PPC64
> -#define PRu64	"%lx"
> -#else
> -#define PRu64	"%llx"
> -#endif
> -
> -/* Max address size we deal with */
> -#define OF_MAX_ADDR_CELLS	4
> -#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
> -			(ns) > 0)
> -
> -static struct of_bus *of_match_bus(struct device_node *np);
> -
> -/* Debug utility */
> -#ifdef DEBUG
> -static void of_dump_addr(const char *s, const u32 *addr, int na)
> -{
> -	printk("%s", s);
> -	while(na--)
> -		printk(" %08x", *(addr++));
> -	printk("\n");
> -}
> -#else
> -static void of_dump_addr(const char *s, const u32 *addr, int na) { }
> -#endif
> -
> -
> -/* Callbacks for bus specific translators */
> -struct of_bus {
> -	const char	*name;
> -	const char	*addresses;
> -	int		(*match)(struct device_node *parent);
> -	void		(*count_cells)(struct device_node *child,
> -				       int *addrc, int *sizec);
> -	u64		(*map)(u32 *addr, const u32 *range,
> -				int na, int ns, int pna);
> -	int		(*translate)(u32 *addr, u64 offset, int na);
> -	unsigned int	(*get_flags)(const u32 *addr);
> -};
> -
> -
> -/*
> - * Default translator (generic bus)
> - */
> -
> -static void of_bus_default_count_cells(struct device_node *dev,
> -				       int *addrc, int *sizec)
> -{
> -	if (addrc)
> -		*addrc = of_n_addr_cells(dev);
> -	if (sizec)
> -		*sizec = of_n_size_cells(dev);
> -}
> -
> -static u64 of_bus_default_map(u32 *addr, const u32 *range,
> -		int na, int ns, int pna)
> -{
> -	u64 cp, s, da;
> -
> -	cp = of_read_number(range, na);
> -	s  = of_read_number(range + na + pna, ns);
> -	da = of_read_number(addr, na);
> -
> -	DBG("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
> -	    cp, s, da);
> -
> -	if (da < cp || da >= (cp + s))
> -		return OF_BAD_ADDR;
> -	return da - cp;
> -}
> -
> -static int of_bus_default_translate(u32 *addr, u64 offset, int na)
> -{
> -	u64 a = of_read_number(addr, na);
> -	memset(addr, 0, na * 4);
> -	a += offset;
> -	if (na > 1)
> -		addr[na - 2] = a >> 32;
> -	addr[na - 1] = a & 0xffffffffu;
> -
> -	return 0;
> -}
> -
> -static unsigned int of_bus_default_get_flags(const u32 *addr)
> -{
> -	return IORESOURCE_MEM;
> -}
> -
> -
>  #ifdef CONFIG_PCI
> -/*
> - * PCI bus specific translator
> - */
> -
> -static int of_bus_pci_match(struct device_node *np)
> -{
> -	/* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
> -	return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
> -}
> -
> -static void of_bus_pci_count_cells(struct device_node *np,
> -				   int *addrc, int *sizec)
> -{
> -	if (addrc)
> -		*addrc = 3;
> -	if (sizec)
> -		*sizec = 2;
> -}
> -
> -static unsigned int of_bus_pci_get_flags(const u32 *addr)
> -{
> -	unsigned int flags = 0;
> -	u32 w = addr[0];
> -
> -	switch((w >> 24) & 0x03) {
> -	case 0x01:
> -		flags |= IORESOURCE_IO;
> -		break;
> -	case 0x02: /* 32 bits */
> -	case 0x03: /* 64 bits */
> -		flags |= IORESOURCE_MEM;
> -		break;
> -	}
> -	if (w & 0x40000000)
> -		flags |= IORESOURCE_PREFETCH;
> -	return flags;
> -}
> -
> -static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
> -{
> -	u64 cp, s, da;
> -	unsigned int af, rf;
> -
> -	af = of_bus_pci_get_flags(addr);
> -	rf = of_bus_pci_get_flags(range);
> -
> -	/* Check address type match */
> -	if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
> -		return OF_BAD_ADDR;
> -
> -	/* Read address values, skipping high cell */
> -	cp = of_read_number(range + 1, na - 1);
> -	s  = of_read_number(range + na + pna, ns);
> -	da = of_read_number(addr + 1, na - 1);
> -
> -	DBG("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
> -
> -	if (da < cp || da >= (cp + s))
> -		return OF_BAD_ADDR;
> -	return da - cp;
> -}
> -
> -static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
> -{
> -	return of_bus_default_translate(addr + 1, offset, na - 1);
> -}
> -
> -const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
> -			unsigned int *flags)
> -{
> -	const u32 *prop;
> -	unsigned int psize;
> -	struct device_node *parent;
> -	struct of_bus *bus;
> -	int onesize, i, na, ns;
> -
> -	/* Get parent & match bus type */
> -	parent = of_get_parent(dev);
> -	if (parent == NULL)
> -		return NULL;
> -	bus = of_match_bus(parent);
> -	if (strcmp(bus->name, "pci")) {
> -		of_node_put(parent);
> -		return NULL;
> -	}
> -	bus->count_cells(dev, &na, &ns);
> -	of_node_put(parent);
> -	if (!OF_CHECK_COUNTS(na, ns))
> -		return NULL;
> -
> -	/* Get "reg" or "assigned-addresses" property */
> -	prop = of_get_property(dev, bus->addresses, &psize);
> -	if (prop == NULL)
> -		return NULL;
> -	psize /= 4;
> -
> -	onesize = na + ns;
> -	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> -		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
> -			if (size)
> -				*size = of_read_number(prop + na, ns);
> -			if (flags)
> -				*flags = bus->get_flags(prop);
> -			return prop;
> -		}
> -	return NULL;
> -}
> -EXPORT_SYMBOL(of_get_pci_address);
> -
> -int of_pci_address_to_resource(struct device_node *dev, int bar,
> -			       struct resource *r)
> -{
> -	const u32	*addrp;
> -	u64		size;
> -	unsigned int	flags;
> -
> -	addrp = of_get_pci_address(dev, bar, &size, &flags);
> -	if (addrp == NULL)
> -		return -EINVAL;
> -	return __of_address_to_resource(dev, addrp, size, flags, r);
> -}
> -EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
> -
>  int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
>  {
>  	struct device_node *dn, *ppnode;
> @@ -310,303 +92,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
>  EXPORT_SYMBOL_GPL(of_irq_map_pci);
>  #endif /* CONFIG_PCI */
>  
> -/*
> - * ISA bus specific translator
> - */
> -
> -static int of_bus_isa_match(struct device_node *np)
> -{
> -	return !strcmp(np->name, "isa");
> -}
> -
> -static void of_bus_isa_count_cells(struct device_node *child,
> -				   int *addrc, int *sizec)
> -{
> -	if (addrc)
> -		*addrc = 2;
> -	if (sizec)
> -		*sizec = 1;
> -}
> -
> -static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
> -{
> -	u64 cp, s, da;
> -
> -	/* Check address type match */
> -	if ((addr[0] ^ range[0]) & 0x00000001)
> -		return OF_BAD_ADDR;
> -
> -	/* Read address values, skipping high cell */
> -	cp = of_read_number(range + 1, na - 1);
> -	s  = of_read_number(range + na + pna, ns);
> -	da = of_read_number(addr + 1, na - 1);
> -
> -	DBG("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
> -
> -	if (da < cp || da >= (cp + s))
> -		return OF_BAD_ADDR;
> -	return da - cp;
> -}
> -
> -static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
> -{
> -	return of_bus_default_translate(addr + 1, offset, na - 1);
> -}
> -
> -static unsigned int of_bus_isa_get_flags(const u32 *addr)
> -{
> -	unsigned int flags = 0;
> -	u32 w = addr[0];
> -
> -	if (w & 1)
> -		flags |= IORESOURCE_IO;
> -	else
> -		flags |= IORESOURCE_MEM;
> -	return flags;
> -}
> -
> -
> -/*
> - * Array of bus specific translators
> - */
> -
> -static struct of_bus of_busses[] = {
> -#ifdef CONFIG_PCI
> -	/* PCI */
> -	{
> -		.name = "pci",
> -		.addresses = "assigned-addresses",
> -		.match = of_bus_pci_match,
> -		.count_cells = of_bus_pci_count_cells,
> -		.map = of_bus_pci_map,
> -		.translate = of_bus_pci_translate,
> -		.get_flags = of_bus_pci_get_flags,
> -	},
> -#endif /* CONFIG_PCI */
> -	/* ISA */
> -	{
> -		.name = "isa",
> -		.addresses = "reg",
> -		.match = of_bus_isa_match,
> -		.count_cells = of_bus_isa_count_cells,
> -		.map = of_bus_isa_map,
> -		.translate = of_bus_isa_translate,
> -		.get_flags = of_bus_isa_get_flags,
> -	},
> -	/* Default */
> -	{
> -		.name = "default",
> -		.addresses = "reg",
> -		.match = NULL,
> -		.count_cells = of_bus_default_count_cells,
> -		.map = of_bus_default_map,
> -		.translate = of_bus_default_translate,
> -		.get_flags = of_bus_default_get_flags,
> -	},
> -};
> -
> -static struct of_bus *of_match_bus(struct device_node *np)
> -{
> -	int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(of_busses); i ++)
> -		if (!of_busses[i].match || of_busses[i].match(np))
> -			return &of_busses[i];
> -	BUG();
> -	return NULL;
> -}
> -
> -static int of_translate_one(struct device_node *parent, struct of_bus *bus,
> -			    struct of_bus *pbus, u32 *addr,
> -			    int na, int ns, int pna, const char *rprop)
> -{
> -	const u32 *ranges;
> -	unsigned int rlen;
> -	int rone;
> -	u64 offset = OF_BAD_ADDR;
> -
> -	/* Normally, an absence of a "ranges" property means we are
> -	 * crossing a non-translatable boundary, and thus the addresses
> -	 * below the current not cannot be converted to CPU physical ones.
> -	 * Unfortunately, while this is very clear in the spec, it's not
> -	 * what Apple understood, and they do have things like /uni-n or
> -	 * /ht nodes with no "ranges" property and a lot of perfectly
> -	 * useable mapped devices below them. Thus we treat the absence of
> -	 * "ranges" as equivalent to an empty "ranges" property which means
> -	 * a 1:1 translation at that level. It's up to the caller not to try
> -	 * to translate addresses that aren't supposed to be translated in
> -	 * the first place. --BenH.
> -	 */
> -	ranges = of_get_property(parent, rprop, &rlen);
> -	if (ranges == NULL || rlen == 0) {
> -		offset = of_read_number(addr, na);
> -		memset(addr, 0, pna * 4);
> -		DBG("OF: no ranges, 1:1 translation\n");
> -		goto finish;
> -	}
> -
> -	DBG("OF: walking ranges...\n");
> -
> -	/* Now walk through the ranges */
> -	rlen /= 4;
> -	rone = na + pna + ns;
> -	for (; rlen >= rone; rlen -= rone, ranges += rone) {
> -		offset = bus->map(addr, ranges, na, ns, pna);
> -		if (offset != OF_BAD_ADDR)
> -			break;
> -	}
> -	if (offset == OF_BAD_ADDR) {
> -		DBG("OF: not found !\n");
> -		return 1;
> -	}
> -	memcpy(addr, ranges + na, 4 * pna);
> -
> - finish:
> -	of_dump_addr("OF: parent translation for:", addr, pna);
> -	DBG("OF: with offset: "PRu64"\n", offset);
> -
> -	/* Translate it into parent bus space */
> -	return pbus->translate(addr, offset, pna);
> -}
> -
> -
> -/*
> - * Translate an address from the device-tree into a CPU physical address,
> - * this walks up the tree and applies the various bus mappings on the
> - * way.
> - *
> - * Note: We consider that crossing any level with #size-cells == 0 to mean
> - * that translation is impossible (that is we are not dealing with a value
> - * that can be mapped to a cpu physical address). This is not really specified
> - * that way, but this is traditionally the way IBM at least do things
> - */
> -u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
> -			   const char *rprop)
> -{
> -	struct device_node *parent = NULL;
> -	struct of_bus *bus, *pbus;
> -	u32 addr[OF_MAX_ADDR_CELLS];
> -	int na, ns, pna, pns;
> -	u64 result = OF_BAD_ADDR;
> -
> -	DBG("OF: ** translation for device %s **\n", dev->full_name);
> -
> -	/* Increase refcount at current level */
> -	of_node_get(dev);
> -
> -	/* Get parent & match bus type */
> -	parent = of_get_parent(dev);
> -	if (parent == NULL)
> -		goto bail;
> -	bus = of_match_bus(parent);
> -
> -	/* Cound address cells & copy address locally */
> -	bus->count_cells(dev, &na, &ns);
> -	if (!OF_CHECK_COUNTS(na, ns)) {
> -		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
> -		       dev->full_name);
> -		goto bail;
> -	}
> -	memcpy(addr, in_addr, na * 4);
> -
> -	DBG("OF: bus is %s (na=%d, ns=%d) on %s\n",
> -	    bus->name, na, ns, parent->full_name);
> -	of_dump_addr("OF: translating address:", addr, na);
> -
> -	/* Translate */
> -	for (;;) {
> -		/* Switch to parent bus */
> -		of_node_put(dev);
> -		dev = parent;
> -		parent = of_get_parent(dev);
> -
> -		/* If root, we have finished */
> -		if (parent == NULL) {
> -			DBG("OF: reached root node\n");
> -			result = of_read_number(addr, na);
> -			break;
> -		}
> -
> -		/* Get new parent bus and counts */
> -		pbus = of_match_bus(parent);
> -		pbus->count_cells(dev, &pna, &pns);
> -		if (!OF_CHECK_COUNTS(pna, pns)) {
> -			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
> -			       dev->full_name);
> -			break;
> -		}
> -
> -		DBG("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
> -		    pbus->name, pna, pns, parent->full_name);
> -
> -		/* Apply bus translation */
> -		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
> -			break;
> -
> -		/* Complete the move up one level */
> -		na = pna;
> -		ns = pns;
> -		bus = pbus;
> -
> -		of_dump_addr("OF: one level translation:", addr, na);
> -	}
> - bail:
> -	of_node_put(parent);
> -	of_node_put(dev);
> -
> -	return result;
> -}
> -
> -u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
> -{
> -	return __of_translate_address(dev, in_addr, "ranges");
> -}
> -EXPORT_SYMBOL(of_translate_address);
> -
> -u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr)
> -{
> -	return __of_translate_address(dev, in_addr, "dma-ranges");
> -}
> -EXPORT_SYMBOL(of_translate_dma_address);
> -
> -const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
> -		    unsigned int *flags)
> -{
> -	const u32 *prop;
> -	unsigned int psize;
> -	struct device_node *parent;
> -	struct of_bus *bus;
> -	int onesize, i, na, ns;
> -
> -	/* Get parent & match bus type */
> -	parent = of_get_parent(dev);
> -	if (parent == NULL)
> -		return NULL;
> -	bus = of_match_bus(parent);
> -	bus->count_cells(dev, &na, &ns);
> -	of_node_put(parent);
> -	if (!OF_CHECK_COUNTS(na, ns))
> -		return NULL;
> -
> -	/* Get "reg" or "assigned-addresses" property */
> -	prop = of_get_property(dev, bus->addresses, &psize);
> -	if (prop == NULL)
> -		return NULL;
> -	psize /= 4;
> -
> -	onesize = na + ns;
> -	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> -		if (i == index) {
> -			if (size)
> -				*size = of_read_number(prop + na, ns);
> -			if (flags)
> -				*flags = bus->get_flags(prop);
> -			return prop;
> -		}
> -	return NULL;
> -}
> -EXPORT_SYMBOL(of_get_address);
> -
>  void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
>  		unsigned long *busno, unsigned long *phys, unsigned long *size)
>  {
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index c381955..2a905d5 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -1,11 +1,522 @@
>  
>  #include <linux/io.h>
>  #include <linux/ioport.h>
> +#include <linux/module.h>
>  #include <linux/of_address.h>
> +#include <linux/pci_regs.h>
> +#include <linux/string.h>
>  
> -int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> -			     u64 size, unsigned int flags,
> -			     struct resource *r)
> +/* Max address size we deal with */
> +#define OF_MAX_ADDR_CELLS	4
> +#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
> +			(ns) > 0)
> +
> +static struct of_bus *of_match_bus(struct device_node *np);
> +static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> +				    u64 size, unsigned int flags,
> +				    struct resource *r);
> +
> +/* Debug utility */
> +#ifdef DEBUG
> +static void of_dump_addr(const char *s, const u32 *addr, int na)
> +{
> +	printk(KERN_DEBUG "%s", s);
> +	while (na--)
> +		printk(" %08x", *(addr++));
> +	printk("\n");
> +}
> +#else
> +static void of_dump_addr(const char *s, const u32 *addr, int na) { }
> +#endif
> +
> +/* Callbacks for bus specific translators */
> +struct of_bus {
> +	const char	*name;
> +	const char	*addresses;
> +	int		(*match)(struct device_node *parent);
> +	void		(*count_cells)(struct device_node *child,
> +				       int *addrc, int *sizec);
> +	u64		(*map)(u32 *addr, const u32 *range,
> +				int na, int ns, int pna);
> +	int		(*translate)(u32 *addr, u64 offset, int na);
> +	unsigned int	(*get_flags)(const u32 *addr);
> +};
> +
> +/*
> + * Default translator (generic bus)
> + */
> +
> +static void of_bus_default_count_cells(struct device_node *dev,
> +				       int *addrc, int *sizec)
> +{
> +	if (addrc)
> +		*addrc = of_n_addr_cells(dev);
> +	if (sizec)
> +		*sizec = of_n_size_cells(dev);
> +}
> +
> +static u64 of_bus_default_map(u32 *addr, const u32 *range,
> +		int na, int ns, int pna)
> +{
> +	u64 cp, s, da;
> +
> +	cp = of_read_number(range, na);
> +	s  = of_read_number(range + na + pna, ns);
> +	da = of_read_number(addr, na);
> +
> +	pr_debug("OF: default map, cp=%llx, s=%llx, da=%llx\n",
> +		 (unsigned long long)cp, (unsigned long long)s,
> +		 (unsigned long long)da);
> +
> +	if (da < cp || da >= (cp + s))
> +		return OF_BAD_ADDR;
> +	return da - cp;
> +}
> +
> +static int of_bus_default_translate(u32 *addr, u64 offset, int na)
> +{
> +	u64 a = of_read_number(addr, na);
> +	memset(addr, 0, na * 4);
> +	a += offset;
> +	if (na > 1)
> +		addr[na - 2] = a >> 32;
> +	addr[na - 1] = a & 0xffffffffu;
> +
> +	return 0;
> +}
> +
> +static unsigned int of_bus_default_get_flags(const u32 *addr)
> +{
> +	return IORESOURCE_MEM;
> +}
> +
> +#ifdef CONFIG_PCI
> +/*
> + * PCI bus specific translator
> + */
> +
> +static int of_bus_pci_match(struct device_node *np)
> +{
> +	/* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
> +	return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
> +}
> +
> +static void of_bus_pci_count_cells(struct device_node *np,
> +				   int *addrc, int *sizec)
> +{
> +	if (addrc)
> +		*addrc = 3;
> +	if (sizec)
> +		*sizec = 2;
> +}
> +
> +static unsigned int of_bus_pci_get_flags(const u32 *addr)
> +{
> +	unsigned int flags = 0;
> +	u32 w = addr[0];
> +
> +	switch((w >> 24) & 0x03) {
> +	case 0x01:
> +		flags |= IORESOURCE_IO;
> +		break;
> +	case 0x02: /* 32 bits */
> +	case 0x03: /* 64 bits */
> +		flags |= IORESOURCE_MEM;
> +		break;
> +	}
> +	if (w & 0x40000000)
> +		flags |= IORESOURCE_PREFETCH;
> +	return flags;
> +}
> +
> +static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
> +{
> +	u64 cp, s, da;
> +	unsigned int af, rf;
> +
> +	af = of_bus_pci_get_flags(addr);
> +	rf = of_bus_pci_get_flags(range);
> +
> +	/* Check address type match */
> +	if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
> +		return OF_BAD_ADDR;
> +
> +	/* Read address values, skipping high cell */
> +	cp = of_read_number(range + 1, na - 1);
> +	s  = of_read_number(range + na + pna, ns);
> +	da = of_read_number(addr + 1, na - 1);
> +
> +	pr_debug("OF: PCI map, cp=%llx, s=%llx, da=%llx\n",
> +		 (unsigned long long)cp, (unsigned long long)s,
> +		 (unsigned long long)da);
> +
> +	if (da < cp || da >= (cp + s))
> +		return OF_BAD_ADDR;
> +	return da - cp;
> +}
> +
> +static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
> +{
> +	return of_bus_default_translate(addr + 1, offset, na - 1);
> +}
> +
> +const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
> +			unsigned int *flags)
> +{
> +	const u32 *prop;
> +	unsigned int psize;
> +	struct device_node *parent;
> +	struct of_bus *bus;
> +	int onesize, i, na, ns;
> +
> +	/* Get parent & match bus type */
> +	parent = of_get_parent(dev);
> +	if (parent == NULL)
> +		return NULL;
> +	bus = of_match_bus(parent);
> +	if (strcmp(bus->name, "pci")) {
> +		of_node_put(parent);
> +		return NULL;
> +	}
> +	bus->count_cells(dev, &na, &ns);
> +	of_node_put(parent);
> +	if (!OF_CHECK_COUNTS(na, ns))
> +		return NULL;
> +
> +	/* Get "reg" or "assigned-addresses" property */
> +	prop = of_get_property(dev, bus->addresses, &psize);
> +	if (prop == NULL)
> +		return NULL;
> +	psize /= 4;
> +
> +	onesize = na + ns;
> +	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> +		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
> +			if (size)
> +				*size = of_read_number(prop + na, ns);
> +			if (flags)
> +				*flags = bus->get_flags(prop);
> +			return prop;
> +		}
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_get_pci_address);
> +
> +int of_pci_address_to_resource(struct device_node *dev, int bar,
> +			       struct resource *r)
> +{
> +	const u32	*addrp;
> +	u64		size;
> +	unsigned int	flags;
> +
> +	addrp = of_get_pci_address(dev, bar, &size, &flags);
> +	if (addrp == NULL)
> +		return -EINVAL;
> +	return __of_address_to_resource(dev, addrp, size, flags, r);
> +}
> +EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
> +#endif /* CONFIG_PCI */
> +
> +/*
> + * ISA bus specific translator
> + */
> +
> +static int of_bus_isa_match(struct device_node *np)
> +{
> +	return !strcmp(np->name, "isa");
> +}
> +
> +static void of_bus_isa_count_cells(struct device_node *child,
> +				   int *addrc, int *sizec)
> +{
> +	if (addrc)
> +		*addrc = 2;
> +	if (sizec)
> +		*sizec = 1;
> +}
> +
> +static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
> +{
> +	u64 cp, s, da;
> +
> +	/* Check address type match */
> +	if ((addr[0] ^ range[0]) & 0x00000001)
> +		return OF_BAD_ADDR;
> +
> +	/* Read address values, skipping high cell */
> +	cp = of_read_number(range + 1, na - 1);
> +	s  = of_read_number(range + na + pna, ns);
> +	da = of_read_number(addr + 1, na - 1);
> +
> +	pr_debug("OF: ISA map, cp=%llx, s=%llx, da=%llx\n",
> +		 (unsigned long long)cp, (unsigned long long)s,
> +		 (unsigned long long)da);
> +
> +	if (da < cp || da >= (cp + s))
> +		return OF_BAD_ADDR;
> +	return da - cp;
> +}
> +
> +static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
> +{
> +	return of_bus_default_translate(addr + 1, offset, na - 1);
> +}
> +
> +static unsigned int of_bus_isa_get_flags(const u32 *addr)
> +{
> +	unsigned int flags = 0;
> +	u32 w = addr[0];
> +
> +	if (w & 1)
> +		flags |= IORESOURCE_IO;
> +	else
> +		flags |= IORESOURCE_MEM;
> +	return flags;
> +}
> +
> +/*
> + * Array of bus specific translators
> + */
> +
> +static struct of_bus of_busses[] = {
> +#ifdef CONFIG_PCI
> +	/* PCI */
> +	{
> +		.name = "pci",
> +		.addresses = "assigned-addresses",
> +		.match = of_bus_pci_match,
> +		.count_cells = of_bus_pci_count_cells,
> +		.map = of_bus_pci_map,
> +		.translate = of_bus_pci_translate,
> +		.get_flags = of_bus_pci_get_flags,
> +	},
> +#endif /* CONFIG_PCI */
> +	/* ISA */
> +	{
> +		.name = "isa",
> +		.addresses = "reg",
> +		.match = of_bus_isa_match,
> +		.count_cells = of_bus_isa_count_cells,
> +		.map = of_bus_isa_map,
> +		.translate = of_bus_isa_translate,
> +		.get_flags = of_bus_isa_get_flags,
> +	},
> +	/* Default */
> +	{
> +		.name = "default",
> +		.addresses = "reg",
> +		.match = NULL,
> +		.count_cells = of_bus_default_count_cells,
> +		.map = of_bus_default_map,
> +		.translate = of_bus_default_translate,
> +		.get_flags = of_bus_default_get_flags,
> +	},
> +};
> +
> +static struct of_bus *of_match_bus(struct device_node *np)
> +{
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(of_busses); i++)
> +		if (!of_busses[i].match || of_busses[i].match(np))
> +			return &of_busses[i];
> +	BUG();
> +	return NULL;
> +}
> +
> +static int of_translate_one(struct device_node *parent, struct of_bus *bus,
> +			    struct of_bus *pbus, u32 *addr,
> +			    int na, int ns, int pna, const char *rprop)
> +{
> +	const u32 *ranges;
> +	unsigned int rlen;
> +	int rone;
> +	u64 offset = OF_BAD_ADDR;
> +
> +	/* Normally, an absence of a "ranges" property means we are
> +	 * crossing a non-translatable boundary, and thus the addresses
> +	 * below the current not cannot be converted to CPU physical ones.
> +	 * Unfortunately, while this is very clear in the spec, it's not
> +	 * what Apple understood, and they do have things like /uni-n or
> +	 * /ht nodes with no "ranges" property and a lot of perfectly
> +	 * useable mapped devices below them. Thus we treat the absence of
> +	 * "ranges" as equivalent to an empty "ranges" property which means
> +	 * a 1:1 translation at that level. It's up to the caller not to try
> +	 * to translate addresses that aren't supposed to be translated in
> +	 * the first place. --BenH.
> +	 */
> +	ranges = of_get_property(parent, rprop, &rlen);
> +	if (ranges == NULL || rlen == 0) {
> +		offset = of_read_number(addr, na);
> +		memset(addr, 0, pna * 4);
> +		pr_debug("OF: no ranges, 1:1 translation\n");
> +		goto finish;
> +	}
> +
> +	pr_debug("OF: walking ranges...\n");
> +
> +	/* Now walk through the ranges */
> +	rlen /= 4;
> +	rone = na + pna + ns;
> +	for (; rlen >= rone; rlen -= rone, ranges += rone) {
> +		offset = bus->map(addr, ranges, na, ns, pna);
> +		if (offset != OF_BAD_ADDR)
> +			break;
> +	}
> +	if (offset == OF_BAD_ADDR) {
> +		pr_debug("OF: not found !\n");
> +		return 1;
> +	}
> +	memcpy(addr, ranges + na, 4 * pna);
> +
> + finish:
> +	of_dump_addr("OF: parent translation for:", addr, pna);
> +	pr_debug("OF: with offset: %llx\n", (unsigned long long)offset);
> +
> +	/* Translate it into parent bus space */
> +	return pbus->translate(addr, offset, pna);
> +}
> +
> +/*
> + * Translate an address from the device-tree into a CPU physical address,
> + * this walks up the tree and applies the various bus mappings on the
> + * way.
> + *
> + * Note: We consider that crossing any level with #size-cells == 0 to mean
> + * that translation is impossible (that is we are not dealing with a value
> + * that can be mapped to a cpu physical address). This is not really specified
> + * that way, but this is traditionally the way IBM at least do things
> + */
> +u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
> +			   const char *rprop)
> +{
> +	struct device_node *parent = NULL;
> +	struct of_bus *bus, *pbus;
> +	u32 addr[OF_MAX_ADDR_CELLS];
> +	int na, ns, pna, pns;
> +	u64 result = OF_BAD_ADDR;
> +
> +	pr_debug("OF: ** translation for device %s **\n", dev->full_name);
> +
> +	/* Increase refcount at current level */
> +	of_node_get(dev);
> +
> +	/* Get parent & match bus type */
> +	parent = of_get_parent(dev);
> +	if (parent == NULL)
> +		goto bail;
> +	bus = of_match_bus(parent);
> +
> +	/* Cound address cells & copy address locally */
> +	bus->count_cells(dev, &na, &ns);
> +	if (!OF_CHECK_COUNTS(na, ns)) {
> +		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
> +		       dev->full_name);
> +		goto bail;
> +	}
> +	memcpy(addr, in_addr, na * 4);
> +
> +	pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
> +	    bus->name, na, ns, parent->full_name);
> +	of_dump_addr("OF: translating address:", addr, na);
> +
> +	/* Translate */
> +	for (;;) {
> +		/* Switch to parent bus */
> +		of_node_put(dev);
> +		dev = parent;
> +		parent = of_get_parent(dev);
> +
> +		/* If root, we have finished */
> +		if (parent == NULL) {
> +			pr_debug("OF: reached root node\n");
> +			result = of_read_number(addr, na);
> +			break;
> +		}
> +
> +		/* Get new parent bus and counts */
> +		pbus = of_match_bus(parent);
> +		pbus->count_cells(dev, &pna, &pns);
> +		if (!OF_CHECK_COUNTS(pna, pns)) {
> +			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
> +			       dev->full_name);
> +			break;
> +		}
> +
> +		pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
> +		    pbus->name, pna, pns, parent->full_name);
> +
> +		/* Apply bus translation */
> +		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
> +			break;
> +
> +		/* Complete the move up one level */
> +		na = pna;
> +		ns = pns;
> +		bus = pbus;
> +
> +		of_dump_addr("OF: one level translation:", addr, na);
> +	}
> + bail:
> +	of_node_put(parent);
> +	of_node_put(dev);
> +
> +	return result;
> +}
> +
> +u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
> +{
> +	return __of_translate_address(dev, in_addr, "ranges");
> +}
> +EXPORT_SYMBOL(of_translate_address);
> +
> +u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr)
> +{
> +	return __of_translate_address(dev, in_addr, "dma-ranges");
> +}
> +EXPORT_SYMBOL(of_translate_dma_address);
> +
> +const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
> +		    unsigned int *flags)
> +{
> +	const u32 *prop;
> +	unsigned int psize;
> +	struct device_node *parent;
> +	struct of_bus *bus;
> +	int onesize, i, na, ns;
> +
> +	/* Get parent & match bus type */
> +	parent = of_get_parent(dev);
> +	if (parent == NULL)
> +		return NULL;
> +	bus = of_match_bus(parent);
> +	bus->count_cells(dev, &na, &ns);
> +	of_node_put(parent);
> +	if (!OF_CHECK_COUNTS(na, ns))
> +		return NULL;
> +
> +	/* Get "reg" or "assigned-addresses" property */
> +	prop = of_get_property(dev, bus->addresses, &psize);
> +	if (prop == NULL)
> +		return NULL;
> +	psize /= 4;
> +
> +	onesize = na + ns;
> +	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> +		if (i == index) {
> +			if (size)
> +				*size = of_read_number(prop + na, ns);
> +			if (flags)
> +				*flags = bus->get_flags(prop);
> +			return prop;
> +		}
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_get_address);
> +
> +static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> +				    u64 size, unsigned int flags,
> +				    struct resource *r)
>  {
>  	u64 taddr;
>  
> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
> index 474b794..cc567df 100644
> --- a/include/linux/of_address.h
> +++ b/include/linux/of_address.h
> @@ -3,9 +3,7 @@
>  #include <linux/ioport.h>
>  #include <linux/of.h>
>  
> -extern int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
> -				    u64 size, unsigned int flags,
> -				    struct resource *r);
> +extern u64 of_translate_address(struct device_node *np, const u32 *addr);
>  extern int of_address_to_resource(struct device_node *dev, int index,
>  				  struct resource *r);
>  extern void __iomem *of_iomap(struct device_node *device, int index);

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

* Re: [PATCH 4/5] of/address: little-endian fixes
  2010-06-08 14:10 ` [PATCH 4/5] of/address: little-endian fixes Grant Likely
@ 2010-06-10  6:43   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-10  6:43 UTC (permalink / raw)
  To: Grant Likely
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> Fix some endian issues in the OF address translation code.
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> CC: Michal Simek <monstr@monstr.eu>
> CC: Wolfram Sang <w.sang@pengutronix.de>
> CC: Stephen Rothwell <sfr@canb.auug.org.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> CC: microblaze-uclinux@itee.uq.edu.au
> CC: linuxppc-dev@ozlabs.org
> ---
>  drivers/of/address.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 2a905d5..0b04137 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -22,7 +22,7 @@ static void of_dump_addr(const char *s, const u32 *addr, int na)
>  {
>  	printk(KERN_DEBUG "%s", s);
>  	while (na--)
> -		printk(" %08x", *(addr++));
> +		printk(" %08x", be32_to_cpu(*(addr++)));
>  	printk("\n");
>  }
>  #else
> @@ -79,8 +79,8 @@ static int of_bus_default_translate(u32 *addr, u64 offset, int na)
>  	memset(addr, 0, na * 4);
>  	a += offset;
>  	if (na > 1)
> -		addr[na - 2] = a >> 32;
> -	addr[na - 1] = a & 0xffffffffu;
> +		addr[na - 2] = cpu_to_be32(a >> 32);
> +	addr[na - 1] = cpu_to_be32(a & 0xffffffffu);
>  
>  	return 0;
>  }
> @@ -190,14 +190,16 @@ const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
>  	psize /= 4;
>  
>  	onesize = na + ns;
> -	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
> -		if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
> +	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {
> +		u32 val = be32_to_cpu(prop[0]);
> +		if ((val & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
>  			if (size)
>  				*size = of_read_number(prop + na, ns);
>  			if (flags)
>  				*flags = bus->get_flags(prop);
>  			return prop;
>  		}
> +	}
>  	return NULL;
>  }
>  EXPORT_SYMBOL(of_get_pci_address);

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
  2010-06-08 14:10   ` Grant Likely
@ 2010-06-10  6:44     ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-10  6:44 UTC (permalink / raw)
  To: Grant Likely
  Cc: Stephen Rothwell, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> Certain Apple machines don't use the ranges property correctly, but the
> workaround should not be applied on other architectures.  This patch
> disables the workaround for non-powerpc architectures.

I'm half tempted to add it to the quirk list (which should really be
made generic) so I can disable it on more 'modern' powerpc as well.

Cheers,
Ben.

> Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> CC: Stephen Rothwell <sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>
> CC: Benjamin Herrenschmidt <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
> CC: linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> CC: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> ---
>  drivers/of/address.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 0b04137..5c220c3 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
>  	 * a 1:1 translation at that level. It's up to the caller not to try
>  	 * to translate addresses that aren't supposed to be translated in
>  	 * the first place. --BenH.
> +	 *
> +	 * As far as we know, this damage only exists on Apple machines, so
> +	 * This code is only enabled on powerpc. --gcl
>  	 */
>  	ranges = of_get_property(parent, rprop, &rlen);
> +#if !defined(CONFIG_PPC)
> +	if (ranges == NULL) {
> +		pr_err("OF: no ranges; cannot translate\n");
> +		return 1;
> +	}
> +#endif /* !defined(CONFIG_PPC) */
>  	if (ranges == NULL || rlen == 0) {
>  		offset = of_read_number(addr, na);
>  		memset(addr, 0, pna * 4);
> -		pr_debug("OF: no ranges, 1:1 translation\n");
> +		pr_debug("OF: empty ranges; 1:1 translation\n");
>  		goto finish;
>  	}
>  

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
@ 2010-06-10  6:44     ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-10  6:44 UTC (permalink / raw)
  To: Grant Likely; +Cc: Stephen Rothwell, devicetree-discuss, linuxppc-dev

On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> Certain Apple machines don't use the ranges property correctly, but the
> workaround should not be applied on other architectures.  This patch
> disables the workaround for non-powerpc architectures.

I'm half tempted to add it to the quirk list (which should really be
made generic) so I can disable it on more 'modern' powerpc as well.

Cheers,
Ben.

> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> CC: Stephen Rothwell <sfr@canb.auug.org.au>
> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> CC: linuxppc-dev@lists.ozlabs.org
> CC: devicetree-discuss@lists.ozlabs.org
> ---
>  drivers/of/address.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 0b04137..5c220c3 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
>  	 * a 1:1 translation at that level. It's up to the caller not to try
>  	 * to translate addresses that aren't supposed to be translated in
>  	 * the first place. --BenH.
> +	 *
> +	 * As far as we know, this damage only exists on Apple machines, so
> +	 * This code is only enabled on powerpc. --gcl
>  	 */
>  	ranges = of_get_property(parent, rprop, &rlen);
> +#if !defined(CONFIG_PPC)
> +	if (ranges == NULL) {
> +		pr_err("OF: no ranges; cannot translate\n");
> +		return 1;
> +	}
> +#endif /* !defined(CONFIG_PPC) */
>  	if (ranges == NULL || rlen == 0) {
>  		offset = of_read_number(addr, na);
>  		memset(addr, 0, pna * 4);
> -		pr_debug("OF: no ranges, 1:1 translation\n");
> +		pr_debug("OF: empty ranges; 1:1 translation\n");
>  		goto finish;
>  	}
>  

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

* Re: [PATCH 3/5] of/address: Merge all of the bus translation code
  2010-06-10  6:43   ` Benjamin Herrenschmidt
@ 2010-06-10 14:26     ` Grant Likely
  2010-06-21 21:06       ` Grant Likely
  0 siblings, 1 reply; 24+ messages in thread
From: Grant Likely @ 2010-06-10 14:26 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Thu, Jun 10, 2010 at 12:43 AM, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
> On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
>> Microblaze and PowerPC share a large chunk of code for translating
>> OF device tree data into usable addresses. =A0There aren't many differen=
ces
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^^^^
> Care to comment on these differences ?

Purely cosmetic IIRC, but I will go back and double check.  Things
like printk vs. pr_info and some style differences.  I looked at them
side-by-side and fixed each difference individually until they were
identical.

>> between the two, so merge the codebase wholesale rather than trying to
>> work out the independent bits.
>
> Well, I don't see ifdef's in the resulting code (but I'm a bit blind),
> so what did you do with the differences ?
>
> This is complex and fragile code, so any change to it must be very
> carefully scrutinized.
>
> Cheers,
> Ben.
>
>> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
>> CC: Michal Simek <monstr@monstr.eu>
>> CC: Wolfram Sang <w.sang@pengutronix.de>
>> CC: Stephen Rothwell <sfr@canb.auug.org.au>
>> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>> CC: microblaze-uclinux@itee.uq.edu.au
>> CC: linuxppc-dev@ozlabs.org
>> ---
>> =A0arch/microblaze/include/asm/prom.h =A0| =A0 =A04
>> =A0arch/microblaze/kernel/prom_parse.c | =A0489 ------------------------=
---------
>> =A0arch/powerpc/include/asm/prom.h =A0 =A0 | =A0 =A04
>> =A0arch/powerpc/kernel/prom_parse.c =A0 =A0| =A0515 --------------------=
---------------
>> =A0drivers/of/address.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0517 ++++++++=
+++++++++++++++++++++++++++
>> =A0include/linux/of_address.h =A0 =A0 =A0 =A0 =A0| =A0 =A04
>> =A06 files changed, 515 insertions(+), 1018 deletions(-)
>>
>> diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/includ=
e/asm/prom.h
>> index 644fa32..35cb3de 100644
>> --- a/arch/microblaze/include/asm/prom.h
>> +++ b/arch/microblaze/include/asm/prom.h
>> @@ -52,10 +52,6 @@ extern void pci_create_OF_bus_map(void);
>> =A0 * OF address retreival & translation
>> =A0 */
>>
>> -/* Translate an OF address block into a CPU physical address
>> - */
>> -extern u64 of_translate_address(struct device_node *np, const u32 *addr=
);
>> -
>> =A0/* Extract an address from a device, returns the region size and
>> =A0 * the address space flags too. The PCI version uses a BAR number
>> =A0 * instead of an absolute index
>> diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kerne=
l/prom_parse.c
>> index 7cb5a98..1d610e6 100644
>> --- a/arch/microblaze/kernel/prom_parse.c
>> +++ b/arch/microblaze/kernel/prom_parse.c
>> @@ -10,213 +10,7 @@
>> =A0#include <asm/prom.h>
>> =A0#include <asm/pci-bridge.h>
>>
>> -#define PRu64 =A0 =A0 =A0 =A0"%llx"
>> -
>> -/* Max address size we deal with */
>> -#define OF_MAX_ADDR_CELLS =A0 =A04
>> -#define OF_CHECK_COUNTS(na, ns) =A0 =A0 =A0((na) > 0 && (na) <=3D OF_MA=
X_ADDR_CELLS && \
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (ns) > 0)
>> -
>> -static struct of_bus *of_match_bus(struct device_node *np);
>> -
>> -/* Debug utility */
>> -#ifdef DEBUG
>> -static void of_dump_addr(const char *s, const u32 *addr, int na)
>> -{
>> - =A0 =A0 printk(KERN_INFO "%s", s);
>> - =A0 =A0 while (na--)
>> - =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO " %08x", *(addr++));
>> - =A0 =A0 printk(KERN_INFO "\n");
>> -}
>> -#else
>> -static void of_dump_addr(const char *s, const u32 *addr, int na) { }
>> -#endif
>> -
>> -/* Callbacks for bus specific translators */
>> -struct of_bus {
>> - =A0 =A0 const char =A0 =A0 =A0*name;
>> - =A0 =A0 const char =A0 =A0 =A0*addresses;
>> - =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*match)(struct device_node *paren=
t);
>> - =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0(*count_cells)(struct device_node =
*child,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 int *addrc, int *sizec);
>> - =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 (*map)(u32 *addr, const u32 *range=
,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns=
, int pna);
>> - =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*translate)(u32 *addr, u64 offset=
, int na);
>> - =A0 =A0 unsigned int =A0 =A0(*get_flags)(const u32 *addr);
>> -};
>> -
>> -/*
>> - * Default translator (generic bus)
>> - */
>> -
>> -static void of_bus_default_count_cells(struct device_node *dev,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 int *addrc, int *sizec)
>> -{
>> - =A0 =A0 if (addrc)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D of_n_addr_cells(dev);
>> - =A0 =A0 if (sizec)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D of_n_size_cells(dev);
>> -}
>> -
>> -static u64 of_bus_default_map(u32 *addr, const u32 *range,
>> - =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pna)
>> -{
>> - =A0 =A0 u64 cp, s, da;
>> -
>> - =A0 =A0 cp =3D of_read_number(range, na);
>> - =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> - =A0 =A0 da =3D of_read_number(addr, na);
>> -
>> - =A0 =A0 pr_debug("OF: default map, cp=3D"PRu64", s=3D"PRu64", da=3D"PR=
u64"\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 cp, s, da);
>> -
>> - =A0 =A0 if (da < cp || da >=3D (cp + s))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> - =A0 =A0 return da - cp;
>> -}
>> -
>> -static int of_bus_default_translate(u32 *addr, u64 offset, int na)
>> -{
>> - =A0 =A0 u64 a =3D of_read_number(addr, na);
>> - =A0 =A0 memset(addr, 0, na * 4);
>> - =A0 =A0 a +=3D offset;
>> - =A0 =A0 if (na > 1)
>> - =A0 =A0 =A0 =A0 =A0 =A0 addr[na - 2] =3D a >> 32;
>> - =A0 =A0 addr[na - 1] =3D a & 0xffffffffu;
>> -
>> - =A0 =A0 return 0;
>> -}
>> -
>> -static unsigned int of_bus_default_get_flags(const u32 *addr)
>> -{
>> - =A0 =A0 return IORESOURCE_MEM;
>> -}
>> -
>> =A0#ifdef CONFIG_PCI
>> -/*
>> - * PCI bus specific translator
>> - */
>> -
>> -static int of_bus_pci_match(struct device_node *np)
>> -{
>> - =A0 =A0 /* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
>> - =A0 =A0 return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
>> -}
>> -
>> -static void of_bus_pci_count_cells(struct device_node *np,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int *addrc, in=
t *sizec)
>> -{
>> - =A0 =A0 if (addrc)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D 3;
>> - =A0 =A0 if (sizec)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D 2;
>> -}
>> -
>> -static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
>> -{
>> - =A0 =A0 u64 cp, s, da;
>> -
>> - =A0 =A0 /* Check address type match */
>> - =A0 =A0 if ((addr[0] ^ range[0]) & 0x03000000)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> -
>> - =A0 =A0 /* Read address values, skipping high cell */
>> - =A0 =A0 cp =3D of_read_number(range + 1, na - 1);
>> - =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> - =A0 =A0 da =3D of_read_number(addr + 1, na - 1);
>> -
>> - =A0 =A0 pr_debug("OF: PCI map, cp=3D"PRu64", s=3D"PRu64", da=3D"PRu64"=
\n", cp, s, da);
>> -
>> - =A0 =A0 if (da < cp || da >=3D (cp + s))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> - =A0 =A0 return da - cp;
>> -}
>> -
>> -static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
>> -{
>> - =A0 =A0 return of_bus_default_translate(addr + 1, offset, na - 1);
>> -}
>> -
>> -static unsigned int of_bus_pci_get_flags(const u32 *addr)
>> -{
>> - =A0 =A0 unsigned int flags =3D 0;
>> - =A0 =A0 u32 w =3D addr[0];
>> -
>> - =A0 =A0 switch ((w >> 24) & 0x03) {
>> - =A0 =A0 case 0x01:
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_IO;
>> - =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 case 0x02: /* 32 bits */
>> - =A0 =A0 case 0x03: /* 64 bits */
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_MEM;
>> - =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 }
>> - =A0 =A0 if (w & 0x40000000)
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_PREFETCH;
>> - =A0 =A0 return flags;
>> -}
>> -
>> -const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 =
*size,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
>> -{
>> - =A0 =A0 const u32 *prop;
>> - =A0 =A0 unsigned int psize;
>> - =A0 =A0 struct device_node *parent;
>> - =A0 =A0 struct of_bus *bus;
>> - =A0 =A0 int onesize, i, na, ns;
>> -
>> - =A0 =A0 /* Get parent & match bus type */
>> - =A0 =A0 parent =3D of_get_parent(dev);
>> - =A0 =A0 if (parent =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 bus =3D of_match_bus(parent);
>> - =A0 =A0 if (strcmp(bus->name, "pci")) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(parent);
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 }
>> - =A0 =A0 bus->count_cells(dev, &na, &ns);
>> - =A0 =A0 of_node_put(parent);
>> - =A0 =A0 if (!OF_CHECK_COUNTS(na, ns))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> -
>> - =A0 =A0 /* Get "reg" or "assigned-addresses" property */
>> - =A0 =A0 prop =3D of_get_property(dev, bus->addresses, &psize);
>> - =A0 =A0 if (prop =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 psize /=3D 4;
>> -
>> - =A0 =A0 onesize =3D na + ns;
>> - =A0 =A0 for (i =3D 0; psize >=3D onesize; psize -=3D onesize, prop +=
=3D onesize, i++)
>> - =A0 =A0 =A0 =A0 =A0 =A0 if ((prop[0] & 0xff) =3D=3D ((bar_no * 4) + PC=
I_BASE_ADDRESS_0)) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *size =3D of_r=
ead_number(prop + na, ns);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (flags)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *flags =3D bus=
->get_flags(prop);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> - =A0 =A0 return NULL;
>> -}
>> -EXPORT_SYMBOL(of_get_pci_address);
>> -
>> -int of_pci_address_to_resource(struct device_node *dev, int bar,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct resourc=
e *r)
>> -{
>> - =A0 =A0 const u32 =A0 =A0 =A0 *addrp;
>> - =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 size;
>> - =A0 =A0 unsigned int =A0 =A0flags;
>> -
>> - =A0 =A0 addrp =3D of_get_pci_address(dev, bar, &size, &flags);
>> - =A0 =A0 if (addrp =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
>> - =A0 =A0 return __of_address_to_resource(dev, addrp, size, flags, r);
>> -}
>> -EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
>> -
>> -static u8 of_irq_pci_swizzle(u8 slot, u8 pin)
>> -{
>> - =A0 =A0 return (((pin - 1) + slot) % 4) + 1;
>> -}
>> -
>> =A0int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
>> =A0{
>> =A0 =A0 =A0 struct device_node *dn, *ppnode;
>> @@ -291,289 +85,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_=
irq *out_irq)
>> =A0EXPORT_SYMBOL_GPL(of_irq_map_pci);
>> =A0#endif /* CONFIG_PCI */
>>
>> -/*
>> - * ISA bus specific translator
>> - */
>> -
>> -static int of_bus_isa_match(struct device_node *np)
>> -{
>> - =A0 =A0 return !strcmp(np->name, "isa");
>> -}
>> -
>> -static void of_bus_isa_count_cells(struct device_node *child,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int *addrc, in=
t *sizec)
>> -{
>> - =A0 =A0 if (addrc)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D 2;
>> - =A0 =A0 if (sizec)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D 1;
>> -}
>> -
>> -static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
>> -{
>> - =A0 =A0 u64 cp, s, da;
>> -
>> - =A0 =A0 /* Check address type match */
>> - =A0 =A0 if ((addr[0] ^ range[0]) & 0x00000001)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> -
>> - =A0 =A0 /* Read address values, skipping high cell */
>> - =A0 =A0 cp =3D of_read_number(range + 1, na - 1);
>> - =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> - =A0 =A0 da =3D of_read_number(addr + 1, na - 1);
>> -
>> - =A0 =A0 pr_debug("OF: ISA map, cp=3D"PRu64", s=3D"PRu64", da=3D"PRu64"=
\n", cp, s, da);
>> -
>> - =A0 =A0 if (da < cp || da >=3D (cp + s))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> - =A0 =A0 return da - cp;
>> -}
>> -
>> -static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
>> -{
>> - =A0 =A0 return of_bus_default_translate(addr + 1, offset, na - 1);
>> -}
>> -
>> -static unsigned int of_bus_isa_get_flags(const u32 *addr)
>> -{
>> - =A0 =A0 unsigned int flags =3D 0;
>> - =A0 =A0 u32 w =3D addr[0];
>> -
>> - =A0 =A0 if (w & 1)
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_IO;
>> - =A0 =A0 else
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_MEM;
>> - =A0 =A0 return flags;
>> -}
>> -
>> -/*
>> - * Array of bus specific translators
>> - */
>> -
>> -static struct of_bus of_busses[] =3D {
>> -#ifdef CONFIG_PCI
>> - =A0 =A0 /* PCI */
>> - =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "pci",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "assigned-addresses",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .match =3D of_bus_pci_match,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_pci_count_cells,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_pci_map,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_pci_translate,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_pci_get_flags,
>> - =A0 =A0 },
>> -#endif /* CONFIG_PCI */
>> - =A0 =A0 /* ISA */
>> - =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "isa",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "reg",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .match =3D of_bus_isa_match,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_isa_count_cells,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_isa_map,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_isa_translate,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_isa_get_flags,
>> - =A0 =A0 },
>> - =A0 =A0 /* Default */
>> - =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "default",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "reg",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .match =3D NULL,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_default_count_cells,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_default_map,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_default_translate,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_default_get_flags,
>> - =A0 =A0 },
>> -};
>> -
>> -static struct of_bus *of_match_bus(struct device_node *np)
>> -{
>> - =A0 =A0 int i;
>> -
>> - =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(of_busses); i++)
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (!of_busses[i].match || of_busses[i].match(=
np))
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return &of_busses[i];
>> - =A0 =A0 BUG();
>> - =A0 =A0 return NULL;
>> -}
>> -
>> -static int of_translate_one(struct device_node *parent, struct of_bus *=
bus,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct of_bus *pbus, u32 *addr=
,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pna)
>> -{
>> - =A0 =A0 const u32 *ranges;
>> - =A0 =A0 unsigned int rlen;
>> - =A0 =A0 int rone;
>> - =A0 =A0 u64 offset =3D OF_BAD_ADDR;
>> -
>> - =A0 =A0 /* Normally, an absence of a "ranges" property means we are
>> - =A0 =A0 =A0* crossing a non-translatable boundary, and thus the addres=
ses
>> - =A0 =A0 =A0* below the current not cannot be converted to CPU physical=
 ones.
>> - =A0 =A0 =A0* Unfortunately, while this is very clear in the spec, it's=
 not
>> - =A0 =A0 =A0* what Apple understood, and they do have things like /uni-=
n or
>> - =A0 =A0 =A0* /ht nodes with no "ranges" property and a lot of perfectl=
y
>> - =A0 =A0 =A0* useable mapped devices below them. Thus we treat the abse=
nce of
>> - =A0 =A0 =A0* "ranges" as equivalent to an empty "ranges" property whic=
h means
>> - =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller no=
t to try
>> - =A0 =A0 =A0* to translate addresses that aren't supposed to be transla=
ted in
>> - =A0 =A0 =A0* the first place. --BenH.
>> - =A0 =A0 =A0*/
>> - =A0 =A0 ranges =3D of_get_property(parent, "ranges", (int *) &rlen);
>> - =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 offset =3D of_read_number(addr, na);
>> - =A0 =A0 =A0 =A0 =A0 =A0 memset(addr, 0, pna * 4);
>> - =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: no ranges, 1:1 translation\n");
>> - =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
>> - =A0 =A0 }
>> -
>> - =A0 =A0 pr_debug("OF: walking ranges...\n");
>> -
>> - =A0 =A0 /* Now walk through the ranges */
>> - =A0 =A0 rlen /=3D 4;
>> - =A0 =A0 rone =3D na + pna + ns;
>> - =A0 =A0 for (; rlen >=3D rone; rlen -=3D rone, ranges +=3D rone) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 offset =3D bus->map(addr, ranges, na, ns, pna)=
;
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (offset !=3D OF_BAD_ADDR)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 }
>> - =A0 =A0 if (offset =3D=3D OF_BAD_ADDR) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: not found !\n");
>> - =A0 =A0 =A0 =A0 =A0 =A0 return 1;
>> - =A0 =A0 }
>> - =A0 =A0 memcpy(addr, ranges + na, 4 * pna);
>> -
>> - finish:
>> - =A0 =A0 of_dump_addr("OF: parent translation for:", addr, pna);
>> - =A0 =A0 pr_debug("OF: with offset: "PRu64"\n", offset);
>> -
>> - =A0 =A0 /* Translate it into parent bus space */
>> - =A0 =A0 return pbus->translate(addr, offset, pna);
>> -}
>> -
>> -/*
>> - * Translate an address from the device-tree into a CPU physical addres=
s,
>> - * this walks up the tree and applies the various bus mappings on the
>> - * way.
>> - *
>> - * Note: We consider that crossing any level with #size-cells =3D=3D 0 =
to mean
>> - * that translation is impossible (that is we are not dealing with a va=
lue
>> - * that can be mapped to a cpu physical address). This is not really sp=
ecified
>> - * that way, but this is traditionally the way IBM at least do things
>> - */
>> -u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
>> -{
>> - =A0 =A0 struct device_node *parent =3D NULL;
>> - =A0 =A0 struct of_bus *bus, *pbus;
>> - =A0 =A0 u32 addr[OF_MAX_ADDR_CELLS];
>> - =A0 =A0 int na, ns, pna, pns;
>> - =A0 =A0 u64 result =3D OF_BAD_ADDR;
>> -
>> - =A0 =A0 pr_debug("OF: ** translation for device %s **\n", dev->full_na=
me);
>> -
>> - =A0 =A0 /* Increase refcount at current level */
>> - =A0 =A0 of_node_get(dev);
>> -
>> - =A0 =A0 /* Get parent & match bus type */
>> - =A0 =A0 parent =3D of_get_parent(dev);
>> - =A0 =A0 if (parent =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
>> - =A0 =A0 bus =3D of_match_bus(parent);
>> -
>> - =A0 =A0 /* Cound address cells & copy address locally */
>> - =A0 =A0 bus->count_cells(dev, &na, &ns);
>> - =A0 =A0 if (!OF_CHECK_COUNTS(na, ns)) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "prom_parse: Bad cell count fo=
r %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev->full_name);
>> - =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
>> - =A0 =A0 }
>> - =A0 =A0 memcpy(addr, in_addr, na * 4);
>> -
>> - =A0 =A0 pr_debug("OF: bus is %s (na=3D%d, ns=3D%d) on %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 bus->name, na, ns, parent->full_name);
>> - =A0 =A0 of_dump_addr("OF: translating address:", addr, na);
>> -
>> - =A0 =A0 /* Translate */
>> - =A0 =A0 for (;;) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Switch to parent bus */
>> - =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(dev);
>> - =A0 =A0 =A0 =A0 =A0 =A0 dev =3D parent;
>> - =A0 =A0 =A0 =A0 =A0 =A0 parent =3D of_get_parent(dev);
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* If root, we have finished */
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (parent =3D=3D NULL) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: reached root nod=
e\n");
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D of_read_number(addr=
, na);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Get new parent bus and counts */
>> - =A0 =A0 =A0 =A0 =A0 =A0 pbus =3D of_match_bus(parent);
>> - =A0 =A0 =A0 =A0 =A0 =A0 pbus->count_cells(dev, &pna, &pns);
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (!OF_CHECK_COUNTS(pna, pns)) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "prom_parse: B=
ad cell count for %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev->full_name=
);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: parent bus is %s (na=3D%d, ns=3D=
%d) on %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pbus->name, pna, pns, parent->=
full_name);
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Apply bus translation */
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (of_translate_one(dev, bus, pbus, addr, na,=
 ns, pna))
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Complete the move up one level */
>> - =A0 =A0 =A0 =A0 =A0 =A0 na =3D pna;
>> - =A0 =A0 =A0 =A0 =A0 =A0 ns =3D pns;
>> - =A0 =A0 =A0 =A0 =A0 =A0 bus =3D pbus;
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 of_dump_addr("OF: one level translation:", add=
r, na);
>> - =A0 =A0 }
>> - bail:
>> - =A0 =A0 of_node_put(parent);
>> - =A0 =A0 of_node_put(dev);
>> -
>> - =A0 =A0 return result;
>> -}
>> -EXPORT_SYMBOL(of_translate_address);
>> -
>> -const u32 *of_get_address(struct device_node *dev, int index, u64 *size=
,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
>> -{
>> - =A0 =A0 const u32 *prop;
>> - =A0 =A0 unsigned int psize;
>> - =A0 =A0 struct device_node *parent;
>> - =A0 =A0 struct of_bus *bus;
>> - =A0 =A0 int onesize, i, na, ns;
>> -
>> - =A0 =A0 /* Get parent & match bus type */
>> - =A0 =A0 parent =3D of_get_parent(dev);
>> - =A0 =A0 if (parent =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 bus =3D of_match_bus(parent);
>> - =A0 =A0 bus->count_cells(dev, &na, &ns);
>> - =A0 =A0 of_node_put(parent);
>> - =A0 =A0 if (!OF_CHECK_COUNTS(na, ns))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> -
>> - =A0 =A0 /* Get "reg" or "assigned-addresses" property */
>> - =A0 =A0 prop =3D of_get_property(dev, bus->addresses, (int *) &psize);
>> - =A0 =A0 if (prop =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 psize /=3D 4;
>> -
>> - =A0 =A0 onesize =3D na + ns;
>> - =A0 =A0 for (i =3D 0; psize >=3D onesize; psize -=3D onesize, prop +=
=3D onesize, i++)
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D index) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *size =3D of_r=
ead_number(prop + na, ns);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (flags)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *flags =3D bus=
->get_flags(prop);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> - =A0 =A0 return NULL;
>> -}
>> -EXPORT_SYMBOL(of_get_address);
>> -
>> =A0void of_parse_dma_window(struct device_node *dn, const void *dma_wind=
ow_prop,
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long *busno, unsigned long *phys, u=
nsigned long *size)
>> =A0{
>> diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/=
prom.h
>> index e1c1bdd..8e1d0fe 100644
>> --- a/arch/powerpc/include/asm/prom.h
>> +++ b/arch/powerpc/include/asm/prom.h
>> @@ -45,10 +45,6 @@ extern void pci_create_OF_bus_map(void);
>> =A0 * OF address retreival & translation
>> =A0 */
>>
>> -/* Translate an OF address block into a CPU physical address
>> - */
>> -extern u64 of_translate_address(struct device_node *np, const u32 *addr=
);
>> -
>> =A0/* Translate a DMA address from device space to CPU space */
>> =A0extern u64 of_translate_dma_address(struct device_node *dev,
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cons=
t u32 *in_addr);
>> diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom=
_parse.c
>> index a2ef129..64f2606 100644
>> --- a/arch/powerpc/kernel/prom_parse.c
>> +++ b/arch/powerpc/kernel/prom_parse.c
>> @@ -10,225 +10,7 @@
>> =A0#include <asm/prom.h>
>> =A0#include <asm/pci-bridge.h>
>>
>> -#ifdef DEBUG
>> -#define DBG(fmt...) do { printk(fmt); } while(0)
>> -#else
>> -#define DBG(fmt...) do { } while(0)
>> -#endif
>> -
>> -#ifdef CONFIG_PPC64
>> -#define PRu64 =A0 =A0 =A0 =A0"%lx"
>> -#else
>> -#define PRu64 =A0 =A0 =A0 =A0"%llx"
>> -#endif
>> -
>> -/* Max address size we deal with */
>> -#define OF_MAX_ADDR_CELLS =A0 =A04
>> -#define OF_CHECK_COUNTS(na, ns) =A0 =A0 =A0((na) > 0 && (na) <=3D OF_MA=
X_ADDR_CELLS && \
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (ns) > 0)
>> -
>> -static struct of_bus *of_match_bus(struct device_node *np);
>> -
>> -/* Debug utility */
>> -#ifdef DEBUG
>> -static void of_dump_addr(const char *s, const u32 *addr, int na)
>> -{
>> - =A0 =A0 printk("%s", s);
>> - =A0 =A0 while(na--)
>> - =A0 =A0 =A0 =A0 =A0 =A0 printk(" %08x", *(addr++));
>> - =A0 =A0 printk("\n");
>> -}
>> -#else
>> -static void of_dump_addr(const char *s, const u32 *addr, int na) { }
>> -#endif
>> -
>> -
>> -/* Callbacks for bus specific translators */
>> -struct of_bus {
>> - =A0 =A0 const char =A0 =A0 =A0*name;
>> - =A0 =A0 const char =A0 =A0 =A0*addresses;
>> - =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*match)(struct device_node *paren=
t);
>> - =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0(*count_cells)(struct device_node =
*child,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0int *addrc, int *sizec);
>> - =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 (*map)(u32 *addr, const u32 *range=
,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns=
, int pna);
>> - =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*translate)(u32 *addr, u64 offset=
, int na);
>> - =A0 =A0 unsigned int =A0 =A0(*get_flags)(const u32 *addr);
>> -};
>> -
>> -
>> -/*
>> - * Default translator (generic bus)
>> - */
>> -
>> -static void of_bus_default_count_cells(struct device_node *dev,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0int *addrc, int *sizec)
>> -{
>> - =A0 =A0 if (addrc)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D of_n_addr_cells(dev);
>> - =A0 =A0 if (sizec)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D of_n_size_cells(dev);
>> -}
>> -
>> -static u64 of_bus_default_map(u32 *addr, const u32 *range,
>> - =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pna)
>> -{
>> - =A0 =A0 u64 cp, s, da;
>> -
>> - =A0 =A0 cp =3D of_read_number(range, na);
>> - =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> - =A0 =A0 da =3D of_read_number(addr, na);
>> -
>> - =A0 =A0 DBG("OF: default map, cp=3D"PRu64", s=3D"PRu64", da=3D"PRu64"\=
n",
>> - =A0 =A0 =A0 =A0 cp, s, da);
>> -
>> - =A0 =A0 if (da < cp || da >=3D (cp + s))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> - =A0 =A0 return da - cp;
>> -}
>> -
>> -static int of_bus_default_translate(u32 *addr, u64 offset, int na)
>> -{
>> - =A0 =A0 u64 a =3D of_read_number(addr, na);
>> - =A0 =A0 memset(addr, 0, na * 4);
>> - =A0 =A0 a +=3D offset;
>> - =A0 =A0 if (na > 1)
>> - =A0 =A0 =A0 =A0 =A0 =A0 addr[na - 2] =3D a >> 32;
>> - =A0 =A0 addr[na - 1] =3D a & 0xffffffffu;
>> -
>> - =A0 =A0 return 0;
>> -}
>> -
>> -static unsigned int of_bus_default_get_flags(const u32 *addr)
>> -{
>> - =A0 =A0 return IORESOURCE_MEM;
>> -}
>> -
>> -
>> =A0#ifdef CONFIG_PCI
>> -/*
>> - * PCI bus specific translator
>> - */
>> -
>> -static int of_bus_pci_match(struct device_node *np)
>> -{
>> - =A0 =A0 /* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
>> - =A0 =A0 return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
>> -}
>> -
>> -static void of_bus_pci_count_cells(struct device_node *np,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int *ad=
drc, int *sizec)
>> -{
>> - =A0 =A0 if (addrc)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D 3;
>> - =A0 =A0 if (sizec)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D 2;
>> -}
>> -
>> -static unsigned int of_bus_pci_get_flags(const u32 *addr)
>> -{
>> - =A0 =A0 unsigned int flags =3D 0;
>> - =A0 =A0 u32 w =3D addr[0];
>> -
>> - =A0 =A0 switch((w >> 24) & 0x03) {
>> - =A0 =A0 case 0x01:
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_IO;
>> - =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 case 0x02: /* 32 bits */
>> - =A0 =A0 case 0x03: /* 64 bits */
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_MEM;
>> - =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 }
>> - =A0 =A0 if (w & 0x40000000)
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_PREFETCH;
>> - =A0 =A0 return flags;
>> -}
>> -
>> -static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
>> -{
>> - =A0 =A0 u64 cp, s, da;
>> - =A0 =A0 unsigned int af, rf;
>> -
>> - =A0 =A0 af =3D of_bus_pci_get_flags(addr);
>> - =A0 =A0 rf =3D of_bus_pci_get_flags(range);
>> -
>> - =A0 =A0 /* Check address type match */
>> - =A0 =A0 if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> -
>> - =A0 =A0 /* Read address values, skipping high cell */
>> - =A0 =A0 cp =3D of_read_number(range + 1, na - 1);
>> - =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> - =A0 =A0 da =3D of_read_number(addr + 1, na - 1);
>> -
>> - =A0 =A0 DBG("OF: PCI map, cp=3D"PRu64", s=3D"PRu64", da=3D"PRu64"\n", =
cp, s, da);
>> -
>> - =A0 =A0 if (da < cp || da >=3D (cp + s))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> - =A0 =A0 return da - cp;
>> -}
>> -
>> -static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
>> -{
>> - =A0 =A0 return of_bus_default_translate(addr + 1, offset, na - 1);
>> -}
>> -
>> -const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 =
*size,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
>> -{
>> - =A0 =A0 const u32 *prop;
>> - =A0 =A0 unsigned int psize;
>> - =A0 =A0 struct device_node *parent;
>> - =A0 =A0 struct of_bus *bus;
>> - =A0 =A0 int onesize, i, na, ns;
>> -
>> - =A0 =A0 /* Get parent & match bus type */
>> - =A0 =A0 parent =3D of_get_parent(dev);
>> - =A0 =A0 if (parent =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 bus =3D of_match_bus(parent);
>> - =A0 =A0 if (strcmp(bus->name, "pci")) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(parent);
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 }
>> - =A0 =A0 bus->count_cells(dev, &na, &ns);
>> - =A0 =A0 of_node_put(parent);
>> - =A0 =A0 if (!OF_CHECK_COUNTS(na, ns))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> -
>> - =A0 =A0 /* Get "reg" or "assigned-addresses" property */
>> - =A0 =A0 prop =3D of_get_property(dev, bus->addresses, &psize);
>> - =A0 =A0 if (prop =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 psize /=3D 4;
>> -
>> - =A0 =A0 onesize =3D na + ns;
>> - =A0 =A0 for (i =3D 0; psize >=3D onesize; psize -=3D onesize, prop +=
=3D onesize, i++)
>> - =A0 =A0 =A0 =A0 =A0 =A0 if ((prop[0] & 0xff) =3D=3D ((bar_no * 4) + PC=
I_BASE_ADDRESS_0)) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *size =3D of_r=
ead_number(prop + na, ns);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (flags)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *flags =3D bus=
->get_flags(prop);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> - =A0 =A0 return NULL;
>> -}
>> -EXPORT_SYMBOL(of_get_pci_address);
>> -
>> -int of_pci_address_to_resource(struct device_node *dev, int bar,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct resource=
 *r)
>> -{
>> - =A0 =A0 const u32 =A0 =A0 =A0 *addrp;
>> - =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 size;
>> - =A0 =A0 unsigned int =A0 =A0flags;
>> -
>> - =A0 =A0 addrp =3D of_get_pci_address(dev, bar, &size, &flags);
>> - =A0 =A0 if (addrp =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
>> - =A0 =A0 return __of_address_to_resource(dev, addrp, size, flags, r);
>> -}
>> -EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
>> -
>> =A0int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
>> =A0{
>> =A0 =A0 =A0 struct device_node *dn, *ppnode;
>> @@ -310,303 +92,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_=
irq *out_irq)
>> =A0EXPORT_SYMBOL_GPL(of_irq_map_pci);
>> =A0#endif /* CONFIG_PCI */
>>
>> -/*
>> - * ISA bus specific translator
>> - */
>> -
>> -static int of_bus_isa_match(struct device_node *np)
>> -{
>> - =A0 =A0 return !strcmp(np->name, "isa");
>> -}
>> -
>> -static void of_bus_isa_count_cells(struct device_node *child,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int *ad=
drc, int *sizec)
>> -{
>> - =A0 =A0 if (addrc)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D 2;
>> - =A0 =A0 if (sizec)
>> - =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D 1;
>> -}
>> -
>> -static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
>> -{
>> - =A0 =A0 u64 cp, s, da;
>> -
>> - =A0 =A0 /* Check address type match */
>> - =A0 =A0 if ((addr[0] ^ range[0]) & 0x00000001)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> -
>> - =A0 =A0 /* Read address values, skipping high cell */
>> - =A0 =A0 cp =3D of_read_number(range + 1, na - 1);
>> - =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> - =A0 =A0 da =3D of_read_number(addr + 1, na - 1);
>> -
>> - =A0 =A0 DBG("OF: ISA map, cp=3D"PRu64", s=3D"PRu64", da=3D"PRu64"\n", =
cp, s, da);
>> -
>> - =A0 =A0 if (da < cp || da >=3D (cp + s))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> - =A0 =A0 return da - cp;
>> -}
>> -
>> -static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
>> -{
>> - =A0 =A0 return of_bus_default_translate(addr + 1, offset, na - 1);
>> -}
>> -
>> -static unsigned int of_bus_isa_get_flags(const u32 *addr)
>> -{
>> - =A0 =A0 unsigned int flags =3D 0;
>> - =A0 =A0 u32 w =3D addr[0];
>> -
>> - =A0 =A0 if (w & 1)
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_IO;
>> - =A0 =A0 else
>> - =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_MEM;
>> - =A0 =A0 return flags;
>> -}
>> -
>> -
>> -/*
>> - * Array of bus specific translators
>> - */
>> -
>> -static struct of_bus of_busses[] =3D {
>> -#ifdef CONFIG_PCI
>> - =A0 =A0 /* PCI */
>> - =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "pci",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "assigned-addresses",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .match =3D of_bus_pci_match,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_pci_count_cells,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_pci_map,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_pci_translate,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_pci_get_flags,
>> - =A0 =A0 },
>> -#endif /* CONFIG_PCI */
>> - =A0 =A0 /* ISA */
>> - =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "isa",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "reg",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .match =3D of_bus_isa_match,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_isa_count_cells,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_isa_map,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_isa_translate,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_isa_get_flags,
>> - =A0 =A0 },
>> - =A0 =A0 /* Default */
>> - =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "default",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "reg",
>> - =A0 =A0 =A0 =A0 =A0 =A0 .match =3D NULL,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_default_count_cells,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_default_map,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_default_translate,
>> - =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_default_get_flags,
>> - =A0 =A0 },
>> -};
>> -
>> -static struct of_bus *of_match_bus(struct device_node *np)
>> -{
>> - =A0 =A0 int i;
>> -
>> - =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(of_busses); i ++)
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (!of_busses[i].match || of_busses[i].match(=
np))
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return &of_busses[i];
>> - =A0 =A0 BUG();
>> - =A0 =A0 return NULL;
>> -}
>> -
>> -static int of_translate_one(struct device_node *parent, struct of_bus *=
bus,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct of_bus *pbus, u=
32 *addr,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pn=
a, const char *rprop)
>> -{
>> - =A0 =A0 const u32 *ranges;
>> - =A0 =A0 unsigned int rlen;
>> - =A0 =A0 int rone;
>> - =A0 =A0 u64 offset =3D OF_BAD_ADDR;
>> -
>> - =A0 =A0 /* Normally, an absence of a "ranges" property means we are
>> - =A0 =A0 =A0* crossing a non-translatable boundary, and thus the addres=
ses
>> - =A0 =A0 =A0* below the current not cannot be converted to CPU physical=
 ones.
>> - =A0 =A0 =A0* Unfortunately, while this is very clear in the spec, it's=
 not
>> - =A0 =A0 =A0* what Apple understood, and they do have things like /uni-=
n or
>> - =A0 =A0 =A0* /ht nodes with no "ranges" property and a lot of perfectl=
y
>> - =A0 =A0 =A0* useable mapped devices below them. Thus we treat the abse=
nce of
>> - =A0 =A0 =A0* "ranges" as equivalent to an empty "ranges" property whic=
h means
>> - =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller no=
t to try
>> - =A0 =A0 =A0* to translate addresses that aren't supposed to be transla=
ted in
>> - =A0 =A0 =A0* the first place. --BenH.
>> - =A0 =A0 =A0*/
>> - =A0 =A0 ranges =3D of_get_property(parent, rprop, &rlen);
>> - =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 offset =3D of_read_number(addr, na);
>> - =A0 =A0 =A0 =A0 =A0 =A0 memset(addr, 0, pna * 4);
>> - =A0 =A0 =A0 =A0 =A0 =A0 DBG("OF: no ranges, 1:1 translation\n");
>> - =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
>> - =A0 =A0 }
>> -
>> - =A0 =A0 DBG("OF: walking ranges...\n");
>> -
>> - =A0 =A0 /* Now walk through the ranges */
>> - =A0 =A0 rlen /=3D 4;
>> - =A0 =A0 rone =3D na + pna + ns;
>> - =A0 =A0 for (; rlen >=3D rone; rlen -=3D rone, ranges +=3D rone) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 offset =3D bus->map(addr, ranges, na, ns, pna)=
;
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (offset !=3D OF_BAD_ADDR)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 }
>> - =A0 =A0 if (offset =3D=3D OF_BAD_ADDR) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 DBG("OF: not found !\n");
>> - =A0 =A0 =A0 =A0 =A0 =A0 return 1;
>> - =A0 =A0 }
>> - =A0 =A0 memcpy(addr, ranges + na, 4 * pna);
>> -
>> - finish:
>> - =A0 =A0 of_dump_addr("OF: parent translation for:", addr, pna);
>> - =A0 =A0 DBG("OF: with offset: "PRu64"\n", offset);
>> -
>> - =A0 =A0 /* Translate it into parent bus space */
>> - =A0 =A0 return pbus->translate(addr, offset, pna);
>> -}
>> -
>> -
>> -/*
>> - * Translate an address from the device-tree into a CPU physical addres=
s,
>> - * this walks up the tree and applies the various bus mappings on the
>> - * way.
>> - *
>> - * Note: We consider that crossing any level with #size-cells =3D=3D 0 =
to mean
>> - * that translation is impossible (that is we are not dealing with a va=
lue
>> - * that can be mapped to a cpu physical address). This is not really sp=
ecified
>> - * that way, but this is traditionally the way IBM at least do things
>> - */
>> -u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const char *rprop)
>> -{
>> - =A0 =A0 struct device_node *parent =3D NULL;
>> - =A0 =A0 struct of_bus *bus, *pbus;
>> - =A0 =A0 u32 addr[OF_MAX_ADDR_CELLS];
>> - =A0 =A0 int na, ns, pna, pns;
>> - =A0 =A0 u64 result =3D OF_BAD_ADDR;
>> -
>> - =A0 =A0 DBG("OF: ** translation for device %s **\n", dev->full_name);
>> -
>> - =A0 =A0 /* Increase refcount at current level */
>> - =A0 =A0 of_node_get(dev);
>> -
>> - =A0 =A0 /* Get parent & match bus type */
>> - =A0 =A0 parent =3D of_get_parent(dev);
>> - =A0 =A0 if (parent =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
>> - =A0 =A0 bus =3D of_match_bus(parent);
>> -
>> - =A0 =A0 /* Cound address cells & copy address locally */
>> - =A0 =A0 bus->count_cells(dev, &na, &ns);
>> - =A0 =A0 if (!OF_CHECK_COUNTS(na, ns)) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "prom_parse: Bad cell count fo=
r %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name);
>> - =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
>> - =A0 =A0 }
>> - =A0 =A0 memcpy(addr, in_addr, na * 4);
>> -
>> - =A0 =A0 DBG("OF: bus is %s (na=3D%d, ns=3D%d) on %s\n",
>> - =A0 =A0 =A0 =A0 bus->name, na, ns, parent->full_name);
>> - =A0 =A0 of_dump_addr("OF: translating address:", addr, na);
>> -
>> - =A0 =A0 /* Translate */
>> - =A0 =A0 for (;;) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Switch to parent bus */
>> - =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(dev);
>> - =A0 =A0 =A0 =A0 =A0 =A0 dev =3D parent;
>> - =A0 =A0 =A0 =A0 =A0 =A0 parent =3D of_get_parent(dev);
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* If root, we have finished */
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (parent =3D=3D NULL) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DBG("OF: reached root node\n")=
;
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D of_read_number(addr=
, na);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Get new parent bus and counts */
>> - =A0 =A0 =A0 =A0 =A0 =A0 pbus =3D of_match_bus(parent);
>> - =A0 =A0 =A0 =A0 =A0 =A0 pbus->count_cells(dev, &pna, &pns);
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (!OF_CHECK_COUNTS(pna, pns)) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "prom_parse: B=
ad cell count for %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name)=
;
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 DBG("OF: parent bus is %s (na=3D%d, ns=3D%d) o=
n %s\n",
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pbus->name, pna, pns, parent->full_nam=
e);
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Apply bus translation */
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (of_translate_one(dev, bus, pbus, addr, na,=
 ns, pna, rprop))
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 /* Complete the move up one level */
>> - =A0 =A0 =A0 =A0 =A0 =A0 na =3D pna;
>> - =A0 =A0 =A0 =A0 =A0 =A0 ns =3D pns;
>> - =A0 =A0 =A0 =A0 =A0 =A0 bus =3D pbus;
>> -
>> - =A0 =A0 =A0 =A0 =A0 =A0 of_dump_addr("OF: one level translation:", add=
r, na);
>> - =A0 =A0 }
>> - bail:
>> - =A0 =A0 of_node_put(parent);
>> - =A0 =A0 of_node_put(dev);
>> -
>> - =A0 =A0 return result;
>> -}
>> -
>> -u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
>> -{
>> - =A0 =A0 return __of_translate_address(dev, in_addr, "ranges");
>> -}
>> -EXPORT_SYMBOL(of_translate_address);
>> -
>> -u64 of_translate_dma_address(struct device_node *dev, const u32 *in_add=
r)
>> -{
>> - =A0 =A0 return __of_translate_address(dev, in_addr, "dma-ranges");
>> -}
>> -EXPORT_SYMBOL(of_translate_dma_address);
>> -
>> -const u32 *of_get_address(struct device_node *dev, int index, u64 *size=
,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
>> -{
>> - =A0 =A0 const u32 *prop;
>> - =A0 =A0 unsigned int psize;
>> - =A0 =A0 struct device_node *parent;
>> - =A0 =A0 struct of_bus *bus;
>> - =A0 =A0 int onesize, i, na, ns;
>> -
>> - =A0 =A0 /* Get parent & match bus type */
>> - =A0 =A0 parent =3D of_get_parent(dev);
>> - =A0 =A0 if (parent =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 bus =3D of_match_bus(parent);
>> - =A0 =A0 bus->count_cells(dev, &na, &ns);
>> - =A0 =A0 of_node_put(parent);
>> - =A0 =A0 if (!OF_CHECK_COUNTS(na, ns))
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> -
>> - =A0 =A0 /* Get "reg" or "assigned-addresses" property */
>> - =A0 =A0 prop =3D of_get_property(dev, bus->addresses, &psize);
>> - =A0 =A0 if (prop =3D=3D NULL)
>> - =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> - =A0 =A0 psize /=3D 4;
>> -
>> - =A0 =A0 onesize =3D na + ns;
>> - =A0 =A0 for (i =3D 0; psize >=3D onesize; psize -=3D onesize, prop +=
=3D onesize, i++)
>> - =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D index) {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *size =3D of_r=
ead_number(prop + na, ns);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (flags)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *flags =3D bus=
->get_flags(prop);
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
>> - =A0 =A0 =A0 =A0 =A0 =A0 }
>> - =A0 =A0 return NULL;
>> -}
>> -EXPORT_SYMBOL(of_get_address);
>> -
>> =A0void of_parse_dma_window(struct device_node *dn, const void *dma_wind=
ow_prop,
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long *busno, unsigned long *phys, u=
nsigned long *size)
>> =A0{
>> diff --git a/drivers/of/address.c b/drivers/of/address.c
>> index c381955..2a905d5 100644
>> --- a/drivers/of/address.c
>> +++ b/drivers/of/address.c
>> @@ -1,11 +1,522 @@
>>
>> =A0#include <linux/io.h>
>> =A0#include <linux/ioport.h>
>> +#include <linux/module.h>
>> =A0#include <linux/of_address.h>
>> +#include <linux/pci_regs.h>
>> +#include <linux/string.h>
>>
>> -int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0u64 size, unsigned =
int flags,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct resource *r)
>> +/* Max address size we deal with */
>> +#define OF_MAX_ADDR_CELLS =A0 =A04
>> +#define OF_CHECK_COUNTS(na, ns) =A0 =A0 =A0((na) > 0 && (na) <=3D OF_MA=
X_ADDR_CELLS && \
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (ns) > 0)
>> +
>> +static struct of_bus *of_match_bus(struct device_node *np);
>> +static int __of_address_to_resource(struct device_node *dev, const u32 =
*addrp,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 si=
ze, unsigned int flags,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct=
 resource *r);
>> +
>> +/* Debug utility */
>> +#ifdef DEBUG
>> +static void of_dump_addr(const char *s, const u32 *addr, int na)
>> +{
>> + =A0 =A0 printk(KERN_DEBUG "%s", s);
>> + =A0 =A0 while (na--)
>> + =A0 =A0 =A0 =A0 =A0 =A0 printk(" %08x", *(addr++));
>> + =A0 =A0 printk("\n");
>> +}
>> +#else
>> +static void of_dump_addr(const char *s, const u32 *addr, int na) { }
>> +#endif
>> +
>> +/* Callbacks for bus specific translators */
>> +struct of_bus {
>> + =A0 =A0 const char =A0 =A0 =A0*name;
>> + =A0 =A0 const char =A0 =A0 =A0*addresses;
>> + =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*match)(struct device_node *paren=
t);
>> + =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0(*count_cells)(struct device_node =
*child,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0int *addrc, int *sizec);
>> + =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 (*map)(u32 *addr, const u32 *range=
,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns=
, int pna);
>> + =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*translate)(u32 *addr, u64 offset=
, int na);
>> + =A0 =A0 unsigned int =A0 =A0(*get_flags)(const u32 *addr);
>> +};
>> +
>> +/*
>> + * Default translator (generic bus)
>> + */
>> +
>> +static void of_bus_default_count_cells(struct device_node *dev,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0int *addrc, int *sizec)
>> +{
>> + =A0 =A0 if (addrc)
>> + =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D of_n_addr_cells(dev);
>> + =A0 =A0 if (sizec)
>> + =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D of_n_size_cells(dev);
>> +}
>> +
>> +static u64 of_bus_default_map(u32 *addr, const u32 *range,
>> + =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pna)
>> +{
>> + =A0 =A0 u64 cp, s, da;
>> +
>> + =A0 =A0 cp =3D of_read_number(range, na);
>> + =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> + =A0 =A0 da =3D of_read_number(addr, na);
>> +
>> + =A0 =A0 pr_debug("OF: default map, cp=3D%llx, s=3D%llx, da=3D%llx\n",
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)cp, (unsigned long long=
)s,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)da);
>> +
>> + =A0 =A0 if (da < cp || da >=3D (cp + s))
>> + =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> + =A0 =A0 return da - cp;
>> +}
>> +
>> +static int of_bus_default_translate(u32 *addr, u64 offset, int na)
>> +{
>> + =A0 =A0 u64 a =3D of_read_number(addr, na);
>> + =A0 =A0 memset(addr, 0, na * 4);
>> + =A0 =A0 a +=3D offset;
>> + =A0 =A0 if (na > 1)
>> + =A0 =A0 =A0 =A0 =A0 =A0 addr[na - 2] =3D a >> 32;
>> + =A0 =A0 addr[na - 1] =3D a & 0xffffffffu;
>> +
>> + =A0 =A0 return 0;
>> +}
>> +
>> +static unsigned int of_bus_default_get_flags(const u32 *addr)
>> +{
>> + =A0 =A0 return IORESOURCE_MEM;
>> +}
>> +
>> +#ifdef CONFIG_PCI
>> +/*
>> + * PCI bus specific translator
>> + */
>> +
>> +static int of_bus_pci_match(struct device_node *np)
>> +{
>> + =A0 =A0 /* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
>> + =A0 =A0 return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
>> +}
>> +
>> +static void of_bus_pci_count_cells(struct device_node *np,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int *ad=
drc, int *sizec)
>> +{
>> + =A0 =A0 if (addrc)
>> + =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D 3;
>> + =A0 =A0 if (sizec)
>> + =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D 2;
>> +}
>> +
>> +static unsigned int of_bus_pci_get_flags(const u32 *addr)
>> +{
>> + =A0 =A0 unsigned int flags =3D 0;
>> + =A0 =A0 u32 w =3D addr[0];
>> +
>> + =A0 =A0 switch((w >> 24) & 0x03) {
>> + =A0 =A0 case 0x01:
>> + =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_IO;
>> + =A0 =A0 =A0 =A0 =A0 =A0 break;
>> + =A0 =A0 case 0x02: /* 32 bits */
>> + =A0 =A0 case 0x03: /* 64 bits */
>> + =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_MEM;
>> + =A0 =A0 =A0 =A0 =A0 =A0 break;
>> + =A0 =A0 }
>> + =A0 =A0 if (w & 0x40000000)
>> + =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_PREFETCH;
>> + =A0 =A0 return flags;
>> +}
>> +
>> +static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
>> +{
>> + =A0 =A0 u64 cp, s, da;
>> + =A0 =A0 unsigned int af, rf;
>> +
>> + =A0 =A0 af =3D of_bus_pci_get_flags(addr);
>> + =A0 =A0 rf =3D of_bus_pci_get_flags(range);
>> +
>> + =A0 =A0 /* Check address type match */
>> + =A0 =A0 if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
>> + =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> +
>> + =A0 =A0 /* Read address values, skipping high cell */
>> + =A0 =A0 cp =3D of_read_number(range + 1, na - 1);
>> + =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> + =A0 =A0 da =3D of_read_number(addr + 1, na - 1);
>> +
>> + =A0 =A0 pr_debug("OF: PCI map, cp=3D%llx, s=3D%llx, da=3D%llx\n",
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)cp, (unsigned long long=
)s,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)da);
>> +
>> + =A0 =A0 if (da < cp || da >=3D (cp + s))
>> + =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> + =A0 =A0 return da - cp;
>> +}
>> +
>> +static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
>> +{
>> + =A0 =A0 return of_bus_default_translate(addr + 1, offset, na - 1);
>> +}
>> +
>> +const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 =
*size,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
>> +{
>> + =A0 =A0 const u32 *prop;
>> + =A0 =A0 unsigned int psize;
>> + =A0 =A0 struct device_node *parent;
>> + =A0 =A0 struct of_bus *bus;
>> + =A0 =A0 int onesize, i, na, ns;
>> +
>> + =A0 =A0 /* Get parent & match bus type */
>> + =A0 =A0 parent =3D of_get_parent(dev);
>> + =A0 =A0 if (parent =3D=3D NULL)
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> + =A0 =A0 bus =3D of_match_bus(parent);
>> + =A0 =A0 if (strcmp(bus->name, "pci")) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(parent);
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> + =A0 =A0 }
>> + =A0 =A0 bus->count_cells(dev, &na, &ns);
>> + =A0 =A0 of_node_put(parent);
>> + =A0 =A0 if (!OF_CHECK_COUNTS(na, ns))
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> +
>> + =A0 =A0 /* Get "reg" or "assigned-addresses" property */
>> + =A0 =A0 prop =3D of_get_property(dev, bus->addresses, &psize);
>> + =A0 =A0 if (prop =3D=3D NULL)
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> + =A0 =A0 psize /=3D 4;
>> +
>> + =A0 =A0 onesize =3D na + ns;
>> + =A0 =A0 for (i =3D 0; psize >=3D onesize; psize -=3D onesize, prop +=
=3D onesize, i++)
>> + =A0 =A0 =A0 =A0 =A0 =A0 if ((prop[0] & 0xff) =3D=3D ((bar_no * 4) + PC=
I_BASE_ADDRESS_0)) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *size =3D of_r=
ead_number(prop + na, ns);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (flags)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *flags =3D bus=
->get_flags(prop);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
>> + =A0 =A0 =A0 =A0 =A0 =A0 }
>> + =A0 =A0 return NULL;
>> +}
>> +EXPORT_SYMBOL(of_get_pci_address);
>> +
>> +int of_pci_address_to_resource(struct device_node *dev, int bar,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct resource=
 *r)
>> +{
>> + =A0 =A0 const u32 =A0 =A0 =A0 *addrp;
>> + =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 size;
>> + =A0 =A0 unsigned int =A0 =A0flags;
>> +
>> + =A0 =A0 addrp =3D of_get_pci_address(dev, bar, &size, &flags);
>> + =A0 =A0 if (addrp =3D=3D NULL)
>> + =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
>> + =A0 =A0 return __of_address_to_resource(dev, addrp, size, flags, r);
>> +}
>> +EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
>> +#endif /* CONFIG_PCI */
>> +
>> +/*
>> + * ISA bus specific translator
>> + */
>> +
>> +static int of_bus_isa_match(struct device_node *np)
>> +{
>> + =A0 =A0 return !strcmp(np->name, "isa");
>> +}
>> +
>> +static void of_bus_isa_count_cells(struct device_node *child,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int *ad=
drc, int *sizec)
>> +{
>> + =A0 =A0 if (addrc)
>> + =A0 =A0 =A0 =A0 =A0 =A0 *addrc =3D 2;
>> + =A0 =A0 if (sizec)
>> + =A0 =A0 =A0 =A0 =A0 =A0 *sizec =3D 1;
>> +}
>> +
>> +static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
>> +{
>> + =A0 =A0 u64 cp, s, da;
>> +
>> + =A0 =A0 /* Check address type match */
>> + =A0 =A0 if ((addr[0] ^ range[0]) & 0x00000001)
>> + =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> +
>> + =A0 =A0 /* Read address values, skipping high cell */
>> + =A0 =A0 cp =3D of_read_number(range + 1, na - 1);
>> + =A0 =A0 s =A0=3D of_read_number(range + na + pna, ns);
>> + =A0 =A0 da =3D of_read_number(addr + 1, na - 1);
>> +
>> + =A0 =A0 pr_debug("OF: ISA map, cp=3D%llx, s=3D%llx, da=3D%llx\n",
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)cp, (unsigned long long=
)s,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)da);
>> +
>> + =A0 =A0 if (da < cp || da >=3D (cp + s))
>> + =A0 =A0 =A0 =A0 =A0 =A0 return OF_BAD_ADDR;
>> + =A0 =A0 return da - cp;
>> +}
>> +
>> +static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
>> +{
>> + =A0 =A0 return of_bus_default_translate(addr + 1, offset, na - 1);
>> +}
>> +
>> +static unsigned int of_bus_isa_get_flags(const u32 *addr)
>> +{
>> + =A0 =A0 unsigned int flags =3D 0;
>> + =A0 =A0 u32 w =3D addr[0];
>> +
>> + =A0 =A0 if (w & 1)
>> + =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_IO;
>> + =A0 =A0 else
>> + =A0 =A0 =A0 =A0 =A0 =A0 flags |=3D IORESOURCE_MEM;
>> + =A0 =A0 return flags;
>> +}
>> +
>> +/*
>> + * Array of bus specific translators
>> + */
>> +
>> +static struct of_bus of_busses[] =3D {
>> +#ifdef CONFIG_PCI
>> + =A0 =A0 /* PCI */
>> + =A0 =A0 {
>> + =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "pci",
>> + =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "assigned-addresses",
>> + =A0 =A0 =A0 =A0 =A0 =A0 .match =3D of_bus_pci_match,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_pci_count_cells,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_pci_map,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_pci_translate,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_pci_get_flags,
>> + =A0 =A0 },
>> +#endif /* CONFIG_PCI */
>> + =A0 =A0 /* ISA */
>> + =A0 =A0 {
>> + =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "isa",
>> + =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "reg",
>> + =A0 =A0 =A0 =A0 =A0 =A0 .match =3D of_bus_isa_match,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_isa_count_cells,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_isa_map,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_isa_translate,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_isa_get_flags,
>> + =A0 =A0 },
>> + =A0 =A0 /* Default */
>> + =A0 =A0 {
>> + =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "default",
>> + =A0 =A0 =A0 =A0 =A0 =A0 .addresses =3D "reg",
>> + =A0 =A0 =A0 =A0 =A0 =A0 .match =3D NULL,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .count_cells =3D of_bus_default_count_cells,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .map =3D of_bus_default_map,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .translate =3D of_bus_default_translate,
>> + =A0 =A0 =A0 =A0 =A0 =A0 .get_flags =3D of_bus_default_get_flags,
>> + =A0 =A0 },
>> +};
>> +
>> +static struct of_bus *of_match_bus(struct device_node *np)
>> +{
>> + =A0 =A0 int i;
>> +
>> + =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(of_busses); i++)
>> + =A0 =A0 =A0 =A0 =A0 =A0 if (!of_busses[i].match || of_busses[i].match(=
np))
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return &of_busses[i];
>> + =A0 =A0 BUG();
>> + =A0 =A0 return NULL;
>> +}
>> +
>> +static int of_translate_one(struct device_node *parent, struct of_bus *=
bus,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct of_bus *pbus, u=
32 *addr,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pn=
a, const char *rprop)
>> +{
>> + =A0 =A0 const u32 *ranges;
>> + =A0 =A0 unsigned int rlen;
>> + =A0 =A0 int rone;
>> + =A0 =A0 u64 offset =3D OF_BAD_ADDR;
>> +
>> + =A0 =A0 /* Normally, an absence of a "ranges" property means we are
>> + =A0 =A0 =A0* crossing a non-translatable boundary, and thus the addres=
ses
>> + =A0 =A0 =A0* below the current not cannot be converted to CPU physical=
 ones.
>> + =A0 =A0 =A0* Unfortunately, while this is very clear in the spec, it's=
 not
>> + =A0 =A0 =A0* what Apple understood, and they do have things like /uni-=
n or
>> + =A0 =A0 =A0* /ht nodes with no "ranges" property and a lot of perfectl=
y
>> + =A0 =A0 =A0* useable mapped devices below them. Thus we treat the abse=
nce of
>> + =A0 =A0 =A0* "ranges" as equivalent to an empty "ranges" property whic=
h means
>> + =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller no=
t to try
>> + =A0 =A0 =A0* to translate addresses that aren't supposed to be transla=
ted in
>> + =A0 =A0 =A0* the first place. --BenH.
>> + =A0 =A0 =A0*/
>> + =A0 =A0 ranges =3D of_get_property(parent, rprop, &rlen);
>> + =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 offset =3D of_read_number(addr, na);
>> + =A0 =A0 =A0 =A0 =A0 =A0 memset(addr, 0, pna * 4);
>> + =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: no ranges, 1:1 translation\n");
>> + =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
>> + =A0 =A0 }
>> +
>> + =A0 =A0 pr_debug("OF: walking ranges...\n");
>> +
>> + =A0 =A0 /* Now walk through the ranges */
>> + =A0 =A0 rlen /=3D 4;
>> + =A0 =A0 rone =3D na + pna + ns;
>> + =A0 =A0 for (; rlen >=3D rone; rlen -=3D rone, ranges +=3D rone) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 offset =3D bus->map(addr, ranges, na, ns, pna)=
;
>> + =A0 =A0 =A0 =A0 =A0 =A0 if (offset !=3D OF_BAD_ADDR)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> + =A0 =A0 }
>> + =A0 =A0 if (offset =3D=3D OF_BAD_ADDR) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: not found !\n");
>> + =A0 =A0 =A0 =A0 =A0 =A0 return 1;
>> + =A0 =A0 }
>> + =A0 =A0 memcpy(addr, ranges + na, 4 * pna);
>> +
>> + finish:
>> + =A0 =A0 of_dump_addr("OF: parent translation for:", addr, pna);
>> + =A0 =A0 pr_debug("OF: with offset: %llx\n", (unsigned long long)offset=
);
>> +
>> + =A0 =A0 /* Translate it into parent bus space */
>> + =A0 =A0 return pbus->translate(addr, offset, pna);
>> +}
>> +
>> +/*
>> + * Translate an address from the device-tree into a CPU physical addres=
s,
>> + * this walks up the tree and applies the various bus mappings on the
>> + * way.
>> + *
>> + * Note: We consider that crossing any level with #size-cells =3D=3D 0 =
to mean
>> + * that translation is impossible (that is we are not dealing with a va=
lue
>> + * that can be mapped to a cpu physical address). This is not really sp=
ecified
>> + * that way, but this is traditionally the way IBM at least do things
>> + */
>> +u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const char *rprop)
>> +{
>> + =A0 =A0 struct device_node *parent =3D NULL;
>> + =A0 =A0 struct of_bus *bus, *pbus;
>> + =A0 =A0 u32 addr[OF_MAX_ADDR_CELLS];
>> + =A0 =A0 int na, ns, pna, pns;
>> + =A0 =A0 u64 result =3D OF_BAD_ADDR;
>> +
>> + =A0 =A0 pr_debug("OF: ** translation for device %s **\n", dev->full_na=
me);
>> +
>> + =A0 =A0 /* Increase refcount at current level */
>> + =A0 =A0 of_node_get(dev);
>> +
>> + =A0 =A0 /* Get parent & match bus type */
>> + =A0 =A0 parent =3D of_get_parent(dev);
>> + =A0 =A0 if (parent =3D=3D NULL)
>> + =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
>> + =A0 =A0 bus =3D of_match_bus(parent);
>> +
>> + =A0 =A0 /* Cound address cells & copy address locally */
>> + =A0 =A0 bus->count_cells(dev, &na, &ns);
>> + =A0 =A0 if (!OF_CHECK_COUNTS(na, ns)) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "prom_parse: Bad cell count fo=
r %s\n",
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name);
>> + =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
>> + =A0 =A0 }
>> + =A0 =A0 memcpy(addr, in_addr, na * 4);
>> +
>> + =A0 =A0 pr_debug("OF: bus is %s (na=3D%d, ns=3D%d) on %s\n",
>> + =A0 =A0 =A0 =A0 bus->name, na, ns, parent->full_name);
>> + =A0 =A0 of_dump_addr("OF: translating address:", addr, na);
>> +
>> + =A0 =A0 /* Translate */
>> + =A0 =A0 for (;;) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 /* Switch to parent bus */
>> + =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(dev);
>> + =A0 =A0 =A0 =A0 =A0 =A0 dev =3D parent;
>> + =A0 =A0 =A0 =A0 =A0 =A0 parent =3D of_get_parent(dev);
>> +
>> + =A0 =A0 =A0 =A0 =A0 =A0 /* If root, we have finished */
>> + =A0 =A0 =A0 =A0 =A0 =A0 if (parent =3D=3D NULL) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: reached root nod=
e\n");
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D of_read_number(addr=
, na);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> + =A0 =A0 =A0 =A0 =A0 =A0 }
>> +
>> + =A0 =A0 =A0 =A0 =A0 =A0 /* Get new parent bus and counts */
>> + =A0 =A0 =A0 =A0 =A0 =A0 pbus =3D of_match_bus(parent);
>> + =A0 =A0 =A0 =A0 =A0 =A0 pbus->count_cells(dev, &pna, &pns);
>> + =A0 =A0 =A0 =A0 =A0 =A0 if (!OF_CHECK_COUNTS(pna, pns)) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "prom_parse: B=
ad cell count for %s\n",
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name)=
;
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> + =A0 =A0 =A0 =A0 =A0 =A0 }
>> +
>> + =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: parent bus is %s (na=3D%d, ns=3D=
%d) on %s\n",
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pbus->name, pna, pns, parent->full_nam=
e);
>> +
>> + =A0 =A0 =A0 =A0 =A0 =A0 /* Apply bus translation */
>> + =A0 =A0 =A0 =A0 =A0 =A0 if (of_translate_one(dev, bus, pbus, addr, na,=
 ns, pna, rprop))
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
>> +
>> + =A0 =A0 =A0 =A0 =A0 =A0 /* Complete the move up one level */
>> + =A0 =A0 =A0 =A0 =A0 =A0 na =3D pna;
>> + =A0 =A0 =A0 =A0 =A0 =A0 ns =3D pns;
>> + =A0 =A0 =A0 =A0 =A0 =A0 bus =3D pbus;
>> +
>> + =A0 =A0 =A0 =A0 =A0 =A0 of_dump_addr("OF: one level translation:", add=
r, na);
>> + =A0 =A0 }
>> + bail:
>> + =A0 =A0 of_node_put(parent);
>> + =A0 =A0 of_node_put(dev);
>> +
>> + =A0 =A0 return result;
>> +}
>> +
>> +u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
>> +{
>> + =A0 =A0 return __of_translate_address(dev, in_addr, "ranges");
>> +}
>> +EXPORT_SYMBOL(of_translate_address);
>> +
>> +u64 of_translate_dma_address(struct device_node *dev, const u32 *in_add=
r)
>> +{
>> + =A0 =A0 return __of_translate_address(dev, in_addr, "dma-ranges");
>> +}
>> +EXPORT_SYMBOL(of_translate_dma_address);
>> +
>> +const u32 *of_get_address(struct device_node *dev, int index, u64 *size=
,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
>> +{
>> + =A0 =A0 const u32 *prop;
>> + =A0 =A0 unsigned int psize;
>> + =A0 =A0 struct device_node *parent;
>> + =A0 =A0 struct of_bus *bus;
>> + =A0 =A0 int onesize, i, na, ns;
>> +
>> + =A0 =A0 /* Get parent & match bus type */
>> + =A0 =A0 parent =3D of_get_parent(dev);
>> + =A0 =A0 if (parent =3D=3D NULL)
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> + =A0 =A0 bus =3D of_match_bus(parent);
>> + =A0 =A0 bus->count_cells(dev, &na, &ns);
>> + =A0 =A0 of_node_put(parent);
>> + =A0 =A0 if (!OF_CHECK_COUNTS(na, ns))
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> +
>> + =A0 =A0 /* Get "reg" or "assigned-addresses" property */
>> + =A0 =A0 prop =3D of_get_property(dev, bus->addresses, &psize);
>> + =A0 =A0 if (prop =3D=3D NULL)
>> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
>> + =A0 =A0 psize /=3D 4;
>> +
>> + =A0 =A0 onesize =3D na + ns;
>> + =A0 =A0 for (i =3D 0; psize >=3D onesize; psize -=3D onesize, prop +=
=3D onesize, i++)
>> + =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D index) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *size =3D of_r=
ead_number(prop + na, ns);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (flags)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *flags =3D bus=
->get_flags(prop);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
>> + =A0 =A0 =A0 =A0 =A0 =A0 }
>> + =A0 =A0 return NULL;
>> +}
>> +EXPORT_SYMBOL(of_get_address);
>> +
>> +static int __of_address_to_resource(struct device_node *dev, const u32 =
*addrp,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 si=
ze, unsigned int flags,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct=
 resource *r)
>> =A0{
>> =A0 =A0 =A0 u64 taddr;
>>
>> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
>> index 474b794..cc567df 100644
>> --- a/include/linux/of_address.h
>> +++ b/include/linux/of_address.h
>> @@ -3,9 +3,7 @@
>> =A0#include <linux/ioport.h>
>> =A0#include <linux/of.h>
>>
>> -extern int __of_address_to_resource(struct device_node *dev, const u32 =
*addrp,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 si=
ze, unsigned int flags,
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct=
 resource *r);
>> +extern u64 of_translate_address(struct device_node *np, const u32 *addr=
);
>> =A0extern int of_address_to_resource(struct device_node *dev, int index,
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct r=
esource *r);
>> =A0extern void __iomem *of_iomap(struct device_node *device, int index);
>
>
>



--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
  2010-06-10  6:44     ` Benjamin Herrenschmidt
@ 2010-06-10 14:28       ` Grant Likely
  -1 siblings, 0 replies; 24+ messages in thread
From: Grant Likely @ 2010-06-10 14:28 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Stephen Rothwell, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Thu, Jun 10, 2010 at 12:44 AM, Benjamin Herrenschmidt
<benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org> wrote:
> On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
>> Certain Apple machines don't use the ranges property correctly, but the
>> workaround should not be applied on other architectures.  This patch
>> disables the workaround for non-powerpc architectures.
>
> I'm half tempted to add it to the quirk list (which should really be
> made generic) so I can disable it on more 'modern' powerpc as well.

In the mean time, are you okay with this version of the patch?

g.

>
> Cheers,
> Ben.
>
>> Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>> CC: Stephen Rothwell <sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>
>> CC: Benjamin Herrenschmidt <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
>> CC: linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
>> CC: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
>> ---
>>  drivers/of/address.c |   11 ++++++++++-
>>  1 files changed, 10 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/of/address.c b/drivers/of/address.c
>> index 0b04137..5c220c3 100644
>> --- a/drivers/of/address.c
>> +++ b/drivers/of/address.c
>> @@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
>>        * a 1:1 translation at that level. It's up to the caller not to try
>>        * to translate addresses that aren't supposed to be translated in
>>        * the first place. --BenH.
>> +      *
>> +      * As far as we know, this damage only exists on Apple machines, so
>> +      * This code is only enabled on powerpc. --gcl
>>        */
>>       ranges = of_get_property(parent, rprop, &rlen);
>> +#if !defined(CONFIG_PPC)
>> +     if (ranges == NULL) {
>> +             pr_err("OF: no ranges; cannot translate\n");
>> +             return 1;
>> +     }
>> +#endif /* !defined(CONFIG_PPC) */
>>       if (ranges == NULL || rlen == 0) {
>>               offset = of_read_number(addr, na);
>>               memset(addr, 0, pna * 4);
>> -             pr_debug("OF: no ranges, 1:1 translation\n");
>> +             pr_debug("OF: empty ranges; 1:1 translation\n");
>>               goto finish;
>>       }
>>
>
>
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
@ 2010-06-10 14:28       ` Grant Likely
  0 siblings, 0 replies; 24+ messages in thread
From: Grant Likely @ 2010-06-10 14:28 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Stephen Rothwell, devicetree-discuss, linuxppc-dev

On Thu, Jun 10, 2010 at 12:44 AM, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
> On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
>> Certain Apple machines don't use the ranges property correctly, but the
>> workaround should not be applied on other architectures. =A0This patch
>> disables the workaround for non-powerpc architectures.
>
> I'm half tempted to add it to the quirk list (which should really be
> made generic) so I can disable it on more 'modern' powerpc as well.

In the mean time, are you okay with this version of the patch?

g.

>
> Cheers,
> Ben.
>
>> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
>> CC: Stephen Rothwell <sfr@canb.auug.org.au>
>> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>> CC: linuxppc-dev@lists.ozlabs.org
>> CC: devicetree-discuss@lists.ozlabs.org
>> ---
>> =A0drivers/of/address.c | =A0 11 ++++++++++-
>> =A01 files changed, 10 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/of/address.c b/drivers/of/address.c
>> index 0b04137..5c220c3 100644
>> --- a/drivers/of/address.c
>> +++ b/drivers/of/address.c
>> @@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *pa=
rent, struct of_bus *bus,
>> =A0 =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller =
not to try
>> =A0 =A0 =A0 =A0* to translate addresses that aren't supposed to be trans=
lated in
>> =A0 =A0 =A0 =A0* the first place. --BenH.
>> + =A0 =A0 =A0*
>> + =A0 =A0 =A0* As far as we know, this damage only exists on Apple machi=
nes, so
>> + =A0 =A0 =A0* This code is only enabled on powerpc. --gcl
>> =A0 =A0 =A0 =A0*/
>> =A0 =A0 =A0 ranges =3D of_get_property(parent, rprop, &rlen);
>> +#if !defined(CONFIG_PPC)
>> + =A0 =A0 if (ranges =3D=3D NULL) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 pr_err("OF: no ranges; cannot translate\n");
>> + =A0 =A0 =A0 =A0 =A0 =A0 return 1;
>> + =A0 =A0 }
>> +#endif /* !defined(CONFIG_PPC) */
>> =A0 =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 offset =3D of_read_number(addr, na);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(addr, 0, pna * 4);
>> - =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: no ranges, 1:1 translation\n");
>> + =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("OF: empty ranges; 1:1 translation\n"=
);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
>> =A0 =A0 =A0 }
>>
>
>
>



--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
  2010-06-10 14:28       ` Grant Likely
@ 2010-06-11  1:12           ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-11  1:12 UTC (permalink / raw)
  To: Grant Likely
  Cc: Stephen Rothwell, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Thu, 2010-06-10 at 08:28 -0600, Grant Likely wrote:
> On Thu, Jun 10, 2010 at 12:44 AM, Benjamin Herrenschmidt
> <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org> wrote:
> > On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> >> Certain Apple machines don't use the ranges property correctly, but the
> >> workaround should not be applied on other architectures.  This patch
> >> disables the workaround for non-powerpc architectures.
> >
> > I'm half tempted to add it to the quirk list (which should really be
> > made generic) so I can disable it on more 'modern' powerpc as well.
> 
> In the mean time, are you okay with this version of the patch?

For the time being yes.

Cheers,
Ben.

> g.
> 
> >
> > Cheers,
> > Ben.
> >
> >> Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> >> CC: Stephen Rothwell <sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>
> >> CC: Benjamin Herrenschmidt <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
> >> CC: linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> >> CC: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> >> ---
> >>  drivers/of/address.c |   11 ++++++++++-
> >>  1 files changed, 10 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/drivers/of/address.c b/drivers/of/address.c
> >> index 0b04137..5c220c3 100644
> >> --- a/drivers/of/address.c
> >> +++ b/drivers/of/address.c
> >> @@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
> >>        * a 1:1 translation at that level. It's up to the caller not to try
> >>        * to translate addresses that aren't supposed to be translated in
> >>        * the first place. --BenH.
> >> +      *
> >> +      * As far as we know, this damage only exists on Apple machines, so
> >> +      * This code is only enabled on powerpc. --gcl
> >>        */
> >>       ranges = of_get_property(parent, rprop, &rlen);
> >> +#if !defined(CONFIG_PPC)
> >> +     if (ranges == NULL) {
> >> +             pr_err("OF: no ranges; cannot translate\n");
> >> +             return 1;
> >> +     }
> >> +#endif /* !defined(CONFIG_PPC) */
> >>       if (ranges == NULL || rlen == 0) {
> >>               offset = of_read_number(addr, na);
> >>               memset(addr, 0, pna * 4);
> >> -             pr_debug("OF: no ranges, 1:1 translation\n");
> >> +             pr_debug("OF: empty ranges; 1:1 translation\n");
> >>               goto finish;
> >>       }
> >>
> >
> >
> >
> 
> 
> 

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
@ 2010-06-11  1:12           ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-11  1:12 UTC (permalink / raw)
  To: Grant Likely; +Cc: Stephen Rothwell, devicetree-discuss, linuxppc-dev

On Thu, 2010-06-10 at 08:28 -0600, Grant Likely wrote:
> On Thu, Jun 10, 2010 at 12:44 AM, Benjamin Herrenschmidt
> <benh@kernel.crashing.org> wrote:
> > On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> >> Certain Apple machines don't use the ranges property correctly, but the
> >> workaround should not be applied on other architectures.  This patch
> >> disables the workaround for non-powerpc architectures.
> >
> > I'm half tempted to add it to the quirk list (which should really be
> > made generic) so I can disable it on more 'modern' powerpc as well.
> 
> In the mean time, are you okay with this version of the patch?

For the time being yes.

Cheers,
Ben.

> g.
> 
> >
> > Cheers,
> > Ben.
> >
> >> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> >> CC: Stephen Rothwell <sfr@canb.auug.org.au>
> >> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> >> CC: linuxppc-dev@lists.ozlabs.org
> >> CC: devicetree-discuss@lists.ozlabs.org
> >> ---
> >>  drivers/of/address.c |   11 ++++++++++-
> >>  1 files changed, 10 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/drivers/of/address.c b/drivers/of/address.c
> >> index 0b04137..5c220c3 100644
> >> --- a/drivers/of/address.c
> >> +++ b/drivers/of/address.c
> >> @@ -346,12 +346,21 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
> >>        * a 1:1 translation at that level. It's up to the caller not to try
> >>        * to translate addresses that aren't supposed to be translated in
> >>        * the first place. --BenH.
> >> +      *
> >> +      * As far as we know, this damage only exists on Apple machines, so
> >> +      * This code is only enabled on powerpc. --gcl
> >>        */
> >>       ranges = of_get_property(parent, rprop, &rlen);
> >> +#if !defined(CONFIG_PPC)
> >> +     if (ranges == NULL) {
> >> +             pr_err("OF: no ranges; cannot translate\n");
> >> +             return 1;
> >> +     }
> >> +#endif /* !defined(CONFIG_PPC) */
> >>       if (ranges == NULL || rlen == 0) {
> >>               offset = of_read_number(addr, na);
> >>               memset(addr, 0, pna * 4);
> >> -             pr_debug("OF: no ranges, 1:1 translation\n");
> >> +             pr_debug("OF: empty ranges; 1:1 translation\n");
> >>               goto finish;
> >>       }
> >>
> >
> >
> >
> 
> 
> 

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
  2010-06-10  6:44     ` Benjamin Herrenschmidt
@ 2010-06-15 16:23       ` Segher Boessenkool
  -1 siblings, 0 replies; 24+ messages in thread
From: Segher Boessenkool @ 2010-06-15 16:23 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Stephen Rothwell, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

>> Certain Apple machines don't use the ranges property correctly,  
>> but the
>> workaround should not be applied on other architectures.  This patch
>> disables the workaround for non-powerpc architectures.
>
> I'm half tempted to add it to the quirk list (which should really be
> made generic) so I can disable it on more 'modern' powerpc as well.

Oh please oh please oh please yes do.

OTOH, it would be even better to just fix up the device tree in the
early platform code.  Quirks are for broken hardware; software, we
can fix.


Segher

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
@ 2010-06-15 16:23       ` Segher Boessenkool
  0 siblings, 0 replies; 24+ messages in thread
From: Segher Boessenkool @ 2010-06-15 16:23 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Stephen Rothwell, devicetree-discuss, linuxppc-dev

>> Certain Apple machines don't use the ranges property correctly,  
>> but the
>> workaround should not be applied on other architectures.  This patch
>> disables the workaround for non-powerpc architectures.
>
> I'm half tempted to add it to the quirk list (which should really be
> made generic) so I can disable it on more 'modern' powerpc as well.

Oh please oh please oh please yes do.

OTOH, it would be even better to just fix up the device tree in the
early platform code.  Quirks are for broken hardware; software, we
can fix.


Segher

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
  2010-06-15 16:23       ` Segher Boessenkool
@ 2010-06-16  0:33           ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-16  0:33 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Stephen Rothwell, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Tue, 2010-06-15 at 18:23 +0200, Segher Boessenkool wrote:
> >> Certain Apple machines don't use the ranges property correctly,  
> >> but the
> >> workaround should not be applied on other architectures.  This patch
> >> disables the workaround for non-powerpc architectures.
> >
> > I'm half tempted to add it to the quirk list (which should really be
> > made generic) so I can disable it on more 'modern' powerpc as well.
> 
> Oh please oh please oh please yes do.
> 
> OTOH, it would be even better to just fix up the device tree in the
> early platform code.  Quirks are for broken hardware; software, we
> can fix.

That would work if I could bloody remember which machines need what on
what nodes ... some of those are ancient and I don't have access to all
of them.

Cheers,
Ben.

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

* Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
@ 2010-06-16  0:33           ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-16  0:33 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Stephen Rothwell, devicetree-discuss, linuxppc-dev

On Tue, 2010-06-15 at 18:23 +0200, Segher Boessenkool wrote:
> >> Certain Apple machines don't use the ranges property correctly,  
> >> but the
> >> workaround should not be applied on other architectures.  This patch
> >> disables the workaround for non-powerpc architectures.
> >
> > I'm half tempted to add it to the quirk list (which should really be
> > made generic) so I can disable it on more 'modern' powerpc as well.
> 
> Oh please oh please oh please yes do.
> 
> OTOH, it would be even better to just fix up the device tree in the
> early platform code.  Quirks are for broken hardware; software, we
> can fix.

That would work if I could bloody remember which machines need what on
what nodes ... some of those are ancient and I don't have access to all
of them.

Cheers,
Ben.

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

* Re: [PATCH 3/5] of/address: Merge all of the bus translation code
  2010-06-10 14:26     ` Grant Likely
@ 2010-06-21 21:06       ` Grant Likely
  2010-06-21 23:16         ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 24+ messages in thread
From: Grant Likely @ 2010-06-21 21:06 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Thu, Jun 10, 2010 at 8:26 AM, Grant Likely <grant.likely@secretlab.ca> w=
rote:
> On Thu, Jun 10, 2010 at 12:43 AM, Benjamin Herrenschmidt
> <benh@kernel.crashing.org> wrote:
>> On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
>>> Microblaze and PowerPC share a large chunk of code for translating
>>> OF device tree data into usable addresses. =A0There aren't many differe=
nces
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^^^^
>> Care to comment on these differences ?
>
> Purely cosmetic IIRC, but I will go back and double check. =A0Things
> like printk vs. pr_info and some style differences. =A0I looked at them
> side-by-side and fixed each difference individually until they were
> identical.
>
>>> between the two, so merge the codebase wholesale rather than trying to
>>> work out the independent bits.
>>
>> Well, I don't see ifdef's in the resulting code (but I'm a bit blind),
>> so what did you do with the differences ?
>>
>> This is complex and fragile code, so any change to it must be very
>> carefully scrutinized.

Hi Ben,

I've double checked side-by-side.  The changes are all cosmetic expect
for the addition of dma-ranges support on the powerpc version that
hadn't been applied to microblaze.  This patch takes the powerpc code
plus the cosmetic changes (spaces, pr_debug vs DBG, etc) from the
microblaze side.  There should be no functional changes to either
platform since microblaze doesn't currently use dma-ranges anyway.

Here's the new commit text:

----
    of/address: Merge all of the bus translation code

    Microblaze and PowerPC share a large chunk of code for translating
    OF device tree data into usable addresses.  Differences between the two
    consist of cosmetic differences, and the addition of dma-ranges support
    to powerpc but not microblaze.  This patch moves the powerpc
    version into common code and applies many of the cosmetic (non-function=
al)
    changes from the microblaze version.
----

I've only changed the commit text.  The patch remains unchanged.  Are
you okay with this patch?

Cheers,
g.


>>
>> Cheers,
>> Ben.
>>
>>> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
>>> CC: Michal Simek <monstr@monstr.eu>
>>> CC: Wolfram Sang <w.sang@pengutronix.de>
>>> CC: Stephen Rothwell <sfr@canb.auug.org.au>
>>> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>>> CC: microblaze-uclinux@itee.uq.edu.au
>>> CC: linuxppc-dev@ozlabs.org

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

* Re: [PATCH 3/5] of/address: Merge all of the bus translation code
  2010-06-21 21:06       ` Grant Likely
@ 2010-06-21 23:16         ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2010-06-21 23:16 UTC (permalink / raw)
  To: Grant Likely
  Cc: linuxppc-dev, Stephen Rothwell, Michal Simek, microblaze-uclinux

On Mon, 2010-06-21 at 15:06 -0600, Grant Likely wrote:
> On Thu, Jun 10, 2010 at 8:26 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
> > On Thu, Jun 10, 2010 at 12:43 AM, Benjamin Herrenschmidt
> > <benh@kernel.crashing.org> wrote:
> >> On Tue, 2010-06-08 at 08:10 -0600, Grant Likely wrote:
> >>> Microblaze and PowerPC share a large chunk of code for translating
> >>> OF device tree data into usable addresses.  There aren't many differences
> >>                                                           ^^^^
> >> Care to comment on these differences ?
> >
> > Purely cosmetic IIRC, but I will go back and double check.  Things
> > like printk vs. pr_info and some style differences.  I looked at them
> > side-by-side and fixed each difference individually until they were
> > identical.
> >
> >>> between the two, so merge the codebase wholesale rather than trying to
> >>> work out the independent bits.
> >>
> >> Well, I don't see ifdef's in the resulting code (but I'm a bit blind),
> >> so what did you do with the differences ?
> >>
> >> This is complex and fragile code, so any change to it must be very
> >> carefully scrutinized.
> 
> Hi Ben,
> 
> I've double checked side-by-side.  The changes are all cosmetic expect
> for the addition of dma-ranges support on the powerpc version that
> hadn't been applied to microblaze.  This patch takes the powerpc code
> plus the cosmetic changes (spaces, pr_debug vs DBG, etc) from the
> microblaze side.  There should be no functional changes to either
> platform since microblaze doesn't currently use dma-ranges anyway.
> 
> Here's the new commit text:

Ok.

Cheers
,Ben.

> ----
>     of/address: Merge all of the bus translation code
> 
>     Microblaze and PowerPC share a large chunk of code for translating
>     OF device tree data into usable addresses.  Differences between the two
>     consist of cosmetic differences, and the addition of dma-ranges support
>     to powerpc but not microblaze.  This patch moves the powerpc
>     version into common code and applies many of the cosmetic (non-functional)
>     changes from the microblaze version.
> ----
> 
> I've only changed the commit text.  The patch remains unchanged.  Are
> you okay with this patch?
> 
> Cheers,
> g.
> 
> 
> >>
> >> Cheers,
> >> Ben.
> >>
> >>> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> >>> CC: Michal Simek <monstr@monstr.eu>
> >>> CC: Wolfram Sang <w.sang@pengutronix.de>
> >>> CC: Stephen Rothwell <sfr@canb.auug.org.au>
> >>> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> >>> CC: microblaze-uclinux@itee.uq.edu.au
> >>> CC: linuxppc-dev@ozlabs.org

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

end of thread, other threads:[~2010-06-21 23:16 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20100608140917.25879.67745.stgit@angua>
2010-06-08 14:09 ` [PATCH 1/5] of/address: merge of_iomap() Grant Likely
2010-06-10  6:40   ` Benjamin Herrenschmidt
2010-06-08 14:10 ` [PATCH 2/5] of/address: merge of_address_to_resource() Grant Likely
2010-06-10  6:41   ` Benjamin Herrenschmidt
2010-06-08 14:10 ` [PATCH 3/5] of/address: Merge all of the bus translation code Grant Likely
2010-06-10  6:43   ` Benjamin Herrenschmidt
2010-06-10 14:26     ` Grant Likely
2010-06-21 21:06       ` Grant Likely
2010-06-21 23:16         ` Benjamin Herrenschmidt
2010-06-08 14:10 ` [PATCH 4/5] of/address: little-endian fixes Grant Likely
2010-06-10  6:43   ` Benjamin Herrenschmidt
2010-06-08 14:10 ` [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc Grant Likely
2010-06-08 14:10   ` Grant Likely
2010-06-10  6:44   ` Benjamin Herrenschmidt
2010-06-10  6:44     ` Benjamin Herrenschmidt
2010-06-10 14:28     ` Grant Likely
2010-06-10 14:28       ` Grant Likely
     [not found]       ` <AANLkTikg1hLdV_OUjc3QIhFatP_iLfVClhzmyixmjje1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-11  1:12         ` Benjamin Herrenschmidt
2010-06-11  1:12           ` Benjamin Herrenschmidt
2010-06-15 16:23     ` Segher Boessenkool
2010-06-15 16:23       ` Segher Boessenkool
     [not found]       ` <1C7A9067-DDE6-47D3-AC78-FDC081354519-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
2010-06-16  0:33         ` Benjamin Herrenschmidt
2010-06-16  0:33           ` Benjamin Herrenschmidt
2010-06-08 14:12 ` [PATCH 0/5] Merge common address translation code (ppc & mb) Grant Likely

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.