diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2010-06-08 09:48:09 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-07-05 18:14:26 -0400 |
commit | 1f5bef30cf6c66f097ea5dfc580a41924df888d1 (patch) | |
tree | 345d9db4b6b20de814599cb7129005abd945ceea /drivers/of | |
parent | 6b884a8d50a6eea2fb3dad7befe748f67193073b (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>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/address.c | 51 |
1 files changed, 51 insertions, 0 deletions
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 | ||
6 | int __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 | */ | ||
42 | int 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 | } | ||
54 | EXPORT_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 |