1 /* SPDX-License-Identifier: GPL-2.0 */
4 #include <linux/ioport.h>
5 #include <linux/errno.h>
11 struct of_pci_range_parser {
12 struct device_node *node;
21 #define of_range_parser of_pci_range_parser
32 #define of_range of_pci_range
34 #define for_each_of_pci_range(parser, range) \
35 for (; of_pci_range_parser_one(parser, range);)
36 #define for_each_of_range for_each_of_pci_range
38 /* Translate a DMA address from device space to CPU space */
39 extern u64 of_translate_dma_address(struct device_node *dev,
40 const __be32 *in_addr);
42 #ifdef CONFIG_OF_ADDRESS
43 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
44 extern int of_address_to_resource(struct device_node *dev, int index,
46 extern void __iomem *of_iomap(struct device_node *device, int index);
47 void __iomem *of_io_request_and_map(struct device_node *device,
48 int index, const char *name);
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
54 extern const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
55 u64 *size, unsigned int *flags);
57 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
58 struct device_node *node);
59 extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
60 struct device_node *node);
61 extern struct of_pci_range *of_pci_range_parser_one(
62 struct of_pci_range_parser *parser,
63 struct of_pci_range *range);
64 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
66 extern int of_pci_range_to_resource(struct of_pci_range *range,
67 struct device_node *np,
68 struct resource *res);
69 extern bool of_dma_is_coherent(struct device_node *np);
70 #else /* CONFIG_OF_ADDRESS */
71 static inline void __iomem *of_io_request_and_map(struct device_node *device,
72 int index, const char *name)
74 return IOMEM_ERR_PTR(-EINVAL);
77 static inline u64 of_translate_address(struct device_node *np,
83 static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
84 u64 *size, unsigned int *flags)
89 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
90 struct device_node *node)
95 static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
96 struct device_node *node)
101 static inline struct of_pci_range *of_pci_range_parser_one(
102 struct of_pci_range_parser *parser,
103 struct of_pci_range *range)
108 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
114 static inline int of_pci_range_to_resource(struct of_pci_range *range,
115 struct device_node *np,
116 struct resource *res)
121 static inline bool of_dma_is_coherent(struct device_node *np)
125 #endif /* CONFIG_OF_ADDRESS */
128 extern int of_address_to_resource(struct device_node *dev, int index,
130 void __iomem *of_iomap(struct device_node *node, int index);
132 static inline int of_address_to_resource(struct device_node *dev, int index,
138 static inline void __iomem *of_iomap(struct device_node *device, int index)
143 #define of_range_parser_init of_pci_range_parser_init
145 static inline const __be32 *of_get_address(struct device_node *dev, int index,
146 u64 *size, unsigned int *flags)
148 return __of_get_address(dev, index, -1, size, flags);
151 static inline const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
152 u64 *size, unsigned int *flags)
154 return __of_get_address(dev, -1, bar_no, size, flags);
157 #endif /* __OF_ADDRESS_H */