Merge tag 'platform-drivers-x86-v5.18-1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / linux / of_address.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6b884a8d
GL
2#ifndef __OF_ADDRESS_H
3#define __OF_ADDRESS_H
4#include <linux/ioport.h>
99ce39e3 5#include <linux/errno.h>
6b884a8d 6#include <linux/of.h>
fcd71d9c 7#include <linux/io.h>
6b884a8d 8
2f96593e
JY
9struct of_bus;
10
29b635c0
AM
11struct of_pci_range_parser {
12 struct device_node *node;
2f96593e 13 struct of_bus *bus;
29b635c0
AM
14 const __be32 *range;
15 const __be32 *end;
bc5e522e
RH
16 int na;
17 int ns;
29b635c0 18 int pna;
645c1386 19 bool dma;
29b635c0 20};
bc5e522e 21#define of_range_parser of_pci_range_parser
29b635c0
AM
22
23struct of_pci_range {
bc5e522e
RH
24 union {
25 u64 pci_addr;
26 u64 bus_addr;
27 };
29b635c0
AM
28 u64 cpu_addr;
29 u64 size;
30 u32 flags;
31};
bc5e522e 32#define of_range of_pci_range
29b635c0
AM
33
34#define for_each_of_pci_range(parser, range) \
35 for (; of_pci_range_parser_one(parser, range);)
bc5e522e 36#define for_each_of_range for_each_of_pci_range
29b635c0 37
d0dfa16a
RH
38/* Translate a DMA address from device space to CPU space */
39extern u64 of_translate_dma_address(struct device_node *dev,
40 const __be32 *in_addr);
41
a850a755 42#ifdef CONFIG_OF_ADDRESS
0131d897 43extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
1f5bef30
GL
44extern int of_address_to_resource(struct device_node *dev, int index,
45 struct resource *r);
6b884a8d 46extern void __iomem *of_iomap(struct device_node *device, int index);
fcd71d9c
SM
47void __iomem *of_io_request_and_map(struct device_node *device,
48 int index, const char *name);
6b884a8d 49
22ae782f
GL
50/* Extract an address from a device, returns the region size and
51 * the address space flags too. The PCI version uses a BAR number
52 * instead of an absolute index
53 */
050a2c62
RH
54extern const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
55 u64 *size, unsigned int *flags);
22ae782f 56
29b635c0
AM
57extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
58 struct device_node *node);
a060c210
MG
59extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
60 struct device_node *node);
29b635c0
AM
61extern struct of_pci_range *of_pci_range_parser_one(
62 struct of_pci_range_parser *parser,
63 struct of_pci_range *range);
c3c0dc75
RH
64extern int of_pci_address_to_resource(struct device_node *dev, int bar,
65 struct resource *r);
66extern int of_pci_range_to_resource(struct of_pci_range *range,
67 struct device_node *np,
68 struct resource *res);
92ea637e 69extern bool of_dma_is_coherent(struct device_node *np);
a850a755 70#else /* CONFIG_OF_ADDRESS */
fcd71d9c
SM
71static inline void __iomem *of_io_request_and_map(struct device_node *device,
72 int index, const char *name)
73{
74 return IOMEM_ERR_PTR(-EINVAL);
75}
b1d06b60
GR
76
77static inline u64 of_translate_address(struct device_node *np,
78 const __be32 *addr)
79{
80 return OF_BAD_ADDR;
81}
82
050a2c62
RH
83static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
84 u64 *size, unsigned int *flags)
a850a755
GL
85{
86 return NULL;
87}
29b635c0
AM
88
89static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
90 struct device_node *node)
91{
a060c210
MG
92 return -ENOSYS;
93}
94
95static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
96 struct device_node *node)
97{
98 return -ENOSYS;
29b635c0
AM
99}
100
101static inline struct of_pci_range *of_pci_range_parser_one(
102 struct of_pci_range_parser *parser,
103 struct of_pci_range *range)
104{
105 return NULL;
106}
18308c94 107
c3c0dc75
RH
108static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
109 struct resource *r)
110{
111 return -ENOSYS;
112}
113
114static inline int of_pci_range_to_resource(struct of_pci_range *range,
115 struct device_node *np,
116 struct resource *res)
117{
118 return -ENOSYS;
119}
120
92ea637e
SS
121static inline bool of_dma_is_coherent(struct device_node *np)
122{
123 return false;
124}
a850a755
GL
125#endif /* CONFIG_OF_ADDRESS */
126
4acf4b9c
RH
127#ifdef CONFIG_OF
128extern int of_address_to_resource(struct device_node *dev, int index,
129 struct resource *r);
130void __iomem *of_iomap(struct device_node *node, int index);
131#else
132static inline int of_address_to_resource(struct device_node *dev, int index,
133 struct resource *r)
134{
135 return -EINVAL;
136}
137
138static inline void __iomem *of_iomap(struct device_node *device, int index)
139{
140 return NULL;
141}
142#endif
2f96593e 143#define of_range_parser_init of_pci_range_parser_init
a850a755 144
050a2c62
RH
145static inline const __be32 *of_get_address(struct device_node *dev, int index,
146 u64 *size, unsigned int *flags)
147{
148 return __of_get_address(dev, index, -1, size, flags);
149}
150
151static inline const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
152 u64 *size, unsigned int *flags)
153{
154 return __of_get_address(dev, -1, bar_no, size, flags);
155}
156
6b884a8d 157#endif /* __OF_ADDRESS_H */