3 #include <linux/ioport.h>
4 #include <linux/errno.h>
7 struct of_pci_range_parser {
8 struct device_node *node;
23 #define for_each_of_pci_range(parser, range) \
24 for (; of_pci_range_parser_one(parser, range);)
26 /* Translate a DMA address from device space to CPU space */
27 extern u64 of_translate_dma_address(struct device_node *dev,
28 const __be32 *in_addr);
30 #ifdef CONFIG_OF_ADDRESS
31 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
32 extern int of_address_to_resource(struct device_node *dev, int index,
34 extern struct device_node *of_find_matching_node_by_address(
35 struct device_node *from,
36 const struct of_device_id *matches,
38 extern void __iomem *of_iomap(struct device_node *device, int index);
39 extern void __iomem *of_iomap_by_name(struct device_node *device,
42 /* Extract an address from a device, returns the region size and
43 * the address space flags too. The PCI version uses a BAR number
44 * instead of an absolute index
46 extern const __be32 *of_get_address(struct device_node *dev, int index,
47 u64 *size, unsigned int *flags);
48 extern const __be32 *of_get_address_by_name(struct device_node *dev,
49 const char *name, u64 *size, unsigned int *flags);
51 extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
52 extern unsigned long pci_address_to_pio(phys_addr_t addr);
53 extern phys_addr_t pci_pio_to_address(unsigned long pio);
55 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
56 struct device_node *node);
57 extern struct of_pci_range *of_pci_range_parser_one(
58 struct of_pci_range_parser *parser,
59 struct of_pci_range *range);
60 extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
61 u64 *paddr, u64 *size);
62 extern bool of_dma_is_coherent(struct device_node *np);
63 #else /* CONFIG_OF_ADDRESS */
65 static inline u64 of_translate_address(struct device_node *np,
71 static inline struct device_node *of_find_matching_node_by_address(
72 struct device_node *from,
73 const struct of_device_id *matches,
79 static inline const __be32 *of_get_address(struct device_node *dev, int index,
80 u64 *size, unsigned int *flags)
85 static inline phys_addr_t pci_pio_to_address(unsigned long pio)
90 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
91 struct device_node *node)
96 static inline struct of_pci_range *of_pci_range_parser_one(
97 struct of_pci_range_parser *parser,
98 struct of_pci_range *range)
103 static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
104 u64 *paddr, u64 *size)
109 static inline bool of_dma_is_coherent(struct device_node *np)
113 #endif /* CONFIG_OF_ADDRESS */
116 extern int of_address_to_resource(struct device_node *dev, int index,
118 void __iomem *of_iomap(struct device_node *node, int index);
119 void __iomem *of_io_request_and_map(struct device_node *device,
120 int index, const char *name);
123 #include <linux/io.h>
125 static inline int of_address_to_resource(struct device_node *dev, int index,
131 static inline void __iomem *of_iomap(struct device_node *device, int index)
136 static inline void __iomem *of_io_request_and_map(struct device_node *device,
137 int index, const char *name)
139 return IOMEM_ERR_PTR(-EINVAL);
143 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
144 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
145 u64 *size, unsigned int *flags);
146 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
148 extern int of_pci_range_to_resource(struct of_pci_range *range,
149 struct device_node *np,
150 struct resource *res);
151 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
152 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
158 static inline const __be32 *of_get_pci_address(struct device_node *dev,
159 int bar_no, u64 *size, unsigned int *flags)
163 static inline int of_pci_range_to_resource(struct of_pci_range *range,
164 struct device_node *np,
165 struct resource *res)
169 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
171 #endif /* __OF_ADDRESS_H */