License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / include / linux / of_address.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __OF_ADDRESS_H
3 #define __OF_ADDRESS_H
4 #include <linux/ioport.h>
5 #include <linux/errno.h>
6 #include <linux/of.h>
7 #include <linux/io.h>
8
9 struct of_pci_range_parser {
10 struct device_node *node;
11 const __be32 *range;
12 const __be32 *end;
13 int np;
14 int pna;
15 };
16
17 struct of_pci_range {
18 u32 pci_space;
19 u64 pci_addr;
20 u64 cpu_addr;
21 u64 size;
22 u32 flags;
23 };
24
25 #define for_each_of_pci_range(parser, range) \
26 for (; of_pci_range_parser_one(parser, range);)
27
28 /* Translate a DMA address from device space to CPU space */
29 extern u64 of_translate_dma_address(struct device_node *dev,
30 const __be32 *in_addr);
31
32 #ifdef CONFIG_OF_ADDRESS
33 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
34 extern int of_address_to_resource(struct device_node *dev, int index,
35 struct resource *r);
36 extern struct device_node *of_find_matching_node_by_address(
37 struct device_node *from,
38 const struct of_device_id *matches,
39 u64 base_address);
40 extern void __iomem *of_iomap(struct device_node *device, int index);
41 void __iomem *of_io_request_and_map(struct device_node *device,
42 int index, const char *name);
43
44 /* Extract an address from a device, returns the region size and
45 * the address space flags too. The PCI version uses a BAR number
46 * instead of an absolute index
47 */
48 extern const __be32 *of_get_address(struct device_node *dev, int index,
49 u64 *size, unsigned int *flags);
50
51 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
52 struct device_node *node);
53 extern struct of_pci_range *of_pci_range_parser_one(
54 struct of_pci_range_parser *parser,
55 struct of_pci_range *range);
56 extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
57 u64 *paddr, u64 *size);
58 extern bool of_dma_is_coherent(struct device_node *np);
59 #else /* CONFIG_OF_ADDRESS */
60 static inline void __iomem *of_io_request_and_map(struct device_node *device,
61 int index, const char *name)
62 {
63 return IOMEM_ERR_PTR(-EINVAL);
64 }
65
66 static inline u64 of_translate_address(struct device_node *np,
67 const __be32 *addr)
68 {
69 return OF_BAD_ADDR;
70 }
71
72 static inline struct device_node *of_find_matching_node_by_address(
73 struct device_node *from,
74 const struct of_device_id *matches,
75 u64 base_address)
76 {
77 return NULL;
78 }
79
80 static inline const __be32 *of_get_address(struct device_node *dev, int index,
81 u64 *size, unsigned int *flags)
82 {
83 return NULL;
84 }
85
86 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
87 struct device_node *node)
88 {
89 return -1;
90 }
91
92 static inline struct of_pci_range *of_pci_range_parser_one(
93 struct of_pci_range_parser *parser,
94 struct of_pci_range *range)
95 {
96 return NULL;
97 }
98
99 static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
100 u64 *paddr, u64 *size)
101 {
102 return -ENODEV;
103 }
104
105 static inline bool of_dma_is_coherent(struct device_node *np)
106 {
107 return false;
108 }
109 #endif /* CONFIG_OF_ADDRESS */
110
111 #ifdef CONFIG_OF
112 extern int of_address_to_resource(struct device_node *dev, int index,
113 struct resource *r);
114 void __iomem *of_iomap(struct device_node *node, int index);
115 #else
116 static inline int of_address_to_resource(struct device_node *dev, int index,
117 struct resource *r)
118 {
119 return -EINVAL;
120 }
121
122 static inline void __iomem *of_iomap(struct device_node *device, int index)
123 {
124 return NULL;
125 }
126 #endif
127
128 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
129 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
130 u64 *size, unsigned int *flags);
131 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
132 struct resource *r);
133 extern int of_pci_range_to_resource(struct of_pci_range *range,
134 struct device_node *np,
135 struct resource *res);
136 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
137 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
138 struct resource *r)
139 {
140 return -ENOSYS;
141 }
142
143 static inline const __be32 *of_get_pci_address(struct device_node *dev,
144 int bar_no, u64 *size, unsigned int *flags)
145 {
146 return NULL;
147 }
148 static inline int of_pci_range_to_resource(struct of_pci_range *range,
149 struct device_node *np,
150 struct resource *res)
151 {
152 return -ENOSYS;
153 }
154 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
155
156 #endif /* __OF_ADDRESS_H */
157