of/address: merge of_iomap()
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): 20100608140917.25879.67745.stgit@angua
PATCH 1/5 of/address: merge of_iomap()
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()
--- 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
arch/microblaze/include/asm/prom.h +1 -9
@@ -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 */
arch/microblaze/kernel/prom_parse.c +0 -11
@@ -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);
arch/powerpc/include/asm/prom.h +1 -9
@@ -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 */
arch/powerpc/kernel/prom_parse.c +0 -11
@@ -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);
drivers/of/Kconfig +4 -0
@@ -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
drivers/of/Makefile +1 -0
@@ -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
drivers/of/address.c new file +22 -0
@@ -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);
include/linux/of_address.h new file +9 -0
@@ -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 */ +
Quoted 8 lines · Grant Likely
Merge common code between Microblaze and PowerPC. This patch creates new
of_address.handaddress.cfiles to containing address translation and mapping routines. First routine to be moved itof_iomap()Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>
Quoted 177 lines
--- 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.harch/microblaze/include/asm/prom.h +1
-9@@ -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 */ arch/microblaze/kernel/prom_parse.c +0
-11@@ -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);arch/powerpc/include/asm/prom.h +1
-9@@ -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 */ arch/powerpc/kernel/prom_parse.c +0
-11@@ -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);drivers/of/Kconfig +4
-0@@ -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 && !SPARCdrivers/of/Makefile +1
-0@@ -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.odrivers/of/address.c new file +22
-0@@ -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);include/linux/of_address.h new file +9
-0@@ -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 */ +
PATCH 2/5 of/address: merge of_address_to_resource()
In reply to a message not in the archiveMerge 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().
--- 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(-)
arch/microblaze/include/asm/pci-bridge.h +0 -5
@@ -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 ;
arch/microblaze/include/asm/prom.h +9 -8
@@ -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. */
arch/microblaze/kernel/prom_parse.c +1 -45
64 lines not on this page · raw message
arch/powerpc/include/asm/pci-bridge.h +0 -5
@@ -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 ;
arch/powerpc/include/asm/prom.h +9 -8
@@ -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. */
arch/powerpc/kernel/prom_parse.c +1 -46
65 lines not on this page · raw message
drivers/of/address.c +51 -0
57 lines not on this page · raw message
include/linux/of_address.h +5 -0
@@ -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 */
Re: [PATCH 2/5] of/address: merge of_address_to_resource()
Quoted 10 lines · Grant Likely
Merge common code between PowerPC and Microblaze. This patch also moves the prototype of
pci_address_to_pio()out ofpci-bridge.hand intoprom.hbecause the only user ofpci_address_to_pio()isof_address_to_resource().Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Grant Likely <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>
Quoted 336 lines
--- 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(-)arch/microblaze/include/asm/pci-bridge.h +0
-5@@ -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 ;arch/microblaze/include/asm/prom.h +9
-8@@ -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. */ arch/microblaze/kernel/prom_parse.c +1
-45@@ -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) {arch/powerpc/include/asm/pci-bridge.h +0
-5@@ -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 ;arch/powerpc/include/asm/prom.h +9
-8@@ -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. */ arch/powerpc/kernel/prom_parse.c +1
-46@@ -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) {drivers/of/address.c +51
-0@@ -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 include/linux/of_address.h +5
-0@@ -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 */
PATCH 5/5 of/address: restrict 'no-ranges' kludge to powerpc
In reply to a message not in the archiveCertain 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.
--- drivers/of/address.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
drivers/of/address.c +10 -1
@@ -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; }
Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
Quoted 3 lines · Grant Likely
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.
Quoted 36 lines
Signed-off-by Grant Likely <grant.likely-s3s/[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>CC linuxppc-dev-uLR06cmDAlY/[email protected]CC devicetree-discuss-uLR06cmDAlY/[email protected]--- drivers/of/address.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)drivers/of/address.c +10
-1@@ -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; }
Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 3 lines · Grant Likely
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.
Quoted 43 lines
Cheers,
Ben.Quoted 36 lines
Signed-off-by Grant Likely <grant.likely-s3s/[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>CC linuxppc-dev-uLR06cmDAlY/[email protected]CC devicetree-discuss-uLR06cmDAlY/[email protected]---
drivers/of/address.c | 11 ++++++++++-1 files changed, 10 insertions(+), 1 deletions(-)drivers/of/address.c +10
-1@@ -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; }
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
A message that is not in the archive (sent off-list or not yet received): AANLkTikg1hLdV_OUjc3QIhFatP_iLfVClhzmyixmjje1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
Quoted 11 lines · Grant Likely
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 3 lines · Grant Likely
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.
Quoted 48 lines
g.
Quoted 43 lines
Cheers,
Ben.Quoted 36 lines
Signed-off-by Grant Likely <grant.likely-s3s/[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>CC linuxppc-dev-uLR06cmDAlY/[email protected]CC devicetree-discuss-uLR06cmDAlY/[email protected]--- drivers/of/address.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)drivers/of/address.c +10
-1@@ -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; }
Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
In reply to Benjamin HerrenschmidtQuoted 6 lines
Quoted 3 lines
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
A message that is not in the archive (sent off-list or not yet received): 1C7A9067-DDE6-47D3-AC78-FDC081354519-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org
Re: [PATCH 5/5] of/address: restrict 'no-ranges' kludge to powerpc
Quoted 5 lines · Segher Boessenkool
Quoted 5 lines
Quoted 4 lines
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.
Quoted 8 lines
Quoted 2 lines
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.
cover Merge common address translation code (ppc & mb)
In reply to a message not in the archiveThese 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.
PATCH 3/5 of/address: Merge all of the bus translation code
In reply to a message not in the archiveMicroblaze 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.
--- 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(-)
arch/microblaze/include/asm/prom.h +0 -4
@@ -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
arch/microblaze/kernel/prom_parse.c +0 -489
502 lines not on this page · raw message
arch/powerpc/include/asm/prom.h +0 -4
@@ -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);
arch/powerpc/kernel/prom_parse.c +0 -515
528 lines not on this page · raw message
drivers/of/address.c +514 -3
525 lines not on this page · raw message
include/linux/of_address.h +1 -3
@@ -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);
Re: [PATCH 3/5] of/address: Merge all of the bus translation code
Quoted 2 lines · Grant Likely
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 ?
Quoted 2 lines
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.
Quoted 1,633 lines
Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>--- 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(-)arch/microblaze/include/asm/prom.h +0
-4@@ -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 arch/microblaze/kernel/prom_parse.c +0
-489@@ -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) {arch/powerpc/include/asm/prom.h +0
-4@@ -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);arch/powerpc/kernel/prom_parse.c +0
-515@@ -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) {drivers/of/address.c +514
-3@@ -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;include/linux/of_address.h +1
-3@@ -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);
Re: [PATCH 3/5] of/address: Merge all of the bus translation code
Quoted 3 lines · Benjamin Herrenschmidt
Quoted 2 lines · Grant Likely
Microblaze and PowerPC share a large chunk of code for translating OF device tree data into usable addresses. =A0There aren't many differen=
ces
Quoted 1 line
=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 ^^^^
Quoted 1 line
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.
Quoted 22 lines
Quoted 2 lines
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.Quoted 10 lines
Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>---
=A0arch/microblaze/include/asm/prom.h =A0| =A0 =A04 =A0arch/microblaze/kernel/prom_parse.c | =A0489 ------------------------=
---------
Quoted 2 lines
Quoted 2 lines
=A0arch/powerpc/include/asm/prom.h =A0 =A0 | =A0 =A04 =A0arch/powerpc/kernel/prom_parse.c =A0 =A0| =A0515 --------------------=
---------------
Quoted 1 line
Quoted 1 line
=A0drivers/of/address.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0517 ++++++++=
+++++++++++++++++++++++++++
Quoted 4 lines
arch/microblaze/includ=
Quoted 4 lines
=A0include/linux/of_address.h =A0 =A0 =A0 =A0 =A0| =A0 =A04 =A06 files changed, 515 insertions(+), 1018 deletions(-)
arch/microblaze/includ= renamed from arch/microblaze/include/asm/prom.h +0
-0
e/asm/prom.h
Quoted 10 lines
arch/microblaze/include/asm/prom.h extern void pci_create_OF_bus_map(void);
Quoted 10 lines
index 644fa32..35cb3de 100644
arch/microblaze/include/asm/prom.h +0
-0@@ -52,10 +52,6 @@ extern void pci_create_OF_bus_map(void);=A0 * OF address retreival & translation
=A0 */arch/microblaze/include/asm/prom.h +0
-3-/* Translate an OF address block into a CPU physical address -*/ -extern u64 of_translate_address(struct device_node *np, const u32 *addr=
);
Quoted 5 lines
arch/microblaze/kerne=
Quoted 5 lines
-
=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 indexarch/microblaze/kerne= renamed from arch/microblaze/kernel/prom_parse.c +0
-0
l/prom_parse.c
Quoted 7 lines
Quoted 7 lines
index 7cb5a98..1d610e6 100644
arch/microblaze/kernel/prom_parse.c +0
-0@@ -10,213 +10,7 @@=A0#include <
asm/prom.h>
=A0#include <asm/pci-bridge.h>
Quoted 5 lines
arch/microblaze/kernel/prom_parse.c
Quoted 5 lines
arch/microblaze/kernel/prom_parse.c +0
-5-#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 && \
Quoted 14 lines
Quoted 14 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (ns) > 0)
arch/microblaze/kernel/prom_parse.c +0
-13- -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
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8-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);
Quoted 1 line
Quoted 1 line
- =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0(*count_cells)(struct
device_node=
*child,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 int *addrc, int *sizec);
Quoted 1 line
Quoted 1 line
- =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 (*map)(u32 *addr, const u32 *range=
,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns=
, int pna);
Quoted 1 line
Quoted 1 line
- =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*translate)(u32 *addr, u64 offset=
, int na);
Quoted 9 lines
arch/microblaze/kernel/prom_parse.c
Quoted 9 lines
- =A0 =A0 unsigned int =A0 =A0(*get_flags)(const u32 *addr);
arch/microblaze/kernel/prom_parse.c +0
-8-}; - -/* -* 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)
Quoted 9 lines
Quoted 9 lines
arch/microblaze/kernel/prom_parse.c +0
-9-{ - =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)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8-{ - =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",
Quoted 29 lines
Quoted 29 lines
- =A0 =A0 =A0 =A0 =A0 =A0 cp, s, da);
arch/microblaze/kernel/prom_parse.c +0
-23- - =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_PCIarch/microblaze/kernel/prom_parse.c +0
-4-/* -* PCI bus specific translator -*/ -
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8-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)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8-{ - =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)
Quoted 5 lines
Quoted 5 lines
arch/microblaze/kernel/prom_parse.c +0
-5-{ - =A0 =A0 u64 cp, s, da; - - =A0 =A0 /* Check address type match */ - =A0 =A0 if ((addr[0] ^ range[0]) & 0x03000000)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 return
OF_BAD_ADDR;arch/microblaze/kernel/prom_parse.c +0
-7- - =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);
Quoted 23 lines
Quoted 23 lines
arch/microblaze/kernel/prom_parse.c +0
-23- - =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;
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 break;
- =A0 =A0 }
- =A0 =A0 if (w &0x40000000)
- =A0 =A0 =A0 =A0 =A0 =A0 flags |=3DIORESOURCE_PREFETCH;
- =A0 =A0 return flags;arch/microblaze/kernel/prom_parse.c +0
-3-} - -const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 =
*size,
Quoted 22 lines
Quoted 22 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
arch/microblaze/kernel/prom_parse.c +0
-21-{ - =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; -
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 /* Get "reg" or "assigned-addresses" property */
- =A0 =A0 prop =3Dof_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++)
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 if ((prop[0] &
0xff) =3D=3D ((bar_no* 4) + PC=
I_BASE_ADDRESS_0)) {
Quoted 2 lines
Quoted 2 lines
- =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);
Quoted 2 lines
Quoted 2 lines
- =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);
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
- =A0 =A0 =A0 =A0 =A0 =A0 }
- =A0 =A0 return NULL;arch/microblaze/kernel/prom_parse.c +0
-5-} -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)
Quoted 13 lines
Quoted 13 lines
arch/microblaze/kernel/prom_parse.c +0
-13-{ - =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)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c int of_irq_map_pci(struct pci_dev *pdev, struct of_=
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-4-{ - =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 structdevice_node*dn, *ppnode;arch/microblaze/kernel/prom_parse.c +0
-0@@ -291,289 +85,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_=
irq *out_irq)
Quoted 14 lines
Quoted 4 lines
arch/microblaze/kernel/prom_parse.c +0
-0=A0EXPORT_SYMBOL_GPL(of_irq_map_pci);=A0#endif /*
CONFIG_PCI*/arch/microblaze/kernel/prom_parse.c +0
-1-/* arch/microblaze/kernel/prom_parse.c int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
Quoted 10 lines
arch/microblaze/kernel/prom_parse.c +0
-10-* 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)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8-{ - =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)
Quoted 5 lines
Quoted 5 lines
arch/microblaze/kernel/prom_parse.c +0
-5-{ - =A0 =A0 u64 cp, s, da; - - =A0 =A0 /* Check address type match */ - =A0 =A0 if ((addr[0] ^ range[0]) & 0x00000001)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 return
OF_BAD_ADDR;arch/microblaze/kernel/prom_parse.c +0
-7- - =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);
Quoted 60 lines
Quoted 60 lines
arch/microblaze/kernel/prom_parse.c +0
-60- - =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 },
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8-}; - -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))
Quoted 6 lines
arch/microblaze/kernel/prom_parse.c
Quoted 6 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return &of_busses[i];
- =A0 =A0BUG();
- =A0 =A0 return NULL;arch/microblaze/kernel/prom_parse.c +0
-3-} - -static int of_translate_one(struct device_node *parent, struct of_bus *=
bus,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct
of_bus*pbus, u32 *addr=
,
Quoted 9 lines
arch/microblaze/kernel/prom_parse.c
Quoted 9 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pna)
arch/microblaze/kernel/prom_parse.c +0
-8-{ - =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
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* below the current not cannot be converted to CPU physical=
ones.
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* Unfortunately, while this is very clear in the spec, it's=
not
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* what Apple understood, and they do have things like /uni-=
n or
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* /ht nodes with no "ranges" property and a lot of perfectl=
y
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* useable mapped devices below them. Thus we treat the abse=
nce of
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* "ranges" as equivalent to an empty "ranges" property whic=
h means
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller no=
t to try
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* to translate addresses that aren't supposed to be transla=
ted in
Quoted 9 lines
Quoted 9 lines
- =A0 =A0 =A0* the first place. --BenH.
- =A0 =A0 =A0*/
- =A0 =A0 ranges =3Dof_get_property(parent, "ranges", (int *) &rlen);
- =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
- =A0 =A0 =A0 =A0 =A0 =A0 offset =3Dof_read_number(addr, na);
- =A0 =A0 =A0 =A0 =A0 =A0memset(addr, 0, pna * 4);
- =A0 =A0 =A0 =A0 =A0 =A0pr_debug("OF: no ranges, 1:1 translation\n");
- =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
- =A0 =A0 }
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c +0
-8- - =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)=
;
Quoted 11 lines
Quoted 11 lines
- =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=3DOF_BAD_ADDR) {
- =A0 =A0 =A0 =A0 =A0 =A0pr_debug("OF: not found !\n");
- =A0 =A0 =A0 =A0 =A0 =A0 return 1;
- =A0 =A0 }
- =A0 =A0memcpy(addr, ranges + na, 4 * pna);
-
- finish:
- =A0 =A0of_dump_addr("OF: parent translation for:", addr, pna);
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0
pr_debug("OF: with offset: "PRu64"\n", offset);arch/microblaze/kernel/prom_parse.c +0
-7- - =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,
Quoted 4 lines
Quoted 4 lines
- * 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
Quoted 1 line
Quoted 1 line
- * that translation is impossible (that is we are not dealing with a va=
lue
Quoted 1 line
Quoted 1 line
- * that can be mapped to a cpu physical address). This is not really sp=
ecified
Quoted 11 lines
arch/microblaze/kernel/prom_parse.c
Quoted 11 lines
- * that way, but this is traditionally the way IBM at least do things
- */arch/microblaze/kernel/prom_parse.c +0
-9-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);
Quoted 6 lines
Quoted 6 lines
arch/microblaze/kernel/prom_parse.c +0
-6- - =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);
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 if (parent =3D=3D NULL)
- =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
- =A0 =A0 bus =3Dof_match_bus(parent);
-
- =A0 =A0 /* Cound address cells & copy address locally */
- =A0 =A0bus->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",
Quoted 11 lines
Quoted 11 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
dev->full_name);
- =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
- =A0 =A0 }
- =A0 =A0memcpy(addr, in_addr, na * 4);arch/microblaze/kernel/prom_parse.c +0
-7- - =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 (;;) {
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 /* Switch to parent bus */
- =A0 =A0 =A0 =A0 =A0 =A0of_node_put(dev);
- =A0 =A0 =A0 =A0 =A0 =A0 dev =3D parent;
- =A0 =A0 =A0 =A0 =A0 =A0 parent =3Dof_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");
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D of_read_number(addr=
, na);
Quoted 8 lines
Quoted 8 lines
- =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 =3Dof_match_bus(parent);
- =A0 =A0 =A0 =A0 =A0 =A0pbus->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",
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev->full_name=
);
Quoted 4 lines
Quoted 4 lines
- =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",
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
pbus->name, pna, pns, parent->=
full_name);
Quoted 3 lines
Quoted 3 lines
-
- =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))
Quoted 8 lines
arch/microblaze/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
arch/microblaze/kernel/prom_parse.c +0
-7- - =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);
Quoted 10 lines
arch/microblaze/kernel/prom_parse.c int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
Quoted 10 lines
- =A0 =A0 }
- bail:
- =A0 =A0of_node_put(parent);
- =A0 =A0of_node_put(dev);arch/microblaze/kernel/prom_parse.c +0
-6- - =A0 =A0 return result; -} -EXPORT_SYMBOL (of_translate_address); - -const u32 *of_get_address(struct device_node *dev, int index, u64 *size=
,
Quoted 18 lines
Quoted 18 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
arch/microblaze/kernel/prom_parse.c +0
-17-{ - =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; -
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 /* Get "reg" or "assigned-addresses" property */
- =A0 =A0 prop =3Dof_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++)
Quoted 3 lines
Quoted 3 lines
- =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);
Quoted 2 lines
Quoted 2 lines
- =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);
Quoted 7 lines
Quoted 7 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
- =A0 =A0 =A0 =A0 =A0 =A0 }
- =A0 =A0 return NULL;arch/microblaze/kernel/prom_parse.c +0
-3-} -EXPORT_SYMBOL (of_get_address); -=A0void of_parse_dma_window(struct
device_node*dn, const void *dma_wind=
ow_prop,
Quoted 1 line
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long *busno, unsigned long *phys, u=
nsigned long *size)
Quoted 2 lines
arch/powerpc/include/asm/=
Quoted 2 lines
=A0{
arch/powerpc/include/asm/= renamed from arch/powerpc/include/asm/prom.h +0
-0
prom.h
Quoted 10 lines
arch/powerpc/include/asm/prom.h
Quoted 10 lines
index e1c1bdd..8e1d0fe 100644
arch/powerpc/include/asm/prom.h +0
-0@@ -45,10 +45,6 @@ extern void pci_create_OF_bus_map(void);=A0 * OF address retreival & translation
=A0 */arch/powerpc/include/asm/prom.h +0
-3-/* Translate an OF address block into a CPU physical address -*/ -extern u64 of_translate_address(struct device_node *np, const u32 *addr=
);
Quoted 4 lines
Quoted 4 lines
-
=A0/* Translate a DMA address from device space to CPU space */ =A0extern u64 of_translate_dma_address(structdevice_node*dev, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cons=
t u32 *in_addr);
Quoted 1 line
arch/powerpc/kernel/prom=
Quoted 1 line
arch/powerpc/kernel/prom= renamed from arch/powerpc/kernel/prom_parse.c +0
-0
_parse.c
Quoted 7 lines
Quoted 7 lines
index a2ef129..64f2606 100644
arch/powerpc/kernel/prom_parse.c +0
-0@@ -10,225 +10,7 @@=A0#include <
asm/prom.h>
=A0#include <asm/pci-bridge.h>
Quoted 15 lines
Quoted 5 lines
arch/powerpc/kernel/prom_parse.c +0
-5-#ifdef DEBUG -#define DBG(fmt...) do { printk(fmt); } while(0) -#else -#define DBG(fmt...) do { } while(0) -#endif arch/powerpc/kernel/prom_parse.c
Quoted 10 lines
arch/powerpc/kernel/prom_parse.c +0
-10- -#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 && \
Quoted 15 lines
Quoted 15 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (ns) > 0)
arch/powerpc/kernel/prom_parse.c +0
-14- -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) { }
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-#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);
Quoted 1 line
Quoted 1 line
- =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0(*count_cells)(struct
device_node=
*child,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0int *addrc, int *sizec);
Quoted 1 line
Quoted 1 line
- =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 (*map)(u32 *addr, const u32 *range=
,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns=
, int pna);
Quoted 1 line
Quoted 1 line
- =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*translate)(u32 *addr, u64 offset=
, int na);
Quoted 10 lines
arch/powerpc/kernel/prom_parse.c
Quoted 10 lines
- =A0 =A0 unsigned int =A0 =A0(*get_flags)(const u32 *addr);
arch/powerpc/kernel/prom_parse.c +0
-9-}; - - -/* -* 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)
Quoted 9 lines
Quoted 9 lines
arch/powerpc/kernel/prom_parse.c +0
-9-{ - =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)
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-{ - =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",
Quoted 30 lines
Quoted 30 lines
- =A0 =A0 =A0 =A0 cp, s, da);
arch/powerpc/kernel/prom_parse.c +0
-24- - =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_PCIarch/powerpc/kernel/prom_parse.c +0
-4-/* -* PCI bus specific translator -*/ -
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-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)
Quoted 19 lines
Quoted 19 lines
arch/powerpc/kernel/prom_parse.c +0
-19-{ - =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;
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 break;
- =A0 =A0 }
- =A0 =A0 if (w &0x40000000)
- =A0 =A0 =A0 =A0 =A0 =A0 flags |=3DIORESOURCE_PREFETCH;
- =A0 =A0 return flags;arch/powerpc/kernel/prom_parse.c +0
-3-} - -static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
Quoted 9 lines
Quoted 9 lines
arch/powerpc/kernel/prom_parse.c +0
-9-{ - =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))
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 return
OF_BAD_ADDR;arch/powerpc/kernel/prom_parse.c +0
-7- - =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);
Quoted 4 lines
Quoted 4 lines
-
- =A0 =A0 if (da < cp || da >=3D (cp + s))
- =A0 =A0 =A0 =A0 =A0 =A0 returnOF_BAD_ADDR;
- =A0 =A0 return da - cp;
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-} - -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,
Quoted 22 lines
Quoted 22 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
arch/powerpc/kernel/prom_parse.c +0
-21-{ - =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; -
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 /* Get "reg" or "assigned-addresses" property */
- =A0 =A0 prop =3Dof_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++)
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 if ((prop[0] &
0xff) =3D=3D ((bar_no* 4) + PC=
I_BASE_ADDRESS_0)) {
Quoted 2 lines
Quoted 2 lines
- =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);
Quoted 2 lines
Quoted 2 lines
- =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);
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
- =A0 =A0 =A0 =A0 =A0 =A0 }
- =A0 =A0 return NULL;arch/powerpc/kernel/prom_parse.c +0
-5-} -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)
Quoted 8 lines
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-{ - =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;
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c int of_irq_map_pci(struct pci_dev *pdev, struct of_=
Quoted 8 lines
- =A0 =A0 return
__of_address_to_resource(dev, addrp, size, flags, r);arch/powerpc/kernel/prom_parse.c +0
-3-} -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 structdevice_node*dn, *ppnode;arch/powerpc/kernel/prom_parse.c +0
-0@@ -310,303 +92,6 @@ int of_irq_map_pci(struct pci_dev *pdev, struct of_=
irq *out_irq)
Quoted 14 lines
Quoted 4 lines
arch/powerpc/kernel/prom_parse.c +0
-0=A0EXPORT_SYMBOL_GPL(of_irq_map_pci);=A0#endif /*
CONFIG_PCI*/arch/powerpc/kernel/prom_parse.c +0
-1-/* arch/powerpc/kernel/prom_parse.c
Quoted 10 lines
arch/powerpc/kernel/prom_parse.c +0
-10-* 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)
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-{ - =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)
Quoted 5 lines
Quoted 5 lines
arch/powerpc/kernel/prom_parse.c +0
-5-{ - =A0 =A0 u64 cp, s, da; - - =A0 =A0 /* Check address type match */ - =A0 =A0 if ((addr[0] ^ range[0]) & 0x00000001)
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 return
OF_BAD_ADDR;arch/powerpc/kernel/prom_parse.c +0
-7- - =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);
Quoted 61 lines
Quoted 61 lines
arch/powerpc/kernel/prom_parse.c +0
-61- - =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 },
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-}; - -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))
Quoted 6 lines
arch/powerpc/kernel/prom_parse.c
Quoted 6 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return &of_busses[i];
- =A0 =A0BUG();
- =A0 =A0 return NULL;arch/powerpc/kernel/prom_parse.c +0
-3-} - -static int of_translate_one(struct device_node *parent, struct of_bus *=
bus,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct
of_bus*pbus, u=
32 *addr,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pn=
a, const char *rprop)
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8-{ - =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
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* below the current not cannot be converted to CPU physical=
ones.
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* Unfortunately, while this is very clear in the spec, it's=
not
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* what Apple understood, and they do have things like /uni-=
n or
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* /ht nodes with no "ranges" property and a lot of perfectl=
y
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* useable mapped devices below them. Thus we treat the abse=
nce of
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* "ranges" as equivalent to an empty "ranges" property whic=
h means
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller no=
t to try
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0* to translate addresses that aren't supposed to be transla=
ted in
Quoted 9 lines
Quoted 9 lines
- =A0 =A0 =A0* the first place. --BenH.
- =A0 =A0 =A0*/
- =A0 =A0 ranges =3Dof_get_property(parent, rprop, &rlen);
- =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
- =A0 =A0 =A0 =A0 =A0 =A0 offset =3Dof_read_number(addr, na);
- =A0 =A0 =A0 =A0 =A0 =A0memset(addr, 0, pna * 4);
- =A0 =A0 =A0 =A0 =A0 =A0DBG("OF: no ranges, 1:1 translation\n");
- =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
- =A0 =A0 }
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8- - =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)=
;
Quoted 12 lines
Quoted 12 lines
- =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=3DOF_BAD_ADDR) {
- =A0 =A0 =A0 =A0 =A0 =A0DBG("OF: not found !\n");
- =A0 =A0 =A0 =A0 =A0 =A0 return 1;
- =A0 =A0 }
- =A0 =A0memcpy(addr, ranges + na, 4 * pna);
-
- finish:
- =A0 =A0of_dump_addr("OF: parent translation for:", addr, pna);
- =A0 =A0DBG("OF: with offset: "PRu64"\n", offset);
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8- - =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,
Quoted 4 lines
Quoted 4 lines
- * 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
Quoted 1 line
Quoted 1 line
- * that translation is impossible (that is we are not dealing with a va=
lue
Quoted 1 line
Quoted 1 line
- * that can be mapped to a cpu physical address). This is not really sp=
ecified
Quoted 18 lines
Quoted 18 lines
- * that way, but this is traditionally the way IBM at least do things
- */arch/powerpc/kernel/prom_parse.c +0
-16-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);
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 if (parent =3D=3D NULL)
- =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
- =A0 =A0 bus =3Dof_match_bus(parent);
-
- =A0 =A0 /* Cound address cells & copy address locally */
- =A0 =A0bus->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",
Quoted 11 lines
Quoted 11 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name);
- =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
- =A0 =A0 }
- =A0 =A0memcpy(addr, in_addr, na * 4);arch/powerpc/kernel/prom_parse.c +0
-7- - =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 (;;) {
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 /* Switch to parent bus */
- =A0 =A0 =A0 =A0 =A0 =A0of_node_put(dev);
- =A0 =A0 =A0 =A0 =A0 =A0 dev =3D parent;
- =A0 =A0 =A0 =A0 =A0 =A0 parent =3Dof_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 =A0DBG("OF: reached root node\n")=
;
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D of_read_number(addr=
, na);
Quoted 8 lines
Quoted 8 lines
- =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 =3Dof_match_bus(parent);
- =A0 =A0 =A0 =A0 =A0 =A0pbus->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",
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name)=
;
Quoted 4 lines
Quoted 4 lines
- =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",
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
pbus->name, pna, pns, parent->full_nam=
e);
Quoted 3 lines
Quoted 3 lines
-
- =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))
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
arch/powerpc/kernel/prom_parse.c +0
-7- - =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);
Quoted 7 lines
Quoted 7 lines
- =A0 =A0 }
- bail:
- =A0 =A0of_node_put(parent);
- =A0 =A0of_node_put(dev);arch/powerpc/kernel/prom_parse.c +0
-3- - =A0 =A0 return result; -}
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +0
-8- -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)
Quoted 6 lines
arch/powerpc/kernel/prom_parse.c int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
Quoted 6 lines
arch/powerpc/kernel/prom_parse.c +0
-6-{ - =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=
,
Quoted 18 lines
Quoted 18 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
arch/powerpc/kernel/prom_parse.c +0
-17-{ - =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; -
Quoted 8 lines
Quoted 8 lines
- =A0 =A0 /* Get "reg" or "assigned-addresses" property */
- =A0 =A0 prop =3Dof_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++)
Quoted 3 lines
Quoted 3 lines
- =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);
Quoted 2 lines
Quoted 2 lines
- =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);
Quoted 7 lines
Quoted 7 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
- =A0 =A0 =A0 =A0 =A0 =A0 }
- =A0 =A0 return NULL;arch/powerpc/kernel/prom_parse.c +0
-3-} -EXPORT_SYMBOL (of_get_address); -=A0void of_parse_dma_window(struct
device_node*dn, const void *dma_wind=
ow_prop,
Quoted 1 line
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long *busno, unsigned long *phys, u=
nsigned long *size)
Quoted 14 lines
Quoted 14 lines
=A0{
drivers/of/address.c +0
-0@@ -1,11 +1,522 @@=A0#include <
linux/io.h>
=A0#include <linux/ioport.h>
+#include <linux/module.h>
=A0#include <linux/of_address.h>drivers/of/address.c +2
-0+#include <linux/pci_regs.h> +#include <linux/string.h>
Quoted 2 lines
Quoted 2 lines
-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,
Quoted 4 lines
drivers/of/address.c
Quoted 4 lines
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct resource *r)
drivers/of/address.c +3
-0+/* 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 && \
Quoted 4 lines
drivers/of/address.c
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (ns) > 0)
drivers/of/address.c +3
-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,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 si=
ze, unsigned int flags,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct=
resource *r);
Quoted 11 lines
Quoted 11 lines
drivers/of/address.c +11
-0+ +/* 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
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+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);
Quoted 1 line
Quoted 1 line
+ =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0(*count_cells)(struct
device_node=
*child,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0int *addrc, int *sizec);
Quoted 1 line
Quoted 1 line
+ =A0 =A0 u64 =A0 =A0 =A0 =A0 =A0 =A0 (*map)(u32 *addr, const u32 *range=
,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns=
, int pna);
Quoted 1 line
Quoted 1 line
+ =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 (*translate)(u32 *addr, u64 offset=
, int na);
Quoted 9 lines
drivers/of/address.c
Quoted 9 lines
+ =A0 =A0 unsigned int =A0 =A0(*get_flags)(const u32 *addr);
drivers/of/address.c +8
-0+}; + +/* +* 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)
Quoted 10 lines
Quoted 10 lines
drivers/of/address.c +10
-0+{ + =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) +{
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
+ =A0 =A0 u64 cp, s, da;
drivers/of/address.c +7
-0+ + =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,
Quoted 29 lines
Quoted 29 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)da);
drivers/of/address.c +28
-0+ + =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 +*/ +
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+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)
Quoted 19 lines
Quoted 19 lines
drivers/of/address.c +19
-0+{ + =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;
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 }
+ =A0 =A0 if (w &0x40000000)
+ =A0 =A0 =A0 =A0 =A0 =A0 flags |=3DIORESOURCE_PREFETCH;
+ =A0 =A0 return flags;drivers/of/address.c +3
-0+} + +static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, =
int pna)
Quoted 10 lines
Quoted 10 lines
drivers/of/address.c +10
-0+{ + =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;
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+ + =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,
Quoted 5 lines
Quoted 5 lines
+ =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 returnOF_BAD_ADDR;
+ =A0 =A0 return da - cp;
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+} + +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,
Quoted 22 lines
Quoted 22 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
drivers/of/address.c +21
-0+{ + =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; +
Quoted 8 lines
Quoted 8 lines
+ =A0 =A0 /* Get "reg" or "assigned-addresses" property */
+ =A0 =A0 prop =3Dof_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++)
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 if ((prop[0] &
0xff) =3D=3D ((bar_no* 4) + PC=
I_BASE_ADDRESS_0)) {
Quoted 2 lines
Quoted 2 lines
+ =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);
Quoted 2 lines
Quoted 2 lines
+ =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);
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
+ =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 return NULL;drivers/of/address.c +5
-0+} +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)
Quoted 16 lines
Quoted 16 lines
drivers/of/address.c +16
-0+{ + =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 +*/
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+ +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)
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+{ + =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)
Quoted 6 lines
Quoted 6 lines
drivers/of/address.c +6
-0+{ + =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;
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+ + =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,
Quoted 61 lines
Quoted 61 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long long)da);
drivers/of/address.c +60
-0+ + =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 },
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+}; + +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))
Quoted 6 lines
drivers/of/address.c
Quoted 6 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return &of_busses[i];
+ =A0 =A0BUG();
+ =A0 =A0 return NULL;drivers/of/address.c +3
-0+} + +static int of_translate_one(struct device_node *parent, struct of_bus *=
bus,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct
of_bus*pbus, u=
32 *addr,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int na, int ns, int pn=
a, const char *rprop)
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+{ + =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
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* below the current not cannot be converted to CPU physical=
ones.
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* Unfortunately, while this is very clear in the spec, it's=
not
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* what Apple understood, and they do have things like /uni-=
n or
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* /ht nodes with no "ranges" property and a lot of perfectl=
y
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* useable mapped devices below them. Thus we treat the abse=
nce of
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* "ranges" as equivalent to an empty "ranges" property whic=
h means
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* a 1:1 translation at that level. It's up to the caller no=
t to try
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0* to translate addresses that aren't supposed to be transla=
ted in
Quoted 9 lines
Quoted 9 lines
+ =A0 =A0 =A0* the first place. --BenH.
+ =A0 =A0 =A0*/
+ =A0 =A0 ranges =3Dof_get_property(parent, rprop, &rlen);
+ =A0 =A0 if (ranges =3D=3D NULL || rlen =3D=3D 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 offset =3Dof_read_number(addr, na);
+ =A0 =A0 =A0 =A0 =A0 =A0memset(addr, 0, pna * 4);
+ =A0 =A0 =A0 =A0 =A0 =A0pr_debug("OF: no ranges, 1:1 translation\n");
+ =A0 =A0 =A0 =A0 =A0 =A0 goto finish;
+ =A0 =A0 }
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+ + =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)=
;
Quoted 4 lines
Quoted 4 lines
+ =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=3DOF_BAD_ADDR) {
Quoted 8 lines
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0
pr_debug("OF: not found !\n");
+ =A0 =A0 =A0 =A0 =A0 =A0 return 1;
+ =A0 =A0 }
+ =A0 =A0memcpy(addr, ranges + na, 4 * pna);
+
+ finish:
+ =A0 =A0of_dump_addr("OF: parent translation for:", addr, pna);
+ =A0 =A0 pr_debug("OF: with offset: %llx\n", (unsigned long long)offset=
);
Quoted 7 lines
drivers/of/address.c
Quoted 7 lines
drivers/of/address.c +7
-0+ + =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,
Quoted 4 lines
Quoted 4 lines
+ * 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
Quoted 1 line
Quoted 1 line
+ * that translation is impossible (that is we are not dealing with a va=
lue
Quoted 1 line
Quoted 1 line
+ * that can be mapped to a cpu physical address). This is not really sp=
ecified
Quoted 4 lines
Quoted 4 lines
+ * that way, but this is traditionally the way IBM at least do things
+ */
+u64 __of_translate_address(structdevice_node*dev, const u32*in_addr,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const char *rprop)
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+{ + =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);
Quoted 6 lines
Quoted 6 lines
drivers/of/address.c +6
-0+ + =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);
Quoted 8 lines
Quoted 8 lines
+ =A0 =A0 if (parent =3D=3D NULL)
+ =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
+ =A0 =A0 bus =3Dof_match_bus(parent);
+
+ =A0 =A0 /* Cound address cells & copy address locally */
+ =A0 =A0bus->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",
Quoted 11 lines
Quoted 11 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name);
+ =A0 =A0 =A0 =A0 =A0 =A0 goto bail;
+ =A0 =A0 }
+ =A0 =A0memcpy(addr, in_addr, na * 4);drivers/of/address.c +7
-0+ + =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 (;;) {
Quoted 8 lines
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 /* Switch to parent bus */
+ =A0 =A0 =A0 =A0 =A0 =A0of_node_put(dev);
+ =A0 =A0 =A0 =A0 =A0 =A0 dev =3D parent;
+ =A0 =A0 =A0 =A0 =A0 =A0 parent =3Dof_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");
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D of_read_number(addr=
, na);
Quoted 8 lines
Quoted 8 lines
+ =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 =3Dof_match_bus(parent);
+ =A0 =A0 =A0 =A0 =A0 =A0pbus->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",
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->full_name)=
;
Quoted 4 lines
Quoted 4 lines
+ =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",
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
pbus->name, pna, pns, parent->full_nam=
e);
Quoted 3 lines
Quoted 3 lines
+
+ =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))
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
drivers/of/address.c +7
-0+ + =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);
Quoted 7 lines
Quoted 7 lines
+ =A0 =A0 }
+ bail:
+ =A0 =A0of_node_put(parent);
+ =A0 =A0of_node_put(dev);drivers/of/address.c +3
-0+ + =A0 =A0 return result; +}
Quoted 8 lines
drivers/of/address.c
Quoted 8 lines
drivers/of/address.c +8
-0+ +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)
Quoted 6 lines
drivers/of/address.c
Quoted 6 lines
drivers/of/address.c +6
-0+{ + =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=
,
Quoted 18 lines
Quoted 18 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int *flags)
drivers/of/address.c +17
-0+{ + =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; +
Quoted 8 lines
Quoted 8 lines
+ =A0 =A0 /* Get "reg" or "assigned-addresses" property */
+ =A0 =A0 prop =3Dof_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++)
Quoted 3 lines
Quoted 3 lines
+ =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);
Quoted 2 lines
Quoted 2 lines
+ =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);
Quoted 7 lines
drivers/of/address.c
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return prop;
+ =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 return NULL;drivers/of/address.c +4
-0+} +EXPORT_SYMBOL (of_get_address); + +static int __of_address_to_resource(struct device_node *dev, const u32 =
*addrp,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 si=
ze, unsigned int flags,
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct=
resource *r)
Quoted 11 lines
Quoted 11 lines
=A0{
=A0 =A0 =A0 u64 taddr;include/linux/of_address.h +0
-0@@ -3,9 +3,7 @@=A0#include <
linux/ioport.h>
=A0#include <linux/of.h>
Quoted 1 line
Quoted 1 line
-extern int __of_address_to_resource(struct
device_node*dev, const u32 =
*addrp,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 si=
ze, unsigned int flags,
Quoted 1 line
Quoted 1 line
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct=
resource *r);
Quoted 1 line
Quoted 1 line
+extern u64 of_translate_address(struct
device_node*np, const u32 *addr=
);
Quoted 2 lines
Quoted 2 lines
=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);
Quoted 4 lines
Quoted 1 line
=A0extern void
__iomem*of_iomap(structdevice_node*device, int index);
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Re: [PATCH 3/5] of/address: Merge all of the bus translation code
On Thu, Jun 10, 2010 at 8:26 AM, Grant Likely <[email protected]> w= rote:
Quoted 5 lines
Quoted 3 lines · Benjamin Herrenschmidt
Quoted 2 lines · Grant Likely
Microblaze and PowerPC share a large chunk of code for translating OF device tree data into usable addresses. =A0There aren't many differe=
nces
Quoted 1 line
Quoted 1 line
=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 ^^^^
Quoted 15 lines
Quoted 1 line
Care to comment on these differences ?
Purely cosmetic IIRC, but I will go back and double check. =A0Things like printk vs.
pr_infoand some style differences. =A0I looked at them side-by-side and fixed each difference individually until they were identical.Quoted 8 lines
Quoted 2 lines
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.
Quoted 11 lines
Quoted 11 lines
Cheers,
Ben.Quoted 7 lines
Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>
Re: [PATCH 3/5] of/address: Merge all of the bus translation code
Quoted 25 lines · Grant Likely
Quoted 5 lines · Grant Likely
Quoted 3 lines · Benjamin Herrenschmidt
Quoted 2 lines · Grant Likely
Microblaze and PowerPC share a large chunk of code for translating OF device tree data into usable addresses. There aren't many differences
Quoted 16 lines
Quoted 2 lines
^^^^Care to comment on these differences ?
Purely cosmetic IIRC, but I will go back and double check. Things like printk vs.
pr_infoand some style differences. I looked at them side-by-side and fixed each difference individually until they were identical.Quoted 8 lines
Quoted 2 lines
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,
Quoted 8 lines
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_debugvs 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.
Quoted 29 lines
----
of/address: Merge all of the bus translation codeMicroblaze 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.Quoted 11 lines
Quoted 11 lines
Cheers,
Ben.Quoted 7 lines
Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>CC Benjamin Herrenschmidt <[email protected]>
PATCH 4/5 of/address: little-endian fixes
In reply to a message not in the archiveFix some endian issues in the OF address translation code.
--- drivers/of/address.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
drivers/of/address.c +7 -5
@@ -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);
Re: [PATCH 4/5] of/address: little-endian fixes
Quoted 6 lines · Grant Likely
Fix some endian issues in the OF address translation code.
Signed-off-by Grant Likely <[email protected]>CC Michal Simek <[email protected]>CC Wolfram Sang <[email protected]>CC Stephen Rothwell <[email protected]>
Quoted 49 lines
--- drivers/of/address.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)drivers/of/address.c +7
-5@@ -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);