Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[linux-2.6.git] / include / linux / of_address.h
blob4c2e6f26432cfe5b0260fecb0caa5a15601482e8
1 #ifndef __OF_ADDRESS_H
2 #define __OF_ADDRESS_H
3 #include <linux/ioport.h>
4 #include <linux/errno.h>
5 #include <linux/of.h>
7 struct of_pci_range_parser {
8 struct device_node *node;
9 const __be32 *range;
10 const __be32 *end;
11 int np;
12 int pna;
15 struct of_pci_range {
16 u32 pci_space;
17 u64 pci_addr;
18 u64 cpu_addr;
19 u64 size;
20 u32 flags;
23 #define for_each_of_pci_range(parser, range) \
24 for (; of_pci_range_parser_one(parser, range);)
26 static inline void of_pci_range_to_resource(struct of_pci_range *range,
27 struct device_node *np,
28 struct resource *res)
30 res->flags = range->flags;
31 res->start = range->cpu_addr;
32 res->end = range->cpu_addr + range->size - 1;
33 res->parent = res->child = res->sibling = NULL;
34 res->name = np->full_name;
37 #ifdef CONFIG_OF_ADDRESS
38 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
39 extern bool of_can_translate_address(struct device_node *dev);
40 extern int of_address_to_resource(struct device_node *dev, int index,
41 struct resource *r);
42 extern struct device_node *of_find_matching_node_by_address(
43 struct device_node *from,
44 const struct of_device_id *matches,
45 u64 base_address);
46 extern void __iomem *of_iomap(struct device_node *device, int index);
48 /* Extract an address from a device, returns the region size and
49 * the address space flags too. The PCI version uses a BAR number
50 * instead of an absolute index
52 extern const __be32 *of_get_address(struct device_node *dev, int index,
53 u64 *size, unsigned int *flags);
55 #ifndef pci_address_to_pio
56 static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
57 #define pci_address_to_pio pci_address_to_pio
58 #endif
60 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
61 struct device_node *node);
62 extern struct of_pci_range *of_pci_range_parser_one(
63 struct of_pci_range_parser *parser,
64 struct of_pci_range *range);
65 #else /* CONFIG_OF_ADDRESS */
66 #ifndef of_address_to_resource
67 static inline int of_address_to_resource(struct device_node *dev, int index,
68 struct resource *r)
70 return -EINVAL;
72 #endif
73 static inline struct device_node *of_find_matching_node_by_address(
74 struct device_node *from,
75 const struct of_device_id *matches,
76 u64 base_address)
78 return NULL;
80 #ifndef of_iomap
81 static inline void __iomem *of_iomap(struct device_node *device, int index)
83 return NULL;
85 #endif
86 static inline const __be32 *of_get_address(struct device_node *dev, int index,
87 u64 *size, unsigned int *flags)
89 return NULL;
92 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
93 struct device_node *node)
95 return -1;
98 static inline struct of_pci_range *of_pci_range_parser_one(
99 struct of_pci_range_parser *parser,
100 struct of_pci_range *range)
102 return NULL;
104 #endif /* CONFIG_OF_ADDRESS */
107 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
108 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
109 u64 *size, unsigned int *flags);
110 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
111 struct resource *r);
112 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
113 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
114 struct resource *r)
116 return -ENOSYS;
119 static inline const __be32 *of_get_pci_address(struct device_node *dev,
120 int bar_no, u64 *size, unsigned int *flags)
122 return NULL;
124 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
126 #endif /* __OF_ADDRESS_H */