aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:09 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:26 -0400
commit1f5bef30cf6c66f097ea5dfc580a41924df888d1 (patch)
tree345d9db4b6b20de814599cb7129005abd945ceea
parent6b884a8d50a6eea2fb3dad7befe748f67193073b (diff)
of/address: merge of_address_to_resource()
Merge common code between PowerPC and Microblaze. This patch also moves the prototype of pci_address_to_pio() out of pci-bridge.h and into prom.h because the only user of pci_address_to_pio() is of_address_to_resource(). Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> CC: Michal Simek <monstr@monstr.eu> CC: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r--arch/microblaze/include/asm/pci-bridge.h5
-rw-r--r--arch/microblaze/include/asm/prom.h17
-rw-r--r--arch/microblaze/kernel/prom_parse.c46
-rw-r--r--arch/powerpc/include/asm/pci-bridge.h5
-rw-r--r--arch/powerpc/include/asm/prom.h17
-rw-r--r--arch/powerpc/kernel/prom_parse.c47
-rw-r--r--drivers/of/address.c51
-rw-r--r--include/linux/of_address.h5
8 files changed, 76 insertions, 117 deletions
diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h
index 0c77cda9f5d8..0c68764ab547 100644
--- a/arch/microblaze/include/asm/pci-bridge.h
+++ b/arch/microblaze/include/asm/pci-bridge.h
@@ -172,13 +172,8 @@ static inline int pci_has_flag(int flag)
172 172
173extern struct list_head hose_list; 173extern struct list_head hose_list;
174 174
175extern unsigned long pci_address_to_pio(phys_addr_t address);
176extern int pcibios_vaddr_is_ioport(void __iomem *address); 175extern int pcibios_vaddr_is_ioport(void __iomem *address);
177#else 176#else
178static inline unsigned long pci_address_to_pio(phys_addr_t address)
179{
180 return (unsigned long)-1;
181}
182static inline int pcibios_vaddr_is_ioport(void __iomem *address) 177static inline int pcibios_vaddr_is_ioport(void __iomem *address)
183{ 178{
184 return 0; 179 return 0;
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
index 6411c3b3a80f..4e94c0706c50 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -65,17 +65,18 @@ extern const u32 *of_get_address(struct device_node *dev, int index,
65extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no, 65extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
66 u64 *size, unsigned int *flags); 66 u64 *size, unsigned int *flags);
67 67
68/* Get an address as a resource. Note that if your address is
69 * a PIO address, the conversion will fail if the physical address
70 * can't be internally converted to an IO token with
71 * pci_address_to_pio(), that is because it's either called to early
72 * or it can't be matched to any host bridge IO space
73 */
74extern int of_address_to_resource(struct device_node *dev, int index,
75 struct resource *r);
76extern int of_pci_address_to_resource(struct device_node *dev, int bar, 68extern int of_pci_address_to_resource(struct device_node *dev, int bar,
77 struct resource *r); 69 struct resource *r);
78 70
71#ifdef CONFIG_PCI
72extern unsigned long pci_address_to_pio(phys_addr_t address);
73#else
74static inline unsigned long pci_address_to_pio(phys_addr_t address)
75{
76 return (unsigned long)-1;
77}
78#endif /* CONFIG_PCI */
79
79/* Parse the ibm,dma-window property of an OF node into the busno, phys and 80/* Parse the ibm,dma-window property of an OF node into the busno, phys and
80 * size parameters. 81 * size parameters.
81 */ 82 */
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
index 1159ba52ad4a..2f9cdd26ca12 100644
--- a/arch/microblaze/kernel/prom_parse.c
+++ b/arch/microblaze/kernel/prom_parse.c
@@ -6,6 +6,7 @@
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/ioport.h> 7#include <linux/ioport.h>
8#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
9#include <linux/of_address.h>
9#include <asm/prom.h> 10#include <asm/prom.h>
10#include <asm/pci-bridge.h> 11#include <asm/pci-bridge.h>
11 12
@@ -17,9 +18,6 @@
17 (ns) > 0) 18 (ns) > 0)
18 19
19static struct of_bus *of_match_bus(struct device_node *np); 20static struct of_bus *of_match_bus(struct device_node *np);
20static int __of_address_to_resource(struct device_node *dev,
21 const u32 *addrp, u64 size, unsigned int flags,
22 struct resource *r);
23 21
24/* Debug utility */ 22/* Debug utility */
25#ifdef DEBUG 23#ifdef DEBUG
@@ -576,48 +574,6 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
576} 574}
577EXPORT_SYMBOL(of_get_address); 575EXPORT_SYMBOL(of_get_address);
578 576
579static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
580 u64 size, unsigned int flags,
581 struct resource *r)
582{
583 u64 taddr;
584
585 if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
586 return -EINVAL;
587 taddr = of_translate_address(dev, addrp);
588 if (taddr == OF_BAD_ADDR)
589 return -EINVAL;
590 memset(r, 0, sizeof(struct resource));
591 if (flags & IORESOURCE_IO) {
592 unsigned long port;
593 port = -1; /* pci_address_to_pio(taddr); */
594 if (port == (unsigned long)-1)
595 return -EINVAL;
596 r->start = port;
597 r->end = port + size - 1;
598 } else {
599 r->start = taddr;
600 r->end = taddr + size - 1;
601 }
602 r->flags = flags;
603 r->name = dev->name;
604 return 0;
605}
606
607int of_address_to_resource(struct device_node *dev, int index,
608 struct resource *r)
609{
610 const u32 *addrp;
611 u64 size;
612 unsigned int flags;
613
614 addrp = of_get_address(dev, index, &size, &flags);
615 if (addrp == NULL)
616 return -EINVAL;
617 return __of_address_to_resource(dev, addrp, size, flags, r);
618}
619EXPORT_SYMBOL_GPL(of_address_to_resource);
620
621void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, 577void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
622 unsigned long *busno, unsigned long *phys, unsigned long *size) 578 unsigned long *busno, unsigned long *phys, unsigned long *size)
623{ 579{
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index 76e1f313a58e..51e9e6f90d12 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -303,13 +303,8 @@ extern void pcibios_free_controller(struct pci_controller *phb);
303extern void pcibios_setup_phb_resources(struct pci_controller *hose); 303extern void pcibios_setup_phb_resources(struct pci_controller *hose);
304 304
305#ifdef CONFIG_PCI 305#ifdef CONFIG_PCI
306extern unsigned long pci_address_to_pio(phys_addr_t address);
307extern int pcibios_vaddr_is_ioport(void __iomem *address); 306extern int pcibios_vaddr_is_ioport(void __iomem *address);
308#else 307#else
309static inline unsigned long pci_address_to_pio(phys_addr_t address)
310{
311 return (unsigned long)-1;
312}
313static inline int pcibios_vaddr_is_ioport(void __iomem *address) 308static inline int pcibios_vaddr_is_ioport(void __iomem *address)
314{ 309{
315 return 0; 310 return 0;
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index 0abe379c6f33..ceace966c51c 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -70,14 +70,6 @@ static inline const u32 *of_get_pci_address(struct device_node *dev,
70} 70}
71#endif /* CONFIG_PCI */ 71#endif /* CONFIG_PCI */
72 72
73/* Get an address as a resource. Note that if your address is
74 * a PIO address, the conversion will fail if the physical address
75 * can't be internally converted to an IO token with
76 * pci_address_to_pio(), that is because it's either called to early
77 * or it can't be matched to any host bridge IO space
78 */
79extern int of_address_to_resource(struct device_node *dev, int index,
80 struct resource *r);
81#ifdef CONFIG_PCI 73#ifdef CONFIG_PCI
82extern int of_pci_address_to_resource(struct device_node *dev, int bar, 74extern int of_pci_address_to_resource(struct device_node *dev, int bar,
83 struct resource *r); 75 struct resource *r);
@@ -89,6 +81,15 @@ static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
89} 81}
90#endif /* CONFIG_PCI */ 82#endif /* CONFIG_PCI */
91 83
84#ifdef CONFIG_PCI
85extern unsigned long pci_address_to_pio(phys_addr_t address);
86#else
87static inline unsigned long pci_address_to_pio(phys_addr_t address)
88{
89 return (unsigned long)-1;
90}
91#endif /* CONFIG_PCI */
92
92/* Parse the ibm,dma-window property of an OF node into the busno, phys and 93/* Parse the ibm,dma-window property of an OF node into the busno, phys and
93 * size parameters. 94 * size parameters.
94 */ 95 */
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 1d5d4f6dfef5..1dac535de78f 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -6,6 +6,7 @@
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/ioport.h> 7#include <linux/ioport.h>
8#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
9#include <linux/of_address.h>
9#include <asm/prom.h> 10#include <asm/prom.h>
10#include <asm/pci-bridge.h> 11#include <asm/pci-bridge.h>
11 12
@@ -27,10 +28,6 @@
27 (ns) > 0) 28 (ns) > 0)
28 29
29static struct of_bus *of_match_bus(struct device_node *np); 30static struct of_bus *of_match_bus(struct device_node *np);
30static int __of_address_to_resource(struct device_node *dev,
31 const u32 *addrp, u64 size, unsigned int flags,
32 struct resource *r);
33
34 31
35/* Debug utility */ 32/* Debug utility */
36#ifdef DEBUG 33#ifdef DEBUG
@@ -610,48 +607,6 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
610} 607}
611EXPORT_SYMBOL(of_get_address); 608EXPORT_SYMBOL(of_get_address);
612 609
613static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
614 u64 size, unsigned int flags,
615 struct resource *r)
616{
617 u64 taddr;
618
619 if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
620 return -EINVAL;
621 taddr = of_translate_address(dev, addrp);
622 if (taddr == OF_BAD_ADDR)
623 return -EINVAL;
624 memset(r, 0, sizeof(struct resource));
625 if (flags & IORESOURCE_IO) {
626 unsigned long port;
627 port = pci_address_to_pio(taddr);
628 if (port == (unsigned long)-1)
629 return -EINVAL;
630 r->start = port;
631 r->end = port + size - 1;
632 } else {
633 r->start = taddr;
634 r->end = taddr + size - 1;
635 }
636 r->flags = flags;
637 r->name = dev->name;
638 return 0;
639}
640
641int of_address_to_resource(struct device_node *dev, int index,
642 struct resource *r)
643{
644 const u32 *addrp;
645 u64 size;
646 unsigned int flags;
647
648 addrp = of_get_address(dev, index, &size, &flags);
649 if (addrp == NULL)
650 return -EINVAL;
651 return __of_address_to_resource(dev, addrp, size, flags, r);
652}
653EXPORT_SYMBOL_GPL(of_address_to_resource);
654
655void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, 610void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
656 unsigned long *busno, unsigned long *phys, unsigned long *size) 611 unsigned long *busno, unsigned long *phys, unsigned long *size)
657{ 612{
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 258528d6c4fe..c3819550f907 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -3,6 +3,57 @@
3#include <linux/ioport.h> 3#include <linux/ioport.h>
4#include <linux/of_address.h> 4#include <linux/of_address.h>
5 5
6int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
7 u64 size, unsigned int flags,
8 struct resource *r)
9{
10 u64 taddr;
11
12 if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
13 return -EINVAL;
14 taddr = of_translate_address(dev, addrp);
15 if (taddr == OF_BAD_ADDR)
16 return -EINVAL;
17 memset(r, 0, sizeof(struct resource));
18 if (flags & IORESOURCE_IO) {
19 unsigned long port;
20 port = pci_address_to_pio(taddr);
21 if (port == (unsigned long)-1)
22 return -EINVAL;
23 r->start = port;
24 r->end = port + size - 1;
25 } else {
26 r->start = taddr;
27 r->end = taddr + size - 1;
28 }
29 r->flags = flags;
30 r->name = dev->name;
31 return 0;
32}
33
34/**
35 * of_address_to_resource - Translate device tree address and return as resource
36 *
37 * Note that if your address is a PIO address, the conversion will fail if
38 * the physical address can't be internally converted to an IO token with
39 * pci_address_to_pio(), that is because it's either called to early or it
40 * can't be matched to any host bridge IO space
41 */
42int of_address_to_resource(struct device_node *dev, int index,
43 struct resource *r)
44{
45 const u32 *addrp;
46 u64 size;
47 unsigned int flags;
48
49 addrp = of_get_address(dev, index, &size, &flags);
50 if (addrp == NULL)
51 return -EINVAL;
52 return __of_address_to_resource(dev, addrp, size, flags, r);
53}
54EXPORT_SYMBOL_GPL(of_address_to_resource);
55
56
6/** 57/**
7 * of_iomap - Maps the memory mapped IO for a given device_node 58 * of_iomap - Maps the memory mapped IO for a given device_node
8 * @device: the device whose io range will be mapped 59 * @device: the device whose io range will be mapped
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 570831d7e795..474b794ed9d2 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -3,6 +3,11 @@
3#include <linux/ioport.h> 3#include <linux/ioport.h>
4#include <linux/of.h> 4#include <linux/of.h>
5 5
6extern int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
7 u64 size, unsigned int flags,
8 struct resource *r);
9extern int of_address_to_resource(struct device_node *dev, int index,
10 struct resource *r);
6extern void __iomem *of_iomap(struct device_node *device, int index); 11extern void __iomem *of_iomap(struct device_node *device, int index);
7 12
8#endif /* __OF_ADDRESS_H */ 13#endif /* __OF_ADDRESS_H */