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
;
25 #define for_each_of_pci_range(parser, range) \
26 for (; of_pci_range_parser_one(parser, range);)
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
);
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
,
36 extern struct device_node
*of_find_matching_node_by_address(
37 struct device_node
*from
,
38 const struct of_device_id
*matches
,
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
);
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
48 extern const __be32
*of_get_address(struct device_node
*dev
, int index
,
49 u64
*size
, unsigned int *flags
);
51 extern int of_pci_range_parser_init(struct of_pci_range_parser
*parser
,
52 struct device_node
*node
);
53 extern int of_pci_dma_range_parser_init(struct of_pci_range_parser
*parser
,
54 struct device_node
*node
);
55 extern struct of_pci_range
*of_pci_range_parser_one(
56 struct of_pci_range_parser
*parser
,
57 struct of_pci_range
*range
);
58 extern int of_dma_get_range(struct device_node
*np
, u64
*dma_addr
,
59 u64
*paddr
, u64
*size
);
60 extern bool of_dma_is_coherent(struct device_node
*np
);
61 #else /* CONFIG_OF_ADDRESS */
62 static inline void __iomem
*of_io_request_and_map(struct device_node
*device
,
63 int index
, const char *name
)
65 return IOMEM_ERR_PTR(-EINVAL
);
68 static inline u64
of_translate_address(struct device_node
*np
,
74 static inline struct device_node
*of_find_matching_node_by_address(
75 struct device_node
*from
,
76 const struct of_device_id
*matches
,
82 static inline const __be32
*of_get_address(struct device_node
*dev
, int index
,
83 u64
*size
, unsigned int *flags
)
88 static inline int of_pci_range_parser_init(struct of_pci_range_parser
*parser
,
89 struct device_node
*node
)
94 static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser
*parser
,
95 struct device_node
*node
)
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
)
107 static inline int of_dma_get_range(struct device_node
*np
, u64
*dma_addr
,
108 u64
*paddr
, u64
*size
)
113 static inline bool of_dma_is_coherent(struct device_node
*np
)
117 #endif /* CONFIG_OF_ADDRESS */
120 extern int of_address_to_resource(struct device_node
*dev
, int index
,
122 void __iomem
*of_iomap(struct device_node
*node
, int index
);
124 static inline int of_address_to_resource(struct device_node
*dev
, int index
,
130 static inline void __iomem
*of_iomap(struct device_node
*device
, int index
)
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
,
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
,
151 static inline const __be32
*of_get_pci_address(struct device_node
*dev
,
152 int bar_no
, u64
*size
, unsigned int *flags
)
156 static inline int of_pci_range_to_resource(struct of_pci_range
*range
,
157 struct device_node
*np
,
158 struct resource
*res
)
162 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
164 #endif /* __OF_ADDRESS_H */