1 /* SPDX-License-Identifier: GPL-2.0 */
4 #include <linux/ioport.h>
5 #include <linux/errno.h>
9 struct of_pci_range_parser
{
10 struct device_node
*node
;
26 #define for_each_of_pci_range(parser, range) \
27 for (; of_pci_range_parser_one(parser, range);)
29 /* Translate a DMA address from device space to CPU space */
30 extern u64
of_translate_dma_address(struct device_node
*dev
,
31 const __be32
*in_addr
);
33 #ifdef CONFIG_OF_ADDRESS
34 extern u64
of_translate_address(struct device_node
*np
, const __be32
*addr
);
35 extern int of_address_to_resource(struct device_node
*dev
, int index
,
37 extern void __iomem
*of_iomap(struct device_node
*device
, int index
);
38 void __iomem
*of_io_request_and_map(struct device_node
*device
,
39 int index
, const char *name
);
41 /* Extract an address from a device, returns the region size and
42 * the address space flags too. The PCI version uses a BAR number
43 * instead of an absolute index
45 extern const __be32
*of_get_address(struct device_node
*dev
, int index
,
46 u64
*size
, unsigned int *flags
);
48 extern int of_pci_range_parser_init(struct of_pci_range_parser
*parser
,
49 struct device_node
*node
);
50 extern int of_pci_dma_range_parser_init(struct of_pci_range_parser
*parser
,
51 struct device_node
*node
);
52 extern struct of_pci_range
*of_pci_range_parser_one(
53 struct of_pci_range_parser
*parser
,
54 struct of_pci_range
*range
);
55 extern bool of_dma_is_coherent(struct device_node
*np
);
56 #else /* CONFIG_OF_ADDRESS */
57 static inline void __iomem
*of_io_request_and_map(struct device_node
*device
,
58 int index
, const char *name
)
60 return IOMEM_ERR_PTR(-EINVAL
);
63 static inline u64
of_translate_address(struct device_node
*np
,
69 static inline const __be32
*of_get_address(struct device_node
*dev
, int index
,
70 u64
*size
, unsigned int *flags
)
75 static inline int of_pci_range_parser_init(struct of_pci_range_parser
*parser
,
76 struct device_node
*node
)
81 static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser
*parser
,
82 struct device_node
*node
)
87 static inline struct of_pci_range
*of_pci_range_parser_one(
88 struct of_pci_range_parser
*parser
,
89 struct of_pci_range
*range
)
94 static inline bool of_dma_is_coherent(struct device_node
*np
)
98 #endif /* CONFIG_OF_ADDRESS */
101 extern int of_address_to_resource(struct device_node
*dev
, int index
,
103 void __iomem
*of_iomap(struct device_node
*node
, int index
);
105 static inline int of_address_to_resource(struct device_node
*dev
, int index
,
111 static inline void __iomem
*of_iomap(struct device_node
*device
, int index
)
117 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
118 extern const __be32
*of_get_pci_address(struct device_node
*dev
, int bar_no
,
119 u64
*size
, unsigned int *flags
);
120 extern int of_pci_address_to_resource(struct device_node
*dev
, int bar
,
122 extern int of_pci_range_to_resource(struct of_pci_range
*range
,
123 struct device_node
*np
,
124 struct resource
*res
);
125 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
126 static inline int of_pci_address_to_resource(struct device_node
*dev
, int bar
,
132 static inline const __be32
*of_get_pci_address(struct device_node
*dev
,
133 int bar_no
, u64
*size
, unsigned int *flags
)
137 static inline int of_pci_range_to_resource(struct of_pci_range
*range
,
138 struct device_node
*np
,
139 struct resource
*res
)
143 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
145 #endif /* __OF_ADDRESS_H */