blob: 37864734ca50f76838cc1e95ea92f8d37bbdc856 [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
Andrew Murray29b635c2013-05-16 17:55:17 +020050extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
51 struct device_node *node);
52extern struct of_pci_range *of_pci_range_parser_one(
53 struct of_pci_range_parser *parser,
54 struct of_pci_range *range);
Grygorii Strashko18308c92014-04-24 11:30:02 -040055extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
56 u64 *paddr, u64 *size);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040057extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070058#else /* CONFIG_OF_ADDRESS */
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053059static inline void __iomem *of_io_request_and_map(struct device_node *device,
60 int index, const char *name)
61{
62 return IOMEM_ERR_PTR(-EINVAL);
63}
Guenter Roeckb1d06b62015-11-06 19:28:22 -080064
65static inline u64 of_translate_address(struct device_node *np,
66 const __be32 *addr)
67{
68 return OF_BAD_ADDR;
69}
70
Grant Likelya850a752012-02-14 14:06:55 -070071static inline struct device_node *of_find_matching_node_by_address(
72 struct device_node *from,
73 const struct of_device_id *matches,
74 u64 base_address)
75{
76 return NULL;
77}
Rob Herring4acf4b92013-09-16 21:03:24 -050078
Kim Phillips47b1e682012-10-08 19:41:58 -050079static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070080 u64 *size, unsigned int *flags)
81{
82 return NULL;
83}
Andrew Murray29b635c2013-05-16 17:55:17 +020084
85static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
86 struct device_node *node)
87{
88 return -1;
89}
90
91static inline struct of_pci_range *of_pci_range_parser_one(
92 struct of_pci_range_parser *parser,
93 struct of_pci_range *range)
94{
95 return NULL;
96}
Grygorii Strashko18308c92014-04-24 11:30:02 -040097
98static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
99 u64 *paddr, u64 *size)
100{
101 return -ENODEV;
102}
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400103
104static inline bool of_dma_is_coherent(struct device_node *np)
105{
106 return false;
107}
Grant Likelya850a752012-02-14 14:06:55 -0700108#endif /* CONFIG_OF_ADDRESS */
109
Rob Herring4acf4b92013-09-16 21:03:24 -0500110#ifdef CONFIG_OF
111extern int of_address_to_resource(struct device_node *dev, int index,
112 struct resource *r);
113void __iomem *of_iomap(struct device_node *node, int index);
114#else
115static inline int of_address_to_resource(struct device_node *dev, int index,
116 struct resource *r)
117{
118 return -EINVAL;
119}
120
121static inline void __iomem *of_iomap(struct device_node *device, int index)
122{
123 return NULL;
124}
125#endif
Grant Likelya850a752012-02-14 14:06:55 -0700126
127#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100128extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600129 u64 *size, unsigned int *flags);
130extern int of_pci_address_to_resource(struct device_node *dev, int bar,
131 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100132extern int of_pci_range_to_resource(struct of_pci_range *range,
133 struct device_node *np,
134 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700135#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600136static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
137 struct resource *r)
138{
139 return -ENOSYS;
140}
141
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100142static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600143 int bar_no, u64 *size, unsigned int *flags)
144{
145 return NULL;
146}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100147static inline int of_pci_range_to_resource(struct of_pci_range *range,
148 struct device_node *np,
149 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100150{
151 return -ENOSYS;
152}
Grant Likelya850a752012-02-14 14:06:55 -0700153#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600154
Grant Likely6b884a82010-06-08 07:48:09 -0600155#endif /* __OF_ADDRESS_H */
156