blob: 01c0a556448b227e6cbc4717a78d62d399d64494 [file] [log] [blame]
Grant Likely6b884a82010-06-08 07:48:09 -06001#ifndef __OF_ADDRESS_H
2#define __OF_ADDRESS_H
3#include <linux/ioport.h>
Grant Likely99ce39e2011-07-05 23:42:37 -06004#include <linux/errno.h>
Grant Likely6b884a82010-06-08 07:48:09 -06005#include <linux/of.h>
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +05306#include <linux/io.h>
Grant Likely6b884a82010-06-08 07:48:09 -06007
Andrew Murray29b635c2013-05-16 17:55:17 +02008struct of_pci_range_parser {
9 struct device_node *node;
10 const __be32 *range;
11 const __be32 *end;
12 int np;
13 int pna;
14};
15
16struct of_pci_range {
17 u32 pci_space;
18 u64 pci_addr;
19 u64 cpu_addr;
20 u64 size;
21 u32 flags;
22};
23
24#define for_each_of_pci_range(parser, range) \
25 for (; of_pci_range_parser_one(parser, range);)
26
Rob Herringd0dfa162013-09-16 21:05:05 -050027/* Translate a DMA address from device space to CPU space */
28extern u64 of_translate_dma_address(struct device_node *dev,
29 const __be32 *in_addr);
30
Grant Likelya850a752012-02-14 14:06:55 -070031#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010032extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060033extern int of_address_to_resource(struct device_node *dev, int index,
34 struct resource *r);
Grant Likely90e33f62011-07-05 23:42:28 -060035extern struct device_node *of_find_matching_node_by_address(
36 struct device_node *from,
37 const struct of_device_id *matches,
38 u64 base_address);
Grant Likely6b884a82010-06-08 07:48:09 -060039extern void __iomem *of_iomap(struct device_node *device, int index);
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053040void __iomem *of_io_request_and_map(struct device_node *device,
41 int index, const char *name);
Grant Likely6b884a82010-06-08 07:48:09 -060042
Grant Likely22ae7822010-07-29 11:49:01 -060043/* Extract an address from a device, returns the region size and
44 * the address space flags too. The PCI version uses a BAR number
45 * instead of an absolute index
46 */
Kim Phillips47b1e682012-10-08 19:41:58 -050047extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060048 u64 *size, unsigned int *flags);
49
Liviu Dudau41f8bba2014-09-29 15:29:21 +010050extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
Rob Herring25ff7942013-09-07 14:07:11 -050051extern unsigned long pci_address_to_pio(phys_addr_t addr);
Liviu Dudau41f8bba2014-09-29 15:29:21 +010052extern phys_addr_t pci_pio_to_address(unsigned long pio);
Grant Likely22ae7822010-07-29 11:49:01 -060053
Andrew Murray29b635c2013-05-16 17:55:17 +020054extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
55 struct device_node *node);
56extern struct of_pci_range *of_pci_range_parser_one(
57 struct of_pci_range_parser *parser,
58 struct of_pci_range *range);
Grygorii Strashko18308c92014-04-24 11:30:02 -040059extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
60 u64 *paddr, u64 *size);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040061extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070062#else /* CONFIG_OF_ADDRESS */
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053063static inline void __iomem *of_io_request_and_map(struct device_node *device,
64 int index, const char *name)
65{
66 return IOMEM_ERR_PTR(-EINVAL);
67}
Guenter Roeckb1d06b62015-11-06 19:28:22 -080068
69static inline u64 of_translate_address(struct device_node *np,
70 const __be32 *addr)
71{
72 return OF_BAD_ADDR;
73}
74
Grant Likelya850a752012-02-14 14:06:55 -070075static inline struct device_node *of_find_matching_node_by_address(
76 struct device_node *from,
77 const struct of_device_id *matches,
78 u64 base_address)
79{
80 return NULL;
81}
Rob Herring4acf4b92013-09-16 21:03:24 -050082
Kim Phillips47b1e682012-10-08 19:41:58 -050083static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070084 u64 *size, unsigned int *flags)
85{
86 return NULL;
87}
Andrew Murray29b635c2013-05-16 17:55:17 +020088
Liviu Dudau41f8bba2014-09-29 15:29:21 +010089static inline phys_addr_t pci_pio_to_address(unsigned long pio)
90{
91 return 0;
92}
93
Andrew Murray29b635c2013-05-16 17:55:17 +020094static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
95 struct device_node *node)
96{
97 return -1;
98}
99
100static inline struct of_pci_range *of_pci_range_parser_one(
101 struct of_pci_range_parser *parser,
102 struct of_pci_range *range)
103{
104 return NULL;
105}
Grygorii Strashko18308c92014-04-24 11:30:02 -0400106
107static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
108 u64 *paddr, u64 *size)
109{
110 return -ENODEV;
111}
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400112
113static inline bool of_dma_is_coherent(struct device_node *np)
114{
115 return false;
116}
Grant Likelya850a752012-02-14 14:06:55 -0700117#endif /* CONFIG_OF_ADDRESS */
118
Rob Herring4acf4b92013-09-16 21:03:24 -0500119#ifdef CONFIG_OF
120extern int of_address_to_resource(struct device_node *dev, int index,
121 struct resource *r);
122void __iomem *of_iomap(struct device_node *node, int index);
123#else
124static inline int of_address_to_resource(struct device_node *dev, int index,
125 struct resource *r)
126{
127 return -EINVAL;
128}
129
130static inline void __iomem *of_iomap(struct device_node *device, int index)
131{
132 return NULL;
133}
134#endif
Grant Likelya850a752012-02-14 14:06:55 -0700135
136#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100137extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600138 u64 *size, unsigned int *flags);
139extern int of_pci_address_to_resource(struct device_node *dev, int bar,
140 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100141extern int of_pci_range_to_resource(struct of_pci_range *range,
142 struct device_node *np,
143 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700144#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600145static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
146 struct resource *r)
147{
148 return -ENOSYS;
149}
150
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100151static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600152 int bar_no, u64 *size, unsigned int *flags)
153{
154 return NULL;
155}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100156static inline int of_pci_range_to_resource(struct of_pci_range *range,
157 struct device_node *np,
158 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100159{
160 return -ENOSYS;
161}
Grant Likelya850a752012-02-14 14:06:55 -0700162#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600163
Grant Likely6b884a82010-06-08 07:48:09 -0600164#endif /* __OF_ADDRESS_H */
165