Linux 4.6-rc6
[cris-mirror.git] / include / linux / of_address.h
blob01c0a556448b227e6cbc4717a78d62d399d64494
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>
6 #include <linux/io.h>
8 struct of_pci_range_parser {
9 struct device_node *node;
10 const __be32 *range;
11 const __be32 *end;
12 int np;
13 int pna;
16 struct of_pci_range {
17 u32 pci_space;
18 u64 pci_addr;
19 u64 cpu_addr;
20 u64 size;
21 u32 flags;
24 #define for_each_of_pci_range(parser, range) \
25 for (; of_pci_range_parser_one(parser, range);)
27 /* Translate a DMA address from device space to CPU space */
28 extern u64 of_translate_dma_address(struct device_node *dev,
29 const __be32 *in_addr);
31 #ifdef CONFIG_OF_ADDRESS
32 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
33 extern int of_address_to_resource(struct device_node *dev, int index,
34 struct resource *r);
35 extern struct device_node *of_find_matching_node_by_address(
36 struct device_node *from,
37 const struct of_device_id *matches,
38 u64 base_address);
39 extern void __iomem *of_iomap(struct device_node *device, int index);
40 void __iomem *of_io_request_and_map(struct device_node *device,
41 int index, const char *name);
43 /* Extract an address from a device, returns the region size and
44 * the address space flags too. The PCI version uses a BAR number
45 * instead of an absolute index
47 extern const __be32 *of_get_address(struct device_node *dev, int index,
48 u64 *size, unsigned int *flags);
50 extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
51 extern unsigned long pci_address_to_pio(phys_addr_t addr);
52 extern phys_addr_t pci_pio_to_address(unsigned long pio);
54 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
55 struct device_node *node);
56 extern struct of_pci_range *of_pci_range_parser_one(
57 struct of_pci_range_parser *parser,
58 struct of_pci_range *range);
59 extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
60 u64 *paddr, u64 *size);
61 extern bool of_dma_is_coherent(struct device_node *np);
62 #else /* CONFIG_OF_ADDRESS */
63 static inline void __iomem *of_io_request_and_map(struct device_node *device,
64 int index, const char *name)
66 return IOMEM_ERR_PTR(-EINVAL);
69 static inline u64 of_translate_address(struct device_node *np,
70 const __be32 *addr)
72 return OF_BAD_ADDR;
75 static inline struct device_node *of_find_matching_node_by_address(
76 struct device_node *from,
77 const struct of_device_id *matches,
78 u64 base_address)
80 return NULL;
83 static inline const __be32 *of_get_address(struct device_node *dev, int index,
84 u64 *size, unsigned int *flags)
86 return NULL;
89 static inline phys_addr_t pci_pio_to_address(unsigned long pio)
91 return 0;
94 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
95 struct device_node *node)
97 return -1;
100 static inline struct of_pci_range *of_pci_range_parser_one(
101 struct of_pci_range_parser *parser,
102 struct of_pci_range *range)
104 return NULL;
107 static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
108 u64 *paddr, u64 *size)
110 return -ENODEV;
113 static inline bool of_dma_is_coherent(struct device_node *np)
115 return false;
117 #endif /* CONFIG_OF_ADDRESS */
119 #ifdef CONFIG_OF
120 extern int of_address_to_resource(struct device_node *dev, int index,
121 struct resource *r);
122 void __iomem *of_iomap(struct device_node *node, int index);
123 #else
124 static inline int of_address_to_resource(struct device_node *dev, int index,
125 struct resource *r)
127 return -EINVAL;
130 static inline void __iomem *of_iomap(struct device_node *device, int index)
132 return NULL;
134 #endif
136 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
137 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
138 u64 *size, unsigned int *flags);
139 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
140 struct resource *r);
141 extern int of_pci_range_to_resource(struct of_pci_range *range,
142 struct device_node *np,
143 struct resource *res);
144 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
145 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
146 struct resource *r)
148 return -ENOSYS;
151 static inline const __be32 *of_get_pci_address(struct device_node *dev,
152 int bar_no, u64 *size, unsigned int *flags)
154 return NULL;
156 static inline int of_pci_range_to_resource(struct of_pci_range *range,
157 struct device_node *np,
158 struct resource *res)
160 return -ENOSYS;
162 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
164 #endif /* __OF_ADDRESS_H */